-// $Id: settings.c,v 1.3 2007-03-29 13:44:19 quinn Exp $
+// $Id: settings.c,v 1.5 2007-03-31 19:55:25 marc Exp $
// This module implements a generic system of settings (attribute-value) that can
// be associated with search targets. The system supports both default values,
// per-target overrides, and per-user settings.
-//
#include <string.h>
#include <stdio.h>
static char *hard_settings[] = {
"pz:piggyback",
"pz:elements",
- "pz::syntax",
+ "pz:syntax",
+ "pz:cclmap:",
0
};
return -1;
}
+// Ignores everything after second colon, if present
+// A bit of a hack to support the pz:cclmap: scheme (and more to come?)
+static int settings_offset_cprefix(const char *name)
+{
+ const char *p;
+ int maxlen = 100;
+ int i;
+
+ if (!strncmp("pz:", name, 3) && (p = strchr(name + 3, ':')))
+ maxlen = (p - name) + 1;
+ for (i = 0; i < dictionary->num; i++)
+ if (!strncmp(name, dictionary->dict[i], maxlen))
+ return i;
+ return -1;
+}
+
char *settings_name(int offset)
{
return dictionary->dict[offset];
{
if (n->type != XML_ELEMENT_NODE)
continue;
- if (!strcmp(n->name, (xmlChar *) "set"))
+ if (!strcmp((const char *) n->name, "set"))
{
char *name, *target, *value, *user, *precedence;
- name = xmlGetProp(n, (xmlChar *) "name");
- target = xmlGetProp(n, (xmlChar *) "target");
- value = xmlGetProp(n, (xmlChar *) "value");
- user = xmlGetProp(n, (xmlChar *) "user");
- precedence = xmlGetProp(n, (xmlChar *) "precedence");
+ name = (char *) xmlGetProp(n, (xmlChar *) "name");
+ target = (char *) xmlGetProp(n, (xmlChar *) "target");
+ value = (char *) xmlGetProp(n, (xmlChar *) "value");
+ user = (char *) xmlGetProp(n, (xmlChar *) "user");
+ precedence = (char *) xmlGetProp(n, (xmlChar *) "precedence");
if ((!name && !namea) || (!value && !valuea) || (!target && !targeta))
{
if (user)
strcpy(userb, user);
else if (usera)
- strcpy(userb, usera);
+ strcpy(userb, (const char *) usera);
else
set.user = "";
if (target)
strcpy(targetb, target);
else
- strcpy(targetb, targeta);
+ strcpy(targetb, (const char *) targeta);
set.target = targetb;
if (name)
strcpy(nameb, name);
else
- strcpy(nameb, namea);
+ strcpy(nameb, (const char *) namea);
set.name = nameb;
if (value)
strcpy(valueb, value);
else
- strcpy(valueb, valuea);
+ strcpy(valueb, (const char *) valuea);
set.value = valueb;
set.next = 0;
(*fun)(&set);
static void prepare_dictionary(struct setting *set)
{
int i;
+ char *p;
+ 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 (!db->settings)
{
db->settings = nmem_malloc(nmem, sizeof(struct settings*) * dictionary->num);
- memset(db->settings, sizeof(struct settings*) * dictionary->num, 0);
+ memset(db->settings, 0, sizeof(struct settings*) * dictionary->num);
}
- if ((offset = settings_offset(set->name)) < 0)
+ if ((offset = settings_offset_cprefix(set->name)) < 0)
abort(); // Should never get here
// First we determine if this setting is overriding any existing settings
// with the same name.
for (s = db->settings[offset], sp = &db->settings[offset]; s;
sp = &s->next, s = s->next)
- if (!strcmp(s->user, set->user))
+ if (!strcmp(s->user, set->user) && !strcmp(s->name, set->name))
{
if (s->precedence < set->precedence)
// We discard the value (nmem keeps track of the space)
{
struct setting *new = nmem_malloc(nmem, sizeof(*new));
- memset(new, sizeof(*new), 0);
+ memset(new, 0, sizeof(*new));
new->precedence = set->precedence;
new->target = nmem_strdup(nmem, set->target);
new->name = nmem_strdup(nmem, set->name);
else
nmem_reset(nmem);
new = nmem_malloc(nmem, sizeof(*new));
+ memset(new, 0, sizeof(*new));
initialize_hard_settings(new);
- memset(new, sizeof(*new), 0);
dictionary = new;
read_settings(path, prepare_dictionary);
read_settings(path, update_databases);