diff options
author | Remko Tronçon <git@el-tramo.be> | 2009-06-01 08:48:42 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2009-06-01 09:24:28 (GMT) |
commit | 2812bddd81f8a1b804c7460f4e14cd0aa393d129 (patch) | |
tree | d46294f35150c4f0f43deaf2d31fceaf945ae715 /Swiften/Elements | |
download | swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.zip swift-2812bddd81f8a1b804c7460f4e14cd0aa393d129.tar.bz2 |
Import.
Diffstat (limited to 'Swiften/Elements')
45 files changed, 1425 insertions, 0 deletions
diff --git a/Swiften/Elements/AuthFailure.h b/Swiften/Elements/AuthFailure.h new file mode 100644 index 0000000..b1857b3 --- /dev/null +++ b/Swiften/Elements/AuthFailure.h @@ -0,0 +1,13 @@ +#ifndef SWIFTEN_AuthFailure_H +#define SWIFTEN_AuthFailure_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class AuthFailure : public Element { + public: + AuthFailure() {} + }; +} + +#endif diff --git a/Swiften/Elements/AuthRequest.h b/Swiften/Elements/AuthRequest.h new file mode 100644 index 0000000..1f49175 --- /dev/null +++ b/Swiften/Elements/AuthRequest.h @@ -0,0 +1,36 @@ +#ifndef SWIFTEN_AuthRequest_H +#define SWIFTEN_AuthRequest_H + +#include "Swiften/Base/ByteArray.h" +#include "Swiften/Elements/Element.h" + +namespace Swift { + class AuthRequest : public Element { + public: + AuthRequest(const String& mechanism = "", const ByteArray& message = "") : + mechanism_(mechanism), message_(message) { + } + + const ByteArray& getMessage() const { + return message_; + } + + void setMessage(const ByteArray& message) { + message_ = message; + } + + const String& getMechanism() const { + return mechanism_; + } + + void setMechanism(const String& mechanism) { + mechanism_ = mechanism; + } + + private: + String mechanism_; + ByteArray message_; + }; +} + +#endif diff --git a/Swiften/Elements/AuthSuccess.h b/Swiften/Elements/AuthSuccess.h new file mode 100644 index 0000000..f63d0a8 --- /dev/null +++ b/Swiften/Elements/AuthSuccess.h @@ -0,0 +1,13 @@ +#ifndef SWIFTEN_AuthSuccess_H +#define SWIFTEN_AuthSuccess_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class AuthSuccess : public Element { + public: + AuthSuccess() {} + }; +} + +#endif diff --git a/Swiften/Elements/Body.h b/Swiften/Elements/Body.h new file mode 100644 index 0000000..d78cecf --- /dev/null +++ b/Swiften/Elements/Body.h @@ -0,0 +1,26 @@ +#ifndef SWIFTEN_Body_H +#define SWIFTEN_Body_H + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class Body : public Payload { + public: + Body(const String& text = "") : text_(text) { + } + + void setText(const String& text) { + text_ = text; + } + + const String& getText() const { + return text_; + } + + private: + String text_; + }; +} + +#endif diff --git a/Swiften/Elements/CapsInfo.h b/Swiften/Elements/CapsInfo.h new file mode 100644 index 0000000..4b478aa --- /dev/null +++ b/Swiften/Elements/CapsInfo.h @@ -0,0 +1,23 @@ +#ifndef SWIFTEN_CapsInfo_H +#define SWIFTEN_CapsInfo_H + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class CapsInfo : public Payload { + public: + CapsInfo(const String& node, const String& version, const String& hash = "sha-1") : node_(node), version_(version), hash_(hash) {} + + const String& getNode() const { return node_; } + const String& getVersion() const { return version_; } + const String& getHash() const { return hash_; } + + private: + String node_; + String version_; + String hash_; + }; +} + +#endif diff --git a/Swiften/Elements/CompressFailure.h b/Swiften/Elements/CompressFailure.h new file mode 100644 index 0000000..880f71a --- /dev/null +++ b/Swiften/Elements/CompressFailure.h @@ -0,0 +1,13 @@ +#ifndef SWIFTEN_CompressFailure_H +#define SWIFTEN_CompressFailure_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class CompressFailure : public Element { + public: + CompressFailure() {} + }; +} + +#endif diff --git a/Swiften/Elements/CompressRequest.h b/Swiften/Elements/CompressRequest.h new file mode 100644 index 0000000..53c0805 --- /dev/null +++ b/Swiften/Elements/CompressRequest.h @@ -0,0 +1,25 @@ +#ifndef SWIFTEN_CompressRequest_H +#define SWIFTEN_CompressRequest_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class CompressRequest : public Element + { + public: + CompressRequest(const String& method = "") : method_(method) {} + + const String& getMethod() const { + return method_; + } + + void setMethod(const String& method) { + method_ = method; + } + + private: + String method_; + }; +} + +#endif diff --git a/Swiften/Elements/Compressed.h b/Swiften/Elements/Compressed.h new file mode 100644 index 0000000..37113d8 --- /dev/null +++ b/Swiften/Elements/Compressed.h @@ -0,0 +1,14 @@ +#ifndef SWIFTEN_COMPRESSED_H +#define SWIFTEN_COMPRESSED_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class Compressed : public Element + { + public: + Compressed() {} + }; +} + +#endif diff --git a/Swiften/Elements/DiscoInfo.cpp b/Swiften/Elements/DiscoInfo.cpp new file mode 100644 index 0000000..63ee051 --- /dev/null +++ b/Swiften/Elements/DiscoInfo.cpp @@ -0,0 +1,25 @@ +#include "Swiften/Elements/DiscoInfo.h" + +namespace Swift { + +bool DiscoInfo::Identity::operator<(const Identity& other) const { + if (category_ == other.category_) { + if (type_ == other.type_) { + if (lang_ == other.lang_) { + return name_ < other.name_; + } + else { + return lang_ < other.lang_; + } + } + else { + return type_ < other.type_; + } + } + else { + return category_ < other.category_; + } +} + +const std::string DiscoInfo::SecurityLabels = "urn:xmpp:sec-label:0"; +} diff --git a/Swiften/Elements/DiscoInfo.h b/Swiften/Elements/DiscoInfo.h new file mode 100644 index 0000000..8caeaf9 --- /dev/null +++ b/Swiften/Elements/DiscoInfo.h @@ -0,0 +1,83 @@ +#ifndef SWIFTEN_DiscoInfo_H +#define SWIFTEN_DiscoInfo_H + +#include <vector> +#include <algorithm> + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class DiscoInfo : public Payload { + public: + const static std::string SecurityLabels; + class Identity { + public: + Identity(const String& name, const String& category = "client", const String& type = "pc", const String& lang = "") : name_(name), category_(category), type_(type), lang_(lang) { + } + + const String& getCategory() const { + return category_; + } + + const String& getType() const { + return type_; + } + + const String& getLanguage() const { + return lang_; + } + + const String& getName() const { + return name_; + } + + // Sorted according to XEP-115 rules + bool operator<(const Identity& other) const; + + private: + String name_; + String category_; + String type_; + String lang_; + }; + + DiscoInfo() { + } + + const String& getNode() const { + return node_; + } + + void setNode(const String& node) { + node_ = node; + } + + const std::vector<Identity> getIdentities() const { + return identities_; + } + + void addIdentity(const Identity& identity) { + identities_.push_back(identity); + } + + const std::vector<String>& getFeatures() const { + return features_; + } + + void addFeature(const String& feature) { + features_.push_back(feature); + } + + bool hasFeature(const String& feature) const { + return std::find(features_.begin(), features_.end(), feature) != features_.end(); + } + + private: + String node_; + std::vector<Identity> identities_; + std::vector<String> features_; + }; +} + +#endif diff --git a/Swiften/Elements/Element.cpp b/Swiften/Elements/Element.cpp new file mode 100644 index 0000000..a62aad9 --- /dev/null +++ b/Swiften/Elements/Element.cpp @@ -0,0 +1,8 @@ +#include "Swiften/Elements/Element.h" + +namespace Swift { + +Element::~Element() { +} + +} diff --git a/Swiften/Elements/Element.h b/Swiften/Elements/Element.h new file mode 100644 index 0000000..d1e9c6a --- /dev/null +++ b/Swiften/Elements/Element.h @@ -0,0 +1,11 @@ +#ifndef SWIFTEN_ELEMENT_H +#define SWIFTEN_ELEMENT_H + +namespace Swift { + class Element { + public: + virtual ~Element(); + }; +} + +#endif diff --git a/Swiften/Elements/Error.h b/Swiften/Elements/Error.h new file mode 100644 index 0000000..8793f35 --- /dev/null +++ b/Swiften/Elements/Error.h @@ -0,0 +1,70 @@ +#ifndef SWIFTEN_Error_H +#define SWIFTEN_Error_H + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class Error : public Payload { + public: + enum Type { Cancel, Continue, Modify, Auth, Wait }; + + enum Condition { + BadRequest, + Conflict, + FeatureNotImplemented, + Forbidden, + Gone, + InternalServerError, + ItemNotFound, + JIDMalformed, + NotAcceptable, + NotAllowed, + NotAuthorized, + PaymentRequired, + RecipientUnavailable, + Redirect, + RegistrationRequired, + RemoteServerNotFound, + RemoteServerTimeout, + ResourceConstraint, + ServiceUnavailable, + SubscriptionRequired, + UndefinedCondition, + UnexpectedRequest + }; + + Error(Condition condition = UndefinedCondition, Type type = Cancel, const String& text = String()) : type_(type), condition_(condition), text_(text) { } + + Type getType() const { + return type_; + } + + void setType(Type type) { + type_ = type; + } + + Condition getCondition() const { + return condition_; + } + + void setCondition(Condition condition) { + condition_ = condition; + } + + void setText(const String& text) { + text_ = text; + } + + const String& getText() const { + return text_; + } + + private: + Type type_; + Condition condition_; + String text_; + }; +} + +#endif diff --git a/Swiften/Elements/IQ.cpp b/Swiften/Elements/IQ.cpp new file mode 100644 index 0000000..51f4745 --- /dev/null +++ b/Swiften/Elements/IQ.cpp @@ -0,0 +1,37 @@ +#include "Swiften/Elements/IQ.h" + +namespace Swift { + +boost::shared_ptr<IQ> IQ::createRequest( + Type type, const JID& to, const String& id, boost::shared_ptr<Payload> payload) { + boost::shared_ptr<IQ> iq(new IQ(type)); + if (to.isValid()) { + iq->setTo(to); + } + iq->setID(id); + if (payload) { + iq->addPayload(payload); + } + return iq; +} + +boost::shared_ptr<IQ> IQ::createResult( + const JID& to, const String& id, boost::shared_ptr<Payload> payload) { + boost::shared_ptr<IQ> iq(new IQ(Result)); + iq->setTo(to); + iq->setID(id); + if (payload) { + iq->addPayload(payload); + } + return iq; +} + +boost::shared_ptr<IQ> IQ::createError(const JID& to, const String& id, Error::Condition condition, Error::Type type) { + boost::shared_ptr<IQ> iq(new IQ(IQ::Error)); + iq->setTo(to); + iq->setID(id); + iq->addPayload(boost::shared_ptr<Swift::Error>(new Swift::Error(condition, type))); + return iq; +} + +} diff --git a/Swiften/Elements/IQ.h b/Swiften/Elements/IQ.h new file mode 100644 index 0000000..231439f --- /dev/null +++ b/Swiften/Elements/IQ.h @@ -0,0 +1,39 @@ +#ifndef SWIFTEN_IQ_H +#define SWIFTEN_IQ_H + +#include "Swiften/Elements/Stanza.h" +#include "Swiften/Elements/Error.h" + +namespace Swift +{ + class IQ : public Stanza + { + public: + enum Type { Get, Set, Result, Error }; + + IQ(Type type = Get) : type_(type) { } + + Type getType() const { return type_; } + void setType(Type type) { type_ = type; } + + static boost::shared_ptr<IQ> createRequest( + Type type, + const JID& to, + const String& id, + boost::shared_ptr<Payload> payload); + static boost::shared_ptr<IQ> createResult( + const JID& to, + const String& id, + boost::shared_ptr<Payload> payload = boost::shared_ptr<Payload>()); + static boost::shared_ptr<IQ> createError( + const JID& to, + const String& id, + Error::Condition condition, + Error::Type type); + + private: + Type type_; + }; +} + +#endif diff --git a/Swiften/Elements/MUCPayload.cpp b/Swiften/Elements/MUCPayload.cpp new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Swiften/Elements/MUCPayload.cpp diff --git a/Swiften/Elements/MUCPayload.h b/Swiften/Elements/MUCPayload.h new file mode 100644 index 0000000..205ae46 --- /dev/null +++ b/Swiften/Elements/MUCPayload.h @@ -0,0 +1,16 @@ +#ifndef SWIFTEN_MUCPayload_H +#define SWIFTEN_MUCPayload_H + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class MUCPayload : public Payload + { + public: + MUCPayload() { } + + }; +} + +#endif diff --git a/Swiften/Elements/Makefile.inc b/Swiften/Elements/Makefile.inc new file mode 100644 index 0000000..aceaac0 --- /dev/null +++ b/Swiften/Elements/Makefile.inc @@ -0,0 +1,9 @@ +SWIFTEN_SOURCES += \ + Swiften/Elements/RosterPayload.cpp \ + Swiften/Elements/Payload.cpp \ + Swiften/Elements/Stanza.cpp \ + Swiften/Elements/Element.cpp \ + Swiften/Elements/DiscoInfo.cpp \ + Swiften/Elements/IQ.cpp + +include Swiften/Elements/UnitTest/Makefile.inc diff --git a/Swiften/Elements/Message.h b/Swiften/Elements/Message.h new file mode 100644 index 0000000..a49f496 --- /dev/null +++ b/Swiften/Elements/Message.h @@ -0,0 +1,46 @@ +#ifndef SWIFTEN_STANZAS_MESSAGE_H +#define SWIFTEN_STANZAS_MESSAGE_H + +#include <boost/optional.hpp> + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Body.h" +#include "Swiften/Elements/Error.h" +#include "Swiften/Elements/Stanza.h" + +namespace Swift +{ + class Message : public Stanza + { + public: + enum Type { Normal, Chat, Error, Groupchat, Headline }; + + Message() : type_(Chat) { } + + String getBody() const { + boost::shared_ptr<Body> body(getPayload<Body>()); + if (body) { + return body->getText(); + } + return ""; + } + + void setBody(const String& body) { + updatePayload(boost::shared_ptr<Body>(new Body(body))); + } + + bool isError() { + boost::shared_ptr<Swift::Error> error(getPayload<Swift::Error>()); + return getType() == Message::Error || error.get() != NULL; + } + + Type getType() const { return type_; } + void setType(Type type) { type_ = type; } + + private: + String body_; + Type type_; + }; +} + +#endif diff --git a/Swiften/Elements/Payload.cpp b/Swiften/Elements/Payload.cpp new file mode 100644 index 0000000..d929fad --- /dev/null +++ b/Swiften/Elements/Payload.cpp @@ -0,0 +1,8 @@ +#include "Swiften/Elements/Payload.h" + +namespace Swift { + +Payload::~Payload() { +} + +} diff --git a/Swiften/Elements/Payload.h b/Swiften/Elements/Payload.h new file mode 100644 index 0000000..829dc24 --- /dev/null +++ b/Swiften/Elements/Payload.h @@ -0,0 +1,11 @@ +#ifndef SWIFTEN_PAYLOAD_H +#define SWIFTEN_PAYLOAD_H + +namespace Swift { + class Payload { + public: + virtual ~Payload(); + }; +} + +#endif diff --git a/Swiften/Elements/Presence.h b/Swiften/Elements/Presence.h new file mode 100644 index 0000000..1243bca --- /dev/null +++ b/Swiften/Elements/Presence.h @@ -0,0 +1,58 @@ +#ifndef SWIFTEN_Presence +#define SWIFTEN_Presence + +#include "Swiften/Elements/Stanza.h" +#include "Swiften/Elements/Status.h" +#include "Swiften/Elements/StatusShow.h" +#include "Swiften/Elements/Priority.h" + +namespace Swift { + class Presence : public Stanza + { + public: + enum Type { Available, Error, Probe, Subscribe, Subscribed, Unavailable, Unsubscribe, Unsubscribed }; + + Presence() : type_(Available) /*, showType_(Online)*/ {} + + Type getType() const { return type_; } + void setType(Type type) { type_ = type; } + + StatusShow::Type getShow() const { + boost::shared_ptr<StatusShow> show(getPayload<StatusShow>()); + if (show) { + return show->getType(); + } + return type_ == Available ? StatusShow::Online : StatusShow::None; + } + + void setShow(const StatusShow::Type &show) { + updatePayload(boost::shared_ptr<StatusShow>(new StatusShow(show))); + } + + String getStatus() const { + boost::shared_ptr<Status> status(getPayload<Status>()); + if (status) { + return status->getText(); + } + return ""; + } + + void setStatus(const String& status) { + updatePayload(boost::shared_ptr<Status>(new Status(status))); + } + + int getPriority() const { + boost::shared_ptr<Priority> priority(getPayload<Priority>()); + return (priority ? priority->getPriority() : 0); + } + + void setPriority(int priority) { + updatePayload(boost::shared_ptr<Priority>(new Priority(priority))); + } + + private: + Presence::Type type_; + }; +} + +#endif diff --git a/Swiften/Elements/Priority.h b/Swiften/Elements/Priority.h new file mode 100644 index 0000000..fd6080e --- /dev/null +++ b/Swiften/Elements/Priority.h @@ -0,0 +1,25 @@ +#ifndef SWIFTEN_Priority_H +#define SWIFTEN_Priority_H + +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class Priority : public Payload { + public: + Priority(int priority = 0) : priority_(priority) { + } + + void setPriority(int priority) { + priority_ = priority; + } + + int getPriority() const { + return priority_; + } + + private: + int priority_; + }; +} + +#endif diff --git a/Swiften/Elements/ResourceBind.h b/Swiften/Elements/ResourceBind.h new file mode 100644 index 0000000..3b6c632 --- /dev/null +++ b/Swiften/Elements/ResourceBind.h @@ -0,0 +1,36 @@ +#ifndef SWIFTEN_ResourceBind_H +#define SWIFTEN_ResourceBind_H + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Payload.h" +#include "Swiften/JID/JID.h" + +namespace Swift { + class ResourceBind : public Payload + { + public: + ResourceBind() {} + + void setJID(const JID& jid) { + jid_ = jid; + } + + const JID& getJID() const { + return jid_; + } + + void setResource(const String& resource) { + resource_ = resource; + } + + const String& getResource() const { + return resource_; + } + + private: + JID jid_; + String resource_; + }; +} + +#endif diff --git a/Swiften/Elements/RosterItemPayload.h b/Swiften/Elements/RosterItemPayload.h new file mode 100644 index 0000000..3925117 --- /dev/null +++ b/Swiften/Elements/RosterItemPayload.h @@ -0,0 +1,43 @@ +#ifndef SWIFTEN_RosterItemPayloadPayload_H +#define SWIFTEN_RosterItemPayloadPayload_H + +#include <vector> + +#include "Swiften/JID/JID.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class RosterItemPayload + { + public: + enum Subscription { None, To, From, Both, Remove }; + + RosterItemPayload() : subscription_(None), ask_(false) {} + RosterItemPayload(const JID& jid, const String& name, Subscription subscription) : jid_(jid), name_(name), subscription_(subscription), ask_(false) { } + + void setJID(const JID& jid) { jid_ = jid; } + const JID& getJID() const { return jid_; } + + void setName(const String& name) { name_ = name; } + const String& getName() const { return name_; } + + void setSubscription(Subscription subscription) { subscription_ = subscription; } + const Subscription& getSubscription() const { return subscription_; } + + void addGroup(const String& group) { groups_.push_back(group); } + void setGroups(const std::vector<String>& groups) { groups_ = groups; } + const std::vector<String>& getGroups() const { return groups_; } + + void setSubscriptionRequested() { ask_ = true; } + bool getSubscriptionRequested() const { return ask_; } + + private: + JID jid_; + String name_; + Subscription subscription_; + std::vector<String> groups_; + bool ask_; + }; +} + +#endif diff --git a/Swiften/Elements/RosterPayload.cpp b/Swiften/Elements/RosterPayload.cpp new file mode 100644 index 0000000..6d39264 --- /dev/null +++ b/Swiften/Elements/RosterPayload.cpp @@ -0,0 +1,17 @@ +#include "Swiften/Elements/RosterPayload.h" +#include "Swiften/Base/foreach.h" + +namespace Swift { + +boost::optional<RosterItemPayload> RosterPayload::getItem(const JID& jid) const { + foreach(const RosterItemPayload& item, items_) { + // FIXME: MSVC rejects this. Find out why. + //if (item.getJID() == jid) { + if (item.getJID().compare(jid, JID::WithResource)) { + return boost::optional<RosterItemPayload>(item); + } + } + return boost::optional<RosterItemPayload>(); +} + +} diff --git a/Swiften/Elements/RosterPayload.h b/Swiften/Elements/RosterPayload.h new file mode 100644 index 0000000..afb68c2 --- /dev/null +++ b/Swiften/Elements/RosterPayload.h @@ -0,0 +1,33 @@ +#ifndef SWIFTEN_RosterPayload_H +#define SWIFTEN_RosterPayload_H + +#include <vector> +#include <boost/optional.hpp> + +#include "Swiften/Elements/RosterItemPayload.h" +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class RosterPayload : public Payload { + public: + typedef std::vector<RosterItemPayload> RosterItemPayloads; + + public: + RosterPayload() {} + + boost::optional<RosterItemPayload> getItem(const JID& jid) const; + + void addItem(const RosterItemPayload& item) { + items_.push_back(item); + } + + const RosterItemPayloads& getItems() const { + return items_; + } + + private: + RosterItemPayloads items_; + }; +} + +#endif diff --git a/Swiften/Elements/SecurityLabel.h b/Swiften/Elements/SecurityLabel.h new file mode 100644 index 0000000..65bdb4f --- /dev/null +++ b/Swiften/Elements/SecurityLabel.h @@ -0,0 +1,57 @@ +#ifndef SWIFTEN_SecurityLabel_H +#define SWIFTEN_SecurityLabel_H + +#include <vector> + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class SecurityLabel : public Payload { + public: + SecurityLabel() {} + + const String& getDisplayMarking() const { return displayMarking_; } + + void setDisplayMarking(const String& displayMarking) { + displayMarking_ = displayMarking; + } + + const String& getForegroundColor() const { + return foregroundColor_; + } + + void setForegroundColor(const String& foregroundColor) { + foregroundColor_ = foregroundColor; + } + + const String& getBackgroundColor() const { + return backgroundColor_; + } + + void setBackgroundColor(const String& backgroundColor) { + backgroundColor_ = backgroundColor; + } + + const String& getLabel() const { return label_; } + + void setLabel(const String& label) { + label_ = label; + } + + const std::vector<String>& getEquivalentLabels() const { return equivalentLabels_; } + + void addEquivalentLabel(const String& label) { + equivalentLabels_.push_back(label); + } + + private: + String displayMarking_; + String foregroundColor_; + String backgroundColor_; + String label_; + std::vector<String> equivalentLabels_; + }; +} + +#endif diff --git a/Swiften/Elements/SecurityLabelsCatalog.h b/Swiften/Elements/SecurityLabelsCatalog.h new file mode 100644 index 0000000..611c26b --- /dev/null +++ b/Swiften/Elements/SecurityLabelsCatalog.h @@ -0,0 +1,56 @@ +#ifndef SWIFTEN_SecurityLabelsCatalog_H +#define SWIFTEN_SecurityLabelsCatalog_H + +#include <vector> + +#include "Swiften/JID/JID.h" +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Payload.h" +#include "Swiften/Elements/SecurityLabel.h" + +namespace Swift { + class SecurityLabelsCatalog : public Payload { + public: + SecurityLabelsCatalog(const JID& to = JID()) : to_(to) {} + + const std::vector<SecurityLabel>& getLabels() const { + return labels_; + } + + void addLabel(const SecurityLabel& label) { + labels_.push_back(label); + } + + const JID& getTo() const { + return to_; + } + + void setTo(const JID& to) { + to_ = to; + } + + const String& getName() const { + return name_; + } + + void setName(const String& name) { + name_ = name; + } + + const String& getDescription() const { + return description_; + } + + void setDescription(const String& description) { + description_ = description; + } + + private: + JID to_; + String name_; + String description_; + std::vector<SecurityLabel> labels_; + }; +} + +#endif diff --git a/Swiften/Elements/SoftwareVersion.h b/Swiften/Elements/SoftwareVersion.h new file mode 100644 index 0000000..d064414 --- /dev/null +++ b/Swiften/Elements/SoftwareVersion.h @@ -0,0 +1,47 @@ +#ifndef SWIFTEN_SoftwareVersion_H +#define SWIFTEN_SoftwareVersion_H + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class SoftwareVersion : public Payload { + public: + SoftwareVersion( + const String& name = "", + const String& version = "", + const String& os = "") : + name_(name), version_(version), os_(os) {} + + const String& getName() const { + return name_; + } + + void setName(const String& name) { + name_ = name; + } + + const String& getVersion() const { + return version_; + } + + void setVersion(const String& version) { + version_ = version; + } + + const String& getOS() const { + return os_; + } + + void setOS(const String& os) { + os_ = os; + } + + private: + String name_; + String version_; + String os_; + }; +} + +#endif diff --git a/Swiften/Elements/Stanza.cpp b/Swiften/Elements/Stanza.cpp new file mode 100644 index 0000000..e644665 --- /dev/null +++ b/Swiften/Elements/Stanza.cpp @@ -0,0 +1,31 @@ +#include "Swiften/Elements/Stanza.h" + +#include <typeinfo> + +namespace Swift { + +Stanza::~Stanza() { + payloads_.clear(); +} + +void Stanza::updatePayload(boost::shared_ptr<Payload> payload) { + foreach (boost::shared_ptr<Payload>& i, payloads_) { + if (typeid(*i.get()) == typeid(*payload.get())) { + i = payload; + return; + } + } + addPayload(payload); +} + +boost::shared_ptr<Payload> Stanza::getPayloadOfSameType(boost::shared_ptr<Payload> payload) const { + foreach (const boost::shared_ptr<Payload>& i, payloads_) { + if (typeid(*i.get()) == typeid(*payload.get())) { + return i; + } + } + return boost::shared_ptr<Payload>(); +} + + +} diff --git a/Swiften/Elements/Stanza.h b/Swiften/Elements/Stanza.h new file mode 100644 index 0000000..e60ab21 --- /dev/null +++ b/Swiften/Elements/Stanza.h @@ -0,0 +1,60 @@ +#ifndef SWIFTEN_STANZAS_STANZA_H +#define SWIFTEN_STANZAS_STANZA_H + +#include <vector> +#include <boost/shared_ptr.hpp> + +#include "Swiften/Elements/Element.h" +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" +#include "Swiften/Base/foreach.h" +#include "Swiften/JID/JID.h" + +namespace Swift { + class Stanza : public Element { + public: + virtual ~Stanza(); + + template<typename T> + boost::shared_ptr<T> getPayload() const { + foreach (const boost::shared_ptr<Payload>& i, payloads_) { + boost::shared_ptr<T> result(boost::dynamic_pointer_cast<T>(i)); + if (result) { + return result; + } + } + return boost::shared_ptr<T>(); + } + + const std::vector< boost::shared_ptr<Payload> >& getPayloads() const { + return payloads_; + } + + void addPayload(boost::shared_ptr<Payload> payload) { + payloads_.push_back(payload); + } + + void updatePayload(boost::shared_ptr<Payload> payload); + + boost::shared_ptr<Payload> getPayloadOfSameType(boost::shared_ptr<Payload>) const; + + const JID& getFrom() const { return from_; } + void setFrom(const JID& from) { from_ = from; } + + const JID& getTo() const { return to_; } + void setTo(const JID& to) { to_ = to; } + + const String& getID() const { return id_; } + void setID(const String& id) { id_ = id; } + + private: + String id_; + JID from_; + JID to_; + + typedef std::vector< boost::shared_ptr<Payload> > Payloads; + Payloads payloads_; + }; +} + +#endif diff --git a/Swiften/Elements/StartSession.h b/Swiften/Elements/StartSession.h new file mode 100644 index 0000000..2b46d05 --- /dev/null +++ b/Swiften/Elements/StartSession.h @@ -0,0 +1,14 @@ +#ifndef SWIFTEN_StartSession_H +#define SWIFTEN_StartSession_H + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class StartSession : public Payload { + public: + StartSession() {} + }; +} + +#endif diff --git a/Swiften/Elements/StartTLSFailure.h b/Swiften/Elements/StartTLSFailure.h new file mode 100644 index 0000000..17a1750 --- /dev/null +++ b/Swiften/Elements/StartTLSFailure.h @@ -0,0 +1,13 @@ +#ifndef SWIFTEN_StartTLSFailure_H +#define SWIFTEN_StartTLSFailure_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class StartTLSFailure : public Element { + public: + StartTLSFailure() {} + }; +} + +#endif diff --git a/Swiften/Elements/StartTLSRequest.h b/Swiften/Elements/StartTLSRequest.h new file mode 100644 index 0000000..c40499a --- /dev/null +++ b/Swiften/Elements/StartTLSRequest.h @@ -0,0 +1,14 @@ +#ifndef SWIFTEN_StartTLSRequest_H +#define SWIFTEN_StartTLSRequest_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class StartTLSRequest : public Element + { + public: + StartTLSRequest() {} + }; +} + +#endif diff --git a/Swiften/Elements/Status.h b/Swiften/Elements/Status.h new file mode 100644 index 0000000..0b80682 --- /dev/null +++ b/Swiften/Elements/Status.h @@ -0,0 +1,26 @@ +#ifndef SWIFTEN_Status_H +#define SWIFTEN_Status_H + +#include "Swiften/Elements/Payload.h" +#include "Swiften/Base/String.h" + +namespace Swift { + class Status : public Payload { + public: + Status(const String& text = "") : text_(text) { + } + + void setText(const String& text) { + text_ = text; + } + + const String& getText() const { + return text_; + } + + private: + String text_; + }; +} + +#endif diff --git a/Swiften/Elements/StatusShow.h b/Swiften/Elements/StatusShow.h new file mode 100644 index 0000000..a001657 --- /dev/null +++ b/Swiften/Elements/StatusShow.h @@ -0,0 +1,27 @@ +#ifndef SWIFTEN_StatusShow_H +#define SWIFTEN_StatusShow_H + +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class StatusShow : public Payload { + public: + enum Type { Online, Away, FFC, XA, DND, None }; + + StatusShow(const Type& type = Online) : type_(type) { + } + + void setType(const Type& type) { + type_ = type; + } + + const Type& getType() const { + return type_; + } + + private: + Type type_; + }; +} + +#endif diff --git a/Swiften/Elements/StreamFeatures.h b/Swiften/Elements/StreamFeatures.h new file mode 100644 index 0000000..2d5f4d6 --- /dev/null +++ b/Swiften/Elements/StreamFeatures.h @@ -0,0 +1,77 @@ +#ifndef SWIFTEN_StreamFeatures_H +#define SWIFTEN_StreamFeatures_H + +#include <vector> +#include <algorithm> + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Element.h" + +namespace Swift { + class StreamFeatures : public Element + { + public: + StreamFeatures() : hasStartTLS_(false), hasResourceBind_(false), hasSession_(false) {} + + void setHasStartTLS() { + hasStartTLS_ = true; + } + + bool hasStartTLS() const { + return hasStartTLS_; + } + + void setHasSession() { + hasSession_ = true; + } + + bool hasSession() const { + return hasSession_; + } + + void setHasResourceBind() { + hasResourceBind_ = true; + } + + bool hasResourceBind() const { + return hasResourceBind_; + } + + const std::vector<String>& getCompressionMethods() const { + return compressionMethods_; + } + + void addCompressionMethod(const String& mechanism) { + compressionMethods_.push_back(mechanism); + } + + bool hasCompressionMethod(const String& mechanism) const { + return std::find(compressionMethods_.begin(), compressionMethods_.end(), mechanism) != compressionMethods_.end(); + } + + const std::vector<String>& getAuthenticationMechanisms() const { + return authenticationMechanisms_; + } + + void addAuthenticationMechanism(const String& mechanism) { + authenticationMechanisms_.push_back(mechanism); + } + + bool hasAuthenticationMechanism(const String& mechanism) const { + return std::find(authenticationMechanisms_.begin(), authenticationMechanisms_.end(), mechanism) != authenticationMechanisms_.end(); + } + + bool hasAuthenticationMechanisms() const { + return !authenticationMechanisms_.empty(); + } + + private: + bool hasStartTLS_; + std::vector<String> compressionMethods_; + std::vector<String> authenticationMechanisms_; + bool hasResourceBind_; + bool hasSession_; + }; +} + +#endif diff --git a/Swiften/Elements/TLSProceed.h b/Swiften/Elements/TLSProceed.h new file mode 100644 index 0000000..41f0341 --- /dev/null +++ b/Swiften/Elements/TLSProceed.h @@ -0,0 +1,14 @@ +#ifndef SWIFTEN_TLSProceed_H +#define SWIFTEN_TLSProceed_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class TLSProceed : public Element + { + public: + TLSProceed() {} + }; +} + +#endif diff --git a/Swiften/Elements/UnitTest/IQTest.cpp b/Swiften/Elements/UnitTest/IQTest.cpp new file mode 100644 index 0000000..bc22c81 --- /dev/null +++ b/Swiften/Elements/UnitTest/IQTest.cpp @@ -0,0 +1,52 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <boost/shared_ptr.hpp> + +#include "Swiften/Elements/IQ.h" +#include "Swiften/Elements/SoftwareVersion.h" + +using namespace Swift; + +class IQTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(IQTest); + CPPUNIT_TEST(testCreateResult); + CPPUNIT_TEST(testCreateResult_WithoutPayload); + CPPUNIT_TEST(testCreateError); + CPPUNIT_TEST_SUITE_END(); + + public: + IQTest() {} + + void testCreateResult() { + boost::shared_ptr<Payload> payload(new SoftwareVersion("myclient")); + boost::shared_ptr<IQ> iq(IQ::createResult(JID("foo@bar/fum"), "myid", payload)); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo()); + CPPUNIT_ASSERT_EQUAL(String("myid"), iq->getID()); + CPPUNIT_ASSERT(iq->getPayload<SoftwareVersion>()); + CPPUNIT_ASSERT(payload == iq->getPayload<SoftwareVersion>()); + } + + void testCreateResult_WithoutPayload() { + boost::shared_ptr<IQ> iq(IQ::createResult(JID("foo@bar/fum"), "myid")); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo()); + CPPUNIT_ASSERT_EQUAL(String("myid"), iq->getID()); + CPPUNIT_ASSERT(!iq->getPayload<SoftwareVersion>()); + } + + void testCreateError() { + boost::shared_ptr<IQ> iq(IQ::createError(JID("foo@bar/fum"), "myid", Error::BadRequest, Error::Modify)); + + CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo()); + CPPUNIT_ASSERT_EQUAL(String("myid"), iq->getID()); + boost::shared_ptr<Error> error(iq->getPayload<Error>()); + CPPUNIT_ASSERT(error); + CPPUNIT_ASSERT_EQUAL(Error::BadRequest, error->getCondition()); + CPPUNIT_ASSERT_EQUAL(Error::Modify, error->getType()); + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(IQTest); diff --git a/Swiften/Elements/UnitTest/Makefile.inc b/Swiften/Elements/UnitTest/Makefile.inc new file mode 100644 index 0000000..848aa19 --- /dev/null +++ b/Swiften/Elements/UnitTest/Makefile.inc @@ -0,0 +1,3 @@ +UNITTEST_SOURCES += \ + Swiften/Elements/UnitTest/StanzaTest.cpp \ + Swiften/Elements/UnitTest/IQTest.cpp diff --git a/Swiften/Elements/UnitTest/StanzaTest.cpp b/Swiften/Elements/UnitTest/StanzaTest.cpp new file mode 100644 index 0000000..b905957 --- /dev/null +++ b/Swiften/Elements/UnitTest/StanzaTest.cpp @@ -0,0 +1,155 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <boost/shared_ptr.hpp> + +#include "Swiften/Elements/Stanza.h" +#include "Swiften/Elements/Payload.h" +#include "Swiften/Elements/Message.h" + +using namespace Swift; + +class StanzaTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(StanzaTest); + CPPUNIT_TEST(testConstructor_Copy); + CPPUNIT_TEST(testGetPayload); + CPPUNIT_TEST(testGetPayload_NoSuchPayload); + CPPUNIT_TEST(testDestructor); + CPPUNIT_TEST(testDestructor_Copy); + CPPUNIT_TEST(testUpdatePayload_ExistingPayload); + CPPUNIT_TEST(testUpdatePayload_NewPayload); + CPPUNIT_TEST(testGetPayloadOfSameType); + CPPUNIT_TEST(testGetPayloadOfSameType_NoSuchPayload); + CPPUNIT_TEST_SUITE_END(); + + public: + class MyPayload1 : public Payload { + public: + MyPayload1() {} + }; + + class MyPayload2 : public Payload { + public: + MyPayload2(const String& s = "") : text_(s) {} + + String text_; + }; + + class MyPayload3 : public Payload { + public: + MyPayload3() {} + }; + + class DestroyingPayload : public Payload { + public: + DestroyingPayload(bool* alive) : alive_(alive) { + } + + ~DestroyingPayload() { + (*alive_) = false; + } + + private: + bool* alive_; + }; + + StanzaTest() {} + + void testConstructor_Copy() { + Message m; + m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1())); + m.addPayload(boost::shared_ptr<MyPayload2>(new MyPayload2())); + Message copy(m); + + CPPUNIT_ASSERT(copy.getPayload<MyPayload1>()); + CPPUNIT_ASSERT(copy.getPayload<MyPayload2>()); + } + + void testDestructor() { + bool payloadAlive = true; + { + Message m; + m.addPayload(boost::shared_ptr<DestroyingPayload>(new DestroyingPayload(&payloadAlive))); + } + + CPPUNIT_ASSERT(!payloadAlive); + } + + void testDestructor_Copy() { + bool payloadAlive = true; + Message* m1 = new Message(); + m1->addPayload(boost::shared_ptr<DestroyingPayload>(new DestroyingPayload(&payloadAlive))); + Message* m2 = new Message(*m1); + + delete m1; + CPPUNIT_ASSERT(payloadAlive); + + delete m2; + CPPUNIT_ASSERT(!payloadAlive); + } + + void testGetPayload() { + Message m; + m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1())); + m.addPayload(boost::shared_ptr<MyPayload2>(new MyPayload2())); + m.addPayload(boost::shared_ptr<MyPayload3>(new MyPayload3())); + + boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>()); + CPPUNIT_ASSERT(p); + } + + void testGetPayload_NoSuchPayload() { + Message m; + m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1())); + m.addPayload(boost::shared_ptr<MyPayload3>(new MyPayload3())); + + boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>()); + CPPUNIT_ASSERT(!p); + } + + void testUpdatePayload_ExistingPayload() { + Message m; + m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1())); + m.addPayload(boost::shared_ptr<MyPayload2>(new MyPayload2("foo"))); + m.addPayload(boost::shared_ptr<MyPayload3>(new MyPayload3())); + + m.updatePayload(boost::shared_ptr<MyPayload2>(new MyPayload2("bar"))); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), m.getPayloads().size()); + boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>()); + CPPUNIT_ASSERT_EQUAL(String("bar"), p->text_); + } + + void testUpdatePayload_NewPayload() { + Message m; + m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1())); + m.addPayload(boost::shared_ptr<MyPayload3>(new MyPayload3())); + + m.updatePayload(boost::shared_ptr<MyPayload2>(new MyPayload2("bar"))); + + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), m.getPayloads().size()); + boost::shared_ptr<MyPayload2> p(m.getPayload<MyPayload2>()); + CPPUNIT_ASSERT_EQUAL(String("bar"), p->text_); + } + + void testGetPayloadOfSameType() { + Message m; + m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1())); + m.addPayload(boost::shared_ptr<MyPayload2>(new MyPayload2("foo"))); + m.addPayload(boost::shared_ptr<MyPayload3>(new MyPayload3())); + + boost::shared_ptr<MyPayload2> payload(boost::dynamic_pointer_cast<MyPayload2>(m.getPayloadOfSameType(boost::shared_ptr<MyPayload2>(new MyPayload2("bar"))))); + CPPUNIT_ASSERT(payload); + CPPUNIT_ASSERT_EQUAL(String("foo"), payload->text_); + } + + void testGetPayloadOfSameType_NoSuchPayload() { + Message m; + m.addPayload(boost::shared_ptr<MyPayload1>(new MyPayload1())); + m.addPayload(boost::shared_ptr<MyPayload3>(new MyPayload3())); + + CPPUNIT_ASSERT(!m.getPayloadOfSameType(boost::shared_ptr<MyPayload2>(new MyPayload2("bar")))); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(StanzaTest); diff --git a/Swiften/Elements/UnitTest/StanzasTest.cpp b/Swiften/Elements/UnitTest/StanzasTest.cpp new file mode 100644 index 0000000..35b84e7 --- /dev/null +++ b/Swiften/Elements/UnitTest/StanzasTest.cpp @@ -0,0 +1,3 @@ +#include "Swiften/Elements/Message.h" +#include "Swiften/Elements/IQ.h" +#include "Swiften/Elements/Presence.h" diff --git a/Swiften/Elements/UnknownElement.h b/Swiften/Elements/UnknownElement.h new file mode 100644 index 0000000..a2ae406 --- /dev/null +++ b/Swiften/Elements/UnknownElement.h @@ -0,0 +1,14 @@ +#ifndef SWIFTEN_UnknownElement_H +#define SWIFTEN_UnknownElement_H + +#include "Swiften/Elements/Element.h" + +namespace Swift { + class UnknownElement : public Element + { + public: + UnknownElement() {} + }; +} + +#endif diff --git a/Swiften/Elements/Version.h b/Swiften/Elements/Version.h new file mode 100644 index 0000000..327178e --- /dev/null +++ b/Swiften/Elements/Version.h @@ -0,0 +1,24 @@ +#ifndef SWIFTEN_STANZAS_VERSION_H +#define SWIFTEN_STANZAS_VERSION_H + +#include "Swiften/Base/String.h" +#include "Swiften/Elements/Payload.h" + +namespace Swift { + class Version : public Payload + { + public: + Version(const String& name = "", const String& version = "", const String& os = "") : name_(name), version_(version), os_(os) { } + + const String& getName() const { return name_; } + const String& getVersion() const { return version_; } + const String& getOS() const { return os_; } + + private: + String name_; + String version_; + String os_; + }; +} + +#endif |