aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/strings.h
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-14 16:53:38 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-14 16:53:38 +0000
commit8bbcf7838437c446659f0988f623facce292bd3c (patch)
tree9c95c9f6a5849fa85869f98ea8021b673b948d7f /include/asterisk/strings.h
parent7e9cdbaadb4dc5aee07d8c21fe92b48d940d1c7e (diff)
Fix some refcounting in app_queue.c and change the
hashing used by app_queue.c to be case-insensitive. This is accomplished by adding a new case-insensitive hashing function. This was necessary to prevent bad refcount errors (and potential crashes) which would occur due to the fact that queues were initially read from the config file in a case-sensitive manner. Then, when a user issued a CLI command or manager action, we allowed for case-insensitive input and used that input to directly try to find the queue in the hash table. The result was either that we could not find a queue that was input or worse, we would end up hashing to a completely bogus value based on the input. This commit resolves the problem presented in issue #13703. However, that issue was reported against 1.6.0. Since this fix introduces a behavior change, I am electing to not place this same fix in to the 1.6.0 or 1.6.1 branches, and instead will opt for a change which does not change behavior. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@156883 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r--include/asterisk/strings.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 5ad362e56..142fc7c62 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -23,6 +23,8 @@
#ifndef _ASTERISK_STRINGS_H
#define _ASTERISK_STRINGS_H
+#include <ctype.h>
+
#include "asterisk/inline_api.h"
#include "asterisk/utils.h"
#include "asterisk/threadstorage.h"
@@ -738,4 +740,21 @@ static force_inline int ast_str_hash(const char *str)
return abs(hash);
}
+/*!
+ * \brief Compute a hash value on a case-insensitive string
+ *
+ * Uses the same hash algorithm as ast_str_hash, but converts
+ * all characters to lowercase prior to computing a hash. This
+ * allows for easy case-insensitive lookups in a hash table.
+ */
+static force_inline int ast_str_case_hash(const char *str)
+{
+ int hash = 5381;
+
+ while (*str) {
+ hash = hash * 33 ^ tolower(*str++);
+ }
+
+ return abs(hash);
+}
#endif /* _ASTERISK_STRINGS_H */