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