[asterisk-commits] mmichelson: branch mmichelson/forward-loop r86879 - in /team/mmichelson/forwa...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Oct 23 14:52:59 CDT 2007
Author: mmichelson
Date: Tue Oct 23 14:52:58 2007
New Revision: 86879
URL: http://svn.digium.com/view/asterisk?view=rev&rev=86879
Log:
This is my first fix for the forwarding loop issue.
It is unoptimized and probably has some holes in it, but it otherwise
works in tests I've made with dialing. The next step is to change to using
a datastore instead of modifying the channel structure as I have done here.
Modified:
team/mmichelson/forward-loop/apps/app_dial.c
team/mmichelson/forward-loop/channels/chan_local.c
team/mmichelson/forward-loop/include/asterisk/channel.h
team/mmichelson/forward-loop/main/channel.c
Modified: team/mmichelson/forward-loop/apps/app_dial.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/forward-loop/apps/app_dial.c?view=diff&rev=86879&r1=86878&r2=86879
==============================================================================
--- team/mmichelson/forward-loop/apps/app_dial.c (original)
+++ team/mmichelson/forward-loop/apps/app_dial.c Tue Oct 23 14:52:58 2007
@@ -500,9 +500,20 @@
} else {
/* Setup parameters */
if ((c = o->chan = ast_request(tech, in->nativeformats, stuff, &cause))) {
+ struct ast_dialed_interface *cur;
+ ast_log(LOG_DEBUG, "Requester 2 got channel %p\n", c);
+ ast_log(LOG_DEBUG, "Is it bridged? %s %p\n", ast_bridged_channel(c) ? "Yes" : "No", ast_bridged_channel(c));
if (single)
ast_channel_make_compatible(o->chan, in);
ast_channel_inherit_variables(in, o->chan);
+ AST_LIST_LOCK(&in->dialed_interfaces);
+ AST_LIST_TRAVERSE(&in->dialed_interfaces, cur, list) {
+ struct ast_dialed_interface *tmp = ast_calloc(1, sizeof(*tmp));
+ ast_copy_string(tmp->interface, cur->interface, sizeof(tmp->interface));
+ ast_log(LOG_DEBUG, "Copying '%s' to the outgoing channel '%s': %p\n", cur->interface, c->name, c);
+ AST_LIST_INSERT_TAIL(&c->dialed_interfaces, tmp, list);
+ }
+ AST_LIST_UNLOCK(&in->dialed_interfaces);
} else
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
}
@@ -1088,6 +1099,9 @@
/* Get a technology/[device:]number pair */
char *number = cur;
char *tech = strsep(&number, "/");
+ /* find if we already dialed this interface */
+ int dialed = 0;
+ struct ast_dialed_interface *cur;
if (!number) {
ast_log(LOG_WARNING, "Dial argument takes format (technology/[device:]number1)\n");
goto out;
@@ -1115,7 +1129,46 @@
free(tmp);
continue;
}
+ ast_log(LOG_DEBUG, "Dialing from interface %s: %p\n", chan->name, chan);
+ AST_LIST_LOCK(&chan->dialed_interfaces);
+ AST_LIST_TRAVERSE(&chan->dialed_interfaces, cur, list) {
+ char *dash;
+ char *name = ast_strdupa(tmp->chan->name);
+ if ((dash = strchr(name, '-')))
+ *dash = '\0';
+ /* XXX case sensitive??? */
+ ast_log(LOG_DEBUG, "Checking interface '%s' against '%s'\n", cur->interface, name);
+ if(!strcasecmp(cur->interface, name)) {
+ dialed = 1;
+ break;
+ }
+ }
+ AST_LIST_UNLOCK(&chan->dialed_interfaces);
+ if(!dialed) {
+ char *blah;
+ char *tech;
+ char *interface = ast_strdupa(tmp->chan->name);
+ if ((blah = strchr(interface, '-')))
+ *blah = '\0';
+ tech = ast_strdupa(interface);
+ if ((blah = strchr(tech, '/')))
+ *blah = '\0';
+ if (strcasecmp(tech, "Local")) {
+ if(!(cur = ast_calloc(1, sizeof(*cur))))
+ goto out;
+ ast_copy_string(cur->interface, interface, sizeof(cur->interface));
+ ast_log(LOG_DEBUG, "Adding interface '%s' to the list of dialed interfaces\n", cur->interface);
+ AST_LIST_INSERT_TAIL(&chan->dialed_interfaces, cur, list);
+ }
+ } else {
+ ast_log(LOG_DEBUG, "Skipping dialing interface '%s' since it has already been dialed\n", cur->interface);
+ ast_hangup(tmp->chan);
+ tmp->chan = NULL;
+ free(tmp);
+ continue;
+ }
pbx_builtin_setvar_helper(tmp->chan, "DIALEDPEERNUMBER", numsubst);
+#if 0
if (!ast_strlen_zero(tmp->chan->call_forward)) {
char tmpchan[256];
char *stuff;
@@ -1142,6 +1195,7 @@
ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' prevented.\n", chan->name, tech, stuff);
} else {
tmp->chan = ast_request(tech, chan->nativeformats, stuff, &cause);
+ ast_log(LOG_DEBUG, "Requester 1 got channel %p\n", tmp->chan);
}
if (!tmp->chan)
ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause);
@@ -1160,6 +1214,7 @@
continue;
}
}
+#endif
/* Setup outgoing SDP to match incoming one */
ast_rtp_make_compatible(tmp->chan, chan, !outgoing && !rest);
Modified: team/mmichelson/forward-loop/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/forward-loop/channels/chan_local.c?view=diff&rev=86879&r1=86878&r2=86879
==============================================================================
--- team/mmichelson/forward-loop/channels/chan_local.c (original)
+++ team/mmichelson/forward-loop/channels/chan_local.c Tue Oct 23 14:52:58 2007
@@ -436,6 +436,7 @@
struct local_pvt *p = ast->tech_pvt;
int res;
struct ast_var_t *varptr = NULL, *new;
+ struct ast_dialed_interface *di;
size_t len, namelen;
if (!p)
@@ -466,6 +467,11 @@
new->value = &(new->name[0]) + namelen + 1;
AST_LIST_INSERT_TAIL(&p->chan->varshead, new, entries);
}
+ }
+ AST_LIST_TRAVERSE(&p->owner->dialed_interfaces, di, list) {
+ struct ast_dialed_interface *tmp = ast_calloc(1, sizeof(*tmp));
+ ast_copy_string(tmp->interface, di->interface, sizeof(tmp->interface));
+ AST_LIST_INSERT_TAIL(&p->chan->dialed_interfaces, tmp, list);
}
/* Start switch on sub channel */
Modified: team/mmichelson/forward-loop/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/mmichelson/forward-loop/include/asterisk/channel.h?view=diff&rev=86879&r1=86878&r2=86879
==============================================================================
--- team/mmichelson/forward-loop/include/asterisk/channel.h (original)
+++ team/mmichelson/forward-loop/include/asterisk/channel.h Tue Oct 23 14:52:58 2007
@@ -176,6 +176,11 @@
int cid_tns; /*!< Callerid Transit Network Select */
};
+struct ast_dialed_interface {
+ char interface[80];
+ AST_LIST_ENTRY(ast_dialed_interface) list;
+};
+
/*! \brief
Structure to describe a channel "technology", ie a channel driver
See for examples:
@@ -436,6 +441,8 @@
char emulate_dtmf_digit; /*!< Digit being emulated */
unsigned int emulate_dtmf_duration; /*!< Number of ms left to emulate DTMF for */
struct timeval dtmf_tv; /*!< The time that an in process digit began, or the last digit ended */
+
+ AST_LIST_HEAD(dialed_interfaces, ast_dialed_interface) dialed_interfaces;
/*! \brief Data stores on the channel */
AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores;
Modified: team/mmichelson/forward-loop/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/mmichelson/forward-loop/main/channel.c?view=diff&rev=86879&r1=86878&r2=86879
==============================================================================
--- team/mmichelson/forward-loop/main/channel.c (original)
+++ team/mmichelson/forward-loop/main/channel.c Tue Oct 23 14:52:58 2007
@@ -888,6 +888,9 @@
AST_LIST_INSERT_HEAD(&channels, tmp, chan_list);
AST_LIST_UNLOCK(&channels);
+ ast_log(LOG_DEBUG, "Created new channel %p\n", tmp);
+ ast_backtrace();
+
return tmp;
}
@@ -1194,6 +1197,7 @@
struct ast_frame *f;
struct varshead *headp;
struct ast_datastore *datastore = NULL;
+ struct ast_dialed_interface *di = NULL;
char name[AST_CHANNEL_NAME];
headp=&chan->varshead;
@@ -1259,6 +1263,9 @@
while ((vardata = AST_LIST_REMOVE_HEAD(headp, entries)))
ast_var_delete(vardata);
+
+ while ((di = AST_LIST_REMOVE_HEAD(&chan->dialed_interfaces, list)))
+ free(di);
ast_app_group_discard(chan);
More information about the asterisk-commits
mailing list