[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Move string_is_key_value to lib/encoding



commit 30166261bb1e523db1199ea422c9bf09f30de69f
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Jun 28 11:46:32 2018 -0400

    Move string_is_key_value to lib/encoding
---
 src/common/util.c           | 33 --------------------------------
 src/common/util.h           |  2 --
 src/lib/encoding/include.am |  2 ++
 src/lib/encoding/keyval.c   | 46 +++++++++++++++++++++++++++++++++++++++++++++
 src/lib/encoding/keyval.h   | 11 +++++++++++
 src/or/config.c             |  1 +
 src/test/test_util.c        |  1 +
 7 files changed, 61 insertions(+), 35 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index 304101ec0..5a104d39f 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -225,39 +225,6 @@ add_laplace_noise(int64_t signal_, double random_, double delta_f,
  * String manipulation
  * ===== */
 
-/** Return true if <b>string</b> is a valid 'key=[value]' string.
- *  "value" is optional, to indicate the empty string. Log at logging
- *  <b>severity</b> if something ugly happens. */
-int
-string_is_key_value(int severity, const char *string)
-{
-  /* position of equal sign in string */
-  const char *equal_sign_pos = NULL;
-
-  tor_assert(string);
-
-  if (strlen(string) < 2) { /* "x=" is shortest args 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) {
-    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) {
-    tor_log(severity, LD_GENERAL, "'%s' is not a valid k=v value.",
-            escaped(string));
-    return 0;
-  }
-
-  return 1;
-}
-
 /** Return a newly allocated string equal to <b>string</b>, except that every
  * character in <b>chars_to_escape</b> is preceded by a backslash. */
 char *
diff --git a/src/common/util.h b/src/common/util.h
index 7d7544006..f473d6f59 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -72,8 +72,6 @@ int64_t clamp_double_to_int64(double number);
 
 /* String manipulation */
 
-int string_is_key_value(int severity, const char *string);
-
 char *tor_escape_str_for_pt_args(const char *string,
                                  const char *chars_to_escape);
 
diff --git a/src/lib/encoding/include.am b/src/lib/encoding/include.am
index 93f515dd4..cf9fb1b25 100644
--- a/src/lib/encoding/include.am
+++ b/src/lib/encoding/include.am
@@ -8,6 +8,7 @@ src_lib_libtor_encoding_a_SOURCES =			\
 	src/lib/encoding/binascii.c			\
         src/lib/encoding/confline.c			\
         src/lib/encoding/cstring.c			\
+        src/lib/encoding/keyval.c			\
 	src/lib/encoding/time_fmt.c
 
 src_lib_libtor_encoding_testing_a_SOURCES = \
@@ -19,4 +20,5 @@ noinst_HEADERS +=					\
 	src/lib/encoding/binascii.h			\
         src/lib/encoding/confline.h			\
         src/lib/encoding/cstring.h			\
+        src/lib/encoding/keyval.h			\
 	src/lib/encoding/time_fmt.h
diff --git a/src/lib/encoding/keyval.c b/src/lib/encoding/keyval.c
new file mode 100644
index 000000000..cffd6f6db
--- /dev/null
+++ b/src/lib/encoding/keyval.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2003, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include "orconfig.h"
+#include "lib/encoding/keyval.h"
+#include "lib/log/escape.h"
+#include "lib/log/torlog.h"
+#include "lib/log/util_bug.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/** Return true if <b>string</b> is a valid 'key=[value]' string.
+ *  "value" is optional, to indicate the empty string. Log at logging
+ *  <b>severity</b> if something ugly happens. */
+int
+string_is_key_value(int severity, const char *string)
+{
+  /* position of equal sign in string */
+  const char *equal_sign_pos = NULL;
+
+  tor_assert(string);
+
+  if (strlen(string) < 2) { /* "x=" is shortest args 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) {
+    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) {
+    tor_log(severity, LD_GENERAL, "'%s' is not a valid k=v value.",
+            escaped(string));
+    return 0;
+  }
+
+  return 1;
+}
diff --git a/src/lib/encoding/keyval.h b/src/lib/encoding/keyval.h
new file mode 100644
index 000000000..745855520
--- /dev/null
+++ b/src/lib/encoding/keyval.h
@@ -0,0 +1,11 @@
+/* Copyright (c) 2003, Roger Dingledine
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef TOR_KEYVAL_H
+#define TOR_KEYVAL_H
+
+int string_is_key_value(int severity, const char *string);
+
+#endif
diff --git a/src/or/config.c b/src/or/config.c
index fb0ea5d59..a553e7edb 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -117,6 +117,7 @@
 #include "lib/process/setuid.h"
 #include "lib/process/subprocess.h"
 
+#include "lib/encoding/keyval.h"
 #include "lib/fs/conffile.h"
 #include "common/procmon.h"
 
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 8afd9473e..4d171d5d0 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -21,6 +21,7 @@
 #include "lib/process/waitpid.h"
 #include "test/log_test_helpers.h"
 #include "lib/compress/compress_zstd.h"
+#include "lib/encoding/keyval.h"
 #include "lib/fdio/fdio.h"
 #include "lib/process/env.h"
 #include "lib/process/pidfile.h"



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits