1 <!-- $Id: soap.xml,v 1.6 2006-04-24 09:21:35 adam Exp $ -->
2 <chapter id="soap"><title>SOAP and SRW</title>
3 <sect1 id="soap.introduction"><title>Introduction</title>
5 &yaz; uses a very simple implementation of
6 <ulink url="&url.soap;">SOAP</ulink> that only,
7 currenly, supports what is sufficient to offer SRW functionality.
8 The implementation uses the
9 <ulink url="&url.libxml2.api.tree;">tree API</ulink> of
10 libxml2 to encode and decode SOAP packages.
13 Like the Z39.50 ASN.1 module, the &yaz; SRW implementation uses
14 simple C structs to represent SOAP packages as well as
18 <sect1 id="soap.http"><title>HTTP</title>
20 &yaz; only offers HTTP as transport carrier for SOAP, but it is
21 relatively easy to change that.
24 The following definition of <literal>Z_GDU</literal> (Generic Data
25 Unit) allows for both HTTP and Z39.50 in one packet.
28 #include <yaz/zgdu.h>
31 #define Z_GDU_HTTP_Request 2
32 #define Z_GDU_HTTP_Response 3
37 Z_HTTP_Request *HTTP_Request;
38 Z_HTTP_Response *HTTP_Response;
43 The corresponding Z_GDU encoder/decoder is <function>z_GDU</function>.
44 The <literal>z3950</literal> is any of the known BER encoded Z39.50
46 <literal>HTTP_Request</literal> and <literal>HTTP_Response</literal>
47 is the HTTP Request and Response respectively.
50 <sect1 id="soap.xml"><title>SOAP Packages</title>
52 Every SOAP package in &yaz; is represented as follows:
54 #include <yaz/soap.h>
68 #define Z_SOAP_fault 1
69 #define Z_SOAP_generic 2
70 #define Z_SOAP_error 3
75 Z_SOAP_Generic *generic;
76 Z_SOAP_Fault *soap_error;
83 The <literal>fault</literal> and <literal>soap_error</literal>
84 arms represent both a SOAP fault - struct
85 <literal>Z_SOAP_Fault</literal>. Any other generic
86 (valid) package is represented by <literal>Z_SOAP_Generic</literal>.
89 The <literal>ns</literal> as part of <literal>Z_SOAP</literal>
90 is the namespace for SOAP itself and reflects the SOAP
91 version. For version 1.1 it is
92 <literal>http://schemas.xmlsoap.org/soap/envelope/</literal>,
94 <literal>http://www.w3.org/2001/06/soap-envelope</literal>.
97 int z_soap_codec(ODR o, Z_SOAP **pp,
98 char **content_buf, int *content_len,
99 Z_SOAP_Handler *handlers);
102 The <literal>content_buf</literal> and <literal>content_len</literal>
103 is XML buffer and length of buffer respectively.
106 The <literal>handlers</literal> is a list of SOAP codec
107 handlers - one handler for each service namespace. For SRW, the
108 namespace would be <literal>http://www.loc.gov/zing/srw/v1.0/</literal>.
111 When decoding, the <function>z_soap_codec</function>
112 inspects the XML content
113 and tries to match one of the services namespaces of the
114 supplied handlers. If there is a match a handler function
115 is invoked which decodes that particular SOAP package.
116 If successful, the returned <literal>Z_SOAP</literal> package will be
117 of type <literal>Z_SOAP_Generic</literal>.
118 Member <literal>no</literal> is
119 set the offset of handler that matched; <literal>ns</literal>
120 is set to namespace of matching handler; the void pointer
121 <literal>p</literal> is set to the C data structure assocatiated
125 When a NULL namespace is met (member <literal>ns</literal> bwlow),
126 that specifies end-of-list.
129 Each handler is defined as follows:
137 The <literal>ns</literal> is namespace of service associated with
138 handler <literal>f</literal>. <literal>client_data</literal>
139 is user-defined data which is passed to handler.
142 The prototype for a SOAP service handler is:
144 int handler(ODR o, void * ptr, void **handler_data,
145 void *client_data, const char *ns);
147 The <parameter>o</parameter> specifies the mode (decode/encode)
148 as usual. The second argument, <parameter>ptr</parameter>,
149 is a libxml2 tree node pointer (<literal>xmlNodePtr</literal>)
150 and is a pointer to the <literal>Body</literal> element
151 of the SOAP package. The <parameter>handler_data</parameter>
152 is an opaque pointer to a C definitions associated with the
153 SOAP service. <parameter>client_data</parameter> is the pointer
154 which was set as part of the <literal>Z_SOAP_handler</literal>.
155 Finally, <parameter>ns</parameter> the service namespace.
158 <sect1 id="soap.srw"><title>SRW</title>
160 SRW is just one implementation of a SOAP handler as described
161 in the previous section.
162 The encoder/decoder handler for SRW is defined as
165 #include <yaz/srw.h>
167 int yaz_srw_codec(ODR o, void * pptr,
168 Z_SRW_GDU **handler_data,
169 void *client_data, const char *ns);
171 Here, <literal>Z_SRW_GDU</literal> is either
172 searchRetrieveRequest or a searchRetrieveResponse.
176 The xQuery and xSortKeys are not handled yet by
177 the SRW implementation of &yaz;. Explain is also missing.
178 Future versions of &yaz; will include these features.
182 The definition of searchRetrieveRequest is:
186 #define Z_SRW_query_type_cql 1
187 #define Z_SRW_query_type_xcql 2
188 #define Z_SRW_query_type_pqf 3
196 #define Z_SRW_sort_type_none 1
197 #define Z_SRW_sort_type_sort 2
198 #define Z_SRW_sort_type_xSort 3
210 } Z_SRW_searchRetrieveRequest;
212 Please observe that data of type xsd:string is represented
213 as a char pointer (<literal>char *</literal>). A null pointer
214 means that the element is absent.
215 Data of type xsd:integer is representd as a pointer to
216 an int (<literal>int *</literal>). Again, a null pointer
217 us used for absent elements.
220 The SearchRetrieveResponse has the following definition.
223 int * numberOfRecords;
225 int * resultSetIdleTime;
227 Z_SRW_record *records;
230 Z_SRW_diagnostic *diagnostics;
232 int *nextRecordPosition;
233 } Z_SRW_searchRetrieveResponse;
235 The <literal>num_records</literal> and <literal>num_diagnostics</literal>
236 is number of returned records and diagnostics respectively and also
237 correspond to the "size of" arrays <literal>records</literal>
238 and <literal>diagnostics</literal>.
241 A retrieval record is defined as follows:
245 char *recordData_buf;
250 The record data is defined as a buffer of some length so that
251 data can be of any type. SRW 1.0 currenly doesn't allow for this
252 (only XML), but future versions might do.
255 And, a diagnostic as: