Commit 3e6c5194 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added a method to know if a deviceId exists as a local user

parent 80ddf043
......@@ -331,6 +331,15 @@ namespace lime {
*/
lime::PeerDeviceStatus get_peerDeviceStatus(const std::string &peerDeviceId);
/**
* @brief checks if a device iD exists in the local users
*
* @param[in] deviceId The device Id to check
*
* @return true if the device Id exists in the local users table, false otherwise
*/
bool is_localUser(const std::string &deviceId);
/**
* @brief delete a peerDevice from local storage
*
......
......@@ -453,6 +453,20 @@ lime::PeerDeviceStatus Db::get_peerDeviceStatus(const std::string &peerDeviceId)
return lime::PeerDeviceStatus::unknown;
}
/**
* @brief checks if a device Id exists in the local users table
*
* @param[in] deviceId The device Id
*
* @return true if it exists, false otherwise
*/
bool Db::is_localUser(const std::string &deviceId) {
std::lock_guard<std::recursive_mutex> lock(*m_db_mutex);
int count = 0;
sql<<"SELECT count(*) FROM Lime_LocalUsers WHERE UserId = :deviceId LIMIT 1;", into(count), use(deviceId);
return sql.got_data() && count > 0;
}
/**
* @brief delete a peerDevice from local storage
*
......
......@@ -57,6 +57,7 @@ namespace lime {
void set_peerDeviceStatus(const std::string &peerDeviceId, const std::vector<uint8_t> &Ik, lime::PeerDeviceStatus status);
void set_peerDeviceStatus(const std::string &peerDeviceId, lime::PeerDeviceStatus status);
lime::PeerDeviceStatus get_peerDeviceStatus(const std::string &peerDeviceId);
bool is_localUser(const std::string &deviceId);
void delete_peerDevice(const std::string &peerDeviceId);
template <typename Curve>
long int check_peerDevice(const std::string &peerDeviceId, const DSA<Curve, lime::DSAtype::publicKey> &peerIk);
......
......@@ -221,6 +221,13 @@ namespace lime {
return localStorage->get_peerDeviceStatus(peerDeviceId);
}
bool LimeManager::is_localUser(const std::string &deviceId) {
// open local DB
auto localStorage = std::unique_ptr<lime::Db>(new lime::Db(m_db_access, m_db_mutex));
return localStorage->is_localUser(deviceId);
}
void LimeManager::delete_peerDevice(const std::string &peerDeviceId) {
std::lock_guard<std::mutex> lock(m_users_mutex);
// loop on all local users in cache to destroy any cached session linked to that user
......
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