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