X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=zutil%2Fzoom-c.c;h=7ce62e7dce858b0221661053a8770e65f17276ff;hp=e94a9a9fcd3f886bb61f1ab956c1dc463ea940a1;hb=3b10b3e056bb684b8f33123a79410f771adbee0a;hpb=72d53a9d929783e997c41330bb28859018088b53 diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index e94a9a9..7ce62e7 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -1,18 +1,25 @@ /* - * $Id: zoom-c.c,v 1.4 2002-10-04 11:23:50 adam Exp $ + * Copyright (c) 2000-2003, Index Data + * See the file LICENSE for details. + * + * $Id: zoom-c.c,v 1.32 2003-04-28 11:04:52 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ #include +#include +#include "zoom-p.h" + +#include #include #include #include #include +#include #include #include #include - -#include "zoom-p.h" +#include #if HAVE_SYS_POLL_H #include @@ -23,7 +30,6 @@ typedef enum { zoom_complete } zoom_ret; - static zoom_ret ZOOM_connection_send_init (ZOOM_connection c); static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out); @@ -76,6 +82,42 @@ static ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c) return event; } + +static void set_dset_error (ZOOM_connection c, int error, + const char *dset, + const char *addinfo, const char *addinfo2) +{ + xfree (c->addinfo); + c->addinfo = 0; + c->error = error; + c->diagset = dset; + if (addinfo && addinfo2) + { + c->addinfo = xmalloc(strlen(addinfo) + strlen(addinfo2) + 2); + strcpy(c->addinfo, addinfo); + strcat(c->addinfo, addinfo2); + } + else if (addinfo) + c->addinfo = xstrdup(addinfo); + if (error) + yaz_log(LOG_DEBUG, "Error %s %s:%d %s %s", + c->host_port ? c->host_port : "<>", dset, error, + addinfo ? addinfo : "", + addinfo2 ? addinfo2 : ""); +} + +static void set_HTTP_error (ZOOM_connection c, int error, + const char *addinfo, const char *addinfo2) +{ + set_dset_error(c, error, "HTTP", addinfo, addinfo2); +} + +static void set_ZOOM_error (ZOOM_connection c, int error, + const char *addinfo) +{ + set_dset_error(c, error, "ZOOM", addinfo, 0); +} + static void clear_error (ZOOM_connection c) { @@ -87,11 +129,10 @@ static void clear_error (ZOOM_connection c) case ZOOM_ERROR_CONNECTION_LOST: case ZOOM_ERROR_INIT: case ZOOM_ERROR_INTERNAL: + case ZOOM_ERROR_UNSUPPORTED_PROTOCOL: break; default: - c->error = ZOOM_ERROR_NONE; - xfree (c->addinfo); - c->addinfo = 0; + set_ZOOM_error(c, ZOOM_ERROR_NONE, 0); } } @@ -131,6 +172,7 @@ void ZOOM_connection_remove_task (ZOOM_connection c) switch (task->which) { case ZOOM_TASK_SEARCH: + ZOOM_resultset_destroy (task->u.search.resultset); break; case ZOOM_TASK_RETRIEVE: @@ -151,6 +193,8 @@ void ZOOM_connection_remove_task (ZOOM_connection c) } } +static int ZOOM_connection_exec_task (ZOOM_connection c); + void ZOOM_connection_remove_tasks (ZOOM_connection c) { while (c->tasks) @@ -164,12 +208,13 @@ ZOOM_connection_create (ZOOM_options options) { ZOOM_connection c = (ZOOM_connection) xmalloc (sizeof(*c)); + c->proto = PROTO_Z3950; c->cs = 0; c->mask = 0; c->reconnect_ok = 0; c->state = STATE_IDLE; - c->error = ZOOM_ERROR_NONE; c->addinfo = 0; + set_ZOOM_error(c, ZOOM_ERROR_NONE, 0); c->buf_in = 0; c->len_in = 0; c->buf_out = 0; @@ -179,6 +224,7 @@ ZOOM_connection_create (ZOOM_options options) c->options = ZOOM_options_create_with_parent(options); c->host_port = 0; + c->path = 0; c->proxy = 0; c->charset = c->lang = 0; @@ -323,7 +369,7 @@ ZOOM_connection_connect(ZOOM_connection c, c->async = ZOOM_options_get_bool (c->options, "async", 0); - c->error = ZOOM_ERROR_NONE; + set_ZOOM_error(c, ZOOM_ERROR_NONE, 0); task = ZOOM_connection_add_task (c, ZOOM_TASK_CONNECT); @@ -340,9 +386,10 @@ ZOOM_query_create(void) ZOOM_query s = (ZOOM_query) xmalloc (sizeof(*s)); s->refcount = 1; - s->query = 0; + s->z_query = 0; s->sort_spec = 0; s->odr = odr_createmem (ODR_ENCODE); + s->query_string = 0; return s; } @@ -365,15 +412,37 @@ ZOOM_query_destroy(ZOOM_query s) ZOOM_API(int) ZOOM_query_prefix(ZOOM_query s, const char *str) { - s->query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->query)); - s->query->which = Z_Query_type_1; - s->query->u.type_1 = p_query_rpn(s->odr, PROTO_Z3950, str); - if (!s->query->u.type_1) + s->query_string = odr_strdup(s->odr, str); + s->z_query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->z_query)); + s->z_query->which = Z_Query_type_1; + s->z_query->u.type_1 = p_query_rpn(s->odr, PROTO_Z3950, str); + if (!s->z_query->u.type_1) return -1; return 0; } ZOOM_API(int) +ZOOM_query_cql(ZOOM_query s, const char *str) +{ + Z_External *ext; + + s->query_string = odr_strdup(s->odr, str); + + ext = (Z_External *) odr_malloc(s->odr, sizeof(*ext)); + ext->direct_reference = odr_getoidbystr(s->odr, "1.2.840.10003.16.2"); + ext->indirect_reference = 0; + ext->descriptor = 0; + ext->which = Z_External_CQL; + ext->u.cql = s->query_string; + + s->z_query = (Z_Query *) odr_malloc (s->odr, sizeof(*s->z_query)); + s->z_query->which = Z_Query_type_104; + s->z_query->u.type_104 = ext; + + return 0; +} + +ZOOM_API(int) ZOOM_query_sortby(ZOOM_query s, const char *criteria) { s->sort_spec = yaz_sort_spec (s->odr, criteria); @@ -402,6 +471,7 @@ ZOOM_connection_destroy(ZOOM_connection c) ZOOM_options_destroy (c->options); ZOOM_connection_remove_tasks (c); xfree (c->host_port); + xfree (c->path); xfree (c->proxy); xfree (c->charset); xfree (c->lang); @@ -431,11 +501,11 @@ ZOOM_resultset ZOOM_resultset_create () r->start = 0; r->piggyback = 1; r->setname = 0; + r->schema = 0; r->count = 0; r->record_cache = 0; r->r_sort_spec = 0; - r->r_query = 0; - r->search = 0; + r->query = 0; r->connection = 0; r->next = 0; return r; @@ -462,8 +532,7 @@ ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) const char *cp; r->r_sort_spec = q->sort_spec; - r->r_query = q->query; - r->search = q; + r->query = q; r->options = ZOOM_options_create_with_parent(c->options); @@ -472,13 +541,30 @@ ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) r->piggyback = ZOOM_options_get_bool (r->options, "piggyback", 1); cp = ZOOM_options_get (r->options, "setname"); if (cp) - r->setname = xstrdup (cp); + r->setname = xstrdup(cp); + cp = ZOOM_options_get (r->options, "schema"); + if (cp) + r->schema = xstrdup(cp); r->connection = c; r->next = c->resultsets; c->resultsets = r; + if (c->host_port && c->proto == PROTO_HTTP) + { + if (!c->cs) + { + yaz_log(LOG_DEBUG, "NO COMSTACK"); + ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); + } + else + { + yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT"); + c->reconnect_ok = 1; + } + } + task = ZOOM_connection_add_task (c, ZOOM_TASK_SEARCH); task->u.search.resultset = r; ZOOM_resultset_addref (r); @@ -523,10 +609,11 @@ ZOOM_resultset_destroy(ZOOM_resultset r) rp = &(*rp)->next; } } - ZOOM_query_destroy (r->search); + ZOOM_query_destroy (r->query); ZOOM_options_destroy (r->options); odr_destroy (r->odr); xfree (r->setname); + xfree (r->schema); xfree (r); } } @@ -551,17 +638,42 @@ static void ZOOM_resultset_retrieve (ZOOM_resultset r, { ZOOM_task task; ZOOM_connection c; + const char *cp; if (!r) return; c = r->connection; if (!c) return; + + if (c->host_port && c->proto == PROTO_HTTP) + { + if (!c->cs) + { + yaz_log(LOG_DEBUG, "NO COMSTACK"); + ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT); + } + else + { + yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT"); + c->reconnect_ok = 1; + } + } task = ZOOM_connection_add_task (c, ZOOM_TASK_RETRIEVE); task->u.retrieve.resultset = r; task->u.retrieve.start = start; task->u.retrieve.count = count; + cp = ZOOM_options_get (r->options, "schema"); + if (cp) + { + if (!r->schema || strcmp(r->schema, cp)) + { + xfree(r->schema); + r->schema = xstrdup(cp); + } + } + ZOOM_resultset_addref (r); if (!r->connection->async || force_sync) @@ -603,30 +715,56 @@ static zoom_ret do_connect (ZOOM_connection c) assert (!c->cs); c->cs = cs_create_host (effective_host, 0, &add); + if (c->cs && c->cs->protocol == PROTO_HTTP) + { +#if HAVE_XML2 + const char *path = 0; + + c->proto = PROTO_HTTP; + cs_get_host_args(c->host_port, &path); + xfree(c->path); + c->path = xmalloc(strlen(path)+2); + c->path[0] = '/'; + strcpy (c->path+1, path); +#else + set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, "SRW"); + do_close(c); + return zoom_complete; +#endif + } if (c->cs) { - int ret = cs_connect (c->cs, add); + int ret = cs_connect (c->cs, add); if (ret == 0) { ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_CONNECT); ZOOM_connection_put_event(c, event); - ZOOM_connection_send_init(c); + if (c->proto == PROTO_Z3950) + ZOOM_connection_send_init(c); + else + { + /* no init request for SRW .. */ + assert (c->tasks->which == ZOOM_TASK_CONNECT); + ZOOM_connection_remove_task (c); + c->mask = 0; + ZOOM_connection_exec_task (c); + } c->state = STATE_ESTABLISHED; return zoom_pending; } else if (ret > 0) - { - c->state = STATE_CONNECTING; + { + c->state = STATE_CONNECTING; c->mask = ZOOM_SELECT_EXCEPT; if (c->cs->io_pending & CS_WANT_WRITE) c->mask += ZOOM_SELECT_WRITE; if (c->cs->io_pending & CS_WANT_READ) c->mask += ZOOM_SELECT_READ; - return zoom_pending; - } + return zoom_pending; + } } c->state = STATE_IDLE; - c->error = ZOOM_ERROR_CONNECT; + set_ZOOM_error(c, ZOOM_ERROR_CONNECT, effective_host); return zoom_complete; } @@ -705,7 +843,7 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) odr_destroy(odr_pr); } yaz_log (LOG_DEBUG, "encoding failed"); - c->error = ZOOM_ERROR_ENCODE; + set_ZOOM_error(c, ZOOM_ERROR_ENCODE, 0); odr_reset(out); return -1; } @@ -837,6 +975,160 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) return send_APDU (c, apdu); } +#if HAVE_XML2 +static zoom_ret send_srw (ZOOM_connection c, Z_SRW_PDU *sr) +{ + char ctype[50]; + Z_SOAP_Handler h[2] = { + {"http://www.loc.gov/zing/srw/v1.0/", 0, (Z_SOAP_fun) yaz_srw_codec}, + {0, 0, 0} + }; + ODR o = odr_createmem(ODR_ENCODE); + int ret; + Z_SOAP *p = odr_malloc(o, sizeof(*p)); + Z_GDU *gdu; + ZOOM_Event event; + + gdu = z_get_HTTP_Request(c->odr_out); + gdu->u.HTTP_Request->path = c->path; + + if (c->host_port) + { + const char *cp0 = strstr(c->host_port, "://"); + const char *cp1 = 0; + if (cp0) + cp0 = cp0+3; + else + cp0 = c->host_port; + + cp1 = strchr(cp0, '/'); + if (!cp1) + cp1 = cp0+strlen(cp0); + + if (cp0 && cp1) + { + char *h = odr_malloc(c->odr_out, cp1 - cp0 + 1); + memcpy (h, cp0, cp1 - cp0); + h[cp1-cp0] = '\0'; + z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, + "host", h); + } + } + + strcpy(ctype, "text/xml"); + if (c->charset && strlen(c->charset) < 20) + { + strcat(ctype, "; charset="); + strcat(ctype, c->charset); + } + z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, + "Content-Type", ctype); + z_HTTP_header_add(c->odr_out, &gdu->u.HTTP_Request->headers, + "SOAPAction", "\"\""); + p->which = Z_SOAP_generic; + p->u.generic = odr_malloc(o, sizeof(*p->u.generic)); + p->u.generic->no = 0; + p->u.generic->ns = 0; + p->u.generic->p = sr; + p->ns = "http://schemas.xmlsoap.org/soap/envelope/"; + + ret = z_soap_codec_enc(o, &p, + &gdu->u.HTTP_Request->content_buf, + &gdu->u.HTTP_Request->content_len, h, + c->charset); + + if (!z_GDU(c->odr_out, &gdu, 0, 0)) + return zoom_complete; + c->buf_out = odr_getbuf(c->odr_out, &c->len_out, 0); + + odr_destroy(o); + + event = ZOOM_Event_create (ZOOM_EVENT_SEND_APDU); + ZOOM_connection_put_event (c, event); + odr_reset(c->odr_out); + return do_write (c); +} +#endif + +#if HAVE_XML2 +static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) +{ + int i; + ZOOM_resultset resultset = 0; + Z_SRW_PDU *sr = 0; + const char *recordPacking = 0; + + if (c->error) /* don't continue on error */ + return zoom_complete; + assert (c->tasks); + if (c->tasks->which == ZOOM_TASK_SEARCH) + { + resultset = c->tasks->u.search.resultset; + resultset->setname = xstrdup ("default"); + ZOOM_options_set (resultset->options, "setname", resultset->setname); + } + else if(c->tasks->which == ZOOM_TASK_RETRIEVE) + { + resultset = c->tasks->u.retrieve.resultset; + + resultset->start = c->tasks->u.retrieve.start; + resultset->count = c->tasks->u.retrieve.count; + + if (resultset->start >= resultset->size) + return zoom_complete; + if (resultset->start + resultset->count > resultset->size) + resultset->count = resultset->size - resultset->start; + + for (i = 0; icount; i++) + { + ZOOM_record rec = + record_cache_lookup (resultset, i + resultset->start); + if (!rec) + break; + } + if (i == resultset->count) + return zoom_complete; + } + assert(resultset->query); + + sr = yaz_srw_get(c->odr_out, Z_SRW_searchRetrieve_request); + + if (resultset->query->z_query->which == Z_Query_type_104 + && resultset->query->z_query->u.type_104->which == Z_External_CQL) + { + + sr->u.request->query_type = Z_SRW_query_type_cql; + sr->u.request->query.cql =resultset->query->z_query->u.type_104->u.cql; + } + else if (resultset->query->z_query->which == Z_Query_type_1 && + resultset->query->z_query->u.type_1) + { + sr->u.request->query_type = Z_SRW_query_type_pqf; + sr->u.request->query.pqf = resultset->query->query_string; + } + else + { + set_ZOOM_error(c, ZOOM_ERROR_UNSUPPORTED_QUERY, 0); + return zoom_complete; + } + sr->u.request->startRecord = odr_intdup (c->odr_out, resultset->start + 1); + sr->u.request->maximumRecords = odr_intdup (c->odr_out, resultset->count); + sr->u.request->recordSchema = resultset->schema; + + recordPacking = ZOOM_resultset_option_get (resultset, "recordPacking"); + + if (recordPacking) + sr->u.request->recordPacking = odr_strdup(c->odr_out, recordPacking); + + return send_srw(c, sr); +} +#else +static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) +{ + return zoom_complete; +} +#endif + static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) { ZOOM_resultset r; @@ -847,7 +1139,6 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) const char *elementSetName; const char *smallSetElementSetName; const char *mediumSetElementSetName; - const char *schema; assert (c->tasks); assert (c->tasks->which == ZOOM_TASK_SEARCH); @@ -860,8 +1151,6 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) ZOOM_options_get (r->options, "smallSetElementSetName"); mediumSetElementSetName = ZOOM_options_get (r->options, "mediumSetElementSetName"); - schema = - ZOOM_options_get (r->options, "schema"); if (!smallSetElementSetName) smallSetElementSetName = elementSetName; @@ -870,10 +1159,10 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) mediumSetElementSetName = elementSetName; assert (r); - assert (r->r_query); + assert (r->query); /* prepare query for the search request */ - search_req->query = r->r_query; + search_req->query = r->query->z_query; search_req->databaseNames = set_DatabaseNames (c, r->options, &search_req->num_databaseNames); @@ -892,13 +1181,13 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) *search_req->mediumSetPresentNumber = mspn; } else if (r->start == 0 && r->count > 0 - && r->piggyback && !r->r_sort_spec && !schema) + && r->piggyback && !r->r_sort_spec && !r->schema) { /* Regular piggyback - do it unless we're going to do sort */ *search_req->largeSetLowerBound = 2000000000; - *search_req->smallSetUpperBound = r->count; + *search_req->smallSetUpperBound = 0; *search_req->mediumSetPresentNumber = r->count; - smallSetElementSetName = 0; /* no need to provide this */ + smallSetElementSetName = 0; } else { @@ -961,6 +1250,7 @@ static zoom_ret ZOOM_connection_send_search (ZOOM_connection c) static void response_diag (ZOOM_connection c, Z_DiagRec *p) { + int oclass; Z_DefaultDiagFormat *r; char *addinfo = 0; @@ -968,7 +1258,7 @@ static void response_diag (ZOOM_connection c, Z_DiagRec *p) c->addinfo = 0; if (p->which != Z_DiagRec_defaultFormat) { - c->error = ZOOM_ERROR_DECODE; + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); return; } r = p->u.defaultFormat; @@ -981,9 +1271,9 @@ static void response_diag (ZOOM_connection c, Z_DiagRec *p) addinfo = r->u.v3Addinfo; break; } - if (addinfo) - c->addinfo = xstrdup (addinfo); - c->error = *r->condition; + set_dset_error(c, *r->condition, + yaz_z3950oid_to_str(r->diagnosticSetId, &oclass), + addinfo, 0); } ZOOM_API(ZOOM_record) @@ -1018,8 +1308,14 @@ ZOOM_resultset_record_immediate (ZOOM_resultset s,size_t pos) ZOOM_API(ZOOM_record) ZOOM_resultset_record (ZOOM_resultset r, size_t pos) { - ZOOM_resultset_retrieve (r, 1, pos, 1); - return ZOOM_resultset_record_immediate (r, pos); + ZOOM_record rec = ZOOM_resultset_record_immediate(r, pos); + + if (!rec) + { + ZOOM_resultset_retrieve (r, 1, pos, 1); + rec = ZOOM_resultset_record_immediate (r, pos); + } + return rec; } ZOOM_API(void) @@ -1054,18 +1350,19 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) } else if (!strcmp (type, "syntax")) { + const char *desc = 0; if (npr->which == Z_NamePlusRecord_databaseRecord) { Z_External *r = (Z_External *) npr->u.databaseRecord; oident *ent = oid_getentbyoid(r->direct_reference); if (ent) - { - if (len) - *len = strlen(ent->desc); - return ent->desc; - } + desc = ent->desc; } - return "none"; + if (!desc) + desc = "none"; + if (len) + *len = strlen(desc); + return desc; } else if (!strcmp (type, "render") && npr->which == Z_NamePlusRecord_databaseRecord) @@ -1080,6 +1377,7 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) } else if (r->which == Z_External_octet) { + yaz_marc_t mt; switch (ent->value) { case VAL_SOIF: @@ -1092,29 +1390,39 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) default: if (!rec->wrbuf_marc) rec->wrbuf_marc = wrbuf_alloc(); + + mt = yaz_marc_create(); wrbuf_rewind (rec->wrbuf_marc); - if (yaz_marc_decode ((const char *) - r->u.octet_aligned->buf, - rec->wrbuf_marc, 0, - r->u.octet_aligned->len, - 0) > 0) + if (yaz_marc_decode_wrbuf ( + mt, (const char *) r->u.octet_aligned->buf, + r->u.octet_aligned->len, + rec->wrbuf_marc) > 0) { - if (len) *len = wrbuf_len(rec->wrbuf_marc); + if (len) + *len = wrbuf_len(rec->wrbuf_marc); + yaz_marc_destroy(mt); return wrbuf_buf(rec->wrbuf_marc); } + yaz_marc_destroy(mt); } - if (len) *len = r->u.octet_aligned->len; + if (len) + *len = r->u.octet_aligned->len; return (const char *) r->u.octet_aligned->buf; } else if (r->which == Z_External_grs1) { - if (len) *len = 5; - return "GRS-1"; + if (!rec->wrbuf_marc) + rec->wrbuf_marc = wrbuf_alloc(); + wrbuf_rewind (rec->wrbuf_marc); + yaz_display_grs1(rec->wrbuf_marc, r->u.grs1, 0); + if (len) + *len = wrbuf_len(rec->wrbuf_marc); + return wrbuf_buf(rec->wrbuf_marc); } return 0; } - else if (!strcmp (type, "xml") && - npr->which == Z_NamePlusRecord_databaseRecord) + else if (npr->which == Z_NamePlusRecord_databaseRecord && + (!strcmp (type, "xml") || !strcmp(type, "oai"))) { Z_External *r = (Z_External *) npr->u.databaseRecord; oident *ent = oid_getentbyoid(r->direct_reference); @@ -1126,6 +1434,11 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) } else if (r->which == Z_External_octet) { + yaz_marc_t mt; + int marc_decode_type = YAZ_MARC_MARCXML; + + if (!strcmp(type, "oai")) + marc_decode_type = YAZ_MARC_OAIMARC; switch (ent->value) { case VAL_SOIF: @@ -1139,15 +1452,20 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) if (!rec->wrbuf_marc) rec->wrbuf_marc = wrbuf_alloc(); wrbuf_rewind (rec->wrbuf_marc); - if (yaz_marc_decode ((const char *) - r->u.octet_aligned->buf, - rec->wrbuf_marc, 0, - r->u.octet_aligned->len, - 2) > 0) + mt = yaz_marc_create(); + + yaz_marc_xml(mt, YAZ_MARC_MARCXML); + if (yaz_marc_decode_wrbuf ( + mt, (const char *) r->u.octet_aligned->buf, + r->u.octet_aligned->len, + rec->wrbuf_marc) > 0) { - if (len) *len = wrbuf_len(rec->wrbuf_marc); + if (len) + *len = wrbuf_len(rec->wrbuf_marc); + yaz_marc_destroy(mt); return wrbuf_buf(rec->wrbuf_marc); } + yaz_marc_destroy(mt); } if (len) *len = r->u.octet_aligned->len; return (const char *) r->u.octet_aligned->buf; @@ -1157,6 +1475,11 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) if (len) *len = 5; return "GRS-1"; } + else if (r->which == Z_External_OPAC) + { + if (len) *len = 4; + return "OPAC"; + } return 0; } else if (!strcmp (type, "raw")) @@ -1192,7 +1515,17 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) return 0; } -static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, int pos) +static int strcmp_null(const char *v1, const char *v2) +{ + if (!v1 && !v2) + return 0; + if (!v1 || !v2) + return -1; + return strcmp(v1, v2); +} + +static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, + int pos) { ZOOM_record_cache rc; const char *elementSetName = @@ -1200,25 +1533,23 @@ static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, int pos) const char *syntax = ZOOM_resultset_option_get (r, "preferredRecordSyntax"); + ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_RECV_RECORD); + ZOOM_connection_put_event(r->connection, event); for (rc = r->record_cache; rc; rc = rc->next) { if (pos == rc->pos) { - if ((!elementSetName && !rc->elementSetName) - || (elementSetName && rc->elementSetName && - !strcmp (elementSetName, rc->elementSetName))) - { - if ((!syntax && !rc->syntax) - || (syntax && rc->syntax && - !strcmp (syntax, rc->syntax))) - { - /* not destroying rc->npr (it's handled by nmem )*/ - rc->rec.npr = npr; - /* keeping wrbuf_marc too */ - return; - } - } + if (strcmp_null(r->schema, rc->schema)) + continue; + if (strcmp_null(elementSetName,rc->elementSetName)) + continue; + if (strcmp_null(syntax, rc->syntax)) + continue; + /* not destroying rc->npr (it's handled by nmem )*/ + rc->rec.npr = npr; + /* keeping wrbuf_marc too */ + return; } } rc = (ZOOM_record_cache) odr_malloc (r->odr, sizeof(*rc)); @@ -1235,6 +1566,11 @@ static void record_cache_add (ZOOM_resultset r, Z_NamePlusRecord *npr, int pos) else rc->syntax = 0; + if (r->schema) + rc->schema = odr_strdup (r->odr, r->schema); + else + rc->schema = 0; + rc->pos = pos; rc->next = r->record_cache; r->record_cache = rc; @@ -1252,15 +1588,13 @@ static ZOOM_record record_cache_lookup (ZOOM_resultset r, int pos) { if (pos == rc->pos) { - if ((!elementSetName && !rc->elementSetName) - || (elementSetName && rc->elementSetName && - !strcmp (elementSetName, rc->elementSetName))) - { - if ((!syntax && !rc->syntax) - || (syntax && rc->syntax && - !strcmp (syntax, rc->syntax))) - return &rc->rec; - } + if (strcmp_null(r->schema, rc->schema)) + continue; + if (strcmp_null(elementSetName,rc->elementSetName)) + continue; + if (strcmp_null(syntax, rc->syntax)) + continue; + return &rc->rec; } } return 0; @@ -1297,7 +1631,7 @@ static void handle_records (ZOOM_connection c, Z_Records *sr, if (sr->u.multipleNonSurDiagnostics->num_diagRecs >= 1) response_diag(c, sr->u.multipleNonSurDiagnostics->diagRecs[0]); else - c->error = ZOOM_ERROR_DECODE; + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); } else { @@ -1322,13 +1656,13 @@ static void handle_records (ZOOM_connection c, Z_Records *sr, if (present_phase && p->num_records == 0) { /* present response and we didn't get any records! */ - c->error = ZOOM_ERROR_DECODE; + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); } } else if (present_phase) { /* present response and we didn't get any records! */ - c->error = ZOOM_ERROR_DECODE; + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); } } } @@ -1341,11 +1675,15 @@ static void handle_present_response (ZOOM_connection c, Z_PresentResponse *pr) static void handle_search_response (ZOOM_connection c, Z_SearchResponse *sr) { ZOOM_resultset resultset; - + ZOOM_Event event; + yaz_log (LOG_DEBUG, "got search response"); - + if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH) return ; + + event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH); + ZOOM_connection_put_event(c, event); resultset = c->tasks->u.search.resultset; @@ -1424,7 +1762,6 @@ static zoom_ret send_present (ZOOM_connection c) int i = 0; const char *syntax = 0; const char *elementSetName = 0; - const char *schema = 0; ZOOM_resultset resultset; if (!c->tasks) @@ -1451,7 +1788,6 @@ static zoom_ret send_present (ZOOM_connection c) syntax = ZOOM_resultset_option_get (resultset, "preferredRecordSyntax"); elementSetName = ZOOM_resultset_option_get (resultset, "elementSetName"); - schema = ZOOM_resultset_option_get (resultset, "schema"); if (c->error) /* don't continue on error */ return zoom_complete; @@ -1480,7 +1816,7 @@ static zoom_ret send_present (ZOOM_connection c) req->preferredRecordSyntax = yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, syntax); - if (schema && *schema) + if (resultset->schema && *resultset->schema) { Z_RecordComposition *compo = (Z_RecordComposition *) odr_malloc (c->odr_out, sizeof(*compo)); @@ -1496,15 +1832,16 @@ static zoom_ret send_present (ZOOM_connection c) compo->u.complex->generic = (Z_Specification *) odr_malloc(c->odr_out, sizeof(*compo->u.complex->generic)); - compo->u.complex->generic->schema = (Odr_oid *) - yaz_str_to_z3950oid (c->odr_out, CLASS_SCHEMA, schema); + compo->u.complex->generic->which = Z_Schema_oid; + compo->u.complex->generic->schema.oid = (Odr_oid *) + yaz_str_to_z3950oid (c->odr_out, CLASS_SCHEMA, resultset->schema); - if (!compo->u.complex->generic->schema) + if (!compo->u.complex->generic->schema.oid) { /* OID wasn't a schema! Try record syntax instead. */ - compo->u.complex->generic->schema = (Odr_oid *) - yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, schema); + compo->u.complex->generic->schema.oid = (Odr_oid *) + yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, resultset->schema); } if (elementSetName && *elementSetName) { @@ -1793,21 +2130,26 @@ static Z_ItemOrder *encode_item_order(ZOOM_package p) req->u.esRequest->notToKeep = (Z_IOOriginPartNotToKeep *) odr_malloc(p->odr_out,sizeof(Z_IOOriginPartNotToKeep)); - req->u.esRequest->notToKeep->resultSetItem = (Z_IOResultSetItem *) - odr_malloc(p->odr_out, sizeof(Z_IOResultSetItem)); - str = ZOOM_options_get(p->options, "itemorder-setname"); if (!str) str = "default"; - req->u.esRequest->notToKeep->resultSetItem->resultSetId = - nmem_strdup (p->odr_out->mem, str); - req->u.esRequest->notToKeep->resultSetItem->item = - (int *) odr_malloc(p->odr_out, sizeof(int)); + + if (!*str) + req->u.esRequest->notToKeep->resultSetItem = 0; + else + { + req->u.esRequest->notToKeep->resultSetItem = (Z_IOResultSetItem *) + odr_malloc(p->odr_out, sizeof(Z_IOResultSetItem)); + + req->u.esRequest->notToKeep->resultSetItem->resultSetId = + nmem_strdup (p->odr_out->mem, str); + req->u.esRequest->notToKeep->resultSetItem->item = + (int *) odr_malloc(p->odr_out, sizeof(int)); - str = ZOOM_options_get(p->options, "itemorder-item"); - *req->u.esRequest->notToKeep->resultSetItem->item = - (str ? atoi(str) : 1); - + str = ZOOM_options_get(p->options, "itemorder-item"); + *req->u.esRequest->notToKeep->resultSetItem->item = + (str ? atoi(str) : 1); + } req->u.esRequest->notToKeep->itemRequest = encode_ill_request(p); return req; @@ -1901,6 +2243,7 @@ ZOOM_package_option_get (ZOOM_package p, const char *key) return ZOOM_options_get (p->options, key); } + ZOOM_API(void) ZOOM_package_option_set (ZOOM_package p, const char *key, const char *val) @@ -1920,8 +2263,7 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) } yaz_log (LOG_DEBUG, "ZOOM_connection_exec_task type=%d run=%d", task->which, task->running); - if (c->error != ZOOM_ERROR_NONE || - (!c->cs && task->which != ZOOM_TASK_CONNECT)) + if (c->error != ZOOM_ERROR_NONE) { yaz_log (LOG_DEBUG, "remove tasks because of error = %d", c->error); ZOOM_connection_remove_tasks (c); @@ -1933,23 +2275,38 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) return 0; } task->running = 1; - switch (task->which) + ret = zoom_complete; + if (c->cs || task->which == ZOOM_TASK_CONNECT) { - case ZOOM_TASK_SEARCH: - ret = ZOOM_connection_send_search (c); - break; - case ZOOM_TASK_RETRIEVE: - ret = send_present (c); - break; - case ZOOM_TASK_CONNECT: - ret = do_connect(c); - break; - case ZOOM_TASK_SCAN: - ret = send_scan(c); - break; - case ZOOM_TASK_PACKAGE: - ret = send_package(c); - break; + switch (task->which) + { + case ZOOM_TASK_SEARCH: + if (c->proto == PROTO_HTTP) + ret = ZOOM_connection_srw_send_search(c); + else + ret = ZOOM_connection_send_search(c); + break; + case ZOOM_TASK_RETRIEVE: + if (c->proto == PROTO_HTTP) + ret = ZOOM_connection_srw_send_search(c); + else + ret = send_present (c); + break; + case ZOOM_TASK_CONNECT: + ret = do_connect(c); + break; + case ZOOM_TASK_SCAN: + ret = send_scan(c); + break; + case ZOOM_TASK_PACKAGE: + ret = send_package(c); + break; + } + } + else + { + yaz_log (LOG_DEBUG, "remove tasks because no connection exist"); + ZOOM_connection_remove_tasks (c); } if (ret == zoom_complete) { @@ -2000,9 +2357,18 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) { case Z_APDU_initResponse: initrs = apdu->u.initResponse; + ZOOM_connection_option_set(c, "targetImplementationId", + initrs->implementationId ? + initrs->implementationId : ""); + ZOOM_connection_option_set(c, "targetImplementationName", + initrs->implementationName ? + initrs->implementationName : ""); + ZOOM_connection_option_set(c, "targetImplementationVersion", + initrs->implementationVersion ? + initrs->implementationVersion : ""); if (!*initrs->result) { - c->error = ZOOM_ERROR_INIT; + set_ZOOM_error(c, ZOOM_ERROR_INIT, 0); } else { @@ -2080,20 +2446,156 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) } else { - c->error = ZOOM_ERROR_CONNECTION_LOST; + set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, 0); do_close(c); } break; default: - c->error = ZOOM_ERROR_DECODE; + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); do_close(c); } } +#if HAVE_XML2 +static void handle_srw_response(ZOOM_connection c, + Z_SRW_searchRetrieveResponse *res) +{ + ZOOM_resultset resultset = 0; + int i; + NMEM nmem; + ZOOM_Event event; + + if (!c->tasks) + return; + + if (c->tasks->which == ZOOM_TASK_SEARCH) + resultset = c->tasks->u.search.resultset; + else if (c->tasks->which == ZOOM_TASK_RETRIEVE) + resultset = c->tasks->u.retrieve.resultset; + else + return ; + + event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH); + ZOOM_connection_put_event(c, event); + + resultset->size = 0; + + yaz_log(LOG_DEBUG, "got SRW response OK"); + + if (res->numberOfRecords) + resultset->size = *res->numberOfRecords; + + for (i = 0; inum_records; i++) + { + int pos; + + Z_NamePlusRecord *npr = (Z_NamePlusRecord *) + odr_malloc(c->odr_in, sizeof(Z_NamePlusRecord)); + + if (res->records[i].recordPosition && + *res->records[i].recordPosition > 0) + pos = *res->records[i].recordPosition - 1; + else + pos = resultset->start + i; + + npr->databaseName = 0; + npr->which = Z_NamePlusRecord_databaseRecord; + npr->u.databaseRecord = (Z_External *) + odr_malloc(c->odr_in, sizeof(Z_External)); + npr->u.databaseRecord->descriptor = 0; + npr->u.databaseRecord->direct_reference = + yaz_oidval_to_z3950oid(c->odr_in, CLASS_RECSYN, VAL_TEXT_XML); + npr->u.databaseRecord->which = Z_External_octet; + npr->u.databaseRecord->u.octet_aligned = (Odr_oct *) + odr_malloc(c->odr_in, sizeof(Odr_oct)); + npr->u.databaseRecord->u.octet_aligned->buf = + res->records[i].recordData_buf; + npr->u.databaseRecord->u.octet_aligned->len = + npr->u.databaseRecord->u.octet_aligned->size = + res->records[i].recordData_len; + record_cache_add (resultset, npr, pos); + } + if (res->num_diagnostics > 0) + { + set_dset_error(c, *res->diagnostics[0].code, "SRW", + res->diagnostics[0].details, 0); + } + nmem = odr_extract_mem(c->odr_in); + nmem_transfer(resultset->odr->mem, nmem); + nmem_destroy(nmem); +} +#endif + +#if HAVE_XML2 +static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) +{ + int ret = -1; + const char *content_type = z_HTTP_header_lookup(hres->headers, + "Content-Type"); + const char *connection_head = z_HTTP_header_lookup(hres->headers, + "Connection"); + c->mask = 0; + yaz_log (LOG_DEBUG, "handle_http"); + + if (content_type && !yaz_strcmp_del("text/xml", content_type, "; ")) + { + Z_SOAP *soap_package = 0; + ODR o = odr_createmem(ODR_DECODE); + Z_SOAP_Handler soap_handlers[2] = { + {"http://www.loc.gov/zing/srw/v1.0/", 0, + (Z_SOAP_fun) yaz_srw_codec}, + {0, 0, 0} + }; + ret = z_soap_codec(o, &soap_package, + &hres->content_buf, &hres->content_len, + soap_handlers); + if (!ret && soap_package->which == Z_SOAP_generic && + soap_package->u.generic->no == 0) + { + Z_SRW_PDU *sr = soap_package->u.generic->p; + if (sr->which == Z_SRW_searchRetrieve_response) + handle_srw_response(c, sr->u.response); + else + ret = -1; + } + else if (!ret && (soap_package->which == Z_SOAP_fault + || soap_package->which == Z_SOAP_error)) + { + set_HTTP_error(c, hres->code, + soap_package->u.fault->fault_code, + soap_package->u.fault->fault_string); + } + else + ret = -1; + odr_destroy(o); + } + if (ret) + { + if (hres->code != 200) + set_HTTP_error(c, hres->code, 0, 0); + else + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); + do_close (c); + } + ZOOM_connection_remove_task(c); + if (!strcmp(hres->version, "1.0")) + { + /* HTTP 1.0: only if Keep-Alive we stay alive.. */ + if (!connection_head || strcmp(connection_head, "Keep-Alive")) + do_close(c); + } + else + { + /* HTTP 1.1: only if no close we stay alive .. */ + if (connection_head && !strcmp(connection_head, "close")) + do_close(c); + } +} +#endif + static int do_read (ZOOM_connection c) { int r; - Z_APDU *apdu; ZOOM_Event event; event = ZOOM_Event_create (ZOOM_EVENT_RECV_DATA); @@ -2116,24 +2618,36 @@ static int do_read (ZOOM_connection c) } else { - c->error= ZOOM_ERROR_CONNECTION_LOST; + set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, 0); do_close (c); } } else { + Z_GDU *gdu; ZOOM_Event event; + odr_reset (c->odr_in); odr_setbuf (c->odr_in, c->buf_in, r, 0); event = ZOOM_Event_create (ZOOM_EVENT_RECV_APDU); ZOOM_connection_put_event (c, event); - if (!z_APDU (c->odr_in, &apdu, 0, 0)) + + if (!z_GDU (c->odr_in, &gdu, 0, 0)) { - c->error = ZOOM_ERROR_DECODE; + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); do_close (c); } - else - handle_apdu (c, apdu); + else if (gdu->which == Z_GDU_Z3950) + handle_apdu (c, gdu->u.z3950); + else if (gdu->which == Z_GDU_HTTP_Response) + { +#if HAVE_XML2 + handle_http (c, gdu->u.HTTP_Response); +#else + set_ZOOM_error(c, ZOOM_ERROR_DECODE, 0); + do_close (c); +#endif + } c->reconnect_ok = 0; } return 1; @@ -2157,12 +2671,12 @@ static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out) yaz_log (LOG_DEBUG, "reconnect write"); c->tasks->running = 0; ZOOM_connection_insert_task (c, ZOOM_TASK_CONNECT); - return zoom_complete; + return zoom_pending; } if (c->state == STATE_CONNECTING) - c->error = ZOOM_ERROR_CONNECT; + set_ZOOM_error(c, ZOOM_ERROR_CONNECT, 0); else - c->error = ZOOM_ERROR_CONNECTION_LOST; + set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, 0); do_close (c); return zoom_complete; } @@ -2177,7 +2691,6 @@ static zoom_ret do_write_ex (ZOOM_connection c, char *buf_out, int len_out) } else { - // c->reconnect_ok = 0; c->mask = ZOOM_SELECT_READ|ZOOM_SELECT_EXCEPT; yaz_log (LOG_DEBUG, "do_write_ex 2 mask=%d", c->mask); } @@ -2239,47 +2752,70 @@ ZOOM_connection_addinfo (ZOOM_connection c) return addinfo; } +ZOOM_API(const char *) +ZOOM_diag_str (int error) +{ + switch (error) + { + case ZOOM_ERROR_NONE: + return "No error"; + case ZOOM_ERROR_CONNECT: + return "Connect failed"; + case ZOOM_ERROR_MEMORY: + return "Out of memory"; + case ZOOM_ERROR_ENCODE: + return "Encoding failed"; + case ZOOM_ERROR_DECODE: + return "Decoding failed"; + case ZOOM_ERROR_CONNECTION_LOST: + return "Connection lost"; + case ZOOM_ERROR_INIT: + return "Init rejected"; + case ZOOM_ERROR_INTERNAL: + return "Internal failure"; + case ZOOM_ERROR_TIMEOUT: + return "Timeout"; + case ZOOM_ERROR_UNSUPPORTED_PROTOCOL: + return "Unsupported protocol"; + case ZOOM_ERROR_UNSUPPORTED_QUERY: + return "Unsupported query type"; + default: + return diagbib1_str (error); + } +} + ZOOM_API(int) -ZOOM_connection_error (ZOOM_connection c, const char **cp, - const char **addinfo) +ZOOM_connection_error_x (ZOOM_connection c, const char **cp, + const char **addinfo, const char **diagset) { int error = c->error; if (cp) { - switch (error) - { - case ZOOM_ERROR_NONE: - *cp = "No error"; break; - case ZOOM_ERROR_CONNECT: - *cp = "Connect failed"; break; - case ZOOM_ERROR_MEMORY: - *cp = "Out of memory"; break; - case ZOOM_ERROR_ENCODE: - *cp = "Encoding failed"; break; - case ZOOM_ERROR_DECODE: - *cp = "Decoding failed"; break; - case ZOOM_ERROR_CONNECTION_LOST: - *cp = "Connection lost"; break; - case ZOOM_ERROR_INIT: - *cp = "Init rejected"; break; - case ZOOM_ERROR_INTERNAL: - *cp = "Internal failure"; break; - case ZOOM_ERROR_TIMEOUT: - *cp = "Timeout"; break; - default: - *cp = diagbib1_str (error); - } + if (!c->diagset || !strcmp(c->diagset, "ZOOM")) + *cp = ZOOM_diag_str(error); + else if (!strcmp(c->diagset, "HTTP")) + *cp = z_HTTP_errmsg(c->error); + else if (!strcmp(c->diagset, "Bib-1")) + *cp = ZOOM_diag_str(error); + else if (!strcmp(c->diagset, "SRW")) + *cp = yaz_diag_srw_str(c->error); + else + *cp = "Unknown error and diagnostic set"; } if (addinfo) - { - if (c->addinfo) - *addinfo = c->addinfo; - else - *addinfo = ""; - } + *addinfo = c->addinfo ? c->addinfo : ""; + if (diagset) + *diagset = c->diagset ? c->diagset : ""; return c->error; } +ZOOM_API(int) +ZOOM_connection_error (ZOOM_connection c, const char **cp, + const char **addinfo) +{ + return ZOOM_connection_error_x(c, cp, addinfo, 0); +} + static int ZOOM_connection_do_io(ZOOM_connection c, int mask) { ZOOM_Event event = 0; @@ -2290,7 +2826,7 @@ static int ZOOM_connection_do_io(ZOOM_connection c, int mask) if (r == CS_NONE) { event = ZOOM_Event_create (ZOOM_EVENT_CONNECT); - c->error = ZOOM_ERROR_CONNECT; + set_ZOOM_error(c, ZOOM_ERROR_CONNECT, 0); do_close (c); ZOOM_connection_put_event (c, event); } @@ -2313,12 +2849,21 @@ static int ZOOM_connection_do_io(ZOOM_connection c, int mask) else if (ret == 0) { ZOOM_connection_put_event (c, event); - ZOOM_connection_send_init (c); + if (c->proto == PROTO_Z3950) + ZOOM_connection_send_init(c); + else + { + /* no init request for SRW .. */ + assert (c->tasks->which == ZOOM_TASK_CONNECT); + ZOOM_connection_remove_task (c); + c->mask = 0; + ZOOM_connection_exec_task (c); + } c->state = STATE_ESTABLISHED; } else { - c->error = ZOOM_ERROR_CONNECT; + set_ZOOM_error(c, ZOOM_ERROR_CONNECT, 0); do_close (c); ZOOM_connection_put_event (c, event); } @@ -2467,7 +3012,7 @@ ZOOM_event (int no, ZOOM_connection *cs) { ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_TIMEOUT); /* timeout and this connection was waiting */ - c->error = ZOOM_ERROR_TIMEOUT; + set_ZOOM_error(c, ZOOM_ERROR_TIMEOUT, 0); do_close (c); ZOOM_connection_put_event(c, event); } @@ -2503,7 +3048,7 @@ ZOOM_event (int no, ZOOM_connection *cs) { ZOOM_Event event = ZOOM_Event_create(ZOOM_EVENT_TIMEOUT); /* timeout and this connection was waiting */ - c->error = ZOOM_ERROR_TIMEOUT; + set_ZOOM_error(c, ZOOM_ERROR_TIMEOUT, 0); do_close (c); yaz_log (LOG_DEBUG, "timeout"); ZOOM_connection_put_event(c, event);