[or-cvs] Add ability to warn when using abbrev mechanism to deprecat...

Nick Mathewson nickm at seul.org
Mon Oct 17 03:06:02 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv28374/src/or

Modified Files:
	config.c 
Log Message:
Add ability to warn when using abbrev mechanism to deprecate option names

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.437
retrieving revision 1.438
diff -u -d -r1.437 -r1.438
--- config.c	17 Oct 2005 00:35:53 -0000	1.437
+++ config.c	17 Oct 2005 03:06:00 -0000	1.438
@@ -41,11 +41,12 @@
   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 @@
   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 @@
 /** 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 @@
     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 @@
 
   /* 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);



More information about the tor-commits mailing list