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