diff options
Diffstat (limited to 'Swiften/Elements')
-rw-r--r-- | Swiften/Elements/DiscoInfo.h | 17 | ||||
-rw-r--r-- | Swiften/Elements/Form.cpp | 22 | ||||
-rw-r--r-- | Swiften/Elements/Form.h | 2 | ||||
-rw-r--r-- | Swiften/Elements/FormField.h | 13 | ||||
-rw-r--r-- | Swiften/Elements/UnitTest/FormTest.cpp | 36 |
5 files changed, 85 insertions, 5 deletions
diff --git a/Swiften/Elements/DiscoInfo.h b/Swiften/Elements/DiscoInfo.h index cee9200..2cc914a 100644 --- a/Swiften/Elements/DiscoInfo.h +++ b/Swiften/Elements/DiscoInfo.h @@ -4,8 +4,7 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ -#ifndef SWIFTEN_DiscoInfo_H -#define SWIFTEN_DiscoInfo_H +#pragma once #include <vector> #include <algorithm> @@ -13,6 +12,7 @@ #include "Swiften/Elements/Payload.h" #include "Swiften/Base/String.h" #include "Swiften/Base/Shared.h" +#include "Swiften/Elements/Form.h" namespace Swift { class DiscoInfo : public Payload, public Shared<DiscoInfo> { @@ -60,7 +60,7 @@ namespace Swift { node_ = node; } - const std::vector<Identity> getIdentities() const { + const std::vector<Identity>& getIdentities() const { return identities_; } @@ -80,11 +80,18 @@ namespace Swift { return std::find(features_.begin(), features_.end(), feature) != features_.end(); } + void addExtension(Form::ref form) { + extensions_.push_back(form); + } + + const std::vector<Form::ref> getExtensions() const { + return extensions_; + } + private: String node_; std::vector<Identity> identities_; std::vector<String> features_; + std::vector<Form::ref> extensions_; }; } - -#endif diff --git a/Swiften/Elements/Form.cpp b/Swiften/Elements/Form.cpp new file mode 100644 index 0000000..9420fb9 --- /dev/null +++ b/Swiften/Elements/Form.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/Elements/Form.h" +#include "Swiften/Base/foreach.h" + +namespace Swift { + +String Form::getFormType() 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(); + } + } + return ""; +} + +} diff --git a/Swiften/Elements/Form.h b/Swiften/Elements/Form.h index 34068ee..f5826a5 100644 --- a/Swiften/Elements/Form.h +++ b/Swiften/Elements/Form.h @@ -38,6 +38,8 @@ namespace Swift { Type getType() { return type_; } void setType(Type type) { type_ = type; } + String getFormType() const; + private: std::vector<boost::shared_ptr<FormField> > fields_; String title_; diff --git a/Swiften/Elements/FormField.h b/Swiften/Elements/FormField.h index 732203a..a0240e1 100644 --- a/Swiften/Elements/FormField.h +++ b/Swiften/Elements/FormField.h @@ -4,6 +4,9 @@ * See Documentation/Licenses/GPLv3.txt for more information. */ +// FIXME: We currently keep 2 values: the raw values, and the actual value. +// We should only store the raw values, and deduce the actual values from this + #pragma once #include <vector> @@ -45,6 +48,14 @@ namespace Swift { return options; } + const std::vector<String> getRawValues() const { + return rawValues; + } + + void addRawValue(const String& value) { + rawValues.push_back(value); + } + protected: FormField() : required(false) {} @@ -54,6 +65,7 @@ namespace Swift { String description; bool required; std::vector<Option> options; + std::vector<String> rawValues; }; template<typename T> class GenericFormField : public FormField { @@ -99,4 +111,5 @@ namespace Swift { SWIFTEN_DECLARE_FORM_FIELD(JIDSingle, JID); SWIFTEN_DECLARE_FORM_FIELD(JIDMulti, std::vector<JID>); SWIFTEN_DECLARE_FORM_FIELD(ListMulti, std::vector<String>); + SWIFTEN_DECLARE_FORM_FIELD(Untyped, std::vector<String>); } diff --git a/Swiften/Elements/UnitTest/FormTest.cpp b/Swiften/Elements/UnitTest/FormTest.cpp new file mode 100644 index 0000000..3852d98 --- /dev/null +++ b/Swiften/Elements/UnitTest/FormTest.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> +#include <boost/shared_ptr.hpp> + +#include "Swiften/Elements/Form.h" + +using namespace Swift; + +class FormTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(FormTest); + CPPUNIT_TEST(testGetFormType); + CPPUNIT_TEST_SUITE_END(); + + public: + void testGetFormType() { + Form form; + + form.addField(FixedFormField::create("Foo")); + + FormField::ref field = HiddenFormField::create("jabber:bot"); + field->setName("FORM_TYPE"); + form.addField(field); + + form.addField(FixedFormField::create("Bar")); + + CPPUNIT_ASSERT_EQUAL(String("jabber:bot"), form.getFormType()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(FormTest); |