[OpenSIPS-Users] Regex module limitations ?

denis.barbaron at orange.com denis.barbaron at orange.com
Mon Oct 1 15:56:49 CEST 2012


Hi Odin,

Thank you very much for your answer, but it doesn't meet my requirements. In fact, I really need to have a generic regexp API to parse generic strings (including SIP headers). The dialplan module performs strings substitution and comparison based on static rules stored in database and return only one value. But from my side, strings to parse may also contains patterns which have to be matched against other strings to produce sometimes more than one value, etc., for instance (TCL language):

# set input string
set input_string "apply_pattern={[^@]+} on_string=10.194.124.1 at toto.com"

# extract pattern and string from input string
if {[regexp {apply_pattern=([^[:blank:]]+)[[:blank:]]+on_string=([^[:blank:]]+)} $input_string -> pattern string]} {

	#apply pattern on string to get result
	if {[regexp $pattern $string result]} {
		log $result
		...
	}
}

Do I have to write my own module for that ? Is there an existing documentation helping for module development ?

Denis.

-----Message d'origine-----
De : users-bounces at lists.opensips.org [mailto:users-bounces at lists.opensips.org] De la part de Odin Gremaud
Envoyé : lundi 1 octobre 2012 14:09
À : OpenSIPS users mailling list
Objet : Re: [OpenSIPS-Users] Regex module limitations ?

Hi,

 From my understanding (correct me if I'm wrong), you want to match a particular header value and return this value to use it afterwards in your script. You could of course use an external script (using exec or perl module), but may I suggest you having a look at the dialplan module ? It can not only be used for a dial plan (thus the name), but you can match almost anything with it : IP addresses, SIP headers, ...

For instance, you would populate the database table, and then, you could do this :

if !dp_translate("<dialplan_id>","$ua/$avp(ua)") {
     xlog("L_INFO", "No match found for User-Agent"); }

If your rule is done correctly (you can apply transformations or not, it's up to you), you could get in $avp(ua) the matched (transformed or not) value, or anything else you want. You could even declare, in your rules, some attributes that could be fetched at the same time, using the "attrs_pvar" module parameter.

Hope this helps.

Odin



On Mon, 01 Oct 2012 12:25:02 +0200, <denis.barbaron at orange.com> wrote:

> Hi,
>
> I would like to use the "regex" module to perform pattern matching 
> against strings or SIP headers in order to get back results in the 
> same way I can do it with PCRE API, as follow :
> preg_match_all('#<([ib])>(.*?)</\1>#', $txt, $out). The problem is 
> that "regex" module seems to not be able to provide such feature but 
> only a comparison function returning a boolean value (TRUE or FALSE), 
> as follow
> :
> ...
> if (pcre_match("$ua", "(?i)^twinkle")) {
>     xlog("L_INFO", "User-Agent matches\n"); } ...
>
> The only way I found to solve this problem would be to use the "exec"  
> module to run an external script doing the job or to develop a new 
> module, so is there a more simple solution please ?
> Thanks.
> Denis.
>
>
>
> [cid:image001.gif at 01CD85FD.DD28EF80]
>
> Denis Barbaron
> R&D engineer
> FT/OLPS/OLNC/IVA/VMI/INTL
> tél. +33 2 96 05 03 57
> denis.barbaron at orange.com<mailto:thierry.moreau at orange-ftgroup.com>
>
>
> ______________________________________________________________________
> ___________________________________________________
>
> Ce message et ses pieces jointes peuvent contenir des informations 
> confidentielles ou privilegiees et ne doivent donc pas etre diffuses, 
> exploites ou copies sans autorisation. Si vous avez recu ce message 
> par erreur, veuillez le signaler a l'expediteur et le detruire ainsi 
> que les pieces jointes. Les messages electroniques etant susceptibles 
> d'alteration, France Telecom - Orange decline toute responsabilite si 
> ce message a ete altere, deforme ou falsifie. Merci.
>
> This message and its attachments may contain confidential or 
> privileged information that may be protected by law; they should not 
> be distributed, used or copied without authorisation.
> If you have received this email in error, please notify the sender and 
> delete this message and its attachments.
> As emails may be altered, France Telecom - Orange is not liable for 
> messages that have been modified, changed or falsified.
> Thank you.

_______________________________________________
Users mailing list
Users at lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users

_________________________________________________________________________________________________________________________

Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc
pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler
a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration,
France Telecom - Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci.

This message and its attachments may contain confidential or privileged information that may be protected by law;
they should not be distributed, used or copied without authorisation.
If you have received this email in error, please notify the sender and delete this message and its attachments.
As emails may be altered, France Telecom - Orange is not liable for messages that have been modified, changed or falsified.
Thank you.




More information about the Users mailing list