X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fhttp_command.c;h=4258b29a2999b3c8a01e370244637cebeefc339d;hb=58aba67e02b51934a2cae721269fb381d8b0b08b;hp=5b84951de532a0f898e8b54850228a38b36bf6b1;hpb=3c83516283deb5286ecaf72411fc150c8e2eee20;p=pazpar2-moved-to-github.git diff --git a/src/http_command.c b/src/http_command.c index 5b84951..4258b29 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -41,9 +41,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "settings.h" #include "client.h" -#ifdef __LINUX__ +#ifdef HAVE_MALLINFO #include -void print_meminfo(WRBUF wrbuf) { + +void print_meminfo(WRBUF wrbuf) +{ struct mallinfo minfo; minfo = mallinfo(); wrbuf_printf(wrbuf, " \n" @@ -100,7 +102,7 @@ int http_session_use(int delta) g_http_sessions += delta; sessions = g_http_sessions; yaz_mutex_leave(g_http_session_mutex); - yaz_log(YLOG_DEBUG, "%s sesions=%d", delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), sessions); + yaz_log(YLOG_DEBUG, "%s sessions=%d", delta == 0 ? "" : (delta > 0 ? "INC" : "DEC"), sessions); return sessions; } @@ -181,7 +183,8 @@ void http_session_destroy(struct http_session *s) yaz_log(http_sessions->log_level, "%p HTTP Session %u destroyed", s, s->session_id); yaz_mutex_enter(http_sessions->mutex); /* only if http_session has no active http sessions on it can be destroyed */ - if (s->destroy_counter == s->activity_counter) { + if (s->destroy_counter == s->activity_counter) + { struct http_session **p = 0; must_destroy = 1; for (p = &http_sessions->session_list; *p; p = &(*p)->next) @@ -323,7 +326,9 @@ static struct http_session *locate_session(struct http_channel *c) } // Call after use of locate_session, in order to increment the destroy_counter -static void release_session(struct http_channel *c, struct http_session *session) { +static void release_session(struct http_channel *c, + struct http_session *session) +{ http_sessions_t http_sessions = c->http_sessions; yaz_mutex_enter(http_sessions->mutex); if (session) @@ -474,13 +479,14 @@ static void cmd_settings(struct http_channel *c) xmlFreeDoc(doc); } - if (process_settings(s->psession, rq, rs) < 0) { - release_session(c,s); + if (process_settings(s->psession, rq, rs) < 0) + { + release_session(c, s); return; } rs->payload = HTTP_COMMAND_RESPONSE_PREFIX "OK"; http_send_response(c); - release_session(c,s); + release_session(c, s); } // Compares two hitsbytarget nodes by hitcount @@ -537,14 +543,11 @@ static void cmd_termlist(struct http_channel *c) struct http_response *rs = c->response; struct http_request *rq = c->request; struct http_session *s = locate_session(c); - struct termlist_score **p; - int len; - int i; const char *name = http_argbyname(rq, "name"); const char *nums = http_argbyname(rq, "num"); int num = 15; int status; - WRBUF debug_log = wrbuf_alloc(); + WRBUF debug_log = 0; if (!s) return; @@ -558,6 +561,8 @@ static void cmd_termlist(struct http_channel *c) if (nums) num = atoi(nums); + debug_log = wrbuf_alloc(); + wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, "\n"); @@ -574,17 +579,23 @@ static void cmd_termlist(struct http_channel *c) wrbuf_puts(c->wrbuf, "wrbuf, tname); wrbuf_puts(c->wrbuf, "\">\n"); - if (!strcmp(tname, "xtargets")) { + if (!strcmp(tname, "xtargets")) + { int targets = targets_termlist(c->wrbuf, s->psession, num, c->nmem); wrbuf_printf(debug_log, " xtargets: %d", targets); } else { - p = termlist(s->psession, tname, &len); + int len; + struct termlist_score **p = + get_termlist_score(s->psession, tname, &len); if (p && len) wrbuf_printf(debug_log, " %s: %d", tname, len); - if (p) { - for (i = 0; i < len && i < num; i++){ + if (p) + { + int i; + for (i = 0; i < len && i < num; i++) + { // prevnt sending empty term elements if (!p[i]->term || !p[i]->term[0]) continue; @@ -593,12 +604,12 @@ static void cmd_termlist(struct http_channel *c) wrbuf_puts(c->wrbuf, ""); wrbuf_xmlputs(c->wrbuf, p[i]->term); wrbuf_puts(c->wrbuf, ""); - + wrbuf_printf(c->wrbuf, "%d", p[i]->frequency); wrbuf_puts(c->wrbuf, "\n"); - } + } } } wrbuf_puts(c->wrbuf, "\n"); @@ -611,7 +622,7 @@ static void cmd_termlist(struct http_channel *c) wrbuf_destroy(debug_log); rs->payload = nmem_strdup(rq->channel->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); - release_session(c,s); + release_session(c, s); } size_t session_get_memory_status(struct session *session); @@ -625,7 +636,8 @@ static void session_status(struct http_channel *c, struct http_session *s) wrbuf_printf(c->wrbuf, "%zu\n", session_nmem); } -static void cmd_session_status(struct http_channel *c) { +static void cmd_session_status(struct http_channel *c) +{ struct http_response *rs = c->response; struct http_session *s = locate_session(c); if (!s) @@ -637,7 +649,7 @@ static void cmd_session_status(struct http_channel *c) { wrbuf_puts(c->wrbuf, "\n"); rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); - release_session(c,s); + release_session(c, s); } @@ -668,7 +680,8 @@ static void cmd_server_status(struct http_channel *c) /* struct http_session *p; */ /* yaz_mutex_enter(http_sessions->mutex); - for (p = http_sessions->session_list; p; p = p->next) { + for (p = http_sessions->session_list; p; p = p->next) + { p->activity_counter++; wrbuf_puts(c->wrbuf, "\n"); wrbuf_printf(c->wrbuf, "%s\n", p->session_id); @@ -736,7 +749,7 @@ static void cmd_bytarget(struct http_channel *c) wrbuf_puts(c->wrbuf, ""); rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); - release_session(c,s); + release_session(c, s); } static void write_metadata(WRBUF w, struct conf_service *service, @@ -1055,7 +1068,8 @@ static void cmd_show(struct http_channel *c) if (block) { - if (!strcmp(block, "preferred") && !session_is_preferred_clients_ready(s->psession) && reclist_get_num_records(s->psession->reclist) == 0) { + if (!strcmp(block, "preferred") && !session_is_preferred_clients_ready(s->psession) && reclist_get_num_records(s->psession->reclist) == 0) + { // if there is already a watch/block. we do not block this one if (session_set_watch(s->psession, SESSION_WATCH_SHOW_PREF, show_records_ready, c, c) != 0) @@ -1063,7 +1077,7 @@ static void cmd_show(struct http_channel *c) yaz_log(c->http_sessions->log_level, "%p Session %u: Blocking on cmd_show. Waiting for preferred targets", s, s->session_id); } - release_session(c,s); + release_session(c, s); return; } @@ -1075,12 +1089,12 @@ static void cmd_show(struct http_channel *c) { yaz_log(c->http_sessions->log_level, "%p Session %u: Blocking on cmd_show", s, s->session_id); } - release_session(c,s); + release_session(c, s); return; } } show_records(c, status); - release_session(c,s); + release_session(c, s); } static void cmd_ping(struct http_channel *c) @@ -1094,31 +1108,6 @@ static void cmd_ping(struct http_channel *c) release_session(c, s); } -static int utf_8_valid(const char *str) -{ - yaz_iconv_t cd = yaz_iconv_open("utf-8", "utf-8"); - if (cd) - { - /* check that query is UTF-8 encoded */ - char *inbuf = (char *) str; /* we know iconv does not alter this */ - size_t inbytesleft = strlen(inbuf); - - size_t outbytesleft = strlen(inbuf) + 10; - char *out = xmalloc(outbytesleft); - char *outbuf = out; - size_t r = yaz_iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); - - /* if OK, try flushing the rest */ - if (r != (size_t) (-1)) - r = yaz_iconv(cd, 0, 0, &outbuf, &outbytesleft); - yaz_iconv_close(cd); - xfree(out); - if (r == (size_t) (-1)) - return 0; - } - return 1; -} - static void cmd_search(struct http_channel *c) { struct http_request *rq = c->request; @@ -1128,6 +1117,7 @@ static void cmd_search(struct http_channel *c) const char *filter = http_argbyname(rq, "filter"); const char *maxrecs = http_argbyname(rq, "maxrecs"); const char *startrecs = http_argbyname(rq, "startrecs"); + const char *limit = http_argbyname(rq, "limit"); enum pazpar2_error_code code; const char *addinfo = 0; @@ -1136,25 +1126,26 @@ static void cmd_search(struct http_channel *c) if (!query) { error(rs, PAZPAR2_MISSING_PARAMETER, "query"); - release_session(c,s); + release_session(c, s); return; } - if (!utf_8_valid(query)) + if (!yaz_utf8_check(query)) { error(rs, PAZPAR2_MALFORMED_PARAMETER_ENCODING, "query"); - release_session(c,s); + release_session(c, s); return; } - code = search(s->psession, query, startrecs, maxrecs, filter, &addinfo); + code = search(s->psession, query, startrecs, maxrecs, filter, limit, + &addinfo); if (code) { error(rs, code, addinfo); - release_session(c,s); + release_session(c, s); return; } rs->payload = HTTP_COMMAND_RESPONSE_PREFIX "OK"; http_send_response(c); - release_session(c,s); + release_session(c, s); } @@ -1173,7 +1164,8 @@ static void cmd_stat(struct http_channel *c) clients = session_active_clients(s->psession); statistics(s->psession, &stat); - if (stat.num_clients > 0) { + if (stat.num_clients > 0) + { progress = (stat.num_clients - clients) / (float)stat.num_clients; } @@ -1193,7 +1185,7 @@ static void cmd_stat(struct http_channel *c) wrbuf_puts(c->wrbuf, ""); rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); - release_session(c,s); + release_session(c, s); } static void cmd_info(struct http_channel *c)