[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Merge remote-tracking branch 'asn/bug3594_rebased_and_fixed'
commit c101ecc8dcc733fda31c0834f19c48d717ebe4c7
Merge: 6e94d2f 9bdd33e
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue Mar 19 13:25:45 2013 -0400
Merge remote-tracking branch 'asn/bug3594_rebased_and_fixed'
Conflicts:
src/common/util.c
src/or/entrynodes.h
changes/bug3594 | 3 +
src/common/util.c | 73 +++++++++++++++++++++
src/common/util.h | 4 +
src/or/config.c | 164 +++++++++++++++++++++++++++++++++++++-----------
src/or/config.h | 14 ++++
src/or/connection.c | 157 ++++++++++++++++++++++++++++++++++++---------
src/or/connection.h | 8 +++
src/or/entrynodes.c | 72 +++++++++++++++++-----
src/or/entrynodes.h | 11 ++-
src/or/or.h | 4 +-
src/or/transports.c | 52 +++++++++++++++
src/or/transports.h | 4 +
src/test/test_config.c | 150 +++++++++++++++++++++++++++++++++++++++++++
src/test/test_util.c | 60 ++++++++++++++++++
14 files changed, 686 insertions(+), 90 deletions(-)
diff --cc src/common/util.c
index 17fb949,bcb69f2..144f472
--- a/src/common/util.c
+++ b/src/common/util.c
@@@ -1176,6 -1209,119 +1209,46 @@@ escaped(const char *s
return escaped_val_;
}
-/** Rudimentary string wrapping code: given a un-wrapped <b>string</b> (no
- * newlines!), break the string into newline-terminated lines of no more than
- * <b>width</b> characters long (not counting newline) and insert them into
- * <b>out</b> in order. Precede the first line with prefix0, and subsequent
- * lines with prefixRest.
- */
-/* This uses a stupid greedy wrapping algorithm right now:
- * - For each line:
- * - Try to fit as much stuff as possible, but break on a space.
- * - If the first "word" of the line will extend beyond the allowable
- * width, break the word at the end of the width.
- */
-void
-wrap_string(smartlist_t *out, const char *string, size_t width,
- const char *prefix0, const char *prefixRest)
-{
- size_t p0Len, pRestLen, pCurLen;
- const char *eos, *prefixCur;
- tor_assert(out);
- tor_assert(string);
- tor_assert(width);
- if (!prefix0)
- prefix0 = "";
- if (!prefixRest)
- prefixRest = "";
-
- p0Len = strlen(prefix0);
- pRestLen = strlen(prefixRest);
- tor_assert(width > p0Len && width > pRestLen);
- eos = strchr(string, '\0');
- tor_assert(eos);
- pCurLen = p0Len;
- prefixCur = prefix0;
-
- while ((eos-string)+pCurLen > width) {
- const char *eol = string + width - pCurLen;
- while (eol > string && *eol != ' ')
- --eol;
- /* eol is now the last space that can fit, or the start of the string. */
- if (eol > string) {
- size_t line_len = (eol-string) + pCurLen + 2;
- char *line = tor_malloc(line_len);
- memcpy(line, prefixCur, pCurLen);
- memcpy(line+pCurLen, string, eol-string);
- line[line_len-2] = '\n';
- line[line_len-1] = '\0';
- smartlist_add(out, line);
- string = eol + 1;
- } else {
- size_t line_len = width + 2;
- char *line = tor_malloc(line_len);
- memcpy(line, prefixCur, pCurLen);
- memcpy(line+pCurLen, string, width - pCurLen);
- line[line_len-2] = '\n';
- line[line_len-1] = '\0';
- smartlist_add(out, line);
- string += width-pCurLen;
- }
- prefixCur = prefixRest;
- pCurLen = pRestLen;
- }
-
- if (string < eos) {
- size_t line_len = (eos-string) + pCurLen + 2;
- char *line = tor_malloc(line_len);
- memcpy(line, prefixCur, pCurLen);
- memcpy(line+pCurLen, string, eos-string);
- line[line_len-2] = '\n';
- line[line_len-1] = '\0';
- smartlist_add(out, line);
- }
-}
-
+ /** Escape every ";" or "\" character of <b>string</b>. Use
+ * <b>escape_char</b> as the character to use for escaping.
+ * The returned string is allocated on the heap and it's the
+ * responsibility of the caller to free it. */
+ char *
+ tor_escape_str_for_socks_arg(const char *string)
+ {
+ char *new_string = NULL;
+ char *new_cp = NULL;
+ size_t length, new_length;
+ static const char *chars_to_escape = ";\\";
+
+ 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
* ===== */
diff --cc src/common/util.h
index 8206a6d,624202c..11a50eb
--- a/src/common/util.h
+++ b/src/common/util.h
@@@ -214,7 -216,12 +215,10 @@@ int tor_digest_is_zero(const char *dige
int tor_digest256_is_zero(const char *digest);
char *esc_for_log(const char *string) ATTR_MALLOC;
const char *escaped(const char *string);
+
+ char *tor_escape_str_for_socks_arg(const char *string);
+
struct smartlist_t;
-void wrap_string(struct smartlist_t *out, const char *string, size_t width,
- const char *prefix0, const char *prefixRest);
int tor_vsscanf(const char *buf, const char *pattern, va_list ap)
#ifdef __GNUC__
__attribute__((format(scanf, 2, 0)))
diff --cc src/or/entrynodes.h
index 52b8dc0,6a4bcea..533f202
--- a/src/or/entrynodes.h
+++ b/src/or/entrynodes.h
@@@ -108,7 -107,10 +107,11 @@@ int any_pending_bridge_descriptor_fetch
int entries_known_but_down(const or_options_t *options);
void entries_retry_all(const or_options_t *options);
+int any_bridge_supports_microdescriptors(void);
+ const smartlist_t *get_socks_args_by_bridge_addrport(const tor_addr_t *addr,
+ uint16_t port);
+
+ int any_bridges_dont_support_microdescriptors(void);
void entry_guards_free_all(void);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits