<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Bogdan,<br>
Thanks for the help ... I am running on a debian lenny system and do
not have fnmatch()<br>
<br>
# man fnmatch<br>
No manual entry for fnmatch<br>
# apt-get install fnmatch<br>
Reading package lists... Done<br>
Building dependency tree&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
Reading state information... Done<br>
E: Couldn't find package fnmatch<br>
# man 3 fnmatch<br>
No manual entry for fnmatch in section 3<br>
# apt-cache search fnmatch<br>
# <br>
<br>
do you know what package I need to install?<br>
<br>
Thanks,<br>
Paul.<br>
<br>
Bogdan-Andrei Iancu wrote:
<blockquote cite="mid:4CA0B1B7.600@voice-system.ro" type="cite">
  <pre wrap="">Hi Paul,

yes, one approach will be to get rid of the regexp matching and to try 
something different (like substring matching). Runtime regexps are not 
implemented in script as they are very time consuming - actually you 
need first to compile the regexp and than to check it - and this for 
each SIP message going through your script.

Some pattern based matching, much lighter, is FM based in avpops (see 
<a class="moz-txt-link-freetext" href="http://www.opensips.org/html/docs/modules/1.6.x/avpops.html#id271322">http://www.opensips.org/html/docs/modules/1.6.x/avpops.html#id271322</a> and 
"man fnmatch").

Of course, if there is a need and if performance penalties are not a big 
issue, it is simple to implement runtime regexps....

Regards,
Bogdan

PS: I strongly advice you not to use REGEXP in mysql as it is 
performance killer for DB.




Paul Smith wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">OK I have a working solution now... code still needs tidying up and 
optimizing but I'll post it here in case anyone comes looking for this 
in the future.

