From db585d7fcb8319fa86543eb062df7fdaf16858c6 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 17 Feb 2003 21:23:31 +0000 Subject: [PATCH] HTTP Timeouts. Memory leak checks and fixes. Changed member names for schema via ASN.1 compiler directives. --- CHANGELOG | 4 ++-- client/client.c | 10 +++++----- server/eventl.c | 32 +++++++++++++++++++++----------- server/seshigh.c | 24 ++++++++++++++++++------ server/session.h | 11 +---------- server/statserv.c | 8 ++++---- z39.50/z.tcl | 3 ++- zoom/zoomsh.c | 17 +++++++++++++---- zutil/srwtst.c | 6 +++++- zutil/zgdu.c | 4 ++-- zutil/zoom-c.c | 35 +++++++++++++++++++++++++---------- 11 files changed, 98 insertions(+), 56 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 29dc685..ee5f6d4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,8 +3,8 @@ Possible compatibility problems with earlier versions marked with '*'. --- 1.9.3 2003/MM/DD Support for SRW 1.0. This is an optional feature and requires -libxml and libxslt to operate. Enable it by specifying --with-xslt for -configure. +libxml and libxslt to operate. Enable it by specifying --with-xslt +for configure. Z39.50 Query Type-104 added - to facilitate CQL within Z39.50. diff --git a/client/client.c b/client/client.c index 85e54b6..cd973bd 100644 --- a/client/client.c +++ b/client/client.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: client.c,v 1.181 2003-02-14 18:49:23 adam Exp $ + * $Id: client.c,v 1.182 2003-02-17 21:23:31 adam Exp $ */ #include @@ -1788,14 +1788,14 @@ static int send_presentRequest(char *arg) compo.u.complex->generic = (Z_Specification *) odr_malloc(out, sizeof(*compo.u.complex->generic)); - compo.u.complex->generic->which = Z_Specification_oid; - compo.u.complex->generic->u.oid = (Odr_oid *) + compo.u.complex->generic->which = Z_Schema_oid; + compo.u.complex->generic->schema.oid = (Odr_oid *) odr_oiddup(out, oid_ent_to_oid(&prefschema, oid)); - if (!compo.u.complex->generic->u.oid) + if (!compo.u.complex->generic->schema.oid) { /* OID wasn't a schema! Try record syntax instead. */ prefschema.oclass = CLASS_RECSYN; - compo.u.complex->generic->u.oid = (Odr_oid *) + compo.u.complex->generic->schema.oid = (Odr_oid *) odr_oiddup(out, oid_ent_to_oid(&prefschema, oid)); } if (!elementSetNames) diff --git a/server/eventl.c b/server/eventl.c index 541bba4..cc150e7 100644 --- a/server/eventl.c +++ b/server/eventl.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: eventl.c,v 1.35 2003-02-12 15:06:43 adam Exp $ + * $Id: eventl.c,v 1.36 2003-02-17 21:23:31 adam Exp $ */ #include @@ -57,8 +57,8 @@ int event_loop(IOCHAN *iochans) IOCHAN p, nextp; fd_set in, out, except; int res, max; - static struct timeval nullto = {0, 0}, to; - struct timeval *timeout; + static struct timeval to; + time_t now = time(0); if (statserv_must_terminate()) { @@ -68,16 +68,16 @@ int event_loop(IOCHAN *iochans) FD_ZERO(&in); FD_ZERO(&out); FD_ZERO(&except); - timeout = &to; /* hang on select */ - to.tv_sec = 5*60; - to.tv_usec = 0; + to.tv_sec = 3600; + to.tv_usec = 1; max = 0; for (p = *iochans; p; p = p->next) { + time_t w, ftime; yaz_log(LOG_LOG, "fd=%d flags=%d force_event=%d", p->fd, p->flags, p->force_event); if (p->force_event) - timeout = &nullto; /* polling select */ + to.tv_sec = 0; /* polling select */ if (p->flags & EVENT_INPUT) FD_SET(p->fd, &in); if (p->flags & EVENT_OUTPUT) @@ -86,9 +86,19 @@ int event_loop(IOCHAN *iochans) FD_SET(p->fd, &except); if (p->fd > max) max = p->fd; + if (p->max_idle && p->last_event) + { + ftime = p->last_event + p->max_idle; + if (ftime < now) + w = p->max_idle; + else + w = ftime - now; + if (w < to.tv_sec) + to.tv_sec = w; + } } - yaz_log(LOG_LOG, "select start"); - res = YAZ_EV_SELECT(max + 1, &in, &out, &except, timeout); + yaz_log(LOG_LOG, "select start %d", to.tv_sec); + res = YAZ_EV_SELECT(max + 1, &in, &out, &except, &to); yaz_log(LOG_LOG, "select end"); if (res < 0) { @@ -114,10 +124,10 @@ int event_loop(IOCHAN *iochans) *iochans); } } + now = time(0); for (p = *iochans; p; p = p->next) { int force_event = p->force_event; - time_t now = time(0); p->force_event = 0; if (!p->destroyed && (FD_ISSET(p->fd, &in) || @@ -138,7 +148,7 @@ int event_loop(IOCHAN *iochans) p->last_event = now; (*p->fun)(p, EVENT_EXCEPT); } - if (!p->destroyed && ((p->max_idle && now - p->last_event > + if (!p->destroyed && ((p->max_idle && now - p->last_event >= p->max_idle) || force_event == EVENT_TIMEOUT)) { p->last_event = now; diff --git a/server/seshigh.c b/server/seshigh.c index b19cc62..8820d5d 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2003, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.136 2003-02-17 14:35:42 adam Exp $ + * $Id: seshigh.c,v 1.137 2003-02-17 21:23:31 adam Exp $ */ /* @@ -181,7 +181,9 @@ void destroy_association(association *h) xfree(h); xmalloc_trav("session closed"); if (control_block && control_block->one_shot) + { exit (0); + } } static void do_close_req(association *a, int reason, char *message, @@ -202,7 +204,7 @@ static void do_close_req(association *a, int reason, char *message, *cls->closeReason = reason; cls->diagnosticInformation = message; process_z_response(a, req, &apdu); - iochan_settimeout(a->client_chan, 60); + iochan_settimeout(a->client_chan, 20); } else { @@ -383,14 +385,12 @@ void ir_session(IOCHAN h, int event) { /* restore mask for cs_get operation ... */ iochan_clearflag(h, EVENT_OUTPUT|EVENT_INPUT); iochan_setflag(h, assoc->cs_get_mask); - yaz_log(LOG_LOG, "queue empty mask=%d", assoc->cs_get_mask); if (assoc->state == ASSOC_DEAD) iochan_setevent(assoc->client_chan, EVENT_TIMEOUT); } else { assoc->cs_put_mask = EVENT_OUTPUT; - yaz_log(LOG_LOG, "queue not empty"); } break; default: @@ -478,8 +478,8 @@ static void srw_bend_fetch(association *assoc, int pos, rr.comp->u.complex->generic = (Z_Specification *) odr_malloc(assoc->decode, sizeof(Z_Specification)); - rr.comp->u.complex->generic->which = Z_Specification_uri; - rr.comp->u.complex->generic->u.uri = srw_req->recordSchema; + rr.comp->u.complex->generic->which = Z_Schema_uri; + rr.comp->u.complex->generic->schema.uri = srw_req->recordSchema; rr.comp->u.complex->generic->elementSpec = 0; rr.stream = assoc->encode; @@ -797,6 +797,16 @@ static void process_http_request(association *assoc, request *req) } else { + int t; + const char *alive = z_HTTP_header_lookup(hreq->headers, "Keep-Alive"); + + if (alive && isdigit(*alive)) + t = atoi(alive); + else + t = 30; + if (t < 0 || t > 3600) + t = 3600; + iochan_settimeout(assoc->client_chan,t); z_HTTP_header_add(o, &hres->headers, "Connection", "Keep-Alive"); } process_gdu_response(assoc, req, p); @@ -838,6 +848,8 @@ static int process_z_request(association *assoc, request *req, char **msg) switch (req->apdu_request->which) { case Z_APDU_initRequest: + iochan_settimeout(assoc->client_chan, + statserv_getcontrol()->idle_timeout * 60); res = process_initRequest(assoc, req); break; case Z_APDU_searchRequest: res = process_searchRequest(assoc, req, &fd); break; diff --git a/server/session.h b/server/session.h index 72623f3..4254cd2 100644 --- a/server/session.h +++ b/server/session.h @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: session.h,v 1.28 2003-02-12 15:06:43 adam Exp $ + * $Id: session.h,v 1.29 2003-02-17 21:23:31 adam Exp $ */ #ifndef SESSION_H @@ -87,15 +87,6 @@ typedef struct association unsigned cs_accept_mask; struct bend_initrequest *init; -#if 0 - int (*bend_sort) (); - int (*bend_search) (); - int (*bend_present) (); - int (*bend_esrequest) (); - int (*bend_delete) (); - int (*bend_scan) (); - int (*bend_segment) (); -#endif } association; association *create_association(IOCHAN channel, COMSTACK link); diff --git a/server/statserv.c b/server/statserv.c index 3480c5d..2e01fbb 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -6,7 +6,7 @@ * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.92 2003-02-14 18:49:24 adam Exp $ + * $Id: statserv.c,v 1.93 2003-02-17 21:23:31 adam Exp $ */ #include @@ -58,7 +58,7 @@ statserv_options_block control_block = { "", /* diagnostic output to stderr */ "tcp:@:9999", /* default listener port */ PROTO_Z3950, /* default application protocol */ - 60, /* idle timeout (minutes) */ + 15, /* idle timeout (minutes) */ 1024*1024, /* maximum PDU size (approx.) to allow */ "default-config", /* configuration name to pass to backend */ "", /* set user id */ @@ -305,7 +305,7 @@ static void listener(IOCHAN h, int event) yaz_log(LOG_DEBUG, "Setting timeout %d", control_block.idle_timeout); iochan_setdata(new_chan, newas); - iochan_settimeout(new_chan, control_block.idle_timeout * 60); + iochan_settimeout(new_chan, 60); /* Now what we need todo is create a new thread with this iochan as the parameter */ @@ -565,7 +565,7 @@ static void *new_session (void *vp) newas->cs_get_mask = cs_get_mask; iochan_setdata(new_chan, newas); - iochan_settimeout(new_chan, control_block.idle_timeout * 60); + iochan_settimeout(new_chan, 60); a = cs_addrstr(new_line); yaz_log(LOG_LOG, "Starting session %d from %s", no_sessions, a ? a : "[Unknown]"); diff --git a/z39.50/z.tcl b/z39.50/z.tcl index bd2d6d7..47bb1c3 100644 --- a/z39.50/z.tcl +++ b/z39.50/z.tcl @@ -1,5 +1,5 @@ # YC Sample Config File for Z39.50 -# $Id: z.tcl,v 1.9 2002-12-05 12:07:00 adam Exp $ +# $Id: z.tcl,v 1.10 2003-02-17 21:23:31 adam Exp $ # ---------------------------------------------------------- # Prefix Specifications # @@ -134,6 +134,7 @@ set unionmap($m,OtherInformationUnit,information) {which information OtherInfo} set unionmap($m,OtherInformation) {num_elements list} set unionmap($m,Specification,elementSpec) {} set map($m,Specification_0) ElementSpec +set unionmap($m,Specification,schema) {which schema Schema} # ---- set m DiagnosticFormatDiag1 diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 8097066..fb538f3 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -1,5 +1,5 @@ /* - * $Id: zoomsh.c,v 1.14 2003-02-17 14:35:42 adam Exp $ + * $Id: zoomsh.c,v 1.15 2003-02-17 21:23:31 adam Exp $ * * ZOOM-C Shell */ @@ -18,6 +18,7 @@ #include +#include #include #define MAX_CON 100 @@ -227,6 +228,13 @@ static void cmd_ext (ZOOM_connection *c, ZOOM_resultset *r, } } +static void cmd_debug (ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) +{ + yaz_log_init_level(LOG_ALL); +} + static void cmd_search (ZOOM_connection *c, ZOOM_resultset *r, ZOOM_options options, const char **args) @@ -393,6 +401,8 @@ static int cmd_parse (ZOOM_connection *c, ZOOM_resultset *r, cmd_help(c, r, options, buf); else if (is_command ("ext", cmd_str, cmd_len)) cmd_ext(c, r, options, buf); + else if (is_command ("debug", cmd_str, cmd_len)) + cmd_debug(c, r, options, buf); else printf ("unknown command %.*s\n", cmd_len, cmd_str); return 2; @@ -440,9 +450,7 @@ int main (int argc, char **argv) ZOOM_connection z39_con[MAX_CON]; ZOOM_resultset z39_res[MAX_CON]; -#if 0 - yaz_log_init_level(65535); -#endif + nmem_init(); for (i = 0; i @@ -24,6 +24,7 @@ int main(int argc, char **argv) ODR decode, encode; int debug = 0; + nmem_init(); if (argc == 2 && !strcmp(argv[1], "debug")) debug = 1; no = fread(buf, 1, sizeof(buf), stdin); @@ -80,6 +81,9 @@ int main(int argc, char **argv) fprintf(stderr, "No output!\n"); exit(1); } + odr_destroy(decode); + odr_destroy(encode); + nmem_exit(); exit(0); } #else diff --git a/zutil/zgdu.c b/zutil/zgdu.c index 6213b12..b96bc4d 100644 --- a/zutil/zgdu.c +++ b/zutil/zgdu.c @@ -2,12 +2,12 @@ * Copyright (c) 2002-2003, Index Data. * See the file LICENSE for details. * - * $Id: zgdu.c,v 1.3 2003-02-17 14:35:42 adam Exp $ + * $Id: zgdu.c,v 1.4 2003-02-17 21:23:32 adam Exp $ */ #include -#define HTTP_DEBUG 1 +#define HTTP_DEBUG 0 static int decode_headers_content(ODR o, int off, Z_HTTP_Header **headers, char **content_buf, int *content_len) diff --git a/zutil/zoom-c.c b/zutil/zoom-c.c index 9a9e9da..2d299c1 100644 --- a/zutil/zoom-c.c +++ b/zutil/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2003, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.20 2003-02-17 14:35:42 adam Exp $ + * $Id: zoom-c.c,v 1.21 2003-02-17 21:23:32 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -347,7 +347,6 @@ ZOOM_connection_connect(ZOOM_connection c, c->lang = 0; xfree (c->host_port); - xfree (c->path); if (portnum) { char hostn[128]; @@ -466,6 +465,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); @@ -641,6 +641,20 @@ static void ZOOM_resultset_retrieve (ZOOM_resultset r, c = r->connection; if (!c) return; + + if (c->host_port && c->proto == PROTO_SRW) + { + 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; @@ -840,7 +854,6 @@ static int encode_APDU(ZOOM_connection c, Z_APDU *a, ODR out) static zoom_ret send_APDU (ZOOM_connection c, Z_APDU *a) { ZOOM_Event event; - yaz_log(LOG_LOG, "sending Z39.50 APDU"); assert (a); if (encode_APDU(c, a, c->odr_out)) return zoom_complete; @@ -1016,7 +1029,11 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) 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; @@ -1060,8 +1077,6 @@ static zoom_ret ZOOM_connection_srw_send_search(ZOOM_connection c) sr->u.request->maximumRecords = odr_intdup (c->odr_out, resultset->count); sr->u.request->recordSchema = resultset->schema; - resultset->setname = xstrdup ("default"); - ZOOM_options_set (resultset->options, "setname", resultset->setname); return send_srw(c, sr); } @@ -1757,15 +1772,15 @@ 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->which = Z_Specification_oid; - compo->u.complex->generic->u.oid = (Odr_oid *) + 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->u.oid) + if (!compo->u.complex->generic->schema.oid) { /* OID wasn't a schema! Try record syntax instead. */ - compo->u.complex->generic->u.oid = (Odr_oid *) + compo->u.complex->generic->schema.oid = (Odr_oid *) yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, resultset->schema); } if (elementSetName && *elementSetName) @@ -2587,7 +2602,7 @@ 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) set_ZOOM_error(c, ZOOM_ERROR_CONNECT, 0); -- 1.7.10.4