summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-04-17 00:58:30 +0000
committerNick Mathewson <nickm@torproject.org>2007-04-17 00:58:30 +0000
commit00941b01714b08623110ee831a0f479ce194b389 (patch)
tree870e4a75d60d718cb1186fc48aee958b2fed33b1
parentbfac679cd4209ea441211bcb5c5e210c6264e8c7 (diff)
downloadtor-00941b01714b08623110ee831a0f479ce194b389.tar.gz
tor-00941b01714b08623110ee831a0f479ce194b389.zip
r12418@catbus: nickm | 2007-04-16 20:58:25 -0400
Twiddle tor_version_as_new_as() so we can check for particular svn revisions. With unit tests, for added freshness. svn:r9977
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/routerparse.c38
-rw-r--r--src/or/test.c15
3 files changed, 49 insertions, 5 deletions
diff --git a/src/or/or.h b/src/or/or.h
index 577caf37ab..c42a57d690 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3084,6 +3084,7 @@ typedef struct tor_version_t {
enum { VER_PRE=0, VER_RC=1, VER_RELEASE=2, } status;
int patchlevel;
char status_tag[MAX_STATUS_TAG_LEN];
+ int svn_revision;
} tor_version_t;
typedef enum version_status_t {
diff --git a/src/or/routerparse.c b/src/or/routerparse.c
index 92224183d1..265bb6e5aa 100644
--- a/src/or/routerparse.c
+++ b/src/or/routerparse.c
@@ -1947,7 +1947,7 @@ int
tor_version_as_new_as(const char *platform, const char *cutoff)
{
tor_version_t cutoff_version, router_version;
- char *s, *start;
+ char *s, *s2, *start;
char tmp[128];
tor_assert(platform);
@@ -1962,6 +1962,10 @@ tor_version_as_new_as(const char *platform, const char *cutoff)
start = (char *)eat_whitespace(platform+3);
if (!*start) return 0;
s = (char *)find_whitespace(start); /* also finds '\0', which is fine */
+ s2 = (char*)eat_whitespace(s);
+ if (!strcmpstart(s2, "(r"))
+ s = (char*)find_whitespace(s2);
+
if ((size_t)(s-start+1) >= sizeof(tmp)) /* too big, no */
return 0;
strlcpy(tmp, start, s-start+1);
@@ -1971,6 +1975,15 @@ tor_version_as_new_as(const char *platform, const char *cutoff)
return 1; /* be safe and say yes */
}
+ /* Here's why we don't need to do any special handling for svn revisions:
+ * - If neither has an svn revision, we're fine.
+ * - If the router doesn't have an svn revision, we can't assume that it
+ * is "at least" any svn revision, so we need to return 0.
+ * - If the target version doesn't have an svn revision, any svn revision
+ * (or none at all) is good enough, so return 1.
+ * - If both target and router have an svn revision, we compare them.
+ */
+
return tor_version_compare(&router_version, &cutoff_version) >= 0;
}
@@ -1979,7 +1992,8 @@ tor_version_as_new_as(const char *platform, const char *cutoff)
int
tor_version_parse(const char *s, tor_version_t *out)
{
- char *eos=NULL, *cp=NULL;
+ char *eos=NULL;
+ const char *cp=NULL;
/* Format is:
* "Tor " ? NUM dot NUM dot NUM [ ( pre | rc | dot ) NUM [ - tag ] ]
*/
@@ -2033,7 +2047,19 @@ tor_version_parse(const char *s, tor_version_t *out)
/* Get status tag. */
if (*cp == '-' || *cp == '.')
++cp;
- strlcpy(out->status_tag, cp, sizeof(out->status_tag));
+ eos = (char*) find_whitespace(cp);
+ if (eos-cp >= (int)sizeof(out->status_tag))
+ strlcpy(out->status_tag, cp, sizeof(out->status_tag));
+ else {
+ memcpy(out->status_tag, cp, eos-cp);
+ out->status_tag[eos-cp] = 0;
+ }
+ cp = eat_whitespace(eos);
+
+ if (!strcmpstart(cp, "(r")) {
+ cp += 2;
+ out->svn_revision = strtol(cp,&eos,10);
+ }
return 0;
}
@@ -2056,8 +2082,10 @@ tor_version_compare(tor_version_t *a, tor_version_t *b)
return i;
else if ((i = a->patchlevel - b->patchlevel))
return i;
-
- return strcmp(a->status_tag, b->status_tag);
+ else if ((i = strcmp(a->status_tag, b->status_tag)))
+ return i;
+ else
+ return a->svn_revision - b->svn_revision;
}
/** Return true iff versions <b>a</b> and <b>b</b> belong to the same series.
diff --git a/src/or/test.c b/src/or/test.c
index 98a10f8d9c..a03f17134e 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1918,6 +1918,21 @@ test_dir_format(void)
"Tor 0.0.8 on Darwin 64-121-192-100.c3-0."
"sfpo-ubr1.sfrn-sfpo.ca.cable.rcn.com Power Macintosh", "0.0.8.2"));
+ /* Now try svn revisions. */
+ test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100)",
+ "Tor 0.2.1.0-dev (r99)"));
+ test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100) on Banana Jr",
+ "Tor 0.2.1.0-dev (r99) on Hal 9000"));
+ test_eq(1, tor_version_as_new_as("Tor 0.2.1.0-dev (r100)",
+ "Tor 0.2.1.0-dev on Colossus"));
+ test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev (r99)",
+ "Tor 0.2.1.0-dev (r100)"));
+ test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev (r99) on MCP",
+ "Tor 0.2.1.0-dev (r100) on AM"));
+ test_eq(0, tor_version_as_new_as("Tor 0.2.1.0-dev",
+ "Tor 0.2.1.0-dev (r99)"));
+ test_eq(1, tor_version_as_new_as("Tor 0.2.1.1",
+ "Tor 0.2.1.0-dev (r99)"));
}
static void