Module: sip-router
Branch: master
Commit: 6d8a726754799cb4e7e312a1436f79da7ee91646
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6d8a726…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Fri Nov 26 14:26:27 2010 +0100
topoh: option to bind to sanity for parsing checks
- the module can bind to sanity to perform parsing checks before
proceeding to encoding/decoding of received requests
- new parameter 'sanity_checks'
---
modules/topoh/README | 18 ++++++++++++++++++
modules/topoh/doc/topoh_admin.xml | 22 ++++++++++++++++++++++
modules/topoh/topoh_mod.c | 31 +++++++++++++++++++++++++++++++
3 files changed, 71 insertions(+), 0 deletions(-)
diff --git a/modules/topoh/README b/modules/topoh/README
index 0ed980f..0cc398b 100644
--- a/modules/topoh/README
+++ b/modules/topoh/README
@@ -33,6 +33,7 @@ Daniel-Constantin Mierla
3.6. vparam_name (str)
3.7. vparam_prefix (str)
3.8. callid_prefix (str)
+ 3.9. sanity_checks (integer)
4. Exported Functions
@@ -48,6 +49,7 @@ Daniel-Constantin Mierla
1.6. Set vparam_name parameter
1.7. Set vparam_prefix parameter
1.8. Set callid_prefix parameter
+ 1.9. Set sanity_checks parameter
Chapter 1. Admin Guide
@@ -69,6 +71,7 @@ Chapter 1. Admin Guide
3.6. vparam_name (str)
3.7. vparam_prefix (str)
3.8. callid_prefix (str)
+ 3.9. sanity_checks (integer)
4. Exported Functions
@@ -117,6 +120,7 @@ Chapter 1. Admin Guide
3.6. vparam_name (str)
3.7. vparam_prefix (str)
3.8. callid_prefix (str)
+ 3.9. sanity_checks (integer)
3.1. mask_key (str)
@@ -212,6 +216,20 @@ modparam("topoh", "vparam_prefix",
"xyz")
modparam("topoh", "callid_prefix", "***")
...
+3.9. sanity_checks (integer)
+
+ If set to 1, topoh module will bind to sanity module in order to
+ perform sanity checks over received SIP request. Default sanity checks
+ are done. It is useful to check if received request is well formated
+ before proceeding to encoding/decoding.
+
+ Default value is 0 (do not bind to sanity module).
+
+ Example 1.9. Set sanity_checks parameter
+...
+modparam("topoh", "sanity_checks", 1)
+...
+
4. Exported Functions
4.1.
diff --git a/modules/topoh/doc/topoh_admin.xml b/modules/topoh/doc/topoh_admin.xml
index d028437..152de2d 100644
--- a/modules/topoh/doc/topoh_admin.xml
+++ b/modules/topoh/doc/topoh_admin.xml
@@ -225,6 +225,28 @@ modparam("topoh", "callid_prefix",
"***")
</programlisting>
</example>
</section>
+ <section>
+ <title><varname>sanity_checks</varname> (integer)</title>
+ <para>
+ If set to 1, topoh module will bind to sanity module in order
+ to perform sanity checks over received SIP request. Default
+ sanity checks are done. It is useful to check if received request
+ is well formated before proceeding to encoding/decoding.
+ </para>
+ <para>
+ <emphasis>
+ Default value is 0 (do not bind to sanity module).
+ </emphasis>
+ </para>
+ <example>
+ <title>Set <varname>sanity_checks</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("topoh", "sanity_checks", 1)
+...
+</programlisting>
+ </example>
+ </section>
</section>
<section>
diff --git a/modules/topoh/topoh_mod.c b/modules/topoh/topoh_mod.c
index 87a8a13..bc7ea8e 100644
--- a/modules/topoh/topoh_mod.c
+++ b/modules/topoh/topoh_mod.c
@@ -47,6 +47,8 @@
#include "../../parser/parse_to.h"
#include "../../parser/parse_from.h"
+#include "../../modules/sanity/api.h"
+
#include "th_mask.h"
#include "th_msg.h"
@@ -69,6 +71,9 @@ str th_uri_prefix = {0, 0};
int th_param_mask_callid = 0;
+int th_sanity_checks = 0;
+sanity_api_t scb;
+
int th_msg_received(void *data);
int th_msg_sent(void *data);
@@ -84,6 +89,7 @@ static param_export_t params[]={
{"vparam_name", STR_PARAM, &th_vparam_name.s},
{"vparam_prefix", STR_PARAM, &th_vparam_prefix.s},
{"callid_prefix", STR_PARAM, &th_callid_prefix.s},
+ {"sanity_checks", INT_PARAM, &th_sanity_checks},
{0,0,0}
};
@@ -109,6 +115,14 @@ struct module_exports exports= {
*/
static int mod_init(void)
{
+ if(th_sanity_checks!=0)
+ {
+ if(sanity_load_api(&scb)<0)
+ {
+ LM_ERR("cannot bind to sanity module\n");
+ goto error;
+ }
+ }
th_cookie_name.len = strlen(th_cookie_name.s);
th_ip.len = strlen(th_ip.s);
if(th_ip.len<=0)
@@ -175,6 +189,9 @@ error:
return -1;
}
+/**
+ *
+ */
int th_prepare_msg(sip_msg_t *msg)
{
if (parse_msg(msg->buf, msg->len, msg)!=0)
@@ -198,6 +215,9 @@ int th_prepare_msg(sip_msg_t *msg)
return 0;
}
+/**
+ *
+ */
int th_msg_received(void *data)
{
sip_msg_t msg;
@@ -223,6 +243,14 @@ int th_msg_received(void *data)
th_cookie_value.len = 2;
if(msg.first_line.type==SIP_REQUEST)
{
+ if(th_sanity_checks!=0)
+ {
+ if(scb.check_defaults(&msg)<1)
+ {
+ LM_ERR("sanity checks failed\n");
+ goto done;
+ }
+ }
dialog = (get_to(&msg)->tag_value.len>0)?1:0;
if(dialog)
{
@@ -280,6 +308,9 @@ done:
return 0;
}
+/**
+ *
+ */
int th_msg_sent(void *data)
{
sip_msg_t msg;