+// This establishes the precedence of wildcard expressions
+#define SETTING_WILDCARD_NO 0 // No wildcard
+#define SETTING_WILDCARD_DB 1 // Database wildcard 'host:port/*'
+#define SETTING_WILDCARD_YES 2 // Complete wildcard '*'
+
+// Returns size of settings directory
+int settings_num(struct conf_service *service)
+{
+ return service->dictionary->num;
+}
+
+/* Find and possible create a new dictionary entry. Pass valid NMEM pointer if creation is allowed, otherwise null */
+static int settings_index_lookup(struct setting_dictionary *dictionary, const char *name, NMEM nmem)
+{
+ size_t maxlen;
+ int i;
+ const char *p;
+
+ assert(name);
+
+ if (!strncmp("pz:", name, 3) && (p = strchr(name + 3, ':')))
+ maxlen = (p - name) + 1;
+ else
+ maxlen = strlen(name) + 1;
+ for (i = 0; i < dictionary->num; i++)
+ if (!strncmp(name, dictionary->dict[i], maxlen))
+ return i;
+ if (!nmem)
+ return -1;
+ if (!strncmp("pz:", name, 3))
+ yaz_log(YLOG_WARN, "Adding pz-type setting name %s", name);
+ if (dictionary->num + 1 > dictionary->size)
+ {
+ char **tmp =
+ nmem_malloc(nmem, dictionary->size * 2 * sizeof(char*));
+ memcpy(tmp, dictionary->dict, dictionary->size * sizeof(char*));
+ dictionary->dict = tmp;
+ dictionary->size *= 2;
+ }
+ dictionary->dict[dictionary->num] = nmem_strdup(nmem, name);
+ dictionary->dict[dictionary->num][maxlen-1] = '\0';
+ return dictionary->num++;
+}
+
+int settings_create_offset(struct conf_service *service, const char *name)
+{
+ return settings_index_lookup(service->dictionary, name, service->nmem);
+}
+
+int settings_lookup_offset(struct conf_service *service, const char *name)
+{
+ return settings_index_lookup(service->dictionary, name, 0);
+}
+
+char *settings_name(struct conf_service *service, int offset)
+{
+ assert(offset < service->dictionary->num);
+ return service->dictionary->dict[offset];
+}
+
+
+// Apply a session override to a database
+void service_apply_setting(struct conf_service *service, char *setting, char *value)
+{
+ struct setting *new = nmem_malloc(service->nmem, sizeof(*new));
+ int offset = settings_create_offset(service, setting);
+ expand_settings_array(&service->settings->settings, &service->settings->num_settings, offset, service->nmem);
+ new->precedence = 0;
+ new->target = NULL;
+ new->name = setting;
+ new->value = value;
+ new->next = service->settings->settings[offset];
+ service->settings->settings[offset] = new;
+}
+
+