[asterisk-commits] mmichelson: branch 1.8 r279887 - /branches/1.8/channels/chan_sip.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 27 13:54:12 CDT 2010
Author: mmichelson
Date: Tue Jul 27 13:54:07 2010
New Revision: 279887
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=279887
Log:
Fix parsing error in sip_sipredirect().
The code was written in a way that did a bad job of
parsing the port out of a URI. Specifically, it would
do badly when dealing with an IPv6 address. In this
particular scenario, there was no value from parsing
the port out, so I just removed that logic. And while
I was messing around in the function, I changed some
variable names to be more descriptive.
(closes issue #17661)
Reported by: oej
Patches:
17661.diff uploaded by mmichelson (license 60)
Modified:
branches/1.8/channels/chan_sip.c
Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=279887&r1=279886&r2=279887
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Tue Jul 27 13:54:07 2010
@@ -27462,49 +27462,44 @@
static int sip_sipredirect(struct sip_pvt *p, const char *dest)
{
char *cdest;
- char *extension, *host, *port;
- char tmp[80];
+ char *extension, *domain;
cdest = ast_strdupa(dest);
extension = strsep(&cdest, "@");
- host = strsep(&cdest, ":");
- port = strsep(&cdest, ":");
+ domain = strsep(&cdest, ":");
if (ast_strlen_zero(extension)) {
ast_log(LOG_ERROR, "Missing mandatory argument: extension\n");
return 0;
}
/* we'll issue the redirect message here */
- if (!host) {
- char *localtmp;
-
- ast_copy_string(tmp, get_header(&p->initreq, "To"), sizeof(tmp));
- if (ast_strlen_zero(tmp)) {
+ if (!domain) {
+ char *local_to_header;
+ char to_header[256];
+
+ ast_copy_string(to_header, get_header(&p->initreq, "To"), sizeof(to_header));
+ if (ast_strlen_zero(to_header)) {
ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n");
return 0;
}
- if ( ( (localtmp = strcasestr(tmp, "sip:")) || (localtmp = strcasestr(tmp, "sips:")) )
- && (localtmp = strchr(localtmp, '@'))) {
- char lhost[80], lport[80];
-
- memset(lhost, 0, sizeof(lhost));
- memset(lport, 0, sizeof(lport));
- localtmp++;
+ if (((local_to_header = strcasestr(to_header, "sip:")) || (local_to_header = strcasestr(to_header, "sips:")))
+ && (local_to_header = strchr(local_to_header, '@'))) {
+ char ldomain[256];
+
+ memset(ldomain, 0, sizeof(ldomain));
+ local_to_header++;
/* This is okey because lhost and lport are as big as tmp */
- sscanf(localtmp, "%80[^<>:; ]:%80[^<>:; ]", lhost, lport);
- if (ast_strlen_zero(lhost)) {
+ sscanf(local_to_header, "%256[^<>; ]", ldomain);
+ if (ast_strlen_zero(ldomain)) {
ast_log(LOG_ERROR, "Can't find the host address\n");
return 0;
}
- host = ast_strdupa(lhost);
- if (!ast_strlen_zero(lport)) {
- port = ast_strdupa(lport);
- }
- }
- }
-
- ast_string_field_build(p, our_contact, "Transfer <sip:%s@%s%s%s>", extension, host, port ? ":" : "", port ? port : "");
+ domain = ast_strdupa(ldomain);
+ }
+ }
+
+ ast_string_field_build(p, our_contact, "Transfer <sip:%s@%s>", extension, domain);
transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq);
sip_scheddestroy(p, SIP_TRANS_TIMEOUT); /* Make sure we stop send this reply. */
More information about the asterisk-commits
mailing list