summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-10 22:02:28 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-10 22:33:58 (GMT)
commit2fec654b2345ba974b843a0868d580f9c12fdfea (patch)
treeaee0bf059eaf66864c56e31316921fb428dad114 /Swiften/Parser
parent896e2a121d58931740ea8becc0544e10e629c6c5 (diff)
downloadswift-2fec654b2345ba974b843a0868d580f9c12fdfea.zip
swift-2fec654b2345ba974b843a0868d580f9c12fdfea.tar.bz2
Added InBandRegistration classes.
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp2
-rw-r--r--Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp125
-rw-r--r--Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h37
-rw-r--r--Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h17
-rw-r--r--Swiften/Parser/SConscript1
5 files changed, 182 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 90e9038..41bba11 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -27,6 +27,7 @@
#include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h"
#include "Swiften/Parser/PayloadParsers/FormParserFactory.h"
#include "Swiften/Parser/PayloadParsers/CommandParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h"
#include "Swiften/Parser/PayloadParsers/StreamInitiationParserFactory.h"
#include "Swiften/Parser/PayloadParsers/BytestreamsParserFactory.h"
#include "Swiften/Parser/PayloadParsers/IBBParserFactory.h"
@@ -62,6 +63,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
factories_.push_back(shared_ptr<PayloadParserFactory>(new SecurityLabelsCatalogParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new FormParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new CommandParserFactory()));
+ factories_.push_back(shared_ptr<PayloadParserFactory>(new InBandRegistrationPayloadParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new StreamInitiationParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new BytestreamsParserFactory()));
factories_.push_back(shared_ptr<PayloadParserFactory>(new VCardUpdateParserFactory()));
diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp
new file mode 100644
index 0000000..0e1b593
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h"
+#include "Swiften/Parser/PayloadParsers/FormParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/FormParser.h"
+
+namespace Swift {
+
+InBandRegistrationPayloadParser::InBandRegistrationPayloadParser() : level(TopLevel), formParser(NULL) {
+ formParserFactory = new FormParserFactory();
+}
+
+InBandRegistrationPayloadParser::~InBandRegistrationPayloadParser() {
+ delete formParserFactory;
+}
+
+void InBandRegistrationPayloadParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) {
+ if (level == TopLevel) {
+ }
+ else if (level == PayloadLevel) {
+ if (element == "x" && ns == "jabber:x:data") {
+ assert(!formParser);
+ formParser = dynamic_cast<FormParser*>(formParserFactory->createPayloadParser());
+ }
+ else {
+ currentText.clear();
+ }
+ }
+
+ if (formParser) {
+ formParser->handleStartElement(element, ns, attributes);
+ }
+
+ ++level;
+}
+
+void InBandRegistrationPayloadParser::handleEndElement(const String& element, const String& ns) {
+ --level;
+
+ if (formParser) {
+ formParser->handleEndElement(element, ns);
+ }
+
+ if (level == TopLevel) {
+ }
+ else if (level == PayloadLevel) {
+ if (formParser) {
+ getPayloadInternal()->setForm(formParser->getPayloadInternal());
+ delete formParser;
+ formParser = NULL;
+ }
+ else if (element == "registered") {
+ getPayloadInternal()->setRegistered(true);
+ }
+ else if (element == "instructions") {
+ getPayloadInternal()->setInstructions(currentText);
+ }
+ else if (element == "username") {
+ getPayloadInternal()->setUsername(currentText);
+ }
+ else if (element == "nick") {
+ getPayloadInternal()->setNick(currentText);
+ }
+ else if (element == "password") {
+ getPayloadInternal()->setPassword(currentText);
+ }
+ else if (element == "name") {
+ getPayloadInternal()->setName(currentText);
+ }
+ else if (element == "first") {
+ getPayloadInternal()->setFirst(currentText);
+ }
+ else if (element == "last") {
+ getPayloadInternal()->setLast(currentText);
+ }
+ else if (element == "email") {
+ getPayloadInternal()->setEMail(currentText);
+ }
+ else if (element == "address") {
+ getPayloadInternal()->setAddress(currentText);
+ }
+ else if (element == "city") {
+ getPayloadInternal()->setCity(currentText);
+ }
+ else if (element == "state") {
+ getPayloadInternal()->setState(currentText);
+ }
+ else if (element == "zip") {
+ getPayloadInternal()->setZip(currentText);
+ }
+ else if (element == "phone") {
+ getPayloadInternal()->setPhone(currentText);
+ }
+ else if (element == "url") {
+ getPayloadInternal()->setURL(currentText);
+ }
+ else if (element == "date") {
+ getPayloadInternal()->setDate(currentText);
+ }
+ else if (element == "misc") {
+ getPayloadInternal()->setMisc(currentText);
+ }
+ else if (element == "text") {
+ getPayloadInternal()->setText(currentText);
+ }
+ else if (element == "key") {
+ getPayloadInternal()->setKey(currentText);
+ }
+ }
+}
+
+void InBandRegistrationPayloadParser::handleCharacterData(const String& data) {
+ if (formParser) {
+ formParser->handleCharacterData(data);
+ }
+ else {
+ currentText += data;
+ }
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h
new file mode 100644
index 0000000..d616e70
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h
@@ -0,0 +1,37 @@
+/*
+ * 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 <boost/optional.hpp>
+
+#include "Swiften/Elements/InBandRegistrationPayload.h"
+#include "Swiften/Parser/GenericPayloadParser.h"
+
+namespace Swift {
+ class FormParserFactory;
+ class FormParser;
+
+ class InBandRegistrationPayloadParser : public GenericPayloadParser<InBandRegistrationPayload> {
+ public:
+ InBandRegistrationPayloadParser();
+ ~InBandRegistrationPayloadParser();
+
+ 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;
+ FormParserFactory* formParserFactory;
+ FormParser* formParser;
+ String currentText;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h
new file mode 100644
index 0000000..0417174
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParserFactory.h
@@ -0,0 +1,17 @@
+/*
+ * 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/Parser/GenericPayloadParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h"
+
+namespace Swift {
+ class InBandRegistrationPayloadParserFactory : public GenericPayloadParserFactory<InBandRegistrationPayloadParser> {
+ public:
+ InBandRegistrationPayloadParserFactory() : GenericPayloadParserFactory<InBandRegistrationPayloadParser>("query", "jabber:iq:register") {}
+ };
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 1eeb266..92d5aa9 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -29,6 +29,7 @@ sources = [
"PayloadParsers/FormParser.cpp",
"PayloadParsers/IBBParser.cpp",
"PayloadParsers/CommandParser.cpp",
+ "PayloadParsers/InBandRegistrationPayloadParser.cpp",
"PayloadParsers/FullPayloadParserFactoryCollection.cpp",
"PayloadParsers/PriorityParser.cpp",
"PayloadParsers/PrivateStorageParser.cpp",