diff options
author | Nick Mathewson <nickm@torproject.org> | 2019-09-09 12:56:04 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-09-10 09:10:49 -0400 |
commit | 7282213bd3aa1b21928e7d134180781158ebdb4b (patch) | |
tree | 4a171b22ca93356d5071038eb597cd7b5912d77b /src/feature/dirparse/microdesc_parse.c | |
parent | d8ef6b154890e1b6e8842c68ebd68d954c852e38 (diff) | |
download | tor-7282213bd3aa1b21928e7d134180781158ebdb4b.tar.gz tor-7282213bd3aa1b21928e7d134180781158ebdb4b.zip |
Extract saved_location_to_string() from microdesc parsing.
We may be able to use this function in other places in the future;
if so, we should move it to somewhere more useful.
Part of 31675.
Diffstat (limited to 'src/feature/dirparse/microdesc_parse.c')
-rw-r--r-- | src/feature/dirparse/microdesc_parse.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/feature/dirparse/microdesc_parse.c b/src/feature/dirparse/microdesc_parse.c index e02dfcf11a..441c3bb838 100644 --- a/src/feature/dirparse/microdesc_parse.c +++ b/src/feature/dirparse/microdesc_parse.c @@ -98,6 +98,31 @@ policy_is_reject_star_or_null(struct short_policy_t *policy) return !policy || short_policy_is_reject_star(policy); } +/** + * Return a human-readable description of a given saved_location_t. + * Never returns NULL. + **/ +static const char * +saved_location_to_string(saved_location_t where) +{ + const char *location; + switch (where) { + case SAVED_NOWHERE: + location = "download or generated string"; + break; + case SAVED_IN_CACHE: + location = "cache"; + break; + case SAVED_IN_JOURNAL: + location = "journal"; + break; + default: + location = "unknown location"; + break; + } + return location; +} + /** Parse as many microdescriptors as are found from the string starting at * <b>s</b> and ending at <b>eos</b>. If allow_annotations is set, read any * annotations we recognize and ignore ones we don't. @@ -166,22 +191,8 @@ microdescs_parse_from_string(const char *s, const char *eos, if (tokenize_string(area, s, start_of_next_microdesc, tokens, microdesc_token_table, flags)) { - const char *location; - switch (where) { - case SAVED_NOWHERE: - location = "download or generated string"; - break; - case SAVED_IN_CACHE: - location = "cache"; - break; - case SAVED_IN_JOURNAL: - location = "journal"; - break; - default: - location = "unknown location"; - break; - } - log_warn(LD_DIR, "Unparseable microdescriptor found in %s", location); + log_warn(LD_DIR, "Unparseable microdescriptor found in %s", + saved_location_to_string(where)); goto next; } |