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