GPLv2. Added appendix with full license. Added refernece to that from
[pazpar2-moved-to-github.git] / src / http_command.c
index 0dfbc6d..aeb8686 100644 (file)
@@ -1,5 +1,26 @@
+/* $Id: http_command.c,v 1.32 2007-04-10 08:48:56 adam Exp $
+   Copyright (c) 2006-2007, Index Data.
+
+This file is part of Pazpar2.
+
+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
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with Pazpar2; see the file LICENSE.  If not, write to the
+Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA.
+ */
+
 /*
- * $Id: http_command.c,v 1.27 2007-03-20 05:32:58 quinn Exp $
+ * $Id: http_command.c,v 1.32 2007-04-10 08:48:56 adam Exp $
  */
 
 #include <stdio.h>
@@ -32,6 +53,7 @@ struct http_session {
     struct session *psession;
     unsigned int session_id;
     int timestamp;
+    NMEM nmem;
     struct http_session *next;
 };
 
@@ -47,10 +69,13 @@ static void session_timeout(IOCHAN i, int event)
 
 struct http_session *http_session_create()
 {
-    struct http_session *r = xmalloc(sizeof(*r));
-    r->psession = new_session();
+    NMEM nmem = nmem_create();
+    struct http_session *r = nmem_malloc(nmem, sizeof(*r));
+
+    r->psession = new_session(nmem);
     r->session_id = 0;
     r->timestamp = 0;
+    r->nmem = nmem;
     r->next = session_list;
     session_list = r;
     r->timeout_iochan = iochan_create(-1, session_timeout, 0);
@@ -73,7 +98,7 @@ void http_session_destroy(struct http_session *s)
         }
     iochan_destroy(s->timeout_iochan);
     destroy_session(s->psession);
-    xfree(s);
+    nmem_destroy(s->nmem);
 }
 
 static void error(struct http_response *rs, char *code, char *msg, char *txt)
@@ -237,7 +262,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);
 }
 
@@ -272,7 +297,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);
 }
 
@@ -348,7 +373,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);
 }
 
@@ -415,7 +440,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);
 }
 
@@ -519,7 +544,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);
 }
 
@@ -539,7 +564,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);
 }