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