/* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include namespace Swift { StorageSerializer::StorageSerializer() : GenericPayloadSerializer() { } std::string StorageSerializer::serializePayload(std::shared_ptr storage) const { XMLElement storageElement("storage", "storage:bookmarks"); for (const auto& room : storage->getRooms()) { std::shared_ptr conferenceElement(new XMLElement("conference")); conferenceElement->setAttribute("name", room.name); conferenceElement->setAttribute("jid", room.jid); conferenceElement->setAttribute("autojoin", room.autoJoin ? "1" : "0"); if (!room.nick.empty()) { std::shared_ptr nickElement(new XMLElement("nick")); nickElement->addNode(std::make_shared(room.nick)); conferenceElement->addNode(nickElement); } if (room.password) { std::shared_ptr passwordElement(new XMLElement("password")); passwordElement->addNode(std::make_shared(*room.password)); conferenceElement->addNode(passwordElement); } storageElement.addNode(conferenceElement); } for (const auto& url : storage->getURLs()) { std::shared_ptr urlElement(new XMLElement("url")); urlElement->setAttribute("name", url.name); urlElement->setAttribute("url", url.url); storageElement.addNode(urlElement); } return storageElement.serialize(); } }