From 15f236dc80e9d06944cc49289fd032d748e0c4bc Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Wed, 5 Sep 2007 07:24:04 +0000 Subject: [PATCH] Fixed bug #1395: Fixed size array in function hitsbytarget in logic.c. Also added a test for command=bytarget. --- src/http_command.c | 18 +++++++----------- src/logic.c | 12 ++++++++---- src/pazpar2.h | 4 ++-- test/test_http_21.res | 7 +++++++ test/test_http_urls | 1 + 5 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 test/test_http_21.res diff --git a/src/http_command.c b/src/http_command.c index 0ad6492..cfd4dc1 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,4 +1,4 @@ -/* $Id: http_command.c,v 1.58 2007-08-17 12:39:11 adam Exp $ +/* $Id: http_command.c,v 1.59 2007-09-05 07:24:04 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -20,7 +20,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA */ /* - * $Id: http_command.c,v 1.58 2007-08-17 12:39:11 adam Exp $ + * $Id: http_command.c,v 1.59 2007-09-05 07:24:04 adam Exp $ */ #include @@ -286,13 +286,13 @@ static int cmp_ht(const void *p1, const void *p2) } // This implements functionality somewhat similar to 'bytarget', but in a termlist form -static void targets_termlist(WRBUF wrbuf, struct session *se, int num) +static void targets_termlist(WRBUF wrbuf, struct session *se, int num, + NMEM nmem) { struct hitsbytarget *ht; int count, i; - if (!(ht = hitsbytarget(se, &count))) - return; + ht = hitsbytarget(se, &count, nmem); qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht); for (i = 0; i < count && i < num && ht[i].hits > 0; i++) { @@ -367,7 +367,7 @@ static void cmd_termlist(struct http_channel *c) wrbuf_xmlputs(c->wrbuf, tname); wrbuf_puts(c->wrbuf, "\">\n"); if (!strcmp(tname, "xtargets")) - targets_termlist(c->wrbuf, s->psession, num); + targets_termlist(c->wrbuf, s->psession, num, c->nmem); else { p = termlist(s->psession, tname, &len); @@ -409,11 +409,7 @@ static void cmd_bytarget(struct http_channel *c) if (!s) return; - if (!(ht = hitsbytarget(s->psession, &count))) - { - error(rs, PAZPAR2_HITCOUNTS_FAILED, 0); - return; - } + ht = hitsbytarget(s->psession, &count, c->nmem); wrbuf_rewind(c->wrbuf); wrbuf_puts(c->wrbuf, "OK"); diff --git a/src/logic.c b/src/logic.c index f98d240..e3f5f17 100644 --- a/src/logic.c +++ b/src/logic.c @@ -1,4 +1,4 @@ -/* $Id: logic.c,v 1.62 2007-08-17 12:39:11 adam Exp $ +/* $Id: logic.c,v 1.63 2007-09-05 07:24:04 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -858,11 +858,16 @@ struct session *new_session(NMEM nmem) return session; } -struct hitsbytarget *hitsbytarget(struct session *se, int *count) +struct hitsbytarget *hitsbytarget(struct session *se, int *count, NMEM nmem) { - static struct hitsbytarget res[1000]; // FIXME MM + struct hitsbytarget *res = 0; struct client *cl; + size_t sz = 0; + for (cl = se->clients; cl; cl = client_next_in_session(cl)) + sz++; + + res = nmem_malloc(nmem, sizeof(*res) * sz); *count = 0; for (cl = se->clients; cl; cl = client_next_in_session(cl)) { @@ -878,7 +883,6 @@ struct hitsbytarget *hitsbytarget(struct session *se, int *count) res[*count].connected = client_get_connection(cl) ? 1 : 0; (*count)++; } - return res; } diff --git a/src/pazpar2.h b/src/pazpar2.h index 5ccf667..a21c1f1 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -1,4 +1,4 @@ -/* $Id: pazpar2.h,v 1.47 2007-08-17 12:39:11 adam Exp $ +/* $Id: pazpar2.h,v 1.48 2007-09-05 07:24:04 adam Exp $ Copyright (c) 2006-2007, Index Data. This file is part of Pazpar2. @@ -166,7 +166,7 @@ struct hitsbytarget { int connected; }; -struct hitsbytarget *hitsbytarget(struct session *s, int *count); +struct hitsbytarget *hitsbytarget(struct session *s, int *count, NMEM nmem); int select_targets(struct session *se, struct database_criterion *crit); struct session *new_session(NMEM nmem); void destroy_session(struct session *s); diff --git a/test/test_http_21.res b/test/test_http_21.res new file mode 100644 index 0000000..c31b004 --- /dev/null +++ b/test/test_http_21.res @@ -0,0 +1,7 @@ +OK +z3950.indexdata.com/gils +0 +0 +0 +Client_Idle + \ No newline at end of file diff --git a/test/test_http_urls b/test/test_http_urls index dd9cd95..bddbe4b 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -20,4 +20,5 @@ http://localhost:9763/search.pz2?session=2&command=search&query=computer http://localhost:9763/search.pz2?session=2&command=show&start=0&number=1&block=1 http://localhost:9763/search.pz2?session=2&command=search&query=kubiak%20stanis%C5%82aw http://localhost:9763/search.pz2?session=2&command=search&query=kubiak%20sts%C5%82aw +http://localhost:9763/search.pz2?session=2&command=bytarget -- 1.7.10.4