Document ZOOM_query_sortby2
[yaz-moved-to-github.git] / doc / zoom.xml
1 <!--
2 ### Still to document:
3 ZOOM_connection_errcode(c)
4 ZOOM_connection_errmsg(c)
5 ZOOM_connection_addinfo(c)
6 ZOOM_connection_addinfo(c)
7 ZOOM_connection_diagset(c);
8 ZOOM_connection_save_apdu_wrbuf
9 ZOOM_diag_str(error)
10 ZOOM_resultset_record_immediate(s, pos)
11 ZOOM_resultset_cache_reset(r)
12 ZOOM_resultset_sort(r, sort_type, sort_spec)
13 ZOOM_resultset_sort1(r, sort_type, sort_spec)
14 ZOOM_options_set_callback(opt, function, handle)
15 ZOOM_options_create_with_parent2(parent1, parent2)
16 ZOOM_options_getl(opt, name, len)
17 ZOOM_options_setl(opt, name, value, len)
18 ZOOM_options_get_bool(opt, name, defa)
19 ZOOM_options_get_int(opt, name, defa)
20 ZOOM_options_set_int(opt, name, value)
21 ZOOM_query_cql2rpn(ZOOM_query s, const char *str, ZOOM_connection conn)
22 -->
23  <chapter id="zoom"><title>ZOOM</title>
24   <para>
25     &zoom; is an acronym for 'Z39.50 Object-Orientation Model' and is
26    an initiative started by Mike Taylor (Mike is from the UK, which
27    explains the peculiar name of the model). The goal of &zoom; is to
28    provide a common Z39.50 client API not bound to a particular
29    programming language or toolkit.
30   </para>
31
32   <para>
33     From YAZ version 2.1.12, <ulink url="&url.sru;">SRU</ulink> is supported.
34     You can make SRU ZOOM connections by specifying scheme
35     <literal>http://</literal> for the hostname for a connection.
36     The dialect of SRU used is specified by the value of the
37     connection's <literal>sru</literal> option, which may be SRU over
38     HTTP GET (<literal>get</literal>),
39     SRU over HTTP POST (<literal>post</literal>), (SRU over
40     SOAP) (<literal>soap</literal>) or <literal>SOLR</literal>
41     (<ulink url="&url.solr;">SOLR</ulink> Web Service).
42     Using the facility for embedding options in target strings, a
43     connection can be forced to use SRU rather the SRW (the default) by
44     prefixing the target string with <literal>sru=get,</literal>, like this:
45     <literal>sru=get,http://sru.miketaylor.org.uk:80/sru.pl</literal>
46   </para>
47   <para>
48    <ulink url="&url.solr;">SOLR</ulink>  protocol support was added to
49    YAZ in version 4.1.0, as a dialect of a SRU protocol, since both are
50    HTTP based protocols.
51   </para>
52   <para>
53    The lack of a simple Z39.50 client API for &yaz; has become more
54    and more apparent over time. So when the first &zoom; specification
55    became available,
56    an implementation for &yaz; was quickly developed. For the first time, it is
57    now as easy (or easier!) to develop clients than servers with &yaz;. This
58    chapter describes the &zoom; C binding. Before going further, please
59    reconsider whether C is the right programming language for the job.
60    There are other language bindings available for &yaz;, and still
61    more
62    are in active development. See the
63    <ulink url="&url.zoom;">ZOOM web-site</ulink> for
64    more information.
65   </para>
66
67   <para>
68    In order to fully understand this chapter you should read and
69    try the example programs <literal>zoomtst1.c</literal>,
70    <literal>zoomtst2.c</literal>, .. in the <literal>zoom</literal>
71    directory.
72   </para>
73
74   <para>
75    The C language misses features found in object oriented languages
76    such as C++, Java, etc. For example, you'll have to manually,
77    destroy all objects you create, even though you may think of them as
78    temporary. Most objects has a <literal>_create</literal> - and a
79    <literal>_destroy</literal> variant.
80    All objects are in fact pointers to internal stuff, but you don't see
81    that because of typedefs. All destroy methods should gracefully ignore a
82    <literal>NULL</literal> pointer.
83   </para>
84   <para>
85    In each of the sections below you'll find a sub section called
86    protocol behavior, that describes how the API maps to the Z39.50
87    protocol.
88   </para>
89   <sect1 id="zoom-connections"><title>Connections</title>
90
91    <para>The Connection object is a session with a target.
92    </para>
93    <synopsis>
94     #include &lt;yaz/zoom.h>
95
96     ZOOM_connection ZOOM_connection_new(const char *host, int portnum);
97
98     ZOOM_connection ZOOM_connection_create(ZOOM_options options);
99
100     void ZOOM_connection_connect(ZOOM_connection c, const char *host,
101                                  int portnum);
102     void ZOOM_connection_destroy(ZOOM_connection c);
103    </synopsis>
104    <para>
105     Connection objects are created with either function
106     <function>ZOOM_connection_new</function> or
107     <function>ZOOM_connection_create</function>.
108     The former creates and automatically attempts to establish a network
109     connection with the target. The latter doesn't establish
110     a connection immediately, thus allowing you to specify options
111     before establishing network connection using the function
112     <function>ZOOM_connection_connect</function>.
113     If the port number, <literal>portnum</literal>, is zero, the
114     <literal>host</literal> is consulted for a port specification.
115     If no port is given, 210 is used. A colon denotes the beginning of
116     a port number in the host string. If the host string includes a
117     slash, the following part specifies a database for the connection.
118    </para>
119    <para>
120     You can prefix the host with a scheme followed by colon. The
121     default scheme is <literal>tcp</literal> (Z39.50 protocol).
122     The scheme <literal>http</literal> selects SRU/get over HTTP by default,
123     but can overridded to use SRU/post, SRW and the SOLR protocol.
124    </para>
125    <para>
126     You can prefix the scheme-qualified host-string with one or more
127     comma-separated
128     <literal><parameter>key</parameter>=<parameter>value</parameter></literal>
129     sequences, each of which represents an option to be set into the
130     connection structure <emphasis>before</emphasis> the
131     protocol-level connection is forged and the initialization
132     handshake takes place.  This facility can be used to provide
133     authentication credentials, as in host-strings such as:
134     <literal>user=admin,password=halfAm4n,tcp:localhost:8017/db</literal>
135    </para>
136    <para>
137     Connection objects should be destroyed using the function
138     <function>ZOOM_connection_destroy</function>.
139    </para>
140    <synopsis>
141     void ZOOM_connection_option_set(ZOOM_connection c,
142                                     const char *key, const char *val);
143
144     void ZOOM_connection_option_setl(ZOOM_connection c,
145                                      const char *key,
146                                      const char *val, int len);
147
148     const char *ZOOM_connection_option_get(ZOOM_connection c,
149                                            const char *key);
150     const char *ZOOM_connection_option_getl(ZOOM_connection c,
151                                             const char *key,
152                                             int *lenp);
153    </synopsis>
154    <para>
155     The functions <function>ZOOM_connection_option_set</function> and
156     <function>ZOOM_connection_option_setl</function> allows you to
157     set an option given by <parameter>key</parameter> to the value
158     <parameter>value</parameter> for the connection.
159     For <function>ZOOM_connection_option_set</function>, the
160     value is assumed to be a 0-terminated string. Function
161     <function>ZOOM_connection_option_setl</function> specifies a
162     value of a certain size (len).
163    </para>
164    <para>
165     Functions <function>ZOOM_connection_option_get</function> and
166     <function>ZOOM_connection_option_getl</function> returns
167     the value for an option given by <parameter>key</parameter>.
168    </para>
169    <table id="zoom-connection-options" frame="top">
170     <title>ZOOM Connection Options</title>
171     <tgroup cols="3">
172      <colspec colwidth="4*" colname="name"></colspec>
173      <colspec colwidth="7*" colname="description"></colspec>
174      <colspec colwidth="3*" colname="default"></colspec>
175      <thead>
176       <row>
177        <entry>Option</entry>
178        <entry>Description</entry>
179        <entry>Default</entry>
180       </row>
181      </thead>
182      <tbody>
183       <row><entry>
184         implementationName</entry><entry>Name of Your client
185        </entry><entry>none</entry></row>
186       <row><entry>
187         user</entry><entry>Authentication user name
188        </entry><entry>none</entry></row>
189       <row><entry>
190         group</entry><entry>Authentication group name
191        </entry><entry>none</entry></row>
192       <row><entry>
193         password</entry><entry>Authentication password.
194        </entry><entry>none</entry></row>
195       <row><entry>
196         host</entry><entry>Target host. This setting is "read-only".
197         It's automatically set internally when connecting to a target.
198        </entry><entry>none</entry></row>
199       <row><entry>
200         proxy</entry><entry>Proxy host. If set, the logical host
201         is encoded in the otherInfo area of the Z39.50 Init PDU
202         with OID 1.2.840.10003.10.1000.81.1.
203        </entry><entry>none</entry></row>
204       <row><entry>
205         clientIP</entry><entry>Client IP. If set, is
206         encoded in the otherInfo area of a Z39.50 PDU with OID
207         1.2.840.10003.10.1000.81.3. Holds the original IP addreses
208         of a client. Is used of ZOOM is used in a gateway of some sort.
209        </entry><entry>none</entry></row>
210       <row><entry>
211         async</entry><entry>If true (1) the connection operates in
212         asynchronous operation which means that all calls are non-blocking
213         except
214         <link linkend="zoom.events"><function>ZOOM_event</function></link>.
215        </entry><entry>0</entry></row>
216       <row><entry>
217         maximumRecordSize</entry><entry> Maximum size of single record.
218        </entry><entry>1 MB</entry></row>
219       <row><entry>
220         preferredMessageSize</entry><entry> Maximum size of multiple records.
221        </entry><entry>1 MB</entry></row>
222       <row><entry>
223         lang</entry><entry> Language for negotiation.
224        </entry><entry>none</entry></row>
225       <row><entry>
226         charset</entry><entry> Character set for negotiation.
227        </entry><entry>none</entry></row>
228       <row><entry>
229         serverImplementationId</entry><entry>
230         Implementation ID of server.  (The old targetImplementationId
231         option is also supported for the benefit of old applications.)
232        </entry><entry>none</entry></row>
233       <row><entry>
234         targetImplementationName</entry><entry>
235         Implementation Name of server.  (The old
236         targetImplementationName option is also supported for the
237         benefit of old applications.)
238        </entry><entry>none</entry></row>
239       <row><entry>
240         serverImplementationVersion</entry><entry>
241         Implementation Version of server.  (the old
242         targetImplementationVersion option is also supported for the
243         benefit of old applications.)
244        </entry><entry>none</entry></row>
245       <row><entry>
246         databaseName</entry><entry>One or more database names
247         separated by character plus (<literal>+</literal>), which to
248         be used by subsequent search requests on this Connection.
249        </entry><entry>Default</entry></row>
250       <row><entry>
251         piggyback</entry><entry>True (1) if piggyback should be
252         used in searches; false (0) if not.
253        </entry><entry>1</entry></row>
254       <row><entry>
255         smallSetUpperBound</entry><entry>If hits is less than or equal to this
256         value, then target will return all records using small element set name
257        </entry><entry>0</entry></row>
258       <row><entry>
259         largeSetLowerBound</entry><entry>If hits is greater than this
260         value, the target will return no records.
261        </entry><entry>1</entry></row>
262       <row><entry>
263         mediumSetPresentNumber</entry><entry>This value represents
264         the number of records to be returned as part of a search when when
265         hits is less than or equal to large set lower bound and if hits
266         is greater than small set upper bound.
267        </entry><entry>0</entry></row>
268       <row><entry>
269         smallSetElementSetName</entry><entry>
270         The element set name to be used for small result sets.
271        </entry><entry>none</entry></row>
272       <row><entry>
273         mediumSetElementSetName</entry><entry>
274         The element set name to be for medium-sized result sets.
275        </entry><entry>none</entry></row>
276       <row><entry>
277         init_opt_search, init_opt_present, init_opt_delSet, etc.</entry><entry>
278         After a successful Init, these options may be interrogated to
279         discover whether the server claims to support the specified
280         operations.
281        </entry><entry>none</entry></row>
282       <row>
283         <entry>sru</entry><entry>
284         SRU/SOLR transport type. Must be either <literal>soap</literal>,
285         <literal>get</literal>, <literal>post</literal>, or
286         <literal>solr</literal>.
287         </entry><entry>soap</entry></row>
288       <row><entry>
289         sru_version</entry><entry>
290         SRU/SRW version. Should be <literal>1.1</literal>, or
291         <literal>1.2</literal>. This is , prior to connect, the version
292         to offer (highest version). And following connect (in fact
293         first operation), holds the negotiated version with the server
294         (same or lower version).
295        </entry><entry>1.2</entry></row>
296       <row><entry>
297         facets</entry><entry>
298         A FacetList is comma-separated list of facet, which is defined
299         as <literal>AttributeList</literal>  and a optional FacetTerm
300         (a Term and a frequency). On request the terms is missing.
301         On response the the list contains the terms that the target
302         could collect.
303        </entry><entry>none</entry></row>
304       <row><entry>
305         apdulog</entry><entry>
306         If set to a true value such as "1", a log of low-level
307         protocol packets is emitted on standard error stream.  This
308         can be very useful for debugging.
309        </entry><entry>0</entry></row>
310       <row><entry>
311         saveAPDU</entry><entry>
312         If set to a true value such as "1", a log of low-level
313         protocol packets is saved. The log can be retrieved by reading
314         option APDU. Setting saveAPDU always has the side effect of
315         resetting the currently saved log. This setting is
316         <emphasis>write-only</emphasis>. If read, NULL will be returned.
317         It is only recognized in
318         <function>ZOOM_connection_option_set</function>.
319        </entry><entry>0</entry></row>
320       <row><entry>
321         APDU</entry><entry>
322         Returns the log of protocol packets. Will be empty if logging
323         is not enabled (see saveAPDU above). This setting is
324         <emphasis>read-only</emphasis>. It is only recognized if used
325         in call to <function>ZOOM_connection_option_get</function> or
326         <function>ZOOM_connection_option_getl</function>.
327        </entry><entry></entry></row>
328      </tbody>
329     </tgroup>
330    </table>
331    <para>
332     If either option <literal>lang</literal> or <literal>charset</literal>
333     is set, then
334     <ulink url="&url.z39.50.charneg;">
335      Character Set and Language Negotiation</ulink> is in effect.
336    </para>
337    <synopsis>
338      int ZOOM_connection_error(ZOOM_connection c, const char **cp,
339                                const char **addinfo);
340      int ZOOM_connection_error_x(ZOOM_connection c, const char **cp,
341                                  const char **addinfo, const char **dset);
342    </synopsis>
343    <para>
344     Function <function>ZOOM_connection_error</function> checks for
345     errors for the last operation(s) performed. The function returns
346     zero if no errors occurred; non-zero otherwise indicating the error.
347     Pointers <parameter>cp</parameter> and <parameter>addinfo</parameter>
348     holds messages for the error and additional-info if passed as
349     non-<literal>NULL</literal>. Function
350     <function>ZOOM_connection_error_x</function> is an extended version
351     of <function>ZOOM_connection_error</function> that is capable of
352     returning name of diagnostic set in <parameter>dset</parameter>.
353    </para>
354    <sect2 id="zoom-connection-z39.50">
355     <title>Z39.50 Protocol behavior</title>
356     <para>
357      The calls <function>ZOOM_connection_new</function> and
358      <function>ZOOM_connection_connect</function> establishes a TCP/IP
359       connection and sends an Initialize Request to the target if
360       possible. In addition, the calls waits for an Initialize Response
361       from the target and the result is inspected (OK or rejected).
362     </para>
363     <para>
364      If <literal>proxy</literal> is set then the client will establish
365      a TCP/IP connection with the peer as specified by the
366      <literal>proxy</literal> host and the hostname as part of the
367      connect calls will be set as part of the Initialize Request.
368      The proxy server will then "forward" the PDU's transparently
369      to the target behind the proxy.
370     </para>
371     <para>
372      For the authentication parameters, if option <literal>user</literal>
373      is set and both options <literal>group</literal> and
374      <literal>pass</literal> are unset, then Open style
375      authentication is used (Version 2/3) in which case the username
376      is usually followed by a slash, then by a password.
377      If either <literal>group</literal>
378      or <literal>pass</literal> is set then idPass authentication
379      (Version 3 only) is used. If none of the options are set, no
380      authentication parameters are set as part of the Initialize Request
381      (obviously).
382     </para>
383     <para>
384      When option <literal>async</literal> is 1, it really means that
385      all network operations are postponed (and queued) until the
386      function <literal>ZOOM_event</literal> is invoked. When doing so
387      it doesn't make sense to check for errors after
388      <literal>ZOOM_connection_new</literal> is called since that
389      operation "connecting - and init" is still incomplete and the
390      API cannot tell the outcome (yet).
391     </para>
392     </sect2>
393    <sect2 id="zoom.sru.init.behavior">
394     <title>SRU/SOLR Protocol behavior</title>
395     <para>
396      The HTTP based protocols (SRU, SRW, SOLR) doesn't feature an Inititialize Request, so
397      the connection phase merely establishes a TCP/IP connection
398      with the SOAP service.
399     </para>
400     <para>Most of the ZOOM connection options do not
401      affect SRU/SOLR and they are ignored. However, future versions
402      of &yaz; might honor <literal>implementationName</literal> and
403      put that as part of User-Agent header for HTTP requests.
404      </para>
405     <para>
406      The <literal>charset</literal> is used in the Content-Type header
407      of HTTP requests.
408     </para>
409    </sect2>
410   </sect1>
411   <sect1 id="zoom.query"><title>Queries</title>
412    <para>
413     Query objects represents queries.
414    </para>
415    <synopsis>
416      ZOOM_query ZOOM_query_create(void);
417
418      void ZOOM_query_destroy(ZOOM_query q);
419
420      int ZOOM_query_prefix(ZOOM_query q, const char *str);
421
422      int ZOOM_query_cql(ZOOM_query s, const char *str);
423
424      int ZOOM_query_sortby(ZOOM_query q, const char *criteria);
425
426      int ZOOM_query_sortby2(ZOOM_query q, const char *strategy,
427                             const char *criteria);
428    </synopsis>
429    <para>
430     Create query objects using <function>ZOOM_query_create</function>
431     and destroy them by calling <function>ZOOM_query_destroy</function>.
432     RPN-queries can be specified in <link linkend="PQF">PQF</link>
433     notation by using the
434     function <function>ZOOM_query_prefix</function>.
435     The <function>ZOOM_query_cql</function> specifies a CQL
436     query to be sent to the server/target.
437     More query types will be added in future versions of &yaz;, such as
438     <link linkend="CCL">CCL</link> to RPN-mapping, native CCL query,
439     etc. In addition to a search, a sort criteria may be set. Function
440     <function>ZOOM_query_sortby</function> specifies a
441     sort criteria using the same string notation for sort as offered by
442     the <link linkend="sortspec">YAZ client</link>.
443    </para>
444    <para>
445     <function>ZOOM_query_sortby2</function> is similar to
446     <function>ZOOM_query_sortby</function> but allows a strategy for
447     sorting. The reason for the strategy parameter is that some
448     protocols offers multiple ways of performing sorting.
449     For example, Z39.50 has the standard sort, which is performed after
450     search on an existing result set.
451     It's also possible to use CQL in Z39.50 as the query type and use
452     CQL's SORTBY keyword. Finally, Index Data's
453     Zebra server also allows sorting to be specified as part of RPN (Type 7).
454    </para>
455    <table id="zoom-sort-strategy" frame="top">
456     <title>ZOOM sort strategy</title>
457     <tgroup cols="2">
458      <colspec colwidth="2*" colname="name"/>
459      <colspec colwidth="5*" colname="description"/>
460      <thead>
461       <row>
462        <entry>Name</entry>
463        <entry>Description</entry>
464       </row>
465      </thead>
466      <tbody>
467       <row>
468        <entry>z39.50</entry><entry>Z39.50 resultset sort</entry>
469       </row>
470       <row>
471        <entry>type7</entry><entry>Sorting embedded in RPN(Type-7)</entry>
472       </row>
473       <row>
474        <entry>cql</entry><entry>CQL SORTBY</entry>
475       </row>
476       <row>
477        <entry>sru11</entry><entry>SRU sortKeys element</entry>
478       </row>
479       <row>
480        <entry>solr</entry><entry>Solr sort</entry>
481       </row>
482       <row>
483        <entry>embed</entry><entry>type7 for Z39.50, cql for SRU,
484         solr for Solr protocol</entry>
485       </row>
486      </tbody>
487     </tgroup>
488    </table>
489   </sect1>
490   <sect1 id="zoom.resultsets"><title>Result sets</title>
491    <para>
492     The result set object is a container for records returned from
493     a target.
494    </para>
495    <synopsis>
496      ZOOM_resultset ZOOM_connection_search(ZOOM_connection, ZOOM_query q);
497
498      ZOOM_resultset ZOOM_connection_search_pqf(ZOOM_connection c,
499                                                const char *q);
500      void ZOOM_resultset_destroy(ZOOM_resultset r);
501    </synopsis>
502    <para>
503     Function <function>ZOOM_connection_search</function> creates
504     a result set given a connection and query.
505     Destroy a result set by calling
506     <function>ZOOM_resultset_destroy</function>.
507     Simple clients may using PQF only may use function
508     <function>ZOOM_connection_search_pqf</function> in which case
509     creating query objects is not necessary.
510    </para>
511    <synopsis>
512      void ZOOM_resultset_option_set(ZOOM_resultset r,
513                                     const char *key, const char *val);
514
515      const char *ZOOM_resultset_option_get(ZOOM_resultset r, const char *key);
516
517      size_t ZOOM_resultset_size(ZOOM_resultset r);
518    </synopsis>
519    <para>
520     Functions <function>ZOOM_resultset_options_set</function> and
521     <function>ZOOM_resultset_get</function> sets and gets an option
522     for a result set similar to <function>ZOOM_connection_option_get</function>
523     and <function>ZOOM_connection_option_set</function>.
524    </para>
525    <para>
526     The number of hits also called result-count is returned by
527     function <function>ZOOM_resultset_size</function>.
528    </para>
529    <table id="zoom.resultset.options"
530     frame="top"><title>ZOOM Result set Options</title>
531     <tgroup cols="3">
532      <colspec colwidth="4*" colname="name"></colspec>
533      <colspec colwidth="7*" colname="description"></colspec>
534      <colspec colwidth="2*" colname="default"></colspec>
535      <thead>
536       <row>
537        <entry>Option</entry>
538        <entry>Description</entry>
539        <entry>Default</entry>
540       </row>
541      </thead>
542      <tbody>
543       <row><entry>
544         start</entry><entry>Offset of first record to be
545         retrieved from target. First record has offset 0 unlike the
546         protocol specifications where first record has position 1.
547         This option affects ZOOM_resultset_search and
548         ZOOM_resultset_search_pqf and must be set before any of
549         these functions are invoked. If a range of
550         records must be fetched manually after search,
551         function ZOOM_resultset_records should be used.
552        </entry><entry>0</entry></row>
553       <row><entry>
554         count</entry><entry>Number of records to be retrieved.
555         This option affects ZOOM_resultset_search and
556         ZOOM_resultset_search_pqf and must be set before any of
557         these functions are invoked.
558        </entry><entry>0</entry></row>
559       <row><entry>
560         presentChunk</entry><entry>The number of records to be
561         requested from the server in each chunk (present request). The
562         value 0 means to request all the records in a single chunk.
563         (The old <literal>step</literal>
564         option is also supported for the benefit of old applications.)
565        </entry><entry>0</entry></row>
566       <row><entry>
567         elementSetName</entry><entry>Element-Set name of records.
568         Most targets should honor element set name <literal>B</literal>
569         and <literal>F</literal> for brief and full respectively.
570        </entry><entry>none</entry></row>
571       <row><entry>
572         preferredRecordSyntax</entry><entry>Preferred Syntax, such as
573         <literal>USMARC</literal>, <literal>SUTRS</literal>, etc.
574        </entry><entry>none</entry></row>
575       <row><entry>
576         schema</entry><entry>Schema for retrieval, such as
577         <literal>Gils-schema</literal>, <literal>Geo-schema</literal>, etc.
578        </entry><entry>none</entry></row>
579       <row><entry>
580         setname</entry><entry>Name of Result Set (Result Set ID).
581         If this option isn't set, the ZOOM module will automatically
582         allocate a result set name.
583        </entry><entry>default</entry></row>
584       <row><entry>
585         rpnCharset</entry><entry>Character set for RPN terms.
586         If this is set, ZOOM C will assume that the ZOOM application is
587         running UTF-8. Terms in RPN queries are then converted to the
588         rpnCharset. If this is unset, ZOOM C will not assume any encoding
589         of RPN terms and no conversion is performed.
590        </entry><entry>none</entry></row>
591      </tbody>
592     </tgroup>
593    </table>
594    <para>
595     For servers that support Search Info report, the following
596     options may be read using <function>ZOOM_resultset_get</function>.
597     This detailed information is read after a successful search has
598     completed.
599    </para>
600    <para>
601     This information is a list of of items, where each item is
602     information about a term or subquery. All items in the list
603     are prefixed by
604     <literal>SearchResult.</literal><replaceable>no</replaceable>
605     where no presents the item number (0=first, 1=second).
606     Read <literal>searchresult.size</literal> to determine the
607     number of items.
608    </para>
609    <table id="zoom.search.info.report.options"
610     frame="top"><title>Search Info Report Options</title>
611     <tgroup cols="2">
612      <colspec colwidth="4*" colname="name"></colspec>
613      <colspec colwidth="7*" colname="description"></colspec>
614      <thead>
615       <row>
616        <entry>Option</entry>
617        <entry>Description</entry>
618       </row>
619      </thead>
620      <tbody>
621       <row>
622        <entry>searchresult.size</entry>
623        <entry>
624         number of search result entries. This option is-nonexistant
625         if no entries are returned by the server.
626        </entry>
627       </row>
628       <row>
629        <entry>searchresult.<replaceable>no</replaceable>.id</entry>
630        <entry>sub query ID</entry>
631       </row>
632       <row>
633        <entry>searchresult.<replaceable>no</replaceable>.count</entry>
634        <entry>result count for item (number of hits)</entry>
635       </row>
636       <row>
637        <entry>searchresult.<replaceable>no</replaceable>.subquery.term</entry>
638        <entry>subquery term</entry>
639       </row>
640       <row>
641        <entry>
642         searchresult.<replaceable>no</replaceable>.interpretation.term
643        </entry>
644        <entry>interpretation term</entry>
645       </row>
646       <row>
647        <entry>
648         searchresult.<replaceable>no</replaceable>.recommendation.term
649        </entry>
650        <entry>recommendation term</entry>
651       </row>
652      </tbody>
653     </tgroup>
654    </table>
655    <sect2 id="zoom.z3950.resultset.behavior">
656     <title>Z39.50 Protocol behavior</title>
657     <para>
658      The creation of a result set involves at least a SearchRequest
659      - SearchResponse protocol handshake. Following that, if a sort
660      criteria was specified as part of the query, a SortRequest -
661      SortResponse handshake takes place. Note that it is necessary to
662      perform sorting before any retrieval takes place, so no records will
663      be returned from the target as part of the SearchResponse because these
664      would be unsorted. Hence, piggyback is disabled when sort criteria
665      are set. Following Search - and a possible sort - Retrieval takes
666      place - as one or more Present Requests/Response pairs being
667      transferred.
668      </para>
669     <para>
670      The API allows for two different modes for retrieval. A high level
671      mode which is somewhat more powerful and a low level one.
672      The low level is enabled when searching on a Connection object
673      for which the settings
674      <literal>smallSetUpperBound</literal>,
675      <literal>mediumSetPresentNumber</literal> and
676      <literal>largeSetLowerBound</literal> are set. The low level mode
677      thus allows you to precisely set how records are returned as part
678      of a search response as offered by the Z39.50 protocol.
679      Since the client may be retrieving records as part of the
680      search response, this mode doesn't work well if sorting is used.
681      </para>
682     <para>
683      The high-level mode allows you to fetch a range of records from
684      the result set with a given start offset. When you use this mode
685      the client will automatically use piggyback if that is possible
686      with the target and perform one or more present requests as needed.
687      Even if the target returns fewer records as part of a present response
688      because of a record size limit, etc. the client will repeat sending
689      present requests. As an example, if option <literal>start</literal>
690      is 0 (default) and <literal>count</literal> is 4, and
691      <literal>piggyback</literal> is 1 (default) and no sorting criteria
692      is specified, then the client will attempt to retrieve the 4
693      records as part the search response (using piggyback). On the other
694      hand, if either <literal>start</literal> is positive or if
695      a sorting criteria is set, or if <literal>piggyback</literal>
696      is 0, then the client will not perform piggyback but send Present
697      Requests instead.
698     </para>
699     <para>
700      If either of the options <literal>mediumSetElementSetName</literal> and
701      <literal>smallSetElementSetName</literal> are unset, the value
702      of option <literal>elementSetName</literal> is used for piggyback
703      searches. This means that for the high-level mode you only have
704      to specify one elementSetName option rather than three.
705      </para>
706    </sect2>
707    <sect2 id="zoom.sru.resultset.behavior">
708     <title>SRU Protocol behavior</title>
709     <para>
710      Current version of &yaz; does not take advantage of a result set id
711      returned by the SRU server. Future versions might do, however.
712      Since, the ZOOM driver does not save result set IDs any
713      present (retrieval) is transformed to a SRU SearchRetrieveRequest
714      with same query but, possibly, different offsets.
715     </para>
716     <para>
717      Option <literal>schema</literal> specifies SRU schema
718      for retrieval. However, options <literal>elementSetName</literal> and
719      <literal>preferredRecordSyntax</literal> are ignored.
720     </para>
721     <para>
722      Options <literal>start</literal> and <literal>count</literal>
723      are supported by SRU.
724      The remaining options
725      <literal>piggyback</literal>,
726      <literal>smallSetUpperBound</literal>,
727      <literal>largeSetLowerBound</literal>,
728      <literal>mediumSetPresentNumber</literal>,
729      <literal>mediumSetElementSetName</literal>,
730       <literal>smallSetElementSetName</literal> are
731      unsupported.
732     </para>
733     <para>
734      SRU supports CQL queries, <emphasis>not</emphasis> PQF.
735      If PQF is used, however, the PQF query is transferred anyway
736      using non-standard element <literal>pQuery</literal> in
737      SRU SearchRetrieveRequest.
738     </para>
739     <para>
740      SOLR queries has to be done in SOLR query format.
741     </para>
742     <para>
743      Unfortunately, SRU or SOLR does not define a database setting. Hence,
744      <literal>databaseName</literal> is unsupported and ignored.
745      However, the path part in host parameter for functions
746      <function>ZOOM_connecton_new</function> and
747      <function>ZOOM_connection_connect</function> acts as a
748      database (at least for the &yaz; SRU server).
749     </para>
750    </sect2>
751   </sect1>
752   <sect1 id="zoom.records"><title>Records</title>
753    <para>
754     A record object is a retrieval record on the client side -
755     created from result sets.
756    </para>
757    <synopsis>
758      void ZOOM_resultset_records(ZOOM_resultset r,
759                                  ZOOM_record *recs,
760                                  size_t start, size_t count);
761      ZOOM_record ZOOM_resultset_record(ZOOM_resultset s, size_t pos);
762
763      const char *ZOOM_record_get(ZOOM_record rec, const char *type,
764                                  size_t *len);
765
766      int ZOOM_record_error(ZOOM_record rec, const char **msg,
767                            const char **addinfo, const char **diagset);
768
769      ZOOM_record ZOOM_record_clone(ZOOM_record rec);
770
771      void ZOOM_record_destroy(ZOOM_record rec);
772    </synopsis>
773    <para>
774     References to temporary records are returned by functions
775     <function>ZOOM_resultset_records</function> or
776     <function>ZOOM_resultset_record</function>.
777     </para>
778    <para>
779     If a persistent reference to a record is desired
780     <function>ZOOM_record_clone</function> should be used.
781     It returns a record reference that should be destroyed
782     by a call to <function>ZOOM_record_destroy</function>.
783    </para>
784    <para>
785     A single record is returned by function
786     <function>ZOOM_resultset_record</function> that takes a
787     position as argument. First record has position zero.
788     If no record could be obtained <literal>NULL</literal> is returned.
789    </para>
790    <para>
791     Error information for a record can be checked with
792     <function>ZOOM_record_error</function> which returns non-zero
793     (error code) if record is in error, called <emphasis>Surrogate
794      Diagnostics</emphasis> in Z39.50.
795    </para>
796    <para>
797     Function <function>ZOOM_resultset_records</function> retrieves
798     a number of records from a result set. Parameter <literal>start</literal>
799     and <literal>count</literal> specifies the range of records to
800     be returned. Upon completion array
801     <literal>recs[0], ..recs[count-1]</literal>
802     holds record objects for the records. The array of records
803      <literal>recs</literal> should be allocated prior the call
804     <function>ZOOM_resultset_records</function>. Note that for those
805     records that couldn't be retrieved from the target
806     <literal>recs[ ..]</literal> is set to <literal>NULL</literal>.
807    </para>
808    <para id="zoom.record.get">
809     In order to extract information about a single record,
810     <function>ZOOM_record_get</function> is provided. The
811     function returns a pointer to certain record information. The
812     nature (type) of the pointer depends on the parameter,
813     <parameter>type</parameter>.
814    </para>
815    <para>
816     The <parameter>type</parameter> is a string of the format:
817    </para>
818    <para>
819     <replaceable>format</replaceable>[;charset=<replaceable>from</replaceable>[/<replaceable>opacfrom</replaceable>][,<replaceable>to</replaceable>]][;format=<replaceable>v</replaceable>]
820    </para>
821    <para>
822     where <replaceable>format</replaceable> specifies the format of the
823     returned record, <replaceable>from</replaceable>
824     specifies the character set of the record in its original form
825     (as returned by the server), <replaceable>to</replaceable> specifies
826     the output (returned)
827     character set encoding.
828     If <replaceable>to</replaceable> is omitted UTF-8 is assumed.
829     If charset is not given, then no character set conversion takes place.
830    </para>
831
832    <para>OPAC records may be returned in a different
833      set from the bibliographic MARC record. If this is this the case,
834     <replaceable>opacfrom</replaceable> should be set to the character set
835     of the OPAC record part.
836    </para>
837    <note>
838      <para>
839        Specifying the OPAC record character set requires YAZ 4.1.5 or later.
840      </para>
841    </note>
842    <para>
843     The format argument controls whether record data should be XML
844     pretty-printed (post process operation).
845     It is enabled only if format value <replaceable>v</replaceable> is
846     <literal>1</literal> and the record content is XML well-formed.
847    </para>
848    <para>
849     In addition, for certain types, the length
850     <literal>len</literal> passed will be set to the size in bytes of
851     the returned information.
852     </para>
853    <para>
854     The following are the supported values for <replaceable>form</replaceable>.
855     <variablelist>
856      <varlistentry><term><literal>database</literal></term>
857       <listitem><para>Database of record is returned
858         as a C null-terminated string. Return type
859         <literal>const char *</literal>.
860        </para></listitem>
861      </varlistentry>
862      <varlistentry><term><literal>syntax</literal></term>
863       <listitem><para>The transfer syntax of the record is returned
864         as a C null-terminated string containing the symbolic name of
865         the record syntax, e.g. <literal>Usmarc</literal>. Return type
866         is
867         <literal>const char *</literal>.
868        </para></listitem>
869      </varlistentry>
870      <varlistentry><term><literal>schema</literal></term>
871       <listitem><para>The schema of the record is returned
872         as a C null-terminated string. Return type is
873         <literal>const char *</literal>.
874        </para></listitem>
875      </varlistentry>
876      <varlistentry><term><literal>render</literal></term>
877       <listitem><para>The record is returned in a display friendly
878         format. Upon completion buffer is returned
879         (type <literal>const char *</literal>) and length is stored in
880         <literal>*len</literal>.
881        </para></listitem>
882      </varlistentry>
883      <varlistentry><term><literal>raw</literal></term>
884       <listitem><para>The record is returned in the internal
885         YAZ specific format. For GRS-1, Explain, and others, the
886         raw data is returned as type
887         <literal>Z_External *</literal> which is just the type for
888         the member <literal>retrievalRecord</literal> in
889         type <literal>NamePlusRecord</literal>.
890         For SUTRS and octet aligned record (including all MARCs) the
891         octet buffer is returned and the length of the buffer.
892        </para></listitem>
893      </varlistentry>
894      <varlistentry><term><literal>xml</literal></term>
895       <listitem><para>The record is returned in XML if possible.
896         SRU, SOLR and Z39.50 records with transfer syntax XML are
897         returned verbatim. MARC records are returned in
898         <ulink url="&url.marcxml;">
899          MARCXML
900          </ulink>
901         (converted from ISO2709 to MARCXML by YAZ).
902         OPAC records are also converted to XML and the
903         bibliographic record is converted to MARCXML (when possible).
904         GRS-1 records are not supported for this form.
905         Upon completion, the XML buffer is returned
906         (type <literal>const char *</literal>) and length is stored in
907         <literal>*len</literal>.
908        </para></listitem>
909      </varlistentry>
910      <varlistentry><term><literal>opac</literal></term>
911       <listitem><para>OPAC information for record is returned in XML
912         if an OPAC record is present at the position given. If no
913         OPAC record is present, a NULL pointer is returned.
914        </para></listitem>
915      </varlistentry>
916      <varlistentry><term><literal>txml</literal></term>
917       <listitem><para>The record is returned in TurboMARC if possible.
918         SRU and Z39.50 records with transfer syntax XML are
919         returned verbatim. MARC records are returned in
920         <link linkend="tools.turbomarc">
921          TurboMARC
922         </link>
923         (converted from ISO2709 to TurboMARC by YAZ).
924         Upon completion, the XML buffer is returned
925         (type <literal>const char *</literal>) and length is stored in
926         <literal>*len</literal>.
927        </para></listitem>
928      </varlistentry>
929     </variablelist>
930    </para>
931    <para>
932     Most
933     <ulink url="&url.marc21;">MARC21</ulink>
934     records uses the
935     <ulink url="&url.marc8;">MARC-8</ulink>
936     character set encoding.
937     An application that wishes to display in Latin-1 would use
938     <screen>
939      render; charset=marc8,iso-8859-1
940     </screen>
941    </para>
942    <sect2 id="zoom.z3950.record.behavior">
943     <title>Z39.50 Protocol behavior</title>
944     <para>
945      The functions <function>ZOOM_resultset_record</function> and
946      <function>ZOOM_resultset_records</function> inspects the client-side
947      record cache. Records not found in cache are fetched using
948      Present.
949      The functions may block (and perform network I/O)  - even though option
950      <literal>async</literal> is 1, because they return records objects.
951      (and there's no way to return records objects without retrieving them!).
952      </para>
953     <para>
954      There is a trick, however, in the usage of function
955      <function>ZOOM_resultset_records</function> that allows for
956      delayed retrieval (and makes it non-blocking). By using
957      a null pointer for <parameter>recs</parameter> you're indicating
958      you're not interested in getting records objects
959      <emphasis>now</emphasis>.
960     </para>
961    </sect2>
962    <sect2 id="zoom.sru.record.behavior">
963     <title>SRU/SOLR Protocol behavior</title>
964     <para>
965      The ZOOM driver for SRU/SOLR treats records returned by a SRU/SOLR server
966      as if they where Z39.50 records with transfer syntax XML and
967      no element set name or database name.
968     </para>
969    </sect2>
970   </sect1>
971   <sect1 id="zoom.facets"><title>Facets</title>
972    <para>
973     Facets operations is not part of the official ZOOM specification, but
974     is an Index Data extension for YAZ-based Z39.50 targets or
975     <ulink url="&url.solr;">SOLR</ulink> targets.
976     In case the target can and is requested to return facets, using a
977     result set the ZOOM client can request one or all facet fields.
978     Using a facet field the client can request the term count and then
979     interate over the terms.
980    </para>
981    <synopsis>
982     ZOOM_facet_field *ZOOM_resultset_facets(ZOOM_resultset r);
983
984     const char ** ZOOM_resultset_facets_names(ZOOM_resultset r);
985
986     ZOOM_facet_field ZOOM_resultset_get_facet_field(ZOOM_resultset r,
987                                                     const char *facet_name);
988
989     ZOOM_facet_field ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r,
990                                                              int pos);
991
992     size_t ZOOM_resultset_facets_size(ZOOM_resultset r);
993
994     const char *ZOOM_facet_field_name(ZOOM_facet_field facet_field);
995
996     size_t ZOOM_facet_field_term_count(ZOOM_facet_field facet_field);
997
998     const char *ZOOM_facet_field_get_term(ZOOM_facet_field facet_field,
999                                           size_t idx, int *freq);
1000    </synopsis>
1001    <para>
1002     References to temporary structures are returned by all functions.
1003     They are only valid as long the Result set is valid.
1004     <function>ZOOM_resultset_get_facet_field</function> or
1005     <function>ZOOM_resultset_get_facet_field_by_index</function>.
1006     <function>ZOOM_resultset_facets</function>.
1007     <function>ZOOM_resultset_facets_names</function>.
1008     <function>ZOOM_facet_field_name</function>.
1009     <function>ZOOM_facet_field_get_term</function>.
1010     </para>
1011    <para id="zoom.resultset.get_facet_field">
1012     A single Facet field  is returned by function
1013     <function>ZOOM_resultset_get_facet_field</function> or
1014     <function>ZOOM_resultset_get_facet_field_by_index</function> that takes
1015     a  result set and facet name or positive index respectively. First
1016     facet has position zero. If no facet could be obtained (invalid name
1017     or index out of bounds) <literal>NULL</literal> is returned.
1018    </para>
1019    <para id="zoom.resultset.facets">
1020     An array of facets field can be returned by
1021     <function>ZOOM_resultset_facets</function>. The length of the array is
1022     given by <function>ZOOM_resultset_facets_size</function>. The array is
1023     zero-based and last entry will be at
1024     <function>ZOOM_resultset_facets_size(result_set)</function>-1.
1025    </para>
1026    <para id="zoom.resultset.facets_names">
1027     It is possible to interate over facets by name, by calling
1028     <function>ZOOM_resultset_facets_names</function>.
1029     This will return an const array of char * where each string can be used
1030     as parameter for <function>ZOOM_resultset_get_facet_field</function>.
1031    </para>
1032    <para>
1033    Function <function>ZOOM_facet_field_name</function> gets the request
1034     facet name from a returned facet field.
1035    </para>
1036    <para>
1037     Function <function>ZOOM_facet_field_get_term</function> returns the
1038     idx'th term and term count for a facet field.
1039     Idx must between 0 and
1040     <function>ZOOM_facet_field_term_count</function>-1, otherwise the
1041     returned reference will be <literal>NULL</literal>. On a valid idx, the
1042     value of the freq reference will be the term count.
1043     The <literal>freq</literal> parameter must be valid pointer to integer.
1044    </para>
1045    </sect1>
1046   <sect1 id="zoom.scan"><title>Scan</title>
1047    <para>
1048     This section describes an interface for Scan. Scan is not an
1049     official part of the ZOOM model yet. The result of a scan operation
1050     is the <literal>ZOOM_scanset</literal> which is a set of terms
1051     returned by a target.
1052    </para>
1053
1054    <para>
1055     The Scan interface is supported for both Z39.50, SRU (and SOLR?).
1056    </para>
1057
1058    <synopsis>
1059     ZOOM_scanset ZOOM_connection_scan(ZOOM_connection c,
1060                                       const char *startpqf);
1061
1062     ZOOM_scanset ZOOM_connection_scan1(ZOOM_connection c,
1063                                        ZOOM_query q);
1064
1065     size_t ZOOM_scanset_size(ZOOM_scanset scan);
1066
1067     const char *ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
1068                                   size_t *occ, size_t *len);
1069
1070     const char *ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
1071                                           size_t *occ, size_t *len);
1072
1073     void ZOOM_scanset_destroy(ZOOM_scanset scan);
1074
1075     const char *ZOOM_scanset_option_get(ZOOM_scanset scan,
1076                                         const char *key);
1077
1078     void ZOOM_scanset_option_set(ZOOM_scanset scan, const char *key,
1079                                  const char *val);
1080     </synopsis>
1081    <para>
1082     The scan set is created by function
1083     <function>ZOOM_connection_scan</function> which performs a scan
1084     operation on the connection using the specified
1085     <parameter>startpqf</parameter>.
1086     If the operation was successful, the size of the scan set can be
1087     retrieved by a call to <function>ZOOM_scanset_size</function>.
1088     Like result sets, the items are numbered 0,..size-1.
1089     To obtain information about a particular scan term, call function
1090     <function>ZOOM_scanset_term</function>. This function takes
1091     a scan set offset <literal>pos</literal> and returns a pointer
1092     to a <emphasis>raw term</emphasis> or <literal>NULL</literal> if
1093     non-present.
1094     If present, the <literal>occ</literal> and <literal>len</literal>
1095     are set to the number of occurrences and the length
1096     of the actual term respectively.
1097     <function>ZOOM_scanset_display_term</function> is similar to
1098     <function>ZOOM_scanset_term</function> except that it returns
1099     the <emphasis>display term</emphasis> rather than the raw term.
1100     In a few cases, the term is different from display term. Always
1101     use the display term for display and the raw term for subsequent
1102     scan operations (to get more terms, next scan result, etc).
1103    </para>
1104    <para>
1105     A scan set may be freed by a call to function
1106     <function>ZOOM_scanset_destroy</function>.
1107     Functions <function>ZOOM_scanset_option_get</function> and
1108     <function>ZOOM_scanset_option_set</function> retrieves and sets
1109     an option respectively.
1110    </para>
1111
1112    <para>
1113     The <parameter>startpqf</parameter> is a subset of PQF, namely
1114     the Attributes+Term part. Multiple <literal>@attr</literal> can
1115     be used. For example to scan in title (complete) phrases:
1116     <literallayout>
1117      @attr 1=4 @attr 6=2 "science o"
1118     </literallayout>
1119    </para>
1120
1121    <para>
1122     The <function>ZOOM_connecton_scan1</function> is a newer and
1123     more generic alternative to <function>ZOOM_connection_scan</function>
1124     which allows to use both CQL and PQF for Scan.
1125    </para>
1126
1127    <table frame="top" id="zoom.scanset.options">
1128     <title>ZOOM Scan Set Options</title>
1129     <tgroup cols="3">
1130      <colspec colwidth="4*" colname="name"></colspec>
1131      <colspec colwidth="7*" colname="description"></colspec>
1132      <colspec colwidth="2*" colname="default"></colspec>
1133      <thead>
1134       <row>
1135        <entry>Option</entry>
1136        <entry>Description</entry>
1137        <entry>Default</entry>
1138       </row>
1139      </thead>
1140      <tbody>
1141       <row><entry>
1142         number</entry><entry>Number of Scan Terms requested in next scan.
1143         After scan it holds the actual number of terms returned.
1144        </entry><entry>20</entry></row>
1145       <row><entry>
1146         position</entry><entry>Preferred Position of term in response
1147         in next scan; actual position after completion of scan.
1148        </entry><entry>1</entry></row>
1149       <row><entry>
1150         stepSize</entry><entry>Step Size
1151        </entry><entry>0</entry></row>
1152       <row><entry>
1153         scanStatus</entry><entry>An integer indicating the Scan Status
1154         of last scan.
1155        </entry><entry>0</entry></row>
1156       <row><entry>
1157         rpnCharset</entry><entry>Character set for RPN terms.
1158         If this is set, ZOOM C will assume that the ZOOM application is
1159         running UTF-8. Terms in RPN queries are then converted to the
1160         rpnCharset. If this is unset, ZOOM C will not assume any encoding
1161         of RPN terms and no conversion is performed.
1162        </entry><entry>none</entry></row>
1163      </tbody>
1164     </tgroup>
1165    </table>
1166   </sect1>
1167
1168   <sect1 id="zoom.extendedservices"><title>Extended Services</title>
1169    <para>
1170     ZOOM offers an interface to a subset of the Z39.50 extended services
1171     as well as a few privately defined ones:
1172    </para>
1173    <itemizedlist>
1174     <listitem>
1175      <para>
1176       Z39.50 Item Order (ILL).
1177       See <xref linkend="zoom.item.order"/>.
1178      </para>
1179     </listitem>
1180     <listitem>
1181      <para>
1182       Record Update. This allows a client to insert, modify or delete
1183       records.
1184       See <xref linkend="zoom.record.update"/>.
1185      </para>
1186     </listitem>
1187     <listitem>
1188      <para>
1189       Database Create. This a non-standard feature. Allows a client
1190       to create a database.
1191       See <xref linkend="zoom.database.create"/>.
1192      </para>
1193     </listitem>
1194     <listitem>
1195      <para>
1196       Database Drop. This a non-standard feature. Allows a client
1197       to delete/drop a database.
1198       See <xref linkend="zoom.database.drop"/>.
1199      </para>
1200      </listitem>
1201     <listitem>
1202      <para>
1203       Commit operation. This a non-standard feature. Allows a client
1204       to commit operations.
1205       See <xref linkend="zoom.commit"/>.
1206      </para>
1207     </listitem>
1208     <!-- all the ILL PDU options should go here too -->
1209    </itemizedlist>
1210    <para>
1211     To create an extended service operation a <literal>ZOOM_package</literal>
1212     must be created. The operation is a five step operation. The
1213     package is created, package is configured by means of options,
1214     the package is send, result is inspected (by means of options),
1215     the package is destroyed.
1216    </para>
1217    <synopsis>
1218     ZOOM_package ZOOM_connection_package(ZOOM_connection c,
1219                                          ZOOM_options options);
1220
1221     const char *ZOOM_package_option_get(ZOOM_package p,
1222                                         const char *key);
1223     void ZOOM_package_option_set(ZOOM_package p, const char *key,
1224                                  const char *val);
1225     void ZOOM_package_send(ZOOM_package p, const char *type);
1226
1227     void ZOOM_package_destroy(ZOOM_package p);
1228    </synopsis>
1229    <para>
1230     The <function>ZOOM_connection_package</function> creates a
1231     package for the connection given using the options specified.
1232    </para>
1233    <para>
1234     Functions <function>ZOOM_package_option_get</function> and
1235     <function>ZOOM_package_option_set</function> gets and sets
1236     options.
1237    </para>
1238    <para>
1239     <function>ZOOM_package_send</function> sends
1240     the package the via connection specified in
1241     <function>ZOOM_connection_package</function>.
1242     The <parameter>type</parameter> specifies the actual extended service
1243     package type to be sent.
1244    </para>
1245
1246    <table frame="top" id="zoom.extendedservices.options">
1247     <title>Extended Service Common Options</title>
1248     <tgroup cols="3">
1249      <colspec colwidth="4*" colname="name"></colspec>
1250      <colspec colwidth="7*" colname="description"></colspec>
1251      <colspec colwidth="3*" colname="default"></colspec>
1252      <thead>
1253       <row>
1254        <entry>Option</entry>
1255        <entry>Description</entry>
1256        <entry>Default</entry>
1257       </row>
1258      </thead>
1259      <tbody>
1260       <row>
1261        <entry>package-name</entry>
1262        <entry>Extended Service Request package name. Must be specified
1263        as part of a request</entry>
1264        <entry>none</entry>
1265       </row>
1266       <row>
1267        <entry>user-id</entry>
1268        <entry>User ID of Extended Service Package. Is a request option</entry>
1269        <entry>none</entry>
1270       </row>
1271       <row>
1272        <entry>function</entry>
1273        <entry>
1274         Function of package - one of <literal>create</literal>,
1275         <literal>delete</literal>, <literal>modify</literal>. Is
1276         a request option.
1277        </entry>
1278        <entry><literal>create</literal></entry>
1279       </row>
1280       <row>
1281        <entry>waitAction</entry>
1282        <entry>
1283         Wait action for package. Possible values:
1284         <literal>wait</literal>, <literal>waitIfPossible</literal>,
1285         <literal>dontWait</literal> or <literal>dontReturnPackage</literal>.
1286        </entry>
1287        <entry><literal>waitIfPossible</literal></entry>
1288       </row>
1289       <row>
1290        <entry>targetReference</entry>
1291        <entry>
1292         Target Reference. This is part of the response as returned
1293         by the server. Read it after a successful operation.
1294        </entry>
1295        <entry><literal>none</literal></entry>
1296       </row>
1297      </tbody>
1298     </tgroup>
1299    </table>
1300
1301    <sect2 id="zoom.item.order"><title>Item Order</title>
1302     <para>
1303      For Item Order, type must be set to <literal>itemorder</literal> in
1304      <function>ZOOM_package_send</function>.
1305     </para>
1306
1307     <table frame="top" id="zoom.item.order.options">
1308      <title>Item Order Options</title>
1309      <tgroup cols="3">
1310       <colspec colwidth="4*" colname="name"></colspec>
1311       <colspec colwidth="7*" colname="description"></colspec>
1312       <colspec colwidth="3*" colname="default"></colspec>
1313       <thead>
1314        <row>
1315         <entry>Option</entry>
1316         <entry>Description</entry>
1317         <entry>Default</entry>
1318        </row>
1319       </thead>
1320       <tbody>
1321        <row>
1322         <entry>contact-name</entry>
1323         <entry>ILL contact name</entry>
1324         <entry>none</entry>
1325        </row>
1326        <row>
1327         <entry>contact-phone</entry>
1328         <entry>ILL contact phone</entry>
1329         <entry>none</entry>
1330        </row>
1331        <row>
1332         <entry>contact-email</entry>
1333         <entry>ILL contact email</entry>
1334         <entry>none</entry>
1335        </row>
1336        <row>
1337         <entry>itemorder-item</entry>
1338         <entry>Position for item (record) requested. An integer</entry>
1339         <entry>1</entry>
1340        </row>
1341       </tbody>
1342      </tgroup>
1343     </table>
1344
1345    </sect2>
1346
1347    <sect2 id="zoom.record.update"><title>Record Update</title>
1348     <para>
1349      For Record Update, type must be set to <literal>update</literal> in
1350      <function>ZOOM_package_send</function>.
1351     </para>
1352
1353     <table frame="top" id="zoom.record.update.options">
1354      <title>Record Update Options</title>
1355      <tgroup cols="3">
1356       <colspec colwidth="4*" colname="name"></colspec>
1357       <colspec colwidth="7*" colname="description"></colspec>
1358       <colspec colwidth="3*" colname="default"></colspec>
1359       <thead>
1360        <row>
1361         <entry>Option</entry>
1362         <entry>Description</entry>
1363         <entry>Default</entry>
1364        </row>
1365       </thead>
1366       <tbody>
1367        <row>
1368         <entry>action</entry>
1369         <entry>
1370          The update action. One of
1371          <literal>specialUpdate</literal>,
1372          <literal>recordInsert</literal>,
1373          <literal>recordReplace</literal>,
1374          <literal>recordDelete</literal>,
1375          <literal>elementUpdate</literal>.
1376         </entry>
1377         <entry><literal>specialUpdate (recordInsert for updateVersion=1 which does not support specialUpdate)</literal></entry>
1378        </row>
1379        <row>
1380         <entry>recordIdOpaque</entry>
1381         <entry>Opaque Record ID</entry>
1382         <entry>none</entry>
1383        </row>
1384        <row>
1385         <entry>recordIdNumber</entry>
1386         <entry>Record ID number</entry>
1387         <entry>none</entry>
1388        </row>
1389        <row>
1390         <entry>record</entry>
1391         <entry>The record itself</entry>
1392         <entry>none</entry>
1393        </row>
1394        <row>
1395         <entry>recordOpaque</entry>
1396         <entry>Specifies an opaque record which is
1397           encoded as an ASN.1 ANY type with the OID as tiven by option
1398           <literal>syntax</literal> (see below).
1399           Option <literal>recordOpaque</literal> is an alternative
1400           to record - and <literal>record</literal> option (above) is
1401           ignored if recordOpaque is set. This option is only available in
1402           YAZ 3.0.35 and later and is meant to facilitate Updates with
1403           servers from OCLC.
1404         </entry>
1405         <entry>none</entry>
1406        </row>
1407        <row>
1408         <entry>syntax</entry>
1409         <entry>The record syntax (transfer syntax). Is a string that
1410          is a known record syntax.
1411         </entry>
1412         <entry>no syntax</entry>
1413        </row>
1414        <row>
1415         <entry>databaseName</entry>
1416         <entry>Database from connection object</entry>
1417         <entry>Default</entry>
1418        </row>
1419        <row>
1420         <entry>correlationInfo.note</entry>
1421         <entry>Correlation Info Note (string)</entry>
1422         <entry>none</entry>
1423        </row>
1424        <row>
1425         <entry>correlationInfo.id</entry>
1426         <entry>Correlation Info ID (integer)</entry>
1427         <entry>none</entry>
1428        </row>
1429        <row>
1430         <entry>elementSetName</entry>
1431         <entry>Element Set for Record</entry>
1432         <entry>none</entry>
1433        </row>
1434        <row>
1435         <entry>updateVersion</entry>
1436         <entry>Record Update version which holds one of the values
1437          1, 2 or 3. Each version has a distinct OID:
1438          1.2.840.10003.9.5
1439          (<ulink url="&url.z39.50.extupdate1;">first version</ulink>) ,
1440          1.2.840.10003.9.5.1
1441          (second version) and
1442          1.2.840.10003.9.5.1.1
1443          (<ulink url="&url.z39.50.extupdate3;">third and
1444           newest version</ulink>).
1445         </entry>
1446         <entry>3</entry>
1447        </row>
1448       </tbody>
1449      </tgroup>
1450     </table>
1451
1452    </sect2>
1453
1454    <sect2 id="zoom.database.create"><title>Database Create</title>
1455     <para>
1456      For Database Create, type must be set to <literal>create</literal> in
1457      <function>ZOOM_package_send</function>.
1458     </para>
1459
1460     <table frame="top" id="zoom.database.create.options">
1461      <title>Database Create Options</title>
1462      <tgroup cols="3">
1463       <colspec colwidth="4*" colname="name"></colspec>
1464       <colspec colwidth="7*" colname="description"></colspec>
1465       <colspec colwidth="3*" colname="default"></colspec>
1466       <thead>
1467        <row>
1468         <entry>Option</entry>
1469         <entry>Description</entry>
1470         <entry>Default</entry>
1471        </row>
1472       </thead>
1473       <tbody>
1474        <row>
1475         <entry>databaseName</entry>
1476         <entry>Database from connection object</entry>
1477         <entry>Default</entry>
1478        </row>
1479       </tbody>
1480      </tgroup>
1481     </table>
1482    </sect2>
1483
1484    <sect2 id="zoom.database.drop"><title>Database Drop</title>
1485     <para>
1486      For Database Drop, type must be set to <literal>drop</literal> in
1487      <function>ZOOM_package_send</function>.
1488     </para>
1489
1490     <table frame="top" id="zoom.database.drop.options">
1491      <title>Database Drop Options</title>
1492      <tgroup cols="3">
1493       <colspec colwidth="4*" colname="name"></colspec>
1494       <colspec colwidth="7*" colname="description"></colspec>
1495       <colspec colwidth="3*" colname="default"></colspec>
1496       <thead>
1497        <row>
1498         <entry>Option</entry>
1499         <entry>Description</entry>
1500         <entry>Default</entry>
1501        </row>
1502       </thead>
1503       <tbody>
1504        <row>
1505         <entry>databaseName</entry>
1506         <entry>Database from connection object</entry>
1507         <entry>Default</entry>
1508        </row>
1509       </tbody>
1510      </tgroup>
1511     </table>
1512    </sect2>
1513
1514    <sect2 id="zoom.commit"><title>Commit Operation</title>
1515     <para>
1516      For Commit, type must be set to <literal>commit</literal> in
1517      <function>ZOOM_package_send</function>.
1518     </para>
1519    </sect2>
1520
1521    <sect2 id="zoom.extended.services.behavior">
1522     <title>Protocol behavior</title>
1523     <para>
1524      All the extended services are Z39.50-only.
1525     </para>
1526     <note>
1527      <para>
1528       The database create, drop and commit services are privately defined
1529       operations.
1530       Refer to <filename>esadmin.asn</filename> in YAZ for the ASN.1
1531       definitions.
1532      </para>
1533     </note>
1534    </sect2>
1535   </sect1>
1536
1537   <sect1 id="zoom.options"><title>Options</title>
1538    <para>
1539     Most &zoom; objects provide a way to specify options to change behavior.
1540     From an implementation point of view a set of options is just like
1541     an associative array / hash.
1542    </para>
1543    <synopsis>
1544      ZOOM_options ZOOM_options_create(void);
1545
1546      ZOOM_options ZOOM_options_create_with_parent(ZOOM_options parent);
1547
1548      void ZOOM_options_destroy(ZOOM_options opt);
1549    </synopsis>
1550    <synopsis>
1551      const char *ZOOM_options_get(ZOOM_options opt, const char *name);
1552
1553      void ZOOM_options_set(ZOOM_options opt, const char *name,
1554                            const char *v);
1555    </synopsis>
1556    <synopsis>
1557      typedef const char *(*ZOOM_options_callback)
1558                             (void *handle, const char *name);
1559
1560      ZOOM_options_callback
1561              ZOOM_options_set_callback(ZOOM_options opt,
1562                                        ZOOM_options_callback c,
1563                                        void *handle);
1564    </synopsis>
1565   </sect1>
1566   <sect1 id="zoom.events"><title>Events</title>
1567    <para>
1568     If you're developing non-blocking applications, you have to deal
1569     with events.
1570    </para>
1571    <synopsis>
1572     int ZOOM_event(int no, ZOOM_connection *cs);
1573    </synopsis>
1574    <para>
1575     The <function>ZOOM_event</function> executes pending events for
1576     a number of connections. Supply the number of connections in
1577     <literal>no</literal> and an array of connections in
1578     <literal>cs</literal> (<literal>cs[0] ... cs[no-1]</literal>).
1579     A pending event could be a sending a search, receiving a response,
1580     etc.
1581     When an event has occurred for one of the connections, this function
1582     returns a positive integer <literal>n</literal> denoting that an event
1583     occurred for connection <literal>cs[n-1]</literal>.
1584     When no events are pending for the connections, a value of zero is
1585     returned.
1586     To ensure that all outstanding requests are performed call this function
1587     repeatedly until zero is returned.
1588    </para>
1589    <para>
1590     If <function>ZOOM_event</function> returns and returns non-zero, the
1591     last event that occurred can be expected.
1592    </para>
1593    <synopsis>
1594     int ZOOM_connection_last_event(ZOOM_connection cs);
1595    </synopsis>
1596    <para>
1597     <function>ZOOM_connection_last_event</function> returns an event type
1598     (integer) for the last event.
1599    </para>
1600
1601    <table frame="top" id="zoom.event.ids">
1602     <title>ZOOM Event IDs</title>
1603     <tgroup cols="2">
1604      <colspec colwidth="4*" colname="name"></colspec>
1605      <colspec colwidth="7*" colname="description"></colspec>
1606      <thead>
1607       <row>
1608        <entry>Event</entry>
1609        <entry>Description</entry>
1610       </row>
1611      </thead>
1612      <tbody>
1613       <row>
1614        <entry>ZOOM_EVENT_NONE</entry>
1615        <entry>No event has occurred</entry>
1616       </row>
1617       <row>
1618        <entry>ZOOM_EVENT_CONNECT</entry>
1619        <entry>TCP/IP connect has initiated</entry>
1620       </row>
1621       <row>
1622        <entry>ZOOM_EVENT_SEND_DATA</entry>
1623        <entry>Data has been transmitted (sending)</entry>
1624       </row>
1625       <row>
1626        <entry>ZOOM_EVENT_RECV_DATA</entry>
1627        <entry>Data has been received)</entry>
1628       </row>
1629       <row>
1630        <entry>ZOOM_EVENT_TIMEOUT</entry>
1631        <entry>Timeout</entry>
1632       </row>
1633       <row>
1634        <entry>ZOOM_EVENT_UNKNOWN</entry>
1635        <entry>Unknown event</entry>
1636       </row>
1637       <row>
1638        <entry>ZOOM_EVENT_SEND_APDU</entry>
1639        <entry>An APDU has been transmitted (sending)</entry>
1640       </row>
1641       <row>
1642        <entry>ZOOM_EVENT_RECV_APDU</entry>
1643        <entry>An APDU has been received</entry>
1644       </row>
1645       <row>
1646        <entry>ZOOM_EVENT_RECV_RECORD</entry>
1647        <entry>A result-set record has been received</entry>
1648       </row>
1649       <row>
1650        <entry>ZOOM_EVENT_RECV_SEARCH</entry>
1651        <entry>A search result been received</entry>
1652       </row>
1653      </tbody>
1654     </tgroup>
1655    </table>
1656   </sect1>
1657  </chapter>
1658
1659  <!-- Keep this comment at the end of the file
1660  Local variables:
1661  mode: sgml
1662  sgml-omittag:t
1663  sgml-shorttag:t
1664  sgml-minimize-attributes:nil
1665  sgml-always-quote-attributes:t
1666  sgml-indent-step:1
1667  sgml-indent-data:t
1668  sgml-parent-document: "yaz.xml"
1669  sgml-local-catalogs: nil
1670  sgml-namecase-general:t
1671  End:
1672  -->
1673