Module: kamailio
Branch: master
Commit: efffd1db25f2da411f53fdab4954c60c16c021ae
URL:
https://github.com/kamailio/kamailio/commit/efffd1db25f2da411f53fdab4954c60…
Author: Daniel Donoghue <daniel.donoghue(a)aurorainnovation.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2024-04-27T08:44:10+02:00
phonenum: add national number
- add natnum property, containing the nationally formatted number, to pv
---
Modified: src/modules/phonenum/cphonenumber.cpp
Modified: src/modules/phonenum/cphonenumber.h
Modified: src/modules/phonenum/doc/phonenum_admin.xml
Modified: src/modules/phonenum/phonenum_pv.c
---
Diff:
https://github.com/kamailio/kamailio/commit/efffd1db25f2da411f53fdab4954c60…
Patch:
https://github.com/kamailio/kamailio/commit/efffd1db25f2da411f53fdab4954c60…
---
diff --git a/src/modules/phonenum/cphonenumber.cpp
b/src/modules/phonenum/cphonenumber.cpp
index 60f5039c88f..94cc9d2cddb 100644
--- a/src/modules/phonenum/cphonenumber.cpp
+++ b/src/modules/phonenum/cphonenumber.cpp
@@ -128,9 +128,11 @@ telnum_t* telnum_parse(char* number, char* region)
return res;
}
res->valid = 1;
- string formattedNumber;
- _phoneUtil.Format(parsedNumber, PhoneNumberUtil::E164, &formattedNumber);
- res->normalized = strdup(formattedNumber.c_str());
+ string formattedNumberE164, formattedNumberNational;
+ _phoneUtil.Format(parsedNumber, PhoneNumberUtil::E164, &formattedNumberE164);
+ _phoneUtil.Format(parsedNumber, PhoneNumberUtil::NATIONAL,
&formattedNumberNational);
+ res->normalized = strdup(formattedNumberE164.c_str());
+ res->natnum = strdup(formattedNumberNational.c_str());
string descNumber = _phoneGeoCoder->GetDescriptionForNumber(parsedNumber,
Locale("en"));
res->ndesc = strdup(descNumber.c_str());
res->ltype = strdup(telnum_linetype(_phoneUtil.GetNumberType(parsedNumber)));
@@ -156,6 +158,7 @@ telnum_t* telnum_new(char* number)
tn->ltype = NULL;
tn->ndesc = NULL;
tn->ccname = NULL;
+ tn->natnum = NULL;
tn->error = NULL;
return tn;
}
@@ -183,5 +186,8 @@ void telnum_free(telnum_t* tn)
if (tn->ccname) {
free(tn->ccname);
}
+ if (tn->natnum) {
+ free(tn->natnum);
+ }
free(tn);
}
diff --git a/src/modules/phonenum/cphonenumber.h b/src/modules/phonenum/cphonenumber.h
index 1a6a06df861..b9e1dc09d96 100644
--- a/src/modules/phonenum/cphonenumber.h
+++ b/src/modules/phonenum/cphonenumber.h
@@ -37,6 +37,7 @@ extern "C"
char *ltype;
char *ndesc;
char *ccname;
+ char *natnum;
char *error;
int cctel;
int valid;
diff --git a/src/modules/phonenum/doc/phonenum_admin.xml
b/src/modules/phonenum/doc/phonenum_admin.xml
index f3a3e98ede0..740ec4780a3 100644
--- a/src/modules/phonenum/doc/phonenum_admin.xml
+++ b/src/modules/phonenum/doc/phonenum_admin.xml
@@ -205,7 +205,10 @@ if(phonenum_match_cn("1-484-555-8888", "US",
"src")) {
valid result; 0 otherwise
</para></listitem>
<listitem><para>
- <emphasis>normalized</emphasis> - normalized phone number
+ <emphasis>normalized</emphasis> - normalized (E164) phone number
+ </para></listitem>
+ <listitem><para>
+ <emphasis>natnum</emphasis> - nationally formatted phone number
</para></listitem>
<listitem><para>
<emphasis>cctel</emphasis> - country code for phone number
diff --git a/src/modules/phonenum/phonenum_pv.c b/src/modules/phonenum/phonenum_pv.c
index f6bcc025f66..5970c6b9845 100644
--- a/src/modules/phonenum/phonenum_pv.c
+++ b/src/modules/phonenum/phonenum_pv.c
@@ -190,6 +190,8 @@ int pv_parse_phonenum_name(pv_spec_p sp, str *in)
gpv->type = 0;
else if(strncmp(pvs.s, "ccname", 6) == 0)
gpv->type = 7;
+ else if(strncmp(pvs.s, "natnum", 6) == 0)
+ gpv->type = 8;
else
goto error;
break;
@@ -268,6 +270,10 @@ int pv_get_phonenum(struct sip_msg *msg, pv_param_t *param,
pv_value_t *res)
if(gpv->item->r.record->ccname == NULL)
return pv_get_null(msg, param, res);
return pv_get_strzval(msg, param, res, gpv->item->r.record->ccname);
+ case 8: /* natnum */
+ if(gpv->item->r.record->natnum == NULL)
+ return pv_get_null(msg, param, res);
+ return pv_get_strzval(msg, param, res, gpv->item->r.record->natnum);
default: /* number */
if(gpv->item->r.record->number == NULL)
return pv_get_null(msg, param, res);