From 1c793310ab772f41040bdf954d8a2b5e5da8b8ad Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 23 Feb 2004 09:26:11 +0000 Subject: [PATCH] Implement ZOOM_resultset_{sort,cache_reset} which sorts and resets cache for result set respectively. --- CHANGELOG | 4 +++ include/yaz/zoom.h | 12 ++++++- src/zoom-c.c | 99 +++++++++++++++++++++++++++++++++++++++------------- src/zoom-p.h | 7 +++- zoom/zoomsh.c | 23 +++++++++++- 5 files changed, 118 insertions(+), 27 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6673be3..f9966a2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ Possible compatibility problems with earlier versions marked with '*'. +Implement ZOOM_resultset_cache_reset which resets record cache. + +Implement ZOOM_resultset_sort which sorts a result set. + Implement chunked HTTP transfer. For SSL, use -lssl -lcrypto on systems that don't have pkg-config. diff --git a/include/yaz/zoom.h b/include/yaz/zoom.h index 71cea77..7b09867 100644 --- a/include/yaz/zoom.h +++ b/include/yaz/zoom.h @@ -1,6 +1,6 @@ /* * Public header for ZOOM C. - * $Id: zoom.h,v 1.21 2004-02-16 11:22:34 adam Exp $ + * $Id: zoom.h,v 1.22 2004-02-23 09:26:11 adam Exp $ */ #include @@ -148,6 +148,10 @@ ZOOM_resultset_record (ZOOM_resultset s, size_t pos); ZOOM_API(ZOOM_record) ZOOM_resultset_record_immediate (ZOOM_resultset s, size_t pos); +/* reset record cache for result set */ +ZOOM_API(void) +ZOOM_resultset_cache_reset(ZOOM_resultset r); + /* ----------------------------------------------------------- */ /* records */ @@ -227,6 +231,12 @@ ZOOM_API(void) const char *val); /* ----------------------------------------------------------- */ +/* Sort */ +ZOOM_API(void) + ZOOM_resultset_sort(ZOOM_resultset r, + const char *sort_type, const char *sort_spec); + +/* ----------------------------------------------------------- */ /* options */ ZOOM_API(ZOOM_options_callback) diff --git a/src/zoom-c.c b/src/zoom-c.c index 6078c93..0c6f48e 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (c) 2000-2004, Index Data * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.24 2004-02-14 15:58:42 adam Exp $ + * $Id: zoom-c.c,v 1.25 2004-02-23 09:26:11 adam Exp $ * * ZOOM layer for C, connections, result sets, queries. */ @@ -199,6 +199,10 @@ void ZOOM_connection_remove_task (ZOOM_connection c) case ZOOM_TASK_PACKAGE: ZOOM_package_destroy (task->u.package); break; + case ZOOM_TASK_SORT: + ZOOM_resultset_destroy (task->u.sort.resultset); + ZOOM_query_destroy(task->u.sort.q); + break; default: assert (0); } @@ -508,6 +512,7 @@ void ZOOM_resultset_addref (ZOOM_resultset r) r, r->refcount); } } + ZOOM_resultset ZOOM_resultset_create () { ZOOM_resultset r = (ZOOM_resultset) xmalloc (sizeof(*r)); @@ -605,6 +610,62 @@ ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) } ZOOM_API(void) + ZOOM_resultset_sort(ZOOM_resultset r, + const char *sort_type, const char *sort_spec) +{ + ZOOM_connection c = r->connection; + ZOOM_task task; + + 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; + } + } + + ZOOM_resultset_cache_reset(r); + task = ZOOM_connection_add_task (c, ZOOM_TASK_SORT); + task->u.sort.resultset = r; + task->u.sort.q = ZOOM_query_create(); + ZOOM_query_sortby(task->u.sort.q, sort_spec); + + ZOOM_resultset_addref (r); + + if (!c->async) + { + while (ZOOM_event (1, &c)) + ; + } +} + +ZOOM_API(void) + ZOOM_resultset_cache_reset(ZOOM_resultset r) +{ + ZOOM_record_cache rc; + + for (rc = r->record_cache; rc; rc = rc->next) + { + if (rc->rec.wrbuf_marc) + wrbuf_free (rc->rec.wrbuf_marc, 1); + if (rc->rec.wrbuf_iconv) + wrbuf_free (rc->rec.wrbuf_iconv, 1); + if (rc->rec.wrbuf_opac) + wrbuf_free (rc->rec.wrbuf_opac, 1); + } + r->record_cache = 0; +} + +ZOOM_API(void) ZOOM_resultset_destroy(ZOOM_resultset r) { if (!r) @@ -614,17 +675,8 @@ ZOOM_resultset_destroy(ZOOM_resultset r) r, r->refcount); if (r->refcount == 0) { - ZOOM_record_cache rc; + ZOOM_resultset_cache_reset(r); - for (rc = r->record_cache; rc; rc = rc->next) - { - if (rc->rec.wrbuf_marc) - wrbuf_free (rc->rec.wrbuf_marc, 1); - if (rc->rec.wrbuf_iconv) - wrbuf_free (rc->rec.wrbuf_iconv, 1); - if (rc->rec.wrbuf_opac) - wrbuf_free (rc->rec.wrbuf_opac, 1); - } if (r->connection) { /* remove ourselves from the resultsets in connection */ @@ -935,7 +987,7 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) ZOOM_options_get(c->options, "implementationName"), odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.24 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.25 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = odr_prepend(c->odr_out, @@ -1949,20 +2001,11 @@ static int scan_response (ZOOM_connection c, Z_ScanResponse *res) return 1; } -static zoom_ret send_sort (ZOOM_connection c) +static zoom_ret send_sort (ZOOM_connection c, + ZOOM_resultset resultset) { - ZOOM_resultset resultset; - - if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH) - return zoom_complete; - - resultset = c->tasks->u.search.resultset; - if (c->error) - { resultset->r_sort_spec = 0; - return zoom_complete; - } if (resultset->r_sort_spec) { Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_sortRequest); @@ -2740,6 +2783,11 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) break; case ZOOM_TASK_PACKAGE: ret = send_package(c); + break; + case ZOOM_TASK_SORT: + c->tasks->u.sort.resultset->r_sort_spec = + c->tasks->u.sort.q->sort_spec; + ret = send_sort(c, c->tasks->u.sort.resultset); break; } } @@ -2760,7 +2808,10 @@ static int ZOOM_connection_exec_task (ZOOM_connection c) static zoom_ret send_sort_present (ZOOM_connection c) { - zoom_ret r = send_sort (c); + zoom_ret r = zoom_complete; + + if (c->tasks && c->tasks->which == ZOOM_TASK_SEARCH) + r = send_sort (c, c->tasks->u.search.resultset); if (r == zoom_complete) r = send_present (c); return r; diff --git a/src/zoom-p.h b/src/zoom-p.h index a991aaf..221a21e 100644 --- a/src/zoom-p.h +++ b/src/zoom-p.h @@ -1,6 +1,6 @@ /* * Private C header for ZOOM C. - * $Id: zoom-p.h,v 1.3 2004-01-27 21:22:44 adam Exp $ + * $Id: zoom-p.h,v 1.4 2004-02-23 09:26:11 adam Exp $ */ #include @@ -151,6 +151,11 @@ struct ZOOM_task_p { } scan; #define ZOOM_TASK_PACKAGE 5 ZOOM_package package; +#define ZOOM_TASK_SORT 6 + struct { + ZOOM_resultset resultset; + ZOOM_query q; + } sort; } u; ZOOM_task next; }; diff --git a/zoom/zoomsh.c b/zoom/zoomsh.c index 0196c81..af47ecd 100644 --- a/zoom/zoomsh.c +++ b/zoom/zoomsh.c @@ -2,7 +2,7 @@ * Copyright (c) 2002-2004, Index Data. * See the file LICENSE for details. * - * $Id: zoomsh.c,v 1.26 2004-01-16 10:04:55 adam Exp $ + * $Id: zoomsh.c,v 1.27 2004-02-23 09:26:11 adam Exp $ */ /* ZOOM-C Shell */ @@ -368,6 +368,25 @@ static void cmd_scan (ZOOM_connection *c, ZOOM_resultset *r, } } +static void cmd_sort (ZOOM_connection *c, ZOOM_resultset *r, + ZOOM_options options, + const char **args) +{ + const char *sort_spec = *args; + int i; + + while (*sort_spec == ' ') + sort_spec++; + + for (i = 0; i