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