[svn-commits] simon.perreault: branch group/v6-new r272962 - /team/group/v6-new/channels/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Jun 29 08:17:17 CDT 2010
Author: simon.perreault
Date: Tue Jun 29 08:17:12 2010
New Revision: 272962
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=272962
Log:
Fixed coding guidelines issues and restored original manager behaviour. This addresses all
review comments by pabelanger.
Modified:
team/group/v6-new/channels/chan_iax2.c
team/group/v6-new/channels/chan_mgcp.c
team/group/v6-new/channels/chan_sip.c
Modified: team/group/v6-new/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_iax2.c?view=diff&rev=272962&r1=272961&r2=272962
==============================================================================
--- team/group/v6-new/channels/chan_iax2.c (original)
+++ team/group/v6-new/channels/chan_iax2.c Tue Jun 29 08:17:12 2010
@@ -12237,8 +12237,9 @@
} else if (!strcasecmp(v->name, "defaultip")) {
struct ast_sockaddr peer_defaddr_tmp;
- if (ast_get_ip(&peer_defaddr_tmp, v->value))
+ if (ast_get_ip(&peer_defaddr_tmp, v->value)) {
return peer_unref(peer);
+ }
ast_sockaddr_to_sin(&peer_defaddr_tmp,
&peer->defaddr);
} else if (!strcasecmp(v->name, "sourceaddress")) {
Modified: team/group/v6-new/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_mgcp.c?view=diff&rev=272962&r1=272961&r2=272962
==============================================================================
--- team/group/v6-new/channels/chan_mgcp.c (original)
+++ team/group/v6-new/channels/chan_mgcp.c Tue Jun 29 08:17:12 2010
@@ -1776,8 +1776,9 @@
tmp3.sin_addr = g->ourip;
tmp1 = ast_sockaddr_from_sin(g->addr);
tmp2 = ast_sockaddr_from_sin(tmp3);
- if (ast_ouraddrfor(&tmp1, &tmp2))
+ if (ast_ouraddrfor(&tmp1, &tmp2)) {
memcpy(&g->ourip, &__ourip, sizeof(g->ourip));
+ }
ast_sockaddr_to_sin(&tmp2, &tmp3);
g->ourip = tmp3.sin_addr;
}
Modified: team/group/v6-new/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/channels/chan_sip.c?view=diff&rev=272962&r1=272961&r2=272962
==============================================================================
--- team/group/v6-new/channels/chan_sip.c (original)
+++ team/group/v6-new/channels/chan_sip.c Tue Jun 29 08:17:12 2010
@@ -3083,9 +3083,10 @@
ast_sockaddr_to_sin(&externip, &externip_sin);
ast_stun_request(sipsock, &stunaddr, NULL, &externip_sin);
} else {
- if(ast_sockaddr_resolve_first(&externip,
- externhost, 0, 0))
+ if (ast_sockaddr_resolve_first(&externip,
+ externhost, 0, 0)) {
ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
+ }
externexpire = time(NULL);
}
externexpire = time(NULL) + externrefresh;
@@ -3094,9 +3095,10 @@
ast_sockaddr_copy(us, &externip);
switch (p->socket.type) {
case SIP_TRANSPORT_TCP:
- if(!externtcpport && ast_sockaddr_port(&externip))
+ if (!externtcpport && ast_sockaddr_port(&externip)) {
/* for consistency, default to the externip port */
- externtcpport = ast_sockaddr_port(&externip);
+ externtcpport = ast_sockaddr_port(&externip);
+ }
ast_sockaddr_set_port(us, externtcpport);
break;
case SIP_TRANSPORT_TLS:
@@ -3117,20 +3119,22 @@
/* no remapping, but we bind to a specific address, so use it. */
switch (p->socket.type) {
case SIP_TRANSPORT_TCP:
- if (!ast_sockaddr_is_any(&sip_tcp_desc.local_address))
+ if (!ast_sockaddr_is_any(&sip_tcp_desc.local_address)) {
ast_sockaddr_copy(us,
&sip_tcp_desc.local_address);
- else
+ } else {
ast_sockaddr_set_port(us,
ast_sockaddr_port(&sip_tcp_desc.local_address));
+ }
break;
case SIP_TRANSPORT_TLS:
- if (!ast_sockaddr_is_any(&sip_tls_desc.local_address))
+ if (!ast_sockaddr_is_any(&sip_tls_desc.local_address)) {
ast_sockaddr_copy(us,
&sip_tls_desc.local_address);
- else
+ } else {
ast_sockaddr_set_port(us,
ast_sockaddr_port(&sip_tls_desc.local_address));
+ }
break;
case SIP_TRANSPORT_UDP:
/* fall through on purpose */
@@ -3756,10 +3760,11 @@
finalize_content(req);
add_blank(req);
if (sip_debug_test_pvt(p)) {
- if (ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT))
+ if (ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT)) {
ast_verbose("%sTransmitting (NAT) to %s:\n%s\n---\n", reliable ? "Reliably " : "", ast_sockaddr_stringify(&p->recv), req->data->str);
- else
+ } else {
ast_verbose("%sTransmitting (no NAT) to %s:\n%s\n---\n", reliable ? "Reliably " : "", ast_sockaddr_stringify(&p->sa), req->data->str);
+ }
}
if (p->do_history) {
struct sip_request tmp = { .rlPart1 = 0, };
@@ -4229,8 +4234,9 @@
varregs = ast_load_realtime("sipregs", "name", newpeername, SENTINEL);
var = ast_load_realtime("sippeers", "name", newpeername, "host", "dynamic", SENTINEL);
- if (!var && addr)
+ if (!var && addr) {
var = ast_load_realtime("sippeers", "name", newpeername, "host", ast_sockaddr_stringify_addr(addr), SENTINEL);
+ }
if (!var) {
var = ast_load_realtime("sippeers", "name", newpeername, SENTINEL);
/*!\note
@@ -4794,8 +4800,9 @@
peername = ast_strdupa(opeer);
ast_sockaddr_parse(&dialog->sa, peername, 0);
- if (ast_sockaddr_port(&dialog->sa))
+ if (ast_sockaddr_port(&dialog->sa)) {
dialog->portinuri = 1;
+ }
dialog->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */
dialog->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */
@@ -4842,25 +4849,32 @@
if (!ast_sockaddr_port(&dialog->sa) && sip_cfg.srvlookup) {
snprintf(service, sizeof(service), "_sip._%s.%s", get_transport(dialog->socket.type), peername);
if ((srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno,
- service)) > 0)
+ service)) > 0) {
hostn = host;
+ }
}
if (ast_sockaddr_resolve_first(&dialog->sa, hostn,
- PARSE_PORT_FORBID, 0))
+ PARSE_PORT_FORBID, 0)) {
ast_log(LOG_WARNING, "No such host: %s\n", peername);
-
- if (srv_ret > 0)
+ }
+
+ if (srv_ret > 0) {
ast_sockaddr_set_port(&dialog->sa, tportno);
+ }
}
if (!dialog->socket.type)
set_socket_transport(&dialog->socket, SIP_TRANSPORT_UDP);
- if (!dialog->socket.port)
+ if (!dialog->socket.port) {
dialog->socket.port = htons(ast_sockaddr_port(&bindaddr));
-
- if(!ast_sockaddr_port(&dialog->sa))
- ast_sockaddr_set_port(&dialog->sa, (dialog->socket.type == SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT);
+ }
+
+ if (!ast_sockaddr_port(&dialog->sa)) {
+ ast_sockaddr_set_port(&dialog->sa,
+ (dialog->socket.type == SIP_TRANSPORT_TLS) ?
+ STANDARD_TLS_PORT : STANDARD_SIP_PORT);
+ }
ast_sockaddr_copy(&dialog->recv, &dialog->sa);
return 0;
}
@@ -6891,9 +6905,9 @@
p->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */
}
- if (!addr)
+ if (!addr) {
p->ourip = internip;
- else {
+ } else {
ast_sockaddr_copy(&p->sa, addr);
ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
}
@@ -7601,7 +7615,7 @@
return -1;
}
- if(ast_sockaddr_resolve_first(addr, host, 0, af)) {
+ if (ast_sockaddr_resolve_first(addr, host, 0, af)) {
ast_log(LOG_WARNING, "Could not look up IP address of alternate hostname. Expect %s problems\n", media == SDP_AUDIO? "audio" : "video");
return -1;
}
@@ -8026,8 +8040,10 @@
if (portno > 0) {
ast_sockaddr_set_port(sa, portno);
ast_rtp_instance_set_remote_address(p->rtp, sa);
- if (debug)
- ast_verbose("Peer audio RTP is at port %s\n", ast_sockaddr_stringify(sa));
+ if (debug) {
+ ast_verbose("Peer audio RTP is at port %s\n",
+ ast_sockaddr_stringify(sa));
+ }
/* We are now ready to change the sip session and p->rtp and p->vrtp with the offered codecs, since
they are acceptable */
p->jointcapability = newjointcapability; /* Our joint codec profile for this call */
@@ -8067,8 +8083,10 @@
if (vportno > 0) {
ast_sockaddr_set_port(vsa, vportno);
ast_rtp_instance_set_remote_address(p->vrtp, vsa);
- if (debug)
- ast_verbose("Peer video RTP is at port %s\n", ast_sockaddr_stringify(vsa));
+ if (debug) {
+ ast_verbose("Peer video RTP is at port %s\n",
+ ast_sockaddr_stringify(vsa));
+ }
ast_rtp_codecs_payloads_copy(&newvideortp, ast_rtp_instance_get_codecs(p->vrtp), p->vrtp);
} else {
ast_rtp_instance_stop(p->vrtp);
@@ -8082,8 +8100,10 @@
if (tportno > 0) {
ast_sockaddr_set_port(tsa, tportno);
ast_rtp_instance_set_remote_address(p->trtp, tsa);
- if (debug)
- ast_verbose("Peer T.140 RTP is at port %s\n", ast_sockaddr_stringify(tsa));
+ if (debug) {
+ ast_verbose("Peer T.140 RTP is at port %s\n",
+ ast_sockaddr_stringify(tsa));
+ }
if ((p->jointcapability & AST_FORMAT_T140RED)) {
p->red = 1;
ast_rtp_red_init(p->trtp, 300, red_data_pt, 2);
@@ -8323,15 +8343,15 @@
/* Check for Media-description-level-address */
if (sscanf(c, "IN %3s %255s", proto, host) == 2) {
- if(!strcmp("IP4", proto))
+ if (!strcmp("IP4", proto)) {
af = AF_INET;
- else if(!strcmp("IP6", proto))
+ } else if (!strcmp("IP6", proto)) {
af = AF_INET6;
- else {
+ } else {
ast_log(LOG_WARNING, "Unknown protocol '%s'.\n", proto);
return FALSE;
}
- if(ast_sockaddr_resolve_first(addr, host, 0, af)) {
+ if (ast_sockaddr_resolve_first(addr, host, 0, af)) {
ast_log(LOG_WARNING, "Unable to lookup RTP Audio host in c= line, '%s'\n", c);
return FALSE;
}
@@ -8870,7 +8890,7 @@
/*! \todo XXX If we have sip_cfg.srvlookup on, then look for NAPTR/SRV,
* otherwise, just look for A records */
- if(ast_sockaddr_resolve_first(&p->sa, hostname, 0, 0)) {
+ if (ast_sockaddr_resolve_first(&p->sa, hostname, 0, 0)) {
ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname);
return;
}
@@ -8890,7 +8910,7 @@
/*! \todo XXX If we have sip_cfg.srvlookup on, then look for
* NAPTR/SRV, otherwise, just look for A records */
- if(ast_sockaddr_resolve_first(&p->sa, hostname, PARSE_PORT_FORBID, 0)) {
+ if (ast_sockaddr_resolve_first(&p->sa, hostname, PARSE_PORT_FORBID, 0)) {
ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname);
return;
}
@@ -8898,13 +8918,15 @@
ast_sockaddr_set_port(&p->sa, port);
}
- if (!ast_sockaddr_port(&p->sa))
+ if (!ast_sockaddr_port(&p->sa)) {
ast_sockaddr_set_port(&p->sa, tls_on ?
STANDARD_TLS_PORT : STANDARD_SIP_PORT);
-
- if (debug)
+ }
+
+ if (debug) {
ast_verbose("set_destination: set destination to %s\n",
- ast_sockaddr_stringify(&p->sa));
+ ast_sockaddr_stringify(&p->sa));
+ }
}
/*! \brief Initialize SIP response, based on SIP request */
@@ -9331,9 +9353,9 @@
/* Initialize the bare minimum */
p->method = intended_method;
- if (!addr)
+ if (!addr) {
ast_sockaddr_copy(&p->ourip, &internip);
- else {
+ } else {
ast_sockaddr_copy(&p->sa, addr);
ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
}
@@ -9855,10 +9877,12 @@
{
/* First, get our address */
ast_rtp_instance_get_local_address(p->rtp, addr);
- if (p->vrtp)
+ if (p->vrtp) {
ast_rtp_instance_get_local_address(p->vrtp, vaddr);
- if (p->trtp)
+ }
+ if (p->trtp) {
ast_rtp_instance_get_local_address(p->trtp, taddr);
+ }
/* Now, try to figure out where we want them to send data */
/* Is this a re-invite to move the media out, then use the original offer from caller */
@@ -10073,8 +10097,9 @@
if (capability & AST_FORMAT_AUDIO_MASK)
needaudio = TRUE;
- if (debug)
+ if (debug) {
ast_verbose("Audio is at %s\n", ast_sockaddr_stringify_port(&p->ourip));
+ }
/* Ok, we need video. Let's add what we need for video and set codecs.
Video is handled differently than audio since we can not transcode. */
@@ -10086,8 +10111,9 @@
/* Build max bitrate string */
if (p->maxcallbitrate)
snprintf(bandwidth, sizeof(bandwidth), "b=CT:%d\r\n", p->maxcallbitrate);
- if (debug)
+ if (debug) {
ast_verbose("Video is at %s\n", ast_sockaddr_stringify(&p->ourip));
+ }
}
/* Ok, we need text. Let's add what we need for text and set codecs.
@@ -10098,8 +10124,9 @@
get_crypto_attrib(p->tsrtp, &t_a_crypto);
ast_str_append(&m_text, 0, "m=text %d RTP/%s", ast_sockaddr_port(&tdest),
t_a_crypto ? "SAVP" : "AVP");
- if (debug) /* XXX should I use tdest below ? */
+ if (debug) { /* XXX should I use tdest below ? */
ast_verbose("Text is at %s\n", ast_sockaddr_stringify(&p->ourip));
+ }
}
/* Start building generic SDP headers */
@@ -10209,8 +10236,9 @@
ast_sockaddr_to_sin(&p->ourip,&udptldest);
}
- if (debug)
+ if (debug) {
ast_debug(1, "T.38 UDPTL is at %s port %d\n", ast_sockaddr_stringify_addr(&p->ourip), ntohs(udptlsin.sin_port));
+ }
/* We break with the "recommendation" and send our IP, in order that our
peer doesn't have to ast_gethostbyname() us */
@@ -10557,13 +10585,14 @@
/*! \brief Build contact header - the contact header we send out */
static void build_contact(struct sip_pvt *p)
{
- if (p->socket.type == SIP_TRANSPORT_UDP)
+ if (p->socket.type == SIP_TRANSPORT_UDP) {
ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten,
ast_strlen_zero(p->exten) ? "" : "@", ast_sockaddr_stringify(&p->ourip));
- else
+ } else {
ast_string_field_build(p, our_contact, "<sip:%s%s%s;transport=%s>", p->exten,
ast_strlen_zero(p->exten) ? "" : "@", ast_sockaddr_stringify(&p->ourip),
get_transport(p->socket.type));
+ }
}
/*! \brief Initiate new SIP request to peer/user */
@@ -10671,8 +10700,9 @@
ast_str_append(&invite, 0, "%s@", n);
}
ast_str_append(&invite, 0, "%s", p->tohost);
- if (p->portinuri)
+ if (p->portinuri) {
ast_str_append(&invite, 0, ":%d", ast_sockaddr_port(&p->sa));
+ }
ast_str_append(&invite, 0, "%s", urioptions);
}
}
@@ -11732,8 +11762,9 @@
append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname);
/* Use port number specified if no SRV record was found */
- if (!ast_sockaddr_port(&r->us) && r->portno)
- ast_sockaddr_set_port(&r->us, r->portno);
+ if (!ast_sockaddr_port(&r->us) && r->portno) {
+ ast_sockaddr_set_port(&r->us, r->portno);
+ }
/* Find address to hostname */
if (create_addr(p, S_OR(r->peername, r->hostname), &r->us, 0, NULL)) {
@@ -12239,16 +12270,18 @@
return;
addr = scan = data;
- if ('[' == scan[0])
+ if ('[' == scan[0]) {
/* It must be a bracket enclosed IPv6 address */
scan = strchr(scan, ']') + 1;
+ }
scan = strchr(scan, ':') + 1;
expiry_str = strsep(&scan, ":");
username = strsep(&scan, ":");
contact = scan; /* Contact include sip: and has to be the last part of the database entry as long as we use : as a separator */
- if (!ast_sockaddr_parse(&sa, addr, 0));
+ if (!ast_sockaddr_parse(&sa, addr, 0)) {
return;
+ }
if (expiry_str)
expire = atoi(expiry_str);
@@ -12330,19 +12363,20 @@
assume that the domain part is a host name and only look for an A/AAAA record in DNS.
*/
- if(ast_sockaddr_resolve_first(addr, domain, 0, 0)) {
+ if (ast_sockaddr_resolve_first(addr, domain, 0, 0)) {
ast_log(LOG_WARNING, "Invalid host name in Contact: (can't "
"resolve in DNS) : '%s'\n", domain);
return -1;
}
/* set port */
- if (!ast_sockaddr_port(addr))
+ if (!ast_sockaddr_port(addr)) {
ast_sockaddr_set_port(addr,
(get_transport_str2enum(transport) ==
SIP_TRANSPORT_TLS ||
!strncasecmp(fullcontact, "sips", 4)) ?
STANDARD_TLS_PORT : STANDARD_SIP_PORT);
+ }
return 0;
}
@@ -12471,7 +12505,7 @@
}
ast_sockaddr_copy(&peer->addr, &testsa);
- /* If we have a port number in the given URI, make sure we do remember to not check for NAPTR/SRV records.
+ /* If we have a port number in the given URI, make sure we do remember to not check for NAPTR/SRV records.
The domain part is actually a host. */
peer->portinuri = ast_sockaddr_port(&testsa) ? TRUE : FALSE;
@@ -12534,8 +12568,8 @@
}
}
pvt->expiry = expire;
- snprintf(data, sizeof(data), "%s:%d:%s:%s", ast_sockaddr_stringify(&peer->addr), expire,
- peer->username, peer->fullcontact);
+ snprintf(data, sizeof(data), "%s:%d:%s:%s", ast_sockaddr_stringify(&peer->addr),
+ expire, peer->username, peer->fullcontact);
/* Saving TCP connections is useless, we won't be able to reconnect
XXX WHY???? XXX
\todo Fix this immediately.
@@ -13258,9 +13292,16 @@
case AUTH_SECRET_FAILED:
/* Wrong password in authentication. Go away, don't try again until you fixed it */
transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq);
- if (global_authfailureevents)
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Rejected\r\nCause: AUTH_SECRET_FAILED\r\nAddress: %s\r\n",
- name, ast_sockaddr_stringify(addr));
+ if (global_authfailureevents) {
+ manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
+ "ChannelType: SIP\r\n"
+ "Peer: SIP/%s\r\n"
+ "PeerStatus: Rejected\r\n"
+ "Cause: AUTH_SECRET_FAILED\r\n"
+ "Address: %s\r\nPort: %s\r\n",
+ name, ast_sockaddr_stringify_addr(addr),
+ ast_sockaddr_stringify_port(addr));
+ }
break;
case AUTH_USERNAME_MISMATCH:
/* Username and digest username does not match.
@@ -14102,7 +14143,7 @@
/* XXX add error checking */
ast_sockaddr_set_port(&p->ourip, port);
} else if (!strncmp(cur, "received=", 9)) {
- if (ast_parse_arg(cur+9, PARSE_ADDR, &p->ourip))
+ if (ast_parse_arg(cur + 9, PARSE_ADDR, &p->ourip))
; /* XXX add error checking */
}
}
@@ -14152,14 +14193,17 @@
if (pt)
*pt++ = '\0'; /* remember port pointer */
- if (maddr && ast_sockaddr_resolve_first(&p->sa, maddr, 0, 0))
+ if (maddr && ast_sockaddr_resolve_first(&p->sa, maddr, 0, 0)) {
p->sa = p->recv;
+ }
ast_sockaddr_set_port(&p->sa, port_str2int(pt, STANDARD_SIP_PORT));
- if (sip_debug_test_pvt(p))
- ast_verbose("Sending to %s (%s)\n", ast_sockaddr_stringify(sip_real_dst(p)),
- sip_nat_mode(p));
+ if (sip_debug_test_pvt(p)) {
+ ast_verbose("Sending to %s (%s)\n",
+ ast_sockaddr_stringify(sip_real_dst(p)),
+ sip_nat_mode(p));
+ }
}
}
@@ -14189,9 +14233,10 @@
}
if (!peer) {
- if (debug)
+ if (debug) {
ast_verbose("No matching peer for '%s' from '%s'\n",
of, ast_sockaddr_stringify(&p->recv));
+ }
return AUTH_DONT_KNOW;
}
if (!ast_sockaddr_is_ipv6(addr)) {
@@ -14979,10 +15024,12 @@
else if (pstatus == 0)
peers_mon_offline++;
else {
- if (ast_sockaddr_isnull(&peer->addr) || !ast_sockaddr_port(&peer->addr))
+ if (ast_sockaddr_isnull(&peer->addr) ||
+ !ast_sockaddr_port(&peer->addr)) {
peers_unmon_offline++;
- else
+ } else {
peers_unmon_online++;
+ }
}
snprintf(srch, sizeof(srch), FORMAT, name,
@@ -16695,12 +16742,15 @@
ast_cli(a->fd, " Received Address: %s\n", ast_sockaddr_stringify(&cur->recv));
ast_cli(a->fd, " SIP Transfer mode: %s\n", transfermode2str(cur->allowtransfer));
ast_cli(a->fd, " Force rport: %s\n", AST_CLI_YESNO(ast_test_flag(&cur->flags[0], SIP_NAT_FORCE_RPORT)));
- if(ast_sockaddr_isnull(&cur->redirip))
- ast_cli(a->fd, " Audio IP: %s (local)\n",
- ast_sockaddr_stringify_addr(&cur->ourip));
- else
- ast_cli(a->fd, " Audio IP: %s (Outside bridge)\n",
- ast_sockaddr_stringify_addr(&cur->redirip));
+ if (ast_sockaddr_isnull(&cur->redirip)) {
+ ast_cli(a->fd,
+ " Audio IP: %s (local)\n",
+ ast_sockaddr_stringify_addr(&cur->ourip));
+ } else {
+ ast_cli(a->fd,
+ " Audio IP: %s (Outside bridge)\n",
+ ast_sockaddr_stringify_addr(&cur->redirip));
+ }
ast_cli(a->fd, " Our Tag: %s\n", cur->tag);
ast_cli(a->fd, " Their Tag: %s\n", cur->theirtag);
ast_cli(a->fd, " SIP User agent: %s\n", cur->useragent);
@@ -17037,8 +17087,9 @@
/*! \brief Enable SIP Debugging for a single IP */
static char *sip_do_debug_ip(int fd, const char *arg)
{
- if (ast_sockaddr_resolve_first(&debugaddr, arg, 0, 0))
+ if (ast_sockaddr_resolve_first(&debugaddr, arg, 0, 0)) {
return CLI_SHOWUSAGE;
+ }
ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_sockaddr_stringify_addr(&debugaddr));
sipdebug |= sip_debug_console;
@@ -23372,8 +23423,9 @@
struct sip_threadinfo *th = obj;
struct ast_sockaddr *s = arg;
- if (!ast_sockaddr_cmp(s, &th->tcptls_session->remote_address))
+ if (!ast_sockaddr_cmp(s, &th->tcptls_session->remote_address)) {
return CMP_MATCH | CMP_STOP;
+ }
return 0;
}
@@ -23401,10 +23453,13 @@
*
* \note return 0 if addr is [::] else it returns addr's family.
*/
-int get_address_family_filter(const struct ast_sockaddr *addr) {
- if (ast_sockaddr_is_ipv6(addr) && ast_sockaddr_is_any(addr))
- return 0;
- return addr->ss.ss_family;
+int get_address_family_filter(const struct ast_sockaddr *addr)
+{
+ if (ast_sockaddr_is_ipv6(addr) && ast_sockaddr_is_any(addr)) {
+ return 0;
+ }
+
+ return addr->ss.ss_family;
}
/*! \todo Get socket for dialog, prepare if needed, and return file handle */
@@ -24467,9 +24522,12 @@
remote_address, 0, 0)) {
ast_log(LOG_WARNING, "Unable to find IP address for host %s. We will not use this remote IP address\n", remote_address);
} else {
- if(!ast_sockaddr_port(&remote_address_sa))
+ if (!ast_sockaddr_port(&remote_address_sa)) {
ast_sockaddr_set_port(&remote_address_sa,
- transport & SIP_TRANSPORT_TLS ? STANDARD_TLS_PORT : STANDARD_SIP_PORT);
+ transport & SIP_TRANSPORT_TLS ?
+ STANDARD_TLS_PORT :
+ STANDARD_SIP_PORT);
+ }
}
}
@@ -25716,7 +25774,7 @@
struct sockaddr_in externip_sin;
run_start = time(0);
- ast_unload_realtime("sipregs");
+ ast_unload_realtime("sipregs");
ast_unload_realtime("sippeers");
cfg = ast_config_load(config, config_flags);
@@ -26023,13 +26081,16 @@
}
}
} else if (!strcasecmp(v->name, "tcpenable")) {
- if(!ast_false(v->value)) {
+ if (!ast_false(v->value)) {
ast_debug(2, "Enabling TCP socket for listening\n");
sip_cfg.tcp_enabled = TRUE;
}
} else if (!strcasecmp(v->name, "tcpbindaddr")) {
- if (ast_parse_arg(v->value, PARSE_ADDR, &sip_tcp_desc.local_address))
- ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of %s\n", v->name, v->value, v->lineno, config);
+ if (ast_parse_arg(v->value, PARSE_ADDR,
+ &sip_tcp_desc.local_address)) {
+ ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of %s\n",
+ v->name, v->value, v->lineno, config);
+ }
ast_debug(2, "Setting TCP socket address to %s\n",
ast_sockaddr_stringify(&sip_tcp_desc.local_address));
} else if (!strcasecmp(v->name, "dynamic_exclude_static") || !strcasecmp(v->name, "dynamic_excludes_static")) {
@@ -26194,10 +26255,12 @@
ast_log(LOG_WARNING, "Invalid STUN server address: %s\n", v->value);
externexpire = time(NULL);
} else if (!strcasecmp(v->name, "bindaddr") || !strcasecmp(v->name, "udpbindaddr")) {
- if (ast_parse_arg(v->value, PARSE_ADDR, &bindaddr))
+ if (ast_parse_arg(v->value, PARSE_ADDR, &bindaddr)) {
ast_log(LOG_WARNING, "Invalid address: %s\n", v->value);
- if (!ast_sockaddr_port(&bindaddr))
+ }
+ if (!ast_sockaddr_port(&bindaddr)) {
ast_sockaddr_set_port(&bindaddr, STANDARD_SIP_PORT);
+ }
} else if (!strcasecmp(v->name, "localnet")) {
struct ast_ha *na;
int ha_error = 0;
@@ -26212,14 +26275,17 @@
if (ast_parse_arg(v->value, PARSE_ADDR, &media_address))
ast_log(LOG_WARNING, "Invalid address for media_address keyword: %s\n", v->value);
} else if (!strcasecmp(v->name, "externip")) {
- if (ast_parse_arg(v->value, PARSE_ADDR, &externip))
- ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value);
+ if (ast_parse_arg(v->value, PARSE_ADDR, &externip)) {
+ ast_log(LOG_WARNING,
+ "Invalid address for externip keyword: %s\n",
+ v->value);
+ }
externexpire = 0;
} else if (!strcasecmp(v->name, "externhost")) {
ast_copy_string(externhost, v->value, sizeof(externhost));
- if(ast_sockaddr_resolve_first(&externip, externhost, 0,
- 0))
+ if (ast_sockaddr_resolve_first(&externip, externhost, 0, 0)) {
ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost);
+ }
externexpire = time(NULL);
} else if (!strcasecmp(v->name, "externrefresh")) {
if (sscanf(v->value, "%30d", &externrefresh) != 1) {
@@ -26563,10 +26629,12 @@
/* Start TCP server */
if (sip_cfg.tcp_enabled) {
- if (ast_sockaddr_isnull(&sip_tcp_desc.local_address))
+ if (ast_sockaddr_isnull(&sip_tcp_desc.local_address)) {
ast_sockaddr_copy(&sip_tcp_desc.local_address, &bindaddr);
- if (!ast_sockaddr_port(&sip_tcp_desc.local_address))
+ }
+ if (!ast_sockaddr_port(&sip_tcp_desc.local_address)) {
ast_sockaddr_set_port(&sip_tcp_desc.local_address, STANDARD_SIP_PORT);
+ }
} else {
ast_sockaddr_setnull(&sip_tcp_desc.local_address);
}
@@ -26584,10 +26652,13 @@
if (ast_ssl_setup(sip_tls_desc.tls_cfg)) {
if (ast_sockaddr_isnull(&sip_tls_desc.local_address)) {
ast_sockaddr_copy(&sip_tls_desc.local_address, &bindaddr);
- ast_sockaddr_set_port(&sip_tls_desc.local_address, STANDARD_TLS_PORT);
- }
- if (!ast_sockaddr_port(&sip_tls_desc.local_address))
- ast_sockaddr_set_port(&sip_tls_desc.local_address, STANDARD_TLS_PORT);
+ ast_sockaddr_set_port(&sip_tls_desc.local_address,
+ STANDARD_TLS_PORT);
+ }
+ if (!ast_sockaddr_port(&sip_tls_desc.local_address)) {
+ ast_sockaddr_set_port(&sip_tls_desc.local_address,
+ STANDARD_TLS_PORT);
+ }
ast_tcptls_server_start(&sip_tls_desc);
if (default_tls_cfg.enabled && sip_tls_desc.accept_fd == -1) {
ast_log(LOG_ERROR, "TLS Server start failed. Not listening on TLS socket.\n");
@@ -26618,21 +26689,26 @@
}
/* If TCP is running on a different IP than UDP, then add it too */
- if (!ast_sockaddr_isnull(&sip_tcp_desc.local_address) &&
- !ast_sockaddr_cmp(&bindaddr, &sip_tcp_desc.local_address))
- add_sip_domain(ast_sockaddr_stringify(&sip_tcp_desc.local_address),
- SIP_DOMAIN_AUTO, NULL);
+ if (!ast_sockaddr_isnull(&sip_tcp_desc.local_address) &&
+ !ast_sockaddr_cmp(&bindaddr, &sip_tcp_desc.local_address)) {
+ add_sip_domain(ast_sockaddr_stringify(&sip_tcp_desc.local_address),
+ SIP_DOMAIN_AUTO, NULL);
+ }
/* If TLS is running on a different IP than UDP and TCP, then add that too */
- if (!ast_sockaddr_isnull(&sip_tls_desc.local_address) &&
- !ast_sockaddr_cmp(&bindaddr, &sip_tls_desc.local_address) &&
- !ast_sockaddr_cmp(&sip_tcp_desc.local_address, &sip_tls_desc.local_address))
- add_sip_domain(ast_sockaddr_stringify(&sip_tcp_desc.local_address),
- SIP_DOMAIN_AUTO, NULL);
+ if (!ast_sockaddr_isnull(&sip_tls_desc.local_address) &&
+ !ast_sockaddr_cmp(&bindaddr, &sip_tls_desc.local_address) &&
+ !ast_sockaddr_cmp(&sip_tcp_desc.local_address,
+ &sip_tls_desc.local_address)) {
+ add_sip_domain(ast_sockaddr_stringify(&sip_tcp_desc.local_address),
+ SIP_DOMAIN_AUTO, NULL);
+ }
/* Our extern IP address, if configured */
- if (!ast_sockaddr_isnull(&externip))
- add_sip_domain(ast_sockaddr_stringify(&externip), SIP_DOMAIN_AUTO, NULL);
+ if (!ast_sockaddr_isnull(&externip)) {
+ add_sip_domain(ast_sockaddr_stringify(&externip), SIP_DOMAIN_AUTO,
+ NULL);
+ }
/* Extern host name (NAT traversal support) */
if (!ast_strlen_zero(externhost))
@@ -27298,7 +27374,10 @@
return 1;
}
-/*! \brief Return the first entry from ast_sockaddr_resolve. Temporary during IPv6 portage */
+/*! \brief Return the first entry from ast_sockaddr_resolve.
+ *
+ * \warn Using this function probably means you have a faulty design.
+ */
static int ast_sockaddr_resolve_first(struct ast_sockaddr *addr,
const char* name, int flag, int family)
{
@@ -27306,10 +27385,12 @@
int addrs_cnt;
addrs_cnt = ast_sockaddr_resolve(&addrs, name, flag, family);
- if(addrs_cnt <= 0)
+ if (addrs_cnt <= 0) {
return 1;
- if(addrs_cnt > 1)
+ }
+ if (addrs_cnt > 1) {
ast_log(LOG_DEBUG, "Multiple addresses, using the first one only\n");
+ }
ast_sockaddr_copy(addr, &addrs[0]);
@@ -27339,7 +27420,7 @@
}
/*!
- * Hash function based on the the peer's ip address. For IPv6, we use the end
+ * Hash function based on the the peer's ip address. For IPv6, we use the end
* of the address.
* \todo Find a better hashing function
*/
@@ -27348,12 +27429,13 @@
const struct sip_peer *peer = obj;
int ret = 0;
- if (ast_sockaddr_isnull(&peer->addr))
+ if (ast_sockaddr_isnull(&peer->addr)) {
ast_log(LOG_ERROR, "Empty address\n");
+ }
switch(peer->addr.ss.ss_family) {
case AF_INET:
- ret = ((struct sockaddr_in*)&peer->addr.ss)->sin_addr.s_addr ;
+ ret = ((struct sockaddr_in*)&peer->addr.ss)->sin_addr.s_addr;
break;
case AF_INET6:
ret = ((uint32_t *)&((struct sockaddr_in6*)&peer->addr.ss)->sin6_addr)[3];
@@ -27362,8 +27444,9 @@
ast_log(LOG_ERROR, "Unknown address type\n");
}
- if (ret < 0)
+ if (ret < 0) {
ret = -ret;
+ }
return ret;
}
More information about the svn-commits
mailing list