textops Module


Table of Contents

1. Admin Guide
1.1. Overview
1.1.1. Known Limitations
1.2. Dependencies
1.2.1. OpenSIPS Modules
1.2.2. External Libraries or Applications
1.3. Exported Functions
1.3.1. search(re)
1.3.2. search_body(re)
1.3.3. search_append(re, txt)
1.3.4. search_append_body(re, txt)
1.3.5. replace(re, txt)
1.3.6. replace_body(re, txt)
1.3.7. replace_all(re, txt)
1.3.8. replace_body_all(re, txt)
1.3.9. replace_body_atonce(re, txt)
1.3.10. subst('/re/repl/flags')
1.3.11. subst_uri('/re/repl/flags')
1.3.12. subst_user('/re/repl/flags')
1.3.13. subst_body('/re/repl/flags')
2. Contributors
2.1. By Commit Statistics
2.2. By Commit Activity
3. Documentation
3.1. Contributors

List of Tables

2.1. Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
2.2. Most recently active contributors(1) to this module

List of Examples

1.1. search usage
1.2. search_body usage
1.3. search_append usage
1.4. search_append_body usage
1.5. replace usage
1.6. replace_body usage
1.7. replace_all usage
1.8. replace_body_all usage
1.9. replace_body_atonce usage
1.10. subst usage
1.11. subst_uri usage
1.12. subst usage
1.13. subst_body usage

Chapter 1. Admin Guide

1.1. Overview

The module implements text based operations over the SIP message processed by OpenSIPS. SIP is a text based protocol and the module provides a large set of very useful functions to manipulate the message at text level, e.g., regular expression search and replace, Perl-like substitutions, etc.

Note: all SIP-aware functions like insert_hf, append_hf or codec operations have been moved to the sipmsgops module.

1.1.1. Known Limitations

search ignores folded lines. For example, search((From|f):.*@foo.bar) doesn't match the following From header field:

From: medabeda 
 <sip:medameda@foo.bar>;tag=1234

1.2. Dependencies

1.2.1. OpenSIPS Modules

The following modules must be loaded before this module:

  • No dependencies on other OpenSIPS modules.

1.2.2. External Libraries or Applications

The following libraries or applications must be installed before running OpenSIPS with this module loaded:

  • None.

1.3. Exported Functions

1.3.1.  search(re)

Searches for the re in the message.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.1. search usage

...
if ( search("[Ss][Ii][Pp]") ) { /*....*/ };
...

1.3.2.  search_body(re)

Searches for the re in the body of the message.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.2. search_body usage

...
if ( search_body("[Ss][Ii][Pp]") ) { /*....*/ };
...

1.3.3.  search_append(re, txt)

Searches for the first match of re and appends txt after it.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

  • txt (string) - String to be appended.

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.3. search_append usage

...
search_append("[Oo]pen[Ss]er", " SIP Proxy");
...

1.3.4.  search_append_body(re, txt)

Searches for the first match of re in the body of the message and appends txt after it.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

  • txt (string) - String to be appended.

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.4. search_append_body usage

...
search_append_body("[Oo]pen[Ss]er", " SIP Proxy");
...

1.3.5.  replace(re, txt)

Replaces the first occurrence of re with txt.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

  • txt (string)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.5. replace usage

...
replace("opensips", "Open SIP Server");
...

1.3.6.  replace_body(re, txt)

Replaces the first occurrence of re in the body of the message with txt.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

  • txt (string)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.6. replace_body usage

...
replace_body("opensips", "Open SIP Server");
...

1.3.7.  replace_all(re, txt)

Replaces all occurrence of re with txt.

Meaning of the parameters is as follows:

  • re - (string) Regular expression.

  • txt (string)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.7. replace_all usage

...
replace_all("opensips", "Open SIP Server");
...

1.3.8.  replace_body_all(re, txt)

Replaces all occurrence of re in the body of the message with txt. Matching is done on a per-line basis.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

  • txt (string)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.8. replace_body_all usage

