unsigned int session_id;
int timestamp;
NMEM nmem;
+ http_sessions_t http_sessions;
struct http_session *next;
};
-static struct http_session *session_list = 0; /* thread pr */
-
-
struct http_sessions {
struct http_session *session_list;
YAZ_MUTEX mutex;
{
if (hs)
{
+ struct http_session *s = hs->session_list;
+ while (s)
+ {
+ struct http_session *s_next = s->next;
+ iochan_destroy(s->timeout_iochan);
+ destroy_session(s->psession);
+ nmem_destroy(s->nmem);
+ s = s_next;
+ }
yaz_mutex_destroy(&hs->mutex);
- /* should remove session_list too */
xfree(hs);
}
}
http_session_destroy(s);
}
-struct http_session *http_session_create(struct conf_service *service)
+struct http_session *http_session_create(struct conf_service *service,
+ http_sessions_t http_sessions)
{
NMEM nmem = nmem_create();
struct http_session *r = nmem_malloc(nmem, sizeof(*r));
r->session_id = 0;
r->timestamp = 0;
r->nmem = nmem;
- r->next = session_list;
- session_list = r;
+ r->http_sessions = http_sessions;
+
+ yaz_mutex_enter(http_sessions->mutex);
+ r->next = http_sessions->session_list;
+ http_sessions->session_list = r;
+ yaz_mutex_leave(http_sessions->mutex);
+
r->timeout_iochan = iochan_create(-1, session_timeout, 0);
iochan_setdata(r->timeout_iochan, r);
iochan_settimeout(r->timeout_iochan, service->session_timeout);
{
struct http_session **p;
- for (p = &session_list; *p; p = &(*p)->next)
+ http_sessions_t http_sessions = s->http_sessions;
+
+ yaz_mutex_enter(http_sessions->mutex);
+ for (p = &http_sessions->session_list; *p; p = &(*p)->next)
if (*p == s)
{
*p = (*p)->next;
break;
}
+ yaz_mutex_leave(http_sessions->mutex);
yaz_log(YLOG_LOG, "Destroying session %u", s->session_id);
iochan_destroy(s->timeout_iochan);
destroy_session(s->psession);
return res;
}
-static struct http_session *locate_session(struct http_request *rq, struct http_response *rs)
+static struct http_session *locate_session(struct http_channel *c)
{
+ struct http_response *rs = c->response;
+ struct http_request *rq = c->request;
struct http_session *p;
const char *session = http_argbyname(rq, "session");
+ http_sessions_t http_sessions = c->http_sessions;
unsigned int id;
if (!session)
return 0;
}
id = atoi(session);
- for (p = session_list; p; p = p->next)
+ yaz_mutex_enter(http_sessions->mutex);
+ for (p = http_sessions->session_list; p; p = p->next)
if (id == p->session_id)
- {
- iochan_activity(p->timeout_iochan);
- return p;
- }
- error(rs, PAZPAR2_NO_SESSION, session);
- return 0;
+ break;
+ yaz_mutex_leave(http_sessions->mutex);
+ if (p)
+ iochan_activity(p->timeout_iochan);
+ else
+ error(rs, PAZPAR2_NO_SESSION, session);
+ return p;
}
// Decode settings parameters and apply to session
return;
}
}
- s = http_session_create(service);
+ s = http_session_create(service, c->http_sessions);
yaz_log(YLOG_DEBUG, "HTTP Session init");
if (!clear || *clear == '0')
{
struct http_response *rs = c->response;
struct http_request *rq = c->request;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
const char *content_type = http_lookup_header(rq->headers, "Content-Type");
if (!s)
{
struct http_response *rs = c->response;
struct http_request *rq = c->request;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
struct termlist_score **p;
int len;
int i;
{
struct http_response *rs = c->response;
struct http_request *rq = c->request;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
struct hitsbytarget *ht;
const char *settings = http_argbyname(rq, "settings");
int count, i;
{
struct http_response *rs = c->response;
struct http_request *rq = c->request;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
struct record_cluster *rec, *prev_r, *next_r;
struct record *r;
struct conf_service *service;
{
struct http_request *rq = c->request;
struct http_response *rs = c->response;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
struct record_cluster **rl;
struct reclist_sortparms *sp;
const char *start = http_argbyname(rq, "start");
static void cmd_show(struct http_channel *c)
{
struct http_request *rq = c->request;
- struct http_response *rs = c->response;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
const char *block = http_argbyname(rq, "block");
int status;
static void cmd_ping(struct http_channel *c)
{
- struct http_request *rq = c->request;
struct http_response *rs = c->response;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
if (!s)
return;
rs->payload = HTTP_COMMAND_RESPONSE_PREFIX "<ping><status>OK</status></ping>";
{
struct http_request *rq = c->request;
struct http_response *rs = c->response;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
const char *query = http_argbyname(rq, "query");
const char *filter = http_argbyname(rq, "filter");
const char *maxrecs = http_argbyname(rq, "maxrecs");
static void cmd_stat(struct http_channel *c)
{
- struct http_request *rq = c->request;
struct http_response *rs = c->response;
- struct http_session *s = locate_session(rq, rs);
+ struct http_session *s = locate_session(c);
struct statistics stat;
int clients;