[sr-dev] git:master:cc7c066d: phonenum: new function phonenum_match_cn(...)

Daniel-Constantin Mierla miconda at gmail.com
Wed Mar 28 08:28:55 CEST 2018


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

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2018-03-28T08:14:37+02:00

phonenum: new function phonenum_match_cn(...)

- match a phone number within a specific country provided by country
code two letter

---

Modified: src/modules/phonenum/phonenum_mod.c
Modified: src/modules/phonenum/phonenum_pv.c
Modified: src/modules/phonenum/phonenum_pv.h

---

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

---

diff --git a/src/modules/phonenum/phonenum_mod.c b/src/modules/phonenum/phonenum_mod.c
index 5a051842cb..5c6c6c8294 100644
--- a/src/modules/phonenum/phonenum_mod.c
+++ b/src/modules/phonenum/phonenum_mod.c
@@ -43,6 +43,8 @@ static int mod_init(void);
 static void mod_destroy(void);
 
 static int w_phonenum_match(struct sip_msg *msg, char *str1, char *str2);
+static int w_phonenum_match_cn(struct sip_msg *msg, char *str1, char *str2,
+		char *str3);
 static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass);
 
 /* clang-format off */
@@ -55,6 +57,8 @@ static pv_export_t mod_pvs[] = {
 static cmd_export_t cmds[]={
 	{"phonenum_match", (cmd_function)w_phonenum_match, 2, fixup_spve_spve,
 		0, ANY_ROUTE},
+	{"phonenum_match_cn", (cmd_function)w_phonenum_match_cn, 3, fixup_spve_all,
+		0, ANY_ROUTE},
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -105,7 +109,7 @@ static int phonenum_match(sip_msg_t *msg, str *tomatch, str *pvclass)
 {
 	phonenum_pv_reset(pvclass);
 
-	return phonenum_update_pv(tomatch, pvclass);
+	return phonenum_update_pv(tomatch, pvclass, NULL);
 }
 
 static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
@@ -130,6 +134,41 @@ static int w_phonenum_match(sip_msg_t *msg, char *target, char *pvname)
 	return phonenum_match(msg, &tomatch, &pvclass);
 }
 
+static int phonenum_match_cn(sip_msg_t *msg, str *tomatch, str *pvclass, str *cc)
+{
+	phonenum_pv_reset(pvclass);
+
+	return phonenum_update_pv(tomatch, pvclass, cc);
+}
+
+static int w_phonenum_match_cn(sip_msg_t *msg, char *target, char *pvname,
+		char *cncstr)
+{
+	str tomatch = STR_NULL;
+	str pvclass = STR_NULL;
+	str cncval = STR_NULL;
+
+	if(msg == NULL) {
+		LM_ERR("received null msg\n");
+		return -1;
+	}
+
+	if(fixup_get_svalue(msg, (gparam_t *)target, &tomatch) < 0) {
+		LM_ERR("cannot get the address\n");
+		return -1;
+	}
+	if(fixup_get_svalue(msg, (gparam_t *)pvname, &pvclass) < 0) {
+		LM_ERR("cannot get the pv class\n");
+		return -1;
+	}
+	if(fixup_get_svalue(msg, (gparam_t *)cncstr, &cncval) < 0) {
+		LM_ERR("cannot get the country code\n");
+		return -1;
+	}
+
+	return phonenum_match_cn(msg, &tomatch, &pvclass, &cncval);
+}
+
 /**
  *
  */
diff --git a/src/modules/phonenum/phonenum_pv.c b/src/modules/phonenum/phonenum_pv.c
index f4e2763bf0..0de7b5250d 100644
--- a/src/modules/phonenum/phonenum_pv.c
+++ b/src/modules/phonenum/phonenum_pv.c
@@ -289,7 +289,7 @@ void phonenum_pv_reset(str *name)
 	memset(gr, 0, sizeof(sr_phonenum_record_t));
 }
 
-int phonenum_update_pv(str *tomatch, str *name)
+int phonenum_update_pv(str *tomatch, str *name, str *cncode)
 {
 	sr_phonenum_record_t *gr = NULL;
 
@@ -310,7 +310,8 @@ int phonenum_update_pv(str *tomatch, str *name)
 	strncpy(gr->tomatch, tomatch->s, tomatch->len);
 	gr->tomatch[tomatch->len] = '\0';
 	LM_DBG("attempt to match: %s\n", gr->tomatch);
-	gr->record = telnum_parse(gr->tomatch, "ZZ");
+	gr->record = telnum_parse(gr->tomatch,
+			(cncode && cncode->len>0)?cncode->s:"ZZ");
 	if(gr->record == NULL) {
 		LM_DBG("no match for: %s\n", gr->tomatch);
 		return -2;
diff --git a/src/modules/phonenum/phonenum_pv.h b/src/modules/phonenum/phonenum_pv.h
index 1decc95f4d..2156c33be6 100644
--- a/src/modules/phonenum/phonenum_pv.h
+++ b/src/modules/phonenum/phonenum_pv.h
@@ -33,7 +33,7 @@ int pv_get_phonenum(struct sip_msg *msg, pv_param_t *param,
 int phonenum_init_pv(int smode);
 void phonenum_destroy_pv(void);
 void phonenum_pv_reset(str *pvclass);
-int phonenum_update_pv(str *tomatch, str *pvclass);
+int phonenum_update_pv(str *tomatch, str *pvclass, str *cncode);
 
 #endif
 




More information about the sr-dev mailing list