For SRU responses allow Content-Type application/xml as well as text/xml.
[yaz-moved-to-github.git] / include / yaz / srw.h
1 /*
2  * Copyright (c) 1995-2007, Index Data
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
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.
15  *
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.
26  */
27 /* $Id: srw.h,v 1.34 2007-05-23 11:54:47 adam Exp $ */
28
29 /**
30  * \file srw.h
31  * \brief Header for SRW/SRU
32  */
33
34 #ifndef YAZ_SRW_H
35 #define YAZ_SRW_H
36
37 #include <yaz/soap.h>
38 #include <yaz/zgdu.h>
39 #include <yaz/diagsrw.h>
40 #include <yaz/diagsru_update.h>
41
42 YAZ_BEGIN_CDECL
43
44 typedef struct {
45     char *extraRecordData_buf;
46     int extraRecordData_len;
47     char *recordIdentifier;
48 } Z_SRW_extra_record;
49
50 typedef struct {
51     char *recordSchema;
52     int recordPacking;
53 #define Z_SRW_recordPacking_string 0
54 #define Z_SRW_recordPacking_XML 1
55 #define Z_SRW_recordPacking_URL 2
56     char *recordData_buf;
57     int recordData_len;
58     int *recordPosition;
59 } Z_SRW_record;
60
61 typedef struct {
62     char *uri;
63     char *details;
64     char *message;
65 } Z_SRW_diagnostic;
66     
67 typedef struct {
68
69 #define Z_SRW_query_type_cql  1
70 #define Z_SRW_query_type_xcql 2
71 #define Z_SRW_query_type_pqf  3
72     int query_type;
73     union {
74         char *cql;
75         char *xcql;
76         char *pqf;
77     } query;
78
79 #define Z_SRW_sort_type_none 1
80 #define Z_SRW_sort_type_sort 2
81 #define Z_SRW_sort_type_xSort 3
82     int sort_type;
83     union {
84         char *none;
85         char *sortKeys;
86         char *xSortKeys;
87     } sort;
88     int *startRecord;
89     int *maximumRecords;
90     char *recordSchema;
91     char *recordPacking;
92     char *recordXPath;
93     char *database;
94     char *stylesheet;
95     int *resultSetTTL;
96 } Z_SRW_searchRetrieveRequest;
97
98 typedef struct {
99     int * numberOfRecords;
100     char * resultSetId;
101     int * resultSetIdleTime;
102     
103     Z_SRW_record *records;
104     int num_records;
105
106     Z_SRW_diagnostic *diagnostics;
107     int num_diagnostics;
108     int *nextRecordPosition;
109
110     Z_SRW_extra_record **extra_records;  /* of size num_records */
111 } Z_SRW_searchRetrieveResponse;
112
113 typedef struct {
114     char *recordPacking;
115     char *database;
116     char *stylesheet;
117 } Z_SRW_explainRequest;
118
119 typedef struct {
120     Z_SRW_record record;
121     Z_SRW_diagnostic *diagnostics;
122     int num_diagnostics;
123     Z_SRW_extra_record *extra_record;
124 } Z_SRW_explainResponse;
125     
126 typedef struct {
127     int query_type;
128     union {
129         char *cql;
130         char *xcql;
131         char *pqf;
132     } scanClause;
133     int *responsePosition;
134     int *maximumTerms;
135     char *stylesheet;
136     char *database;
137 } Z_SRW_scanRequest;
138
139 typedef struct {
140     char *value;
141     int *numberOfRecords;
142     char *displayTerm;
143     char *whereInList;
144 } Z_SRW_scanTerm;
145
146 typedef struct {
147     Z_SRW_scanTerm *terms;
148     int num_terms;
149     Z_SRW_diagnostic *diagnostics;
150     int num_diagnostics;
151 } Z_SRW_scanResponse;
152
153
154 typedef struct {
155     char *versionType;
156     char *versionValue;
157 } Z_SRW_recordVersion;
158
159 typedef struct {
160     char *database;
161     char *operation;
162     char *recordId;
163     Z_SRW_recordVersion *recordVersions;
164     int num_recordVersions;
165     Z_SRW_record *record;
166     Z_SRW_extra_record *extra_record;
167     char *extraRequestData_buf;
168     int extraRequestData_len;
169     char *stylesheet;
170 } Z_SRW_updateRequest;
171
172 typedef struct {
173     char *operationStatus;
174     char *recordId;
175     Z_SRW_recordVersion *recordVersions;
176     int num_recordVersions;
177     Z_SRW_record *record;
178     Z_SRW_extra_record *extra_record;
179     char *extraResponseData_buf;
180     int extraResponseData_len;
181     Z_SRW_diagnostic *diagnostics;
182     int num_diagnostics;
183 } Z_SRW_updateResponse;
184
185 #define Z_SRW_searchRetrieve_request  1
186 #define Z_SRW_searchRetrieve_response 2
187 #define Z_SRW_explain_request 3
188 #define Z_SRW_explain_response 4
189 #define Z_SRW_scan_request 5
190 #define Z_SRW_scan_response 6
191 #define Z_SRW_update_request 7
192 #define Z_SRW_update_response 8
193
194 typedef struct {
195     int which;
196     union {
197         Z_SRW_searchRetrieveRequest *request;
198         Z_SRW_searchRetrieveResponse *response;
199         Z_SRW_explainRequest *explain_request;
200         Z_SRW_explainResponse *explain_response;
201         Z_SRW_scanRequest *scan_request;
202         Z_SRW_scanResponse *scan_response;
203         Z_SRW_updateRequest *update_request;
204         Z_SRW_updateResponse *update_response;
205     } u;
206     char *srw_version;
207     char *username; /* From HTTP header or request */
208     char *password; /* From HTTP header or request  */
209     char *extra_args; /* For SRU GET/POST only */
210 } Z_SRW_PDU;
211
212 YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr,
213                              Z_SRW_PDU **handler_data,
214                              void *client_data, const char *ns);
215 YAZ_EXPORT int yaz_ucp_codec(ODR o, void * pptr,
216                              Z_SRW_PDU **handler_data,
217                              void *client_data, const char *ns);
218 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_core_v_1_1(ODR o);
219 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get(ODR o, int which);
220 YAZ_EXPORT Z_SRW_recordVersion *yaz_srw_get_record_versions(ODR o, int num);
221 YAZ_EXPORT Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o);
222 YAZ_EXPORT Z_SRW_record *yaz_srw_get_record(ODR o);
223 YAZ_EXPORT Z_SRW_record *yaz_srw_get_records(ODR o, int num);
224
225 YAZ_EXPORT int yaz_diag_bib1_to_srw (int bib1_code);
226
227 YAZ_EXPORT int yaz_diag_srw_to_bib1(int srw_code);
228
229 YAZ_EXPORT const char *yaz_srw_pack_to_str(int pack);
230 YAZ_EXPORT int yaz_srw_str_to_pack(const char *str);
231
232 YAZ_EXPORT char *yaz_uri_val(const char *path, const char *name, ODR o);
233 YAZ_EXPORT void yaz_uri_val_int(const char *path, const char *name,
234                                 ODR o, int **intp);
235 YAZ_EXPORT int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
236                               Z_SOAP **soap_package, ODR decode, char **charset);
237 YAZ_EXPORT int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
238                               Z_SOAP **soap_package, ODR decode, 
239                               char **charset,
240                               Z_SRW_diagnostic **, int *num_diagnostic);
241
242 YAZ_EXPORT void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
243                                        int *num, int code,
244                                        const char *addinfo);
245     
246 YAZ_EXPORT void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d,
247                                               int *num, int code,
248                                               const char *addinfo);
249
250 YAZ_EXPORT void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d, 
251                                       int code, const char *details);
252
253 YAZ_EXPORT void yaz_add_srw_diagnostic_uri(ODR o, Z_SRW_diagnostic **d,
254                                            int *num, const char *uri,
255                                            const char *message,
256                                            const char *details);
257
258 YAZ_EXPORT void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d, 
259                                       const char *uri, const char *message,
260                                       const char *details);
261
262 YAZ_EXPORT int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
263                                   ODR encode, const char *charset);
264 YAZ_EXPORT int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
265                                    ODR encode, const char *charset);
266 YAZ_EXPORT int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
267                                    ODR odr, const char *charset);
268
269 #define YAZ_XMLNS_SRU_v1_0 "http://www.loc.gov/zing/srw/v1.0/"
270 #define YAZ_XMLNS_SRU_v1_1 "http://www.loc.gov/zing/srw/"
271 #define YAZ_XMLNS_DIAG_v1_1 "http://www.loc.gov/zing/srw/diagnostic/"
272 #define YAZ_XMLNS_UPDATE_v0_9 "http://www.loc.gov/zing/srw/update/"
273
274 YAZ_EXPORT
275 int yaz_srw_check_content_type(Z_HTTP_Response *hres);
276
277 YAZ_END_CDECL
278
279 #endif
280 /*
281  * Local variables:
282  * c-basic-offset: 4
283  * indent-tabs-mode: nil
284  * End:
285  * vim: shiftwidth=4 tabstop=8 expandtab
286  */
287