X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fzoom-c.c;h=417e7fd7ee82556cc52840253ade22ce32c40d62;hb=19c0b332044f06ee33eaf66ca92675d9cda8d1b9;hp=44408840d8821b5a6a8823b1d2d02dbd353f8252;hpb=84cb4c71eb572b5700cd7b3230446d9578521870;p=yaz-moved-to-github.git diff --git a/src/zoom-c.c b/src/zoom-c.c index 4440884..417e7fd 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.109 2007-01-22 10:35:07 adam Exp $ + * $Id: zoom-c.c,v 1.115 2007-03-07 14:26:44 adam Exp $ */ /** * \file zoom-c.c @@ -27,6 +27,8 @@ #include #include +#define TASK_FIX 1 + static int log_api = 0; static int log_details = 0; @@ -39,6 +41,21 @@ 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); static char *cql2pqf(ZOOM_connection c, const char *cql); + +/* + * This wrapper is just for logging failed lookups. It would be nicer + * if it could cause failure when a lookup fails, but that's hard. + */ +static Odr_oid *zoom_yaz_str_to_z3950oid(ZOOM_connection c, + int oid_class, const char *str) { + Odr_oid *res = yaz_str_to_z3950oid(c->odr_out, oid_class, str); + if (res == 0) + yaz_log(YLOG_WARN, "%p OID lookup (%d, '%s') failed", + c, (int) oid_class, str); + return res; +} + + static void initlog(void) { static int log_level_initialized = 0; @@ -103,6 +120,13 @@ static ZOOM_Event ZOOM_connection_get_event(ZOOM_connection c) return event; } +static void ZOOM_connection_remove_events(ZOOM_connection c) +{ + ZOOM_Event event; + while ((event = ZOOM_connection_get_event(c))) + ZOOM_Event_destroy(event); +} + ZOOM_API(int) ZOOM_connection_peek_event(ZOOM_connection c) { ZOOM_Event event = c->m_queue_front; @@ -110,6 +134,8 @@ ZOOM_API(int) ZOOM_connection_peek_event(ZOOM_connection c) return event ? event->kind : ZOOM_EVENT_NONE; } +void ZOOM_connection_remove_tasks(ZOOM_connection c); + static void set_dset_error(ZOOM_connection c, int error, const char *dset, const char *addinfo, const char *addinfo2) @@ -135,11 +161,16 @@ static void set_dset_error(ZOOM_connection c, int error, } else if (addinfo) c->addinfo = xstrdup(addinfo); - if (error) + if (error != ZOOM_ERROR_NONE) + { yaz_log(log_api, "%p set_dset_error %s %s:%d %s %s", c, c->host_port ? c->host_port : "<>", dset, error, addinfo ? addinfo : "", addinfo2 ? addinfo2 : ""); +#if TASK_FIX + ZOOM_connection_remove_tasks(c); +#endif + } } #if YAZ_HAVE_XML2 @@ -150,6 +181,7 @@ static void set_HTTP_error(ZOOM_connection c, int error, } #endif + static void set_ZOOM_error(ZOOM_connection c, int error, const char *addinfo) { @@ -165,6 +197,8 @@ static void clear_error(ZOOM_connection c) * or Init Refused are not cleared, because they are not * recoverable: doing another search doesn't help. */ + + ZOOM_connection_remove_events(c); switch (c->error) { case ZOOM_ERROR_CONNECT: @@ -398,7 +432,7 @@ ZOOM_API(void) initlog(); yaz_log(log_api, "%p ZOOM_connection_connect host=%s portnum=%d", - c, host, portnum); + c, host ? host : "null", portnum); set_ZOOM_error(c, ZOOM_ERROR_NONE, 0); ZOOM_connection_remove_tasks(c); @@ -440,15 +474,18 @@ ZOOM_API(void) else c->lang = 0; - xfree(c->host_port); - if (portnum) + if (host) { - char hostn[128]; - sprintf(hostn, "%.80s:%d", host, portnum); - c->host_port = xstrdup(hostn); - } - else - c->host_port = xstrdup(host); + xfree(c->host_port); + if (portnum) + { + char hostn[128]; + sprintf(hostn, "%.80s:%d", host, portnum); + c->host_port = xstrdup(hostn); + } + else + c->host_port = xstrdup(host); + } { /* @@ -682,6 +719,7 @@ ZOOM_API(void) odr_destroy(c->odr_out); ZOOM_options_destroy(c->options); ZOOM_connection_remove_tasks(c); + ZOOM_connection_remove_events(c); xfree(c->host_port); xfree(c->path); xfree(c->proxy); @@ -953,12 +991,18 @@ static void do_close(ZOOM_connection c) static int ZOOM_test_reconnect(ZOOM_connection c) { + ZOOM_Event event; + if (!c->reconnect_ok) return 0; do_close(c); c->reconnect_ok = 0; c->tasks->running = 0; ZOOM_connection_insert_task(c, ZOOM_TASK_CONNECT); + + event = ZOOM_Event_create(ZOOM_EVENT_CONNECT); + ZOOM_connection_put_event(c, event); + return 1; } @@ -1250,7 +1294,7 @@ static zoom_ret ZOOM_connection_send_init(ZOOM_connection c) odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.109 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.115 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = @@ -1552,7 +1596,7 @@ static zoom_ret ZOOM_connection_send_search(ZOOM_connection c) } if (syntax) search_req->preferredRecordSyntax = - yaz_str_to_z3950oid(c->odr_out, CLASS_RECSYN, syntax); + zoom_yaz_str_to_z3950oid(c, CLASS_RECSYN, syntax); if (!r->setname) { @@ -2392,6 +2436,16 @@ static void handle_search_response(ZOOM_connection c, Z_SearchResponse *sr) resultset = c->tasks->u.search.resultset; + if (sr->resultSetStatus) + { + ZOOM_options_set_int(resultset->options, "resultSetStatus", + *sr->resultSetStatus); + } + if (sr->presentStatus) + { + ZOOM_options_set_int(resultset->options, "presentStatus", + *sr->presentStatus); + } handle_searchResult(c, resultset, sr->additionalSearchInfo); resultset->size = *sr->resultCount; @@ -2537,7 +2591,7 @@ static zoom_ret send_present(ZOOM_connection c) if (syntax && *syntax) req->preferredRecordSyntax = - yaz_str_to_z3950oid(c->odr_out, CLASS_RECSYN, syntax); + zoom_yaz_str_to_z3950oid(c, CLASS_RECSYN, syntax); if (resultset->schema && *resultset->schema) { @@ -2557,14 +2611,14 @@ static zoom_ret send_present(ZOOM_connection c) 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); + zoom_yaz_str_to_z3950oid (c, CLASS_SCHEMA, resultset->schema); if (!compo->u.complex->generic->schema.oid) { /* OID wasn't a schema! Try record syntax instead. */ compo->u.complex->generic->schema.oid = (Odr_oid *) - yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, resultset->schema); + zoom_yaz_str_to_z3950oid (c, CLASS_RECSYN, resultset->schema); } if (elementSetName && *elementSetName) { @@ -3734,11 +3788,7 @@ static int do_read(ZOOM_connection c) return 0; if (r <= 0) { - if (ZOOM_test_reconnect(c)) - { - yaz_log(log_details, "%p do_read reconnect read", c); - } - else + if (!ZOOM_test_reconnect(c)) { set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, c->host_port); do_close(c); @@ -4029,12 +4079,7 @@ static void ZOOM_connection_do_io(ZOOM_connection c, int mask) { if (mask & ZOOM_SELECT_EXCEPT) { - if (ZOOM_test_reconnect(c)) - { - event = ZOOM_Event_create(ZOOM_EVENT_CONNECT); - ZOOM_connection_put_event(c, event); - } - else + if (!ZOOM_test_reconnect(c)) { set_ZOOM_error(c, ZOOM_ERROR_CONNECTION_LOST, c->host_port); do_close(c);