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