1 <chapter id="soap"><title>SOAP and SRU</title>
2 <sect1 id="soap.introduction"><title>Introduction</title>
4 &yaz; uses a very simple implementation of
5 <ulink url="&url.soap;">SOAP</ulink> that only,
6 currenly, supports what is sufficient to offer SRU SOAP functionality.
7 The implementation uses the
8 <ulink url="&url.libxml2.api.tree;">tree API</ulink> of
9 libxml2 to encode and decode SOAP packages.
12 Like the Z39.50 ASN.1 module, the &yaz; SRU implementation uses
13 simple C structs to represent SOAP packages as well as
17 <sect1 id="soap.http"><title>HTTP</title>
19 &yaz; only offers HTTP as transport carrier for SOAP, but it is
20 relatively easy to change that.
23 The following definition of <literal>Z_GDU</literal> (Generic Data
24 Unit) allows for both HTTP and Z39.50 in one packet.
27 #include <yaz/zgdu.h>
30 #define Z_GDU_HTTP_Request 2
31 #define Z_GDU_HTTP_Response 3
36 Z_HTTP_Request *HTTP_Request;
37 Z_HTTP_Response *HTTP_Response;
42 The corresponding Z_GDU encoder/decoder is <function>z_GDU</function>.
43 The <literal>z3950</literal> is any of the known BER encoded Z39.50
45 <literal>HTTP_Request</literal> and <literal>HTTP_Response</literal>
46 is the HTTP Request and Response respectively.
49 <sect1 id="soap.xml"><title>SOAP Packages</title>
51 Every SOAP package in &yaz; is represented as follows:
53 #include <yaz/soap.h>
67 #define Z_SOAP_fault 1
68 #define Z_SOAP_generic 2
69 #define Z_SOAP_error 3
74 Z_SOAP_Generic *generic;
75 Z_SOAP_Fault *soap_error;
82 The <literal>fault</literal> and <literal>soap_error</literal>
83 arms represent both a SOAP fault - struct
84 <literal>Z_SOAP_Fault</literal>. Any other generic
85 (valid) package is represented by <literal>Z_SOAP_Generic</literal>.
88 The <literal>ns</literal> as part of <literal>Z_SOAP</literal>
89 is the namespace for SOAP itself and reflects the SOAP
90 version. For version 1.1 it is
91 <literal>http://schemas.xmlsoap.org/soap/envelope/</literal>,
93 <literal>http://www.w3.org/2001/06/soap-envelope</literal>.
96 int z_soap_codec(ODR o, Z_SOAP **pp,
97 char **content_buf, int *content_len,
98 Z_SOAP_Handler *handlers);
101 The <literal>content_buf</literal> and <literal>content_len</literal>
102 is XML buffer and length of buffer respectively.
105 The <literal>handlers</literal> is a list of SOAP codec
106 handlers - one handler for each service namespace. For SRU SOAP, the
107 namespace would be <literal>http://www.loc.gov/zing/srw/v1.0/</literal>.
110 When decoding, the <function>z_soap_codec</function>
111 inspects the XML content
112 and tries to match one of the services namespaces of the
113 supplied handlers. If there is a match a handler function
114 is invoked which decodes that particular SOAP package.
115 If successful, the returned <literal>Z_SOAP</literal> package will be
116 of type <literal>Z_SOAP_Generic</literal>.
117 Member <literal>no</literal> is
118 set the offset of handler that matched; <literal>ns</literal>
119 is set to namespace of matching handler; the void pointer
120 <literal>p</literal> is set to the C data structure assocatiated
124 When a NULL namespace is met (member <literal>ns</literal> bwlow),
125 that specifies end-of-list.
128 Each handler is defined as follows:
136 The <literal>ns</literal> is namespace of service associated with
137 handler <literal>f</literal>. <literal>client_data</literal>
138 is user-defined data which is passed to handler.
141 The prototype for a SOAP service handler is:
143 int handler(ODR o, void * ptr, void **handler_data,
144 void *client_data, const char *ns);
146 The <parameter>o</parameter> specifies the mode (decode/encode)
147 as usual. The second argument, <parameter>ptr</parameter>,
148 is a libxml2 tree node pointer (<literal>xmlNodePtr</literal>)
149 and is a pointer to the <literal>Body</literal> element
150 of the SOAP package. The <parameter>handler_data</parameter>
151 is an opaque pointer to a C definitions associated with the
152 SOAP service. <parameter>client_data</parameter> is the pointer
153 which was set as part of the <literal>Z_SOAP_handler</literal>.
154 Finally, <parameter>ns</parameter> the service namespace.
157 <sect1 id="soap.srw"><title>SRU</title>
159 SRU SOAP is just one implementation of a SOAP handler as described
160 in the previous section.
161 The encoder/decoder handler for SRU is defined as
164 #include <yaz/srw.h>
166 int yaz_srw_codec(ODR o, void * pptr,
167 Z_SRW_GDU **handler_data,
168 void *client_data, const char *ns);
170 Here, <literal>Z_SRW_GDU</literal> is either
171 searchRetrieveRequest or a searchRetrieveResponse.
175 The xQuery and xSortKeys are not handled yet by
176 the SRW implementation of &yaz;. Explain is also missing.
177 Future versions of &yaz; will include these features.
181 The definition of searchRetrieveRequest is:
185 #define Z_SRW_query_type_cql 1
186 #define Z_SRW_query_type_xcql 2
187 #define Z_SRW_query_type_pqf 3
195 #define Z_SRW_sort_type_none 1
196 #define Z_SRW_sort_type_sort 2
197 #define Z_SRW_sort_type_xSort 3
209 } Z_SRW_searchRetrieveRequest;
211 Please observe that data of type xsd:string is represented
212 as a char pointer (<literal>char *</literal>). A null pointer
213 means that the element is absent.
214 Data of type xsd:integer is representd as a pointer to
215 an int (<literal>int *</literal>). Again, a null pointer
216 us used for absent elements.
219 The SearchRetrieveResponse has the following definition.
222 int * numberOfRecords;
224 int * resultSetIdleTime;
226 Z_SRW_record *records;
229 Z_SRW_diagnostic *diagnostics;
231 int *nextRecordPosition;
232 } Z_SRW_searchRetrieveResponse;
234 The <literal>num_records</literal> and <literal>num_diagnostics</literal>
235 is number of returned records and diagnostics respectively and also
236 correspond to the "size of" arrays <literal>records</literal>
237 and <literal>diagnostics</literal>.
240 A retrieval record is defined as follows:
244 char *recordData_buf;
249 The record data is defined as a buffer of some length so that
250 data can be of any type. SRW 1.0 currenly doesn't allow for this
251 (only XML), but future versions might do.
254 And, a diagnostic as: