summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-10-27 17:37:01 +0000
committerNick Mathewson <nickm@torproject.org>2004-10-27 17:37:01 +0000
commitc5eb95b644284f3fc40d65e305386b84f65b92a2 (patch)
treeac1f54c0b9e714c86f63111afe44257dc6abfa4a /src/or
parent75ad4615d1c77639c38764065ddf91932e90f263 (diff)
downloadtor-c5eb95b644284f3fc40d65e305386b84f65b92a2.tar.gz
tor-c5eb95b644284f3fc40d65e305386b84f65b92a2.zip
Add ability for some-but-not-all abbrevs to work in config file. Add a bunch of singular/plural abbrevs suggested by arma
svn:r2612
Diffstat (limited to 'src/or')
-rw-r--r--src/or/config.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/or/config.c b/src/or/config.c
index 9811371d99..c4dcf780ff 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -30,13 +30,27 @@ typedef enum config_type_t {
typedef struct config_abbrev_t {
char *abbreviated;
char *full;
+ int commandline_only;
} 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 }
+
/* A list of command-line abbreviations. */
static config_abbrev_t config_abbrevs[] = {
- { "l", "LogLevel" },
+ PLURAL(ExitNode),
+ PLURAL(EntryNodes),
+ PLURAL(ExcludeNode),
+ PLURAL(FirewallPort),
+ PLURAL(HiddenServiceNode),
+ PLURAL(HiddenServiceExcludeNode),
+ PLURAL(RendNode),
+ PLURAL(RendExcludeNode),
+ { "l", "LogLevel" , 1},
{ NULL, NULL },
};
+#undef PLURAL
/* A variable allowed in the configuration file or on the command line */
typedef struct config_var_t {
@@ -135,19 +149,23 @@ static int config_assign(or_options_t *options, struct config_line_t *list);
static int parse_dir_server_line(const char *line);
static int parse_redirect_line(or_options_t *options,
struct config_line_t *line);
-static const char *expand_abbrev(const char *option);
+static const char *expand_abbrev(const char *option, int commandline_only);
static config_var_t *config_find_option(const char *key);
/** If <b>option</b> is an official abbreviation for a longer option,
- * return the longer option. Otherwise return <b>option</b> */
+ * 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. */
static const char *
-expand_abbrev(const char *option)
+expand_abbrev(const char *option, int command_line)
{
int i;
for (i=0; config_abbrevs[i].abbreviated; ++i) {
/* Abbreviations aren't casei. */
- if (!strcmp(option,config_abbrevs[i].abbreviated))
+ if (!strcmp(option,config_abbrevs[i].abbreviated) &&
+ (command_line || !config_abbrevs[i].commandline_only)) {
return config_abbrevs[i].full;
+ }
}
return option;
}
@@ -174,7 +192,7 @@ config_get_commandlines(int argc, char **argv)
while(*s == '-')
s++;
- new->key = tor_strdup(expand_abbrev(s));
+ new->key = tor_strdup(expand_abbrev(s, 1));
new->value = tor_strdup(argv[i+1]);
log(LOG_DEBUG,"Commandline: parsed keyword '%s', value '%s'",
@@ -354,6 +372,12 @@ static int
config_assign(or_options_t *options, struct config_line_t *list)
{
while (list) {
+ const char *full = expand_abbrev(list->key, 0);
+ if (strcmp(full,list->key)) {
+ tor_free(list->key);
+ list->key = tor_strdup(full);
+ }
+
if (config_assign_line(options, list))
return -1;
list = list->next;