From 7592d966e684410f603942e34413375c8d98ac9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 29 Apr 2018 01:40:46 +0200 Subject: Missing fields in a data-form response are now interpreted as an empty value --- CHANGELOG.rst | 3 +++ src/database/column.hpp | 16 ++++++++++++++-- src/database/database.hpp | 10 +++++----- src/database/row.hpp | 21 ++++++++++++++++++--- src/xmpp/biboumi_adhoc_commands.cpp | 5 ++++- tests/database.cpp | 4 ++++ tests/end_to_end/__main__.py | 1 + 7 files changed, 49 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4966a3c..f24faf4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,9 @@ Version 8.0 - A Nick field has been added in the IRC server configuration form, to let the user force a nickname whenever a channel on the server is joined. - Multiple admins can now be listed in the admin field, separated with a colon. +- Missing fields in a data-form response are now properly interpreted as + an empty value, and not the default value. Gajim users were not able to + empty a field of type text-multi because of this issue. Version 7.3 =========== diff --git a/src/database/column.hpp b/src/database/column.hpp index 50c9c14..837aa3f 100644 --- a/src/database/column.hpp +++ b/src/database/column.hpp @@ -9,18 +9,30 @@ struct Column value{default_value} {} Column(): value{} {} + void clear() + { + this->value = {}; + } using real_type = T; T value{}; }; +template +struct UnclearableColumn: public Column +{ + using Column::Column; + void clear() + { } +}; + struct ForeignKey: Column { static constexpr auto name = "fk_"; }; -struct Id: Column { +struct Id: UnclearableColumn { static constexpr std::size_t unset_value = static_cast(-1); static constexpr auto name = "id_"; static constexpr auto options = "PRIMARY KEY"; - Id(): Column(unset_value) {} + Id(): UnclearableColumn(unset_value) {} }; diff --git a/src/database/database.hpp b/src/database/database.hpp index d986ecc..30ffcb4 100644 --- a/src/database/database.hpp +++ b/src/database/database.hpp @@ -27,15 +27,15 @@ class Database struct Uuid: Column { static constexpr auto name = "uuid_"; }; - struct Owner: Column { static constexpr auto name = "owner_"; }; + struct Owner: UnclearableColumn { static constexpr auto name = "owner_"; }; - struct IrcChanName: Column { static constexpr auto name = "ircchanname_"; }; + struct IrcChanName: UnclearableColumn { static constexpr auto name = "ircchanname_"; }; - struct Channel: Column { static constexpr auto name = "channel_"; }; + struct Channel: UnclearableColumn { static constexpr auto name = "channel_"; }; - struct IrcServerName: Column { static constexpr auto name = "ircservername_"; }; + struct IrcServerName: UnclearableColumn { static constexpr auto name = "ircservername_"; }; - struct Server: Column { static constexpr auto name = "server_"; }; + struct Server: UnclearableColumn { static constexpr auto name = "server_"; }; struct Date: Column { static constexpr auto name = "date_"; }; diff --git a/src/database/row.hpp b/src/database/row.hpp index 27caf43..1253f93 100644 --- a/src/database/row.hpp +++ b/src/database/row.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include template @@ -25,7 +23,24 @@ struct Row return col.value; } -public: + void clear() + { + this->clear_col<0>(); + } + std::tuple columns; std::string table_name; + +private: + template + typename std::enable_if::type + clear_col() + { + std::get(this->columns).clear(); + this->clear_col(); + } + template + typename std::enable_if::type + clear_col() + { } }; diff --git a/src/xmpp/biboumi_adhoc_commands.cpp b/src/xmpp/biboumi_adhoc_commands.cpp index 53806d6..b62dcfc 100644 --- a/src/xmpp/biboumi_adhoc_commands.cpp +++ b/src/xmpp/biboumi_adhoc_commands.cpp @@ -177,6 +177,7 @@ void ConfigureGlobalStep2(XmppComponent& xmpp_component, AdhocSession& session, { const Jid owner(session.get_owner_jid()); auto options = Database::get_global_options(owner.bare()); + options.clear(); for (const XmlNode* field: x->get_children("field", "jabber:x:data")) { const XmlNode* value = field->get_child("value", "jabber:x:data"); @@ -400,7 +401,8 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com server_domain = target.local; auto options = Database::get_irc_server_options(owner.local + "@" + owner.domain, server_domain); - auto commands = Database::get_after_connection_commands(options); + options.clear(); + Database::AfterConnectionCommands commands{}; for (const XmlNode* field: x->get_children("field", "jabber:x:data")) { @@ -608,6 +610,7 @@ bool handle_irc_channel_configuration_form(XmppComponent& xmpp_component, const const Iid iid(target.local, {}); auto options = Database::get_irc_channel_options(requester.bare(), iid.get_server(), iid.get_local()); + options.clear(); for (const XmlNode *field: x->get_children("field", "jabber:x:data")) { const XmlNode *value = field->get_child("value", "jabber:x:data"); diff --git a/tests/database.cpp b/tests/database.cpp index 15c117b..070a460 100644 --- a/tests/database.cpp +++ b/tests/database.cpp @@ -64,6 +64,10 @@ TEST_CASE("Database") CHECK(o.col() == "ISO-8859-1"); CHECK(o.col().is_set == true); CHECK(o.col().value == false); + + o.clear(); + CHECK(o.col() == ""); + CHECK(o.col() == "zouzou@example.com"); } SECTION("Channel options with server default") diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index 82321eb..2f6fc28 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -2885,6 +2885,7 @@ if __name__ == '__main__': partial(expect_stanza, ("/iq[@type='result']/commands:command[@node='configure'][@sessionid][@status='executing']", "/iq/commands:command/dataform:x[@type='form']/dataform:title[text()='Configure the IRC server irc.localhost']", "/iq/commands:command/dataform:x[@type='form']/dataform:instructions[text()='Edit the form, to configure the settings of the IRC server irc.localhost']", + "!/iq/commands:command/dataform:x/dataform:field[@var='tls_ports']/dataform:value", "!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='pass']/dataform:value", "!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='after_connect_commands']/dataform:value", "!/iq/commands:command/dataform:x[@type='form']/dataform:field[@var='username']/dataform:value", -- cgit v1.2.3