chiark / gitweb /
Check namepart/stopword don't change across reload.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 12 Apr 2009 19:38:48 +0000 (20:38 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 12 Apr 2009 19:38:48 +0000 (20:38 +0100)
README.reload
lib/configuration.c
lib/configuration.h

index 6c645ec81188411f028f310ea1c87907dfb113f2..23fad2c6f72a33a4e7ffe8efaa8042a969b4c2b8 100644 (file)
@@ -18,14 +18,13 @@ bug!
 This defines how aliases are inserted into the track database.  Need
 to think about how changing it will affect things.
 
 This defines how aliases are inserted into the track database.  Need
 to think about how changing it will affect things.
 
-** namepart
+** namepart (enforced at reload only)
 
 Probably affects alias construction.
 
 
 Probably affects alias construction.
 
-** stopword
+** stopword (enforced at reload only)
 
 
-The search database will have to be rebuilt from scratch.  This is
-do-able but AFAIK we don't detect it.
+The search database will have to be rebuilt from scratch.
 
 ** user (enforced at reload only)
 
 
 ** user (enforced at reload only)
 
index dd089491ce423b9b31eacfb4d997de14e760c515..98f5fbfd8f582cb1d1ee521cf0b66c942ff6fc7f 100644 (file)
@@ -109,6 +109,11 @@ struct conftype {
 /** @brief Return the value of an item */
 #define VALUE(C, TYPE) (*ADDRESS(C, TYPE))
 
 /** @brief Return the value of an item */
 #define VALUE(C, TYPE) (*ADDRESS(C, TYPE))
 
+static int stringlist_compare(const struct stringlist *a,
+                              const struct stringlist *b);
+static int namepartlist_compare(const struct namepartlist *a,
+                                const struct namepartlist *b);
+
 static int set_signal(const struct config_state *cs,
                      const struct conf *whoami,
                      int nvec, char **vec) {
 static int set_signal(const struct config_state *cs,
                      const struct conf *whoami,
                      int nvec, char **vec) {
@@ -420,6 +425,7 @@ static int set_namepart(const struct config_state *cs,
   npl->s = xrealloc(npl->s, (npl->n + 1) * sizeof (struct namepart));
   npl->s[npl->n].part = xstrdup(vec[0]);
   npl->s[npl->n].re = re;
   npl->s = xrealloc(npl->s, (npl->n + 1) * sizeof (struct namepart));
   npl->s[npl->n].part = xstrdup(vec[0]);
   npl->s[npl->n].re = re;
+  npl->s[npl->n].res = xstrdup(vec[1]);
   npl->s[npl->n].replace = xstrdup(vec[2]);
   npl->s[npl->n].context = xstrdup(vec[3]);
   npl->s[npl->n].reflags = reflags;
   npl->s[npl->n].replace = xstrdup(vec[2]);
   npl->s[npl->n].context = xstrdup(vec[3]);
   npl->s[npl->n].reflags = reflags;
@@ -563,6 +569,7 @@ static void free_namepartlist(struct config *c,
     np = &npl->s[n];
     xfree(np->part);
     pcre_free(np->re);                 /* ...whatever pcre_free is set to. */
     np = &npl->s[n];
     xfree(np->part);
     pcre_free(np->re);                 /* ...whatever pcre_free is set to. */
+    xfree(np->res);
     xfree(np->replace);
     xfree(np->context);
   }
     xfree(np->replace);
     xfree(np->context);
   }
@@ -1386,8 +1393,14 @@ int config_read(int server,
       error(0, "'nice_speaker' cannot be changed without a restart");
       /* ...but we accept the new config anyway */
     }
       error(0, "'nice_speaker' cannot be changed without a restart");
       /* ...but we accept the new config anyway */
     }
-    /* TODO namepart */
-    /* TODO stopword */
+    if(namepartlist_compare(&c->namepart, &oldconfig->namepart)) {
+      error(0, "'namepart' settings cannot be changed without a restart");
+      failed = 1;
+    }
+    if(stringlist_compare(&c->stopword, &oldconfig->stopword)) {
+      error(0, "'stopword' settings cannot be changed without a restart");
+      failed = 1;
+    }
     if(failed) {
       error(0, "not installing incompatible new configuration");
       return -1;
     if(failed) {
       error(0, "not installing incompatible new configuration");
       return -1;
@@ -1447,6 +1460,59 @@ char *config_get_file(const char *name) {
   return config_get_file2(config, name);
 }
 
   return config_get_file2(config, name);
 }
 
+static int stringlist_compare(const struct stringlist *a,
+                              const struct stringlist *b) {
+  int n, c;
+
+  while(n < a->n && n < b->n) {
+    if((c = strcmp(a->s[n], b->s[n])))
+      return c;
+    ++n;
+  }
+  if(a->n < b->n)
+    return -1;
+  else if(a->n > b->n)
+    return 1;
+  else
+    return 0;
+}
+
+static int namepart_compare(const struct namepart *a,
+                            const struct namepart *b) {
+  int c;
+
+  if((c = strcmp(a->part, b->part)))
+    return c;
+  if((c = strcmp(a->res, b->res)))
+    return c;
+  if((c = strcmp(a->replace, b->replace)))
+    return c;
+  if((c = strcmp(a->context, b->context)))
+    return c;
+  if(a->reflags > b->reflags)
+    return 1;
+  if(a->reflags < b->reflags)
+    return -1;
+  return 0;
+}
+
+static int namepartlist_compare(const struct namepartlist *a,
+                                const struct namepartlist *b) {
+  int n, c;
+
+  while(n < a->n && n < b->n) {
+    if((c = namepart_compare(&a->s[n], &b->s[n])))
+      return c;
+    ++n;
+  }
+  if(a->n > b->n)
+    return 1;
+  else if(a->n < b->n)
+    return -1;
+  else
+    return 0;
+}
+
 /*
 Local Variables:
 c-basic-offset:2
 /*
 Local Variables:
 c-basic-offset:2
index e9fce7359a48da7aa409a7e4169e32a2f879f78c..875b9d627851d3573d05868bc8864ebfe243ed06 100644 (file)
@@ -70,7 +70,8 @@ struct collectionlist {
 
 struct namepart {
   char *part;                          /* part */
 
 struct namepart {
   char *part;                          /* part */
-  pcre *re;                            /* regexp */
+  pcre *re;                            /* compiled regexp */
+  char *res;                            /* regexp as a string */
   char *replace;                       /* replacement string */
   char *context;                       /* context glob */
   unsigned reflags;                    /* regexp flags */
   char *replace;                       /* replacement string */
   char *context;                       /* context glob */
   unsigned reflags;                    /* regexp flags */