summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-10-17 03:06:00 +0000
committerNick Mathewson <nickm@torproject.org>2005-10-17 03:06:00 +0000
commit22c72bd9c5117dba89cedca28a7809393c20fd78 (patch)
tree83ddefcfce454c1cc6378dbf70471a949d5679b6
parent435fb973c27c95fe254f4ffeb253526ce5c5a922 (diff)
downloadtor-22c72bd9c5117dba89cedca28a7809393c20fd78.tar.gz
tor-22c72bd9c5117dba89cedca28a7809393c20fd78.zip
Add ability to warn when using abbrev mechanism to deprecate option names
svn:r5259
-rw-r--r--src/or/config.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/or/config.c b/src/or/config.c
index c33bebce0f..3735a04679 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -41,11 +41,12 @@ typedef struct config_abbrev_t {
const char *abbreviated;
const char *full;
int commandline_only;
+ int warn;
} config_abbrev_t;
/* Handy macro for declaring "In the config file or on the command line,
* you can abbreviate <b>tok</b>s as <b>tok</b>". */
-#define PLURAL(tok) { #tok, #tok "s", 0 }
+#define PLURAL(tok) { #tok, #tok "s", 0, 0 }
/* A list of command-line abbreviations. */
static config_abbrev_t _option_abbrevs[] = {
@@ -62,11 +63,11 @@ static config_abbrev_t _option_abbrevs[] = {
PLURAL(StrictEntryNode),
PLURAL(StrictExitNode),
{ "l", "Log", 1},
- { "BandwidthRateBytes", "BandwidthRate", 0},
- { "BandwidthBurstBytes", "BandwidthBurst", 0},
- { "DirFetchPostPeriod", "StatusFetchPeriod", 0},
- { "MaxConn", "ConnLimit", 0},
- { NULL, NULL , 0},
+ { "BandwidthRateBytes", "BandwidthRate", 0, 0},
+ { "BandwidthBurstBytes", "BandwidthBurst", 0, 0},
+ { "DirFetchPostPeriod", "StatusFetchPeriod", 0, 0},
+ { "MaxConn", "ConnLimit", 0, 1},
+ { NULL, NULL, 0, 0},
};
#undef PLURAL
@@ -662,17 +663,25 @@ options_act(or_options_t *old_options)
/** If <b>option</b> is an official abbreviation for a longer option,
* return the longer option. Otherwise return <b>option</b>.
* If <b>command_line</b> is set, apply all abbreviations. Otherwise, only
- * apply abbreviations that work for the config file and the command line. */
+ * apply abbreviations that work for the config file and the command line.
+ * If <b>warn_obsolete</b> is set, warn about deprecated names. */
static const char *
-expand_abbrev(config_format_t *fmt, const char *option, int command_line)
+expand_abbrev(config_format_t *fmt, const char *option, int command_line,
+ int warn_obsolete)
{
int i;
if (! fmt->abbrevs)
return option;
for (i=0; fmt->abbrevs[i].abbreviated; ++i) {
- /* Abbreviations aren't casei. */
+ /* Abbreviations are casei. */
if (!strcasecmp(option,fmt->abbrevs[i].abbreviated) &&
(command_line || !fmt->abbrevs[i].commandline_only)) {
+ if (warn_obsolete && fmt->abbrevs[i].warn) {
+ log_fn(LOG_WARN,
+ "The configuration option '%s' is deprecated; use '%s' instead.",
+ fmt->abbrevs[i].abbreviated,
+ fmt->abbrevs[i].full);
+ }
return fmt->abbrevs[i].full;
}
}
@@ -715,7 +724,7 @@ config_get_commandlines(int argc, char **argv, config_line_t **result)
while (*s == '-')
s++;
- (*new)->key = tor_strdup(expand_abbrev(&options_format, s, 1));
+ (*new)->key = tor_strdup(expand_abbrev(&options_format, s, 1, 1));
(*new)->value = tor_strdup(argv[i+1]);
(*new)->next = NULL;
log(LOG_DEBUG,"Commandline: parsed keyword '%s', value '%s'",
@@ -1197,7 +1206,7 @@ config_assign(config_format_t *fmt, void *options,
/* pass 1: normalize keys */
for (p = list; p; p = p->next) {
- const char *full = expand_abbrev(fmt, p->key, 0);
+ const char *full = expand_abbrev(fmt, p->key, 0, 1);
if (strcmp(full,p->key)) {
tor_free(p->key);
p->key = tor_strdup(full);