Procházet zdrojové kódy

phonenum: add national number

- add natnum property, containing the nationally formatted number, to pv
Daniel Donoghue před 1 rokem
rodič
revize
efffd1db25

+ 9 - 3
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);
 }

+ 1 - 0
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;

+ 4 - 1
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

+ 6 - 0
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);