Log when session is created
[pazpar2-moved-to-github.git] / src / http_command.c
index 9fc50a8..2e8a6ea 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2012 Index Data
+   Copyright (C) 2006-2013 Index Data
 
 Pazpar2 is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -162,7 +162,7 @@ struct http_session *http_session_create(struct conf_service *service,
     char tmp_str[50];
 
     sprintf(tmp_str, "session#%u", sesid);
-    r->psession = new_session(nmem, service, sesid);
+    r->psession = session_create(nmem, service, sesid);
     r->session_id = sesid;
     r->timestamp = 0;
     r->nmem = nmem;
@@ -405,7 +405,8 @@ static void cmd_exit(struct http_channel *c)
 
     response_open(c, "exit");
     response_close(c, "exit");
-    http_close_server(c->server);
+    if (global_parameters.debug_mode)
+        http_close_server(c->server);
 }
 
 static void cmd_init(struct http_channel *c)
@@ -824,7 +825,9 @@ static void cmd_bytarget(struct http_channel *c)
             return;
         }
     }
+    session_enter_ro(s->psession, "cmd_bytarget");
     bytarget_response(c, s, status_message);
+    session_leave_ro(s->psession, "cmd_bytarget");
     release_session(c, s);
 }
 
@@ -1114,7 +1117,6 @@ static void show_records(struct http_channel *c, struct http_session *s, int act
     {
         error(rs, PAZPAR2_MALFORMED_PARAMETER_VALUE, "sort");
         return;
-
     }
 
     rl = show_range_start(s->psession, sp, startn, &numn, &total, &total_hits, &approx_hits);
@@ -1160,7 +1162,6 @@ static void show_records(struct http_channel *c, struct http_session *s, int act
     }
 
     show_range_stop(s->psession, rl);
-
     response_close(c, "show");
 }
 
@@ -1264,7 +1265,9 @@ static void cmd_show(struct http_channel *c)
             }
         }
     }
+    session_enter_ro(s->psession, "show_records");
     show_records(c, s, status);
+    session_leave_ro(s->psession, "show_records");
     release_session(c, s);
 }
 
@@ -1354,17 +1357,17 @@ static void cmd_stat(struct http_channel *c)
     }
 
     response_open_no_status(c, "stat");
-    wrbuf_printf(c->wrbuf, "<activeclients>%d</activeclients>\n", clients);
-    wrbuf_printf(c->wrbuf, "<hits>" ODR_INT_PRINTF "</hits>\n", stat.num_hits);
-    wrbuf_printf(c->wrbuf, "<records>%d</records>\n", stat.num_records);
-    wrbuf_printf(c->wrbuf, "<clients>%d</clients>\n", stat.num_clients);
-    wrbuf_printf(c->wrbuf, "<unconnected>%d</unconnected>\n", stat.num_no_connection);
-    wrbuf_printf(c->wrbuf, "<connecting>%d</connecting>\n", stat.num_connecting);
-    wrbuf_printf(c->wrbuf, "<working>%d</working>\n", stat.num_working);
-    wrbuf_printf(c->wrbuf, "<idle>%d</idle>\n", stat.num_idle);
-    wrbuf_printf(c->wrbuf, "<failed>%d</failed>\n", stat.num_failed);
-    wrbuf_printf(c->wrbuf, "<error>%d</error>\n", stat.num_error);
-    wrbuf_printf(c->wrbuf, "<progress>%.2f</progress>\n", progress);
+    wrbuf_printf(c->wrbuf, "\n <activeclients>%d</activeclients>\n", clients);
+    wrbuf_printf(c->wrbuf, " <hits>" ODR_INT_PRINTF "</hits>\n", stat.num_hits);
+    wrbuf_printf(c->wrbuf, " <records>%d</records>\n", stat.num_records);
+    wrbuf_printf(c->wrbuf, " <clients>%d</clients>\n", stat.num_clients);
+    wrbuf_printf(c->wrbuf, " <unconnected>%d</unconnected>\n", stat.num_no_connection);
+    wrbuf_printf(c->wrbuf, " <connecting>%d</connecting>\n", stat.num_connecting);
+    wrbuf_printf(c->wrbuf, " <working>%d</working>\n", stat.num_working);
+    wrbuf_printf(c->wrbuf, " <idle>%d</idle>\n", stat.num_idle);
+    wrbuf_printf(c->wrbuf, " <failed>%d</failed>\n", stat.num_failed);
+    wrbuf_printf(c->wrbuf, " <error>%d</error>\n", stat.num_error);
+    wrbuf_printf(c->wrbuf, " <progress>%.2f</progress>\n", progress);
     response_close(c, "stat");
     release_session(c, s);
 }
@@ -1372,26 +1375,39 @@ static void cmd_stat(struct http_channel *c)
 static void cmd_info(struct http_channel *c)
 {
     char yaz_version_str[20];
+    char yaz_sha1_str[42];
 
     response_open_no_status(c, "info");
-    wrbuf_puts(c->wrbuf, " <version>\n");
+    wrbuf_puts(c->wrbuf, "\n <version>\n");
     wrbuf_puts(c->wrbuf, "  <pazpar2");
 #ifdef PAZPAR2_VERSION_SHA1
     wrbuf_printf(c->wrbuf, " sha1=\"%s\"", PAZPAR2_VERSION_SHA1);
 #endif
     wrbuf_puts(c->wrbuf, ">");
     wrbuf_xmlputs(c->wrbuf, VERSION);
-    wrbuf_puts(c->wrbuf, "</pazpar2>");
+    wrbuf_puts(c->wrbuf, "</pazpar2>\n");
 
-    yaz_version(yaz_version_str, 0);
+    yaz_version(yaz_version_str, yaz_sha1_str);
     wrbuf_puts(c->wrbuf, "  <yaz compiled=\"");
     wrbuf_xmlputs(c->wrbuf, YAZ_VERSION);
+    wrbuf_puts(c->wrbuf, "\" sha1=\"");
+    wrbuf_xmlputs(c->wrbuf, yaz_sha1_str);
     wrbuf_puts(c->wrbuf, "\">");
     wrbuf_xmlputs(c->wrbuf, yaz_version_str);
     wrbuf_puts(c->wrbuf, "</yaz>\n");
 
     wrbuf_puts(c->wrbuf, " </version>\n");
-
+#if HAVE_UNISTD_H
+    {
+        char hostname_str[64];
+        if (gethostname(hostname_str, sizeof(hostname_str)) == 0)
+        {
+            wrbuf_puts(c->wrbuf, " <host>");
+            wrbuf_xmlputs(c->wrbuf, hostname_str);
+            wrbuf_puts(c->wrbuf, "</host>\n");
+        }
+    }
+#endif
     info_services(c->server, c->wrbuf);
 
     response_close(c, "info");