Gateway payload

This commit is contained in:
HanzZ 2012-02-26 12:40:48 +01:00
parent 197cd61f95
commit 54dff8d280
6 changed files with 179 additions and 0 deletions

View file

@ -0,0 +1,16 @@
/*
* Copyright (c) 2011 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Elements/GatewayPayload.h>
namespace Swift {
GatewayPayload::GatewayPayload(const JID &jid, const std::string &desc, const std::string &prompt) :
jid(jid), desc(desc), prompt(prompt) {
}
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2011 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#pragma once
#include <vector>
#include <string>
#include <Swiften/Elements/Payload.h>
#include <Swiften/JID/JID.h>
namespace Swift {
class GatewayPayload : public Payload {
public:
GatewayPayload(const JID &jid = JID(), const std::string &desc = "", const std::string &prompt = "");
void setJID(const JID &jid) {
this->jid = jid;
}
const JID &getJID() const {
return jid;
}
void setDesc(const std::string &desc) {
this->desc = desc;
}
const std::string &getDesc() const {
return desc;
}
void setPrompt(const std::string &prompt) {
this->prompt = prompt;
}
const std::string &getPrompt() const {
return prompt;
}
private:
JID jid;
std::string desc;
std::string prompt;
};
}

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2012 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Parser/PayloadParsers/GatewayPayloadParser.h>
#include <boost/lexical_cast.hpp>
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParserFactory.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/Elements/MUCOccupant.h>
#include <Swiften/Parser/Tree/TreeReparser.h>
namespace Swift {
void GatewayPayloadParser::handleTree(ParserElement::ref root) {
foreach (ParserElement::ref child, root->getAllChildren()) {
if (child->getName() == "desc") {
getPayloadInternal()->setDesc(child->getText());
}
else if (child->getName() == "prompt") {
getPayloadInternal()->setPrompt(child->getText());
}
else if (child->getName() == "jid") {
getPayloadInternal()->setJID(child->getText());
}
}
}
}

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2012 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#pragma once
#include <boost/optional.hpp>
#include <Swiften/Elements/GatewayPayload.h>
#include <Swiften/Parser/GenericPayloadTreeParser.h>
#include <Swiften/Parser/PayloadParsers/MUCItemParser.h>
namespace Swift {
class GatewayPayloadParser : public GenericPayloadTreeParser<GatewayPayload> {
public:
GatewayPayloadParser() {}
virtual void handleTree(ParserElement::ref root);
};
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2011 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Serializer/PayloadSerializers/GatewayPayloadSerializer.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
#include <Swiften/Serializer/XML/XMLTextNode.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/PayloadSerializerCollection.h>
namespace Swift {
GatewayPayloadSerializer::GatewayPayloadSerializer()
: GenericPayloadSerializer<GatewayPayload>() {
}
std::string GatewayPayloadSerializer::serializePayload(boost::shared_ptr<GatewayPayload> payload) const {
XMLElement query("query", "jabber:iq:gateway");
if (!payload->getJID().isValid()) {
boost::shared_ptr<XMLElement> jid(new XMLElement("jid", "", payload->getJID().toBare().toString()));
query.addNode(jid);
}
if (!payload->getDesc().empty()) {
boost::shared_ptr<XMLElement> desc(new XMLElement("desc", "", payload->getDesc()));
query.addNode(desc);
}
if (!payload->getPrompt().empty()) {
boost::shared_ptr<XMLElement> prompt(new XMLElement("prompt", "", payload->getPrompt()));
query.addNode(prompt);
}
return query.serialize();
}
}

View file

@ -0,0 +1,19 @@
/*
* Copyright (c) 2011 Jan Kaluza
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#pragma once
#include <Swiften/Serializer/GenericPayloadSerializer.h>
#include <Swiften/Elements/GatewayPayload.h>
namespace Swift {
class GatewayPayloadSerializer : public GenericPayloadSerializer<GatewayPayload> {
public:
GatewayPayloadSerializer();
virtual std::string serializePayload(boost::shared_ptr<GatewayPayload> item) const;
};
}