Added handle member to statserv_control.
[yaz-moved-to-github.git] / include / yaz / backend.h
1 /*
2  * Copyright (c) 1995-2000, Index Data.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation, in whole or in part, for any purpose, is hereby granted,
6  * provided that:
7  *
8  * 1. This copyright and permission notice appear in all copies of the
9  * software and its documentation. Notices of copyright or attribution
10  * which appear at the beginning of any file must remain unchanged.
11  *
12  * 2. The name of Index Data or the individual authors may not be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19  * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
20  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
21  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
22  * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  *
26  * $Log: backend.h,v $
27  * Revision 1.5  2000-03-15 12:59:49  adam
28  * Added handle member to statserv_control.
29  *
30  * Revision 1.4  2000/02/28 11:20:06  adam
31  * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL.
32  *
33  * Revision 1.3  2000/01/12 14:36:07  adam
34  * Added printing stream (ODR) for backend functions.
35  *
36  * Revision 1.2  1999/12/16 23:36:19  adam
37  * Implemented ILL protocol. Minor updates ASN.1 compiler.
38  *
39  * Revision 1.1  1999/11/30 13:47:11  adam
40  * Improved installation. Moved header files to include/yaz.
41  *
42  * Revision 1.28  1999/11/04 14:58:44  adam
43  * Added status elements for backend delete result set handler.
44  * Updated delete result result set command for client.
45  *
46  * Revision 1.27  1999/10/11 10:01:24  adam
47  * Implemented bend_sort_rr handler for frontend server.
48  *
49  * Revision 1.26  1999/06/17 10:54:44  adam
50  * Added facility to specify implementation version - and name
51  * for server.
52  *
53  * Revision 1.25  1999/06/01 14:29:12  adam
54  * Work on Extended Services.
55  *
56  * Revision 1.24  1999/03/31 11:18:24  adam
57  * Implemented odr_strdup. Added Reference ID to backend server API.
58  *
59  * Revision 1.23  1998/10/13 16:12:23  adam
60  * Added support for Surrogate Diagnostics for Scan Term entries.
61  *
62  * Revision 1.22  1998/09/02 12:41:51  adam
63  * Added decode stream in bend search structures.
64  *
65  * Revision 1.21  1998/07/20 12:38:41  adam
66  * Implemented delete result set service to server API.
67  *
68  * Revision 1.20  1998/05/27 16:57:06  adam
69  * Support for surrogate diagnostic records added for bend_fetch.
70  *
71  * Revision 1.19  1998/03/31 11:07:45  adam
72  * Furhter work on UNIverse resource report.
73  * Added Extended Services handling in frontend server.
74  *
75  * Revision 1.18  1998/02/10 11:03:56  adam
76  * Added support for extended handlers in backend server interface.
77  *
78  * Revision 1.17  1998/01/29 13:15:35  adam
79  * Implemented sort for the backend interface.
80  *
81  * Revision 1.16  1997/09/17 12:10:31  adam
82  * YAZ version 1.4.
83  *
84  */
85
86 #ifndef BACKEND_H
87 #define BACKEND_H
88
89 #include <yaz/yconfig.h>
90 #include <yaz/proto.h>
91 #include <yaz/statserv.h>
92
93 YAZ_BEGIN_CDECL
94     
95 typedef struct request *bend_request;
96 typedef struct association *bend_association;
97
98 /* old search request input */ 
99 typedef struct 
100 {
101     char *setname;             /* name to give to this set */
102     int replace_set;           /* replace set, if it already exists */
103     int num_bases;             /* number of databases in list */
104     char **basenames;          /* databases to search */
105     Z_ReferenceId *referenceId;/* reference ID */
106     Z_Query *query;            /* query structure */
107     ODR stream;                /* encoding stream */
108     ODR decode;                /* decoding stream */
109     ODR print;                 /* printing stream */
110 } bend_searchrequest;
111
112 /* old search request output */
113 typedef struct
114 {
115     int hits;                  /* number of hits */
116     int errcode;               /* 0==OK */
117     char *errstring;           /* system error string or NULL */
118 } bend_searchresult;
119
120 /* extended search handler (rr = request response) */
121 typedef struct {
122     char *setname;             /* name to give to this set */
123     int replace_set;           /* replace set, if it already exists */
124     int num_bases;             /* number of databases in list */
125     char **basenames;          /* databases to search */
126     Z_ReferenceId *referenceId;/* reference ID */
127     Z_Query *query;            /* query structure */
128     ODR stream;                /* encode stream */
129     ODR decode;                /* decode stream */
130     ODR print;                 /* print stream */
131
132     bend_request request;
133     bend_association association;
134     int *fd;
135     int hits;                  /* number of hits */
136     int errcode;               /* 0==OK */
137     char *errstring;           /* system error string or NULL */
138 } bend_search_rr;
139
140 /* extended present handler. Does not replace bend_fetch. */
141 typedef struct {
142     char *setname;             /* set name */
143     int start;
144     int number;                /* record number */
145     oid_value format;          /* One of the CLASS_RECSYN members */
146     Z_ReferenceId *referenceId;/* reference ID */
147     Z_RecordComposition *comp; /* Formatting instructions */
148     ODR stream;                /* encoding stream - memory source if required */
149     ODR print;                 /* printing stream */
150     bend_request request;
151     bend_association association;
152
153     int hits;                  /* number of hits */
154     int errcode;               /* 0==OK */
155     char *errstring;           /* system error string or NULL */
156 } bend_present_rr;
157
158 YAZ_EXPORT bend_searchresult *bend_search(void *handle, bend_searchrequest *r,
159                                           int *fd);
160 YAZ_EXPORT int bend_searchresponse(void *handle, bend_search_rr *bsrr);
161
162 typedef struct
163 {
164     char *setname;             /* set name */
165     int number;                /* record number */
166     Z_ReferenceId *referenceId;/* reference ID */
167     oid_value format;          /* One of the CLASS_RECSYN members */
168     Z_RecordComposition *comp; /* Formatting instructions */
169     ODR stream;                /* encoding stream - memory source if req */
170     ODR print;                 /* printing stream */
171     int surrogate_flag;        /* surrogate diagnostic flag (rw) */
172 } bend_fetchrequest;
173
174 typedef struct
175 {
176     char *basename;            /* name of database that provided record */
177     int len;                   /* length of record or -1 if structured */
178     char *record;              /* record */
179     int last_in_set;           /* is it?  */
180     oid_value format;          /* format */
181     int errcode;               /* 0==success */
182     char *errstring;           /* system error string or NULL */
183 } bend_fetchresult;
184
185 YAZ_EXPORT bend_fetchresult *bend_fetch(void *handle, bend_fetchrequest *r,
186                                         int *fd);
187 YAZ_EXPORT bend_fetchresult *bend_fetchresponse(void *handle);
188
189 typedef struct
190 {
191     int num_bases;      /* number of elements in databaselist */
192     char **basenames;   /* databases to search */
193     oid_value attributeset;
194     Z_ReferenceId *referenceId; /* reference ID */
195     Z_AttributesPlusTerm *term;
196     int term_position;  /* desired index of term in result list */
197     int num_entries;    /* number of entries requested */
198     ODR stream;         /* encoding stream - memory source if required */
199     ODR print;          /* printing stream */
200 } bend_scanrequest;
201
202 struct scan_entry {
203     char *term;         /* the returned scan term */
204     int occurrences;    /* no of occurrences or -1 if error (see below) */
205     int errcode;        /* Bib-1 diagnostic code; only used when occur.= -1 */
206     char *errstring;    /* Additional string */
207 };
208
209 typedef enum {
210     BEND_SCAN_SUCCESS,  /* ok */
211     BEND_SCAN_PARTIAL   /* not all entries could be found */
212 } bend_scan_status;
213
214 typedef struct bend_scanresult
215 {
216     int num_entries;
217     struct scan_entry *entries;
218     int term_position;
219     bend_scan_status status;
220     int errcode;
221     char *errstring;
222 } bend_scanresult;
223
224 typedef struct bend_scan_rr {
225     int num_bases;      /* number of elements in databaselist */
226     char **basenames;   /* databases to search */
227     oid_value attributeset;
228     Z_ReferenceId *referenceId; /* reference ID */
229     Z_AttributesPlusTerm *term;
230     ODR stream;         /* encoding stream - memory source if required */
231     ODR print;          /* printing stream */
232
233     int term_position;  /* desired index of term in result list/returned */
234     int num_entries;    /* number of entries requested/returned */
235
236     struct scan_entry *entries;
237     bend_scan_status status;
238     int errcode;
239     char *errstring;
240 } bend_scan_rr;
241
242 YAZ_EXPORT bend_scanresult *bend_scan(void *handle, bend_scanrequest *r,
243                                       int *fd);
244 YAZ_EXPORT bend_scanresult *bend_scanresponse(void *handle);
245
246 /* delete handler */
247 typedef struct bend_delete_rr {
248     int function;
249     int num_setnames;
250     char **setnames;
251     Z_ReferenceId *referenceId;
252     int delete_status;      /* status for the whole operation */
253     int *statuses;          /* status each set - indexed as setnames */
254     ODR stream;
255     ODR print; 
256 } bend_delete_rr;
257
258 /* close handler */
259 YAZ_EXPORT void bend_close(void *handle);
260
261 /* sort handler */
262 typedef struct bend_sort_rr
263 {
264     int num_input_setnames;
265     char **input_setnames;
266     char *output_setname;
267     Z_SortKeySpecList *sort_sequence;
268     ODR stream;
269     ODR print;
270     Z_ReferenceId *referenceId;/* reference ID */
271
272     int sort_status;
273     int errcode;
274     char *errstring;
275 } bend_sort_rr;
276
277 typedef struct bend_esrequest_rr
278 {
279     int ItemNo;
280     Z_ExtendedServicesRequest *esr;
281     
282     ODR stream;                /* encoding stream */
283     ODR decode;                /* decoding stream */
284     ODR print;                 /* printing stream */
285     Z_ReferenceId *referenceId;/* reference ID */
286     bend_request request;
287     bend_association association;
288     int errcode;               /* 0==success, -1==accepted, >0 = failure */
289     char *errstring;           /* system error string or NULL */
290 } bend_esrequest_rr;
291
292 typedef struct bend_initrequest
293 {
294     Z_IdAuthentication *auth;
295     ODR stream;                /* encoding stream */
296     ODR print;                 /* printing stream */
297     Z_ReferenceId *referenceId;/* reference ID */
298     
299     char *implementation_name;
300     char *implementation_version;
301     int (*bend_sort) (void *handle, bend_sort_rr *rr);
302     int (*bend_search) (void *handle, bend_search_rr *rr);
303     int (*bend_present) (void *handle, bend_present_rr *rr);
304     int (*bend_esrequest) (void *handle, bend_esrequest_rr *rr);
305     int (*bend_delete)(void *handle, bend_delete_rr *rr);
306     int (*bend_scan)(void *handle, bend_scan_rr *rr);
307 } bend_initrequest;
308
309 typedef struct bend_initresult
310 {
311     int errcode;               /* 0==OK */
312     char *errstring;           /* system error string or NULL */
313     void *handle;              /* private handle to the backend module */
314 } bend_initresult;
315
316 YAZ_EXPORT bend_initresult *bend_init(bend_initrequest *r);
317
318 YAZ_EXPORT void bend_request_send (bend_association a, bend_request req,
319                                    Z_APDU *res);
320
321 YAZ_EXPORT bend_request bend_request_mk (bend_association a);
322
323 YAZ_EXPORT void bend_request_destroy (bend_request *req);
324
325 YAZ_EXPORT Z_ReferenceId *bend_request_getid (ODR odr, bend_request req);
326 YAZ_EXPORT int bend_backend_respond (bend_association a, bend_request req);
327 YAZ_EXPORT void bend_request_setdata(bend_request r, void *p);
328 YAZ_EXPORT void *bend_request_getdata(bend_request r);
329
330 YAZ_END_CDECL
331
332 #endif