aboutsummaryrefslogtreecommitdiff
path: root/src/or/routerparse.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-09-02 18:39:59 +0000
committerNick Mathewson <nickm@torproject.org>2004-09-02 18:39:59 +0000
commitbda41ba3fdcedf1bf9564e9b57d656bb6565f076 (patch)
tree8e781bf5c907a60882f1a1f30358e858b10fa27a /src/or/routerparse.c
parent4c799ae7311afa29dde472a0f84a56bac44333f1 (diff)
downloadtor-bda41ba3fdcedf1bf9564e9b57d656bb6565f076.tar
tor-bda41ba3fdcedf1bf9564e9b57d656bb6565f076.tar.gz
Use new split function and strcmpstart correctly
svn:r2327
Diffstat (limited to 'src/or/routerparse.c')
-rw-r--r--src/or/routerparse.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index c12d07f61..c970851b9 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -172,7 +172,7 @@ get_recommended_software_from_directory(const char *str)
const char *cp = str, *eol;
int len = strlen(REC);
cp = str;
- if (strncmp(str, REC, len)==0) {
+ if (strcmpstart(str, REC)==0) {
cp += len;
} else {
cp = strstr(str, "\n"REC);
@@ -196,10 +196,10 @@ get_recommended_software_from_directory(const char *str)
/* static */ int is_obsolete_version(const char *myversion,
const char *versionlist) {
const char *vl;
- char *version, *comma, *cp;
tor_version_t mine, other;
- int found_newer = 0, r;
+ int found_newer = 0, r, ret;
static int warned_too_new=0;
+ smartlist_t *version_sl;
vl = versionlist;
@@ -209,14 +209,11 @@ get_recommended_software_from_directory(const char *str)
log_fn(LOG_ERR, "I couldn't parse my own version (%s)", myversion);
tor_assert(0);
}
+ version_sl = smartlist_create();
+ smartlist_split_string(version_sl, versionlist, ",", SPLIT_SKIP_SPACE, 0);
- for(;;) {
- comma = strchr(vl, ',');
- version = tor_strndup(vl, comma?(comma-vl):strlen(vl));
- cp = version;
- while (isspace((int)*cp))
- ++cp;
- if (!strncmp(cp, "Tor ", 4))
+ SMARTLIST_FOREACH(version_sl, const char *, cp, {
+ if (!strcmpstart(cp, "Tor "))
cp += 4;
if (tor_version_parse(cp, &other)) {
@@ -224,28 +221,29 @@ get_recommended_software_from_directory(const char *str)
} else {
r = tor_version_compare(&mine, &other);
if (r==0) {
- tor_free(version);
- return 0; /* It's a match. */
+ ret = 0;
+ goto done;
} else if (r<0) {
found_newer = 1;
}
}
- tor_free(version);
- if (comma)
- vl = comma+1;
- else
- break;
- }
+ });
+
if (!found_newer) {
if (!warned_too_new) {
log_fn(LOG_WARN, "This version of Tor (%s) is newer than any on the recommended list (%s)",
myversion, versionlist);
warned_too_new=1;
}
- return 0;
+ ret = 0;
} else {
- return 1;
+ ret = 1;
}
+
+ done:
+ SMARTLIST_FOREACH(version_sl, char *, version, tor_free(version));
+ smartlist_free(version_sl);
+ return ret;
}
/* Return 0 if myversion is supported; else log a message and return
@@ -1162,13 +1160,13 @@ get_next_token(const char **s, where_syntax where) {
}
}
*s = eat_whitespace(*s);
- if (strncmp(*s, "-----BEGIN ", 11)) {
+ if (strcmpstart(*s, "-----BEGIN ")) {
goto done_tokenizing;
}
obstart = *s;
*s += 11; /* length of "-----BEGIN ". */
next = strchr(*s, '\n');
- if (next-*s < 6 || strncmp(next-5, "-----\n", 6)) {
+ if (next-*s < 6 || strcmpstart(next-5, "-----\n")) {
RET_ERR("Malformed object: bad begin line");
}
tok->object_type = tor_strndup(*s, next-*s-5);
@@ -1178,7 +1176,7 @@ get_next_token(const char **s, where_syntax where) {
RET_ERR("Malformed object: missing end line");
}
if (!strcmp(tok->object_type, "RSA PUBLIC KEY")) {
- if (strncmp(next, "-----END RSA PUBLIC KEY-----\n", 29))
+ if (strcmpstart(next, "-----END RSA PUBLIC KEY-----\n"))
RET_ERR("Malformed object: mismatched end line");
next = strchr(next,'\n')+1;
tok->key = crypto_new_pk_env();
@@ -1194,7 +1192,7 @@ get_next_token(const char **s, where_syntax where) {
tok->object_size = i;
*s = next + 9; /* length of "-----END ". */
i = strlen(tok->object_type);
- if (strncmp(*s, tok->object_type, i) || strncmp(*s+i, "-----\n", 6)) {
+ if (strncmp(*s, tok->object_type, i) || strcmpstart(*s+i, "-----\n")) {
RET_ERR("Malformed object: mismatched end tag");
}
*s += i+6;