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