diff --git a/src/jamidht/archive_account_manager.cpp b/src/jamidht/archive_account_manager.cpp index 0a44d6f784f7631f9ec076ac4122669012ae4e35..32186189d08564b8296d147b44a8d7a990c215ae 100644 --- a/src/jamidht/archive_account_manager.cpp +++ b/src/jamidht/archive_account_manager.cpp @@ -839,7 +839,7 @@ ArchiveAccountManager::registerName(const std::string& name, ethAccount = dev::KeyPair(dev::Secret(archive.eth_key)).address().hex(); } catch (const std::exception& e) { // JAMI_ERR("[Auth] can't export account: %s", e.what()); - cb(NameDirectory::RegistrationResponse::invalidCredentials); + cb(NameDirectory::RegistrationResponse::invalidCredentials, name); return; } diff --git a/src/jamidht/jamiaccount.cpp b/src/jamidht/jamiaccount.cpp index 4d7fa7808051037b631f2dcd1ffd2dc7b2734470..c02a9af90f8ad650e5dfbba6336e5be7b11a19f0 100644 --- a/src/jamidht/jamiaccount.cpp +++ b/src/jamidht/jamiaccount.cpp @@ -1453,7 +1453,7 @@ JamiAccount::registerName(const std::string& name, name, scheme, password, - [acc = getAccountID(), name, w = weak()](NameDirectory::RegistrationResponse response) { + [acc = getAccountID(), name, w = weak()](NameDirectory::RegistrationResponse response, const std::string& regName) { int res = (response == NameDirectory::RegistrationResponse::success) ? 0 @@ -1467,10 +1467,10 @@ JamiAccount::registerName(const std::string& name, : 4))); if (response == NameDirectory::RegistrationResponse::success) { if (auto this_ = w.lock()) { - this_->registeredName_ = name; - if (this_->config().registeredName != name) + this_->registeredName_ = regName; + if (this_->config().registeredName != regName) this_->editConfig( - [&](JamiAccountConfig& config) { config.registeredName = name; }); + [&](JamiAccountConfig& config) { config.registeredName = regName; }); emitSignal<libjami::ConfigurationSignal::VolatileDetailsChanged>( this_->accountID_, this_->getVolatileAccountDetails()); } diff --git a/src/jamidht/namedirectory.cpp b/src/jamidht/namedirectory.cpp index bd1555a549e90a69d54f63e7ca8e19fb86879b48..2b95521e5160f4fb2a9cda9fd5a2d441e26d4550 100644 --- a/src/jamidht/namedirectory.cpp +++ b/src/jamidht/namedirectory.cpp @@ -344,16 +344,16 @@ NameDirectory::registerName(const std::string& addr, { std::string name {n}; if (not validateName(name)) { - cb(RegistrationResponse::invalidName); + cb(RegistrationResponse::invalidName, name); return; } toLower(name); auto cacheResult = addrCache(name); if (not cacheResult.empty()) { if (cacheResult == addr) - cb(RegistrationResponse::success); + cb(RegistrationResponse::success, name); else - cb(RegistrationResponse::alreadyTaken); + cb(RegistrationResponse::alreadyTaken, name); return; } std::string body = fmt::format("{{\"addr\":\"{}\",\"owner\":\"{}\",\"signature\":\"{}\",\"publickey\":\"{}\"}}", @@ -374,22 +374,22 @@ NameDirectory::registerName(const std::string& addr, request->add_on_done_callback( [this, name, addr, cb = std::move(cb)](const dht::http::Response& response) { if (response.status_code == 400) { - cb(RegistrationResponse::incompleteRequest); + cb(RegistrationResponse::incompleteRequest, name); JAMI_ERR("RegistrationResponse::incompleteRequest"); } else if (response.status_code == 401) { - cb(RegistrationResponse::signatureVerificationFailed); + cb(RegistrationResponse::signatureVerificationFailed, name); JAMI_ERR("RegistrationResponse::signatureVerificationFailed"); } else if (response.status_code == 403) { - cb(RegistrationResponse::alreadyTaken); + cb(RegistrationResponse::alreadyTaken, name); JAMI_ERR("RegistrationResponse::alreadyTaken"); } else if (response.status_code == 409) { - cb(RegistrationResponse::alreadyTaken); + cb(RegistrationResponse::alreadyTaken, name); JAMI_ERR("RegistrationResponse::alreadyTaken"); } else if (response.status_code > 400 && response.status_code < 500) { - cb(RegistrationResponse::alreadyTaken); + cb(RegistrationResponse::alreadyTaken, name); JAMI_ERR("RegistrationResponse::alreadyTaken"); } else if (response.status_code < 200 || response.status_code > 299) { - cb(RegistrationResponse::error); + cb(RegistrationResponse::error, name); JAMI_ERR("RegistrationResponse::error"); } else { Json::Value json; @@ -401,7 +401,7 @@ NameDirectory::registerName(const std::string& addr, response.body.data() + response.body.size(), &json, &err)) { - cb(RegistrationResponse::error); + cb(RegistrationResponse::error, name); return; } auto success = json["success"].asBool(); @@ -414,7 +414,7 @@ NameDirectory::registerName(const std::string& addr, addrCache_.emplace(name, addr); nameCache_.emplace(addr, name); } - cb(success ? RegistrationResponse::success : RegistrationResponse::error); + cb(success ? RegistrationResponse::success : RegistrationResponse::error, name); } std::lock_guard lk(requestsMtx_); if (auto req = response.request.lock()) @@ -427,7 +427,7 @@ NameDirectory::registerName(const std::string& addr, request->send(); } catch (const std::exception& e) { JAMI_ERR("Error when performing name registration: %s", e.what()); - cb(RegistrationResponse::error); + cb(RegistrationResponse::error, name); std::lock_guard lk(requestsMtx_); if (request) requests_.erase(request); diff --git a/src/jamidht/namedirectory.h b/src/jamidht/namedirectory.h index e7d3b40ec5b194fe6005fa1e6a8d84e03aabb3f7..2d7a862ab54c744e4b4ba74a6155308a20bbca39 100644 --- a/src/jamidht/namedirectory.h +++ b/src/jamidht/namedirectory.h @@ -69,7 +69,7 @@ public: using LookupCallback = std::function<void(const std::string& result, Response response)>; using SearchResult = std::vector<std::map<std::string, std::string>>; using SearchCallback = std::function<void(const SearchResult& result, Response response)>; - using RegistrationCallback = std::function<void(RegistrationResponse response)>; + using RegistrationCallback = std::function<void(RegistrationResponse response, const std::string& name)>; NameDirectory(const std::string& serverUrl, std::shared_ptr<dht::Logger> l = {}); ~NameDirectory(); diff --git a/src/jamidht/server_account_manager.cpp b/src/jamidht/server_account_manager.cpp index d708e2d1d94040f99551c7cb55a3c86a6c0530b1..d69e115fd81fa71c4a06c262f812a8733b91f1d8 100644 --- a/src/jamidht/server_account_manager.cpp +++ b/src/jamidht/server_account_manager.cpp @@ -627,9 +627,9 @@ ServerAccountManager::revokeDevice(const std::string& device, } void -ServerAccountManager::registerName(const std::string&, std::string_view scheme, const std::string&, RegistrationCallback cb) +ServerAccountManager::registerName(const std::string& name, std::string_view scheme, const std::string&, RegistrationCallback cb) { - cb(NameDirectory::RegistrationResponse::unsupported); + cb(NameDirectory::RegistrationResponse::unsupported, name); } bool