summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-05-03 02:36:31 +0000
committerStef Walter <stef@memberwebs.com>2008-05-03 02:36:31 +0000
commitec0d36ee55709f1df76f977823722a4b53cf27ed (patch)
tree4df12b55e1f5568c85bfc0aec72ae09e219fefa7 /common
parentc6e6d2852303ab491badd3af5571af0f36f67cc5 (diff)
A whole bunch of changes including:
* Measure disk space * Support mulitple IPs per jail.
Diffstat (limited to 'common')
-rw-r--r--common/hash.c24
-rw-r--r--common/hash.h11
2 files changed, 35 insertions, 0 deletions
diff --git a/common/hash.c b/common/hash.c
index 9acd2df..b509d03 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -286,6 +286,11 @@ static hsh_entry_t** find_entry(hsh_t* ht, const void* key, size_t klen, const v
klen = p - (const unsigned char *)key;
}
+ else if(klen == HSH_KEY_DIRECT)
+ {
+ hash = (unsigned int)key;
+ klen = 0;
+ }
else
{
for(p = key, i = klen; i; i--, p++)
@@ -374,6 +379,25 @@ void* hsh_rem(hsh_t* ht, const void* key, size_t klen)
return val;
}
+void hsh_clear(hsh_t* ht)
+{
+ hsh_entry_t *he, *next;
+ int i;
+
+ /* Free all entries in the array */
+ for (i = 0; i < ht->max; ++i) {
+ he = ht->array[i];
+ while (he) {
+ next = he->next;
+ free (he);
+ he = next;
+ }
+ }
+
+ memset (ht->array, 0, ht->max * sizeof (hsh_entry_t*));
+ ht->count = 0;
+}
+
unsigned int hsh_count(hsh_t* ht)
{
return ht->count;
diff --git a/common/hash.h b/common/hash.h
index 4dc37b2..bf9d7b8 100644
--- a/common/hash.h
+++ b/common/hash.h
@@ -134,9 +134,20 @@ hsh_index_t* hsh_next(hsh_index_t* hi);
void* hsh_this(hsh_index_t* hi, const void** key, size_t* klen);
/*
+ * hsh_clear: Clear all values from has htable.
+ */
+void hsh_clear(hsh_t* ht);
+
+/*
* This can be passed as 'klen' in any of the above functions to indicate
* a string-valued key, and have hash compute the length automatically.
*/
#define HSH_KEY_STRING (-1)
+/*
+ * This can be passed as 'klen' in any of the above functions to indicate
+ * use of the key pointer directly as a hash.
+ */
+#define HSH_KEY_DIRECT (-2)
+
#endif /* __HSH_H__ */