[asterisk-commits] pabelanger: branch pabelanger/issue18183 r292781 - /team/pabelanger/issue1818...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Oct 22 14:41:54 CDT 2010
Author: pabelanger
Date: Fri Oct 22 14:41:51 2010
New Revision: 292781
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=292781
Log:
realtime iax2 working again.
Will need to review all code changes here. Removed, what looks to be
redundant code, from realtime_peer. Plus various formatting.
Also include some TODO comments.
Modified:
team/pabelanger/issue18183/channels/chan_iax2.c
Modified: team/pabelanger/issue18183/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/pabelanger/issue18183/channels/chan_iax2.c?view=diff&rev=292781&r1=292780&r2=292781
==============================================================================
--- team/pabelanger/issue18183/channels/chan_iax2.c (original)
+++ team/pabelanger/issue18183/channels/chan_iax2.c Fri Oct 22 14:41:51 2010
@@ -1691,8 +1691,9 @@
peer = ao2_find(peers, &tmp_peer, OBJ_POINTER);
/* Now go for realtime if applicable */
- if(!peer && realtime)
+ if (!peer && realtime) {
peer = realtime_peer(name, NULL);
+ }
return peer;
}
@@ -4346,41 +4347,15 @@
}
}
}
- if (!var)
+ if (!var) {
return NULL;
+ }
peer = build_peer(peername, var, NULL, ast_test_flag64((&globalflags), IAX_RTCACHEFRIENDS) ? 0 : 1);
-
+ ast_variables_destroy(var);
if (!peer) {
- ast_variables_destroy(var);
return NULL;
}
-
- for (tmp = var; tmp; tmp = tmp->next) {
- /* Make sure it's not a user only... */
- if (!strcasecmp(tmp->name, "type")) {
- if (strcasecmp(tmp->value, "friend") &&
- strcasecmp(tmp->value, "peer")) {
- /* Whoops, we weren't supposed to exist! */
- peer = peer_unref(peer);
- break;
- }
- } else if (!strcasecmp(tmp->name, "regseconds")) {
- ast_get_time_t(tmp->value, ®seconds, 0, NULL);
- } else if (!strcasecmp(tmp->name, "ipaddr")) {
- ast_sockaddr_parse(&peer->addr, tmp->value, PARSE_PORT_IGNORE);
- } else if (!strcasecmp(tmp->name, "port")) {
- ast_sockaddr_set_port(&peer->addr, atoi(tmp->value));
- } else if (!strcasecmp(tmp->name, "host")) {
- if (!strcasecmp(tmp->value, "dynamic"))
- dynamic = 1;
- }
- }
-
- ast_variables_destroy(var);
-
- if (!peer)
- return NULL;
if (ast_test_flag64((&globalflags), IAX_RTCACHEFRIENDS)) {
ast_copy_flags64(peer, &globalflags, IAX_RTAUTOCLEAR|IAX_RTCACHEFRIENDS);
@@ -4392,12 +4367,14 @@
}
}
peer->expire = iax2_sched_add(sched, (global_rtautoclear) * 1000, expire_registry, peer_ref(peer));
- if (peer->expire == -1)
+ if (peer->expire == -1) {
peer_unref(peer);
+ }
}
ao2_link(peers, peer);
- if (ast_test_flag64(peer, IAX_DYNAMIC))
+ if (ast_test_flag64(peer, IAX_DYNAMIC)) {
reg_source_db(peer);
+ }
} else {
ast_set_flag64(peer, IAX_TEMPONLY);
}
@@ -4543,6 +4520,7 @@
sin->sin_family = AF_INET;
if (!(peer = find_peer(peername, 1))) {
+ast_log(LOG_WARNING, "No peer, lets check");
struct ast_sockaddr sin_tmp;
cai->found = 0;
@@ -4612,7 +4590,6 @@
goto return_unref;
}
}
-
if (peer_addr.sin_addr.s_addr) {
sin->sin_addr = peer_addr.sin_addr;
sin->sin_port = peer_addr.sin_port;
@@ -4620,7 +4597,6 @@
sin->sin_addr = peer->defaddr.sin_addr;
sin->sin_port = peer->defaddr.sin_port;
}
-
res = 0;
return_unref:
@@ -5011,6 +4987,7 @@
ast_log(LOG_WARNING, "No peer provided in the IAX2 dial string '%s'\n", dest);
return -1;
}
+
if (!pds.exten) {
pds.exten = defaultrdest;
}
@@ -5039,8 +5016,9 @@
/* Keep track of the context for outgoing calls too */
ast_copy_string(c->context, cai.context, sizeof(c->context));
- if (pds.port)
+ if (pds.port) {
sin.sin_port = htons(atoi(pds.port));
+ }
l = c->connected.id.number.valid ? c->connected.id.number.str : NULL;
n = c->connected.id.name.valid ? c->connected.id.name.str : NULL;
@@ -5152,8 +5130,9 @@
}
} else
ast_log(LOG_WARNING, "OSP token is too long\n");
- } else if (iaxdebug)
+ } else if (iaxdebug) {
ast_debug(1, "OSP token is undefined\n");
+ }
/* send the command using the appropriate socket for this peer */
iaxs[callno]->sockfd = cai.sockfd;
@@ -12251,6 +12230,20 @@
ast_string_field_free_memory(peer);
}
+/*! \brief converts ascii port to int representation. If no
+ * pt buffer is provided or the pt has errors when being converted
+ * to an int value, the port provided as the standard is used.
+ */
+/* TODO: Copied from chan_sip.c, convert to ast_ function. */
+unsigned int port_str2int(const char *pt, unsigned int standard)
+{
+ int port = standard;
+ if (ast_strlen_zero(pt) || (sscanf(pt, "%30d", &port) != 1) || (port < 1) || (port > 65535)) {
+ port = standard;
+ }
+ return port;
+}
+
/*! \brief Create peer structure based on configuration */
static struct iax2_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int temponly)
{
@@ -12265,8 +12258,9 @@
if (!temponly) {
peer = ao2_find(peers, &tmp_peer, OBJ_POINTER);
- if (peer && !ast_test_flag64(peer, IAX_DELME))
+ if (peer && !ast_test_flag64(peer, IAX_DELME)) {
firstpass = 0;
+ }
}
if (peer) {
@@ -12280,8 +12274,9 @@
peer->expire = -1;
peer->pokeexpire = -1;
peer->sockfd = defaultsockfd;
- if (ast_string_field_init(peer, 32))
+ if (ast_string_field_init(peer, 32)) {
peer = peer_unref(peer);
+ }
}
if (peer) {
@@ -12292,6 +12287,9 @@
ast_string_field_set(peer,secret,"");
if (!found) {
ast_string_field_set(peer, name, name);
+ /* TODO: Why do we need to set this? */
+ peer->addr.ss.ss_family = AF_INET;
+ peer->addr.len = sizeof(struct sockaddr_in);
ast_sockaddr_set_port(&peer->addr, IAX_DEFAULT_PORTNO);
peer->expiry = min_reg_expire;
}
@@ -12316,7 +12314,7 @@
v = alt;
alt = NULL;
}
- while(v) {
+ while (v) {
if (!strcasecmp(v->name, "secret")) {
ast_string_field_set(peer, secret, v->value);
} else if (!strcasecmp(v->name, "mailbox")) {
@@ -12358,8 +12356,9 @@
ast_set_flags_to64(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_TRANSFERMEDIA);
} else if (ast_true(v->value)) {
ast_set_flags_to64(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, 0);
- } else
+ } else {
ast_set_flags_to64(peer, IAX_NOTRANSFER|IAX_TRANSFERMEDIA, IAX_NOTRANSFER);
+ }
} else if (!strcasecmp(v->name, "jitterbuffer")) {
ast_set2_flag64(peer, ast_true(v->value), IAX_USEJITTERBUF);
} else if (!strcasecmp(v->name, "forcejitterbuffer")) {
@@ -12369,8 +12368,7 @@
/* They'll register with us */
ast_set_flag64(peer, IAX_DYNAMIC);
if (!found) {
- /* Initialize stuff iff we're not found, otherwise
- we keep going with what we had */
+ /* Initialize stuff iff we're not found, otherwise we keep going with what we had */
if (ast_sockaddr_port(&peer->addr)) {
peer->defaddr.sin_port = htons(ast_sockaddr_port(&peer->addr));
}
@@ -12380,26 +12378,26 @@
/* Non-dynamic. Make sure we become that way if we're not */
ast_sched_thread_del(sched, peer->expire);
ast_clear_flag64(peer, IAX_DYNAMIC);
- if (ast_dnsmgr_lookup(v->value, &peer->addr, &peer->dnsmgr, srvlookup ? "_iax._udp" : NULL))
+ if (ast_dnsmgr_lookup(v->value, &peer->addr, &peer->dnsmgr, srvlookup ? "_iax._udp" : NULL)) {
return peer_unref(peer);
+ }
if (!ast_sockaddr_port(&peer->addr)) {
ast_sockaddr_set_port(&peer->addr, IAX_DEFAULT_PORTNO);
}
}
- if (!maskfound)
+ if (!maskfound) {
inet_aton("255.255.255.255", &peer->mask);
+ }
} else if (!strcasecmp(v->name, "defaultip")) {
struct ast_sockaddr peer_defaddr_tmp;
if (ast_get_ip(&peer_defaddr_tmp, v->value)) {
return peer_unref(peer);
}
- ast_sockaddr_to_sin(&peer_defaddr_tmp,
- &peer->defaddr);
+ ast_sockaddr_to_sin(&peer_defaddr_tmp, &peer->defaddr);
} else if (!strcasecmp(v->name, "sourceaddress")) {
peer_set_srcaddr(peer, v->value);
- } else if (!strcasecmp(v->name, "permit") ||
- !strcasecmp(v->name, "deny")) {
+ } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) {
peer->ha = ast_append_ha(v->name, v->value, peer->ha, NULL);
} else if (!strcasecmp(v->name, "mask")) {
maskfound++;
@@ -12411,10 +12409,14 @@
} else if (!strcasecmp(v->name, "peercontext")) {
ast_string_field_set(peer, peercontext, v->value);
} else if (!strcasecmp(v->name, "port")) {
- if (ast_test_flag64(peer, IAX_DYNAMIC)) {
+ if (!ast_test_flag64(peer, IAX_DYNAMIC)) {
+ if (port_str2int(v->value, 0) > 0) {
+ ast_sockaddr_set_port(&peer->addr, atoi(v->value));
+ } else {
+ ast_log(LOG_WARNING, "Invalid peer port configuration at line %d : %s\n", v->lineno, v->value);
+ }
+ } else {
peer->defaddr.sin_port = htons(atoi(v->value));
- } else {
- ast_sockaddr_set_port(&peer->addr, atoi(v->value));
}
} else if (!strcasecmp(v->name, "username")) {
ast_string_field_set(peer, username, v->value);
@@ -12506,20 +12508,23 @@
alt = NULL;
}
}
- if (!peer->authmethods)
+ if (!peer->authmethods) {
peer->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
+ }
ast_clear_flag64(peer, IAX_DELME);
}
- if (oldha)
+ if (oldha) {
ast_free_ha(oldha);
+ }
if (!ast_strlen_zero(peer->mailbox)) {
char *mailbox, *context;
context = mailbox = ast_strdupa(peer->mailbox);
strsep(&context, "@");
- if (ast_strlen_zero(context))
+ if (ast_strlen_zero(context)) {
context = "default";
+ }
peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "IAX MWI subscription", NULL,
AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
More information about the asterisk-commits
mailing list