X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=ztest%2Fztest.c;h=cda0bab2af57a608d411063851b3900203374d65;hp=c5f7432ddbd2ffb177dd21805a4a8173d32de6f6;hb=7a98e9bfbb9d5fe7d44822a9838e3becbdce9363;hpb=1e8eb130ff83dedfb7382ca3e38651add9894662 diff --git a/ztest/ztest.c b/ztest/ztest.c index c5f7432..cda0bab 100644 --- a/ztest/ztest.c +++ b/ztest/ztest.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2005, Index Data ApS + * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: ztest.c,v 1.78 2006-03-13 12:14:00 adam Exp $ + * $Id: ztest.c,v 1.91 2007-05-08 08:22:37 adam Exp $ */ /* @@ -16,7 +16,7 @@ #include #endif -#include +#include #include #include @@ -54,9 +54,19 @@ int ztest_search(void *handle, bend_search_rr *rr) else if(!yaz_matchstr (rr->basenames[0], "Slow")) { #if HAVE_UNISTD_H - sleep(3); + /* wait up to 3 seconds and check if connection is still alive */ + int i; + for (i = 0; i<3; i++) + { + if (!bend_assoc_is_alive(rr->association)) + { + yaz_log(YLOG_LOG, "search aborted"); + break; + } + sleep(1); + } #endif - ; + rr->estimated_hit_count = 1; } else { @@ -127,17 +137,22 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) ILL_APDU *ill_apdu = 0; if (r->direct_reference) { - oident *ent = oid_getentbyoid(r->direct_reference); - if (ent) - yaz_log(log_level, "OID %s", ent->desc); - if (ent && ent->value == VAL_TEXT_XML) + char oid_name_str[OID_STR_MAX]; + oid_class oclass; + const char *oid_name = + yaz_oid_to_string_buf(r->direct_reference, + &oclass, oid_name_str); + if (oid_name) + yaz_log(log_level, "OID %s", oid_name); + if (!oid_oidcmp(r->direct_reference, yaz_oid_recsyn_xml)) { yaz_log (log_level, "ILL XML request"); if (r->which == Z_External_octet) yaz_log (log_level, "%.*s", r->u.octet_aligned->len, r->u.octet_aligned->buf); } - if (ent && ent->value == VAL_ISO_ILL_1) + if (!oid_oidcmp(r->direct_reference, + yaz_oid_general_isoill_1)) { yaz_log (log_level, "Decode ItemRequest begin"); if (r->which == ODR_EXTERNAL_single) @@ -149,9 +164,9 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) if (!ill_ItemRequest (rr->decode, &item_req, 0, 0)) { yaz_log (log_level, - "Couldn't decode ItemRequest %s near %d", + "Couldn't decode ItemRequest %s near %ld", odr_errmsg(odr_geterror(rr->decode)), - odr_offset(rr->decode)); + (long) odr_offset(rr->decode)); } else yaz_log(log_level, "Decode ItemRequest OK"); @@ -172,9 +187,9 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) if (!ill_APDU (rr->decode, &ill_apdu, 0, 0)) { yaz_log (log_level, - "Couldn't decode ILL APDU %s near %d", + "Couldn't decode ILL APDU %s near %ld", odr_errmsg(odr_geterror(rr->decode)), - odr_offset(rr->decode)); + (long) odr_offset(rr->decode)); yaz_log(log_level, "PDU dump:"); odr_dumpBER(yaz_log_file(), (char *) r->u.single_ASN1_type->buf, @@ -359,7 +374,7 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) targetPart->taskPackageRecords[0]->which = Z_IUTaskPackageRecordStructure_record; targetPart->taskPackageRecords[0]->u.record = - z_ext_record (rr->stream, VAL_SUTRS, "test", 4); + z_ext_record_sutrs(rr->stream, "test", 4); targetPart->taskPackageRecords[0]->correlationInfo = 0; targetPart->taskPackageRecords[0]->recordStatus = odr_intdup (rr->stream, @@ -378,11 +393,14 @@ int ztest_esrequest (void *handle, bend_esrequest_rr *rr) if (rec->direct_reference) { - struct oident *oident; - oident = oid_getentbyoid(rec->direct_reference); - if (oident) + char oid_name_str[OID_STR_MAX]; + const char *oid_name + = oid_name = yaz_oid_to_string_buf( + rec->direct_reference, 0, + oid_name_str); + if (oid_name) yaz_log (log_level, "record %d type %s", i, - oident->desc); + oid_name); } switch (rec->which) { @@ -442,11 +460,18 @@ int ztest_present (void *handle, bend_present_rr *rr) int ztest_fetch(void *handle, bend_fetch_rr *r) { char *cp; + oid_class oclass; + char oid_str_buf[OID_STR_MAX]; + const char *oid_str = 0; + const Odr_oid *oid = r->request_format; r->last_in_set = 0; r->basename = "Default"; - r->output_format = r->request_format; - if (r->request_format == VAL_SUTRS) + r->output_format = r->request_format; + + oid_str = yaz_oid_to_string_buf(oid, &oclass, oid_str_buf); + + if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_sutrs)) { /* this section returns a small record */ char buf[100]; @@ -457,7 +482,7 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) r->record = (char *) odr_malloc (r->stream, r->len+1); strcpy(r->record, buf); } - else if (r->request_format == VAL_GRS1) + else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_grs_1)) { r->len = -1; r->record = (char*) dummy_grs_record(r->number, r->stream); @@ -467,7 +492,7 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) return 0; } } - else if (r->request_format == VAL_POSTSCRIPT) + else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_postscript)) { char fname[20]; FILE *f; @@ -490,17 +515,15 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) fseek (f, 0L, SEEK_SET); 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 (r->request_format == VAL_TEXT_XML) + else if (oid && !oid_oidcmp(oid, yaz_oid_recsyn_xml)) { if ((cp = dummy_xml_record (r->number, r->stream))) { r->len = strlen(cp); r->record = cp; - r->output_format = VAL_TEXT_XML; } else { @@ -513,7 +536,7 @@ int ztest_fetch(void *handle, bend_fetch_rr *r) { r->len = strlen(cp); r->record = cp; - r->output_format = VAL_USMARC; + r->output_format = odr_oiddup(r->stream, yaz_oid_recsyn_usmarc); } else { @@ -663,6 +686,12 @@ int ztest_explain(void *handle, bend_explain_rr *rr) return 0; } +int ztest_update(void *handle, bend_update_rr *rr) +{ + rr->operation_status = "success"; + return 0; +} + bend_initresult *bend_init(bend_initrequest *q) { bend_initresult *r = (bend_initresult *) @@ -690,6 +719,10 @@ bend_initresult *bend_init(bend_initrequest *q) q->bend_explain = ztest_explain; #endif q->bend_srw_scan = ztest_scan; + q->bend_srw_update = ztest_update; + + q->query_charset = "ISO-8859-1"; + q->records_in_same_charset = 0; return r; }