Module: kamailio
Branch: master
Commit: 76c5da5ec048cd62c0f3cab6bf38aef5f3c19248
URL: 
https://github.com/kamailio/kamailio/commit/76c5da5ec048cd62c0f3cab6bf38aef5f3c19248

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2017-03-03T09:32:05+01:00

siputils: added is_alphanumex(tval, eset) function

- check if tval contains only alphanumeric characters or those from the
  eset parameter

---

Modified: src/modules/siputils/checks.c
Modified: src/modules/siputils/checks.h
Modified: src/modules/siputils/doc/siputils_admin.xml
Modified: src/modules/siputils/siputils.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/76c5da5ec048cd62c0f3cab6bf38aef5f3c19248.diff
Patch: 
https://github.com/kamailio/kamailio/commit/76c5da5ec048cd62c0f3cab6bf38aef5f3c19248.patch

---

diff --git a/src/modules/siputils/checks.c b/src/modules/siputils/checks.c
index 1fb6060..cfddfda 100644
--- a/src/modules/siputils/checks.c
+++ b/src/modules/siputils/checks.c
@@ -808,18 +808,26 @@ int is_numeric(sip_msg_t *msg, char *_sp, char* _s2)
 }
 
 /*
- * Check if the parameter contains alphanumeric characters
+ * Check if the parameter contains alphanumeric characters or are part of
+ * the second parameter
  */
-int is_alphanum(sip_msg_t *msg, char *_sp, char* _s2)
+int is_alphanumex(sip_msg_t *msg, char *_sp, char* _se)
 {
        str tval = {0, 0};
+       str eset = {0, 0};
        int i;
+       int j;
+       int found;
 
-       if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0)
-       {
-               LM_ERR("cannot get parameter value\n");
+       if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) {
+               LM_ERR("cannot get tval parameter value\n");
                return -1;
        }
+       if(fixup_get_svalue(msg, (gparam_t*)_se, &eset)!=0) {
+               LM_ERR("cannot get eset parameter value\n");
+               return -1;
+       }
+
        if(tval.len<=0)
                return -2;
 
@@ -827,8 +835,21 @@ int is_alphanum(sip_msg_t *msg, char *_sp, char* _s2)
        for(; i<tval.len; i++) {
                if( !((tval.s[i]>='0' && tval.s[i]<='9')
                                || (tval.s[i]>='A' && tval.s[i]<='Z')
-                               || (tval.s[i]>='z' && tval.s[i]<='z')) )
-                       return -3;
+                               || (tval.s[i]>='z' && tval.s[i]<='z')) ) {
+                       if(eset.len<=0) {
+                               return -3;
+                       }
+                       found = 0;
+                       for(j=0; j<eset.len; j++) {
+                               if(tval.s[i]==eset.s[j]) {
+                                       found = 1;
+                                       break;
+                               }
+                       }
+                       if(found==0) {
+                               return -3;
+                       }
+               }
        }
 
        return 1;
diff --git a/src/modules/siputils/checks.h b/src/modules/siputils/checks.h
index 9b5be13..f071e24 100644
--- a/src/modules/siputils/checks.h
+++ b/src/modules/siputils/checks.h
@@ -129,4 +129,10 @@ int is_numeric(sip_msg_t *msg, char *_sp, char* _s2);
  */
 int is_alphanum(sip_msg_t *msg, char *_sp, char* _s2);
 
+/*
+ * Check if the parameter contains alphanumeric characters or are part of
+ * the second parameter
+ */
+int is_alphanumex(sip_msg_t *msg, char *_sp, char* _se);
+
 #endif /* CHECKS_H */
diff --git a/src/modules/siputils/doc/siputils_admin.xml 
b/src/modules/siputils/doc/siputils_admin.xml
index 60cb3d4..e28f7a2 100644
--- a/src/modules/siputils/doc/siputils_admin.xml
+++ b/src/modules/siputils/doc/siputils_admin.xml
@@ -681,6 +681,30 @@ if (is_alphanum("$rU")) {
                </example>
        </section>
 
+       <section id="siputils.f.is_alphanumex">
+               <title>
+               <function moreinfo="none">is_alphanumex(tval, eset)</function>
+               </title>
+               <para>
+                       Checks if the value of parameter 'tval' consists solely 
of decimal
+                       digits, alphabetic ASCII characters and the characters 
in the
+                       second parameter 'eset'. The parameters can include 
variables.
+               </para>
+               <para>
+               This function can be used from ANY_ROUTE.
+               </para>
+               <example>
+               <title><function>is_alphanumex</function> usage</title>
+               <programlisting format="linespecific">
+...
+if (is_alphanumex("$rU", "+.-_")) {
+   ...
+}
+...
+</programlisting>
+               </example>
+       </section>
+
        <section id="siputils.f.encode_contact">
                <title>
                <function 
moreinfo="none">encode_contact(encoding_prefix,hostpart)</function>
diff --git a/src/modules/siputils/siputils.c b/src/modules/siputils/siputils.c
index 3677086..f01bf6f 100644
--- a/src/modules/siputils/siputils.c
+++ b/src/modules/siputils/siputils.c
@@ -181,6 +181,8 @@ static cmd_export_t cmds[]={
                0, ANY_ROUTE},
        {"is_alphanum", (cmd_function)is_alphanum,               1, 
fixup_spve_null,
                0, ANY_ROUTE},
+       {"is_alphanumex", (cmd_function)is_alphanumex,           2, 
fixup_spve_spve,
+               0, ANY_ROUTE},
        {"sip_p_charging_vector", (cmd_function)sip_handle_pcv,  1, 
fixup_spve_null,
                fixup_free_spve_null, ANY_ROUTE},
        {0,0,0,0,0,0}


_______________________________________________
sr-dev mailing list
sr-dev@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to