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