From 266f8cddd87f8cf507e094725b3f6028bb8d803b Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 11 Feb 2013 13:43:20 +0000 Subject: Refactoring to make parse_bridge_line() unittestable. - Make parse_bridge_line() return a struct. - Make bridge_add_from_config() accept a struct. - Make string_is_key_value() less hysterical. --- src/common/util.c | 13 ++++++++----- src/common/util.h | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/common') diff --git a/src/common/util.c b/src/common/util.c index 9aba7d6c5d..bcb69f2081 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -866,9 +866,10 @@ tor_digest_is_zero(const char *digest) } /** Return true if string is a valid '=[]' string. - * is optional, to indicate the empty string. */ + * is optional, to indicate the empty string. Log at logging + * severity if something ugly happens. */ int -string_is_key_value(const char *string) +string_is_key_value(int severity, const char *string) { /* position of equal sign in string */ const char *equal_sign_pos = NULL; @@ -876,19 +877,21 @@ string_is_key_value(const char *string) tor_assert(string); if (strlen(string) < 2) { /* "x=" is shortest args string */ - log_warn(LD_GENERAL, "'%s' is too short to be a k=v value.", escaped(string)); + tor_log(severity, LD_GENERAL, "'%s' is too short to be a k=v value.", + escaped(string)); return 0; } equal_sign_pos = strchr(string, '='); if (!equal_sign_pos) { - log_warn(LD_GENERAL, "'%s' is not a k=v value.", escaped(string)); + tor_log(severity, LD_GENERAL, "'%s' is not a k=v value.", escaped(string)); return 0; } /* validate that the '=' is not in the beginning of the string. */ if (equal_sign_pos == string) { - log_warn(LD_GENERAL, "'%s' is not a valid k=v value.", escaped(string)); + tor_log(severity, LD_GENERAL, "'%s' is not a valid k=v value.", + escaped(string)); return 0; } diff --git a/src/common/util.h b/src/common/util.h index e3cd72118c..624202c8dd 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -209,7 +209,7 @@ const char *find_whitespace_eos(const char *s, const char *eos); const char *find_str_at_start_of_line(const char *haystack, const char *needle); int string_is_C_identifier(const char *string); -int string_is_key_value(const char *string); +int string_is_key_value(int severity, const char *string); int tor_mem_is_zero(const char *mem, size_t len); int tor_digest_is_zero(const char *digest); -- cgit v1.2.3-54-g00ecf