From 9417e1a3cc1e271731a15af771234f92da8d2646 Mon Sep 17 00:00:00 2001 Message-Id: <9417e1a3cc1e271731a15af771234f92da8d2646.1715321037.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 12 Apr 2009 20:38:48 +0100 Subject: [PATCH] Check namepart/stopword don't change across reload. Organization: Straylight/Edgeware From: Richard Kettlewell --- README.reload | 7 ++--- lib/configuration.c | 70 +++++++++++++++++++++++++++++++++++++++++++-- lib/configuration.h | 3 +- 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/README.reload b/README.reload index 6c645ec..23fad2c 100644 --- a/README.reload +++ b/README.reload @@ -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. -** namepart +** namepart (enforced at reload only) 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) diff --git a/lib/configuration.c b/lib/configuration.c index dd08949..98f5fbf 100644 --- a/lib/configuration.c +++ b/lib/configuration.c @@ -109,6 +109,11 @@ struct conftype { /** @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) { @@ -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[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; @@ -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. */ + xfree(np->res); 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 */ } - /* 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; @@ -1447,6 +1460,59 @@ char *config_get_file(const char *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 diff --git a/lib/configuration.h b/lib/configuration.h index e9fce73..875b9d6 100644 --- a/lib/configuration.h +++ b/lib/configuration.h @@ -70,7 +70,8 @@ struct collectionlist { 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 */ -- [mdw]