aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-01-13 21:18:13 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-01-13 21:18:13 +0000
commite3260b3633727abdc7e912643987f704b74c056c (patch)
treec818b3bd2c641eb07b20c36f161f14286b283b05
parentd056b18a40018d38abbeb107412cc83b78b3c406 (diff)
Allow specifying a port number in the user portion of a register => line in sip.conf
With this commit, a register => line in sip.conf may contain a port number in the "user" section of the line. Please see CHANGES and sip.conf.sample for more details regarding this. (closes issue #14198) Reported by: Nick_Lewis Patches: chan_sip.c-domainport2.patch uploaded by Nick (license 657) Tested by: Nick_Lewis git-svn-id: http://svn.digium.com/svn/asterisk/trunk@168575 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--CHANGES3
-rw-r--r--channels/chan_sip.c45
-rw-r--r--configs/sip.conf.sample13
3 files changed, 50 insertions, 11 deletions
diff --git a/CHANGES b/CHANGES
index fb2ed66b1..884714e36 100644
--- a/CHANGES
+++ b/CHANGES
@@ -41,6 +41,9 @@ SIP Changes
option is required to interoperate with devices that have non-standard SDP
session version implementations (observed with Microsoft OCS). This option
is diabled by default.
+ * The parsing of register => lines in sip.conf has been modified to allow a port
+ to be present in the "user" portion. Please see the sip.conf.sample file for more
+ information
Skinny Changes
--------------
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index c2062d56f..0a066c7dc 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -6852,14 +6852,23 @@ static int sip_register(const char *value, int lineno)
ast_log(LOG_WARNING, "Format for registration is [transport://]user[:secret[:authuser]]@host[:port][/contact][~expiry] at line %d\n", lineno);
return -1;
}
- /* split user[:secret[:authuser]] */
- secret = strchr(username, ':');
- if (secret) {
- *secret++ = '\0';
- authuser = strchr(secret, ':');
- if (authuser)
- *authuser++ = '\0';
+
+ /* split user[:secret[:authuser]] from the end to allow : character in user portion*/
+ authuser = strrchr(username, ':');
+ if (authuser) {
+ *authuser++ = '\0';
+ secret = strrchr(username, ':');
+ if (secret)
+ *secret++ = '\0';
+ else {
+ secret = authuser;
+ authuser = NULL;
+ }
}
+ if ((authuser) && (ast_strlen_zero(authuser)))
+ authuser = NULL;
+ if ((secret) && (ast_strlen_zero(secret)))
+ secret = NULL;
/* split host[:port][/contact] */
expire = strchr(hostname, '~');
@@ -10475,6 +10484,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, const char *
struct sip_pvt *p;
int res;
char *fromdomain;
+ char *domainport = NULL;
/* exit if we are already in process with this registrar ?*/
if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) {
@@ -10622,10 +10632,23 @@ static int transmit_register(struct sip_registry *r, int sipmethod, const char *
/* Fromdomain is what we are registering to, regardless of actual
host name from SRV */
if (!ast_strlen_zero(p->fromdomain)) {
- if (r->portno && r->portno != STANDARD_SIP_PORT)
- snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno);
- else
- snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
+ domainport = strrchr(p->fromdomain, ':');
+ if (domainport) {
+ *domainport++ = '\0'; /* trim off domainport from p->fromdomain */
+ if (ast_strlen_zero(domainport))
+ domainport = NULL;
+ }
+ if (domainport) {
+ if (atoi(domainport) != STANDARD_SIP_PORT)
+ snprintf(addr, sizeof(addr), "sip:%s:%s", p->fromdomain, domainport);
+ else
+ snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
+ } else {
+ if (r->portno && r->portno != STANDARD_SIP_PORT)
+ snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno);
+ else
+ snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
+ }
} else {
if (r->portno && r->portno != STANDARD_SIP_PORT)
snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, r->portno);
diff --git a/configs/sip.conf.sample b/configs/sip.conf.sample
index 42bb57f8e..0b73f08d1 100644
--- a/configs/sip.conf.sample
+++ b/configs/sip.conf.sample
@@ -432,6 +432,14 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
; and more readable because you don't have to write the parameters in two places
; (note that the "port" is ignored - this is a bug that should be fixed).
;
+; Beginning with Asterisk version 1.6.2, the "user" portion of the register line may
+; contain a port number. Since the logical separator between a host and port number is a
+; ':' character, and this character is already used to separate between the optional "secret"
+; and "authuser" portions of the line, there is a bit of a hoop to jump through if you wish
+; to use a port here. That is, you must explicitly provide a "secret" and "authuser" even if
+; they are blank. See the third example below for an illustration.
+;
+;
; Examples:
;
;register => 1234:password@mysipprovider.com
@@ -448,6 +456,11 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
; Tip 1: Avoid assigning hostname to a sip.conf section like [provider.com]
; Tip 2: Use separate inbound and outbound sections for SIP providers
; (instead of type=friend) if you have calls in both directions
+;
+;register => 3456@mydomain:5082::@mysipprovider.com
+;
+; Note that in this example, the optional authuser and secret portions have
+; been left blank because we have specified a port in the user section
;registertimeout=20 ; retry registration calls every 20 seconds (default)
;registerattempts=10 ; Number of registration attempts before we give up