コード例 #1
0
        void testSerialize_Form() {
            InBandRegistrationPayloadSerializer testling;
            std::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload());
            registration->setInstructions("Use the enclosed form to register.");

            std::shared_ptr<Form> form(new Form(Form::FormType));
            form->setTitle("Contest Registration");

            FormField::ref field = std::make_shared<FormField>(FormField::HiddenType, "jabber:iq:register");
            field->setName("FORM_TYPE");
            form->addField(field);
            registration->setForm(form);

            std::string expectedResult =
                "<query xmlns=\"jabber:iq:register\">"
                    "<instructions>Use the enclosed form to register.</instructions>"
                    "<x type=\"form\" xmlns=\"jabber:x:data\">"
                        "<title>Contest Registration</title>"
                        "<field type=\"hidden\" var=\"FORM_TYPE\">"
                            "<value>jabber:iq:register</value>"
                        "</field>"
                    "</x>"
                "</query>";

            CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(registration));
        }
コード例 #2
0
ファイル: formutils.cpp プロジェクト: hanzz/spectrum2
std::string fieldValue(Swift::Form::ref form, const std::string &key, const std::string &def) {
	const std::vector<FormField::ref> fields = form->getFields();
	for (std::vector<FormField::ref>::const_iterator it = fields.begin(); it != fields.end(); it++) {
#if HAVE_SWIFTEN_3
		FormField::ref field = *it;
		const std::vector<std::string> values = field->getValues();
		if (field->getName() == key) {
			return values.empty() ? "" : values[0];
		}
#else
		TextSingleFormField::ref textSingle = SWIFTEN_SHRPTR_NAMESPACE::dynamic_pointer_cast<TextSingleFormField>(*it);
		if (textSingle && textSingle->getName() == key) {
			return textSingle->getValue();
		}

		TextPrivateFormField::ref textPrivate = SWIFTEN_SHRPTR_NAMESPACE::dynamic_pointer_cast<TextPrivateFormField>(*it);
		if (textPrivate && textPrivate->getName() == key) {
			return textPrivate->getValue();
		}

		ListSingleFormField::ref listSingle = SWIFTEN_SHRPTR_NAMESPACE::dynamic_pointer_cast<ListSingleFormField>(*it);
		if (listSingle && listSingle->getName() == key) {
			return listSingle->getValue();
		}

		BooleanFormField::ref boolean = SWIFTEN_SHRPTR_NAMESPACE::dynamic_pointer_cast<BooleanFormField>(*it);
		if (boolean && boolean->getName() == key) {
			return boolean->getValue() ? "1" : "0";
		}
#endif
	}

	return def;
}
コード例 #3
0
		foreach(FormField::ref field, fields) {
			if (field->getName() == "FORM_TYPE") {
				continue;
			}
			serializedCaps += field->getName() + "<";
			std::vector<std::string> values(field->getValues());
			std::sort(values.begin(), values.end());
			foreach(const std::string& value, values) {
				serializedCaps += value + "<";
			}
コード例 #4
0
ファイル: formutils.cpp プロジェクト: hanzz/spectrum2
static 
#if HAVE_SWIFTEN_3
FormField::ref
#else
HiddenFormField::ref
#endif
createHiddenField(const std::string &name, const std::string &value) {
#if HAVE_SWIFTEN_3
	FormField::ref field = SWIFTEN_SHRPTR_NAMESPACE::make_shared<FormField>(FormField::HiddenType, value);
#else
	HiddenFormField::ref field = HiddenFormField::create();
	field->setValue(value);
#endif
	field->setName(name);
	return field;
}
コード例 #5
0
ファイル: formutils.cpp プロジェクト: hanzz/spectrum2
static 
#if HAVE_SWIFTEN_3
FormField::ref
#else
TextPrivateFormField::ref
#endif
createTextPrivateField(const std::string &name, const std::string &label, bool required) {
#if HAVE_SWIFTEN_3
	FormField::ref field = SWIFTEN_SHRPTR_NAMESPACE::make_shared<FormField>(FormField::TextPrivateType);
#else
	TextPrivateFormField::ref field = TextPrivateFormField::create();
#endif
	field->setName(name);
	field->setLabel(label);
	field->setRequired(required);
	return field;
}
コード例 #6
0
ファイル: formutils.cpp プロジェクト: hanzz/spectrum2
static 
#if HAVE_SWIFTEN_3
FormField::ref
#else
BooleanFormField::ref
#endif
createBooleanField(const std::string &name, const std::string &value, const std::string &label, bool required) {
#if HAVE_SWIFTEN_3
	FormField::ref field = SWIFTEN_SHRPTR_NAMESPACE::make_shared<FormField>(FormField::BooleanType, value);
#else
	BooleanFormField::ref field = BooleanFormField::create();
	field->setValue(value == "1");
#endif
	field->setName(name);
	field->setLabel(label);
	field->setRequired(required);
	return field;
}
コード例 #7
0
        void testGenerate_XEP0115ComplexExample() {
            DiscoInfo discoInfo;
            discoInfo.addIdentity(DiscoInfo::Identity("Psi 0.11", "client", "pc", "en"));
            discoInfo.addIdentity(DiscoInfo::Identity("\xce\xa8 0.11", "client", "pc", "el"));
            discoInfo.addFeature("http://jabber.org/protocol/disco#items");
            discoInfo.addFeature("http://jabber.org/protocol/caps");
            discoInfo.addFeature("http://jabber.org/protocol/disco#info");
            discoInfo.addFeature("http://jabber.org/protocol/muc");

            Form::ref extension(new Form(Form::ResultType));
            FormField::ref field = std::make_shared<FormField>(FormField::HiddenType, "urn:xmpp:dataforms:softwareinfo");
            field->setName("FORM_TYPE");
            extension->addField(field);
            field = std::make_shared<FormField>(FormField::ListMultiType);
            field->addValue("ipv6");
            field->addValue("ipv4");
            field->setName("ip_version");
            extension->addField(field);
            field = std::make_shared<FormField>(FormField::TextSingleType, "Psi");
            field->setName("software");
            extension->addField(field);
            field = std::make_shared<FormField>(FormField::TextSingleType, "0.11");
            field->setName("software_version");
            extension->addField(field);
            field = std::make_shared<FormField>(FormField::TextSingleType, "Mac");
            field->setName("os");
            extension->addField(field);
            field = std::make_shared<FormField>(FormField::TextSingleType, "10.5.1");
            field->setName("os_version");
            extension->addField(field);
            discoInfo.addExtension(extension);

            CapsInfoGenerator testling("http://psi-im.org", crypto.get());
            CapsInfo result = testling.generateCapsInfo(discoInfo);

            CPPUNIT_ASSERT_EQUAL(std::string("q07IKJEyjvHSyhy//CH0CxmKi8w="), result.getVersion());
        }
コード例 #8
0
ファイル: formutils.cpp プロジェクト: hanzz/spectrum2
static 
#if HAVE_SWIFTEN_3
FormField::ref
#else
ListSingleFormField::ref
#endif
createListSingleField(const std::string &name, Swift::FormField::Option value, const std::string &label, const std::string &def, bool required) {
#if HAVE_SWIFTEN_3
	FormField::ref field = SWIFTEN_SHRPTR_NAMESPACE::make_shared<FormField>(FormField::ListSingleType);
#else
	ListSingleFormField::ref field = ListSingleFormField::create();
#endif
	field->setName(name);
	field->setLabel(label);
	field->addOption(value);
#if HAVE_SWIFTEN_3
	field->addValue(def);
#else
	field->setValue(def);
#endif
	return field;
}
コード例 #9
0
		void testSerialize_DataForm() {
			SearchPayloadSerializer testling;

			SearchPayload::ref payload(new SearchPayload());
			boost::shared_ptr<Form> form(new Form(Form::ResultType));

			FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:search");
			field->setName("FORM_TYPE");
			form->addField(field);

			// reported fields
			field = boost::make_shared<FormField>(FormField::TextSingleType);
			field->setName("first");
			field->setLabel("Given Name");
			form->addReportedField(field);

			field = boost::make_shared<FormField>(FormField::TextSingleType);
			field->setName("last");
			field->setLabel("Family Name");
			form->addReportedField(field);

			field = boost::make_shared<FormField>(FormField::JIDSingleType);
			field->setName("jid");
			field->setLabel("Jabber ID");
			form->addReportedField(field);

			field = boost::make_shared<FormField>(FormField::ListSingleType);
			field->setName("x-gender");
			field->setLabel("Gender");
			form->addReportedField(field);

			Form::FormItem firstItem;
			field = boost::make_shared<FormField>(FormField::TextSingleType, "Benvolio");
			field->setName("first");
			firstItem.push_back(field);

			field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague");
			field->setName("last");
			firstItem.push_back(field);

			field = boost::make_shared<FormField>(FormField::TextSingleType, "*****@*****.**");
			field->setName("jid");
			firstItem.push_back(field);

			field = boost::make_shared<FormField>(FormField::ListSingleType, "male");
			field->setName("x-gender");
			firstItem.push_back(field);

			Form::FormItem secondItem;
			field = boost::make_shared<FormField>(FormField::TextSingleType, "Romeo");
			field->setName("first");
			secondItem.push_back(field);

			field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague");
			field->setName("last");
			secondItem.push_back(field);

			field = boost::make_shared<FormField>(FormField::TextSingleType, "*****@*****.**");
			field->setName("jid");
			secondItem.push_back(field);

			field = boost::make_shared<FormField>(FormField::ListSingleType, "male");
			field->setName("x-gender");
			secondItem.push_back(field);

			form->addItem(firstItem);
			form->addItem(secondItem);

			payload->setForm(form);

			CPPUNIT_ASSERT_EQUAL(std::string(
				"<query xmlns=\"jabber:iq:search\">"
					"<x type=\"result\" xmlns=\"jabber:x:data\">"
						"<field type=\"hidden\" var=\"FORM_TYPE\">"
							"<value>jabber:iq:search</value>"
						"</field>"
						"<reported>"
							"<field label=\"Given Name\" type=\"text-single\" var=\"first\"/>"
							"<field label=\"Family Name\" type=\"text-single\" var=\"last\"/>"
							"<field label=\"Jabber ID\" type=\"jid-single\" var=\"jid\"/>"
							"<field label=\"Gender\" type=\"list-single\" var=\"x-gender\"/>"
						"</reported>"
						"<item>"
							"<field var=\"first\"><value>Benvolio</value></field>"
							"<field var=\"last\"><value>Montague</value></field>"
							"<field var=\"jid\"><value>[email protected]</value></field>"
							"<field var=\"x-gender\"><value>male</value></field>"
						"</item>"
						"<item>"
							"<field var=\"first\"><value>Romeo</value></field>"
							"<field var=\"last\"><value>Montague</value></field>"
							"<field var=\"jid\"><value>[email protected]</value></field>"
							"<field var=\"x-gender\"><value>male</value></field>"
						"</item>"
					"</x>"
				"</query>"), testling.serialize(payload));

		}
コード例 #10
0
ファイル: Form.cpp プロジェクト: marosi/SocialDesktopClient
	foreach(FormField::ref field, fields_) {
		if (field->getName() == name) {
			return field;
		}
	}