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/Parser/PayloadParsers | |
parent | eb788bf484f4d11f524473986bf19d1a80f522bc (diff) | |
download | swift-contrib-cb32ea0954558da4bec9d4e9f13710a7f1a17d5a.zip swift-contrib-cb32ea0954558da4bec9d4e9f13710a7f1a17d5a.tar.bz2 |
Added User Nickname element, serializer, and parser.
Diffstat (limited to 'Swiften/Parser/PayloadParsers')
4 files changed, 73 insertions, 0 deletions
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") {} + }; +} |