Changed enclosing tag for info command response to <info>
[pazpar2-moved-to-github.git] / src / http_command.c
index edd6425..8483705 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: http_command.c,v 1.14 2007-01-09 22:06:49 quinn Exp $
+ * $Id: http_command.c,v 1.21 2007-01-12 23:41:35 quinn Exp $
  */
 
 #include <stdio.h>
@@ -17,6 +17,7 @@
 
 #include <yaz/yaz-util.h>
 
+#include "config.h"
 #include "util.h"
 #include "eventl.h"
 #include "pazpar2.h"
@@ -99,7 +100,7 @@ unsigned int make_sessionid()
     if (gettimeofday(&t, 0) < 0)
         abort();
     res = t.tv_sec;
-    res = ((res << 8) | (seq & 0xff)) & ((unsigned int) (1 << 31) - 1);
+    res = ((res << 8) | (seq & 0xff)) & ((1U << 31) - 1);
     return res;
 }
 
@@ -327,6 +328,7 @@ static void cmd_record(struct http_channel *c)
         return;
     }
     wrbuf_puts(c->wrbuf, "<record>\n");
+    wrbuf_printf(c->wrbuf, "<recid>%d</recid>", rec->recid);
     write_metadata(c->wrbuf, service, rec->metadata, 1);
     wrbuf_puts(c->wrbuf, "</record>\n");
     rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
@@ -497,6 +499,26 @@ static void cmd_stat(struct http_channel *c)
     http_send_response(c);
 }
 
+static void cmd_info(struct http_channel *c)
+{
+    char yaz_version_str[20];
+    struct http_request *rq = c->request;
+    struct http_response *rs = c->response;
+
+    wrbuf_rewind(c->wrbuf);
+    wrbuf_puts(c->wrbuf, "<info>\n");
+    wrbuf_printf(c->wrbuf, " <version>\n");
+    wrbuf_printf(c->wrbuf, "  <pazpar2>%s</pazpar2>\n", VERSION);
+
+    yaz_version(yaz_version_str, 0);
+    wrbuf_printf(c->wrbuf, "  <yaz compiled=\"%s\">%s</yaz>\n",
+                 YAZ_VERSION, yaz_version_str);
+    wrbuf_printf(c->wrbuf, " </version>\n");
+    
+    wrbuf_puts(c->wrbuf, "</info>");
+    rs->payload = nmem_strdup(c->nmem, wrbuf_buf(c->wrbuf));
+    http_send_response(c);
+}
 
 struct {
     char *name;
@@ -511,6 +533,7 @@ struct {
     { "exit", cmd_exit },
     { "ping", cmd_ping },
     { "record", cmd_record },
+    { "info", cmd_info },
     {0,0}
 };
 
@@ -521,6 +544,10 @@ void http_command(struct http_channel *c)
     int i;
 
     c->response = rs;
+
+    http_addheader(rs, "Expires", "Thu, 19 Nov 1981 08:52:00 GMT");
+    http_addheader(rs, "Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
+
     if (!command)
     {
         error(rs, "417", "Must supply command", 0);