Skip to content
Snippets Groups Projects
Commit 6bff8561 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

account manager: check info

Change-Id: Iccae983c6d70ba47e0ec20c83d209c16bbe8b2b0
parent d89bccf0
No related branches found
No related tags found
No related merge requests found
...@@ -320,6 +320,10 @@ AccountManager::addContact(const std::string& uri, bool confirmed) ...@@ -320,6 +320,10 @@ AccountManager::addContact(const std::string& uri, bool confirmed)
JAMI_ERR("addContact: invalid contact URI"); JAMI_ERR("addContact: invalid contact URI");
return; return;
} }
if (not info_) {
JAMI_ERR("addContact(): account not loaded");
return;
}
if (info_->contacts->addContact(h, confirmed)) { if (info_->contacts->addContact(h, confirmed)) {
syncDevices(); syncDevices();
} }
...@@ -333,6 +337,10 @@ AccountManager::removeContact(const std::string& uri, bool banned) ...@@ -333,6 +337,10 @@ AccountManager::removeContact(const std::string& uri, bool banned)
JAMI_ERR("removeContact: invalid contact URI"); JAMI_ERR("removeContact: invalid contact URI");
return; return;
} }
if (not info_) {
JAMI_ERR("addContact(): account not loaded");
return;
}
if (info_->contacts->removeContact(h, banned)) { if (info_->contacts->removeContact(h, banned)) {
syncDevices(); syncDevices();
} }
...@@ -391,25 +399,25 @@ AccountManager::findCertificate(const dht::InfoHash& h, std::function<void(const ...@@ -391,25 +399,25 @@ AccountManager::findCertificate(const dht::InfoHash& h, std::function<void(const
bool bool
AccountManager::setCertificateStatus(const std::string& cert_id, tls::TrustStore::PermissionStatus status) AccountManager::setCertificateStatus(const std::string& cert_id, tls::TrustStore::PermissionStatus status)
{ {
return info_->contacts->setCertificateStatus(cert_id, status); return info_ and info_->contacts->setCertificateStatus(cert_id, status);
} }
std::vector<std::string> std::vector<std::string>
AccountManager::getCertificatesByStatus(tls::TrustStore::PermissionStatus status) AccountManager::getCertificatesByStatus(tls::TrustStore::PermissionStatus status)
{ {
return info_->contacts->getCertificatesByStatus(status); return info_ ? info_->contacts->getCertificatesByStatus(status) : std::vector<std::string>{};
} }
tls::TrustStore::PermissionStatus tls::TrustStore::PermissionStatus
AccountManager::getCertificateStatus(const std::string& cert_id) const AccountManager::getCertificateStatus(const std::string& cert_id) const
{ {
return info_->contacts->getCertificateStatus(cert_id); return info_ ? info_->contacts->getCertificateStatus(cert_id) : tls::TrustStore::PermissionStatus::UNDEFINED;
} }
bool bool
AccountManager::isAllowed(const crypto::Certificate& crt, bool allowPublic) AccountManager::isAllowed(const crypto::Certificate& crt, bool allowPublic)
{ {
return info_->contacts->isAllowed(crt, allowPublic); return info_ and info_->contacts->isAllowed(crt, allowPublic);
} }
std::vector<std::map<std::string, std::string>> std::vector<std::map<std::string, std::string>>
...@@ -426,7 +434,7 @@ bool ...@@ -426,7 +434,7 @@ bool
AccountManager::acceptTrustRequest(const std::string& from) AccountManager::acceptTrustRequest(const std::string& from)
{ {
dht::InfoHash f(from); dht::InfoHash f(from);
if (info_->contacts->acceptTrustRequest(f)) { if (info_ and info_->contacts->acceptTrustRequest(f)) {
sendTrustRequestConfirm(f); sendTrustRequestConfirm(f);
syncDevices(); syncDevices();
return true; return true;
...@@ -438,7 +446,7 @@ bool ...@@ -438,7 +446,7 @@ bool
AccountManager::discardTrustRequest(const std::string& from) AccountManager::discardTrustRequest(const std::string& from)
{ {
dht::InfoHash f(from); dht::InfoHash f(from);
return info_->contacts->discardTrustRequest(f); return info_ and info_->contacts->discardTrustRequest(f);
} }
void void
...@@ -450,6 +458,10 @@ AccountManager::sendTrustRequest(const std::string& to, const std::vector<uint8_ ...@@ -450,6 +458,10 @@ AccountManager::sendTrustRequest(const std::string& to, const std::vector<uint8_
JAMI_ERR("can't send trust request to invalid hash: %s", to.c_str()); JAMI_ERR("can't send trust request to invalid hash: %s", to.c_str());
return; return;
} }
if (not info_) {
JAMI_ERR("sendTrustRequest(): account not loaded");
return;
}
if (info_->contacts->addContact(toH)) { if (info_->contacts->addContact(toH)) {
syncDevices(); syncDevices();
} }
...@@ -474,7 +486,6 @@ AccountManager::sendTrustRequestConfirm(const dht::InfoHash& toH) ...@@ -474,7 +486,6 @@ AccountManager::sendTrustRequestConfirm(const dht::InfoHash& toH)
}); });
} }
void void
AccountManager::forEachDevice(const dht::InfoHash& to, AccountManager::forEachDevice(const dht::InfoHash& to,
std::function<void(const dht::InfoHash&)>&& op, std::function<void(const dht::InfoHash&)>&& op,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment