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

Author: Xenofon Karamanos <[email protected]>
Committer: Henning Westerholt <[email protected]>
Date: 2026-06-22T17:20:22+02:00

phonenum: add support for short-number validation mode

---

Modified: src/modules/phonenum/cphonenumber.cpp
Modified: src/modules/phonenum/cphonenumber.h
Modified: src/modules/phonenum/phonenum_mod.c

---

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

---

diff --git a/src/modules/phonenum/cphonenumber.cpp 
b/src/modules/phonenum/cphonenumber.cpp
index 9ac887c5a01..82291020e0d 100644
--- a/src/modules/phonenum/cphonenumber.cpp
+++ b/src/modules/phonenum/cphonenumber.cpp
@@ -23,6 +23,7 @@
 
 #include <phonenumbers/geocoding/phonenumber_offline_geocoder.h>
 #include <phonenumbers/phonenumberutil.h>
+#include <phonenumbers/shortnumberinfo.h>
 #include <unicode/locid.h>
 #include <string.h>
 #include <cstring>
@@ -34,8 +35,15 @@ using icu::Locale;
 using std::string;
 
 const PhoneNumberUtil &_phoneUtil(*PhoneNumberUtil::GetInstance());
+static const ShortNumberInfo _shortInfo;
 static PhoneNumberOfflineGeocoder *_phoneGeoCoder =
                new PhoneNumberOfflineGeocoder();
+static int _telnum_short_mode = 0;
+
+void telnum_set_short_mode(int mode)
+{
+       _telnum_short_mode = mode;
+}
 
 const char *telnum_linetype(PhoneNumberUtil::PhoneNumberType ltype)
 {
@@ -126,6 +134,15 @@ telnum_t *telnum_parse(char *number, char *region)
                return res;
        }
        if(!_phoneUtil.IsValidNumber(parsedNumber)) {
+               if(_telnum_short_mode > 0 && regionStr != "ZZ"
+                               && _shortInfo.IsValidShortNumberForRegion(
+                                               parsedNumber, regionStr)) {
+                       res->valid = 1;
+                       res->natnum = strdup(number);
+                       res->ccname = strdup(regionStr.c_str());
+                       res->cctel = 
_phoneUtil.GetCountryCodeForRegion(regionStr);
+                       return res;
+               }
                string error = "Invalid number";
                res->error = strdup(error.c_str());
                return res;
diff --git a/src/modules/phonenum/cphonenumber.h 
b/src/modules/phonenum/cphonenumber.h
index b9e1dc09d96..f24b5fae5ce 100644
--- a/src/modules/phonenum/cphonenumber.h
+++ b/src/modules/phonenum/cphonenumber.h
@@ -50,6 +50,8 @@ extern "C"
        int telnum_possible(char *number, char *region);
        // parse a number
        telnum_t *telnum_parse(char *number, char *region);
+       // enable or disable short-number validation branch
+       void telnum_set_short_mode(int mode);
        // get country code for number
        char *telnum_cc(char *number);
 
diff --git a/src/modules/phonenum/phonenum_mod.c 
b/src/modules/phonenum/phonenum_mod.c
index c5eda4bdc35..b5fe70e0cb8 100644
--- a/src/modules/phonenum/phonenum_mod.c
+++ b/src/modules/phonenum/phonenum_mod.c
@@ -34,10 +34,12 @@
 #include "../../core/mod_fix.h"
 
 #include "phonenum_pv.h"
+#include "cphonenumber.h"
 
 MODULE_VERSION
 
 static int phonenum_smode = 0;
+static int phonenum_shortcode = 0;
 
 static int mod_init(void);
 static void mod_destroy(void);
@@ -66,6 +68,7 @@ static cmd_export_t cmds[]={
 
 static param_export_t params[]={
        {"smode", PARAM_INT, &phonenum_smode},
+       {"shortcode", PARAM_INT, &phonenum_shortcode},
        {"resid", PARAM_STR|PARAM_USE_FUNC, &phonenum_resid_param},
        {0, 0, 0}
 };
@@ -89,6 +92,7 @@ struct module_exports exports = {
  */
 static int mod_init(void)
 {
+       telnum_set_short_mode(phonenum_shortcode);
 
        if(phonenum_init_pv(phonenum_smode) != 0) {
                LM_ERR("cannot do init\n");

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to