2 * Copyright (C) 1995-1999, Index Data
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.67 1999-02-02 14:51:14 adam
8 * Updated WIN32 code specific sections. Changed header.
10 * Revision 1.66 1998/10/28 10:54:41 adam
13 * Revision 1.65 1998/10/18 07:54:54 adam
14 * Additional info added for diagnostics 114 (Unsupported use attribute) and
15 * 121 (Unsupported attribute set).
17 * Revision 1.64 1998/09/22 10:48:21 adam
18 * Minor changes in search API.
20 * Revision 1.63 1998/09/02 13:53:21 adam
21 * Extra parameter decode added to search routines to implement
24 * Revision 1.62 1998/08/06 14:35:28 adam
25 * Routine bend_deleterequest removed.
27 * Revision 1.61 1998/06/24 12:16:15 adam
28 * Support for relations on text operands. Open range support in
29 * DFA module (i.e. [-j], [g-]).
31 * Revision 1.60 1998/06/22 11:36:49 adam
32 * Added authentication check facility to zebra.
34 * Revision 1.59 1998/06/12 12:22:13 adam
37 * Revision 1.58 1998/05/27 16:57:46 adam
38 * Zebra returns surrogate diagnostic for single records when
41 * Revision 1.57 1998/04/03 14:45:18 adam
42 * Fixed setting of last_in_set in bend_fetch.
44 * Revision 1.56 1998/03/05 08:45:13 adam
45 * New result set model and modular ranking system. Moved towards
46 * descent server API. System information stored as "SGML" records.
48 * Revision 1.55 1998/02/10 12:03:06 adam
51 * Revision 1.54 1998/01/29 13:39:13 adam
52 * Compress ISAM is default.
54 * Revision 1.53 1998/01/12 15:04:09 adam
55 * The test option (-s) only uses read-lock (and not write lock).
57 * Revision 1.52 1997/11/18 10:05:08 adam
58 * Changed character map facility so that admin can specify character
59 * mapping files for each register type, w, p, etc.
61 * Revision 1.51 1997/10/27 14:33:06 adam
62 * Moved towards generic character mapping depending on "structure"
63 * field in abstract syntax file. Fixed a few memory leaks. Fixed
64 * bug with negative integers when doing searches with relational
67 * Revision 1.50 1997/09/29 09:08:36 adam
68 * Revised locking system to be thread safe for the server.
70 * Revision 1.49 1997/09/25 14:57:23 adam
73 * Revision 1.48 1997/09/17 12:19:19 adam
74 * Zebra version corresponds to YAZ version 1.4.
75 * Changed Zebra server so that it doesn't depend on global common_resource.
77 * Revision 1.47 1997/09/04 13:58:36 adam
78 * New retrieve/extract method tellf (added).
79 * Added O_BINARY for open calls.
81 * Revision 1.46 1997/07/28 08:30:47 adam
82 * Server returns diagnostic 14 when record doesn't exist.
84 * Revision 1.45 1996/12/23 15:30:45 adam
86 * Bug fix: result sets weren't deleted after server shut down.
88 * Revision 1.44 1996/12/11 12:08:01 adam
89 * Added better compression.
91 * Revision 1.43 1996/11/15 15:03:58 adam
92 * Logging of execution speed by using the times(2) call.
94 * Revision 1.42 1996/11/08 11:10:36 adam
95 * Buffers used during file match got bigger.
96 * Compressed ISAM support everywhere.
97 * Bug fixes regarding masking characters in queries.
98 * Redesigned Regexp-2 queries.
100 * Revision 1.41 1996/10/29 14:09:56 adam
101 * Use of cisam system - enabled if setting isamc is 1.
103 * Revision 1.40 1996/06/04 10:19:02 adam
104 * Minor changes - removed include of ctype.h.
106 * Revision 1.39 1996/05/31 09:07:05 quinn
107 * Work on character-set handling
109 * Revision 1.38 1996/05/14 11:34:01 adam
110 * Scan support in multiple registers/databases.
112 * Revision 1.37 1996/05/14 06:16:48 adam
113 * Compact use/set bytes used in search service.
115 * Revision 1.36 1996/05/01 13:46:37 adam
116 * First work on multiple records in one file.
117 * New option, -offset, to the "unread" command in the filter module.
119 * Revision 1.35 1996/03/26 16:01:14 adam
120 * New setting lockPath: directory of various lock files.
122 * Revision 1.34 1996/03/20 09:36:46 adam
123 * Function dict_lookup_grep got extra parameter, init_pos, which marks
124 * from which position in pattern approximate pattern matching should occur.
125 * Approximate pattern matching is used in relevance=re-2.
127 * Revision 1.33 1996/01/17 14:57:56 adam
128 * Prototype changed for reader functions in extract/retrieve. File
129 * is identified by 'void *' instead of 'int.
131 * Revision 1.32 1995/12/11 09:12:58 adam
132 * The rec_get function returns NULL if record doesn't exist - will
133 * happen in the server if the result set records have been deleted since
134 * the creation of the set (i.e. the search).
135 * The server saves a result temporarily if it is 'volatile', i.e. the
136 * set is register dependent.
138 * Revision 1.31 1995/12/08 16:22:56 adam
139 * Work on update while servers are running. Three lock files introduced.
140 * The servers reload their registers when necessary, but they don't
141 * reestablish result sets yet.
143 * Revision 1.30 1995/12/07 17:38:48 adam
144 * Work locking mechanisms for concurrent updates/commit.
146 * Revision 1.29 1995/12/04 14:22:32 adam
147 * Extra arg to recType_byName.
148 * Started work on new regular expression parsed input to
149 * structured records.
151 * Revision 1.28 1995/11/28 09:09:48 adam
152 * Zebra config renamed.
153 * Use setting 'recordId' to identify record now.
154 * Bug fix in recindex.c: rec_release_blocks was invokeded even
155 * though the blocks were already released.
156 * File traversal properly deletes records when needed.
158 * Revision 1.27 1995/11/27 13:58:54 adam
159 * New option -t. storeStore data implemented in server.
161 * Revision 1.26 1995/11/25 10:24:07 adam
162 * More record fields - they are enumerated now.
163 * New options: flagStoreData flagStoreKey.
165 * Revision 1.25 1995/11/21 15:29:13 adam
166 * Config file 'base' read by default by both indexer and server.
168 * Revision 1.24 1995/11/20 16:59:47 adam
169 * New update method: the 'old' keys are saved for each records.
171 * Revision 1.23 1995/11/16 17:00:56 adam
172 * Better logging of rpn query.
174 * Revision 1.22 1995/11/16 15:34:55 adam
175 * Uses new record management system in both indexer and server.
177 * Revision 1.21 1995/11/01 16:25:52 quinn
178 * *** empty log message ***
180 * Revision 1.20 1995/10/27 14:00:12 adam
181 * Implemented detection of database availability.
183 * Revision 1.19 1995/10/17 18:02:11 adam
184 * New feature: databases. Implemented as prefix to words in dictionary.
186 * Revision 1.18 1995/10/16 14:03:09 quinn
187 * Changes to support element set names and espec1
189 * Revision 1.17 1995/10/16 09:32:40 adam
190 * More work on relational op.
192 * Revision 1.16 1995/10/13 12:26:44 adam
193 * Optimization of truncation.
195 * Revision 1.15 1995/10/12 12:40:55 adam
196 * Bug fixes in rpn_prox.
198 * Revision 1.14 1995/10/09 16:18:37 adam
199 * Function dict_lookup_grep got extra client data parameter.
201 * Revision 1.13 1995/10/06 14:38:00 adam
202 * New result set method: r_score.
203 * Local no (sysno) and score is transferred to retrieveCtrl.
205 * Revision 1.12 1995/10/06 13:52:06 adam
206 * Bug fixes. Handler may abort further scanning.
208 * Revision 1.11 1995/10/06 10:43:57 adam
209 * Scan added. 'occurrences' in scan entries not set yet.
211 * Revision 1.10 1995/10/02 16:43:32 quinn
212 * Set default resulting record type in fetch.
214 * Revision 1.9 1995/10/02 15:18:52 adam
215 * New member in recRetrieveCtrl: diagnostic.
217 * Revision 1.8 1995/09/28 09:19:47 adam
218 * xfree/xmalloc used everywhere.
219 * Extract/retrieve method seems to work for text records.
221 * Revision 1.7 1995/09/27 16:17:32 adam
222 * More work on retrieve.
224 * Revision 1.6 1995/09/08 08:53:22 adam
225 * Record buffer maintained in server_info.
227 * Revision 1.5 1995/09/06 16:11:18 adam
228 * Option: only one word key per file.
230 * Revision 1.4 1995/09/06 10:33:04 adam
231 * More work on present. Some log messages removed.
233 * Revision 1.3 1995/09/05 15:28:40 adam
234 * More work on search engine.
236 * Revision 1.2 1995/09/04 12:33:43 adam
237 * Various cleanup. YAZ util used instead.
239 * Revision 1.1 1995/09/04 09:10:41 adam
240 * More work on index add/del/update.
241 * Merge sort implemented.
242 * Initial work on z39 server.
265 #include "zebrasdr.h"
268 static int bend_sort (void *handle, bend_sort_rr *rr);
270 bend_initresult *bend_init (bend_initrequest *q)
272 bend_initresult *r = odr_malloc (q->stream, sizeof(*r));
274 struct statserv_options_block *sob;
280 q->bend_sort = bend_sort;
282 logf (LOG_DEBUG, "bend_init");
284 sob = statserv_getcontrol ();
285 if (!(zh = zebra_open (sob->configname)))
287 logf (LOG_FATAL, "Failed to open Zebra `%s'", sob->configname);
293 if (q->auth->which == Z_IdAuthentication_open)
295 char *openpass = xstrdup (q->auth->u.open);
296 char *cp = strchr (openpass, '/');
300 user = nmem_strdup (odr_getmem (q->stream), openpass);
301 passwd = nmem_strdup (odr_getmem (q->stream), cp+1);
306 if (zebra_auth (zh, user, passwd))
317 bend_searchresult *bend_search (void *handle, bend_searchrequest *q, int *fd)
319 ZebraHandle zh = handle;
320 bend_searchresult *r = odr_malloc (q->stream, sizeof(*r));
326 logf (LOG_LOG, "ResultSet '%s'", q->setname);
327 switch (q->query->which)
329 case Z_Query_type_1: case Z_Query_type_101:
330 zebra_search_rpn (zh, q->decode, q->stream, q->query->u.type_1,
331 q->num_bases, q->basenames, q->setname);
332 r->errcode = zh->errCode;
333 r->errstring = zh->errString;
338 r->errstring = "type-2";
346 bend_fetchresult *bend_fetch (void *handle, bend_fetchrequest *q, int *num)
348 ZebraHandle zh = handle;
349 bend_fetchresult *r = odr_malloc (q->stream, sizeof(*r));
350 ZebraRetrievalRecord retrievalRecord;
352 retrievalRecord.position = q->number;
355 zebra_records_retrieve (zh, q->stream, q->setname, q->comp,
356 q->format, 1, &retrievalRecord);
357 if (zh->errCode) /* non Surrogate Diagnostic */
359 r->errcode = zh->errCode;
360 r->errstring = zh->errString;
362 else if (retrievalRecord.errCode) /* Surrogate Diagnostic */
364 q->surrogate_flag = 1;
365 r->errcode = retrievalRecord.errCode;
366 r->errstring = retrievalRecord.errString;
367 r->basename = retrievalRecord.base;
369 else /* Database Record */
372 r->basename = retrievalRecord.base;
373 r->record = retrievalRecord.buf;
374 r->len = retrievalRecord.len;
375 r->format = retrievalRecord.format;
380 bend_scanresult *bend_scan (void *handle, bend_scanrequest *q, int *num)
382 ZebraScanEntry *entries;
383 ZebraHandle zh = handle;
384 bend_scanresult *r = odr_malloc (q->stream, sizeof(*r));
387 r->term_position = q->term_position;
388 r->num_entries = q->num_entries;
390 r->entries = odr_malloc (q->stream, sizeof(*r->entries) * q->num_entries);
391 zebra_scan (zh, q->stream, q->term,
393 q->num_bases, q->basenames,
395 &r->num_entries, &entries, &is_partial);
397 r->status = BEND_SCAN_PARTIAL;
399 r->status = BEND_SCAN_SUCCESS;
400 for (i = 0; i < r->num_entries; i++)
402 r->entries[i].term = entries[i].term;
403 r->entries[i].occurrences = entries[i].occurrences;
405 r->errcode = zh->errCode;
406 r->errstring = zh->errString;
410 void bend_close (void *handle)
412 zebra_close ((ZebraHandle) handle);
415 int bend_sort (void *handle, bend_sort_rr *rr)
417 ZebraHandle zh = handle;
419 zebra_sort (zh, rr->stream,
420 rr->num_input_setnames, (const char **) rr->input_setnames,
421 rr->output_setname, rr->sort_sequence, &rr->sort_status);
422 rr->errcode = zh->errCode;
423 rr->errstring = zh->errString;
428 static void pre_init (struct statserv_options_block *sob)
430 char *pidfile = "zebrasrv.pid";
431 int fd = creat (pidfile, 0666);
434 logf (LOG_WARN|LOG_ERRNO, "creat %s", pidfile);
439 sprintf (pidstr, "%ld", (long) getpid ());
440 write (fd, pidstr, strlen(pidstr));
446 int main (int argc, char **argv)
448 struct statserv_options_block *sob;
450 sob = statserv_getcontrol ();
451 strcpy (sob->configname, FNAME_CONFIG);
453 sob->pre_init = pre_init;
455 statserv_setcontrol (sob);
460 return statserv_main (argc, argv);