summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-17 20:04:40 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-21 11:50:43 (GMT)
commit76d967cf7cef073501d152cb4863af418e74cdbe (patch)
tree437674039510ceba139f7c02fbebe95e5186ea94 /Swiften/Serializer/PayloadSerializers
parent94d7b0822e041740232f9d4b0f1e0f9f3dee1dd4 (diff)
downloadswift-76d967cf7cef073501d152cb4863af418e74cdbe.zip
swift-76d967cf7cef073501d152cb4863af418e74cdbe.tar.bz2
Added search parserialement.
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp62
-rw-r--r--Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h22
2 files changed, 84 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp
new file mode 100644
index 0000000..5d71fd3
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.cpp
@@ -0,0 +1,62 @@
+/*
+ * 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/SearchPayloadSerializer.h"
+
+#include <boost/shared_ptr.hpp>
+
+#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 {
+
+SearchPayloadSerializer::SearchPayloadSerializer() {
+}
+
+String SearchPayloadSerializer::serializePayload(boost::shared_ptr<SearchPayload> searchPayload) const {
+ XMLElement searchElement("query", "jabber:iq:search");
+
+ if (searchPayload->getInstructions()) {
+ searchElement.addNode(XMLElement::ref(new XMLElement("instructions", "", *searchPayload->getInstructions())));
+ }
+
+ if (searchPayload->getNick()) {
+ searchElement.addNode(XMLElement::ref(new XMLElement("nick", "", *searchPayload->getNick())));
+ }
+
+ if (searchPayload->getFirst()) {
+ searchElement.addNode(XMLElement::ref(new XMLElement("first", "", *searchPayload->getFirst())));
+ }
+
+ if (searchPayload->getLast()) {
+ searchElement.addNode(XMLElement::ref(new XMLElement("last", "", *searchPayload->getLast())));
+ }
+
+ if (searchPayload->getEMail()) {
+ searchElement.addNode(XMLElement::ref(new XMLElement("email", "", *searchPayload->getEMail())));
+ }
+
+ foreach(const SearchPayload::Item& item, searchPayload->getItems()) {
+ XMLElement::ref itemElement(new XMLElement("item"));
+ itemElement->setAttribute("jid", item.jid);
+ itemElement->addNode(XMLElement::ref(new XMLElement("first", "", item.first)));
+ itemElement->addNode(XMLElement::ref(new XMLElement("last", "", item.last)));
+ itemElement->addNode(XMLElement::ref(new XMLElement("nick", "", item.nick)));
+ itemElement->addNode(XMLElement::ref(new XMLElement("email", "", item.email)));
+
+ searchElement.addNode(itemElement);
+ }
+
+ if (Form::ref form = searchPayload->getForm()) {
+ searchElement.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(FormSerializer().serialize(form))));
+ }
+
+ return searchElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h
new file mode 100644
index 0000000..b64749b
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+
+#pragma once
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/SearchPayload.h"
+
+namespace Swift {
+ class PayloadSerializerCollection;
+
+ class SearchPayloadSerializer : public GenericPayloadSerializer<SearchPayload> {
+ public:
+ SearchPayloadSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<SearchPayload>) const;
+ };
+}