+// Apply a session override to a database
+void session_apply_setting(struct session *se, char *dbname, char *setting, char *value)
+{
+ struct session_database *sdb;
+
+ for (sdb = se->databases; sdb; sdb = sdb->next)
+ if (!strcmp(dbname, sdb->database->url))
+ {
+ struct setting *new = nmem_malloc(se->session_nmem, sizeof(*new));
+ int offset = settings_offset(setting);
+
+ if (offset < 0)
+ {
+ yaz_log(YLOG_WARN, "Unknown setting %s", setting);
+ return;
+ }
+ new->precedence = 0;
+ new->target = dbname;
+ new->name = setting;
+ new->value = value;
+ new->user = "";
+ new->next = sdb->settings[offset];
+ sdb->settings[offset] = new;
+ break;
+ }
+ if (!sdb)
+ yaz_log(YLOG_WARN, "Unknown database in setting override: %s", dbname);
+}
+
+void session_init_databases_fun(void *context, struct database *db)
+{
+ struct session *se = (struct session *) context;
+ struct session_database *new = nmem_malloc(se->session_nmem, sizeof(*new));
+ int num = settings_num();
+ int i;
+
+ new->database = db;
+ new->settings = nmem_malloc(se->session_nmem, sizeof(struct settings *) * num);
+ for (i = 0; i < num; i++)
+ new->settings[i] = db->settings[i];
+ new->next = se->databases;
+ se->databases = new;
+}
+
+// Initialize session_database list -- this represents this session's view
+// of the database list -- subject to modification by the settings ws command
+void session_init_databases(struct session *se)
+{
+ grep_databases(se, 0, session_init_databases_fun);
+}
+