[svn-commits] branch oej/moduletest r8894 - in
/team/oej/moduletest: ./ apps/ channels/ utils/
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Tue Jan 31 14:20:46 MST 2006
Author: oej
Date: Mon Jan 30 04:04:10 2006
New Revision: 8894
URL: http://svn.digium.com/view/asterisk?rev=8894&view=rev
Log:
Merged revisions 8320,8347,8394,8412,8414,8418,8429,8433,8437,8445,8537,8562,8573,8588,8600,8608,8619,8632,8666,8677,8710,8729,8758,8785,8808 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r8320 | mogorman | 2006-01-20 02:00:46 +0100 (Fri, 20 Jan 2006) | 3 lines
solved problem with delayreject and iax trunking
bug 4291
........
r8347 | russell | 2006-01-20 19:34:42 +0100 (Fri, 20 Jan 2006) | 2 lines
fix invalid value of prev_q (issue #6302)
........
r8394 | tilghman | 2006-01-21 19:29:39 +0100 (Sat, 21 Jan 2006) | 2 lines
Bug 5936 - AddQueueMember fails on realtime queue, if queue not yet loaded
........
r8412 | russell | 2006-01-22 00:17:06 +0100 (Sun, 22 Jan 2006) | 2 lines
prevent the possibility of writing outside of the available workspace (issue #6271)
........
r8414 | russell | 2006-01-22 00:43:14 +0100 (Sun, 22 Jan 2006) | 2 lines
temporarily revert substring fix pending the result of the discussion in issue #6271
........
r8418 | russell | 2006-01-22 03:05:41 +0100 (Sun, 22 Jan 2006) | 3 lines
add a modified fix to prevent writing outside of the provided workspace when
calculating a substring (issue #6271)
........
r8429 | tilghman | 2006-01-22 09:52:49 +0100 (Sun, 22 Jan 2006) | 2 lines
Bug 6281 - Cannot set more than a single header with SIPAddHeader
........
r8433 | bweschke | 2006-01-22 16:13:41 +0100 (Sun, 22 Jan 2006) | 3 lines
Bug fix: Correct some scenarios where CALL_LIMIT could not be getting adjusted properly allowing chan_sip to send calls when it really shouldn't. Bug #6111
........
r8437 | russell | 2006-01-22 18:47:13 +0100 (Sun, 22 Jan 2006) | 2 lines
fix MixMonitor crash (issue #6321, probably others)
........
r8445 | russell | 2006-01-22 20:03:53 +0100 (Sun, 22 Jan 2006) | 2 lines
fix memory leak from not freeing the queue member list when freeing an old queue
........
r8537 | oej | 2006-01-24 14:15:13 +0100 (Tue, 24 Jan 2006) | 2 lines
Issue #6308 - never send response to ACK. (Reported by whiskerp)
........
r8562 | oej | 2006-01-24 20:21:15 +0100 (Tue, 24 Jan 2006) | 2 lines
Issue 6114: Don't hangup on BYE/ALSO with no channel.
........
r8573 | mattf | 2006-01-24 21:37:30 +0100 (Tue, 24 Jan 2006) | 2 lines
Backport fix for #6229, hangup on polarity reversal
........
r8588 | kpfleming | 2006-01-24 23:32:09 +0100 (Tue, 24 Jan 2006) | 2 lines
ensure that channel cannot become zombie after we check but before we try to start indications
........
r8600 | russell | 2006-01-24 23:55:32 +0100 (Tue, 24 Jan 2006) | 2 lines
completely arbitrary whitespace change for testing something with svnmerge ...
........
r8608 | kpfleming | 2006-01-25 02:50:52 +0100 (Wed, 25 Jan 2006) | 2 lines
ensure hangup cause code is handled properly when channel does not return a frame (issue #6346)
........
r8619 | russell | 2006-01-25 06:38:36 +0100 (Wed, 25 Jan 2006) | 2 lines
don't leak almost 200 bytes for each new channel (issue #6330)
........
r8632 | oej | 2006-01-25 10:46:43 +0100 (Wed, 25 Jan 2006) | 2 lines
Issue #6439 - the "timebomb" bug. Patch by Markster over GPRS
........
r8666 | russell | 2006-01-25 19:39:44 +0100 (Wed, 25 Jan 2006) | 2 lines
fix memory leak (inspired by issue #6351)
........
r8677 | russell | 2006-01-25 20:14:43 +0100 (Wed, 25 Jan 2006) | 3 lines
don't call ast_update_realtime with uninitialized variables if we get a
registration with an expirey of 0 seconds (issue #6173)
........
r8710 | oej | 2006-01-26 15:39:36 +0100 (Thu, 26 Jan 2006) | 2 lines
Issue 5898: Registrations does not get deleted if there's an active SIP dialog
........
r8729 | russell | 2006-01-26 20:42:35 +0100 (Thu, 26 Jan 2006) | 2 lines
fix problem with dtmf on e&m (issue #6364)
........
r8758 | tilghman | 2006-01-27 01:52:12 +0100 (Fri, 27 Jan 2006) | 2 lines
Bug 6072 - Revisions to the source bison and flex files don't auto-regenerate these files
........
r8785 | oej | 2006-01-27 09:02:16 +0100 (Fri, 27 Jan 2006) | 2 lines
Issue 6362 - Register without Contact: and Expires: fails (reporter: op)
........
r8808 | oej | 2006-01-28 14:52:15 +0100 (Sat, 28 Jan 2006) | 3 lines
Issue 6182 - Don't remove scheduled event until it's really done.
(reported by malverian)
........
Modified:
team/oej/moduletest/ (props changed)
team/oej/moduletest/apps/app_dial.c
team/oej/moduletest/apps/app_queue.c
team/oej/moduletest/ast_expr2.c
team/oej/moduletest/ast_expr2.h
team/oej/moduletest/ast_expr2f.c
team/oej/moduletest/asterisk.c
team/oej/moduletest/channel.c
team/oej/moduletest/channels/chan_features.c
team/oej/moduletest/channels/chan_iax2.c
team/oej/moduletest/channels/chan_sip.c
team/oej/moduletest/channels/chan_zap.c
team/oej/moduletest/pbx.c
team/oej/moduletest/utils/astman.c
Propchange: team/oej/moduletest/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Jan 30 04:04:10 2006
@@ -1,1 +1,1 @@
-/branches/1.2:1-7496,7498-8301
+/branches/1.2:1-7496,7498-8893
Modified: team/oej/moduletest/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/oej/moduletest/apps/app_dial.c?rev=8894&r1=8893&r2=8894&view=diff
==============================================================================
--- team/oej/moduletest/apps/app_dial.c (original)
+++ team/oej/moduletest/apps/app_dial.c Mon Jan 30 04:04:10 2006
@@ -650,6 +650,7 @@
ast_hangup(o->chan);
o->chan = NULL;
ast_clear_flag(o, DIAL_STILLGOING);
+ HANDLE_CAUSE(in->hangupcause, in);
}
}
o = o->next;
Modified: team/oej/moduletest/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/oej/moduletest/apps/app_queue.c?rev=8894&r1=8893&r2=8894&view=diff
==============================================================================
--- team/oej/moduletest/apps/app_queue.c (original)
+++ team/oej/moduletest/apps/app_queue.c Mon Jan 30 04:04:10 2006
@@ -19,6 +19,8 @@
/*! \file
*
* \brief True call queues with optional send URL on answer
+ *
+ * \author Mark Spencer <markster at digium.com>
*
* \arg Config in \ref Config_qu queues.conf
*
@@ -112,6 +114,7 @@
#define DEFAULT_RETRY 5
#define DEFAULT_TIMEOUT 15
#define RECHECK 1 /* Recheck every second to see we we're at the top yet */
+#define MAX_PERIODIC_ANNOUNCEMENTS 10 /* The maximum periodic announcements we can have */
#define RES_OKAY 0 /* Action completed */
#define RES_EXISTS (-1) /* Entry already exists */
@@ -221,7 +224,7 @@
/*! \brief Persistent Members astdb family */
static const char *pm_family = "/Queue/PersistentMembers";
-/* The maximum lengh of each persistent member queue database entry */
+/* The maximum length of each persistent member queue database entry */
#define PM_MAX_LEN 2048
/*! \brief queues.conf [general] option */
@@ -280,10 +283,12 @@
int pos; /*!< Where we are in the queue */
int prio; /*!< Our priority */
int last_pos_said; /*!< Last position we told the user */
- time_t last_periodic_announce_time; /*!< The last time we played a periodic anouncement */
+ time_t last_periodic_announce_time; /*!< The last time we played a periodic announcement */
+ int last_periodic_announce_sound; /* The last periodic announcement we made */
time_t last_pos; /*!< Last time we told the user their position */
int opos; /*!< Where we started in the queue */
int handled; /*!< Whether our call was handled */
+ int max_penalty; /*!< Limit the members that can take this call to this penalty or lower */
time_t start; /*!< When we started holding */
time_t expire; /*!< When this entry should expire (time out of queue) */
struct ast_channel *chan; /*!< Our channel */
@@ -314,18 +319,18 @@
char moh[80]; /*!< Music On Hold class to be used */
char announce[80]; /*!< Announcement to play when call is answered */
char context[AST_MAX_CONTEXT]; /*!< Exit context */
- unsigned int monjoin:1;
- unsigned int dead:1;
- unsigned int joinempty:2;
- unsigned int eventwhencalled:1;
- unsigned int leavewhenempty:2;
- unsigned int reportholdtime:1;
- unsigned int wrapped:1;
- unsigned int timeoutrestart:1;
- unsigned int announceholdtime:2;
- unsigned int strategy:3;
- unsigned int maskmemberstatus:1;
- unsigned int realtime:1;
+ unsigned int monjoin:1;
+ unsigned int dead:1;
+ unsigned int joinempty:2;
+ unsigned int eventwhencalled:1;
+ unsigned int leavewhenempty:2;
+ unsigned int reportholdtime:1;
+ unsigned int wrapped:1;
+ unsigned int timeoutrestart:1;
+ unsigned int announceholdtime:2;
+ unsigned int strategy:3;
+ unsigned int maskmemberstatus:1;
+ unsigned int realtime:1;
int announcefrequency; /*!< How often to announce their position */
int periodicannouncefrequency; /*!< How often to play periodic announcement */
int roundingseconds; /*!< How many seconds do we round to? */
@@ -344,7 +349,7 @@
char sound_seconds[80]; /*!< Sound file: "seconds." (def. queue-seconds) */
char sound_thanks[80]; /*!< Sound file: "Thank you for your patience." (def. queue-thankyou) */
char sound_reporthold[80]; /*!< Sound file: "Hold time" (def. queue-reporthold) */
- char sound_periodicannounce[80];/*!< Sound file: Custom announce, no default */
+ char sound_periodicannounce[MAX_PERIODIC_ANNOUNCEMENTS][80];/* Sound files: Custom announce, no default */
int count; /*!< How many entries */
int maxlen; /*!< Max number of entries */
@@ -353,18 +358,21 @@
int retry; /*!< Retry calling everyone after this amount of time */
int timeout; /*!< How long to wait for an answer */
int weight; /*!< Respective weight */
-
+ int autopause; /*!< Auto pause queue members if they fail to answer */
+
/* Queue strategy things */
int rrpos; /*!< Round Robin - position */
int memberdelay; /*!< Seconds to delay connecting member to caller */
-
+ int autofill; /*!< Ignore the head call status and ring an available agent */
+
struct member *members; /*!< Head of the list of members */
struct queue_ent *head; /*!< Head of the list of callers */
- struct ast_call_queue *next; /*!< Next call queue */
+ AST_LIST_ENTRY(ast_call_queue) list; /*!< Next call queue */
};
-static struct ast_call_queue *queues = NULL;
-AST_MUTEX_DEFINE_STATIC(qlock);
+static AST_LIST_HEAD_STATIC(queues, ast_call_queue);
+
+static int set_member_paused(char *queuename, char *interface, int paused);
static void set_queue_result(struct ast_channel *chan, enum queue_result res)
{
@@ -424,12 +432,15 @@
QUEUE_NORMAL
};
-static enum queue_member_status get_member_status(const struct ast_call_queue *q)
+static enum queue_member_status get_member_status(const struct ast_call_queue *q, int max_penalty)
{
struct member *member;
enum queue_member_status result = QUEUE_NO_MEMBERS;
for (member = q->members; member; member = member->next) {
+ if (max_penalty && (member->penalty > max_penalty))
+ continue;
+
switch (member->status) {
case AST_DEVICE_INVALID:
/* nothing to do */
@@ -469,8 +480,8 @@
}
if (option_debug)
ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s)\n", technology, loc, sc->state, devstate2str(sc->state));
- ast_mutex_lock(&qlock);
- for (q = queues; q; q = q->next) {
+ AST_LIST_LOCK(&queues);
+ AST_LIST_TRAVERSE(&queues, q, list) {
ast_mutex_lock(&q->lock);
cur = q->members;
while(cur) {
@@ -496,7 +507,7 @@
}
ast_mutex_unlock(&q->lock);
}
- ast_mutex_unlock(&qlock);
+ AST_LIST_UNLOCK(&queues);
free(sc);
return NULL;
}
@@ -508,9 +519,8 @@
struct statechange *sc;
pthread_t t;
pthread_attr_t attr;
-
- sc = malloc(sizeof(struct statechange) + strlen(dev) + 1);
- if (sc) {
+
+ if ((sc = ast_calloc(1, sizeof(*sc) + strlen(dev) + 1))) {
sc->state = state;
strcpy(sc->dev, dev);
pthread_attr_init(&attr);
@@ -529,10 +539,7 @@
/* Add a new member */
- cur = malloc(sizeof(struct member));
-
- if (cur) {
- memset(cur, 0, sizeof(struct member));
+ if ((cur = ast_calloc(1, sizeof(*cur)))) {
cur->penalty = penalty;
cur->paused = paused;
ast_copy_string(cur->interface, interface, sizeof(cur->interface));
@@ -548,9 +555,7 @@
{
struct ast_call_queue *q;
- q = malloc(sizeof(*q));
- if (q) {
- memset(q, 0, sizeof(*q));
+ if ((q = ast_calloc(1, sizeof(*q)))) {
ast_mutex_init(&q->lock);
ast_copy_string(q->name, queuename, sizeof(q->name));
}
@@ -559,6 +564,7 @@
static void init_queue(struct ast_call_queue *q)
{
+ int i;
q->dead = 0;
q->retry = DEFAULT_RETRY;
q->timeout = -1;
@@ -581,7 +587,10 @@
ast_copy_string(q->sound_thanks, "queue-thankyou", sizeof(q->sound_thanks));
ast_copy_string(q->sound_lessthan, "queue-less-than", sizeof(q->sound_lessthan));
ast_copy_string(q->sound_reporthold, "queue-reporthold", sizeof(q->sound_reporthold));
- ast_copy_string(q->sound_periodicannounce, "queue-periodic-announce", sizeof(q->sound_periodicannounce));
+ ast_copy_string(q->sound_periodicannounce[0], "queue-periodic-announce", sizeof(q->sound_periodicannounce[0]));
+ for (i=1;i<MAX_PERIODIC_ANNOUNCEMENTS;i++) {
+ q->sound_periodicannounce[i][0]='\0';
+ }
}
static void clear_queue(struct ast_call_queue *q)
@@ -602,6 +611,9 @@
extra fields in the tables. */
static void queue_set_param(struct ast_call_queue *q, const char *param, const char *val, int linenum, int failunknown)
{
+ int i = 0;
+ char *c, *lastc;
+ char buff[80];
if (!strcasecmp(param, "music") || !strcasecmp(param, "musiconhold")) {
ast_copy_string(q->moh, val, sizeof(q->moh));
} else if (!strcasecmp(param, "announce")) {
@@ -656,8 +668,24 @@
q->announceholdtime = ANNOUNCEHOLDTIME_ALWAYS;
else
q->announceholdtime = 0;
- } else if (!strcasecmp(param, "periodic-announce")) {
- ast_copy_string(q->sound_periodicannounce, val, sizeof(q->sound_periodicannounce));
+ } else if (!strcasecmp(param, "periodic-announce")) {
+ if (strchr(val,'|')) {
+ lastc = (char *)val;
+ while ((c = strchr(lastc,'|'))) {
+ if (i > MAX_PERIODIC_ANNOUNCEMENTS)
+ break;
+ strncpy(buff, lastc, abs(lastc - c));
+ buff[abs(lastc - c)] = '\0';
+ ast_copy_string(q->sound_periodicannounce[i], buff, sizeof(q->sound_periodicannounce[i]));
+ lastc = (c + 1);
+ i++;
+ }
+ if (strlen(lastc)) {
+ ast_copy_string(q->sound_periodicannounce[i], lastc, sizeof(q->sound_periodicannounce[i]));
+ }
+ } else {
+ ast_copy_string(q->sound_periodicannounce[i], val, sizeof(q->sound_periodicannounce[i]));
+ }
} else if (!strcasecmp(param, "periodic-announce-frequency")) {
q->periodicannouncefrequency = atoi(val);
} else if (!strcasecmp(param, "retry")) {
@@ -666,6 +694,10 @@
q->retry = DEFAULT_RETRY;
} else if (!strcasecmp(param, "wrapuptime")) {
q->wrapuptime = atoi(val);
+ } else if (!strcasecmp(param, "autofill")) {
+ q->autofill = ast_true(val);
+ } else if (!strcasecmp(param, "autopause")) {
+ q->autopause = ast_true(val);
} else if (!strcasecmp(param, "maxlen")) {
q->maxlen = atoi(val);
if (q->maxlen < 0)
@@ -755,29 +787,48 @@
}
}
+static void free_members(struct ast_call_queue *q, int all)
+{
+ /* Free non-dynamic members */
+ struct member *curm, *next, *prev = NULL;
+
+ for (curm = q->members; curm; curm = next) {
+ next = curm->next;
+ if (all || !curm->dynamic) {
+ if (prev)
+ prev->next = next;
+ else
+ q->members = next;
+ free(curm);
+ } else
+ prev = curm;
+ }
+}
+
+static void destroy_queue(struct ast_call_queue *q)
+{
+ free_members(q, 1);
+ ast_mutex_destroy(&q->lock);
+ free(q);
+}
/*!\brief Reload a single queue via realtime.
\return Return the queue, or NULL if it doesn't exist.
- \note Should be called with the global qlock locked.
- When found, the queue is returned with q->lock locked. */
+ \note Should be called with the global qlock locked. */
static struct ast_call_queue *find_queue_by_name_rt(const char *queuename, struct ast_variable *queue_vars, struct ast_config *member_config)
{
struct ast_variable *v;
- struct ast_call_queue *q, *prev_q;
+ struct ast_call_queue *q;
struct member *m, *prev_m, *next_m;
char *interface;
char *tmp, *tmp_name;
char tmpbuf[64]; /* Must be longer than the longest queue param name. */
/* Find the queue in the in-core list (we will create a new one if not found). */
- q = queues;
- prev_q = NULL;
- while (q) {
+ AST_LIST_TRAVERSE(&queues, q, list) {
if (!strcasecmp(q->name, queuename)) {
break;
}
- q = q->next;
- prev_q = q;
}
/* Static queues override realtime. */
@@ -788,6 +839,7 @@
ast_mutex_unlock(&q->lock);
return NULL;
} else {
+ ast_mutex_unlock(&q->lock);
return q;
}
}
@@ -808,13 +860,9 @@
/* Delete if unused (else will be deleted when last caller leaves). */
if (!q->count) {
/* Delete. */
- if (!prev_q) {
- queues = q->next;
- } else {
- prev_q->next = q->next;
- }
+ AST_LIST_REMOVE(&queues, q, list);
ast_mutex_unlock(&q->lock);
- free(q);
+ destroy_queue(q);
} else
ast_mutex_unlock(&q->lock);
}
@@ -823,14 +871,12 @@
/* Create a new queue if an in-core entry does not exist yet. */
if (!q) {
- q = alloc_queue(queuename);
- if (!q)
+ if (!(q = alloc_queue(queuename)))
return NULL;
ast_mutex_lock(&q->lock);
clear_queue(q);
q->realtime = 1;
- q->next = queues;
- queues = q;
+ AST_LIST_INSERT_HEAD(&queues, q, list);
}
init_queue(q); /* Ensure defaults for all parameters not set explicitly. */
@@ -882,13 +928,60 @@
m = next_m;
}
+ ast_mutex_unlock(&q->lock);
+
return q;
}
-static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason)
+static struct ast_call_queue *load_realtime_queue(char *queuename)
{
struct ast_variable *queue_vars = NULL;
struct ast_config *member_config = NULL;
+ struct ast_call_queue *q;
+
+ /* Find the queue in the in-core list first. */
+ AST_LIST_LOCK(&queues);
+ AST_LIST_TRAVERSE(&queues, q, list) {
+ if (!strcasecmp(q->name, queuename)) {
+ break;
+ }
+ }
+ AST_LIST_UNLOCK(&queues);
+
+ if (!q) {
+ /*! \note Load from realtime before taking the global qlock, to avoid blocking all
+ queue operations while waiting for the DB.
+
+ This will be two separate database transactions, so we might
+ see queue parameters as they were before another process
+ changed the queue and member list as it was after the change.
+ Thus we might see an empty member list when a queue is
+ deleted. In practise, this is unlikely to cause a problem. */
+
+ queue_vars = ast_load_realtime("queues", "name", queuename, NULL);
+ if (queue_vars) {
+ member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", queuename, NULL);
+ if (!member_config) {
+ ast_log(LOG_ERROR, "no queue_members defined in your config (extconfig.conf).\n");
+ return NULL;
+ }
+ }
+
+ AST_LIST_LOCK(&queues);
+
+ q = find_queue_by_name_rt(queuename, queue_vars, member_config);
+ if (member_config)
+ ast_config_destroy(member_config);
+ if (queue_vars)
+ ast_variables_destroy(queue_vars);
+
+ AST_LIST_UNLOCK(&queues);
+ }
+ return q;
+}
+
+static int join_queue(char *queuename, struct queue_ent *qe, enum queue_result *reason)
+{
struct ast_call_queue *q;
struct queue_ent *cur, *prev = NULL;
int res = -1;
@@ -896,38 +989,15 @@
int inserted = 0;
enum queue_member_status stat;
- /*! \note Load from realtime before taking the global qlock, to avoid blocking all
- queue operations while waiting for the DB.
-
- This will be two separate database transactions, so we might
- see queue parameters as they were before another process
- changed the queue and member list as it was after the change.
- Thus we might see an empty member list when a queue is
- deleted. In practise, this is unlikely to cause a problem. */
- queue_vars = ast_load_realtime("queues", "name", queuename, NULL);
- if (queue_vars) {
- member_config = ast_load_realtime_multientry("queue_members", "interface LIKE", "%", "queue_name", queuename, NULL);
- if (!member_config) {
- ast_log(LOG_ERROR, "no queue_members defined in your config (extconfig.conf).\n");
- return res;
- }
- }
-
- ast_mutex_lock(&qlock);
- q = find_queue_by_name_rt(queuename, queue_vars, member_config);
- /* Note: If found, find_queue_by_name_rt() returns with q->lock locked. */
- if(member_config)
- ast_config_destroy(member_config);
- if(queue_vars)
- ast_variables_destroy(queue_vars);
-
- if (!q) {
- ast_mutex_unlock(&qlock);
+ q = load_realtime_queue(queuename);
+ if (!q)
return res;
- }
+
+ AST_LIST_LOCK(&queues);
+ ast_mutex_lock(&q->lock);
/* This is our one */
- stat = get_member_status(q);
+ stat = get_member_status(q, qe->max_penalty);
if (!q->joinempty && (stat == QUEUE_NO_MEMBERS))
*reason = QUEUE_JOINEMPTY;
else if ((q->joinempty == QUEUE_EMPTY_STRICT) && (stat == QUEUE_NO_REACHABLE_MEMBERS))
@@ -972,50 +1042,8 @@
#endif
}
ast_mutex_unlock(&q->lock);
- ast_mutex_unlock(&qlock);
+ AST_LIST_UNLOCK(&queues);
return res;
-}
-
-static void free_members(struct ast_call_queue *q, int all)
-{
- /* Free non-dynamic members */
- struct member *curm, *next, *prev;
-
- curm = q->members;
- prev = NULL;
- while(curm) {
- next = curm->next;
- if (all || !curm->dynamic) {
- if (prev)
- prev->next = next;
- else
- q->members = next;
- free(curm);
- } else
- prev = curm;
- curm = next;
- }
-}
-
-static void destroy_queue(struct ast_call_queue *q)
-{
- struct ast_call_queue *cur, *prev = NULL;
-
- ast_mutex_lock(&qlock);
- for (cur = queues; cur; cur = cur->next) {
- if (cur == q) {
- if (prev)
- prev->next = cur->next;
- else
- queues = cur->next;
- } else {
- prev = cur;
- }
- }
- ast_mutex_unlock(&qlock);
- free_members(q, 1);
- ast_mutex_destroy(&q->lock);
- free(q);
}
static int play_file(struct ast_channel *chan, char *filename)
@@ -1225,6 +1253,9 @@
ast_mutex_unlock(&q->lock);
if (q->dead && !q->count) {
/* It's dead and nobody is in it, so kill it */
+ AST_LIST_LOCK(&queues);
+ AST_LIST_REMOVE(&queues, q, list);
+ AST_LIST_UNLOCK(&queues);
destroy_queue(q);
}
}
@@ -1299,7 +1330,7 @@
/* &qlock and &rq->lock already set by try_calling()
* to solve deadlock */
- for (q = queues; q; q = q->next) {
+ AST_LIST_TRAVERSE(&queues, q, list) {
if (q == rq) /* don't check myself, could deadlock */
continue;
ast_mutex_lock(&q->lock);
@@ -1319,7 +1350,6 @@
if (found)
break;
}
- ast_mutex_unlock(&qlock);
return found;
}
@@ -1564,8 +1594,13 @@
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "Playing periodic announcement\n");
+ /* Check to make sure we have a sound file. If not, reset to the first sound file */
+ if (qe->last_periodic_announce_sound >= MAX_PERIODIC_ANNOUNCEMENTS || !strlen(qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound])) {
+ qe->last_periodic_announce_sound = 0;
+ }
+
/* play the announcement */
- res = background_file(qe, qe->chan, qe->parent->sound_periodicannounce);
+ res = background_file(qe, qe->chan, qe->parent->sound_periodicannounce[qe->last_periodic_announce_sound]);
/* Resume Music on Hold */
ast_moh_start(qe->chan, qe->moh);
@@ -1573,6 +1608,9 @@
/* update last_periodic_announce_time */
qe->last_periodic_announce_time = now;
+ /* Update the current periodic announcement to the next announcement */
+ qe->last_periodic_announce_sound++;
+
return res;
}
@@ -1609,6 +1647,7 @@
static struct localuser *wait_for_answer(struct queue_ent *qe, struct localuser *outgoing, int *to, char *digit, int prebusies, int caller_disconnect)
{
char *queue = qe->parent->name;
+ char on[256] = "";
struct localuser *o;
int found;
int numlines;
@@ -1652,6 +1691,7 @@
peer = o;
}
} else if (o->chan && (o->chan == winner)) {
+ ast_copy_string(on, o->member->interface, sizeof(on));
if (!ast_strlen_zero(o->chan->call_forward)) {
char tmpchan[256]="";
char *stuff;
@@ -1701,11 +1741,7 @@
if (in->cid.cid_ani) {
if (o->chan->cid.cid_ani)
free(o->chan->cid.cid_ani);
- o->chan->cid.cid_ani = malloc(strlen(in->cid.cid_ani) + 1);
- if (o->chan->cid.cid_ani)
- strncpy(o->chan->cid.cid_ani, in->cid.cid_ani, strlen(in->cid.cid_ani) + 1);
- else
- ast_log(LOG_WARNING, "Out of memory\n");
+ o->chan->cid.cid_ani = ast_strdup(in->cid.cid_ani);
}
if (o->chan->cid.cid_rdnis)
free(o->chan->cid.cid_rdnis);
@@ -1830,8 +1866,19 @@
}
ast_frfree(f);
}
- if (!*to && (option_verbose > 2))
- ast_verbose( VERBOSE_PREFIX_3 "Nobody picked up in %d ms\n", orig);
+ if (!*to) {
+ if (option_verbose > 2)
+ ast_verbose( VERBOSE_PREFIX_3 "Nobody picked up in %d ms\n", orig);
+ if (qe->parent->autopause) {
+ if (!set_member_paused(qe->parent->name, on, 1)) {
+ if (option_verbose > 2)
+ ast_verbose( VERBOSE_PREFIX_3 "Auto-Pausing Queue Member %s in queue %s since they failed to answer.\n", on, qe->parent->name);
+ } else {
+ if (option_verbose > 2)
+ ast_verbose( VERBOSE_PREFIX_3 "Failed to pause Queue Member %s in queue %s!\n", on, qe->parent->name);
+ }
+ }
+ }
}
return peer;
@@ -1846,7 +1893,7 @@
/* Atomically read the parent head -- does not need a lock */
ch = qe->parent->head;
/* If we are now at the top of the head, break out */
- if (ch == qe) {
+ if ((ch == qe) || (qe->parent->autofill)) {
if (option_debug)
ast_log(LOG_DEBUG, "It's our turn (%s).\n", qe->chan->name);
res = 1;
@@ -1876,7 +1923,7 @@
break;
}
- stat = get_member_status(qe->parent);
+ stat = get_member_status(qe->parent, qe->max_penalty);
/* leave the queue if no agents, if enabled */
if (qe->parent->leavewhenempty && (stat == QUEUE_NO_MEMBERS)) {
@@ -1933,6 +1980,9 @@
static int calc_metric(struct ast_call_queue *q, struct member *mem, int pos, struct queue_ent *qe, struct localuser *tmp)
{
+ if (mem->penalty > qe->max_penalty)
+ return -1;
+
switch (q->strategy) {
case QUEUE_STRATEGY_RINGALL:
/* Everyone equal, except for penalty */
@@ -2041,7 +2091,7 @@
/* Hold the lock while we setup the outgoing calls */
if (use_weight)
- ast_mutex_lock(&qlock);
+ AST_LIST_LOCK(&queues);
ast_mutex_lock(&qe->parent->lock);
if (option_debug)
ast_log(LOG_DEBUG, "%s is trying to call a queue member.\n",
@@ -2054,15 +2104,12 @@
announce = announceoverride;
while(cur) {
- tmp = malloc(sizeof(*tmp));
- if (!tmp) {
+ if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
ast_mutex_unlock(&qe->parent->lock);
if (use_weight)
- ast_mutex_unlock(&qlock);
- ast_log(LOG_WARNING, "Out of memory\n");
+ AST_LIST_UNLOCK(&queues);
goto out;
}
- memset(tmp, 0, sizeof(*tmp));
tmp->stillgoing = -1;
if (option_debug) {
if (url)
@@ -2085,15 +2132,18 @@
}
/* Special case: If we ring everyone, go ahead and ring them, otherwise
just calculate their metric for the appropriate strategy */
- calc_metric(qe->parent, cur, x++, qe, tmp);
- /* Put them in the list of outgoing thingies... We're ready now.
- XXX If we're forcibly removed, these outgoing calls won't get
- hung up XXX */
- tmp->next = outgoing;
- outgoing = tmp;
- /* If this line is up, don't try anybody else */
- if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP))
- break;
+ if (!calc_metric(qe->parent, cur, x++, qe, tmp)) {
+ /* Put them in the list of outgoing thingies... We're ready now.
+ XXX If we're forcibly removed, these outgoing calls won't get
+ hung up XXX */
+ tmp->next = outgoing;
+ outgoing = tmp;
+ /* If this line is up, don't try anybody else */
+ if (outgoing->chan && (outgoing->chan->_state == AST_STATE_UP))
+ break;
+ } else {
+ free(tmp);
+ }
cur = cur->next;
}
@@ -2104,7 +2154,7 @@
ring_one(qe, outgoing, &numbusies);
ast_mutex_unlock(&qe->parent->lock);
if (use_weight)
- ast_mutex_unlock(&qlock);
+ AST_LIST_UNLOCK(&queues);
lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT));
ast_mutex_lock(&qe->parent->lock);
if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) {
@@ -2117,7 +2167,7 @@
peer = NULL;
if (!peer) {
if (to) {
- /* Musta gotten hung up */
+ /* Must gotten hung up */
record_abandoned(qe);
res = -1;
} else {
@@ -2284,7 +2334,7 @@
ast_hangup(peer);
update_queue(qe->parent, member);
if (bridge == 0)
- res = 1; /* JDG: bridge successfull, leave app_queue */
+ res = 1; /* JDG: bridge successfully, leave app_queue */
else
res = bridge; /* bridge error, stay in the queue */
}
@@ -2314,7 +2364,7 @@
}
-/* Dump all members in a specific queue to the databse
+/* Dump all members in a specific queue to the database
*
* <pm_family>/<queuename> = <interface>;<penalty>;<paused>[|...]
*
@@ -2359,8 +2409,8 @@
struct member *last_member, *look;
int res = RES_NOSUCHQUEUE;
- ast_mutex_lock(&qlock);
- for (q = queues ; q ; q = q->next) {
+ AST_LIST_LOCK(&queues);
+ AST_LIST_TRAVERSE(&queues, q, list) {
ast_mutex_lock(&q->lock);
if (!strcmp(q->name, queuename)) {
if ((last_member = interface_exists(q, interface))) {
@@ -2394,7 +2444,7 @@
}
ast_mutex_unlock(&q->lock);
}
- ast_mutex_unlock(&qlock);
+ AST_LIST_UNLOCK(&queues);
return res;
}
@@ -2404,45 +2454,46 @@
struct member *new_member;
int res = RES_NOSUCHQUEUE;
- ast_mutex_lock(&qlock);
- for (q = queues ; q ; q = q->next) {
+ /* \note Ensure the appropriate realtime queue is loaded. Note that this
+ * short-circuits if the queue is already in memory. */
+ q = load_realtime_queue(queuename);
+
+ AST_LIST_LOCK(&queues);
+
+ if (q) {
ast_mutex_lock(&q->lock);
- if (!strcmp(q->name, queuename)) {
- if (interface_exists(q, interface) == NULL) {
- new_member = create_queue_member(interface, penalty, paused);
-
- if (new_member != NULL) {
- new_member->dynamic = 1;
- new_member->next = q->members;
- q->members = new_member;
- manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
- "Queue: %s\r\n"
- "Location: %s\r\n"
- "Membership: %s\r\n"
- "Penalty: %d\r\n"
- "CallsTaken: %d\r\n"
- "LastCall: %d\r\n"
- "Status: %d\r\n"
- "Paused: %d\r\n",
- q->name, new_member->interface, new_member->dynamic ? "dynamic" : "static",
- new_member->penalty, new_member->calls, (int)new_member->lastcall, new_member->status, new_member->paused);
+ if (interface_exists(q, interface) == NULL) {
+ new_member = create_queue_member(interface, penalty, paused);
+
+ if (new_member != NULL) {
+ new_member->dynamic = 1;
+ new_member->next = q->members;
+ q->members = new_member;
+ manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
+ "Queue: %s\r\n"
+ "Location: %s\r\n"
+ "Membership: %s\r\n"
+ "Penalty: %d\r\n"
+ "CallsTaken: %d\r\n"
+ "LastCall: %d\r\n"
+ "Status: %d\r\n"
+ "Paused: %d\r\n",
+ q->name, new_member->interface, new_member->dynamic ? "dynamic" : "static",
+ new_member->penalty, new_member->calls, (int)new_member->lastcall, new_member->status, new_member->paused);
- if (dump)
- dump_queue_members(q);
-
- res = RES_OKAY;
- } else {
- res = RES_OUTOFMEMORY;
- }
+ if (dump)
+ dump_queue_members(q);
+
+ res = RES_OKAY;
} else {
- res = RES_EXISTS;
- }
- ast_mutex_unlock(&q->lock);
- break;
+ res = RES_OUTOFMEMORY;
+ }
+ } else {
+ res = RES_EXISTS;
}
ast_mutex_unlock(&q->lock);
}
- ast_mutex_unlock(&qlock);
+ AST_LIST_UNLOCK(&queues);
return res;
}
@@ -2457,8 +2508,8 @@
if (ast_strlen_zero(queuename))
ast_queue_log("NONE", "NONE", interface, (paused ? "PAUSEALL" : "UNPAUSEALL"), "%s", "");
- ast_mutex_lock(&qlock);
- for (q = queues ; q ; q = q->next) {
+ AST_LIST_LOCK(&queues);
+ AST_LIST_TRAVERSE(&queues, q, list) {
ast_mutex_lock(&q->lock);
if (ast_strlen_zero(queuename) || !strcasecmp(q->name, queuename)) {
if ((mem = interface_exists(q, interface))) {
@@ -2481,7 +2532,7 @@
}
ast_mutex_unlock(&q->lock);
}
- ast_mutex_unlock(&qlock);
+ AST_LIST_UNLOCK(&queues);
if (found)
return RESULT_SUCCESS;
@@ -2505,7 +2556,7 @@
struct ast_call_queue *cur_queue;
char queue_data[PM_MAX_LEN];
- ast_mutex_lock(&qlock);
+ AST_LIST_LOCK(&queues);
/* Each key in 'pm_family' is the name of a queue */
db_tree = ast_db_gettree(pm_family, NULL);
@@ -2513,13 +2564,11 @@
queue_name = entry->key + strlen(pm_family) + 2;
- cur_queue = queues;
- while (cur_queue) {
+ AST_LIST_TRAVERSE(&queues, cur_queue, list) {
ast_mutex_lock(&cur_queue->lock);
if (!strcmp(queue_name, cur_queue->name))
break;
ast_mutex_unlock(&cur_queue->lock);
- cur_queue = cur_queue->next;
}
if (!cur_queue) {
@@ -2543,7 +2592,7 @@
paused_tok = strsep(&member, ";");
if (!penalty_tok) {
- ast_log(LOG_WARNING, "Error parsing persisent member string for '%s' (penalty)\n", queue_name);
+ ast_log(LOG_WARNING, "Error parsing persistent member string for '%s' (penalty)\n", queue_name);
break;
}
penalty = strtol(penalty_tok, NULL, 10);
@@ -2572,9 +2621,9 @@
}
}
- ast_mutex_unlock(&qlock);
+ AST_LIST_UNLOCK(&queues);
if (db_tree) {
- ast_log(LOG_NOTICE, "Queue members sucessfully reloaded from database.\n");
+ ast_log(LOG_NOTICE, "Queue members successfully reloaded from database.\n");
ast_db_freetree(db_tree);
}
}
@@ -2595,15 +2644,12 @@
return -1;
}
+ if (!(parse = ast_strdupa(data)))
+ return -1;
+
+ AST_STANDARD_APP_ARGS(args, parse);
+
LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
if (args.options) {
if (strchr(args.options, 'j'))
@@ -2651,15 +2697,12 @@
return -1;
}
+ if (!(parse = ast_strdupa(data)))
+ return -1;
+
+ AST_STANDARD_APP_ARGS(args, parse);
+
LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
if (args.options) {
if (strchr(args.options, 'j'))
@@ -2709,15 +2752,12 @@
return -1;
}
+ if (!(parse = ast_strdupa(data)))
+ return -1;
+
+ AST_STANDARD_APP_ARGS(args, parse);
+
LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
if (ast_strlen_zero(args.interface)) {
args.interface = ast_strdupa(chan->name);
@@ -2777,15 +2817,12 @@
return -1;
}
+ if (!(parse = ast_strdupa(data)))
+ return -1;
+
+ AST_STANDARD_APP_ARGS(args, parse);
+
LOCAL_USER_ADD(u);
-
- if (!(parse = ast_strdupa(data))) {
- ast_log(LOG_WARNING, "Memory Error!\n");
- LOCAL_USER_REMOVE(u);
- return -1;
- }
-
- AST_STANDARD_APP_ARGS(args, parse);
if (ast_strlen_zero(args.interface)) {
args.interface = ast_strdupa(chan->name);
@@ -2839,20 +2876,24 @@
int res=-1;
int ringing=0;
struct localuser *u;
- char *queuename;
- char info[512];
- char *info_ptr = info;
- char *options = NULL;
- char *url = NULL;
- char *announceoverride = NULL;
const char *user_priority;
+ const char *max_penalty_str;
int prio;
- char *queuetimeoutstr = NULL;
+ int max_penalty;
enum queue_result reason = QUEUE_UNKNOWN;
/* whether to exit Queue application after the timeout hits */
int go_on = 0;
+ char *parse;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(queuename);
+ AST_APP_ARG(options);
+ AST_APP_ARG(url);
+ AST_APP_ARG(announceoverride);
+ AST_APP_ARG(queuetimeoutstr);
+ );
+
/* Our queue entry */
struct queue_ent qe;
@@ -2860,24 +2901,23 @@
ast_log(LOG_WARNING, "Queue requires an argument: queuename[|options[|URL][|announceoverride][|timeout]]\n");
return -1;
}
+
+ parse = ast_strdupa(data);
+ if (!parse) {
+ ast_log(LOG_ERROR, "Out of memory!\n");
+ return -1;
+ }
+ AST_STANDARD_APP_ARGS(args, parse);
LOCAL_USER_ADD(u);
/* Setup our queue entry */
memset(&qe, 0, sizeof(qe));
qe.start = time(NULL);
-
- /* Parse our arguments XXX Check for failure XXX */
- ast_copy_string(info, (char *) data, sizeof(info));
- queuename = strsep(&info_ptr, "|");
- options = strsep(&info_ptr, "|");
- url = strsep(&info_ptr, "|");
- announceoverride = strsep(&info_ptr, "|");
- queuetimeoutstr = info_ptr;
/* set the expire time based on the supplied timeout; */
- if (queuetimeoutstr)
- qe.expire = qe.start + atoi(queuetimeoutstr);
+ if (args.queuetimeoutstr)
+ qe.expire = qe.start + atoi(args.queuetimeoutstr);
else
qe.expire = 0;
@@ -2899,20 +2939,37 @@
prio = 0;
}
- if (options && (strchr(options, 'r')))
+ /* Get the maximum penalty from the variable ${QUEUE_MAX_PENALTY} */
+ if ((max_penalty_str = pbx_builtin_getvar_helper(chan, "QUEUE_MAX_PENALTY"))) {
+ if (sscanf(max_penalty_str, "%d", &max_penalty) == 1) {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "%s: Got max penalty %d from ${QUEUE_MAX_PENALTY}.\n",
+ chan->name, max_penalty);
+ } else {
+ ast_log(LOG_WARNING, "${QUEUE_MAX_PENALTY}: Invalid value (%s), channel %s.\n",
+ max_penalty_str, chan->name);
+ max_penalty = 0;
+ }
+ } else {
+ max_penalty = 0;
+ }
+
+ if (args.options && (strchr(args.options, 'r')))
ringing = 1;
if (option_debug)
ast_log(LOG_DEBUG, "queue: %s, options: %s, url: %s, announce: %s, expires: %ld, priority: %d\n",
- queuename, options, url, announceoverride, (long)qe.expire, (int)prio);
+ args.queuename, args.options, args.url, args.announceoverride, (long)qe.expire, prio);
qe.chan = chan;
- qe.prio = (int)prio;
+ qe.prio = prio;
+ qe.max_penalty = max_penalty;
qe.last_pos_said = 0;
qe.last_pos = 0;
qe.last_periodic_announce_time = time(NULL);
- if (!join_queue(queuename, &qe, &reason)) {
- ast_queue_log(queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", url ? url : "",
+ qe.last_periodic_announce_sound = 0;
+ if (!join_queue(args.queuename, &qe, &reason)) {
+ ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ENTERQUEUE", "%s|%s", args.url ? args.url : "",
chan->cid.cid_num ? chan->cid.cid_num : "");
check_turns:
if (ringing) {
@@ -2928,9 +2985,9 @@
if (res < 0) {
/* Record this abandoned call */
record_abandoned(&qe);
- ast_queue_log(queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
+ ast_queue_log(args.queuename, chan->uniqueid, "NONE", "ABANDON", "%d|%d|%ld", qe.pos, qe.opos, (long)time(NULL) - qe.start);
if (option_verbose > 2) {
- ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s while waiting their turn\n", queuename);
+ ast_verbose(VERBOSE_PREFIX_3 "User disconnected from queue %s while waiting their turn\n", args.queuename);
res = -1;
}
break;
@@ -2938,7 +2995,7 @@
if (!res)
break;
if (valid_exit(&qe, res)) {
- ast_queue_log(queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
+ ast_queue_log(args.queuename, chan->uniqueid, "NONE", "EXITWITHKEY", "%s|%d", qe.digits, qe.pos);
break;
}
}
@@ -2957,7 +3014,7 @@
record_abandoned(&qe);
reason = QUEUE_TIMEOUT;
res = 0;
- ast_queue_log(queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
+ ast_queue_log(args.queuename, chan->uniqueid,"NONE", "EXITWITHTIMEOUT", "%d", qe.pos);
break;
}
[... 3168 lines stripped ...]
More information about the svn-commits
mailing list