diff --git a/src/modules/phonenum/phonenum_mod.c b/src/modules/phonenum/phonenum_mod.c index 5a051842cb9..5c6c6c82942 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 f4e2763bf04..0de7b5250da 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 1decc95f4d1..2156c33be69 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