From 0b309a2b8cf939c7a0f5c765a2ab64f8df23c511 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sun, 20 Dec 2015 20:03:03 +0100 Subject: [PATCH] move FourHash into libcitadel. --- citadel/modules/ctdlproto/serv_messages.c | 10 ++++++---- libcitadel/lib/hash.c | 23 +++++++++++++++++++++++ libcitadel/lib/libcitadel.h | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/citadel/modules/ctdlproto/serv_messages.c b/citadel/modules/ctdlproto/serv_messages.c index 0751e28a9..ef1d70a7a 100644 --- a/citadel/modules/ctdlproto/serv_messages.c +++ b/citadel/modules/ctdlproto/serv_messages.c @@ -156,10 +156,12 @@ void cmd_msgs(char *cmdbuf) long tValueLen; extract_token(tfield, buf, 0, '|', sizeof tfield); tValueLen = extract_token(tvalue, buf, 1, '|', sizeof tvalue); - for (i='A'; i<='Z'; ++i) if (msgkeys[i]!=NULL) { - if (!strcasecmp(tfield, msgkeys[i])) { - CM_SetField(template, i, tvalue, tValueLen); - } + if (tValueLen >= 0) { + for (i='A'; i<='Z'; ++i) if (msgkeys[i]!=NULL) { + if (!strcasecmp(tfield, msgkeys[i])) { + CM_SetField(template, i, tvalue, tValueLen); + } + } } } buffer_output(); diff --git a/libcitadel/lib/hash.c b/libcitadel/lib/hash.c index c1e8d4d42..665e39b30 100644 --- a/libcitadel/lib/hash.c +++ b/libcitadel/lib/hash.c @@ -657,6 +657,29 @@ long lFlathash(const char *str, long len) else return *(long*)str; } +/** + * @ingroup HashListAlgorithm + * @brief another hashing algorithm; accepts exactly 4 characters, convert it to a hash key. + * @param str Our pointer to the long value + * @param len the length of the data pointed to; needs to be sizeof long, else we won't use it! + * @return the calculated hash value + */ +long FourHash(const char *key, long length) +{ + int i; + int ret = 0; + const unsigned char *ptr = (const unsigned char*)key; + + for (i = 0; i < 4; i++, ptr ++) + ret = (ret << 8) | + ( ((*ptr >= 'a') && + (*ptr <= 'z'))? + *ptr - 'a' + 'A': + *ptr); + + return ret; +} + /** * @ingroup HashListPrivate * @brief private abstract wrapper around the hashing algorithm diff --git a/libcitadel/lib/libcitadel.h b/libcitadel/lib/libcitadel.h index 9d251ad83..3a4d7a18b 100644 --- a/libcitadel/lib/libcitadel.h +++ b/libcitadel/lib/libcitadel.h @@ -515,6 +515,7 @@ typedef long (*HashFunc)(const char *Str, long Len); typedef void (*TransitionFunc) (void *Item1, void *Item2, int Odd); typedef const char* (*PrintHashDataFunc) (const char *Key, void *Item, int Odd); +long FourHash(const char *key, long length); long Flathash(const char *str, long len); long lFlathash(const char *str, long len); #define IKEY(a) (const char*) &a, sizeof(a) -- 2.30.2