X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fzoom-c.c;h=6e0a88363dd7439846c15112ada66be73afdada6;hp=331f54453118d1d1a7a037cef69757b82b30fff6;hb=22c19c698f72ce5328ea6d5d685c019be92d24d3;hpb=3bfb3813869cfa6d6e199bf7a24ebd8e300054be diff --git a/src/zoom-c.c b/src/zoom-c.c index 331f544..6e0a883 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -136,9 +136,6 @@ void ZOOM_connection_show_task(ZOOM_task task) case ZOOM_TASK_SEARCH: yaz_log(YLOG_LOG, "search p=%p", task); break; - case ZOOM_TASK_RETRIEVE: - yaz_log(YLOG_LOG, "retrieve p=%p", task); - break; case ZOOM_TASK_CONNECT: yaz_log(YLOG_LOG, "connect p=%p", task); break; @@ -201,12 +198,6 @@ void ZOOM_connection_remove_task(ZOOM_connection c) xfree(task->u.search.elementSetName); xfree(task->u.search.schema); break; - case ZOOM_TASK_RETRIEVE: - resultset_destroy(task->u.retrieve.resultset); - xfree(task->u.retrieve.syntax); - xfree(task->u.retrieve.elementSetName); - xfree(task->u.retrieve.schema); - break; case ZOOM_TASK_CONNECT: break; case ZOOM_TASK_SCAN: @@ -308,6 +299,10 @@ ZOOM_API(ZOOM_connection) c->no_redirects = 0; c->cookies = 0; c->saveAPDU_wrbuf = 0; + +#if HAVE_LIBMEMCACHED_MEMCACHED_H + c->mc_st = 0; +#endif return c; } @@ -370,6 +365,7 @@ ZOOM_API(void) const char *host, int portnum) { const char *val; + const char *http_lead; initlog(); @@ -436,17 +432,25 @@ 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]; xfree(c->host_port); if (portnum) { - char hostn[128]; sprintf(hostn, "%.80s:%d", host, portnum); - c->host_port = xstrdup(hostn); + host = hostn; } - else - c->host_port = xstrdup(host); + c->host_port = xmalloc(strlen(host) + strlen(http_lead) + 1); + strcpy(c->host_port, http_lead); + strcat(c->host_port, host); } { @@ -482,9 +486,6 @@ ZOOM_API(void) } } - val = ZOOM_options_get(c->options, "sru"); - c->sru_mode = get_sru_mode_from_string(val); - xfree(c->sru_version); val = ZOOM_options_get(c->options, "sru_version"); c->sru_version = xstrdup(val ? val : "1.2"); @@ -546,6 +547,29 @@ ZOOM_API(void) yaz_cookies_destroy(c->cookies); c->cookies = yaz_cookies_create(); +#if HAVE_LIBMEMCACHED_MEMCACHED_H + if (c->mc_st) + { + 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"); + return; +#endif + } + if (c->sru_mode == zoom_sru_error) { ZOOM_set_error(c, ZOOM_ERROR_UNSUPPORTED_PROTOCOL, val); @@ -590,6 +614,11 @@ ZOOM_API(void) if (!c) 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 if (c->cs) cs_close(c->cs); @@ -694,6 +723,8 @@ ZOOM_resultset ZOOM_resultset_create(void) } #endif resultset_use(1); + r->mc_key = 0; + r->live_set = 0; return r; } @@ -714,14 +745,14 @@ ZOOM_API(ZOOM_resultset) ZOOM_connection_search(ZOOM_connection c, ZOOM_query q) { ZOOM_resultset r = ZOOM_resultset_create(); - ZOOM_task task; const char *cp; + ZOOM_task task; int start, count; const char *syntax, *elementSetName, *schema; - yaz_log(c->log_api, "%p ZOOM_connection_search set %p query %p", c, r, q); r->r_sort_spec = ZOOM_query_get_sortspec(q); r->query = q; + ZOOM_query_addref(q); r->options = ZOOM_options_create_with_parent(c->options); @@ -744,6 +775,43 @@ ZOOM_API(ZOOM_resultset) 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, c->host_port); + wrbuf_puts(r->mc_key, ";"); + wrbuf_puts(r->mc_key, ZOOM_query_get_query_string(q)); + if (c->mc_st) + { + size_t v_len; + uint32_t flags; + memcached_return_t rc; + char *v = memcached_get(c->mc_st, wrbuf_buf(r->mc_key), + wrbuf_len(r->mc_key), &v_len, &flags, &rc); + if (v) + { + ZOOM_Event event; + WRBUF w = wrbuf_alloc(); + + wrbuf_write(w, v, v_len); + free(v); + r->size = odr_atoi(wrbuf_cstr(w)); + + yaz_log(YLOG_LOG, "For key %s got value %s", + wrbuf_cstr(r->mc_key), wrbuf_cstr(w)); + + wrbuf_destroy(w); + event = ZOOM_Event_create(ZOOM_EVENT_RECV_SEARCH); + ZOOM_connection_put_event(c, event); + return r; + } + else + { + yaz_log(YLOG_LOG, "For key %s got NO value", wrbuf_cstr(r->mc_key)); + } + } +#endif + if (c->host_port && c->proto == PROTO_HTTP) { if (!c->cs) @@ -774,8 +842,6 @@ ZOOM_API(ZOOM_resultset) ZOOM_resultset_addref(r); - ZOOM_query_addref(q); - if (!c->async) { while (ZOOM_event(1, &c)) @@ -868,6 +934,7 @@ static void resultset_destroy(ZOOM_resultset r) #if SHPTR YAZ_SHPTR_DEC(r->record_wrbuf, wrbuf_destroy); #endif + wrbuf_destroy(r->mc_key); resultset_use(-1); xfree(r); } @@ -928,19 +995,19 @@ static void ZOOM_resultset_retrieve(ZOOM_resultset r, c->reconnect_ok = 1; } } - task = ZOOM_connection_add_task(c, ZOOM_TASK_RETRIEVE); - task->u.retrieve.resultset = r; - task->u.retrieve.start = start; - task->u.retrieve.count = count; + task = ZOOM_connection_add_task(c, ZOOM_TASK_SEARCH); + task->u.search.resultset = r; + task->u.search.start = start; + task->u.search.count = count; syntax = ZOOM_options_get(r->options, "preferredRecordSyntax"); - task->u.retrieve.syntax = syntax ? xstrdup(syntax) : 0; + task->u.search.syntax = syntax ? xstrdup(syntax) : 0; elementSetName = ZOOM_options_get(r->options, "elementSetName"); - task->u.retrieve.elementSetName = elementSetName + task->u.search.elementSetName = elementSetName ? xstrdup(elementSetName) : 0; cp = ZOOM_options_get(r->options, "schema"); - task->u.retrieve.schema = cp ? xstrdup(cp) : 0; + task->u.search.schema = cp ? xstrdup(cp) : 0; ZOOM_resultset_addref(r); @@ -1438,12 +1505,6 @@ ZOOM_API(int) else ret = ZOOM_connection_Z3950_send_search(c); break; - case ZOOM_TASK_RETRIEVE: - if (c->proto == PROTO_HTTP) - ret = ZOOM_connection_srw_send_search(c); - else - ret = send_Z3950_present(c); - break; case ZOOM_TASK_CONNECT: ret = do_connect(c); break; @@ -1559,11 +1620,8 @@ static void handle_http(ZOOM_connection c, Z_HTTP_Response *hres) int host_change = 0; location = yaz_check_location(c->odr_in, c->host_port, location, &host_change); - if (host_change) - { - if (do_connect_host(c, location) == zoom_complete) - return; /* connect failed.. */ - } + if (do_connect_host(c, location) == zoom_complete) + return; /* connect failed.. */ send_HTTP_redirect(c, location); return; } @@ -1895,6 +1953,8 @@ ZOOM_API(const char *) return "Extended Service. invalid version"; case ZOOM_ERROR_ES_INVALID_SYNTAX: return "Extended Service. invalid syntax"; + case ZOOM_ERROR_MEMCACHED: + return "Memcached"; default: return diagbib1_str(error); }