Hi Vivek,
You were looking at the OpenSER documents for instruction on creating
"regular expressions".
Search for some information about "regular expressions". They are very
powerful, but also can sometimes be difficult to understand.
Generally, the parens "()" are used to save a piece of matched text.
The matched text can then be referenced by the \1. If you have two sets
of parens, then \1 would match the first set and \2 will match the
second set.
I have both the first and second editions of "Mastering Regular
Expressions" by Jeffery Friedl in the bookcase next to my desk. It's
pretty much the definitive reference on the subject. A quick search on
the net will also provide you many good references.
Regards,
Norm
Vivek Bhat wrote:
Hi Norman,
Thanks for your response. It is working now.
I tried to understand how avp_subst() works. How
avp_subst() gets the correct string in s:match in the
example below? What is "\1" token doing here? Could
you please explain? I read the openser module
document, but could not understand either :-)
Thanks,
Vivek
--- Norman Brandinger <norm(a)goes.com> wrote:
Hi Vivek,
Below is an example that appears to solve your
problem.
Note that the regular expression in the avp_subst()
statement was made
specifically for this example. Based on your
example, the "needle"
that is being matched is preceded by an underscore.
If this can ALWAYS
be guaranteed then you shouldn't have a problem
using this regular
expression. If the haystack has some other known
pattern that a regular
expression can be used to match, then all you have
to do is create
another regular expression and drop it into the
example below.
avp_write("7267261000", "$avp(s:needle)");
avp_write("<sip:termdoneatscsf_7267261000@test.com;lr>",
"$avp(s:haystack)");
avp_subst("$avp(s:haystack)/$avp(s:match)","/<sip:.*_(.*)@(.*)>/\1/");
xlog("L_NOTICE", "needle=($avp(s:needle))
haystack=($avp(s:haystack))
match=($avp(s:match))\n");
if
(avp_check("$avp(s:needle)","eq/$avp(s:match)/g")) {
xlog("L_NOTICE", "Match found\n");
} else {
xlog("L_NOTICE", "Match not found\n");
}
Regards,
Norm
Vivek Bhat wrote:
Hi,
I have installed openser v1.1.0 on Linux system.
I have problem checking if "Route" header contains
the
"username" of Req-URI as below:
Req-URI will be like "sip:7267261000@<domain>"
and Route header will be like
"<sip:termdoneatscsf_7267261000@<domain>;lr>
# To get the RURI I did like this
avp_write("$ru/username", "$avp(UNAMEOFRURI)");
avp_print();
# To get the Route Header, I did like this
avp_write("$hdr(Route)", "$avp(ROUTEUSERNAME)");
avp_print();
Now, what is the best way to check if
$avp(ROUTEUSERNAME) contains $avp(UNAMEOFRURI)?
I tried as below, and it gives error "regexp
requires
> string value"
>
>
>
if(avp_check("$avp(UNAMEOFRURI)","re/$avp(ROUTEUSERNAME)/gi"))
{
log(1, "Usernames of RURI is found inside Route
header.");
} else
{
log(1, "Usernames of RURI is NOT found inside
Route
header.");
}
Instead of avp_check, I tried to use search as
below:
if(search("^(Route):.*$ru/username.*"))
{
log(1, "Usernames of RURI is found inside
Route header.");
}
But, it didn't work either.
Please suggest what is the best method to do this?
Thanks,
Vivek
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam
protection around
http://mail.yahoo.com
_______________________________________________
Users mailing list
Users(a)openser.org
http://openser.org/cgi-bin/mailman/listinfo/users
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com