Skip to content

TEXTOPS module

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.

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

The following modules must be loaded before this module:

  • No dependencies on other OpenSIPS modules.

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

  • None.

Searches for the re in the message.

Meaning of the parameters is as follows:

  • re - Regular expression.

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

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

Searches for the re in the body of the message.

Meaning of the parameters is as follows:

  • re - Regular expression.

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

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

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

Meaning of the parameters is as follows:

  • re - Regular expression.
  • txt - String to be appended.

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

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

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 - Regular expression.
  • txt - String to be appended.

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

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

Replaces the first occurrence of re with txt.

Meaning of the parameters is as follows:

  • re - Regular expression.
  • txt - String.

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

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

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

Meaning of the parameters is as follows:

  • re - Regular expression.
  • txt - String.

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

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

Replaces all occurrence of re with txt.

Meaning of the parameters is as follows:

  • re - Regular expression.
  • txt - String.

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

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

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 - Regular expression.
  • txt - String.

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

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

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 - Regular expression.
  • txt - String.

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

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

Replaces re with repl (sed or perl like).

Meaning of the parameters is as follows:

  • ‘/re/repl/flags’ - 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 expresion ‘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.

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') ) {};
...

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’ - 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 expresion ‘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.

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')){$
...

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’ - 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 expresion ‘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.

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/')){$
...

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

Meaning of the parameters is as follows:

  • ‘/re/repl/flags’ - 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 expresion ‘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.

subst_body usage
...
if ( subst_body('/^o=(.*) /o=$fU ') ) {};
...

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

#NameDevScoreCommitsLines++Lines—
1.Bogdan-Andrei Iancu (@bogdan-iancu)5541495532
2.Razvan Crainea (@razvancrainea)512102868
3.Daniel-Constantin Mierla (@miconda)4028949212
4.Andrei Dragus34151603259
5.Andrei Pelinescu-Onciul2821459147
6.Jiri Kuthan (@jiriatipteldotorg)181430153
7.Jan Janak (@janakj)12649627
8.Stefan Darius (@dariusstefan)9447556
9.Juha Heinanen (@juha-h)852108
10.Elena-Ramona Modroiu6320514

All remaining contributors: Henning Westerholt (@henningw), Ovidiu Sas (@ovidiusas), Anca Vamanu, Marc Haisenko, Andreas Heise, Klaus Darilion, Andreas Granig, Vlad Paiu (@vladpaiu), Maksym Sobolyev (@sobomax), Hugues Mitonneau, Liviu Chircu (@liviuchircu), Saúl Ibarra Corretgé (@saghul), Konstantin Bokarius, 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

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

#NameCommit Activity
1.Stefan Darius (@dariusstefan)Jun 2026 - Jul 2026
2.Razvan Crainea (@razvancrainea)Feb 2012 - Jun 2026
3.Liviu Chircu (@liviuchircu)Oct 2013 - Oct 2013
4.Bogdan-Andrei Iancu (@bogdan-iancu)Feb 2002 - Jan 2013
5.Anca VamanuOct 2008 - May 2011
6.Ovidiu Sas (@ovidiusas)Dec 2010 - Jan 2011
7.Christophe Sollet (@csollet)Dec 2010 - Dec 2010
8.Vlad Paiu (@vladpaiu)Oct 2010 - Oct 2010
9.Andrei DragusJul 2009 - Aug 2010
10.Saúl Ibarra Corretgé (@saghul)Apr 2010 - Apr 2010

All remaining contributors: 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), Maksym Sobolyev (@sobomax), Jiri Kuthan (@jiriatipteldotorg).

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

Last edited by: Razvan Crainea (@razvancrainea), Liviu Chircu (@liviuchircu), 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.

All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0