authdb: can now use custom phone alias when creating test accounts

parent 559870c0
......@@ -161,16 +161,17 @@ void AuthDbBackend::getPassword(const char* user, const char* host, const char *
}
void AuthDbBackend::createCachedAccount(const char* user, const char* host, const char *auth_username, const char *password,
int expires) {
int expires, const char* phone_alias) {
if (user && host) {
string key = createPasswordKey(user, auth_username ? auth_username : "");
cachePassword(key, host, password, expires);
cacheUserWithPhone(user, host, user);
cacheUserWithPhone(phone_alias ? phone_alias : user, host, user);
}
}
void AuthDbBackend::createAccount(const char* user, const char* host, const char *auth_username, const char *password, int expires) {
createCachedAccount(user, host, auth_username, password, expires);
void AuthDbBackend::createAccount(const char* user, const char* host, const char *auth_username, const char *password,
int expires, const char* phone_alias) {
createCachedAccount(user, host, auth_username, password, expires, phone_alias);
}
AuthDbBackend::CacheResult AuthDbBackend::getCachedUserWithPhone(const string &phone, const string &domain, string &user) {
......
......@@ -75,7 +75,7 @@ class AuthDbBackend {
bool cacheUserWithPhone(const std::string &phone, const std::string &domain, const std::string &user);
CacheResult getCachedPassword(const std::string &key, const std::string &domain, std::string &pass);
CacheResult getCachedUserWithPhone(const string &phone, const string &domain, string &user);
void createCachedAccount(const char* user, const char* domain, const char *auth_username, const char *password, int expires);
void createCachedAccount(const char* user, const char* domain, const char *auth_username, const char *password, int expires, const char* phone_alias = NULL);
void clearCache();
int mCacheExpire;
public:
......@@ -85,7 +85,7 @@ class AuthDbBackend {
void getUserWithPhone(const char* phone, const char* domain, AuthDbListener *listener);
virtual void getUserWithPhoneFromBackend(const char* phone, const char* domain, AuthDbListener *listener) = 0;
virtual void createAccount(const char* user, const char* domain, const char *auth_username, const char *password, int expires);
virtual void createAccount(const char* user, const char* domain, const char *auth_username, const char *password, int expires, const char* phone_alias = NULL);
virtual void getPasswordFromBackend(const std::string &id, const std::string &domain,
const std::string &authid, AuthDbListener *listener) = 0;
......
......@@ -413,10 +413,13 @@ class Authentication : public Module {
if (h && strcasecmp(h->un_value, "yes") == 0) {
url_t *url = sip->sip_from->a_url;
if (url) {
sip_unknown_t *h2 = ModuleToolbox::getCustomHeaderByName(sip, "X-Phone-Alias");
const char* phone_alias = h2 ? h2->un_value : NULL;
AuthDbBackend::get()->createAccount(url->url_user, url->url_host, url->url_user, url->url_password,
sip->sip_expires->ex_delta);
LOGD("Account created for %s@%s with password %s and expires %lu", url->url_user, url->url_host,
url->url_password, sip->sip_expires->ex_delta);
sip->sip_expires->ex_delta, phone_alias);
LOGD("Account created for %s@%s with password %s and expires %lu%s%s", url->url_user, url->url_host,
url->url_password, sip->sip_expires->ex_delta, phone_alias ? " with phone alias " : "", phone_alias ? phone_alias : "");
return 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