Prechádzať zdrojové kódy

siputils: exported to kemi the functions to check alpha numeric values

Daniel-Constantin Mierla 7 rokov pred
rodič
commit
fb07b4cb95

+ 91 - 50
src/modules/siputils/checks.c

@@ -804,30 +804,24 @@ found:
  * Check if the parameter is a valid telephone number
  * Check if the parameter is a valid telephone number
  * - optional leading + followed by digits only
  * - optional leading + followed by digits only
  */
  */
-int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2)
+int ki_is_tel_number(sip_msg_t *msg, str *tval)
 {
 {
-	str tval = {0, 0};
 	int i;
 	int i;
 
 
-	if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0)
-	{
-		LM_ERR("cannot get parameter value\n");
-		return -1;
-	}
-	if(tval.len<1)
+	if(tval==NULL || tval->len<1)
 		return -2;
 		return -2;
 
 
 	i = 0;
 	i = 0;
-	if(tval.s[0]=='+') {
-		if(tval.len<2)
+	if(tval->s[0]=='+') {
+		if(tval->len<2)
 			return -2;
 			return -2;
-		if(tval.s[1]<'1' || tval.s[1]>'9')
+		if(tval->s[1]<'1' || tval->s[1]>'9')
 			return -2;
 			return -2;
 		i = 2;
 		i = 2;
 	}
 	}
 
 
-	for(; i<tval.len; i++) {
-		if(tval.s[i]<'0' || tval.s[i]>'9')
+	for(; i<tval->len; i++) {
+		if(tval->s[i]<'0' || tval->s[i]>'9')
 			return -2;
 			return -2;
 	}
 	}
 
 
@@ -836,24 +830,35 @@ int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2)
 
 
 
 
 /*
 /*
- * Check if the parameter contains decimal digits only
+ * Check if the parameter is a valid telephone number
+ * - optional leading + followed by digits only
  */
  */
-int is_numeric(sip_msg_t *msg, char *_sp, char* _s2)
+int is_tel_number(sip_msg_t *msg, char *_sp, char* _s2)
 {
 {
 	str tval = {0, 0};
 	str tval = {0, 0};
-	int i;
 
 
-	if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0)
-	{
+	if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) {
 		LM_ERR("cannot get parameter value\n");
 		LM_ERR("cannot get parameter value\n");
 		return -1;
 		return -1;
 	}
 	}
-	if(tval.len<=0)
+
+	return ki_is_tel_number(msg, &tval);
+}
+
+
+/*
+ * Check if the parameter contains decimal digits only
+ */
+int ki_is_numeric(sip_msg_t *msg, str *tval)
+{
+	int i;
+
+	if(tval==NULL || tval->len<=0)
 		return -2;
 		return -2;
 
 
 	i = 0;
 	i = 0;
-	for(; i<tval.len; i++) {
-		if(tval.s[i]<'0' || tval.s[i]>'9')
+	for(; i<tval->len; i++) {
+		if(tval->s[i]<'0' || tval->s[i]>'9')
 			return -2;
 			return -2;
 	}
 	}
 
 
@@ -862,66 +867,81 @@ int is_numeric(sip_msg_t *msg, char *_sp, char* _s2)
 
 
 
 
 /*
 /*
- * Check if the parameter contains alphanumeric characters
+ * Check if the parameter contains decimal digits only
  */
  */
-int ksr_is_alphanum(sip_msg_t *msg, char *_sp, char* _s2)
+int is_numeric(sip_msg_t *msg, char *_sp, char* _s2)
 {
 {
 	str tval = {0, 0};
 	str tval = {0, 0};
-	int i;
 
 
 	if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) {
 	if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) {
 		LM_ERR("cannot get parameter value\n");
 		LM_ERR("cannot get parameter value\n");
 		return -1;
 		return -1;
 	}
 	}
-	if(tval.len<=0)
+
+	return ki_is_numeric(msg, &tval);
+}
+
+
+/*
+ * Check if the parameter contains alphanumeric characters
+ */
+int ki_is_alphanum(sip_msg_t *msg, str *tval)
+{
+	int i;
+
+	if(tval==NULL || tval->len<=0)
 		return -2;
 		return -2;
 
 
 	i = 0;
 	i = 0;
-	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;
+	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;
 	}
 	}
 
 
 	return 1;
 	return 1;
 }
 }
 
 
 /*
 /*
- * Check if the parameter contains alphanumeric characters or are part of
- * the second parameter
+ * Check if the parameter contains alphanumeric characters
  */
  */
