diff options
author | Roger Dingledine <arma@torproject.org> | 2012-10-22 17:09:43 -0400 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2012-10-22 17:09:43 -0400 |
commit | 4c8b58f9005b7a187878273b8ff0f8ec23e86326 (patch) | |
tree | 07dac5f06df0d3a1b0aa69fc3e28a4e2f3cd1adf /src/or/policies.c | |
parent | 1cc06bd35e4203569ecc72ff314a1dd543f60651 (diff) | |
download | tor-4c8b58f9005b7a187878273b8ff0f8ec23e86326.tar.gz tor-4c8b58f9005b7a187878273b8ff0f8ec23e86326.zip |
add a unit test to expose bug 7192
Diffstat (limited to 'src/or/policies.c')
-rw-r--r-- | src/or/policies.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/or/policies.c b/src/or/policies.c index 6e984211ba..486c2647eb 100644 --- a/src/or/policies.c +++ b/src/or/policies.c @@ -1413,6 +1413,33 @@ parse_short_policy(const char *summary) return result; } +/** Write <b>policy</b> back out into a string. Used only for unit tests + * currently. */ +const char * +write_short_policy(const short_policy_t *policy) +{ + int i; + char *answer; + smartlist_t *sl = smartlist_new(); + + smartlist_add_asprintf(sl, "%s", policy->is_accept ? "accept " : "reject "); + + for(i=0; i < policy->n_entries; i++) { + const short_policy_entry_t *e = &policy->entries[i]; + if (e->min_port == e->max_port) { + smartlist_add_asprintf(sl, "%d", e->min_port); + } else { + smartlist_add_asprintf(sl, "%d-%d", e->min_port, e->max_port); + } + if (i < policy->n_entries-1) + smartlist_add(sl, tor_strdup(",")); + } + answer = smartlist_join_strings(sl, "", 0, NULL); + SMARTLIST_FOREACH(sl, char *, a, tor_free(a)); + smartlist_free(sl); + return answer; +} + /** Release all storage held in <b>policy</b>. */ void short_policy_free(short_policy_t *policy) |