Extended the GFS search facility. New member of bend_search_rr
[yaz-moved-to-github.git] / include / yaz / backend.h
1 /*
2  * Copyright (c) 1995-2007, Index Data
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of Index Data nor the names of its contributors
13  *       may be used to endorse or promote products derived from this
14  *       software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 /* $Id: backend.h,v 1.42 2007-01-16 14:12:37 adam Exp $ */
28
29 /** 
30  * \file backend.h
31  * \brief Header for GFS
32  *
33  * This header includes all public definitions for the
34  * Generic Frontend Server (GFS).
35  */
36
37 #ifndef BACKEND_H
38 #define BACKEND_H
39
40 #include <yaz/yconfig.h>
41 #include <yaz/proto.h>
42 #include <yaz/srw.h>
43
44 YAZ_BEGIN_CDECL
45     
46 typedef struct request *bend_request;
47 typedef struct association *bend_association;
48
49 /* extended search handler (rr = request response) */
50 typedef struct {
51     char *setname;             /* name to give to this set */
52     int replace_set;           /* replace set, if it already exists */
53     int num_bases;             /* number of databases in list */
54     char **basenames;          /* databases to search */
55     Z_ReferenceId *referenceId;/* reference ID */
56     Z_Query *query;            /* query structure */
57     ODR stream;                /* encode stream */
58     ODR decode;                /* decode stream */
59     ODR print;                 /* print stream */
60
61     bend_request request;
62     bend_association association;
63     int *fd;
64     int hits;                  /* number of hits */
65     int errcode;               /* 0==OK */
66     char *errstring;           /* system error string or NULL */
67     Z_OtherInformation *search_info; /* additional search info */
68     char *srw_sortKeys;        /* holds SRU/SRW sortKeys info */
69     char *srw_setname;         /* holds SRU/SRW generated resultsetID */
70     int *srw_setnameIdleTime;  /* holds SRU/SRW life-time */
71     int estimated_hit_count;   /* if hit count is estimated */
72     int partial_resultset;     /* if result set is partial */
73 } bend_search_rr;
74
75 /* extended present handler. Does not replace bend_fetch. */
76 typedef struct {
77     char *setname;             /* set name */
78     int start;
79     int number;                /* record number */
80     oid_value format;          /* One of the CLASS_RECSYN members */
81     Z_ReferenceId *referenceId;/* reference ID */
82     Z_RecordComposition *comp; /* Formatting instructions */
83     ODR stream;                /* encoding stream - memory source if required */
84     ODR print;                 /* printing stream */
85     bend_request request;
86     bend_association association;
87
88     int hits;                  /* number of hits */
89     int errcode;               /* 0==OK */
90     char *errstring;           /* system error string or NULL */
91 } bend_present_rr;
92
93 typedef struct bend_fetch_rr {
94     char *setname;             /* set name */
95     int number;                /* record number */
96     Z_ReferenceId *referenceId;/* reference ID */
97     oid_value request_format;  /* One of the CLASS_RECSYN members */
98     int *request_format_raw;   /* same as above (raw OID) */
99     Z_RecordComposition *comp; /* Formatting instructions */
100     ODR stream;                /* encoding stream - memory source if req */
101     ODR print;                 /* printing stream */
102
103     char *basename;            /* name of database that provided record */
104     int len;                   /* length of record or -1 if structured */
105     char *record;              /* record */
106     int last_in_set;           /* is it?  */
107     oid_value output_format;   /* format */
108     int *output_format_raw;    /* used instead of above if not-null */
109     int errcode;               /* 0==success */
110     char *errstring;           /* system error string or NULL */
111     int surrogate_flag;        /* surrogate diagnostic */
112     char *schema;              /* string record schema input/output */
113 } bend_fetch_rr;
114
115 struct scan_entry {
116     char *term;         /* the returned scan term */
117     int occurrences;    /* no of occurrences or -1 if error (see below) */
118     int errcode;        /* Bib-1 diagnostic code; only used when occur.= -1 */
119     char *errstring;    /* Additional string */
120     char *display_term;
121 };
122
123 typedef enum {
124     BEND_SCAN_SUCCESS,  /* ok */
125     BEND_SCAN_PARTIAL   /* not all entries could be found */
126 } bend_scan_status;
127
128 typedef struct bend_scan_rr {
129     int num_bases;      /* number of elements in databaselist */
130     char **basenames;   /* databases to search */
131     oid_value attributeset;
132     Z_ReferenceId *referenceId; /* reference ID */
133     Z_AttributesPlusTerm *term;
134     ODR stream;         /* encoding stream - memory source if required */
135     ODR print;          /* printing stream */
136
137     int *step_size;     /* step size */
138     int term_position;  /* desired index of term in result list/returned */
139     int num_entries;    /* number of entries requested/returned */
140
141     /* scan term entries. The called handler does not have
142        to allocate this. Size of entries is num_entries (see above) */
143     struct scan_entry *entries;
144     bend_scan_status status;
145     int errcode;
146     char *errstring;
147     char *scanClause;   /* CQL scan clause */
148 } bend_scan_rr;
149
150 typedef struct bend_update_rr {
151     int num_bases;      /* number of elements in databaselist */
152     char **basenames;   /* databases to search */
153     Z_ReferenceId *referenceId; /* reference ID */
154     ODR stream;         /* encoding stream - memory source if required */
155     ODR print;          /* printing stream */
156     char *operation;
157     char *operation_status;
158     char *record_id;
159     Z_SRW_recordVersion *record_versions;
160     int num_versions;
161     char *record_packing;
162     char *record_schema;
163     char *record_data;
164     char *extra_record_data;
165     char *extra_request_data;
166     char *extra_response_data;
167     char *uri;
168     char *message;
169     char *details;
170 } bend_update_rr;
171
172 /* delete handler */
173 typedef struct bend_delete_rr {
174     int function;
175     int num_setnames;
176     char **setnames;
177     Z_ReferenceId *referenceId;
178     int delete_status;      /* status for the whole operation */
179     int *statuses;          /* status each set - indexed as setnames */
180     ODR stream;
181     ODR print; 
182 } bend_delete_rr;
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     ODR print;
193     Z_ReferenceId *referenceId;/* reference ID */
194
195     int sort_status;
196     int errcode;
197     char *errstring;
198 } bend_sort_rr;
199
200 typedef struct bend_esrequest_rr
201 {
202     int ItemNo;
203     Z_ExtendedServicesRequest *esr;
204     
205     ODR stream;                /* encoding stream */
206     ODR decode;                /* decoding stream */
207     ODR print;                 /* printing stream */
208     Z_ReferenceId *referenceId;/* reference ID */
209     bend_request request;
210     bend_association association;
211     int errcode;               /* 0==success, -1==accepted, >0 = failure */
212     char *errstring;           /* system error string or NULL */
213     Z_TaskPackage *taskPackage;
214 } bend_esrequest_rr;
215
216 typedef struct bend_segment_rr {
217     Z_Segment *segment;
218     ODR stream;
219     ODR decode;
220     ODR print;
221     bend_request request;
222     bend_association association;
223 } bend_segment_rr;
224
225 typedef struct {
226     ODR stream;
227     ODR decode;
228     ODR print;
229     char *explain_buf;
230     char *database;
231     char *schema;
232     void *server_node_ptr;
233 } bend_explain_rr;
234
235 typedef struct bend_initrequest
236 {
237     Z_IdAuthentication *auth;
238     ODR stream;                /* encoding stream */
239     ODR print;                 /* printing stream */
240     Z_ReferenceId *referenceId;/* reference ID */
241     char *peer_name;           /* dns host of peer (client) */
242     
243     char *implementation_id;
244     char *implementation_name;
245     char *implementation_version;
246     int (*bend_sort) (void *handle, bend_sort_rr *rr);
247     int (*bend_search) (void *handle, bend_search_rr *rr);
248     int (*bend_fetch) (void *handle, bend_fetch_rr *rr);
249     int (*bend_present) (void *handle, bend_present_rr *rr);
250     int (*bend_esrequest) (void *handle, bend_esrequest_rr *rr);
251     int (*bend_delete)(void *handle, bend_delete_rr *rr);
252     int (*bend_scan)(void *handle, bend_scan_rr *rr);
253     int (*bend_segment)(void *handle, bend_segment_rr *rr);
254
255     ODR decode;                 /* decoding stream */
256     /* character set and language negotiation - see include/yaz/z-charneg.h */
257     Z_CharSetandLanguageNegotiation *charneg_request;
258     Z_External *charneg_response;
259     int (*bend_explain)(void *handle, bend_explain_rr *rr);
260     int (*bend_srw_scan)(void *handle, bend_scan_rr *rr);
261     int (*bend_srw_update)(void *handle, bend_update_rr *rr);
262 } bend_initrequest;
263
264 typedef struct bend_initresult
265 {
266     int errcode;               /* 0==OK */
267     char *errstring;           /* system error string or NULL */
268     void *handle;              /* private handle to the backend module */
269 } bend_initresult;
270
271 YAZ_EXPORT void bend_request_send (bend_association a, bend_request req,
272                                    Z_APDU *res);
273
274 YAZ_EXPORT bend_request bend_request_mk (bend_association a);
275
276 YAZ_EXPORT void bend_request_destroy (bend_request *req);
277
278 YAZ_EXPORT Z_ReferenceId *bend_request_getid (ODR odr, bend_request req);
279 YAZ_EXPORT int bend_backend_respond (bend_association a, bend_request req);
280 YAZ_EXPORT void bend_request_setdata(bend_request r, void *p);
281 YAZ_EXPORT void *bend_request_getdata(bend_request r);
282
283 typedef struct statserv_options_block
284 {
285     int dynamic;                  /* fork on incoming requests */
286     int threads;                  /* use threads */
287     int one_shot;                 /* one session then exit(1) */
288     int __UNUSED__loglevel;       /* desired logging-level */
289     char apdufile[ODR_MAXNAME+1]; /* file for pretty-printed PDUs */
290     char logfile[ODR_MAXNAME+1];  /* file for diagnostic output */
291     char default_listen[1024];    /* 0 == no default listen */
292     enum oid_proto default_proto; /* PROTO_SR or PROTO_Z3950 */
293     int idle_timeout;             /* how many minutes to wait before closing */
294     int maxrecordsize;            /* maximum value for negotiation */
295     char configname[ODR_MAXNAME+1];  /* given to the backend in bend_init */
296     char setuid[ODR_MAXNAME+1];     /* setuid to this user after binding */
297     void (*bend_start)(struct statserv_options_block *p);
298     void (*bend_stop)(struct statserv_options_block *p);
299     int (*options_func)(int argc, char **argv);
300     int (*check_ip)(void *cd, const char *addr, int len, int type);
301     char daemon_name[128];
302     int inetd;                    /* Do we use the inet deamon or not */
303
304     void *handle;                 /* Handle */
305     bend_initresult *(*bend_init)(bend_initrequest *r);
306     void (*bend_close)(void *handle);
307 #ifdef WIN32
308     /* We only have these members for the windows version */
309     /* They seemed a bit large to have them there in general */
310     char service_name[128];         /* NT Service Name */
311     char app_name[128];             /* Application Name */
312     char service_dependencies[128]; /* The services we are dependent on */
313     char service_display_name[128]; /* The service display name */
314 #endif /* WIN32 */
315     struct bend_soap_handler *soap_handlers;
316     char pid_fname[128];            /* pid fname */
317     int background;                 /* auto daemon */
318     char cert_fname[128];           /* SSL certificate fname */
319     char xml_config[128];           /* XML config filename */
320 } statserv_options_block;
321
322 YAZ_EXPORT int statserv_main(
323     int argc, char **argv,
324     bend_initresult *(*bend_init)(bend_initrequest *r),
325     void (*bend_close)(void *handle));
326 YAZ_EXPORT int statserv_start(int argc, char **argv);
327 YAZ_EXPORT void statserv_closedown(void);
328 YAZ_EXPORT statserv_options_block *statserv_getcontrol(void);
329 YAZ_EXPORT void statserv_setcontrol(statserv_options_block *block);
330 YAZ_EXPORT int check_ip_tcpd(void *cd, const char *addr, int len, int type);
331
332 YAZ_EXPORT int bend_assoc_is_alive(bend_association assoc);
333
334 YAZ_END_CDECL
335
336 #endif
337 /*
338  * Local variables:
339  * c-basic-offset: 4
340  * indent-tabs-mode: nil
341  * End:
342  * vim: shiftwidth=4 tabstop=8 expandtab
343  */
344