Fix bug #3260 (dynamic/static settings mixed)
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 11 Feb 2010 13:52:07 +0000 (14:52 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 11 Feb 2010 13:52:07 +0000 (14:52 +0100)
src/database.c
src/database.h
src/http_command.c
src/logic.c
test/test_http_urls
test/test_settings_8.res
test/test_settings_urls

index fa531b5..c2fb3b1 100644 (file)
@@ -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;
 
index 1d73161..cf12e9d 100644 (file)
@@ -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
index b98cd31..bfc101e 100644 (file)
@@ -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;
 }
index 0180c27..28929de 100644 (file)
@@ -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;
 }
index 93cf534..2ef6c62 100644 (file)
@@ -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
index 31008db..066eca1 100644 (file)
@@ -1,17 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <bytarget><status>OK</status>
 <target><id>z3950.indexdata.com/marc</id>
-<name>Target name</name>
+<name>1</name>
 <hits>0</hits>
 <diagnostic>0</diagnostic>
 <records>0</records>
 <state>Client_Idle</state>
 <settings>
-<set name="pz:elements" value="F"/><set name="pz:elements" value="F"/>
-<set name="pz:requestsyntax" value="marc21"/>
-<set name="pz:cclmap:term" value="u=1016"/><set name="pz:cclmap:term" value="u=host_wildcard"/>
+<set name="pz:elements" value="F"/>
+<set name="pz:cclmap:term" value="u=1016"/>
 <set name="pz:id" value="z3950.indexdata.com/marc"/>
-<set name="pz:name" value="Target name"/>
-<set name="category" value="1"/>
+<set name="pz:name" value="1"/>
 </settings>
 </target></bytarget>
\ No newline at end of file
index 5f7a967..bd7de1c 100644 (file)
@@ -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