summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Elements')
-rw-r--r--Swiften/Elements/Bytestreams.h59
-rw-r--r--Swiften/Elements/Form.cpp14
-rw-r--r--Swiften/Elements/Form.h2
-rw-r--r--Swiften/Elements/IBB.h103
-rw-r--r--Swiften/Elements/StreamInitiation.h76
-rw-r--r--Swiften/Elements/UnitTest/FormTest.cpp20
6 files changed, 270 insertions, 4 deletions
diff --git a/Swiften/Elements/Bytestreams.h b/Swiften/Elements/Bytestreams.h
new file mode 100644
index 0000000..323167c
--- /dev/null
+++ b/Swiften/Elements/Bytestreams.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <vector>
+#include <boost/optional.hpp>
+
+#include "Swiften/JID/JID.h"
+#include "Swiften/Base/String.h"
+#include "Swiften/Base/Shared.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class Bytestreams : public Payload, public Shared<Bytestreams> {
+ public:
+ struct StreamHost {
+ StreamHost(const String& host = "", const JID& jid = JID(), int port = -1) : host(host), jid(jid), port(port) {}
+
+ String host;
+ JID jid;
+ int port;
+ };
+
+ Bytestreams() {}
+
+ const String& getStreamID() const {
+ return id;
+ }
+
+ void setStreamID(const String& id) {
+ this->id = id;
+ }
+
+ const boost::optional<JID>& getUsedStreamHost() const {
+ return usedStreamHost;
+ }
+
+ void setUsedStreamHost(const JID& host) {
+ usedStreamHost = host;
+ }
+
+ const std::vector<StreamHost>& getStreamHosts() const {
+ return streamHosts;
+ }
+
+ void addStreamHost(const StreamHost& streamHost) {
+ streamHosts.push_back(streamHost);
+ }
+
+ private:
+ String id;
+ boost::optional<JID> usedStreamHost;
+ std::vector<StreamHost> streamHosts;
+ };
+}
diff --git a/Swiften/Elements/Form.cpp b/Swiften/Elements/Form.cpp
index 9420fb9..41014ba 100644
--- a/Swiften/Elements/Form.cpp
+++ b/Swiften/Elements/Form.cpp
@@ -10,13 +10,19 @@
namespace Swift {
String Form::getFormType() const {
+ FormField::ref field = getField("FORM_TYPE");
+ boost::shared_ptr<HiddenFormField> f = boost::dynamic_pointer_cast<HiddenFormField>(field);
+ return (f ? f->getValue() : "");
+}
+
+FormField::ref Form::getField(const String& name) const {
foreach(FormField::ref field, fields_) {
- boost::shared_ptr<HiddenFormField> f = boost::dynamic_pointer_cast<HiddenFormField>(field);
- if (f && f->getName() == "FORM_TYPE") {
- return f->getValue();
+ if (field->getName() == name) {
+ return field;
}
}
- return "";
+ return FormField::ref();
}
+
}
diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h
index f5826a5..0eb6ef0 100644
--- a/Swiften/Elements/Form.h
+++ b/Swiften/Elements/Form.h
@@ -40,6 +40,8 @@ namespace Swift {
String getFormType() const;
+ FormField::ref getField(const String& name) const;
+
private:
std::vector<boost::shared_ptr<FormField> > fields_;
String title_;
diff --git a/Swiften/Elements/IBB.h b/Swiften/Elements/IBB.h
new file mode 100644
index 0000000..da9c18a
--- /dev/null
+++ b/Swiften/Elements/IBB.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Base/Shared.h"
+#include "Swiften/Base/ByteArray.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class IBB : public Payload, public Shared<IBB> {
+ public:
+ enum Action {
+ Open,
+ Close,
+ Data,
+ };
+ enum StanzaType {
+ IQStanza,
+ MessageStanza,
+ };
+
+ IBB(Action action = Open, const String& streamID = "") : action(action), streamID(streamID), stanzaType(IQStanza), blockSize(-1), sequenceNumber(-1) {
+ }
+
+ static IBB::ref createIBBOpen(const String& streamID, int blockSize) {
+ IBB::ref result(new IBB(Open, streamID));
+ result->setBlockSize(blockSize);
+ return result;
+ }
+
+ static IBB::ref createIBBData(const String& streamID, int sequenceNumber, const ByteArray& data) {
+ IBB::ref result(new IBB(Data, streamID));
+ result->setSequenceNumber(sequenceNumber);
+ result->setData(data);
+ return result;
+ }
+
+ static IBB::ref createIBBClose(const String& streamID) {
+ return IBB::ref(new IBB(Close, streamID));
+ }
+
+ void setAction(Action action) {
+ this->action = action;
+ }
+
+ Action getAction() const {
+ return action;
+ }
+
+ void setStanzaType(StanzaType stanzaType) {
+ this->stanzaType = stanzaType;
+ }
+
+ StanzaType getStanzaType() const {
+ return stanzaType;
+ }
+
+ void setStreamID(const String& id) {
+ streamID = id;
+ }
+
+ const String& getStreamID() const {
+ return streamID;
+ }
+
+ const ByteArray& getData() const {
+ return data;
+ }
+
+ void setData(const ByteArray& data) {
+ this->data = data;
+ }
+
+ int getBlockSize() const {
+ return blockSize;
+ }
+
+ void setBlockSize(int blockSize) {
+ this->blockSize = blockSize;
+ }
+
+ int getSequenceNumber() const {
+ return sequenceNumber;
+ }
+
+ void setSequenceNumber(int i) {
+ sequenceNumber = i;
+ }
+
+ private:
+ Action action;
+ String streamID;
+ ByteArray data;
+ StanzaType stanzaType;
+ int blockSize;
+ int sequenceNumber;
+ };
+}
diff --git a/Swiften/Elements/StreamInitiation.h b/Swiften/Elements/StreamInitiation.h
new file mode 100644
index 0000000..fdf2399
--- /dev/null
+++ b/Swiften/Elements/StreamInitiation.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#pragma once
+
+#include <vector>
+#include <boost/optional.hpp>
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Base/Shared.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class StreamInitiation : public Payload, public Shared<StreamInitiation> {
+ public:
+ struct FileInfo {
+ FileInfo(const String& name = "", const String& description = "", int size = -1) : name(name), description(description), size(size) {}
+
+ String name;
+ String description;
+ int size;
+ };
+
+ StreamInitiation() : isFileTransfer(true) {}
+
+ const String& getID() const {
+ return id;
+ }
+
+ void setID(const String& id) {
+ this->id = id;
+ }
+
+ const boost::optional<FileInfo>& getFileInfo() const {
+ return fileInfo;
+ }
+
+ void setFileInfo(const FileInfo& info) {
+ fileInfo = info;
+ }
+
+ const std::vector<String>& getProvidedMethods() const {
+ return providedMethods;
+ }
+
+ void addProvidedMethod(const String& method) {
+ providedMethods.push_back(method);
+ }
+
+ void setRequestedMethod(const String& method) {
+ requestedMethod = method;
+ }
+
+ const String& getRequestedMethod() const {
+ return requestedMethod;
+ }
+
+ bool getIsFileTransfer() const {
+ return isFileTransfer;
+ }
+
+ void setIsFileTransfer(bool b) {
+ isFileTransfer = b;
+ }
+
+ private:
+ bool isFileTransfer;
+ String id;
+ boost::optional<FileInfo> fileInfo;
+ std::vector<String> providedMethods;
+ String requestedMethod;
+ };
+}
diff --git a/Swiften/Elements/UnitTest/FormTest.cpp b/Swiften/Elements/UnitTest/FormTest.cpp
index 3852d98..715111b 100644
--- a/Swiften/Elements/UnitTest/FormTest.cpp
+++ b/Swiften/Elements/UnitTest/FormTest.cpp
@@ -15,6 +15,8 @@ using namespace Swift;
class FormTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(FormTest);
CPPUNIT_TEST(testGetFormType);
+ CPPUNIT_TEST(testGetFormType_InvalidFormType);
+ CPPUNIT_TEST(testGetFormType_NoFormType);
CPPUNIT_TEST_SUITE_END();
public:
@@ -31,6 +33,24 @@ class FormTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(String("jabber:bot"), form.getFormType());
}
+
+ void testGetFormType_InvalidFormType() {
+ Form form;
+
+ FormField::ref field = FixedFormField::create("jabber:bot");
+ field->setName("FORM_TYPE");
+ form.addField(field);
+
+ CPPUNIT_ASSERT_EQUAL(String(""), form.getFormType());
+ }
+
+ void testGetFormType_NoFormType() {
+ Form form;
+
+ form.addField(FixedFormField::create("Foo"));
+
+ CPPUNIT_ASSERT_EQUAL(String(""), form.getFormType());
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(FormTest);