summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorSean Bright <sean@malleable.com>2012-10-01 20:36:25 +0000
committerSean Bright <sean@malleable.com>2012-10-01 20:36:25 +0000
commitb9eeff1521cb1c0d479761dfa17cf88d19cd7bf7 (patch)
treea554bc0a54a608da5a41a4763e7aec082304e724 /apps
parentb3c739a8424720bc63e15faebc8e6ffe15944294 (diff)
app_queue: Support persisting and loading of long member lists.
Greenlight in #asterisk brought up that he was receiving an error message "Could not create persistent member string, out of space" when running app_queue in Asterisk 10. dump_queue_members() made an assumption that 8K would be enough to store the generated string, but with queues that have large member lists this is not always the case. This patch removes the limitation and uses ast_str instead of a fixed sized buffer. The complicating factor comes from the fact that ast_db_get requires a buffer and buffer size argument, which doesn't let us pull back more than what we pass in, so I introduced a new ast_db_get_allocated() which returns an ast_strdup()'d copy of the value from astdb. As an aside, I did some testing on the maximum size of data that we can store in the BDB library we distribute and was able to store a 10MB string and retrieve it with no problems, so I feel this is a safe patch. Review: https://reviewboard.asterisk.org/r/2136/ ........ Merged revisions 374108 from http://svn.asterisk.org/svn/asterisk/branches/1.8 ........ Merged revisions 374135 from http://svn.asterisk.org/svn/asterisk/branches/10 ........ Merged revisions 374150 from http://svn.asterisk.org/svn/asterisk/branches/11 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@374151 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'apps')
-rw-r--r--apps/app_queue.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 13577cc68..963ac24a3 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -1014,8 +1014,6 @@ static char *app_ql = "QueueLog" ;
/*! \brief Persistent Members astdb family */
static const char * const pm_family = "Queue/PersistentMembers";
-/* The maximum length of each persistent member queue database entry */
-#define PM_MAX_LEN 8192
/*! \brief queues.conf [general] option */
static int queue_persistent_members = 0;
@@ -5815,17 +5813,19 @@ static struct member *interface_exists(struct call_queue *q, const char *interfa
static void dump_queue_members(struct call_queue *pm_queue)
{
struct member *cur_member;
- char value[PM_MAX_LEN];
- int value_len = 0;
- int res;
+ struct ast_str *value;
struct ao2_iterator mem_iter;
- memset(value, 0, sizeof(value));
-
if (!pm_queue) {
return;
}
+ /* 4K is a reasonable default for most applications, but we grow to
+ * accommodate more if necessary. */
+ if (!(value = ast_str_create(4096))) {
+ return;
+ }
+
mem_iter = ao2_iterator_init(pm_queue->members, 0);
while ((cur_member = ao2_iterator_next(&mem_iter))) {
if (!cur_member->dynamic) {
@@ -5833,26 +5833,28 @@ static void dump_queue_members(struct call_queue *pm_queue)
continue;
}
- res = snprintf(value + value_len, sizeof(value) - value_len, "%s%s;%d;%d;%s;%s",
- value_len ? "|" : "", cur_member->interface, cur_member->penalty, cur_member->paused, cur_member->membername, cur_member->state_interface);
+ ast_str_append(&value, 0, "%s%s;%d;%d;%s;%s",
+ ast_str_strlen(value) ? "|" : "",
+ cur_member->interface,
+ cur_member->penalty,
+ cur_member->paused,
+ cur_member->membername,
+ cur_member->state_interface);
ao2_ref(cur_member, -1);
-
- if (res != strlen(value + value_len)) {
- ast_log(LOG_WARNING, "Could not create persistent member string, out of space\n");
- break;
- }
- value_len += res;
}
ao2_iterator_destroy(&mem_iter);
-
- if (value_len && !cur_member) {
- if (ast_db_put(pm_family, pm_queue->name, value))
- ast_log(LOG_WARNING, "failed to create persistent dynamic entry!\n");
+
+ if (ast_str_strlen(value) && !cur_member) {
+ if (ast_db_put(pm_family, pm_queue->name, ast_str_buffer(value))) {
+ ast_log(LOG_WARNING, "failed to create persistent dynamic entry!\n");
+ }
} else {
/* Delete the entry if the queue is empty or there is an error */
ast_db_del(pm_family, pm_queue->name);
}
+
+ ast_free(value);
}
/*! \brief Remove member from queue
@@ -6356,7 +6358,7 @@ static void reload_queue_members(void)
struct ast_db_entry *db_tree;
struct ast_db_entry *entry;
struct call_queue *cur_queue;
- char queue_data[PM_MAX_LEN];
+ char *queue_data;
/* Each key in 'pm_family' is the name of a queue */
db_tree = ast_db_gettree(pm_family, NULL);
@@ -6383,7 +6385,7 @@ static void reload_queue_members(void)
continue;
}
- if (ast_db_get(pm_family, queue_name, queue_data, PM_MAX_LEN)) {
+ if (ast_db_get_allocated(pm_family, queue_name, &queue_data)) {
queue_t_unref(cur_queue, "Expire reload reference");
continue;
}
@@ -6428,6 +6430,7 @@ static void reload_queue_members(void)
}
}
queue_t_unref(cur_queue, "Expire reload reference");
+ ast_free(queue_data);
}
if (db_tree) {