]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Move tor_escape_str_for_pt_args into or/transports.c
authorNick Mathewson <nickm@torproject.org>
Thu, 28 Jun 2018 15:49:27 +0000 (11:49 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 28 Jun 2018 15:49:27 +0000 (11:49 -0400)
src/common/util.c
src/common/util.h
src/or/transports.c
src/or/transports.h
src/test/test_util.c

index 5a104d39f1a3d8d317ae27affee880214a7fd5c9..6a557c956038a8a5dc5b6f0caef4a687faa3e110 100644 (file)
@@ -225,43 +225,6 @@ add_laplace_noise(int64_t signal_, double random_, double delta_f,
  * String manipulation
  * ===== */
 
-/** 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 *
-tor_escape_str_for_pt_args(const char *string, const char *chars_to_escape)
-{
-  char *new_string = NULL;
-  char *new_cp = NULL;
-  size_t length, new_length;
-
-  tor_assert(string);
-
-  length = strlen(string);
-
-  if (!length) /* If we were given the empty string, return the same. */
-    return tor_strdup("");
-  /* (new_length > SIZE_MAX) => ((length * 2) + 1 > SIZE_MAX) =>
-     (length*2 > SIZE_MAX - 1) => (length > (SIZE_MAX - 1)/2) */
-  if (length > (SIZE_MAX - 1)/2) /* check for overflow */
-    return NULL;
-
-  /* this should be enough even if all characters must be escaped */
-  new_length = (length * 2) + 1;
-
-  new_string = new_cp = tor_malloc(new_length);
-
-  while (*string) {
-    if (strchr(chars_to_escape, *string))
-      *new_cp++ = '\\';
-
-    *new_cp++ = *string++;
-  }
-
-  *new_cp = '\0'; /* NUL-terminate the new string */
-
-  return new_string;
-}
-
 /* =====
  * Time
  * ===== */
index f473d6f59fd77e0f8eb231085a6f1c31ade6ab5d..8007aa05c7cc3ac3bea4ee9afc3966bbe831d959 100644 (file)
@@ -72,8 +72,6 @@ int64_t clamp_double_to_int64(double number);
 
 /* String manipulation */
 
-char *tor_escape_str_for_pt_args(const char *string,
-                                 const char *chars_to_escape);
 
 /* Time helpers */
 long tv_udiff(const struct timeval *start, const struct timeval *end);
index 6cc7f844ab5023d7e2a802008fbfd4244ad2ecd7..34161fd16e887268f660bf71aa6815bfe346d039 100644 (file)
@@ -1699,3 +1699,40 @@ pt_free_all(void)
     managed_proxy_list=NULL;
   }
 }
+
+/** 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 *
+tor_escape_str_for_pt_args(const char *string, const char *chars_to_escape)
+{
+  char *new_string = NULL;
+  char *new_cp = NULL;
+  size_t length, new_length;
+
+  tor_assert(string);
+
+  length = strlen(string);
+
+  if (!length) /* If we were given the empty string, return the same. */
+    return tor_strdup("");
+  /* (new_length > SIZE_MAX) => ((length * 2) + 1 > SIZE_MAX) =>
+     (length*2 > SIZE_MAX - 1) => (length > (SIZE_MAX - 1)/2) */
+  if (length > (SIZE_MAX - 1)/2) /* check for overflow */
+    return NULL;
+
+  /* this should be enough even if all characters must be escaped */
+  new_length = (length * 2) + 1;
+
+  new_string = new_cp = tor_malloc(new_length);
+
+  while (*string) {
+    if (strchr(chars_to_escape, *string))
+      *new_cp++ = '\\';
+
+    *new_cp++ = *string++;
+  }
+
+  *new_cp = '\0'; /* NUL-terminate the new string */
+
+  return new_string;
+}
index 0bd96e0950bacb8b6f458ab75f2178cd00d84902..d304dcd4859af8534dd997474fbb7e914c5e4326 100644 (file)
@@ -66,6 +66,9 @@ char *pt_stringify_socks_args(const smartlist_t *socks_args);
 char *pt_get_socks_args_for_proxy_addrport(const tor_addr_t *addr,
                                             uint16_t port);
 
+char *tor_escape_str_for_pt_args(const char *string,
+                                 const char *chars_to_escape);
+
 #ifdef PT_PRIVATE
 /** State of the managed proxy configuration protocol. */
 enum pt_proto_state {
index 4d171d5d0ee5f561b21065d2b0a627939adcab4c..a6fb0ce846b2a7df285ded94c4ed86f86440dd61 100644 (file)
@@ -15,6 +15,7 @@
 #include "common/buffers.h"
 #include "or/config.h"
 #include "or/control.h"
+#include "or/transports.h"
 #include "lib/crypt_ops/crypto_rand.h"
 #include "test/test.h"
 #include "lib/memarea/memarea.h"