Merged revisions 77852 via svnmerge from
authorMark Michelson <mmichelson@digium.com>
Wed, 1 Aug 2007 14:02:19 +0000 (14:02 +0000)
committerMark Michelson <mmichelson@digium.com>
Wed, 1 Aug 2007 14:02:19 +0000 (14:02 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r77852 | mmichelson | 2007-08-01 08:59:59 -0500 (Wed, 01 Aug 2007) | 7 lines

If a queue uses dynamic realtime members, then the member list should be updated after each attempt to call the queue.
This fixes an issue where if a caller calls into a queue where no one is logged in, they would wait forever even if a member
logged in at some point.

(closes issue #10346, reported by and tested by blitzrage, patched by me)

........

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@77853 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_queue.c

index d7691f2..fd6d3b2 100644 (file)
@@ -1258,6 +1258,56 @@ static struct call_queue *load_realtime_queue(const char *queuename)
        return q;
 }
 
+static void update_realtime_members(struct call_queue *q)
+{
+       struct ast_config *member_config = NULL;
+       struct member *m, *prev_m, *next_m;
+       char *interface = NULL;
+
+       member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", q->name , NULL);
+       if (!member_config) {
+               /*This queue doesn't have realtime members*/
+               ast_debug(3, "Queue %s has no realtime members defined. No need for update\n", q->name);
+               return;
+       }
+
+       ast_mutex_lock(&q->lock);
+       
+       /* Temporarily set non-dynamic members dead so we can detect deleted ones.*/ 
+       for (m = q->members; m; m = m->next) {
+               if (!m->dynamic)
+                       m->dead = 1;
+       }
+
+       while ((interface = ast_category_browse(member_config, interface))) {
+               rt_handle_member_record(q, interface,
+                       S_OR(ast_variable_retrieve(member_config, interface, "membername"), interface),
+                       ast_variable_retrieve(member_config, interface, "penalty"),
+                       ast_variable_retrieve(member_config, interface, "paused"));
+       }
+
+       /* Delete all realtime members that have been deleted in DB. */
+       m = q->members;
+       prev_m = NULL;
+       while (m) {
+               next_m = m->next;
+               if (m->dead) {
+                       if (prev_m) {
+                               prev_m->next = next_m;
+                       } else {
+                               q->members = next_m;
+                       }
+                       remove_from_interfaces(m->interface);
+                       q->membercount--;
+                       free(m);
+               } else {
+                       prev_m = m;
+               }
+               m = next_m;
+       }
+       ast_mutex_unlock(&q->lock);
+}
+
 static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason)
 {
        struct call_queue *q;
@@ -3624,6 +3674,9 @@ check_turns:
                                break;
                        }
 
+                       /* If using dynamic realtime members, we should regenerate the member list for this queue */
+                       update_realtime_members(qe.parent);
+
                        /* OK, we didn't get anybody; wait for 'retry' seconds; may get a digit to exit with */
                        res = wait_a_bit(&qe);
                        if (res)