voipopensips

How to convert string in URI


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.


Solution

  • 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:

    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.