diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp new file mode 100644 index 0000000..bc6a41f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp @@ -0,0 +1,30 @@ +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" +#include "Swiften/Base/foreach.h" +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLRawTextNode.h" +#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" + +namespace Swift { + +SecurityLabelsCatalogSerializer::SecurityLabelsCatalogSerializer() : GenericPayloadSerializer<SecurityLabelsCatalog>() { +} + +String SecurityLabelsCatalogSerializer::serializePayload(boost::shared_ptr<SecurityLabelsCatalog> catalog) const { + XMLElement element("catalog", "urn:xmpp:sec-label:catalog:0"); + if (!catalog->getName().isEmpty()) { + element.setAttribute("name", catalog->getName()); + } + if (catalog->getTo().isValid()) { + element.setAttribute("to", catalog->getTo()); + } + if (!catalog->getDescription().isEmpty()) { + element.setAttribute("desc", catalog->getDescription()); + } + foreach (const SecurityLabel& label, catalog->getLabels()) { + String serializedLabel = SecurityLabelSerializer().serialize(boost::shared_ptr<SecurityLabel>(new SecurityLabel(label))); + element.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializedLabel))); + } + return element.serialize(); +} + +} |