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