[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Versions should be sorted by version. Lexical sorting shoul...
Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv20654/src/or
Modified Files:
dirserv.c
Log Message:
Versions should be sorted by version. Lexical sorting should be used only as a last resort.
Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.222
retrieving revision 1.223
diff -u -d -r1.222 -r1.223
--- dirserv.c 12 Sep 2005 08:31:47 -0000 1.222
+++ dirserv.c 12 Sep 2005 08:46:37 -0000 1.223
@@ -554,6 +554,27 @@
return 0;
}
+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 neiher 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);
+}
+
/* Given a (possibly empty) list of config_line_t, each line of which contains
* a list of comma-separated version numbers surrounded by optional space,
* allocate and return a new string containing the version numbers, in order,
@@ -568,7 +589,7 @@
smartlist_split_string(versions, ln->value, ",",
SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
}
- smartlist_sort_strings(versions); /* sort them */
+ smartlist_sort(versions, _compare_tor_version_str_ptr);
result = smartlist_join_strings(versions,",",0,NULL);
SMARTLIST_FOREACH(versions,char *,s,tor_free(s));
smartlist_free(versions);