/* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include #include #include namespace Swift { DiscoInfoSerializer::DiscoInfoSerializer() : GenericPayloadSerializer() { } std::string DiscoInfoSerializer::serializePayload(std::shared_ptr discoInfo) const { XMLElement queryElement("query", "http://jabber.org/protocol/disco#info"); if (!discoInfo->getNode().empty()) { queryElement.setAttribute("node", discoInfo->getNode()); } foreach(const DiscoInfo::Identity& identity, discoInfo->getIdentities()) { std::shared_ptr identityElement(new XMLElement("identity")); if (!identity.getLanguage().empty()) { 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 std::string& feature, discoInfo->getFeatures()) { std::shared_ptr featureElement(new XMLElement("feature")); featureElement->setAttribute("var", feature); queryElement.addNode(featureElement); } foreach(const Form::ref extension, discoInfo->getExtensions()) { queryElement.addNode(std::make_shared(FormSerializer().serialize(extension))); } return queryElement.serialize(); } }