A big one...

This is the merge of the forward-loop branch. The main change here is that call-forwards can no longer loop.
This is accomplished by creating a datastore on the calling channel which has a linked list of all devices
dialed. If a forward happens, then the local channel which is created inherits the datastore. If, through this
progression of forwards and datastore inheritance, a device is attempted to be dialed a second time, it will simply
be skipped and a warning message will be printed to the CLI. After the dialing has been completed, the datastore
is detached from the channel and destroyed.

This change also introduces some side effects to the code which I shall enumerate here:

1. Datastore inheritance has been backported from trunk into 1.4
2. A large chunk of code has been removed from app_dial. This chunk is the section of code
   which handles the call forward case after the channel has been requested but before it has
   been called. This was removed because call-forwarding still works fine without it, it makes the
   code less error-prone should it need changing, and it made this set of changes much less painful
   to just have the forwarding handled in one place in each module.
3. Two new files, global_datastores.h and .c have been added. These are necessary since the datastore
   which is attached to the channel may be created and attached in either app_dial or app_queue, so they
   need a common place to find the datastore info. This approach was taken in case similar datastores are
   needed in the future, there will be a common place to add them.


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@90735 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Michelson
2007-12-03 23:12:17 +00:00
parent 8315785663
commit 7b052b78e1
8 changed files with 267 additions and 73 deletions

View File

@@ -93,6 +93,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/devicestate.h"
#include "asterisk/stringfields.h"
#include "asterisk/astobj2.h"
#include "asterisk/global_datastores.h"
enum {
QUEUE_STRATEGY_RINGALL = 0,
@@ -2133,6 +2134,7 @@ static struct callattempt *wait_for_answer(struct queue_ent *qe, struct callatte
numnochan++;
} else {
ast_channel_inherit_variables(in, o->chan);
ast_channel_datastore_inherit(in, o->chan);
if (o->chan->cid.cid_num)
free(o->chan->cid.cid_num);
o->chan->cid.cid_num = ast_strdup(in->cid.cid_num);
@@ -2500,6 +2502,7 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
int forwardsallowed = 1;
int callcompletedinsl;
struct ao2_iterator memi;
struct ast_datastore *datastore = ast_channel_datastore_find(qe->chan, &dialed_interface_info, NULL);
memset(&bridge_config, 0, sizeof(bridge_config));
time(&now);
@@ -2555,7 +2558,9 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
memi = ao2_iterator_init(qe->parent->members, 0);
while ((cur = ao2_iterator_next(&memi))) {
struct callattempt *tmp = ast_calloc(1, sizeof(*tmp));
struct ast_dialed_interface *di;
int dialed = 0;
AST_LIST_HEAD(, ast_dialed_interface) *dialed_interfaces;
if (!tmp) {
ao2_ref(cur, -1);
ast_mutex_unlock(&qe->parent->lock);
@@ -2563,6 +2568,49 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
AST_LIST_UNLOCK(&queues);
goto out;
}
if (!datastore) {
if(!(datastore = ast_channel_datastore_alloc(&dialed_interface_info, NULL))) {
ao2_ref(cur, -1);
ast_mutex_unlock(&qe->parent->lock);
if(use_weight)
AST_LIST_UNLOCK(&queues);
free(tmp);
goto out;
}
datastore->inheritance = DATASTORE_INHERIT_FOREVER;
dialed_interfaces = ast_calloc(1, sizeof(*dialed_interfaces));
datastore->data = dialed_interfaces;
AST_LIST_HEAD_INIT(dialed_interfaces);
ast_channel_datastore_add(qe->chan, datastore);
} else
dialed_interfaces = datastore->data;
AST_LIST_LOCK(dialed_interfaces);
AST_LIST_TRAVERSE(dialed_interfaces, di, list) {
/* XXX case sensitive ?? */
if(!strcasecmp(cur->interface, di->interface)) {
dialed = 1;
break;
}
}
if (!dialed && strncasecmp(cur->interface, "Local/", 6)) {
if(!(di = ast_calloc(1, sizeof(*di) + strlen(cur->interface)))) {
ao2_ref(cur, -1);
AST_LIST_UNLOCK(dialed_interfaces);
ast_mutex_unlock(&qe->parent->lock);
if(use_weight)
AST_LIST_UNLOCK(&queues);
free(tmp);
goto out;
}
strcpy(di->interface, cur->interface);
AST_LIST_INSERT_TAIL(dialed_interfaces, di, list);
} else {
AST_LIST_UNLOCK(dialed_interfaces);
ast_log(LOG_DEBUG, "Skipping dialing interface '%s' since it has already been dialed\n", di->interface);
free(tmp);
continue;
}
AST_LIST_UNLOCK(dialed_interfaces);
tmp->stillgoing = -1;
tmp->member = cur;
tmp->oldstatus = cur->status;
@@ -2593,6 +2641,8 @@ static int try_calling(struct queue_ent *qe, const char *options, char *announce
if (use_weight)
AST_LIST_UNLOCK(&queues);
lpeer = wait_for_answer(qe, outgoing, &to, &digit, numbusies, ast_test_flag(&(bridge_config.features_caller), AST_FEATURE_DISCONNECT), forwardsallowed);
ast_channel_datastore_remove(qe->chan, datastore);
ast_channel_datastore_free(datastore);
ast_mutex_lock(&qe->parent->lock);
if (qe->parent->strategy == QUEUE_STRATEGY_RRMEMORY) {
store_next(qe, outgoing);