summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-11-20 22:28:29 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-11-20 22:28:29 (GMT)
commit4e944a225d91ff4622e50186120ef0bbbb3a1d69 (patch)
tree2221e2ccdbaade17c419f45bfea139c3f952f85f /Swiften/Parser
parentc84fb752cc881dfca9727b69fcdb3230830b7cc4 (diff)
downloadswift-contrib-4e944a225d91ff4622e50186120ef0bbbb3a1d69.zip
swift-contrib-4e944a225d91ff4622e50186120ef0bbbb3a1d69.tar.bz2
Added challenge & response parser & serializer.
Diffstat (limited to 'Swiften/Parser')
-rw-r--r--Swiften/Parser/AuthChallengeParser.cpp24
-rw-r--r--Swiften/Parser/AuthChallengeParser.h20
-rw-r--r--Swiften/Parser/AuthResponseParser.cpp24
-rw-r--r--Swiften/Parser/AuthResponseParser.h20
-rw-r--r--Swiften/Parser/SConscript2
-rw-r--r--Swiften/Parser/XMPPParser.cpp8
6 files changed, 98 insertions, 0 deletions
diff --git a/Swiften/Parser/AuthChallengeParser.cpp b/Swiften/Parser/AuthChallengeParser.cpp
new file mode 100644
index 0000000..c83cf7d
--- /dev/null
+++ b/Swiften/Parser/AuthChallengeParser.cpp
@@ -0,0 +1,24 @@
+#include "Swiften/Parser/AuthChallengeParser.h"
+#include "Swiften/StringCodecs/Base64.h"
+
+namespace Swift {
+
+AuthChallengeParser::AuthChallengeParser() : GenericElementParser<AuthChallenge>(), depth(0) {
+}
+
+void AuthChallengeParser::handleStartElement(const String&, const String&, const AttributeMap&) {
+ ++depth;
+}
+
+void AuthChallengeParser::handleEndElement(const String&, const String&) {
+ --depth;
+ if (depth == 0) {
+ getElementGeneric()->setValue(Base64::decode(text));
+ }
+}
+
+void AuthChallengeParser::handleCharacterData(const String& text) {
+ this->text += text;
+}
+
+}
diff --git a/Swiften/Parser/AuthChallengeParser.h b/Swiften/Parser/AuthChallengeParser.h
new file mode 100644
index 0000000..be44b96
--- /dev/null
+++ b/Swiften/Parser/AuthChallengeParser.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "Swiften/Parser/GenericElementParser.h"
+#include "Swiften/Elements/AuthChallenge.h"
+#include "Swiften/Base/String.h"
+
+namespace Swift {
+ class AuthChallengeParser : public GenericElementParser<AuthChallenge> {
+ public:
+ AuthChallengeParser();
+
+ virtual void handleStartElement(const String&, const String& ns, const AttributeMap&);
+ virtual void handleEndElement(const String&, const String& ns);
+ virtual void handleCharacterData(const String&);
+
+ private:
+ int depth;
+ String text;
+ };
+}
diff --git a/Swiften/Parser/AuthResponseParser.cpp b/Swiften/Parser/AuthResponseParser.cpp
new file mode 100644
index 0000000..b5976a5
--- /dev/null
+++ b/Swiften/Parser/AuthResponseParser.cpp
@@ -0,0 +1,24 @@
+#include "Swiften/Parser/AuthResponseParser.h"
+#include "Swiften/StringCodecs/Base64.h"
+
+namespace Swift {
+
+AuthResponseParser::AuthResponseParser() : GenericElementParser<AuthResponse>(), depth(0) {
+}
+
+void AuthResponseParser::handleStartElement(const String&, const String&, const AttributeMap&) {
+ ++depth;
+}
+
+void AuthResponseParser::handleEndElement(const String&, const String&) {
+ --depth;
+ if (depth == 0) {
+ getElementGeneric()->setValue(Base64::decode(text));
+ }
+}
+
+void AuthResponseParser::handleCharacterData(const String& text) {
+ this->text += text;
+}
+
+}
diff --git a/Swiften/Parser/AuthResponseParser.h b/Swiften/Parser/AuthResponseParser.h
new file mode 100644
index 0000000..f2b3a9e
--- /dev/null
+++ b/Swiften/Parser/AuthResponseParser.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "Swiften/Parser/GenericElementParser.h"
+#include "Swiften/Elements/AuthResponse.h"
+#include "Swiften/Base/String.h"
+
+namespace Swift {
+ class AuthResponseParser : public GenericElementParser<AuthResponse> {
+ public:
+ AuthResponseParser();
+
+ virtual void handleStartElement(const String&, const String& ns, const AttributeMap&);
+ virtual void handleEndElement(const String&, const String& ns);
+ virtual void handleCharacterData(const String&);
+
+ private:
+ int depth;
+ String text;
+ };
+}
diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript
index 3330775..d04712c 100644
--- a/Swiften/Parser/SConscript
+++ b/Swiften/Parser/SConscript
@@ -7,6 +7,8 @@ myenv.MergeFlags(swiften_env.get("EXPAT_FLAGS", ""))
sources = [
"AuthRequestParser.cpp",
+ "AuthChallengeParser.cpp",
+ "AuthResponseParser.cpp",
"CompressParser.cpp",
"ElementParser.cpp",
"IQParser.cpp",
diff --git a/Swiften/Parser/XMPPParser.cpp b/Swiften/Parser/XMPPParser.cpp
index f97bed8..83de263 100644
--- a/Swiften/Parser/XMPPParser.cpp
+++ b/Swiften/Parser/XMPPParser.cpp
@@ -17,6 +17,8 @@
#include "Swiften/Parser/AuthRequestParser.h"
#include "Swiften/Parser/AuthSuccessParser.h"
#include "Swiften/Parser/AuthFailureParser.h"
+#include "Swiften/Parser/AuthChallengeParser.h"
+#include "Swiften/Parser/AuthResponseParser.h"
#include "Swiften/Parser/StartTLSParser.h"
#include "Swiften/Parser/StartTLSFailureParser.h"
#include "Swiften/Parser/CompressParser.h"
@@ -127,6 +129,12 @@ ElementParser* XMPPParser::createElementParser(const String& element, const Stri
else if (element == "failure" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") {
return new AuthFailureParser();
}
+ else if (element == "challenge" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") {
+ return new AuthChallengeParser();
+ }
+ else if (element == "response" && ns == "urn:ietf:params:xml:ns:xmpp-sasl") {
+ return new AuthResponseParser();
+ }
else if (element == "starttls") {
return new StartTLSParser();
}