diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-14 20:14:08 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-14 20:14:08 (GMT) |
commit | cb32ea0954558da4bec9d4e9f13710a7f1a17d5a (patch) | |
tree | 91cf3495f6cfe4955c193b1b4d9badaebd854d03 /Swiften | |
parent | eb788bf484f4d11f524473986bf19d1a80f522bc (diff) | |
download | swift-contrib-cb32ea0954558da4bec9d4e9f13710a7f1a17d5a.zip swift-contrib-cb32ea0954558da4bec9d4e9f13710a7f1a17d5a.tar.bz2 |
Added User Nickname element, serializer, and parser.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Elements/Nickname.h | 29 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp | 2 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/NicknameParser.cpp | 29 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/NicknameParser.h | 25 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/NicknameParserFactory.h | 17 | ||||
-rw-r--r-- | Swiften/Parser/SConscript | 1 | ||||
-rw-r--r-- | Swiften/SConscript | 1 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp | 2 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/NicknameSerializer.cpp | 25 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/NicknameSerializer.h | 21 |
10 files changed, 152 insertions, 0 deletions
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<PayloadParserFactory>(new ChatStateParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new DelayParserFactory())); factories_.push_back(shared_ptr<PayloadParserFactory>(new MUCUserPayloadParserFactory())); + factories_.push_back(shared_ptr<PayloadParserFactory>(new NicknameParserFactory())); foreach(shared_ptr<PayloadParserFactory> 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<Nickname> { + 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<NicknameParser> { + public: + NicknameParserFactory() : GenericPayloadParserFactory<NicknameParser>("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 <boost/shared_ptr.hpp> + +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +NicknameSerializer::NicknameSerializer() : GenericPayloadSerializer<Nickname>() { +} + +String NicknameSerializer::serializePayload(boost::shared_ptr<Nickname> nick) const { + XMLElement nickElement("nick", "http://jabber.org/protocol/nick"); + nickElement.addNode(boost::shared_ptr<XMLTextNode>(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<Nickname> { + public: + NicknameSerializer(); + + virtual String serializePayload(boost::shared_ptr<Nickname>) const; + }; +} + + |