Commit e22acb9f authored by Sébastien Blin's avatar Sébastien Blin

ringaccount: update account's archive before exporting

If the archive is not updated before exporting it, contacts can be
missing (because the file is only updated when a new device is
added for now).

Change-Id: Ie1068af26826b2a9acd1aa2c76123cff43eb6836
Gitlab: #65
parent fe226c7a
......@@ -178,6 +178,8 @@
</arg>
<arg type="s" name="destinationPath" direction="in">
</arg>
<arg type="s" name="password" direction="in">
</arg>
<arg type="b" name="success" direction="out">
<tp:docstring>
True if the operation was initialized successfully.
......
......@@ -82,9 +82,9 @@ DBusConfigurationManager::exportOnRing(const std::string& accountID, const std::
}
auto
DBusConfigurationManager::exportToFile(const std::string& accountID, const std::string& destinationPath) -> decltype(DRing::exportToFile(accountID, destinationPath))
DBusConfigurationManager::exportToFile(const std::string& accountID, const std::string& destinationPath, const std::string& password) -> decltype(DRing::exportToFile(accountID, destinationPath, password))
{
return DRing::exportToFile(accountID, destinationPath);
return DRing::exportToFile(accountID, destinationPath, password);
}
auto
......
......@@ -71,7 +71,7 @@ class DRING_PUBLIC DBusConfigurationManager :
std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
std::string addAccount(const std::map<std::string, std::string>& details);
bool exportOnRing(const std::string& accountID, const std::string& password);
bool exportToFile(const std::string& accountID, const std::string& destinationPath);
bool exportToFile(const std::string& accountID, const std::string& destinationPath, const std::string& password = {});
bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& device);
std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID);
bool changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new);
......
......@@ -98,7 +98,7 @@ std::map<std::string, std::string> getCodecDetails(const std::string& accountID,
bool setCodecDetails(const std::string& accountID, const unsigned& codecId, const std::map<std::string, std::string>& details);
std::vector<unsigned> getActiveCodecList(const std::string& accountID);
bool exportOnRing(const std::string& accountID, const std::string& password);
bool exportToFile(const std::string& accountID, const std::string& destinationPath);
bool exportToFile(const std::string& accountID, const std::string& destinationPath, const std::string& password);
std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID);
bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& deviceID);
......
......@@ -94,7 +94,7 @@ std::map<std::string, std::string> getCodecDetails(const std::string& accountID,
bool setCodecDetails(const std::string& accountID, const unsigned& codecId, const std::map<std::string, std::string>& details);
std::vector<unsigned> getActiveCodecList(const std::string& accountID);
bool exportOnRing(const std::string& accountID, const std::string& password);
bool exportToFile(const std::string& accountID, const std::string& destinationPath);
bool exportToFile(const std::string& accountID, const std::string& destinationPath, const std::string& password);
std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID);
bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& deviceID);
......
......@@ -2,7 +2,7 @@ dnl Jami - configure.ac for automake 1.9 and autoconf 2.59
dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.65])
AC_INIT([Ring Daemon],[7.1.0],[ring@gnu.org],[ring])
AC_INIT([Ring Daemon],[7.2.0],[ring@gnu.org],[ring])
AC_COPYRIGHT([[Copyright (c) Savoir-faire Linux 2004-2018]])
AC_REVISION([$Revision$])
......
......@@ -284,10 +284,10 @@ exportOnRing(const std::string& accountID, const std::string& password)
}
bool
exportToFile(const std::string& accountID, const std::string& destinationPath)
exportToFile(const std::string& accountID, const std::string& destinationPath, const std::string& password)
{
if (const auto account = ring::Manager::instance().getAccount<ring::RingAccount>(accountID)) {
return account->exportArchive(destinationPath);
return account->exportArchive(destinationPath, password);
}
return false;
}
......
......@@ -60,7 +60,7 @@ DRING_PUBLIC void setAccountActive(const std::string& accountID, bool active);
DRING_PUBLIC std::map<std::string, std::string> getAccountTemplate(const std::string& accountType);
DRING_PUBLIC std::string addAccount(const std::map<std::string, std::string>& details);
DRING_PUBLIC bool exportOnRing(const std::string& accountID, const std::string& password);
DRING_PUBLIC bool exportToFile(const std::string& accountID, const std::string& destinationPath);
DRING_PUBLIC bool exportToFile(const std::string& accountID, const std::string& destinationPath, const std::string& password = {});
DRING_PUBLIC bool revokeDevice(const std::string& accountID, const std::string& password, const std::string& deviceID);
DRING_PUBLIC std::map<std::string, std::string> getKnownRingDevices(const std::string& accountID);
DRING_PUBLIC bool changeAccountPassword(const std::string& accountID, const std::string& password_old, const std::string& password_new);
......
......@@ -1086,9 +1086,17 @@ RingAccount::addDevice(const std::string& password)
}
bool
RingAccount::exportArchive(const std::string& destinationPath)
RingAccount::exportArchive(const std::string& destinationPath, const std::string& password)
{
try {
// Save contacts if possible before exporting
AccountArchive archive;
if (!archiveHasPassword_ || !password.empty()) {
archive = readArchive(password);
updateArchive(archive);
archive.save(fileutils::getFullPath(idPath_, archivePath_), password);
}
// Export the file
auto sourcePath = fileutils::getFullPath(idPath_, archivePath_);
std::ifstream src(sourcePath, std::ios::in | std::ios::binary);
if (!src) return false;
......@@ -1097,6 +1105,9 @@ RingAccount::exportArchive(const std::string& destinationPath)
} catch (const std::runtime_error& ex) {
RING_ERR("[Account %s] Can't export archive: %s", getAccountID().c_str(), ex.what());
return false;
} catch (...) {
RING_ERR("[Account %s] Can't export archive: can't read archive", getAccountID().c_str());
return false;
}
return true;
}
......
......@@ -313,7 +313,13 @@ class RingAccount : public SIPAccountBase {
/* Devices */
void addDevice(const std::string& password);
bool exportArchive(const std::string& destinationPath);
/**
* Export the archive to a file
* @param destinationPath
* @param (optional) password, if not provided, will update the contacts only if the archive doesn't have a password
* @return if the archive was exported
*/
bool exportArchive(const std::string& destinationPath, const std::string& password = {});
bool revokeDevice(const std::string& password, const std::string& device);
std::map<std::string, std::string> getKnownDevices() const;
......
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