summaryrefslogtreecommitdiff
path: root/src/or/config.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-03-17 02:27:19 +0000
committerNick Mathewson <nickm@torproject.org>2003-03-17 02:27:19 +0000
commit5dc443a8c55688637e71f984c76b45ba1515fb71 (patch)
tree7edb6ae934c3c5cab20b12e1de10464405b6ceb4 /src/or/config.c
parent9f0e93e7161797caa197c372d6d93e7297ae1a5b (diff)
downloadtor-5dc443a8c55688637e71f984c76b45ba1515fb71.tar.gz
tor-5dc443a8c55688637e71f984c76b45ba1515fb71.zip
Add daemon option and bool config type
svn:r184
Diffstat (limited to 'src/or/config.c')
-rw-r--r--src/or/config.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/or/config.c b/src/or/config.c
index fdd9380e67..f69d7ea4c5 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -134,6 +134,7 @@ void config_free_lines(struct config_line *front) {
}
int config_compare(struct config_line *c, char *key, int type, void *arg) {
+ int i;
if(strncasecmp(c->key,key,strlen(c->key)))
return 0;
@@ -145,6 +146,14 @@ int config_compare(struct config_line *c, char *key, int type, void *arg) {
case CONFIG_TYPE_INT:
*(int *)arg = atoi(c->value);
break;
+ case CONFIG_TYPE_BOOL:
+ i = atoi(c->value);
+ if (i != 0 && i != 1) {
+ log(LOG_ERR, "Boolean keyword '%s' expects 0 or 1", c->key);
+ return 0;
+ }
+ *(int *)arg = i;
+ break;
case CONFIG_TYPE_STRING:
*(char **)arg = strdup(c->value);
break;
@@ -176,13 +185,15 @@ void config_assign(or_options_t *options, struct config_line *list) {
config_compare(list, "OPPort", CONFIG_TYPE_INT, &options->OPPort) ||
config_compare(list, "ORPort", CONFIG_TYPE_INT, &options->ORPort) ||
config_compare(list, "DirPort", CONFIG_TYPE_INT, &options->DirPort) ||
- config_compare(list, "TrafficShaping", CONFIG_TYPE_INT, &options->TrafficShaping) ||
- config_compare(list, "LinkPadding", CONFIG_TYPE_INT, &options->LinkPadding) ||
config_compare(list, "DirRebuildPeriod",CONFIG_TYPE_INT, &options->DirRebuildPeriod) ||
config_compare(list, "DirFetchPeriod", CONFIG_TYPE_INT, &options->DirFetchPeriod) ||
config_compare(list, "KeepalivePeriod", CONFIG_TYPE_INT, &options->KeepalivePeriod) ||
config_compare(list, "MaxOnionsPending",CONFIG_TYPE_INT, &options->MaxOnionsPending) ||
+ config_compare(list, "Daemon", CONFIG_TYPE_BOOL, &options->Daemon) ||
+ config_compare(list, "TrafficShaping", CONFIG_TYPE_BOOL, &options->TrafficShaping) ||
+ config_compare(list, "LinkPadding", CONFIG_TYPE_BOOL, &options->LinkPadding) ||
+
/* float options */
config_compare(list, "CoinWeight", CONFIG_TYPE_DOUBLE, &options->CoinWeight)
@@ -207,6 +218,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
/* give reasonable defaults for each option */
memset(options,0,sizeof(or_options_t));
+ options->Daemon = 0;
options->LogLevel = "debug";
options->loglevel = LOG_DEBUG;
options->CoinWeight = 0.8;
@@ -276,6 +288,7 @@ int getconfig(int argc, char **argv, or_options_t *options) {
options->DirRebuildPeriod,
options->DirFetchPeriod,
options->KeepalivePeriod);
+ printf("Daemon=%d", options->Daemon);
}
/* Validate options */
@@ -354,6 +367,11 @@ int getconfig(int argc, char **argv, or_options_t *options) {
result = -1;
}
+ if(options->Daemon != 0 && options->Daemon != 1) {
+ log(LOG_ERR,"TrafficShaping option must be either 0 or 1.");
+ result = -1;
+ }
+
if(options->TrafficShaping != 0 && options->TrafficShaping != 1) {
log(LOG_ERR,"TrafficShaping option must be either 0 or 1.");
result = -1;