14dc8b916605440c8be2a365ff810e2571763090
[yaz-moved-to-github.git] / include / yaz / srw.h
1 /*
2  * Copyright (c) 1995-2006, 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.31 2006-10-27 11:22:08 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     int type;
46     char *recordReviewCode;
47     char *recordReviewNote;
48     char *recordId;
49     char *nonDupRecordId;
50     char *recordLockStatus;
51     char *recordOldVersion;
52 } Z_SRW_extra_record;
53
54 typedef struct {
55     char *recordSchema;
56     int recordPacking;
57 #define Z_SRW_recordPacking_string 0
58 #define Z_SRW_recordPacking_XML 1
59 #define Z_SRW_recordPacking_URL 2
60     char *recordData_buf;
61     int recordData_len;
62     int *recordPosition;
63 } Z_SRW_record;
64
65 typedef struct {
66     char *uri;
67     char *details;
68     char *message;
69 } Z_SRW_diagnostic;
70     
71 typedef struct {
72
73 #define Z_SRW_query_type_cql  1
74 #define Z_SRW_query_type_xcql 2
75 #define Z_SRW_query_type_pqf  3
76     int query_type;
77     union {
78         char *cql;
79         char *xcql;
80         char *pqf;
81     } query;
82
83 #define Z_SRW_sort_type_none 1
84 #define Z_SRW_sort_type_sort 2
85 #define Z_SRW_sort_type_xSort 3
86     int sort_type;
87     union {
88         char *none;
89         char *sortKeys;
90         char *xSortKeys;
91     } sort;
92     int *startRecord;
93     int *maximumRecords;
94     char *recordSchema;
95     char *recordPacking;
96     char *recordXPath;
97     char *database;
98     char *stylesheet;
99     int *resultSetTTL;
100 } Z_SRW_searchRetrieveRequest;
101
102 typedef struct {
103     int * numberOfRecords;
104     char * resultSetId;
105     int * resultSetIdleTime;
106     
107     Z_SRW_record *records;
108     int num_records;
109
110     Z_SRW_diagnostic *diagnostics;
111     int num_diagnostics;
112     int *nextRecordPosition;
113
114     Z_SRW_extra_record **extra_records;  /* of size num_records */
115 } Z_SRW_searchRetrieveResponse;
116
117 typedef struct {
118     char *recordPacking;
119     char *database;
120     char *stylesheet;
121 } Z_SRW_explainRequest;
122
123 typedef struct {
124     Z_SRW_record record;
125     Z_SRW_diagnostic *diagnostics;
126     int num_diagnostics;
127     Z_SRW_extra_record *extra_record;
128 } Z_SRW_explainResponse;
129     
130 typedef struct {
131     int query_type;
132     union {
133         char *cql;
134         char *xcql;
135         char *pqf;
136     } scanClause;
137     int *responsePosition;
138     int *maximumTerms;
139     char *stylesheet;
140     char *database;
141 } Z_SRW_scanRequest;
142
143 typedef struct {
144     char *value;
145     int *numberOfRecords;
146     char *displayTerm;
147     char *whereInList;
148 } Z_SRW_scanTerm;
149
150 typedef struct {
151     Z_SRW_scanTerm *terms;
152     int num_terms;
153     Z_SRW_diagnostic *diagnostics;
154     int num_diagnostics;
155 } Z_SRW_scanResponse;
156
157
158 typedef struct {
159     char *database;
160     char *operation;
161     char *recordId;
162     char *recordVersion;
163     char *recordOldVersion;
164     Z_SRW_record record;
165     Z_SRW_extra_record *extra_record;
166     char *extraRequestData;
167     char *stylesheet;
168 } Z_SRW_updateRequest;
169
170 typedef struct {
171     char *operationStatus;
172     char *recordId;
173     char *recordVersion;
174     char *recordChecksum;
175     char *extraResponseData;
176     Z_SRW_record record;
177     Z_SRW_extra_record *extra_record;
178     Z_SRW_diagnostic *diagnostics;
179     int num_diagnostics;
180 } Z_SRW_updateResponse;
181
182 #define Z_SRW_searchRetrieve_request  1
183 #define Z_SRW_searchRetrieve_response 2
184 #define Z_SRW_explain_request 3
185 #define Z_SRW_explain_response 4
186 #define Z_SRW_scan_request 5
187 #define Z_SRW_scan_response 6
188 #define Z_SRW_update_request 7
189 #define Z_SRW_update_response 8
190
191 typedef struct {
192     int which;
193     union {
194         Z_SRW_searchRetrieveRequest *request;
195         Z_SRW_searchRetrieveResponse *response;
196         Z_SRW_explainRequest *explain_request;
197         Z_SRW_explainResponse *explain_response;
198         Z_SRW_scanRequest *scan_request;
199         Z_SRW_scanResponse *scan_response;
200         Z_SRW_updateRequest *update_request;
201         Z_SRW_updateResponse *update_response;
202     } u;
203     char *srw_version;
204     char *username; /* From HTTP header or request */
205     char *password; /* From HTTP header or request  */
206     char *extra_args; /* For SRU GET/POST only */
207 } Z_SRW_PDU;
208
209 YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr,
210                              Z_SRW_PDU **handler_data,
211                              void *client_data, const char *ns);
212 YAZ_EXPORT int yaz_ucp_codec(ODR o, void * pptr,
213                              Z_SRW_PDU **handler_data,
214                              void *client_data, const char *ns);
215 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get_core_v_1_1(ODR o);
216 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get(ODR o, int which);
217 YAZ_EXPORT Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o);
218
219 YAZ_EXPORT int yaz_diag_bib1_to_srw (int bib1_code);
220
221 YAZ_EXPORT int yaz_diag_srw_to_bib1(int srw_code);
222
223 YAZ_EXPORT char *yaz_uri_val(const char *path, const char *name, ODR o);
224 YAZ_EXPORT void yaz_uri_val_int(const char *path, const char *name,
225                                 ODR o, int **intp);
226 YAZ_EXPORT int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
227                               Z_SOAP **soap_package, ODR decode, char **charset);
228 YAZ_EXPORT int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
229                               Z_SOAP **soap_package, ODR decode, 
230                               char **charset,
231                               Z_SRW_diagnostic **, int *num_diagnostic);
232
233 YAZ_EXPORT void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
234                                        int *num, int code,
235                                        const char *addinfo);
236     
237 YAZ_EXPORT void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d,
238                                               int *num, int code,
239                                               const char *addinfo);
240
241 YAZ_EXPORT void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d, 
242                                       int code, const char *details);
243
244 YAZ_EXPORT void yaz_add_srw_diagnostic_uri(ODR o, Z_SRW_diagnostic **d,
245                                            int *num, const char *uri,
246                                            const char *message,
247                                            const char *details);
248
249 YAZ_EXPORT void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d, 
250                                       const char *uri, const char *message,
251                                       const char *details);
252
253 YAZ_EXPORT int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
254                                   ODR encode, const char *charset);
255 YAZ_EXPORT int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
256                                    ODR encode, const char *charset);
257 YAZ_EXPORT int yaz_sru_soap_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
258                                    ODR odr, const char *charset);
259
260 YAZ_END_CDECL
261
262 #endif
263 /*
264  * Local variables:
265  * c-basic-offset: 4
266  * indent-tabs-mode: nil
267  * End:
268  * vim: shiftwidth=4 tabstop=8 expandtab
269  */
270