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