Starting HTTP session manager
authorAdam Dickmeiss <adam@indexdata.dk>
Wed, 10 Feb 2010 14:58:24 +0000 (15:58 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Wed, 10 Feb 2010 14:58:24 +0000 (15:58 +0100)
src/http.c
src/http.h
src/http_command.c

index 1e73f7c..a12fb4e 100644 (file)
@@ -84,9 +84,9 @@ struct http_buf
 
 
 static void proxy_io(IOCHAN i, int event);
-static struct http_channel *http_create(http_server_t http_server,
-                                        const char *addr,
-                                        struct conf_server *server);
+static struct http_channel *http_channel_create(http_server_t http_server,
+                                                const char *addr,
+                                                struct conf_server *server);
 static void http_destroy(IOCHAN i);
 static http_server_t http_server_create(void);
 static void http_server_incref(http_server_t hs);
@@ -98,6 +98,7 @@ struct http_server
     YAZ_MUTEX mutex;
     int listener_socket;
     int ref_count;
+    http_sessions_t http_sessions;
     struct sockaddr_in *proxy_addr;
 };
 
@@ -1102,9 +1103,9 @@ static void http_destroy(IOCHAN i)
     iochan_destroy(i);
 }
 
-static struct http_channel *http_create(http_server_t hs,
-                                        const char *addr,
-                                        struct conf_server *server)
+static struct http_channel *http_channel_create(http_server_t hs,
+                                                const char *addr,
+                                                struct conf_server *server)
 {
     struct http_channel *r;
 
@@ -1127,6 +1128,7 @@ static struct http_channel *http_create(http_server_t hs,
     }
     http_server_incref(hs);
     r->http_server = hs;
+    r->http_sessions = hs->http_sessions;
     r->server = server;
     r->proxy = 0;
     r->iochan = 0;
@@ -1168,7 +1170,8 @@ 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(server->http_server, inet_ntoa(addr.sin_addr), server);
+    ch = http_channel_create(server->http_server, inet_ntoa(addr.sin_addr),
+                             server);
     ch->iochan = c;
     iochan_setdata(c, ch);
 
@@ -1360,6 +1363,7 @@ http_server_t http_server_create(void)
     hs->ref_count = 1;
     hs->http_buf_freelist = 0;
     hs->http_channel_freelist = 0;
+    hs->http_sessions = 0;
     return hs;
 }
 
@@ -1394,6 +1398,7 @@ void http_server_destroy(http_server_t hs)
                 xfree(c);
                 c = c_next;
             }
+            http_sessions_destroy(hs->http_sessions);
             xfree(hs->proxy_addr);
             yaz_mutex_destroy(&hs->mutex);
             xfree(hs);
@@ -1415,6 +1420,7 @@ void http_mutex_init(struct conf_server *server)
 
     assert(server->http_server->mutex == 0);
     yaz_mutex_create(&server->http_server->mutex);
+    server->http_server->http_sessions = http_sessions_create();
 }
 
 /*
index e075e0c..f9af7b6 100644 (file)
@@ -26,6 +26,7 @@ struct http_buf;
 typedef struct http_channel_observer_s *http_channel_observer_t;
 
 typedef struct http_server *http_server_t;
+typedef struct http_sessions *http_sessions_t;
 
 struct http_channel
 {
@@ -49,6 +50,7 @@ struct http_channel
     http_channel_observer_t observers;
     struct conf_server *server;
     http_server_t http_server;
+    http_sessions_t http_sessions;
 };
 
 struct http_proxy //  attached to iochan for proxy connection
@@ -128,6 +130,9 @@ struct http_channel *http_channel_observer_chan(http_channel_observer_t obs);
 
 void http_command(struct http_channel *c);
 
+http_sessions_t http_sessions_create(void);
+void http_sessions_destroy(http_sessions_t hs);
+
 #endif
 
 /*
index 3631740..b98cd31 100644 (file)
@@ -56,6 +56,30 @@ struct http_session {
 
 static struct http_session *session_list = 0; /* thread pr */
 
+
+struct http_sessions {
+    struct http_session *session_list;
+    YAZ_MUTEX mutex;
+};
+
+http_sessions_t http_sessions_create(void)
+{
+    http_sessions_t hs = xmalloc(sizeof(*hs));
+    hs->session_list = 0;
+    yaz_mutex_create(&hs->mutex);
+    return hs;
+}
+
+void http_sessions_destroy(http_sessions_t hs)
+{
+    if (hs)
+    {
+        yaz_mutex_destroy(&hs->mutex);
+        /* should remove session_list too */
+        xfree(hs);
+    }
+}
+
 void http_session_destroy(struct http_session *s);
 
 static void session_timeout(IOCHAN i, int event)