diff options
author | Nick Mathewson <nickm@torproject.org> | 2006-02-06 05:04:27 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2006-02-06 05:04:27 +0000 |
commit | e5a574ce2e80e4fc202f2ea35b5bb6c986aab025 (patch) | |
tree | 2481609cd213a93b887cf80599f74b353045fff0 /src/or/routerparse.c | |
parent | 2bb4fd24de054685ba005177e7359ad1eb087804 (diff) | |
download | tor-e5a574ce2e80e4fc202f2ea35b5bb6c986aab025.tar.gz tor-e5a574ce2e80e4fc202f2ea35b5bb6c986aab025.zip |
Move "sort list of versions" logic into routerparse.c; make version-checking code say which versions it would have accepted. (not tested.)
svn:r5927
Diffstat (limited to 'src/or/routerparse.c')
-rw-r--r-- | src/or/routerparse.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 99fb7defb5..61de43fcae 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -1835,3 +1835,34 @@ tor_version_same_series(tor_version_t *a, tor_version_t *b) (a->micro == b->micro)); } +/** Helper: Given pointers to two strings describing tor versions, return -1 + * if _a precedes _b, 1 if _b preceeds _a, and 0 if they are equivalent. + * Used to sort a list of versions. */ +static int +_compare_tor_version_str_ptr(const void **_a, const void **_b) +{ + const char *a = *_a, *b = *_b; + int ca, cb; + tor_version_t va, vb; + ca = tor_version_parse(a, &va); + cb = tor_version_parse(b, &vb); + /* If they both parse, compare them. */ + if (!ca && !cb) + return tor_version_compare(&va,&vb); + /* If one parses, it comes first. */ + if (!ca && cb) + return -1; + if (ca && !cb) + return 1; + /* If neither parses, compare strings. Also, the directory server admin + ** needs to be smacked upside the head. But Tor is tolerant and gentle. */ + return strcmp(a,b); +} + +/** Sort a list of string-representations of versions in ascending order. */ +void +sort_version_list(smartlist_t *versions) +{ + smartlist_sort(versions, _compare_tor_version_str_ptr); +} + |