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