X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fztest.c;h=ee1b4a2d21fbc94f0f041798a75622956b363d63;hp=52ea6661d9587ee136acb51b4461486b1871a1e9;hb=6a7d650e44134d161a4614a5e68245216dec2b19;hpb=9006495b0949ec4c474866cb69376653540b1aab diff --git a/ztest/ztest.c b/ztest/ztest.c index 52ea666..ee1b4a2 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995-1997, Index Data. + * Copyright (c) 1995-1998, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * @@ -7,7 +7,17 @@ * Chas Woodfield, Fretwell Downing Datasystems. * * $Log: ztest.c,v $ - * Revision 1.3 1997-09-09 10:10:20 adam + * Revision 1.6 1998-01-29 13:16:02 adam + * Added dummy sort in test server. + * + * Revision 1.5 1997/11/07 13:31:58 adam + * Added NT Service name part of statserv_options_block. Moved NT + * service utility to server library. + * + * Revision 1.4 1997/09/17 12:10:43 adam + * YAZ version 1.4. + * + * Revision 1.3 1997/09/09 10:10:20 adam * Another MSV5.0 port. Changed projects to include proper * library/include paths. * Server starts server in test-mode when no options are given. @@ -30,31 +40,37 @@ #include #include -/* Specifically for NT Services - Shouldn't cause problems on UNIX */ -#include "service.h" - Z_GenericRecord *read_grs1(FILE *f, ODR o); +int bend_sort (void *handle, bend_sortrequest *req, bend_sortresult *res) +{ + res->errcode = 1; + res->errstring = "Sort not implemented"; + res->sort_status = Z_SortStatus_failure; + return 0; +} + bend_initresult *bend_init(bend_initrequest *q) { - static bend_initresult r; + bend_initresult *r = odr_malloc (q->stream, sizeof(*r)); static char *dummy = "Hej fister"; - r.errcode = 0; - r.errstring = 0; - r.handle = dummy; - return &r; + r->errcode = 0; + r->errstring = 0; + r->handle = dummy; + q->bend_sort = bend_sort; /* register sort handler */ + return r; } bend_searchresult *bend_search(void *handle, bend_searchrequest *q, int *fd) { - static bend_searchresult r; + bend_searchresult *r = odr_malloc (q->stream, sizeof(*r)); - r.errcode = 0; - r.errstring = 0; - r.hits = rand() % 22; + r->errcode = 0; + r->errstring = 0; + r->hits = rand() % 22; - return &r; + return r; } static int atoin (const char *buf, int n) @@ -142,47 +158,47 @@ static Z_GenericRecord *dummy_grs_record (int num, ODR o) bend_fetchresult *bend_fetch(void *handle, bend_fetchrequest *q, int *num) { - static bend_fetchresult r; + bend_fetchresult *r = odr_malloc (q->stream, sizeof(*r)); static char *bbb = 0; - r.errstring = 0; - r.last_in_set = 0; - r.basename = "DUMMY"; + r->errstring = 0; + r->last_in_set = 0; + r->basename = "DUMMY"; if (bbb) { xfree(bbb); bbb = 0; } - r.format = q->format; + r->format = q->format; if (q->format == VAL_SUTRS) { char buf[100]; sprintf(buf, "This is dummy SUTRS record number %d\n", q->number); - assert(r.record = bbb = xmalloc(strlen(buf)+1)); + assert(r->record = bbb = xmalloc(strlen(buf)+1)); strcpy(bbb, buf); - r.len = strlen(buf); + r->len = strlen(buf); } else if (q->format == VAL_GRS1) { - r.len = -1; - r.record = (char*) dummy_grs_record(q->number, q->stream); - if (!r.record) + r->len = -1; + r->record = (char*) dummy_grs_record(q->number, q->stream); + if (!r->record) { - r.errcode = 13; - return &r; + r->errcode = 13; + return r; } } - else if (!(r.record = bbb = dummy_database_record(q->number))) + else if (!(r->record = bbb = dummy_database_record(q->number))) { - r.errcode = 13; - r.format = VAL_USMARC; - return &r; + r->errcode = 13; + r->format = VAL_USMARC; + return r; } else - r.len = strlen(r.record); - r.errcode = 0; - return &r; + r->len = strlen(r->record); + r->errcode = 0; + return r; } bend_deleteresult *bend_delete(void *handle, bend_deleterequest *q, int *num) @@ -217,7 +233,7 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) */ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) { - static bend_scanresult r; + bend_scanresult *r = odr_malloc (q->stream, sizeof(*r)); static FILE *f = 0; static struct scan_entry list[200]; static char entries[200][80]; @@ -225,9 +241,9 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) char term[80], *p; int i, pos; - r.errstring = 0; - r.entries = list; - r.status = BEND_SCAN_SUCCESS; + r->errstring = 0; + r->entries = list; + r->status = BEND_SCAN_SUCCESS; if (!f && !(f = fopen("dummy-words", "r"))) { perror("dummy-words"); @@ -235,18 +251,18 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) } if (q->term->term->which != Z_Term_general) { - r.errcode = 229; /* unsupported term type */ - return &r; + r->errcode = 229; /* unsupported term type */ + return r; } if (q->term->term->u.general->len >= 80) { - r.errcode = 11; /* term too long */ - return &r; + r->errcode = 11; /* term too long */ + return r; } if (q->num_entries > 200) { - r.errcode = 31; - return &r; + r->errcode = 31; + return r; } memcpy(term, q->term->term->u.general->buf, q->term->term->u.general->len); term[q->term->term->u.general->len] = '\0'; @@ -255,40 +271,40 @@ bend_scanresult *bend_scan(void *handle, bend_scanrequest *q, int *num) *p = toupper(*p); fseek(f, 0, 0); - r.num_entries = 0; + r->num_entries = 0; for (i = 0, pos = 0; fscanf(f, " %79[^:]:%d", entries[pos], &hits[pos]) == 2; i++, pos < 199 ? pos++ : (pos = 0)) { - if (!r.num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */ + if (!r->num_entries && strcmp(entries[pos], term) >= 0) /* s-point fnd */ { - if ((r.term_position = q->term_position) > i + 1) + if ((r->term_position = q->term_position) > i + 1) { - r.term_position = i + 1; - r.status = BEND_SCAN_PARTIAL; + r->term_position = i + 1; + r->status = BEND_SCAN_PARTIAL; } - for (; r.num_entries < r.term_position; r.num_entries++) + for (; r->num_entries < r->term_position; r->num_entries++) { int po; - po = pos - r.term_position + r.num_entries + 1; /* find pos */ + po = pos - r->term_position + r->num_entries + 1; /* find pos */ if (po < 0) po += 200; - list[r.num_entries].term = entries[po]; - list[r.num_entries].occurrences = hits[po]; + list[r->num_entries].term = entries[po]; + list[r->num_entries].occurrences = hits[po]; } } - else if (r.num_entries) + else if (r->num_entries) { - list[r.num_entries].term = entries[pos]; - list[r.num_entries].occurrences = hits[pos]; - r.num_entries++; + list[r->num_entries].term = entries[pos]; + list[r->num_entries].occurrences = hits[pos]; + r->num_entries++; } - if (r.num_entries >= q->num_entries) + if (r->num_entries >= q->num_entries) break; } if (feof(f)) - r.status = BEND_SCAN_PARTIAL; - return &r; + r->status = BEND_SCAN_PARTIAL; + return r; } #endif @@ -298,67 +314,7 @@ void bend_close(void *handle) return; } -typedef struct _Args -{ - char **argv; - int argc; -} Args; - -static Args ArgDetails; - -/* name of the executable */ -#define SZAPPNAME "server" - -/* internal name of the service */ -#define SZSERVICENAME "Z3950 Test Server" - -/* displayed name of the service */ -#define SZSERVICEDISPLAYNAME "Z3950 Test Server" - -/* list of service dependencies - "dep1\0dep2\0\0" */ -#define SZDEPENDENCIES "" - int main(int argc, char **argv) { - /* Lets setup the Arg structure */ - ArgDetails.argc = argc; - ArgDetails.argv = argv; - -#ifdef WIN32 - - /* Now setup the service with the service controller */ - SetupService(argc, argv, &ArgDetails, SZAPPNAME, SZSERVICENAME, SZSERVICEDISPLAYNAME, SZDEPENDENCIES); - -#else /* WIN32 */ - - /* The service controller does the following for us under windows */ - if (StartAppService(NULL, argc, argv)) - RunAppService(&ArgDetails); - - /* Ensure the service has been stopped */ - StopAppService(NULL); - -#endif /* WIN32 */ - - return(0); -} - -int StartAppService(void *pHandle, int argc, char **argv) -{ - /* Initializes the App */ - return 1; -} - -void RunAppService(void *pHandle) -{ - Args *pArgs = (Args *)pHandle; - - /* Starts the app running */ - statserv_main(pArgs->argc, pArgs->argv); -} - -void StopAppService(void *pHandle) -{ - /* Stops the app */ - statserv_closedown(); + return statserv_main(argc, argv); }