summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-12-16 21:10:51 +0000
committerNick Mathewson <nickm@torproject.org>2004-12-16 21:10:51 +0000
commitbbc10c2ea12b836497d3ef41fc434b50108b70f1 (patch)
tree53b685569045209495dfba7b1f81f7b69c831402
parenta3922d0bdcc06a22131d26a4258590338b8cea12 (diff)
downloadtor-bbc10c2ea12b836497d3ef41fc434b50108b70f1.tar.gz
tor-bbc10c2ea12b836497d3ef41fc434b50108b70f1.zip
Make split(..., NULL) split on horizontal space; fix bug with tabs in config file.
svn:r3155
-rw-r--r--src/common/container.c15
-rw-r--r--src/or/config.c6
-rw-r--r--src/or/hibernate.c3
-rw-r--r--src/or/test.c16
4 files changed, 32 insertions, 8 deletions
diff --git a/src/common/container.c b/src/common/container.c
index 0055fcb476..5ce205f466 100644
--- a/src/common/container.c
+++ b/src/common/container.c
@@ -247,7 +247,7 @@ void smartlist_insert(smartlist_t *sl, int idx, void *val)
* trailing space from each entry. If
* <b>flags</b>&amp;SPLIT_IGNORE_BLANK is true, remove any entries of
* length 0. If max>0, divide the string into no more than <b>max</b>
- * pieces.
+ * pieces. If <b>sep</b> is NULL, split on any sequence of horizontal space.
*/
int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep,
int flags, int max)
@@ -257,7 +257,6 @@ int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep,
tor_assert(sl);
tor_assert(str);
- tor_assert(sep);
cp = str;
while (1) {
@@ -267,15 +266,23 @@ int smartlist_split_string(smartlist_t *sl, const char *str, const char *sep,
if (max>0 && n == max-1) {
end = strchr(cp,'\0');
- } else {
+ } else if (sep) {
end = strstr(cp,sep);
if (!end)
end = strchr(cp,'\0');
+ } else {
+ for (end = cp; *end && *end != '\t' && *end != ' '; ++end)
+ ;
}
+
if (!*end) {
next = NULL;
- } else {
+ } else if (sep) {
next = end+strlen(sep);
+ } else {
+ next = end+1;
+ while (*next == '\t' || *next == ' ')
+ ++next;
}
if (flags&SPLIT_SKIP_SPACE) {
diff --git a/src/or/config.c b/src/or/config.c
index 74c50f6fa1..61dcfbbbc6 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1831,7 +1831,7 @@ config_init_logs(or_options_t *options, int validate_only)
elts = smartlist_create();
for (opt = options->Logs; opt; opt = opt->next) {
int levelMin=LOG_DEBUG, levelMax=LOG_ERR;
- smartlist_split_string(elts, opt->value, " ",
+ smartlist_split_string(elts, opt->value, NULL,
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 3);
if (smartlist_len(elts) == 0) {
log_fn(LOG_WARN, "Bad syntax on Log option 'Log %s'", opt->value);
@@ -2045,7 +2045,7 @@ parse_redirect_line(smartlist_t *result, struct config_line_t *line)
r = tor_malloc_zero(sizeof(exit_redirect_t));
elements = smartlist_create();
- smartlist_split_string(elements, line->value, " ",
+ smartlist_split_string(elements, line->value, NULL,
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
if (smartlist_len(elements) != 2) {
log_fn(LOG_WARN, "Wrong number of elements in RedirectExit line");
@@ -2098,7 +2098,7 @@ parse_dir_server_line(const char *line, int validate_only)
char digest[DIGEST_LEN];
items = smartlist_create();
- smartlist_split_string(items, line, " ",
+ smartlist_split_string(items, line, NULL,
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 2);
if (smartlist_len(items) < 2) {
log_fn(LOG_WARN, "Too few arguments to DirServer line.");
diff --git a/src/or/hibernate.c b/src/or/hibernate.c
index f075a5fd40..fdb72ee56c 100644
--- a/src/or/hibernate.c
+++ b/src/or/hibernate.c
@@ -125,7 +125,8 @@ accounting_parse_options(or_options_t *options, int validate_only)
}
items = smartlist_create();
- smartlist_split_string(items, v, " ", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK,0);
+ smartlist_split_string(items, v, NULL,
+ SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK,0);
if (smartlist_len(items)<2) {
log_fn(LOG_WARN, "Too few arguments to AccountingStart");
goto err;
diff --git a/src/or/test.c b/src/or/test.c
index 4cbdf1bca6..817e571e92 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -642,6 +642,22 @@ test_util(void) {
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
smartlist_clear(sl);
+ smartlist_split_string(sl, " ab\tc \td ef ", NULL,
+ SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+ test_eq(4, smartlist_len(sl));
+ test_streq("ab", smartlist_get(sl,0));
+ test_streq("c", smartlist_get(sl,1));
+ test_streq("d", smartlist_get(sl,2));
+ test_streq("ef", smartlist_get(sl,3));
+ smartlist_split_string(sl, "ghi\tj", NULL,
+ SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+ test_eq(6, smartlist_len(sl));
+ test_streq("ghi", smartlist_get(sl,4));
+ test_streq("j", smartlist_get(sl,5));
+
+ SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
+ smartlist_clear(sl);
+
smartlist_split_string(sl, " z <> zhasd <> <> bnud<> ", "<>", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
test_eq(3, smartlist_len(sl));
test_streq("z", smartlist_get(sl, 0));