X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/71ad017abe933ba0dc7ed1b005074c4a5ab9978a..807aad387f6698a1eec1acf340496f064cb04cbb:/keydb_fs.c diff --git a/keydb_fs.c b/keydb_fs.c index 69a76b1..01101f0 100644 --- a/keydb_fs.c +++ b/keydb_fs.c @@ -4,8 +4,6 @@ * Daniel Silverstone * * Copyright 2004 Daniel Silverstone and Project Purple - * - * $Id: keydb_fs.c,v 1.3 2004/05/28 03:23:04 noodles Exp $ */ #include @@ -45,7 +43,7 @@ static uint32_t calchash(uint8_t * ptr) { register uint32_t h = FNV_offset_basis; register uint32_t p = FNV_mixing_prime; - register uint32_t n = strlen(ptr); + register uint32_t n = strlen((char *) ptr); register uint8_t *c = ptr; while (n--) { h *= p; @@ -58,7 +56,7 @@ static uint32_t calchash(uint8_t * ptr) void keypath(char *buffer, uint64_t _keyid) { uint64_t keyid = _keyid << 32; - snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08lX/%016llX", + snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08X/%016llX", config.db_dir, (uint8_t) ((keyid >> 56) & 0xFF), (uint8_t) ((keyid >> 48) & 0xFF), (uint32_t) (keyid >> 32), _keyid); @@ -67,7 +65,7 @@ void keypath(char *buffer, uint64_t _keyid) void keydir(char *buffer, uint64_t _keyid) { uint64_t keyid = _keyid << 32; - snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08lX", config.db_dir, + snprintf(buffer, PATH_MAX, "%s/key/%02X/%02X/%08X", config.db_dir, (uint8_t) ((keyid >> 56) & 0xFF), (uint8_t) ((keyid >> 48) & 0xFF), (uint32_t) (keyid >> 32)); @@ -88,7 +86,7 @@ void prove_path_to(uint64_t keyid, char *what) (uint8_t) ((keyid >> 16) & 0xFF)); mkdir(buffer, 0777); - snprintf(buffer, PATH_MAX, "%s/%s/%02X/%02X/%08lX", config.db_dir, what, + snprintf(buffer, PATH_MAX, "%s/%s/%02X/%02X/%08X", config.db_dir, what, (uint8_t) ((keyid >> 24) & 0xFF), (uint8_t) ((keyid >> 16) & 0xFF), (uint32_t) (keyid)); mkdir(buffer, 0777); @@ -96,14 +94,14 @@ void prove_path_to(uint64_t keyid, char *what) void wordpath(char *buffer, char *word, uint32_t hash, uint64_t keyid) { - snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08lX/%s/%016llX", + snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08X/%s/%016llX", config.db_dir, (uint8_t) ((hash >> 24) & 0xFF), (uint8_t) ((hash >> 16) & 0xFF), hash, word, keyid); } void worddir(char *buffer, char *word, uint32_t hash) { - snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08lX/%s", config.db_dir, + snprintf(buffer, PATH_MAX, "%s/words/%02X/%02X/%08X/%s", config.db_dir, (uint8_t) ((hash >> 24) & 0xFF), (uint8_t) ((hash >> 16) & 0xFF), hash, word); } @@ -349,7 +347,9 @@ static struct ll *internal_get_key_by_word(char *word, struct ll *mct) de = readdir(d); if (de && de->d_name[0] != '.') { if ((!mct) - || (llfind(mct, de->d_name, strcmp) != + || (llfind(mct, de->d_name, + (int (*)(const void *, const void *)) + strcmp) != NULL)) { logthing(LOGTHING_CRITICAL, "Found %s // %s", word, @@ -375,16 +375,20 @@ int fetch_key_text(const char *search, { struct ll *wordlist = NULL, *wl = NULL; struct ll *keylist = NULL; + char *searchtext = NULL; int addedkeys = 0; logthing(LOGTHING_CRITICAL, "Search was '%s'", search); - wl = wordlist = makewordlist(wordlist, search); + searchtext = strdup(search); + wl = wordlist = makewordlist(wordlist, searchtext); keylist = internal_get_key_by_word(wordlist->object, NULL); if (!keylist) { llfree(wordlist, NULL); + free(searchtext); + searchtext = NULL; return 0; } @@ -395,6 +399,8 @@ int fetch_key_text(const char *search, if (!nkl) { llfree(wordlist, NULL); llfree(keylist, free); + free(searchtext); + searchtext = NULL; return 0; } llfree(keylist, free); @@ -417,6 +423,8 @@ int fetch_key_text(const char *search, } llfree(keylist, free); + free(searchtext); + searchtext = NULL; return addedkeys; }