1 | /*
|
---|
2 | * Copyright (c) 1995-2000, Index Data.
|
---|
3 | * See the file LICENSE for details.
|
---|
4 | *
|
---|
5 | * NT Service interface by
|
---|
6 | * Chas Woodfield, Fretwell Downing Datasystems.
|
---|
7 | *
|
---|
8 | * $Log$
|
---|
9 | * Revision 1.1 2000/08/03 03:12:33 johnmcp
|
---|
10 | * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
|
---|
11 | *
|
---|
12 | * Revision 1.31 2000/01/31 13:15:21 adam
|
---|
13 | * Removed uses of assert(3). Cleanup of ODR. CCL parser update so
|
---|
14 | * that some characters are not surrounded by spaces in resulting term.
|
---|
15 | * ILL-code updates.
|
---|
16 | *
|
---|
17 | * Revision 1.30 2000/01/13 23:05:50 adam
|
---|
18 | * Fixed tagging for member requester-CHECKED-IN in ILL ASN.1 spec.
|
---|
19 | *
|
---|
20 | * Revision 1.29 2000/01/12 14:36:07 adam
|
---|
21 | * Added printing stream (ODR) for backend functions.
|
---|
22 | *
|
---|
23 | * Revision 1.28 1999/12/16 23:36:19 adam
|
---|
24 | * Implemented ILL protocol. Minor updates ASN.1 compiler.
|
---|
25 | *
|
---|
26 | * Revision 1.27 1999/11/30 13:47:12 adam
|
---|
27 | * Improved installation. Moved header files to include/yaz.
|
---|
28 | *
|
---|
29 | * Revision 1.26 1999/08/27 09:40:32 adam
|
---|
30 | * Renamed logf function to yaz_log. Removed VC++ project files.
|
---|
31 | *
|
---|
32 | * Revision 1.25 1999/06/01 14:29:12 adam
|
---|
33 | * Work on Extended Services.
|
---|
34 | *
|
---|
35 | * Revision 1.24 1999/05/27 13:07:54 adam
|
---|
36 | * Fix.
|
---|
37 | *
|
---|
38 | * Revision 1.23 1999/05/27 13:02:20 adam
|
---|
39 | * Assigned OID for old DB Update (VAL_DBUPDATE0).
|
---|
40 | *
|
---|
41 | * Revision 1.22 1999/05/26 13:49:12 adam
|
---|
42 | * DB Update implemented in client (very basic).
|
---|
43 | *
|
---|
44 | * Revision 1.21 1998/12/15 12:45:42 adam
|
---|
45 | * Minor change.
|
---|
46 | *
|
---|
47 | * Revision 1.20 1998/12/14 14:48:05 adam
|
---|
48 | * Fixed memory leak - happened when fetching MARC records.
|
---|
49 | *
|
---|
50 | * Revision 1.19 1998/10/20 15:16:22 adam
|
---|
51 | * Minor change to prevent warning.
|
---|
52 | *
|
---|
53 | * Revision 1.18 1998/10/20 15:13:45 adam
|
---|
54 | * Minor fix regarding output for Item Order.
|
---|
55 | *
|
---|
56 | * Revision 1.17 1998/10/18 22:33:35 quinn
|
---|
57 | * Added diagnostic dump of Item Order Eservice.
|
---|
58 | *
|
---|
59 | * Revision 1.16 1998/10/15 08:26:23 adam
|
---|
60 | * Added type cast to make C++ happy.
|
---|
61 | *
|
---|
62 | * Revision 1.15 1998/10/13 20:05:57 adam
|
---|
63 | * Minor change.
|
---|
64 | *
|
---|
65 | * Revision 1.14 1998/10/13 16:12:25 adam
|
---|
66 | * Added support for Surrogate Diagnostics for Scan Term entries.
|
---|
67 | *
|
---|
68 | * Revision 1.13 1998/08/19 16:10:09 adam
|
---|
69 | * Changed som member names of DeleteResultSetRequest/Response.
|
---|
70 | *
|
---|
71 | * Revision 1.12 1998/07/20 12:38:44 adam
|
---|
72 | * Implemented delete result set service to server API.
|
---|
73 | *
|
---|
74 | * Revision 1.11 1998/06/09 13:55:08 adam
|
---|
75 | * Minor changes.
|
---|
76 | *
|
---|
77 | * Revision 1.10 1998/05/27 16:55:54 adam
|
---|
78 | * Minor changes.
|
---|
79 | *
|
---|
80 | * Revision 1.9 1998/03/31 11:07:45 adam
|
---|
81 | * Furhter work on UNIverse resource report.
|
---|
82 | * Added Extended Services handling in frontend server.
|
---|
83 | *
|
---|
84 | * Revision 1.8 1998/02/11 11:53:36 adam
|
---|
85 | * Changed code so that it compiles as C++.
|
---|
86 | *
|
---|
87 | * Revision 1.7 1998/02/10 11:03:57 adam
|
---|
88 | * Added support for extended handlers in backend server interface.
|
---|
89 | *
|
---|
90 | * Revision 1.6 1998/01/29 13:16:02 adam
|
---|
91 | * Added dummy sort in test server.
|
---|
92 | *
|
---|
93 | * Revision 1.5 1997/11/07 13:31:58 adam
|
---|
94 | * Added NT Service name part of statserv_options_block. Moved NT
|
---|
95 | * service utility to server library.
|
---|
96 | *
|
---|
97 | * Revision 1.4 1997/09/17 12:10:43 adam
|
---|
98 | * YAZ version 1.4.
|
---|
99 | *
|
---|
100 | * Revision 1.3 1997/09/09 10:10:20 adam
|
---|
101 | * Another MSV5.0 port. Changed projects to include proper
|
---|
102 | * library/include paths.
|
---|
103 | * Server starts server in test-mode when no options are given.
|
---|
104 | *
|
---|
105 | * Revision 1.2 1997/09/04 13:50:31 adam
|
---|
106 | * Bug fix in ztest.
|
---|
107 | *
|
---|
108 | */
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * Demonstration of simple server
|
---|
112 | */
|
---|
113 |
|
---|
114 | #include <stdio.h>
|
---|
115 | #include <stdlib.h>
|
---|
116 | #include <ctype.h>
|
---|
117 |
|
---|
118 | #include <yaz/backend.h>
|
---|
119 | #include <yaz/log.h>
|
---|
120 |
|
---|
121 | #ifdef ASN_COMPILED
|
---|
122 | #include <yaz/ill.h>
|
---|
123 | #endif
|
---|
124 |
|
---|
125 | Z_GenericRecord *read_grs1(FILE *f, ODR o);
|
---|
126 |
|
---|
127 | int ztest_search (void *handle, bend_search_rr *rr);
|
---|
128 | int ztest_sort (void *handle, bend_sort_rr *rr);
|
---|
129 | int ztest_present (void *handle, bend_present_rr *rr);
|
---|
130 | int ztest_esrequest (void *handle, bend_esrequest_rr *rr);
|
---|
131 | int ztest_delete (void *handle, bend_delete_rr *rr);
|
---|
132 |
|
---|
133 | bend_initresult *bend_init(bend_initrequest *q)
|
---|
134 | {
|
---|
135 | bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r));
|
---|
136 | static char *dummy = "Hej fister";
|
---|
137 |
|
---|
138 | r->errcode = 0;
|
---|
139 | r->errstring = 0;
|
---|
140 | r->handle = dummy;
|
---|
141 | q->bend_sort = ztest_sort; /* register sort handler */
|
---|
142 | q->bend_search = ztest_search; /* register search handler */
|
---|
143 | q->bend_present = ztest_present; /* register present handle */
|
---|
144 | q->bend_esrequest = ztest_esrequest;
|
---|
145 | q->bend_delete = ztest_delete;
|
---|
146 | return r;
|
---|
147 | }
|
---|
148 |
|
---|
149 | int ztest_search (void *handle, bend_search_rr *rr)
|
---|
150 | {
|
---|
151 | rr->hits = rand() % 22;
|
---|
152 | return 0;
|
---|
153 | }
|
---|
154 |
|
---|
155 | int ztest_present (void *handle, bend_present_rr *rr)
|
---|
156 | {
|
---|
157 | return 0;
|
---|
158 | }
|
---|
159 |
|
---|
160 | int ztest_esrequest (void *handle, bend_esrequest_rr *rr)
|
---|
161 | {
|
---|
162 | yaz_log(LOG_LOG, "function: %d", *rr->esr->function);
|
---|
163 | if (rr->esr->packageName)
|
---|
164 | yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);
|
---|
165 | yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);
|
---|
166 |
|
---|
167 | if (!rr->esr->taskSpecificParameters)
|
---|
168 | {
|
---|
169 | yaz_log (LOG_WARN, "No task specific parameters");
|
---|
170 | }
|
---|
171 | else if (rr->esr->taskSpecificParameters->which == Z_External_itemOrder)
|
---|
172 | {
|
---|
173 | Z_ItemOrder *it = rr->esr->taskSpecificParameters->u.itemOrder;
|
---|
174 | yaz_log (LOG_LOG, "Received ItemOrder");
|
---|
175 | switch (it->which)
|
---|
176 | {
|
---|
177 | #ifdef ASN_COMPILED
|
---|
178 | case Z_IOItemOrder_esRequest:
|
---|
179 | #else
|
---|
180 | case Z_ItemOrder_esRequest:
|
---|
181 | #endif
|
---|
182 | {
|
---|
183 | Z_IORequest *ir = it->u.esRequest;
|
---|
184 | Z_IOOriginPartToKeep *k = ir->toKeep;
|
---|
185 | Z_IOOriginPartNotToKeep *n = ir->notToKeep;
|
---|
186 |
|
---|
187 | if (k && k->contact)
|
---|
188 | {
|
---|
189 | if (k->contact->name)
|
---|
190 | yaz_log(LOG_LOG, "contact name %s", k->contact->name);
|
---|
191 | if (k->contact->phone)
|
---|
192 | yaz_log(LOG_LOG, "contact phone %s", k->contact->phone);
|
---|
193 | if (k->contact->email)
|
---|
194 | yaz_log(LOG_LOG, "contact email %s", k->contact->email);
|
---|
195 | }
|
---|
196 | if (k->addlBilling)
|
---|
197 | {
|
---|
198 | yaz_log(LOG_LOG, "Billing info (not shown)");
|
---|
199 | }
|
---|
200 |
|
---|
201 | if (n->resultSetItem)
|
---|
202 | {
|
---|
203 | yaz_log(LOG_LOG, "resultsetItem");
|
---|
204 | yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId);
|
---|
205 | yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item);
|
---|
206 | }
|
---|
207 | #ifdef ASN_COMPILED
|
---|
208 | if (n->itemRequest)
|
---|
209 | {
|
---|
210 | Z_External *r = (Z_External*) n->itemRequest;
|
---|
211 | ILL_ItemRequest *item_req = 0;
|
---|
212 | ILL_Request *ill_req = 0;
|
---|
213 | if (r->direct_reference)
|
---|
214 | {
|
---|
215 | oident *ent = oid_getentbyoid(r->direct_reference);
|
---|
216 | if (ent)
|
---|
217 | yaz_log(LOG_LOG, "OID %s", ent->desc);
|
---|
218 | if (ent && ent->value == VAL_ISO_ILL_1)
|
---|
219 | {
|
---|
220 | yaz_log (LOG_LOG, "ItemRequest");
|
---|
221 | if (r->which == ODR_EXTERNAL_single)
|
---|
222 | {
|
---|
223 | odr_setbuf(rr->decode,
|
---|
224 | r->u.single_ASN1_type->buf,
|
---|
225 | r->u.single_ASN1_type->len, 0);
|
---|
226 |
|
---|
227 | if (!ill_ItemRequest (rr->decode, &item_req, 0, 0))
|
---|
228 | {
|
---|
229 | yaz_log (LOG_LOG,
|
---|
230 | "Couldn't decode ItemRequest %s near %d",
|
---|
231 | odr_errmsg(odr_geterror(rr->decode)),
|
---|
232 | odr_offset(rr->decode));
|
---|
233 | yaz_log(LOG_LOG, "PDU dump:");
|
---|
234 | odr_dumpBER(log_file(),
|
---|
235 | r->u.single_ASN1_type->buf,
|
---|
236 | r->u.single_ASN1_type->len);
|
---|
237 | }
|
---|
238 | if (rr->print)
|
---|
239 | {
|
---|
240 | ill_ItemRequest (rr->print, &item_req, 0,
|
---|
241 | "ItemRequest");
|
---|
242 | odr_reset (rr->print);
|
---|
243 | }
|
---|
244 | }
|
---|
245 | if (!item_req && r->which == ODR_EXTERNAL_single)
|
---|
246 | {
|
---|
247 | yaz_log (LOG_LOG, "ILLRequest");
|
---|
248 | odr_setbuf(rr->decode,
|
---|
249 | r->u.single_ASN1_type->buf,
|
---|
250 | r->u.single_ASN1_type->len, 0);
|
---|
251 |
|
---|
252 | if (!ill_Request (rr->decode, &ill_req, 0, 0))
|
---|
253 | {
|
---|
254 | yaz_log (LOG_LOG,
|
---|
255 | "Couldn't decode ILLRequest %s near %d",
|
---|
256 | odr_errmsg(odr_geterror(rr->decode)),
|
---|
257 | odr_offset(rr->decode));
|
---|
258 | yaz_log(LOG_LOG, "PDU dump:");
|
---|
259 | odr_dumpBER(log_file(),
|
---|
260 | r->u.single_ASN1_type->buf,
|
---|
261 | r->u.single_ASN1_type->len);
|
---|
262 | }
|
---|
263 | if (rr->print)
|
---|
264 | {
|
---|
265 | ill_Request (rr->print, &ill_req, 0,
|
---|
266 | "ILLRequest");
|
---|
267 | odr_reset (rr->print);
|
---|
268 | }
|
---|
269 | }
|
---|
270 | }
|
---|
271 | }
|
---|
272 | if (item_req)
|
---|
273 | {
|
---|
274 | yaz_log (LOG_LOG, "ILL protocol version = %d",
|
---|
275 | *item_req->protocol_version_num);
|
---|
276 | }
|
---|
277 | }
|
---|
278 | #endif
|
---|
279 | }
|
---|
280 | break;
|
---|
281 | }
|
---|
282 | }
|
---|
283 | else if (rr->esr->taskSpecificParameters->which == Z_External_update)
|
---|
284 | {
|
---|
285 | Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;
|
---|
286 | yaz_log (LOG_LOG, "Received DB Update");
|
---|
287 | if (up->which == Z_IUUpdate_esRequest)
|
---|
288 | {
|
---|
289 | Z_IUUpdateEsRequest *esRequest = up->u.esRequest;
|
---|
290 | Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;
|
---|
291 | Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;
|
---|
292 |
|
---|
293 | yaz_log (LOG_LOG, "action");
|
---|
294 | if (toKeep->action)
|
---|
295 | {
|
---|
296 | switch (*toKeep->action)
|
---|
297 | {
|
---|
298 | case Z_IUOriginPartToKeep_recordInsert:
|
---|
299 | yaz_log (LOG_LOG, " recordInsert");
|
---|
300 | break;
|
---|
301 | case Z_IUOriginPartToKeep_recordReplace:
|
---|
302 | yaz_log (LOG_LOG, " recordUpdate");
|
---|
303 | break;
|
---|
304 | case Z_IUOriginPartToKeep_recordDelete:
|
---|
305 | yaz_log (LOG_LOG, " recordDelete");
|
---|
306 | break;
|
---|
307 | case Z_IUOriginPartToKeep_elementUpdate:
|
---|
308 | yaz_log (LOG_LOG, " elementUpdate");
|
---|
309 | break;
|
---|
310 | case Z_IUOriginPartToKeep_specialUpdate:
|
---|
311 | yaz_log (LOG_LOG, " specialUpdate");
|
---|
312 | break;
|
---|
313 | default:
|
---|
314 | yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action);
|
---|
315 | }
|
---|
316 | }
|
---|
317 | if (toKeep->databaseName)
|
---|
318 | {
|
---|
319 | yaz_log (LOG_LOG, "database: %s", toKeep->databaseName);
|
---|
320 | if (!strcmp(toKeep->databaseName, "fault"))
|
---|
321 | {
|
---|
322 | rr->errcode = 109;
|
---|
323 | rr->errstring = toKeep->databaseName;
|
---|
324 | }
|
---|
325 | if (!strcmp(toKeep->databaseName, "accept"))
|
---|
326 | rr->errcode = -1;
|
---|
327 | }
|
---|
328 | if (notToKeep)
|
---|
329 | {
|
---|
330 | int i;
|
---|
331 | for (i = 0; i < notToKeep->num; i++)
|
---|
332 | {
|
---|
333 | Z_External *rec = notToKeep->elements[i]->record;
|
---|
334 |
|
---|
335 | if (rec->direct_reference)
|
---|
336 | {
|
---|
337 | struct oident *oident;
|
---|
338 | oident = oid_getentbyoid(rec->direct_reference);
|
---|
339 | if (oident)
|
---|
340 | yaz_log (LOG_LOG, "record %d type %s", i,
|
---|
341 | oident->desc);
|
---|
342 | }
|
---|
343 | switch (rec->which)
|
---|
344 | {
|
---|
345 | case Z_External_sutrs:
|
---|
346 | if (rec->u.octet_aligned->len > 170)
|
---|
347 | yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
|
---|
348 | rec->u.sutrs->len,
|
---|
349 | rec->u.sutrs->buf);
|
---|
350 | else
|
---|
351 | yaz_log (LOG_LOG, "%d bytes:\n%s",
|
---|
352 | rec->u.sutrs->len,
|
---|
353 | rec->u.sutrs->buf);
|
---|
354 | break;
|
---|
355 | case Z_External_octet :
|
---|
356 | if (rec->u.octet_aligned->len > 170)
|
---|
357 | yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",
|
---|
358 | rec->u.octet_aligned->len,
|
---|
359 | rec->u.octet_aligned->buf);
|
---|
360 | else
|
---|
361 | yaz_log (LOG_LOG, "%d bytes\n%s",
|
---|
362 | rec->u.octet_aligned->len,
|
---|
363 | rec->u.octet_aligned->buf);
|
---|
364 | }
|
---|
365 | }
|
---|
366 | }
|
---|
367 | }
|
---|
368 | }
|
---|
369 | else
|
---|
370 | {
|
---|
371 | yaz_log (LOG_WARN, "Unknown Extended Service(%d)",
|
---|
372 | rr->esr->taskSpecificParameters->which);
|
---|
373 |
|
---|
374 | }
|
---|
375 | return 0;
|
---|
376 | }
|
---|
377 |
|
---|
378 | int ztest_delete (void *handle, bend_delete_rr *rr)
|
---|
379 | {
|
---|
380 | if (rr->num_setnames == 1 && !strcmp (rr->setnames[0], "1"))
|
---|
381 | rr->delete_status = Z_DeleteStatus_success;
|
---|
382 | else
|
---|
383 | rr->delete_status = Z_DeleteStatus_resultSetDidNotExist;
|
---|
384 | return 0;
|
---|
385 | }
|
---|
386 |
|
---|
387 | /* Obsolete bend_search, never called because handler is registered */
|
---|
388 | bend_searchresult *bend_search(void *handle, bend_searchrequest *q, int *fd)
|
---|
389 | {
|
---|
390 | return 0;
|
---|
391 | }
|
---|
392 |
|
---|
393 | /* Our sort handler really doesn't sort... */
|
---|
394 | int ztest_sort (void *handle, bend_sort_rr *rr)
|
---|
395 | {
|
---|
396 | rr->errcode = 0;
|
---|
397 | rr->sort_status = Z_SortStatus_success;
|
---|
398 | return 0;
|
---|
399 | }
|
---|
400 |
|
---|
401 | static int atoin (const char *buf, int n)
|
---|
402 | {
|
---|
403 | int val = 0;
|
---|
404 | while (--n >= 0)
|
---|
405 | {
|
---|
406 | if (isdigit(*buf))
|
---|
407 | val = val*10 + (*buf - '0');
|
---|
408 | buf++;
|
---|
409 | }
|
---|
410 | return val;
|
---|
411 | }
|
---|
412 |
|
---|
413 | char *marc_read(FILE *inf, ODR odr)
|
---|
414 | {
|
---|
415 | char length_str[5];
|
---|
416 | size_t size;
|
---|
417 | char *buf;
|
---|
418 |
|
---|
419 | if (fread (length_str, 1, 5, inf) != 5)
|
---|
420 | return NULL;
|
---|
421 | size = atoin (length_str, 5);
|
---|
422 | if (size <= 6)
|
---|
423 | return NULL;
|
---|
424 | if (!(buf = (char*) odr_malloc (odr, size+1)))
|
---|
425 | return NULL;
|
---|
426 | if (fread (buf+5, 1, size-5, inf) != (size-5))
|
---|
427 | {
|
---|
428 | xfree (buf);
|
---|
429 | return NULL;
|
---|
430 | }
|
---|
431 | memcpy (buf, length_str, 5);
|
---|
432 | buf[size] = '\0';
|
---|
433 | return buf;
|
---|
434 | }
|
---|
435 |
|
---|
436 | static char *dummy_database_record (int num, ODR odr)
|
---|
437 | {
|
---|
438 | FILE *inf = fopen ("dummy-records", "r");
|
---|
439 | char *buf = 0;
|
---|
440 |
|
---|
441 | if (!inf)
|
---|
442 | return NULL;
|
---|
443 | while (--num >= 0)
|
---|
444 | {
|
---|
445 | if (num == 98)
|
---|
446 | {
|
---|
447 | buf = (char*) odr_malloc(odr, 2101);
|
---|
448 | memset(buf, 'A', 2100);
|
---|
449 | buf[2100] = '\0';
|
---|
450 | break;
|
---|
451 | }
|
---|
452 | else
|
---|
453 | buf = marc_read (inf, odr);
|
---|
454 | if (!num || !buf)
|
---|
455 | break;
|
---|
456 | }
|
---|
457 | fclose(inf);
|
---|
458 | if (num < 0)
|
---|
459 | return 0;
|
---|
460 | return buf;
|
---|
461 | }
|
---|
462 |
|
---|
463 | static Z_GenericRecord *dummy_grs_record (int num, ODR o)
|
---|
464 | {
|
---|
465 | FILE *f = fopen("dummy-grs", "r");
|
---|
466 | char line[512];
|
---|
467 | Z_GenericRecord *r = 0;
|
---|
468 | int n;
|
---|
469 |
|
---|
470 | if (!f)
|
---|
471 | return 0;
|
---|
472 | while (fgets(line, 512, f))
|
---|
473 | if (*line == '#' && sscanf(line, "#%d", &n) == 1 && n == num)
|
---|
474 | {
|
---|
475 | r = read_grs1(f, o);
|
---|
476 | break;
|
---|
477 | }
|
---|
478 | fclose(f);
|
---|
479 | return r;
|
---|
480 | }
|
---|
481 |
|
---|
482 | bend_fetchresult *bend_fetch(void *handle, bend_fetchrequest *q, int *fd)
|
---|
483 | {
|
---|
484 | bend_fetchresult *r = (bend_fetchresult *)
|
---|
485 | odr_malloc (q->stream, sizeof(*r));
|
---|
486 | char *cp;
|
---|
487 | r->errstring = 0;
|
---|
488 | r->last_in_set = 0;
|
---|
489 | r->basename = "DUMMY";
|
---|
490 | r->format = q->format;
|
---|
491 | if (q->format == VAL_SUTRS)
|
---|
492 | {
|
---|
493 | char buf[100];
|
---|
494 |
|
---|
495 | sprintf(buf, "This is dummy SUTRS record number %d\n", q->number);
|
---|
496 | r->len = strlen(buf);
|
---|
497 | r->record = (char *) odr_malloc (q->stream, r->len+1);
|
---|
498 | strcpy(r->record, buf);
|
---|
499 | }
|
---|
500 | else if (q->format == VAL_GRS1)
|
---|
501 | {
|
---|
502 | r->len = -1;
|
---|
503 | r->record = (char*) dummy_grs_record(q->number, q->stream);
|
---|
504 | if (!r->record)
|
---|
505 | {
|
---|
506 | r->errcode = 13;
|
---|
507 | return r;
|
---|
508 | }
|
---|
509 | }
|
---|
510 | else if ((cp = dummy_database_record(q->number, q->stream)))
|
---|
511 | {
|
---|
512 | r->len = strlen(cp);
|
---|
513 | r->record = cp;
|
---|
514 | r->format = VAL_USMARC;
|
---|
515 | }
|
---|
516 | else
|
---|
517 | {
|
---|
518 | r->errcode = 13;
|
---|
519 | return r;
|
---|
520 | }
|
---|
521 | r->errcode = 0;
|
---|
522 | return r;
|
---|
523 | }
|
---|
524 |
|
---|
525 | /*
|
---|
526 | * silly dummy-scan what reads words from a file.
|
---|
527 | */
|
---|
528 | bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *fd)
|
---|
529 | {
|
---|
530 | bend_scanresult *r = (bend_scanresult *)
|
---|
531 | odr_malloc (q->stream, sizeof(*r));
|
---|
532 | static FILE *f = 0;
|
---|
533 | static struct scan_entry list[200];
|
---|
534 | static char entries[200][80];
|
---|
535 | int hits[200];
|
---|
536 | char term[80], *p;
|
---|
537 | int i, pos;
|
---|
538 |
|
---|
539 | r->errcode = 0;
|
---|
540 | r->errstring = 0;
|
---|
541 | r->entries = list;
|
---|
542 | r->status = BEND_SCAN_SUCCESS;
|
---|
543 | if (!f && !(f = fopen("dummy-words", "r")))
|
---|
544 | {
|
---|
545 | perror("dummy-words");
|
---|
546 | exit(1);
|
---|
547 | }
|
---|
548 | if (q->term->term->which != Z_Term_general)
|
---|
549 | {
|
---|
550 | r->errcode = 229; /* unsupported term type */
|
---|
551 | return r;
|
---|
552 | }
|
---|
553 | if (q->term->term->u.general->len >= 80)
|
---|
554 | {
|
---|
555 | r->errcode = 11; /* term too long */
|
---|
556 | return r;
|
---|
557 | }
|
---|
558 | if (q->num_entries > 200)
|
---|
559 | {
|
---|
560 | r->errcode = 31;
|
---|
561 | return r;
|
---|
562 | }
|
---|
563 | memcpy(term, q->term->term->u.general->buf, q->term->term->u.general->len);
|
---|
564 | term[q->term->term->u.general->len] = '\0';
|
---|
565 | for (p = term; *p; p++)
|
---|
566 | if (islower(*p))
|
---|
567 | *p = toupper(*p);
|
---|
568 |
|
---|
569 | fseek(f, 0, SEEK_SET);
|
---|
570 | r->num_entries = 0;
|
---|
571 | for (i = 0, pos = 0; fscanf(f, " %79[^:]:%d", entries[pos], &hits[pos]) == 2;
|
---|
572 | i++, pos < 199 ? pos++ : (pos = 0))
|
---|
573 | {
|
---|
574 | if (!r->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */
|
---|
575 | {
|
---|
576 | if ((r->term_position = q->term_position) > i + 1)
|
---|
577 | {
|
---|
578 | r->term_position = i + 1;
|
---|
579 | r->status = BEND_SCAN_PARTIAL;
|
---|
580 | }
|
---|
581 | for (; r->num_entries < r->term_position; r->num_entries++)
|
---|
582 | {
|
---|
583 | int po;
|
---|
584 |
|
---|
585 | po = pos - r->term_position + r->num_entries + 1; /* find pos */
|
---|
586 | if (po < 0)
|
---|
587 | po += 200;
|
---|
588 |
|
---|
589 | if (!strcmp (term, "SD") && r->num_entries == 2)
|
---|
590 | {
|
---|
591 | list[r->num_entries].term = entries[pos];
|
---|
592 | list[r->num_entries].occurrences = -1;
|
---|
593 | list[r->num_entries].errcode = 233;
|
---|
594 | list[r->num_entries].errstring = "SD for Scan Term";
|
---|
595 | }
|
---|
596 | else
|
---|
597 | {
|
---|
598 | list[r->num_entries].term = entries[po];
|
---|
599 | list[r->num_entries].occurrences = hits[po];
|
---|
600 | }
|
---|
601 | }
|
---|
602 | }
|
---|
603 | else if (r->num_entries)
|
---|
604 | {
|
---|
605 | list[r->num_entries].term = entries[pos];
|
---|
606 | list[r->num_entries].occurrences = hits[pos];
|
---|
607 | r->num_entries++;
|
---|
608 | }
|
---|
609 | if (r->num_entries >= q->num_entries)
|
---|
610 | break;
|
---|
611 | }
|
---|
612 | if (feof(f))
|
---|
613 | r->status = BEND_SCAN_PARTIAL;
|
---|
614 | return r;
|
---|
615 | }
|
---|
616 |
|
---|
617 | void bend_close(void *handle)
|
---|
618 | {
|
---|
619 | return;
|
---|
620 | }
|
---|
621 |
|
---|
622 | int main(int argc, char **argv)
|
---|
623 | {
|
---|
624 | return statserv_main(argc, argv);
|
---|
625 | }
|
---|