[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Extract saved_location_to_string() from microdesc parsing.
commit 7282213bd3aa1b21928e7d134180781158ebdb4b
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon Sep 9 12:56:04 2019 -0400
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.
---
src/feature/dirparse/microdesc_parse.c | 43 +++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 16 deletions(-)
diff --git a/src/feature/dirparse/microdesc_parse.c b/src/feature/dirparse/microdesc_parse.c
index e02dfcf11..441c3bb83 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;
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits