From: Adam Dickmeiss Date: Wed, 10 Feb 2010 14:58:24 +0000 (+0100) Subject: Starting HTTP session manager X-Git-Tag: v1.4.0~145 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=c453b003094541adc6fc155bc9a7aecf788245bc;p=pazpar2-moved-to-github.git Starting HTTP session manager --- diff --git a/src/http.c b/src/http.c index 1e73f7c..a12fb4e 100644 --- a/src/http.c +++ b/src/http.c @@ -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(); } /* diff --git a/src/http.h b/src/http.h index e075e0c..f9af7b6 100644 --- a/src/http.h +++ b/src/http.h @@ -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 /* diff --git a/src/http_command.c b/src/http_command.c index 3631740..b98cd31 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -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)