int setting;
if (md->setting == Metadata_setting_parameter &&
- (setting = settings_offset(service, md->name)) > 0)
+ (setting = settings_lookup_offset(service, md->name)) >= 0)
{
const char *val = session_setting_oneval(sdb, setting);
if (val && nparms < MAX_XSLT_ARGS)
int offset;
if (md->setting == Metadata_setting_postproc &&
- (offset = settings_offset(service, md->name)) > 0)
+ (offset = settings_lookup_offset(service, md->name)) >= 0)
{
const char *val = session_setting_oneval(sdb, offset);
if (val)
{
if (db->settings)
{
- struct conf_service *service = se->service;
- int i, num = settings_num(service);
+ int i, num = db->num_settings;
for (i = 0; i < num; i++)
{
struct setting *s = db->settings[i];
- for (;s; s = s->next)
+ for (;s ; s = s->next)
{
wrbuf_puts(w, "<set name=\"");
wrbuf_xmlputs(w, s->name);
wrbuf_puts(w, "\" value=\"");
wrbuf_xmlputs(w, s->value);
- wrbuf_puts(w, "\"/>\n");
+ wrbuf_puts(w, "\"/>");
}
+ if (db->settings[i])
+ wrbuf_puts(w, "\n");
}
}
}
static void session_init_databases_fun(void *context, struct database *db)
{
struct session *se = (struct session *) context;
- struct conf_service *service = se->service;
struct session_database *new = nmem_malloc(se->session_nmem, sizeof(*new));
- int num = settings_num(service);
int i;
new->database = db;
new->map = 0;
- new->settings
- = nmem_malloc(se->session_nmem, sizeof(struct settings *) * num);
- memset(new->settings, 0, sizeof(struct settings*) * num);
-
- if (db->settings)
- {
- for (i = 0; i < num; i++)
- new->settings[i] = db->settings[i];
- }
+ assert(db->settings);
+ new->settings = nmem_malloc(se->session_nmem,
+ 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];
new->next = se->databases;
se->databases = new;
}
struct session_database *sdb = find_session_database(se, dbname);
struct conf_service *service = se->service;
struct setting *new = nmem_malloc(se->session_nmem, sizeof(*new));
- int offset = settings_offset_cprefix(service, setting);
+ int offset = settings_create_offset(service, setting);
- if (offset < 0)
- {
- yaz_log(YLOG_WARN, "Unknown setting %s", setting);
- return;
- }
- // Jakub: This breaks the filter setting.
- /*if (offset == PZ_ID)
- {
- yaz_log(YLOG_WARN, "No need to set pz:id setting. Ignoring");
- return;
- }*/
+ expand_settings_array(&sdb->settings, &sdb->num_settings, offset,
+ se->session_nmem);
new->precedence = 0;
new->target = dbname;
new->name = setting;
return service->dictionary->num;
}
-int settings_offset(struct conf_service *service, const char *name)
+static int settings_lookup(struct conf_service *service, const char *name,
+ int allow_create)
{
+ size_t maxlen;
int i;
+ const char *p;
+ struct setting_dictionary *dictionary = service->dictionary;
+
+ assert(name);
- if (!name)
- name = "";
- for (i = 0; i < service->dictionary->num; i++)
- if (!strcmp(name, service->dictionary->dict[i]))
+ 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;
- return -1;
+ if (!allow_create)
+ 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(service->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(service->nmem, name);
+ dictionary->dict[dictionary->num][maxlen-1] = '\0';
+ return dictionary->num++;
}
-// Ignores everything after second colon, if present
-// A bit of a hack to support the pz:cclmap: scheme (and more to come?)
-int settings_offset_cprefix(struct conf_service *service, const char *name)
+int settings_create_offset(struct conf_service *service, const char *name)
{
- const char *p;
- int maxlen = 100;
- int i;
+ return settings_lookup(service, name, 1);
+}
- if (!strncmp("pz:", name, 3) && (p = strchr(name + 3, ':')))
- maxlen = (p - name) + 1;
- for (i = 0; i < service->dictionary->num; i++)
- if (!strncmp(name, service->dictionary->dict[i], maxlen))
- return i;
- return -1;
+int settings_lookup_offset(struct conf_service *service, const char *name)
+{
+ return settings_lookup(service, name, 0);
}
char *settings_name(struct conf_service *service, int offset)
{
+ assert(offset < service->dictionary->num);
return service->dictionary->dict[offset];
}
return SETTING_WILDCARD_NO;
}
-// Callback. Adds a new entry to the dictionary if necessary
-// This is used in pass 1 to determine layout of dictionary
-// and to load any databases mentioned
-static void prepare_dictionary(struct conf_service *service,
- struct setting *set)
-{
- struct setting_dictionary *dictionary = service->dictionary;
-
- int i;
- char *p;
-
- // Determine if we already have a dictionary entry
- if (!strncmp(set->name, "pz:", 3) && (p = strchr(set->name + 3, ':')))
- *(p + 1) = '\0';
- for (i = 0; i < dictionary->num; i++)
- if (!strcmp(dictionary->dict[i], set->name))
- return;
-
- if (!strncmp(set->name, "pz:", 3)) // Probably a typo in config file
- {
- yaz_log(YLOG_FATAL, "Unknown pz: setting '%s'", set->name);
- exit(1);
- }
-
- // Create a new dictionary entry
- // Grow dictionary if necessary
- if (!dictionary->size)
- dictionary->dict =
- nmem_malloc(service->nmem, (dictionary->size = 50) * sizeof(char*));
- else if (dictionary->num + 1 > dictionary->size)
- {
- char **tmp =
- nmem_malloc(service->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(service->nmem, set->name);
-}
-
-
struct update_database_context {
struct setting *set;
struct conf_service *service;
};
+void expand_settings_array(struct setting ***set_ar, int *num, int offset,
+ NMEM nmem)
+{
+ assert(offset >= 0);
+ assert(*set_ar);
+ if (offset >= *num)
+ {
+ int i, n_num = offset + 10;
+ struct setting **n_ar = nmem_malloc(nmem, n_num * sizeof(*n_ar));
+ for (i = 0; i < *num; i++)
+ n_ar[i] = (*set_ar)[i];
+ for (; i < n_num; i++)
+ n_ar[i] = 0;
+ *num = n_num;
+ *set_ar = n_ar;
+ }
+}
+
// This is called from grep_databases -- adds/overrides setting for a target
// This is also where the rules for precedence of settings are implemented
static void update_database(void *context, struct database *db)
if (!match_zurl(db->url, set->target))
return;
- if ((offset = settings_offset_cprefix(service, set->name)) < 0)
- return ;
+ offset = settings_create_offset(service, set->name);
+ expand_settings_array(&db->settings, &db->num_settings, offset,
+ service->nmem);
// First we determine if this setting is overriding any existing settings
// with the same name.
for (i = 0; i < service->num_metadata; i++)
{
- struct setting set;
struct conf_metadata *md = &service->metadata[i];
if (md->setting == Metadata_setting_no)
continue;
- set.precedence = 0;
- set.target = "";
- set.name = md->name;
- set.value = "";
- set.next = 0;
- prepare_dictionary(service, &set);
+ settings_create_offset(service, md->name);
}
}