1 <?xml version="1.0" standalone="no"?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
3 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
5 <!ENTITY % local SYSTEM "local.ent">
7 <!ENTITY % entities SYSTEM "entities.ent">
9 <!ENTITY % idcommon SYSTEM "common/common.ent">
14 <title>YAZ User's Guide and Reference</title>
16 <author><firstname>Sebastian</firstname><surname>Hammer</surname></author>
17 <author><firstname>Adam</firstname><surname>Dickmeiss</surname></author>
18 <author><firstname>Mike</firstname><surname>Taylor</surname></author>
19 <author><firstname>Heikki</firstname><surname>Levanto</surname></author>
20 <author><firstname>Dennis</firstname><surname>Schafroth</surname></author>
22 <releaseinfo>&version;</releaseinfo>
24 <year>©right-year;</year>
25 <holder>Index Data</holder>
29 This document is the programmer's guide and reference to the &yaz;
30 package version &version;. &yaz; is a compact toolkit that provides
31 access to the Z39.50 and SRU/Solr protocols, as well as a set of
32 higher-level tools for implementing the server and client
34 The documentation can be used on its own, or as a reference when
35 looking at the example applications provided with the package.
40 <imagedata fileref="common/id.png" format="PNG"/>
43 <imagedata fileref="common/id.eps" format="EPS"/>
48 <chapter id="introduction">
49 <title>Introduction</title>
51 &yaz; is a C/C++ library for information retrieval applications
52 using the Z39.50/SRU/Solr protocols for information retrieval.
60 <ulink url="&url.z39.50;">Z39.50</ulink> version 3 support.
61 Amendments and Z39.50-2002 revision is supported.
67 <ulink url="&url.sru;">SRU GET/POST/SOAP</ulink>
68 version 1.1, 1.2 and 2.0 (over HTTP and HTTPS).
73 Includes BER encoders/decoders for the
74 <ulink url="&url.ill;">ISO ILL</ulink>
81 <ulink url="&url.solr;">Solr</ulink> Web Service version 1.4.x
87 Supports the following transports: BER over TCP/IP
88 (<ulink url="&url.ber.over.tcpip;">RFC1729</ulink>),
89 BER over unix local socket, and
90 <ulink url="&url.http.1.1;">HTTP 1.1</ulink>.
95 Secure Socket Layer support using
96 <ulink url="&url.gnutls;">GnuTLS</ulink>.
97 If enabled, &yaz; uses HTTPS transport (for SOAP) or
98 "Secure BER" (for Z39.50).
104 <ulink url="&url.zoom;">ZOOM</ulink> C API implementing
105 Z39.50, SRU and Solr Web Service.
110 The &yaz; library offers a set of useful utilities
111 related to the protocols, such as MARC (ISO2709) parser,
112 CCL (ISO8777) parser,
113 <ulink url="&url.cql;">CQL</ulink>
114 parser, memory management routines, character set conversion.
119 Portable code. &yaz; compiles out-of-the box on most Unixes and
120 on Windows using Microsoft Visual C++.
125 Fast operation. The C based BER encoders/decoders as well
126 as the server component of &yaz; is very fast.
131 Liberal license that allows for commercial use of &yaz;.
137 <sect1 id="introduction.reading">
138 <title>Reading this Manual</title>
140 Most implementors only need to read a fraction of the
141 material in thie manual, so a quick walkthrough of the chapters
147 <xref linkend="installation"/> contains installation
148 instructions for &yaz;. You don't need reading this
149 if you expect to download &yaz; binaries.
150 However, the chapter contains information about how
151 to make <emphasis>your</emphasis> application link
157 <xref linkend="zoom"/> describes the ZOOM API of &yaz;.
158 This is definitely worth a read if you wish to develop a Z39.50/SRU
164 <xref linkend="server"/> describes the generic frontend server
165 and explains how to develop server Z39.50/SRU applications for &yaz;.
166 Obviously worth reading if you're to develop a server.
171 <xref linkend="yaz-client"/> describes how to use the &yaz; Z39.50
172 client. If you're developer and wish to test your server
173 or a server from another party, you might find this chapter
179 <xref linkend="asn"/> documents the most commonly used Z39.50
180 C data structures offered by the &yaz; API. Client
181 developers using ZOOM and non-Z39.50 implementors may skip this.
186 <xref linkend="soap"/> describes how SRU and SOAP is used
187 in &yaz;. Only if you're developing SRU applications
188 this section is a must.
193 <xref linkend="tools"/> contains sections for the various
194 tools offered by &yaz;. Scan through the material quickly
195 and see what's relevant to you! SRU implementors
196 might find the <link linkend="cql">CQL</link> section
202 <xref linkend="odr"/> goes through the details of the
203 ODR module which is the work horse that encodes and decodes
204 BER packages. Implementors using ZOOM only, do <emphasis>not</emphasis>
206 Most other Z39.50 implementors only need to read the first two
207 sections (<xref linkend="odr.introduction"/> and
208 <xref linkend="odr.use"/>).
213 <xref linkend="comstack"/> describes the network layer module
214 COMSTACK. Implementors using ZOOM or the generic frontend server
215 may skip this. Others, presumably, handling client/server
216 communication on their own should read this.
221 <sect1 id="introduction.api">
222 <title>The API</title>
224 The <ulink url="&url.yaz;">&yaz;</ulink>
225 toolkit offers several different levels of access to the
226 <ulink url="&url.z39.50;">ISO23950/Z39.50</ulink>,
227 <ulink url="&url.ill;">ILL</ulink> and
228 <ulink url="&url.sru;">SRU</ulink>
230 The level that you need to use depends on your requirements, and
231 the role (server or client) that you want to implement.
232 If you're developing a client application you should consider the
233 <link linkend="zoom">ZOOM</link> API.
234 It is, by far, the easiest way to develop clients in C.
235 Server implementers should consider the
236 <link linkend="server">generic frontend server</link>.
237 None of those high-level APIs support the whole protocol, but
238 they do include most facilities used in existing Z39.50 applications.
241 If you're using 'exotic' functionality (meaning anything not included in
242 the high-level APIs), developing non-standard extensions to Z39.50 or
243 you're going to develop an ILL application you'll have to learn the lower
247 The YAZ toolkit modules is shown in figure <xref linkend="yaz.layer"/>.
249 <figure id="yaz.layer">
250 <title>YAZ layers</title>
253 <imagedata fileref="apilayer.png" format="PNG"/>
256 <imagedata fileref="apilayer.eps" format="EPS"/>
261 There are four layers.
264 <para>A client or server application (or both).
265 This layer includes ZOOM and the generic frontend server.
270 The second layer provides a C represenation of the
271 protocol units (packages) for Z39.50 ASN.1, ILL ASN.1,
277 The third layer encodes and decodes protocol data units to
278 simple packages (buffer with certain length). The &odr; module
279 encodes and decodes BER whereas the HTTP modules encodes and
280 decodes HTTP ruquests/responses.
285 The lowest layer is &comstack; which exchanges the encoded packages
286 with a peer process over a network.
292 The &asn; module represents the ASN.1 definition of
293 the Z39.50 protocol. It establishes a set of type and
294 structure definitions, with one structure for each of the top-level
295 PDUs, and one structure or type for each of the contained ASN.1 types.
296 For primitive types, or other types that are defined by the ASN.1
297 standard itself (such as the EXTERNAL type), the C representation is
298 provided by the &odr; (Open Data Representation) subsystem.
301 &odr; is a basic mechanism for representing an
302 ASN.1 type in the C programming language, and for implementing BER
303 encoders and decoders for values of that type. The types defined in
304 the &asn; module generally have the prefix <literal>Z_</literal>, and
305 a suffix corresponding to the name of the type in the ASN.1
306 specification of the protocol (generally Z39.50-1995). In the case of
307 base types (those originating in the ASN.1 standard itself), the prefix
308 <literal>Odr_</literal> is sometimes seen. Either way, look for
309 the actual definition in either <filename>z-core.h</filename> (for the types
310 from the protocol), <filename>odr.h</filename> (for the primitive ASN.1
312 The &asn; library also provides functions (which are, in turn,
313 defined using &odr; primitives) for encoding and decoding data values.
314 Their general form is
316 <funcprototype><funcdef>int <function>z_<replaceable>xxx</replaceable></function></funcdef>
317 <paramdef>ODR <parameter>o</parameter></paramdef>
318 <paramdef>Z_<replaceable>xxx</replaceable> **<parameter>p</parameter></paramdef>
319 <paramdef>int <parameter>optional</parameter></paramdef>
320 <paramdef>const char *<parameter>name</parameter></paramdef>
323 (note the lower-case "z" in the function name)
327 If you are using the premade definitions of the &asn; module, and you
328 are not adding new protocol of your own, the only parts of &odr; that you
329 need to worry about are documented in
330 <xref linkend="odr.use"/>.
334 When you have created a BER-encoded buffer, you can use the &comstack;
335 subsystem to transmit (or receive) data over the network. The &comstack;
336 module provides simple functions for establishing a connection
337 (passively or actively, depending on the role of your application),
338 and for exchanging BER-encoded PDUs over that connection. When you
339 create a connection endpoint, you need to specify what transport to
340 use (TCP/IP, SSL or UNIX sockets).
341 For the remainder of the connection's lifetime, you don't have
342 to worry about the underlying transport protocol at all - the &comstack;
343 will ensure that the correct mechanism is used.
346 We call the combined interfaces to &odr;, &asn;, and &comstack; the service
347 level API. It's the API that most closely models the Z39.50
348 service/protocol definition, and it provides unlimited access to all
349 fields and facilities of the protocol definitions.
352 The reason that the &yaz; service-level API is a conglomerate of the
353 APIs from three different submodules is twofold. First, we wanted to allow
354 the user a choice of different options for each major task. For instance,
355 if you don't like the protocol API provided by &odr;/&asn;, you
356 can use SNACC or BERUtils instead, and still have the benefits of the
357 transparent transport approach of the &comstack; module. Secondly,
358 we realize that you may have to fit the toolkit into an existing
359 event-processing structure, in a way that is incompatible with
360 the &comstack; interface or some other part of &yaz;.
364 <chapter id="installation">
365 <title>Compilation and Installation</title>
366 <sect1 id="installation-introduction">
367 <title>Introduction</title>
369 The latest version of the software will generally be found at:
372 <ulink url="&url.yaz.download;"/>
375 We have tried our best to keep the software portable, and on many
376 platforms, you should be able to compile everything with little or
380 The software is regularly tested on
381 <ulink url="&url.debian;">Debian GNU/Linux</ulink>,
382 <ulink url="&url.centos;">CentOS</ulink>,
383 <ulink url="&url.ubuntu;">Ubuntu Linux</ulink>,
384 <ulink url="&url.freebsd;">FreeBSD (i386)</ulink>,
385 <ulink url="&url.macosx;">MAC OSX</ulink>,
386 <ulink url="&url.solaris;">Solaris</ulink>,
387 Windows 7, Windows XP.
390 Some versions have be known to work on HP/UX,
391 DEC Unix, <ulink url="&url.netbsd;">NetBSD</ulink>,
392 <ulink url="&url.openbsd;">OpenBSD</ulink>,
394 Data General DG/UX (with some CFLAGS tinkering),
395 SGI/IRIX, DDE Supermax, Apple Macintosh (using the Codewarrior programming
396 environment and the GUSI socket libraries),
400 If you move the software to other platforms, we'd be grateful if you'd
401 let us know about it. If you run into difficulties, we will try to help
402 if we can, and if you solve the problems, we would be happy to include
403 your fixes in the next release. So far, we have mostly avoided
404 <literal>#ifdefs</literal> for individual platforms, and we'd
405 like to keep it that way as far as it makes sense.
408 We maintain a mailing-list for the purpose of announcing new releases and
409 bug-fixes, as well as general discussion. Subscribe by
411 <ulink url="&url.yaz.mailinglist;">here</ulink>.
412 General questions and problems can be directed at
413 <ulink url="&url.yaz.mail;"/>, or the address given at the top of
417 <sect1 id="installation.unix"><title>UNIX</title>
420 <ulink url="&url.debian;">Debian GNU/Linux</ulink> (i386 and amd64),
421 <ulink url="&url.ubuntu;">Ubuntu</ulink> (i386 and amd64)
423 <ulink url="&url.centos;">CentOS</ulink> (amd64 only) packages for &yaz;.
424 You should be able to create packages for other CPUs by building
425 them from the source package.
428 YAZ is also part of several packages repositories. Some of them are
433 Solaris CSW: <ulink url="http://www.opencsw.org/packages/yaz/"/>
438 Solaris: <ulink url="http://unixpackages.com"/>
443 FreeBSD: <ulink url="http://www.freshports.org/net/yaz"/>
448 Debian: <ulink url="http://packages.debian.org/search?keywords=yaz"/>
453 Ubuntu: <ulink url="https://launchpad.net/ubuntu/+source/yaz"/>
459 <ulink url="http://ftp.netbsd.org/pub/pkgsrc/current/pkgsrc/net/yaz/README.html"/>
463 <sect2 id="installation.source.unix">
464 <title>Compiling from source on Unix</title>
466 Note that if your system doesn't have a native ANSI C compiler, you may
467 have to acquire one separately. We recommend
468 <ulink url="&url.gcc;">GCC</ulink>.
471 If you wish to use character set conversion facilities in &yaz; or if you
472 are compiling &yaz; for use with Zebra it is a good idea to ensure that
473 the iconv library is installed. Some Unixes today already have it
475 <ulink url="&url.libiconv;">GNU libiconv</ulink>.
478 YAZ 3.0.16 and later includes a wrapper for the
479 <ulink url="&url.icu;">ICU</ulink>
480 (International Components for Unicode).
481 In order to use this, the developer version of the ICU library
482 must be available. ICU support is recommended for applications
483 such as Pazpar2 and Zebra.
486 The <ulink url="&url.libxslt;">libxslt</ulink>,
487 <ulink url="&url.libxml2;">libxml2</ulink> librararies are required
488 if &yaz; is to support SRU/Solr.
489 These libraries are very portable and should compile out-of-the
490 box on virtually all Unix platforms. It is available in binary
491 forms for Linux and others.
495 <ulink url="&url.autoconf;">Autoconf</ulink>,
496 <ulink url="&url.automake;">Automake</ulink> and
497 <ulink url="&url.libtool;">Libtool</ulink>
498 are used to generate Makefiles and configure &yaz; for the system.
499 You do <emphasis>not</emphasis> these tools unless you're using the
500 Git version of &yaz;.
503 The CQL parser for &yaz; is built using
504 GNU <ulink url="&url.bison;">Bison</ulink>.
505 This tool is only needed if you're using the Git version of &yaz;.
508 &yaz; includes a tiny ASN.1 compiler. This compiler is
509 written in <ulink url="&url.tcl;">Tcl</ulink>.
510 But as for Bison you do not need it unless you're using Git
511 version of &yaz; or you're using the compiler to built own codecs
515 Generally it should be sufficient to run configure without options,
522 The configure script attempts to use use the C compiler specified by
523 the <literal>CC</literal> environment variable. If not set, GNU C will be
524 used if it is available. The <literal>CFLAGS</literal> environment
525 variable holds options to be passed to the C compiler. If you're using
526 Bourne-compatible shell you may pass something like this to use a
527 particular C compiler with optimization enabled:
530 CC=/opt/ccs/bin/cc CFLAGS=-O ./configure
533 To customize &yaz;, the configure script also accepts a set of options.
534 The most important are:
538 <literal>--prefix</literal>=<replaceable>prefix</replaceable>
541 <para>Specifies installation prefix for &yaz;. This is
542 only needed if you run <literal>make install</literal> later to
543 perform a "system" installation. The prefix is
544 <literal>/usr/local</literal> if not specified.
550 <literal>--enable-tcpd</literal>
553 <para>The front end server will be built using Wietse's
554 <ulink url="&url.tcpwrapper;">TCP wrapper library</ulink>.
555 It allows you to allow/deny clients depending on IP number.
556 The TCP wrapper library is often used in GNU/Linux and
560 <refentrytitle>hosts_access</refentrytitle>
561 <manvolnum>5</manvolnum>
565 <refentrytitle>tcpd</refentrytitle>
566 <manvolnum>8</manvolnum>
573 <literal>--enable-threads</literal>
576 <para>&yaz; will be built using POSIX threads.
577 Specifically, <constant>_REENTRANT</constant> will be defined during
584 <literal>--disable-shared</literal>
587 <para>The make process will not create shared
588 libraries (also known as shared objects <filename>.so</filename>).
589 By default, shared libraries are created -
590 equivalent to <literal>--enable-shared</literal>.
596 <literal>--disable-shared</literal>
599 <para>The make process will not create
600 static libraries (<filename>.a</filename>).
601 By default, static libraries are created -
602 equivalent to <literal>--enable-static</literal>.
608 <literal>--with-iconv</literal>[=<replaceable>prefix</replaceable>]
611 <para>Compile &yaz; with iconv library in directory
612 <replaceable>prefix</replaceable>. By default configure will
613 search for iconv on the system. Use this option if it
614 doesn't find iconv. Alternatively,
615 <literal>--without-iconv</literal>, can be uset to force &yaz;
622 <literal>--with-xslt</literal>[=<replaceable>prefix</replaceable>]
625 <para>Compile &yaz; with
626 <ulink url="&url.libxslt;">libxslt</ulink> in directory
627 <replaceable>prefix</replaceable>.
628 Use this option if you want XSLT and XML support.
629 By default, configure will
630 search for libxslt on the system. Use this option if it
631 libxslt is not found automatically. Alternatively,
632 <literal>--without-xslt</literal>, can be used to force &yaz;
639 <literal>--with-xml2</literal>[=<replaceable>prefix</replaceable>]
642 <para>Compile &yaz; with
643 <ulink url="&url.libxml2;">libxml2</ulink> in directory
644 <replaceable>prefix</replaceable>.
645 Use this option if you want &yaz; to use XML and support SRU/Solr.
646 By default, configure will
647 search for libxml2 on the system. Use this option if it
648 libxml2 is not found automatically. Alternatively,
649 <literal>--without-xml2</literal>, can be used to force &yaz;
653 Note that option <literal>--with-xslt</literal>
654 also enables libxml2.
660 <literal>--with-gnutls</literal>[=<replaceable>prefix</replaceable>]
663 <para>&yaz; will be linked with the GNU TLS libraries and
664 an SSL COMSTACK will be provided. By default configure enables
665 SSL support for YAZ if the GNU TLS development libraries are found
672 <literal>--with-icu</literal>[=<replaceable>prefix</replaceable>]
675 <para>&yaz; will be linked the
676 <ulink url="&url.icu;">ICU</ulink> library in the prefix if given.
677 If prefix is not given, the libraries exposed by the script
678 <application>icu-config</application> will be used if found.
685 <literal>--with-libgcrypt</literal>[=<replaceable>prefix</replaceable>]
688 <para>&yaz; will be linked with
689 <ulink url="&url.libgcrypt;">Libgcrypt</ulink> in the prefix if given.
690 If prefix is not given, the libraries exposed by the script
691 <application>libgcrypt-config</application> will be used if found.
697 <literal>--with-memcached</literal>
700 <para>&yaz; will be linked with
701 <ulink url="&url.libmemcached;">libMemcached</ulink> to allow
702 for result-set caching for ZOOM.
703 The prefix can not be given. Note that YAZ will only search
704 for libMemcached if Libgcrypt is also enabled.
705 Note that 0.40 of libmemcached is required.
711 <literal>--with-redis</literal>
714 <para>&yaz; will be linked with the hiredis C library
715 to allow for result-set caching for ZOOM on a
716 <ulink url="&url.redis;">redis</ulink> server.
717 The prefix can not be given. Note that YAZ will only search
718 for hiredis if Libgcrypt is also enabled.
726 When configured, build the software by typing:
732 The following files are generated by the make process:
735 <term><filename>src/libyaz.la</filename></term>
737 Main &yaz; library. This is no ordinary library. It's
739 By default, &yaz; creates a static library in
740 <filename>lib/.libs/libyaz.a</filename>.
744 <term><filename>src/libyaz_server.la</filename></term>
746 Generic Frontend server. This is an add-on for libyaz.la.
747 Code in this library uses POSIX threads functions - if POSIX
748 threads are available on the platform.
752 <term><filename>src/libyaz_icu.la</filename></term>
754 Functions that wrap the ICU library.
758 <term><filename>ztest/yaz-ztest</filename></term>
759 <listitem><para>Test Z39.50 server.
763 <term><filename>client/yaz-client</filename></term>
764 <listitem><para>Z39.50 client for testing the protocol.
765 See chapter <link linkend="yaz-client">
766 YAZ client</link> for more information.
770 <term><filename>util/yaz-config</filename></term>
771 <listitem><para>A Bourne-shell script, generated by configure, that
772 specifies how external applications should compile - and link with
777 <term><filename>util/yaz-asncomp</filename></term>
778 <listitem><para>The ASN.1 compiler for &yaz;. Requires the
779 Tcl Shell, <application>tclsh</application>, in
780 <literal>PATH</literal> to operate.
784 <term><filename>util/yaz-iconv</filename></term>
785 <listitem><para>This program converts data in one character set to
786 another. This command exercises the YAZ character set
791 <term><filename>util/yaz-marcdump</filename></term>
792 <listitem><para>This program parses ISO2709 encoded MARC records
793 and prints them in line-format or XML.
797 <term><filename>util/yaz-icu</filename></term>
798 <listitem><para>This program exposes the ICU wrapper library if that
799 is enabled for YAZ. Only if ICU is available this program is
804 <term><filename>util/yaz-url</filename></term>
805 <listitem><para>This program is a simple HTTP page fetcher ala
810 <term><filename>zoom/zoomsh</filename></term>
812 A simple shell implemented on top of the
813 <link linkend="zoom">ZOOM</link> functions.
814 The shell is a command line application that allows you to enter
815 simple commands to perform ZOOM operations.
819 <term><filename>zoom/zoomtst1</filename>,
820 <filename>zoom/zoomtst2</filename>, ..</term>
822 Several small applications that demonstrates the ZOOM API.
828 If you wish to install &yaz; in system directories
829 <filename>/usr/local/bin</filename>,
830 <filename>/usr/local/lib</filename> .. etc, you can type:
836 You probably need to have root access in order to perform this.
837 You must specify the <literal>--prefix</literal> option for configure if
838 you wish to install &yaz; in other directories than the default
839 <filename>/usr/local/</filename>.
842 If you wish to perform an un-installation of &yaz;, use:
848 This will only work if you haven't reconfigured &yaz; (and therefore
849 changed installation prefix). Note that uninstall will not
850 remove directories created by make install, e.g.
851 <filename>/usr/local/include/yaz</filename>.
854 <sect2 id="installation-linking-yaz-unix">
855 <title>How to make apps using YAZ on UNIX</title>
857 This section describes how to compile - and link your own
858 applications using the &yaz; toolkit.
859 If you're used to Makefiles this shouldn't be hard. As for
860 other libraries you have used before, you have to set a proper include
861 path for your C/C++ compiler and specify the location of
862 &yaz; libraries. You can do it by hand, but generally we suggest
863 you use the <filename>yaz-config</filename> that is generated
864 by <filename>configure</filename>. This is especially
865 important if you're using the threaded version of &yaz; which
866 require you to pass more options to your linker/compiler.
869 The <filename>yaz-config</filename> script accepts command line
870 options that makes the <filename>yaz-config</filename> script print
871 options that you should use in your make process.
872 The most important ones are:
873 <literal>--cflags</literal>, <literal>--libs</literal>
874 which prints C compiler flags, and linker flags respectively.
877 A small and complete <literal>Makefile</literal> for a C
878 application consisting of one source file,
879 <filename>myprog.c</filename>, may look like this:
881 YAZCONFIG=/usr/local/bin/yaz-config
882 CFLAGS=`$(YAZCONFIG) --cflags`
883 LIBS=`$(YAZCONFIG) --libs`
885 $(CC) $(CFLAGS) -o myprog myprog.o $(LIBS)
889 The CFLAGS variable consists of a C compiler directive that will set
890 the include path to the <emphasis>parent</emphasis> directory
891 of <filename>yaz</filename>. That is, if &yaz; header files were
892 installed in <filename>/usr/local/include/yaz</filename>,
893 then include path is set to <filename>/usr/local/include</filename>.
894 Therefore, in your applications you should use
896 #include <yaz/proto.h>
898 and <emphasis>not</emphasis>
900 #include <proto.h>
904 For Libtool users, the <filename>yaz-config</filename> script provides
905 a different variant of option <literal>--libs</literal>, called
906 <literal>--lalibs</literal> that returns the name of the
907 Libtool archive(s) for &yaz; rather than the ordinary ones.
910 For applications using the threaded version of &yaz;,
911 specify <literal>threads</literal> after the
912 other options. When <literal>threads</literal> is given,
913 more flags and linker flags will be printed by
914 <filename>yaz-config</filename>. If our previous example was
915 using threads, you'd have to modify the lines that set
916 <literal>CFLAGS</literal> and <literal>LIBS</literal> as
919 CFLAGS=`$(YAZCONFIG) --cflags threads`
920 LIBS=`$(YAZCONFIG) --libs threads`
922 There is no need specify POSIX thread libraries in your Makefile.
923 The <literal>LIBS</literal> variable includes that as well.
927 <sect1 id="installation.win32">
928 <title>Windows</title>
929 <para>The easiest way to install YAZ on Windows is by downloading
931 <ulink url="&url.yaz.download.win32;">here</ulink>.
932 The installer comes with source too - in case you wish to
933 compile YAZ with different compiler options, etc.
936 <sect2 id="installation.win32.source">
937 <title>Compiling from Source on Windows</title>
939 &yaz; is shipped with "makefiles" for the NMAKE tool that comes
940 with <ulink url="&url.vstudio;">
941 Microsoft Visual Studio</ulink>. It has been tested with
942 Microsoft Visual Studio 2013.
945 Start a command prompt and switch the sub directory
946 <filename>WIN</filename> where the file <filename>makefile</filename>
947 is located. Customize the installation by editing the
948 <filename>makefile</filename> file (for example by using notepad).
949 The following summarizes the most important settings in that file:
952 <term><literal>DEBUG</literal></term>
954 If set to 1, the software is
955 compiled with debugging libraries (code generation is
956 multi-threaded debug DLL).
957 If set to 0, the software is compiled with release libraries
958 (code generation is multi-threaded DLL).
962 <term><literal>HAVE_TCL</literal>, <literal>TCL</literal></term>
964 If <literal>HAVE_TCL</literal> is set to 1, nmake will
965 use the ASN.1 compiler (<ulink url="&url.tcl;">Tcl</ulink> based).
966 You must set <literal>TCL</literal> to the full path of the Tcl
967 interpreter. A Windows version of Tcl is part of
968 <ulink url="&url.gitwindows;">Git for Windows</ulink>.
971 If you do not have Tcl installed, set
972 <literal>HAVE_TCL</literal> to 0.
976 <term><literal>HAVE_BISON</literal>,
977 <literal>BISON</literal></term>
979 If GNU Bison is present, you might set <literal>HAVE_BISON</literal>
980 to 1 and specify the Bison executable in <literal>BISON</literal>.
981 Bison is only required if you use the Git version of
982 YAZ or if you modify the grammar for CQL
983 (<filename>cql.y</filename>).
986 A Windows version of GNU Bison is part of
987 <ulink url="&url.gitwindows;">Git for Windows</ulink>.
991 <term><literal>HAVE_ICONV</literal>,
992 <literal>ICONV_DIR</literal></term>
994 If <literal>HAVE_ICONV</literal> is set to 1, YAZ is compiled
995 with iconv support. In this configuration, set
996 <literal>ICONV_DIR</literal> to the iconv source directory.
1000 <term><literal>HAVE_LIBXML2</literal>,
1001 <literal>LIBXML2_DIR</literal></term>
1004 If <literal>HAVE_LIBXML2</literal> is set to 1, YAZ is compiled
1005 with SRU support. In this configuration, set
1006 <literal>LIBXML2_DIR</literal> to the
1007 <ulink url="&url.libxml2;">libxml2</ulink> source directory.
1010 You can get pre-compiled Libxml2+Libxslt DLLs and headers from
1011 <ulink url="&url.libxml2.download.windows;">here</ulink>.
1012 Should you with to compile those libraries yourself, refer to
1013 to <xref linkend="installation.windows.libxml2"/>
1018 <term><literal>HAVE_LIBXSLT</literal>,
1019 <literal>LIBXSLT_DIR</literal></term>
1022 If <literal>HAVE_LIBXSLT</literal> is set to 1, YAZ is compiled
1023 with XSLT support. In this configuration, set
1024 <literal>LIBXSLT_DIR</literal> to the
1025 <ulink url="&url.libxslt;">libxslt</ulink> source directory.
1029 libxslt depends libxml2.
1035 <term><literal>HAVE_ICU</literal>,
1036 <literal>ICU_DIR</literal></term>
1039 If <literal>HAVE_ICU</literal> is set to 1, YAZ is compiled
1040 with <ulink url="&url.icu;">ICU</ulink> support.
1041 In this configuration, set
1042 <literal>ICU_DIR</literal> to the
1043 <ulink url="&url.icu;">ICU</ulink> source directory.
1050 When satisfied with the settings in the makefile, type
1057 If the <filename>nmake</filename> command is not found on your system
1058 you probably haven't defined the environment variables required to
1059 use that tool. To fix that, find and run the batch file
1060 <filename>vcvars32.bat</filename>. You need to run it from within
1061 the command prompt or set the environment variables "globally";
1062 otherwise it doesn't work.
1066 If you wish to recompile &yaz; - for example if you modify
1067 settings in the <filename>makefile</filename> you can delete
1068 object files, etc by running.
1074 The following files are generated upon successful compilation:
1077 <term><filename>bin/yaz&soversion;.dll</filename> /
1078 <filename>bin/yaz&soversion;d.dll</filename></term>
1080 &yaz; Release/Debug DLL.
1084 <term><filename>lib/yaz&soversion;.lib</filename> /
1085 <filename>lib/yaz&soversion;d.lib</filename></term>
1087 Import library for <filename>yaz&soversion;.dll</filename> /
1088 <filename>yaz&soversion;d.dll</filename>.
1092 <term><filename>bin/yaz_cond&soversion;.dll</filename> /
1093 <filename>bin/yaz_cond&soversion;d.dll</filename></term>
1095 Release/Debug DLL for condition variable utilities (condvar.c).
1099 <term><filename>lib/yaz_cond&soversion;.lib</filename> /
1100 <filename>lib/yaz_cond&soversion;d.lib</filename></term>
1102 Import library for <filename>yaz_cond&soversion;.dll</filename> /
1103 <filename>yaz_cond&soversion;d.dll</filename>.
1107 <term><filename>bin/yaz_icu&soversion;.dll</filename> /
1108 <filename>bin/yaz_icu&soversion;d.dll</filename></term>
1110 Release/Debug DLL for the ICU wrapper utility.
1111 Only build if HAVE_ICU is 1.
1115 <term><filename>lib/yaz_icu&soversion;.lib</filename> /
1116 <filename>lib/yaz_icu&soversion;d.lib</filename></term>
1118 Import library for <filename>yaz_icu&soversion;.dll</filename> /
1119 <filename>yaz_icu&soversion;d.dll</filename>.
1123 <term><filename>bin/yaz-ztest.exe</filename></term>
1125 Z39.50 multi-threaded test/example server. It's a WIN32
1126 console application.
1130 <term><filename>bin/yaz-client.exe</filename></term>
1132 &yaz; Z39.50 client application. It's a WIN32 console application.
1133 See chapter <link linkend="yaz-client">YAZ client</link> for more
1138 <term><filename>bin/yaz-icu.exe</filename></term>
1139 <listitem><para>This program exposes the ICU wrapper library if that
1140 is enabled for YAZ. Only if ICU is available this program is
1145 <term><filename>bin/zoomsh.exe</filename></term>
1147 Simple console application implemented on top of the
1148 <link linkend="zoom">ZOOM</link> functions.
1149 The application is a command line shell that allows you to enter
1150 simple commands to perform ZOOM operations.
1154 <term><filename>bin/zoomtst1.exe</filename>,
1155 <filename>bin/zoomtst2.exe</filename>, ..</term>
1157 Several small applications that demonstrates the ZOOM API.
1164 <sect2 id="installation-linking-yaz-win32">
1165 <title>How to make apps using YAZ on Windows</title>
1167 This section will go though the process of linking your Windows
1168 applications with &yaz;.
1171 Some people are confused by the fact that we use the nmake
1172 tool to build &yaz;. They think they have to do that too - in order
1173 to make their Windows applications work with &yaz;. The good news is that
1174 you don't have to. You can use the integrated environment of
1175 Visual Studio if desired for your own application.
1178 When setting up a project or Makefile you have to set the following:
1181 <term>include path</term>
1183 Set it to the <filename>include</filename> directory of &yaz;.
1187 <term>import library <filename>yaz&soversion;.lib</filename></term>
1189 You must link with this library. It's located in the
1190 sub directory <filename>lib</filename> of &yaz;.
1191 If you want to link with the debug version of &yaz;, you must
1192 link against <filename>yaz&soversion;d.lib</filename> instead.
1196 <term>dynamic link library
1197 <filename>yaz&soversion;.dll</filename>
1200 This DLL must be in your execution path when you invoke
1201 your application. Specifically, you should distribute this
1202 DLL with your application.
1209 <sect2 id="installation.windows.libxml2">
1210 <title>Compiling Libxml2 and Libxslt on windows</title>
1212 Download libxml2 and Libxslt source and unpack it.
1213 In the example below we install Libxml2 2.9.2 and Libxslt 1.1.28
1214 for 32-bit, so we use the destination directories
1215 libxml2.2.9.2.win32 and libxslt-1.1.28.win32 to reflect both
1216 version and architecture.
1219 cscript configure.js prefix=c:\libxml2-2.9.2.win32 iconv=no
1226 There's an error in <filename>configure.js</filename> for Libxml2 2.9.2.
1227 Line 17 should be assigned to <filename>configure.ac</filename>
1228 rather than <filename>configure.in</filename>.
1232 For Libxslt it is similar. We must ensure that compilation of
1233 Libxslt links against the already installed libxml2.
1236 cscript configure.js prefix=c:\libxslt-1.1.28.win32 iconv=no \
1237 lib=c:\libxml2-2.9.2.win32\lib \
1238 include=c:\libxml2-2.9.2.win32\include\libxml2
1248 ### Still to document:
1249 ZOOM_connection_errcode(c)
1250 ZOOM_connection_errmsg(c)
1251 ZOOM_connection_addinfo(c)
1252 ZOOM_connection_addinfo(c)
1253 ZOOM_connection_diagset(c);
1254 ZOOM_connection_save_apdu_wrbuf
1255 ZOOM_diag_str(error)
1256 ZOOM_resultset_record_immediate(s, pos)
1257 ZOOM_resultset_cache_reset(r)
1258 ZOOM_options_set_callback(opt, function, handle)
1259 ZOOM_options_create_with_parent2(parent1, parent2)
1260 ZOOM_options_getl(opt, name, len)
1261 ZOOM_options_setl(opt, name, value, len)
1262 ZOOM_options_get_bool(opt, name, defa)
1263 ZOOM_options_get_int(opt, name, defa)
1264 ZOOM_options_set_int(opt, name, value)
1269 &zoom; is an acronym for 'Z39.50 Object-Orientation Model' and is
1270 an initiative started by Mike Taylor (Mike is from the UK, which
1271 explains the peculiar name of the model). The goal of &zoom; is to
1272 provide a common Z39.50 client API not bound to a particular
1273 programming language or toolkit.
1276 From YAZ version 2.1.12, <ulink url="&url.sru;">SRU</ulink> is supported.
1277 You can make SRU ZOOM connections by specifying scheme
1278 <literal>http://</literal> for the hostname for a connection.
1279 The dialect of SRU used is specified by the value of the
1280 connection's <literal>sru</literal> option, which may be SRU over
1281 HTTP GET (<literal>get</literal>),
1282 SRU over HTTP POST (<literal>post</literal>), (SRU over
1283 SOAP) (<literal>soap</literal>) or <literal>solr</literal>
1284 (<ulink url="&url.solr;">Solr</ulink> Web Service).
1285 Using the facility for embedding options in target strings, a
1286 connection can be forced to use SRU rather the SRW (the default) by
1287 prefixing the target string with <literal>sru=get,</literal>, like this:
1288 <literal>sru=get,http://sru.miketaylor.org.uk:80/sru.pl</literal>
1291 <ulink url="&url.solr;">Solr</ulink> protocol support was added to
1292 YAZ in version 4.1.0, as a dialect of a SRU protocol, since both are
1293 HTTP based protocols.
1296 The lack of a simple Z39.50 client API for &yaz; has become more
1297 and more apparent over time. So when the first &zoom; specification
1299 an implementation for &yaz; was quickly developed. For the first time, it is
1300 now as easy (or easier!) to develop clients than servers with &yaz;. This
1301 chapter describes the &zoom; C binding. Before going further, please
1302 reconsider whether C is the right programming language for the job.
1303 There are other language bindings available for &yaz;, and still
1305 are in active development. See the
1306 <ulink url="&url.zoom;">ZOOM web-site</ulink> for
1310 In order to fully understand this chapter you should read and
1311 try the example programs <literal>zoomtst1.c</literal>,
1312 <literal>zoomtst2.c</literal>, .. in the <literal>zoom</literal>
1316 The C language misses features found in object oriented languages
1317 such as C++, Java, etc. For example, you'll have to manually,
1318 destroy all objects you create, even though you may think of them as
1319 temporary. Most objects has a <literal>_create</literal> - and a
1320 <literal>_destroy</literal> variant.
1321 All objects are in fact pointers to internal stuff, but you don't see
1322 that because of typedefs. All destroy methods should gracefully ignore a
1323 <literal>NULL</literal> pointer.
1326 In each of the sections below you'll find a sub section called
1327 protocol behavior, that describes how the API maps to the Z39.50
1330 <sect1 id="zoom-connections">
1331 <title>Connections</title>
1332 <para>The Connection object is a session with a target.
1335 #include <yaz/zoom.h>
1337 ZOOM_connection ZOOM_connection_new(const char *host, int portnum);
1339 ZOOM_connection ZOOM_connection_create(ZOOM_options options);
1341 void ZOOM_connection_connect(ZOOM_connection c, const char *host,
1343 void ZOOM_connection_destroy(ZOOM_connection c);
1346 Connection objects are created with either function
1347 <function>ZOOM_connection_new</function> or
1348 <function>ZOOM_connection_create</function>.
1349 The former creates and automatically attempts to establish a network
1350 connection with the target. The latter doesn't establish
1351 a connection immediately, thus allowing you to specify options
1352 before establishing network connection using the function
1353 <function>ZOOM_connection_connect</function>.
1354 If the port number, <literal>portnum</literal>, is zero, the
1355 <literal>host</literal> is consulted for a port specification.
1356 If no port is given, 210 is used. A colon denotes the beginning of
1357 a port number in the host string. If the host string includes a
1358 slash, the following part specifies a database for the connection.
1361 You can prefix the host with a scheme followed by colon. The
1362 default scheme is <literal>tcp</literal> (Z39.50 protocol).
1363 The scheme <literal>http</literal> selects SRU/get over HTTP by default,
1364 but can overridded to use SRU/post, SRW and the Solr protocol.
1367 You can prefix the scheme-qualified host-string with one or more
1369 <literal><parameter>key</parameter>=<parameter>value</parameter></literal>
1370 sequences, each of which represents an option to be set into the
1371 connection structure <emphasis>before</emphasis> the
1372 protocol-level connection is forged and the initialization
1373 handshake takes place. This facility can be used to provide
1374 authentication credentials, as in host-strings such as:
1375 <literal>user=admin,password=halfAm4n,tcp:localhost:8017/db</literal>
1378 Connection objects should be destroyed using the function
1379 <function>ZOOM_connection_destroy</function>.
1382 void ZOOM_connection_option_set(ZOOM_connection c,
1383 const char *key, const char *val);
1385 void ZOOM_connection_option_setl(ZOOM_connection c,
1387 const char *val, int len);
1389 const char *ZOOM_connection_option_get(ZOOM_connection c,
1391 const char *ZOOM_connection_option_getl(ZOOM_connection c,
1396 The functions <function>ZOOM_connection_option_set</function> and
1397 <function>ZOOM_connection_option_setl</function> allows you to
1398 set an option given by <parameter>key</parameter> to the value
1399 <parameter>value</parameter> for the connection.
1400 For <function>ZOOM_connection_option_set</function>, the
1401 value is assumed to be a 0-terminated string. Function
1402 <function>ZOOM_connection_option_setl</function> specifies a
1403 value of a certain size (len).
1406 Functions <function>ZOOM_connection_option_get</function> and
1407 <function>ZOOM_connection_option_getl</function> returns
1408 the value for an option given by <parameter>key</parameter>.
1410 <table id="zoom-connection-options" frame="top">
1411 <title>ZOOM Connection Options</title>
1413 <colspec colwidth="4*" colname="name"></colspec>
1414 <colspec colwidth="7*" colname="description"></colspec>
1415 <colspec colwidth="3*" colname="default"></colspec>
1418 <entry>Option</entry>
1419 <entry>Description</entry>
1420 <entry>Default</entry>
1425 implementationName</entry><entry>Name of Your client
1426 </entry><entry>none</entry></row>
1428 user</entry><entry>Authentication user name
1429 </entry><entry>none</entry></row>
1431 group</entry><entry>Authentication group name
1432 </entry><entry>none</entry></row>
1434 password</entry><entry>Authentication password.
1435 </entry><entry>none</entry></row>
1437 authenticationMode</entry><entry>How authentication is encoded.
1438 </entry><entry>basic</entry></row>
1440 host</entry><entry>Target host. This setting is "read-only".
1441 It's automatically set internally when connecting to a target.
1442 </entry><entry>none</entry></row>
1444 proxy</entry><entry>Proxy host. If set, the logical host
1445 is encoded in the otherInfo area of the Z39.50 Init PDU
1446 with OID 1.2.840.10003.10.1000.81.1.
1447 </entry><entry>none</entry></row>
1449 clientIP</entry><entry>Client IP. If set, is
1450 encoded in the otherInfo area of a Z39.50 PDU with OID
1451 1.2.840.10003.10.1000.81.3. Holds the original IP addreses
1452 of a client. Is used of ZOOM is used in a gateway of some sort.
1453 </entry><entry>none</entry></row>
1455 async</entry><entry>If true (1) the connection operates in
1456 asynchronous operation which means that all calls are non-blocking
1458 <link linkend="zoom.events"><function>ZOOM_event</function></link>.
1459 </entry><entry>0</entry></row>
1461 maximumRecordSize</entry><entry> Maximum size of single record.
1462 </entry><entry>1 MB</entry></row>
1464 preferredMessageSize</entry><entry> Maximum size of multiple records.
1465 </entry><entry>1 MB</entry></row>
1467 lang</entry><entry> Language for negotiation.
1468 </entry><entry>none</entry></row>
1470 charset</entry><entry> Character set for negotiation.
1471 </entry><entry>none</entry></row>
1473 serverImplementationId</entry><entry>
1474 Implementation ID of server. (The old targetImplementationId
1475 option is also supported for the benefit of old applications.)
1476 </entry><entry>none</entry></row>
1478 targetImplementationName</entry><entry>
1479 Implementation Name of server. (The old
1480 targetImplementationName option is also supported for the
1481 benefit of old applications.)
1482 </entry><entry>none</entry></row>
1484 serverImplementationVersion</entry><entry>
1485 Implementation Version of server. (the old
1486 targetImplementationVersion option is also supported for the
1487 benefit of old applications.)
1488 </entry><entry>none</entry></row>
1490 databaseName</entry><entry>One or more database names
1491 separated by character plus (<literal>+</literal>), which to
1492 be used by subsequent search requests on this Connection.
1493 </entry><entry>Default</entry></row>
1495 piggyback</entry><entry>True (1) if piggyback should be
1496 used in searches; false (0) if not.
1497 </entry><entry>1</entry></row>
1499 smallSetUpperBound</entry><entry>If hits is less than or equal to this
1500 value, then target will return all records using small element set name
1501 </entry><entry>0</entry></row>
1503 largeSetLowerBound</entry><entry>If hits is greater than this
1504 value, the target will return no records.
1505 </entry><entry>1</entry></row>
1507 mediumSetPresentNumber</entry><entry>This value represents
1508 the number of records to be returned as part of a search when when
1509 hits is less than or equal to large set lower bound and if hits
1510 is greater than small set upper bound.
1511 </entry><entry>0</entry></row>
1513 smallSetElementSetName</entry><entry>
1514 The element set name to be used for small result sets.
1515 </entry><entry>none</entry></row>
1517 mediumSetElementSetName</entry><entry>
1518 The element set name to be for medium-sized result sets.
1519 </entry><entry>none</entry></row>
1521 init_opt_search, init_opt_present, init_opt_delSet, etc.</entry><entry>
1522 After a successful Init, these options may be interrogated to
1523 discover whether the server claims to support the specified
1525 </entry><entry>none</entry></row>
1527 <entry>sru</entry><entry>
1528 SRU/Solr transport type. Must be either <literal>soap</literal>,
1529 <literal>get</literal>, <literal>post</literal>, or
1530 <literal>solr</literal>.
1531 </entry><entry>soap</entry></row>
1533 sru_version</entry><entry>
1534 SRU/SRW version. Should be <literal>1.1</literal>, or
1535 <literal>1.2</literal>. This is , prior to connect, the version
1536 to offer (highest version). And following connect (in fact
1537 first operation), holds the negotiated version with the server
1538 (same or lower version).
1539 </entry><entry>1.2</entry></row>
1540 <row id="zoom.extraArgs.option"><entry>
1541 extraArgs</entry><entry>
1542 Extra arguments for SRU/Solr URLs. The value must be
1543 URL encoded already.
1544 </entry><entry></entry></row>
1545 <row id="zoom.facets.option"><entry>
1546 facets</entry><entry>
1547 Requested or recommend facets may be given before a search is sent.
1548 The value of this setting is described in <xref linkend="facets"/>
1549 For inspection of the facets returned, refer to the functions
1550 described in <xref linkend="zoom.facets"/>.
1551 </entry><entry>none</entry></row>
1553 apdulog</entry><entry>
1554 If set to a true value such as "1", a log of low-level
1555 protocol packets is emitted on standard error stream. This
1556 can be very useful for debugging.
1557 </entry><entry>0</entry></row>
1559 saveAPDU</entry><entry>
1560 If set to a true value such as "1", a log of low-level
1561 protocol packets is saved. The log can be retrieved by reading
1562 option APDU. Setting saveAPDU always has the side effect of
1563 resetting the currently saved log. This setting is
1564 <emphasis>write-only</emphasis>. If read, NULL will be returned.
1565 It is only recognized in
1566 <function>ZOOM_connection_option_set</function>.
1567 </entry><entry>0</entry></row>
1570 Returns the log of protocol packets. Will be empty if logging
1571 is not enabled (see saveAPDU above). This setting is
1572 <emphasis>read-only</emphasis>. It is only recognized if used
1573 in call to <function>ZOOM_connection_option_get</function> or
1574 <function>ZOOM_connection_option_getl</function>.
1575 </entry><entry></entry></row>
1577 memcached</entry><entry>
1578 If given and non-empty,
1579 <ulink url="&url.libmemcached;">libMemcached</ulink>
1580 will be configured for the connection.
1581 This option is inspected by ZOOM when a connection is established.
1582 If the <literal>memcached</literal> option is given
1583 and YAZ is compiled without libMemcached support, an internal
1584 diagnostic (10018) will be thrown.
1585 libMemcached support is available for YAZ 5.0.13 or later. If this
1586 option is supplied for an earlier version of YAZ, it is
1587 <emphasis>ignored</emphasis>.
1588 The value of this option is a list options - each is of the
1589 form <literal>--name=value</literal>.
1590 Option <literal>--server=</literal>host[:port] specifies a memcached
1591 server. It may be repeated for multiple memcached servers.
1592 Option <literal>--expire=</literal>seconds sets expiry time in seconds
1593 for how long result sets are to be cached.
1594 </entry><entry>none</entry></row>
1596 redis</entry><entry>
1597 If given and non-empty,
1598 a <ulink url="&url.redis;">redis</ulink> context will be created
1600 This option is inspected by ZOOM when a connection is established.
1601 If the <literal>redis</literal> option is given
1602 and YAZ is compiled without redis support, an internal
1603 diagnostic (10018) will be thrown.
1604 redis support is available for YAZ 5.2.0 or later. If this
1605 option is supplied for an earlier version of YAZ, it is
1606 <emphasis>ignored</emphasis>.
1607 The value of this option is a set options, similar to that
1608 of the memcached setting. At this stage only --server=host[:port]
1609 and --expire=seconds is supported.
1610 </entry><entry>none</entry></row>
1615 If either option <literal>lang</literal> or <literal>charset</literal>
1617 <ulink url="&url.z39.50.charneg;">
1618 Character Set and Language Negotiation</ulink> is in effect.
1621 int ZOOM_connection_error(ZOOM_connection c, const char **cp,
1622 const char **addinfo);
1623 int ZOOM_connection_error_x(ZOOM_connection c, const char **cp,
1624 const char **addinfo, const char **dset);
1627 Function <function>ZOOM_connection_error</function> checks for
1628 errors for the last operation(s) performed. The function returns
1629 zero if no errors occurred; non-zero otherwise indicating the error.
1630 Pointers <parameter>cp</parameter> and <parameter>addinfo</parameter>
1631 holds messages for the error and additional-info if passed as
1632 non-<literal>NULL</literal>. Function
1633 <function>ZOOM_connection_error_x</function> is an extended version
1634 of <function>ZOOM_connection_error</function> that is capable of
1635 returning name of diagnostic set in <parameter>dset</parameter>.
1637 <sect2 id="zoom-connection-z39.50">
1638 <title>Z39.50 Protocol behavior</title>
1640 The calls <function>ZOOM_connection_new</function> and
1641 <function>ZOOM_connection_connect</function> establishes a TCP/IP
1642 connection and sends an Initialize Request to the target if
1643 possible. In addition, the calls waits for an Initialize Response
1644 from the target and the result is inspected (OK or rejected).
1647 If <literal>proxy</literal> is set then the client will establish
1648 a TCP/IP connection with the peer as specified by the
1649 <literal>proxy</literal> host and the hostname as part of the
1650 connect calls will be set as part of the Initialize Request.
1651 The proxy server will then "forward" the PDU's transparently
1652 to the target behind the proxy.
1655 For the authentication parameters, if option <literal>user</literal>
1656 is set and both options <literal>group</literal> and
1657 <literal>pass</literal> are unset, then Open style
1658 authentication is used (Version 2/3) in which case the username
1659 is usually followed by a slash, then by a password.
1660 If either <literal>group</literal>
1661 or <literal>pass</literal> is set then idPass authentication
1662 (Version 3 only) is used. If none of the options are set, no
1663 authentication parameters are set as part of the Initialize Request
1667 When option <literal>async</literal> is 1, it really means that
1668 all network operations are postponed (and queued) until the
1669 function <literal>ZOOM_event</literal> is invoked. When doing so
1670 it doesn't make sense to check for errors after
1671 <literal>ZOOM_connection_new</literal> is called since that
1672 operation "connecting - and init" is still incomplete and the
1673 API cannot tell the outcome (yet).
1676 <sect2 id="zoom.sru.init.behavior">
1677 <title>SRU/Solr Protocol behavior</title>
1679 The HTTP based protocols (SRU, SRW, Solr) doesn't feature an
1680 Inititialize Request, so the connection phase merely establishes a
1681 TCP/IP connection with the HTTP server.
1683 <para>Most of the ZOOM connection options do not
1684 affect SRU/Solr and they are ignored. However, future versions
1685 of &yaz; might honor <literal>implementationName</literal> and
1686 put that as part of User-Agent header for HTTP requests.
1689 The <literal>charset</literal> is used in the Content-Type header
1693 Setting <literal>authentcationMode</literal> specifies how
1694 authentication parameters are encoded for HTTP. The default is
1695 "<literal>basic</literal>" where <literal>user</literal> and
1696 <literal>password</literal> are encoded by using HTTP basic
1700 If <literal>authentcationMode</literal> is "<literal>url</literal>", then
1701 user and password are encoded in the URL by parameters
1702 <literal>x-username</literal> and <literal>x-password</literal> as
1703 given by the SRU standard.
1707 <sect1 id="zoom.query">
1708 <title>Queries</title>
1710 Query objects represents queries.
1713 ZOOM_query ZOOM_query_create(void);
1715 void ZOOM_query_destroy(ZOOM_query q);
1717 int ZOOM_query_prefix(ZOOM_query q, const char *str);
1719 int ZOOM_query_cql(ZOOM_query s, const char *str);
1721 int ZOOM_query_sortby(ZOOM_query q, const char *criteria);
1723 int ZOOM_query_sortby2(ZOOM_query q, const char *strategy,
1724 const char *criteria);
1727 Create query objects using <function>ZOOM_query_create</function>
1728 and destroy them by calling <function>ZOOM_query_destroy</function>.
1729 RPN-queries can be specified in <link linkend="PQF">PQF</link>
1730 notation by using the
1731 function <function>ZOOM_query_prefix</function>.
1732 The <function>ZOOM_query_cql</function> specifies a CQL
1733 query to be sent to the server/target.
1734 More query types will be added in future versions of &yaz;, such as
1735 <link linkend="CCL">CCL</link> to RPN-mapping, native CCL query,
1736 etc. In addition to a search, a sort criteria may be set. Function
1737 <function>ZOOM_query_sortby</function> enables Z39.50 sorting and
1738 it takes sort criteria using the same string notation as
1739 yaz-client's <link linkend="sortspec">sort command</link>.
1741 <para id="zoom.query.sortby2">
1742 <function>ZOOM_query_sortby2</function> is similar to
1743 <function>ZOOM_query_sortby</function> but allows a strategy for
1744 sorting. The reason for the strategy parameter is that some
1745 protocols offers multiple ways of performing sorting.
1746 For example, Z39.50 has the standard sort, which is performed after
1747 search on an existing result set.
1748 It's also possible to use CQL in Z39.50 as the query type and use
1749 CQL's SORTBY keyword. Finally, Index Data's
1750 Zebra server also allows sorting to be specified as part of RPN (Type 7).
1752 <table id="zoom-sort-strategy" frame="top">
1753 <title>ZOOM sort strategy</title>
1755 <colspec colwidth="2*" colname="name"/>
1756 <colspec colwidth="5*" colname="description"/>
1760 <entry>Description</entry>
1765 <entry>z39.50</entry><entry>Z39.50 resultset sort</entry>
1768 <entry>type7</entry><entry>Sorting embedded in RPN(Type-7)</entry>
1771 <entry>cql</entry><entry>CQL SORTBY</entry>
1774 <entry>sru11</entry><entry>SRU sortKeys parameter</entry>
1777 <entry>solr</entry><entry>Solr sort</entry>
1780 <entry>embed</entry><entry>type7 for Z39.50, cql for SRU,
1781 solr for Solr protocol</entry>
1787 <sect1 id="zoom.resultsets"><title>Result sets</title>
1789 The result set object is a container for records returned from
1793 ZOOM_resultset ZOOM_connection_search(ZOOM_connection, ZOOM_query q);
1795 ZOOM_resultset ZOOM_connection_search_pqf(ZOOM_connection c,
1797 void ZOOM_resultset_destroy(ZOOM_resultset r);
1800 Function <function>ZOOM_connection_search</function> creates
1801 a result set given a connection and query.
1802 Destroy a result set by calling
1803 <function>ZOOM_resultset_destroy</function>.
1804 Simple clients may using PQF only may use function
1805 <function>ZOOM_connection_search_pqf</function> in which case
1806 creating query objects is not necessary.
1809 void ZOOM_resultset_option_set(ZOOM_resultset r,
1810 const char *key, const char *val);
1812 const char *ZOOM_resultset_option_get(ZOOM_resultset r, const char *key);
1814 size_t ZOOM_resultset_size(ZOOM_resultset r);
1817 Functions <function>ZOOM_resultset_options_set</function> and
1818 <function>ZOOM_resultset_get</function> sets and gets an option
1819 for a result set similar to <function>ZOOM_connection_option_get</function>
1820 and <function>ZOOM_connection_option_set</function>.
1823 The number of hits also called result-count is returned by
1824 function <function>ZOOM_resultset_size</function>.
1826 <table id="zoom.resultset.options"
1827 frame="top"><title>ZOOM Result set Options</title>
1829 <colspec colwidth="4*" colname="name"></colspec>
1830 <colspec colwidth="7*" colname="description"></colspec>
1831 <colspec colwidth="2*" colname="default"></colspec>
1834 <entry>Option</entry>
1835 <entry>Description</entry>
1836 <entry>Default</entry>
1841 start</entry><entry>Offset of first record to be
1842 retrieved from target. First record has offset 0 unlike the
1843 protocol specifications where first record has position 1.
1844 This option affects ZOOM_resultset_search and
1845 ZOOM_resultset_search_pqf and must be set before any of
1846 these functions are invoked. If a range of
1847 records must be fetched manually after search,
1848 function ZOOM_resultset_records should be used.
1849 </entry><entry>0</entry></row>
1851 count</entry><entry>Number of records to be retrieved.
1852 This option affects ZOOM_resultset_search and
1853 ZOOM_resultset_search_pqf and must be set before any of
1854 these functions are invoked.
1855 </entry><entry>0</entry></row>
1857 presentChunk</entry><entry>The number of records to be
1858 requested from the server in each chunk (present request). The
1859 value 0 means to request all the records in a single chunk.
1860 (The old <literal>step</literal>
1861 option is also supported for the benefit of old applications.)
1862 </entry><entry>0</entry></row>
1864 elementSetName</entry><entry>Element-Set name of records.
1865 Most targets should honor element set name <literal>B</literal>
1866 and <literal>F</literal> for brief and full respectively.
1867 </entry><entry>none</entry></row>
1869 preferredRecordSyntax</entry><entry>Preferred Syntax, such as
1870 <literal>USMARC</literal>, <literal>SUTRS</literal>, etc.
1871 </entry><entry>none</entry></row>
1873 schema</entry><entry>Schema for retrieval, such as
1874 <literal>Gils-schema</literal>, <literal>Geo-schema</literal>, etc.
1875 </entry><entry>none</entry></row>
1877 setname</entry><entry>Name of Result Set (Result Set ID).
1878 If this option isn't set, the ZOOM module will automatically
1879 allocate a result set name.
1880 </entry><entry>default</entry></row>
1882 rpnCharset</entry><entry>Character set for RPN terms.
1883 If this is set, ZOOM C will assume that the ZOOM application is
1884 running UTF-8. Terms in RPN queries are then converted to the
1885 rpnCharset. If this is unset, ZOOM C will not assume any encoding
1886 of RPN terms and no conversion is performed.
1887 </entry><entry>none</entry></row>
1892 For servers that support Search Info report, the following
1893 options may be read using <function>ZOOM_resultset_get</function>.
1894 This detailed information is read after a successful search has
1898 This information is a list of of items, where each item is
1899 information about a term or subquery. All items in the list
1901 <literal>SearchResult.</literal><replaceable>no</replaceable>
1902 where no presents the item number (0=first, 1=second).
1903 Read <literal>searchresult.size</literal> to determine the
1906 <table id="zoom.search.info.report.options"
1907 frame="top"><title>Search Info Report Options</title>
1909 <colspec colwidth="4*" colname="name"></colspec>
1910 <colspec colwidth="7*" colname="description"></colspec>
1913 <entry>Option</entry>
1914 <entry>Description</entry>
1919 <entry>searchresult.size</entry>
1921 number of search result entries. This option is-nonexistant
1922 if no entries are returned by the server.
1926 <entry>searchresult.<replaceable>no</replaceable>.id</entry>
1927 <entry>sub query ID</entry>
1930 <entry>searchresult.<replaceable>no</replaceable>.count</entry>
1931 <entry>result count for item (number of hits)</entry>
1934 <entry>searchresult.<replaceable>no</replaceable>.subquery.term</entry>
1935 <entry>subquery term</entry>
1939 searchresult.<replaceable>no</replaceable>.interpretation.term
1941 <entry>interpretation term</entry>
1945 searchresult.<replaceable>no</replaceable>.recommendation.term
1947 <entry>recommendation term</entry>
1952 <sect2 id="zoom.z3950.resultset.sort">
1953 <title>Z39.50 Result-set Sort</title>
1955 void ZOOM_resultset_sort(ZOOM_resultset r,
1956 const char *sort_type, const char *sort_spec);
1958 int ZOOM_resultset_sort1(ZOOM_resultset r,
1959 const char *sort_type, const char *sort_spec);
1962 <function>ZOOM_resultset_sort</function> and
1963 <function>ZOOM_resultset_sort1</function> both sort an existing
1964 result-set. The sort_type parameter is not use. Set it to "yaz".
1965 The sort_spec is same notation as ZOOM_query_sortby and identical
1966 to that offered by yaz-client's
1967 <link linkend="sortspec">sort command</link>.
1970 These functions only work for Z39.50. Use the more generic utility
1971 <link linkend="zoom.query.sortby2">
1972 <function>ZOOM_query_sortby2</function></link>
1973 for other protocols (and even Z39.50).
1976 <sect2 id="zoom.z3950.resultset.behavior">
1977 <title>Z39.50 Protocol behavior</title>
1979 The creation of a result set involves at least a SearchRequest
1980 - SearchResponse protocol handshake. Following that, if a sort
1981 criteria was specified as part of the query, a SortRequest -
1982 SortResponse handshake takes place. Note that it is necessary to
1983 perform sorting before any retrieval takes place, so no records will
1984 be returned from the target as part of the SearchResponse because these
1985 would be unsorted. Hence, piggyback is disabled when sort criteria
1986 are set. Following Search - and a possible sort - Retrieval takes
1987 place - as one or more Present Requests/Response pairs being
1991 The API allows for two different modes for retrieval. A high level
1992 mode which is somewhat more powerful and a low level one.
1993 The low level is enabled when searching on a Connection object
1994 for which the settings
1995 <literal>smallSetUpperBound</literal>,
1996 <literal>mediumSetPresentNumber</literal> and
1997 <literal>largeSetLowerBound</literal> are set. The low level mode
1998 thus allows you to precisely set how records are returned as part
1999 of a search response as offered by the Z39.50 protocol.
2000 Since the client may be retrieving records as part of the
2001 search response, this mode doesn't work well if sorting is used.
2004 The high-level mode allows you to fetch a range of records from
2005 the result set with a given start offset. When you use this mode
2006 the client will automatically use piggyback if that is possible
2007 with the target and perform one or more present requests as needed.
2008 Even if the target returns fewer records as part of a present response
2009 because of a record size limit, etc. the client will repeat sending
2010 present requests. As an example, if option <literal>start</literal>
2011 is 0 (default) and <literal>count</literal> is 4, and
2012 <literal>piggyback</literal> is 1 (default) and no sorting criteria
2013 is specified, then the client will attempt to retrieve the 4
2014 records as part the search response (using piggyback). On the other
2015 hand, if either <literal>start</literal> is positive or if
2016 a sorting criteria is set, or if <literal>piggyback</literal>
2017 is 0, then the client will not perform piggyback but send Present
2021 If either of the options <literal>mediumSetElementSetName</literal> and
2022 <literal>smallSetElementSetName</literal> are unset, the value
2023 of option <literal>elementSetName</literal> is used for piggyback
2024 searches. This means that for the high-level mode you only have
2025 to specify one elementSetName option rather than three.
2028 <sect2 id="zoom.sru.resultset.behavior">
2029 <title>SRU Protocol behavior</title>
2031 Current version of &yaz; does not take advantage of a result set id
2032 returned by the SRU server. Future versions might do, however.
2033 Since, the ZOOM driver does not save result set IDs any
2034 present (retrieval) is transformed to a SRU SearchRetrieveRequest
2035 with same query but, possibly, different offsets.
2038 Option <literal>schema</literal> specifies SRU schema
2039 for retrieval. However, options <literal>elementSetName</literal> and
2040 <literal>preferredRecordSyntax</literal> are ignored.
2043 Options <literal>start</literal> and <literal>count</literal>
2044 are supported by SRU.
2045 The remaining options
2046 <literal>piggyback</literal>,
2047 <literal>smallSetUpperBound</literal>,
2048 <literal>largeSetLowerBound</literal>,
2049 <literal>mediumSetPresentNumber</literal>,
2050 <literal>mediumSetElementSetName</literal>,
2051 <literal>smallSetElementSetName</literal> are
2055 SRU supports CQL queries, <emphasis>not</emphasis> PQF.
2056 If PQF is used, however, the PQF query is transferred anyway
2057 using non-standard element <literal>pQuery</literal> in
2058 SRU SearchRetrieveRequest.
2061 Solr queries has to be done in Solr query format.
2064 Unfortunately, SRU or Solr does not define a database setting. Hence,
2065 <literal>databaseName</literal> is unsupported and ignored.
2066 However, the path part in host parameter for functions
2067 <function>ZOOM_connecton_new</function> and
2068 <function>ZOOM_connection_connect</function> acts as a
2069 database (at least for the &yaz; SRU server).
2073 <sect1 id="zoom.records">
2074 <title>Records</title>
2076 A record object is a retrieval record on the client side -
2077 created from result sets.
2080 void ZOOM_resultset_records(ZOOM_resultset r,
2082 size_t start, size_t count);
2083 ZOOM_record ZOOM_resultset_record(ZOOM_resultset s, size_t pos);
2085 const char *ZOOM_record_get(ZOOM_record rec, const char *type,
2088 int ZOOM_record_error(ZOOM_record rec, const char **msg,
2089 const char **addinfo, const char **diagset);
2091 ZOOM_record ZOOM_record_clone(ZOOM_record rec);
2093 void ZOOM_record_destroy(ZOOM_record rec);
2096 References to temporary records are returned by functions
2097 <function>ZOOM_resultset_records</function> or
2098 <function>ZOOM_resultset_record</function>.
2101 If a persistent reference to a record is desired
2102 <function>ZOOM_record_clone</function> should be used.
2103 It returns a record reference that should be destroyed
2104 by a call to <function>ZOOM_record_destroy</function>.
2107 A single record is returned by function
2108 <function>ZOOM_resultset_record</function> that takes a
2109 position as argument. First record has position zero.
2110 If no record could be obtained <literal>NULL</literal> is returned.
2113 Error information for a record can be checked with
2114 <function>ZOOM_record_error</function> which returns non-zero
2115 (error code) if record is in error, called <emphasis>Surrogate
2116 Diagnostics</emphasis> in Z39.50.
2119 Function <function>ZOOM_resultset_records</function> retrieves
2120 a number of records from a result set. Parameter <literal>start</literal>
2121 and <literal>count</literal> specifies the range of records to
2122 be returned. Upon completion array
2123 <literal>recs[0], ..recs[count-1]</literal>
2124 holds record objects for the records. The array of records
2125 <literal>recs</literal> should be allocated prior the call
2126 <function>ZOOM_resultset_records</function>. Note that for those
2127 records that couldn't be retrieved from the target
2128 <literal>recs[ ..]</literal> is set to <literal>NULL</literal>.
2130 <para id="zoom.record.get">
2131 In order to extract information about a single record,
2132 <function>ZOOM_record_get</function> is provided. The
2133 function returns a pointer to certain record information. The
2134 nature (type) of the pointer depends on the parameter,
2135 <parameter>type</parameter>.
2138 The <parameter>type</parameter> is a string of the format:
2141 <replaceable>format</replaceable>[;charset=<replaceable>from</replaceable>[/<replaceable>opacfrom</replaceable>][,<replaceable>to</replaceable>]][;format=<replaceable>v</replaceable>][;base64=<replaceable>xpath</replaceable>]
2144 If <literal>charset</literal> is given, then <replaceable>from</replaceable>
2145 specifies the character set of the record in its original form
2146 (as returned by the server), <replaceable>to</replaceable> specifies
2147 the output (returned) character set encoding.
2148 If <replaceable>to</replaceable> is omitted, then UTF-8 is assumed.
2149 If charset is not given, then no character set conversion takes place.
2150 OPAC records may be returned in a different
2151 set from the bibliographic MARC record. If this is this the case,
2152 <replaceable>opacfrom</replaceable> should be set to the character set
2153 of the OPAC record part.
2157 The <literal>format</literal> is generic but can only be used to
2158 specify XML indentation when the value <replaceable>v</replaceable>
2159 is 1 (<literal>format=1</literal>).
2162 The <literal>base64</literal> allows a full record to be extracted
2163 from base64-encoded string in an XML document.
2167 Specifying the OPAC record character set requires YAZ 4.1.5 or later.
2170 Specifying the base64 parameter requires YAZ 4.2.35 or later.
2174 The format argument controls whether record data should be XML
2175 pretty-printed (post process operation).
2176 It is enabled only if format value <replaceable>v</replaceable> is
2177 <literal>1</literal> and the record content is XML well-formed.
2180 In addition, for certain types, the length
2181 <literal>len</literal> passed will be set to the size in bytes of
2182 the returned information.
2185 The following are the supported values for <replaceable>form</replaceable>.
2187 <varlistentry><term><literal>database</literal></term>
2188 <listitem><para>Database of record is returned
2189 as a C null-terminated string. Return type
2190 <literal>const char *</literal>.
2193 <varlistentry><term><literal>syntax</literal></term>
2194 <listitem><para>The transfer syntax of the record is returned
2195 as a C null-terminated string containing the symbolic name of
2196 the record syntax, e.g. <literal>Usmarc</literal>. Return type
2198 <literal>const char *</literal>.
2201 <varlistentry><term><literal>schema</literal></term>
2202 <listitem><para>The schema of the record is returned
2203 as a C null-terminated string. Return type is
2204 <literal>const char *</literal>.
2207 <varlistentry><term><literal>render</literal></term>
2208 <listitem><para>The record is returned in a display friendly
2209 format. Upon completion buffer is returned
2210 (type <literal>const char *</literal>) and length is stored in
2211 <literal>*len</literal>.
2214 <varlistentry><term><literal>raw</literal></term>
2215 <listitem><para>The record is returned in the internal
2216 YAZ specific format. For GRS-1, Explain, and others, the
2217 raw data is returned as type
2218 <literal>Z_External *</literal> which is just the type for
2219 the member <literal>retrievalRecord</literal> in
2220 type <literal>NamePlusRecord</literal>.
2221 For SUTRS and octet aligned record (including all MARCs) the
2222 octet buffer is returned and the length of the buffer.
2225 <varlistentry><term><literal>xml</literal></term>
2226 <listitem><para>The record is returned in XML if possible.
2227 SRU, Solr and Z39.50 records with transfer syntax XML are
2228 returned verbatim. MARC records are returned in
2229 <ulink url="&url.marcxml;">
2232 (converted from ISO2709 to MARCXML by YAZ).
2233 OPAC records are also converted to XML and the
2234 bibliographic record is converted to MARCXML (when possible).
2235 GRS-1 records are not supported for this form.
2236 Upon completion, the XML buffer is returned
2237 (type <literal>const char *</literal>) and length is stored in
2238 <literal>*len</literal>.
2241 <varlistentry><term><literal>opac</literal></term>
2242 <listitem><para>OPAC information for record is returned in XML
2243 if an OPAC record is present at the position given. If no
2244 OPAC record is present, a NULL pointer is returned.
2247 <varlistentry><term><literal>txml</literal></term>
2248 <listitem><para>The record is returned in TurboMARC if possible.
2249 SRU and Z39.50 records with transfer syntax XML are
2250 returned verbatim. MARC records are returned in
2251 <link linkend="tools.turbomarc">
2254 (converted from ISO2709 to TurboMARC by YAZ).
2255 Upon completion, the XML buffer is returned
2256 (type <literal>const char *</literal>) and length is stored in
2257 <literal>*len</literal>.
2260 <varlistentry><term><literal>json</literal></term>
2261 <listitem><para>Like xml, but MARC records are converted to
2262 <ulink url="&url.marc_in_json;">MARC-in-JSON</ulink>.
2270 <ulink url="&url.marc21;">MARC21</ulink>
2272 <ulink url="&url.marc8;">MARC-8</ulink>
2273 character set encoding.
2274 An application that wishes to display in Latin-1 would use
2276 render; charset=marc8,iso-8859-1
2279 <sect2 id="zoom.z3950.record.behavior">
2280 <title>Z39.50 Protocol behavior</title>
2282 The functions <function>ZOOM_resultset_record</function> and
2283 <function>ZOOM_resultset_records</function> inspects the client-side
2284 record cache. Records not found in cache are fetched using
2286 The functions may block (and perform network I/O) - even though option
2287 <literal>async</literal> is 1, because they return records objects.
2288 (and there's no way to return records objects without retrieving them!).
2291 There is a trick, however, in the usage of function
2292 <function>ZOOM_resultset_records</function> that allows for
2293 delayed retrieval (and makes it non-blocking). By using
2294 a null pointer for <parameter>recs</parameter> you're indicating
2295 you're not interested in getting records objects
2296 <emphasis>now</emphasis>.
2299 <sect2 id="zoom.sru.record.behavior">
2300 <title>SRU/Solr Protocol behavior</title>
2302 The ZOOM driver for SRU/Solr treats records returned by a SRU/Solr server
2303 as if they where Z39.50 records with transfer syntax XML and
2304 no element set name or database name.
2308 <sect1 id="zoom.facets"><title>Facets</title>
2310 Facet operations is not part of the official ZOOM specification, but
2311 is an Index Data extension for YAZ-based Z39.50 targets,
2312 <ulink url="&url.solr;">Solr</ulink> and SRU 2.0 targets.
2314 Facets may be requestd by the
2315 <link linkend="zoom.facets.option">facets</link> option before a
2317 For inspection of the returned facets, the following functions are
2321 ZOOM_facet_field *ZOOM_resultset_facets(ZOOM_resultset r);
2323 ZOOM_facet_field ZOOM_resultset_get_facet_field(ZOOM_resultset r,
2324 const char *facet_name);
2326 ZOOM_facet_field ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r,
2329 size_t ZOOM_resultset_facets_size(ZOOM_resultset r);
2331 const char *ZOOM_facet_field_name(ZOOM_facet_field facet_field);
2333 size_t ZOOM_facet_field_term_count(ZOOM_facet_field facet_field);
2335 const char *ZOOM_facet_field_get_term(ZOOM_facet_field facet_field,
2336 size_t idx, int *freq);
2339 References to temporary structures are returned by all functions.
2340 They are only valid as long the Result set is valid.
2341 <function>ZOOM_resultset_get_facet_field</function> or
2342 <function>ZOOM_resultset_get_facet_field_by_index</function>.
2343 <function>ZOOM_resultset_facets</function>.
2344 <function>ZOOM_facet_field_name</function>.
2345 <function>ZOOM_facet_field_get_term</function>.
2347 <para id="zoom.resultset.get_facet_field">
2348 A single Facet field is returned by function
2349 <function>ZOOM_resultset_get_facet_field</function> or
2350 <function>ZOOM_resultset_get_facet_field_by_index</function> that takes
2351 a result set and facet name or positive index respectively. First
2352 facet has position zero. If no facet could be obtained (invalid name
2353 or index out of bounds) <literal>NULL</literal> is returned.
2355 <para id="zoom.resultset.facets">
2356 An array of facets field can be returned by
2357 <function>ZOOM_resultset_facets</function>. The length of the array is
2358 given by <function>ZOOM_resultset_facets_size</function>. The array is
2359 zero-based and last entry will be at
2360 <function>ZOOM_resultset_facets_size(result_set)</function>-1.
2362 <para id="zoom.resultset.facets_names">
2363 It is possible to interate over facets by name, by calling
2364 <function>ZOOM_resultset_facets_names</function>.
2365 This will return an const array of char * where each string can be used
2366 as parameter for <function>ZOOM_resultset_get_facet_field</function>.
2369 Function <function>ZOOM_facet_field_name</function> gets the request
2370 facet name from a returned facet field.
2373 Function <function>ZOOM_facet_field_get_term</function> returns the
2374 idx'th term and term count for a facet field.
2375 Idx must between 0 and
2376 <function>ZOOM_facet_field_term_count</function>-1, otherwise the
2377 returned reference will be <literal>NULL</literal>. On a valid idx, the
2378 value of the freq reference will be the term count.
2379 The <literal>freq</literal> parameter must be valid pointer to integer.
2382 <sect1 id="zoom.scan"><title>Scan</title>
2384 This section describes an interface for Scan. Scan is not an
2385 official part of the ZOOM model yet. The result of a scan operation
2386 is the <literal>ZOOM_scanset</literal> which is a set of terms
2387 returned by a target.
2391 The Scan interface is supported for both Z39.50, SRU and Solr.
2395 ZOOM_scanset ZOOM_connection_scan(ZOOM_connection c,
2396 const char *startpqf);
2398 ZOOM_scanset ZOOM_connection_scan1(ZOOM_connection c,
2401 size_t ZOOM_scanset_size(ZOOM_scanset scan);
2403 const char *ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
2404 size_t *occ, size_t *len);
2406 const char *ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
2407 size_t *occ, size_t *len);
2409 void ZOOM_scanset_destroy(ZOOM_scanset scan);
2411 const char *ZOOM_scanset_option_get(ZOOM_scanset scan,
2414 void ZOOM_scanset_option_set(ZOOM_scanset scan, const char *key,
2418 The scan set is created by function
2419 <function>ZOOM_connection_scan</function> which performs a scan
2420 operation on the connection using the specified
2421 <parameter>startpqf</parameter>.
2422 If the operation was successful, the size of the scan set can be
2423 retrieved by a call to <function>ZOOM_scanset_size</function>.
2424 Like result sets, the items are numbered 0,..size-1.
2425 To obtain information about a particular scan term, call function
2426 <function>ZOOM_scanset_term</function>. This function takes
2427 a scan set offset <literal>pos</literal> and returns a pointer
2428 to a <emphasis>raw term</emphasis> or <literal>NULL</literal> if
2430 If present, the <literal>occ</literal> and <literal>len</literal>
2431 are set to the number of occurrences and the length
2432 of the actual term respectively.
2433 <function>ZOOM_scanset_display_term</function> is similar to
2434 <function>ZOOM_scanset_term</function> except that it returns
2435 the <emphasis>display term</emphasis> rather than the raw term.
2436 In a few cases, the term is different from display term. Always
2437 use the display term for display and the raw term for subsequent
2438 scan operations (to get more terms, next scan result, etc).
2441 A scan set may be freed by a call to function
2442 <function>ZOOM_scanset_destroy</function>.
2443 Functions <function>ZOOM_scanset_option_get</function> and
2444 <function>ZOOM_scanset_option_set</function> retrieves and sets
2445 an option respectively.
2448 The <parameter>startpqf</parameter> is a subset of PQF, namely
2449 the Attributes+Term part. Multiple <literal>@attr</literal> can
2450 be used. For example to scan in title (complete) phrases:
2452 @attr 1=4 @attr 6=2 "science o"
2456 The <function>ZOOM_connecton_scan1</function> is a newer and
2457 more generic alternative to <function>ZOOM_connection_scan</function>
2458 which allows to use both CQL and PQF for Scan.
2460 <table frame="top" id="zoom.scanset.options">
2461 <title>ZOOM Scan Set Options</title>
2463 <colspec colwidth="4*" colname="name"></colspec>
2464 <colspec colwidth="7*" colname="description"></colspec>
2465 <colspec colwidth="2*" colname="default"></colspec>
2468 <entry>Option</entry>
2469 <entry>Description</entry>
2470 <entry>Default</entry>
2475 number</entry><entry>Number of Scan Terms requested in next scan.
2476 After scan it holds the actual number of terms returned.
2477 </entry><entry>20</entry></row>
2479 position</entry><entry>Preferred Position of term in response
2480 in next scan; actual position after completion of scan.
2481 </entry><entry>1</entry></row>
2483 stepSize</entry><entry>Step Size
2484 </entry><entry>0</entry></row>
2486 scanStatus</entry><entry>An integer indicating the Scan Status
2488 </entry><entry>0</entry></row>
2490 rpnCharset</entry><entry>Character set for RPN terms.
2491 If this is set, ZOOM C will assume that the ZOOM application is
2492 running UTF-8. Terms in RPN queries are then converted to the
2493 rpnCharset. If this is unset, ZOOM C will not assume any encoding
2494 of RPN terms and no conversion is performed.
2495 </entry><entry>none</entry></row>
2500 <sect1 id="zoom.extendedservices">
2501 <title>Extended Services</title>
2503 ZOOM offers an interface to a subset of the Z39.50 extended services
2504 as well as a few privately defined ones:
2509 Z39.50 Item Order (ILL).
2510 See <xref linkend="zoom.item.order"/>.
2515 Record Update. This allows a client to insert, modify or delete
2517 See <xref linkend="zoom.record.update"/>.
2522 Database Create. This a non-standard feature. Allows a client
2523 to create a database.
2524 See <xref linkend="zoom.database.create"/>.
2529 Database Drop. This a non-standard feature. Allows a client
2530 to delete/drop a database.
2531 See <xref linkend="zoom.database.drop"/>.
2536 Commit operation. This a non-standard feature. Allows a client
2537 to commit operations.
2538 See <xref linkend="zoom.commit"/>.
2541 <!-- all the ILL PDU options should go here too -->
2544 To create an extended service operation a <literal>ZOOM_package</literal>
2545 must be created. The operation is a five step operation. The
2546 package is created, package is configured by means of options,
2547 the package is send, result is inspected (by means of options),
2548 the package is destroyed.
2551 ZOOM_package ZOOM_connection_package(ZOOM_connection c,
2552 ZOOM_options options);
2554 const char *ZOOM_package_option_get(ZOOM_package p,
2556 void ZOOM_package_option_set(ZOOM_package p, const char *key,
2558 void ZOOM_package_send(ZOOM_package p, const char *type);
2560 void ZOOM_package_destroy(ZOOM_package p);
2563 The <function>ZOOM_connection_package</function> creates a
2564 package for the connection given using the options specified.
2567 Functions <function>ZOOM_package_option_get</function> and
2568 <function>ZOOM_package_option_set</function> gets and sets
2572 <function>ZOOM_package_send</function> sends
2573 the package the via connection specified in
2574 <function>ZOOM_connection_package</function>.
2575 The <parameter>type</parameter> specifies the actual extended service
2576 package type to be sent.
2578 <table frame="top" id="zoom.extendedservices.type">
2579 <title>Extended Service Type</title>
2581 <colspec colwidth="3*" colname="value"></colspec>
2582 <colspec colwidth="7*" colname="description"></colspec>
2586 <entry>Description</entry>
2591 <entry>itemorder</entry><entry>Item Order</entry>
2594 <entry>update</entry><entry>Record Update</entry>
2597 <entry>create</entry><entry>Database Create</entry>
2600 <entry>drop</entry><entry>Database Drop</entry>
2603 <entry>commit</entry><entry>Commit Operation</entry>
2609 <table frame="top" id="zoom.extendedservices.options">
2610 <title>Extended Service Common Options</title>
2612 <colspec colwidth="4*" colname="name"></colspec>
2613 <colspec colwidth="7*" colname="description"></colspec>
2614 <colspec colwidth="3*" colname="default"></colspec>
2617 <entry>Option</entry>
2618 <entry>Description</entry>
2619 <entry>Default</entry>
2624 <entry>package-name</entry>
2625 <entry>Extended Service Request package name. Must be specified
2626 as part of a request</entry>
2630 <entry>user-id</entry>
2631 <entry>User ID of Extended Service Package. Is a request option</entry>
2635 <entry>function</entry>
2637 Function of package - one of <literal>create</literal>,
2638 <literal>delete</literal>, <literal>modify</literal>. Is
2641 <entry><literal>create</literal></entry>
2644 <entry>waitAction</entry>
2646 Wait action for package. Possible values:
2647 <literal>wait</literal>, <literal>waitIfPossible</literal>,
2648 <literal>dontWait</literal> or <literal>dontReturnPackage</literal>.
2650 <entry><literal>waitIfPossible</literal></entry>
2653 <entry>targetReference</entry>
2655 Target Reference. This is part of the response as returned
2656 by the server. Read it after a successful operation.
2658 <entry><literal>none</literal></entry>
2663 <sect2 id="zoom.item.order">
2664 <title>Item Order</title>
2666 For Item Order, <literal>type</literal> must be set to
2667 <literal>itemorder</literal> in
2668 <function>ZOOM_package_send</function>.
2671 <table frame="top" id="zoom.item.order.options">
2672 <title>Item Order Options</title>
2674 <colspec colwidth="4*" colname="name"></colspec>
2675 <colspec colwidth="7*" colname="description"></colspec>
2676 <colspec colwidth="3*" colname="default"></colspec>
2679 <entry>Option</entry>
2680 <entry>Description</entry>
2681 <entry>Default</entry>
2686 <entry>contact-name</entry>
2687 <entry>ILL contact name</entry>
2691 <entry>contact-phone</entry>
2692 <entry>ILL contact phone</entry>
2696 <entry>contact-email</entry>
2697 <entry>ILL contact email</entry>
2701 <entry>itemorder-setname</entry>
2702 <entry>Name of result set for record</entry>
2703 <entry>default</entry>
2706 <entry>itemorder-item</entry>
2707 <entry>Position for item (record) requested. An integer</entry>
2714 There are two variants of item order: ILL-variant and
2715 XML document variant. In order to use the XML variant the setting
2716 <literal>doc</literal> must hold the XML item order document. If that
2717 setting is unset, the ILL-variant is used.
2720 <table frame="top" id="zoom.illrequest.options">
2721 <title>ILL Request Options</title>
2723 <colspec colwidth="4*" colname="name"></colspec>
2726 <entry>Option</entry>
2730 <row><entry>protocol-version-num</entry></row>
2731 <row><entry>transaction-id,initial-requester-id,person-or-institution-symbol,person</entry></row>
2732 <row><entry>transaction-id,initial-requester-id,person-or-institution-symbol,institution</entry></row>
2733 <row><entry>transaction-id,initial-requester-id,name-of-person-or-institution,name-of-person</entry></row>
2734 <row><entry>transaction-id,initial-requester-id,name-of-person-or-institution,name-of-institution</entry></row>
2735 <row><entry>transaction-id,transaction-group-qualifier</entry></row>
2736 <row><entry>transaction-id,transaction-qualifier</entry></row>
2737 <row><entry>transaction-id,sub-transaction-qualifier</entry></row>
2738 <row><entry>service-date-time,this,date</entry></row>
2739 <row><entry>service-date-time,this,time</entry></row>
2740 <row><entry>service-date-time,original,date</entry></row>
2741 <row><entry>service-date-time,original,time</entry></row>
2742 <row><entry>requester-id,person-or-institution-symbol,person</entry></row>
2743 <row><entry>requester-id,person-or-institution-symbol,institution</entry></row>
2744 <row><entry>requester-id,name-of-person-or-institution,name-of-person</entry></row>
2745 <row><entry>requester-id,name-of-person-or-institution,name-of-institution</entry></row>
2746 <row><entry>responder-id,person-or-institution-symbol,person</entry></row>
2747 <row><entry>responder-id,person-or-institution-symbol,institution</entry></row>
2748 <row><entry>responder-id,name-of-person-or-institution,name-of-person</entry></row>
2749 <row><entry>responder-id,name-of-person-or-institution,name-of-institution</entry></row>
2750 <row><entry>transaction-type</entry></row>
2751 <row><entry>delivery-address,postal-address,name-of-person-or-institution,name-of-person</entry></row>
2752 <row><entry>delivery-address,postal-address,name-of-person-or-institution,name-of-institution</entry></row>
2753 <row><entry>delivery-address,postal-address,extended-postal-delivery-address</entry></row>
2754 <row><entry>delivery-address,postal-address,street-and-number</entry></row>
2755 <row><entry>delivery-address,postal-address,post-office-box</entry></row>
2756 <row><entry>delivery-address,postal-address,city</entry></row>
2757 <row><entry>delivery-address,postal-address,region</entry></row>
2758 <row><entry>delivery-address,postal-address,country</entry></row>
2759 <row><entry>delivery-address,postal-address,postal-code</entry></row>
2760 <row><entry>delivery-address,electronic-address,telecom-service-identifier</entry></row>
2761 <row><entry>delivery-address,electronic-address,telecom-service-addreess</entry></row>
2762 <row><entry>billing-address,postal-address,name-of-person-or-institution,name-of-person</entry></row>
2763 <row><entry>billing-address,postal-address,name-of-person-or-institution,name-of-institution</entry></row>
2764 <row><entry>billing-address,postal-address,extended-postal-delivery-address</entry></row>
2765 <row><entry>billing-address,postal-address,street-and-number</entry></row>
2766 <row><entry>billing-address,postal-address,post-office-box</entry></row>
2767 <row><entry>billing-address,postal-address,city</entry></row>
2768 <row><entry>billing-address,postal-address,region</entry></row>
2769 <row><entry>billing-address,postal-address,country</entry></row>
2770 <row><entry>billing-address,postal-address,postal-code</entry></row>
2771 <row><entry>billing-address,electronic-address,telecom-service-identifier</entry></row>
2772 <row><entry>billing-address,electronic-address,telecom-service-addreess</entry></row>
2773 <row><entry>ill-service-type</entry></row>
2774 <row><entry>requester-optional-messages,can-send-RECEIVED</entry></row>
2775 <row><entry>requester-optional-messages,can-send-RETURNED</entry></row>
2776 <row><entry>requester-optional-messages,requester-SHIPPED</entry></row>
2777 <row><entry>requester-optional-messages,requester-CHECKED-IN</entry></row>
2778 <row><entry>search-type,level-of-service</entry></row>
2779 <row><entry>search-type,need-before-date</entry></row>
2780 <row><entry>search-type,expiry-date</entry></row>
2781 <row><entry>search-type,expiry-flag</entry></row>
2782 <row><entry>place-on-hold</entry></row>
2783 <row><entry>client-id,client-name</entry></row>
2784 <row><entry>client-id,client-status</entry></row>
2785 <row><entry>client-id,client-identifier</entry></row>
2786 <row><entry>item-id,item-type</entry></row>
2787 <row><entry>item-id,call-number</entry></row>
2788 <row><entry>item-id,author</entry></row>
2789 <row><entry>item-id,title</entry></row>
2790 <row><entry>item-id,sub-title</entry></row>
2791 <row><entry>item-id,sponsoring-body</entry></row>
2792 <row><entry>item-id,place-of-publication</entry></row>
2793 <row><entry>item-id,publisher</entry></row>
2794 <row><entry>item-id,series-title-number</entry></row>
2795 <row><entry>item-id,volume-issue</entry></row>
2796 <row><entry>item-id,edition</entry></row>
2797 <row><entry>item-id,publication-date</entry></row>
2798 <row><entry>item-id,publication-date-of-component</entry></row>
2799 <row><entry>item-id,author-of-article</entry></row>
2800 <row><entry>item-id,title-of-article</entry></row>
2801 <row><entry>item-id,pagination</entry></row>
2802 <row><entry>item-id,ISBN</entry></row>
2803 <row><entry>item-id,ISSN</entry></row>
2804 <row><entry>item-id,additional-no-letters</entry></row>
2805 <row><entry>item-id,verification-reference-source</entry></row>
2806 <row><entry>copyright-complicance</entry></row>
2807 <row><entry>retry-flag</entry></row>
2808 <row><entry>forward-flag</entry></row>
2809 <row><entry>requester-note</entry></row>
2810 <row><entry>forward-note</entry></row>
2815 <sect2 id="zoom.record.update">
2816 <title>Record Update</title>
2818 For Record Update, <literal>type</literal> must be set to
2819 <literal>update</literal> in
2820 <function>ZOOM_package_send</function>.
2822 <table frame="top" id="zoom.record.update.options">
2823 <title>Record Update Options</title>
2825 <colspec colwidth="4*" colname="name"></colspec>
2826 <colspec colwidth="7*" colname="description"></colspec>
2827 <colspec colwidth="3*" colname="default"></colspec>
2830 <entry>Option</entry>
2831 <entry>Description</entry>
2832 <entry>Default</entry>
2837 <entry>action</entry>
2839 The update action. One of
2840 <literal>specialUpdate</literal>,
2841 <literal>recordInsert</literal>,
2842 <literal>recordReplace</literal>,
2843 <literal>recordDelete</literal>,
2844 <literal>elementUpdate</literal>.
2846 <entry><literal>specialUpdate (recordInsert for updateVersion=1 which does not support specialUpdate)</literal></entry>
2849 <entry>recordIdOpaque</entry>
2850 <entry>Opaque Record ID</entry>
2854 <entry>recordIdNumber</entry>
2855 <entry>Record ID number</entry>
2859 <entry>record</entry>
2860 <entry>The record itself</entry>
2864 <entry>recordOpaque</entry>
2865 <entry>Specifies an opaque record which is
2866 encoded as an ASN.1 ANY type with the OID as tiven by option
2867 <literal>syntax</literal> (see below).
2868 Option <literal>recordOpaque</literal> is an alternative
2869 to record - and <literal>record</literal> option (above) is
2870 ignored if recordOpaque is set. This option is only available in
2871 YAZ 3.0.35 and later and is meant to facilitate Updates with
2877 <entry>syntax</entry>
2878 <entry>The record syntax (transfer syntax). Is a string that
2879 is a known record syntax.
2881 <entry>no syntax</entry>
2884 <entry>databaseName</entry>
2885 <entry>Database from connection object</entry>
2886 <entry>Default</entry>
2889 <entry>correlationInfo.note</entry>
2890 <entry>Correlation Info Note (string)</entry>
2894 <entry>correlationInfo.id</entry>
2895 <entry>Correlation Info ID (integer)</entry>
2899 <entry>elementSetName</entry>
2900 <entry>Element Set for Record</entry>
2904 <entry>updateVersion</entry>
2905 <entry>Record Update version which holds one of the values
2906 1, 2 or 3. Each version has a distinct OID:
2908 (<ulink url="&url.z39.50.extupdate1;">first version</ulink>) ,
2910 (second version) and
2911 1.2.840.10003.9.5.1.1
2912 (<ulink url="&url.z39.50.extupdate3;">third and
2913 newest version</ulink>).
2923 <sect2 id="zoom.database.create"><title>Database Create</title>
2925 For Database Create, <literal>type</literal> must be set to
2926 <literal>create</literal> in
2927 <function>ZOOM_package_send</function>.
2930 <table frame="top" id="zoom.database.create.options">
2931 <title>Database Create Options</title>
2933 <colspec colwidth="4*" colname="name"></colspec>
2934 <colspec colwidth="7*" colname="description"></colspec>
2935 <colspec colwidth="3*" colname="default"></colspec>
2938 <entry>Option</entry>
2939 <entry>Description</entry>
2940 <entry>Default</entry>
2945 <entry>databaseName</entry>
2946 <entry>Database from connection object</entry>
2947 <entry>Default</entry>
2953 <sect2 id="zoom.database.drop">
2954 <title>Database Drop</title>
2956 For Database Drop, <literal>type</literal> must be set to
2957 <literal>drop</literal> in
2958 <function>ZOOM_package_send</function>.
2960 <table frame="top" id="zoom.database.drop.options">
2961 <title>Database Drop Options</title>
2963 <colspec colwidth="4*" colname="name"></colspec>
2964 <colspec colwidth="7*" colname="description"></colspec>
2965 <colspec colwidth="3*" colname="default"></colspec>
2968 <entry>Option</entry>
2969 <entry>Description</entry>
2970 <entry>Default</entry>
2975 <entry>databaseName</entry>
2976 <entry>Database from connection object</entry>
2977 <entry>Default</entry>
2983 <sect2 id="zoom.commit">
2984 <title>Commit Operation</title>
2986 For Commit, <literal>type</literal> must be set to
2987 <literal>commit</literal> in
2988 <function>ZOOM_package_send</function>.
2991 <sect2 id="zoom.extended.services.behavior">
2992 <title>Protocol behavior</title>
2994 All the extended services are Z39.50-only.
2998 The database create, drop and commit services are privately defined
3000 Refer to <filename>esadmin.asn</filename> in YAZ for the ASN.1
3006 <sect1 id="zoom.options">
3007 <title>Options</title>
3009 Most &zoom; objects provide a way to specify options to change behavior.
3010 From an implementation point of view a set of options is just like
3011 an associative array / hash.
3014 ZOOM_options ZOOM_options_create(void);
3016 ZOOM_options ZOOM_options_create_with_parent(ZOOM_options parent);
3018 void ZOOM_options_destroy(ZOOM_options opt);
3021 const char *ZOOM_options_get(ZOOM_options opt, const char *name);
3023 void ZOOM_options_set(ZOOM_options opt, const char *name,
3027 typedef const char *(*ZOOM_options_callback)
3028 (void *handle, const char *name);
3030 ZOOM_options_callback
3031 ZOOM_options_set_callback(ZOOM_options opt,
3032 ZOOM_options_callback c,
3036 <sect1 id="zoom.queryconversions">
3037 <title>Query conversions</title>
3039 int ZOOM_query_cql2rpn(ZOOM_query s, const char *cql_str,
3040 ZOOM_connection conn);
3042 int ZOOM_query_ccl2rpn(ZOOM_query s, const char *ccl_str,
3044 int *ccl_error, const char **error_string,
3048 <function>ZOOM_query_cql2rpn</function> translates the CQL string,
3049 client-side, into RPN which may be passed to the server.
3050 This is useful for server's that don't themselves
3051 support CQL, for which <function>ZOOM_query_cql</function> is useless.
3052 `conn' is used only as a place to stash diagnostics if compilation
3053 fails; if this information is not needed, a null pointer may be used.
3054 The CQL conversion is driven by option <literal>cqlfile</literal> from
3055 connection conn. This specifies a conversion file (eg pqf.properties)
3056 which <emphasis>must</emphasis> be present.
3059 <function>ZOOM_query_ccl2rpn</function> translates the CCL string,
3060 client-side, into RPN which may be passed to the server.
3061 The conversion is driven by the specification given by
3062 <literal>config</literal>. Upon completion 0 is returned on success; -1
3063 is returned on on failure. Om failure <literal>error_string</literal> and
3064 <literal>error_pos</literal> holds error message and position of
3065 first error in original CCL string.
3068 <sect1 id="zoom.events"><title>Events</title>
3070 If you're developing non-blocking applications, you have to deal
3074 int ZOOM_event(int no, ZOOM_connection *cs);
3077 The <function>ZOOM_event</function> executes pending events for
3078 a number of connections. Supply the number of connections in
3079 <literal>no</literal> and an array of connections in
3080 <literal>cs</literal> (<literal>cs[0] ... cs[no-1]</literal>).
3081 A pending event could be a sending a search, receiving a response,
3083 When an event has occurred for one of the connections, this function
3084 returns a positive integer <literal>n</literal> denoting that an event
3085 occurred for connection <literal>cs[n-1]</literal>.
3086 When no events are pending for the connections, a value of zero is
3088 To ensure that all outstanding requests are performed call this function
3089 repeatedly until zero is returned.
3092 If <function>ZOOM_event</function> returns and returns non-zero, the
3093 last event that occurred can be expected.
3096 int ZOOM_connection_last_event(ZOOM_connection cs);
3099 <function>ZOOM_connection_last_event</function> returns an event type
3100 (integer) for the last event.
3103 <table frame="top" id="zoom.event.ids">
3104 <title>ZOOM Event IDs</title>
3106 <colspec colwidth="4*" colname="name"></colspec>
3107 <colspec colwidth="7*" colname="description"></colspec>
3110 <entry>Event</entry>
3111 <entry>Description</entry>
3116 <entry>ZOOM_EVENT_NONE</entry>
3117 <entry>No event has occurred</entry>
3120 <entry>ZOOM_EVENT_CONNECT</entry>
3121 <entry>TCP/IP connect has initiated</entry>
3124 <entry>ZOOM_EVENT_SEND_DATA</entry>
3125 <entry>Data has been transmitted (sending)</entry>
3128 <entry>ZOOM_EVENT_RECV_DATA</entry>
3129 <entry>Data has been received)</entry>
3132 <entry>ZOOM_EVENT_TIMEOUT</entry>
3133 <entry>Timeout</entry>
3136 <entry>ZOOM_EVENT_UNKNOWN</entry>
3137 <entry>Unknown event</entry>
3140 <entry>ZOOM_EVENT_SEND_APDU</entry>
3141 <entry>An APDU has been transmitted (sending)</entry>
3144 <entry>ZOOM_EVENT_RECV_APDU</entry>
3145 <entry>An APDU has been received</entry>
3148 <entry>ZOOM_EVENT_RECV_RECORD</entry>
3149 <entry>A result-set record has been received</entry>
3152 <entry>ZOOM_EVENT_RECV_SEARCH</entry>
3153 <entry>A search result been received</entry>
3160 <chapter id="server">
3161 <title>Generic server</title>
3162 <sect1 id="server.introduction"><title>Introduction</title>
3164 If you aren't into documentation, a good way to learn how the
3165 back end interface works is to look at the <filename>backend.h</filename>
3166 file. Then, look at the small dummy-server in
3167 <filename>ztest/ztest.c</filename>. The <filename>backend.h</filename>
3168 file also makes a good reference, once you've chewed your way through
3169 the prose of this file.
3172 If you have a database system that you would like to make available by
3173 means of Z39.50 or SRU, &yaz; basically offers your two options. You
3174 can use the APIs provided by the &asn;, &odr;, and &comstack;
3176 create and decode PDUs, and exchange them with a client.
3177 Using this low-level interface gives you access to all fields and
3178 options of the protocol, and you can construct your server as close
3179 to your existing database as you like.
3180 It is also a fairly involved process, requiring
3181 you to set up an event-handling mechanism, protocol state machine,
3182 etc. To simplify server implementation, we have implemented a compact
3183 and simple, but reasonably full-functioned server-frontend that will
3184 handle most of the protocol mechanics, while leaving you to
3185 concentrate on your database interface.
3189 The backend interface was designed in anticipation of a specific
3190 integration task, while still attempting to achieve some degree of
3191 generality. We realize fully that there are points where the
3192 interface can be improved significantly. If you have specific
3193 functions or parameters that you think could be useful, send us a
3194 mail (or better, sign on to the mailing list referred to in the
3195 top-level README file). We will try to fit good suggestions into future
3196 releases, to the extent that it can be done without requiring
3197 too many structural changes in existing applications.
3202 The &yaz; server does not support XCQL.
3206 <sect1 id="server.frontend">
3207 <title>The Database Frontend</title>
3209 We refer to this software as a generic database frontend. Your
3210 database system is the <emphasis>backend database</emphasis>, and the
3211 interface between the two is called the <emphasis>backend API</emphasis>.
3212 The backend API consists of a small number of function handlers and
3213 structure definitions. You are required to provide the
3214 <function>main()</function> routine for the server (which can be
3215 quite simple), as well as a set of handlers to match each of the
3217 The interface functions that you write can use any mechanism you like
3218 to communicate with your database system: You might link the whole
3219 thing together with your database application and access it by
3220 function calls; you might use IPC to talk to a database server
3221 somewhere; or you might link with third-party software that handles
3222 the communication for you (like a commercial database client library).
3223 At any rate, the handlers will perform the tasks of:
3236 Scanning the database index (optional - if you wish to implement SCAN).
3239 Extended Services (optional).
3242 Result-Set Delete (optional).
3245 Result-Set Sort (optional).
3248 Return Explain for SRU (optional).
3252 (more functions will be added in time to support as much of
3253 Z39.50-1995 as possible).
3256 <sect1 id="server.backend">
3257 <title>The Backend API</title>
3259 The header file that you need to use the interface are in the
3260 <filename>include/yaz</filename> directory. It's called
3261 <filename>backend.h</filename>. It will include other files from
3262 the <filename>include/yaz</filename> directory, so you'll
3263 probably want to use the -I option of your compiler to tell it
3264 where to find the files. When you run
3265 <literal>make</literal> in the top-level &yaz; directory,
3266 everything you need to create your server is to link with the
3267 <filename>lib/libyaz.la</filename> library.
3270 <sect1 id="server.main">
3271 <title>Your main() Routine</title>
3273 As mentioned, your <function>main()</function> routine can be quite brief.
3274 If you want to initialize global parameters, or read global configuration
3275 tables, this is the place to do it. At the end of the routine, you should
3279 int statserv_main(int argc, char **argv,
3280 bend_initresult *(*bend_init)(bend_initrequest *r),
3281 void (*bend_close)(void *handle));
3284 The third and fourth arguments are pointers to handlers. Handler
3285 <function>bend_init</function> is called whenever the server receives
3286 an Initialize Request, so it serves as a Z39.50 session initializer. The
3287 <function>bend_close</function> handler is called when the session is
3291 <function>statserv_main</function> will establish listening sockets
3292 according to the parameters given. When connection requests are received,
3293 the event handler will typically <function>fork()</function> and
3294 create a sub-process to handle a new connection.
3295 Alternatively the server may be setup to create threads for each
3297 If you do use global variables and forking, you should be aware, then,
3298 that these cannot be shared between associations, unless you explicitly
3299 disable forking by command line parameters.
3302 The server provides a mechanism for controlling some of its behavior
3303 without using command-line options. The function
3306 statserv_options_block *statserv_getcontrol(void);
3309 will return a pointer to a <literal>struct statserv_options_block</literal>
3310 describing the current default settings of the server. The structure
3311 contains these elements:
3314 <term><literal>int dynamic</literal></term>
3316 A boolean value, which determines whether the server
3317 will fork on each incoming request (TRUE), or not (FALSE). Default is
3318 TRUE. This flag is only read by UNIX-based servers (WIN32 based servers
3323 <term><literal>int threads</literal></term>
3325 A boolean value, which determines whether the server
3326 will create a thread on each incoming request (TRUE), or not (FALSE).
3327 Default is FALSE. This flag is only read by UNIX-based servers
3328 that offer POSIX Threads support.
3329 WIN32-based servers always operate in threaded mode.
3333 <term><literal>int inetd</literal></term>
3335 A boolean value, which determines whether the server
3336 will operates under a UNIX INET daemon (inetd). Default is FALSE.
3340 <term><literal>char logfile[ODR_MAXNAME+1]</literal></term>
3341 <listitem><para>File for diagnostic output ("": stderr).
3345 <term><literal>char apdufile[ODR_MAXNAME+1]</literal></term>
3347 Name of file for logging incoming and outgoing APDUs
3348 ("": don't log APDUs, "-":
3349 <literal>stderr</literal>).
3353 <term><literal>char default_listen[1024]</literal></term>
3354 <listitem><para>Same form as the command-line specification of
3355 listener address. "": no default listener address.
3356 Default is to listen at "tcp:@:9999". You can only
3357 specify one default listener address in this fashion.
3361 <term><literal>enum oid_proto default_proto;</literal></term>
3362 <listitem><para>Either <literal>PROTO_Z3950</literal> or
3363 <literal>PROTO_SR</literal>.
3364 Default is <literal>PROTO_Z39_50</literal>.
3368 <term><literal>int idle_timeout;</literal></term>
3369 <listitem><para>Maximum session idle-time, in minutes. Zero indicates
3370 no (infinite) timeout. Default is 15 minutes.
3374 <term><literal>int maxrecordsize;</literal></term>
3375 <listitem><para>Maximum permissible record (message) size. Default
3376 is 64 MB. This amount of memory will only be allocated if a
3377 client requests a very large amount of records in one operation
3379 Set it to a lower number if you are worried about resource
3380 consumption on your host system.
3384 <term><literal>char configname[ODR_MAXNAME+1]</literal></term>
3385 <listitem><para>Passed to the backend when a new connection is received.
3389 <term><literal>char setuid[ODR_MAXNAME+1]</literal></term>
3390 <listitem><para>Set user id to the user specified, after binding
3391 the listener addresses.
3396 <literal>void (*bend_start)(struct statserv_options_block *p)</literal>
3398 <listitem><para>Pointer to function which is called after the
3399 command line options have been parsed - but before the server
3401 For forked UNIX servers this handler is called in the mother
3402 process; for threaded servers this handler is called in the
3404 The default value of this pointer is NULL in which case it
3405 isn't invoked by the frontend server.
3406 When the server operates as an NT service this handler is called
3407 whenever the service is started.
3412 <literal>void (*bend_stop)(struct statserv_options_block *p)</literal>
3414 <listitem><para>Pointer to function which is called whenever the server
3415 has stopped listening for incoming connections. This function pointer
3416 has a default value of NULL in which case it isn't called.
3417 When the server operates as an NT service this handler is called
3418 whenever the service is stopped.
3422 <term><literal>void *handle</literal></term>
3423 <listitem><para>User defined pointer (default value NULL).
3424 This is a per-server handle that can be used to specify "user-data".
3425 Do not confuse this with the session-handle as returned by bend_init.
3431 The pointer returned by <literal>statserv_getcontrol</literal> points to
3432 a static area. You are allowed to change the contents of the structure,
3433 but the changes will not take effect before you call
3436 void statserv_setcontrol(statserv_options_block *block);
3440 that you should generally update this structure before calling
3441 <function>statserv_main()</function>.
3445 <sect1 id="server.backendfunctions">
3446 <title>The Backend Functions</title>
3448 For each service of the protocol, the backend interface declares one or
3449 two functions. You are required to provide implementations of the
3450 functions representing the services that you wish to implement.
3452 <sect2 id="server.init">
3455 bend_initresult (*bend_init)(bend_initrequest *r);
3458 This handler is called once for each new connection request, after
3459 a new process/thread has been created, and an Initialize Request has
3460 been received from the client. The pointer to the
3461 <function>bend_init</function> handler is passed in the call to
3462 <function>statserv_start</function>.
3465 This handler is also called when operating in SRU mode - when
3466 a connection has been made (even though SRU does not offer
3470 Unlike previous versions of YAZ, the <function>bend_init</function> also
3471 serves as a handler that defines the Z39.50 services that the backend
3472 wish to support. Pointers to <emphasis>all</emphasis> service handlers,
3473 including search - and fetch must be specified here in this handler.
3476 The request - and result structures are defined as
3479 typedef struct bend_initrequest
3481 /** \brief user/name/password to be read */
3482 Z_IdAuthentication *auth;
3483 /** \brief encoding stream (for results) */