diff --git a/engine/Channel.cpp b/engine/Channel.cpp index 8f79aadb..e7c7eb90 100644 --- a/engine/Channel.cpp +++ b/engine/Channel.cpp @@ -27,6 +27,40 @@ using namespace TelEngine; +// Find if a string appears to be an E164 phone number +bool TelEngine::isE164(const char* str) +{ + if (!str) + return false; + // an initial + character is ok, we skip it + if (*str == '+') + str++; + // at least one valid character is required + if (!*str) + return false; + for (;;) { + switch (*str++) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '*': + case '#': + break; + case '\0': + return true; + default: + return false; + } + } +} + static unsigned int s_callid = 0; static Mutex s_callidMutex; diff --git a/modules/h323chan.cpp b/modules/h323chan.cpp index c08a4c70..8d4ee514 100644 --- a/modules/h323chan.cpp +++ b/modules/h323chan.cpp @@ -208,33 +208,6 @@ static const char* CallEndReasonText(int reason) #undef MAKE_END_REASON } -static bool isE164(const char* str) -{ - if (!(str && *str)) - return false; - for (;;) { - switch (*str++) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '*': - case '#': - continue; - case 0: - return true; - default: - return false; - } - } -} - static int cleaningCount() { Lock lock(s_mutex); diff --git a/yatephone.h b/yatephone.h index 6129fd4f..c26a7749 100644 --- a/yatephone.h +++ b/yatephone.h @@ -1921,6 +1921,13 @@ protected: { return m_id; } }; +/** + * Find if a string appears to be an E164 phone number + * @param str String to check + * @return True if str appears to be a valid E164 number + */ +YATE_API bool isE164(const char* str); + }; // namespace TelEngine #endif /* __YATEPHONE_H */