[Kamailio-Devel] [ openser-Patches-2505748 ] module 'Regex' tarball

SourceForge.net noreply at sourceforge.net
Mon Jan 19 13:30:24 CET 2009


Patches item #2505748, was opened at 2009-01-14 00:23
Message generated for change (Comment added) made by henningw
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=743022&aid=2505748&group_id=139143

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: modules
Group: ver devel
>Status: Closed
>Resolution: Accepted
Priority: 5
Private: No
Submitted By: Iñaki Baz (ibc_sf)
Assigned to: Daniel-Constantin Mierla (miconda)
Summary: module 'Regex' tarball

Initial Comment:
Hi, I upload a tarball containing a new module called 'Regex':

This module offers matching operations against regular expressions using the powerful PCRE library.  A text file containing regular expressions categorized in groups is compiled when the module is loaded, storing the compiled PCRE objects in an array. A function to match a string or pseudo-variable against any of these groups is provided. The text file can be modified and reloaded at any time via a MI command. The module also offers a function to perform a PCRE matching operation against a regular expression provided as function parameter.

I hope it is useful.

----------------------------------------------------------------------

>Comment By: Henning Westerholt (henningw)
Date: 2009-01-19 12:30

Message:
Is now in svn trunk since rev 5462, this can be closed.

----------------------------------------------------------------------

Comment By: Iñaki Baz (ibc_sf)
Date: 2009-01-14 11:15

Message:
Thanks, I've already replaced malloc/free with pkg_malloc/pkg_free.

About line 616, I've re-checked it and (*pcres_addr)[num_pcre] cannot be
null:
- When MI reload is called, a pcres_tmp pointer is used to re-read the
file and compile the new patters (they could be more or less groups than
before).
- *num_pcres (shm: number of groups) and pcres (shm: pointer to pcres) are
just updated in case the file has been correctly re-parsed so pcres_tmp
just contains valid compiled PCRE objects.
- When pcre_match_group() script function is called, the group number is
checked (it must be smaller than *num_pcres) before doing "pcre_exec"
(which uses (*pcres_addr)[num_pcre]).

I've tested it several times:
- Kamailio starts with 5 groups in the regex file.
- A script function "pcre_match_group($pseudo-variable, 4)" is used in the
config file. It works.
- Now I modify the regex file and leave just 4 groups.
- I reload via MI.
- When "pcre_match_group($pseudo-variable, 4)" is called from script it
returns -4 since num_pcre >= *num_pcres (being num_pcre the group number of
the second parameter in  pcre_match_group() function).

Anyway, if you consider your suggestion is still needed please tell me and
I'll add the check.

Thanks for all.

----------------------------------------------------------------------

Comment By: Daniel-Constantin Mierla (miconda)
Date: 2009-01-14 10:46

Message:
Here are couple remarks:
- it is recommended use pkg_malloc()/pkg_free() instead of standard
malloc/free for temporary operation.
- in regex_mod.c line 616, it might be needed to check if
(*pcres_addr)[num_pcre] is NULL, maybe a reload removed a group or
parameter is not a valid group. Just something I could spot.

Once you double-check the second, you can go ahead and check in the code.
Your account has write access. Let me know if you have troubles.


----------------------------------------------------------------------

Comment By: Daniel-Constantin Mierla (miconda)
Date: 2009-01-14 09:33

Message:
Thanks. I will review it and then grant you SVN access to commit.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=743022&aid=2505748&group_id=139143



More information about the Devel mailing list