diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-10-14 16:15:41 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-10-14 16:15:41 -0400 |
commit | 83c3f118db0ae3911ea72403856df9fb08b2d0e5 (patch) | |
tree | 9ca6f88f567835462314c426397923996bf8bebb /src/or/networkstatus.c | |
parent | 95008db08d1bb5d7b608654fc1a115a42cd15252 (diff) | |
download | tor-83c3f118db0ae3911ea72403856df9fb08b2d0e5.tar.gz tor-83c3f118db0ae3911ea72403856df9fb08b2d0e5.zip |
Code to parse and access network parameters.
Partial backport of 381766ce4b1145460.
Partial backport of 56c6d78520a98fb64.
Diffstat (limited to 'src/or/networkstatus.c')
-rw-r--r-- | src/or/networkstatus.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index 573197a53f..05da73b5cb 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -286,6 +286,10 @@ networkstatus_vote_free(networkstatus_t *ns) SMARTLIST_FOREACH(ns->known_flags, char *, c, tor_free(c)); smartlist_free(ns->known_flags); } + if (ns->net_params) { + SMARTLIST_FOREACH(ns->net_params, char *, c, tor_free(c)); + smartlist_free(ns->net_params); + } if (ns->supported_methods) { SMARTLIST_FOREACH(ns->supported_methods, char *, c, tor_free(c)); smartlist_free(ns->supported_methods); @@ -1884,6 +1888,33 @@ networkstatus_dump_bridge_status_to_file(time_t now) tor_free(status); } +/** Return the value of a integer parameter from the networkstatus <b>ns</b> + * whose name is <b>param_name</b>. Return <b>default_val</b> if ns is NULL, + * or if it has no parameter called <b>param_name</b>. */ +int32_t +networkstatus_get_param(networkstatus_t *ns, const char *param_name, + int32_t default_val) +{ + size_t name_len; + + if (!ns || !ns->net_params) + return default_val; + + name_len = strlen(param_name); + + SMARTLIST_FOREACH_BEGIN(ns->net_params, const char *, p) { + if (!strcmpstart(p, param_name) && p[name_len] == '=') { + int ok=0; + long v = tor_parse_long(p+name_len+1, 10, INT32_MIN, INT32_MAX, &ok, + NULL); + if (ok) + return (int32_t) v; + } + } SMARTLIST_FOREACH_END(p); + + return default_val; +} + /** If <b>question</b> is a string beginning with "ns/" in a format the * control interface expects for a GETINFO question, set *<b>answer</b> to a * newly-allocated string containing networkstatus lines for the appropriate |