summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThanos Doukoudakis <thanos.doukoudakis@isode.com>2017-07-20 16:28:31 (GMT)
committerThanos Doukoudakis <thanos.doukoudakis@isode.com>2017-07-26 08:35:20 (GMT)
commitbc58d59636f28909d90464cea7ebf5eeb8f230be (patch)
tree67c77e5f10f15eb2ec6202591ed20e24cb1d9ede /Swift/Controllers/Chat/ChatListWindowChatBoostSerialize.h
parent810d77181de6408d54fd3a07964317d4866c732d (diff)
downloadswift-bc58d59636f28909d90464cea7ebf5eeb8f230be.zip
swift-bc58d59636f28909d90464cea7ebf5eeb8f230be.tar.bz2
Workaround Boost bug to prevent crash in recents loading
Boost 1.64 introduced a regression where boost::optional deserialisation could lead to a crash when loading the recent chats. This fix updates the way we serialise the ChatListWindow::Chat and HighlightAction classes to avoid these errors. A flag has been added, to allow the use of the erroneous version of the library during the build. During runtime if needed, the client will skip loading the data, to avoid any unpredicted behaviour. Test-Information: Tested on windows 10 with different versions of boost 1.56(bundled), 1.63, 1.64, 1.65 and Ubuntu 17.04 with versions 1.56(bundled) and 1.64. Added unit tests for the serialisation ChatListWindow::Chat class. Change-Id: Idc5c3a6cfd92272b8eab2d77e243dda743803a31
Diffstat (limited to 'Swift/Controllers/Chat/ChatListWindowChatBoostSerialize.h')
-rw-r--r--Swift/Controllers/Chat/ChatListWindowChatBoostSerialize.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/Swift/Controllers/Chat/ChatListWindowChatBoostSerialize.h b/Swift/Controllers/Chat/ChatListWindowChatBoostSerialize.h
new file mode 100644
index 0000000..1e053b2
--- /dev/null
+++ b/Swift/Controllers/Chat/ChatListWindowChatBoostSerialize.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2017 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#pragma once
+
+#include <memory>
+
+#include <boost/version.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/bind.hpp>
+#include <boost/serialization/map.hpp>
+#include <boost/serialization/optional.hpp>
+#include <boost/serialization/split_free.hpp>
+#include <boost/serialization/string.hpp>
+#include <boost/serialization/vector.hpp>
+
+#include <Swift/Controllers/UIInterfaces/ChatListWindow.h>
+
+BOOST_CLASS_VERSION(Swift::ChatListWindow::Chat, 3)
+namespace Swift {
+ const boost::archive::library_version_type BoostArchiveSkipVersion(15);
+}
+
+namespace boost {
+ namespace serialization {
+ template<class Archive> void save(Archive& ar, const Swift::JID& jid, const unsigned int /*version*/) {
+ std::string jidStr = jid.toString();
+ ar << jidStr;
+ }
+
+ template<class Archive> void load(Archive& ar, Swift::JID& jid, const unsigned int /*version*/) {
+ std::string stringJID;
+ ar >> stringJID;
+ jid = Swift::JID(stringJID);
+ }
+
+ template<class Archive> inline void serialize(Archive& ar, Swift::JID& t, const unsigned int file_version) {
+ split_free(ar, t, file_version);
+ }
+
+ template<class Archive> void serialize(Archive& ar, Swift::ChatListWindow::Chat& chat, const unsigned int version) {
+ auto archiveLibraryVersion = boost::archive::BOOST_ARCHIVE_VERSION();
+ int archiveVersion = 0;
+ archive::text_oarchive* outputStream = dynamic_cast<archive::text_oarchive*>(&ar);
+ if (outputStream) {
+ archiveVersion = outputStream->get_library_version();
+ }
+ archive::text_iarchive* inputStream = dynamic_cast<archive::text_iarchive*>(&ar);
+ if (inputStream) {
+ archiveVersion = inputStream->get_library_version();
+ //Due to https://svn.boost.org/trac10/ticket/13050 the password field may fail to load and crash the client. Therefore we skip loading the values from previous versions.
+ if (archiveLibraryVersion == Swift::BoostArchiveSkipVersion && archiveLibraryVersion > archiveVersion) {
+ return;
+ }
+ }
+ ar & chat.jid;
+ ar & chat.chatName;
+ ar & chat.activity;
+ ar & chat.isMUC;
+ ar & chat.nick;
+ ar & chat.impromptuJIDs;
+ if (version > 0) {
+ if (outputStream && archiveLibraryVersion == Swift::BoostArchiveSkipVersion) {
+ //The bug does not affect the case boost::optional doesn't have a value. Therefore we store always that value, to avoid problem on future launches of the client.
+ boost::optional<std::string> empty;
+ ar & empty;
+ }
+ else {
+ ar & chat.password;
+ }
+ }
+ if (version > 1) {
+ ar & chat.inviteesNames;
+ }
+ }
+ }
+}