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