diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-07-13 20:40:40 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-07-13 20:43:34 (GMT) |
commit | 7f9c693b3d90ebd5bbb7a99d99ba0dc6213dcb47 (patch) | |
tree | 8c332e98b7fbfeeee6df5c82f3cdd2307db4008f /Swiften | |
parent | 43eadfb5d884407c54ccd41cf46881ae374fdf15 (diff) | |
download | swift-contrib-7f9c693b3d90ebd5bbb7a99d99ba0dc6213dcb47.zip swift-contrib-7f9c693b3d90ebd5bbb7a99d99ba0dc6213dcb47.tar.bz2 |
Implement a clean full login procedure.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Elements/VCard.h | 4 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp | 14 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/VCardParser.cpp | 3 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp | 8 | ||||
-rw-r--r-- | Swiften/Server/ServerFromClientSession.cpp | 21 | ||||
-rw-r--r-- | Swiften/Server/ServerFromClientSession.h | 15 |
6 files changed, 57 insertions, 8 deletions
diff --git a/Swiften/Elements/VCard.h b/Swiften/Elements/VCard.h index 53be318..f389ba7 100644 --- a/Swiften/Elements/VCard.h +++ b/Swiften/Elements/VCard.h @@ -9,6 +9,9 @@ namespace Swift { public: VCard() {} + void setNickname(const String& nick) { nick_ = nick; } + const String& getNickname() const { return nick_; } + void setPhoto(const ByteArray& photo) { photo_ = photo; } const ByteArray& getPhoto() { return photo_; } @@ -18,5 +21,6 @@ namespace Swift { private: ByteArray photo_; String photoType_; + String nick_; }; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp index 2d16636..bfae4f0 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp @@ -10,6 +10,7 @@ class VCardParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(VCardParserTest); CPPUNIT_TEST(testParse_Photo); + CPPUNIT_TEST(testParse_Nickname); CPPUNIT_TEST_SUITE_END(); public: @@ -34,6 +35,19 @@ class VCardParserTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL(String("image/jpeg"), payload->getPhotoType()); CPPUNIT_ASSERT_EQUAL(ByteArray("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"), payload->getPhoto()); } + + void testParse_Nickname() { + VCardParser testling; + PayloadParserTester parser(&testling); + + CPPUNIT_ASSERT(parser.parse( + "<vCard xmlns='vcard-temp'>" + "<NICKNAME>mynick</NICKNAME>" + "</vCard>")); + + VCard* payload = dynamic_cast<VCard*>(testling.getPayload().get()); + CPPUNIT_ASSERT_EQUAL(String("mynick"), payload->getNickname()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(VCardParserTest); diff --git a/Swiften/Parser/PayloadParsers/VCardParser.cpp b/Swiften/Parser/PayloadParsers/VCardParser.cpp index a6fe2be..b7845a7 100644 --- a/Swiften/Parser/PayloadParsers/VCardParser.cpp +++ b/Swiften/Parser/PayloadParsers/VCardParser.cpp @@ -20,6 +20,9 @@ void VCardParser::handleEndElement(const String&, const String&) { else if (elementHierarchy == "/vCard/PHOTO/BINVAL") { getPayloadInternal()->setPhoto(Base64::decode(currentText_)); } + else if (elementHierarchy == "/vCard/NICKNAME") { + getPayloadInternal()->setNickname(currentText_); + } elementStack_.pop_back(); } diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp index 4e1a762..26e1623 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp @@ -3,14 +3,20 @@ #include <boost/shared_ptr.hpp> #include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" namespace Swift { VCardSerializer::VCardSerializer() : GenericPayloadSerializer<VCard>() { } -String VCardSerializer::serializePayload(boost::shared_ptr<VCard>) const { +String VCardSerializer::serializePayload(boost::shared_ptr<VCard> vcard) const { XMLElement queryElement("vCard", "vcard-temp"); + if (!vcard->getNickname().isEmpty()) { + boost::shared_ptr<XMLElement> nickElement(new XMLElement("NICKNAME")); + nickElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(vcard->getNickname()))); + queryElement.addNode(nickElement); + } // TODO return queryElement.serialize(); } diff --git a/Swiften/Server/ServerFromClientSession.cpp b/Swiften/Server/ServerFromClientSession.cpp index 4fc517f..e6ba28a 100644 --- a/Swiften/Server/ServerFromClientSession.cpp +++ b/Swiften/Server/ServerFromClientSession.cpp @@ -54,7 +54,12 @@ ServerFromClientSession::~ServerFromClientSession() { void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) { if (initialized_) { - onElementReceived(element); + if (boost::shared_ptr<Stanza> stanza = boost::dynamic_pointer_cast<Stanza>(element)) { + onStanzaReceived(stanza); + } + else { + std::cerr << "Received unexpected element" << std::endl; + } } else { if (AuthRequest* authRequest = dynamic_cast<AuthRequest*>(element.get())) { @@ -64,8 +69,9 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) } else { PLAINMessage plainMessage(authRequest->getMessage()); - if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), domain_), plainMessage.getPassword())) { + if (userRegistry_->isValidUserPassword(JID(plainMessage.getAuthenticationID(), domain_.getDomain()), plainMessage.getPassword())) { xmppLayer_->writeElement(boost::shared_ptr<AuthSuccess>(new AuthSuccess())); + user_ = plainMessage.getAuthenticationID(); authenticated_ = true; xmppLayer_->resetParser(); } @@ -77,7 +83,7 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) } else if (IQ* iq = dynamic_cast<IQ*>(element.get())) { if (boost::shared_ptr<ResourceBind> resourceBind = iq->getPayload<ResourceBind>()) { - jid_ = JID(user_, domain_, resourceBind->getResource()); + jid_ = JID(user_, domain_.getDomain(), resourceBind->getResource()); boost::shared_ptr<ResourceBind> resultResourceBind(new ResourceBind()); resultResourceBind->setJID(jid_); xmppLayer_->writeElement(IQ::createResult(JID(), iq->getID(), resultResourceBind)); @@ -91,8 +97,8 @@ void ServerFromClientSession::handleElement(boost::shared_ptr<Element> element) } void ServerFromClientSession::handleStreamStart(const String& domain) { - domain_ = domain; - xmppLayer_->writeHeader(domain_, id_); + domain_ = JID("", domain); + xmppLayer_->writeHeader(domain, id_); boost::shared_ptr<StreamFeatures> features(new StreamFeatures()); if (!authenticated_) { @@ -105,4 +111,9 @@ void ServerFromClientSession::handleStreamStart(const String& domain) { xmppLayer_->writeElement(features); } +void ServerFromClientSession::sendStanza(boost::shared_ptr<Stanza> stanza) { + xmppLayer_->writeElement(stanza); +} + + } diff --git a/Swiften/Server/ServerFromClientSession.h b/Swiften/Server/ServerFromClientSession.h index 9b340bc..6c74093 100644 --- a/Swiften/Server/ServerFromClientSession.h +++ b/Swiften/Server/ServerFromClientSession.h @@ -8,6 +8,7 @@ namespace Swift { class Element; + class Stanza; class PayloadParserFactoryCollection; class PayloadSerializerCollection; class StreamStack; @@ -27,7 +28,17 @@ namespace Swift { UserRegistry* userRegistry); ~ServerFromClientSession(); - boost::signal<void (boost::shared_ptr<Element>)> onElementReceived; + void sendStanza(boost::shared_ptr<Stanza>); + + const JID& getJID() const { + return jid_; + } + + const JID& getDomain() const { + return domain_; + } + + boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaReceived; boost::signal<void ()> onSessionFinished; boost::signal<void (const ByteArray&)> onDataWritten; boost::signal<void (const ByteArray&)> onDataRead; @@ -47,7 +58,7 @@ namespace Swift { IncomingConnectionLayer* connectionLayer_; StreamStack* streamStack_; XMPPLayer* xmppLayer_; - String domain_; + JID domain_; String user_; JID jid_; }; |