added documentation on new filter load_balance
[metaproxy-moved-to-github.git] / doc / book.xml
1 <?xml version="1.0" standalone="no"?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1//EN"
3     "http://www.oasis-open.org/docbook/xml/4.1/docbookx.dtd" 
4 [
5      <!ENTITY local SYSTEM "local.ent">
6      <!ENTITY manref SYSTEM "manref.xml">
7      <!ENTITY progref SYSTEM "progref.xml">
8      <!ENTITY % common SYSTEM "common/common.ent">
9      %common;
10      <!-- Next line allows imagedata/@format="PDF" and is taken from 
11          http://lists.oasis-open.org/archives/docbook/200303/msg00163.html
12      -->
13      <!ENTITY % local.notation.class "| PDF">
14      <!-- Next line is necessary for some XML parsers, for reasons I
15           don't understand.  I got this from
16          http://lists.oasis-open.org/archives/docbook/200303/msg00180.html
17      -->
18      <!NOTATION PDF SYSTEM "PDF">
19 ]>
20 <!-- $Id: book.xml,v 1.45 2007-01-03 15:34:50 marc Exp $ -->
21 <book id="metaproxy">
22  <bookinfo>
23   <title>Metaproxy - User's Guide and Reference</title>
24   <author>
25    <firstname>Adam</firstname><surname>Dickmeiss</surname>
26   </author>
27   <author>
28    <firstname>Marc</firstname><surname>Cromme</surname>
29   </author>
30   <author>
31    <firstname>Mike</firstname><surname>Taylor</surname>
32   </author>
33   <copyright>
34    <year>2006</year>
35    <holder>Index Data ApS</holder>
36   </copyright>
37   <abstract>
38    <simpara>
39     Metaproxy is a universal router, proxy and encapsulated
40     metasearcher for information retrieval protocols.  It accepts,
41     processes, interprets and redirects requests from IR clients using
42     standard protocols such as
43     <ulink url="&url.z39.50;">ANSI/NISO Z39.50</ulink>
44     (and in the future <ulink url="&url.sru;">SRU</ulink>
45     and <ulink url="&url.srw;">SRW</ulink>), as
46     well as functioning as a limited
47     <ulink url="&url.http;">HTTP</ulink> server. 
48     Metaproxy is configured by an XML file which
49     specifies how the software should function in terms of routes that
50     the request packets can take through the proxy, each step on a
51     route being an instantiation of a filter.  Filters come in many
52     types, one for each operation: accepting Z39.50 packets, logging,
53     query transformation, multiplexing, etc.  Further filter-types can
54     be added as loadable modules to extend Metaproxy functionality,
55     using the filter API.
56    </simpara>
57    <simpara>
58     Metaproxy is <emphasis>not</emphasis> open-source software, but
59     may be freely downloaded, unpacked, inspected, built and run for
60     evaluation purposes.  Deployment requires a separate, commercial,
61     license.
62    </simpara>
63    <simpara>
64     <inlinemediaobject>
65      <imageobject>
66       <imagedata fileref="common/id.png" format="PNG"/>
67      </imageobject>
68      <imageobject>
69       <imagedata fileref="common/id.eps" format="EPS"/>
70      </imageobject>
71     </inlinemediaobject>
72    </simpara>
73   </abstract>
74  </bookinfo>
75
76  <chapter id="introduction">
77   <title>Introduction</title>
78   
79   
80   <para>
81    <ulink url="&url.metaproxy;">Metaproxy</ulink>
82    is a stand alone program that acts as a universal router, proxy and
83    encapsulated metasearcher for information retrieval protocols such
84    as <ulink url="&url.z39.50;">Z39.50</ulink>, and in the future
85    <ulink url="&url.sru;">SRU</ulink> and <ulink url="&url.srw;">SRW</ulink>.
86    To clients, it acts as a server of these protocols: it can be searched,
87    records can be retrieved from it, etc. 
88    To servers, it acts as a client: it searches in them,
89    retrieves records from them, etc.  it satisfies its clients'
90    requests by transforming them, multiplexing them, forwarding them
91    on to zero or more servers, merging the results, transforming
92    them, and delivering them back to the client.  In addition, it
93    acts as a simple <ulink url="&url.http;">HTTP</ulink> server; support
94    for further protocols can be added in a modular fashion, through the
95    creation of new filters.
96   </para>
97   <screen>
98    Anything goes in!
99    Anything goes out!
100    Fish, bananas, cold pyjamas,
101    Mutton, beef and trout!
102         - attributed to Cole Porter.
103   </screen>
104   <para>
105    Metaproxy is a more capable alternative to
106    <ulink url="&url.yazproxy;">YAZ Proxy</ulink>,
107    being more powerful, flexible, configurable and extensible.  Among
108    its many advantages over the older, more pedestrian work are
109    support for multiplexing (encapsulated metasearching), routing by
110    database name, authentication and authorization and serving local
111    files via HTTP.  Equally significant, its modular architecture
112    facilitites the creation of pluggable modules implementing further
113    functionality.
114   </para>
115   <para>
116    This manual will describe how to install Metaproxy
117    before giving an overview of its architecture, then discussing the
118    key concept of a filter in some depth and giving an overview of
119    the various filter types, then discussing the configuration file
120    format.  After this come several optional chapters which may be
121    freely skipped: a detailed discussion of virtual databases and
122    multi-database searching, some notes on writing extensions
123    (additional filter types) and a high-level description of the
124    source code.  Finally comes the reference guide, which contains
125    instructions for invoking the <command>metaproxy</command>
126    program, and detailed information on each type of filter,
127    including examples.
128   </para>
129  </chapter>
130
131  <chapter id="license">
132   <title>The Metaproxy License</title>
133   <orderedlist numeration="arabic">
134    <listitem>
135     <para>
136      You are allowed to download this software for evaluation purposes.
137      You can unpack it, build it, run it, see how it works and how it fits
138      your needs, all at zero cost.
139     </para>
140    </listitem>
141    <listitem>
142     <para>
143      You may NOT deploy the software.  For the purposes of this license,
144      deployment means running it for any purpose other than evaluation,
145      whether or not you or anyone else makes a profit from doing so.  If
146      you wish to deploy the software, you must first contact Index Data and
147      arrange to purchase a DEPLOYMENT LICENCE.  If you are unsure
148      whether or not your proposed use of the software constitutes
149      deployment, email us at <literal>info@indexdata.com</literal>
150      for clarification.
151     </para>
152    </listitem>
153    <listitem>
154     <para>
155      You may modify your copy of the software (fix bugs, add features)
156      if you need to.  We encourage you to send your changes back to us for
157      integration into the master copy, but you are not obliged to do so.  You
158       may NOT pass your changes on to any other party.
159     </para>
160    </listitem>
161    <listitem>
162     <para>
163      There is NO WARRANTY for this software, to the extent permitted by
164      applicable law.  We provide the software ``as is'' without warranty of
165      any kind, either expressed or implied, including, but not limited to, the
166      implied warranties of MERCHANTABILITY and FITNESS FOR A
167      PARTICULAR PURPOSE.  The entire risk as to the quality and
168      performance of the software is with you.  Should the software prove
169      defective, you assume the cost of all necessary servicing, repair or
170      correction.  In no event unless required by applicable law will we be
171      liable to you for damages, arising out of the use of the software,
172      including but not limited to loss of data or data being rendered
173      inaccurate.
174     </para>
175    </listitem>
176    <listitem>
177     <para>
178      All rights to the software are reserved by Index Data except where
179      this license explicitly says otherwise.
180     </para>
181    </listitem>
182   </orderedlist>
183  </chapter>
184  
185  <chapter id="installation">
186   <title>Installation</title>
187   <para>
188    Metaproxy depends on the following tools/libraries:
189    <variablelist>
190     <varlistentry><term><ulink url="&url.yazplusplus;">YAZ++</ulink></term>
191      <listitem>
192       <para>
193        This is a C++ library based on <ulink url="&url.yaz;">YAZ</ulink>.
194       </para>
195      </listitem>
196     </varlistentry>
197     <varlistentry><term><ulink url="&url.libxslt;">Libxslt</ulink></term>
198      <listitem>
199       <para>This is an XSLT processor - based on 
200        <ulink url="&url.libxml2;">Libxml2</ulink>. Both Libxml2 and
201        Libxslt must be installed with the development components
202        (header files, etc.) as well as the run-time libraries.
203       </para>
204      </listitem>
205     </varlistentry>
206     <varlistentry><term><ulink url="&url.boost;">Boost</ulink></term>
207      <listitem>
208       <para>
209        The popular C++ library. Initial versions of Metaproxy
210        was built with 1.33.0. Version 1.33.1 works too.
211       </para>
212      </listitem>
213     </varlistentry>
214    </variablelist>
215   </para>
216   <para>
217    In order to compile Metaproxy a modern C++ compiler is
218    required. Boost, in particular, requires the C++ compiler
219    to facilitate the newest features. Refer to Boost
220    <ulink url="&url.boost.compilers.status;">Compiler Status</ulink>
221    for more information.
222   </para>
223   <para>
224    We have successfully built Metaproxy using the compilers
225    <ulink url="&url.gcc;">GCC</ulink> version 4.0 and
226    <ulink url="&url.vstudio;">Microsoft Visual Studio</ulink> 2003/2005.
227   </para>
228
229   <section id="installation.unix">
230    <title>Installation on Unix (from Source)</title>
231    <para>
232     Here is a quick step-by-step guide on how to compile all the
233     tools that Metaproxy uses. Only few systems have none of the required
234     tools binary packages. If, for example, Libxml2/libxslt are already
235     installed as development packages use those (and omit compilation).
236    </para>
237    
238    <para>
239     Libxml2/libxslt:
240    </para>
241    <screen>
242     gunzip -c libxml2-version.tar.gz|tar xf -
243     cd libxml2-version
244     ./configure
245     make
246     su
247     make install
248    </screen>
249    <screen>
250     gunzip -c libxslt-version.tar.gz|tar xf -
251     cd libxslt-version
252     ./configure
253     make
254     su
255     make install
256    </screen>
257    <para>
258     YAZ/YAZ++:
259    </para>
260    <screen>
261     gunzip -c yaz-version.tar.gz|tar xf -
262     cd yaz-version
263     ./configure
264     make
265     su
266     make install
267    </screen>
268    <screen>
269     gunzip -c yazpp-version.tar.gz|tar xf -
270     cd yazpp-version
271     ./configure
272     make
273     su
274     make install
275    </screen>
276    <para>
277     Boost:
278    </para>
279    <screen>
280     gunzip -c boost-version.tar.gz|tar xf -
281     cd boost-version
282     ./configure
283     make
284     su
285     make install
286    </screen>
287    <para>
288     Metaproxy:
289    </para>
290    <screen>
291     gunzip -c metaproxy-version.tar.gz|tar xf -
292     cd metaproxy-version
293     ./configure
294     make
295     su
296     make install
297    </screen>
298   </section>
299
300   <section id="installation.debian">
301    <title>Installation on Debian GNU/Linux</title>
302    <para>
303     All dependencies for Metaproxy are available as 
304     <ulink url="&url.debian;">Debian</ulink>
305     packages for the sarge (stable in 2005) and etch (testing in 2005)
306     distributions.
307    </para>
308    <para>
309     The procedures for Debian based systems, such as
310     <ulink url="&url.ubuntu;">Ubuntu</ulink> is probably similar
311    </para>
312    <para>
313     There is currently no official Debian package for YAZ++.
314     And the Debian package for YAZ is probably too old.
315     Update the <filename>/etc/apt/sources.list</filename>
316     to include the Index Data repository.
317     See YAZ' <ulink url="&url.yaz.download.debian;">Download Debian</ulink>
318     for more information.
319    </para>
320    <screen>
321     apt-get install libxslt1-dev
322     apt-get install libyazpp-dev
323     apt-get install libboost-dev
324     apt-get install libboost-thread-dev
325     apt-get install libboost-date-time-dev
326     apt-get install libboost-program-options-dev
327     apt-get install libboost-test-dev
328    </screen>
329    <para>
330     With these packages installed, the usual configure + make
331     procedure can be used for Metaproxy as outlined in
332     <xref linkend="installation.unix"/>.
333    </para>
334   </section>
335
336   <section id="installation.windows">
337    <title>Installation on Windows</title>
338    <para>
339     Metaproxy can be compiled with Microsoft
340     <ulink url="&url.vstudio;">Visual Studio</ulink>.
341     Version 2003 (C 7.1) and 2005 (C 8.0) is known to work.
342    </para>
343    <section id="installation.windows.boost">
344     <title>Boost</title>
345     <para>
346      Get Boost from its <ulink url="&url.boost;">home page</ulink>.
347      You also need Boost Jam (an alternative to make).
348      That's also available from the Boost home page.
349      The files to be downloaded are called something like:
350      <filename>boost_1_33-1.exe</filename>
351      and
352      <filename>boost-jam-3.1.12-1-ntx86.zip</filename>.
353      Unpack Boost Jam first. Put <filename>bjam.exe</filename>
354      in your system path. Make a command prompt and ensure
355      it can be found automatically. If not check the PATH.
356      The Boost .exe is a self-extracting exe with
357      complete source for Boost. Compile that source with
358      Boost Jam (An alternative to Make).
359      The compilation takes a while.
360      For Visual Studio 2003, use
361      <screen>
362       bjam "-sTOOLS=vc-7_1"
363      </screen>
364      Here <literal>vc-7_1</literal> refers to a "Toolset" (compiler system).
365      For Visual Studio 2005, use
366      <screen>
367       bjam "-sTOOLS=vc-8_0"
368      </screen>
369      To install the libraries in a common place, use
370      <screen>
371       bjam "-sTOOLS=vc-7_1" install
372      </screen>
373      (or vc-8_0 for VS 2005).
374     </para>
375     <para>
376      By default, the Boost build process installs the resulting
377      libraries + header files in
378      <literal>\boost\lib</literal>, <literal>\boost\include</literal>.
379     </para>
380     <para>
381      For more information about installing Boost refer to the
382      <ulink url="&url.boost.getting.started;">getting started</ulink>
383      pages.
384     </para>
385    </section>
386
387    <section id="installation.windows.libxslt">
388     <title>Libxslt</title>
389     <para>
390      <ulink url="&url.libxslt;">Libxslt</ulink> can be downloaded
391      for Windows from
392      <ulink url="&url.libxml2.download.win32;">here</ulink>.
393     </para>
394     <para>
395      Libxslt has other dependencies, but these can all be downloaded
396      from the same site. Get the following:
397      iconv, zlib, libxml2, libxslt.
398     </para>
399    </section>
400
401    <section id="installation.windows.yaz">
402     <title>YAZ</title>
403     <para>
404      <ulink url="&url.yaz;">YAZ</ulink> can be downloaded
405      for Windows from
406      <ulink url="&url.yaz.download.win32;">here</ulink>.
407     </para>
408    </section>
409
410    <section id="installation.windows.yazplusplus">
411     <title>YAZ++</title>
412     <para>
413      Get <ulink url="&url.yazplusplus;">YAZ++</ulink> as well.
414      Version 1.0 or later is required. For now get it from
415      Index Data's
416      <ulink url="&url.snapshot.download;">Snapshot area</ulink>.
417     </para>
418     <para>
419      YAZ++ includes NMAKE makefiles, similar to those found in the
420      YAZ package.
421     </para>
422    </section>
423
424    <section id="installation.windows.metaproxy">
425     <title>Metaproxy</title>
426     <para>
427      Metaproxy is shipped with NMAKE makefiles as well - similar
428      to those found in the YAZ++/YAZ packages. Adjust this Makefile
429      to point to the proper locations of Boost, Libxslt, Libxml2,
430      zlib, iconv, yaz and yazpp.
431     </para>
432
433     <variablelist>
434      <varlistentry><term><literal>DEBUG</literal></term>
435       <listitem><para>
436         If set to 1, the software is
437         compiled with debugging libraries (code generation is
438         multi-threaded debug DLL).
439         If set to 0, the software is compiled with release libraries
440         (code generation is multi-threaded DLL).
441        </para></listitem>
442      </varlistentry>
443
444      <varlistentry>
445       <term><literal>BOOST</literal></term>
446       <listitem>
447        <para>
448         Boost install location
449        </para>
450       </listitem>
451      </varlistentry>
452
453      <varlistentry>
454       <term><literal>BOOST_VERSION</literal></term>
455       <listitem>
456        <para>
457         Boost version (replace . with _).
458        </para>
459       </listitem>
460      </varlistentry>
461
462      <varlistentry>
463       <term><literal>BOOST_TOOLSET</literal></term>
464       <listitem>
465        <para>
466         Boost toolset.
467        </para>
468       </listitem>
469      </varlistentry>
470
471      <varlistentry>
472       <term><literal>LIBXSLT_DIR</literal>,
473        <literal>LIBXML2_DIR</literal> ..</term>
474       <listitem>
475        <para>
476         Specify the locations of Libxslt, libiconv, libxml2 and
477         libxslt.
478        </para>
479       </listitem>
480      </varlistentry>
481       
482     </variablelist>
483     
484     <para>
485      After successful compilation you'll find
486      <literal>metaproxy.exe</literal> in the
487      <literal>bin</literal> directory.
488     </para>
489    </section>
490
491
492   </section>
493  </chapter>
494  
495  <chapter id="architecture">
496   <title>The Metaproxy Architecture</title>
497   <para>
498    The Metaproxy architecture is based on three concepts:
499    the <emphasis>package</emphasis>,
500    the <emphasis>route</emphasis>
501    and the <emphasis>filter</emphasis>.
502   </para>
503   <variablelist>
504    <varlistentry>
505     <term>Packages</term>
506     <listitem>
507      <para>
508       A package is request or response, encoded in some protocol,
509       issued by a client, making its way through Metaproxy, send to or
510       received from a server, or sent back to the client.
511      </para>
512      <para>
513       The core of a package is the protocol unit - for example, a
514       Z39.50 Init Request or Search Response, or an SRU searchRetrieve
515       URL or Explain Response.  In addition to this core, a package
516       also carries some extra information added and used by Metaproxy
517       itself.
518      </para>
519      <para>
520       In general, packages are doctored as they pass through
521       Metaproxy.  For example, when the proxy performs authentication
522       and authorization on a Z39.50 Init request, it removes the
523       authentication credentials from the package so that they are not
524       passed onto the back-end server; and when search-response
525       packages are obtained from multiple servers, they are merged
526       into a single unified package that makes its way back to the
527       client.
528      </para>
529     </listitem>
530    </varlistentry>
531    <varlistentry>
532     <term>Routes</term>
533     <listitem>
534      <para>
535       Packages make their way through routes, which can be thought of
536       as programs that operate on the package data-type.  Each
537       incoming package initially makes its way through a default
538       route, but may be switched to a different route based on various
539       considerations.  Routes are made up of sequences of filters (see
540       below).
541      </para>
542     </listitem>
543    </varlistentry>
544    <varlistentry>
545     <term>Filters</term>
546     <listitem>
547      <para>
548       Filters provide the individual instructions within a route, and
549       effect the necessary transformations on packages.  A particular
550       configuration of Metaproxy is essentially a set of filters,
551       described by configuration details and arranged in order in one
552       or more routes.  There are many kinds of filter - about a dozen
553       at the time of writing with more appearing all the time - each
554       performing a specific function and configured by different
555       information.
556      </para>
557      <para>
558       The word ``filter'' is sometimes used rather loosely, in two
559       different ways: it may be used to mean a particular
560       <emphasis>type</emphasis> of filter, as when we speak of ``the
561       auth_simple filter'' or ``the multi filter''; or it may be used
562       to be a specific <emphasis>instance</emphasis> of a filter
563       within a Metaproxy configuration.  For example, a single
564       configuration will often contain multiple instances of the
565       <literal>z3950_client</literal> filter.  In
566       operational terms, of these is a separate filter.  In practice,
567       context always make it clear which sense of the word ``filter''
568       is being used.
569      </para>
570      <para>
571       Extensibility of Metaproxy is primarily through the creation of
572       plugins that provide new filters.  The filter API is small and
573       conceptually simple, but there are many details to master.  See
574       the section below on
575       <link linkend="extensions">extensions</link>.
576      </para>
577     </listitem>
578    </varlistentry>
579   </variablelist>
580   <para>
581    Since packages are created and handled by the system itself, and
582    routes are conceptually simple, most of the remainder of this
583    document concentrates on filters.  After a brief overview of the
584    filter types follows, along with some thoughts on possible future
585    directions.
586   </para>
587  </chapter>
588
589
590
591  <chapter id="filters">
592   <title>Filters</title>
593   
594   
595   <section>
596    <title>Introductory notes</title>
597    <para>
598     It's useful to think of Metaproxy as an interpreter providing a small
599     number of primitives and operations, but operating on a very
600     complex data type, namely the ``package''.
601    </para>
602    <para>
603     A package represents a Z39.50 or SRU/W request (whether for Init,
604     Search, Scan, etc.)  together with information about where it came
605     from.  Packages are created by front-end filters such as
606     <literal>frontend_net</literal> (see below), which reads them from
607     the network; other front-end filters are possible.  They then pass
608     along a route consisting of a sequence of filters, each of which
609     transforms the package and may also have side-effects such as
610     generating logging.  Eventually, the route will yield a response,
611     which is sent back to the origin.
612    </para>
613    <para>
614     There are many kinds of filter: some that are defined statically
615     as part of Metaproxy, and others may be provided by third parties
616     and dynamically loaded.  They all conform to the same simple API
617     of essentially two methods: <function>configure()</function> is
618     called at startup time, and is passed an XML DOM tree representing that
619     part of the configuration file that pertains to this filter
620     instance: it is expected to walk that tree extracting relevant
621     information; and <function>process()</function> is called every
622     time the filter has to processes a package.
623    </para>
624    <para>
625     While all filters provide the same API, there are different modes
626     of functionality.  Some filters are sources: they create
627     packages
628     (<literal>frontend_net</literal>);
629     others are sinks: they consume packages and return a result
630     (<literal>z3950_client</literal>,
631     <literal>backend_test</literal>,
632     <literal>bounce</literal>,
633     <literal>http_file</literal>);
634     the others are true filters, that read, process and pass on the
635     packages they are fed
636     (<literal>auth_simple</literal>,
637     <literal>log</literal>,
638     <literal>multi</literal>,
639     <literal>query_rewrite</literal>,
640     <literal>record_transform</literal>,
641     <literal>session_shared</literal>,
642     <literal>sru_z3950</literal>,
643     <literal>template</literal>,
644     <literal>virt_db</literal>).
645    </para>
646  </section>
647   
648   
649   <section id="overview.filter.types">
650    <title>Overview of filter types</title>
651    <para>
652     We now briefly consider each of the types of filter supported by
653     the core Metaproxy binary.  This overview is intended to give a
654     flavor of the available functionality; more detailed information
655     about each type of filter is included below in
656     <link linkend="filterref"
657           >the reference guide to Metaproxy filters</link>.
658    </para>
659    <para>
660     The filters are here named by the string that is used as the
661     <literal>type</literal> attribute of a
662     <literal>&lt;filter&gt;</literal> element in the configuration
663     file to request them, with the name of the class that implements
664     them in parentheses.  (The classname is not needed for normal
665     configuration and use of Metaproxy; it is useful only to
666     developers.)
667    </para>
668    <para>
669     The filters are here listed in alphabetical order:
670    </para>
671    
672 <!--
673
674 ### New filters:
675
676 New virt_db-alike that does inteligent peer choice, explain merging,
677 adds FD&N to explain.  Keeps init responses (like "virt_db Classic"),
678 makes routing choices based on local explain knowledge.  Ref IDDI
679 paper.
680
681 Filter to convert Explain Classic to ZeeRex.
682
683 CQL2PQF (which needs augmented ZeeRex) - MARC for Talis.
684
685 SRU2Z39.50 (ditto).
686
687 Figure out what additional information we need in:
688         ZeeRex (check against D3.1)
689         Init request (e.g. loop detection)
690         Query package (e.g. number of hops)
691         Query response (e.g. record source)
692
693 -->
694
695    <section>
696     <title><literal>auth_simple</literal>
697      (mp::filter::AuthSimple)</title>
698     <para>
699      Simple authentication and authorization.  The configuration
700      specifies the name of a file that is the user register, which
701      lists <varname>username</varname>:<varname>password</varname>
702      pairs, one per line, colon separated. When a session begins, it
703      is rejected unless username and passsword are supplied, and match
704      a pair in the register.  The configuration file may also specific
705      the name of another file that is the target register: this lists
706      lists <varname>username</varname>:<varname>dbname</varname>,<varname>dbname</varname>...
707      sets, one per line, with multiple database names separated by
708      commas.  When a search is processed, it is rejected unless the
709      database to be searched is one of those listed as available to
710      the user.
711     </para>
712    </section>
713    
714    <section>
715     <title><literal>backend_test</literal>
716     (mp::filter::Backend_test)</title>
717     <para>
718      A partial sink that provides dummy responses in the manner of the
719      <literal>yaz-ztest</literal> Z39.50 server.  This is useful only
720      for testing.  Seriously, you don't need this.  Pretend you didn't
721      even read this section.
722     </para>
723    </section>
724    
725    <section>
726     <title><literal>bounce</literal>
727     (mp::filter::Bounce)</title>
728     <para>
729      A sink that swallows <emphasis>all packages</emphasis>, 
730      and returns them almost unprocessed.
731      It never sends any package of any type further down the row, but
732      sets Z39.50 packages to Z_Close, and HTTP_Request packages to
733      HTTP_Response err code 400 packages, and adds a suitable bounce
734      message. 
735      The bounce filter is usually added at end of each filter chain
736      config.xml to prevent infinite hanging of for example HTTP
737      requests packages when only the Z39.50 client partial sink 
738      filter is found in the
739      route.  
740     </para>
741    </section>
742    
743    <section>
744     <title><literal>frontend_net</literal>
745      (mp::filter::FrontendNet)</title>
746     <para>
747      A source that accepts Z39.50 connections from a port
748      specified in the configuration, reads protocol units, and
749      feeds them into the next filter in the route.  When the result is
750      received, it is returned to the original origin.
751     </para>
752    </section>
753
754    <section>
755     <title><literal>http_file</literal>
756      (mp::filter::HttpFile)</title>
757     <para>
758      A partial sink which swallows only HTTP_Request packages, and 
759      returns the contents of files from the local
760      filesystem in response to HTTP requests.  
761      It lets Z39.50 packages and all other forthcoming package types
762      pass untouched. 
763      (Yes, Virginia, this
764      does mean that Metaproxy is also a Web-server in its spare time.  So
765      far it does not contain either an email-reader or a Lisp
766      interpreter, but that day is surely coming.)
767     </para>
768    </section>
769    
770    <section>
771     <title><literal>log</literal>
772      (mp::filter::Log)</title>
773     <para>
774      Writes logging information to standard output, and passes on
775      the package unchanged. A log file name can be specified, as well
776      as multiple different logging formats.
777    </para>
778    </section>
779    
780    <section>
781     <title><literal>load_balance</literal>
782      (mp::filter::LoadBalance)</title>
783     <para>
784      Performs load balancing for incoming Z39.50 init requests.
785      It is used together with the <literal>virt_db</literal> filter,
786      but unlike the <literal>multi</literal> filter it does send an
787      entire session to only one of the virtual backends. The 
788      <literal>load_balance</literal> filter is assuming that
789      all backend targets have equal content, and chooses the backend
790      with least load cost for a new session.
791    </para>
792    </section>
793    
794    <section>
795    <title><literal>multi</literal>
796      (mp::filter::Multi)</title>
797     <para>
798      Performs multi-database searching.
799      See
800      <link linkend="multidb">the extended discussion</link>
801      of virtual databases and multi-database searching below.
802     </para>
803    </section>
804    
805    <section>
806    <title><literal>query_rewrite</literal>
807      (mp::filter::QueryRewrite)</title>
808     <para>
809      Rewrites Z39.50 Type-1 and Type-101 (``RPN'') queries by a
810      three-step process: the query is transliterated from Z39.50
811      packet structures into an XML representation; that XML
812      representation is transformed by an XSLT stylesheet; and the
813      resulting XML is transliterated back into the Z39.50 packet
814      structure.
815     </para>
816    </section>
817    
818    
819    <section>
820     <title><literal>record_transform</literal>
821     (mp::filter::RecordTransform)</title>
822     <para>
823      This filter acts only on Z3950 present requests, and let all
824      other types of packages and requests pass untouched. It's use is
825      twofold: blocking Z3950  present requests, which the backend
826      server does not understand and can not honor, and transforming
827      the present syntax and elementset name according to the rules
828      specified, to fetch only existing record formats, and transform
829      them on the fly to requested record syntaxes.
830     </para>
831    </section>
832
833    <section>
834     <title><literal>session_shared</literal>
835      (mp::filter::SessionShared)</title>
836     <para>
837      When this is finished, it will implement global sharing of
838      result sets (i.e. between threads and therefore between
839      clients), yielding performance improvements especially when
840      incoming requests are from a stateless environment such as a
841      web-server, in which the client process representing a session
842      might be any one of many.  However:
843     </para>
844     <warning>
845      <para>
846       This filter is not yet completed.
847      </para>
848     </warning>
849    </section>
850
851    <section>
852     <title><literal>sru_z3950</literal>
853     (mp::filter::SRUtoZ3950)</title>
854     <para>
855      This filter transforms valid
856      SRU/GET or SRU/SOAP requests to Z3950 requests, and wraps the
857      received hit counts and XML records into suitable SRU response messages.
858     </para>
859    </section>
860    
861    <section>
862     <title><literal>template</literal>
863      (mp::filter::Template)</title>
864     <para>
865      Does nothing at all, merely passing the packet on.  (Maybe it
866      should be called <literal>nop</literal> or
867      <literal>passthrough</literal>?)  This exists not to be used, but
868      to be copied - to become the skeleton of new filters as they are
869      written.  As with <literal>backend_test</literal>, this is not
870      intended for civilians.
871     </para>
872    </section>
873    
874    <section>
875     <title><literal>virt_db</literal>
876      (mp::filter::VirtualDB)</title>
877     <para>
878      Performs virtual database selection: based on the name of the
879      database in the search request, a server is selected, and its
880      address added to the request in a <literal>VAL_PROXY</literal>
881      otherInfo packet.  It will subsequently be used by a
882      <literal>z3950_client</literal> filter.
883      See
884      <link linkend="multidb">the extended discussion</link>
885      of virtual databases and multi-database searching below.
886     </para>
887    </section>
888    
889    <section>
890     <title><literal>z3950_client</literal>
891      (mp::filter::Z3950Client)</title>
892     <para>
893      A partial sink which swallows only Z39.50 packages.
894      It performs Z39.50 searching and retrieval by proxying the
895      packages that are passed to it.  Init requests are sent to the
896      address specified in the <literal>VAL_PROXY</literal> otherInfo
897      attached to the request: this may have been specified by client,
898      or generated by a <literal>virt_db</literal> filter earlier in
899      the route.  Subsequent requests are sent to the same address,
900      which is remembered at Init time in a Session object.
901      HTTP_Request packages and all other forthcoming package types
902      are passed untouched. 
903     </para>
904   </section>
905   </section>
906   
907   
908   <section id="future.directions">
909    <title>Future directions</title>
910   <para>
911     Some other filters that do not yet exist, but which would be
912     useful, are briefly described.  These may be added in future
913     releases (or may be created by third parties, as loadable
914     modules).
915    </para>
916
917    <variablelist>
918     <varlistentry>
919      <term><literal>frontend_cli</literal> (source)</term>
920     <listitem>
921       <para>
922        Command-line interface for generating requests.
923       </para>
924      </listitem>
925     </varlistentry>
926     <varlistentry>
927      <term><literal>sru_client</literal> (sink)</term>
928      <listitem>
929       <para>
930        SRU/GET and SRU/SOAP searching and retrieval.
931       </para>
932      </listitem>
933     </varlistentry>
934     <varlistentry>
935      <term><literal>opensearch_client</literal> (sink)</term>
936      <listitem>
937       <para>
938        A9 OpenSearch searching and retrieval.
939       </para>
940      </listitem>
941     </varlistentry>
942    </variablelist>
943   </section>
944  </chapter>
945  
946  
947  
948  <chapter id="configuration">
949   <title>Configuration: the Metaproxy configuration file format</title>
950   
951   
952   <section>
953    <title>Introductory notes</title>
954    <para>
955     If Metaproxy is an interpreter providing operations on packages, then
956     its configuration file can be thought of as a program for that
957     interpreter.  Configuration is by means of a single file, the name
958     of which is supplied as the sole command-line argument to the
959     <command>metaproxy</command> program.  (See
960     <link linkend="progref">the reference guide</link>
961     below for more information on invoking Metaproxy.)
962    </para>
963    <para>
964     The configuration files are written in XML.  (But that's just an
965     implementation detail - they could just as well have been written
966     in YAML or Lisp-like S-expressions, or in a custom syntax.)
967    </para>
968   </section>
969   
970   <section id="overview.xml.structure">
971    <title>Overview of the config file XML structure</title>
972    <para>
973     All elements and attributes are in the namespace
974     <ulink url="http://indexdata.com/metaproxy"/>.
975      This is most easily achieved by setting the default namespace on
976      the top-level element, as here:
977    </para>
978    <screen>
979     &lt;metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0"&gt;
980    </screen>
981    <para>
982     The top-level element is &lt;metaproxy&gt;.  This contains a
983     &lt;start&gt; element, a &lt;filters&gt; element and a
984     &lt;routes&gt; element, in that order.  &lt;filters&gt; is
985     optional; the other two are mandatory.  All three are
986     non-repeatable.
987    </para>
988   <para>
989     The &lt;start&gt; element is empty, but carries a
990     <literal>route</literal> attribute, whose value is the name of
991     route at which to start running - analogous to the name of the
992     start production in a formal grammar.
993    </para>
994   <para>
995     If present, &lt;filters&gt; contains zero or more &lt;filter&gt;
996     elements.  Each filter carries a <literal>type</literal> attribute
997     which specifies what kind of filter is being defined
998     (<literal>frontend_net</literal>, <literal>log</literal>, etc.)
999     and contain various elements that provide suitable configuration
1000     for a filter of its type.  The filter-specific elements are
1001     described in
1002     <link linkend="filterref">the reference guide below</link>.
1003     Filters defined in this part of the file must carry an
1004     <literal>id</literal> attribute so that they can be referenced
1005     from elsewhere.
1006    </para>
1007    <para>
1008     &lt;routes&gt; contains one or more &lt;route&gt; elements, each
1009     of which must carry an <literal>id</literal> element.  One of the
1010     routes must have the ID value that was specified as the start
1011     route in the &lt;start&gt; element's <literal>route</literal>
1012     attribute.  Each route contains zero or more &lt;filter&gt;
1013     elements.  These are of two types.  They may be empty, but carry a
1014     <literal>refid</literal> attribute whose value is the same as the
1015     <literal>id</literal> of a filter previously defined in the
1016     &lt;filters&gt; section.  Alternatively, a route within a filter
1017     may omit the <literal>refid</literal> attribute, but contain
1018     configuration elements similar to those used for filters defined
1019     in the &lt;filters&gt; section.  (In other words, each filter in a
1020     route may be included either by reference or by physical
1021     inclusion.)
1022    </para>
1023   </section>
1024
1025
1026   <section id="example.configuration">
1027    <title>An example configuration</title>
1028    <para>
1029     The following is a small, but complete, Metaproxy configuration
1030     file (included in the distribution as
1031     <literal>metaproxy/etc/config1.xml</literal>).
1032     This file defines a very simple configuration that simply proxies
1033     to whatever back-end server the client requests, but logs each
1034     request and response.  This can be useful for debugging complex
1035     client-server dialogues.
1036    </para>
1037    <screen><![CDATA[<?xml version="1.0"?>
1038 <metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0">
1039   <start route="start"/>
1040   <filters>
1041     <filter id="frontend" type="frontend_net">
1042       <port>@:9000</port>
1043     </filter>
1044     <filter id="backend" type="z3950_client">
1045     </filter>
1046   </filters>
1047   <routes>  
1048     <route id="start">
1049       <filter refid="frontend"/>
1050       <filter type="log"/>
1051       <filter refid="backend"/>
1052       <filter type="bounce"/>
1053     </route>
1054   </routes>
1055 </metaproxy>
1056 ]]></screen>
1057    <para>
1058     It works by defining a single route, called
1059     <literal>start</literal>, which consists of a sequence of four
1060     filters.  The first and last of these are included by reference:
1061     their <literal>&lt;filter&gt;</literal> elements have
1062     <literal>refid</literal> attributes that refer to filters defined
1063     within the prior <literal>&lt;filters&gt;</literal> section.  The
1064     middle filter is included inline in the route.
1065    </para>
1066    <para>
1067     The four filters in the route are as follows: first, a
1068     <literal>frontend_net</literal> filter accepts Z39.50 requests
1069     from any host on port 9000; then these requests are passed through
1070     a <literal>log</literal> filter that emits a message for each
1071     request; they are then fed into a <literal>z3950_client</literal>
1072     filter, which forwards all Z39.50 requests to the client-specified
1073     back-end Z39.509 server. Those Z39.50 packages are returned by the
1074     <literal>z3950_client</literal> filter, with the response data
1075     filled by the external Z39.50 server targeted.
1076     All non-Z39.50 packages are passed through to the
1077     <literal>bounce</literal> filter, which definitely bounces
1078     everything, including fish, bananas, cold pyjamas,
1079     mutton, beef and trout packages.
1080     When the response arrives, it is handed
1081     back to the <literal>log</literal> filter, which emits another
1082     message; and then to the <literal>frontend_net</literal> filter, 
1083     which returns the response to the client.
1084    </para>
1085   </section>
1086   <section id="checking.xml.syntax">
1087    <title>Config file syntax checking</title>
1088    <para>
1089     The distribution contains RelaxNG Compact and XML syntax checking
1090     files, as well as XML Schema files. These are found in the
1091     distribution paths 
1092    <screen>
1093     xml/schema/metaproxy.rnc
1094     xml/schema/metaproxy.rng
1095     xml/schema/metaproxy.xsd
1096    </screen>
1097     and can be used to verify or debug the XML structure of
1098     configuration files. For example, using the utility
1099     <filename>xmllint</filename>, syntax checking is done like this:
1100    <screen>
1101     xmllint --noout --schema xml/schema/metaproxy.xsd etc/config-local.xml 
1102     xmllint --noout --relaxng xml/schema/metaproxy.rng etc/config-local.xml 
1103    </screen>
1104     (A recent version of <literal>libxml2</literal> is required, as
1105     support for XML Schemas is a relatively recent addition.)
1106    </para>
1107    <para>
1108     You can of course use any other RelaxNG or XML Schema compliant tool
1109     you wish.
1110    </para>
1111    </section>
1112  </chapter>
1113
1114
1115
1116  <chapter id="multidb">
1117   <title>Virtual databases and multi-database searching</title>
1118
1119
1120   <section>
1121    <title>Introductory notes</title>
1122    <para>
1123     Two of Metaproxy's filters are concerned with multiple-database
1124     operations.  Of these, <literal>virt_db</literal> can work alone
1125     to control the routing of searches to one of a number of servers,
1126     while <literal>multi</literal> can work together with
1127     <literal>virt_db</literal> to perform multi-database searching, merging
1128     the results into a unified result-set - ``metasearch in a box''.
1129    </para>
1130    <para>
1131     The interaction between
1132     these two filters is necessarily complex: it reflects the real,
1133     irreducible complexity of multi-database searching in a protocol such
1134     as Z39.50 that separates initialization from searching, and in
1135     which the database to be searched is not known at initialization
1136     time.
1137    </para>
1138    <para>
1139     It's possible to use these filters without understanding the
1140     details of their functioning and the interaction between them; the
1141     next two sections of this chapter are ``HOW-TO'' guides for doing
1142     just that.  However, debugging complex configurations will require
1143     a deeper understanding, which the last two sections of this
1144     chapters attempt to provide.
1145    </para>
1146   </section>
1147
1148
1149   <section id="multidb.virt_db">
1150    <title>Virtual databases with the <literal>virt_db</literal> filter</title>
1151    <para>
1152     Working alone, the purpose of the
1153     <literal>virt_db</literal>
1154     filter is to route search requests to one of a selection of
1155     back-end databases.  In this way, a single Z39.50 endpoint
1156     (running Metaproxy) can provide access to several different
1157     underlying services, including those that would otherwise be
1158     inaccessible due to firewalls.  In many useful configurations, the
1159     back-end databases are local to the Metaproxy installation, but
1160     the software does not enforce this, and any valid Z39.50 servers
1161     may be used as back-ends.
1162    </para>
1163    <para>
1164     For example, a <literal>virt_db</literal>
1165     filter could be set up so that searches in the virtual database
1166     ``lc'' are forwarded to the Library of Congress bibliographic
1167     catalogue server, and searches in the virtual database ``marc''
1168     are forwarded to the toy database of MARC records that Index Data
1169     hosts for testing purposes.  A <literal>virt_db</literal>
1170     configuration to make this switch would look like this:
1171    </para>
1172    <screen><![CDATA[<filter type="virt_db">
1173   <virtual>
1174     <database>lc</database>
1175     <target>z3950.loc.gov:7090/voyager</target>
1176   </virtual>
1177   <virtual>
1178     <database>marc</database>
1179     <target>indexdata.com/marc</target>
1180   </virtual>
1181 </filter>]]></screen>
1182    <para>
1183     As well as being useful in it own right, this filter also provides
1184     the foundation for multi-database searching.
1185    </para>
1186   </section>
1187
1188
1189   <section id="multidb.multi">
1190    <title>Multi-database search with the <literal>multi</literal> filter</title>
1191    <para>
1192     To arrange for Metaproxy to broadcast searches to multiple back-end
1193     servers, the configuration needs to include two components: a
1194     <literal>virt_db</literal>
1195     filter that specifies multiple
1196     <literal>&lt;target&gt;</literal>
1197     elements, and a subsequent
1198     <literal>multi</literal>
1199     filter.  Here, for example, is a complete configuration that
1200     broadcasts searches to both the Library of Congress catalogue and
1201     Index Data's tiny testing database of MARC records:
1202    </para>
1203    <screen><![CDATA[<?xml version="1.0"?>
1204 <metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0">
1205   <start route="start"/>
1206   <routes>
1207     <route id="start">
1208       <filter type="frontend_net">
1209         <threads>10</threads>
1210         <port>@:9000</port>
1211       </filter>
1212       <filter type="virt_db">
1213         <virtual>
1214           <database>lc</database>
1215           <target>z3950.loc.gov:7090/voyager</target>
1216         </virtual>
1217         <virtual>
1218           <database>marc</database>
1219           <target>indexdata.com/marc</target>
1220         </virtual>
1221         <virtual>
1222           <database>all</database>
1223           <target>z3950.loc.gov:7090/voyager</target>
1224           <target>indexdata.com/marc</target>
1225         </virtual>
1226       </filter>
1227       <filter type="multi"/>
1228       <filter type="z3950_client">
1229         <timeout>30</timeout>
1230       </filter>
1231       <filter type="bounce"/>
1232     </route>
1233   </routes>
1234 </metaproxy>]]></screen>
1235    <para>
1236     (Using a
1237     <literal>virt_db</literal>
1238     filter that specifies multiple
1239     <literal>&lt;target&gt;</literal>
1240     elements but without a subsequent
1241     <literal>multi</literal>
1242     filter yields surprising and undesirable results, as will be
1243     described below.  Don't do that.)
1244    </para>
1245    <para>
1246     Metaproxy can be invoked with this configuration as follows:
1247    </para>
1248    <screen>../src/metaproxy --config config-simple-multi.xml</screen>
1249    <para>
1250     And thereafter, Z39.50 clients can connect to the running server
1251     (on port 9000, as specified in the configuration) and search in
1252     any of the databases
1253     <literal>lc</literal> (the Library of Congress catalogue),
1254     <literal>marc</literal> (Index Data's test database of MARC records)
1255     or
1256     <literal>all</literal> (both of these).  As an example, a session
1257     using the YAZ command-line client <literal>yaz-client</literal> is
1258     here included (edited for brevity and clarity):
1259    </para>
1260    <screen><![CDATA[$ yaz-client @:9000
1261 Connecting...OK.
1262 Z> base lc
1263 Z> find computer
1264 Search was a success.
1265 Number of hits: 10000, setno 1
1266 Elapsed: 5.521070
1267 Z> base marc
1268 Z> find computer
1269 Search was a success.
1270 Number of hits: 10, setno 3
1271 Elapsed: 0.060187
1272 Z> base all
1273 Z> find computer
1274 Search was a success.
1275 Number of hits: 10010, setno 4
1276 Elapsed: 2.237648
1277 Z> show 1
1278 [marc]Record type: USmarc
1279 001    11224466
1280 003 DLC
1281 005 00000000000000.0
1282 008 910710c19910701nju           00010 eng
1283 010    $a 11224466
1284 040    $a DLC $c DLC
1285 050 00 $a 123-xyz
1286 100 10 $a Jack Collins
1287 245 10 $a How to program a computer
1288 260 1  $a Penguin
1289 263    $a 8710
1290 300    $a p. cm.
1291 Elapsed: 0.119612
1292 Z> show 2
1293 [VOYAGER]Record type: USmarc
1294 001 13339105
1295 005 20041229102447.0
1296 008 030910s2004    caua          000 0 eng
1297 035    $a (DLC)  2003112666
1298 906    $a 7 $b cbc $c orignew $d 4 $e epcn $f 20 $g y-gencatlg
1299 925 0  $a acquire $b 1 shelf copy $x policy default
1300 955    $a pc10 2003-09-10 $a pv12 2004-06-23 to SSCD; $h sj05 2004-11-30 $e sj05 2004-11-30 to Shelf.
1301 010    $a   2003112666
1302 020    $a 0761542892
1303 040    $a DLC $c DLC $d DLC
1304 050 00 $a MLCM 2004/03312 (G)
1305 245 10 $a 007, everything or nothing : $b Prima's official strategy guide / $c created by Kaizen Media Group.
1306 246 3  $a Double-O-seven, everything or nothing
1307 246 30 $a Prima's official strategy guide
1308 260    $a Roseville, CA : $b Prima Games, $c c2004.
1309 300    $a 161 p. : $b col. ill. ; $c 28 cm.
1310 500    $a "Platforms: Nintendo GameCube, Macintosh, PC, PlayStation 2 computer entertainment system, Xbox"--P. [4] of cover.
1311 650  0 $a Video games.
1312 710 2  $a Kaizen Media Group.
1313 856 42 $3 Publisher description $u http://www.loc.gov/catdir/description/random052/2003112666.html
1314 Elapsed: 0.150623
1315 Z>
1316 ]]></screen>
1317    <para>
1318     As can be seen, the first record in the result set is from the
1319     Index Data test database, and the second from the Library of
1320     Congress database.  The result-set continues alternating records
1321     round-robin style until the point where one of the databases'
1322     records are exhausted.
1323    </para>
1324    <para>
1325     This example uses only two back-end databases; more may be used.
1326     There is no limitation imposed on the number of databases that may
1327     be metasearched in this way: issues of resource usage and
1328     administrative complexity dictate the practical limits.
1329    </para>
1330    <para>
1331     What happens when one of the databases doesn't respond?  By default,
1332     the entire multi-database search fails, and the appropriate
1333     diagnostic is returned to the client.  This is usually appropriate
1334     during development, when technicians need maximum information, but
1335     can be inconvenient in deployment, when users typically don't want
1336     to be bothered with problems of this kind and prefer just to get
1337     the records from the databases that are available.  To obtain this
1338     latter behavior add an empty
1339     <literal>&lt;hideunavailable&gt;</literal>
1340     element inside the
1341     <literal>multi</literal> filter:
1342    </para>
1343    <screen><![CDATA[      <filter type="multi">
1344         <hideunavailable/>
1345       </filter>]]></screen>
1346    <para>
1347     Under this regime, an error is reported to the client only if
1348     <emphasis>all</emphasis> the databases in a multi-database search
1349     are unavailable.
1350    </para>
1351   </section>
1352
1353
1354   <section id="multidb.what">
1355    <title>What's going on?</title>
1356    <warning>
1357     <title>Lark's vomit</title>
1358     <para>
1359      This section goes into a level of technical detail that is
1360      probably not necessary in order to configure and use Metaproxy.
1361      It is provided only for those who like to know how things work.
1362      You should feel free to skip on to the next section if this one
1363      doesn't seem like fun.
1364     </para>
1365    </warning>
1366    <para>
1367     Hold on tight - this may get a little hairy.
1368    </para>
1369    <para>
1370     In the general course of things, a Z39.50 Init request may carry
1371     with it an otherInfo packet of type <literal>VAL_PROXY</literal>,
1372     whose value indicates the address of a Z39.50 server to which the
1373     ultimate connection is to be made.  (This otherInfo packet is
1374     supported by YAZ-based Z39.50 clients and servers, but has not yet
1375     been ratified by the Maintenance Agency and so is not widely used
1376     in non-Index Data software.  We're working on it.)
1377     The <literal>VAL_PROXY</literal> packet functions
1378     analogously to the absoluteURI-style Request-URI used with the GET
1379     method when a web browser asks a proxy to forward its request: see
1380     the
1381     <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2"
1382            >Request-URI</ulink>
1383     section of
1384     <ulink url="http://www.w3.org/Protocols/rfc2616/rfc2616.html"
1385            >the HTTP 1.1 specification</ulink>.
1386    </para>
1387    <para>
1388     Within Metaproxy, Search requests that are part of the same
1389     session as an Init request that carries a
1390     <literal>VAL_PROXY</literal> otherInfo are also annotated with the
1391     same information.  The role of the <literal>virt_db</literal>
1392     filter is to rewrite this otherInfo packet dependent on the
1393     virtual database that the client wants to search.
1394    </para>
1395    <para>
1396     When Metaproxy receives a Z39.50 Init request from a client, it
1397     doesn't immediately forward that request to the back-end server.
1398     Why not?  Because it doesn't know <emphasis>which</emphasis>
1399     back-end server to forward it to until the client sends a Search
1400     request that specifies the database that it wants to search in.
1401     Instead, it just treasures the Init request up in its heart; and,
1402     later, the first time the client does a search on one of the
1403     specified virtual databases, a connection is forged to the
1404     appropriate server and the Init request is forwarded to it.  If,
1405     later in the session, the same client searches in a different
1406     virtual database, then a connection is forged to the server that
1407     hosts it, and the same cached Init request is forwarded there,
1408     too.
1409    </para>
1410    <para>
1411     All of this clever Init-delaying is done by the
1412     <literal>frontend_net</literal> filter.  The
1413     <literal>virt_db</literal> filter knows nothing about it; in
1414     fact, because the Init request that is received from the client
1415     doesn't get forwarded until a Search request is received, the
1416     <literal>virt_db</literal> filter (and the
1417     <literal>z3950_client</literal> filter behind it) doesn't even get
1418     invoked at Init time.  The <emphasis>only</emphasis> thing that a
1419     <literal>virt_db</literal> filter ever does is rewrite the
1420     <literal>VAL_PROXY</literal> otherInfo in the requests that pass
1421     through it.
1422    </para>
1423    <para>
1424     It is possible for a <literal>virt_db</literal> filter to contain
1425     multiple
1426     <literal>&lt;target&gt;</literal>
1427     elements.  What does this mean?  Only that the filter will add
1428     multiple <literal>VAL_PROXY</literal> otherInfo packets to the
1429     Search requests that pass through it.  That's because the virtual
1430     DB filter is dumb, and does exactly what it's told - no more, no
1431     less.
1432     If a Search request with multiple <literal>VAL_PROXY</literal>
1433     otherInfo packets reaches a <literal>z3950_client</literal>
1434     filter, this is an error.  That filter doesn't know how to deal
1435     with multiple targets, so it will either just pick one and search
1436     in it, or (better) fail with an error message.
1437    </para>
1438    <para>
1439     The <literal>multi</literal> filter comes to the rescue!  This is
1440     the only filter that knows how to deal with multiple
1441     <literal>VAL_PROXY</literal> otherInfo packets, and it does so by
1442     making multiple copies of the entire Search request: one for each
1443     <literal>VAL_PROXY</literal>.  Each of these new copies is then
1444     passed down through the remaining filters in the route.  (The
1445     copies are handled in parallel though the
1446     spawning of new threads.)  Since the copies each have only one
1447     <literal>VAL_PROXY</literal> otherInfo, they can be handled by the
1448     <literal>z3950_client</literal> filter, which happily deals with
1449     each one individually.  When the results of the individual
1450     searches come back up to the <literal>multi</literal> filter, it
1451     merges them into a single Search response, which is what
1452     eventually makes it back to the client.
1453    </para>
1454   </section>
1455
1456
1457   <section id="multidb.picture">
1458    <title>A picture is worth a thousand words (but only five hundred on 64-bit architectures)</title>
1459    <simpara>
1460     <inlinemediaobject>
1461      <imageobject>
1462       <imagedata fileref="multi.pdf" format="PDF" scale="50"/>
1463      </imageobject>
1464      <imageobject>
1465       <imagedata fileref="multi.png" format="PNG"/>
1466      </imageobject>
1467      <textobject>
1468       <!-- Fall back if none of the images can be used -->
1469       <phrase>
1470        [Here there should be a diagram showing the progress of
1471        packages through the filters during a simple virtual-database
1472        search and a multi-database search, but is seems that your
1473        tool chain has not been able to include the diagram in this
1474        document.]
1475       </phrase>
1476      </textobject>
1477 <!-- ### This used to work with an older version of DocBook
1478      <caption>
1479       <para>Caption: progress of packages through filters.</para>
1480      </caption>
1481 -->
1482     </inlinemediaobject>
1483    </simpara>
1484   </section>
1485  </chapter>
1486
1487
1488
1489  <chapter id="extensions">
1490   <title>Writing extensions for Metaproxy</title>
1491   <para>### To be written</para>
1492  </chapter>
1493
1494
1495
1496
1497  <chapter id="classes">
1498   <title>Classes in the Metaproxy source code</title>
1499
1500
1501   <section>
1502    <title>Introductory notes</title>
1503    <para>
1504     <emphasis>Stop!  Do not read this!</emphasis>
1505     You won't enjoy it at all.  You should just skip ahead to
1506     <link linkend="refguide">the reference guide</link>,
1507     which tells
1508     <!-- The remainder of this paragraph is lifted verbatim from
1509     Douglas Adams' _Hitch Hiker's Guide to the Galaxy_, chapter 8 -->
1510     you things you really need to know, like the fact that the
1511     fabulously beautiful planet Bethselamin is now so worried about
1512     the cumulative erosion by ten billion visiting tourists a year
1513     that any net imbalance between the amount you eat and the amount
1514     you excrete whilst on the planet is surgically removed from your
1515     bodyweight when you leave: so every time you go to the lavatory it
1516     is vitally important to get a receipt.
1517    </para>
1518    <para>
1519     This chapter contains documentation of the Metaproxy source code, and is
1520     of interest only to maintainers and developers.  If you need to
1521     change Metaproxy's behavior or write a new filter, then you will most
1522     likely find this chapter helpful.  Otherwise it's a waste of your
1523     good time.  Seriously: go and watch a film or something.
1524     <citetitle>This is Spinal Tap</citetitle> is particularly good.
1525    </para>
1526    <para>
1527     Still here?  OK, let's continue.
1528    </para>
1529    <para>
1530     In general, classes seem to be named big-endianly, so that
1531     <literal>FactoryFilter</literal> is not a filter that filters
1532     factories, but a factory that produces filters; and
1533     <literal>FactoryStatic</literal> is a factory for the statically
1534     registered filters (as opposed to those that are dynamically
1535     loaded).
1536    </para>
1537   </section>
1538
1539   <section id="individual.classes">
1540    <title>Individual classes</title>
1541    <para>
1542     The classes making up the Metaproxy application are here listed by
1543     class-name, with the names of the source files that define them in
1544     parentheses.
1545    </para>
1546
1547    <section>
1548     <title><literal>mp::FactoryFilter</literal>
1549      (<filename>factory_filter.cpp</filename>)</title>
1550     <para>
1551      A factory class that exists primarily to provide the
1552      <literal>create()</literal> method, which takes the name of a
1553      filter class as its argument and returns a new filter of that
1554      type.  To enable this, the factory must first be populated by
1555      calling <literal>add_creator()</literal> for static filters (this
1556      is done by the <literal>FactoryStatic</literal> class, see below)
1557      and <literal>add_creator_dyn()</literal> for filters loaded
1558      dynamically.
1559     </para>
1560    </section>
1561
1562    <section>
1563     <title><literal>mp::FactoryStatic</literal>
1564      (<filename>factory_static.cpp</filename>)</title>
1565     <para>
1566      A subclass of <literal>FactoryFilter</literal> which is
1567      responsible for registering all the statically defined filter
1568      types.  It does this by knowing about all those filters'
1569      structures, which are listed in its constructor.  Merely
1570      instantiating this class registers all the static classes.  It is
1571      for the benefit of this class that <literal>struct
1572       metaproxy_1_filter_struct</literal> exists, and that all the filter
1573      classes provide a static object of that type.
1574     </para>
1575    </section>
1576
1577    <section>
1578     <title><literal>mp::filter::Base</literal>
1579      (<filename>filter.cpp</filename>)</title>
1580     <para>
1581      The virtual base class of all filters.  The filter API is, on the
1582      surface at least, extremely simple: two methods.
1583      <literal>configure()</literal> is passed an XML DOM tree representing
1584      that part of the configuration file that pertains to this filter
1585      instance, and is expected to walk that tree extracting relevant
1586      information.  And <literal>process()</literal> processes a
1587      package (see below).  That surface simplicity is a bit
1588      misleading, as <literal>process()</literal> needs to know a lot
1589      about the <literal>Package</literal> class in order to do
1590      anything useful.
1591     </para>
1592    </section>
1593
1594    <section>
1595     <title><literal>mp::filter::AuthSimple</literal>,
1596      <literal>Backend_test</literal>, etc.
1597      (<filename>filter_auth_simple.cpp</filename>,
1598      <filename>filter_backend_test.cpp</filename>, etc.)</title>
1599     <para>
1600      Individual filters.  Each of these is implemented by a header and
1601      a source file, named <filename>filter_*.hpp</filename> and
1602      <filename>filter_*.cpp</filename> respectively.  All the header
1603      files should be pretty much identical, in that they declare the
1604      class, including a private <literal>Rep</literal> class and a
1605      member pointer to it, and the two public methods.
1606     </para>
1607     <para>
1608      The source file for each filter needs to supply:
1609     </para>
1610     <itemizedlist>
1611      <listitem>
1612       <para>
1613        A definition of the private <literal>Rep</literal> class.
1614       </para>
1615      </listitem>
1616      <listitem>
1617       <para>
1618        Some boilerplate constructors and destructors.
1619       </para>
1620      </listitem>
1621      <listitem>
1622       <para>
1623        A <literal>configure()</literal> method that uses the
1624        appropriate XML fragment.
1625       </para>
1626      </listitem>
1627      <listitem>
1628       <para>
1629        Most important, the <literal>process()</literal> method that
1630        does all the actual work.
1631       </para>
1632      </listitem>
1633     </itemizedlist>
1634    </section>
1635
1636    <section>
1637     <title><literal>mp::Package</literal>
1638      (<filename>package.cpp</filename>)</title>
1639     <para>
1640      Represents a package on its way through the series of filters
1641      that make up a route.  This is essentially a Z39.50 or SRU APDU
1642      together with information about where it came from, which is
1643      modified as it passes through the various filters.
1644     </para>
1645    </section>
1646
1647    <section>
1648     <title><literal>mp::Pipe</literal>
1649      (<filename>pipe.cpp</filename>)</title>
1650     <para>
1651      This class provides a compatibility layer so that we have an IPC
1652      mechanism that works the same under Unix and Windows.  It's not
1653      particularly exciting.
1654     </para>
1655    </section>
1656
1657    <section>
1658     <title><literal>mp::RouterChain</literal>
1659      (<filename>router_chain.cpp</filename>)</title>
1660     <para>
1661      ### to be written
1662     </para>
1663    </section>
1664
1665    <section>
1666     <title><literal>mp::RouterFleXML</literal>
1667      (<filename>router_flexml.cpp</filename>)</title>
1668     <para>
1669      ### to be written
1670     </para>
1671    </section>
1672
1673    <section>
1674     <title><literal>mp::Session</literal>
1675      (<filename>session.cpp</filename>)</title>
1676     <para>
1677      ### to be written
1678     </para>
1679    </section>
1680
1681    <section>
1682     <title><literal>mp::ThreadPoolSocketObserver</literal>
1683      (<filename>thread_pool_observer.cpp</filename>)</title>
1684     <para>
1685      ### to be written
1686     </para>
1687    </section>
1688
1689    <section>
1690     <title><literal>mp::util</literal>
1691      (<filename>util.cpp</filename>)</title>
1692     <para>
1693      A namespace of various small utility functions and classes,
1694      collected together for convenience.  Most importantly, includes
1695      the <literal>mp::util::odr</literal> class, a wrapper for YAZ's
1696      ODR facilities.
1697     </para>
1698    </section>
1699
1700    <section>
1701     <title><literal>mp::xml</literal>
1702      (<filename>xmlutil.cpp</filename>)</title>
1703     <para>
1704      A namespace of various XML utility functions and classes,
1705      collected together for convenience.
1706     </para>
1707    </section>
1708   </section>
1709
1710
1711   <section id="other.source.files">
1712    <title>Other Source Files</title>
1713    <para>
1714     In addition to the Metaproxy source files that define the classes
1715     described above, there are a few additional files which are
1716     briefly described here:
1717    </para>
1718    <variablelist>
1719     <varlistentry>
1720      <term><literal>metaproxy_prog.cpp</literal></term>
1721      <listitem>
1722       <para>
1723        The main function of the <command>metaproxy</command> program.
1724       </para>
1725      </listitem>
1726     </varlistentry>
1727     <varlistentry>
1728      <term><literal>ex_router_flexml.cpp</literal></term>
1729      <listitem>
1730       <para>
1731        Identical to <literal>metaproxy_prog.cpp</literal>: it's not clear why.
1732       </para>
1733      </listitem>
1734     </varlistentry>
1735     <varlistentry>
1736      <term><literal>test_*.cpp</literal></term>
1737      <listitem>
1738       <para>
1739        Unit-tests for various modules.
1740       </para>
1741      </listitem>
1742     </varlistentry>
1743    </variablelist>
1744    <para>
1745     ### Still to be described:
1746     <literal>ex_filter_frontend_net.cpp</literal>,
1747     <literal>filter_dl.cpp</literal>,
1748     <literal>plainfile.cpp</literal>,
1749     <literal>tstdl.cpp</literal>.
1750    </para>
1751   </section>
1752  </chapter>
1753  
1754  
1755  
1756  <reference id="refguide">
1757   <title>Reference guide</title>
1758     <para>
1759      The material in this chapter is drawn directly from the individual
1760      manual entries.  In particular, the Metaproxy invocation section is
1761      available using <command>man metaproxy</command>, and the section
1762      on each individual filter is available using the name of the filter
1763      as the argument to the <command>man</command> command.
1764     </para>
1765     &manref;
1766  </reference>
1767 </book>
1768
1769  <!-- Keep this comment at the end of the file
1770  Local variables:
1771  mode: sgml
1772  sgml-omittag:t
1773  sgml-shorttag:t
1774  sgml-minimize-attributes:nil
1775  sgml-always-quote-attributes:t
1776  sgml-indent-step:1
1777  sgml-indent-data:t
1778  sgml-parent-document: nil
1779  sgml-local-catalogs: nil
1780  sgml-namecase-general:t
1781  End:
1782  -->