From c5634aa19153b7b36e6de5a8e5b4536d69b2b7a1 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 22 Nov 2001 09:45:31 +0000 Subject: [PATCH] Implemented named result sets handling for ZOOM. --- CHANGELOG | 2 ++ doc/zoom.xml | 7 ++++++- zoom/zoom-c.c | 48 ++++++++++++++++++++++++++++++++++++++++++------ zoom/zoom-p.h | 4 +++- zoom/zoomtst4.c | 5 ++++- 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 15dd319..0345c56 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ Possible compatibility problems with earlier versions marked with '*'. --- 1.8.4 2001/XX/XX +ZOOM allocates result set name if target supports it. + Two new YAZ client commands: . (dot, which sources a script of YAZ client commands), and ! (to execute shell command.). Implemented by Jacob Poulsen. diff --git a/doc/zoom.xml b/doc/zoom.xml index 6d2ced2..d2c561c 100644 --- a/doc/zoom.xml +++ b/doc/zoom.xml @@ -1,4 +1,4 @@ - + Building clients with ZOOM @@ -329,6 +329,11 @@ databaseNameOne or more database names separated by character plus (+). Default + + setnameName of Result Set (Result Set ID). + If this option isn't set, the ZOOM module will automatically + allocate a result set name. + default diff --git a/zoom/zoom-c.c b/zoom/zoom-c.c index b5a26df..1f093a6 100644 --- a/zoom/zoom-c.c +++ b/zoom/zoom-c.c @@ -1,5 +1,5 @@ /* - * $Id: zoom-c.c,v 1.11 2001-11-18 21:14:23 adam Exp $ + * $Id: zoom-c.c,v 1.12 2001-11-22 09:45:31 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -149,6 +149,7 @@ ZOOM_connection ZOOM_connection_create (ZOOM_options options) c->odr_out = odr_createmem (ODR_ENCODE); c->async = 0; + c->support_named_resultsets = 0; c->m_queue_front = 0; c->m_queue_back = 0; @@ -329,6 +330,7 @@ ZOOM_resultset ZOOM_resultset_create () r->odr = odr_createmem (ODR_ENCODE); r->start = 0; r->piggyback = 1; + r->setname = 0; r->count = 0; r->record_cache = 0; r->r_sort_spec = 0; @@ -355,6 +357,7 @@ ZOOM_resultset ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) { ZOOM_resultset r = ZOOM_resultset_create (); ZOOM_task task; + const char *cp; r->r_sort_spec = q->sort_spec; r->r_query = q->query; @@ -365,6 +368,10 @@ ZOOM_resultset ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) r->start = ZOOM_options_get_int(r->options, "start", 0); r->count = ZOOM_options_get_int(r->options, "count", 0); r->piggyback = ZOOM_options_get_bool (r->options, "piggyback", 1); + cp = ZOOM_options_get (r->options, "setname"); + if (cp) + r->setname = xstrdup (cp); + r->connection = c; r->next = c->resultsets; @@ -410,6 +417,7 @@ void ZOOM_resultset_destroy(ZOOM_resultset r) ZOOM_query_destroy (r->search); ZOOM_options_destroy (r->options); odr_destroy (r->odr); + xfree (r->setname); xfree (r); } } @@ -577,10 +585,8 @@ static int ZOOM_connection_send_init (ZOOM_connection c) ODR_MASK_SET(ireq->options, Z_Options_present); ODR_MASK_SET(ireq->options, Z_Options_scan); ODR_MASK_SET(ireq->options, Z_Options_sort); -#if 0 ODR_MASK_SET(ireq->options, Z_Options_extendedServices); ODR_MASK_SET(ireq->options, Z_Options_namedResultSets); -#endif ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_1); ODR_MASK_SET(ireq->protocolVersion, Z_ProtocolVersion_2); @@ -736,7 +742,33 @@ static int ZOOM_connection_send_search (ZOOM_connection c) if (syntax) search_req->preferredRecordSyntax = yaz_str_to_z3950oid (c->odr_out, CLASS_RECSYN, syntax); - + + if (!r->setname) + { + if (c->support_named_resultsets) + { + char setname[14]; + int ord; + /* find the lowest unused ordinal so that we re-use + result sets on the server. */ + for (ord = 1; ; ord++) + { + ZOOM_resultset rp; + sprintf (setname, "%d", ord); + for (rp = c->resultsets; rp; rp = rp->next) + if (rp->setname && !strcmp (rp->setname, setname)) + break; + if (!rp) + break; + } + r->setname = xstrdup (setname); + yaz_log (LOG_DEBUG, "allocating %s", r->setname); + } + else + r->setname = xstrdup ("default"); + ZOOM_options_set (r->options, "setname", r->setname); + } + search_req->resultSetName = odr_strdup(c->odr_out, r->setname); /* send search request */ send_APDU (c, apdu); r->r_query = 0; @@ -1058,8 +1090,9 @@ static int send_sort (ZOOM_connection c) req->num_inputResultSetNames = 1; req->inputResultSetNames = (Z_InternationalString **) odr_malloc (c->odr_out, sizeof(*req->inputResultSetNames)); - req->inputResultSetNames[0] = odr_strdup (c->odr_out, "default"); - req->sortedResultSetName = odr_strdup (c->odr_out, "default"); + req->inputResultSetNames[0] = + odr_strdup (c->odr_out, resultset->setname); + req->sortedResultSetName = odr_strdup (c->odr_out, resultset->setname); req->sortSequence = resultset->r_sort_spec; resultset->r_sort_spec = 0; send_APDU (c, apdu); @@ -1122,6 +1155,7 @@ static int send_present (ZOOM_connection c) compo->u.simple = esn; req->recordComposition = compo; } + req->resultSetId = odr_strdup(c->odr_out, resultset->setname); send_APDU (c, apdu); return 1; } @@ -1193,6 +1227,8 @@ static void handle_apdu (ZOOM_connection c, Z_APDU *apdu) c->cookie_in = 0; if (cookie) c->cookie_in = xstrdup(cookie); + if (ODR_MASK_GET(initrs->options, Z_Options_namedResultSets)) + c->support_named_resultsets = 1; if (c->tasks) { assert (c->tasks->which == ZOOM_TASK_CONNECT); diff --git a/zoom/zoom-p.h b/zoom/zoom-p.h index 85a80db..28446c8 100644 --- a/zoom/zoom-p.h +++ b/zoom/zoom-p.h @@ -1,6 +1,6 @@ /* * Private C header for ZOOM C. - * $Id: zoom-p.h,v 1.5 2001-11-18 21:14:23 adam Exp $ + * $Id: zoom-p.h,v 1.6 2001-11-22 09:45:31 adam Exp $ */ #include #include @@ -41,6 +41,7 @@ struct ZOOM_connection_p { char *cookie_out; char *cookie_in; int async; + int support_named_resultsets; ZOOM_task tasks; ZOOM_options options; ZOOM_resultset resultsets; @@ -74,6 +75,7 @@ struct ZOOM_resultset_p { int start; int count; int piggyback; + char *setname; ODR odr; ZOOM_record_cache record_cache; ZOOM_options options; diff --git a/zoom/zoomtst4.c b/zoom/zoomtst4.c index 7ed678f..a2eb137 100644 --- a/zoom/zoomtst4.c +++ b/zoom/zoomtst4.c @@ -1,5 +1,5 @@ /* - * $Id: zoomtst4.c,v 1.5 2001-11-18 21:14:23 adam Exp $ + * $Id: zoomtst4.c,v 1.6 2001-11-22 09:45:31 adam Exp $ * * Asynchronous multi-target going through proxy doing search and retrieve * using present. @@ -74,6 +74,9 @@ int main(int argc, char **argv) fprintf (stderr, "%s error: %s (%d) %s\n", ZOOM_connection_option_get(z[i], "host"), errmsg, error, addinfo); + else + printf ("%s: %d hits\n", ZOOM_connection_option_get(z[i], "host"), + ZOOM_resultset_size(r[i])); } /* destroy stuff and exit */ -- 1.7.10.4