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">
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 WIN32</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 2003/2005/2008.
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
1009 <literal>ZLIB_DIR</literal> to the zlib directory.
1012 Windows versions of libxslt, libxml2, zlib and iconv can be found
1013 <ulink url="&url.libxml2.download.win32;">
1014 Igor Zlatković' site</ulink>.
1018 YAZ is not using zlib but libxml2 is depending on it.
1024 <term><literal>HAVE_LIBXSLT</literal>,
1025 <literal>LIBXSLT_DIR</literal></term>
1028 If <literal>HAVE_LIBXSLT</literal> is set to 1, YAZ is compiled
1029 with XSLT support. In this configuration, set
1030 <literal>LIBXSLT_DIR</literal> to the
1031 <ulink url="&url.libxslt;">libxslt</ulink> source directory.
1035 libxslt depends libxml2.
1041 <term><literal>HAVE_ICU</literal>,
1042 <literal>ICU_DIR</literal></term>
1045 If <literal>HAVE_ICU</literal> is set to 1, YAZ is compiled
1046 with <ulink url="&url.icu;">ICU</ulink> support.
1047 In this configuration, set
1048 <literal>ICU_DIR</literal> to the
1049 <ulink url="&url.icu;">ICU</ulink> source directory.
1056 When satisfied with the settings in the makefile, type
1063 If the <filename>nmake</filename> command is not found on your system
1064 you probably haven't defined the environment variables required to
1065 use that tool. To fix that, find and run the batch file
1066 <filename>vcvars32.bat</filename>. You need to run it from within
1067 the command prompt or set the environment variables "globally";
1068 otherwise it doesn't work.
1072 If you wish to recompile &yaz; - for example if you modify
1073 settings in the <filename>makefile</filename> you can delete
1074 object files, etc by running.
1080 The following files are generated upon successful compilation:
1083 <term><filename>bin/yaz&soversion;.dll</filename> /
1084 <filename>bin/yaz&soversion;d.dll</filename></term>
1086 &yaz; Release/Debug DLL.
1090 <term><filename>lib/yaz&soversion;.lib</filename> /
1091 <filename>lib/yaz&soversion;d.lib</filename></term>
1093 Import library for <filename>yaz&soversion;.dll</filename> /
1094 <filename>yaz&soversion;d.dll</filename>.
1098 <term><filename>bin/yaz_cond&soversion;.dll</filename> /
1099 <filename>bin/yaz_cond&soversion;d.dll</filename></term>
1101 Release/Debug DLL for condition variable utilities (condvar.c).
1105 <term><filename>lib/yaz_cond&soversion;.lib</filename> /
1106 <filename>lib/yaz_cond&soversion;d.lib</filename></term>
1108 Import library for <filename>yaz_cond&soversion;.dll</filename> /
1109 <filename>yaz_cond&soversion;d.dll</filename>.
1113 <term><filename>bin/yaz_icu&soversion;.dll</filename> /
1114 <filename>bin/yaz_icu&soversion;d.dll</filename></term>
1116 Release/Debug DLL for the ICU wrapper utility.
1117 Only build if HAVE_ICU is 1.
1121 <term><filename>lib/yaz_icu&soversion;.lib</filename> /
1122 <filename>lib/yaz_icu&soversion;d.lib</filename></term>
1124 Import library for <filename>yaz_icu&soversion;.dll</filename> /
1125 <filename>yaz_icu&soversion;d.dll</filename>.
1129 <term><filename>bin/yaz-ztest.exe</filename></term>
1131 Z39.50 multi-threaded test/example server. It's a WIN32
1132 console application.
1136 <term><filename>bin/yaz-client.exe</filename></term>
1138 &yaz; Z39.50 client application. It's a WIN32 console application.
1139 See chapter <link linkend="yaz-client">YAZ client</link> for more
1144 <term><filename>bin/yaz-icu.exe</filename></term>
1145 <listitem><para>This program exposes the ICU wrapper library if that
1146 is enabled for YAZ. Only if ICU is available this program is
1151 <term><filename>bin/zoomsh.exe</filename></term>
1153 Simple console application implemented on top of the
1154 <link linkend="zoom">ZOOM</link> functions.
1155 The application is a command line shell that allows you to enter
1156 simple commands to perform ZOOM operations.
1160 <term><filename>bin/zoomtst1.exe</filename>,
1161 <filename>bin/zoomtst2.exe</filename>, ..</term>
1163 Several small applications that demonstrates the ZOOM API.
1170 <sect2 id="installation-linking-yaz-win32">
1171 <title>How to make apps using YAZ on WIN32</title>
1173 This section will go though the process of linking your WIN32
1174 applications with &yaz;.
1177 Some people are confused by the fact that we use the nmake
1178 tool to build &yaz;. They think they have to do that too - in order
1179 to make their WIN32 applications work with &yaz;. The good news is that
1180 you don't have to. You can use the integrated environment of
1181 Visual Studio if desired for your own application.
1184 When setting up a project or Makefile you have to set the following:
1187 <term>include path</term>
1189 Set it to the <filename>include</filename> directory of &yaz;.
1193 <term>import library <filename>yaz&soversion;.lib</filename></term>
1195 You must link with this library. It's located in the
1196 sub directory <filename>lib</filename> of &yaz;.
1197 If you want to link with the debug version of &yaz;, you must
1198 link against <filename>yaz&soversion;d.lib</filename> instead.
1202 <term>dynamic link library
1203 <filename>yaz&soversion;.dll</filename>
1206 This DLL must be in your execution path when you invoke
1207 your application. Specifically, you should distribute this
1208 DLL with your application.
1217 ### Still to document:
1218 ZOOM_connection_errcode(c)
1219 ZOOM_connection_errmsg(c)
1220 ZOOM_connection_addinfo(c)
1221 ZOOM_connection_addinfo(c)
1222 ZOOM_connection_diagset(c);
1223 ZOOM_connection_save_apdu_wrbuf
1224 ZOOM_diag_str(error)
1225 ZOOM_resultset_record_immediate(s, pos)
1226 ZOOM_resultset_cache_reset(r)
1227 ZOOM_options_set_callback(opt, function, handle)
1228 ZOOM_options_create_with_parent2(parent1, parent2)
1229 ZOOM_options_getl(opt, name, len)
1230 ZOOM_options_setl(opt, name, value, len)
1231 ZOOM_options_get_bool(opt, name, defa)
1232 ZOOM_options_get_int(opt, name, defa)
1233 ZOOM_options_set_int(opt, name, value)
1238 &zoom; is an acronym for 'Z39.50 Object-Orientation Model' and is
1239 an initiative started by Mike Taylor (Mike is from the UK, which
1240 explains the peculiar name of the model). The goal of &zoom; is to
1241 provide a common Z39.50 client API not bound to a particular
1242 programming language or toolkit.
1245 From YAZ version 2.1.12, <ulink url="&url.sru;">SRU</ulink> is supported.
1246 You can make SRU ZOOM connections by specifying scheme
1247 <literal>http://</literal> for the hostname for a connection.
1248 The dialect of SRU used is specified by the value of the
1249 connection's <literal>sru</literal> option, which may be SRU over
1250 HTTP GET (<literal>get</literal>),
1251 SRU over HTTP POST (<literal>post</literal>), (SRU over
1252 SOAP) (<literal>soap</literal>) or <literal>solr</literal>
1253 (<ulink url="&url.solr;">Solr</ulink> Web Service).
1254 Using the facility for embedding options in target strings, a
1255 connection can be forced to use SRU rather the SRW (the default) by
1256 prefixing the target string with <literal>sru=get,</literal>, like this:
1257 <literal>sru=get,http://sru.miketaylor.org.uk:80/sru.pl</literal>
1260 <ulink url="&url.solr;">Solr</ulink> protocol support was added to
1261 YAZ in version 4.1.0, as a dialect of a SRU protocol, since both are
1262 HTTP based protocols.
1265 The lack of a simple Z39.50 client API for &yaz; has become more
1266 and more apparent over time. So when the first &zoom; specification
1268 an implementation for &yaz; was quickly developed. For the first time, it is
1269 now as easy (or easier!) to develop clients than servers with &yaz;. This
1270 chapter describes the &zoom; C binding. Before going further, please
1271 reconsider whether C is the right programming language for the job.
1272 There are other language bindings available for &yaz;, and still
1274 are in active development. See the
1275 <ulink url="&url.zoom;">ZOOM web-site</ulink> for
1279 In order to fully understand this chapter you should read and
1280 try the example programs <literal>zoomtst1.c</literal>,
1281 <literal>zoomtst2.c</literal>, .. in the <literal>zoom</literal>
1285 The C language misses features found in object oriented languages
1286 such as C++, Java, etc. For example, you'll have to manually,
1287 destroy all objects you create, even though you may think of them as
1288 temporary. Most objects has a <literal>_create</literal> - and a
1289 <literal>_destroy</literal> variant.
1290 All objects are in fact pointers to internal stuff, but you don't see
1291 that because of typedefs. All destroy methods should gracefully ignore a
1292 <literal>NULL</literal> pointer.
1295 In each of the sections below you'll find a sub section called
1296 protocol behavior, that describes how the API maps to the Z39.50
1299 <sect1 id="zoom-connections">
1300 <title>Connections</title>
1301 <para>The Connection object is a session with a target.
1304 #include <yaz/zoom.h>
1306 ZOOM_connection ZOOM_connection_new(const char *host, int portnum);
1308 ZOOM_connection ZOOM_connection_create(ZOOM_options options);
1310 void ZOOM_connection_connect(ZOOM_connection c, const char *host,
1312 void ZOOM_connection_destroy(ZOOM_connection c);
1315 Connection objects are created with either function
1316 <function>ZOOM_connection_new</function> or
1317 <function>ZOOM_connection_create</function>.
1318 The former creates and automatically attempts to establish a network
1319 connection with the target. The latter doesn't establish
1320 a connection immediately, thus allowing you to specify options
1321 before establishing network connection using the function
1322 <function>ZOOM_connection_connect</function>.
1323 If the port number, <literal>portnum</literal>, is zero, the
1324 <literal>host</literal> is consulted for a port specification.
1325 If no port is given, 210 is used. A colon denotes the beginning of
1326 a port number in the host string. If the host string includes a
1327 slash, the following part specifies a database for the connection.
1330 You can prefix the host with a scheme followed by colon. The
1331 default scheme is <literal>tcp</literal> (Z39.50 protocol).
1332 The scheme <literal>http</literal> selects SRU/get over HTTP by default,
1333 but can overridded to use SRU/post, SRW and the Solr protocol.
1336 You can prefix the scheme-qualified host-string with one or more
1338 <literal><parameter>key</parameter>=<parameter>value</parameter></literal>
1339 sequences, each of which represents an option to be set into the
1340 connection structure <emphasis>before</emphasis> the
1341 protocol-level connection is forged and the initialization
1342 handshake takes place. This facility can be used to provide
1343 authentication credentials, as in host-strings such as:
1344 <literal>user=admin,password=halfAm4n,tcp:localhost:8017/db</literal>
1347 Connection objects should be destroyed using the function
1348 <function>ZOOM_connection_destroy</function>.
1351 void ZOOM_connection_option_set(ZOOM_connection c,
1352 const char *key, const char *val);
1354 void ZOOM_connection_option_setl(ZOOM_connection c,
1356 const char *val, int len);
1358 const char *ZOOM_connection_option_get(ZOOM_connection c,
1360 const char *ZOOM_connection_option_getl(ZOOM_connection c,
1365 The functions <function>ZOOM_connection_option_set</function> and
1366 <function>ZOOM_connection_option_setl</function> allows you to
1367 set an option given by <parameter>key</parameter> to the value
1368 <parameter>value</parameter> for the connection.
1369 For <function>ZOOM_connection_option_set</function>, the
1370 value is assumed to be a 0-terminated string. Function
1371 <function>ZOOM_connection_option_setl</function> specifies a
1372 value of a certain size (len).
1375 Functions <function>ZOOM_connection_option_get</function> and
1376 <function>ZOOM_connection_option_getl</function> returns
1377 the value for an option given by <parameter>key</parameter>.
1379 <table id="zoom-connection-options" frame="top">
1380 <title>ZOOM Connection Options</title>
1382 <colspec colwidth="4*" colname="name"></colspec>
1383 <colspec colwidth="7*" colname="description"></colspec>
1384 <colspec colwidth="3*" colname="default"></colspec>
1387 <entry>Option</entry>
1388 <entry>Description</entry>
1389 <entry>Default</entry>
1394 implementationName</entry><entry>Name of Your client
1395 </entry><entry>none</entry></row>
1397 user</entry><entry>Authentication user name
1398 </entry><entry>none</entry></row>
1400 group</entry><entry>Authentication group name
1401 </entry><entry>none</entry></row>
1403 password</entry><entry>Authentication password.
1404 </entry><entry>none</entry></row>
1406 authenticationMode</entry><entry>How authentication is encoded.
1407 </entry><entry>basic</entry></row>
1409 host</entry><entry>Target host. This setting is "read-only".
1410 It's automatically set internally when connecting to a target.
1411 </entry><entry>none</entry></row>
1413 proxy</entry><entry>Proxy host. If set, the logical host
1414 is encoded in the otherInfo area of the Z39.50 Init PDU
1415 with OID 1.2.840.10003.10.1000.81.1.
1416 </entry><entry>none</entry></row>
1418 clientIP</entry><entry>Client IP. If set, is
1419 encoded in the otherInfo area of a Z39.50 PDU with OID
1420 1.2.840.10003.10.1000.81.3. Holds the original IP addreses
1421 of a client. Is used of ZOOM is used in a gateway of some sort.
1422 </entry><entry>none</entry></row>
1424 async</entry><entry>If true (1) the connection operates in
1425 asynchronous operation which means that all calls are non-blocking
1427 <link linkend="zoom.events"><function>ZOOM_event</function></link>.
1428 </entry><entry>0</entry></row>
1430 maximumRecordSize</entry><entry> Maximum size of single record.
1431 </entry><entry>1 MB</entry></row>
1433 preferredMessageSize</entry><entry> Maximum size of multiple records.
1434 </entry><entry>1 MB</entry></row>
1436 lang</entry><entry> Language for negotiation.
1437 </entry><entry>none</entry></row>
1439 charset</entry><entry> Character set for negotiation.
1440 </entry><entry>none</entry></row>
1442 serverImplementationId</entry><entry>
1443 Implementation ID of server. (The old targetImplementationId
1444 option is also supported for the benefit of old applications.)
1445 </entry><entry>none</entry></row>
1447 targetImplementationName</entry><entry>
1448 Implementation Name of server. (The old
1449 targetImplementationName option is also supported for the
1450 benefit of old applications.)
1451 </entry><entry>none</entry></row>
1453 serverImplementationVersion</entry><entry>
1454 Implementation Version of server. (the old
1455 targetImplementationVersion option is also supported for the
1456 benefit of old applications.)
1457 </entry><entry>none</entry></row>
1459 databaseName</entry><entry>One or more database names
1460 separated by character plus (<literal>+</literal>), which to
1461 be used by subsequent search requests on this Connection.
1462 </entry><entry>Default</entry></row>
1464 piggyback</entry><entry>True (1) if piggyback should be
1465 used in searches; false (0) if not.
1466 </entry><entry>1</entry></row>
1468 smallSetUpperBound</entry><entry>If hits is less than or equal to this
1469 value, then target will return all records using small element set name
1470 </entry><entry>0</entry></row>
1472 largeSetLowerBound</entry><entry>If hits is greater than this
1473 value, the target will return no records.
1474 </entry><entry>1</entry></row>
1476 mediumSetPresentNumber</entry><entry>This value represents
1477 the number of records to be returned as part of a search when when
1478 hits is less than or equal to large set lower bound and if hits
1479 is greater than small set upper bound.
1480 </entry><entry>0</entry></row>
1482 smallSetElementSetName</entry><entry>
1483 The element set name to be used for small result sets.
1484 </entry><entry>none</entry></row>
1486 mediumSetElementSetName</entry><entry>
1487 The element set name to be for medium-sized result sets.
1488 </entry><entry>none</entry></row>
1490 init_opt_search, init_opt_present, init_opt_delSet, etc.</entry><entry>
1491 After a successful Init, these options may be interrogated to
1492 discover whether the server claims to support the specified
1494 </entry><entry>none</entry></row>
1496 <entry>sru</entry><entry>
1497 SRU/Solr transport type. Must be either <literal>soap</literal>,
1498 <literal>get</literal>, <literal>post</literal>, or
1499 <literal>solr</literal>.
1500 </entry><entry>soap</entry></row>
1502 sru_version</entry><entry>
1503 SRU/SRW version. Should be <literal>1.1</literal>, or
1504 <literal>1.2</literal>. This is , prior to connect, the version
1505 to offer (highest version). And following connect (in fact
1506 first operation), holds the negotiated version with the server
1507 (same or lower version).
1508 </entry><entry>1.2</entry></row>
1509 <row id="zoom.facets.option"><entry>
1510 facets</entry><entry>
1511 Requested or recommend facets may be given before a search is sent.
1512 The value of this setting is described in <xref linkend="facets"/>
1513 For inspection of the facets returned, refer to the functions
1514 described in <xref linkend="zoom.facets"/>.
1515 </entry><entry>none</entry></row>
1517 apdulog</entry><entry>
1518 If set to a true value such as "1", a log of low-level
1519 protocol packets is emitted on standard error stream. This
1520 can be very useful for debugging.
1521 </entry><entry>0</entry></row>
1523 saveAPDU</entry><entry>
1524 If set to a true value such as "1", a log of low-level
1525 protocol packets is saved. The log can be retrieved by reading
1526 option APDU. Setting saveAPDU always has the side effect of
1527 resetting the currently saved log. This setting is
1528 <emphasis>write-only</emphasis>. If read, NULL will be returned.
1529 It is only recognized in
1530 <function>ZOOM_connection_option_set</function>.
1531 </entry><entry>0</entry></row>
1534 Returns the log of protocol packets. Will be empty if logging
1535 is not enabled (see saveAPDU above). This setting is
1536 <emphasis>read-only</emphasis>. It is only recognized if used
1537 in call to <function>ZOOM_connection_option_get</function> or
1538 <function>ZOOM_connection_option_getl</function>.
1539 </entry><entry></entry></row>
1541 memcached</entry><entry>
1542 If given and non-empty,
1543 <ulink url="&url.libmemcached;">libMemcached</ulink>
1544 will be configured for the connection.
1545 This option is inspected by ZOOM when a connection is established.
1546 If the <literal>memcached</literal> option is given
1547 and YAZ is compiled without libMemcached support, an internal
1548 diagnostic (10018) will be thrown.
1549 libMemcached support is available for YAZ 5.0.13 or later. If this
1550 option is supplied for an earlier version of YAZ, it is
1551 <emphasis>ignored</emphasis>.
1552 The value of this option is a list options - each is of the
1553 form <literal>--name=value</literal>.
1554 Option <literal>--server=</literal>host[:port] specifies a memcached
1555 server. It may be repeated for multiple memcached servers.
1556 Option <literal>--expire=</literal>seconds sets expiry time in seconds
1557 for how long result sets are to be cached.
1558 </entry><entry>none</entry></row>
1560 redis</entry><entry>
1561 If given and non-empty,
1562 a <ulink url="&url.redis;">redis</ulink> context will be created
1564 This option is inspected by ZOOM when a connection is established.
1565 If the <literal>redis</literal> option is given
1566 and YAZ is compiled without redis support, an internal
1567 diagnostic (10018) will be thrown.
1568 redis support is available for YAZ 5.2.0 or later. If this
1569 option is supplied for an earlier version of YAZ, it is
1570 <emphasis>ignored</emphasis>.
1571 The value of this option is a set options, similar to that
1572 of the memcached setting. At this stage only --server=host[:port]
1573 and --expire=seconds is supported.
1574 </entry><entry>none</entry></row>
1579 If either option <literal>lang</literal> or <literal>charset</literal>
1581 <ulink url="&url.z39.50.charneg;">
1582 Character Set and Language Negotiation</ulink> is in effect.
1585 int ZOOM_connection_error(ZOOM_connection c, const char **cp,
1586 const char **addinfo);
1587 int ZOOM_connection_error_x(ZOOM_connection c, const char **cp,
1588 const char **addinfo, const char **dset);
1591 Function <function>ZOOM_connection_error</function> checks for
1592 errors for the last operation(s) performed. The function returns
1593 zero if no errors occurred; non-zero otherwise indicating the error.
1594 Pointers <parameter>cp</parameter> and <parameter>addinfo</parameter>
1595 holds messages for the error and additional-info if passed as
1596 non-<literal>NULL</literal>. Function
1597 <function>ZOOM_connection_error_x</function> is an extended version
1598 of <function>ZOOM_connection_error</function> that is capable of
1599 returning name of diagnostic set in <parameter>dset</parameter>.
1601 <sect2 id="zoom-connection-z39.50">
1602 <title>Z39.50 Protocol behavior</title>
1604 The calls <function>ZOOM_connection_new</function> and
1605 <function>ZOOM_connection_connect</function> establishes a TCP/IP
1606 connection and sends an Initialize Request to the target if
1607 possible. In addition, the calls waits for an Initialize Response
1608 from the target and the result is inspected (OK or rejected).
1611 If <literal>proxy</literal> is set then the client will establish
1612 a TCP/IP connection with the peer as specified by the
1613 <literal>proxy</literal> host and the hostname as part of the
1614 connect calls will be set as part of the Initialize Request.
1615 The proxy server will then "forward" the PDU's transparently
1616 to the target behind the proxy.
1619 For the authentication parameters, if option <literal>user</literal>
1620 is set and both options <literal>group</literal> and
1621 <literal>pass</literal> are unset, then Open style
1622 authentication is used (Version 2/3) in which case the username
1623 is usually followed by a slash, then by a password.
1624 If either <literal>group</literal>
1625 or <literal>pass</literal> is set then idPass authentication
1626 (Version 3 only) is used. If none of the options are set, no
1627 authentication parameters are set as part of the Initialize Request
1631 When option <literal>async</literal> is 1, it really means that
1632 all network operations are postponed (and queued) until the
1633 function <literal>ZOOM_event</literal> is invoked. When doing so
1634 it doesn't make sense to check for errors after
1635 <literal>ZOOM_connection_new</literal> is called since that
1636 operation "connecting - and init" is still incomplete and the
1637 API cannot tell the outcome (yet).
1640 <sect2 id="zoom.sru.init.behavior">
1641 <title>SRU/Solr Protocol behavior</title>
1643 The HTTP based protocols (SRU, SRW, Solr) doesn't feature an
1644 Inititialize Request, so the connection phase merely establishes a
1645 TCP/IP connection with the HTTP server.
1647 <para>Most of the ZOOM connection options do not
1648 affect SRU/Solr and they are ignored. However, future versions
1649 of &yaz; might honor <literal>implementationName</literal> and
1650 put that as part of User-Agent header for HTTP requests.
1653 The <literal>charset</literal> is used in the Content-Type header
1657 Setting <literal>authentcationMode</literal> specifies how
1658 authentication parameters are encoded for HTTP. The default is
1659 "<literal>basic</literal>" where <literal>user</literal> and
1660 <literal>password</literal> are encoded by using HTTP basic
1664 If <literal>authentcationMode</literal> is "<literal>url</literal>", then
1665 user and password are encoded in the URL by parameters
1666 <literal>x-username</literal> and <literal>x-password</literal> as
1667 given by the SRU standard.
1671 <sect1 id="zoom.query">
1672 <title>Queries</title>
1674 Query objects represents queries.
1677 ZOOM_query ZOOM_query_create(void);
1679 void ZOOM_query_destroy(ZOOM_query q);
1681 int ZOOM_query_prefix(ZOOM_query q, const char *str);
1683 int ZOOM_query_cql(ZOOM_query s, const char *str);
1685 int ZOOM_query_sortby(ZOOM_query q, const char *criteria);
1687 int ZOOM_query_sortby2(ZOOM_query q, const char *strategy,
1688 const char *criteria);
1691 Create query objects using <function>ZOOM_query_create</function>
1692 and destroy them by calling <function>ZOOM_query_destroy</function>.
1693 RPN-queries can be specified in <link linkend="PQF">PQF</link>
1694 notation by using the
1695 function <function>ZOOM_query_prefix</function>.
1696 The <function>ZOOM_query_cql</function> specifies a CQL
1697 query to be sent to the server/target.
1698 More query types will be added in future versions of &yaz;, such as
1699 <link linkend="CCL">CCL</link> to RPN-mapping, native CCL query,
1700 etc. In addition to a search, a sort criteria may be set. Function
1701 <function>ZOOM_query_sortby</function> enables Z39.50 sorting and
1702 it takes sort criteria using the same string notation as
1703 yaz-client's <link linkend="sortspec">sort command</link>.
1705 <para id="zoom.query.sortby2">
1706 <function>ZOOM_query_sortby2</function> is similar to
1707 <function>ZOOM_query_sortby</function> but allows a strategy for
1708 sorting. The reason for the strategy parameter is that some
1709 protocols offers multiple ways of performing sorting.
1710 For example, Z39.50 has the standard sort, which is performed after
1711 search on an existing result set.
1712 It's also possible to use CQL in Z39.50 as the query type and use
1713 CQL's SORTBY keyword. Finally, Index Data's
1714 Zebra server also allows sorting to be specified as part of RPN (Type 7).
1716 <table id="zoom-sort-strategy" frame="top">
1717 <title>ZOOM sort strategy</title>
1719 <colspec colwidth="2*" colname="name"/>
1720 <colspec colwidth="5*" colname="description"/>
1724 <entry>Description</entry>
1729 <entry>z39.50</entry><entry>Z39.50 resultset sort</entry>
1732 <entry>type7</entry><entry>Sorting embedded in RPN(Type-7)</entry>
1735 <entry>cql</entry><entry>CQL SORTBY</entry>
1738 <entry>sru11</entry><entry>SRU sortKeys parameter</entry>
1741 <entry>solr</entry><entry>Solr sort</entry>
1744 <entry>embed</entry><entry>type7 for Z39.50, cql for SRU,
1745 solr for Solr protocol</entry>
1751 <sect1 id="zoom.resultsets"><title>Result sets</title>
1753 The result set object is a container for records returned from
1757 ZOOM_resultset ZOOM_connection_search(ZOOM_connection, ZOOM_query q);
1759 ZOOM_resultset ZOOM_connection_search_pqf(ZOOM_connection c,
1761 void ZOOM_resultset_destroy(ZOOM_resultset r);
1764 Function <function>ZOOM_connection_search</function> creates
1765 a result set given a connection and query.
1766 Destroy a result set by calling
1767 <function>ZOOM_resultset_destroy</function>.
1768 Simple clients may using PQF only may use function
1769 <function>ZOOM_connection_search_pqf</function> in which case
1770 creating query objects is not necessary.
1773 void ZOOM_resultset_option_set(ZOOM_resultset r,
1774 const char *key, const char *val);
1776 const char *ZOOM_resultset_option_get(ZOOM_resultset r, const char *key);
1778 size_t ZOOM_resultset_size(ZOOM_resultset r);
1781 Functions <function>ZOOM_resultset_options_set</function> and
1782 <function>ZOOM_resultset_get</function> sets and gets an option
1783 for a result set similar to <function>ZOOM_connection_option_get</function>
1784 and <function>ZOOM_connection_option_set</function>.
1787 The number of hits also called result-count is returned by
1788 function <function>ZOOM_resultset_size</function>.
1790 <table id="zoom.resultset.options"
1791 frame="top"><title>ZOOM Result set Options</title>
1793 <colspec colwidth="4*" colname="name"></colspec>
1794 <colspec colwidth="7*" colname="description"></colspec>
1795 <colspec colwidth="2*" colname="default"></colspec>
1798 <entry>Option</entry>
1799 <entry>Description</entry>
1800 <entry>Default</entry>
1805 start</entry><entry>Offset of first record to be
1806 retrieved from target. First record has offset 0 unlike the
1807 protocol specifications where first record has position 1.
1808 This option affects ZOOM_resultset_search and
1809 ZOOM_resultset_search_pqf and must be set before any of
1810 these functions are invoked. If a range of
1811 records must be fetched manually after search,
1812 function ZOOM_resultset_records should be used.
1813 </entry><entry>0</entry></row>
1815 count</entry><entry>Number of records to be retrieved.
1816 This option affects ZOOM_resultset_search and
1817 ZOOM_resultset_search_pqf and must be set before any of
1818 these functions are invoked.
1819 </entry><entry>0</entry></row>
1821 presentChunk</entry><entry>The number of records to be
1822 requested from the server in each chunk (present request). The
1823 value 0 means to request all the records in a single chunk.
1824 (The old <literal>step</literal>
1825 option is also supported for the benefit of old applications.)
1826 </entry><entry>0</entry></row>
1828 elementSetName</entry><entry>Element-Set name of records.
1829 Most targets should honor element set name <literal>B</literal>
1830 and <literal>F</literal> for brief and full respectively.
1831 </entry><entry>none</entry></row>
1833 preferredRecordSyntax</entry><entry>Preferred Syntax, such as
1834 <literal>USMARC</literal>, <literal>SUTRS</literal>, etc.
1835 </entry><entry>none</entry></row>
1837 schema</entry><entry>Schema for retrieval, such as
1838 <literal>Gils-schema</literal>, <literal>Geo-schema</literal>, etc.
1839 </entry><entry>none</entry></row>
1841 setname</entry><entry>Name of Result Set (Result Set ID).
1842 If this option isn't set, the ZOOM module will automatically
1843 allocate a result set name.
1844 </entry><entry>default</entry></row>
1846 rpnCharset</entry><entry>Character set for RPN terms.
1847 If this is set, ZOOM C will assume that the ZOOM application is
1848 running UTF-8. Terms in RPN queries are then converted to the
1849 rpnCharset. If this is unset, ZOOM C will not assume any encoding
1850 of RPN terms and no conversion is performed.
1851 </entry><entry>none</entry></row>
1856 For servers that support Search Info report, the following
1857 options may be read using <function>ZOOM_resultset_get</function>.
1858 This detailed information is read after a successful search has
1862 This information is a list of of items, where each item is
1863 information about a term or subquery. All items in the list
1865 <literal>SearchResult.</literal><replaceable>no</replaceable>
1866 where no presents the item number (0=first, 1=second).
1867 Read <literal>searchresult.size</literal> to determine the
1870 <table id="zoom.search.info.report.options"
1871 frame="top"><title>Search Info Report Options</title>
1873 <colspec colwidth="4*" colname="name"></colspec>
1874 <colspec colwidth="7*" colname="description"></colspec>
1877 <entry>Option</entry>
1878 <entry>Description</entry>
1883 <entry>searchresult.size</entry>
1885 number of search result entries. This option is-nonexistant
1886 if no entries are returned by the server.
1890 <entry>searchresult.<replaceable>no</replaceable>.id</entry>
1891 <entry>sub query ID</entry>
1894 <entry>searchresult.<replaceable>no</replaceable>.count</entry>
1895 <entry>result count for item (number of hits)</entry>
1898 <entry>searchresult.<replaceable>no</replaceable>.subquery.term</entry>
1899 <entry>subquery term</entry>
1903 searchresult.<replaceable>no</replaceable>.interpretation.term
1905 <entry>interpretation term</entry>
1909 searchresult.<replaceable>no</replaceable>.recommendation.term
1911 <entry>recommendation term</entry>
1916 <sect2 id="zoom.z3950.resultset.sort">
1917 <title>Z39.50 Result-set Sort</title>
1919 void ZOOM_resultset_sort(ZOOM_resultset r,
1920 const char *sort_type, const char *sort_spec);
1922 int ZOOM_resultset_sort1(ZOOM_resultset r,
1923 const char *sort_type, const char *sort_spec);
1926 <function>ZOOM_resultset_sort</function> and
1927 <function>ZOOM_resultset_sort1</function> both sort an existing
1928 result-set. The sort_type parameter is not use. Set it to "yaz".
1929 The sort_spec is same notation as ZOOM_query_sortby and identical
1930 to that offered by yaz-client's
1931 <link linkend="sortspec">sort command</link>.
1934 These functions only work for Z39.50. Use the more generic utility
1935 <link linkend="zoom.query.sortby2">
1936 <function>ZOOM_query_sortby2</function></link>
1937 for other protocols (and even Z39.50).
1940 <sect2 id="zoom.z3950.resultset.behavior">
1941 <title>Z39.50 Protocol behavior</title>
1943 The creation of a result set involves at least a SearchRequest
1944 - SearchResponse protocol handshake. Following that, if a sort
1945 criteria was specified as part of the query, a SortRequest -
1946 SortResponse handshake takes place. Note that it is necessary to
1947 perform sorting before any retrieval takes place, so no records will
1948 be returned from the target as part of the SearchResponse because these
1949 would be unsorted. Hence, piggyback is disabled when sort criteria
1950 are set. Following Search - and a possible sort - Retrieval takes
1951 place - as one or more Present Requests/Response pairs being
1955 The API allows for two different modes for retrieval. A high level
1956 mode which is somewhat more powerful and a low level one.
1957 The low level is enabled when searching on a Connection object
1958 for which the settings
1959 <literal>smallSetUpperBound</literal>,
1960 <literal>mediumSetPresentNumber</literal> and
1961 <literal>largeSetLowerBound</literal> are set. The low level mode
1962 thus allows you to precisely set how records are returned as part
1963 of a search response as offered by the Z39.50 protocol.
1964 Since the client may be retrieving records as part of the
1965 search response, this mode doesn't work well if sorting is used.
1968 The high-level mode allows you to fetch a range of records from
1969 the result set with a given start offset. When you use this mode
1970 the client will automatically use piggyback if that is possible
1971 with the target and perform one or more present requests as needed.
1972 Even if the target returns fewer records as part of a present response
1973 because of a record size limit, etc. the client will repeat sending
1974 present requests. As an example, if option <literal>start</literal>
1975 is 0 (default) and <literal>count</literal> is 4, and
1976 <literal>piggyback</literal> is 1 (default) and no sorting criteria
1977 is specified, then the client will attempt to retrieve the 4
1978 records as part the search response (using piggyback). On the other
1979 hand, if either <literal>start</literal> is positive or if
1980 a sorting criteria is set, or if <literal>piggyback</literal>
1981 is 0, then the client will not perform piggyback but send Present
1985 If either of the options <literal>mediumSetElementSetName</literal> and
1986 <literal>smallSetElementSetName</literal> are unset, the value
1987 of option <literal>elementSetName</literal> is used for piggyback
1988 searches. This means that for the high-level mode you only have
1989 to specify one elementSetName option rather than three.
1992 <sect2 id="zoom.sru.resultset.behavior">
1993 <title>SRU Protocol behavior</title>
1995 Current version of &yaz; does not take advantage of a result set id
1996 returned by the SRU server. Future versions might do, however.
1997 Since, the ZOOM driver does not save result set IDs any
1998 present (retrieval) is transformed to a SRU SearchRetrieveRequest
1999 with same query but, possibly, different offsets.
2002 Option <literal>schema</literal> specifies SRU schema
2003 for retrieval. However, options <literal>elementSetName</literal> and
2004 <literal>preferredRecordSyntax</literal> are ignored.
2007 Options <literal>start</literal> and <literal>count</literal>
2008 are supported by SRU.
2009 The remaining options
2010 <literal>piggyback</literal>,
2011 <literal>smallSetUpperBound</literal>,
2012 <literal>largeSetLowerBound</literal>,
2013 <literal>mediumSetPresentNumber</literal>,
2014 <literal>mediumSetElementSetName</literal>,
2015 <literal>smallSetElementSetName</literal> are
2019 SRU supports CQL queries, <emphasis>not</emphasis> PQF.
2020 If PQF is used, however, the PQF query is transferred anyway
2021 using non-standard element <literal>pQuery</literal> in
2022 SRU SearchRetrieveRequest.
2025 Solr queries has to be done in Solr query format.
2028 Unfortunately, SRU or Solr does not define a database setting. Hence,
2029 <literal>databaseName</literal> is unsupported and ignored.
2030 However, the path part in host parameter for functions
2031 <function>ZOOM_connecton_new</function> and
2032 <function>ZOOM_connection_connect</function> acts as a
2033 database (at least for the &yaz; SRU server).
2037 <sect1 id="zoom.records">
2038 <title>Records</title>
2040 A record object is a retrieval record on the client side -
2041 created from result sets.
2044 void ZOOM_resultset_records(ZOOM_resultset r,
2046 size_t start, size_t count);
2047 ZOOM_record ZOOM_resultset_record(ZOOM_resultset s, size_t pos);
2049 const char *ZOOM_record_get(ZOOM_record rec, const char *type,
2052 int ZOOM_record_error(ZOOM_record rec, const char **msg,
2053 const char **addinfo, const char **diagset);
2055 ZOOM_record ZOOM_record_clone(ZOOM_record rec);
2057 void ZOOM_record_destroy(ZOOM_record rec);
2060 References to temporary records are returned by functions
2061 <function>ZOOM_resultset_records</function> or
2062 <function>ZOOM_resultset_record</function>.
2065 If a persistent reference to a record is desired
2066 <function>ZOOM_record_clone</function> should be used.
2067 It returns a record reference that should be destroyed
2068 by a call to <function>ZOOM_record_destroy</function>.
2071 A single record is returned by function
2072 <function>ZOOM_resultset_record</function> that takes a
2073 position as argument. First record has position zero.
2074 If no record could be obtained <literal>NULL</literal> is returned.
2077 Error information for a record can be checked with
2078 <function>ZOOM_record_error</function> which returns non-zero
2079 (error code) if record is in error, called <emphasis>Surrogate
2080 Diagnostics</emphasis> in Z39.50.
2083 Function <function>ZOOM_resultset_records</function> retrieves
2084 a number of records from a result set. Parameter <literal>start</literal>
2085 and <literal>count</literal> specifies the range of records to
2086 be returned. Upon completion array
2087 <literal>recs[0], ..recs[count-1]</literal>
2088 holds record objects for the records. The array of records
2089 <literal>recs</literal> should be allocated prior the call
2090 <function>ZOOM_resultset_records</function>. Note that for those
2091 records that couldn't be retrieved from the target
2092 <literal>recs[ ..]</literal> is set to <literal>NULL</literal>.
2094 <para id="zoom.record.get">
2095 In order to extract information about a single record,
2096 <function>ZOOM_record_get</function> is provided. The
2097 function returns a pointer to certain record information. The
2098 nature (type) of the pointer depends on the parameter,
2099 <parameter>type</parameter>.
2102 The <parameter>type</parameter> is a string of the format:
2105 <replaceable>format</replaceable>[;charset=<replaceable>from</replaceable>[/<replaceable>opacfrom</replaceable>][,<replaceable>to</replaceable>]][;format=<replaceable>v</replaceable>]
2108 where <replaceable>format</replaceable> specifies the format of the
2109 returned record, <replaceable>from</replaceable>
2110 specifies the character set of the record in its original form
2111 (as returned by the server), <replaceable>to</replaceable> specifies
2112 the output (returned)
2113 character set encoding.
2114 If <replaceable>to</replaceable> is omitted UTF-8 is assumed.
2115 If charset is not given, then no character set conversion takes place.
2118 <para>OPAC records may be returned in a different
2119 set from the bibliographic MARC record. If this is this the case,
2120 <replaceable>opacfrom</replaceable> should be set to the character set
2121 of the OPAC record part.
2125 Specifying the OPAC record character set requires YAZ 4.1.5 or later.
2129 The format argument controls whether record data should be XML
2130 pretty-printed (post process operation).
2131 It is enabled only if format value <replaceable>v</replaceable> is
2132 <literal>1</literal> and the record content is XML well-formed.
2135 In addition, for certain types, the length
2136 <literal>len</literal> passed will be set to the size in bytes of
2137 the returned information.
2140 The following are the supported values for <replaceable>form</replaceable>.
2142 <varlistentry><term><literal>database</literal></term>
2143 <listitem><para>Database of record is returned
2144 as a C null-terminated string. Return type
2145 <literal>const char *</literal>.
2148 <varlistentry><term><literal>syntax</literal></term>
2149 <listitem><para>The transfer syntax of the record is returned
2150 as a C null-terminated string containing the symbolic name of
2151 the record syntax, e.g. <literal>Usmarc</literal>. Return type
2153 <literal>const char *</literal>.
2156 <varlistentry><term><literal>schema</literal></term>
2157 <listitem><para>The schema of the record is returned
2158 as a C null-terminated string. Return type is
2159 <literal>const char *</literal>.
2162 <varlistentry><term><literal>render</literal></term>
2163 <listitem><para>The record is returned in a display friendly
2164 format. Upon completion buffer is returned
2165 (type <literal>const char *</literal>) and length is stored in
2166 <literal>*len</literal>.
2169 <varlistentry><term><literal>raw</literal></term>
2170 <listitem><para>The record is returned in the internal
2171 YAZ specific format. For GRS-1, Explain, and others, the
2172 raw data is returned as type
2173 <literal>Z_External *</literal> which is just the type for
2174 the member <literal>retrievalRecord</literal> in
2175 type <literal>NamePlusRecord</literal>.
2176 For SUTRS and octet aligned record (including all MARCs) the
2177 octet buffer is returned and the length of the buffer.
2180 <varlistentry><term><literal>xml</literal></term>
2181 <listitem><para>The record is returned in XML if possible.
2182 SRU, Solr and Z39.50 records with transfer syntax XML are
2183 returned verbatim. MARC records are returned in
2184 <ulink url="&url.marcxml;">
2187 (converted from ISO2709 to MARCXML by YAZ).
2188 OPAC records are also converted to XML and the
2189 bibliographic record is converted to MARCXML (when possible).
2190 GRS-1 records are not supported for this form.
2191 Upon completion, the XML buffer is returned
2192 (type <literal>const char *</literal>) and length is stored in
2193 <literal>*len</literal>.
2196 <varlistentry><term><literal>opac</literal></term>
2197 <listitem><para>OPAC information for record is returned in XML
2198 if an OPAC record is present at the position given. If no
2199 OPAC record is present, a NULL pointer is returned.
2202 <varlistentry><term><literal>txml</literal></term>
2203 <listitem><para>The record is returned in TurboMARC if possible.
2204 SRU and Z39.50 records with transfer syntax XML are
2205 returned verbatim. MARC records are returned in
2206 <link linkend="tools.turbomarc">
2209 (converted from ISO2709 to TurboMARC by YAZ).
2210 Upon completion, the XML buffer is returned
2211 (type <literal>const char *</literal>) and length is stored in
2212 <literal>*len</literal>.
2215 <varlistentry><term><literal>json</literal></term>
2216 <listitem><para>Like xml, but MARC records are converted to
2217 <ulink url="&url.marc_in_json;">MARC-in-JSON</ulink>.
2225 <ulink url="&url.marc21;">MARC21</ulink>
2227 <ulink url="&url.marc8;">MARC-8</ulink>
2228 character set encoding.
2229 An application that wishes to display in Latin-1 would use
2231 render; charset=marc8,iso-8859-1
2234 <sect2 id="zoom.z3950.record.behavior">
2235 <title>Z39.50 Protocol behavior</title>
2237 The functions <function>ZOOM_resultset_record</function> and
2238 <function>ZOOM_resultset_records</function> inspects the client-side
2239 record cache. Records not found in cache are fetched using
2241 The functions may block (and perform network I/O) - even though option
2242 <literal>async</literal> is 1, because they return records objects.
2243 (and there's no way to return records objects without retrieving them!).
2246 There is a trick, however, in the usage of function
2247 <function>ZOOM_resultset_records</function> that allows for
2248 delayed retrieval (and makes it non-blocking). By using
2249 a null pointer for <parameter>recs</parameter> you're indicating
2250 you're not interested in getting records objects
2251 <emphasis>now</emphasis>.
2254 <sect2 id="zoom.sru.record.behavior">
2255 <title>SRU/Solr Protocol behavior</title>
2257 The ZOOM driver for SRU/Solr treats records returned by a SRU/Solr server
2258 as if they where Z39.50 records with transfer syntax XML and
2259 no element set name or database name.
2263 <sect1 id="zoom.facets"><title>Facets</title>
2265 Facet operations is not part of the official ZOOM specification, but
2266 is an Index Data extension for YAZ-based Z39.50 targets,
2267 <ulink url="&url.solr;">Solr</ulink> and SRU 2.0 targets.
2269 Facets may be requestd by the
2270 <link linkend="zoom.facets.option">facets</link> option before a
2272 For inspection of the returned facets, the following functions are
2276 ZOOM_facet_field *ZOOM_resultset_facets(ZOOM_resultset r);
2278 ZOOM_facet_field ZOOM_resultset_get_facet_field(ZOOM_resultset r,
2279 const char *facet_name);
2281 ZOOM_facet_field ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r,
2284 size_t ZOOM_resultset_facets_size(ZOOM_resultset r);
2286 const char *ZOOM_facet_field_name(ZOOM_facet_field facet_field);
2288 size_t ZOOM_facet_field_term_count(ZOOM_facet_field facet_field);
2290 const char *ZOOM_facet_field_get_term(ZOOM_facet_field facet_field,
2291 size_t idx, int *freq);
2294 References to temporary structures are returned by all functions.
2295 They are only valid as long the Result set is valid.
2296 <function>ZOOM_resultset_get_facet_field</function> or
2297 <function>ZOOM_resultset_get_facet_field_by_index</function>.
2298 <function>ZOOM_resultset_facets</function>.
2299 <function>ZOOM_facet_field_name</function>.
2300 <function>ZOOM_facet_field_get_term</function>.
2302 <para id="zoom.resultset.get_facet_field">
2303 A single Facet field is returned by function
2304 <function>ZOOM_resultset_get_facet_field</function> or
2305 <function>ZOOM_resultset_get_facet_field_by_index</function> that takes
2306 a result set and facet name or positive index respectively. First
2307 facet has position zero. If no facet could be obtained (invalid name
2308 or index out of bounds) <literal>NULL</literal> is returned.
2310 <para id="zoom.resultset.facets">
2311 An array of facets field can be returned by
2312 <function>ZOOM_resultset_facets</function>. The length of the array is
2313 given by <function>ZOOM_resultset_facets_size</function>. The array is
2314 zero-based and last entry will be at
2315 <function>ZOOM_resultset_facets_size(result_set)</function>-1.
2317 <para id="zoom.resultset.facets_names">
2318 It is possible to interate over facets by name, by calling
2319 <function>ZOOM_resultset_facets_names</function>.
2320 This will return an const array of char * where each string can be used
2321 as parameter for <function>ZOOM_resultset_get_facet_field</function>.
2324 Function <function>ZOOM_facet_field_name</function> gets the request
2325 facet name from a returned facet field.
2328 Function <function>ZOOM_facet_field_get_term</function> returns the
2329 idx'th term and term count for a facet field.
2330 Idx must between 0 and
2331 <function>ZOOM_facet_field_term_count</function>-1, otherwise the
2332 returned reference will be <literal>NULL</literal>. On a valid idx, the
2333 value of the freq reference will be the term count.
2334 The <literal>freq</literal> parameter must be valid pointer to integer.
2337 <sect1 id="zoom.scan"><title>Scan</title>
2339 This section describes an interface for Scan. Scan is not an
2340 official part of the ZOOM model yet. The result of a scan operation
2341 is the <literal>ZOOM_scanset</literal> which is a set of terms
2342 returned by a target.
2346 The Scan interface is supported for both Z39.50, SRU and Solr.
2350 ZOOM_scanset ZOOM_connection_scan(ZOOM_connection c,
2351 const char *startpqf);
2353 ZOOM_scanset ZOOM_connection_scan1(ZOOM_connection c,
2356 size_t ZOOM_scanset_size(ZOOM_scanset scan);
2358 const char *ZOOM_scanset_term(ZOOM_scanset scan, size_t pos,
2359 size_t *occ, size_t *len);
2361 const char *ZOOM_scanset_display_term(ZOOM_scanset scan, size_t pos,
2362 size_t *occ, size_t *len);
2364 void ZOOM_scanset_destroy(ZOOM_scanset scan);
2366 const char *ZOOM_scanset_option_get(ZOOM_scanset scan,
2369 void ZOOM_scanset_option_set(ZOOM_scanset scan, const char *key,
2373 The scan set is created by function
2374 <function>ZOOM_connection_scan</function> which performs a scan
2375 operation on the connection using the specified
2376 <parameter>startpqf</parameter>.
2377 If the operation was successful, the size of the scan set can be
2378 retrieved by a call to <function>ZOOM_scanset_size</function>.
2379 Like result sets, the items are numbered 0,..size-1.
2380 To obtain information about a particular scan term, call function
2381 <function>ZOOM_scanset_term</function>. This function takes
2382 a scan set offset <literal>pos</literal> and returns a pointer
2383 to a <emphasis>raw term</emphasis> or <literal>NULL</literal> if
2385 If present, the <literal>occ</literal> and <literal>len</literal>
2386 are set to the number of occurrences and the length
2387 of the actual term respectively.
2388 <function>ZOOM_scanset_display_term</function> is similar to
2389 <function>ZOOM_scanset_term</function> except that it returns
2390 the <emphasis>display term</emphasis> rather than the raw term.
2391 In a few cases, the term is different from display term. Always
2392 use the display term for display and the raw term for subsequent
2393 scan operations (to get more terms, next scan result, etc).
2396 A scan set may be freed by a call to function
2397 <function>ZOOM_scanset_destroy</function>.
2398 Functions <function>ZOOM_scanset_option_get</function> and
2399 <function>ZOOM_scanset_option_set</function> retrieves and sets
2400 an option respectively.
2403 The <parameter>startpqf</parameter> is a subset of PQF, namely
2404 the Attributes+Term part. Multiple <literal>@attr</literal> can
2405 be used. For example to scan in title (complete) phrases:
2407 @attr 1=4 @attr 6=2 "science o"
2411 The <function>ZOOM_connecton_scan1</function> is a newer and
2412 more generic alternative to <function>ZOOM_connection_scan</function>
2413 which allows to use both CQL and PQF for Scan.
2415 <table frame="top" id="zoom.scanset.options">
2416 <title>ZOOM Scan Set Options</title>
2418 <colspec colwidth="4*" colname="name"></colspec>
2419 <colspec colwidth="7*" colname="description"></colspec>
2420 <colspec colwidth="2*" colname="default"></colspec>
2423 <entry>Option</entry>
2424 <entry>Description</entry>
2425 <entry>Default</entry>
2430 number</entry><entry>Number of Scan Terms requested in next scan.
2431 After scan it holds the actual number of terms returned.
2432 </entry><entry>20</entry></row>
2434 position</entry><entry>Preferred Position of term in response
2435 in next scan; actual position after completion of scan.
2436 </entry><entry>1</entry></row>
2438 stepSize</entry><entry>Step Size
2439 </entry><entry>0</entry></row>
2441 scanStatus</entry><entry>An integer indicating the Scan Status
2443 </entry><entry>0</entry></row>
2445 rpnCharset</entry><entry>Character set for RPN terms.
2446 If this is set, ZOOM C will assume that the ZOOM application is
2447 running UTF-8. Terms in RPN queries are then converted to the
2448 rpnCharset. If this is unset, ZOOM C will not assume any encoding
2449 of RPN terms and no conversion is performed.
2450 </entry><entry>none</entry></row>
2455 <sect1 id="zoom.extendedservices">
2456 <title>Extended Services</title>
2458 ZOOM offers an interface to a subset of the Z39.50 extended services
2459 as well as a few privately defined ones:
2464 Z39.50 Item Order (ILL).
2465 See <xref linkend="zoom.item.order"/>.
2470 Record Update. This allows a client to insert, modify or delete
2472 See <xref linkend="zoom.record.update"/>.
2477 Database Create. This a non-standard feature. Allows a client
2478 to create a database.
2479 See <xref linkend="zoom.database.create"/>.
2484 Database Drop. This a non-standard feature. Allows a client
2485 to delete/drop a database.
2486 See <xref linkend="zoom.database.drop"/>.
2491 Commit operation. This a non-standard feature. Allows a client
2492 to commit operations.
2493 See <xref linkend="zoom.commit"/>.
2496 <!-- all the ILL PDU options should go here too -->
2499 To create an extended service operation a <literal>ZOOM_package</literal>
2500 must be created. The operation is a five step operation. The
2501 package is created, package is configured by means of options,
2502 the package is send, result is inspected (by means of options),
2503 the package is destroyed.
2506 ZOOM_package ZOOM_connection_package(ZOOM_connection c,
2507 ZOOM_options options);
2509 const char *ZOOM_package_option_get(ZOOM_package p,
2511 void ZOOM_package_option_set(ZOOM_package p, const char *key,
2513 void ZOOM_package_send(ZOOM_package p, const char *type);
2515 void ZOOM_package_destroy(ZOOM_package p);
2518 The <function>ZOOM_connection_package</function> creates a
2519 package for the connection given using the options specified.
2522 Functions <function>ZOOM_package_option_get</function> and
2523 <function>ZOOM_package_option_set</function> gets and sets
2527 <function>ZOOM_package_send</function> sends
2528 the package the via connection specified in
2529 <function>ZOOM_connection_package</function>.
2530 The <parameter>type</parameter> specifies the actual extended service
2531 package type to be sent.
2533 <table frame="top" id="zoom.extendedservices.options">
2534 <title>Extended Service Common Options</title>
2536 <colspec colwidth="4*" colname="name"></colspec>
2537 <colspec colwidth="7*" colname="description"></colspec>
2538 <colspec colwidth="3*" colname="default"></colspec>
2541 <entry>Option</entry>
2542 <entry>Description</entry>
2543 <entry>Default</entry>
2548 <entry>package-name</entry>
2549 <entry>Extended Service Request package name. Must be specified
2550 as part of a request</entry>
2554 <entry>user-id</entry>
2555 <entry>User ID of Extended Service Package. Is a request option</entry>
2559 <entry>function</entry>
2561 Function of package - one of <literal>create</literal>,
2562 <literal>delete</literal>, <literal>modify</literal>. Is
2565 <entry><literal>create</literal></entry>
2568 <entry>waitAction</entry>
2570 Wait action for package. Possible values:
2571 <literal>wait</literal>, <literal>waitIfPossible</literal>,
2572 <literal>dontWait</literal> or <literal>dontReturnPackage</literal>.
2574 <entry><literal>waitIfPossible</literal></entry>
2577 <entry>targetReference</entry>
2579 Target Reference. This is part of the response as returned
2580 by the server. Read it after a successful operation.
2582 <entry><literal>none</literal></entry>
2587 <sect2 id="zoom.item.order">
2588 <title>Item Order</title>
2590 For Item Order, type must be set to <literal>itemorder</literal> in
2591 <function>ZOOM_package_send</function>.
2594 <table frame="top" id="zoom.item.order.options">
2595 <title>Item Order Options</title>
2597 <colspec colwidth="4*" colname="name"></colspec>
2598 <colspec colwidth="7*" colname="description"></colspec>
2599 <colspec colwidth="3*" colname="default"></colspec>
2602 <entry>Option</entry>
2603 <entry>Description</entry>
2604 <entry>Default</entry>
2609 <entry>contact-name</entry>
2610 <entry>ILL contact name</entry>
2614 <entry>contact-phone</entry>
2615 <entry>ILL contact phone</entry>
2619 <entry>contact-email</entry>
2620 <entry>ILL contact email</entry>
2624 <entry>itemorder-item</entry>
2625 <entry>Position for item (record) requested. An integer</entry>
2632 <sect2 id="zoom.record.update">
2633 <title>Record Update</title>
2635 For Record Update, type must be set to <literal>update</literal> in
2636 <function>ZOOM_package_send</function>.
2638 <table frame="top" id="zoom.record.update.options">
2639 <title>Record Update Options</title>
2641 <colspec colwidth="4*" colname="name"></colspec>
2642 <colspec colwidth="7*" colname="description"></colspec>
2643 <colspec colwidth="3*" colname="default"></colspec>
2646 <entry>Option</entry>
2647 <entry>Description</entry>
2648 <entry>Default</entry>
2653 <entry>action</entry>
2655 The update action. One of
2656 <literal>specialUpdate</literal>,
2657 <literal>recordInsert</literal>,
2658 <literal>recordReplace</literal>,
2659 <literal>recordDelete</literal>,
2660 <literal>elementUpdate</literal>.
2662 <entry><literal>specialUpdate (recordInsert for updateVersion=1 which does not support specialUpdate)</literal></entry>
2665 <entry>recordIdOpaque</entry>
2666 <entry>Opaque Record ID</entry>
2670 <entry>recordIdNumber</entry>
2671 <entry>Record ID number</entry>
2675 <entry>record</entry>
2676 <entry>The record itself</entry>
2680 <entry>recordOpaque</entry>
2681 <entry>Specifies an opaque record which is
2682 encoded as an ASN.1 ANY type with the OID as tiven by option
2683 <literal>syntax</literal> (see below).
2684 Option <literal>recordOpaque</literal> is an alternative
2685 to record - and <literal>record</literal> option (above) is
2686 ignored if recordOpaque is set. This option is only available in
2687 YAZ 3.0.35 and later and is meant to facilitate Updates with
2693 <entry>syntax</entry>
2694 <entry>The record syntax (transfer syntax). Is a string that
2695 is a known record syntax.
2697 <entry>no syntax</entry>
2700 <entry>databaseName</entry>
2701 <entry>Database from connection object</entry>
2702 <entry>Default</entry>
2705 <entry>correlationInfo.note</entry>
2706 <entry>Correlation Info Note (string)</entry>
2710 <entry>correlationInfo.id</entry>
2711 <entry>Correlation Info ID (integer)</entry>
2715 <entry>elementSetName</entry>
2716 <entry>Element Set for Record</entry>
2720 <entry>updateVersion</entry>
2721 <entry>Record Update version which holds one of the values
2722 1, 2 or 3. Each version has a distinct OID:
2724 (<ulink url="&url.z39.50.extupdate1;">first version</ulink>) ,
2726 (second version) and
2727 1.2.840.10003.9.5.1.1
2728 (<ulink url="&url.z39.50.extupdate3;">third and
2729 newest version</ulink>).
2739 <sect2 id="zoom.database.create"><title>Database Create</title>
2741 For Database Create, type must be set to <literal>create</literal> in
2742 <function>ZOOM_package_send</function>.
2745 <table frame="top" id="zoom.database.create.options">
2746 <title>Database Create Options</title>
2748 <colspec colwidth="4*" colname="name"></colspec>
2749 <colspec colwidth="7*" colname="description"></colspec>
2750 <colspec colwidth="3*" colname="default"></colspec>
2753 <entry>Option</entry>
2754 <entry>Description</entry>
2755 <entry>Default</entry>
2760 <entry>databaseName</entry>
2761 <entry>Database from connection object</entry>
2762 <entry>Default</entry>
2768 <sect2 id="zoom.database.drop">
2769 <title>Database Drop</title>
2771 For Database Drop, type must be set to <literal>drop</literal> in
2772 <function>ZOOM_package_send</function>.
2774 <table frame="top" id="zoom.database.drop.options">
2775 <title>Database Drop Options</title>
2777 <colspec colwidth="4*" colname="name"></colspec>
2778 <colspec colwidth="7*" colname="description"></colspec>
2779 <colspec colwidth="3*" colname="default"></colspec>
2782 <entry>Option</entry>
2783 <entry>Description</entry>
2784 <entry>Default</entry>
2789 <entry>databaseName</entry>
2790 <entry>Database from connection object</entry>
2791 <entry>Default</entry>
2797 <sect2 id="zoom.commit">
2798 <title>Commit Operation</title>
2800 For Commit, type must be set to <literal>commit</literal> in
2801 <function>ZOOM_package_send</function>.
2804 <sect2 id="zoom.extended.services.behavior">
2805 <title>Protocol behavior</title>
2807 All the extended services are Z39.50-only.
2811 The database create, drop and commit services are privately defined
2813 Refer to <filename>esadmin.asn</filename> in YAZ for the ASN.1
2819 <sect1 id="zoom.options">
2820 <title>Options</title>
2822 Most &zoom; objects provide a way to specify options to change behavior.
2823 From an implementation point of view a set of options is just like
2824 an associative array / hash.
2827 ZOOM_options ZOOM_options_create(void);
2829 ZOOM_options ZOOM_options_create_with_parent(ZOOM_options parent);
2831 void ZOOM_options_destroy(ZOOM_options opt);
2834 const char *ZOOM_options_get(ZOOM_options opt, const char *name);
2836 void ZOOM_options_set(ZOOM_options opt, const char *name,
2840 typedef const char *(*ZOOM_options_callback)
2841 (void *handle, const char *name);
2843 ZOOM_options_callback
2844 ZOOM_options_set_callback(ZOOM_options opt,
2845 ZOOM_options_callback c,
2849 <sect1 id="zoom.queryconversions">
2850 <title>Query conversions</title>
2852 int ZOOM_query_cql2rpn(ZOOM_query s, const char *cql_str,
2853 ZOOM_connection conn);
2855 int ZOOM_query_ccl2rpn(ZOOM_query s, const char *ccl_str,
2857 int *ccl_error, const char **error_string,
2861 <function>ZOOM_query_cql2rpn</function> translates the CQL string,
2862 client-side, into RPN which may be passed to the server.
2863 This is useful for server's that don't themselves
2864 support CQL, for which <function>ZOOM_query_cql</function> is useless.
2865 `conn' is used only as a place to stash diagnostics if compilation
2866 fails; if this information is not needed, a null pointer may be used.
2867 The CQL conversion is driven by option <literal>cqlfile</literal> from
2868 connection conn. This specifies a conversion file (eg pqf.properties)
2869 which <emphasis>must</emphasis> be present.
2872 <function>ZOOM_query_ccl2rpn</function> translates the CCL string,
2873 client-side, into RPN which may be passed to the server.
2874 The conversion is driven by the specification given by
2875 <literal>config</literal>. Upon completion 0 is returned on success; -1
2876 is returned on on failure. Om failure <literal>error_string</literal> and
2877 <literal>error_pos</literal> holds error message and position of
2878 first error in original CCL string.
2881 <sect1 id="zoom.events"><title>Events</title>
2883 If you're developing non-blocking applications, you have to deal
2887 int ZOOM_event(int no, ZOOM_connection *cs);
2890 The <function>ZOOM_event</function> executes pending events for
2891 a number of connections. Supply the number of connections in
2892 <literal>no</literal> and an array of connections in
2893 <literal>cs</literal> (<literal>cs[0] ... cs[no-1]</literal>).
2894 A pending event could be a sending a search, receiving a response,
2896 When an event has occurred for one of the connections, this function
2897 returns a positive integer <literal>n</literal> denoting that an event
2898 occurred for connection <literal>cs[n-1]</literal>.
2899 When no events are pending for the connections, a value of zero is
2901 To ensure that all outstanding requests are performed call this function
2902 repeatedly until zero is returned.
2905 If <function>ZOOM_event</function> returns and returns non-zero, the
2906 last event that occurred can be expected.
2909 int ZOOM_connection_last_event(ZOOM_connection cs);
2912 <function>ZOOM_connection_last_event</function> returns an event type
2913 (integer) for the last event.
2916 <table frame="top" id="zoom.event.ids">
2917 <title>ZOOM Event IDs</title>
2919 <colspec colwidth="4*" colname="name"></colspec>
2920 <colspec colwidth="7*" colname="description"></colspec>
2923 <entry>Event</entry>
2924 <entry>Description</entry>
2929 <entry>ZOOM_EVENT_NONE</entry>
2930 <entry>No event has occurred</entry>
2933 <entry>ZOOM_EVENT_CONNECT</entry>
2934 <entry>TCP/IP connect has initiated</entry>
2937 <entry>ZOOM_EVENT_SEND_DATA</entry>
2938 <entry>Data has been transmitted (sending)</entry>
2941 <entry>ZOOM_EVENT_RECV_DATA</entry>
2942 <entry>Data has been received)</entry>
2945 <entry>ZOOM_EVENT_TIMEOUT</entry>
2946 <entry>Timeout</entry>
2949 <entry>ZOOM_EVENT_UNKNOWN</entry>
2950 <entry>Unknown event</entry>
2953 <entry>ZOOM_EVENT_SEND_APDU</entry>
2954 <entry>An APDU has been transmitted (sending)</entry>
2957 <entry>ZOOM_EVENT_RECV_APDU</entry>
2958 <entry>An APDU has been received</entry>
2961 <entry>ZOOM_EVENT_RECV_RECORD</entry>
2962 <entry>A result-set record has been received</entry>
2965 <entry>ZOOM_EVENT_RECV_SEARCH</entry>
2966 <entry>A search result been received</entry>
2973 <chapter id="server">
2974 <title>Generic server</title>
2975 <sect1 id="server.introduction"><title>Introduction</title>
2977 If you aren't into documentation, a good way to learn how the
2978 back end interface works is to look at the <filename>backend.h</filename>
2979 file. Then, look at the small dummy-server in
2980 <filename>ztest/ztest.c</filename>. The <filename>backend.h</filename>
2981 file also makes a good reference, once you've chewed your way through
2982 the prose of this file.
2985 If you have a database system that you would like to make available by
2986 means of Z39.50 or SRU, &yaz; basically offers your two options. You
2987 can use the APIs provided by the &asn;, &odr;, and &comstack;
2989 create and decode PDUs, and exchange them with a client.
2990 Using this low-level interface gives you access to all fields and
2991 options of the protocol, and you can construct your server as close
2992 to your existing database as you like.
2993 It is also a fairly involved process, requiring
2994 you to set up an event-handling mechanism, protocol state machine,
2995 etc. To simplify server implementation, we have implemented a compact
2996 and simple, but reasonably full-functioned server-frontend that will
2997 handle most of the protocol mechanics, while leaving you to
2998 concentrate on your database interface.
3002 The backend interface was designed in anticipation of a specific
3003 integration task, while still attempting to achieve some degree of
3004 generality. We realize fully that there are points where the
3005 interface can be improved significantly. If you have specific
3006 functions or parameters that you think could be useful, send us a
3007 mail (or better, sign on to the mailing list referred to in the
3008 top-level README file). We will try to fit good suggestions into future
3009 releases, to the extent that it can be done without requiring
3010 too many structural changes in existing applications.
3015 The &yaz; server does not support XCQL.
3019 <sect1 id="server.frontend">
3020 <title>The Database Frontend</title>
3022 We refer to this software as a generic database frontend. Your
3023 database system is the <emphasis>backend database</emphasis>, and the
3024 interface between the two is called the <emphasis>backend API</emphasis>.
3025 The backend API consists of a small number of function handlers and
3026 structure definitions. You are required to provide the
3027 <function>main()</function> routine for the server (which can be
3028 quite simple), as well as a set of handlers to match each of the
3030 The interface functions that you write can use any mechanism you like
3031 to communicate with your database system: You might link the whole
3032 thing together with your database application and access it by
3033 function calls; you might use IPC to talk to a database server
3034 somewhere; or you might link with third-party software that handles
3035 the communication for you (like a commercial database client library).
3036 At any rate, the handlers will perform the tasks of:
3049 Scanning the database index (optional - if you wish to implement SCAN).
3052 Extended Services (optional).
3055 Result-Set Delete (optional).
3058 Result-Set Sort (optional).
3061 Return Explain for SRU (optional).
3065 (more functions will be added in time to support as much of
3066 Z39.50-1995 as possible).
3069 <sect1 id="server.backend">
3070 <title>The Backend API</title>
3072 The header file that you need to use the interface are in the
3073 <filename>include/yaz</filename> directory. It's called
3074 <filename>backend.h</filename>. It will include other files from
3075 the <filename>include/yaz</filename> directory, so you'll
3076 probably want to use the -I option of your compiler to tell it
3077 where to find the files. When you run
3078 <literal>make</literal> in the top-level &yaz; directory,
3079 everything you need to create your server is to link with the
3080 <filename>lib/libyaz.la</filename> library.
3083 <sect1 id="server.main">
3084 <title>Your main() Routine</title>
3086 As mentioned, your <function>main()</function> routine can be quite brief.
3087 If you want to initialize global parameters, or read global configuration
3088 tables, this is the place to do it. At the end of the routine, you should
3092 int statserv_main(int argc, char **argv,
3093 bend_initresult *(*bend_init)(bend_initrequest *r),
3094 void (*bend_close)(void *handle));
3097 The third and fourth arguments are pointers to handlers. Handler
3098 <function>bend_init</function> is called whenever the server receives
3099 an Initialize Request, so it serves as a Z39.50 session initializer. The
3100 <function>bend_close</function> handler is called when the session is
3104 <function>statserv_main</function> will establish listening sockets
3105 according to the parameters given. When connection requests are received,
3106 the event handler will typically <function>fork()</function> and
3107 create a sub-process to handle a new connection.
3108 Alternatively the server may be setup to create threads for each
3110 If you do use global variables and forking, you should be aware, then,
3111 that these cannot be shared between associations, unless you explicitly
3112 disable forking by command line parameters.
3115 The server provides a mechanism for controlling some of its behavior
3116 without using command-line options. The function
3119 statserv_options_block *statserv_getcontrol(void);
3122 will return a pointer to a <literal>struct statserv_options_block</literal>
3123 describing the current default settings of the server. The structure
3124 contains these elements:
3127 <term><literal>int dynamic</literal></term>
3129 A boolean value, which determines whether the server
3130 will fork on each incoming request (TRUE), or not (FALSE). Default is
3131 TRUE. This flag is only read by UNIX-based servers (WIN32 based servers
3136 <term><literal>int threads</literal></term>
3138 A boolean value, which determines whether the server
3139 will create a thread on each incoming request (TRUE), or not (FALSE).
3140 Default is FALSE. This flag is only read by UNIX-based servers
3141 that offer POSIX Threads support.
3142 WIN32-based servers always operate in threaded mode.
3146 <term><literal>int inetd</literal></term>
3148 A boolean value, which determines whether the server
3149 will operates under a UNIX INET daemon (inetd). Default is FALSE.
3153 <term><literal>char logfile[ODR_MAXNAME+1]</literal></term>
3154 <listitem><para>File for diagnostic output ("": stderr).
3158 <term><literal>char apdufile[ODR_MAXNAME+1]</literal></term>
3160 Name of file for logging incoming and outgoing APDUs
3161 ("": don't log APDUs, "-":
3162 <literal>stderr</literal>).
3166 <term><literal>char default_listen[1024]</literal></term>
3167 <listitem><para>Same form as the command-line specification of
3168 listener address. "": no default listener address.
3169 Default is to listen at "tcp:@:9999". You can only
3170 specify one default listener address in this fashion.
3174 <term><literal>enum oid_proto default_proto;</literal></term>
3175 <listitem><para>Either <literal>PROTO_Z3950</literal> or
3176 <literal>PROTO_SR</literal>.
3177 Default is <literal>PROTO_Z39_50</literal>.
3181 <term><literal>int idle_timeout;</literal></term>
3182 <listitem><para>Maximum session idle-time, in minutes. Zero indicates
3183 no (infinite) timeout. Default is 15 minutes.
3187 <term><literal>int maxrecordsize;</literal></term>
3188 <listitem><para>Maximum permissible record (message) size. Default
3189 is 64 MB. This amount of memory will only be allocated if a
3190 client requests a very large amount of records in one operation
3192 Set it to a lower number if you are worried about resource
3193 consumption on your host system.
3197 <term><literal>char configname[ODR_MAXNAME+1]</literal></term>
3198 <listitem><para>Passed to the backend when a new connection is received.
3202 <term><literal>char setuid[ODR_MAXNAME+1]</literal></term>
3203 <listitem><para>Set user id to the user specified, after binding
3204 the listener addresses.
3209 <literal>void (*bend_start)(struct statserv_options_block *p)</literal>
3211 <listitem><para>Pointer to function which is called after the
3212 command line options have been parsed - but before the server
3214 For forked UNIX servers this handler is called in the mother
3215 process; for threaded servers this handler is called in the
3217 The default value of this pointer is NULL in which case it
3218 isn't invoked by the frontend server.
3219 When the server operates as an NT service this handler is called
3220 whenever the service is started.
3225 <literal>void (*bend_stop)(struct statserv_options_block *p)</literal>
3227 <listitem><para>Pointer to function which is called whenever the server
3228 has stopped listening for incoming connections. This function pointer
3229 has a default value of NULL in which case it isn't called.
3230 When the server operates as an NT service this handler is called
3231 whenever the service is stopped.
3235 <term><literal>void *handle</literal></term>
3236 <listitem><para>User defined pointer (default value NULL).
3237 This is a per-server handle that can be used to specify "user-data".
3238 Do not confuse this with the session-handle as returned by bend_init.
3244 The pointer returned by <literal>statserv_getcontrol</literal> points to
3245 a static area. You are allowed to change the contents of the structure,
3246 but the changes will not take effect before you call
3249 void statserv_setcontrol(statserv_options_block *block);
3253 that you should generally update this structure before calling
3254 <function>statserv_main()</function>.
3258 <sect1 id="server.backendfunctions">
3259 <title>The Backend Functions</title>
3261 For each service of the protocol, the backend interface declares one or
3262 two functions. You are required to provide implementations of the
3263 functions representing the services that you wish to implement.
3265 <sect2 id="server.init">
3268 bend_initresult (*bend_init)(bend_initrequest *r);
3271 This handler is called once for each new connection request, after
3272 a new process/thread has been created, and an Initialize Request has
3273 been received from the client. The pointer to the
3274 <function>bend_init</function> handler is passed in the call to
3275 <function>statserv_start</function>.
3278 This handler is also called when operating in SRU mode - when
3279 a connection has been made (even though SRU does not offer
3283 Unlike previous versions of YAZ, the <function>bend_init</function> also
3284 serves as a handler that defines the Z39.50 services that the backend
3285 wish to support. Pointers to <emphasis>all</emphasis> service handlers,
3286 including search - and fetch must be specified here in this handler.
3289 The request - and result structures are defined as
3292 typedef struct bend_initrequest
3294 /** \brief user/name/password to be read */
3295 Z_IdAuthentication *auth;
3296 /** \brief encoding stream (for results) */
3298 /** \brief printing stream */
3300 /** \brief decoding stream (use stream for results) */
3302 /** \brief reference ID */
3303 Z_ReferenceId *referenceId;
3304 /** \brief peer address of client */
3307 /** \brief character set and language negotiation
3309 see include/yaz/z-charneg.h
3311 Z_CharSetandLanguageNegotiation *charneg_request;
3313 /** \brief character negotiation response */
3314 Z_External *charneg_response;
3316 /** \brief character set (encoding) for query terms
3318 This is NULL by default. It should be set to the native character
3319 set that the backend assumes for query terms */
3320 char *query_charset;
3322 /** \brief whehter query_charset also applies to recors
3324 Is 0 (No) by default. Set to 1 (yes) if records is in the same
3325 character set as queries. If in doubt, use 0 (No).
3327 int records_in_same_charset;
3329 char *implementation_id;
3330 char *implementation_name;
3331 char *implementation_version;
3333 /** \brief Z39.50 sort handler */
3334 int (*bend_sort)(void *handle, bend_sort_rr *rr);
3335 /** \brief SRU/Z39.50 search handler */
3336 int (*bend_search)(void *handle, bend_search_rr *rr);
3337 /** \brief SRU/Z39.50 fetch handler */
3338 int (*bend_fetch)(void *handle, bend_fetch_rr *rr);
3339 /** \brief SRU/Z39.50 present handler */
3340 int (*bend_present)(void *handle, bend_present_rr *rr);
3341 /** \brief Z39.50 extended services handler */
3342 int (*bend_esrequest) (void *handle, bend_esrequest_rr *rr);
3343 /** \brief Z39.50 delete result set handler */
3344 int (*bend_delete)(void *handle, bend_delete_rr *rr);
3345 /** \brief Z39.50 scan handler */
3346 int (*bend_scan)(void *handle, bend_scan_rr *rr);
3347 /** \brief Z39.50 segment facility handler */
3348 int (*bend_segment)(void *handle, bend_segment_rr *rr);
3349 /** \brief SRU explain handler */
3350 int (*bend_explain)(void *handle, bend_explain_rr *rr);
3351 /** \brief SRU scan handler */
3352 int (*bend_srw_scan)(void *handle, bend_scan_rr *rr);
3353 /** \brief SRU record update handler */
3354 int (*bend_srw_update)(void *handle, bend_update_rr *rr);
3356 /** \brief whether named result sets are supported (0=disable, 1=enable) */
3357 int named_result_sets;
3360 typedef struct bend_initresult
3362 int errcode; /* 0==OK */
3363 char *errstring; /* system error string or NULL */
3364 void *handle; /* private handle to the backend module */
3368 In general, the server frontend expects that the
3369 <literal>bend_*result</literal> pointer that you return is valid at
3370 least until the next call to a <literal>bend_* function</literal>.
3371 This applies to all of the functions described herein. The parameter
3372 structure passed to you in the call belongs to the server frontend, and
3373 you should not make assumptions about its contents after the current
3374 function call has completed. In other words, if you want to retain any
3375 of the contents of a request structure, you should copy them.
3378 The <literal>errcode</literal> should be zero if the initialization of
3379 the backend went well. Any other value will be interpreted as an error.
3380 The <literal>errstring</literal> isn't used in the current version, but
3381 one option would be to stick it in the initResponse as a VisibleString.
3382 The <literal>handle</literal> is the most important parameter. It should
3383 be set to some value that uniquely identifies the current session to
3384 the backend implementation. It is used by the frontend server in any
3385 future calls to a backend function.
3386 The typical use is to set it to point to a dynamically allocated state
3387 structure that is private to your backend module.
3390 The <literal>auth</literal> member holds the authentication information
3391 part of the Z39.50 Initialize Request. Interpret this if your serves
3392 requires authentication.
3395 The members <literal>peer_name</literal>,
3396 <literal>implementation_id</literal>,
3397 <literal>implementation_name</literal> and
3398 <literal>implementation_version</literal> holds
3399 DNS of client, ID of implementor, name
3400 of client (Z39.50) implementation - and version.
3403 The <literal>bend_</literal> - members are set to NULL when
3404 <function>bend_init</function> is called. Modify the pointers by
3405 setting them to point to backend functions.
3408 <sect2 id="server.search.retrieve">
3409 <title>Search and Retrieve</title>
3411 We now describe the handlers that are required to support search -
3412 and retrieve. You must support two functions - one for search - and one
3413 for fetch (retrieval of one record). If desirable you can provide a
3414 third handler which is called when a present request is received which
3415 allows you to optimize retrieval of multiple-records.
3418 int (*bend_search) (void *handle, bend_search_rr *rr);
3421 char *setname; /* name to give to this set */
3422 int replace_set; /* replace set, if it already exists */
3423 int num_bases; /* number of databases in list */
3424 char **basenames; /* databases to search */
3425 Z_ReferenceId *referenceId;/* reference ID */
3426 Z_Query *query; /* query structure */
3427 ODR stream; /* encode stream */
3428 ODR decode; /* decode stream */
3429 ODR print; /* print stream */
3431 bend_request request;
3432 bend_association association;
3434 int hits; /* number of hits */
3435 int errcode; /* 0==OK */
3436 char *errstring; /* system error string or NULL */
3437 Z_OtherInformation *search_info; /* additional search info */
3438 char *srw_sortKeys; /* holds SRU/SRW sortKeys info */
3439 char *srw_setname; /* holds SRU/SRW generated resultsetID */
3440 int *srw_setnameIdleTime; /* holds SRU/SRW life-time */
3441 int estimated_hit_count; /* if hit count is estimated */
3442 int partial_resultset; /* if result set is partial */
3446 The <function>bend_search</function> handler is a fairly close
3447 approximation of a protocol Z39.50 Search Request - and Response PDUs
3448 The <literal>setname</literal> is the resultSetName from the protocol.
3449 You are required to establish a mapping between the set name and whatever
3450 your backend database likes to use.
3451 Similarly, the <literal>replace_set</literal> is a boolean value
3452 corresponding to the resultSetIndicator field in the protocol.
3453 <literal>num_bases/basenames</literal> is a length of/array of character
3454 pointers to the database names provided by the client.
3455 The <literal>query</literal> is the full query structure as defined in
3456 the protocol ASN.1 specification.
3457 It can be either of the possible query types, and it's up to you to
3458 determine if you can handle the provided query type.
3459 Rather than reproduce the C interface here, we'll refer you to the
3460 structure definitions in the file
3461 <filename>include/yaz/z-core.h</filename>. If you want to look at the
3462 attributeSetId OID of the RPN query, you can either match it against
3463 your own internal tables, or you can use the <link linkend="tools.oid">
3467 The structure contains a number of hits, and an
3468 <literal>errcode/errstring</literal> pair. If an error occurs
3469 during the search, or if you're unhappy with the request, you should
3470 set the errcode to a value from the BIB-1 diagnostic set. The value
3471 will then be returned to the user in a nonsurrogate diagnostic record
3472 in the response. The <literal>errstring</literal>, if provided, will
3473 go in the addinfo field. Look at the protocol definition for the
3474 defined error codes, and the suggested uses of the addinfo field.
3477 The <function>bend_search</function> handler is also called when
3478 the frontend server receives a SRU SearchRetrieveRequest.
3479 For SRU, a CQL query is usually provided by the client.
3480 The CQL query is available as part of <literal>Z_Query</literal>
3481 structure (note that CQL is now part of Z39.50 via an external).
3482 To support CQL in existing implementations that only do Type-1,
3483 we refer to the CQL-to-PQF tool described
3484 <link linkend="cql.to.pqf">here</link>.
3487 To maintain backwards compatibility, the frontend server
3488 of yaz always assume that error codes are BIB-1 diagnostics.
3489 For SRU operation, a Bib-1 diagnostic code is mapped to
3493 int (*bend_fetch) (void *handle, bend_fetch_rr *rr);
3495 typedef struct bend_fetch_rr {
3496 char *setname; /* set name */
3497 int number; /* record number */
3498 Z_ReferenceId *referenceId;/* reference ID */
3499 Odr_oid *request_format; /* format, transfer syntax (OID) */
3500 Z_RecordComposition *comp; /* Formatting instructions */
3501 ODR stream; /* encoding stream - memory source if req */
3502 ODR print; /* printing stream */
3504 char *basename; /* name of database that provided record */
3505 int len; /* length of record or -1 if structured */
3506 char *record; /* record */
3507 int last_in_set; /* is it? */
3508 Odr_oid *output_format; /* response format/syntax (OID) */
3509 int errcode; /* 0==success */
3510 char *errstring; /* system error string or NULL */
3511 int surrogate_flag; /* surrogate diagnostic */
3512 char *schema; /* string record schema input/output */
3516 The frontend server calls the <function>bend_fetch</function> handler
3517 when it needs database records to fulfill a Z39.50 Search Request, a
3518 Z39.50 Present Request or a SRU SearchRetrieveRequest.
3519 The <literal>setname</literal> is simply the name of the result set
3520 that holds the reference to the desired record.
3521 The <literal>number</literal> is the offset into the set (with 1
3522 being the first record in the set). The <literal>format</literal> field
3523 is the record format requested by the client (See
3524 <xref linkend="tools.oid"/>).
3525 A value of NULL for <literal>format</literal> indicates that the
3526 client did not request a specific format.
3527 The <literal>stream</literal> argument is an &odr; stream which
3528 should be used for allocating space for structured data records.
3529 The stream will be reset when all records have been assembled, and
3530 the response package has been transmitted.
3531 For unstructured data, the backend is responsible for maintaining a
3532 static or dynamic buffer for the record between calls.
3535 If a SRU SearchRetrieveRequest is received by the frontend server,
3536 the <literal>referenceId</literal> is NULL and the
3537 <literal>format</literal> (transfer syntax) is the OID for XML.
3538 The schema for SRU is stored in both the
3539 <literal>Z_RecordComposition</literal>
3540 structure and <literal>schema</literal> (simple string).
3543 In the structure, the <literal>basename</literal> is the name of the
3544 database that holds the
3545 record. <literal>len</literal> is the length of the record returned, in
3546 bytes, and <literal>record</literal> is a pointer to the record.
3547 <literal>last_in_set</literal> should be nonzero only if the record
3548 returned is the last one in the given result set.
3549 <literal>errcode</literal> and <literal>errstring</literal>, if
3550 given, will be interpreted as a global error pertaining to the
3551 set, and will be returned in a non-surrogate-diagnostic.
3552 If you wish to return the error as a surrogate-diagnostic
3553 (local error) you can do this by setting
3554 <literal>surrogate_flag</literal> to 1 also.
3557 If the <literal>len</literal> field has the value -1, then
3558 <literal>record</literal> is assumed to point to a constructed data
3559 type. The <literal>format</literal> field will be used to determine
3560 which encoder should be used to serialize the data.
3564 If your backend generates structured records, it should use
3565 <function>odr_malloc()</function> on the provided stream for allocating
3566 data: This allows the frontend server to keep track of the record sizes.
3570 The <literal>format</literal> field is mapped to an object identifier
3571 in the direct reference of the resulting EXTERNAL representation
3576 The current version of &yaz; only supports the direct reference mode.
3580 int (*bend_present) (void *handle, bend_present_rr *rr);
3583 char *setname; /* set name */
3585 int number; /* record number */
3586 Odr_oid *format; /* format, transfer syntax (OID) */
3587 Z_ReferenceId *referenceId;/* reference ID */
3588 Z_RecordComposition *comp; /* Formatting instructions */
3589 ODR stream; /* encoding stream - memory source if required */
3590 ODR print; /* printing stream */
3591 bend_request request;
3592 bend_association association;
3594 int hits; /* number of hits */
3595 int errcode; /* 0==OK */
3596 char *errstring; /* system error string or NULL */
3600 The <function>bend_present</function> handler is called when
3601 the server receives a Z39.50 Present Request.
3602 The <literal>setname</literal>,
3603 <literal>start</literal> and <literal>number</literal> is the
3604 name of the result set - start position - and number of records to
3605 be retrieved respectively. <literal>format</literal> and
3606 <literal>comp</literal> is the preferred transfer syntax and element
3607 specifications of the present request.
3610 Note that this is handler serves as a supplement for
3611 <function>bend_fetch</function> and need not to be defined in order to
3612 support search - and retrieve.
3615 <sect2 id="server.delete">
3616 <title>Delete</title>
3618 For back-ends that supports delete of a result set only one handler
3622 int (*bend_delete)(void *handle, bend_delete_rr *rr);
3624 typedef struct bend_delete_rr {
3628 Z_ReferenceId *referenceId;
3629 int delete_status; /* status for the whole operation */
3630 int *statuses; /* status each set - indexed as setnames */
3637 The delete set function definition is rather primitive, mostly because
3638 we have had no practical need for it as of yet. If someone wants
3639 to provide a full delete service, we'd be happy to add the
3640 extra parameters that are required. Are there clients out there
3641 that will actually delete sets they no longer need?
3645 <sect2 id="server.scan">
3648 For servers that wish to offer the scan service one handler
3652 int (*bend_scan)(void *handle, bend_scan_rr *rr);
3655 BEND_SCAN_SUCCESS, /* ok */
3656 BEND_SCAN_PARTIAL /* not all entries could be found */
3659 typedef struct bend_scan_rr {
3660 int num_bases; /* number of elements in databaselist */
3661 char **basenames; /* databases to search */
3662 Odr_oid *attributeset;
3663 Z_ReferenceId *referenceId; /* reference ID */
3664 Z_AttributesPlusTerm *term;
3665 ODR stream; /* encoding stream - memory source if required */
3666 ODR print; /* printing stream */
3668 int *step_size; /* step size */
3669 int term_position; /* desired index of term in result list/returned */
3670 int num_entries; /* number of entries requested/returned */
3672 /* scan term entries. The called handler does not have
3673 to allocate this. Size of entries is num_entries (see above) */
3674 struct scan_entry *entries;
3675 bend_scan_status status;
3678 char *scanClause; /* CQL scan clause */
3679 char *setname; /* Scan in result set (NULL if omitted) */
3683 This backend server handles both Z39.50 scan
3684 and SRU scan. In order for a handler to distinguish between SRU (CQL) scan
3685 Z39.50 Scan , it must check for a non-NULL value of
3686 <literal>scanClause</literal>.
3690 if designed today, it would be a choice using a union or similar,
3691 but that would break binary compatibility with existing servers.
3696 <sect1 id="server.invocation">
3697 <title>Application Invocation</title>
3699 The finished application has the following
3700 invocation syntax (by way of <function>statserv_main()</function>):
3708 A listener specification consists of a transport mode followed by a
3709 colon (:) followed by a listener address. The transport mode is
3710 either <literal>tcp</literal>, <literal>unix:</literal> or
3711 <literal>ssl</literal>.
3714 For TCP and SSL, an address has the form
3717 hostname | IP-number [: portnumber]
3720 The port number defaults to 210 (standard Z39.50 port).
3723 For UNIX, the address is the filename of socket.
3726 For TCP/IP and SSL, the special hostnames <literal>@</literal>,
3727 maps to <literal>IN6ADDR_ANY_INIT</literal> with
3728 IPV4 binding as well (bindv6only=0),
3729 The special hostname <literal>@4</literal> binds to
3730 <literal>INADDR_ANY</literal> (IPV4 only listener).
3731 The special hostname <literal>@6</literal> binds to
3732 <literal>IN6ADDR_ANY_INIT</literal> with bindv6only=1 (IPV6 only listener).
3734 <example id="server.example.running.unix">
3735 <title>Running the GFS on Unix</title>
3737 Assuming the server application <replaceable>appname</replaceable> is
3738 started as root, the following will make it listen on port 210.
3739 The server will change identity to <literal>nobody</literal>
3740 and write its log to <filename>/var/log/app.log</filename>.
3742 application -l /var/log/app.log -u nobody tcp:@:210
3746 The server will accept Z39.50 requests and offer SRU service on port 210.
3749 <example id="server.example.apache.sru">
3750 <title>Setting up Apache as SRU Frontend</title>
3752 If you use <ulink url="&url.apache;">Apache</ulink>
3753 as your public web server and want to offer HTTP port 80
3754 access to the YAZ server on 210, you can use the
3755 <ulink url="&url.apache.directive.proxypass;">
3756 <literal>ProxyPass</literal></ulink>
3758 If you have virtual host
3759 <literal>srw.mydomain</literal> you can use the following directives
3760 in Apache's httpd.conf:
3763 ErrorLog /home/srw/logs/error_log
3764 TransferLog /home/srw/logs/access_log
3765 ProxyPass / http://srw.mydomain:210/
3770 The above for the Apache 1.3 series.
3773 <example id="server.example.local.access">
3774 <title>Running a server with local access only</title>
3776 Servers that is only being accessed from the local host should listen
3777 on UNIX file socket rather than a Internet socket. To listen on
3778 <filename>/tmp/mysocket</filename> start the server as follows:
3780 application unix:/tmp/mysocket
3785 <sect1 id="server.vhosts">
3786 <title>GFS Configuration and Virtual Hosts</title>
3791 <title>The Z39.50 ASN.1 Module</title>
3792 <sect1 id="asn.introduction">
3793 <title>Introduction</title>
3795 The &asn; module provides you with a set of C struct definitions for the
3796 various PDUs of the Z39.50 protocol, as well as for the complex types
3797 appearing within the PDUs. For the primitive data types, the C
3798 representation often takes the form of an ordinary C language type,
3799 such as <literal>Odr_int</literal> which is equivalent to an integral
3800 C integer. For ASN.1 constructs that have no direct
3801 representation in C, such as general octet strings and bit strings,
3802 the &odr; module (see section <link linkend="odr">The ODR Module</link>)
3803 provides auxiliary definitions.
3806 The &asn; module is located in sub directory <filename>z39.50</filename>.
3807 There you'll find C files that implements encoders and decoders for the
3808 Z39.50 types. You'll also find the protocol definitions:
3809 <filename>z3950v3.asn</filename>, <filename>esupdate.asn</filename>,
3813 <sect1 id="asn.preparing">
3814 <title>Preparing PDUs</title>
3816 A structure representing a complex ASN.1 type doesn't in itself contain the
3817 members of that type. Instead, the structure contains
3818 <emphasis>pointers</emphasis> to the members of the type.
3819 This is necessary, in part, to allow a mechanism for specifying which
3820 of the optional structure (SEQUENCE) members are present, and which
3821 are not. It follows that you will need to somehow provide space for
3822 the individual members of the structure, and set the pointers to
3823 refer to the members.
3826 The conversion routines don't care how you allocate and maintain your
3827 C structures - they just follow the pointers that you provide.
3828 Depending on the complexity of your application, and your personal
3829 taste, there are at least three different approaches that you may take
3830 when you allocate the structures.
3833 You can use static or automatic local variables in the function that
3834 prepares the PDU. This is a simple approach, and it provides the most
3835 efficient form of memory management. While it works well for flat
3836 PDUs like the InitReqest, it will generally not be sufficient for say,
3837 the generation of an arbitrarily complex RPN query structure.
3840 You can individually create the structure and its members using the
3841 <function>malloc(2)</function> function. If you want to ensure that
3842 the data is freed when it is no longer needed, you will have to
3843 define a function that individually releases each member of a
3844 structure before freeing the structure itself.
3847 You can use the <function>odr_malloc()</function> function (see
3848 <xref linkend="odr.use"/> for details). When you use
3849 <function>odr_malloc()</function>, you can release all of the
3850 allocated data in a single operation, independent of any pointers and
3851 relations between the data. <function>odr_malloc()</function> is based on a
3852 "nibble-memory"
3853 scheme, in which large portions of memory are allocated, and then
3854 gradually handed out with each call to <function>odr_malloc()</function>.
3855 The next time you call <function>odr_reset()</function>, all of the
3856 memory allocated since the last call is recycled for future use (actually,
3857 it is placed on a free-list).
3860 You can combine all of the methods described here. This will often be
3861 the most practical approach. For instance, you might use
3862 <function>odr_malloc()</function> to allocate an entire structure and
3863 some of its elements, while you leave other elements pointing to global
3864 or per-session default variables.
3867 The &asn; module provides an important aid in creating new PDUs. For
3868 each of the PDU types (say, <function>Z_InitRequest</function>), a
3869 function is provided that allocates and initializes an instance of
3870 that PDU type for you. In the case of the InitRequest, the function is
3871 simply named <function>zget_InitRequest()</function>, and it sets up
3872 reasonable default value for all of the mandatory members. The optional
3873 members are generally initialized to null pointers. This last aspect
3874 is very important: it ensures that if the PDU definitions are
3875 extended after you finish your implementation (to accommodate
3876 new versions of the protocol, say), you won't get into trouble with
3877 uninitialized pointers in your structures. The functions use
3878 <function>odr_malloc()</function> to
3879 allocate the PDUs and its members, so you can free everything again with a
3880 single call to <function>odr_reset()</function>. We strongly recommend
3881 that you use the <literal>zget_*</literal>
3882 functions whenever you are preparing a PDU (in a C++ API, the
3883 <literal>zget_</literal>
3884 functions would probably be promoted to constructors for the
3888 The prototype for the individual PDU types generally look like this:
3891 Z_<type> *zget_<type>(ODR o);
3897 Z_InitRequest *zget_InitRequest(ODR o);
3900 The &odr; handle should generally be your encoding stream, but it
3904 As well as the individual PDU functions, a function
3905 <function>zget_APDU()</function> is provided, which allocates
3906 a top-level Z-APDU of the type requested:
3909 Z_APDU *zget_APDU(ODR o, int which);
3912 The <varname>which</varname> parameter is (of course) the discriminator
3913 belonging to the <varname>Z_APDU</varname> <literal>CHOICE</literal> type.
3914 All of the interface described here is provided by the &asn; module, and
3915 you access it through the <filename>proto.h</filename> header file.
3918 <sect1 id="asn.external">
3919 <title>EXTERNAL Data</title>
3921 In order to achieve extensibility and adaptability to different
3922 application domains, the new version of the protocol defines many
3923 structures outside of the main ASN.1 specification, referencing them
3924 through ASN.1 EXTERNAL constructs. To simplify the construction and
3925 access to the externally referenced data, the &asn; module defines a
3926 specialized version of the EXTERNAL construct, called
3927 <literal>Z_External</literal>.It is defined thus:
3930 typedef struct Z_External
3932 Odr_oid *direct_reference;
3933 int *indirect_reference;
3938 Z_External_single = 0,
3940 Z_External_arbitrary,
3942 /* Specific types */
3944 Z_External_explainRecord,
3945 Z_External_resourceReport1,
3946 Z_External_resourceReport2
3954 Odr_any *single_ASN1_type;
3955 Odr_oct *octet_aligned;
3956 Odr_bitmask *arbitrary;
3958 /* Specific types */
3960 Z_ExplainRecord *explainRecord;
3961 Z_ResourceReport1 *resourceReport1;
3962 Z_ResourceReport2 *resourceReport2;
3970 When decoding, the &asn; module will attempt to determine which
3971 syntax describes the data by looking at the reference fields
3972 (currently only the direct-reference). For ASN.1 structured data, you
3973 need only consult the <literal>which</literal> field to determine the
3974 type of data. You can the access the data directly through the union.
3975 When constructing data for encoding, you set the union pointer to point
3976 to the data, and set the <literal>which</literal> field accordingly.
3977 Remember also to set the direct (or indirect) reference to the correct
3978 OID for the data type.
3979 For non-ASN.1 data such as MARC records, use the
3980 <literal>octet_aligned</literal> arm of the union.
3983 Some servers return ASN.1 structured data values (eg. database
3984 records) as BER-encoded records placed in the
3985 <literal>octet-aligned</literal> branch of the EXTERNAL CHOICE.
3986 The ASN-module will <emphasis>not</emphasis> automatically decode
3987 these records. To help you decode the records in the application, the
3991 Z_ext_typeent *z_ext_gettypebyref(const oid *oid);
3994 Can be used to retrieve information about the known, external data
3995 types. The function return a pointer to a static area, or NULL, if no
3996 match for the given direct reference is found. The
3997 <literal>Z_ext_typeent</literal>
4001 typedef struct Z_ext_typeent
4003 int oid[OID_SIZE]; /* the direct-reference OID. */
4004 int what; /* discriminator value for the external CHOICE */
4005 Odr_fun fun; /* decoder function */
4009 The <literal>what</literal> member contains the
4010 <literal>Z_External</literal> union discriminator value for the
4011 given type: For the SUTRS record syntax, the value would be
4012 <literal>Z_External_sutrs</literal>.
4013 The <literal>fun</literal> member contains a pointer to the
4014 function which encodes/decodes the given type. Again, for the SUTRS
4015 record syntax, the value of <literal>fun</literal> would be
4016 <literal>z_SUTRS</literal> (a function pointer).
4019 If you receive an EXTERNAL which contains an octet-string value that
4020 you suspect of being an ASN.1-structured data value, you can use
4021 <literal>z_ext_gettypebyref</literal> to look for the provided
4023 If the return value is different from NULL, you can use the provided
4024 function to decode the BER string (see <xref linkend="odr.use"/>
4028 If you want to <emphasis>send</emphasis> EXTERNALs containing
4029 ASN.1-structured values in the occtet-aligned branch of the CHOICE, this
4030 is possible too. However, on the encoding phase, it requires a somewhat
4031 involved juggling around of the various buffers involved.
4034 If you need to add new, externally defined data types, you must update
4035 the struct above, in the source file <filename>prt-ext.h</filename>, as
4036 well as the encoder/decoder in the file <filename>prt-ext.c</filename>.
4037 When changing the latter, remember to update both the
4038 <literal>arm</literal> arrary and the list
4039 <literal>type_table</literal>, which drives the CHOICE biasing that
4040 is necessary to tell the different, structured types apart
4045 Eventually, the EXTERNAL processing will most likely
4046 automatically insert the correct OIDs or indirect-refs. First,
4047 however, we need to determine how application-context management
4048 (specifically the presentation-context-list) should fit into the
4053 <sect1 id="asn.pdu">
4054 <title>PDU Contents Table</title>
4056 We include, for reference, a listing of the fields of each top-level
4057 PDU, as well as their default settings.
4059 <table frame="top" id="asn.default.initialize.request">
4060 <title>Default settings for PDU Initialize Request</title>
4062 <colspec colwidth="7*" colname="field"></colspec>
4063 <colspec colwidth="5*" colname="type"></colspec>
4064 <colspec colwidth="7*" colname="value"></colspec>
4067 <entry>Field</entry>
4069 <entry>Default Value</entry>
4074 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4077 protocolVersion</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
4080 options</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
4083 preferredMessageSize</entry><entry>Odr_int</entry><entry>30*1024
4086 maximumRecordSize</entry><entry>Odr_int</entry><entry>30*1024
4089 idAuthentication</entry><entry>Z_IdAuthentication</entry><entry>NULL
4092 implementationId</entry><entry>char*</entry><entry>"81"
4095 implementationName</entry><entry>char*</entry><entry>"YAZ"
4098 implementationVersion</entry><entry>char*</entry><entry>YAZ_VERSION
4101 userInformationField</entry><entry>Z_UserInformation</entry><entry>NULL
4104 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4109 <table frame="top" id="asn.default.initialize.response">
4110 <title>Default settings for PDU Initialize Response</title>
4112 <colspec colwidth="7*" colname="field"></colspec>
4113 <colspec colwidth="5*" colname="type"></colspec>
4114 <colspec colwidth="7*" colname="value"></colspec>
4117 <entry>Field</entry>
4119 <entry>Default Value</entry>
4124 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4127 protocolVersion</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
4130 options</entry><entry>Odr_bitmask</entry><entry>Empty bitmask
4133 preferredMessageSize</entry><entry>Odr_int</entry><entry>30*1024
4136 maximumRecordSize</entry><entry>Odr_int</entry><entry>30*1024
4139 result</entry><entry>Odr_bool</entry><entry>TRUE
4142 implementationId</entry><entry>char*</entry><entry>"id)"
4145 implementationName</entry><entry>char*</entry><entry>"YAZ"
4148 implementationVersion</entry><entry>char*</entry><entry>YAZ_VERSION
4151 userInformationField</entry><entry>Z_UserInformation</entry><entry>NULL
4154 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4159 <table frame="top" id="asn.default.search.request">
4160 <title>Default settings for PDU Search Request</title>
4162 <colspec colwidth="7*" colname="field"></colspec>
4163 <colspec colwidth="5*" colname="type"></colspec>
4164 <colspec colwidth="7*" colname="value"></colspec>
4167 <entry>Field</entry>
4169 <entry>Default Value</entry>
4174 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4177 smallSetUpperBound</entry><entry>Odr_int</entry><entry>0
4180 largeSetLowerBound</entry><entry>Odr_int</entry><entry>1
4183 mediumSetPresentNumber</entry><entry>Odr_int</entry><entry>0
4186 replaceIndicator</entry><entry>Odr_bool</entry><entry>TRUE
4189 resultSetName</entry><entry>char *</entry><entry>"default"
4192 num_databaseNames</entry><entry>Odr_int</entry><entry>0
4195 databaseNames</entry><entry>char **</entry><entry>NULL
4198 smallSetElementSetNames</entry><entry>Z_ElementSetNames
4202 mediumSetElementSetNames</entry><entry>Z_ElementSetNames
4206 preferredRecordSyntax</entry><entry>Odr_oid</entry><entry>NULL
4209 query</entry><entry>Z_Query</entry><entry>NULL
4212 additionalSearchInfo</entry><entry>Z_OtherInformation
4216 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4221 <table frame="top" id="asn.default.search.response">
4222 <title>Default settings for PDU Search Response</title>
4224 <colspec colwidth="7*" colname="field"></colspec>
4225 <colspec colwidth="5*" colname="type"></colspec>
4226 <colspec colwidth="7*" colname="value"></colspec>
4229 <entry>Field</entry>
4231 <entry>Default Value</entry>
4236 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4239 resultCount</entry><entry>Odr_int</entry><entry>0
4242 numberOfRecordsReturned</entry><entry>Odr_int</entry><entry>0
4245 nextResultSetPosition</entry><entry>Odr_int</entry><entry>0
4248 searchStatus</entry><entry>Odr_bool</entry><entry>TRUE
4251 resultSetStatus</entry><entry>Odr_int</entry><entry>NULL
4254 presentStatus</entry><entry>Odr_int</entry><entry>NULL
4257 records</entry><entry>Z_Records</entry><entry>NULL
4260 additionalSearchInfo</entry>
4261 <entry>Z_OtherInformation</entry><entry>NULL
4264 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4269 <table frame="top" id="asn.default.present.request">
4270 <title>Default settings for PDU Present Request</title>
4272 <colspec colwidth="7*" colname="field"></colspec>
4273 <colspec colwidth="5*" colname="type"></colspec>
4274 <colspec colwidth="7*" colname="value"></colspec>
4277 <entry>Field</entry>
4279 <entry>Default Value</entry>
4284 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4287 resultSetId</entry><entry>char*</entry><entry>"default"
4290 resultSetStartPoint</entry><entry>Odr_int</entry><entry>1
4293 numberOfRecordsRequested</entry><entry>Odr_int</entry><entry>10
4296 num_ranges</entry><entry>Odr_int</entry><entry>0
4299 additionalRanges</entry><entry>Z_Range</entry><entry>NULL
4302 recordComposition</entry><entry>Z_RecordComposition</entry><entry>NULL
4305 preferredRecordSyntax</entry><entry>Odr_oid</entry><entry>NULL
4308 maxSegmentCount</entry><entry>Odr_int</entry><entry>NULL
4311 maxRecordSize</entry><entry>Odr_int</entry><entry>NULL
4314 maxSegmentSize</entry><entry>Odr_int</entry><entry>NULL
4317 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4322 <table frame="top" id="asn.default.present.response">
4323 <title>Default settings for PDU Present Response</title>
4325 <colspec colwidth="7*" colname="field"></colspec>
4326 <colspec colwidth="5*" colname="type"></colspec>
4327 <colspec colwidth="7*" colname="value"></colspec>
4330 <entry>Field</entry>
4332 <entry>Default Value</entry>
4337 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4340 numberOfRecordsReturned</entry><entry>Odr_int</entry><entry>0
4343 nextResultSetPosition</entry><entry>Odr_int</entry><entry>0
4346 presentStatus</entry><entry>Odr_int</entry><entry>Z_PresentStatus_success
4349 records</entry><entry>Z_Records</entry><entry>NULL
4352 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4357 <table frame="top" id="asn.default.delete.result.set.request">
4358 <title>Default settings for Delete Result Set Request</title>
4360 <colspec colwidth="7*" colname="field"></colspec>
4361 <colspec colwidth="5*" colname="type"></colspec>
4362 <colspec colwidth="7*" colname="value"></colspec>
4365 <entry>Field</entry>
4367 <entry>Default Value</entry>
4371 <row><entry>referenceId
4372 </entry><entry>Z_ReferenceId</entry><entry>NULL
4375 deleteFunction</entry><entry>Odr_int</entry><entry>Z_DeleteResultSetRequest_list
4378 num_ids</entry><entry>Odr_int</entry><entry>0
4381 resultSetList</entry><entry>char**</entry><entry>NULL
4384 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4389 <table frame="top" id="asn.default.delete.result.set.response">
4390 <title>Default settings for Delete Result Set Response</title>
4392 <colspec colwidth="7*" colname="field"></colspec>
4393 <colspec colwidth="5*" colname="type"></colspec>
4394 <colspec colwidth="7*" colname="value"></colspec>
4397 <entry>Field</entry>
4399 <entry>Default Value</entry>
4404 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4407 deleteOperationStatus</entry><entry>Odr_int</entry>
4408 <entry>Z_DeleteStatus_success</entry></row>
4410 num_statuses</entry><entry>Odr_int</entry><entry>0
4413 deleteListStatuses</entry><entry>Z_ListStatus**</entry><entry>NULL
4416 numberNotDeleted</entry><entry>Odr_int</entry><entry>NULL
4419 num_bulkStatuses</entry><entry>Odr_int</entry><entry>0
4422 bulkStatuses</entry><entry>Z_ListStatus</entry><entry>NUL
4425 deleteMessage</entry><entry>char*</entry><entry>NULL
4428 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4433 <table frame="top" id="asn.default.scan.request">
4434 <title>Default settings for Scan Request</title>
4436 <colspec colwidth="7*" colname="field"></colspec>
4437 <colspec colwidth="5*" colname="type"></colspec>
4438 <colspec colwidth="7*" colname="value"></colspec>
4441 <entry>Field</entry>
4443 <entry>Default Value</entry>
4448 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4451 num_databaseNames</entry><entry>Odr_int</entry><entry>0
4454 databaseNames</entry><entry>char**</entry><entry>NULL
4457 attributeSet</entry><entry>Odr_oid</entry><entry>NULL
4460 termListAndStartPoint</entry><entry>Z_AttributesPlus...
4461 </entry><entry>NULL</entry></row>
4463 stepSize</entry><entry>Odr_int</entry><entry>NULL
4466 numberOfTermsRequested</entry><entry>Odr_int</entry><entry>20
4469 preferredPositionInResponse</entry><entry>Odr_int</entry><entry>NULL
4472 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4477 <table frame="top" id="asn.default.scan.response">
4478 <title>Default settings for Scan Response</title>
4480 <colspec colwidth="7*" colname="field"></colspec>
4481 <colspec colwidth="5*" colname="type"></colspec>
4482 <colspec colwidth="7*" colname="value"></colspec>
4485 <entry>Field</entry>
4487 <entry>Default Value</entry>
4492 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4495 stepSize</entry><entry>Odr_int</entry><entry>NULL
4498 scanStatus</entry><entry>Odr_int</entry><entry>Z_Scan_success
4501 numberOfEntriesReturned</entry><entry>Odr_int</entry><entry>0
4504 positionOfTerm</entry><entry>Odr_int</entry><entry>NULL
4507 entries</entry><entry>Z_ListEntris</entry><entry>NULL
4510 attributeSet</entry><entry>Odr_oid</entry><entry>NULL
4513 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4518 <table frame="top" id="asn.default.trigger.resource.control.request">
4519 <title>Default settings for Trigger Resource Control Request</title>
4521 <colspec colwidth="7*" colname="field"></colspec>
4522 <colspec colwidth="5*" colname="type"></colspec>
4523 <colspec colwidth="7*" colname="value"></colspec>
4526 <entry>Field</entry>
4528 <entry>Default Value</entry>
4533 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4536 requestedAction</entry><entry>Odr_int</entry><entry>
4537 Z_TriggerResourceCtrl_resou..
4540 prefResourceReportFormat</entry><entry>Odr_oid</entry><entry>NULL
4543 resultSetWanted</entry><entry>Odr_bool</entry><entry>NULL
4546 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4551 <table frame="top" id="asn.default.resource.control.request">
4552 <title>Default settings for Resource Control Request</title>
4554 <colspec colwidth="7*" colname="field"></colspec>
4555 <colspec colwidth="5*" colname="type"></colspec>
4556 <colspec colwidth="7*" colname="value"></colspec>
4559 <entry>Field</entry>
4561 <entry>Default Value</entry>
4566 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4569 suspendedFlag</entry><entry>Odr_bool</entry><entry>NULL
4572 resourceReport</entry><entry>Z_External</entry><entry>NULL
4575 partialResultsAvailable</entry><entry>Odr_int</entry><entry>NULL
4578 responseRequired</entry><entry>Odr_bool</entry><entry>FALSE
4581 triggeredRequestFlag</entry><entry>Odr_bool</entry><entry>NULL
4584 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4589 <table frame="top" id="asn.default.resource.control.response">
4590 <title>Default settings for Resource Control Response</title>
4592 <colspec colwidth="7*" colname="field"></colspec>
4593 <colspec colwidth="5*" colname="type"></colspec>
4594 <colspec colwidth="7*" colname="value"></colspec>
4597 <entry>Field</entry>
4599 <entry>Default Value</entry>
4604 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4607 continueFlag</entry><entry>bool_t</entry><entry>TRUE
4610 resultSetWanted</entry><entry>bool_t</entry><entry>NULL
4613 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4618 <table frame="top" id="asn.default.access.control.request">
4619 <title>Default settings for Access Control Request</title>
4621 <colspec colwidth="7*" colname="field"></colspec>
4622 <colspec colwidth="5*" colname="type"></colspec>
4623 <colspec colwidth="7*" colname="value"></colspec>
4626 <entry>Field</entry>
4628 <entry>Default Value</entry>
4633 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4636 which</entry><entry>enum</entry><entry>Z_AccessRequest_simpleForm;
4639 u</entry><entry>union</entry><entry>NULL
4642 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4647 <table frame="top" id="asn.default.access.control.response">
4648 <title>Default settings for Access Control Response</title>
4650 <colspec colwidth="7*" colname="field"></colspec>
4651 <colspec colwidth="5*" colname="type"></colspec>
4652 <colspec colwidth="7*" colname="value"></colspec>
4655 <entry>Field</entry>
4657 <entry>Default Value</entry>
4662 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4665 which</entry><entry>enum</entry><entry>Z_AccessResponse_simpleForm
4668 u</entry><entry>union</entry><entry>NULL
4671 diagnostic</entry><entry>Z_DiagRec</entry><entry>NULL
4674 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4679 <table frame="top" id="asn.default.segment">
4680 <title>Default settings for Segment</title>
4682 <colspec colwidth="7*" colname="field"></colspec>
4683 <colspec colwidth="5*" colname="type"></colspec>
4684 <colspec colwidth="7*" colname="value"></colspec>
4687 <entry>Field</entry>
4689 <entry>Default Value</entry>
4694 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4697 numberOfRecordsReturned</entry><entry>Odr_int</entry><entry>value=0
4700 num_segmentRecords</entry><entry>Odr_int</entry><entry>0
4703 segmentRecords</entry><entry>Z_NamePlusRecord</entry><entry>NULL
4705 <row><entry>otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4710 <table frame="top" id="asn.default.close">
4711 <title>Default settings for Close</title>
4713 <colspec colwidth="7*" colname="field"></colspec>
4714 <colspec colwidth="5*" colname="type"></colspec>
4715 <colspec colwidth="7*" colname="value"></colspec>
4718 <entry>Field</entry>
4720 <entry>Default Value</entry>
4725 referenceId</entry><entry>Z_ReferenceId</entry><entry>NULL
4728 closeReason</entry><entry>Odr_int</entry><entry>Z_Close_finished
4731 diagnosticInformation</entry><entry>char*</entry><entry>NULL
4734 resourceReportFormat</entry><entry>Odr_oid</entry><entry>NULL
4737 resourceFormat</entry><entry>Z_External</entry><entry>NULL
4740 otherInfo</entry><entry>Z_OtherInformation</entry><entry>NULL
4748 <title>SOAP and SRU</title>
4749 <sect1 id="soap.introduction">
4750 <title>Introduction</title>
4752 &yaz; uses a very simple implementation of
4753 <ulink url="&url.soap;">SOAP</ulink> that only,
4754 currenly, supports what is sufficient to offer SRU SOAP functionality.
4755 The implementation uses the
4756 <ulink url="&url.libxml2.api.tree;">tree API</ulink> of
4757 libxml2 to encode and decode SOAP packages.
4760 Like the Z39.50 ASN.1 module, the &yaz; SRU implementation uses
4761 simple C structs to represent SOAP packages as well as
4765 <sect1 id="soap.http">
4768 &yaz; only offers HTTP as transport carrier for SOAP, but it is
4769 relatively easy to change that.
4772 The following definition of <literal>Z_GDU</literal> (Generic Data
4773 Unit) allows for both HTTP and Z39.50 in one packet.
4776 #include <yaz/zgdu.h>
4778 #define Z_GDU_Z3950 1
4779 #define Z_GDU_HTTP_Request 2
4780 #define Z_GDU_HTTP_Response 3
4785 Z_HTTP_Request *HTTP_Request;
4786 Z_HTTP_Response *HTTP_Response;
4791 The corresponding Z_GDU encoder/decoder is <function>z_GDU</function>.
4792 The <literal>z3950</literal> is any of the known BER encoded Z39.50
4794 <literal>HTTP_Request</literal> and <literal>HTTP_Response</literal>
4795 is the HTTP Request and Response respectively.
4798 <sect1 id="soap.xml">
4799 <title>SOAP Packages</title>
4801 Every SOAP package in &yaz; is represented as follows:
4803 #include <yaz/soap.h>
4817 #define Z_SOAP_fault 1
4818 #define Z_SOAP_generic 2
4819 #define Z_SOAP_error 3
4823 Z_SOAP_Fault *fault;
4824 Z_SOAP_Generic *generic;
4825 Z_SOAP_Fault *soap_error;
4832 The <literal>fault</literal> and <literal>soap_error</literal>
4833 arms represent both a SOAP fault - struct
4834 <literal>Z_SOAP_Fault</literal>. Any other generic
4835 (valid) package is represented by <literal>Z_SOAP_Generic</literal>.
4838 The <literal>ns</literal> as part of <literal>Z_SOAP</literal>
4839 is the namespace for SOAP itself and reflects the SOAP
4840 version. For version 1.1 it is
4841 <literal>http://schemas.xmlsoap.org/soap/envelope/</literal>,
4842 for version 1.2 it is
4843 <literal>http://www.w3.org/2001/06/soap-envelope</literal>.
4846 int z_soap_codec(ODR o, Z_SOAP **pp,
4847 char **content_buf, int *content_len,
4848 Z_SOAP_Handler *handlers);
4851 The <literal>content_buf</literal> and <literal>content_len</literal>
4852 is XML buffer and length of buffer respectively.
4855 The <literal>handlers</literal> is a list of SOAP codec
4856 handlers - one handler for each service namespace. For SRU SOAP, the
4857 namespace would be <literal>http://www.loc.gov/zing/srw/v1.0/</literal>.
4860 When decoding, the <function>z_soap_codec</function>
4861 inspects the XML content
4862 and tries to match one of the services namespaces of the
4863 supplied handlers. If there is a match a handler function
4864 is invoked which decodes that particular SOAP package.
4865 If successful, the returned <literal>Z_SOAP</literal> package will be
4866 of type <literal>Z_SOAP_Generic</literal>.
4867 Member <literal>no</literal> is
4868 set the offset of handler that matched; <literal>ns</literal>
4869 is set to namespace of matching handler; the void pointer
4870 <literal>p</literal> is set to the C data structure assocatiated
4874 When a NULL namespace is met (member <literal>ns</literal> bwlow),
4875 that specifies end-of-list.
4878 Each handler is defined as follows:
4886 The <literal>ns</literal> is namespace of service associated with
4887 handler <literal>f</literal>. <literal>client_data</literal>
4888 is user-defined data which is passed to handler.
4891 The prototype for a SOAP service handler is:
4893 int handler(ODR o, void * ptr, void **handler_data,
4894 void *client_data, const char *ns);
4896 The <parameter>o</parameter> specifies the mode (decode/encode)
4897 as usual. The second argument, <parameter>ptr</parameter>,
4898 is a libxml2 tree node pointer (<literal>xmlNodePtr</literal>)
4899 and is a pointer to the <literal>Body</literal> element
4900 of the SOAP package. The <parameter>handler_data</parameter>
4901 is an opaque pointer to a C definitions associated with the
4902 SOAP service. <parameter>client_data</parameter> is the pointer
4903 which was set as part of the <literal>Z_SOAP_handler</literal>.
4904 Finally, <parameter>ns</parameter> the service namespace.
4907 <sect1 id="soap.srw">
4910 SRU SOAP is just one implementation of a SOAP handler as described
4911 in the previous section.
4912 The encoder/decoder handler for SRU is defined as
4915 #include <yaz/srw.h>
4917 int yaz_srw_codec(ODR o, void * pptr,
4918 Z_SRW_GDU **handler_data,
4919 void *client_data, const char *ns);
4921 Here, <literal>Z_SRW_GDU</literal> is either
4922 searchRetrieveRequest or a searchRetrieveResponse.
4926 The xQuery and xSortKeys are not handled yet by
4927 the SRW implementation of &yaz;. Explain is also missing.
4928 Future versions of &yaz; will include these features.
4932 The definition of searchRetrieveRequest is:
4936 #define Z_SRW_query_type_cql 1
4937 #define Z_SRW_query_type_xcql 2
4938 #define Z_SRW_query_type_pqf 3
4946 #define Z_SRW_sort_type_none 1
4947 #define Z_SRW_sort_type_sort 2
4948 #define Z_SRW_sort_type_xSort 3
4956 int *maximumRecords;
4958 char *recordPacking;
4960 } Z_SRW_searchRetrieveRequest;
4962 Please observe that data of type xsd:string is represented
4963 as a char pointer (<literal>char *</literal>). A null pointer
4964 means that the element is absent.
4965 Data of type xsd:integer is representd as a pointer to
4966 an int (<literal>int *</literal>). Again, a null pointer
4967 us used for absent elements.
4970 The SearchRetrieveResponse has the following definition.
4973 int * numberOfRecords;
4975 int * resultSetIdleTime;
4977 Z_SRW_record *records;
4980 Z_SRW_diagnostic *diagnostics;
4981 int num_diagnostics;
4982 int *nextRecordPosition;
4983 } Z_SRW_searchRetrieveResponse;
4985 The <literal>num_records</literal> and <literal>num_diagnostics</literal>
4986 is number of returned records and diagnostics respectively and also
4987 correspond to the "size of" arrays <literal>records</literal>
4988 and <literal>diagnostics</literal>.
4991 A retrieval record is defined as follows:
4995 char *recordData_buf;
4997 int *recordPosition;
5000 The record data is defined as a buffer of some length so that
5001 data can be of any type. SRW 1.0 currenly doesn't allow for this
5002 (only XML), but future versions might do.
5005 And, a diagnostic as:
5015 <chapter id="tools">
5016 <title>Supporting Tools</title>
5018 In support of the service API - primarily the ASN module, which
5019 provides the pro-grammatic interface to the Z39.50 APDUs, &yaz; contains
5020 a collection of tools that support the development of applications.
5022 <sect1 id="tools.query">
5023 <title>Query Syntax Parsers</title>
5025 Since the type-1 (RPN) query structure has no direct, useful string
5026 representation, every origin application needs to provide some form of
5027 mapping from a local query notation or representation to a
5028 <token>Z_RPNQuery</token> structure. Some programmers will prefer to
5029 construct the query manually, perhaps using
5030 <function>odr_malloc()</function> to simplify memory management.
5031 The &yaz; distribution includes three separate, query-generating tools
5032 that may be of use to you.
5035 <title>Prefix Query Format</title>
5037 Since RPN or reverse polish notation is really just a fancy way of
5038 describing a suffix notation format (operator follows operands), it
5039 would seem that the confusion is total when we now introduce a prefix
5040 notation for RPN. The reason is one of simple laziness - it's somewhat
5041 simpler to interpret a prefix format, and this utility was designed
5042 for maximum simplicity, to provide a baseline representation for use
5043 in simple test applications and scripting environments (like Tcl). The
5044 demonstration client included with YAZ uses the PQF.
5048 The PQF have been adopted by other parties developing Z39.50
5049 software. It is often referred to as Prefix Query Notation
5054 The PQF is defined by the pquery module in the YAZ library.
5055 There are two sets of function that have similar behavior. First
5056 set operates on a PQF parser handle, second set doesn't. First set
5057 set of functions are more flexible than the second set. Second set
5058 is obsolete and is only provided to ensure backwards compatibility.
5061 First set of functions all operate on a PQF parser handle:
5064 #include <yaz/pquery.h>
5066 YAZ_PQF_Parser yaz_pqf_create(void);
5068 void yaz_pqf_destroy(YAZ_PQF_Parser p);
5070 Z_RPNQuery *yaz_pqf_parse(YAZ_PQF_Parser p, ODR o, const char *qbuf);
5072 Z_AttributesPlusTerm *yaz_pqf_scan(YAZ_PQF_Parser p, ODR o,
5073 Odr_oid **attributeSetId, const char *qbuf);
5075 int yaz_pqf_error(YAZ_PQF_Parser p, const char **msg, size_t *off);
5078 A PQF parser is created and destructed by functions
5079 <function>yaz_pqf_create</function> and
5080 <function>yaz_pqf_destroy</function> respectively.
5081 Function <function>yaz_pqf_parse</function> parses query given
5082 by string <literal>qbuf</literal>. If parsing was successful,
5083 a Z39.50 RPN Query is returned which is created using ODR stream
5084 <literal>o</literal>. If parsing failed, a NULL pointer is
5086 Function <function>yaz_pqf_scan</function> takes a scan query in
5087 <literal>qbuf</literal>. If parsing was successful, the function
5088 returns attributes plus term pointer and modifies
5089 <literal>attributeSetId</literal> to hold attribute set for the
5090 scan request - both allocated using ODR stream <literal>o</literal>.
5091 If parsing failed, yaz_pqf_scan returns a NULL pointer.
5092 Error information for bad queries can be obtained by a call to
5093 <function>yaz_pqf_error</function> which returns an error code and
5094 modifies <literal>*msg</literal> to point to an error description,
5095 and modifies <literal>*off</literal> to the offset within last
5096 query were parsing failed.
5099 The second set of functions are declared as follows:
5102 #include <yaz/pquery.h>
5104 Z_RPNQuery *p_query_rpn(ODR o, oid_proto proto, const char *qbuf);
5106 Z_AttributesPlusTerm *p_query_scan(ODR o, oid_proto proto,
5107 Odr_oid **attributeSetP, const char *qbuf);
5109 int p_query_attset(const char *arg);
5112 The function <function>p_query_rpn()</function> takes as arguments an
5113 &odr; stream (see section <link linkend="odr">The ODR Module</link>)
5114 to provide a memory source (the structure created is released on
5115 the next call to <function>odr_reset()</function> on the stream), a
5116 protocol identifier (one of the constants <token>PROTO_Z3950</token> and
5117 <token>PROTO_SR</token>), an attribute set reference, and
5118 finally a null-terminated string holding the query string.
5121 If the parse went well, <function>p_query_rpn()</function> returns a
5122 pointer to a <literal>Z_RPNQuery</literal> structure which can be
5123 placed directly into a <literal>Z_SearchRequest</literal>.
5124 If parsing failed, due to syntax error, a NULL pointer is returned.
5127 The <literal>p_query_attset</literal> specifies which attribute set
5128 to use if the query doesn't specify one by the
5129 <literal>@attrset</literal> operator.
5130 The <literal>p_query_attset</literal> returns 0 if the argument is a
5131 valid attribute set specifier; otherwise the function returns -1.
5134 The grammar of the PQF is as follows:
5137 query ::= top-set query-struct.
5139 top-set ::= [ '@attrset' string ]
5141 query-struct ::= attr-spec | simple | complex | '@term' term-type query
5143 attr-spec ::= '@attr' [ string ] string query-struct
5145 complex ::= operator query-struct query-struct.
5147 operator ::= '@and' | '@or' | '@not' | '@prox' proximity.
5149 simple ::= result-set | term.
5151 result-set ::= '@set' string.
5155 proximity ::= exclusion distance ordered relation which-code unit-code.
5157 exclusion ::= '1' | '0' | 'void'.
5159 distance ::= integer.
5161 ordered ::= '1' | '0'.
5163 relation ::= integer.
5165 which-code ::= 'known' | 'private' | integer.
5167 unit-code ::= integer.
5169 term-type ::= 'general' | 'numeric' | 'string' | 'oid' | 'datetime' | 'null'.
5172 You will note that the syntax above is a fairly faithful
5173 representation of RPN, except for the Attribute, which has been
5174 moved a step away from the term, allowing you to associate one or more
5175 attributes with an entire query structure. The parser will
5176 automatically apply the given attributes to each term as required.
5179 The @attr operator is followed by an attribute specification
5180 (<literal>attr-spec</literal> above). The specification consists
5181 of an optional attribute set, an attribute type-value pair and
5182 a sub-query. The attribute type-value pair is packed in one string:
5183 an attribute type, an equals sign, and an attribute value, like this:
5184 <literal>@attr 1=1003</literal>.
5185 The type is always an integer but the value may be either an
5186 integer or a string (if it doesn't start with a digit character).
5187 A string attribute-value is encoded as a Type-1 ``complex''
5188 attribute with the list of values containing the single string
5189 specified, and including no semantic indicators.
5192 Version 3 of the Z39.50 specification defines various encoding of terms.
5193 Use <literal>@term </literal> <replaceable>type</replaceable>
5194 <replaceable>string</replaceable>,
5195 where type is one of: <literal>general</literal>,
5196 <literal>numeric</literal> or <literal>string</literal>
5197 (for InternationalString).
5198 If no term type has been given, the <literal>general</literal> form
5199 is used. This is the only encoding allowed in both versions 2 and 3
5200 of the Z39.50 standard.
5202 <sect3 id="PQF-prox">
5203 <title>Using Proximity Operators with PQF</title>
5206 This is an advanced topic, describing how to construct
5207 queries that make very specific requirements on the
5208 relative location of their operands.
5209 You may wish to skip this section and go straight to
5210 <link linkend="pqf-examples">the example PQF queries</link>.
5215 Most Z39.50 servers do not support proximity searching, or
5216 support only a small subset of the full functionality that
5217 can be expressed using the PQF proximity operator. Be
5218 aware that the ability to <emphasis>express</emphasis> a
5219 query in PQF is no guarantee that any given server will
5220 be able to <emphasis>execute</emphasis> it.
5226 The proximity operator <literal>@prox</literal> is a special
5227 and more restrictive version of the conjunction operator
5228 <literal>@and</literal>. Its semantics are described in
5229 section 3.7.2 (Proximity) of Z39.50 the standard itself, which
5230 can be read on-line at
5231 <ulink url="&url.z39.50.proximity;"/>
5234 In PQF, the proximity operation is represented by a sequence
5237 @prox <replaceable>exclusion</replaceable> <replaceable>distance</replaceable> <replaceable>ordered</replaceable> <replaceable>relation</replaceable> <replaceable>which-code</replaceable> <replaceable>unit-code</replaceable>
5239 in which the meanings of the parameters are as described in in
5240 the standard, and they can take the following values:
5243 <formalpara><title>exclusion</title>
5245 0 = false (i.e. the proximity condition specified by the
5246 remaining parameters must be satisfied) or
5247 1 = true (the proximity condition specified by the
5248 remaining parameters must <emphasis>not</emphasis> be
5254 <formalpara><title>distance</title><para>
5255 An integer specifying the difference between the locations
5256 of the operands: e.g. two adjacent words would have
5257 distance=1 since their locations differ by one unit.
5259 </formalpara></listitem>
5261 <formalpara><title>ordered</title><para>
5262 1 = ordered (the operands must occur in the order the
5263 query specifies them) or
5264 0 = unordered (they may appear in either order).
5269 <formalpara><title>relation</title><para>
5270 Recognised values are
5272 2 (lessThanOrEqual),
5274 4 (greaterThanOrEqual),
5281 <formalpara><title>which-code</title><para>
5282 <literal>known</literal>
5284 <literal>k</literal>
5285 (the unit-code parameter is taken from the well-known list
5286 of alternatives described in below) or
5287 <literal>private</literal>
5289 <literal>p</literal>
5290 (the unit-code paramater has semantics specific to an
5291 out-of-band agreement such as a profile).
5296 <formalpara><title>unit-code</title><para>
5297 If the which-code parameter is <literal>known</literal>
5298 then the recognised values are
5308 10 (elementType) and
5310 If which-code is <literal>private</literal> then the
5311 acceptable values are determined by the profile.
5316 (The numeric values of the relation and well-known unit-code
5317 parameters are taken straight from
5318 <ulink url="&url.z39.50.proximity.asn1;"
5319 >the ASN.1</ulink> of the proximity structure in the standard.)
5322 <sect3 id="pqf-examples">
5323 <title>PQF queries</title>
5324 <example id="example.pqf.simple.terms">
5325 <title>PQF queries using simple terms</title>
5334 <example id="pqf.example.pqf.boolean.operators">
5335 <title>PQF boolean operators</title>
5338 @or "dylan" "zimmerman"
5340 @and @or dylan zimmerman when
5342 @and when @or dylan zimmerman
5346 <example id="example.pqf.result.sets">
5347 <title>PQF references to result sets</title>
5352 @and @set seta @set setb
5356 <example id="example.pqf.attributes">
5357 <title>Attributes for terms</title>
5362 @attr 1=4 @attr 4=1 "self portrait"
5364 @attrset exp1 @attr 1=1 CategoryList
5366 @attr gils 1=2008 Copenhagen
5368 @attr 1=/book/title computer
5372 <example id="example.pqf.proximity">
5373 <title>PQF Proximity queries</title>
5376 @prox 0 3 1 2 k 2 dylan zimmerman
5378 Here the parameters 0, 3, 1, 2, k and 2 represent exclusion,
5379 distance, ordered, relation, which-code and unit-code, in that
5383 <para>exclusion = 0: the proximity condition must hold</para>
5386 <para>distance = 3: the terms must be three units apart</para>
5390 ordered = 1: they must occur in the order they are specified
5395 relation = 2: lessThanOrEqual (to the distance of 3 units)
5400 which-code is ``known'', so the standard unit-codes are used
5404 <para>unit-code = 2: word.</para>
5407 So the whole proximity query means that the words
5408 <literal>dylan</literal> and <literal>zimmerman</literal> must
5409 both occur in the record, in that order, differing in position
5410 by three or fewer words (i.e. with two or fewer words between
5411 them.) The query would find ``Bob Dylan, aka. Robert
5412 Zimmerman'', but not ``Bob Dylan, born as Robert Zimmerman''
5413 since the distance in this case is four.
5416 <example id="example.pqf.search.term.type">
5417 <title>PQF specification of search term type</title>
5420 @term string "a UTF-8 string, maybe?"
5424 <example id="example.pqf.mixed.queries">
5425 <title>PQF mixed queries</title>
5428 @or @and bob dylan @set Result-1
5430 @attr 4=1 @and @attr 1=1 "bob dylan" @attr 1=4 "slow train coming"
5432 @and @attr 2=4 @attr gils 1=2038 -114 @attr 2=2 @attr gils 1=2039 -109
5434 The last of these examples is a spatial search: in
5435 <ulink url="http://www.gils.net/prof_v2.html#sec_7_4"
5436 >the GILS attribute set</ulink>,
5438 2038 indicates West Bounding Coordinate and
5439 2030 indicates East Bounding Coordinate,
5440 so the query is for areas extending from -114 degrees
5441 to no more than -109 degrees.
5446 <sect2 id="CCL"><title>CCL</title>
5448 Not all users enjoy typing in prefix query structures and numerical
5449 attribute values, even in a minimalistic test client. In the library
5450 world, the more intuitive Common Command Language - CCL (ISO 8777)
5451 has enjoyed some popularity - especially before the widespread
5452 availability of graphical interfaces. It is still useful in
5453 applications where you for some reason or other need to provide a
5454 symbolic language for expressing boolean query structures.
5456 <sect3 id="ccl.syntax">
5457 <title>CCL Syntax</title>
5459 The CCL parser obeys the following grammar for the FIND argument.
5460 The syntax is annotated by in the lines prefixed by
5461 <literal>--</literal>.
5464 CCL-Find ::= CCL-Find Op Elements
5467 Op ::= "and" | "or" | "not"
5468 -- The above means that Elements are separated by boolean operators.
5470 Elements ::= '(' CCL-Find ')'
5473 | Qualifiers Relation Terms
5474 | Qualifiers Relation '(' CCL-Find ')'
5475 | Qualifiers '=' string '-' string
5476 -- Elements is either a recursive definition, a result set reference, a
5477 -- list of terms, qualifiers followed by terms, qualifiers followed
5478 -- by a recursive definition or qualifiers in a range (lower - upper).
5480 Set ::= 'set' = string
5481 -- Reference to a result set
5483 Terms ::= Terms Prox Term
5485 -- Proximity of terms.
5487 Term ::= Term string
5489 -- This basically means that a term may include a blank
5491 Qualifiers ::= Qualifiers ',' string
5493 -- Qualifiers is a list of strings separated by comma
5495 Relation ::= '=' | '>=' | '<=' | '<>' | '>' | '<'
5496 -- Relational operators. This really doesn't follow the ISO8777
5500 -- Proximity operator
5503 <example id="example.ccl.queries">
5504 <title>CCL queries</title>
5506 The following queries are all valid:
5517 (dylan and bob) or set=1
5526 Assuming that the qualifiers <literal>ti</literal>,
5527 <literal>au</literal>
5528 and <literal>date</literal> are defined we may use:
5533 au=(bob dylan and slow train coming)
5535 date>1980 and (ti=((self portrait)))
5539 <sect3 id="ccl.qualifiers">
5540 <title>CCL Qualifiers</title>
5542 Qualifiers are used to direct the search to a particular searchable
5543 index, such as title (ti) and author indexes (au). The CCL standard
5544 itself doesn't specify a particular set of qualifiers, but it does
5545 suggest a few short-hand notations. You can customize the CCL parser
5546 to support a particular set of qualifiers to reflect the current target
5547 profile. Traditionally, a qualifier would map to a particular
5548 use-attribute within the BIB-1 attribute set. It is also
5549 possible to set other attributes, such as the structure
5553 A CCL profile is a set of predefined CCL qualifiers that may be
5554 read from a file or set in the CCL API.
5555 The YAZ client reads its CCL qualifiers from a file named
5556 <filename>default.bib</filename>. There are four types of
5557 lines in a CCL profile: qualifier specification,
5558 qualifier alias, comments and directives.
5560 <sect4 id="ccl.qualifier.specification">
5561 <title>Qualifier specification</title>
5563 A qualifier specification is of the form:
5566 <replaceable>qualifier-name</replaceable>
5567 [<replaceable>attributeset</replaceable><literal>,</literal>]<replaceable>type</replaceable><literal>=</literal><replaceable>val</replaceable>
5568 [<replaceable>attributeset</replaceable><literal>,</literal>]<replaceable>type</replaceable><literal>=</literal><replaceable>val</replaceable> ...
5571 where <replaceable>qualifier-name</replaceable> is the name of the
5572 qualifier to be used (eg. <literal>ti</literal>),
5573 <replaceable>type</replaceable> is attribute type in the attribute
5574 set (Bib-1 is used if no attribute set is given) and
5575 <replaceable>val</replaceable> is attribute value.
5576 The <replaceable>type</replaceable> can be specified as an
5577 integer or as it be specified either as a single-letter:
5578 <literal>u</literal> for use,
5579 <literal>r</literal> for relation,<literal>p</literal> for position,
5580 <literal>s</literal> for structure,<literal>t</literal> for truncation
5581 or <literal>c</literal> for completeness.
5582 The attributes for the special qualifier name <literal>term</literal>
5583 are used when no CCL qualifier is given in a query.
5584 <table id="ccl.common.bib1.attributes">
5585 <title>Common Bib-1 attributes</title>
5587 <colspec colwidth="2*" colname="type"></colspec>
5588 <colspec colwidth="9*" colname="description"></colspec>
5592 <entry>Description</entry>
5597 <entry><literal>u=</literal><replaceable>value</replaceable></entry>
5599 Use attribute (1). Common use attributes are
5600 1 Personal-name, 4 Title, 7 ISBN, 8 ISSN, 30 Date,
5601 62 Subject, 1003 Author), 1016 Any. Specify value
5606 <entry><literal>r=</literal><replaceable>value</replaceable></entry>
5608 Relation attribute (2). Common values are
5609 1 <, 2 <=, 3 =, 4 >=, 5 >, 6 <>,
5610 100 phonetic, 101 stem, 102 relevance, 103 always matches.
5614 <entry><literal>p=</literal><replaceable>value</replaceable></entry>
5616 Position attribute (3). Values: 1 first in field, 2
5617 first in any subfield, 3 any position in field.
5621 <entry><literal>s=</literal><replaceable>value</replaceable></entry>
5623 Structure attribute (4). Values: 1 phrase, 2 word,
5624 3 key, 4 year, 5 date, 6 word list, 100 date (un),
5625 101 name (norm), 102 name (un), 103 structure, 104 urx,
5626 105 free-form-text, 106 document-text, 107 local-number,
5627 108 string, 109 numeric string.
5631 <entry><literal>t=</literal><replaceable>value</replaceable></entry>
5633 Truncation attribute (5). Values: 1 right, 2 left,
5634 3 left& right, 100 none, 101 process #, 102 regular-1,
5635 103 regular-2, 104 CCL.
5639 <entry><literal>c=</literal><replaceable>value</replaceable></entry>
5641 Completeness attribute (6). Values: 1 incomplete subfield,
5642 2 complete subfield, 3 complete field.
5650 Refer to <xref linkend="bib1"/> or the complete
5651 <ulink url="&url.z39.50.attset.bib1;">list of Bib-1 attributes</ulink>
5654 It is also possible to specify non-numeric attribute values,
5655 which are used in combination with certain types.
5656 The special combinations are:
5657 <table id="ccl.special.attribute.combos">
5658 <title>Special attribute combos</title>
5660 <colspec colwidth="2*" colname="name"></colspec>
5661 <colspec colwidth="9*" colname="description"></colspec>
5665 <entry>Description</entry>
5670 <entry><literal>s=pw</literal></entry>
5672 The structure is set to either word or phrase depending
5673 on the number of tokens in a term (phrase-word).
5677 <entry><literal>s=al</literal></entry>
5679 Each token in the term is ANDed. (and-list).
5680 This does not set the structure at all.
5683 <row><entry><literal>s=ol</literal></entry>
5685 Each token in the term is ORed. (or-list).
5686 This does not set the structure at all.
5689 <row><entry><literal>s=ag</literal></entry>
5691 Tokens that appears as phrases (with blank in them) gets
5692 structure phrase attached (4=1). Tokens that appear to be words
5693 gets structure word attached (4=2). Phrases and words are
5694 ANDed. This is a variant of s=al and s=pw, with the main
5695 difference that words are not split (with operator AND)
5696 but instead kept in one RPN token. This facility appeared
5700 <row><entry><literal>r=o</literal></entry>
5702 Allows ranges and the operators greather-than, less-than, ...
5704 This sets Bib-1 relation attribute accordingly (relation
5705 ordered). A query construct is only treated as a range if
5706 dash is used and that is surrounded by white-space. So
5707 <literal>-1980</literal> is treated as term
5708 <literal>"-1980"</literal> not <literal><= 1980</literal>.
5709 If <literal>- 1980</literal> is used, however, that is
5713 <row><entry><literal>r=r</literal></entry>
5715 Similar to <literal>r=o</literal> but assumes that terms
5716 are non-negative (not prefixed with <literal>-</literal>).
5717 Thus, a dash will always be treated as a range.
5718 The construct <literal>1980-1990</literal> is
5719 treated as a range with <literal>r=r</literal> but as a
5720 single term <literal>"1980-1990"</literal> with
5721 <literal>r=o</literal>. The special attribute
5722 <literal>r=r</literal> is available in YAZ 2.0.24 or later.
5725 <row><entry><literal>r=omiteq</literal></entry>
5727 This will omit relation=equals (@attr 2=3) when r=o / r=r
5728 is used. This is useful for servers that somehow breaks
5729 when an explicit relation=equals is used. Omitting the
5730 relation is usually safe because "equals" is the default
5731 behavior. This tweak was added in YAZ version 5.1.2.
5734 <row><entry><literal>t=l</literal></entry>
5736 Allows term to be left-truncated.
5737 If term is of the form <literal>?x</literal>, the resulting
5738 Type-1 term is <literal>x</literal> and truncation is left.
5741 <row><entry><literal>t=r</literal></entry>
5743 Allows term to be right-truncated.
5744 If term is of the form <literal>x?</literal>, the resulting
5745 Type-1 term is <literal>x</literal> and truncation is right.
5748 <row><entry><literal>t=n</literal></entry>
5750 If term is does not include <literal>?</literal>, the
5751 truncation attribute is set to none (100).
5754 <row><entry><literal>t=b</literal></entry>
5756 Allows term to be both left&right truncated.
5757 If term is of the form <literal>?x?</literal>, the
5758 resulting term is <literal>x</literal> and trunctation is
5759 set to both left&right.
5762 <row><entry><literal>t=x</literal></entry>
5764 Allows masking anywhere in a term, thus fully supporting
5765 # (mask one character) and ? (zero or more of any).
5766 If masking is used, trunction is set to 102 (regexp-1 in term)
5767 and the term is converted accordingly to a regular expression.
5770 <row><entry><literal>t=z</literal></entry>
5772 Allows masking anywhere in a term, thus fully supporting
5773 # (mask one character) and ? (zero or more of any).
5774 If masking is used, trunction is set to 104 (Z39.58 in term)
5775 and the term is converted accordingly to Z39.58 masking term -
5776 actually the same truncation as CCL itself.
5783 <example id="example.ccl.profile">
5784 <title>CCL profile</title>
5786 Consider the following definition:
5796 <literal>ti</literal> and <literal>au</literal> both set
5797 structure attribute to phrase (s=1).
5798 <literal>ti</literal>
5799 sets the use-attribute to 4. <literal>au</literal> sets the
5801 When no qualifiers are used in the query the structure-attribute is
5802 set to free-form-text (105) (rule for <literal>term</literal>).
5803 The <literal>date</literal> sets the relation attribute to
5804 the relation used in the CCL query and sets the use attribute
5808 You can combine attributes. To Search for "ranked title" you
5811 ti,ranked=knuth computer
5813 which will set relation=ranked, use=title, structure=phrase.
5820 is a valid query. But
5828 <sect4 id="ccl.qualifier.alias">
5829 <title>Qualifier alias</title>
5831 A qualifier alias is of the form:
5834 <replaceable>q</replaceable>
5835 <replaceable>q1</replaceable> <replaceable>q2</replaceable> ..
5838 which declares <replaceable>q</replaceable> to
5839 be an alias for <replaceable>q1</replaceable>,
5840 <replaceable>q2</replaceable>... such that the CCL
5841 query <replaceable>q=x</replaceable> is equivalent to
5842 <replaceable>q1=x or q2=x or ...</replaceable>.
5845 <sect4 id="ccl.comments">
5846 <title>Comments</title>
5848 Lines with white space or lines that begin with
5849 character <literal>#</literal> are treated as comments.
5852 <sect4 id="ccl.directives">
5853 <title>Directives</title>
5855 Directive specifications takes the form
5857 <para><literal>@</literal><replaceable>directive</replaceable> <replaceable>value</replaceable>
5859 <table id="ccl.directives.table">
5860 <title>CCL directives</title>
5862 <colspec colwidth="2*" colname="name"></colspec>
5863 <colspec colwidth="8*" colname="description"></colspec>
5864 <colspec colwidth="1*" colname="default"></colspec>
5868 <entry>Description</entry>
5869 <entry>Default</entry>
5874 <entry>truncation</entry>
5875 <entry>Truncation character</entry>
5876 <entry><literal>?</literal></entry>
5880 <entry>Masking character. Requires YAZ 4.2.58 or later</entry>
5881 <entry><literal>#</literal></entry>
5884 <entry>field</entry>
5885 <entry>Specifies how multiple fields are to be
5886 combined. There are two modes: <literal>or</literal>:
5887 multiple qualifier fields are ORed,
5888 <literal>merge</literal>: attributes for the qualifier
5889 fields are merged and assigned to one term.
5891 <entry><literal>merge</literal></entry>
5895 <entry>Specifies if CCL operators and qualifiers should be
5896 compared with case sensitivity or not. Specify 1 for
5897 case sensitive; 0 for case insensitive.</entry>
5898 <entry><literal>1</literal></entry>
5902 <entry>Specifies token for CCL operator AND.</entry>
5903 <entry><literal>and</literal></entry>
5907 <entry>Specifies token for CCL operator OR.</entry>
5908 <entry><literal>or</literal></entry>
5912 <entry>Specifies token for CCL operator NOT.</entry>
5913 <entry><literal>not</literal></entry>
5917 <entry>Specifies token for CCL operator SET.</entry>
5918 <entry><literal>set</literal></entry>
5925 <sect3 id="ccl.api">
5926 <title>CCL API</title>
5928 All public definitions can be found in the header file
5929 <filename>ccl.h</filename>. A profile identifier is of type
5930 <literal>CCL_bibset</literal>. A profile must be created with the call
5931 to the function <function>ccl_qual_mk</function> which returns a profile
5932 handle of type <literal>CCL_bibset</literal>.
5935 To read a file containing qualifier definitions the function
5936 <function>ccl_qual_file</function> may be convenient. This function
5937 takes an already opened <literal>FILE</literal> handle pointer as
5938 argument along with a <literal>CCL_bibset</literal> handle.
5941 To parse a simple string with a FIND query use the function
5944 struct ccl_rpn_node *ccl_find_str(CCL_bibset bibset, const char *str,
5945 int *error, int *pos);
5948 which takes the CCL profile (<literal>bibset</literal>) and query
5949 (<literal>str</literal>) as input. Upon successful completion the RPN
5950 tree is returned. If an error occur, such as a syntax error, the integer
5951 pointed to by <literal>error</literal> holds the error code and
5952 <literal>pos</literal> holds the offset inside query string in which
5956 An English representation of the error may be obtained by calling
5957 the <literal>ccl_err_msg</literal> function. The error codes are
5958 listed in <filename>ccl.h</filename>.
5961 To convert the CCL RPN tree (type
5962 <literal>struct ccl_rpn_node *</literal>)
5963 to the Z_RPNQuery of YAZ the function <function>ccl_rpn_query</function>
5964 must be used. This function which is part of YAZ is implemented in
5965 <filename>yaz-ccl.c</filename>.
5966 After calling this function the CCL RPN tree is probably no longer
5967 needed. The <literal>ccl_rpn_delete</literal> destroys the CCL RPN tree.
5970 A CCL profile may be destroyed by calling the
5971 <function>ccl_qual_rm</function> function.
5974 The token names for the CCL operators may be changed by setting the
5975 globals (all type <literal>char *</literal>)
5976 <literal>ccl_token_and</literal>, <literal>ccl_token_or</literal>,
5977 <literal>ccl_token_not</literal> and <literal>ccl_token_set</literal>.
5978 An operator may have aliases, i.e. there may be more than one name for
5979 the operator. To do this, separate each alias with a space character.
5986 <ulink url="&url.cql;">CQL</ulink>
5987 - Common Query Language - was defined for the
5988 <ulink url="&url.sru;">SRU</ulink> protocol.
5989 In many ways CQL has a similar syntax to CCL.
5990 The objective of CQL is different. Where CCL aims to be
5991 an end-user language, CQL is <emphasis>the</emphasis> protocol
5992 query language for SRU.
5996 If you are new to CQL, read the
5997 <ulink url="&url.cql.intro;">Gentle Introduction</ulink>.
6001 The CQL parser in &yaz; provides the following:
6005 It parses and validates a CQL query.
6010 It generates a C structure that allows you to convert
6011 a CQL query to some other query language, such as SQL.
6016 The parser converts a valid CQL query to PQF, thus providing a
6017 way to use CQL for both SRU servers and Z39.50 targets at the
6023 The parser converts CQL to XCQL.
6024 XCQL is an XML representation of CQL.
6025 XCQL is part of the SRU specification. However, since SRU
6026 supports CQL only, we don't expect XCQL to be widely used.
6027 Furthermore, CQL has the advantage over XCQL that it is
6033 <sect3 id="cql.parsing">
6034 <title>CQL parsing</title>
6036 A CQL parser is represented by the <literal>CQL_parser</literal>
6037 handle. Its contents should be considered &yaz; internal (private).
6039 #include <yaz/cql.h>
6041 typedef struct cql_parser *CQL_parser;
6043 CQL_parser cql_parser_create(void);
6044 void cql_parser_destroy(CQL_parser cp);
6046 A parser is created by <function>cql_parser_create</function> and
6047 is destroyed by <function>cql_parser_destroy</function>.
6050 To parse a CQL query string, the following function
6053 int cql_parser_string(CQL_parser cp, const char *str);
6055 A CQL query is parsed by the <function>cql_parser_string</function>
6056 which takes a query <parameter>str</parameter>.
6057 If the query was valid (no syntax errors), then zero is returned;
6058 otherwise -1 is returned to indicate a syntax error.
6062 int cql_parser_stream(CQL_parser cp,
6063 int (*getbyte)(void *client_data),
6064 void (*ungetbyte)(int b, void *client_data),
6067 int cql_parser_stdio(CQL_parser cp, FILE *f);
6069 The functions <function>cql_parser_stream</function> and
6070 <function>cql_parser_stdio</function> parses a CQL query
6071 - just like <function>cql_parser_string</function>.
6072 The only difference is that the CQL query can be
6073 fed to the parser in different ways.
6074 The <function>cql_parser_stream</function> uses a generic
6075 byte stream as input. The <function>cql_parser_stdio</function>
6076 uses a <literal>FILE</literal> handle which is opened for reading.
6079 <sect3 id="cql.tree">
6080 <title>CQL tree</title>
6082 The the query string is valid, the CQL parser
6083 generates a tree representing the structure of the
6088 struct cql_node *cql_parser_result(CQL_parser cp);
6090 <function>cql_parser_result</function> returns the
6091 a pointer to the root node of the resulting tree.
6094 Each node in a CQL tree is represented by a
6095 <literal>struct cql_node</literal>.
6096 It is defined as follows:
6098 #define CQL_NODE_ST 1
6099 #define CQL_NODE_BOOL 2
6100 #define CQL_NODE_SORT 3
6110 struct cql_node *modifiers;
6114 struct cql_node *left;
6115 struct cql_node *right;
6116 struct cql_node *modifiers;
6120 struct cql_node *next;
6121 struct cql_node *modifiers;
6122 struct cql_node *search;
6127 There are three node types: search term (ST), boolean (BOOL)
6129 A modifier is treated as a search term too.
6132 The search term node has five members:
6136 <literal>index</literal>: index for search term.
6137 If an index is unspecified for a search term,
6138 <literal>index</literal> will be NULL.
6143 <literal>index_uri</literal>: index URi for search term
6144 or NULL if none could be resolved for the index.
6149 <literal>term</literal>: the search term itself.
6154 <literal>relation</literal>: relation for search term.
6159 <literal>relation_uri</literal>: relation URI for search term.
6164 <literal>modifiers</literal>: relation modifiers for search
6165 term. The <literal>modifiers</literal> list itself of cql_nodes
6166 each of type <literal>ST</literal>.
6172 The boolean node represents <literal>and</literal>,
6173 <literal>or</literal>, <literal>not</literal> +
6178 <literal>left</literal> and <literal>right</literal>: left
6179 - and right operand respectively.
6184 <literal>modifiers</literal>: proximity arguments.
6190 The sort node represents both the SORTBY clause.
6193 <sect3 id="cql.to.pqf">
6194 <title>CQL to PQF conversion</title>
6196 Conversion to PQF (and Z39.50 RPN) is tricky by the fact
6197 that the resulting RPN depends on the Z39.50 target
6198 capabilities (combinations of supported attributes).
6199 In addition, the CQL and SRU operates on index prefixes
6200 (URI or strings), whereas the RPN uses Object Identifiers
6204 The CQL library of &yaz; defines a <literal>cql_transform_t</literal>
6205 type. It represents a particular mapping between CQL and RPN.
6206 This handle is created and destroyed by the functions:
6208 cql_transform_t cql_transform_open_FILE (FILE *f);
6209 cql_transform_t cql_transform_open_fname(const char *fname);
6210 void cql_transform_close(cql_transform_t ct);
6212 The first two functions create a tranformation handle from
6213 either an already open FILE or from a filename respectively.
6216 The handle is destroyed by <function>cql_transform_close</function>
6217 in which case no further reference of the handle is allowed.
6220 When a <literal>cql_transform_t</literal> handle has been created
6221 you can convert to RPN.
6223 int cql_transform_buf(cql_transform_t ct,
6224 struct cql_node *cn, char *out, int max);
6226 This function converts the CQL tree <literal>cn</literal>
6227 using handle <literal>ct</literal>.
6228 For the resulting PQF, you supply a buffer <literal>out</literal>
6229 which must be able to hold at at least <literal>max</literal>
6233 If conversion failed, <function>cql_transform_buf</function>
6234 returns a non-zero SRU error code; otherwise zero is returned
6235 (conversion successful). The meanings of the numeric error
6236 codes are listed in the SRU specification somewhere (no
6237 direct link anymore).
6240 If conversion fails, more information can be obtained by calling
6242 int cql_transform_error(cql_transform_t ct, char **addinfop);
6244 This function returns the most recently returned numeric
6245 error-code and sets the string-pointer at
6246 <literal>*addinfop</literal> to point to a string containing
6247 additional information about the error that occurred: for
6248 example, if the error code is 15 (``Illegal or unsupported context
6249 set''), the additional information is the name of the requested
6250 context set that was not recognised.
6253 The SRU error-codes may be translated into brief human-readable
6254 error messages using
6256 const char *cql_strerror(int code);
6260 If you wish to be able to produce a PQF result in a different
6261 way, there are two alternatives.
6263 void cql_transform_pr(cql_transform_t ct,
6264 struct cql_node *cn,
6265 void (*pr)(const char *buf, void *client_data),
6268 int cql_transform_FILE(cql_transform_t ct,
6269 struct cql_node *cn, FILE *f);
6271 The former function produces output to a user-defined
6272 output stream. The latter writes the result to an already
6273 open <literal>FILE</literal>.
6276 <sect3 id="cql.to.rpn">
6277 <title>Specification of CQL to RPN mappings</title>
6279 The file supplied to functions
6280 <function>cql_transform_open_FILE</function>,
6281 <function>cql_transform_open_fname</function> follows
6282 a structure found in many Unix utilities.
6283 It consists of mapping specifications - one per line.
6284 Lines starting with <literal>#</literal> are ignored (comments).
6287 Each line is of the form
6289 <replaceable>CQL pattern</replaceable><literal> = </literal> <replaceable> RPN equivalent</replaceable>
6293 An RPN pattern is a simple attribute list. Each attribute pair
6296 [<replaceable>set</replaceable>] <replaceable>type</replaceable><literal>=</literal><replaceable>value</replaceable>
6298 The attribute <replaceable>set</replaceable> is optional.
6299 The <replaceable>type</replaceable> is the attribute type,
6300 <replaceable>value</replaceable> the attribute value.
6303 The character <literal>*</literal> (asterisk) has special meaning
6304 when used in the RPN pattern.
6305 Each occurrence of <literal>*</literal> is substituted with the
6306 CQL matching name (index, relation, qualifier etc).
6307 This facility can be used to copy a CQL name verbatim to the RPN result.
6310 The following CQL patterns are recognized:
6314 <literal>index.</literal><replaceable>set</replaceable><literal>.</literal><replaceable>name</replaceable>
6318 This pattern is invoked when a CQL index, such as
6319 dc.title is converted. <replaceable>set</replaceable>
6320 and <replaceable>name</replaceable> are the context set and index
6322 Typically, the RPN specifies an equivalent use attribute.
6325 For terms not bound by an index the pattern
6326 <literal>index.cql.serverChoice</literal> is used.
6327 Here, the prefix <literal>cql</literal> is defined as
6328 <literal>http://www.loc.gov/zing/cql/cql-indexes/v1.0/</literal>.
6329 If this pattern is not defined, the mapping will fail.
6333 <literal>index.</literal><replaceable>set</replaceable><literal>.*</literal>
6334 is used when no other index pattern is matched.
6340 <literal>qualifier.</literal><replaceable>set</replaceable><literal>.</literal><replaceable>name</replaceable>
6345 For backwards compatibility, this is recognised as a synonym of
6346 <literal>index.</literal><replaceable>set</replaceable><literal>.</literal><replaceable>name</replaceable>
6352 <literal>relation.</literal><replaceable>relation</replaceable>
6356 This pattern specifies how a CQL relation is mapped to RPN.
6357 <replaceable>pattern</replaceable> is name of relation
6358 operator. Since <literal>=</literal> is used as
6359 separator between CQL pattern and RPN, CQL relations
6360 including <literal>=</literal> cannot be
6361 used directly. To avoid a conflict, the names
6362 <literal>ge</literal>,
6363 <literal>eq</literal>,
6364 <literal>le</literal>,
6365 must be used for CQL operators, greater-than-or-equal,
6366 equal, less-than-or-equal respectively.
6367 The RPN pattern is supposed to include a relation attribute.
6370 For terms not bound by a relation, the pattern
6371 <literal>relation.scr</literal> is used. If the pattern
6372 is not defined, the mapping will fail.
6375 The special pattern, <literal>relation.*</literal> is used
6376 when no other relation pattern is matched.
6382 <literal>relationModifier.</literal><replaceable>mod</replaceable>
6386 This pattern specifies how a CQL relation modifier is mapped to RPN.
6387 The RPN pattern is usually a relation attribute.
6393 <literal>structure.</literal><replaceable>type</replaceable>
6397 This pattern specifies how a CQL structure is mapped to RPN.
6398 Note that this CQL pattern is somewhat to similar to
6399 CQL pattern <literal>relation</literal>.
6400 The <replaceable>type</replaceable> is a CQL relation.
6403 The pattern, <literal>structure.*</literal> is used
6404 when no other structure pattern is matched.
6405 Usually, the RPN equivalent specifies a structure attribute.
6411 <literal>position.</literal><replaceable>type</replaceable>
6415 This pattern specifies how the anchor (position) of
6416 CQL is mapped to RPN.
6417 The <replaceable>type</replaceable> is one
6418 of <literal>first</literal>, <literal>any</literal>,
6419 <literal>last</literal>, <literal>firstAndLast</literal>.
6422 The pattern, <literal>position.*</literal> is used
6423 when no other position pattern is matched.
6429 <literal>set.</literal><replaceable>prefix</replaceable>
6433 This specification defines a CQL context set for a given prefix.
6434 The value on the right hand side is the URI for the set -
6435 <emphasis>not</emphasis> RPN. All prefixes used in
6436 index patterns must be defined this way.
6442 <literal>set</literal>
6446 This specification defines a default CQL context set for index names.
6447 The value on the right hand side is the URI for the set.
6453 <example id="example.cql.to.rpn.mapping">
6454 <title>CQL to RPN mapping file</title>
6456 This simple file defines two context sets, three indexes and three
6457 relations, a position pattern and a default structure.
6459 <programlisting><![CDATA[
6460 set.cql = http://www.loc.gov/zing/cql/context-sets/cql/v1.1/
6461 set.dc = http://www.loc.gov/zing/cql/dc-indexes/v1.0/
6463 index.cql.serverChoice = 1=1016
6464 index.dc.title = 1=4
6465 index.dc.subject = 1=21
6471 position.any = 3=3 6=1
6477 With the mappings above, the CQL query
6481 is converted to the PQF:
6483 @attr 1=1016 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 "computer"
6485 by rules <literal>index.cql.serverChoice</literal>,
6486 <literal>relation.scr</literal>, <literal>structure.*</literal>,
6487 <literal>position.any</literal>.
6494 is rejected, since <literal>position.right</literal> is
6500 >my = "http://www.loc.gov/zing/cql/dc-indexes/v1.0/" my.title = x
6504 @attr 1=4 @attr 2=3 @attr 4=1 @attr 3=3 @attr 6=1 "x"
6508 <example id="example.cql.to.rpn.string">
6509 <title>CQL to RPN string attributes</title>
6511 In this example we allow any index to be passed to RPN as
6514 <programlisting><![CDATA[
6515 # Identifiers for prefixes used in this file. (index.*)
6516 set.cql = info:srw/cql-context-set/1/cql-v1.1
6517 set.rpn = http://bogus/rpn
6518 set = http://bogus/rpn
6520 # The default index when none is specified by the query
6521 index.cql.serverChoice = 1=any
6530 The <literal>http://bogus/rpn</literal> context set is also the default
6531 so we can make queries such as
6535 which is converted to
6537 @attr 2=3 @attr 4=1 @attr 3=3 @attr 1=title "a"
6541 <example id="example.cql.to.rpn.bathprofile">
6542 <title>CQL to RPN using Bath Profile</title>
6544 The file <filename>etc/pqf.properties</filename> has mappings from
6545 the Bath Profile and Dublin Core to RPN.
6546 If YAZ is installed as a package it's usually located
6547 in <filename>/usr/share/yaz/etc</filename> and part of the
6548 development package, such as <literal>libyaz-dev</literal>.
6552 <sect3 id="cql.xcql">
6553 <title>CQL to XCQL conversion</title>
6555 Conversion from CQL to XCQL is trivial and does not
6556 require a mapping to be defined.
6557 There three functions to choose from depending on the
6558 way you wish to store the resulting output (XML buffer
6561 int cql_to_xml_buf(struct cql_node *cn, char *out, int max);
6562 void cql_to_xml(struct cql_node *cn,
6563 void (*pr)(const char *buf, void *client_data),
6565 void cql_to_xml_stdio(struct cql_node *cn, FILE *f);
6567 Function <function>cql_to_xml_buf</function> converts
6568 to XCQL and stores result in a user supplied buffer of a given
6572 <function>cql_to_xml</function> writes the result in
6573 a user defined output stream.
6574 <function>cql_to_xml_stdio</function> writes to a
6578 <sect3 id="rpn.to.cql">
6579 <title>PQF to CQL conversion</title>
6581 Conversion from PQF to CQL is offered by the two functions shown
6582 below. The former uses a generic stream for result. The latter
6583 puts result in a WRBUF (string container).
6585 #include <yaz/rpn2cql.h>
6587 int cql_transform_rpn2cql_stream(cql_transform_t ct,
6588 void (*pr)(const char *buf, void *client_data),
6592 int cql_transform_rpn2cql_wrbuf(cql_transform_t ct,
6596 The configuration is the same as used in CQL to PQF conversions.
6601 <sect1 id="tools.oid">
6602 <title>Object Identifiers</title>
6604 The basic YAZ representation of an OID is an array of integers,
6605 terminated with the value -1. This integer is of type
6606 <literal>Odr_oid</literal>.
6609 Fundamental OID operations and the type <literal>Odr_oid</literal>
6610 are defined in <filename>yaz/oid_util.h</filename>.
6613 An OID can either be declared as a automatic variable or it can
6614 allocated using the memory utilities or ODR/NMEM. It's
6615 guaranteed that an OID can fit in <literal>OID_SIZE</literal> integers.
6617 <example id="tools.oid.bib1.1"><title>Create OID on stack</title>
6619 We can create an OID for the Bib-1 attribute set with:
6621 Odr_oid bib1[OID_SIZE];
6633 And OID may also be filled from a string-based representation using
6634 dots (.). This is achieved by function
6636 int oid_dotstring_to_oid(const char *name, Odr_oid *oid);
6638 This functions returns 0 if name could be converted; -1 otherwise.
6640 <example id="tools.oid.bib1.2"><title>Using oid_oiddotstring_to_oid</title>
6642 We can fill the Bib-1 attribute set OID easier with:
6644 Odr_oid bib1[OID_SIZE];
6645 oid_oiddotstring_to_oid("1.2.840.10003.3.1", bib1);
6650 We can also allocate an OID dynamically on a ODR stream with:
6652 Odr_oid *odr_getoidbystr(ODR o, const char *str);
6654 This creates an OID from string-based representation using dots.
6655 This function take an &odr; stream as parameter. This stream is used to
6656 allocate memory for the data elements, which is released on a
6657 subsequent call to <function>odr_reset()</function> on that stream.
6659 <example id="tools.oid.bib1.3">
6660 <title>Using odr_getoidbystr</title>
6662 We can create a OID for the Bib-1 attribute set with:
6664 Odr_oid *bib1 = odr_getoidbystr(odr, "1.2.840.10003.3.1");
6671 char *oid_oid_to_dotstring(const Odr_oid *oid, char *oidbuf)
6673 does the reverse of <function>oid_oiddotstring_to_oid</function>. It
6674 converts an OID to the string-based representation using dots.
6675 The supplied char buffer <literal>oidbuf</literal> holds the resulting
6676 string and must be at least <literal>OID_STR_MAX</literal> in size.
6679 OIDs can be copied with <function>oid_oidcpy</function> which takes
6680 two OID lists as arguments. Alternativly, an OID copy can be allocated
6681 on a ODR stream with:
6683 Odr_oid *odr_oiddup(ODR odr, const Odr_oid *o);
6687 OIDs can be compared with <function>oid_oidcmp</function> which returns
6688 zero if the two OIDs provided are identical; non-zero otherwise.
6690 <sect2 id="tools.oid.database">
6691 <title>OID database</title>
6693 From YAZ version 3 and later, the oident system has been replaced
6694 by an OID database. OID database is a misnomer .. the old odient
6695 system was also a database.
6698 The OID database is really just a map between named Object Identifiers
6699 (string) and their OID raw equivalents. Most operations either
6700 convert from string to OID or other way around.
6703 Unfortunately, whenever we supply a string we must also specify the
6704 <emphasis>OID class</emphasis>. The class is necessary because some
6705 strings correspond to multiple OIDs. An example of such a string is
6706 <literal>Bib-1</literal> which may either be an attribute-set
6707 or a diagnostic-set.
6710 Applications using the YAZ database should include
6711 <filename>yaz/oid_db.h</filename>.
6714 A YAZ database handle is of type <literal>yaz_oid_db_t</literal>.
6715 Actually that's a pointer. You need not think deal with that.
6716 YAZ has a built-in database which can be considered "constant" for
6718 We can get hold that by using function <function>yaz_oid_std</function>.
6721 All functions with prefix <function>yaz_string_to_oid</function>
6722 converts from class + string to OID. We have variants of this
6723 operation due to different memory allocation strategies.
6726 All functions with prefix
6727 <function>yaz_oid_to_string</function> converts from OID to string
6730 <example id="tools.oid.bib1.4">
6731 <title>Create OID with YAZ DB</title>
6733 We can create an OID for the Bib-1 attribute set on the ODR stream
6737 yaz_string_to_oid_odr(yaz_oid_std(), CLASS_ATTSET, "Bib-1", odr);
6739 This is more complex than using <function>odr_getoidbystr</function>.
6740 You would only use <function>yaz_string_to_oid_odr</function> when the
6741 string (here Bib-1) is supplied by a user or configuration.
6745 <sect2 id="tools.oid.std">
6746 <title>Standard OIDs</title>
6748 All the object identifers in the standard OID database as returned
6749 by <function>yaz_oid_std</function> can referenced directly in a
6750 program as a constant OID.
6751 Each constant OID is prefixed with <literal>yaz_oid_</literal> -
6752 followed by OID class (lowercase) - then by OID name (normalized and
6756 See <xref linkend="list-oids"/> for list of all object identifiers
6758 These are declared in <filename>yaz/oid_std.h</filename> but are
6759 included by <filename>yaz/oid_db.h</filename> as well.
6761 <example id="tools.oid.bib1.5">
6762 <title>Use a built-in OID</title>
6764 We can allocate our own OID filled with the constant OID for
6767 Odr_oid *bib1 = odr_oiddup(o, yaz_oid_attset_bib1);
6773 <sect1 id="tools.nmem">
6774 <title>Nibble Memory</title>
6776 Sometimes when you need to allocate and construct a large,
6777 interconnected complex of structures, it can be a bit of a pain to
6778 release the associated memory again. For the structures describing the
6779 Z39.50 PDUs and related structures, it is convenient to use the
6780 memory-management system of the &odr; subsystem (see
6781 <xref linkend="odr.use"/>). However, in some circumstances
6782 where you might otherwise benefit from using a simple nibble memory
6783 management system, it may be impractical to use
6784 <function>odr_malloc()</function> and <function>odr_reset()</function>.
6785 For this purpose, the memory manager which also supports the &odr;
6786 streams is made available in the NMEM module. The external interface
6787 to this module is given in the <filename>nmem.h</filename> file.
6790 The following prototypes are given:
6793 NMEM nmem_create(void);
6794 void nmem_destroy(NMEM n);
6795 void *nmem_malloc(NMEM n, size_t size);
6796 void nmem_reset(NMEM n);
6797 size_t nmem_total(NMEM n);
6798 void nmem_init(void);
6799 void nmem_exit(void);
6802 The <function>nmem_create()</function> function returns a pointer to a
6803 memory control handle, which can be released again by
6804 <function>nmem_destroy()</function> when no longer needed.
6805 The function <function>nmem_malloc()</function> allocates a block of
6806 memory of the requested size. A call to <function>nmem_reset()</function>
6807 or <function>nmem_destroy()</function> will release all memory allocated
6808 on the handle since it was created (or since the last call to
6809 <function>nmem_reset()</function>. The function
6810 <function>nmem_total()</function> returns the number of bytes currently
6811 allocated on the handle.
6814 The nibble memory pool is shared amongst threads. POSIX
6815 mutex'es and WIN32 Critical sections are introduced to keep the
6816 module thread safe. Function <function>nmem_init()</function>
6817 initializes the nibble memory library and it is called automatically
6818 the first time the <literal>YAZ.DLL</literal> is loaded. &yaz; uses
6819 function <function>DllMain</function> to achieve this. You should
6820 <emphasis>not</emphasis> call <function>nmem_init</function> or
6821 <function>nmem_exit</function> unless you're absolute sure what
6822 you're doing. Note that in previous &yaz; versions you'd have to call
6823 <function>nmem_init</function> yourself.
6826 <sect1 id="tools.log">
6829 &yaz; has evolved a fairly complex log system which should be useful both
6830 for debugging &yaz; itself, debugging applications that use &yaz;, and for
6831 production use of those applications.
6834 The log functions are declared in header <filename>yaz/log.h</filename>
6835 and implemented in <filename>src/log.c</filename>.
6836 Due to name clash with syslog and some math utilities the logging
6837 interface has been modified as of YAZ 2.0.29. The obsolete interface
6838 is still available if in header file <filename>yaz/log.h</filename>.
6839 The key points of the interface are:
6842 void yaz_log(int level, const char *fmt, ...)
6843 void yaz_log_init(int level, const char *prefix, const char *name);
6844 void yaz_log_init_file(const char *fname);
6845 void yaz_log_init_level(int level);
6846 void yaz_log_init_prefix(const char *prefix);
6847 void yaz_log_time_format(const char *fmt);
6848 void yaz_log_init_max_size(int mx);
6850 int yaz_log_mask_str(const char *str);
6851 int yaz_log_module_level(const char *name);
6854 The reason for the whole log module is the <function>yaz_log</function>
6855 function. It takes a bitmask indicating the log levels, a
6856 <literal>printf</literal>-like format string, and a variable number of
6860 The <literal>log level</literal> is a bit mask, that says on which level(s)
6861 the log entry should be made, and optionally set some behaviour of the
6862 logging. In the most simple cases, it can be one of <literal>YLOG_FATAL,
6863 YLOG_DEBUG, YLOG_WARN, YLOG_LOG</literal>. Those can be combined with bits
6864 that modify the way the log entry is written:<literal>YLOG_ERRNO,
6865 YLOG_NOTIME, YLOG_FLUSH</literal>.
6866 Most of the rest of the bits are deprecated, and should not be used. Use
6867 the dynamic log levels instead.
6870 Applications that use &yaz;, should not use the LOG_LOG for ordinary
6871 messages, but should make use of the dynamic loglevel system. This consists
6872 of two parts, defining the loglevel and checking it.
6875 To define the log levels, the (main) program should pass a string to
6876 <function>yaz_log_mask_str</function> to define which log levels are to be
6877 logged. This string should be a comma-separated list of log level names,
6878 and can contain both hard-coded names and dynamic ones. The log level
6879 calculation starts with <literal>YLOG_DEFAULT_LEVEL</literal> and adds a bit
6880 for each word it meets, unless the word starts with a '-', in which case it
6881 clears the bit. If the string <literal>'none'</literal> is found,
6882 all bits are cleared. Typically this string comes from the command-line,
6883 often identified by <literal>-v</literal>. The
6884 <function>yaz_log_mask_str</function> returns a log level that should be
6885 passed to <function>yaz_log_init_level</function> for it to take effect.
6888 Each module should check what log bits it should be used, by calling
6889 <function>yaz_log_module_level</function> with a suitable name for the
6890 module. The name is cleared from a preceding path and an extension, if any,
6891 so it is quite possible to use <literal>__FILE__</literal> for it. If the
6892 name has been passed to <function>yaz_log_mask_str</function>, the routine
6893 returns a non-zero bitmask, which should then be used in consequent calls
6894 to yaz_log. (It can also be tested, so as to avoid unnecessary calls to
6895 yaz_log, in time-critical places, or when the log entry would take time
6899 Yaz uses the following dynamic log levels:
6900 <literal>server, session, request, requestdetail</literal> for the server
6902 <literal>zoom</literal> for the zoom client api.
6903 <literal>ztest</literal> for the simple test server.
6904 <literal>malloc, nmem, odr, eventl</literal> for internal
6905 debugging of yaz itself.
6906 Of course, any program using yaz is welcome to define as many new
6910 By default the log is written to stderr, but this can be changed by a call
6911 to <function>yaz_log_init_file</function> or
6912 <function>yaz_log_init</function>. If the log is directed to a file, the
6913 file size is checked at every write, and if it exceeds the limit given in
6914 <function>yaz_log_init_max_size</function>, the log is rotated. The
6915 rotation keeps one old version (with a <literal>.1</literal> appended to
6916 the name). The size defaults to 1GB. Setting it to zero will disable the
6920 A typical yaz-log looks like this
6921 13:23:14-23/11 yaz-ztest(1) [session] Starting session from tcp:127.0.0.1 (pid=30968)
6922 13:23:14-23/11 yaz-ztest(1) [request] Init from 'YAZ' (81) (ver 2.0.28) OK
6923 13:23:17-23/11 yaz-ztest(1) [request] Search Z: @attrset Bib-1 foo OK:7 hits
6924 13:23:22-23/11 yaz-ztest(1) [request] Present: [1] 2+2 OK 2 records returned
6925 13:24:13-23/11 yaz-ztest(1) [request] Close OK
6928 The log entries start with a time stamp. This can be omitted by setting the
6929 <literal>YLOG_NOTIME</literal> bit in the loglevel. This way automatic tests
6930 can be hoped to produce identical log files, that are easy to diff. The
6931 format of the time stamp can be set with
6932 <function>yaz_log_time_format</function>, which takes a format string just
6933 like <function>strftime</function>.
6936 Next in a log line comes the prefix, often the name of the program. For
6937 yaz-based servers, it can also contain the session number. Then
6938 comes one or more logbits in square brackets, depending on the logging
6939 level set by <function>yaz_log_init_level</function> and the loglevel
6940 passed to <function>yaz_log_init_level</function>. Finally comes the format
6941 string and additional values passed to <function>yaz_log</function>
6944 The log level <literal>YLOG_LOGLVL</literal>, enabled by the string
6945 <literal>loglevel</literal>, will log all the log-level affecting
6946 operations. This can come in handy if you need to know what other log
6947 levels would be useful. Grep the logfile for <literal>[loglevel]</literal>.
6950 The log system is almost independent of the rest of &yaz;, the only
6951 important dependence is of <filename>nmem</filename>, and that only for
6952 using the semaphore definition there.
6955 The dynamic log levels and log rotation were introduced in &yaz; 2.0.28. At
6956 the same time, the log bit names were changed from
6957 <literal>LOG_something</literal> to <literal>YLOG_something</literal>,
6958 to avoid collision with <filename>syslog.h</filename>.
6964 YAZ provides a fast utility for working with MARC records.
6965 Early versions of the MARC utility only allowed decoding of ISO2709.
6966 Today the utility may both encode - and decode to a varity of formats.
6969 #include <yaz/marcdisp.h>
6971 /* create handler */
6972 yaz_marc_t yaz_marc_create(void);
6974 void yaz_marc_destroy(yaz_marc_t mt);
6976 /* set XML mode YAZ_MARC_LINE, YAZ_MARC_SIMPLEXML, ... */
6977 void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
6978 #define YAZ_MARC_LINE 0
6979 #define YAZ_MARC_SIMPLEXML 1
6980 #define YAZ_MARC_OAIMARC 2
6981 #define YAZ_MARC_MARCXML 3
6982 #define YAZ_MARC_ISO2709 4
6983 #define YAZ_MARC_XCHANGE 5
6984 #define YAZ_MARC_CHECK 6
6985 #define YAZ_MARC_TURBOMARC 7
6986 #define YAZ_MARC_JSON 8
6988 /* supply iconv handle for character set conversion .. */
6989 void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);
6991 /* set debug level, 0=none, 1=more, 2=even more, .. */
6992 void yaz_marc_debug(yaz_marc_t mt, int level);
6994 /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
6995 On success, result in *result with size *rsize. */
6996 int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize,
6997 const char **result, size_t *rsize);
6999 /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
7000 On success, result in WRBUF */
7001 int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf,
7002 int bsize, WRBUF wrbuf);
7007 The synopsis is just a basic subset of all functionality. Refer
7008 to the actual header file <filename>marcdisp.h</filename> for
7013 A MARC conversion handle must be created by using
7014 <function>yaz_marc_create</function> and destroyed
7015 by calling <function>yaz_marc_destroy</function>.
7018 All other function operate on a <literal>yaz_marc_t</literal> handle.
7019 The output is specified by a call to <function>yaz_marc_xml</function>.
7020 The <literal>xmlmode</literal> must be one of
7023 <term>YAZ_MARC_LINE</term>
7026 A simple line-by-line format suitable for display but not
7027 recommend for further (machine) processing.
7032 <term>YAZ_MARC_MARCXML</term>
7035 <ulink url="&url.marcxml;">MARCXML</ulink>.
7040 <term>YAZ_MARC_ISO2709</term>
7043 ISO2709 (sometimes just referred to as "MARC").
7048 <term>YAZ_MARC_XCHANGE</term>
7051 <ulink url="&url.marcxchange;">MarcXchange</ulink>.
7056 <term>YAZ_MARC_CHECK</term>
7059 Pseudo format for validation only. Does not generate
7060 any real output except diagnostics.
7065 <term>YAZ_MARC_TURBOMARC</term>
7068 XML format with same semantics as MARCXML but more compact
7069 and geared towards fast processing with XSLT. Refer to
7070 <xref linkend="tools.turbomarc"/> for more information.
7075 <term>YAZ_MARC_JSON</term>
7078 <ulink url="&url.marc_in_json;">MARC-in_JSON</ulink> format.
7085 The actual conversion functions are
7086 <function>yaz_marc_decode_buf</function> and
7087 <function>yaz_marc_decode_wrbuf</function> which decodes and encodes
7088 a MARC record. The former function operates on simple buffers, the
7089 stores the resulting record in a WRBUF handle (WRBUF is a simple string
7092 <example id="example.marc.display">
7093 <title>Display of MARC record</title>
7095 The following program snippet illustrates how the MARC API may
7096 be used to convert a MARC record to the line-by-line format:
7097 <programlisting><![CDATA[
7098 void print_marc(const char *marc_buf, int marc_buf_size)
7100 char *result; /* for result buf */
7101 size_t result_len; /* for size of result */
7102 yaz_marc_t mt = yaz_marc_create();
7103 yaz_marc_xml(mt, YAZ_MARC_LINE);
7104 yaz_marc_decode_buf(mt, marc_buf, marc_buf_size,
7105 &result, &result_len);
7106 fwrite(result, result_len, 1, stdout);
7107 yaz_marc_destroy(mt); /* note that result is now freed... */
7113 <sect2 id="tools.turbomarc">
7114 <title>TurboMARC</title>
7116 TurboMARC is yet another XML encoding of a MARC record. The format
7117 was designed for fast processing with XSLT.
7121 Pazpar2 uses XSLT to convert an XML encoded MARC record to an internal
7122 representation. This conversion mostly check the tag of a MARC field
7123 to determine the basic rules in the conversion. This check is
7124 costly when that is tag is encoded as an attribute in MARCXML.
7125 By having the tag value as the element instead, makes processing
7126 many times faster (at least for Libxslt).
7129 TurboMARC is encoded as follows:
7133 Record elements is part of namespace
7134 "<literal>http://www.indexdata.com/turbomarc</literal>".
7139 A record is enclosed in element <literal>r</literal>.
7144 A collection of records is enclosed in element
7145 <literal>collection</literal>.
7150 The leader is encoded as element <literal>l</literal> with the
7151 leader content as its (text) value.
7156 A control field is encoded as element <literal>c</literal> concatenated
7157 with the tag value of the control field if the tag value
7158 matches the regular expression <literal>[a-zA-Z0-9]*</literal>.
7159 If the tag value do not match the regular expression
7160 <literal>[a-zA-Z0-9]*</literal> the control field is encoded
7161 as element <literal>c</literal> and attribute <literal>code</literal>
7162 will hold the tag value.
7163 This rule ensure that in the rare cases where a tag value might
7164 result in a non-wellformed XML YAZ encode it as a coded attribute
7168 The control field content is the the text value of this element.
7169 Indicators are encoded as attribute names
7170 <literal>i1</literal>, <literal>i2</literal>, etc.. and
7171 corresponding values for each indicator.
7176 A data field is encoded as element <literal>d</literal> concatenated
7177 with the tag value of the data field or using the attribute
7178 <literal>code</literal> as described in the rules for control fields.
7179 The children of the data field element is subfield elements.
7180 Each subfield element is encoded as <literal>s</literal>
7181 concatenated with the sub field code.
7182 The text of the subfield element is the contents of the subfield.
7183 Indicators are encoded as attributes for the data field element similar
7184 to the encoding for control fields.
7191 <sect1 id="tools.retrieval">
7192 <title>Retrieval Facility</title>
7194 YAZ version 2.1.20 or later includes a Retrieval facility tool
7195 which allows a SRU/Z39.50 to describe itself and perform record
7196 conversions. The idea is the following:
7200 An SRU/Z39.50 client sends a retrieval request which includes
7201 a combination of the following parameters: syntax (format),
7202 schema (or element set name).
7207 The retrieval facility is invoked with parameters in a
7208 server/proxy. The retrieval facility matches the parameters a set of
7209 "supported" retrieval types.
7210 If there is no match, the retrieval signals an error
7211 (syntax and / or schema not supported).
7216 For a successful match, the backend is invoked with the same
7217 or altered retrieval parameters (syntax, schema). If
7218 a record is received from the backend, it is converted to the
7219 frontend name / syntax.
7224 The resulting record is sent back the client and tagged with
7225 the frontend syntax / schema.
7231 The Retrieval facility is driven by an XML configuration. The
7232 configuration is neither Z39.50 ZeeRex or SRU ZeeRex. But it
7233 should be easy to generate both of them from the XML configuration.
7234 (unfortunately the two versions
7235 of ZeeRex differ substantially in this regard).
7237 <sect2 id="tools.retrieval.format">
7238 <title>Retrieval XML format</title>
7240 All elements should be covered by namespace
7241 <literal>http://indexdata.com/yaz</literal> .
7242 The root element node must be <literal>retrievalinfo</literal>.
7245 The <literal>retrievalinfo</literal> must include one or
7246 more <literal>retrieval</literal> elements. Each
7247 <literal>retrieval</literal> defines specific combination of
7248 syntax, name and identifier supported by this retrieval service.
7251 The <literal>retrieval</literal> element may include any of the
7252 following attributes:
7254 <varlistentry><term><literal>syntax</literal> (REQUIRED)</term>
7257 Defines the record syntax. Possible values is any
7258 of the names defined in YAZ' OID database or a raw
7263 <varlistentry><term><literal>name</literal> (OPTIONAL)</term>
7266 Defines the name of the retrieval format. This can be
7267 any string. For SRU, the value, is equivalent to schema (short-hand);
7268 for Z39.50 it's equivalent to simple element set name.
7269 For YAZ 3.0.24 and later this name may be specified as a glob
7270 expression with operators
7271 <literal>*</literal> and <literal>?</literal>.
7275 <varlistentry><term><literal>identifier</literal> (OPTIONAL)</term>
7278 Defines the URI schema name of the retrieval format. This can be
7279 any string. For SRU, the value, is equivalent to URI schema.
7280 For Z39.50, there is no equivalent.
7287 The <literal>retrieval</literal> may include one
7288 <literal>backend</literal> element. If a <literal>backend</literal>
7289 element is given, it specifies how the records are retrieved by
7290 some backend and how the records are converted from the backend to
7294 The attributes, <literal>name</literal> and <literal>syntax</literal>
7295 may be specified for the <literal>backend</literal> element. These
7296 semantics of these attributes is equivalent to those for the
7297 <literal>retrieval</literal>. However, these values are passed to
7301 The <literal>backend</literal> element may includes one or more
7302 conversion instructions (as children elements). The supported
7305 <varlistentry><term><literal>marc</literal></term>
7308 The <literal>marc</literal> element specifies a conversion
7309 to - and from ISO2709 encoded MARC and
7310 <ulink url="&url.marcxml;">&acro.marcxml;</ulink>/MarcXchange.
7311 The following attributes may be specified:
7314 <term><literal>inputformat</literal> (REQUIRED)</term>
7317 Format of input. Supported values are
7318 <literal>marc</literal> (for ISO2709), <literal>xml</literal>
7319 (MARCXML/MarcXchange) and <literal>json</literal>
7320 (<ulink url="&url.marc_in_json;">MARC-in_JSON</ulink>).
7325 <term><literal>outputformat</literal> (REQUIRED)</term>
7328 Format of output. Supported values are
7329 <literal>line</literal> (MARC line format);
7330 <literal>marcxml</literal> (for MARCXML),
7331 <literal>marc</literal> (ISO2709),
7332 <literal>marcxhcange</literal> (for MarcXchange),
7333 or <literal>json</literal>
7334 (<ulink url="&url.marc_in_json;">MARC-in_JSON </ulink>).
7339 <term><literal>inputcharset</literal> (OPTIONAL)</term>
7342 Encoding of input. For XML input formats, this need not
7343 be given, but for ISO2709 based inputformats, this should
7344 be set to the encoding used. For MARC21 records, a common
7345 inputcharset value would be <literal>marc-8</literal>.
7350 <term><literal>outputcharset</literal> (OPTIONAL)</term>
7353 Encoding of output. If outputformat is XML based, it is
7354 strongly recommened to use <literal>utf-8</literal>.
7363 <term><literal>xslt</literal></term>
7366 The <literal>xslt</literal> element specifies a conversion
7367 via &acro.xslt;. The following attributes may be specified:
7369 <varlistentry><term><literal>stylesheet</literal> (REQUIRED)</term>
7381 <term><literal>solrmarc</literal></term>
7384 The <literal>solrmarc</literal> decodes solrmarc records.
7385 It assumes that the input is pure solrmarc text (no escaping)
7386 and will convert all sequences of the form #XX; to a single
7387 character of the hexadecimal value as given by XX. The output,
7388 presumably, is a valid ISO2709 buffer.
7391 This conversion is available in YAZ 5.0.21 and later.
7398 <sect2 id="tools.retrieval.examples">
7399 <title>Retrieval Facility Examples</title>
7400 <example id="tools.retrieval.marc21">
7401 <title>MARC21 backend</title>
7403 A typical way to use the retrieval facility is to enable XML
7404 for servers that only supports ISO2709 encoded MARC21 records.
7406 <programlisting><![CDATA[
7408 <retrieval syntax="usmarc" name="F"/>
7409 <retrieval syntax="usmarc" name="B"/>
7410 <retrieval syntax="xml" name="marcxml"
7411 identifier="info:srw/schema/1/marcxml-v1.1">
7412 <backend syntax="usmarc" name="F">
7413 <marc inputformat="marc" outputformat="marcxml"
7414 inputcharset="marc-8"/>
7417 <retrieval syntax="xml" name="dc">
7418 <backend syntax="usmarc" name="F">
7419 <marc inputformat="marc" outputformat="marcxml"
7420 inputcharset="marc-8"/>
7421 <xslt stylesheet="MARC21slim2DC.xsl"/>
7428 This means that our frontend supports:
7432 MARC21 F(ull) records.
7437 MARC21 B(rief) records.
7447 Dublin core records.
7453 <example id="tools.retrieval.marcxml">
7454 <title>MARCXML backend</title>
7456 SRW/SRU and Solr backends returns records in XML.
7457 If they return MARCXML or MarcXchange, the retrieval module
7458 can convert those into ISO2709 formats, most commonly USMARC
7460 In this example, the backend returns MARCXML for schema="marcxml".
7462 <programlisting><![CDATA[
7464 <retrieval syntax="usmarc">
7465 <backend syntax="xml" name="marcxml">
7466 <marc inputformat="xml" outputformat="marc"
7467 outputcharset="marc-8"/>
7470 <retrieval syntax="xml" name="marcxml"
7471 identifier="info:srw/schema/1/marcxml-v1.1"/>
7472 <retrieval syntax="xml" name="dc">
7473 <backend syntax="xml" name="marcxml">
7474 <xslt stylesheet="MARC21slim2DC.xsl"/>
7481 This means that our frontend supports:
7485 MARC21 records (any element set name) in MARC-8 encoding.
7490 MARCXML records for element-set=marcxml
7495 Dublin core records for element-set=dc.
7502 <sect2 id="tools.retrieval.api">
7505 It should be easy to use the retrieval systems from applications. Refer
7507 <filename>yaz/retrieval.h</filename> and
7508 <filename>yaz/record_conv.h</filename>.
7512 <sect1 id="sorting">
7513 <title>Sorting</title>
7515 This chapter describes sorting and how it is supported in YAZ.
7516 Sorting applies to a result-set.
7518 <ulink url="http://www.loc.gov/z3950/agency/markup/05.html#3.2.7">
7519 Z39.50 sorting facility
7521 takes one or more input result-sets
7522 and one result-set as output. The most simple case is that
7523 the input-set is the same as the output-set.
7526 Z39.50 sorting has a separate APDU (service) that is, thus, performed
7527 following a search (two phases).
7530 In SRU/Solr, however, the model is different. Here, sorting is specified
7531 during the the search operation. Note, however, that SRU might
7532 perform sort as separate search, by referring to an existing result-set
7533 in the query (result-set reference).
7536 <title>Using the Z39.50 sort service</title>
7538 yaz-client and the ZOOM API supports the Z39.50 sort facility. In any
7539 case the sort sequence or sort critiera is using a string notation.
7540 This notation is a one-line notation suitable for being manually
7541 entered or generated and allows for easy logging (one liner).
7542 For the ZOOM API, the sort is specified in the call to ZOOM_query_sortby
7543 function. For yaz-client the sort is performed and specified using
7544 the sort and sort+ commands. For description of the sort criteria notation
7545 refer to the <link linkend="sortspec">sort command</link> in the
7549 The ZOOM API might choose one of several sort strategies for
7550 sorting. Refer to <xref linkend="zoom-sort-strategy"/>.
7554 <title>Type-7 sort</title>
7556 Type-7 sort is an extension to the Bib-1 based RPN query where the
7557 sort specification is embedded as an Attribute-Plus-Term.
7560 The objectives for introducing Type-7 sorting is that it allows
7561 a client to perform sorting even if it does not implement/support
7562 Z39.50 sort. Virtually all Z39.50 client software supports
7563 RPN queries. It also may improve performance because the sort
7564 critieria is specified along with the search query.
7567 The sort is triggered by the presence of type 7 and the value of type 7
7569 <ulink url="http://www.loc.gov/z3950/agency/asn1.html#SortKeySpec">
7572 The value for type 7 is 1 for ascending and 2 for descending.
7574 <ulink url="http://www.loc.gov/z3950/agency/asn1.html#SortElement">
7577 only the generic part is handled. If generic sortKey is of type
7578 sortField, then attribute type 1 is present and the value is
7579 sortField (InternationalString). If generic sortKey is of type
7580 sortAttributes, then the attributes in list is used . generic sortKey
7581 of type elementSpec is not supported.
7584 The term in the sorting Attribute-Plus-Term combo should hold
7585 an integer. The value is 0 for primary sorting criteria, 1 for second
7591 <title>Facets</title>
7593 YAZ supports facets for in Solr, SRU 2.0 and Z39.50 protocols.
7596 Like Type-1/RPN, YAZ supports a string notation for specifying
7597 facets. For the API this is performed by
7598 <function>yaz_pqf_parse_facet_list</function>.
7601 For ZOOM C the facets are given by option "facets"
7602 For yaz-client it is used for the facets command.
7605 The grammar of this specification is as follows:
7607 facet-spec ::= facet-list
7609 facet-list ::= facet-list ',' attr-spec | attr-spec
7611 attr-spec ::= attr-spec '@attr' string | '@attr' string
7614 The notation is inspired by PQF. The string following '@attr'
7615 may not include blanks and is of the form
7616 <replaceable>type</replaceable><literal>=</literal><replaceable>value</replaceable>,
7617 where <replaceable>type</replaceable> is an integer and
7618 <replaceable>value</replaceable> is a string or an integer.
7621 The Facets specification is not Bib-1. The following types apply:
7623 <table id="facet.attributes">
7624 <title>Facet attributes</title>
7626 <colspec colwidth="2*" colname="type"></colspec>
7627 <colspec colwidth="9*" colname="description"></colspec>
7631 <entry>Description</entry>
7638 Field-name. This is often a string, eg "Author", "Year", etc.
7644 Sort order. Value should be an integer.
7645 Value 0: count descending (frequency). Value 1: alpha ascending.
7651 Number of terms requested.
7666 <title>The ODR Module</title>
7667 <sect1 id="odr.introduction">
7668 <title>Introduction</title>
7670 &odr; is the BER-encoding/decoding subsystem of &yaz;. Care as been taken
7671 to isolate &odr; from the rest of the package - specifically from the
7672 transport interface. &odr; may be used in any context where basic
7673 ASN.1/BER representations are used.
7676 If you are only interested in writing a Z39.50 implementation based on
7677 the PDUs that are already provided with &yaz;, you only need to concern
7678 yourself with the section on managing ODR streams
7679 (<xref linkend="odr.use"/>). Only if you need to
7680 implement ASN.1 beyond that which has been provided, should you
7681 worry about the second half of the documentation
7682 (<xref linkend="odr.programming"/>).
7683 If you use one of the higher-level interfaces, you can skip this
7687 This is important, so we'll repeat it for emphasis: <emphasis>You do
7688 not need to read <xref linkend="odr.programming"/>
7689 to implement Z39.50 with &yaz;.</emphasis>
7692 If you need a part of the protocol that isn't already in &yaz;, you
7693 should contact the authors before going to work on it yourself: We
7694 might already be working on it. Conversely, if you implement a useful
7695 part of the protocol before us, we'd be happy to include it in a
7699 <sect1 id="odr.use">
7700 <title>Using ODR</title>
7701 <sect2 id="odr.streams">
7702 <title>ODR Streams</title>
7704 Conceptually, the ODR stream is the source of encoded data in the
7705 decoding mode; when encoding, it is the receptacle for the encoded
7706 data. Before you can use an ODR stream it must be allocated. This is
7707 done with the function
7710 ODR odr_createmem(int direction);
7713 The <function>odr_createmem()</function> function takes as argument one
7714 of three manifest constants: <literal>ODR_ENCODE</literal>,
7715 <literal>ODR_DECODE</literal>, or <literal>ODR_PRINT</literal>.
7716 An &odr; stream can be in only one mode - it is not possible to change
7717 its mode once it's selected. Typically, your program will allocate
7718 at least two ODR streams - one for decoding, and one for encoding.
7721 When you're done with the stream, you can use
7724 void odr_destroy(ODR o);
7727 to release the resources allocated for the stream.
7730 <sect2 id="odr.memory.management">
7731 <title id="memory">Memory Management</title>
7733 Two forms of memory management take place in the &odr; system. The first
7734 one, which has to do with allocating little bits of memory (sometimes
7735 quite large bits of memory, actually) when a protocol package is
7736 decoded, and turned into a complex of interlinked structures. This
7737 section deals with this system, and how you can use it for your own
7738 purposes. The next section deals with the memory management which is
7739 required when encoding data - to make sure that a large enough buffer is
7740 available to hold the fully encoded PDU.
7743 The &odr; module has its own memory management system, which is
7744 used whenever memory is required. Specifically, it is used to allocate
7745 space for data when decoding incoming PDUs. You can use the memory
7746 system for your own purposes, by using the function
7749 void *odr_malloc(ODR o, size_t size);
7752 You can't use the normal <function>free(2)</function> routine to free
7753 memory allocated by this function, and &odr; doesn't provide a parallel
7754 function. Instead, you can call
7757 void odr_reset(ODR o);
7760 when you are done with the
7761 memory: Everything allocated since the last call to
7762 <function>odr_reset()</function> is released.
7763 The <function>odr_reset()</function> call is also required to clear
7764 up an error condition on a stream.
7770 size_t odr_total(ODR o);
7773 returns the number of bytes allocated on the stream since the last call to
7774 <function>odr_reset()</function>.
7777 The memory subsystem of &odr; is fairly efficient at allocating and
7778 releasing little bits of memory. Rather than managing the individual,
7779 small bits of space, the system maintains a free-list of larger chunks
7780 of memory, which are handed out in small bits. This scheme is
7781 generally known as a <emphasis>nibble memory</emphasis> system.
7782 It is very useful for maintaining short-lived constructions such
7786 If you want to retain a bit of memory beyond the next call to
7787 <function>odr_reset()</function>, you can use the function
7790 ODR_MEM odr_extract_mem(ODR o);
7793 This function will give you control of the memory recently allocated
7794 on the ODR stream. The memory will live (past calls to
7795 <function>odr_reset()</function>), until you call the function
7798 void odr_release_mem(ODR_MEM p);
7801 The opaque <literal>ODR_MEM</literal> handle has no other purpose than
7802 referencing the memory block for you until you want to release it.
7805 You can use <function>odr_extract_mem()</function> repeatedly between
7806 allocating data, to retain individual control of separate chunks of data.
7809 <sect2 id="odr.encoding.and.decoding">
7810 <title>Encoding and Decoding Data</title>
7812 When encoding data, the ODR stream will write the encoded octet string
7813 in an internal buffer. To retrieve the data, use the function
7816 char *odr_getbuf(ODR o, int *len, int *size);
7819 The integer pointed to by len is set to the length of the encoded
7820 data, and a pointer to that data is returned. <literal>*size</literal>
7821 is set to the size of the buffer (unless <literal>size</literal> is null,
7822 signaling that you are not interested in the size). The next call to
7823 a primitive function using the same &odr; stream will overwrite the
7824 data, unless a different buffer has been supplied using the call
7827 void odr_setbuf(ODR o, char *buf, int len, int can_grow);
7830 which sets the encoding (or decoding) buffer used by
7831 <literal>o</literal> to <literal>buf</literal>, using the length
7832 <literal>len</literal>.
7833 Before a call to an encoding function, you can use
7834 <function>odr_setbuf()</function> to provide the stream with an encoding
7835 buffer of sufficient size (length). The <literal>can_grow</literal>
7836 parameter tells the encoding &odr; stream whether it is allowed to use
7837 <function>realloc(2)</function> to increase the size of the buffer when
7838 necessary. The default condition of a new encoding stream is equivalent
7839 to the results of calling
7842 odr_setbuf(stream, 0, 0, 1);
7845 In this case, the stream will allocate and reallocate memory as
7846 necessary. The stream reallocates memory by repeatedly doubling the
7847 size of the buffer - the result is that the buffer will typically
7848 reach its maximum, working size with only a small number of reallocation
7849 operations. The memory is freed by the stream when the latter is destroyed,
7850 unless it was assigned by the user with the <literal>can_grow</literal>
7851 parameter set to zero (in this case, you are expected to retain
7852 control of the memory yourself).
7855 To assume full control of an encoded buffer, you must first call
7856 <function>odr_getbuf()</function> to fetch the buffer and its length.
7857 Next, you should call <function>odr_setbuf()</function> to provide a
7858 different buffer (or a null pointer) to the stream. In the simplest
7859 case, you will reuse the same buffer over and over again, and you
7860 will just need to call <function>odr_getbuf()</function> after each
7861 encoding operation to get the length and address of the buffer.
7862 Note that the stream may reallocate the buffer during an encoding
7863 operation, so it is necessary to retrieve the correct address after
7864 each encoding operation.
7867 It is important to realize that the ODR stream will not release this
7868 memory when you call <function>odr_reset()</function>: It will
7869 merely update its internal pointers to prepare for the encoding of a
7871 When the stream is released by the <function>odr_destroy()</function>
7872 function, the memory given to it by <function>odr_setbuf</function> will
7873 be released <emphasis>only</emphasis> if the <literal>can_grow</literal>
7874 parameter to <function>odr_setbuf()</function> was nonzero. The
7875 <literal>can_grow</literal> parameter, in other words, is a way of
7876 signaling who is to own the buffer, you or the ODR stream. If you never call
7877 <function>odr_setbuf()</function> on your encoding stream, which is
7878 typically the case, the buffer allocated by the stream will belong to
7879 the stream by default.
7882 When you wish to decode data, you should first call
7883 <function>odr_setbuf()</function>, to tell the decoding stream
7884 where to find the encoded data, and how long the buffer is
7885 (the <literal>can_grow</literal> parameter is ignored by a decoding
7886 stream). After this, you can call the function corresponding to the
7887 data you wish to decode (eg, <function>odr_integer()</function> odr
7888 <function>z_APDU()</function>).
7890 <example id="example.odr.encoding.and.decoding.functions">
7891 <title>Encoding and decoding functions</title>
7893 int odr_integer(ODR o, Odr_int **p, int optional, const char *name);
7895 int z_APDU(ODR o, Z_APDU **p, int optional, const char *name);
7899 If the data is absent (or doesn't match the tag corresponding to
7900 the type), the return value will be either 0 or 1 depending on the
7901 <literal>optional</literal> flag. If <literal>optional</literal>
7902 is 0 and the data is absent, an error flag will be raised in the
7903 stream, and you'll need to call <function>odr_reset()</function> before
7904 you can use the stream again. If <literal>optional</literal> is
7905 nonzero, the pointer <emphasis>pointed</emphasis> to/ by
7906 <literal>p</literal> will be set to the null value, and the function
7908 The <literal>name</literal> argument is used to pretty-print the
7909 tag in question. It may be set to <literal>NULL</literal> if
7910 pretty-printing is not desired.
7913 If the data value is found where it's expected, the pointer
7914 <emphasis>pointed to</emphasis> by the <literal>p</literal> argument
7915 will be set to point to the decoded type.
7916 The space for the type will be allocated and owned by the &odr;
7917 stream, and it will live until you call
7918 <function>odr_reset()</function> on the stream. You cannot use
7919 <function>free(2)</function> to release the memory.
7920 You can decode several data elements (by repeated calls to
7921 <function>odr_setbuf()</function> and your decoding function), and
7922 new memory will be allocated each time. When you do call
7923 <function>odr_reset()</function>, everything decoded since the
7924 last call to <function>odr_reset()</function> will be released.
7926 <example id="example.odr.encoding.of.integer">
7927 <title>Encoding and decoding of an integer</title>
7929 The use of the double indirection can be a little confusing at first
7930 (its purpose will become clear later on, hopefully),
7931 so an example is in order. We'll encode an integer value, and
7932 immediately decode it again using a different stream. A useless, but
7933 informative operation.
7935 <programlisting><![CDATA[
7936 void do_nothing_useful(Odr_int value)
7939 Odr_int *valp, *resvalp;
7943 /* allocate streams */
7944 if (!(encode = odr_createmem(ODR_ENCODE)))
7946 if (!(decode = odr_createmem(ODR_DECODE)))
7950 if (odr_integer(encode, &valp, 0, 0) == 0)
7952 printf("encoding went bad\n");
7955 bufferp = odr_getbuf(encode, &len, 0);
7956 printf("length of encoded data is %d\n", len);
7958 /* now let's decode the thing again */
7959 odr_setbuf(decode, bufferp, len, 0);
7960 if (odr_integer(decode, &resvalp, 0, 0) == 0)
7962 printf("decoding went bad\n");
7965 /* ODR_INT_PRINTF format for printf (such as %d) */
7966 printf("the value is " ODR_INT_PRINTF "\n", *resvalp);
7969 odr_destroy(encode);
7970 odr_destroy(decode);
7975 This looks like a lot of work, offhand. In practice, the &odr; streams
7976 will typically be allocated once, in the beginning of your program
7977 (or at the beginning of a new network session), and the encoding
7978 and decoding will only take place in a few, isolated places in your
7979 program, so the overhead is quite manageable.
7983 <sect2 id="odr.printing">
7984 <title>Printing</title>
7986 When an ODR stream is created of type <literal>ODR_PRINT</literal>
7987 the ODR module will print the contents of a PDU in a readable format.
7988 By default output is written to the <literal>stderr</literal> stream.
7989 This behavior can be changed, however, by calling the function
7991 odr_setprint(ODR o, FILE *file);
7993 before encoders or decoders are being invoked.
7994 It is also possible to direct the output to a buffer (of indeed
7995 another file), by using the more generic mechanism:
7997 void odr_set_stream(ODR o, void *handle,
7998 void (*stream_write)(ODR o, void *handle, int type,
7999 const char *buf, int len),
8000 void (*stream_close)(void *handle));
8002 Here the user provides an opaque handle and two handlers,
8003 <replaceable>stream_write</replaceable> for writing,
8004 and <replaceable>stream_close</replaceable> which is supposed
8005 to close/free resources associated with handle.
8006 The <replaceable>stream_close</replaceable> handler is optional and
8007 if NULL for the function is provided, it will not be invoked.
8008 The <replaceable>stream_write</replaceable> takes the ODR handle
8009 as parameter, the user defined handle, a type
8010 <literal>ODR_OCTETSTRING</literal>, <literal>ODR_VISIBLESTRING</literal>
8011 which indicates the type of contents is being written.
8014 Another utility useful for diagnostics (error handling) or as
8015 part of the printing facilities is:
8017 const char **odr_get_element_path(ODR o);
8019 which returns a list of current elements that ODR deals with at the
8020 moment. For the returned array, say <literal>ar</literal>,
8021 <literal>ar[0]</literal> is the top level element,
8022 <literal>ar[n]</literal> is the last. The last element has the
8023 property that <literal>ar[n+1] == NULL</literal>.
8025 <example id="example.odr.element.path.record">
8026 <title>Element Path for record</title>
8028 For a database record part of a PresentResponse the
8029 array returned by <function>odr_get_element</function>
8030 is <literal>presentResponse</literal>, <literal>databaseOrSurDiagnostics</literal>, <literal>?</literal>, <literal>record</literal>, <literal>?</literal>, <literal>databaseRecord</literal> . The question mark appears due to
8031 unnamed constructions.
8035 <sect2 id="odr.diagnostics">
8036 <title>Diagnostics</title>
8038 The encoding/decoding functions all return 0 when an error occurs.
8039 Until you call <function>odr_reset()</function>, you cannot use the
8040 stream again, and any function called will immediately return 0.
8043 To provide information to the programmer or administrator, the function
8046 void odr_perror(ODR o, char *message);
8049 is provided, which prints the <literal>message</literal> argument to
8050 <literal>stderr</literal> along with an error message from the stream.
8053 You can also use the function
8056 int odr_geterror(ODR o);
8059 to get the current error number from the screen. The number will be
8060 one of these constants:
8062 <table frame="top" id="odr.error.codes">
8063 <title>ODR Error codes</title>
8068 <entry>Description</entry>
8073 <entry>OMEMORY</entry><entry>Memory allocation failed.</entry>
8076 <entry>OSYSERR</entry><entry>A system- or library call has failed.
8077 The standard diagnostic variable <literal>errno</literal> should be
8078 examined to determine the actual error.</entry>
8081 <entry>OSPACE</entry><entry>No more space for encoding.
8082 This will only occur when the user has explicitly provided a
8083 buffer for an encoding stream without allowing the system to
8084 allocate more space.</entry>
8087 <entry>OREQUIRED</entry><entry>This is a common protocol error; A
8088 required data element was missing during encoding or decoding.</entry>
8091 <entry>OUNEXPECTED</entry><entry>An unexpected data element was
8092 found during decoding.</entry>
8095 <entry>OOTHER</entry><entry>Other error. This is typically an
8096 indication of misuse of the &odr; system by the programmer, and also
8097 that the diagnostic system isn't as good as it should be, yet.</entry>
8103 The character string array
8109 can be indexed by the error code to obtain a human-readable
8110 representation of the problem.
8113 <sect2 id="odr.summary.and.synopsis">
8114 <title>Summary and Synopsis</title>
8116 #include <yaz/odr.h>
8118 ODR odr_createmem(int direction);
8120 void odr_destroy(ODR o);
8122 void odr_reset(ODR o);
8124 char *odr_getbuf(ODR o, int *len, int *size);
8126 void odr_setbuf(ODR o, char *buf, int len, int can_grow);
8128 void *odr_malloc(ODR o, int size);
8130 NMEM odr_extract_mem(ODR o);
8132 int odr_geterror(ODR o);
8134 void odr_perror(ODR o, const char *message);
8136 extern char *odr_errlist[];
8140 <sect1 id="odr.programming">
8141 <title>Programming with ODR</title>
8143 The API of &odr; is designed to reflect the structure of ASN.1, rather
8144 than BER itself. Future releases may be able to represent data in
8145 other external forms.
8149 There is an ASN.1 tutorial available at
8150 <ulink url="&url.asn.1.tutorial;">this site</ulink>.
8151 This site also has standards for ASN.1 (X.680) and BER (X.690)
8152 <ulink url="&url.asn.1.standards;">online</ulink>.
8156 The ODR interface is based loosely on that of the Sun Microsystems
8158 Specifically, each function which corresponds to an ASN.1 primitive
8159 type has a dual function. Depending on the settings of the ODR
8160 stream which is supplied as a parameter, the function may be used
8161 either to encode or decode data. The functions that can be built
8162 using these primitive functions, to represent more complex data types,
8163 share this quality. The result is that you only have to enter the
8164 definition for a type once - and you have the functionality of encoding,
8165 decoding (and pretty-printing) all in one unit.
8166 The resulting C source code is quite compact, and is a pretty
8167 straightforward representation of the source ASN.1 specification.
8170 In many cases, the model of the XDR functions works quite well in this
8172 In others, it is less elegant. Most of the hassle comes from the optional
8173 SEQUENCE members which don't exist in XDR.
8175 <sect2 id="odr.primitive.asn1.types">
8176 <title>The Primitive ASN.1 Types</title>
8178 ASN.1 defines a number of primitive types (many of which correspond
8179 roughly to primitive types in structured programming languages, such as C).
8181 <sect3 id="odr.integer">
8182 <title>INTEGER</title>
8184 The &odr; function for encoding or decoding (or printing) the ASN.1
8185 INTEGER type looks like this:
8188 int odr_integer(ODR o, Odr_int **p, int optional, const char *name);
8191 The <literal>Odr_int</literal> is just a simple integer.
8194 This form is typical of the primitive &odr; functions. They are named
8195 after the type of data that they encode or decode. They take an &odr;
8196 stream, an indirect reference to the type in question, and an
8197 <literal>optional</literal> flag (corresponding to the OPTIONAL keyword
8198 of ASN.1) as parameters. They all return an integer value of either one
8200 When you use the primitive functions to construct encoders for complex
8201 types of your own, you should follow this model as well. This
8202 ensures that your new types can be reused as elements in yet more
8206 The <literal>o</literal> parameter should obviously refer to a properly
8207 initialized &odr; stream of the right type (encoding/decoding/printing)
8208 for the operation that you wish to perform.
8211 When encoding or printing, the function first looks at
8212 <literal>* p</literal>. If <literal>* p</literal> (the pointer pointed
8213 to by <literal>p</literal>) is a null pointer, this is taken to mean that
8214 the data element is absent. If the <literal>optional</literal> parameter
8215 is nonzero, the function will return one (signifying success) without
8216 any further processing. If the <literal>optional</literal> is zero, an
8217 internal error flag is set in the &odr; stream, and the function will
8218 return 0. No further operations can be carried out on the stream without
8219 a call to the function <function>odr_reset()</function>.
8222 If <literal>*p</literal> is not a null pointer, it is expected to
8223 point to an instance of the data type. The data will be subjected to
8224 the encoding rules, and the result will be placed in the buffer held
8225 by the &odr; stream.
8228 The other ASN.1 primitives have similar functions that operate in
8232 <sect3 id="odr.boolean">
8233 <title>BOOLEAN</title>
8235 int odr_bool(ODR o, Odr_bool **p, int optional, const char *name);
8238 <sect3 id="odr.real">
8244 <sect3 id="odr.null">
8247 int odr_null(ODR o, Odr_null **p, int optional, const char *name);
8250 In this case, the value of **p is not important. If <literal>*p</literal>
8251 is different from the null pointer, the null value is present, otherwise
8255 <sect3 id="odr.octet.string">
8256 <title>OCTET STRING</title>
8258 typedef struct odr_oct
8264 int odr_octetstring(ODR o, Odr_oct **p, int optional,
8268 The <literal>buf</literal> field should point to the character array
8269 that holds the octetstring. The <literal>len</literal> field holds the
8271 The character array need not be null terminated.
8274 To make things a little easier, an alternative is given for string
8275 types that are not expected to contain embedded NULL characters (eg.
8279 int odr_cstring(ODR o, char **p, int optional, const char *name);
8282 Which encoded or decodes between OCTETSTRING representations and
8283 null-terminates C strings.
8286 Functions are provided for the derived string types, eg:
8289 int odr_visiblestring(ODR o, char **p, int optional,
8293 <sect3 id="odr.bit.string">
8294 <title>BIT STRING</title>
8296 int odr_bitstring(ODR o, Odr_bitmask **p, int optional,
8300 The opaque type <literal>Odr_bitmask</literal> is only suitable for
8301 holding relatively brief bit strings, eg. for options fields, etc.
8302 The constant <literal>ODR_BITMASK_SIZE</literal> multiplied by 8
8303 gives the maximum possible number of bits.
8306 A set of macros are provided for manipulating the
8307 <literal>Odr_bitmask</literal> type:
8310 void ODR_MASK_ZERO(Odr_bitmask *b);
8312 void ODR_MASK_SET(Odr_bitmask *b, int bitno);
8314 void ODR_MASK_CLEAR(Odr_bitmask *b, int bitno);
8316 int ODR_MASK_GET(Odr_bitmask *b, int bitno);
8319 The functions are modeled after the manipulation functions that
8320 accompany the <literal>fd_set</literal> type used by the
8321 <function>select(2)</function> call.
8322 <literal>ODR_MASK_ZERO</literal> should always be called first on a
8323 new bitmask, to initialize the bits to zero.
8326 <sect3 id="odr.object.identifier">
8327 <title>OBJECT IDENTIFIER</title>
8329 int odr_oid(ODR o, Odr_oid **p, int optional, const char *name);
8332 The C OID representation is simply an array of integers, terminated by
8333 the value -1 (the <literal>Odr_oid</literal> type is synonymous with
8334 the <literal>short</literal> type).
8335 We suggest that you use the OID database module (see
8336 <xref linkend="tools.oid.database"/>) to handle object identifiers
8337 in your application.
8341 <sect2 id="odr.tagging.primitive.types">
8342 <title>Tagging Primitive Types</title>
8344 The simplest way of tagging a type is to use the
8345 <function>odr_implicit_tag()</function> or
8346 <function>odr_explicit_tag()</function> macros:
8349 int odr_implicit_tag(ODR o, Odr_fun fun, int class, int tag,
8350 int optional, const char *name);
8352 int odr_explicit_tag(ODR o, Odr_fun fun, int class, int tag,
8353 int optional, const char *name);
8356 To create a type derived from the integer type by implicit tagging, you
8360 MyInt ::= [210] IMPLICIT INTEGER
8363 In the &odr; system, this would be written like:
8366 int myInt(ODR o, Odr_int **p, int optional, const char *name)
8368 return odr_implicit_tag(o, odr_integer, p,
8369 ODR_CONTEXT, 210, optional, name);
8373 The function <function>myInt()</function> can then be used like any of
8374 the primitive functions provided by &odr;. Note that the behavior of
8375 <function>odr_explicit_tag()</function>
8376 and <function>odr_implicit_tag()</function> macros
8377 act exactly the same as the functions they are applied to - they
8378 respond to error conditions, etc, in the same manner - they
8379 simply have three extra parameters. The class parameter may
8380 take one of the values: <literal>ODR_CONTEXT</literal>,
8381 <literal>ODR_PRIVATE</literal>, <literal>ODR_UNIVERSAL</literal>, or
8382 <literal>/ODR_APPLICATION</literal>.
8385 <sect2 id="odr.constructed.types">
8386 <title>Constructed Types</title>
8388 Constructed types are created by combining primitive types. The
8389 &odr; system only implements the SEQUENCE and SEQUENCE OF constructions
8390 (although adding the rest of the container types should be simple
8391 enough, if the need arises).
8394 For implementing SEQUENCEs, the functions
8397 int odr_sequence_begin(ODR o, void *p, int size, const char *name);
8398 int odr_sequence_end(ODR o);
8404 The <function>odr_sequence_begin()</function> function should be
8405 called in the beginning of a function that implements a SEQUENCE type.
8406 Its parameters are the &odr; stream, a pointer (to a pointer to the type
8407 you're implementing), and the <literal>size</literal> of the type
8408 (typically a C structure). On encoding, it returns 1 if
8409 <literal>* p</literal> is a null pointer. The <literal>size</literal>
8410 parameter is ignored. On decoding, it returns 1 if the type is found in
8411 the data stream. <literal>size</literal> bytes of memory are allocated,
8412 and <literal>*p</literal> is set to point to this space.
8413 <function>odr_sequence_end()</function> is called at the end of the
8414 complex function. Assume that a type is defined like this:
8417 MySequence ::= SEQUENCE {
8419 boolval BOOLEAN OPTIONAL
8423 The corresponding &odr; encoder/decoder function and the associated data
8424 structures could be written like this:
8427 typedef struct MySequence
8433 int mySequence(ODR o, MySequence **p, int optional, const char *name)
8435 if (odr_sequence_begin(o, p, sizeof(**p), name) == 0)
8436 return optional && odr_ok(o);
8438 odr_integer(o, &(*p)->intval, 0, "intval") &&
8439 odr_bool(o, &(*p)->boolval, 1, "boolval") &&
8440 odr_sequence_end(o);
8444 Note the 1 in the call to <function>odr_bool()</function>, to mark
8445 that the sequence member is optional.
8446 If either of the member types had been tagged, the macros
8447 <function>odr_implicit_tag()</function> or
8448 <function>odr_explicit_tag()</function>
8449 could have been used.
8450 The new function can be used exactly like the standard functions provided
8451 with &odr;. It will encode, decode or pretty-print a data value of the
8452 <literal>MySequence</literal> type. We like to name types with an
8453 initial capital, as done in ASN.1 definitions, and to name the
8454 corresponding function with the first character of the name in lower case.
8455 You could, of course, name your structures, types, and functions any way
8456 you please - as long as you're consistent, and your code is easily readable.
8457 <literal>odr_ok</literal> is just that - a predicate that returns the
8458 state of the stream. It is used to ensure that the behavior of the new
8459 type is compatible with the interface of the primitive types.
8462 <sect2 id="odr.tagging.constructed.types">
8463 <title>Tagging Constructed Types</title>
8466 See <xref linkend="odr.tagging.primitive.types"/> for information
8467 on how to tag the primitive types, as well as types that are
8471 <sect3 id="odr.implicit.tagging">
8472 <title>Implicit Tagging</title>
8474 Assume the type above had been defined as
8477 MySequence ::= [10] IMPLICIT SEQUENCE {
8479 boolval BOOLEAN OPTIONAL
8483 You would implement this in &odr; by calling the function
8486 int odr_implicit_settag(ODR o, int class, int tag);
8489 which overrides the tag of the type immediately following it. The
8490 macro <function>odr_implicit_tag()</function> works by calling
8491 <function>odr_implicit_settag()</function> immediately
8492 before calling the function pointer argument.
8493 Your type function could look like this:
8496 int mySequence(ODR o, MySequence **p, int optional, const char *name)
8498 if (odr_implicit_settag(o, ODR_CONTEXT, 10) == 0 ||
8499 odr_sequence_begin(o, p, sizeof(**p), name) == 0)
8500 return optional && odr_ok(o);
8502 odr_integer(o, &(*p)->intval, 0, "intval") &&
8503 odr_bool(o, &(*p)->boolval, 1, "boolval") &&
8504 odr_sequence_end(o);
8508 The definition of the structure <literal>MySequence</literal> would be
8512 <sect3 id="odr.explicit.tagging">
8513 <title>Explicit Tagging</title>
8515 Explicit tagging of constructed types is a little more complicated,
8516 since you are in effect adding a level of construction to the data.
8519 Assume the definition:
8522 MySequence ::= [10] IMPLICIT SEQUENCE {
8524 boolval BOOLEAN OPTIONAL
8528 Since the new type has an extra level of construction, two new functions
8529 are needed to encapsulate the base type:
8532 int odr_constructed_begin(ODR o, void *p, int class, int tag,
8535 int odr_constructed_end(ODR o);
8538 Assume that the IMPLICIT in the type definition above were replaced
8539 with EXPLICIT (or that the IMPLICIT keyword were simply deleted, which
8540 would be equivalent). The structure definition would look the same,
8541 but the function would look like this:
8544 int mySequence(ODR o, MySequence **p, int optional, const char *name)
8546 if (odr_constructed_begin(o, p, ODR_CONTEXT, 10, name) == 0)
8547 return optional && odr_ok(o);
8548 if (o->direction == ODR_DECODE)
8549 *p = odr_malloc(o, sizeof(**p));
8550 if (odr_sequence_begin(o, p, sizeof(**p), 0) == 0)
8552 *p = 0; /* this is almost certainly a protocol error */
8556 odr_integer(o, &(*p)->intval, 0, "intval") &&
8557 odr_bool(o, &(*p)->boolval, 1, "boolval") &&
8558 odr_sequence_end(o) &&
8559 odr_constructed_end(o);
8563 Notice that the interface here gets kind of nasty. The reason is
8564 simple: Explicitly tagged, constructed types are fairly rare in
8565 the protocols that we care about, so the
8566 esthetic annoyance (not to mention the dangers of a cluttered
8567 interface) is less than the time that would be required to develop a
8568 better interface. Nevertheless, it is far from satisfying, and it's a
8569 point that will be worked on in the future. One option for you would
8570 be to simply apply the <function>odr_explicit_tag()</function> macro to
8571 the first function, and not
8572 have to worry about <function>odr_constructed_*</function> yourself.
8573 Incidentally, as you might have guessed, the
8574 <function>odr_sequence_</function> functions are themselves
8575 implemented using the <function>/odr_constructed_</function> functions.
8579 <sect2 id="odr.sequence.of">
8580 <title>SEQUENCE OF</title>
8582 To handle sequences (arrays) of a specific type, the function
8585 int odr_sequence_of(ODR o, int (*fun)(ODR o, void *p, int optional),
8586 void *p, int *num, const char *name);
8589 The <literal>fun</literal> parameter is a pointer to the decoder/encoder
8590 function of the type. <literal>p</literal> is a pointer to an array of
8591 pointers to your type. <literal>num</literal> is the number of elements
8598 MyArray ::= SEQUENCE OF INTEGER
8601 The C representation might be
8604 typedef struct MyArray
8611 And the function might look like
8614 int myArray(ODR o, MyArray **p, int optional, const char *name)
8616 if (o->direction == ODR_DECODE)
8617 *p = odr_malloc(o, sizeof(**p));
8618 if (odr_sequence_of(o, odr_integer, &(*p)->elements,
8619 &(*p)->num_elements, name))
8622 return optional && odr_ok(o);
8626 <sect2 id="odr.choice.types">
8627 <title>CHOICE Types</title>
8629 The choice type is used fairly often in some ASN.1 definitions, so
8630 some work has gone into streamlining its interface.
8633 CHOICE types are handled by the function:
8636 int odr_choice(ODR o, Odr_arm arm[], void *p, void *whichp,
8640 The <literal>arm</literal> array is used to describe each of the possible
8641 types that the CHOICE type may assume. Internally in your application,
8642 the CHOICE type is represented as a discriminated union. That is, a
8643 C union accompanied by an integer (or enum) identifying the active
8645 <literal>whichp</literal> is a pointer to the union discriminator.
8646 When encoding, it is examined to determine the current type.
8647 When decoding, it is set to reference the type that was found in
8651 The Odr_arm type is defined thus:
8654 typedef struct odr_arm
8665 The interpretation of the fields are:
8669 <term>tagmode</term>
8670 <listitem><para>Either <literal>ODR_IMPLICIT</literal>,
8671 <literal>ODR_EXPLICIT</literal>, or <literal>ODR_NONE</literal> (-1)
8672 to mark no tagging.</para></listitem>
8676 <listitem><para>The value of the discriminator that corresponds to
8677 this CHOICE element. Typically, it will be a #defined constant, or
8678 an enum member.</para></listitem>
8682 <listitem><para>A pointer to a function that implements the type of
8683 the CHOICE member. It may be either a standard &odr; type or a type
8684 defined by yourself.</para></listitem>
8688 <listitem><para>Name of tag.</para></listitem>
8692 A handy way to prepare the array for use by the
8693 <function>odr_choice()</function> function is to
8694 define it as a static, initialized array in the beginning of your
8695 decoding/encoding function. Assume the type definition:
8698 MyChoice ::= CHOICE {
8700 tagged [99] IMPLICIT INTEGER,
8705 Your C type might look like
8708 typedef struct MyChoice
8725 And your function could look like this:
8728 int myChoice(ODR o, MyChoice **p, int optional, const char *name)
8730 static Odr_arm arm[] =
8732 {-1, -1, -1, MyChoice_untagged, odr_integer, "untagged"},
8733 {ODR_IMPLICIT, ODR_CONTEXT, 99, MyChoice_tagged, odr_integer,
8735 {-1, -1, -1, MyChoice_other, odr_boolean, "other"},
8739 if (o->direction == ODR_DECODE)
8740 *p = odr_malloc(o, sizeof(**p);
8742 return optional && odr_ok(o);
8744 if (odr_choice(o, arm, &(*p)->u, &(*p)->which), name)
8747 return optional && odr_ok(o);
8751 In some cases (say, a non-optional choice which is a member of a
8752 sequence), you can "embed" the union and its discriminator in the
8753 structure belonging to the enclosing type, and you won't need to
8754 fiddle with memory allocation to create a separate structure to
8755 wrap the discriminator and union.
8758 The corresponding function is somewhat nicer in the Sun XDR interface.
8759 Most of the complexity of this interface comes from the possibility of
8760 declaring sequence elements (including CHOICEs) optional.
8763 The ASN.1 specifications naturally requires that each member of a
8764 CHOICE have a distinct tag, so they can be told apart on decoding.
8765 Sometimes it can be useful to define a CHOICE that has multiple types
8766 that share the same tag. You'll need some other mechanism, perhaps
8767 keyed to the context of the CHOICE type. In effect, we would like to
8768 introduce a level of context-sensitiveness to our ASN.1 specification.
8769 When encoding an internal representation, we have no problem, as long
8770 as each CHOICE member has a distinct discriminator value. For
8771 decoding, we need a way to tell the choice function to look for a
8772 specific arm of the table. The function
8775 void odr_choice_bias(ODR o, int what);
8778 provides this functionality. When called, it leaves a notice for the next
8779 call to <function>odr_choice()</function> to be called on the decoding
8780 stream <literal>o</literal> that only the <literal>arm</literal> entry with
8781 a <literal>which</literal> field equal to <literal>what</literal>
8785 The most important application (perhaps the only one, really) is in
8786 the definition of application-specific EXTERNAL encoders/decoders
8787 which will automatically decode an ANY member given the direct or
8792 <sect1 id="odr.debugging">
8793 <title>Debugging</title>
8795 The protocol modules are suffering somewhat from a lack of diagnostic
8796 tools at the moment. Specifically ways to pretty-print PDUs that
8797 aren't recognized by the system. We'll include something to this end
8798 in a not-too-distant release. In the meantime, what we do when we get
8799 packages we don't understand is to compile the ODR module with
8800 <literal>ODR_DEBUG</literal> defined. This causes the module to dump tracing
8801 information as it processes data units. With this output and the
8802 protocol specification (Z39.50), it is generally fairly easy to see
8807 <chapter id="comstack">
8808 <title>The COMSTACK Module</title>
8809 <sect1 id="comstack.synopsis">
8810 <title>Synopsis (blocking mode)</title>
8811 <programlisting><![CDATA[
8814 int size = 0, length_incoming;
8815 char server_address_str[] = "localhost:9999";
8816 void *server_address_ip;
8819 char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
8820 int protocol_package_length = strlen(protocol_package);
8822 stack = cs_create(tcpip_type, 1, PROTO_HTTP);
8824 perror("cs_create"); /* use perror() here since we have no stack yet */
8828 server_address_ip = cs_straddr(stack, server_address_str);
8829 if (!server_address_ip) {
8830 fprintf(stderr, "cs_straddr: address could not be resolved\n");
8834 status = cs_connect(stack, server_address_ip);
8836 fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
8840 status = cs_rcvconnect(stack);
8842 fprintf(stderr, "cs_rcvconnect: %s\n", cs_strerror(stack));
8846 status = cs_put(stack, protocol_package, protocol_package_length);
8848 fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
8852 /* Now get a response */
8853 length_incoming = cs_get(stack, &buf, &size);
8854 if (!length_incoming) {
8855 fprintf(stderr, "Connection closed\n");
8857 } else if (length_incoming < 0) {
8858 fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
8863 fwrite(buf, length_incoming, 1, stdout);
8874 <sect1 id="comstack.introduction">
8875 <title>Introduction</title>
8878 subsystem provides a transparent interface to different types of transport
8879 stacks for the exchange of BER-encoded data and HTTP packets.
8880 At present, the RFC1729 method (BER over TCP/IP), local UNIX socket and an
8881 experimental SSL stack are supported, but others may be added in time.
8882 The philosophy of the
8883 module is to provide a simple interface by hiding unused options and
8884 facilities of the underlying libraries. This is always done at the risk
8885 of losing generality, and it may prove that the interface will need
8890 There hasn't been interest in the XTImOSI stack for some years.
8891 Therefore, it is no longer supported.
8895 The interface is implemented in such a fashion that only the
8896 sub-layers constructed to the transport methods that you wish to
8897 use in your application are linked in.
8900 You will note that even though simplicity was a goal in the design,
8901 the interface is still orders of magnitudes more complex than the
8902 transport systems found in many other packages. One reason is that
8903 the interface needs to support the somewhat different requirements of
8904 the different lower-layer communications stacks; another important
8905 reason is that the interface seeks to provide a more or less
8906 industrial-strength approach to asynchronous event-handling.
8907 When no function is allowed to block, things get more complex -
8908 particularly on the server side.
8909 We urge you to have a look at the demonstration client and server
8910 provided with the package. They are meant to be easily readable and
8911 instructive, while still being at least moderately useful.
8914 <sect1 id="comstack.common">
8915 <title>Common Functions</title>
8916 <sect2 id="comstack.managing.endpoints">
8917 <title>Managing Endpoints</title>
8919 COMSTACK cs_create(CS_TYPE type, int blocking, int protocol);
8922 Creates an instance of the protocol stack - a communications endpoint.
8923 The <literal>type</literal> parameter determines the mode
8924 of communication. At present the following values are supported:
8928 <term><literal>tcpip_type</literal></term>
8929 <listitem><para>TCP/IP (BER over TCP/IP or HTTP over TCP/IP)
8933 <term><literal>ssl_type</literal></term>
8934 <listitem><para>Secure Socket Layer (SSL). This COMSTACK
8935 is experimental and is not fully implemented. If
8936 HTTP is used, this effectively is HTTPS.
8940 <term><literal>unix_type</literal></term>
8941 <listitem><para>Unix socket (unix only). Local Transfer via
8942 file socket. See <citerefentry><refentrytitle>unix</refentrytitle>
8943 <manvolnum>7</manvolnum></citerefentry>.
8948 The <function>cs_create</function> function returns a null-pointer
8949 if a system error occurs.
8950 The <literal>blocking</literal> parameter should be one if
8951 you wish the association to operate in blocking mode, zero otherwise.
8952 The <literal>protocol</literal> field should be
8953 <literal>PROTO_Z3950</literal> or <literal>PROTO_HTTP</literal>.
8954 Protocol <literal>PROTO_SR</literal> is no longer supported.
8957 void cs_close(COMSTACK handle);
8960 Closes the connection (as elegantly as the lower layers will permit),
8961 and releases the resources pointed to by the
8962 <literal>handle</literal>
8964 <literal>handle</literal>
8965 should not be referenced again after this call.
8969 We really need a soft disconnect, don't we?
8973 <sect2 id="comstack.data.exchange">
8974 <title>Data Exchange</title>
8976 int cs_put(COMSTACK handle, char *buf, int len);
8979 Sends <literal>buf</literal> down the wire.
8980 In blocking mode, this function will return only when a full buffer has
8981 been written, or an error has occurred. In nonblocking mode, it's
8982 possible that the function will be unable to send the full buffer
8983 at once, which will be indicated by a return value of 1.
8984 The function will keep track of the number of octets already written; you
8985 should call it repeatedly with the same values of <literal>buf</literal>
8986 and <literal>len</literal>, until the buffer has been transmitted.
8987 When a full buffer has been sent, the function will return 0 for
8988 success. -1 indicates an error condition (see below).
8991 int cs_get(COMSTACK handle, char **buf, int *size);
8994 Receives a PDU or HTTP Response from the peer. Returns the number of
8996 In nonblocking mode, it is possible that not all of the packet can be
8997 read at once. In this case, the function returns 1. To simplify the
8998 interface, the function is
8999 responsible for managing the size of the buffer. It will be reallocated
9000 if necessary to contain large packages, and will sometimes be moved
9001 around internally by the subsystem when partial packages are read. Before
9003 <function>cs_get</function>
9004 for the fist time, the buffer can be initialized to the null pointer,
9005 and the length should also be set to 0 - cs_get will perform a
9006 <function>malloc(2)</function>
9007 on the buffer for you. When a full buffer has been read, the size of
9008 the package is returned (which will always be greater than 1). -1
9009 indicates an error condition.
9012 See also the <function>cs_more()</function> function below.
9015 int cs_more(COMSTACK handle);
9018 The <function>cs_more()</function> function should be used in conjunction
9019 with <function>cs_get</function> and
9020 <function>select(2)</function>.
9021 The <function>cs_get()</function> function will sometimes
9022 (notably in the TCP/IP mode) read more than a single protocol package
9023 off the network. When this happens, the extra package is stored
9024 by the subsystem. After calling <function>cs_get()</function>, and before
9025 waiting for more input, You should always call
9026 <function>cs_more()</function>
9027 to check if there's a full protocol package already read. If
9028 <function>cs_more()</function>
9030 <function>cs_get()</function>
9031 can be used to immediately fetch the new package. For the
9033 subsystem, the function should always return 0, but if you want your
9034 stuff to be protocol independent, you should use it.
9038 The <function>cs_more()</function>
9039 function is required because the RFC1729-method
9040 does not provide a way of separating individual PDUs, short of
9041 partially decoding the BER. Some other implementations will carefully
9042 nibble at the packet by calling
9043 <function>read(2)</function>
9044 several times. This was felt to be too inefficient (or at least
9045 clumsy) - hence the call for this extra function.
9049 int cs_look(COMSTACK handle);
9052 This function is useful when you're operating in nonblocking
9054 <function>select(2)</function>
9055 tells you there's something happening on the line. It returns one of
9056 the following values:
9060 <term>CS_NONE</term>
9062 No event is pending. The data found on the line was not a
9067 <term>CS_CONNECT</term>
9069 A response to your connect request has been received. Call
9070 <function>cs_rcvconnect</function>
9071 to process the event and to finalize the connection establishment.
9075 <term>CS_DISCON</term>
9077 The other side has closed the connection (or maybe sent a disconnect
9078 request - but do we care? Maybe later). Call
9079 <function>cs_close</function> to close your end of the association
9084 <term>CS_LISTEN</term>
9086 A connect request has been received.
9087 Call <function>cs_listen</function> to process the event.
9091 <term>CS_DATA</term>
9093 There's data to be found on the line.
9094 Call <function>cs_get</function> to get it.
9100 You should be aware that even if
9101 <function>cs_look()</function>
9102 tells you that there's an event event pending, the corresponding
9103 function may still return and tell you there was nothing to be found.
9104 This means that only part of a package was available for reading. The
9105 same event will show up again, when more data has arrived.
9109 int cs_fileno(COMSTACK h);
9112 Returns the file descriptor of the association. Use this when
9113 file-level operations on the endpoint are required
9114 (<function>select(2)</function> operations, specifically).
9118 <sect1 id="comstack.client">
9119 <title>Client Side</title>
9121 int cs_connect(COMSTACK handle, void *address);
9124 Initiate a connection with the target at <literal>address</literal>
9125 (more on addresses below). The function will return 0 on success, and 1 if
9126 the operation does not complete immediately (this will only
9127 happen on a nonblocking endpoint). In this case, use
9128 <function>cs_rcvconnect</function> to complete the operation,
9129 when <function>select(2)</function> or <function>poll(2)</function>
9130 reports input pending on the association.
9133 int cs_rcvconnect(COMSTACK handle);
9136 Complete a connect operation initiated by <function>cs_connect()</function>.
9137 It will return 0 on success; 1 if the operation has not yet completed (in
9138 this case, call the function again later); -1 if an error has occurred.
9141 <sect1 id="comstack.server">
9142 <title>Server Side</title>
9144 To establish a server under the <application>inetd</application>
9148 COMSTACK cs_createbysocket(int socket, CS_TYPE type, int blocking,
9152 The <literal>socket</literal> parameter is an established socket (when
9153 your application is invoked from <application>inetd</application>, the
9154 socket will typically be 0.
9155 The following parameters are identical to the ones for
9156 <function>cs_create</function>.
9159 int cs_bind(COMSTACK handle, void *address, int mode)
9162 Binds a local address to the endpoint. Read about addresses below. The
9163 <literal>mode</literal> parameter should be either
9164 <literal>CS_CLIENT</literal> or <literal>CS_SERVER</literal>.
9167 int cs_listen(COMSTACK handle, char *addr, int *addrlen);
9170 Call this to process incoming events on an endpoint that has been
9171 bound in listening mode. It will return 0 to indicate that the connect
9172 request has been received, 1 to signal a partial reception, and -1 to
9173 indicate an error condition.
9176 COMSTACK cs_accept(COMSTACK handle);
9179 This finalizes the server-side association establishment, after
9180 cs_listen has completed successfully. It returns a new connection
9181 endpoint, which represents the new association. The application will
9182 typically wish to fork off a process to handle the association at this
9183 point, and continue listen for new connections on the old
9184 <literal>handle</literal>.
9187 You can use the call
9190 const char *cs_addrstr(COMSTACK);
9193 on an established connection to retrieve the host-name of the remote host.
9197 You may need to use this function with some care if your
9198 name server service is slow or unreliable
9202 <sect1 id="comstack.addresses">
9203 <title>Addresses</title>
9205 The low-level format of the addresses are different depending on the
9206 mode of communication you have chosen. A function is provided by each
9207 of the lower layers to map a user-friendly string-form address to the
9208 binary form required by the lower layers.
9211 void *cs_straddr(COMSTACK handle, const char *str);
9214 The format for TCP/IP and SSL addresses is:
9217 <host> [ ':' <portnum> ]
9220 The <literal>hostname</literal> can be either a domain name or an
9221 IP address. The port number, if omitted, defaults to 210.
9224 For TCP/IP and SSL, the special hostnames <literal>@</literal>,
9225 maps to <literal>IN6ADDR_ANY_INIT</literal> with
9226 IPV4 binding as well (bindv6only=0),
9227 The special hostname <literal>@4</literal> binds to
9228 <literal>INADDR_ANY</literal> (IPV4 only listener).
9229 The special hostname <literal>@6</literal> binds to
9230 <literal>IN6ADDR_ANY_INIT</literal> with bindv6only=1 (IPV6 only listener).
9233 For UNIX sockets, the format of an address is the socket filename.
9236 When a connection has been established, you can use
9239 const char *cs_addrstr(COMSTACK h);
9242 to retrieve the host name of the peer system. The function returns
9243 a pointer to a static area, which is overwritten on the next call
9247 A fairly recent addition to the &comstack; module is the utility
9251 COMSTACK cs_create_host (const char *str, int blocking, void **vp);
9254 which is just a wrapper for <function>cs_create</function> and
9255 <function>cs_straddr</function>. The <parameter>str</parameter>
9256 is similar to that described for <function>cs_straddr</function>
9257 but with a prefix denoting the &comstack; type. Prefixes supported
9258 are <literal>tcp:</literal>, <literal>unix:</literal> and
9259 <literal>ssl:</literal> for TCP/IP, UNIX and SSL respectively.
9260 If no prefix is given, then TCP/IP is used.
9261 The <parameter>blocking</parameter> is passed to
9262 function <function>cs_create</function>. The third parameter
9263 <parameter>vp</parameter> is a pointer to &comstack; stack type
9265 Parameter <parameter>vp</parameter> is reserved for future use.
9266 Set it to <literal>NULL</literal>.
9269 <sect1 id="comstack.ssl">
9273 void *cs_get_ssl(COMSTACK cs);
9275 Returns the SSL handle, <literal>SSL *</literal> for comstack. If comstack
9276 is not of type SSL, NULL is returned.
9280 int cs_set_ssl_ctx(COMSTACK cs, void *ctx);
9282 Sets SSL context for comstack. The parameter is expected to be of type
9283 <literal>SSL_CTX *</literal>. This function should be called just
9284 after comstack has been created (before connect, bind, etc).
9285 This function returns 1 for success; 0 for failure.
9289 int cs_set_ssl_certificate_file(COMSTACK cs, const char *fname);
9291 Sets SSL certificate for comstack as a PEM file. This function
9292 returns 1 for success; 0 for failure.
9296 int cs_get_ssl_peer_certificate_x509(COMSTACK cs, char **buf, int *len);
9298 This function returns the peer certificate. If successful,
9299 <literal>*buf</literal> and <literal>*len</literal> holds
9300 X509 buffer and length respectively. Buffer should be freed
9301 with <literal>xfree</literal>. This function returns 1 for success;
9305 <sect1 id="comstack.diagnostics">
9306 <title>Diagnostics</title>
9308 All functions return -1 if an error occurs. Typically, the functions
9309 will return 0 on success, but the data exchange functions
9310 (<function>cs_get</function>, <function>cs_put</function>,
9311 <function>cs_more</function>) follow special rules. Consult their
9315 The error code for the COMSTACK can be retrieved using C macro
9316 <function>cs_errno</function> which will return one
9317 of the error codes <literal>CSYSERR</literal>,
9318 <literal>CSOUTSTATE</literal>,
9319 <literal>CSNODATA</literal>, ...
9322 int cs_errno(COMSTACK handle);
9325 You can the textual representation of the error code
9326 by using <function>cs_errmsg</function> - which
9327 works like <function>strerror(3)</function>
9330 const char *cs_errmsg(int n);
9333 It is also possible to get straight to the textual represenataion
9334 without the error code by using
9335 <function>cs_strerror</function>.
9338 const char *cs_strerror(COMSTACK h);
9341 <sect1 id="comstack.summary">
9342 <title>Summary and Synopsis</title>
9344 #include <yaz/comstack.h>
9346 #include <yaz/tcpip.h> /* this is for TCP/IP and SSL support */
9347 #include <yaz/unix.h> /* this is for UNIX socket support */
9349 COMSTACK cs_create(CS_TYPE type, int blocking, int protocol);
9351 COMSTACK cs_createbysocket(int s, CS_TYPE type, int blocking,
9353 COMSTACK cs_create_host(const char *str, int blocking,
9356 int cs_bind(COMSTACK handle, int mode);
9358 int cs_connect(COMSTACK handle, void *address);
9360 int cs_rcvconnect(COMSTACK handle);
9362 int cs_listen(COMSTACK handle);
9364 COMSTACK cs_accept(COMSTACK handle);
9366 int cs_put(COMSTACK handle, char *buf, int len);
9368 int cs_get(COMSTACK handle, char **buf, int *size);
9370 int cs_more(COMSTACK handle);
9372 void cs_close(COMSTACK handle);
9374 int cs_look(COMSTACK handle);
9376 void *cs_straddr(COMSTACK handle, const char *str);
9378 const char *cs_addrstr(COMSTACK h);
9383 <chapter id="future">
9384 <title>Future Directions</title>
9386 We have a new and better version of the front-end server on the drawing
9387 board. Resources and external commitments will govern when we'll be
9388 able to do something real with it. Features should include greater
9389 flexibility, greater support for access/resource control, and easy
9390 support for Explain (possibly with Zebra as an extra database engine).
9393 &yaz; is a BER toolkit and as such should support all protocols
9394 out there based on that. We'd like to see running ILL applications.
9395 It shouldn't be that hard. Another thing that would be interesting is
9396 LDAP. Maybe a generic framework for doing IR using both LDAP and
9397 Z39.50 transparently.
9400 The SOAP implementation is incomplete. In the future we hope
9401 to add more features to it. Perhaps make a WSDL/XML Schema compiler.
9402 The authors of libxml2 are already working on XML Schema / RelaxNG
9403 compilers so this may not be too hard.
9406 It would be neat to have a proper module mechanism for the Generic
9407 Frontend Server so that backend would be dynamically
9408 loaded (as shared objects / DLLs).
9411 Other than that, &yaz; generally moves in the directions which appear to
9412 make the most people happy (including ourselves, as prime users of the
9413 software). If there's something you'd like to see in here, then drop
9414 us a note and let's see what we can come up with.
9417 <reference id="reference">
9418 <title>Reference</title>
9419 <partintro id="reference-introduction">
9421 The material in this chapter is drawn directly from the individual
9427 <appendix id="list-oids">
9428 <title>List of Object Identifiers</title>
9430 These is a list of object identifiers that are built into YAZ.
9434 <appendix id="bib1-diagnostics">
9435 <title>Bib-1 diagnostics</title>
9437 List of Bib-1 diagnostics that are known to YAZ.
9441 <appendix id="sru-diagnostics">
9442 <title>SRU diagnostics</title>
9444 List of SRU diagnostics that are known to YAZ.
9448 <appendix id="license">
9449 <title>License</title>
9450 <sect1 id="license.indexdata">
9451 <title>Index Data Copyright</title>
9453 Copyright © ©right-year; Index Data.
9456 All rights reserved.
9459 Redistribution and use in source and binary forms, with or without
9460 modification, are permitted provided that the following conditions are met:
9465 Redistributions of source code must retain the above copyright
9466 notice, this list of conditions and the following disclaimer.
9471 Redistributions in binary form must reproduce the above copyright
9472 notice, this list of conditions and the following disclaimer in the
9473 documentation and/or other materials provided with the distribution.
9478 Neither the name of Index Data nor the names of its contributors
9479 may be used to endorse or promote products derived from this
9480 software without specific prior written permission.
9485 THIS SOFTWARE IS PROVIDED BY INDEX DATA ``AS IS'' AND ANY
9486 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9487 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
9488 DISCLAIMED. IN NO EVENT SHALL INDEX DATA BE LIABLE FOR
9489 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
9490 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
9491 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
9492 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
9493 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
9494 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
9499 <appendix id="indexdata">
9500 <title>About Index Data</title>
9502 Index Data is a consulting and software-development enterprise that
9503 specializes in library and information management systems. Our
9504 interests and expertise span a broad range of related fields, and one
9505 of our primary, long-term objectives is the development of a powerful
9506 information management
9507 system with open network interfaces and hyper-media capabilities.
9509 We make this software available free of charge, on a fairly unrestrictive
9510 license; as a service to the networking community, and to further the
9511 development of quality software for open network communication.
9513 We'll be happy to answer questions about the software, and about ourselves
9519 <street>Amagerfælledvej 56</street>
9520 <postcode>2300 Copenhagen S</postcode>
9521 <country>Denmark</country>
9522 Email <email>info@indexdata.dk</email>
9526 The Hacker's Jargon File has the following to say about the
9528 prefix "YA" in the name of a software product.
9532 Yet Another. adj. 1. Of your own work: A
9533 humorous allusion often used in titles to acknowledge that the
9534 topic is not original, though the content is. As in "Yet Another
9535 AI Group" or "Yet Another Simulated Annealing Algorithm".
9537 others' work: Describes something of which there are already far
9542 <appendix id="credits">
9543 <title>Credits</title>
9545 This appendix lists individuals that have contributed in the development
9546 of &yaz;. Some have contributed with code, while others have provided bug
9547 fixes or suggestions. If we're missing somebody, of if you, for
9548 whatever reason, don't like to be listed here, let us know.
9558 Morten Bøgeskov
9579 Mads Bondo Dydensborg
9588 Morten Garkier Hendriksen
9645 Tom André Øverland
9651 <!-- Keep this comment at the end of the file
9654 nxml-child-indent: 1