From cb32ea0954558da4bec9d4e9f13710a7f1a17d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Thu, 14 Oct 2010 22:14:08 +0200 Subject: Added User Nickname element, serializer, and parser. diff --git a/Swiften/Elements/Nickname.h b/Swiften/Elements/Nickname.h new file mode 100644 index 0000000..1a8d648 --- /dev/null +++ b/Swiften/Elements/Nickname.h @@ -0,0 +1,29 @@ +/* + * 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/Elements/Payload.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class Nickname : public Payload { + public: + Nickname(const String& nickname = "") : nickname(nickname) { + } + + void setNickname(const String& nickname) { + this->nickname = nickname; + } + + const String& getNickname() const { + return nickname; + } + + private: + String nickname; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 6294403..de0e71c 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -33,6 +33,7 @@ #include "Swiften/Parser/PayloadParsers/PrivateStorageParserFactory.h" #include "Swiften/Parser/PayloadParsers/DelayParserFactory.h" #include "Swiften/Parser/PayloadParsers/MUCUserPayloadParserFactory.h" +#include "Swiften/Parser/PayloadParsers/NicknameParserFactory.h" using namespace boost; @@ -63,6 +64,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(shared_ptr(new ChatStateParserFactory())); factories_.push_back(shared_ptr(new DelayParserFactory())); factories_.push_back(shared_ptr(new MUCUserPayloadParserFactory())); + factories_.push_back(shared_ptr(new NicknameParserFactory())); foreach(shared_ptr factory, factories_) { addFactory(factory.get()); } diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.cpp b/Swiften/Parser/PayloadParsers/NicknameParser.cpp new file mode 100644 index 0000000..c60bc72 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/NicknameParser.cpp @@ -0,0 +1,29 @@ +/* + * 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/NicknameParser.h" + +namespace Swift { + +NicknameParser::NicknameParser() : level(0) { +} + +void NicknameParser::handleStartElement(const String&, const String&, const AttributeMap&) { + ++level; +} + +void NicknameParser::handleEndElement(const String&, const String&) { + --level; + if (level == 0) { + getPayloadInternal()->setNickname(text); + } +} + +void NicknameParser::handleCharacterData(const String& data) { + text += data; +} + +} diff --git a/Swiften/Parser/PayloadParsers/NicknameParser.h b/Swiften/Parser/PayloadParsers/NicknameParser.h new file mode 100644 index 0000000..24003b8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/NicknameParser.h @@ -0,0 +1,25 @@ +/* + * 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/Elements/Nickname.h" +#include "Swiften/Parser/GenericPayloadParser.h" + +namespace Swift { + class NicknameParser : public GenericPayloadParser { + public: + NicknameParser(); + + 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: + int level; + String text; + }; +} diff --git a/Swiften/Parser/PayloadParsers/NicknameParserFactory.h b/Swiften/Parser/PayloadParsers/NicknameParserFactory.h new file mode 100644 index 0000000..ce2ebdd --- /dev/null +++ b/Swiften/Parser/PayloadParsers/NicknameParserFactory.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/NicknameParser.h" + +namespace Swift { + class NicknameParserFactory : public GenericPayloadParserFactory { + public: + NicknameParserFactory() : GenericPayloadParserFactory("nick", "http://jabber.org/protocol/nick") {} + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index b9119d0..9cd6b31 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -43,6 +43,7 @@ sources = [ "PayloadParsers/VCardUpdateParser.cpp", "PayloadParsers/DelayParser.cpp", "PayloadParsers/MUCUserPayloadParser.cpp", + "PayloadParsers/NicknameParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", diff --git a/Swiften/SConscript b/Swiften/SConscript index 9ffc3de..839413d 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -92,6 +92,7 @@ if env["SCONS_STAGE"] == "build" : "Serializer/PayloadSerializers/DelaySerializer.cpp", "Serializer/PayloadSerializers/CommandSerializer.cpp", "Serializer/PayloadSerializers/FormSerializer.cpp", + "Serializer/PayloadSerializers/NicknameSerializer.cpp", "Serializer/PresenceSerializer.cpp", "Serializer/StanzaSerializer.cpp", "Serializer/StreamFeaturesSerializer.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index d63c723..8598f17 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -34,6 +34,7 @@ #include "Swiften/Serializer/PayloadSerializers/DelaySerializer.h" #include "Swiften/Serializer/PayloadSerializers/FormSerializer.h" #include "Swiften/Serializer/PayloadSerializers/CommandSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/NicknameSerializer.h" namespace Swift { @@ -65,6 +66,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new FormSerializer()); serializers_.push_back(new PrivateStorageSerializer(this)); serializers_.push_back(new CommandSerializer()); + serializers_.push_back(new NicknameSerializer()); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); } diff --git a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp new file mode 100644 index 0000000..55d5bb6 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Serializer/PayloadSerializers/NicknameSerializer.h" + +#include + +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +NicknameSerializer::NicknameSerializer() : GenericPayloadSerializer() { +} + +String NicknameSerializer::serializePayload(boost::shared_ptr nick) const { + XMLElement nickElement("nick", "http://jabber.org/protocol/nick"); + nickElement.addNode(boost::shared_ptr(new XMLTextNode(nick->getNickname()))); + return nickElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h new file mode 100644 index 0000000..e296ffd --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/NicknameSerializer.h @@ -0,0 +1,21 @@ +/* + * 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/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/Nickname.h" + +namespace Swift { + class NicknameSerializer : public GenericPayloadSerializer { + public: + NicknameSerializer(); + + virtual String serializePayload(boost::shared_ptr) const; + }; +} + + -- cgit v0.10.2-6-g49f6