Skip to content

Commit

Permalink
Fix script varibles for providing port and proto (as part of SIP URI).
Browse files Browse the repository at this point in the history
If the SIP URI does not have an explicit port or proto, determine the default port/proto in a SIP wise manner (rather than returning 5060 / UDP) (Ex: sip:example.com;transport=tls has default port 5061 and not 5060 ; or sips:example.com has default proto TLS and not UDP).

Affected variables are $dp, $rp, $op and $dP, $rP, $oP
  • Loading branch information
bogdan-iancu committed Jun 24, 2016
1 parent 00d052c commit 6cc850e
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions pvar.c
Expand Up @@ -89,12 +89,6 @@ static str str_null = { _str_null_hlp, 6 };
static char _str_empty_hlp[1] = { 0 };
static str str_empty = { _str_empty_hlp, 0 };

static char _str_5060_hlp[5] = {'5','0','6','0',0};
static str str_5060 = { _str_5060_hlp, 4 };

static char _str_udp_hlp[4] = {'u','d','p',0};
static str str_udp = { _str_udp_hlp, 3 };

static char _str_request_route_hlp[] = {'r','e','q','u','e','s','t','_','r','o','u','t','e',0};
static str str_request_route = { _str_request_route_hlp, 13 };

Expand Down Expand Up @@ -247,16 +241,6 @@ int pv_get_null(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
res->flags = PV_VAL_NULL;
return 0;
}
static int pv_get_udp(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
return pv_get_strintval(msg, param, res, &str_udp, (int)PROTO_UDP);
}

static int pv_get_5060(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
{
return pv_get_strintval(msg, param, res, &str_5060, 5060);
}


/************************************************************/
static int pv_get_pid(struct sip_msg *msg, pv_param_t *param,
Expand Down Expand Up @@ -468,6 +452,9 @@ static int pv_get_ouri(struct sip_msg *msg, pv_param_t *param,
static int pv_get_xuri_attr(struct sip_msg *msg, struct sip_uri *parsed_uri,
pv_param_t *param, pv_value_t *res)
{
unsigned short proto;
str proto_s;

if(param->pvn.u.isname.name.n==1) /* username */
{
if(parsed_uri->user.s==NULL || parsed_uri->user.len<=0)
Expand All @@ -479,12 +466,17 @@ static int pv_get_xuri_attr(struct sip_msg *msg, struct sip_uri *parsed_uri,
return pv_get_strval(msg, param, res, &parsed_uri->host);
} else if(param->pvn.u.isname.name.n==3) /* port */ {
if(parsed_uri->port.s==NULL)
return pv_get_5060(msg, param, res);
return pv_get_uintval(msg, param, res,
get_uri_port( parsed_uri, &proto));
return pv_get_strintval(msg, param, res, &parsed_uri->port,
(int)parsed_uri->port_no);
} else if(param->pvn.u.isname.name.n==4) /* protocol */ {
if(parsed_uri->transport_val.s==NULL)
return pv_get_udp(msg, param, res);
if(parsed_uri->transport_val.s==NULL) {
get_uri_port(parsed_uri, &proto);
proto_s.s = protos[proto].name;
proto_s.len = strlen(proto_s.s);
return pv_get_strintval(msg, param, res, &proto_s, (int)proto);
}
return pv_get_strintval(msg, param, res, &parsed_uri->transport_val,
(int)parsed_uri->proto);
}
Expand Down Expand Up @@ -1372,6 +1364,8 @@ static int pv_get_dsturi_attr(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
{
struct sip_uri uri;
unsigned short proto;
str proto_s;

if(msg==NULL)
return -1;
Expand All @@ -1394,11 +1388,15 @@ static int pv_get_dsturi_attr(struct sip_msg *msg, pv_param_t *param,
return pv_get_strval(msg, param, res, &uri.host);
} else if(param->pvn.u.isname.name.n==2) /* port */ {
if(uri.port.s==NULL)
return pv_get_5060(msg, param, res);
return pv_get_uintval(msg, param, res, get_uri_port(&uri, &proto));
return pv_get_strintval(msg, param, res, &uri.port, (int)uri.port_no);
} else if(param->pvn.u.isname.name.n==3) /* proto */ {
if(uri.transport_val.s==NULL)
return pv_get_udp(msg, param, res);
if(uri.transport_val.s==NULL) {
get_uri_port(&uri, &proto);
proto_s.s = protos[proto].name;
proto_s.len = strlen(proto_s.s);
return pv_get_strintval(msg, param, res, &proto_s, (int)proto);
}
return pv_get_strintval(msg, param, res, &uri.transport_val,
(int)uri.proto);
}
Expand Down

0 comments on commit 6cc850e

Please sign in to comment.