From: Dennis Schafroth Date: Thu, 3 Nov 2011 10:10:46 +0000 (+0100) Subject: Refactor for and implement bytarget block X-Git-Tag: mobile-beta-1~31 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=86ecde222a33815232f51f75112b93d6aa1de1a0;hp=ea8c8b095246567e2b94f819868c1bf23ebb9767;p=pazpar2-moved-to-github.git Refactor for and implement bytarget block --- diff --git a/src/http_command.c b/src/http_command.c index a86aabb..1d47702 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -600,17 +600,13 @@ static void cmd_server_status(struct http_channel *c) xmalloc_trav(0); } - -static void cmd_bytarget(struct http_channel *c) -{ - struct http_request *rq = c->request; - struct http_session *s = locate_session(c); +static void bytarget_response(struct http_channel *c) { + int count, i; struct hitsbytarget *ht; + struct http_request *rq = c->request; const char *settings = http_argbyname(rq, "settings"); - int count, i; + struct http_session *s = locate_session(c); - if (!s) - return; ht = get_hitsbytarget(s->psession, &count, c->nmem); response_open(c, "bytarget"); @@ -653,6 +649,39 @@ static void cmd_bytarget(struct http_channel *c) release_session(c, s); } +static void bytarget_result_ready(void *data) +{ + struct http_channel *c = (struct http_channel *) data; + + bytarget_response(c); +} + + +static void cmd_bytarget(struct http_channel *c) +{ + struct http_request *rq = c->request; + struct http_session *s = locate_session(c); + const char *block = http_argbyname(rq, "block"); + struct hitsbytarget *ht; + + if (!s) + return; + + if (block && strcmp("1",*block) == 0) + { + // if there is already a watch/block. we do not block this one + if (session_set_watch(s->psession, SESSION_WATCH_BYTARGET, + bytarget_result_ready, c, c) != 0) + { + yaz_log(c->http_sessions->log_level, "%p Session %u: Blocking on cmd_bytarget", s, s->session_id); + } + release_session(c, s); + return; + } + bytarget_response(c); + release_session(c, s); +} + static void write_metadata(WRBUF w, struct conf_service *service, struct record_metadata **ml, int full) {