Fix bug #3260 (dynamic/static settings mixed)
[pazpar2-moved-to-github.git] / src / logic.c
index 5e9ed3b..28929de 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of Pazpar2.
-   Copyright (C) 2006-2009 Index Data
+   Copyright (C) 2006-2010 Index Data
 
 Pazpar2 is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -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;
 }
@@ -808,17 +812,23 @@ void statistics(struct session *se, struct statistics *stat)
 
 
 // Master list of connections we're handling events to
-static IOCHAN channel_list = 0;  /* thread pr */
+static iochan_man_t pazpar2_chan_man = 0; /* thread pr */
+
+void pazpar2_chan_man_start(int no_threads)
+{
+    pazpar2_chan_man = iochan_man_create(no_threads);
+}
 
 void pazpar2_add_channel(IOCHAN chan)
 {
-    chan->next = channel_list;
-    channel_list = chan;
+    assert(pazpar2_chan_man);
+    iochan_add(pazpar2_chan_man, chan);
 }
 
 void pazpar2_event_loop()
 {
-    event_loop(&channel_list);
+    assert(pazpar2_chan_man);
+    iochan_man_events(pazpar2_chan_man);
 }
 
 static struct record_metadata *record_metadata_init(