WRBUF updates.
[pazpar2-moved-to-github.git] / src / http_command.c
index 40a9a28..223903d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: http_command.c,v 1.25 2007-01-18 16:21:23 quinn Exp $
+ * $Id: http_command.c,v 1.28 2007-03-20 07:27:51 adam Exp $
  */
 
 #include <stdio.h>
@@ -168,7 +168,8 @@ static void targets_termlist(WRBUF wrbuf, struct session *se, int num)
     for (i = 0; i < count && i < num && ht[i].hits > 0; i++)
     {
         wrbuf_puts(wrbuf, "\n<term>\n");
-        wrbuf_printf(wrbuf, "<name>%s</name>\n", ht[i].id);
+        wrbuf_printf(wrbuf, "<id>%s</id>\n", ht[i].id);
+        wrbuf_printf(wrbuf, "<name>%s</name>\n", ht[i].name);
         wrbuf_printf(wrbuf, "<frequency>%d</frequency>\n", ht[i].hits);
         wrbuf_printf(wrbuf, "<state>%s</state>\n", ht[i].state);
         wrbuf_printf(wrbuf, "<diagnostic>%d</diagnostic>\n", ht[i].diagnostic);
@@ -236,7 +237,7 @@ static void cmd_termlist(struct http_channel *c)
             name++;
     }
     wrbuf_puts(c->wrbuf, "</termlist>");
-    rs->payload = nmem_strdup(rq->channel->nmem, wrbuf_buf(c->wrbuf));
+    rs->payload = nmem_strdup(rq->channel->nmem, wrbuf_cstr(c->wrbuf));
     http_send_response(c);
 }
 
@@ -271,7 +272,7 @@ static void cmd_bytarget(struct http_channel *c)
     }
 
     wrbuf_puts(c->wrbuf, "</bytarget>");
-    rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
+    rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
     http_send_response(c);
 }
 
@@ -309,7 +310,9 @@ static void write_metadata(WRBUF w, struct conf_service *service,
 
 static void write_subrecord(struct record *r, WRBUF w, struct conf_service *service)
 {
-    wrbuf_printf(w, "<location id=\"%s\">\n", r->client->database->url);
+    wrbuf_printf(w, "<location id=\"%s\" name=\"%s\">\n",
+            r->client->database->url,
+            r->client->database->name ? r->client->database->name : "");
     write_metadata(w, service, r->metadata, 1);
     wrbuf_puts(w, "</location>\n");
 }
@@ -345,7 +348,7 @@ static void cmd_record(struct http_channel *c)
     for (r = rec->records; r; r = r->next)
         write_subrecord(r, c->wrbuf, service);
     wrbuf_puts(c->wrbuf, "</record>\n");
-    rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
+    rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
     http_send_response(c);
 }
 
@@ -412,7 +415,7 @@ static void show_records(struct http_channel *c, int active)
     }
 
     wrbuf_puts(c->wrbuf, "</show>\n");
-    rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
+    rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
     http_send_response(c);
 }
 
@@ -466,6 +469,7 @@ static void cmd_search(struct http_channel *c)
     struct http_response *rs = c->response;
     struct http_session *s = locate_session(rq, rs);
     char *query = http_argbyname(rq, "query");
+    char *filter = http_argbyname(rq, "filter");
     char *res;
 
     if (!s)
@@ -475,7 +479,7 @@ static void cmd_search(struct http_channel *c)
         error(rs, "417", "Must supply query", 0);
         return;
     }
-    res = search(s->psession, query);
+    res = search(s->psession, query, filter);
     if (res)
     {
         error(rs, "417", res, res);
@@ -515,7 +519,7 @@ static void cmd_stat(struct http_channel *c)
     wrbuf_printf(c->wrbuf, "<failed>%d</failed>\n", stat.num_failed);
     wrbuf_printf(c->wrbuf, "<error>%d</error>\n", stat.num_error);
     wrbuf_puts(c->wrbuf, "</stat>");
-    rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
+    rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
     http_send_response(c);
 }
 
@@ -535,7 +539,7 @@ static void cmd_info(struct http_channel *c)
     wrbuf_printf(c->wrbuf, " </version>\n");
     
     wrbuf_puts(c->wrbuf, "</info>");
-    rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
+    rs->payload = nmem_strdup(c->nmem, wrbuf_cstr(c->wrbuf));
     http_send_response(c);
 }