1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 Index Data.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * \brief Header for SRW/SRU
38 #include <yaz/diagsrw.h>
39 #include <yaz/diagsru_update.h>
45 char *extraRecordData_buf;
46 int extraRecordData_len;
47 char *recordIdentifier;
53 int recordPacking; /* recordXMLEscaping in SRU 2.0 */
54 #define Z_SRW_recordPacking_string 0
55 #define Z_SRW_recordPacking_XML 1
56 #define Z_SRW_recordPacking_URL 2
59 int packing; /* recordPacking in SRU 2.0 */
60 #define Z_SRW_packed 0
61 #define Z_SRW_unpacked 1
66 Odr_int *recordPosition;
80 #define Z_SRW_sort_type_none 1
81 #define Z_SRW_sort_type_sort 2
82 #define Z_SRW_sort_type_xSort 3
90 Odr_int *maximumRecords;
93 char *recordPacking; /* recordXMLEscaping in SRU 2.0 */
94 char *packing; /* recordPacking in SRU 2.0 */
99 Odr_int *resultSetTTL;
100 Z_FacetList *facetList;
101 } Z_SRW_searchRetrieveRequest;
104 Odr_int *numberOfRecords;
105 char *resultCountPrecision;
107 Odr_int *resultSetIdleTime;
109 Z_SRW_record *records;
112 Z_SRW_diagnostic *diagnostics;
114 Odr_int *nextRecordPosition;
116 Z_SRW_extra_record **extra_records; /* of size num_records */
117 Z_FacetList *facetList;
119 } Z_SRW_searchRetrieveResponse;
126 } Z_SRW_explainRequest;
130 Z_SRW_diagnostic *diagnostics;
132 Z_SRW_extra_record *extra_record;
133 } Z_SRW_explainResponse;
138 Odr_int *responsePosition;
139 Odr_int *maximumTerms;
146 Odr_int *numberOfRecords;
152 Z_SRW_scanTerm *terms;
154 Z_SRW_diagnostic *diagnostics;
156 } Z_SRW_scanResponse;
162 } Z_SRW_recordVersion;
168 Z_SRW_recordVersion *recordVersions;
169 int num_recordVersions;
170 Z_SRW_record *record;
171 Z_SRW_extra_record *extra_record;
172 char *extraRequestData_buf;
173 int extraRequestData_len;
175 } Z_SRW_updateRequest;
177 typedef struct Z_SRW_extra_arg Z_SRW_extra_arg;
178 struct Z_SRW_extra_arg {
181 Z_SRW_extra_arg *next;
185 char *operationStatus;
187 Z_SRW_recordVersion *recordVersions;
188 int num_recordVersions;
189 Z_SRW_record *record;
190 Z_SRW_extra_record *extra_record;
191 char *extraResponseData_buf;
192 int extraResponseData_len;
193 Z_SRW_diagnostic *diagnostics;
195 } Z_SRW_updateResponse;
197 #define Z_SRW_searchRetrieve_request 1
198 #define Z_SRW_searchRetrieve_response 2
199 #define Z_SRW_explain_request 3
200 #define Z_SRW_explain_response 4
201 #define Z_SRW_scan_request 5
202 #define Z_SRW_scan_response 6
203 #define Z_SRW_update_request 7
204 #define Z_SRW_update_response 8
209 Z_SRW_searchRetrieveRequest *request;
210 Z_SRW_searchRetrieveResponse *response;
211 Z_SRW_explainRequest *explain_request;
212 Z_SRW_explainResponse *explain_response;
213 Z_SRW_scanRequest *scan_request;
214 Z_SRW_scanResponse *scan_response;
215 Z_SRW_updateRequest *update_request;
216 Z_SRW_updateResponse *update_response;
219 char *username; /* From HTTP header or request */
220 char *password; /* From HTTP header or request */
221 Z_SRW_extra_arg *extra_args; /* extraRequestData SRU GET/POST */
222 char *extraResponseData_buf;
223 int extraResponseData_len;
226 YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr,
227 Z_SRW_PDU **handler_data,
228 void *client_data, const char *ns);
229 YAZ_EXPORT int yaz_ucp_codec(ODR o, void * pptr,
230 Z_SRW_PDU **handler_data,
231 void *client_data, const char *ns);
232 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_core_v_2_0(ODR o);
233 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_pdu(ODR o, int which, const char *version);
234 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get(ODR o, int which);
235 YAZ_EXPORT Z_SRW_recordVersion *yaz_srw_get_record_versions(ODR o, int num);
236 YAZ_EXPORT Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o);
237 YAZ_EXPORT Z_SRW_record *yaz_srw_get_record(ODR o);
238 YAZ_EXPORT Z_SRW_record *yaz_srw_get_records(ODR o, int num);
240 YAZ_EXPORT int yaz_diag_bib1_to_srw (int bib1_code);
242 YAZ_EXPORT int yaz_diag_srw_to_bib1(int srw_code);
244 YAZ_EXPORT const char *yaz_srw_pack_to_str(int pack);
245 YAZ_EXPORT int yaz_srw_str_to_pack(const char *str);
247 /** \brief deprecated */
248 YAZ_EXPORT char *yaz_uri_val(const char *path, const char *name, ODR o);
250 /** \brief deprecated */
251 YAZ_EXPORT void yaz_uri_val_int(const char *path, const char *name,
252 ODR o, Odr_int **intp);
254 YAZ_EXPORT int yaz_uri_to_array(const char *path, ODR o,
255 char ***name, char ***val);
256 YAZ_EXPORT void yaz_array_to_uri(char **path, ODR o,
257 char **name, char **value);
259 /** \brief encodes URI component
260 \param dst destination string (should be at least 3*strlen(uri)+1)
261 \param uri URI component C-string (source)
263 YAZ_EXPORT void yaz_encode_uri_component(char *dst, const char *uri);
265 /** \brief decodes URI component
266 \param dst destination string (should be at least strlen(uri)+1)
267 \param uri URI component buffer (source)
268 \param len number of bytes to decode from uri
270 YAZ_EXPORT void yaz_decode_uri_component(char *dst, const char *uri,
273 YAZ_EXPORT int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
274 Z_SOAP **soap_package, ODR decode, char **charset);
276 YAZ_EXPORT int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
277 Z_SOAP **soap_package, ODR decode,
279 Z_SRW_diagnostic **, int *num_diagnostic);
281 /** \brief decode SOLR response (HTTP)
282 \param o ODR for result
283 \param hres HTTP response to be decoded
284 \param pdup SRW response pointer (set if successful)
288 YAZ_EXPORT int yaz_solr_decode_response(ODR o, Z_HTTP_Response *hres,
292 YAZ_EXPORT void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
294 const char *addinfo);
296 YAZ_EXPORT void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d,
298 const char *addinfo);
300 YAZ_EXPORT void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d,
301 int code, const char *details);
303 YAZ_EXPORT void yaz_add_srw_diagnostic_uri(ODR o, Z_SRW_diagnostic **d,
304 int *num, const char *uri,
306 const char *details);
308 YAZ_EXPORT void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d,
309 const char *uri, const char *message,
310 const char *details);
312 YAZ_EXPORT int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
313 ODR encode, const char *charset);
314 YAZ_EXPORT int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
315 ODR encode, const char *charset);
316 YAZ_EXPORT int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
317 ODR odr, const char *charset);
319 /** \brief encode SOLR request (HTTP)
320 \param hreq HTTP request to be modified (with encoded request)
321 \param srw_pdu SRW request
322 \param encode ODR for result
323 \param charset character set for request (may be NULL)
327 YAZ_EXPORT int yaz_solr_encode_request(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
328 ODR encode, const char *charset);
330 YAZ_EXPORT char *yaz_negotiate_sru_version(char *input_ver);
333 void yaz_encode_sru_extra(Z_SRW_PDU *sr, ODR odr, const char *extra_args);
336 #define YAZ_XMLNS_SRU_v1_0 "http://www.loc.gov/zing/srw/v1.0/"
337 #define YAZ_XMLNS_SRU_v1_1 "http://www.loc.gov/zing/srw/"
338 #define YAZ_XMLNS_DIAG_v1_1 "http://www.loc.gov/zing/srw/diagnostic/"
339 #define YAZ_XMLNS_UPDATE_v0_9 "http://www.loc.gov/zing/srw/update/"
340 #define YAZ_XMLNS_SRU_v2_mask "http://docs.oasis-open.org/ns/search-ws/*"
341 #define YAZ_XMLNS_SRU_v1_response "http://www.loc.gov/*"
344 int yaz_srw_check_content_type(Z_HTTP_Response *hres);
347 int sru_decode_surrogate_diagnostics(const char *buf, size_t len,
348 Z_SRW_diagnostic **diag,
352 void yaz_mk_sru_surrogate(ODR o, Z_SRW_record *record, int pos,
353 int code, const char *details);
355 /** \brief encode SRU database for HTTP path
356 \param out memory handle for resulting encoded database string
357 \param db source database
358 \returns encoded database path (includes leading /)
361 char *yaz_encode_sru_dbpath_odr(ODR out, const char *db);
363 /** \brief encode SRU database for HTTP path
364 \param dst destination buffer (should be at least strlen(db) +2 in size)
365 \param db source database
367 The resulting database (dst) includes a leading /
370 void yaz_encode_sru_dbpath_buf(char *dst, const char *db);
378 * c-file-style: "Stroustrup"
379 * indent-tabs-mode: nil
381 * vim: shiftwidth=4 tabstop=8 expandtab