/* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h" #include #include "Swiften/Base/foreach.h" #include "Swiften/Serializer/XML/XMLElement.h" #include "Swiften/Serializer/XML/XMLRawTextNode.h" #include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" namespace Swift { DiscoInfoSerializer::DiscoInfoSerializer() : GenericPayloadSerializer() { } String DiscoInfoSerializer::serializePayload(boost::shared_ptr discoInfo) const { XMLElement queryElement("query", "http://jabber.org/protocol/disco#info"); if (!discoInfo->getNode().isEmpty()) { queryElement.setAttribute("node", discoInfo->getNode()); } foreach(const DiscoInfo::Identity& identity, discoInfo->getIdentities()) { boost::shared_ptr identityElement(new XMLElement("identity")); if (!identity.getLanguage().isEmpty()) { identityElement->setAttribute("xml:lang", identity.getLanguage()); } identityElement->setAttribute("category", identity.getCategory()); identityElement->setAttribute("name", identity.getName()); identityElement->setAttribute("type", identity.getType()); queryElement.addNode(identityElement); } foreach(const String& feature, discoInfo->getFeatures()) { boost::shared_ptr featureElement(new XMLElement("feature")); featureElement->setAttribute("var", feature); queryElement.addNode(featureElement); } foreach(const Form::ref extension, discoInfo->getExtensions()) { queryElement.addNode(boost::shared_ptr(new XMLRawTextNode(FormSerializer().serialize(extension)))); } return queryElement.serialize(); } }