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/Serializer
parentc84fb752cc881dfca9727b69fcdb3230830b7cc4 (diff)
downloadswift-4e944a225d91ff4622e50186120ef0bbbb3a1d69.zip
swift-4e944a225d91ff4622e50186120ef0bbbb3a1d69.tar.bz2
Added challenge & response parser & serializer.
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/AuthChallengeSerializer.cpp17
-rw-r--r--Swiften/Serializer/AuthChallengeSerializer.h15
-rw-r--r--Swiften/Serializer/AuthResponseSerializer.cpp17
-rw-r--r--Swiften/Serializer/AuthResponseSerializer.h15
-rw-r--r--Swiften/Serializer/XMPPSerializer.cpp4
5 files changed, 68 insertions, 0 deletions
diff --git a/Swiften/Serializer/AuthChallengeSerializer.cpp b/Swiften/Serializer/AuthChallengeSerializer.cpp
new file mode 100644
index 0000000..152607d
--- /dev/null
+++ b/Swiften/Serializer/AuthChallengeSerializer.cpp
@@ -0,0 +1,17 @@
+#include "Swiften/Serializer/AuthChallengeSerializer.h"
+
+#include "Swiften/Elements/AuthChallenge.h"
+#include "Swiften/StringCodecs/Base64.h"
+
+namespace Swift {
+
+AuthChallengeSerializer::AuthChallengeSerializer() {
+}
+
+String AuthChallengeSerializer::serialize(boost::shared_ptr<Element> element) const {
+ boost::shared_ptr<AuthChallenge> authRequest(boost::dynamic_pointer_cast<AuthChallenge>(element));
+ String value = (authRequest->getValue().isEmpty() ? "=" : Base64::encode(authRequest->getValue()));
+ return "<challenge xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</challenge>";
+}
+
+}
diff --git a/Swiften/Serializer/AuthChallengeSerializer.h b/Swiften/Serializer/AuthChallengeSerializer.h
new file mode 100644
index 0000000..010d9a9
--- /dev/null
+++ b/Swiften/Serializer/AuthChallengeSerializer.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Elements/AuthChallenge.h"
+#include "Swiften/Serializer/GenericElementSerializer.h"
+
+namespace Swift {
+ class AuthChallengeSerializer : public GenericElementSerializer<AuthChallenge> {
+ public:
+ AuthChallengeSerializer();
+
+ virtual String serialize(boost::shared_ptr<Element> element) const;
+ };
+}
diff --git a/Swiften/Serializer/AuthResponseSerializer.cpp b/Swiften/Serializer/AuthResponseSerializer.cpp
new file mode 100644
index 0000000..2348a3d
--- /dev/null
+++ b/Swiften/Serializer/AuthResponseSerializer.cpp
@@ -0,0 +1,17 @@
+#include "Swiften/Serializer/AuthResponseSerializer.h"
+
+#include "Swiften/Elements/AuthResponse.h"
+#include "Swiften/StringCodecs/Base64.h"
+
+namespace Swift {
+
+AuthResponseSerializer::AuthResponseSerializer() {
+}
+
+String AuthResponseSerializer::serialize(boost::shared_ptr<Element> element) const {
+ boost::shared_ptr<AuthResponse> authRequest(boost::dynamic_pointer_cast<AuthResponse>(element));
+ String value = (authRequest->getValue().isEmpty() ? "=" : Base64::encode(authRequest->getValue()));
+ return "<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">" + value + "</response>";
+}
+
+}
diff --git a/Swiften/Serializer/AuthResponseSerializer.h b/Swiften/Serializer/AuthResponseSerializer.h
new file mode 100644
index 0000000..8d47291
--- /dev/null
+++ b/Swiften/Serializer/AuthResponseSerializer.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Elements/AuthResponse.h"
+#include "Swiften/Serializer/GenericElementSerializer.h"
+
+namespace Swift {
+ class AuthResponseSerializer : public GenericElementSerializer<AuthResponse> {
+ public:
+ AuthResponseSerializer();
+
+ virtual String serialize(boost::shared_ptr<Element> element) const;
+ };
+}
diff --git a/Swiften/Serializer/XMPPSerializer.cpp b/Swiften/Serializer/XMPPSerializer.cpp
index 660bb37..082cdf3 100644
--- a/Swiften/Serializer/XMPPSerializer.cpp
+++ b/Swiften/Serializer/XMPPSerializer.cpp
@@ -11,6 +11,8 @@
#include "Swiften/Serializer/AuthRequestSerializer.h"
#include "Swiften/Serializer/AuthFailureSerializer.h"
#include "Swiften/Serializer/AuthSuccessSerializer.h"
+#include "Swiften/Serializer/AuthChallengeSerializer.h"
+#include "Swiften/Serializer/AuthResponseSerializer.h"
#include "Swiften/Serializer/StartTLSRequestSerializer.h"
#include "Swiften/Serializer/StartTLSFailureSerializer.h"
#include "Swiften/Serializer/TLSProceedSerializer.h"
@@ -29,6 +31,8 @@ XMPPSerializer::XMPPSerializer(PayloadSerializerCollection* payloadSerializers)
serializers_.push_back(boost::shared_ptr<ElementSerializer>(new AuthRequestSerializer()));
serializers_.push_back(boost::shared_ptr<ElementSerializer>(new AuthFailureSerializer()));
serializers_.push_back(boost::shared_ptr<ElementSerializer>(new AuthSuccessSerializer()));
+ serializers_.push_back(boost::shared_ptr<ElementSerializer>(new AuthChallengeSerializer()));
+ serializers_.push_back(boost::shared_ptr<ElementSerializer>(new AuthResponseSerializer()));
serializers_.push_back(boost::shared_ptr<ElementSerializer>(new StartTLSRequestSerializer()));
serializers_.push_back(boost::shared_ptr<ElementSerializer>(new StartTLSFailureSerializer()));
serializers_.push_back(boost::shared_ptr<ElementSerializer>(new TLSProceedSerializer()));