X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=src%2Fhttp_command.c;h=c4837a66bf49d6a5cf03f80088908ddb6148b50b;hb=fa5ad51f6951bdda9c84f8c2252e457d61edec61;hp=e453a9da2327c65f1a91e3ce63ff1c2d55ab9ced;hpb=b9a83dec2858e9aa4247b29b3f8f8cf42a1a786d;p=pazpar2-moved-to-github.git diff --git a/src/http_command.c b/src/http_command.c index e453a9d..c4837a6 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.2 2006-12-20 22:19:35 adam Exp $ + * $Id: http_command.c,v 1.5 2007-01-04 02:53:37 quinn Exp $ */ #include @@ -152,21 +152,46 @@ static void cmd_termlist(struct http_channel *c) struct termlist_score **p; int len; int i; + char *name = http_argbyname(rq, "name"); + int status = session_active_clients(s->psession); if (!s) return; + + if (!name) + name = "subject"; + if (strlen(name) > 255) + return; + wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, ""); - p = termlist(s->psession, &len); - if (p) - for (i = 0; i < len; i++) - { - wrbuf_puts(c->wrbuf, "\n"); - wrbuf_printf(c->wrbuf, "%s", p[i]->term); - wrbuf_printf(c->wrbuf, "%d", p[i]->frequency); - wrbuf_puts(c->wrbuf, ""); - } + wrbuf_printf(c->wrbuf, "\n%d", status); + while (*name) + { + char tname[256]; + char *tp; + + if (!(tp = strchr(name, ','))) + tp = name + strlen(name); + strncpy(tname, name, tp - name); + tname[tp - name] = '\0'; + + p = termlist(s->psession, tname, &len); + wrbuf_printf(c->wrbuf, "\n\n", tname); + if (p) + for (i = 0; i < len; i++) + { + wrbuf_puts(c->wrbuf, "\n"); + wrbuf_printf(c->wrbuf, "%s", p[i]->term); + wrbuf_printf(c->wrbuf, "%d", p[i]->frequency); + wrbuf_puts(c->wrbuf, ""); + } + wrbuf_puts(c->wrbuf, "\n"); + name = tp; + if (*name == ',') + name++; + } wrbuf_puts(c->wrbuf, ""); rs->payload = nmem_strdup(rq->channel->nmem, wrbuf_buf(c->wrbuf)); http_send_response(c); @@ -207,7 +232,7 @@ static void cmd_bytarget(struct http_channel *c) http_send_response(c); } -static void show_records(struct http_channel *c) +static void show_records(struct http_channel *c, int active) { struct http_request *rq = c->request; struct http_response *rs = c->response; @@ -225,6 +250,10 @@ static void show_records(struct http_channel *c) if (!s) return; + // We haven't counted clients yet if we're called on a block release + if (active < 0) + active = session_active_clients(s->psession); + if (start) startn = atoi(start); if (num) @@ -235,6 +264,7 @@ static void show_records(struct http_channel *c) wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, "\nOK\n"); + wrbuf_printf(c->wrbuf, "%d\n", active); wrbuf_printf(c->wrbuf, "%d\n", total); wrbuf_printf(c->wrbuf, "%d\n", total_hits); wrbuf_printf(c->wrbuf, "%d\n", startn); @@ -264,7 +294,7 @@ static void show_records_ready(void *data) { struct http_channel *c = (struct http_channel *) data; - show_records(c); + show_records(c, -1); } static void cmd_show(struct http_channel *c) @@ -273,13 +303,14 @@ static void cmd_show(struct http_channel *c) struct http_response *rs = c->response; struct http_session *s = locate_session(rq, rs); char *block = http_argbyname(rq, "block"); + int status = session_active_clients(s->psession); if (!s) return; if (block) { - if (!s->psession->reclist || !s->psession->reclist->num_records) + if (status && (!s->psession->reclist || !s->psession->reclist->num_records)) { session_set_watch(s->psession, SESSION_WATCH_RECORDS, show_records_ready, c); yaz_log(YLOG_DEBUG, "Blocking on cmd_show"); @@ -287,7 +318,7 @@ static void cmd_show(struct http_channel *c) } } - show_records(c); + show_records(c, status); } static void cmd_ping(struct http_channel *c) @@ -333,6 +364,7 @@ static void cmd_stat(struct http_channel *c) struct http_response *rs = c->response; struct http_session *s = locate_session(rq, rs); struct statistics stat; + int clients = session_active_clients(s->psession); if (!s) return; @@ -341,6 +373,7 @@ static void cmd_stat(struct http_channel *c) wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, ""); + wrbuf_printf(c->wrbuf, "%d\n", clients); wrbuf_printf(c->wrbuf, "%d\n", stat.num_hits); wrbuf_printf(c->wrbuf, "%d\n", stat.num_records); wrbuf_printf(c->wrbuf, "%d\n", stat.num_clients);