Update Debian Vcs-* fields to point to git repository
[onak.git] / hash.c
diff --git a/hash.c b/hash.c
index 47ec2d8b099446fee0d033c5fad9fc15a5803e28..506bd4c6dc558a23b94acedb1f31cc23c220a4f5 100644 (file)
--- a/hash.c
+++ b/hash.c
@@ -1,18 +1,30 @@
 /*
  * hash.c - hashing routines mainly used for caching key details.
  *
- * Jonathan McDowell <noodles@earth.li>
+ * Copyright 2000-2002 Jonathan McDowell <noodles@earth.li>
  *
- * Copyright 2000-2002 Project Purple
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include "hash.h"
-#include "keydb.h"
-#include "keyid.h"
+#include "keystructs.h"
 #include "ll.h"
+#include "mem.h"
 #include "stats.h"
 
 /**
@@ -38,6 +50,35 @@ void inithash(void)
        elements = 0;
 }
 
+/**
+ *     destroyhash - Clean up the hash after use.
+ *
+ *     This function destroys the hash after use, freeing any memory that was
+ *     used during its lifetime.
+ */
+void destroyhash(void)
+{
+       int i;
+       struct ll *curll = NULL;
+
+       for (i = 0; i < HASHSIZE; i++) {
+               curll = hashtable[i];
+               /*
+                * TODO: The problem is the object has pointers that
+                * need freed too.
+                */
+               llfree(curll, (void (*)(void *)) free_statskey);
+               hashtable[i] = NULL;
+       }
+       elements = 0;
+}
+
+/**
+ *     addtohash - Adds a key to the hash.
+ *     @key: The key to add.
+ *
+ *     Takes a key and stores it in the hash.
+ */
 void addtohash(struct stats_key *key)
 {
        ++elements;
@@ -92,42 +133,7 @@ unsigned long hashelements(void)
        return elements;
 }
 
-struct ll *gethashtableentry(int entry)
+struct ll *gethashtableentry(unsigned int entry)
 {
        return hashtable[entry];
 }
-
-/**
- *     hash_getkeysigs - Gets the signatures on a key.
- *     @keyid: The key we want the signatures for.
- *     
- *     This function gets the signatures on a key. It's the same as the
- *     getkeysigs function from the keydb module except we also cache the data
- *     so that if we need it again we already have it available.
- */
-struct ll *hash_getkeysigs(uint64_t keyid)
-{
-       struct stats_key *key = NULL;
-
-       key = findinhash(keyid);
-       if (key == NULL) {
-               key = malloc(sizeof(*key));
-               if (key != NULL) {
-                       key->keyid = keyid;
-                       key->colour = 0;
-                       key->parent = 0;
-                       key->sigs = NULL;
-                       key->gotsigs = false;
-                       addtohash(key);
-               } else {
-                       perror("hash_getkeysigs()");
-                       return NULL;
-               }
-       }
-       if (key->gotsigs == false) {
-               key->sigs = getkeysigs(key->keyid);
-               key->gotsigs = true;
-       }
-
-       return key->sigs;
-}