X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzoom-c.c;h=3fbd46b1fbf58383c349852d5e5375b40e98affb;hb=3dcdf20f2ccc20554dc247f60281eb06111f0bf6;hp=9bcbed4878998cb2ad7a7196c6f2e4fdc1bdf5b6;hpb=67940e6310f39f7e289d48a7d1fbb577eca56686;p=yaz-moved-to-github.git diff --git a/zoom/zoom-c.c b/zoom/zoom-c.c index 9bcbed4..3fbd46b 100644 --- a/zoom/zoom-c.c +++ b/zoom/zoom-c.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-c.c,v 1.33 2002-06-02 21:27:17 adam Exp $ + * $Id: zoom-c.c,v 1.38 2002-07-29 19:51:34 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -208,10 +208,13 @@ static char **set_DatabaseNames (ZOOM_connection con, ZOOM_options options, if (!cp || !*cp) { - cp = strchr (con->host_port, '/'); + if (strncmp (con->host_port, "unix:", 5) == 0) + cp = strchr (con->host_port+5, ':'); + else + cp = strchr (con->host_port, '/'); if (cp) cp++; - } + } if (cp) { c = cp; @@ -268,9 +271,11 @@ ZOOM_connection_connect(ZOOM_connection c, if (c->cs) { + yaz_log (LOG_DEBUG, "reconnect"); c->reconnect_ok = 1; return; } + yaz_log(LOG_DEBUG, "connect"); xfree (c->proxy); val = ZOOM_options_get (c->options, "proxy"); if (val && *val) @@ -629,6 +634,39 @@ int z3950_connection_mask(ZOOM_connection c) return 0; } +static void otherInfo_attach (ZOOM_connection c, Z_APDU *a, ODR out) +{ + int i; + for (i = 0; i<200; i++) + { + size_t len; + Z_OtherInformation **oi; + char buf[20]; + const char *val; + const char *cp; + int oidval; + + sprintf (buf, "otherInfo%d", i); + val = ZOOM_options_get (c->options, buf); + if (!val) + break; + cp = strchr (val, ':'); + if (!cp) + continue; + len = cp - val; + if (len >= sizeof(buf)) + len = sizeof(buf)-1; + memcpy (buf, val, len); + buf[len] = '\0'; + oidval = oid_getvalbyname (buf); + if (oidval == VAL_NONE) + continue; + + yaz_oi_APDU(a, &oi); + yaz_oi_set_string_oidval(oi, out, oidval, 1, cp+1); + } +} + static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) { assert (a); @@ -644,6 +682,7 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) yaz_oi_APDU(a, &oi); yaz_oi_set_string_oidval(oi, out, VAL_CLIENT_IP, 1, c->client_IP); } + otherInfo_attach (c, a, out); if (!z_APDU(out, &a, 0, 0)) { FILE *outf = fopen("/tmp/apdu.txt", "a"); @@ -770,13 +809,14 @@ static int ZOOM_connection_send_init (ZOOM_connection c) if ((oi_unit = yaz_oi_update(oi, c->odr_out, NULL, 0, 0))) { - ODR_MASK_SET(ireq->options, Z_Options_negotiationModel); - - oi_unit->which = Z_OtherInfo_externallyDefinedInfo; - oi_unit->information.externallyDefinedInfo = - yaz_set_proposal_charneg(c->odr_out, - (const char **)&c->charset, (c->charset) ? 1:0, - (const char **)&c->lang, (c->lang) ? 1:0, 1); + ODR_MASK_SET(ireq->options, Z_Options_negotiationModel); + + oi_unit->which = Z_OtherInfo_externallyDefinedInfo; + oi_unit->information.externallyDefinedInfo = + yaz_set_proposal_charneg + (c->odr_out, + (const char **)&c->charset, (c->charset) ? 1:0, + (const char **)&c->lang, (c->lang) ? 1:0, 1); } } assert (apdu); @@ -1111,6 +1151,30 @@ ZOOM_record_get (ZOOM_record rec, const char *type, int *len) else if (!strcmp (type, "raw")) { if (npr->which == Z_NamePlusRecord_databaseRecord) + { + Z_External *r = (Z_External *) npr->u.databaseRecord; + + if (r->which == Z_External_sutrs) + { + if (len) *len = r->u.sutrs->len; + return (const char *) r->u.sutrs->buf; + } + else if (r->which == Z_External_octet) + { + if (len) *len = r->u.octet_aligned->len; + return (const char *) r->u.octet_aligned->buf; + } + else /* grs-1, explain, ... */ + { + if (len) *len = -1; + return (const char *) npr->u.databaseRecord; + } + } + return 0; + } + else if (!strcmp (type, "ext")) + { + if (npr->which == Z_NamePlusRecord_databaseRecord) return (const char *) npr->u.databaseRecord; return 0; } @@ -1893,8 +1957,8 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) { Z_InitResponse *initrs; - yaz_log (LOG_DEBUG, "hande_apdu type=%d", apdu->which); c->mask = 0; + yaz_log (LOG_DEBUG, "hande_apdu type=%d", apdu->which); switch(apdu->which) { case Z_APDU_initResponse: @@ -1965,6 +2029,22 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) es_response (c, apdu->u.extendedServicesResponse); ZOOM_connection_remove_task (c); break; + case Z_APDU_close: + if (c->reconnect_ok) + { + do_close(c); + c->tasks->running = 0; + ZOOM_connection_insert_task (c, ZOOM_TASK_CONNECT); + } + else + { + c->error = ZOOM_ERROR_CONNECTION_LOST; + do_close(c); + } + break; + default: + c->error = ZOOM_ERROR_DECODE; + do_close(c); } } @@ -2001,7 +2081,6 @@ static int do_read (ZOOM_connection c) else { ZOOM_Event event; - c->reconnect_ok = 0; odr_reset (c->odr_in); odr_setbuf (c->odr_in, c->buf_in, r, 0); event = ZOOM_Event_create (ZOOM_EVENT_RECV_APDU); @@ -2012,9 +2091,8 @@ static int do_read (ZOOM_connection c) do_close (c); } else - { handle_apdu (c, apdu); - } + c->reconnect_ok = 0; } return 1; } @@ -2260,7 +2338,7 @@ ZOOM_event (int no, ZOOM_connection *cs) #if HAVE_SYS_POLL_H #else - tv.tv_sec = 15; + tv.tv_sec = 25; tv.tv_usec = 0; FD_ZERO (&input); @@ -2321,7 +2399,7 @@ ZOOM_event (int no, ZOOM_connection *cs) if (!nfds) return 0; #if HAVE_SYS_POLL_H - r = poll (pollfds, nfds, 15000); + r = poll (pollfds, nfds, 25000); for (i = 0; i