/* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include #include #include namespace Swift { SecurityLabelsCatalogSerializer::SecurityLabelsCatalogSerializer() : GenericPayloadSerializer() { } std::string SecurityLabelsCatalogSerializer::serializePayload(boost::shared_ptr catalog) const { XMLElement element("catalog", "urn:xmpp:sec-label:catalog:2"); if (!catalog->getName().empty()) { element.setAttribute("name", catalog->getName()); } if (catalog->getTo().isValid()) { element.setAttribute("to", catalog->getTo()); } if (!catalog->getDescription().empty()) { element.setAttribute("desc", catalog->getDescription()); } foreach (const SecurityLabelsCatalog::Item& item, catalog->getItems()) { boost::shared_ptr itemElement(new XMLElement("item")); itemElement->setAttribute("selector", item.getSelector()); if (item.getIsDefault()) { itemElement->setAttribute("default", "true"); } if (item.getLabel()) { std::string serializedLabel = SecurityLabelSerializer().serialize(item.getLabel()); itemElement->addNode(boost::make_shared(serializedLabel)); } element.addNode(itemElement); } return element.serialize(); } }