From 048cf254585dc9b8e24fb0eae7d1ebffb48412b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Blin?= <sebastien.blin@savoirfairelinux.com> Date: Wed, 14 Apr 2021 16:15:55 -0400 Subject: [PATCH] api: remove unused importAccounts exportAccounts Change-Id: I7df89a3a8d6f138c5bc88d164116d395cd9c3e5f --- .../cx.ring.Ring.ConfigurationManager.xml | 48 ------- bin/dbus/dbusconfigurationmanager.cpp | 16 --- bin/dbus/dbusconfigurationmanager.h | 2 - bin/jni/configurationmanager.i | 3 - bin/nodejs/configurationmanager.i | 3 - src/archiver.cpp | 122 ------------------ src/archiver.h | 20 --- src/client/configurationmanager.cpp | 17 --- src/dring/configurationmanager_interface.h | 8 -- 9 files changed, 239 deletions(-) diff --git a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml index d42b6094b5..9a84f2666d 100644 --- a/bin/dbus/cx.ring.Ring.ConfigurationManager.xml +++ b/bin/dbus/cx.ring.Ring.ConfigurationManager.xml @@ -510,54 +510,6 @@ </arg> </method> - <method name="importAccounts" tp:name-for-bindings="importAccounts"> - <tp:docstring> - Import previously exported accounts - </tp:docstring> - <arg type="s" name="path" direction="in"> - <tp:docstring> - Path of the file to import - </tp:docstring> - </arg> - <arg type="s" name="password" direction="in"> - <tp:docstring> - Decryption password - </tp:docstring> - </arg> - <arg type="i" direction="out"> - <tp:docstring> - <p>Return code, 0 for success.</p> - </tp:docstring> - </arg> - </method> - - <method name="exportAccounts" tp:name-for-bindings="exportAccounts"> - <tp:docstring> - Export account configuration to an encrypted file. - </tp:docstring> - <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="VectorString"/> - <arg type="as" name="accountIDs" direction="in"> - <tp:docstring> - A list of account IDs - </tp:docstring> - </arg> - <arg type="s" name="filepath" direction="in"> - <tp:docstring> - Where to export the account - </tp:docstring> - </arg> - <arg type="s" name="password" direction="in"> - <tp:docstring> - File encryption password - </tp:docstring> - </arg> - <arg type="i" direction="out"> - <tp:docstring> - <p>Return code, 0 for success.</p> - </tp:docstring> - </arg> - </method> - <method name="registerAllAccounts" tp:name-for-bindings="registerAllAccounts"> <tp:docstring> Send account registration (REGISTER) for all accounts, even if they are not enabled. diff --git a/bin/dbus/dbusconfigurationmanager.cpp b/bin/dbus/dbusconfigurationmanager.cpp index c29d2ffe9c..aeeadb1311 100644 --- a/bin/dbus/dbusconfigurationmanager.cpp +++ b/bin/dbus/dbusconfigurationmanager.cpp @@ -737,22 +737,6 @@ DBusConfigurationManager::getVolume(const std::string& device) -> decltype(DRing return DRing::getVolume(device); } -auto -DBusConfigurationManager::exportAccounts(const std::vector<std::string>& accountIDs, - const std::string& filepath, - const std::string& password) - -> decltype(DRing::exportAccounts(accountIDs, filepath, password)) -{ - return DRing::exportAccounts(accountIDs, filepath, password); -} - -auto -DBusConfigurationManager::importAccounts(const std::string& archivePath, const std::string& password) - -> decltype(DRing::importAccounts(archivePath, password)) -{ - return DRing::importAccounts(archivePath, password); -} - void DBusConfigurationManager::connectivityChanged() { diff --git a/bin/dbus/dbusconfigurationmanager.h b/bin/dbus/dbusconfigurationmanager.h index 1400b6b7c3..e0b56ce883 100644 --- a/bin/dbus/dbusconfigurationmanager.h +++ b/bin/dbus/dbusconfigurationmanager.h @@ -173,8 +173,6 @@ public: void removeContact(const std::string& accountId, const std::string& uri, const bool& ban); std::map<std::string, std::string> getContactDetails(const std::string& accountId, const std::string& uri); std::vector<std::map<std::string, std::string>> getContacts(const std::string& accountId); - int exportAccounts(const std::vector<std::string>& accountIDs, const std::string& filepath, const std::string& password); - int importAccounts(const std::string& archivePath, const std::string& password); void connectivityChanged(); std::vector<uint64_t> dataTransferList(); void sendFile(const RingDBusDataTransferInfo& info, uint32_t& error, DRing::DataTransferId& id); diff --git a/bin/jni/configurationmanager.i b/bin/jni/configurationmanager.i index 3a2f9445c9..66c4916ad6 100644 --- a/bin/jni/configurationmanager.i +++ b/bin/jni/configurationmanager.i @@ -218,9 +218,6 @@ void addContact(const std::string& accountId, const std::string& uri); void removeContact(const std::string& accountId, const std::string& uri, const bool& ban); std::vector<std::map<std::string, std::string>> getContacts(const std::string& accountId); -int exportAccounts(const std::vector<std::string>& accountIDs, const std::string& toDir, const std::string& password); -int importAccounts(const std::string& archivePath, const std::string& password); - void connectivityChanged(); void enableProxyClient(const std::string& accountID, bool enable); diff --git a/bin/nodejs/configurationmanager.i b/bin/nodejs/configurationmanager.i index 596dfd7d77..7f2f019c4b 100644 --- a/bin/nodejs/configurationmanager.i +++ b/bin/nodejs/configurationmanager.i @@ -208,9 +208,6 @@ void addContact(const std::string& accountId, const std::string& uri); void removeContact(const std::string& accountId, const std::string& uri, const bool& ban); std::vector<std::map<std::string, std::string>> getContacts(const std::string& accountId); -int exportAccounts(std::vector<std::string> accountIDs, std::string toDir, std::string password); -int importAccounts(std::string archivePath, std::string password); - void connectivityChanged(); bool isAudioMeterActive(const std::string& id); diff --git a/src/archiver.cpp b/src/archiver.cpp index 9650c5c541..776b020514 100644 --- a/src/archiver.cpp +++ b/src/archiver.cpp @@ -106,128 +106,6 @@ accountToJsonValue(const std::map<std::string, std::string>& details) return root; } -int -exportAccounts(const std::vector<std::string>& accountIDs, - const std::string& filepath, - const std::string& password) -{ - if (filepath.empty() || !accountIDs.size()) { - JAMI_ERR("Missing arguments"); - return EINVAL; - } - - std::size_t found = filepath.find_last_of(DIR_SEPARATOR_CH); - auto toDir = filepath.substr(0, found); - auto filename = filepath.substr(found + 1); - - if (!fileutils::isDirectory(toDir)) { - JAMI_ERR("%s is not a directory", toDir.c_str()); - return ENOTDIR; - } - - // Add - Json::Value root; - Json::Value array; - - for (size_t i = 0; i < accountIDs.size(); ++i) { - auto detailsMap = Manager::instance().getAccountDetails(accountIDs[i]); - if (detailsMap.empty()) { - JAMI_WARN("Can't export account %s", accountIDs[i].c_str()); - continue; - } - - auto jsonAccount = accountToJsonValue(detailsMap); - array.append(jsonAccount); - } - root["accounts"] = array; - Json::StreamWriterBuilder wbuilder; - wbuilder["commentStyle"] = "None"; - wbuilder["indentation"] = ""; - auto output = Json::writeString(wbuilder, root); - - // Compress - std::vector<uint8_t> compressed; - try { - compressed = compress(output); - } catch (const std::runtime_error& ex) { - JAMI_ERR("Export failed: %s", ex.what()); - return 1; - } - - // Encrypt using provided password - auto encrypted = dht::crypto::aesEncrypt(compressed, password); - - // Write - try { - fileutils::saveFile(toDir + DIR_SEPARATOR_STR + filename, encrypted); - } catch (const std::runtime_error& ex) { - JAMI_ERR("Export failed: %s", ex.what()); - return EIO; - } - return 0; -} - -int -importAccounts(const std::string& archivePath, const std::string& password) -{ - if (archivePath.empty()) { - JAMI_ERR("Missing arguments"); - return EINVAL; - } - - // Read file - std::vector<uint8_t> file; - try { - file = fileutils::loadFile(archivePath); - } catch (const std::exception& ex) { - JAMI_ERR("Read failed: %s", ex.what()); - return ENOENT; - } - - // Decrypt - try { - file = dht::crypto::aesDecrypt(file, password); - } catch (const std::exception& ex) { - JAMI_ERR("Decryption failed: %s", ex.what()); - return EPERM; - } - - // Decompress - try { - file = decompress(file); - } catch (const std::exception& ex) { - JAMI_ERR("Decompression failed: %s", ex.what()); - return ERANGE; - } - - try { - const auto* char_file_begin = reinterpret_cast<const char*>(&file[0]); - const auto* char_file_end = char_file_begin + file.size(); - - // Add - std::string err; - Json::Value root; - Json::CharReaderBuilder rbuilder; - auto reader = std::unique_ptr<Json::CharReader>(rbuilder.newCharReader()); - if (!reader->parse(char_file_begin, char_file_end, &root, &err)) { - JAMI_ERR() << "Failed to parse " << err; - return ERANGE; - } - - auto& accounts = root["accounts"]; - for (int i = 0, n = accounts.size(); i < n; ++i) { - // Generate a new account id - auto accountId = jami::Manager::instance().getNewAccountId(); - auto details = jsonValueToAccount(accounts[i], accountId); - jami::Manager::instance().addAccount(details, accountId); - } - } catch (const std::exception& ex) { - JAMI_ERR("Import failed: %s", ex.what()); - return ERANGE; - } - return 0; -} - std::vector<uint8_t> compress(const std::string& str) { diff --git a/src/archiver.h b/src/archiver.h index e4333abb4b..33553f51a9 100644 --- a/src/archiver.h +++ b/src/archiver.h @@ -42,26 +42,6 @@ namespace archiver { using FileMatchPair = std::function<std::pair<bool, const std::string>(const std::string&)>; -/** - * Create a protected archive containing a list of accounts - * @param accountIDs The accounts to exports - * @param filepath The filepath where to put the resulting archive - * @param password The mandatory password to set on the archive - * @returns 0 for OK, error code otherwise - */ -int exportAccounts(const std::vector<std::string>& accountIDs, - const std::string& filepath, - const std::string& password); - -/** - * Read a protected archive and add accounts found in it - * Warning: this function must be called from a registered pjsip thread - * @param archivePath The path to the archive file - * @param password The password to read the archive - * @returns 0 for OK, error code otherwise - */ -int importAccounts(const std::string& archivePath, const std::string& password); - /** * Compress a STL string using zlib with given compression level and return * the binary data. diff --git a/src/client/configurationmanager.cpp b/src/client/configurationmanager.cpp index ba947450f7..d86f9367dc 100644 --- a/src/client/configurationmanager.cpp +++ b/src/client/configurationmanager.cpp @@ -424,23 +424,6 @@ sendTrustRequest(const std::string& accountId, acc->sendTrustRequest(to, payload); } -/* - * Import/Export accounts - */ -int -exportAccounts(const std::vector<std::string>& accountIDs, - const std::string& filepath, - const std::string& password) -{ - return jami::archiver::exportAccounts(accountIDs, filepath, password); -} - -int -importAccounts(const std::string& archivePath, const std::string& password) -{ - return jami::archiver::importAccounts(archivePath, password); -} - /// This function is used as a base for new accounts for clients that support it std::map<std::string, std::string> getAccountTemplate(const std::string& accountType) diff --git a/src/dring/configurationmanager_interface.h b/src/dring/configurationmanager_interface.h index 1c388d34eb..e528e504c3 100644 --- a/src/dring/configurationmanager_interface.h +++ b/src/dring/configurationmanager_interface.h @@ -239,14 +239,6 @@ DRING_PUBLIC std::map<std::string, std::string> getContactDetails(const std::str DRING_PUBLIC std::vector<std::map<std::string, std::string>> getContacts( const std::string& accountId); -/* - * Import/Export accounts - */ -DRING_PUBLIC int exportAccounts(const std::vector<std::string>& accountIDs, - const std::string& filepath, - const std::string& password); -DRING_PUBLIC int importAccounts(const std::string& archivePath, const std::string& password); - /* * Network connectivity */ -- GitLab