[OpenSIPS-Users] dp_translate() on other headers?

Kingsley Tart kingsley at dns99.co.uk
Mon Mar 29 10:19:53 EST 2021


Hi,

Thanks - yes I had realised that but it was the string manipulation of
the header itself that I was mainly thinking about.

I'm thinking that using a regex match on what is between "sip:" and "@"
would hopefully be OK with no false matches anywhere else in the
string, but there is no guarantee this would always be the case if
someone has a strange name string for example.

I like the string transformations - they're a really neat and safe way
of extracting the user part of the SIP address in this scenario; I was
trying to figure out whether there was an equally neat way of putting a
changed user value back into a URI string and nameaddr string without
having to re-construct the URI from its individual parts. 

I tried using construct_uri as below, but when one of the parameters
was null, the string "<null>" got inserted, instead of being ignored:

$var(testURI) = $(var(testRPID){nameaddr.uri});
xlog("oldURI=$var(testURI)");

# wrapped in email but not in the routing script:
construct_uri("$(var(testURI){uri.schema})", "01234567890",
  "$(var(testURI){uri.host})", "$(var(testURI){uri.port})",
  "$(var(testURI){uri.params})", $avp(newURI));

xlog("newURI=$avp(newURI)");

Then this was logged:

oldURI=sip:07890123456 at 83.121.44.30:5060
newURI=sip:01234567890 at 83.121.44.30:5060;<null>

If I don't put quotes around $(var(testURI){uri.params}) then it
complains that this isn't a string.

I know I could create the individual parts with a series of if (thing
== NULL) statements, but that seems quite longwinded and I was
wondering whether there was a better way.

Cheers,
Kingsley.

On Mon, 2021-03-29 at 10:22 +0300, Răzvan Crainea wrote:
> Hi, Kingsley!
> 
> The only way to do this is to remove the header and add a new one
> using 
> remove_hf/append_hf functions.
> 
> Best regards,
> 
> Răzvan Crainea
> OpenSIPS Core Developer
> http://www.opensips-solutions.com
> 
> On 3/26/21 6:09 PM, Kingsley Tart wrote:
> > Hi,
> > 
> > I'm using OpenSIPS 3.1.
> > 
> > I've set up some dialplan rule sets to normalise numbers depending
> > on
> > the carrier, eg:
> > 
> > +-------------------+---------------------+----------+
> > > match_exp         | subst_exp           | repl_exp |
> > 
> > +-------------------+---------------------+----------+
> > > ^\+44[1-9][0-9]+$ | ^\+44([1-9][0-9]+)$ | 0\1      |
> > > ^\+[1-9][0-9]+$   | ^\+([1-9][0-9]+)$   | 00\1     |
> > > ^\+44\*[0-9]+$    | ^\+44\*([0-9]+)$    | \1       |
> > 
> > +-------------------+---------------------+----------+
> > 
> > but I also need to do this with other headers that may be present
> > and
> > contain numbers, eg
> > 
> > P-Asserted-Identity
> > P-Preferred-Identity
> > Remote-Party-ID
> > 
> > I know I can extract the number from the header eg like this:
> > 
> > if (is_present_hf(P-Asserted-Identity)) {
> >    if (dp_translate(1, $(hdr(P-Asserted-
> > Identity){nameaddr.uri}{uri.user}), $var(newnum))) {
> >      xlog("New value is $var(newnum)");
> >    }
> > }
> > 
> > but is there an equally neat way of putting the new value back
> > inside
> > the header string? I can't use $(hdr(P-Asserted-
> > Identity){nameaddr.uri}{uri.user}) as an lvalue.
> > 
> > Otherwise I presume I'm going to have to make my dialplan regex
> > matches
> > try to home in on the number part by having "sip:" instead of my
> > "^"
> > anchor and "@" instead of my "$" anchor in the match rule and hope
> > that
> > doesn't happen to match anything else in the header (unlikely I
> > know,
> > but not impossible).
> > 
> > Forgive me if I've missed something obvious - I'm new to OpenSIPS.
> > 
> > Cheers,
> > Kingsley.
> > 
> > 
> > _______________________________________________
> > Users mailing list
> > Users at lists.opensips.org
> > http://lists.opensips.org/cgi-bin/mailman/listinfo/users
> > 
> 
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users






More information about the Users mailing list