[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Use strmap code for client DNS.



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv24772/src/common

Modified Files:
	util.c 
Log Message:
Use strmap code for client DNS.

Index: util.c
===================================================================
RCS file: /home/or/cvsroot/src/common/util.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- util.c	19 Mar 2004 22:07:24 -0000	1.66
+++ util.c	20 Mar 2004 01:21:19 -0000	1.67
@@ -77,6 +77,16 @@
   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 @@
   }
 }
 
+/* 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