-/* $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.
*/
/*
- * $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 <stdio.h>
}
// 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++)
{
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);
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, "<bytarget><status>OK</status>");
-/* $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.
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))
{
res[*count].connected = client_get_connection(cl) ? 1 : 0;
(*count)++;
}
-
return res;
}
-/* $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.
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);