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

server account manager: cleanup

Change-Id: I9a4aebe059e3b6264de57fecc7cd088429489748
parent 35a6551c
No related branches found
No related tags found
No related merge requests found
...@@ -100,11 +100,9 @@ ServerAccountManager::initAuthentication( ...@@ -100,11 +100,9 @@ ServerAccountManager::initAuthentication(
request->set_body(ss.str()); request->set_body(ss.str());
} }
this_.setHeaderFields(*request); this_.setHeaderFields(*request);
request->add_on_state_change_callback([reqid, request, ctx, onAsync] request->add_on_done_callback([reqid, request, ctx, onAsync]
(Request::State state, const dht::http::Response& response){ (const dht::http::Response& response){
JAMI_DBG("[Auth] Got request callback with state=%d", (int)state); JAMI_DBG("[Auth] Got request callback with status code=%u", response.status_code);
if (state != Request::State::DONE)
return;
if (response.status_code == 0) if (response.status_code == 0)
ctx->onFailure(AuthError::SERVER_ERROR, "Can't connect to server"); ctx->onFailure(AuthError::SERVER_ERROR, "Can't connect to server");
else if (response.status_code >= 400 && response.status_code < 500) else if (response.status_code >= 400 && response.status_code < 500)
...@@ -219,13 +217,10 @@ ServerAccountManager::syncDevices() ...@@ -219,13 +217,10 @@ ServerAccountManager::syncDevices()
request->set_method(restinio::http_method_get()); request->set_method(restinio::http_method_get());
request->set_auth(creds_->username, creds_->password); request->set_auth(creds_->username, creds_->password);
setHeaderFields(*request); setHeaderFields(*request);
request->add_on_state_change_callback([reqid, onAsync = onAsync_] request->add_on_done_callback([reqid, onAsync = onAsync_] (const dht::http::Response& response){
(Request::State state, const dht::http::Response& response){ onAsync([reqid, response] (AccountManager& accountManager) {
onAsync([reqid, state, response] (AccountManager& accountManager) { JAMI_DBG("[Auth] Got request callback with status code=%u", response.status_code);
JAMI_DBG("[Auth] Got request callback with state=%d", (int)state);
auto& this_ = *static_cast<ServerAccountManager*>(&accountManager); auto& this_ = *static_cast<ServerAccountManager*>(&accountManager);
if (state != Request::State::DONE)
return;
if (response.status_code >= 200 || response.status_code < 300) { if (response.status_code >= 200 || response.status_code < 300) {
try { try {
Json::Value json; Json::Value json;
...@@ -275,13 +270,10 @@ ServerAccountManager::revokeDevice(const std::string& password, const std::strin ...@@ -275,13 +270,10 @@ ServerAccountManager::revokeDevice(const std::string& password, const std::strin
request->set_method(restinio::http_method_delete()); request->set_method(restinio::http_method_delete());
request->set_auth(info_->username, password); request->set_auth(info_->username, password);
setHeaderFields(*request); setHeaderFields(*request);
request->add_on_state_change_callback([reqid, cb, onAsync = onAsync_] request->add_on_done_callback([reqid, cb, onAsync = onAsync_] (const dht::http::Response& response){
(Request::State state, const dht::http::Response& response){ onAsync([reqid, cb, response] (AccountManager& accountManager) {
onAsync([reqid, cb, state, response] (AccountManager& accountManager) { JAMI_DBG("[Revoke] Got request callback with status code=%u", response.status_code);
JAMI_DBG("[Revoke] Got request callback with state=%d", (int) state);
auto& this_ = *static_cast<ServerAccountManager*>(&accountManager); auto& this_ = *static_cast<ServerAccountManager*>(&accountManager);
if (state != Request::State::DONE)
return;
if (response.status_code >= 200 || response.status_code < 300) { if (response.status_code >= 200 || response.status_code < 300) {
if (response.body.empty()) if (response.body.empty())
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment