[OpenSIPS-Devel] [ opensips-Feature Requests-3046191 ] URI construction function / transformation

SourceForge.net noreply at sourceforge.net
Fri Oct 15 14:39:31 CEST 2010


Feature Requests item #3046191, was opened at 2010-08-16 14:24
Message generated for change (Comment added) made by vladut-paiu
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086413&aid=3046191&group_id=232389

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: core
Group: None
>Status: Closed
Priority: 5
Private: No
Submitted By: Stanislaw Pitucha (viraptor)
Assigned to: Vladut-Stefan Paiu (vladut-paiu)
Summary: URI construction function / transformation

Initial Comment:
I run a couple of times into situations where I need to change the URI a little bit. It ends up as a mess of if/else-s because the urls can have different protocols, may or may not contain a user and port, may have params, etc.

I propose a function `construct_uri(protocol, user, domain, port, params)` which returns a URI based on those arguments. The user, port, params parts should be optional, so it should be legal to call:

construct_uri("sip", null, "1.2.3.4", null, null) -> "sip:1.2.3.4"
construct_uri("sip", $rU, $rd, null, "key=val") -> "sip:$rU@$rd;key=val" (with expanded vars of course)
etc.

----------------------------------------------------------------------

>Comment By: Vladut-Stefan Paiu (vladut-paiu)
Date: 2010-10-15 15:39

Message:
Hello Stan,

I have just commited a patch to the trunk that implements the
functionality that you asked for. A small documentation as well as a usage
example can be found at
http://www.opensips.org/Resources/DocsCoreFcn#toc99

Let me know if you encounter any problems.

----------------------------------------------------------------------

Comment By: Stanislaw Pitucha (viraptor)
Date: 2010-10-14 05:13

Message:
Optional fields are the problem. Let's say I want to change a domain and
prepend a parameter - after splitting the original uri I have the relevant
parts in different $var-s. To construct a new uri, I need many cases like:

if ($var(user)) {
  if ($var(port))
    $var(result) = "sip:" + $var(user) + "@" + $var(domain) + ":" +
$var(port) + $var(newparam) + $(params);
  else
    $var(result) = "sip:" + $var(user) + "@" + $var(domain) +
$var(newparam) + $(params);
} else {
  if ($var(port))
    $var(result) = "sip:" + $var(domain) + ":" + $var(port) +
$var(newparam) + $(params);
  else
    $var(result) = "sip:" + $var(domain) + $var(newparam) + $(params);
}

I'd prefer to do something like this instead:

$var(result) = construct_uri("sip",$var(user),$var(domain),$var(port)
,$var(newparam) + $(params);

----------------------------------------------------------------------

Comment By: Bogdan-Andrei Iancu (bogdan_iancu)
Date: 2010-10-11 11:48

Message:
Hi Stan,

But what will be the benefit of  
     construct_uri("sip", null, "1.2.3.4", null, null) -> "sip:1.2.3.4"
over
    $ru = "sip:1.2.3.4";

or of
    construct_uri("sip", $rU, $rd, null, "key=val") ->
"sip:$rU@$rd;key=val"
over
    $ru = :sip:"+$rU+"@" +$rd+";key=val" 

?

Regards,
Bogdan

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=1086413&aid=3046191&group_id=232389



More information about the Devel mailing list