Targetprofiles part of service.
[pazpar2-moved-to-github.git] / src / http.c
index 10b9948..69533c6 100644 (file)
@@ -71,7 +71,8 @@ typedef int socklen_t;
 #define MAX_HTTP_HEADER 4096
 
 static void proxy_io(IOCHAN i, int event);
-static struct http_channel *http_create(const char *addr);
+static struct http_channel *http_create(const char *addr,
+                                        struct conf_server *server);
 static void http_destroy(IOCHAN i);
 
 // If this is set, we proxy normal HTTP requests
@@ -735,7 +736,7 @@ static int http_proxy(struct http_request *rq)
     struct http_buf *requestbuf;
     char server_via[128] = "";
     char server_port[16] = "";
-    struct conf_server *ser = global_parameters.server;
+    struct conf_server *ser = c->server;
 
     if (!p) // This is a new connection. Create a proxy channel
     {
@@ -794,7 +795,8 @@ static int http_proxy(struct http_request *rq)
         hp = http_header_append(c, hp, 
                                 "X-Pazpar2-Server-Port", server_port);
         sprintf(server_via,  "1.1 %s:%s (%s/%s)",  
-                ser->host, server_port, PACKAGE_NAME, PACKAGE_VERSION);
+                ser->host ? ser->host : "@",
+                server_port, PACKAGE_NAME, PACKAGE_VERSION);
         hp = http_header_append(c, hp, "Via" , server_via);
         hp = http_header_append(c, hp, "X-Forwarded-For", c->addr);
     }
@@ -1063,7 +1065,8 @@ static void http_destroy(IOCHAN i)
     iochan_destroy(i);
 }
 
-static struct http_channel *http_create(const char *addr)
+static struct http_channel *http_create(const char *addr,
+                                        struct conf_server *server)
 {
     struct http_channel *r = http_channel_freelist;
 
@@ -1079,6 +1082,7 @@ static struct http_channel *http_create(const char *addr)
         r->nmem = nmem_create();
         r->wrbuf = wrbuf_alloc();
     }
+    r->server = server;
     r->proxy = 0;
     r->iochan = 0;
     r->iqueue = r->oqueue = 0;
@@ -1106,6 +1110,7 @@ static void http_accept(IOCHAN i, int event)
     int s;
     IOCHAN c;
     struct http_channel *ch;
+    struct conf_server *server = iochan_getdata(i);
 
     len = sizeof addr;
     if ((s = accept(fd, (struct sockaddr *) &addr, &len)) < 0)
@@ -1118,7 +1123,7 @@ static void http_accept(IOCHAN i, int event)
     yaz_log(YLOG_DEBUG, "New command connection");
     c = iochan_create(s, http_io, EVENT_INPUT | EVENT_EXCEPT);
     
-    ch = http_create(inet_ntoa(addr.sin_addr));
+    ch = http_create(inet_ntoa(addr.sin_addr), server);
     ch->iochan = c;
     iochan_setdata(c, ch);
 
@@ -1128,7 +1133,7 @@ static void http_accept(IOCHAN i, int event)
 static int listener_socket = 0;
 
 /* Create a http-channel listener, syntax [host:]port */
-int http_init(const char *addr)
+int http_init(const char *addr, struct conf_server *server)
 {
     IOCHAN c;
     int l;
@@ -1190,6 +1195,7 @@ int http_init(const char *addr)
     listener_socket = l;
 
     c = iochan_create(l, http_accept, EVENT_INPUT | EVENT_EXCEPT);
+    iochan_setdata(c, server);
     pazpar2_add_channel(c);
     return 0;
 }
@@ -1294,7 +1300,9 @@ void http_observer_set_data2(http_channel_observer_t obs, void *data2)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+