Commit 4c4c64e0 authored by Benjamin REIS's avatar Benjamin REIS

fix first notify of server for user with aliases

parent 485ff30b
......@@ -328,7 +328,8 @@ void SociAuthDB::getUserWithPhoneWithPool(const std::string &phone, const std::s
void SociAuthDB::getUsersWithPhonesWithPool(list<tuple<std::string,std::string,AuthDbListener*>> &creds, AuthDbListener *listener) {
steady_clock::time_point start;
steady_clock::time_point stop;
set<std::string> users;
set<pair<string, string>> presences;
std::ostringstream in;
session *sql = NULL;
list<std::string> phones;
......@@ -371,29 +372,29 @@ void SociAuthDB::getUsersWithPhonesWithPool(list<tuple<std::string,std::string,A
if(phone != "") {
string domain = row.get<string>(1);
cacheUserWithPhone(phone, domain, user);
users.insert(phone);
presences.insert(make_pair(user, phone));
} else {
users.insert(user);
presences.insert(make_pair(user, user));
}
}
if (listener){
listener->onResults(phones, users);
listener->onResults(phones, presences);
}
} catch (mysql_soci_error const &e) {
stop = steady_clock::now();
SLOGE << "[SOCI] getUsersWithPhonesWithPool MySQL error after " << DURATION_MS(start, stop) << "ms : " << e.err_num_ << " " << e.what();
SLOGE << "[SOCI] MySQL request causing the error was : " << s;
users.clear();
if (listener) listener->onResults(phones, users);
presences.clear();
if (listener) listener->onResults(phones, presences);
if (sql) reconnectSession(*sql);
} catch (exception const &e) {
stop = steady_clock::now();
SLOGE << "[SOCI] getUsersWithPhonesWithPool error after " << DURATION_MS(start, stop) << "ms : " << e.what();
users.clear();
if (listener) listener->onResults(phones, users);
presences.clear();
if (listener) listener->onResults(phones, presences);
if (sql) reconnectSession(*sql);
}
if (sql) delete sql;
......
......@@ -26,7 +26,7 @@ AuthDbBackend *AuthDbBackend::sUnique = NULL;
AuthDbListener::~AuthDbListener(){
}
void AuthDbListener::onResults(list<string> &phones, set<string> &users) {
void AuthDbListener::onResults(const list<string> &phones, const set<pair<string, string>> &presences) {
}
......
......@@ -54,7 +54,7 @@ class AuthDbListener : public StatFinishListener {
public:
virtual void onResult(AuthDbResult result, const std::string &passwd) = 0;
virtual void onResult(AuthDbResult result, const std::vector<passwd_algo_t> &passwd)=0;
virtual void onResults(std::list<std::string> &phones, std::set<std::string> &users);
virtual void onResults(const std::list<std::string> &phones, const std::set<std::pair<std::string, std::string>> &presences);
virtual void finishVerifyAlgos(const std::vector<passwd_algo_t> &pass)=0;
virtual ~AuthDbListener();
};
......@@ -206,7 +206,7 @@ private:
const std::string &authid, AuthDbListener *listener, AuthDbListener *listener_ref);
void reconnectSession( soci::session &session );
size_t poolSize;
soci::connection_pool *conn_pool;
......
......@@ -28,7 +28,7 @@ public:
, "OnAuthListener to mainthread");
belle_sip_object_unref(timer);
}
virtual void onResult(AuthDbResult result, const vector<passwd_algo_t> &passwd) {
belle_sip_source_cpp_func_t *func = new belle_sip_source_cpp_func_t([this, result, passwd](unsigned int events) {
this->processResponse(result, passwd.front().pass);
......@@ -40,36 +40,39 @@ public:
, "OnAuthListener to mainthread");
belle_sip_object_unref(timer);
}
virtual void finishVerifyAlgos(const vector<passwd_algo_t> &pass) {
return;
}
void onResults(list<std::string> &phones, set<std::string> &users) {
for(std::string phone : phones) {
if(users.size() == 0) {
this->onResult(PASSWORD_NOT_FOUND, phone);
} else if (users.find(phone) != users.end()){
this->onResult(PASSWORD_FOUND, phone);
} else {
this->onResult(PASSWORD_NOT_FOUND, phone);
void onResults(const list<string> &phones, const set<pair<string, string>> &presences) {
for(const string &phone : phones) {
if(presences.empty()) {
onResult(PASSWORD_NOT_FOUND, phone);
continue;
}
bool found = false;
for (const auto &presence : presences) {
if (presence.second == phone) {
mDInfo[presence.first] = mDInfo[phone];
onResult(PASSWORD_FOUND, presence.first);
found = true;
break;
}
}
if (!found)
onResult(PASSWORD_NOT_FOUND, phone);
}
}
private:
void processResponse(AuthDbResult result, const std::string &user) {
std::shared_ptr<PresentityPresenceInformation> info;
bool must_delete = FALSE;
if(mInfo == nullptr) {
std::map<std::string,std::shared_ptr<PresentityPresenceInformation>>::iterator it = mDInfo.find(user);
info = it->second;
} else {
info = mInfo;
must_delete = TRUE;
}
const char* cuser = belle_sip_uri_get_user(info->getEntity());
const auto &it = mDInfo.find(user);
std::shared_ptr<PresentityPresenceInformation> info = mInfo ? mInfo : it->second;
bool must_delete = !!mInfo;
const char *cuser = belle_sip_uri_get_user(info->getEntity());
if (result == AuthDbResult::PASSWORD_FOUND) {
// result is a phone alias if (and only if) user is not the same as the entity user
bool isPhone = (strcmp(user.c_str(), cuser) != 0);
......@@ -96,7 +99,7 @@ private:
delete this;
}
}
private:
belle_sip_main_loop_t *mMainLoop;
const std::shared_ptr<PresentityPresenceInformation> mInfo;
......@@ -105,7 +108,7 @@ private:
void PresenceLongterm::onNewPresenceInfo(const std::shared_ptr<PresentityPresenceInformation>& info) const {
//no longuer used because long term presence is check at each subscription in case not known yet
//const belle_sip_uri_t* uri = info->getEntity();
//SLOGD << __FILE__ << ": " << "New presence info for " << belle_sip_uri_get_user(uri) << ", checking if this user is already registered";
//AuthDbBackend::get()->getUserWithPhone(belle_sip_uri_get_user(info->getEntity()), belle_sip_uri_get_host(info->getEntity()), new PresenceAuthListener(mMainLoop, info));
......@@ -129,7 +132,7 @@ void PresenceLongterm::onListenerEvents(list<std::shared_ptr<PresentityPresenceI
}
dInfo.insert(std::pair<std::string,std::shared_ptr<PresentityPresenceInformation>>(belle_sip_uri_get_user(info->getEntity()), info));
}
AuthDbBackend::get()->getUsersWithPhone(creds
, new PresenceAuthListener(mMainLoop, dInfo));
}
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