Commit 895f089e authored by Mickaël Turnel's avatar Mickaël Turnel

Use regex function from bctoolbox

parent f4184738
......@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#endif
#include <bctoolbox/crypto.h>
#include <bctoolbox/regex.h>
BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(LinphoneAccountCreatorCbs);
......@@ -91,25 +92,6 @@ static char* _get_identity(const LinphoneAccountCreator *creator) {
return identity;
}
static bool_t is_matching_regex(const char *entry, const char* regex) {
#if _WIN32
return TRUE;
#else
regex_t regex_pattern;
char err_msg[256];
int res;
res = regcomp(&regex_pattern, regex, REG_EXTENDED | REG_NOSUB);
if(res != 0) {
regerror(res, &regex_pattern, err_msg, sizeof(err_msg));
ms_error("Could not compile regex '%s: %s", regex, err_msg);
return FALSE;
}
res = regexec(&regex_pattern, entry, 0, NULL, 0);
regfree(&regex_pattern);
return (res != REG_NOMATCH);
#endif
}
LinphoneProxyConfig * linphone_account_creator_create_proxy_config(const LinphoneAccountCreator *creator) {
LinphoneAuthInfo *info;
LinphoneProxyConfig *cfg = linphone_core_create_proxy_config(creator->core);
......@@ -359,7 +341,7 @@ LinphoneAccountCreatorUsernameStatus linphone_account_creator_set_username(Linph
return LinphoneAccountCreatorUsernameStatusTooLong;
} else if (use_phone_number && !linphone_proxy_config_is_phone_number(NULL, username)) {
return LinphoneAccountCreatorUsernameStatusInvalid;
} else if (regex && !is_matching_regex(username, regex)) {
} else if (regex && !bctbx_is_matching_regex(username, regex)) {
return LinphoneAccountCreatorUsernameStatusInvalidCharacters;
} else if (validate_uri(username, NULL, NULL) != 0) {
return LinphoneAccountCreatorUsernameStatusInvalid;
......@@ -482,10 +464,10 @@ const char * linphone_account_creator_get_display_name(const LinphoneAccountCrea
}
LinphoneAccountCreatorEmailStatus linphone_account_creator_set_email(LinphoneAccountCreator *creator, const char *email) {
if (!email || !is_matching_regex(email, "^.+@.+\\..*$")) {
if (!email || !bctbx_is_matching_regex(email, "^.+@.+\\..*$")) {
return LinphoneAccountCreatorEmailStatusMalformed;
}
if (!is_matching_regex(email, "^.+@.+\\.[A-Za-z]{2}[A-Za-z]*$")) {
if (!bctbx_is_matching_regex(email, "^.+@.+\\.[A-Za-z]{2}[A-Za-z]*$")) {
return LinphoneAccountCreatorEmailStatusInvalidCharacters;
}
set_string(&creator->email, email, TRUE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment