From: Wouter Wijngaards Date: Mon, 18 Jun 2007 15:24:14 +0000 (+0000) Subject: target fetch policy setting from config structure. X-Git-Tag: release-0.4~72 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5543bd63b69b8d44164eb48c6b9e5cc7c4a90981;p=thirdparty%2Funbound.git target fetch policy setting from config structure. git-svn-id: file:///svn/unbound/trunk@394 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/iterator/iter_utils.c b/iterator/iter_utils.c index 6a0234f48..d728cf031 100644 --- a/iterator/iter_utils.c +++ b/iterator/iter_utils.c @@ -55,20 +55,71 @@ #include "util/data/msgparse.h" #include "util/random.h" +/** count number of integers in fetch policy string */ +static int +fetch_count(const char* s) +{ + /* format ::= (sp num)+ sp */ + /* num ::= [-](0-9)+ */ + /* sp ::= (space|tab)* */ + int num = 0; + while(*s) { + while(*s && isspace(*s)) + s++; + if(!*s) /* end of string */ + break; + if(*s == '-') + s++; + if(!*s) /* only - not allowed */ + return 0; + if(!isdigit(*s)) /* bad character */ + return 0; + while(*s && isdigit(*s)) + s++; + num++; + } + return num; +} + +/** fillup fetch policy array */ +static void +fetch_fill(struct iter_env* ie, const char* str) +{ + char* s = (char*)str, *e; + int i; + for(i=0; imax_dependency_depth+1; i++) { + ie->target_fetch_policy[i] = strtol(s, &e, 10); + log_assert(s != e); /* parsed syntax already */ + s = e; + } +} + +/** Read config string that represents the target fetch policy */ +static int +read_fetch_policy(struct iter_env* ie, const char* str) +{ + int count = fetch_count(str); + if(count < 1) { + log_err("Cannot parse target fetch policy: \"%s\"", str); + return 0; + } + ie->max_dependency_depth = count - 1; + ie->target_fetch_policy = (int*)calloc( + (size_t)ie->max_dependency_depth+1, sizeof(int)); + if(!ie->target_fetch_policy) { + log_err("alloc fetch policy: out of memory"); + return 0; + } + fetch_fill(ie, str); + return 1; +} + int iter_apply_cfg(struct iter_env* iter_env, struct config_file* cfg) { int i; /* target fetch policy */ - iter_env->max_dependency_depth = 4; - iter_env->target_fetch_policy = (int*)calloc( - (size_t)iter_env->max_dependency_depth+1, sizeof(int)); - if(iter_env->max_dependency_depth >= 1) - iter_env->target_fetch_policy[1] = 3; - if(iter_env->max_dependency_depth >= 2) - iter_env->target_fetch_policy[2] = 1; - /* TODO read setting from config */ - if(!iter_env->target_fetch_policy) + if(!read_fetch_policy(iter_env, cfg->target_fetch_policy)) return 0; for(i=0; imax_dependency_depth+1; i++) verbose(VERB_DETAIL, "target fetch policy for level %d is %d", diff --git a/util/config_file.c b/util/config_file.c index 7e7aa1c69..cf23a906e 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -94,6 +94,7 @@ config_create() if(!(cfg->directory = strdup("/etc/unbound"))) goto error_exit; if(!(cfg->logfile = strdup(""))) goto error_exit; if(!(cfg->pidfile = strdup("unbound.pid"))) goto error_exit; + if(!(cfg->target_fetch_policy = strdup("3 2 1 0 0"))) goto error_exit; cfg->fwd_port = UNBOUND_DNS_PORT; cfg->do_daemonize = 1; cfg->num_ifs = 0; @@ -165,6 +166,7 @@ config_delete(struct config_file* cfg) free(cfg->directory); free(cfg->logfile); free(cfg->pidfile); + free(cfg->target_fetch_policy); if(cfg->ifs) { int i; for(i=0; inum_ifs; i++) diff --git a/util/config_file.h b/util/config_file.h index ecb12dc19..866fd3cd4 100644 --- a/util/config_file.h +++ b/util/config_file.h @@ -99,6 +99,9 @@ struct config_file { /** forwarder port */ int fwd_port; + /** the target fetch policy for the iterator */ + char* target_fetch_policy; + /** number of interfaces to open. If 0 default all interfaces. */ int num_ifs; /** interface description strings (IP addresses) */