From 8a203ad98e5cd0dc77fcf7e3193bc14c285c635a Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Tue, 10 Apr 2007 00:53:24 +0000 Subject: [PATCH] Added a nmem-handle to the http_session to simplify MM. Used to allocate session- permanent data. --- src/http_command.c | 12 ++++++++---- src/pazpar2.c | 9 ++++----- src/pazpar2.h | 14 ++++++++++++-- src/settings.c | 4 +++- src/settings.h | 2 ++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/http_command.c b/src/http_command.c index ae6e8f8..fccd6e5 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -1,5 +1,5 @@ /* - * $Id: http_command.c,v 1.30 2007-04-08 23:04:20 adam Exp $ + * $Id: http_command.c,v 1.31 2007-04-10 00:53:24 quinn Exp $ */ #include @@ -32,6 +32,7 @@ struct http_session { struct session *psession; unsigned int session_id; int timestamp; + NMEM nmem; struct http_session *next; }; @@ -47,10 +48,13 @@ static void session_timeout(IOCHAN i, int event) struct http_session *http_session_create() { - struct http_session *r = xmalloc(sizeof(*r)); - r->psession = new_session(); + NMEM nmem = nmem_create(); + struct http_session *r = nmem_malloc(nmem, sizeof(*r)); + + r->psession = new_session(nmem); r->session_id = 0; r->timestamp = 0; + r->nmem = nmem; r->next = session_list; session_list = r; r->timeout_iochan = iochan_create(-1, session_timeout, 0); @@ -73,7 +77,7 @@ void http_session_destroy(struct http_session *s) } iochan_destroy(s->timeout_iochan); destroy_session(s->psession); - xfree(s); + nmem_destroy(s->nmem); } static void error(struct http_response *rs, char *code, char *msg, char *txt) diff --git a/src/pazpar2.c b/src/pazpar2.c index 1fa0d0c..5e06bac 100644 --- a/src/pazpar2.c +++ b/src/pazpar2.c @@ -1,4 +1,4 @@ -/* $Id: pazpar2.c,v 1.67 2007-04-08 23:04:20 adam Exp $ */ +/* $Id: pazpar2.c,v 1.68 2007-04-10 00:53:24 quinn Exp $ */ #include #include @@ -1207,7 +1207,6 @@ static void select_targets_callback(void *context, struct database *db) se->clients = cl; } -// This should be extended with parameters to control selection criteria // Associates a set of clients with a session; int select_targets(struct session *se, struct database_criterion *crit) { @@ -1284,7 +1283,6 @@ char *search(struct session *se, char *query, char *filter) criteria = parse_filter(se->nmem, filter); strcpy(se->query, query); se->requestid++; - // Release any existing clients select_targets(se, criteria); for (cl = se->clients; cl; cl = cl->next) { @@ -1316,10 +1314,10 @@ void destroy_session(struct session *s) wrbuf_destroy(s->wrbuf); } -struct session *new_session() +struct session *new_session(NMEM nmem) { int i; - struct session *session = xmalloc(sizeof(*session)); + struct session *session = nmem_malloc(nmem, sizeof(*session)); yaz_log(YLOG_DEBUG, "New pazpar2 session"); @@ -1331,6 +1329,7 @@ struct session *new_session() session->clients = 0; session->expected_maxrecs = 0; session->query[0] = '\0'; + session->session_nmem = nmem; session->nmem = nmem_create(); session->wrbuf = wrbuf_alloc(); for (i = 0; i <= SESSION_WATCH_MAX; i++) diff --git a/src/pazpar2.h b/src/pazpar2.h index f7c8175..a20db30 100644 --- a/src/pazpar2.h +++ b/src/pazpar2.h @@ -149,12 +149,22 @@ struct named_termlist struct termlist *termlist; }; +// Represents a database as viewed from one session, possibly with settings overriden +// for that session (to support authorization/authentication) +struct session_database +{ + struct database *database; + struct setting *settings; + struct session_database *next; +}; + // End-user session struct session { struct client *clients; int requestid; char query[1024]; - NMEM nmem; // Nmem for each operation (i.e. search) + NMEM session_nmem; // Nmem for session-permanent storage + NMEM nmem; // Nmem for each operation (i.e. search, result set, etc) WRBUF wrbuf; // Wrbuf for scratch(i.e. search) int num_termlists; struct named_termlist termlists[SESSION_MAX_TERMLISTS]; @@ -215,7 +225,7 @@ struct parameters { struct hitsbytarget *hitsbytarget(struct session *s, int *count); int select_targets(struct session *se, struct database_criterion *crit); -struct session *new_session(); +struct session *new_session(NMEM nmem); void destroy_session(struct session *s); int load_targets(struct session *s, const char *fn); void statistics(struct session *s, struct statistics *stat); diff --git a/src/settings.c b/src/settings.c index dedda87..bde1d3a 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1,4 +1,4 @@ -// $Id: settings.c,v 1.8 2007-04-08 21:51:58 quinn Exp $ +// $Id: settings.c,v 1.9 2007-04-10 00:53:24 quinn Exp $ // This module implements a generic system of settings (attribute-value) that can // be associated with search targets. The system supports both default values, // per-target overrides, and per-user settings. @@ -32,6 +32,8 @@ static char *hard_settings[] = { "pz:xslt", "pz:nativesyntax", "pz:authentication", + "pz:allow", + "pz:maxrecs", 0 }; diff --git a/src/settings.h b/src/settings.h index 5c13528..86f955f 100644 --- a/src/settings.h +++ b/src/settings.h @@ -9,6 +9,8 @@ #define PZ_XSLT 5 #define PZ_NATIVESYNTAX 6 #define PZ_AUTHENTICATION 7 +#define PZ_ALLOW 8 +#define PZ_MAXRECS 9 struct setting { -- 1.7.10.4