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