summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-03-28 15:46:49 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-03-28 15:46:49 (GMT)
commitf53a1ef582494458301b97bf6e546be52d7ff7e8 (patch)
tree7571b5cbcbd8a8f1dd1c966c9045b6cb69f0e295 /Swiften/Elements
parent638345680d72ca6acaf123f2c8c1c391f696e371 (diff)
downloadswift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.zip
swift-contrib-f53a1ef582494458301b97bf6e546be52d7ff7e8.tar.bz2
Moving submodule contents back.
Diffstat (limited to 'Swiften/Elements')
-rw-r--r--Swiften/Elements/AuthChallenge.h23
-rw-r--r--Swiften/Elements/AuthFailure.h13
-rw-r--r--Swiften/Elements/AuthRequest.h36
-rw-r--r--Swiften/Elements/AuthResponse.h23
-rw-r--r--Swiften/Elements/AuthSuccess.h22
-rw-r--r--Swiften/Elements/Body.h26
-rw-r--r--Swiften/Elements/CapsInfo.h23
-rw-r--r--Swiften/Elements/ChatState.h20
-rw-r--r--Swiften/Elements/CompressFailure.h13
-rw-r--r--Swiften/Elements/CompressRequest.h25
-rw-r--r--Swiften/Elements/Compressed.h14
-rw-r--r--Swiften/Elements/DiscoInfo.cpp25
-rw-r--r--Swiften/Elements/DiscoInfo.h83
-rw-r--r--Swiften/Elements/Element.cpp8
-rw-r--r--Swiften/Elements/Element.h11
-rw-r--r--Swiften/Elements/ErrorPayload.h67
-rw-r--r--Swiften/Elements/IQ.cpp37
-rw-r--r--Swiften/Elements/IQ.h36
-rw-r--r--Swiften/Elements/MUCPayload.h11
-rw-r--r--Swiften/Elements/Message.h43
-rw-r--r--Swiften/Elements/Payload.cpp8
-rw-r--r--Swiften/Elements/Payload.h11
-rw-r--r--Swiften/Elements/Presence.h62
-rw-r--r--Swiften/Elements/Priority.h25
-rw-r--r--Swiften/Elements/PrivateStorage.h24
-rw-r--r--Swiften/Elements/ProtocolHeader.h36
-rw-r--r--Swiften/Elements/RawXMLPayload.h22
-rw-r--r--Swiften/Elements/ResourceBind.h36
-rw-r--r--Swiften/Elements/RosterItemPayload.h43
-rw-r--r--Swiften/Elements/RosterPayload.cpp17
-rw-r--r--Swiften/Elements/RosterPayload.h33
-rw-r--r--Swiften/Elements/SecurityLabel.h57
-rw-r--r--Swiften/Elements/SecurityLabelsCatalog.h56
-rw-r--r--Swiften/Elements/SoftwareVersion.h47
-rw-r--r--Swiften/Elements/Stanza.cpp31
-rw-r--r--Swiften/Elements/Stanza.h60
-rw-r--r--Swiften/Elements/StartSession.h14
-rw-r--r--Swiften/Elements/StartTLSFailure.h13
-rw-r--r--Swiften/Elements/StartTLSRequest.h14
-rw-r--r--Swiften/Elements/Status.h26
-rw-r--r--Swiften/Elements/StatusShow.h27
-rw-r--r--Swiften/Elements/Storage.h36
-rw-r--r--Swiften/Elements/StreamFeatures.h77
-rw-r--r--Swiften/Elements/TLSProceed.h14
-rw-r--r--Swiften/Elements/UnitTest/IQTest.cpp52
-rw-r--r--Swiften/Elements/UnitTest/StanzaTest.cpp155
-rw-r--r--Swiften/Elements/UnitTest/StanzasTest.cpp3
-rw-r--r--Swiften/Elements/UnknownElement.h13
-rw-r--r--Swiften/Elements/VCard.h42
-rw-r--r--Swiften/Elements/VCardUpdate.h17
-rw-r--r--Swiften/Elements/Version.h24
51 files changed, 1654 insertions, 0 deletions
diff --git a/Swiften/Elements/AuthChallenge.h b/Swiften/Elements/AuthChallenge.h
new file mode 100644
index 0000000..b8a9297
--- /dev/null
+++ b/Swiften/Elements/AuthChallenge.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "Swiften/Base/ByteArray.h"
+#include "Swiften/Elements/Element.h"
+
+namespace Swift {
+ class AuthChallenge : public Element {
+ public:
+ AuthChallenge(const ByteArray& value = "") : value(value) {
+ }
+
+ const ByteArray& getValue() const {
+ return value;
+ }
+
+ void setValue(const ByteArray& value) {
+ this->value = value;
+ }
+
+ private:
+ ByteArray value;
+ };
+}
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/AuthResponse.h b/Swiften/Elements/AuthResponse.h
new file mode 100644
index 0000000..8a0679f
--- /dev/null
+++ b/Swiften/Elements/AuthResponse.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "Swiften/Base/ByteArray.h"
+#include "Swiften/Elements/Element.h"
+
+namespace Swift {
+ class AuthResponse : public Element {
+ public:
+ AuthResponse(const ByteArray& value = "") : value(value) {
+ }
+
+ const ByteArray& getValue() const {
+ return value;
+ }
+
+ void setValue(const ByteArray& value) {
+ this->value = value;
+ }
+
+ private:
+ ByteArray value;
+ };
+}
diff --git a/Swiften/Elements/AuthSuccess.h b/Swiften/Elements/AuthSuccess.h
new file mode 100644
index 0000000..1db1729
--- /dev/null
+++ b/Swiften/Elements/AuthSuccess.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Swiften/Elements/Element.h"
+#include "Swiften/Base/ByteArray.h"
+
+namespace Swift {
+ class AuthSuccess : public Element {
+ public:
+ AuthSuccess() {}
+
+ const ByteArray& getValue() const {
+ return value;
+ }
+
+ void setValue(const ByteArray& value) {
+ this->value = value;
+ }
+
+ private:
+ ByteArray value;
+ };
+}
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/ChatState.h b/Swiften/Elements/ChatState.h
new file mode 100644
index 0000000..3378cc3
--- /dev/null
+++ b/Swiften/Elements/ChatState.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class ChatState : public Payload {
+ public:
+ enum ChatStateType {Active, Composing, Paused, Inactive, Gone};
+ ChatState(ChatStateType state = Active) {
+ state_ = state;
+ }
+
+ ChatStateType getChatState() { return state_; }
+ void setChatState(ChatStateType state) {state_ = state;}
+
+ private:
+ ChatStateType state_;
+ };
+}
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/ErrorPayload.h b/Swiften/Elements/ErrorPayload.h
new file mode 100644
index 0000000..32fd067
--- /dev/null
+++ b/Swiften/Elements/ErrorPayload.h
@@ -0,0 +1,67 @@
+#pragma once
+
+#include "Swiften/Elements/Payload.h"
+#include "Swiften/Base/String.h"
+
+namespace Swift {
+ class ErrorPayload : 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
+ };
+
+ ErrorPayload(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_;
+ };
+}
diff --git a/Swiften/Elements/IQ.cpp b/Swiften/Elements/IQ.cpp
new file mode 100644
index 0000000..53dec53
--- /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, ErrorPayload::Condition condition, ErrorPayload::Type type) {
+ boost::shared_ptr<IQ> iq(new IQ(IQ::Error));
+ iq->setTo(to);
+ iq->setID(id);
+ iq->addPayload(boost::shared_ptr<Swift::ErrorPayload>(new Swift::ErrorPayload(condition, type)));
+ return iq;
+}
+
+}
diff --git a/Swiften/Elements/IQ.h b/Swiften/Elements/IQ.h
new file mode 100644
index 0000000..80c2913
--- /dev/null
+++ b/Swiften/Elements/IQ.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "Swiften/Elements/Stanza.h"
+#include "Swiften/Elements/ErrorPayload.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,
+ ErrorPayload::Condition condition,
+ ErrorPayload::Type type);
+
+ private:
+ Type type_;
+ };
+}
diff --git a/Swiften/Elements/MUCPayload.h b/Swiften/Elements/MUCPayload.h
new file mode 100644
index 0000000..97932a1
--- /dev/null
+++ b/Swiften/Elements/MUCPayload.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class MUCPayload : public Payload {
+ public:
+ MUCPayload() {
+ }
+ };
+}
diff --git a/Swiften/Elements/Message.h b/Swiften/Elements/Message.h
new file mode 100644
index 0000000..6d9171f
--- /dev/null
+++ b/Swiften/Elements/Message.h
@@ -0,0 +1,43 @@
+#pragma once
+
+#include <boost/optional.hpp>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/Body.h"
+#include "Swiften/Elements/ErrorPayload.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::ErrorPayload> error(getPayload<Swift::ErrorPayload>());
+ return getType() == Message::Error || error;
+ }
+
+ Type getType() const { return type_; }
+ void setType(Type type) { type_ = type; }
+
+ private:
+ String body_;
+ Type type_;
+ };
+}
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..f748e44
--- /dev/null
+++ b/Swiften/Elements/Presence.h
@@ -0,0 +1,62 @@
+#pragma once
+
+#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)*/ {}
+ Presence(const String& status) : type_(Available) {
+ setStatus(status);
+ }
+
+ 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)));
+ }
+
+ boost::shared_ptr<Presence> clone() const {
+ return boost::shared_ptr<Presence>(new Presence(*this));
+ }
+
+ private:
+ Presence::Type type_;
+ };
+}
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/PrivateStorage.h b/Swiften/Elements/PrivateStorage.h
new file mode 100644
index 0000000..93f1cfe
--- /dev/null
+++ b/Swiften/Elements/PrivateStorage.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class PrivateStorage : public Payload {
+ public:
+ PrivateStorage(boost::shared_ptr<Payload> payload = boost::shared_ptr<Payload>()) : payload(payload) {
+ }
+
+ boost::shared_ptr<Payload> getPayload() const {
+ return payload;
+ }
+
+ void setPayload(boost::shared_ptr<Payload> p) {
+ payload = p;
+ }
+
+ private:
+ boost::shared_ptr<Payload> payload;
+ };
+}
diff --git a/Swiften/Elements/ProtocolHeader.h b/Swiften/Elements/ProtocolHeader.h
new file mode 100644
index 0000000..da64811
--- /dev/null
+++ b/Swiften/Elements/ProtocolHeader.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "Swiften/Base/String.h"
+
+namespace Swift {
+ class ProtocolHeader {
+ public:
+ ProtocolHeader() : version("1.0") {}
+
+ const String& getTo() const { return to; }
+ void setTo(const String& a) {
+ to = a;
+ }
+
+ const String& getFrom() const { return from; }
+ void setFrom(const String& a) {
+ from = a;
+ }
+
+ const String& getVersion() const { return version; }
+ void setVersion(const String& a) {
+ version = a;
+ }
+
+ const String& getID() const { return id; }
+ void setID(const String& a) {
+ id = a;
+ }
+
+ private:
+ String to;
+ String from;
+ String id;
+ String version;
+ };
+}
diff --git a/Swiften/Elements/RawXMLPayload.h b/Swiften/Elements/RawXMLPayload.h
new file mode 100644
index 0000000..c2ee439
--- /dev/null
+++ b/Swiften/Elements/RawXMLPayload.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class RawXMLPayload : public Payload {
+ public:
+ RawXMLPayload() {}
+
+ void setRawXML(const String& data) {
+ rawXML_ = data;
+ }
+
+ const String& getRawXML() const {
+ return rawXML_;
+ }
+
+ private:
+ String rawXML_;
+ };
+}
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..1aecde9
--- /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().equals(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/Storage.h b/Swiften/Elements/Storage.h
new file mode 100644
index 0000000..1458836
--- /dev/null
+++ b/Swiften/Elements/Storage.h
@@ -0,0 +1,36 @@
+#pragma once
+
+#include <vector>
+
+#include "Swiften/Elements/Payload.h"
+#include "Swiften/Base/String.h"
+#include "Swiften/JID/JID.h"
+
+namespace Swift {
+ class Storage : public Payload {
+ public:
+ struct Conference {
+ Conference() : autoJoin(false) {}
+
+ String name;
+ JID jid;
+ bool autoJoin;
+ String nick;
+ String password;
+ };
+
+ Storage() {
+ }
+
+ const std::vector<Conference>& getConferences() const {
+ return conferences;
+ }
+
+ void addConference(const Conference& conference) {
+ conferences.push_back(conference);
+ }
+
+ private:
+ std::vector<Conference> conferences;
+ };
+}
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..a5e6dc8
--- /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", ErrorPayload::BadRequest, ErrorPayload::Modify));
+
+ CPPUNIT_ASSERT_EQUAL(JID("foo@bar/fum"), iq->getTo());
+ CPPUNIT_ASSERT_EQUAL(String("myid"), iq->getID());
+ boost::shared_ptr<ErrorPayload> error(iq->getPayload<ErrorPayload>());
+ CPPUNIT_ASSERT(error);
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::BadRequest, error->getCondition());
+ CPPUNIT_ASSERT_EQUAL(ErrorPayload::Modify, error->getType());
+ }
+
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(IQTest);
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..3d2c219
--- /dev/null
+++ b/Swiften/Elements/UnknownElement.h
@@ -0,0 +1,13 @@
+#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/VCard.h b/Swiften/Elements/VCard.h
new file mode 100644
index 0000000..a42d7e3
--- /dev/null
+++ b/Swiften/Elements/VCard.h
@@ -0,0 +1,42 @@
+#pragma once
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Base/ByteArray.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class VCard : public Payload {
+ public:
+ VCard() {}
+
+ void setFullName(const String& fullName) { fullName_ = fullName; }
+ const String& getFullName() const { return fullName_; }
+
+ void setFamilyName(const String& familyName) { familyName_ = familyName; }
+ const String& getFamilyName() const { return familyName_; }
+
+ void setGivenName(const String& givenName) { givenName_ = givenName; }
+ const String& getGivenName() const { return givenName_; }
+
+ void setEMail(const String& email) { email_ = email; }
+ const String& getEMail() const { return email_; }
+
+ void setNickname(const String& nick) { nick_ = nick; }
+ const String& getNickname() const { return nick_; }
+
+ void setPhoto(const ByteArray& photo) { photo_ = photo; }
+ const ByteArray& getPhoto() { return photo_; }
+
+ void setPhotoType(const String& photoType) { photoType_ = photoType; }
+ const String& getPhotoType() { return photoType_; }
+
+ private:
+ String fullName_;
+ String familyName_;
+ String givenName_;
+ String email_;
+ ByteArray photo_;
+ String photoType_;
+ String nick_;
+ };
+}
diff --git a/Swiften/Elements/VCardUpdate.h b/Swiften/Elements/VCardUpdate.h
new file mode 100644
index 0000000..6bb79cc
--- /dev/null
+++ b/Swiften/Elements/VCardUpdate.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class VCardUpdate : public Payload {
+ public:
+ VCardUpdate(const String& photoHash = "") : photoHash_(photoHash) {}
+
+ void setPhotoHash(const String& photoHash) { photoHash_ = photoHash; }
+ const String& getPhotoHash() { return photoHash_; }
+
+ private:
+ String photoHash_;
+ };
+}
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