The significant bit is that avp_db_query() can run any MYSQL SELECT 
query, and there is a REGEXP() funtion in mysql allowing you to test 
regular expressions.
So now I have a user specific regular expression stored in the 
subscriber table column 'expcallerid', and test the P-Preferred-Identity 
($pU) against that regular expression at run time.. if the test fails 
then $avp(s:callerid) remains set to $avp(s:defcallerid).

        if($(rU{s.substr,0,3})=="141") {
                # 141 prefix in UK or Ireland signifies that the user 
wants to block callerid presentation for this call              
                #check for 141 prefix on number, if set then strip it 
and set s:CLIR before checking aliases or dial plan
                xlog("stripping 141");
                #strip 141
                $rU=$(rU{s.substr,3,0});
                xlog("dialling $rU");
                $avp(s:clir)=1;
        }
        if($pU=="Anonymous") {
                $avp(s:clir)=1;
        }


        xlog("dialled number = $rU");
        xlog("callerid barring requested by device = $avp(s:clir)");
        xlog("callerid set by device = $pU");
        xlog("callerid expression for this user = $avp(s:expcallerid)");
        xlog("default callerid for this user = $avp(s:defcallerid)");

        $avp(s:callerid)=$avp(s:defcallerid);
        $avp(s:preferredcallerid)=$pU;
        if($avp(s:clir)){
                # user has restricted callerid
                $avp(s:callerid)="Anonymous";
        } else if($pU)) {
                # UAC device has set preferred callerid
                # test P-Preferred-Identity against user regualr 
expression held in expcallerid column of subscriber table
                avp_db_query("select '$avp(s:preferredcallerid)' from 
subscriber where username='$fU' and domain='$fd' and '\$pU' REGEXP 
expcallerid","$avp(s:callerid)");
                xlog("preferred callerid $pU tested, using callerid: 
$avp(s:callerid)");

        }

        xlog("callerid now set to $avp(s:callerid)");


Thanks for the hint that there was a way Bogdan... is there a better way?
Paul.





Paul Smith wrote:
  
    </pre>
    <blockquote type="cite">
      <pre wrap="">Hi Bodgan,
Mainly matching, to allow me to verify that a customer owns the CLI he 
is presenting.

Ideally I was thinking substitution as I can then add as well in one 
operation.. but I can do that as 2 separate operations.

So... how can I do a dynamic match using an account specific pattern?

pseudo code would be:
if $(preferred cli) matches $(customer regexp from database) {
    $callerid=$(customer cli prefix) + $(preferred cli)
}
else {
    $callerid=$(customer default cli)
}

The bit I am struggling with is the operation to match a dynamic variable.

Thanks
Paul

Bogdan-Andrei Iancu wrote:
    
      </pre>
      <blockquote type="cite">
        <pre wrap="">Hi Paul,

you need a substitution, replacement or simply matching ?

Regards,
Bogdan

Paul Smith wrote:
  
      
        </pre>
        <blockquote type="cite">
          <pre wrap="">Hi Bogdan,
Thanks for the reply.  I am using dialplan module for mangling the 
dialled number to local valid service codes and e164 destinations.

I was hoping to use a simple field in the usr_preferences or 
substitution table to hold a substitution pattern for each user's 
verified callerid (P-Preferred-Identity) ranges.

I'll have to have a think about how to use dialplan to do this, and 
still keep my simple user provisioning gui...



*Paul Smith | Technical Director | Clarity Telecom*
Number One, Lanyon Quay, Belfast, BT1 3LG
Phone:         0800 91 21 000 | 1800 855 111
FAX:         0800 91 21 999 | 1800 855 112
Email:         <a class="moz-txt-link-abbreviated" href="mailto:Paul.Smith@ClarityTele.com">Paul.Smith@ClarityTele.com</a>
Web:         <a class="moz-txt-link-freetext" href="http://www.ClarityTele.com">http://www.ClarityTele.com</a>



Bogdan-Andrei Iancu wrote:
    
        
          </pre>
          <blockquote type="cite">
            <pre wrap="">Hi Paul,

have you looked at dialplan module ? 
       <a class="moz-txt-link-freetext" href="http://www.opensips.org/html/docs/modules/1.6.x/dialplan.html">http://www.opensips.org/html/docs/modules/1.6.x/dialplan.html</a>

The subst-like funcs in script do not support dynamic patterns..

Regards,
Bogdan

Paul Smith wrote:
  
      
          
            </pre>
            <blockquote type="cite">
              <pre wrap="">How can I do a regular expression substitution on an avp where the 
pattern is loaded from the user subsrciption or usr_preference table?

For example I need to limit callerid presented to a pre-determined range 
owned by my customer, and perform substitution eg add a prefix.  If a 
UAC sets P-Preferred-identify to 1234 and I have a usr_preference to 
match any 4 digit caller starting with 1, and prefix with 789 then 
callerid should be set to 7891234

I have in mind something like:

In my database I set the expression for  $avp(s:expcallerid) for this 
user to "/1.{3}/789\1/i"
then in my dialplan I want to match and substitute the 
Preferred-Identity to form the $avp(s:callerid) and then set 
P-Asserted-Identity

xlog("dialled number = $rU");
xlog("callerid barring requested by device = $avp(s:clir)");
xlog("callerid preferred set by device = $pU");
xlog("callerid expression for this user = $avp(s:expcallerid)");
xlog("default callerid for this user = $avp(s:defcallerid)");

$avp(s:callerid)=$avp(s:defcallerid);
if($avp(s:clir)){
       # user has restricted callerid
        $avp(s:callerid)="Anonymous";
} else if($pU) {
      # UAC device has set preferred callerid
      $avp(s:callerid)=pU;
      if(avp_subst("$avp(s:callerid)",$avp(s:expcallerid)) ){
            xlog("preferred callerid matched callerid expression");
      } else {
           xlog("preferred callerid rejected, using default");
           $avp(s:callerid)=$avp(s:defcallerid);
      }
} else {
      #use default callerid
      $avp(s:callerid)=$avp(s:defcallerid);
}

I get the error
Sep 22 12:30:21 [6253] CRITICAL:core:yyerror: parse error in config 
file, line 518, column 44-45: bad arguments for command &lt;avp_subst&gt;

which I think means that avp_subst is expecting a static regular 
expression in the script, whereas  I want a user variable as the regular 
expression.

Is there another way to look at the problem? Have I missed something 
obvious (again)?

Thanks
Paul

_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>

  
    
        
            
              </pre>
            </blockquote>
            <pre wrap="">  
      
          
            </pre>
          </blockquote>
          <pre wrap="">------------------------------------------------------------------------

_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
  
    
        
          </pre>
        </blockquote>
        <pre wrap="">  
      
        </pre>
      </blockquote>
      <pre wrap="">------------------------------------------------------------------------

_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
  
    
      </pre>
    </blockquote>
    <pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>

  
    </pre>
  </blockquote>
  <pre wrap=""><!---->

  </pre>
</blockquote>
</body>
</html>