Hi Inaki,
that works with string transformations:
- in older versions, use s.substr
- in last one there is s.strip
Cheers,
Daniel
On 9/16/10 8:28 PM, Iñaki Baz Castillo wrote:
2010/9/16 Iñaki Baz Castillo<ibc(a)aliax.net>et>:
Hi, I get a prefix string from a database and
store it in
$var(prefix). Such prefix can contain any number of digits (no fixed
length).
Now I must to check if the RURI username begins with that prefix and
in that case strip it.
I can get the first step (detect it) using pcre_match function:
if pcre_match("$rU", "^$var(prefix)") {
# Prefix match.
But I cannot get the second part working (stripping it). I've tryed everything:
- strip() is not valid as just allows an integer (no pv).
- subst_user() doesn't accept pv:
if subst_user("/^$var(prefix)(.*)$/\1/")
Any ideas please? Thanks a lot.
Finally I got it in an ugly way (assuming that prefix has as maximun 7 digits):
-------------------
# Check that the dialed number begins with the
# configured 'prefix_in'. If not drop the call.
#
if ! pcre_match("$rU", "^$var(prefix)") {
xlog("L_NOTICE", "prefix doesn't match =>403\n");
send_reply("403", "Forbidden: Wrong Prefix");
exit;
}
# If so, strip the prefix.
#
$var(prefix_in_length) = $(var(client_prefix_in){s.len});
switch($var(prefix_in_length)) {
case 1:
strip(1);
break;
case 2:
strip(2);
break;
case 3:
strip(3);
break;
case 4:
strip(4);
break;
case 5:
strip(5);
break;
case 6:
strip(6);
break;
case 7:
strip(7);
break;
}
------------------
Any suggestion providing a more ellegant way is welcome :)
--
Daniel-Constantin Mierla
http://www.asipto.com