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