Module: sip-router Branch: master Commit: 666c83e9a9245fff666f5aa2111c05dbb4367357 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=666c83e9...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: Wed Sep 8 11:28:27 2010 +0200
xhttp: allow chaining with xmlrpc module
- new parameter url_skip to skip execution of xhttp event route if the HTTP URL matches the regexp - e.g., allow to execute all HTTP requests to /RPC2 via xmlrpc module with skip_url="^/RPC2"
---
modules/xhttp/README | 36 +++++++++++++++++++++++++++--------- modules/xhttp/doc/xhttp_admin.xml | 24 +++++++++++++++++++++++- modules/xhttp/xhttp_mod.c | 33 +++++++++++++++++++++++++++------ 3 files changed, 77 insertions(+), 16 deletions(-)
diff --git a/modules/xhttp/README b/modules/xhttp/README index 1ae565e..a44ee3c 100644 --- a/modules/xhttp/README +++ b/modules/xhttp/README @@ -25,7 +25,8 @@ Daniel-Constantin Mierla
3. Exported Parameters
- 3.1. url_match (str) + 3.1. url_skip (str) + 3.2. url_match (str)
4. Exported Functions
@@ -33,8 +34,9 @@ Daniel-Constantin Mierla
List of Examples
- 1.1. Set url_match parameter - 1.2. xhttp_reply usage + 1.1. Set url_skip parameter + 1.2. Set url_match parameter + 1.3. xhttp_reply usage
Chapter 1. Admin Guide
@@ -48,7 +50,8 @@ Chapter 1. Admin Guide
3. Exported Parameters
- 3.1. url_match (str) + 3.1. url_skip (str) + 3.2. url_match (str)
4. Exported Functions
@@ -83,16 +86,31 @@ Chapter 1. Admin Guide
3. Exported Parameters
- 3.1. url_match (str) + 3.1. url_skip (str) + 3.2. url_match (str)
-3.1. url_match (str) +3.1. url_skip (str) + + Regular expression to match the HTPP URL. If there is match, then event + route is not executed. + + Default value is null (don't skip). + + Example 1.1. Set url_skip parameter +... +modparam("xhttp", "url_skip", "^/RPC2") +... + +3.2. url_match (str)
Regular expression to match the HTPP URL. If there is no match, then - event route is not executed + event route is not executed. This check is done after url_skip, so if + both url_skip and url_match would match then the event route is not + executed (url_skip has higher priority).
Default value is null (match everything).
- Example 1.1. Set url_match parameter + Example 1.2. Set url_match parameter ... modparam("xhttp", "url_match", "^/sip/") ... @@ -105,7 +123,7 @@ modparam("xhttp", "url_match", "^/sip/")
Send back a reply with content-type and body.
- Example 1.2. xhttp_reply usage + Example 1.3. xhttp_reply usage ... event_route[xhttp:request] { xhttp_reply("200", "OK", "text/html", diff --git a/modules/xhttp/doc/xhttp_admin.xml b/modules/xhttp/doc/xhttp_admin.xml index 395a450..9ca9af8 100644 --- a/modules/xhttp/doc/xhttp_admin.xml +++ b/modules/xhttp/doc/xhttp_admin.xml @@ -61,10 +61,32 @@ <section> <title>Exported Parameters</title> <section> + <title><varname>url_skip</varname> (str)</title> + <para> + Regular expression to match the HTPP URL. If there is match, + then event route is not executed. + </para> + <para> + <emphasis> + Default value is null (don't skip). + </emphasis> + </para> + <example> + <title>Set <varname>url_skip</varname> parameter</title> + <programlisting format="linespecific"> +... +modparam("xhttp", "url_skip", "^/RPC2") +... +</programlisting> + </example> + </section> + <section> <title><varname>url_match</varname> (str)</title> <para> Regular expression to match the HTPP URL. If there is no match, - then event route is not executed + then event route is not executed. This check is done after + url_skip, so if both url_skip and url_match would match then + the event route is not executed (url_skip has higher priority). </para> <para> <emphasis> diff --git a/modules/xhttp/xhttp_mod.c b/modules/xhttp/xhttp_mod.c index 48ea2be..22ebcc4 100644 --- a/modules/xhttp/xhttp_mod.c +++ b/modules/xhttp/xhttp_mod.c @@ -58,7 +58,9 @@ static int pv_get_huri(struct sip_msg *msg, pv_param_t *param,
static int xhttp_route_no=DEFAULT_RT; static char* xhttp_url_match = NULL; -static regex_t xhttp_url_regexp; +static regex_t xhttp_url_match_regexp; +static char* xhttp_url_skip = NULL; +static regex_t xhttp_url_skip_regexp;
/** SL API structure */ sl_api_t slb; @@ -80,6 +82,7 @@ static pv_export_t mod_pvs[] = {
static param_export_t params[] = { {"url_match", STR_PARAM, &xhttp_url_match}, + {"url_skip", STR_PARAM, &xhttp_url_skip}, {0, 0, 0} };
@@ -138,9 +141,17 @@ static int mod_init(void)
if(xhttp_url_match!=NULL) { - memset(&xhttp_url_regexp, 0, sizeof(regex_t)); - if (regcomp(&xhttp_url_regexp, xhttp_url_match, REG_EXTENDED)!=0) { - LM_ERR("bad re %s\n", xhttp_url_match); + memset(&xhttp_url_match_regexp, 0, sizeof(regex_t)); + if (regcomp(&xhttp_url_match_regexp, xhttp_url_match, REG_EXTENDED)!=0) { + LM_ERR("bad match re %s\n", xhttp_url_match); + return E_BAD_RE; + } + } + if(xhttp_url_skip!=NULL) + { + memset(&xhttp_url_skip_regexp, 0, sizeof(regex_t)); + if (regcomp(&xhttp_url_skip_regexp, xhttp_url_skip, REG_EXTENDED)!=0) { + LM_ERR("bad skip re %s\n", xhttp_url_skip); return E_BAD_RE; } } @@ -292,12 +303,22 @@ static int xhttp_handler(sip_msg_t* msg) return NONSIP_MSG_PASS; }
- if(xhttp_url_match!=NULL) + if(xhttp_url_skip!=NULL || xhttp_url_match!=NULL) { c = msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len]; msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len] = '\0'; - if (regexec(&xhttp_url_regexp, msg->first_line.u.request.uri.s, + if (xhttp_url_skip!=NULL && + regexec(&xhttp_url_skip_regexp, msg->first_line.u.request.uri.s, + 1, &pmatch, 0)==0) + { + LM_DBG("URL matched skip re\n"); + msg->first_line.u.request.uri.s[msg->first_line.u.request.uri.len] + = c; + return NONSIP_MSG_PASS; + } + if (xhttp_url_match!=NULL && + regexec(&xhttp_url_match_regexp, msg->first_line.u.request.uri.s, 1, &pmatch, 0)!=0) { LM_DBG("URL not matched\n");