1

I setup OpenSips 2.3 proxy server, so any call come on server, my script grabs sip URI from DB, and forward call to that uri. When I get value I used AVP to get value and save it in $avp(didnumber), if I use rewrite with manually specifying uri it is working, but when I grab this value from DB and than assign it, it is not working in rewriteuri() method.

$ru = "sip:"+$avp(didnumber)

if I write

rewriteuri("[$ru]")

it throws following error

ERROR:core:parse_sip_msg_uri: bad uri <[$ru>
ERROR:tm:new_t: uri invalid
ERROR:tm:t_newtran: new_t failed

I think this method does not accept normal variable so I added quotation to make it string variable, now it shows fine on log but seem I have to convert variable using AVP or transformation, I tried many syntaxes but still could not do it. Please suggest.

Kamal Panhwar
  • 2,345
  • 3
  • 21
  • 37

1 Answers1

0

rewrite_uri() has been deprecated in favour of simply using $ru. Your R-URI already gets completely rewritten by this statement:

$ru = "sip:" + $avp(didnumber);

However, note that the above is incorrect, since you do not supply a "hostport" part to the uri, according to the SIP RFC 3261:

SIP-URI          =  "sip:" [ userinfo ] hostport
                    uri-parameters [ headers ]

The parser will likely report an error. There are two fixes for this:

  • either only rewrite the R-URI "userinfo" part, like so:

    $rU = $avp(didnumber);
    
  • supply a destination hostname:

    $ru = "sip:" + $avp(didnumber) + "@" + $var(destination);
    

Following from here, you can just t_relay() using your new R-URI.

EDIT: the OpenSIPS URI parser will actually tolerate a URI such as "sip:44776772882", but it will interpret the DID as a hostname, so the errors may start appearing later, should the script writer attempt to relay the message to the invalid "44776772882" hostname.

Liviu Chircu
  • 1,000
  • 3
  • 11
  • 24
  • Thanks Liviu Chircu, I got your point thanks for brief explaination, but I have whole URI in string format, now searching for something that can transform my variable in the host, port, the user. As my DB has 111111@domain.com:5060 and these are million numbers. – Kamal Panhwar Apr 03 '18 at 10:57
  • `$var(did) = $(var(input){s.select,0,@});` `$var(host) = $(var(input){s.select,1,@}{s.select,0,:});` – Liviu Chircu Apr 03 '18 at 14:03