aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-14 16:55:53 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-14 16:55:53 +0000
commit2a39137f85b8821b5c3e5e7cd6a2a1efebd22b2a (patch)
tree6f66029a30b8c3cfb2844f45c4ae7ec677ee8fdb
parent52f1a195f62a55ac12939e27a04956aaad4f38c7 (diff)
This is the 1.6.0 version of revision 156883 of trunk.
This is different in that it preserves the case-sensitiveness of processing queues from configuration. closes issue #13703 git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.0@156889 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--apps/app_queue.c17
-rw-r--r--include/asterisk/strings.h19
2 files changed, 29 insertions, 7 deletions
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 2f87a0f51..98238620a 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -67,6 +67,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <sys/time.h>
#include <sys/signal.h>
#include <netinet/in.h>
+#include <ctype.h>
#include "asterisk/lock.h"
#include "asterisk/file.h"
@@ -557,7 +558,8 @@ static int strat2int(const char *strategy)
static int queue_hash_cb(const void *obj, const int flags)
{
const struct call_queue *q = obj;
- return ast_str_hash(q->name);
+
+ return ast_str_case_hash(q->name);
}
static int queue_cmp_cb(void *obj, void *arg, int flags)
@@ -1471,7 +1473,6 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
/* Delete if unused (else will be deleted when last caller leaves). */
ao2_unlink(queues, q);
ao2_unlock(q);
- queue_unref(q);
}
return NULL;
}
@@ -1980,8 +1981,6 @@ static void leave_queue(struct queue_ent *qe)
if (q->dead) {
/* It's dead and nobody is in it, so kill it */
ao2_unlink(queues, q);
- /* unref the container's reference to the queue */
- queue_unref(q);
}
/* unref the explicit ref earlier in the function */
queue_unref(q);
@@ -2036,11 +2035,10 @@ static int compare_weight(struct call_queue *rq, struct member *member)
}
}
ao2_unlock(q);
+ queue_unref(q);
if (found) {
- queue_unref(q);
break;
}
- queue_unref(q);
}
return found;
}
@@ -3957,6 +3955,8 @@ static int remove_from_queue(const char *queuename, const char *interface)
if (!mem->dynamic) {
ao2_ref(mem, -1);
ao2_unlock(q);
+ queue_unref(q);
+ ao2_unlock(queues);
return RES_NOT_DYNAMIC;
}
q->membercount--;
@@ -5512,13 +5512,15 @@ static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
}
}
- queue_iter = ao2_iterator_init(queues, 0);
+ queue_iter = ao2_iterator_init(queues, F_AO2I_DONTLOCK);
+ ao2_lock(queues);
while ((q = ao2_iterator_next(&queue_iter))) {
float sl;
ao2_lock(q);
if (argc == 3 && strcasecmp(q->name, argv[2])) {
ao2_unlock(q);
+ queue_unref(q);
continue;
}
found = 1;
@@ -5589,6 +5591,7 @@ static char *__queues_show(struct mansession *s, int fd, int argc, char **argv)
}
queue_unref(q); /* Unref the iterator's reference */
}
+ ao2_unlock(queues);
if (!found) {
if (argc == 3)
ast_str_set(&out, 0, "No such queue: %s.", argv[2]);
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 79dac8700..4f5e326cf 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"
@@ -702,4 +704,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 */