Update cql.y for newer bison YAZ-720
[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         authenticationMode</entry><entry>How authentication is encoded.
194        </entry><entry>basic</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
397      Inititialize Request, so  the connection phase merely establishes a
398      TCP/IP connection with the HTTP server.
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     <para>
410      Setting <literal>authentcationMode</literal> specifies how
411      authentication parameters are encoded for HTTP. The default is
412      "<literal>basic</literal>" where <literal>user</literal> and
413      <literal>password</literal> are encoded by using HTTP basic
414      authentication.
415      </para>
416     <para>
417      If <literal>authentcationMode</literal> is "<literal>url</literal>", then
418      user and password are encoded in the URL by parameters
419      <literal>x-username</literal> and <literal>x-password</literal> as
420      given by the SRU standard.
421     </para>
422    </sect2>
423   </sect1>
424   <sect1 id="zoom.query"><title>Queries</title>
425    <para>
426     Query objects represents queries.
427    </para>
428    <synopsis>
429      ZOOM_query ZOOM_query_create(void);
430
431      void ZOOM_query_destroy(ZOOM_query q);
432
433      int ZOOM_query_prefix(ZOOM_query q, const char *str);
434
435      int ZOOM_query_cql(ZOOM_query s, const char *str);
436
437      int ZOOM_query_sortby(ZOOM_query q, const char *criteria);
438
439      int ZOOM_query_sortby2(ZOOM_query q, const char *strategy,
440                             const char *criteria);
441    </synopsis>
442    <para>
443     Create query objects using <function>ZOOM_query_create</function>
444     and destroy them by calling <function>ZOOM_query_destroy</function>.
445     RPN-queries can be specified in <link linkend="PQF">PQF</link>
446     notation by using the
447     function <function>ZOOM_query_prefix</function>.
448     The <function>ZOOM_query_cql</function> specifies a CQL
449     query to be sent to the server/target.
450     More query types will be added in future versions of &yaz;, such as
451     <link linkend="CCL">CCL</link> to RPN-mapping, native CCL query,
452     etc. In addition to a search, a sort criteria may be set. Function
453     <function>ZOOM_query_sortby</function> enables Z39.50 sorting and
454     it takes sort criteria using the same string notation as
455     yaz-client's <link linkend="sortspec">sort command</link>.
456    </para>
457    <para id="zoom.query.sortby2">
458     <function>ZOOM_query_sortby2</function> is similar to
459     <function>ZOOM_query_sortby</function> but allows a strategy for
460     sorting. The reason for the strategy parameter is that some
461     protocols offers multiple ways of performing sorting.
462     For example, Z39.50 has the standard sort, which is performed after
463     search on an existing result set.
464     It's also possible to use CQL in Z39.50 as the query type and use
465     CQL's SORTBY keyword. Finally, Index Data's
466     Zebra server also allows sorting to be specified as part of RPN (Type 7).
467    </para>
468    <table id="zoom-sort-strategy" frame="top">
469     <title>ZOOM sort strategy</title>
470     <tgroup cols="2">
471      <colspec colwidth="2*" colname="name"/>
472      <colspec colwidth="5*" colname="description"/>
473      <thead>
474       <row>
475        <entry>Name</entry>
476        <entry>Description</entry>
477       </row>
478      </thead>
479      <tbody>
480       <row>
481        <entry>z39.50</entry><entry>Z39.50 resultset sort</entry>
482       </row>
483       <row>
484        <entry>type7</entry><entry>Sorting embedded in RPN(Type-7)</entry>
485       </row>
486       <row>
487        <entry>cql</entry><entry>CQL SORTBY</entry>
488       </row>
489       <row>
490        <entry>sru11</entry><entry>SRU sortKeys parameter</entry>
491       </row>
492       <row>
493        <entry>solr</entry><entry>Solr sort</entry>
494       </row>
495       <row>
496        <entry>embed</entry><entry>type7 for Z39.50, cql for SRU,
497         solr for Solr protocol</entry>
498       </row>
499      </tbody>
500     </tgroup>
501    </table>
502   </sect1>
503   <sect1 id="zoom.resultsets"><title>Result sets</title>
504    <para>
505     The result set object is a container for records returned from
506     a target.
507    </para>
508    <synopsis>
509      ZOOM_resultset ZOOM_connection_search(ZOOM_connection, ZOOM_query q);
510
511      ZOOM_resultset ZOOM_connection_search_pqf(ZOOM_connection c,
512                                                const char *q);
513      void ZOOM_resultset_destroy(ZOOM_resultset r);
514    </synopsis>
515    <para>
516     Function <function>ZOOM_connection_search</function> creates
517     a result set given a connection and query.
518     Destroy a result set by calling
519     <function>ZOOM_resultset_destroy</function>.
520     Simple clients may using PQF only may use function
521     <function>ZOOM_connection_search_pqf</function> in which case
522     creating query objects is not necessary.
523    </para>
524    <synopsis>
525      void ZOOM_resultset_option_set(ZOOM_resultset r,
526                                     const char *key, const char *val);
527
528      const char *ZOOM_resultset_option_get(ZOOM_resultset r, const char *key);
529
530      size_t ZOOM_resultset_size(ZOOM_resultset r);
531    </synopsis>
532    <para>
533     Functions <function>ZOOM_resultset_options_set</function> and
534     <function>ZOOM_resultset_get</function> sets and gets an option
535     for a result set similar to <function>ZOOM_connection_option_get</function>
536     and <function>ZOOM_connection_option_set</function>.
537    </para>
538    <para>
539     The number of hits also called result-count is returned by
540     function <function>ZOOM_resultset_size</function>.
541    </para>
542    <table id="zoom.resultset.options"
543     frame="top"><title>ZOOM Result set Options</title>
544     <tgroup cols="3">
545      <colspec colwidth="4*" colname="name"></colspec>
546      <colspec colwidth="7*" colname="description"></colspec>
547      <colspec colwidth="2*" colname="default"></colspec>
548      <thead>
549       <row>
550        <entry>Option</entry>
551        <entry>Description</entry>
552        <entry>Default</entry>
553       </row>
554      </thead>
555      <tbody>
556       <row><entry>
557         start</entry><entry>Offset of first record to be
558         retrieved from target. First record has offset 0 unlike the
559         protocol specifications where first record has position 1.
560         This option affects ZOOM_resultset_search and
561         ZOOM_resultset_search_pqf and must be set before any of
562         these functions are invoked. If a range of
563         records must be fetched manually after search,
564         function ZOOM_resultset_records should be used.
565        </entry><entry>0</entry></row>
566       <row><entry>
567         count</entry><entry>Number of records to be retrieved.
568         This option affects ZOOM_resultset_search and
569         ZOOM_resultset_search_pqf and must be set before any of
570         these functions are invoked.
571        </entry><entry>0</entry></row>
572       <row><entry>
573         presentChunk</entry><entry>The number of records to be
574         requested from the server in each chunk (present request). The
575         value 0 means to request all the records in a single chunk.
576         (The old <literal>step</literal>
577         option is also supported for the benefit of old applications.)
578        </entry><entry>0</entry></row>
579       <row><entry>
580         elementSetName</entry><entry>Element-Set name of records.
581         Most targets should honor element set name <literal>B</literal>
582         and <literal>F</literal> for brief and full respectively.
583        </entry><entry>none</entry></row>
584       <row><entry>
585         preferredRecordSyntax</entry><entry>Preferred Syntax, such as
586         <literal>USMARC</literal>, <literal>SUTRS</literal>, etc.
587        </entry><entry>none</entry></row>
588       <row><entry>
589         schema</entry><entry>Schema for retrieval, such as
590         <literal>Gils-schema</literal>, <literal>Geo-schema</literal>, etc.
591        </entry><entry>none</entry></row>
592       <row><entry>
593         setname</entry><entry>Name of Result Set (Result Set ID).
594         If this option isn't set, the ZOOM module will automatically
595         allocate a result set name.
596        </entry><entry>default</entry></row>
597       <row><entry>
598         rpnCharset</entry><entry>Character set for RPN terms.
599         If this is set, ZOOM C will assume that the ZOOM application is
600         running UTF-8. Terms in RPN queries are then converted to the
601         rpnCharset. If this is unset, ZOOM C will not assume any encoding
602         of RPN terms and no conversion is performed.
603        </entry><entry>none</entry></row>
604      </tbody>
605     </tgroup>
606    </table>
607    <para>
608     For servers that support Search Info report, the following
609     options may be read using <function>ZOOM_resultset_get</function>.
610     This detailed information is read after a successful search has
611     completed.
612    </para>
613    <para>
614     This information is a list of of items, where each item is
615     information about a term or subquery. All items in the list
616     are prefixed by
617     <literal>SearchResult.</literal><replaceable>no</replaceable>
618     where no presents the item number (0=first, 1=second).
619     Read <literal>searchresult.size</literal> to determine the
620     number of items.
621    </para>
622    <table id="zoom.search.info.report.options"
623     frame="top"><title>Search Info Report Options</title>
624     <tgroup cols="2">
625      <colspec colwidth="4*" colname="name"></colspec>
626      <colspec colwidth="7*" colname="description"></colspec>
627      <thead>
628       <row>
629        <entry>Option</entry>
630        <entry>Description</entry>
631       </row>
632      </thead>
633      <tbody>
634       <row>
635        <entry>searchresult.size</entry>
636        <entry>
637         number of search result entries. This option is-nonexistant
638         if no entries are returned by the server.
639        </entry>
640       </row>
641       <row>
642        <entry>searchresult.<replaceable>no</replaceable>.id</entry>
643        <entry>sub query ID</entry>
644       </row>
645       <row>
646        <entry>searchresult.<replaceable>no</replaceable>.count</entry>
647        <entry>result count for item (number of hits)</entry>
648       </row>
649       <row>
650        <entry>searchresult.<replaceable>no</replaceable>.subquery.term</entry>
651        <entry>subquery term</entry>
652       </row>
653       <row>
654        <entry>
655         searchresult.<replaceable>no</replaceable>.interpretation.term
656        </entry>
657        <entry>interpretation term</entry>
658       </row>
659       <row>
660        <entry>
661         searchresult.<replaceable>no</replaceable>.recommendation.term
662        </entry>
663        <entry>recommendation term</entry>
664       </row>
665      </tbody>
666     </tgroup>
667    </table>
668
669    <sect2 id="zoom.z3950.resultset.sort">
670     <title>Z39.50 Result-set Sort</title>
671     <synopsis>
672      void ZOOM_resultset_sort(ZOOM_resultset r,
673                               const char *sort_type, const char *sort_spec);
674
675      int ZOOM_resultset_sort1(ZOOM_resultset r,
676                               const char *sort_type, const char *sort_spec);
677     </synopsis>
678     <para>
679      <function>ZOOM_resultset_sort</function> and
680      <function>ZOOM_resultset_sort1</function> both sort an existing
681      result-set. The sort_type parameter is not use. Set it to "yaz".
682      The sort_spec is same notation as ZOOM_query_sortby and identical
683      to that offered by yaz-client's
684      <link linkend="sortspec">sort command</link>.
685     </para>
686     <para>
687      These functions only work for Z39.50. Use the more generic utility
688      <link linkend="zoom.query.sortby2">
689       <function>ZOOM_query_sortby2</function></link>
690      for other protocols (and even Z39.50).
691     </para>
692    </sect2>
693    <sect2 id="zoom.z3950.resultset.behavior">
694     <title>Z39.50 Protocol behavior</title>
695     <para>
696      The creation of a result set involves at least a SearchRequest
697      - SearchResponse protocol handshake. Following that, if a sort
698      criteria was specified as part of the query, a SortRequest -
699      SortResponse handshake takes place. Note that it is necessary to
700      perform sorting before any retrieval takes place, so no records will
701      be returned from the target as part of the SearchResponse because these
702      would be unsorted. Hence, piggyback is disabled when sort criteria
703      are set. Following Search - and a possible sort - Retrieval takes
704      place - as one or more Present Requests/Response pairs being
705      transferred.
706      </para>
707     <para>
708      The API allows for two different modes for retrieval. A high level
709      mode which is somewhat more powerful and a low level one.
710      The low level is enabled when searching on a Connection object
711      for which the settings
712      <literal>smallSetUpperBound</literal>,
713      <literal>mediumSetPresentNumber</literal> and
714      <literal>largeSetLowerBound</literal> are set. The low level mode
715      thus allows you to precisely set how records are returned as part
716      of a search response as offered by the Z39.50 protocol.
717      Since the client may be retrieving records as part of the
718      search response, this mode doesn't work well if sorting is used.
719      </para>
720     <para>
721      The high-level mode allows you to fetch a range of records from
722      the result set with a given start offset. When you use this mode
723      the client will automatically use piggyback if that is possible
724      with the target and perform one or more present requests as needed.
725      Even if the target returns fewer records as part of a present response
726      because of a record size limit, etc. the client will repeat sending
727      present requests. As an example, if option <literal>start</literal>
728      is 0 (default) and <literal>count</literal> is 4, and
729      <literal>piggyback</literal> is 1 (default) and no sorting criteria
730      is specified, then the client will attempt to retrieve the 4
731      records as part the search response (using piggyback). On the other
732      hand, if either <literal>start</literal> is positive or if
733      a sorting criteria is set, or if <literal>piggyback</literal>
734      is 0, then the client will not perform piggyback but send Present
735      Requests instead.
736     </para>
737     <para>
738      If either of the options <literal>mediumSetElementSetName</literal> and
739      <literal>smallSetElementSetName</literal> are unset, the value
740      of option <literal>elementSetName</literal> is used for piggyback
741      searches. This means that for the high-level mode you only have
742      to specify one elementSetName option rather than three.
743      </para>
744    </sect2>
745    <sect2 id="zoom.sru.resultset.behavior">
746     <title>SRU Protocol behavior</title>
747     <para>
748      Current version of &yaz; does not take advantage of a result set id
749      returned by the SRU server. Future versions might do, however.
750      Since, the ZOOM driver does not save result set IDs any
751      present (retrieval) is transformed to a SRU SearchRetrieveRequest
752      with same query but, possibly, different offsets.
753     </para>
754     <para>
755      Option <literal>schema</literal> specifies SRU schema
756      for retrieval. However, options <literal>elementSetName</literal> and
757      <literal>preferredRecordSyntax</literal> are ignored.
758     </para>
759     <para>
760      Options <literal>start</literal> and <literal>count</literal>
761      are supported by SRU.
762      The remaining options
763      <literal>piggyback</literal>,
764      <literal>smallSetUpperBound</literal>,
765      <literal>largeSetLowerBound</literal>,
766      <literal>mediumSetPresentNumber</literal>,
767      <literal>mediumSetElementSetName</literal>,
768       <literal>smallSetElementSetName</literal> are
769      unsupported.
770     </para>
771     <para>
772      SRU supports CQL queries, <emphasis>not</emphasis> PQF.
773      If PQF is used, however, the PQF query is transferred anyway
774      using non-standard element <literal>pQuery</literal> in
775      SRU SearchRetrieveRequest.
776     </para>
777     <para>
778      Solr queries has to be done in Solr query format.
779     </para>
780     <para>
781      Unfortunately, SRU or Solr does not define a database setting. Hence,
782      <literal>databaseName</literal> is unsupported and ignored.
783      However, the path part in host parameter for functions
784      <function>ZOOM_connecton_new</function> and
785      <function>ZOOM_connection_connect</function> acts as a
786      database (at least for the &yaz; SRU server).
787     </para>
788    </sect2>
789   </sect1>
790   <sect1 id="zoom.records"><title>Records</title>
791    <para>
792     A record object is a retrieval record on the client side -
793     created from result sets.
794    </para>
795    <synopsis>
796      void ZOOM_resultset_records(ZOOM_resultset r,
797                                  ZOOM_record *recs,
798                                  size_t start, size_t count);
799      ZOOM_record ZOOM_resultset_record(ZOOM_resultset s, size_t pos);
800
801      const char *ZOOM_record_get(ZOOM_record rec, const char *type,
802                                  size_t *len);
803
804      int ZOOM_record_error(ZOOM_record rec, const char **msg,
805                            const char **addinfo, const char **diagset);
806
807      ZOOM_record ZOOM_record_clone(ZOOM_record rec);
808
809      void ZOOM_record_destroy(ZOOM_record rec);
810    </synopsis>
811    <para>
812     References to temporary records are returned by functions
813     <function>ZOOM_resultset_records</function> or
814     <function>ZOOM_resultset_record</function>.
815     </para>
816    <para>
817     If a persistent reference to a record is desired
818     <function>ZOOM_record_clone</function> should be used.
819     It returns a record reference that should be destroyed
820     by a call to <function>ZOOM_record_destroy</function>.
821    </para>
822    <para>
823     A single record is returned by function
824     <function>ZOOM_resultset_record</function> that takes a
825     position as argument. First record has position zero.
826     If no record could be obtained <literal>NULL</literal> is returned.
827    </para>
828    <para>
829     Error information for a record can be checked with
830     <function>ZOOM_record_error</function> which returns non-zero
831     (error code) if record is in error, called <emphasis>Surrogate
832      Diagnostics</emphasis> in Z39.50.
833    </para>
834    <para>
835     Function <function>ZOOM_resultset_records</function> retrieves
836     a number of records from a result set. Parameter <literal>start</literal>
837     and <literal>count</literal> specifies the range of records to
838     be returned. Upon completion array
839     <literal>recs[0], ..recs[count-1]</literal>
840     holds record objects for the records. The array of records
841      <literal>recs</literal> should be allocated prior the call
842     <function>ZOOM_resultset_records</function>. Note that for those
843     records that couldn't be retrieved from the target
844     <literal>recs[ ..]</literal> is set to <literal>NULL</literal>.
845    </para>
846    <para id="zoom.record.get">
847     In order to extract information about a single record,
848     <function>ZOOM_record_get</function> is provided. The
849     function returns a pointer to certain record information. The
850     nature (type) of the pointer depends on the parameter,
851     <parameter>type</parameter>.
852    </para>
853    <para>
854     The <parameter>type</parameter> is a string of the format:
855    </para>
856    <para>
857     <replaceable>format</replaceable>[;charset=<replaceable>from</replaceable>[/<replaceable>opacfrom</replaceable>][,<replaceable>to</replaceable>]][;format=<replaceable>v</replaceable>]
858    </para>
859    <para>
860     where <replaceable>format</replaceable> specifies the format of the
861     returned record, <replaceable>from</replaceable>
862     specifies the character set of the record in its original form
863     (as returned by the server), <replaceable>to</replaceable> specifies
864     the output (returned)
865     character set encoding.
866     If <replaceable>to</replaceable> is omitted UTF-8 is assumed.
867     If charset is not given, then no character set conversion takes place.
868    </para>
869
870    <para>OPAC records may be returned in a different
871      set from the bibliographic MARC record. If this is this the case,
872     <replaceable>opacfrom</replaceable> should be set to the character set
873     of the OPAC record part.
874    </para>
875    <note>
876      <para>
877        Specifying the OPAC record character set requires YAZ 4.1.5 or later.
878      </para>
879    </note>
880    <para>
881     The format argument controls whether record data should be XML
882     pretty-printed (post process operation).
883     It is enabled only if format value <replaceable>v</replaceable> is
884     <literal>1</literal> and the record content is XML well-formed.
885    </para>
886    <para>
887     In addition, for certain types, the length
888     <literal>len</literal> passed will be set to the size in bytes of
889     the returned information.
890     </para>
891    <para>
892     The following are the supported values for <replaceable>form</replaceable>.
893     <variablelist>
894      <varlistentry><term><literal>database</literal></term>
895       <listitem><para>Database of record is returned
896         as a C null-terminated string. Return type
897         <literal>const char *</literal>.
898        </para></listitem>
899      </varlistentry>
900      <varlistentry><term><literal>syntax</literal></term>
901       <listitem><para>The transfer syntax of the record is returned
902         as a C null-terminated string containing the symbolic name of
903         the record syntax, e.g. <literal>Usmarc</literal>. Return type
904         is
905         <literal>const char *</literal>.
906        </para></listitem>
907      </varlistentry>
908      <varlistentry><term><literal>schema</literal></term>
909       <listitem><para>The schema of the record is returned
910         as a C null-terminated string. Return type is
911         <literal>const char *</literal>.
912        </para></listitem>
913      </varlistentry>
914      <varlistentry><term><literal>render</literal></term>
915       <listitem><para>The record is returned in a display friendly
916         format. Upon completion buffer is returned
917         (type <literal>const char *</literal>) and length is stored in
918         <literal>*len</literal>.
919        </para></listitem>
920      </varlistentry>
921      <varlistentry><term><literal>raw</literal></term>
922       <listitem><para>The record is returned in the internal
923         YAZ specific format. For GRS-1, Explain, and others, the
924         raw data is returned as type
925         <literal>Z_External *</literal> which is just the type for
926         the member <literal>retrievalRecord</literal> in
927         type <literal>NamePlusRecord</literal>.
928         For SUTRS and octet aligned record (including all MARCs) the
929         octet buffer is returned and the length of the buffer.
930        </para></listitem>
931      </varlistentry>
932      <varlistentry><term><literal>xml</literal></term>
933       <listitem><para>The record is returned in XML if possible.
934         SRU, Solr and Z39.50 records with transfer syntax XML are
935         returned verbatim. MARC records are returned in
936         <ulink url="&url.marcxml;">
937          MARCXML
938          </ulink>
939         (converted from ISO2709 to MARCXML by YAZ).
940         OPAC records are also converted to XML and the
941         bibliographic record is converted to MARCXML (when possible).
942         GRS-1 records are not supported for this form.
943         Upon completion, the XML buffer is returned
944         (type <literal>const char *</literal>) and length is stored in
945         <literal>*len</literal>.
946        </para></listitem>
947      </varlistentry>
948      <varlistentry><term><literal>opac</literal></term>
949       <listitem><para>OPAC information for record is returned in XML
950         if an OPAC record is present at the position given. If no
951         OPAC record is present, a NULL pointer is returned.
952        </para></listitem>
953      </varlistentry>
954      <varlistentry><term><literal>txml</literal></term>
955       <listitem><para>The record is returned in TurboMARC if possible.
956         SRU and Z39.50 records with transfer syntax XML are
957         returned verbatim. MARC records are returned in
958         <link linkend="tools.turbomarc">
959          TurboMARC
960         </link>
961         (converted from ISO2709 to TurboMARC by YAZ).
962         Upon completion, the XML buffer is returned
963         (type <literal>const char *</literal>) and length is stored in
964         <literal>*len</literal>.
965        </para></listitem>
966      </varlistentry>
967      <varlistentry><term><literal>json</literal></term>
968       <listitem><para>Like xml, but MARC records are converted to
969         <ulink url="&url.marc_in_json;">MARC-in-JSON</ulink>.
970        </para></listitem>
971      </varlistentry>
972
973     </variablelist>
974    </para>
975    <para>
976     Most
977     <ulink url="&url.marc21;">MARC21</ulink>
978     records uses the
979     <ulink url="&url.marc8;">MARC-8</ulink>
980     character set encoding.
981     An application that wishes to display in Latin-1 would use
982     <screen>
983      render; charset=marc8,iso-8859-1
984     </screen>
985    </para>
986    <sect2 id="zoom.z3950.record.behavior">
987     <title>Z39.50 Protocol behavior</title>
988     <para>
989      The functions <function>ZOOM_resultset_record</function> and
990      <function>ZOOM_resultset_records</function> inspects the client-side
991      record cache. Records not found in cache are fetched using
992      Present.
993      The functions may block (and perform network I/O)  - even though option
994      <literal>async</literal> is 1, because they return records objects.
995      (and there's no way to return records objects without retrieving them!).
996      </para>
997     <para>
998      There is a trick, however, in the usage of function
999      <function>ZOOM_resultset_records</function> that allows for
1000      delayed retrieval (and makes it non-blocking). By using
1001      a null pointer for <parameter>recs</parameter> you're indicating
1002      you're not interested in getting records objects
1003      <emphasis>now</emphasis>.
1004     </para>
1005    </sect2>
1006    <sect2 id="zoom.sru.record.behavior">
1007     <title>SRU/Solr Protocol behavior</title>
1008     <para>
1009      The ZOOM driver for SRU/Solr treats records returned by a SRU/Solr server
1010      as if they where Z39.50 records with transfer syntax XML and
1011      no element set name or database name.
1012     </para>
1013    </sect2>
1014   </sect1>
1015   <sect1 id="zoom.facets"><title>Facets</title>
1016    <para>
1017     Facets operations is not part of the official ZOOM specification, but
1018     is an Index Data extension for YAZ-based Z39.50 targets or
1019     <ulink url="&url.solr;">Solr</ulink> targets.
1020     In case the target can and is requested to return facets, using a
1021     result set the ZOOM client can request one or all facet fields.
1022     Using a facet field the client can request the term count and then
1023     interate over the terms.
1024    </para>
1025    <synopsis>
1026     ZOOM_facet_field *ZOOM_resultset_facets(ZOOM_resultset r);
1027
1028     const char ** ZOOM_resultset_facets_names(ZOOM_resultset r);
1029
1030     ZOOM_facet_field ZOOM_resultset_get_facet_field(ZOOM_resultset r,
1031                                                     const char *facet_name);
1032
1033     ZOOM_facet_field ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r,
1034                                                              int pos);
1035
1036     size_t ZOOM_resultset_facets_size(ZOOM_resultset r);
1037
1038     const char *ZOOM_facet_field_name(ZOOM_facet_field facet_field);
1039
1040     size_t ZOOM_facet_field_term_count(ZOOM_facet_field facet_field);
1041
1042     const char *ZOOM_facet_field_get_term(ZOOM_facet_field facet_field,
1043                                           size_t idx, int *freq);
1044    </synopsis>
1045    <para>
1046     References to temporary structures are returned by all functions.
1047     They are only valid as long the Result set is valid.
1048     <function>ZOOM_resultset_get_facet_field</function> or
1049     <function>ZOOM_resultset_get_facet_field_by_index</function>.
1050     <function>ZOOM_resultset_facets</function>.
1051     <function>ZOOM_resultset_facets_names</function>.
1052     <function>ZOOM_facet_field_name</function>.
1053     <function>ZOOM_facet_field_get_term</function>.
1054     </para>
1055    <para id="zoom.resultset.get_facet_field">
1056     A single Facet field  is returned by function
1057     <function>ZOOM_resultset_get_facet_field</function> or
1058     <function>ZOOM_resultset_get_facet_field_by_index</function> that takes
1059     a  result set and facet name or positive index respectively. First
1060     facet has position zero. If no facet could be obtained (invalid name
1061     or index out of bounds) <literal>NULL</literal> is returned.
1062    </para>
1063    <para id="zoom.resultset.facets">
1064     An array of facets field can be returned by
1065     <function>ZOOM_resultset_facets</function>. The length of the array is
1066     given by <function>ZOOM_resultset_facets_size</function>. The array is
1067     zero-based and last entry will be at
1068     <function>ZOOM_resultset_facets_size(result_set)</function>-1.
1069    </para>
1070    <para id="zoom.resultset.facets_names">
1071     It is possible to interate over facets by name, by calling
1072     <function>ZOOM_resultset_facets_names</function>.
1073     This will return an const array of char * where each string can be used
1074     as parameter for <function>ZOOM_resultset_get_facet_field</function>.
1075    </para>
1076    <para>
1077    Function <function>ZOOM_facet_field_name</function> gets the request
1078     facet name from a returned facet field.
1079    </para>
1080    <para>
1081     Function <function>ZOOM_facet_field_get_term</function> returns the
1082     idx'th term and term count for a facet field.
1083     Idx must between 0 and
1084     <function>ZOOM_facet_field_term_count</function>-1, otherwise the
1085     returned reference will be <literal>NULL</literal>. On a valid idx, the
1086     value of the freq reference will be the term count.
1087     The <literal>freq</literal> parameter must be valid pointer to integer.
1088    </para>
1089    </sect1>
1090   <sect1 id="zoom.scan"><title>Scan</title>
1091    <para>
1092     This section describes an interface for Scan. Scan is not an
1093     official part of the ZOOM model yet. The result of a scan operation
1094     is the <literal>ZOOM_scanset</literal> which is a set of terms
1095     returned by a target.
1096    </para>
1097
1098    <para>
1099     The Scan interface is supported for both Z39.50, SRU and Solr.
1100    </para>
1101
1102    <synopsis>
1103     ZOOM_scanset ZOOM_connection_scan(ZOOM_connection c,
1104                                       const char *startpqf);
1105
1106     ZOOM_scanset ZOOM_connection_scan1(ZOOM_connection c,
1107                                        ZOOM_query q);
1108
1109     size_t ZOOM_scanset_size(ZOOM_scanset scan);
1110
1111     const char *ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
1112                                   size_t *occ, size_t *len);
1113
1114     const char *ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
1115                                           size_t *occ, size_t *len);
1116
1117     void ZOOM_scanset_destroy(ZOOM_scanset scan);
1118
1119     const char *ZOOM_scanset_option_get(ZOOM_scanset scan,
1120                                         const char *key);
1121
1122     void ZOOM_scanset_option_set(ZOOM_scanset scan, const char *key,
1123                                  const char *val);
1124     </synopsis>
1125    <para>
1126     The scan set is created by function
1127     <function>ZOOM_connection_scan</function> which performs a scan
1128     operation on the connection using the specified
1129     <parameter>startpqf</parameter>.
1130     If the operation was successful, the size of the scan set can be
1131     retrieved by a call to <function>ZOOM_scanset_size</function>.
1132     Like result sets, the items are numbered 0,..size-1.
1133     To obtain information about a particular scan term, call function
1134     <function>ZOOM_scanset_term</function>. This function takes
1135     a scan set offset <literal>pos</literal> and returns a pointer
1136     to a <emphasis>raw term</emphasis> or <literal>NULL</literal> if
1137     non-present.
1138     If present, the <literal>occ</literal> and <literal>len</literal>
1139     are set to the number of occurrences and the length
1140     of the actual term respectively.
1141     <function>ZOOM_scanset_display_term</function> is similar to
1142     <function>ZOOM_scanset_term</function> except that it returns
1143     the <emphasis>display term</emphasis> rather than the raw term.
1144     In a few cases, the term is different from display term. Always
1145     use the display term for display and the raw term for subsequent
1146     scan operations (to get more terms, next scan result, etc).
1147    </para>
1148    <para>
1149     A scan set may be freed by a call to function
1150     <function>ZOOM_scanset_destroy</function>.
1151     Functions <function>ZOOM_scanset_option_get</function> and
1152     <function>ZOOM_scanset_option_set</function> retrieves and sets
1153     an option respectively.
1154    </para>
1155
1156    <para>
1157     The <parameter>startpqf</parameter> is a subset of PQF, namely
1158     the Attributes+Term part. Multiple <literal>@attr</literal> can
1159     be used. For example to scan in title (complete) phrases:
1160     <literallayout>
1161      @attr 1=4 @attr 6=2 "science o"
1162     </literallayout>
1163    </para>
1164
1165    <para>
1166     The <function>ZOOM_connecton_scan1</function> is a newer and
1167     more generic alternative to <function>ZOOM_connection_scan</function>
1168     which allows to use both CQL and PQF for Scan.
1169    </para>
1170
1171    <table frame="top" id="zoom.scanset.options">
1172     <title>ZOOM Scan Set Options</title>
1173     <tgroup cols="3">
1174      <colspec colwidth="4*" colname="name"></colspec>
1175      <colspec colwidth="7*" colname="description"></colspec>
1176      <colspec colwidth="2*" colname="default"></colspec>
1177      <thead>
1178       <row>
1179        <entry>Option</entry>
1180        <entry>Description</entry>
1181        <entry>Default</entry>
1182       </row>
1183      </thead>
1184      <tbody>
1185       <row><entry>
1186         number</entry><entry>Number of Scan Terms requested in next scan.
1187         After scan it holds the actual number of terms returned.
1188        </entry><entry>20</entry></row>
1189       <row><entry>
1190         position</entry><entry>Preferred Position of term in response
1191         in next scan; actual position after completion of scan.
1192        </entry><entry>1</entry></row>
1193       <row><entry>
1194         stepSize</entry><entry>Step Size
1195        </entry><entry>0</entry></row>
1196       <row><entry>
1197         scanStatus</entry><entry>An integer indicating the Scan Status
1198         of last scan.
1199        </entry><entry>0</entry></row>
1200       <row><entry>
1201         rpnCharset</entry><entry>Character set for RPN terms.
1202         If this is set, ZOOM C will assume that the ZOOM application is
1203         running UTF-8. Terms in RPN queries are then converted to the
1204         rpnCharset. If this is unset, ZOOM C will not assume any encoding
1205         of RPN terms and no conversion is performed.
1206        </entry><entry>none</entry></row>
1207      </tbody>
1208     </tgroup>
1209    </table>
1210   </sect1>
1211
1212   <sect1 id="zoom.extendedservices"><title>Extended Services</title>
1213    <para>
1214     ZOOM offers an interface to a subset of the Z39.50 extended services
1215     as well as a few privately defined ones:
1216    </para>
1217    <itemizedlist>
1218     <listitem>
1219      <para>
1220       Z39.50 Item Order (ILL).
1221       See <xref linkend="zoom.item.order"/>.
1222      </para>
1223     </listitem>
1224     <listitem>
1225      <para>
1226       Record Update. This allows a client to insert, modify or delete
1227       records.
1228       See <xref linkend="zoom.record.update"/>.
1229      </para>
1230     </listitem>
1231     <listitem>
1232      <para>
1233       Database Create. This a non-standard feature. Allows a client
1234       to create a database.
1235       See <xref linkend="zoom.database.create"/>.
1236      </para>
1237     </listitem>
1238     <listitem>
1239      <para>
1240       Database Drop. This a non-standard feature. Allows a client
1241       to delete/drop a database.
1242       See <xref linkend="zoom.database.drop"/>.
1243      </para>
1244      </listitem>
1245     <listitem>
1246      <para>
1247       Commit operation. This a non-standard feature. Allows a client
1248       to commit operations.
1249       See <xref linkend="zoom.commit"/>.
1250      </para>
1251     </listitem>
1252     <!-- all the ILL PDU options should go here too -->
1253    </itemizedlist>
1254    <para>
1255     To create an extended service operation a <literal>ZOOM_package</literal>
1256     must be created. The operation is a five step operation. The
1257     package is created, package is configured by means of options,
1258     the package is send, result is inspected (by means of options),
1259     the package is destroyed.
1260    </para>
1261    <synopsis>
1262     ZOOM_package ZOOM_connection_package(ZOOM_connection c,
1263                                          ZOOM_options options);
1264
1265     const char *ZOOM_package_option_get(ZOOM_package p,
1266                                         const char *key);
1267     void ZOOM_package_option_set(ZOOM_package p, const char *key,
1268                                  const char *val);
1269     void ZOOM_package_send(ZOOM_package p, const char *type);
1270
1271     void ZOOM_package_destroy(ZOOM_package p);
1272    </synopsis>
1273    <para>
1274     The <function>ZOOM_connection_package</function> creates a
1275     package for the connection given using the options specified.
1276    </para>
1277    <para>
1278     Functions <function>ZOOM_package_option_get</function> and
1279     <function>ZOOM_package_option_set</function> gets and sets
1280     options.
1281    </para>
1282    <para>
1283     <function>ZOOM_package_send</function> sends
1284     the package the via connection specified in
1285     <function>ZOOM_connection_package</function>.
1286     The <parameter>type</parameter> specifies the actual extended service
1287     package type to be sent.
1288    </para>
1289
1290    <table frame="top" id="zoom.extendedservices.options">
1291     <title>Extended Service Common Options</title>
1292     <tgroup cols="3">
1293      <colspec colwidth="4*" colname="name"></colspec>
1294      <colspec colwidth="7*" colname="description"></colspec>
1295      <colspec colwidth="3*" colname="default"></colspec>
1296      <thead>
1297       <row>
1298        <entry>Option</entry>
1299        <entry>Description</entry>
1300        <entry>Default</entry>
1301       </row>
1302      </thead>
1303      <tbody>
1304       <row>
1305        <entry>package-name</entry>
1306        <entry>Extended Service Request package name. Must be specified
1307        as part of a request</entry>
1308        <entry>none</entry>
1309       </row>
1310       <row>
1311        <entry>user-id</entry>
1312        <entry>User ID of Extended Service Package. Is a request option</entry>
1313        <entry>none</entry>
1314       </row>
1315       <row>
1316        <entry>function</entry>
1317        <entry>
1318         Function of package - one of <literal>create</literal>,
1319         <literal>delete</literal>, <literal>modify</literal>. Is
1320         a request option.
1321        </entry>
1322        <entry><literal>create</literal></entry>
1323       </row>
1324       <row>
1325        <entry>waitAction</entry>
1326        <entry>
1327         Wait action for package. Possible values:
1328         <literal>wait</literal>, <literal>waitIfPossible</literal>,
1329         <literal>dontWait</literal> or <literal>dontReturnPackage</literal>.
1330        </entry>
1331        <entry><literal>waitIfPossible</literal></entry>
1332       </row>
1333       <row>
1334        <entry>targetReference</entry>
1335        <entry>
1336         Target Reference. This is part of the response as returned
1337         by the server. Read it after a successful operation.
1338        </entry>
1339        <entry><literal>none</literal></entry>
1340       </row>
1341      </tbody>
1342     </tgroup>
1343    </table>
1344
1345    <sect2 id="zoom.item.order"><title>Item Order</title>
1346     <para>
1347      For Item Order, type must be set to <literal>itemorder</literal> in
1348      <function>ZOOM_package_send</function>.
1349     </para>
1350
1351     <table frame="top" id="zoom.item.order.options">
1352      <title>Item Order Options</title>
1353      <tgroup cols="3">
1354       <colspec colwidth="4*" colname="name"></colspec>
1355       <colspec colwidth="7*" colname="description"></colspec>
1356       <colspec colwidth="3*" colname="default"></colspec>
1357       <thead>
1358        <row>
1359         <entry>Option</entry>
1360         <entry>Description</entry>
1361         <entry>Default</entry>
1362        </row>
1363       </thead>
1364       <tbody>
1365        <row>
1366         <entry>contact-name</entry>
1367         <entry>ILL contact name</entry>
1368         <entry>none</entry>
1369        </row>
1370        <row>
1371         <entry>contact-phone</entry>
1372         <entry>ILL contact phone</entry>
1373         <entry>none</entry>
1374        </row>
1375        <row>
1376         <entry>contact-email</entry>
1377         <entry>ILL contact email</entry>
1378         <entry>none</entry>
1379        </row>
1380        <row>
1381         <entry>itemorder-item</entry>
1382         <entry>Position for item (record) requested. An integer</entry>
1383         <entry>1</entry>
1384        </row>
1385       </tbody>
1386      </tgroup>
1387     </table>
1388
1389    </sect2>
1390
1391    <sect2 id="zoom.record.update"><title>Record Update</title>
1392     <para>
1393      For Record Update, type must be set to <literal>update</literal> in
1394      <function>ZOOM_package_send</function>.
1395     </para>
1396
1397     <table frame="top" id="zoom.record.update.options">
1398      <title>Record Update Options</title>
1399      <tgroup cols="3">
1400       <colspec colwidth="4*" colname="name"></colspec>
1401       <colspec colwidth="7*" colname="description"></colspec>
1402       <colspec colwidth="3*" colname="default"></colspec>
1403       <thead>
1404        <row>
1405         <entry>Option</entry>
1406         <entry>Description</entry>
1407         <entry>Default</entry>
1408        </row>
1409       </thead>
1410       <tbody>
1411        <row>
1412         <entry>action</entry>
1413         <entry>
1414          The update action. One of
1415          <literal>specialUpdate</literal>,
1416          <literal>recordInsert</literal>,
1417          <literal>recordReplace</literal>,
1418          <literal>recordDelete</literal>,
1419          <literal>elementUpdate</literal>.
1420         </entry>
1421         <entry><literal>specialUpdate (recordInsert for updateVersion=1 which does not support specialUpdate)</literal></entry>
1422        </row>
1423        <row>
1424         <entry>recordIdOpaque</entry>
1425         <entry>Opaque Record ID</entry>
1426         <entry>none</entry>
1427        </row>
1428        <row>
1429         <entry>recordIdNumber</entry>
1430         <entry>Record ID number</entry>
1431         <entry>none</entry>
1432        </row>
1433        <row>
1434         <entry>record</entry>
1435         <entry>The record itself</entry>
1436         <entry>none</entry>
1437        </row>
1438        <row>
1439         <entry>recordOpaque</entry>
1440         <entry>Specifies an opaque record which is
1441           encoded as an ASN.1 ANY type with the OID as tiven by option
1442           <literal>syntax</literal> (see below).
1443           Option <literal>recordOpaque</literal> is an alternative
1444           to record - and <literal>record</literal> option (above) is
1445           ignored if recordOpaque is set. This option is only available in
1446           YAZ 3.0.35 and later and is meant to facilitate Updates with
1447           servers from OCLC.
1448         </entry>
1449         <entry>none</entry>
1450        </row>
1451        <row>
1452         <entry>syntax</entry>
1453         <entry>The record syntax (transfer syntax). Is a string that
1454          is a known record syntax.
1455         </entry>
1456         <entry>no syntax</entry>
1457        </row>
1458        <row>
1459         <entry>databaseName</entry>
1460         <entry>Database from connection object</entry>
1461         <entry>Default</entry>
1462        </row>
1463        <row>
1464         <entry>correlationInfo.note</entry>
1465         <entry>Correlation Info Note (string)</entry>
1466         <entry>none</entry>
1467        </row>
1468        <row>
1469         <entry>correlationInfo.id</entry>
1470         <entry>Correlation Info ID (integer)</entry>
1471         <entry>none</entry>
1472        </row>
1473        <row>
1474         <entry>elementSetName</entry>
1475         <entry>Element Set for Record</entry>
1476         <entry>none</entry>
1477        </row>
1478        <row>
1479         <entry>updateVersion</entry>
1480         <entry>Record Update version which holds one of the values
1481          1, 2 or 3. Each version has a distinct OID:
1482          1.2.840.10003.9.5
1483          (<ulink url="&url.z39.50.extupdate1;">first version</ulink>) ,
1484          1.2.840.10003.9.5.1
1485          (second version) and
1486          1.2.840.10003.9.5.1.1
1487          (<ulink url="&url.z39.50.extupdate3;">third and
1488           newest version</ulink>).
1489         </entry>
1490         <entry>3</entry>
1491        </row>
1492       </tbody>
1493      </tgroup>
1494     </table>
1495
1496    </sect2>
1497
1498    <sect2 id="zoom.database.create"><title>Database Create</title>
1499     <para>
1500      For Database Create, type must be set to <literal>create</literal> in
1501      <function>ZOOM_package_send</function>.
1502     </para>
1503
1504     <table frame="top" id="zoom.database.create.options">
1505      <title>Database Create Options</title>
1506      <tgroup cols="3">
1507       <colspec colwidth="4*" colname="name"></colspec>
1508       <colspec colwidth="7*" colname="description"></colspec>
1509       <colspec colwidth="3*" colname="default"></colspec>
1510       <thead>
1511        <row>
1512         <entry>Option</entry>
1513         <entry>Description</entry>
1514         <entry>Default</entry>
1515        </row>
1516       </thead>
1517       <tbody>
1518        <row>
1519         <entry>databaseName</entry>
1520         <entry>Database from connection object</entry>
1521         <entry>Default</entry>
1522        </row>
1523       </tbody>
1524      </tgroup>
1525     </table>
1526    </sect2>
1527
1528    <sect2 id="zoom.database.drop"><title>Database Drop</title>
1529     <para>
1530      For Database Drop, type must be set to <literal>drop</literal> in
1531      <function>ZOOM_package_send</function>.
1532     </para>
1533
1534     <table frame="top" id="zoom.database.drop.options">
1535      <title>Database Drop Options</title>
1536      <tgroup cols="3">
1537       <colspec colwidth="4*" colname="name"></colspec>
1538       <colspec colwidth="7*" colname="description"></colspec>
1539       <colspec colwidth="3*" colname="default"></colspec>
1540       <thead>
1541        <row>
1542         <entry>Option</entry>
1543         <entry>Description</entry>
1544         <entry>Default</entry>
1545        </row>
1546       </thead>
1547       <tbody>
1548        <row>
1549         <entry>databaseName</entry>
1550         <entry>Database from connection object</entry>
1551         <entry>Default</entry>
1552        </row>
1553       </tbody>
1554      </tgroup>
1555     </table>
1556    </sect2>
1557
1558    <sect2 id="zoom.commit"><title>Commit Operation</title>
1559     <para>
1560      For Commit, type must be set to <literal>commit</literal> in
1561      <function>ZOOM_package_send</function>.
1562     </para>
1563    </sect2>
1564
1565    <sect2 id="zoom.extended.services.behavior">
1566     <title>Protocol behavior</title>
1567     <para>
1568      All the extended services are Z39.50-only.
1569     </para>
1570     <note>
1571      <para>
1572       The database create, drop and commit services are privately defined
1573       operations.
1574       Refer to <filename>esadmin.asn</filename> in YAZ for the ASN.1
1575       definitions.
1576      </para>
1577     </note>
1578    </sect2>
1579   </sect1>
1580
1581   <sect1 id="zoom.options"><title>Options</title>
1582    <para>
1583     Most &zoom; objects provide a way to specify options to change behavior.
1584     From an implementation point of view a set of options is just like
1585     an associative array / hash.
1586    </para>
1587    <synopsis>
1588      ZOOM_options ZOOM_options_create(void);
1589
1590      ZOOM_options ZOOM_options_create_with_parent(ZOOM_options parent);
1591
1592      void ZOOM_options_destroy(ZOOM_options opt);
1593    </synopsis>
1594    <synopsis>
1595      const char *ZOOM_options_get(ZOOM_options opt, const char *name);
1596
1597      void ZOOM_options_set(ZOOM_options opt, const char *name,
1598                            const char *v);
1599    </synopsis>
1600    <synopsis>
1601      typedef const char *(*ZOOM_options_callback)
1602                             (void *handle, const char *name);
1603
1604      ZOOM_options_callback
1605              ZOOM_options_set_callback(ZOOM_options opt,
1606                                        ZOOM_options_callback c,
1607                                        void *handle);
1608    </synopsis>
1609   </sect1>
1610
1611   <sect1 id="zoom.queryconversions"><title>Query conversions</title>
1612    <synopsis>
1613     int ZOOM_query_cql2rpn(ZOOM_query s, const char *cql_str,
1614                            ZOOM_connection conn);
1615
1616     int ZOOM_query_ccl2rpn(ZOOM_query s, const char *ccl_str,
1617                            const char *config,
1618                            int *ccl_error, const char **error_string,
1619                            int *error_pos);
1620    </synopsis>
1621    <para>
1622     <function>ZOOM_query_cql2rpn</function> translates the CQL string,
1623     client-side, into RPN which may be passed to the server.
1624     This is useful for server's that don't themselves
1625     support CQL, for which <function>ZOOM_query_cql</function> is useless.
1626     `conn' is used  only as a place to stash diagnostics if compilation
1627     fails; if this information is not needed, a null pointer may be used.
1628     The CQL conversion is driven by option <literal>cqlfile</literal> from
1629     connection conn. This specifies a conversion file (eg pqf.properties)
1630     which <emphasis>must</emphasis> be present.
1631    </para>
1632    <para>
1633     <function>ZOOM_query_ccl2rpn</function> translates the CCL string,
1634     client-side, into RPN which may be passed to the server.
1635     The conversion is driven by the specification given by
1636     <literal>config</literal>. Upon completion 0 is returned on success; -1
1637     is returned on on failure. Om failure <literal>error_string</literal> and
1638     <literal>error_pos</literal> holds error message and position of
1639     first error in original CCL string.
1640    </para>
1641   </sect1>
1642   <sect1 id="zoom.events"><title>Events</title>
1643    <para>
1644     If you're developing non-blocking applications, you have to deal
1645     with events.
1646    </para>
1647    <synopsis>
1648     int ZOOM_event(int no, ZOOM_connection *cs);
1649    </synopsis>
1650    <para>
1651     The <function>ZOOM_event</function> executes pending events for
1652     a number of connections. Supply the number of connections in
1653     <literal>no</literal> and an array of connections in
1654     <literal>cs</literal> (<literal>cs[0] ... cs[no-1]</literal>).
1655     A pending event could be a sending a search, receiving a response,
1656     etc.
1657     When an event has occurred for one of the connections, this function
1658     returns a positive integer <literal>n</literal> denoting that an event
1659     occurred for connection <literal>cs[n-1]</literal>.
1660     When no events are pending for the connections, a value of zero is
1661     returned.
1662     To ensure that all outstanding requests are performed call this function
1663     repeatedly until zero is returned.
1664    </para>
1665    <para>
1666     If <function>ZOOM_event</function> returns and returns non-zero, the
1667     last event that occurred can be expected.
1668    </para>
1669    <synopsis>
1670     int ZOOM_connection_last_event(ZOOM_connection cs);
1671    </synopsis>
1672    <para>
1673     <function>ZOOM_connection_last_event</function> returns an event type
1674     (integer) for the last event.
1675    </para>
1676
1677    <table frame="top" id="zoom.event.ids">
1678     <title>ZOOM Event IDs</title>
1679     <tgroup cols="2">
1680      <colspec colwidth="4*" colname="name"></colspec>
1681      <colspec colwidth="7*" colname="description"></colspec>
1682      <thead>
1683       <row>
1684        <entry>Event</entry>
1685        <entry>Description</entry>
1686       </row>
1687      </thead>
1688      <tbody>
1689       <row>
1690        <entry>ZOOM_EVENT_NONE</entry>
1691        <entry>No event has occurred</entry>
1692       </row>
1693       <row>
1694        <entry>ZOOM_EVENT_CONNECT</entry>
1695        <entry>TCP/IP connect has initiated</entry>
1696       </row>
1697       <row>
1698        <entry>ZOOM_EVENT_SEND_DATA</entry>
1699        <entry>Data has been transmitted (sending)</entry>
1700       </row>
1701       <row>
1702        <entry>ZOOM_EVENT_RECV_DATA</entry>
1703        <entry>Data has been received)</entry>
1704       </row>
1705       <row>
1706        <entry>ZOOM_EVENT_TIMEOUT</entry>
1707        <entry>Timeout</entry>
1708       </row>
1709       <row>
1710        <entry>ZOOM_EVENT_UNKNOWN</entry>
1711        <entry>Unknown event</entry>
1712       </row>
1713       <row>
1714        <entry>ZOOM_EVENT_SEND_APDU</entry>
1715        <entry>An APDU has been transmitted (sending)</entry>
1716       </row>
1717       <row>
1718        <entry>ZOOM_EVENT_RECV_APDU</entry>
1719        <entry>An APDU has been received</entry>
1720       </row>
1721       <row>
1722        <entry>ZOOM_EVENT_RECV_RECORD</entry>
1723        <entry>A result-set record has been received</entry>
1724       </row>
1725       <row>
1726        <entry>ZOOM_EVENT_RECV_SEARCH</entry>
1727        <entry>A search result been received</entry>
1728       </row>
1729      </tbody>
1730     </tgroup>
1731    </table>
1732   </sect1>
1733  </chapter>
1734
1735  <!-- Keep this comment at the end of the file
1736  Local variables:
1737  mode: sgml
1738  sgml-omittag:t
1739  sgml-shorttag:t
1740  sgml-minimize-attributes:nil
1741  sgml-always-quote-attributes:t
1742  sgml-indent-step:1
1743  sgml-indent-data:t
1744  sgml-parent-document: "yaz.xml"
1745  sgml-local-catalogs: nil
1746  sgml-namecase-general:t
1747  End:
1748  -->
1749