summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/Makefile.inc1
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc3
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp32
-rw-r--r--Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp26
-rw-r--r--Swiften/Parser/PayloadParsers/VCardUpdateParser.h25
-rw-r--r--Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h11
7 files changed, 99 insertions, 1 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index fb2fea7..de66278 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -14,6 +14,7 @@
#include "Swiften/Parser/PayloadParsers/DiscoInfoParserFactory.h"
#include "Swiften/Parser/PayloadParsers/SecurityLabelParserFactory.h"
#include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h"
using namespace boost;
@@ -32,6 +33,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(shared_ptr<PayloadParserFactory>(new StartSessionParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new SecurityLabelParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new SecurityLabelsCatalogParserFactory()));
+ factories_.push_back(shared_ptr<PayloadParserFactory>(new VCardUpdateParserFactory()));
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
addFactory(factory.get());
}
diff --git a/Swiften/Parser/PayloadParsers/Makefile.inc b/Swiften/Parser/PayloadParsers/Makefile.inc
index 828dc5e..e7ea276 100644
--- a/Swiften/Parser/PayloadParsers/Makefile.inc
+++ b/Swiften/Parser/PayloadParsers/Makefile.inc
@@ -10,6 +10,7 @@ SWIFTEN_SOURCES += \
Swiften/Parser/PayloadParsers/ErrorParser.cpp \
Swiften/Parser/PayloadParsers/RosterParser.cpp \
Swiften/Parser/PayloadParsers/ResourceBindParser.cpp \
+ Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp \
Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
include Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc b/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
index f4d4cf9..6d492c1 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
+++ b/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
@@ -9,4 +9,5 @@ UNITTEST_SOURCES += \
Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp \
Swiften/Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp \
Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp \
- Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp
+ Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp \
+ Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp
new file mode 100644
index 0000000..0d9ae64
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp
@@ -0,0 +1,32 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Parser/PayloadParsers/VCardUpdateParser.h"
+#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h"
+
+using namespace Swift;
+
+class VCardUpdateParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(VCardUpdateParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ VCardUpdateParserTest() {}
+
+ void testParse() {
+ VCardUpdateParser testling;
+ PayloadParserTester parser(&testling);
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<x xmlns='vcard-temp:x:update'>"
+ "<photo>sha1-hash-of-image</photo>"
+ "</x>"));
+
+ VCardUpdate* payload = dynamic_cast<VCardUpdate*>(testling.getPayload().get());
+ CPPUNIT_ASSERT_EQUAL(String("sha1-hash-of-image"), payload->getPhotoHash());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(VCardUpdateParserTest);
diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp
new file mode 100644
index 0000000..855f9b0
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp
@@ -0,0 +1,26 @@
+#include "Swiften/Parser/PayloadParsers/VCardUpdateParser.h"
+
+namespace Swift {
+
+VCardUpdateParser::VCardUpdateParser() : level_(TopLevel) {
+}
+
+void VCardUpdateParser::handleStartElement(const String& element, const String&, const AttributeMap& attributes) {
+ if (level_ == PayloadLevel) {
+ currentText_ = "";
+ }
+ ++level_;
+}
+
+void VCardUpdateParser::handleEndElement(const String& element, const String&) {
+ --level_;
+ if (level_ == PayloadLevel && element == "photo") {
+ getPayloadInternal()->setPhotoHash(currentText_);
+ }
+}
+
+void VCardUpdateParser::handleCharacterData(const String& text) {
+ currentText_ += text;
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParser.h b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h
new file mode 100644
index 0000000..3682ccf
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/VCardUpdateParser.h
@@ -0,0 +1,25 @@
+#pragma once
+
+#include "Swiften/Elements/VCardUpdate.h"
+#include "Swiften/Parser/GenericPayloadParser.h"
+
+namespace Swift {
+ class SerializingParser;
+
+ class VCardUpdateParser : public GenericPayloadParser<VCardUpdate> {
+ public:
+ VCardUpdateParser();
+
+ virtual void handleStartElement(const String& element, const String&, const AttributeMap& attributes);
+ virtual void handleEndElement(const String& element, const String&);
+ virtual void handleCharacterData(const String& data);
+
+ private:
+ enum Level {
+ TopLevel = 0,
+ PayloadLevel = 1
+ };
+ int level_;
+ String currentText_;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h b/Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h
new file mode 100644
index 0000000..0a8dddf
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "Swiften/Parser/GenericPayloadParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/VCardUpdateParser.h"
+
+namespace Swift {
+ class VCardUpdateParserFactory : public GenericPayloadParserFactory<VCardUpdateParser> {
+ public:
+ VCardUpdateParserFactory() : GenericPayloadParserFactory<VCardUpdateParser>("x", "vcard-temp:x:update") {}
+ };
+}