From 34e731698c89b509732495158582b2c42186b182 Mon Sep 17 00:00:00 2001 From: Marc Cromme Date: Tue, 5 Jun 2007 14:09:10 +0000 Subject: [PATCH] prevent sending empty XML elements in term lists. In target term lists, empty names are replaced by 'NO TARGET NAME' to be visible, in ordinary dynamic term lists terms without ndisplay names are jumped over. Fixed bug #1161 --- src/http_command.c | 54 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/http_command.c b/src/http_command.c index ec50740..97aac8c 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,4 +1,4 @@ -/* $Id: http_command.c,v 1.46 2007-06-05 13:36:40 marc Exp $ +/* $Id: http_command.c,v 1.47 2007-06-05 14:09:10 marc 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.46 2007-06-05 13:36:40 marc Exp $ + * $Id: http_command.c,v 1.47 2007-06-05 14:09:10 marc Exp $ */ #include @@ -258,25 +258,32 @@ static void targets_termlist(WRBUF wrbuf, struct session *se, int num) qsort(ht, count, sizeof(struct hitsbytarget), cmp_ht); for (i = 0; i < count && i < num && ht[i].hits > 0; i++) { + + // do only print terms which have display names + wrbuf_puts(wrbuf, "\n"); //wrbuf_printf(wrbuf, "%s\n", ht[i].id); wrbuf_puts(wrbuf, ""); wrbuf_xmlputs(wrbuf, ht[i].id); wrbuf_puts(wrbuf, "\n"); - + wrbuf_puts(wrbuf, ""); - wrbuf_xmlputs(wrbuf, ht[i].name); + if (!ht[i].name || !ht[i].name[0]) + wrbuf_xmlputs(wrbuf, "NO TARGET NAME"); + else + wrbuf_xmlputs(wrbuf, ht[i].name); wrbuf_puts(wrbuf, "\n"); - + wrbuf_printf(wrbuf, "%d\n", ht[i].hits); - + //wrbuf_printf(wrbuf, "%s\n", ht[i].state); wrbuf_puts(wrbuf, ""); wrbuf_xmlputs(wrbuf, ht[i].state); wrbuf_puts(wrbuf, "\n"); - - wrbuf_printf(wrbuf, "%d\n", ht[i].diagnostic); + + wrbuf_printf(wrbuf, "%d\n", + ht[i].diagnostic); wrbuf_puts(wrbuf, "\n"); } } @@ -308,8 +315,8 @@ static void cmd_termlist(struct http_channel *c) wrbuf_rewind(c->wrbuf); - wrbuf_puts(c->wrbuf, ""); - wrbuf_printf(c->wrbuf, "\n%d", status); + wrbuf_puts(c->wrbuf, "\n"); + wrbuf_printf(c->wrbuf, "%d\n", status); while (*name) { char tname[256]; @@ -320,7 +327,7 @@ static void cmd_termlist(struct http_channel *c) strncpy(tname, name, tp - name); tname[tp - name] = '\0'; - wrbuf_puts(c->wrbuf, "\nwrbuf, "wrbuf, tname); wrbuf_puts(c->wrbuf, "\">\n"); if (!strcmp(tname, "xtargets")) @@ -329,23 +336,28 @@ static void cmd_termlist(struct http_channel *c) { p = termlist(s->psession, tname, &len); if (p) - for (i = 0; i < len && i < num; i++) - { - wrbuf_puts(c->wrbuf, "\n"); + for (i = 0; i < len && i < num; i++){ + // prevnt sending empty term elements + if (!p[i]->term || !p[i]->term[0]) + continue; + + wrbuf_puts(c->wrbuf, ""); 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, ""); - } + + wrbuf_printf(c->wrbuf, + "%d", + p[i]->frequency); + wrbuf_puts(c->wrbuf, "\n"); + } } - wrbuf_puts(c->wrbuf, "\n"); + wrbuf_puts(c->wrbuf, "\n"); name = tp; if (*name == ',') name++; } - wrbuf_puts(c->wrbuf, ""); + wrbuf_puts(c->wrbuf, "\n"); rs->payload = nmem_strdup(rq->channel->nmem, wrbuf_cstr(c->wrbuf)); http_send_response(c); } @@ -472,7 +484,7 @@ static void cmd_record(struct http_channel *c) return; } wrbuf_puts(c->wrbuf, "\n"); - wrbuf_printf(c->wrbuf, "%d", rec->recid); + wrbuf_printf(c->wrbuf, "%d\n", rec->recid); write_metadata(c->wrbuf, service, rec->metadata, 1); for (r = rec->records; r; r = r->next) write_subrecord(r, c->wrbuf, service, 1); -- 1.7.10.4