...
replace_body_all("opensips", "Open SIP Server");
...

1.3.9.  replace_body_atonce(re, txt)

Replaces all occurrence of re in the body of the message with txt. Matching is done over the whole body.

Meaning of the parameters is as follows:

  • re (string) - Regular expression.

  • txt (string)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.9. replace_body_atonce usage

...
# strip the whole body from the message:
if(has_body() && replace_body_atonce("^.+$", ""))
        remove_hf("Content-Type"); 
...

1.3.10.  subst('/re/repl/flags')

Replaces re with repl (sed or perl like).

Meaning of the parameters is as follows:

  • '/re/repl/flags' (string) - sed like regular expression. flags can be a combination of i (case insensitive), g (global) or s (match newline don't treat it as end of line).

    're' - is regular expression

    'repl' - is replacement string - may contain pseudo-variables

    'flags' - substitution flags (i - ignore case, g - global)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.10. subst usage

...
# replace the uri in to: with the message uri (just an example)
if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1\u\2/ig') ) {};

# replace the uri in to: with the value of avp sip_address (just an example)
if ( subst('/^To:(.*)sip:[^@]*@[a-zA-Z0-9.]+(.*)$/t:\1$avp(sip_address)\2/ig') ) {};

...

1.3.11.  subst_uri('/re/repl/flags')

Runs the re substitution on the message uri (like subst but works only on the uri)

Meaning of the parameters is as follows:

  • '/re/repl/flags' (string) - sed like regular expression. flags can be a combination of i (case insensitive), g (global) or s (match newline don't treat it as end of line).

    're' - is regular expression

    'repl' - is replacement string - may contain pseudo-variables

    'flags' - substitution flags (i - ignore case, g - global)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.11. subst_uri usage

...
# adds 3463 prefix to numeric uris, and save the original uri (\0 match)
# as a parameter: orig_uri (just an example)
if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:3463\1@\2;orig_uri=\0/i')){$

# adds the avp 'uri_prefix' as prefix to numeric uris, and save the original
# uri (\0 match) as a parameter: orig_uri (just an example)
if (subst_uri('/^sip:([0-9]+)@(.*)$/sip:$avp(uri_prefix)\1@\2;orig_uri=\0/i')){$

...

1.3.12.  subst_user('/re/repl/flags')

Runs the re substitution on the message uri (like subst_uri but works only on the user portion of the uri)

Meaning of the parameters is as follows:

  • '/re/repl/flags' (string) - sed like regular expression. flags can be a combination of i (case insensitive), g (global) or s (match newline don't treat it as end of line).

    're' - is regular expression

    'repl' - is replacement string - may contain pseudo-variables

    'flags' - substitution flags (i - ignore case, g - global)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.12. subst usage

...
# adds 3463 prefix to uris ending with 3642 (just an example)
if (subst_user('/3642$/36423463/')){$

...
# adds avp 'user_prefix' as prefix to username in r-uri ending with 3642
if (subst_user('/(.*)3642$/$avp(user_prefix)\13642/')){$

...

1.3.13.  subst_body('/re/repl/flags')

Replaces re with repl (sed or perl like) in the body of the message.

Meaning of the parameters is as follows:

  • '/re/repl/flags' (string) - sed like regular expression. flags can be a combination of i (case insensitive), g (global) or s (match newline don't treat it as end of line).

    're' - is regular expression

    'repl' - is replacement string - may contain pseudo-variables

    'flags' - substitution flags (i - ignore case, g - global)

This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

Example 1.13. subst_body usage

...
if (subst_body("/^o=([^ ]*) /o=$fU /"))
	xlog("successfully prepared an "o" line update!\n");

...

Chapter 2. Contributors

2.1. By Commit Statistics

Table 2.1. Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)

 NameDevScoreCommitsLines ++Lines --
1. Bogdan-Andrei Iancu (@bogdan-iancu)5543440475
2. Daniel-Constantin Mierla (@miconda)4028938201
3. Razvan Crainea (@razvancrainea)396161952
4. Andrei Dragus32151540196
5. Andrei Pelinescu-Onciul2821446134
6. Jiri Kuthan (@jiriatipteldotorg)181429345
7. Liviu Chircu (@liviuchircu)12103260
8. Jan Janak (@janakj)12649627
9. Vlad Patrascu (@rvlad-patrascu)105129147
10. Juha Heinanen (@juha-h)852108

All remaining contributors: Elena-Ramona Modroiu, Henning Westerholt (@henningw), Maksym Sobolyev (@sobomax), Ovidiu Sas (@ovidiusas), Anca Vamanu, Marc Haisenko, Andreas Heise, Klaus Darilion, Vlad Paiu (@vladpaiu), Andreas Granig, Hugues Mitonneau, Konstantin Bokarius, Saúl Ibarra Corretgé (@saghul), Peter Lemenkov (@lemenkov), Edson Gellert Schubert, Christophe Sollet (@csollet).

(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)

(2) including any documentation-related commits, excluding merge commits. Regarding imported patches/code, we do our best to count the work on behalf of the proper owner, as per the "fix_authors" and "mod_renames" arrays in opensips/doc/build-contrib.sh. If you identify any patches/commits which do not get properly attributed to you, please submit a pull request which extends "fix_authors" and/or "mod_renames".

(3) ignoring whitespace edits, renamed files and auto-generated files

2.2. By Commit Activity

Table 2.2. Most recently active contributors(1) to this module

 NameCommit Activity
1. Liviu Chircu (@liviuchircu)Oct 2013 - May 2024
2. Maksym Sobolyev (@sobomax)Jul 2004 - Feb 2023
3. Razvan Crainea (@razvancrainea)Feb 2012 - Sep 2019
4. Vlad Patrascu (@rvlad-patrascu)May 2017 - Jul 2019
5. Bogdan-Andrei Iancu (@bogdan-iancu)Feb 2002 - Apr 2019
6. Peter Lemenkov (@lemenkov)Jun 2018 - Jun 2018
7. Anca VamanuOct 2008 - May 2011
8. Ovidiu Sas (@ovidiusas)Dec 2010 - Jan 2011
9. Christophe Sollet (@csollet)Dec 2010 - Dec 2010
10. Vlad Paiu (@vladpaiu)Oct 2010 - Oct 2010

All remaining contributors: Andrei Dragus, Saúl Ibarra Corretgé (@saghul), Hugues Mitonneau, Andreas Granig, Daniel-Constantin Mierla (@miconda), Konstantin Bokarius, Edson Gellert Schubert, Henning Westerholt (@henningw), Juha Heinanen (@juha-h), Andreas Heise, Klaus Darilion, Marc Haisenko, Elena-Ramona Modroiu, Andrei Pelinescu-Onciul, Jan Janak (@janakj), Jiri Kuthan (@jiriatipteldotorg).

(1) including any documentation-related commits, excluding merge commits

Chapter 3. Documentation

3.1. Contributors

Last edited by: Liviu Chircu (@liviuchircu), Vlad Patrascu (@rvlad-patrascu), Peter Lemenkov (@lemenkov), Razvan Crainea (@razvancrainea), Bogdan-Andrei Iancu (@bogdan-iancu), Ovidiu Sas (@ovidiusas), Andrei Dragus, Anca Vamanu, Andreas Granig, Daniel-Constantin Mierla (@miconda), Konstantin Bokarius, Edson Gellert Schubert, Juha Heinanen (@juha-h), Klaus Darilion, Marc Haisenko, Elena-Ramona Modroiu, Jan Janak (@janakj), Maksym Sobolyev (@sobomax), Jiri Kuthan (@jiriatipteldotorg), Andrei Pelinescu-Onciul.

Documentation Copyrights:

Copyright © 2003 FhG FOKUS