2 * Copyright (c) 1995-2004, Index Data.
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,
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.
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.
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
26 * $Id: backend.h,v 1.24 2004-02-16 17:57:05 adam Exp $
32 #include <yaz/yconfig.h>
33 #include <yaz/proto.h>
37 typedef struct request *bend_request;
38 typedef struct association *bend_association;
40 /* extended search handler (rr = request response) */
42 char *setname; /* name to give to this set */
43 int replace_set; /* replace set, if it already exists */
44 int num_bases; /* number of databases in list */
45 char **basenames; /* databases to search */
46 Z_ReferenceId *referenceId;/* reference ID */
47 Z_Query *query; /* query structure */
48 ODR stream; /* encode stream */
49 ODR decode; /* decode stream */
50 ODR print; /* print stream */
53 bend_association association;
55 int hits; /* number of hits */
56 int errcode; /* 0==OK */
57 char *errstring; /* system error string or NULL */
58 Z_OtherInformation *search_info; /* additional search info */
61 /* extended present handler. Does not replace bend_fetch. */
63 char *setname; /* set name */
65 int number; /* record number */
66 oid_value format; /* One of the CLASS_RECSYN members */
67 Z_ReferenceId *referenceId;/* reference ID */
68 Z_RecordComposition *comp; /* Formatting instructions */
69 ODR stream; /* encoding stream - memory source if required */
70 ODR print; /* printing stream */
72 bend_association association;
74 int hits; /* number of hits */
75 int errcode; /* 0==OK */
76 char *errstring; /* system error string or NULL */
79 typedef struct bend_fetch_rr {
80 char *setname; /* set name */
81 int number; /* record number */
82 Z_ReferenceId *referenceId;/* reference ID */
83 oid_value request_format; /* One of the CLASS_RECSYN members */
84 int *request_format_raw; /* same as above (raw OID) */
85 Z_RecordComposition *comp; /* Formatting instructions */
86 ODR stream; /* encoding stream - memory source if req */
87 ODR print; /* printing stream */
89 char *basename; /* name of database that provided record */
90 int len; /* length of record or -1 if structured */
91 char *record; /* record */
92 int last_in_set; /* is it? */
93 oid_value output_format; /* format */
94 int *output_format_raw; /* used instead of above if not-null */
95 int errcode; /* 0==success */
96 char *errstring; /* system error string or NULL */
97 int surrogate_flag; /* surrogate diagnostic */
98 char *schema; /* string record schema input/output */
102 char *term; /* the returned scan term */
103 int occurrences; /* no of occurrences or -1 if error (see below) */
104 int errcode; /* Bib-1 diagnostic code; only used when occur.= -1 */
105 char *errstring; /* Additional string */
110 BEND_SCAN_SUCCESS, /* ok */
111 BEND_SCAN_PARTIAL /* not all entries could be found */
114 typedef struct bend_scan_rr {
115 int num_bases; /* number of elements in databaselist */
116 char **basenames; /* databases to search */
117 oid_value attributeset;
118 Z_ReferenceId *referenceId; /* reference ID */
119 Z_AttributesPlusTerm *term;
120 ODR stream; /* encoding stream - memory source if required */
121 ODR print; /* printing stream */
123 int *step_size; /* step size */
124 int term_position; /* desired index of term in result list/returned */
125 int num_entries; /* number of entries requested/returned */
127 /* scan term entries. The called handler does not have
128 to allocate this. Size of entries is num_entries (see above) */
129 struct scan_entry *entries;
130 bend_scan_status status;
136 typedef struct bend_delete_rr {
140 Z_ReferenceId *referenceId;
141 int delete_status; /* status for the whole operation */
142 int *statuses; /* status each set - indexed as setnames */
148 typedef struct bend_sort_rr
150 int num_input_setnames;
151 char **input_setnames;
152 char *output_setname;
153 Z_SortKeySpecList *sort_sequence;
156 Z_ReferenceId *referenceId;/* reference ID */
163 typedef struct bend_esrequest_rr
166 Z_ExtendedServicesRequest *esr;
168 ODR stream; /* encoding stream */
169 ODR decode; /* decoding stream */
170 ODR print; /* printing stream */
171 Z_ReferenceId *referenceId;/* reference ID */
172 bend_request request;
173 bend_association association;
174 int errcode; /* 0==success, -1==accepted, >0 = failure */
175 char *errstring; /* system error string or NULL */
176 Z_TaskPackage *taskPackage;
179 typedef struct bend_segment_rr {
184 bend_request request;
185 bend_association association;
197 typedef struct bend_initrequest
199 Z_IdAuthentication *auth;
200 ODR stream; /* encoding stream */
201 ODR print; /* printing stream */
202 Z_ReferenceId *referenceId;/* reference ID */
203 char *peer_name; /* dns host of peer (client) */
205 char *implementation_id;
206 char *implementation_name;
207 char *implementation_version;
208 int (*bend_sort) (void *handle, bend_sort_rr *rr);
209 int (*bend_search) (void *handle, bend_search_rr *rr);
210 int (*bend_fetch) (void *handle, bend_fetch_rr *rr);
211 int (*bend_present) (void *handle, bend_present_rr *rr);
212 int (*bend_esrequest) (void *handle, bend_esrequest_rr *rr);
213 int (*bend_delete)(void *handle, bend_delete_rr *rr);
214 int (*bend_scan)(void *handle, bend_scan_rr *rr);
215 int (*bend_segment)(void *handle, bend_segment_rr *rr);
217 ODR decode; /* decoding stream */
218 /* character set and language negotiation - see include/yaz/z-charneg.h */
219 Z_CharSetandLanguageNegotiation *charneg_request;
220 Z_External *charneg_response;
221 int (*bend_explain)(void *handle, bend_explain_rr *rr);
224 typedef struct bend_initresult
226 int errcode; /* 0==OK */
227 char *errstring; /* system error string or NULL */
228 void *handle; /* private handle to the backend module */
231 YAZ_EXPORT void bend_request_send (bend_association a, bend_request req,
234 YAZ_EXPORT bend_request bend_request_mk (bend_association a);
236 YAZ_EXPORT void bend_request_destroy (bend_request *req);
238 YAZ_EXPORT Z_ReferenceId *bend_request_getid (ODR odr, bend_request req);
239 YAZ_EXPORT int bend_backend_respond (bend_association a, bend_request req);
240 YAZ_EXPORT void bend_request_setdata(bend_request r, void *p);
241 YAZ_EXPORT void *bend_request_getdata(bend_request r);
243 typedef struct statserv_options_block
245 int dynamic; /* fork on incoming requests */
246 int threads; /* use threads */
247 int one_shot; /* one session then exit(1) */
248 int loglevel; /* desired logging-level */
249 char apdufile[ODR_MAXNAME+1]; /* file for pretty-printed PDUs */
250 char logfile[ODR_MAXNAME+1]; /* file for diagnostic output */
251 char default_listen[1024]; /* 0 == no default listen */
252 enum oid_proto default_proto; /* PROTO_SR or PROTO_Z3950 */
253 int idle_timeout; /* how many minutes to wait before closing */
254 int maxrecordsize; /* maximum value for negotiation */
255 char configname[ODR_MAXNAME+1]; /* given to the backend in bend_init */
256 char setuid[ODR_MAXNAME+1]; /* setuid to this user after binding */
257 void (*bend_start)(struct statserv_options_block *p);
258 void (*bend_stop)(struct statserv_options_block *p);
259 int (*options_func)(int argc, char **argv);
260 int (*check_ip)(void *cd, const char *addr, int len, int type);
261 char daemon_name[128];
262 int inetd; /* Do we use the inet deamon or not */
264 void *handle; /* Handle */
265 bend_initresult *(*bend_init)(bend_initrequest *r);
266 void (*bend_close)(void *handle);
268 /* We only have these members for the windows version */
269 /* They seemed a bit large to have them there in general */
270 char service_name[128]; /* NT Service Name */
271 char app_name[128]; /* Application Name */
272 char service_dependencies[128]; /* The services we are dependent on */
273 char service_display_name[128]; /* The service display name */
275 struct bend_soap_handler *soap_handlers;
276 char pid_fname[128]; /* pid fname */
277 int background; /* auto daemon */
278 } statserv_options_block;
280 YAZ_EXPORT int statserv_main(
281 int argc, char **argv,
282 bend_initresult *(*bend_init)(bend_initrequest *r),
283 void (*bend_close)(void *handle));
284 YAZ_EXPORT int statserv_start(int argc, char **argv);
285 YAZ_EXPORT void statserv_closedown(void);
286 YAZ_EXPORT statserv_options_block *statserv_getcontrol(void);
287 YAZ_EXPORT void statserv_setcontrol(statserv_options_block *block);
288 YAZ_EXPORT int check_ip_tcpd(void *cd, const char *addr, int len, int type);