-int ksr_is_alphanumex(sip_msg_t *msg, char *_sp, char* _se)
+int ksr_is_alphanum(sip_msg_t *msg, char *_sp, char* _s2)
 {
 {
 	str tval = {0, 0};
 	str tval = {0, 0};
-	str eset = {0, 0};
-	int i;
-	int j;
-	int found;
 
 
 	if(fixup_get_svalue(msg, (gparam_t*)_sp, &tval)!=0) {
 	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");
+		LM_ERR("cannot get parameter value\n");
 		return -1;
 		return -1;
 	}
 	}
 
 
-	if(tval.len<=0)
+	return ki_is_alphanum(msg, &tval);
+}
+
+/*
+ * Check if the parameter contains alphanumeric characters or are part of
+ * the second parameter
+ */
+int ki_is_alphanumex(sip_msg_t *msg, str *tval, str *eset)
+{
+	int i;
+	int j;
+	int found;
+
+	if(tval==NULL || tval->len<=0)
 		return -2;
 		return -2;
 
 
 	i = 0;
 	i = 0;
-	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')) ) {
-			if(eset.len<=0) {
+	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')) ) {
+			if(eset==NULL || eset->len<=0) {
 				return -3;
 				return -3;
 			}
 			}
 			found = 0;
 			found = 0;
-			for(j=0; j<eset.len; j++) {
-				if(tval.s[i]==eset.s[j]) {
+			for(j=0; j<eset->len; j++) {
+				if(tval->s[i]==eset->s[j]) {
 					found = 1;
 					found = 1;
 					break;
 					break;
 				}
 				}
@@ -934,3 +954,24 @@ int ksr_is_alphanumex(sip_msg_t *msg, char *_sp, char* _se)
 
 
 	return 1;
 	return 1;
 }
 }
+
+/*
+ * Check if the parameter contains alphanumeric characters or are part of
+ * the second parameter
+ */
+int ksr_is_alphanumex(sip_msg_t *msg, char *_sp, char* _se)
+{
+	str tval = {0, 0};
+	str eset = {0, 0};
+
+	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;
+	}
+
+	return ki_is_alphanumex(msg, &tval, &eset);
+}

+ 8 - 0
src/modules/siputils/checks.h

@@ -145,4 +145,12 @@ int ki_uri_param(sip_msg_t *_msg, str *sparam);
 
 
 int ki_uri_param_value(sip_msg_t *_msg, str *sparam, str *svalue);
 int ki_uri_param_value(sip_msg_t *_msg, str *sparam, str *svalue);
 
 
+int ki_is_tel_number(sip_msg_t *msg, str *tval);
+
+int ki_is_numeric(sip_msg_t *msg, str *tval);
+
+int ki_is_alphanum(sip_msg_t *msg, str *tval);
+
+int ki_is_alphanumex(sip_msg_t *msg, str *tval, str *eset);
+
 #endif /* CHECKS_H */
 #endif /* CHECKS_H */

+ 24 - 2
src/modules/siputils/siputils.c

@@ -164,8 +164,6 @@ static cmd_export_t cmds[]={
 		fixup_free_set_uri,	ANY_ROUTE},
 		fixup_free_set_uri,	ANY_ROUTE},
 	{"set_uri_host", (cmd_function)set_uri_host,             2, fixup_set_uri,
 	{"set_uri_host", (cmd_function)set_uri_host,             2, fixup_set_uri,
 		fixup_free_set_uri,	ANY_ROUTE},
 		fixup_free_set_uri,	ANY_ROUTE},
-	{"bind_siputils",       (cmd_function)bind_siputils,           1, 0,
-		0, 0},
 	{"is_request",          (cmd_function)w_is_request,            0, 0,
 	{"is_request",          (cmd_function)w_is_request,            0, 0,
 		0, ANY_ROUTE},
 		0, ANY_ROUTE},
 	{"is_reply",            (cmd_function)w_is_reply,              0, 0,
 	{"is_reply",            (cmd_function)w_is_reply,              0, 0,
@@ -188,6 +186,10 @@ static cmd_export_t cmds[]={
 		0, ANY_ROUTE},
 		0, ANY_ROUTE},
 	{"sip_p_charging_vector", (cmd_function)sip_handle_pcv,  1, fixup_spve_null,
 	{"sip_p_charging_vector", (cmd_function)sip_handle_pcv,  1, fixup_spve_null,
 		fixup_free_spve_null, ANY_ROUTE},
 		fixup_free_spve_null, ANY_ROUTE},
+
+	{"bind_siputils",       (cmd_function)bind_siputils,           1, 0,
+		0, 0},
+
 	{0,0,0,0,0,0}
 	{0,0,0,0,0,0}
 };
 };
 
 
@@ -518,6 +520,26 @@ static sr_kemi_t sr_kemi_siputils_exports[] = {
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
 		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
 	},
 	},
+	{ str_init("siputils"), str_init("is_tel_number"),
+		SR_KEMIP_INT, ki_is_tel_number,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("siputils"), str_init("is_numeric"),
+		SR_KEMIP_INT, ki_is_numeric,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("siputils"), str_init("is_alphanum"),
+		SR_KEMIP_INT, ki_is_alphanum,
+		{ SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("siputils"), str_init("is_alphanumex"),
+		SR_KEMIP_INT, ki_is_alphanumex,
+		{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
 
 
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
 };
 };