From dcc7c34464540d83a35e5c06241518ec26499f7f Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Wed, 1 Jun 2011 12:07:53 +0100 Subject: Add iq:last parsialiser diff --git a/Swiften/Elements/Last.h b/Swiften/Elements/Last.h new file mode 100644 index 0000000..2987817 --- /dev/null +++ b/Swiften/Elements/Last.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +namespace Swift { + class Last : public Payload { + public: + Last() {}; + Last(int seconds) : seconds_(seconds) {}; + + int getSeconds() {return seconds_;} + void setSeconds(int seconds) {seconds_ = seconds;} + + private: + int seconds_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 8d75089..88a7bb6 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -42,6 +42,7 @@ #include #include #include +#include using namespace boost; @@ -52,6 +53,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(shared_ptr(new GenericPayloadParserFactory("show"))); factories_.push_back(shared_ptr(new GenericPayloadParserFactory("status"))); factories_.push_back(shared_ptr(new GenericPayloadParserFactory("replace", "http://swift.im/protocol/replace"))); + factories_.push_back(shared_ptr(new GenericPayloadParserFactory("query", "jabber:iq:last"))); factories_.push_back(shared_ptr(new GenericPayloadParserFactory("body"))); factories_.push_back(shared_ptr(new GenericPayloadParserFactory("subject"))); factories_.push_back(shared_ptr(new GenericPayloadParserFactory("priority"))); diff --git a/Swiften/Parser/PayloadParsers/LastParser.cpp b/Swiften/Parser/PayloadParsers/LastParser.cpp new file mode 100644 index 0000000..77ebba8 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/LastParser.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include + +#include + +namespace Swift { + +LastParser::LastParser() : level_(0) { +} + +void LastParser::handleStartElement(const std::string&, const std::string&, const AttributeMap& attributes) { + if (level_ == 0) { + int seconds = 0; + try { + seconds = boost::lexical_cast(attributes.getAttribute("seconds")); + } + catch (boost::bad_lexical_cast&) { + } + getPayloadInternal()->setSeconds(seconds); + } + ++level_; + +} + +void LastParser::handleEndElement(const std::string&, const std::string&) { +} + +void LastParser::handleCharacterData(const std::string&) { +} + +} diff --git a/Swiften/Parser/PayloadParsers/LastParser.h b/Swiften/Parser/PayloadParsers/LastParser.h new file mode 100644 index 0000000..7c5c707 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/LastParser.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include +#include + +namespace Swift { + class LastParser : public GenericPayloadParser { + public: + LastParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + + private: + int level_; + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index d9915ed..fe5bfb1 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -54,6 +54,7 @@ sources = [ "PayloadParsers/MUCUserPayloadParser.cpp", "PayloadParsers/NicknameParser.cpp", "PayloadParsers/ReplaceParser.cpp", + "PayloadParsers/LastParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 622fe1f..14e3b46 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -42,6 +42,7 @@ #include #include #include +#include namespace Swift { @@ -81,6 +82,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new NicknameSerializer()); serializers_.push_back(new SearchPayloadSerializer()); serializers_.push_back(new ReplaceSerializer()); + serializers_.push_back(new LastSerializer()); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); } diff --git a/Swiften/Serializer/PayloadSerializers/LastSerializer.h b/Swiften/Serializer/PayloadSerializers/LastSerializer.h new file mode 100644 index 0000000..e91d702 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/LastSerializer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2011 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include + +#include +#include + +namespace Swift { + class LastSerializer : public GenericPayloadSerializer { + public: + LastSerializer() : GenericPayloadSerializer() {} + + virtual std::string serializePayload(boost::shared_ptr last) const { + return ""; + } + }; +} -- cgit v0.10.2-6-g49f6