X-Git-Url: https://the.earth.li/gitweb/?p=onak.git;a=blobdiff_plain;f=hash.c;h=9357831ccc9b352fd3531f8afc4ebaf54df58700;hp=f07017a669d7e65342ce81637d801d0548bb9f59;hb=58ed9a0076feb9604154b99da6ed1907ca7df089;hpb=e01d2e2d07392eb03e4268fdc4f0f1339a9a9461 diff --git a/hash.c b/hash.c index f07017a..9357831 100644 --- a/hash.c +++ b/hash.c @@ -1,18 +1,29 @@ /* * hash.c - hashing routines mainly used for caching key details. * - * Jonathan McDowell + * Copyright 2000-2002 Jonathan McDowell * - * 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, see . */ #include #include +#include #include "hash.h" -#include "keydb.h" -#include "keyid.h" +#include "keystructs.h" #include "ll.h" +#include "mem.h" #include "stats.h" /** @@ -25,6 +36,29 @@ static struct ll *hashtable[HASHSIZE]; */ static unsigned long elements; +/** + * free_statskey - free an stats key structure. + * @key: The key to free. + * + * Takes a stats key and frees the memory used by it and the linked list + * of sigs under it. Doesn't recurse into the list as it's assumed all the + * objects referenced also exist in the hash. + */ +static void free_statskey(struct stats_key *key) +{ + if (key != NULL) { + if (key->sigs != NULL) { + llfree(key->sigs, NULL); + key->sigs = NULL; + } + if (key->signs != NULL) { + llfree(key->signs, NULL); + key->signs = NULL; + } + free(key); + } +} + /** * inithash - Initialize the hash ready for use. */ @@ -55,7 +89,7 @@ void destroyhash(void) * TODO: The problem is the object has pointers that * need freed too. */ - llfree(curll, free); + llfree(curll, (void (*)(void *)) free_statskey); hashtable[i] = NULL; } elements = 0; @@ -99,7 +133,7 @@ struct stats_key *createandaddtohash(uint64_t keyid) return tmpkey; } -int stats_key_cmp(struct stats_key *key, uint64_t *keyid) +static int stats_key_cmp(struct stats_key *key, uint64_t *keyid) { return !(key != NULL && key->keyid == *keyid); } @@ -121,42 +155,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; -}