From: Adam Dickmeiss Date: Thu, 11 Feb 2010 13:52:07 +0000 (+0100) Subject: Fix bug #3260 (dynamic/static settings mixed) X-Git-Tag: v1.4.0~143 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=7c65462a944e8f9fbcfa2d310e37dc1a408888e1;p=pazpar2-moved-to-github.git Fix bug #3260 (dynamic/static settings mixed) --- diff --git a/src/database.c b/src/database.c index fa531b5..c2fb3b1 100644 --- a/src/database.c +++ b/src/database.c @@ -140,24 +140,13 @@ void resolve_databases(struct conf_service *service) resolve_database(db); } -static struct database *load_database(const char *id, - struct conf_service *service) +struct database *new_database(const char *id, NMEM nmem) { - xmlDoc *doc = 0; - struct zr_explain *explain = 0; struct database *db; char hostport[256]; char *dbname; struct setting *idset; - if (service->targetprofiles - && (doc = get_explain_xml(service->targetprofiles, id))) - { - explain = zr_read_xml(service->nmem, xmlDocGetRootElement(doc)); - if (!explain) - return 0; - } - if (strlen(id) > 255) return 0; strcpy(hostport, id); @@ -165,27 +154,47 @@ static struct database *load_database(const char *id, *(dbname++) = '\0'; else dbname = ""; - db = nmem_malloc(service->nmem, sizeof(*db)); + db = nmem_malloc(nmem, sizeof(*db)); memset(db, 0, sizeof(*db)); db->host = 0; - db->url = nmem_strdup(service->nmem, id); - db->databases = nmem_malloc(service->nmem, 2 * sizeof(char *)); - db->databases[0] = nmem_strdup(service->nmem, dbname); + db->url = nmem_strdup(nmem, id); + db->databases = nmem_malloc(nmem, 2 * sizeof(char *)); + db->databases[0] = nmem_strdup(nmem, dbname); db->databases[1] = 0; db->errors = 0; - db->explain = explain; + db->explain = 0; - db->num_settings = settings_num(service); - db->settings = nmem_malloc(service->nmem, sizeof(struct settings*) * + db->num_settings = PZ_NEGOTIATION_CHARSET+1; + db->settings = nmem_malloc(nmem, sizeof(struct settings*) * db->num_settings); memset(db->settings, 0, sizeof(struct settings*) * db->num_settings); - idset = nmem_malloc(service->nmem, sizeof(*idset)); + idset = nmem_malloc(nmem, sizeof(*idset)); idset->precedence = 0; idset->name = "pz:id"; idset->target = idset->value = db->url; idset->next = 0; db->settings[PZ_ID] = idset; + db->next = 0; + + return db; +} +static struct database *load_database(const char *id, + struct conf_service *service) +{ + struct database *db; + struct zr_explain *explain = 0; + xmlDoc *doc = 0; + + if (service->targetprofiles + && (doc = get_explain_xml(service->targetprofiles, id))) + { + explain = zr_read_xml(service->nmem, xmlDocGetRootElement(doc)); + if (!explain) + return 0; + } + db = new_database(id, service->nmem); + db->explain = explain; db->next = service->databases; service->databases = db; diff --git a/src/database.h b/src/database.h index 1d73161..cf12e9d 100644 --- a/src/database.h +++ b/src/database.h @@ -27,5 +27,5 @@ int predef_grep_databases(void *context, struct conf_service *service, void (*fun)(void *context, struct database *db)); int match_zurl(const char *zurl, const char *pattern); int resolve_database(struct database *db); - +struct database *new_database(const char *id, NMEM nmem); #endif diff --git a/src/http_command.c b/src/http_command.c index b98cd31..bfc101e 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -66,6 +66,7 @@ http_sessions_t http_sessions_create(void) { http_sessions_t hs = xmalloc(sizeof(*hs)); hs->session_list = 0; + hs->mutex = 0; yaz_mutex_create(&hs->mutex); return hs; } diff --git a/src/logic.c b/src/logic.c index 0180c27..28929de 100644 --- a/src/logic.c +++ b/src/logic.c @@ -297,7 +297,7 @@ void session_settings_dump(struct session *se, // Will be extended to take into account user associated with session const char *session_setting_oneval(struct session_database *db, int offset) { - if (!db->settings[offset]) + if (offset >= db->num_settings || !db->settings[offset]) return ""; return db->settings[offset]->value; } @@ -523,7 +523,10 @@ static void session_init_databases_fun(void *context, struct database *db) sizeof(struct settings *) * db->num_settings); new->num_settings = db->num_settings; for (i = 0; i < db->num_settings; i++) - new->settings[i] = db->settings[i]; + { + struct setting *setting = db->settings[i]; + new->settings[i] = setting; + } new->next = se->databases; se->databases = new; } @@ -547,11 +550,12 @@ void session_init_databases(struct session *se) static struct session_database *load_session_database(struct session *se, char *id) { - struct database *db = find_database(id, se->service); + struct database *db = new_database(id, se->session_nmem); resolve_database(db); session_init_databases_fun((void*) se, db); + // New sdb is head of se->databases list return se->databases; } diff --git a/test/test_http_urls b/test/test_http_urls index 93cf534..2ef6c62 100644 --- a/test/test_http_urls +++ b/test/test_http_urls @@ -30,7 +30,7 @@ http://localhost:9763/search.pz2?command=init&clear=1 http://localhost:9763/search.pz2?session=4&command=settings&pz:name%5Bz3950.indexdata.com%2Fgils%5D=gils&pz:requestsyntax%5Bz3950.indexdata.com%2Fgils%5D=usmarc&pz:nativesyntax%5Bz3950.indexdata.com%2Fgils%5D=iso2709&pz:xslt%5Bz3950.indexdata.com%2Fgils%5D=marc21.mmap http://localhost:9763/search.pz2?session=4&command=search&query=computer 2 http://localhost:9763/search.pz2?session=4&command=show&block=1 -http://localhost:9763/search.pz2?command=init&clear=1 +http://localhost:9763/search.pz2?command=init http://localhost:9763/search.pz2?session=5&command=settings&pz:name%5Bz3950.indexdata.com%2Fmarc%5D=marc&pz:requestsyntax%5Bz3950.indexdata.com%2Fmarc%5D=usmarc&pz:nativesyntax%5Bz3950.indexdata.com%2Fmarc%5D=iso2709&pz:xslt%5Bz3950.indexdata.com%2Fmarc%5D=marc21.xsl&pz:recordfilter%5Bz3950.indexdata.com%2Fmarc%5D=date http://localhost:9763/search.pz2?session=5&command=search&query=computer&filter=pz%3Aid%3Dz3950.indexdata.com%2Fmarc 2 http://localhost:9763/search.pz2?session=5&command=show&block=1 diff --git a/test/test_settings_8.res b/test/test_settings_8.res index 31008db..066eca1 100644 --- a/test/test_settings_8.res +++ b/test/test_settings_8.res @@ -1,17 +1,15 @@ OK z3950.indexdata.com/marc -Target name +1 0 0 0 Client_Idle - - - + + - - + \ No newline at end of file diff --git a/test/test_settings_urls b/test/test_settings_urls index 5f7a967..bd7de1c 100644 --- a/test/test_settings_urls +++ b/test/test_settings_urls @@ -2,7 +2,7 @@ http://localhost:9763/search.pz2?command=init http://localhost:9763/search.pz2?command=init&clear=1 http://localhost:9763/search.pz2?session=1&command=settings&category%5Bz3950.indexdata.com%2Fmarc%5D=1 http://localhost:9763/search.pz2?session=1&command=search&query=water -http://localhost:9763/search.pz2?session=2&command=settings&category%5Bz3950.indexdata.com%2Fmarc%5D=1&pz:cclmap:term%5Bz3950.indexdata.com%2Fmarc%5D=u%3D1016&pz:elements%5Bz3950.indexdata.com%2Fmarc%5D=F +http://localhost:9763/search.pz2?session=2&command=settings&pz:name%5Bz3950.indexdata.com%2Fmarc%5D=1&pz:cclmap:term%5Bz3950.indexdata.com%2Fmarc%5D=u%3D1016&pz:elements%5Bz3950.indexdata.com%2Fmarc%5D=F http://localhost:9763/search.pz2?session=2&command=search&query=water 2 http://localhost:9763/search.pz2?session=1&command=bytarget&settings=1 http://localhost:9763/search.pz2?session=2&command=bytarget&settings=1