Avoid mixed-stmt declare
[pazpar2-moved-to-github.git] / src / http.c
index 781a7d0..c23b63d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: http.c,v 1.39 2007-09-26 08:53:53 adam Exp $
+/* $Id: http.c,v 1.42 2007-10-08 13:19:23 adam Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -68,7 +68,8 @@ static struct http_channel *http_channel_freelist = 0;
 
 struct http_channel_observer_s {
     void *data;
-    void (*destroy)(void *data, struct http_channel *chan);
+    void *data2;
+    http_channel_destroy_t destroy;
     struct http_channel_observer_s *next;
     struct http_channel *chan;
 };
@@ -292,6 +293,7 @@ struct http_response *http_create_response(struct http_channel *c)
     r->channel = c;
     r->headers = 0;
     r->payload = 0;
+    r->content_type = "text/xml";
     return r;
 }
 
@@ -483,13 +485,13 @@ struct http_request *http_parse_request(struct http_channel *c,
 
     if (!(buf = strchr(buf, ' ')))
     {
-        yaz_log(YLOG_WARN, "Syntax error in request (1)");
+        yaz_log(YLOG_WARN, "Missing Request-URI in HTTP request");
         return 0;
     }
     buf++;
     if (!(p = strchr(buf, ' ')))
     {
-        yaz_log(YLOG_WARN, "Syntax error in request (2)");
+        yaz_log(YLOG_WARN, "HTTP Request-URI not terminated (too long?)");
         return 0;
     }
     *(p++) = '\0';
@@ -603,8 +605,8 @@ static struct http_buf *http_serialize_response(struct http_channel *c,
     {
         wrbuf_printf(c->wrbuf, "Content-Length: %d\r\n", r->payload ?
                 (int) strlen(r->payload) : 0);
-        wrbuf_printf(c->wrbuf, "Content-Type: text/xml\r\n");
-        if (1)
+        wrbuf_printf(c->wrbuf, "Content-Type: %s\r\n", r->content_type);
+        if (!strcmp(r->content_type, "text/xml"))
         {
             xmlDoc *doc = xmlParseMemory(r->payload, strlen(r->payload));
             if (doc)
@@ -1227,7 +1229,7 @@ static void http_fire_observers(struct http_channel *c)
     http_channel_observer_t p = c->observers;
     while (p)
     {
-        p->destroy(p->data, c);
+        p->destroy(p->data, c, p->data2);
         p = p->next;
     }
 }
@@ -1248,6 +1250,7 @@ http_channel_observer_t http_add_observer(struct http_channel *c, void *data,
     http_channel_observer_t obs = xmalloc(sizeof(*obs));
     obs->chan = c;
     obs->data = data;
+    obs->data2 = 0;
     obs->destroy= des;
     obs->next = c->observers;
     c->observers = obs;
@@ -1271,6 +1274,12 @@ struct http_channel *http_channel_observer_chan(http_channel_observer_t obs)
     return obs->chan;
 }
 
+void http_observer_set_data2(http_channel_observer_t obs, void *data2)
+{
+    obs->data2 = data2;
+}
+
+
 /*
  * Local variables:
  * c-basic-offset: 4