aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-03-20 01:21:19 +0000
committerNick Mathewson <nickm@torproject.org>2004-03-20 01:21:19 +0000
commitb0ef4e1143619e0beb2388f523c7dce39d5bc6ed (patch)
tree9bd27325d13b3ab75283660bcd992dfe319fdefc /src/common
parent1dca07fc51bf977f4d0f60f5cb36e9aab6d74da4 (diff)
downloadtor-b0ef4e1143619e0beb2388f523c7dce39d5bc6ed.tar
tor-b0ef4e1143619e0beb2388f523c7dce39d5bc6ed.tar.gz
Use strmap code for client DNS.
svn:r1309
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 101ac0b1d..dcbbfa000 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -77,6 +77,16 @@ char *tor_strndup(const char *s, size_t n) {
return dup;
}
+/* Convert s to lowercase. */
+void tor_strlower(char *s)
+{
+ while (*s) {
+ *s = tolower(*s);
+ ++s;
+ }
+}
+
+
/*
* A simple smartlist interface to make an unordered list of acceptable
* nodes and then choose a random one.
@@ -256,6 +266,40 @@ void* strmap_remove(strmap_t *map, const char *key)
}
}
+/* Same as strmap_set, but first converts <key> to lowercase. */
+void* strmap_set_lc(strmap_t *map, const char *key, void *val)
+{
+ /* We could be a little faster by using strcasecmp instead, and a separate
+ * type, but I don't think it matters. */
+ void *v;
+ char *lc_key = tor_strdup(key);
+ tor_strlower(lc_key);
+ v = strmap_set(map,lc_key,val);
+ tor_free(lc_key);
+ return v;
+}
+/* Same as strmap_get, but first converts <key> to lowercase. */
+void* strmap_get_lc(strmap_t *map, const char *key)
+{
+ void *v;
+ char *lc_key = tor_strdup(key);
+ tor_strlower(lc_key);
+ v = strmap_get(map,lc_key);
+ tor_free(lc_key);
+ return v;
+}
+/* Same as strmap_remove, but first converts <key> to lowercase */
+void* strmap_remove_lc(strmap_t *map, const char *key)
+{
+ void *v;
+ char *lc_key = tor_strdup(key);
+ tor_strlower(lc_key);
+ v = strmap_remove(map,lc_key);
+ tor_free(lc_key);
+ return v;
+}
+
+
/* Invoke fn() on every entry of the map, in order. For every entry,
* fn() is invoked with that entry's key, that entry's value, and the
* value of <data> supplied to strmap_foreach. fn() must return a new