From b0ef4e1143619e0beb2388f523c7dce39d5bc6ed Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 20 Mar 2004 01:21:19 +0000 Subject: Use strmap code for client DNS. svn:r1309 --- src/common/util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/common') 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 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 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 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 supplied to strmap_foreach. fn() must return a new -- cgit v1.2.3