X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-c.c;h=1bbac7e69a9a7939ca27b55c44ca74878ca1a435;hp=b1874eac46ead33cc14090fd2d153cca52463c98;hb=adbe5f4a8c685c31a978fcfc85c9099ebf647927;hpb=c65e569219f8a60e2cba17ddc648a48a7b8b5096 diff --git a/src/zoom-c.c b/src/zoom-c.c index b1874ea..1bbac7e 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -298,9 +298,7 @@ ZOOM_API(ZOOM_connection) c->cookies = 0; c->saveAPDU_wrbuf = 0; -#if HAVE_LIBMEMCACHED_MEMCACHED_H - c->mc_st = 0; -#endif + ZOOM_memcached_init(c); return c; } @@ -363,7 +361,6 @@ ZOOM_API(void) const char *host, int portnum) { const char *val; - const char *http_lead; initlog(); @@ -430,16 +427,18 @@ ZOOM_API(void) else c->lang = 0; - val = ZOOM_options_get(c->options, "sru"); - if (val && *val && !strstr(host, "://")) - http_lead = "http://"; - else - http_lead = ""; - c->sru_mode = get_sru_mode_from_string(val); - if (host) { char hostn[128]; + const char *http_lead; + + val = ZOOM_options_get(c->options, "sru"); + if (val && *val && !strstr(host, "://")) + http_lead = "http://"; + else + http_lead = ""; + c->sru_mode = get_sru_mode_from_string(val); + xfree(c->host_port); if (portnum) { @@ -545,29 +544,11 @@ ZOOM_API(void) yaz_cookies_destroy(c->cookies); c->cookies = yaz_cookies_create(); -#if HAVE_LIBMEMCACHED_MEMCACHED_H - if (c->mc_st) + if (ZOOM_memcached_configure(c)) { - memcached_free(c->mc_st); - c->mc_st = 0; - } -#endif - val = ZOOM_options_get(c->options, "memcached"); - if (val && *val) - { -#if HAVE_LIBMEMCACHED_MEMCACHED_H - c->mc_st = memcached(val, strlen(val)); - if (!c->mc_st) - { - ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, val); - return; - } -#else - ZOOM_set_error(c, ZOOM_ERROR_MEMCACHED, "not enabled"); + ZOOM_connection_remove_tasks(c); return; -#endif } - if (c->sru_mode == zoom_sru_error) { ZOOM_set_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, val); @@ -613,10 +594,7 @@ ZOOM_API(void) return; yaz_log(c->log_api, "%p ZOOM_connection_destroy", c); -#if HAVE_LIBMEMCACHED_MEMCACHED_H - if (c->mc_st) - memcached_free(c->mc_st); -#endif + ZOOM_memcached_destroy(c); if (c->cs) cs_close(c->cs); @@ -709,8 +687,9 @@ ZOOM_resultset ZOOM_resultset_create(void) r->connection = 0; r->databaseNames = 0; r->num_databaseNames = 0; - r->facets = 0; - r->num_facets = 0; + r->req_facets = 0; + r->res_facets = 0; + r->num_res_facets = 0; r->facets_names = 0; r->mutex = 0; yaz_mutex_create(&r->mutex); @@ -743,7 +722,6 @@ ZOOM_API(ZOOM_resultset) ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) { ZOOM_resultset r = ZOOM_resultset_create(); - const char *cp; ZOOM_task task; int start, count; const char *syntax, *elementSetName, *schema; @@ -754,6 +732,8 @@ ZOOM_API(ZOOM_resultset) r->options = ZOOM_options_create_with_parent(c->options); + r->req_facets = odr_strdup_null(r->odr, + ZOOM_options_get(r->options, "facets")); start = ZOOM_options_get_int(r->options, "start", 0); count = ZOOM_options_get_int(r->options, "count", 0); { @@ -763,34 +743,16 @@ ZOOM_API(ZOOM_resultset) (cp != 0 ? "presentChunk": "step"), 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->databaseNames = ZOOM_connection_get_databases(c, c->options, &r->num_databaseNames, - r->odr); - + r->setname = odr_strdup_null(r->odr, + ZOOM_options_get(r->options, "setname")); + r->databaseNames = ZOOM_connection_get_databases(c, c->options, + &r->num_databaseNames, + r->odr); r->connection = c; r->next = c->resultsets; c->resultsets = r; -#if HAVE_LIBMEMCACHED_MEMCACHED_H - r->mc_key = wrbuf_alloc(); - wrbuf_puts(r->mc_key, "0;"); - wrbuf_puts(r->mc_key, c->host_port); - wrbuf_puts(r->mc_key, ";"); - if (c->user) - wrbuf_puts(r->mc_key, c->user); - wrbuf_puts(r->mc_key, ";"); - if (c->group) - wrbuf_puts(r->mc_key, c->group); - wrbuf_puts(r->mc_key, ";"); - if (c->password) - wrbuf_sha1_puts(r->mc_key, c->password, 1); - wrbuf_puts(r->mc_key, ";"); - wrbuf_sha1_puts(r->mc_key, ZOOM_query_get_query_string(q), 1); - wrbuf_puts(r->mc_key, ";"); -#endif + ZOOM_memcached_resultset(r, q); if (c->host_port && c->proto == PROTO_HTTP) { @@ -908,7 +870,6 @@ static void resultset_destroy(ZOOM_resultset r) ZOOM_query_destroy(r->query); ZOOM_options_destroy(r->options); odr_destroy(r->odr); - xfree(r->setname); yaz_mutex_destroy(&r->mutex); #if SHPTR YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy); @@ -1019,14 +980,14 @@ ZOOM_API(void) ZOOM_API(size_t) ZOOM_resultset_facets_size(ZOOM_resultset r) { - return r->num_facets; + return r->num_res_facets; } ZOOM_API(ZOOM_facet_field) ZOOM_resultset_get_facet_field(ZOOM_resultset r, const char *name) { - int num = r->num_facets; - ZOOM_facet_field *facets = r->facets; + int num = r->num_res_facets; + ZOOM_facet_field *facets = r->res_facets; int i; for (i = 0; i < num; i++) if (!strcmp(facets[i]->facet_name, name)) @@ -1037,8 +998,8 @@ ZOOM_API(ZOOM_facet_field) ZOOM_API(ZOOM_facet_field) ZOOM_resultset_get_facet_field_by_index(ZOOM_resultset r, int idx) { - int num = r->num_facets; - ZOOM_facet_field *facets = r->facets; + int num = r->num_res_facets; + ZOOM_facet_field *facets = r->res_facets; if (idx >= 0 && idx < num) return facets[idx]; return 0; @@ -1047,7 +1008,7 @@ ZOOM_API(ZOOM_facet_field) ZOOM_API(ZOOM_facet_field *) ZOOM_resultset_facets(ZOOM_resultset r) { - return r->facets; + return r->res_facets; } ZOOM_API(const char**) @@ -1168,7 +1129,7 @@ ZOOM_API(ZOOM_record) const char *schema = ZOOM_options_get(s->options, "schema"); - return ZOOM_record_cache_lookup(s, pos, syntax, elementSetName, schema); + return ZOOM_record_cache_lookup_i(s, pos, syntax, elementSetName, schema); } ZOOM_API(ZOOM_record)