X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fztest.c;h=7ea27de0770fae882932bb655c917c80a62468fc;hp=645ebd8e949756e2ac73ba327d422b7f9c70a4a7;hb=bf6876570c2eeade25f5ed23052d0e94244d568c;hpb=57a4650104210f5e0bd9b6e0dbde0690000c1dc1 diff --git a/ztest/ztest.c b/ztest/ztest.c index 645ebd8..7ea27de 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -1,8 +1,8 @@ /* - * Copyright (c) 1995-2002, Index Data. + * Copyright (c) 1995-2004, Index Data. * See the file LICENSE for details. * - * $Id: ztest.c,v 1.50 2002-01-23 22:40:36 adam Exp $ + * $Id: ztest.c,v 1.63 2004-03-29 15:09:14 adam Exp $ */ /* @@ -13,14 +13,13 @@ #include #include +#include #include -#include - -#if YAZ_MODULE_ill #include -#endif -Z_GenericRecord *read_grs1(FILE *f, ODR o); +Z_GenericRecord *dummy_grs_record (int num, ODR o); +char *dummy_marc_record (int num, ODR odr); +char *dummy_xml_record (int num, ODR odr); int ztest_search (void *handle, bend_search_rr *rr); int ztest_sort (void *handle, bend_sort_rr *rr); @@ -35,21 +34,27 @@ int ztest_search (void *handle, bend_search_rr *rr) rr->errcode = 23; return 0; } - if (strcmp (rr->basenames[0], "Default")) +#if NMEM_DEBUG + /* if database is stop, stop this process.. For debugging only. */ + if (!yaz_matchstr (rr->basenames[0], "stop")) + { + nmem_print_list_l(LOG_LOG); + exit(0); + } +#endif + /* Throw Database unavailable if other than Default */ + if (yaz_matchstr (rr->basenames[0], "Default")) { rr->errcode = 109; rr->errstring = rr->basenames[0]; return 0; } - rr->hits = rand() % 22; + rr->hits = rand() % 24; return 0; } -int ztest_present (void *handle, bend_present_rr *rr) -{ - return 0; -} +/* this huge function handles extended services */ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) { /* user-defined handle - created in bend_init */ @@ -100,7 +105,6 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) yaz_log(LOG_LOG, "setId: %s", n->resultSetItem->resultSetId); yaz_log(LOG_LOG, "item: %d", *n->resultSetItem->item); } -#if YAZ_MODULE_ill if (n->itemRequest) { Z_External *r = (Z_External*) n->itemRequest; @@ -178,7 +182,6 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) *item_req->protocol_version_num); } } -#endif if (k) { @@ -392,6 +395,10 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) } } } + else if (rr->esr->taskSpecificParameters->which == Z_External_update0) + { + yaz_log(LOG_LOG, "Received DB Update (version 0)"); + } else { yaz_log (LOG_WARN, "Unknown Extended Service(%d)", @@ -401,6 +408,7 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) return 0; } +/* result set delete */ int ztest_delete (void *handle, bend_delete_rr *rr) { if (rr->num_setnames == 1 && !strcmp (rr->setnames[0], "1")) @@ -418,111 +426,31 @@ int ztest_sort (void *handle, bend_sort_rr *rr) return 0; } -static int atoin (const char *buf, int n) -{ - int val = 0; - while (--n >= 0) - { - if (isdigit(*buf)) - val = val*10 + (*buf - '0'); - buf++; - } - return val; -} - -char *marc_read(FILE *inf, ODR odr) -{ - char length_str[5]; - size_t size; - char *buf; - - if (fread (length_str, 1, 5, inf) != 5) - return NULL; - size = atoin (length_str, 5); - if (size <= 6) - return NULL; - if (!(buf = (char*) odr_malloc (odr, size+1))) - return NULL; - if (fread (buf+5, 1, size-5, inf) != (size-5)) - { - xfree (buf); - return NULL; - } - memcpy (buf, length_str, 5); - buf[size] = '\0'; - return buf; -} -static char *dummy_database_record (int num, ODR odr) -{ - FILE *inf = fopen ("dummy-records", "r"); - char *buf = 0; - - if (!inf) - return NULL; - if (num == 98) - { /* this will generate a very bad MARC record (testing only) */ - buf = (char*) odr_malloc(odr, 2101); - memset(buf, '7', 2100); - buf[2100] = '\0'; - } - else - { - /* OK, try to get proper MARC records from the file */ - while (--num >= 0) - { - buf = marc_read (inf, odr); - if (!buf) - break; - } - } - fclose(inf); - return buf; -} - -static Z_GenericRecord *dummy_grs_record (int num, ODR o) +/* present request handler */ +int ztest_present (void *handle, bend_present_rr *rr) { - FILE *f = fopen("dummy-grs", "r"); - char line[512]; - Z_GenericRecord *r = 0; - int n; - - if (!f) - return 0; - while (fgets(line, 512, f)) - if (*line == '#' && sscanf(line, "#%d", &n) == 1 && n == num) - { - r = read_grs1(f, o); - break; - } - fclose(f); - return r; + return 0; } +/* retrieval of a single record (present, and piggy back search) */ int ztest_fetch(void *handle, bend_fetch_rr *r) { char *cp; - r->errstring = 0; + r->last_in_set = 0; r->basename = "Default"; r->output_format = r->request_format; if (r->request_format == VAL_SUTRS) { -#if 0 -/* this section returns a huge record (for testing non-blocking write, etc) */ - r->len = 980000; - r->record = odr_malloc (r->stream, r->len); - memset (r->record, 'x', r->len); -#else -/* this section returns a small record */ + /* this section returns a small record */ char buf[100]; - + sprintf(buf, "This is dummy SUTRS record number %d\n", r->number); r->len = strlen(buf); r->record = (char *) odr_malloc (r->stream, r->len+1); strcpy(r->record, buf); -#endif } else if (r->request_format == VAL_GRS1) { @@ -555,13 +483,20 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) return 0; } fseek (f, 0L, SEEK_SET); - r->record = odr_malloc (r->stream, size); + r->record = (char*) odr_malloc (r->stream, size); r->len = size; r->output_format = VAL_POSTSCRIPT; fread (r->record, size, 1, f); fclose (f); } - else if ((cp = dummy_database_record(r->number, r->stream))) + else if (r->request_format == VAL_TEXT_XML && + (cp = dummy_xml_record (r->number, r->stream))) + { + r->len = strlen(cp); + r->record = cp; + r->output_format = VAL_TEXT_XML; + } + else if ((cp = dummy_marc_record(r->number, r->stream))) { r->len = strlen(cp); r->record = cp; @@ -674,9 +609,24 @@ int ztest_scan(void *handle, bend_scan_rr *q) return 0; } +static int ztest_explain(void *handle, bend_explain_rr *rr) +{ + if (rr->database && !strcmp(rr->database, "Default")) + { + rr->explain_buf = "\n" + "\t\n" + "\t\tlocalhost\n" + "\t\t210\n" + "\t\n" + "\n"; + } + return 0; +} + bend_initresult *bend_init(bend_initrequest *q) { - bend_initresult *r = (bend_initresult *) odr_malloc (q->stream, sizeof(*r)); + bend_initresult *r = (bend_initresult *) + odr_malloc (q->stream, sizeof(*r)); int *counter = (int *) xmalloc (sizeof(int)); *counter = 0; @@ -690,6 +640,8 @@ bend_initresult *bend_init(bend_initrequest *q) q->bend_delete = ztest_delete; q->bend_fetch = ztest_fetch; q->bend_scan = ztest_scan; + q->bend_explain = ztest_explain; + return r; }