Supporting Username/password in SRU server mode, either through x-username/x-password
[yaz-moved-to-github.git] / include / yaz / srw.h
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: srw.h,v 1.26 2006-05-05 20:02:22 quinn Exp $
6  */
7 /**
8  * \file srw.h
9  * \brief Header for SRW/SRU
10  */
11
12 #ifndef YAZ_SRW_H
13 #define YAZ_SRW_H
14
15 #include <yaz/soap.h>
16 #include <yaz/zgdu.h>
17 #include <yaz/diagsrw.h>
18
19 YAZ_BEGIN_CDECL
20
21 typedef struct {
22     int type;
23     char *recordReviewCode;
24     char *recordReviewNote;
25     char *recordId;
26     char *nonDupRecordId;
27     char *recordLockStatus;
28     char *recordOldVersion;
29 } Z_SRW_extra_record;
30
31 typedef struct {
32     char *recordSchema;
33     int recordPacking;
34 #define Z_SRW_recordPacking_string 0
35 #define Z_SRW_recordPacking_XML 1
36 #define Z_SRW_recordPacking_URL 2
37     char *recordData_buf;
38     int recordData_len;
39     int *recordPosition;
40 } Z_SRW_record;
41
42 typedef struct {
43     char *uri;
44     char *details;
45     char *message;
46 } Z_SRW_diagnostic;
47     
48 typedef struct {
49
50 #define Z_SRW_query_type_cql  1
51 #define Z_SRW_query_type_xcql 2
52 #define Z_SRW_query_type_pqf  3
53     int query_type;
54     union {
55         char *cql;
56         char *xcql;
57         char *pqf;
58     } query;
59
60 #define Z_SRW_sort_type_none 1
61 #define Z_SRW_sort_type_sort 2
62 #define Z_SRW_sort_type_xSort 3
63     int sort_type;
64     union {
65         char *none;
66         char *sortKeys;
67         char *xSortKeys;
68     } sort;
69     int *startRecord;
70     int *maximumRecords;
71     char *recordSchema;
72     char *recordPacking;
73     char *recordXPath;
74     char *database;
75     char *stylesheet;
76     int *resultSetTTL;
77 } Z_SRW_searchRetrieveRequest;
78
79 typedef struct {
80     int * numberOfRecords;
81     char * resultSetId;
82     int * resultSetIdleTime;
83     
84     Z_SRW_record *records;
85     int num_records;
86
87     Z_SRW_diagnostic *diagnostics;
88     int num_diagnostics;
89     int *nextRecordPosition;
90
91     Z_SRW_extra_record **extra_records;  /* of size num_records */
92 } Z_SRW_searchRetrieveResponse;
93
94 typedef struct {
95     char *recordPacking;
96     char *database;
97     char *stylesheet;
98 } Z_SRW_explainRequest;
99
100 typedef struct {
101     Z_SRW_record record;
102     Z_SRW_diagnostic *diagnostics;
103     int num_diagnostics;
104     Z_SRW_extra_record *extra_record;
105 } Z_SRW_explainResponse;
106     
107 typedef struct {
108     int query_type;
109     union {
110         char *cql;
111         char *xcql;
112         char *pqf;
113     } scanClause;
114     int *responsePosition;
115     int *maximumTerms;
116     char *stylesheet;
117     char *database;
118 } Z_SRW_scanRequest;
119
120 typedef struct {
121     char *value;
122     int *numberOfRecords;
123     char *displayTerm;
124     char *whereInList;
125 } Z_SRW_scanTerm;
126
127 typedef struct {
128     Z_SRW_scanTerm *terms;
129     int num_terms;
130     Z_SRW_diagnostic *diagnostics;
131     int num_diagnostics;
132 } Z_SRW_scanResponse;
133
134
135 typedef struct {
136     char *database;
137     char *operation;
138     char *recordId;
139     char *recordVersion;
140     char *recordOldVersion;
141     Z_SRW_record record;
142     Z_SRW_extra_record *extra_record;
143     char *extraRequestData;
144     char *stylesheet;
145 } Z_SRW_updateRequest;
146
147 typedef struct {
148     char *operationStatus;
149     char *recordId;
150     char *recordVersion;
151     char *recordChecksum;
152     char *extraResponseData;
153     Z_SRW_record record;
154     Z_SRW_extra_record *extra_record;
155     Z_SRW_diagnostic *diagnostics;
156     int num_diagnostics;
157 } Z_SRW_updateResponse;
158
159 #define Z_SRW_searchRetrieve_request  1
160 #define Z_SRW_searchRetrieve_response 2
161 #define Z_SRW_explain_request 3
162 #define Z_SRW_explain_response 4
163 #define Z_SRW_scan_request 5
164 #define Z_SRW_scan_response 6
165 #define Z_SRW_update_request 7
166 #define Z_SRW_update_response 8
167
168 typedef struct {
169     int which;
170     union {
171         Z_SRW_searchRetrieveRequest *request;
172         Z_SRW_searchRetrieveResponse *response;
173         Z_SRW_explainRequest *explain_request;
174         Z_SRW_explainResponse *explain_response;
175         Z_SRW_scanRequest *scan_request;
176         Z_SRW_scanResponse *scan_response;
177         Z_SRW_updateRequest *update_request;
178         Z_SRW_updateResponse *update_response;
179     } u;
180     char *srw_version;
181     char *username; /* From HTTP header or request */
182     char *password; /* From HTTP header or request  */
183 } Z_SRW_PDU;
184
185 YAZ_EXPORT int yaz_srw_codec(ODR o, void * pptr,
186                              Z_SRW_PDU **handler_data,
187                              void *client_data, const char *ns);
188 YAZ_EXPORT int yaz_ucp_codec(ODR o, void * pptr,
189                              Z_SRW_PDU **handler_data,
190                              void *client_data, const char *ns);
191 YAZ_EXPORT Z_SRW_PDU *yaz_srw_get(ODR o, int which);
192 YAZ_EXPORT Z_SRW_extra_record *yaz_srw_get_extra_record(ODR o);
193
194 YAZ_EXPORT int yaz_diag_bib1_to_srw (int bib1_code);
195
196 YAZ_EXPORT int yaz_diag_srw_to_bib1(int srw_code);
197
198 YAZ_EXPORT char *yaz_uri_val(const char *path, const char *name, ODR o);
199 YAZ_EXPORT void yaz_uri_val_int(const char *path, const char *name,
200                                 ODR o, int **intp);
201 YAZ_EXPORT int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
202                               Z_SOAP **soap_package, ODR decode, char **charset);
203 YAZ_EXPORT int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
204                               Z_SOAP **soap_package, ODR decode, 
205                               char **charset,
206                               Z_SRW_diagnostic **, int *num_diagnostic);
207
208 YAZ_EXPORT void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
209                                        int *num, int code,
210                                        const char *addinfo);
211     
212
213 YAZ_EXPORT void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d, 
214                                       int code, const char *details);
215
216 YAZ_EXPORT void yaz_add_srw_diagnostic_uri(ODR o, Z_SRW_diagnostic **d,
217                                            int *num, const char *uri,
218                                            const char *message,
219                                            const char *details);
220
221 YAZ_EXPORT void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d, 
222                                       const char *uri, const char *message,
223                                       const char *details);
224
225 YAZ_EXPORT int yaz_sru_get_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
226                                   ODR encode, char *charset);
227 YAZ_EXPORT int yaz_sru_post_encode(Z_HTTP_Request *hreq, Z_SRW_PDU *srw_pdu,
228                                    ODR encode, char *charset);
229 YAZ_END_CDECL
230
231 #endif
232 /*
233  * Local variables:
234  * c-basic-offset: 4
235  * indent-tabs-mode: nil
236  * End:
237  * vim: shiftwidth=4 tabstop=8 expandtab
238  */
239