From: Sebastian Hammer Date: Thu, 4 Jan 2007 02:35:42 +0000 (+0000) Subject: Added 'activeclients' element to response from show and termlist command X-Git-Tag: before.append.child~52 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=402b4b9a58369a72a46f8c71e708c0a6331560b0;p=pazpar2-moved-to-github.git Added 'activeclients' element to response from show and termlist command so browsers can stop repeating requests when all activity has ended. --- diff --git a/PROTOCOL b/PROTOCOL index 8ae4a9d..272d9c6 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -102,6 +102,7 @@ Output: OK + 3 6 7 0 @@ -134,6 +135,7 @@ search.pz2?session=2044502273&command=termlist&name=author,subject Output: + 3 Donald Knuth diff --git a/src/Makefile b/src/Makefile index f385dbe..69c3c02 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,12 +1,12 @@ # ParaZ. Copyright (C) 2000-2004, Index Data ApS # All rights reserved. -# $Id: Makefile,v 1.5 2007-01-03 14:31:55 quinn Exp $ +# $Id: Makefile,v 1.6 2007-01-04 02:35:42 quinn Exp $ SHELL=/bin/sh CC=gcc -YAZCONF=yaz-config +YAZCONF=yaz/yaz-config YAZLIBS=`$(YAZCONF) --libs` YAZCFLAGS=`$(YAZCONF) --cflags` diff --git a/src/http_command.c b/src/http_command.c index 54a1654..c5dcf0f 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.3 2007-01-03 06:23:44 quinn Exp $ + * $Id: http_command.c,v 1.4 2007-01-04 02:35:42 quinn Exp $ */ #include @@ -153,6 +153,7 @@ static void cmd_termlist(struct http_channel *c) int len; int i; char *name = http_argbyname(rq, "name"); + int status = session_active_clients(s->psession); if (!s) return; @@ -165,6 +166,7 @@ static void cmd_termlist(struct http_channel *c) wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, ""); + wrbuf_printf(c->wrbuf, "\n%d", status); while (*name) { char tname[256]; @@ -230,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; @@ -248,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) @@ -258,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); @@ -287,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) @@ -296,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"); @@ -310,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) diff --git a/src/pazpar2.c b/src/pazpar2.c index 1f91e6a..1f220c5 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.8 2007-01-03 16:59:32 quinn Exp $ */; +/* $Id: pazpar2.c,v 1.9 2007-01-04 02:35:42 quinn Exp $ */; #include #include @@ -1017,6 +1017,21 @@ int select_targets(struct session *se) return c; } +int session_active_clients(struct session *s) +{ + struct client *c; + int res = 0; + + for (c = s->clients; c; c = c->next) + if (c->connection && (c->state == Client_Connecting || + c->state == Client_Initializing || + c->state == Client_Searching || + c->state == Client_Presenting)) + res++; + + return res; +} + char *search(struct session *se, char *query) { int live_channels = 0; diff --git a/src/pazpar2.h b/src/pazpar2.h index 7677d9d..6bb709a 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -173,9 +173,11 @@ void destroy_session(struct session *s); int load_targets(struct session *s, const char *fn); void statistics(struct session *s, struct statistics *stat); char *search(struct session *s, char *query); -struct record **show(struct session *s, int start, int *num, int *total, int *sumhits, NMEM nmem_show); +struct record **show(struct session *s, int start, int *num, int *total, + int *sumhits, NMEM nmem_show); struct termlist_score **termlist(struct session *s, const char *name, int *num); void session_set_watch(struct session *s, int what, session_watchfun fun, void *data); +int session_active_clients(struct session *s); #endif