aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2013-02-11 13:43:20 +0000
committerGeorge Kadianakis <desnacked@riseup.net>2013-02-11 18:07:26 +0000
commit266f8cddd87f8cf507e094725b3f6028bb8d803b (patch)
tree5d903eb81b90ccfe4b5356e8623d83b53ec434d0 /src/common/util.c
parentb5dceab1751dfa12b27b3042a49d90e0b02c2e0c (diff)
downloadtor-266f8cddd87f8cf507e094725b3f6028bb8d803b.tar
tor-266f8cddd87f8cf507e094725b3f6028bb8d803b.tar.gz
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.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 9aba7d6c5..bcb69f208 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 <b>string</b> is a valid '<key>=[<value>]' string.
- * <value> is optional, to indicate the empty string. */
+ * <value> is optional, to indicate the empty string. Log at logging
+ * <b>severity</b> 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;
}