Module: sip-router
Branch: master
Commit: 42f431bc4ceefa32e044750ef60cf600f11fda25
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=42f431b…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Wed Dec 10 16:12:11 2014 +0100
siputils: new function is_tel_number(val)
- returns true if the parameter is a telephone number (optional leading
+ followed by digits)
- the parameter can contain variables
---
modules/siputils/checks.c | 29 +++++++++++++++++++++++++++++
modules/siputils/checks.h | 5 +++++
modules/siputils/siputils.c | 2 ++
3 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/modules/siputils/checks.c b/modules/siputils/checks.c
index 4cc3afd..fab644d 100644
--- a/modules/siputils/checks.c
+++ b/modules/siputils/checks.c
@@ -52,6 +52,7 @@
#include "../../pvar.h"
#include "../../lvalue.h"
#include "../../sr_module.h"
+#include "../../mod_fix.h"
#include "checks.h"
/**
@@ -725,3 +726,31 @@ found:
return 1;
}
+
+/*
+ * Check if the parameter is a valid telephone number
+ * - optional leading + followed by digits only
+ */
+int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2)
+{
+ str tval = {0, 0};
+ int i;
+
+ if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0)
+ {
+ LM_ERR("cannot get parameter value\n");
+ return -1;
+ }
+ if(tval.len<=0)
+ return -2;
+
+ i = 0;
+ if(tval.s[i]=='+') i++;
+
+ for(; i<tval.len; i++) {
+ if(tval.s[i]<'0' || tval.s[i]>'9')
+ return -2;
+ }
+
+ return 1;
+}
diff --git a/modules/siputils/checks.h b/modules/siputils/checks.h
index bc1a99a..dcc45b8 100644
--- a/modules/siputils/checks.h
+++ b/modules/siputils/checks.h
@@ -117,4 +117,9 @@ int w_is_reply(struct sip_msg* msg, char *foo, char *bar);
*/
int get_uri_param(struct sip_msg* _msg, char* _param, char* _value);
+/*
+ * Check if parameter value has a telephone number format
+ */
+int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2);
+
#endif /* CHECKS_H */
diff --git a/modules/siputils/siputils.c b/modules/siputils/siputils.c
index 4ae73b0..076c049 100644
--- a/modules/siputils/siputils.c
+++ b/modules/siputils/siputils.c
@@ -175,6 +175,8 @@ static cmd_export_t cmds[]={
0, ANY_ROUTE},
{"is_first_hop", (cmd_function)w_is_first_hop, 0, 0,
0, ANY_ROUTE},
+ {"is_tel_number", (cmd_function)is_tel_number, 1, fixup_spve_null,
+ 0, ANY_ROUTE},
{0,0,0,0,0,0}
};