From 50cadf3dac0d56ef8181d1800cc30f8dcb749141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 13 Jun 2017 10:38:39 +0200 Subject: Implement our own database ORM, and update the whole code to use it Entirely replace LiteSQL fix #3271 --- src/xmpp/biboumi_adhoc_commands.cpp | 88 ++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 45 deletions(-) (limited to 'src/xmpp/biboumi_adhoc_commands.cpp') diff --git a/src/xmpp/biboumi_adhoc_commands.cpp b/src/xmpp/biboumi_adhoc_commands.cpp index ab28cfd..a13dbb8 100644 --- a/src/xmpp/biboumi_adhoc_commands.cpp +++ b/src/xmpp/biboumi_adhoc_commands.cpp @@ -130,7 +130,7 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman { XmlSubNode value(max_histo_length, "value"); - value.set_inner(std::to_string(options.maxHistoryLength.value())); + value.set_inner(std::to_string(options.col())); } XmlSubNode record_history(x, "field"); @@ -142,7 +142,7 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman { XmlSubNode value(record_history, "value"); value.set_name("value"); - if (options.recordHistory.value()) + if (options.col()) value.set_inner("true"); else value.set_inner("false"); @@ -164,18 +164,18 @@ void ConfigureGlobalStep2(XmppComponent& xmpp_component, AdhocSession& session, if (field->get_tag("var") == "max_history_length" && value && !value->get_inner().empty()) - options.maxHistoryLength = value->get_inner(); + options.col() = atoi(value->get_inner().data()); else if (field->get_tag("var") == "record_history" && value && !value->get_inner().empty()) { - options.recordHistory = to_bool(value->get_inner()); + options.col() = to_bool(value->get_inner()); Bridge* bridge = biboumi_component.find_user_bridge(owner.bare()); if (bridge) - bridge->set_record_history(options.recordHistory.value()); + bridge->set_record_history(options.col()); } } - options.update(); + options.save(Database::db); command_node.delete_all_children(); XmlSubNode note(command_node, "note"); @@ -211,8 +211,7 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com ports["type"] = "text-multi"; ports["label"] = "Ports"; ports["desc"] = "List of ports to try, without TLS. Defaults: 6667."; - auto vals = utils::split(options.ports.value(), ';', false); - for (const auto& val: vals) + for (const auto& val: utils::split(options.col(), ';', false)) { XmlSubNode ports_value(ports, "value"); ports_value.set_inner(val); @@ -224,8 +223,7 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com tls_ports["type"] = "text-multi"; tls_ports["label"] = "TLS ports"; tls_ports["desc"] = "List of ports to try, with TLS. Defaults: 6697, 6670."; - vals = utils::split(options.tlsPorts.value(), ';', false); - for (const auto& val: vals) + for (const auto& val: utils::split(options.col(), ';', false)) { XmlSubNode tls_ports_value(tls_ports, "value"); tls_ports_value.set_inner(val); @@ -237,7 +235,7 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com verify_cert["label"] = "Verify certificate"; verify_cert["desc"] = "Whether or not to abort the connection if the server’s TLS certificate is invalid"; XmlSubNode verify_cert_value(verify_cert, "value"); - if (options.verifyCert.value()) + if (options.col()) verify_cert_value.set_inner("true"); else verify_cert_value.set_inner("false"); @@ -246,10 +244,10 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com fingerprint["var"] = "fingerprint"; fingerprint["type"] = "text-single"; fingerprint["label"] = "SHA-1 fingerprint of the TLS certificate to trust."; - if (!options.trustedFingerprint.value().empty()) + if (!options.col().empty()) { XmlSubNode fingerprint_value(fingerprint, "value"); - fingerprint_value.set_inner(options.trustedFingerprint.value()); + fingerprint_value.set_inner(options.col()); } #endif @@ -258,10 +256,10 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com pass["type"] = "text-private"; pass["label"] = "Server password"; pass["desc"] = "Will be used in a PASS command when connecting"; - if (!options.pass.value().empty()) + if (!options.col().empty()) { XmlSubNode pass_value(pass, "value"); - pass_value.set_inner(options.pass.value()); + pass_value.set_inner(options.col()); } XmlSubNode after_cnt_cmd(x, "field"); @@ -269,10 +267,10 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com after_cnt_cmd["type"] = "text-single"; after_cnt_cmd["desc"] = "Custom IRC command sent after the connection is established with the server."; after_cnt_cmd["label"] = "After-connection IRC command"; - if (!options.afterConnectionCommand.value().empty()) + if (!options.col().empty()) { XmlSubNode after_cnt_cmd_value(after_cnt_cmd, "value"); - after_cnt_cmd_value.set_inner(options.afterConnectionCommand.value()); + after_cnt_cmd_value.set_inner(options.col()); } if (Config::get("realname_customization", "true") == "true") @@ -281,20 +279,20 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com username["var"] = "username"; username["type"] = "text-single"; username["label"] = "Username"; - if (!options.username.value().empty()) + if (!options.col().empty()) { XmlSubNode username_value(username, "value"); - username_value.set_inner(options.username.value()); + username_value.set_inner(options.col()); } XmlSubNode realname(x, "field"); realname["var"] = "realname"; realname["type"] = "text-single"; realname["label"] = "Realname"; - if (!options.realname.value().empty()) + if (!options.col().empty()) { XmlSubNode realname_value(realname, "value"); - realname_value.set_inner(options.realname.value()); + realname_value.set_inner(options.col()); } } @@ -303,10 +301,10 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com encoding_out["type"] = "text-single"; encoding_out["desc"] = "The encoding used when sending messages to the IRC server."; encoding_out["label"] = "Out encoding"; - if (!options.encodingOut.value().empty()) + if (!options.col().empty()) { XmlSubNode encoding_out_value(encoding_out, "value"); - encoding_out_value.set_inner(options.encodingOut.value()); + encoding_out_value.set_inner(options.col()); } XmlSubNode encoding_in(x, "field"); @@ -314,10 +312,10 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com encoding_in["type"] = "text-single"; encoding_in["desc"] = "The encoding used to decode message received from the IRC server."; encoding_in["label"] = "In encoding"; - if (!options.encodingIn.value().empty()) + if (!options.col().empty()) { XmlSubNode encoding_in_value(encoding_in, "value"); - encoding_in_value.set_inner(options.encodingIn.value()); + encoding_in_value.set_inner(options.col()); } } @@ -342,7 +340,7 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com std::string ports; for (const auto& val: values) ports += val->get_inner() + ";"; - options.ports = ports; + options.col() = ports; } #ifdef BOTAN_FOUND @@ -351,31 +349,31 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com std::string ports; for (const auto& val: values) ports += val->get_inner() + ";"; - options.tlsPorts = ports; + options.col() = ports; } else if (field->get_tag("var") == "verify_cert" && value && !value->get_inner().empty()) { auto val = to_bool(value->get_inner()); - options.verifyCert = val; + options.col() = val; } else if (field->get_tag("var") == "fingerprint" && value && !value->get_inner().empty()) { - options.trustedFingerprint = value->get_inner(); + options.col() = value->get_inner(); } #endif // BOTAN_FOUND else if (field->get_tag("var") == "pass" && value && !value->get_inner().empty()) - options.pass = value->get_inner(); + options.col() = value->get_inner(); else if (field->get_tag("var") == "after_connect_command" && value && !value->get_inner().empty()) - options.afterConnectionCommand = value->get_inner(); + options.col() = value->get_inner(); else if (field->get_tag("var") == "username" && value && !value->get_inner().empty()) @@ -383,24 +381,24 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com auto username = value->get_inner(); // The username must not contain spaces std::replace(username.begin(), username.end(), ' ', '_'); - options.username = username; + options.col() = username; } else if (field->get_tag("var") == "realname" && value && !value->get_inner().empty()) - options.realname = value->get_inner(); + options.col() = value->get_inner(); else if (field->get_tag("var") == "encoding_out" && value && !value->get_inner().empty()) - options.encodingOut = value->get_inner(); + options.col() = value->get_inner(); else if (field->get_tag("var") == "encoding_in" && value && !value->get_inner().empty()) - options.encodingIn = value->get_inner(); + options.col() = value->get_inner(); } - options.update(); + options.save(Database::db); command_node.delete_all_children(); XmlSubNode note(command_node, "note"); @@ -441,10 +439,10 @@ void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester, encoding_out["type"] = "text-single"; encoding_out["desc"] = "The encoding used when sending messages to the IRC server. Defaults to the server's “out encoding” if unset for the channel"; encoding_out["label"] = "Out encoding"; - if (!options.encodingOut.value().empty()) + if (!options.col().empty()) { XmlSubNode encoding_out_value(encoding_out, "value"); - encoding_out_value.set_inner(options.encodingOut.value()); + encoding_out_value.set_inner(options.col()); } XmlSubNode encoding_in(x, "field"); @@ -452,10 +450,10 @@ void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester, encoding_in["type"] = "text-single"; encoding_in["desc"] = "The encoding used to decode message received from the IRC server. Defaults to the server's “in encoding” if unset for the channel"; encoding_in["label"] = "In encoding"; - if (!options.encodingIn.value().empty()) + if (!options.col().empty()) { XmlSubNode encoding_in_value(encoding_in, "value"); - encoding_in_value.set_inner(options.encodingIn.value()); + encoding_in_value.set_inner(options.col()); } XmlSubNode persistent(x, "field"); @@ -466,7 +464,7 @@ void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester, { XmlSubNode value(persistent, "value"); value.set_name("value"); - if (options.persistent.value()) + if (options.col()) value.set_inner("true"); else value.set_inner("false"); @@ -510,18 +508,18 @@ bool handle_irc_channel_configuration_form(const XmlNode& node, const Jid& reque if (field->get_tag("var") == "encoding_out" && value && !value->get_inner().empty()) - options.encodingOut = value->get_inner(); + options.col() = value->get_inner(); else if (field->get_tag("var") == "encoding_in" && value && !value->get_inner().empty()) - options.encodingIn = value->get_inner(); + options.col() = value->get_inner(); else if (field->get_tag("var") == "persistent" && value) - options.persistent = to_bool(value->get_inner()); + options.col() = to_bool(value->get_inner()); } - options.update(); + options.save(Database::db); } return true; } -- cgit v1.2.3 From e75d7ad8ea72044fdfd2317e03f91ba5bea06b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 16 Jun 2017 10:48:54 +0200 Subject: Add a Record History option in the Channel configuration form fix #3269 --- src/xmpp/biboumi_adhoc_commands.cpp | 53 ++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) (limited to 'src/xmpp/biboumi_adhoc_commands.cpp') diff --git a/src/xmpp/biboumi_adhoc_commands.cpp b/src/xmpp/biboumi_adhoc_commands.cpp index a13dbb8..ad4faf8 100644 --- a/src/xmpp/biboumi_adhoc_commands.cpp +++ b/src/xmpp/biboumi_adhoc_commands.cpp @@ -434,6 +434,26 @@ void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester, XmlSubNode instructions(x, "instructions"); instructions.set_inner("Edit the form, to configure the settings of the IRC channel "s + iid.get_local()); + XmlSubNode record_history(x, "field"); + record_history["var"] = "record_history"; + record_history["type"] = "list-single"; + record_history["label"] = "Record history for this channel"; + record_history["desc"] = "If unset, the value is the one configured globally"; + + { + // Value selected by default + XmlSubNode value(record_history, "value"); + value.set_inner(options.col().to_string()); + } + // All three possible values + for (const auto& val: {"unset", "true", "false"}) + { + XmlSubNode option(record_history, "option"); + option["label"] = val; + XmlSubNode value(option, "value"); + value.set_inner(val); + } + XmlSubNode encoding_out(x, "field"); encoding_out["var"] = "encoding_out"; encoding_out["type"] = "text-single"; @@ -471,12 +491,12 @@ void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester, } } -void ConfigureIrcChannelStep2(XmppComponent&, AdhocSession& session, XmlNode& command_node) +void ConfigureIrcChannelStep2(XmppComponent& xmpp_component, AdhocSession& session, XmlNode& command_node) { const Jid owner(session.get_owner_jid()); const Jid target(session.get_target_jid()); - if (handle_irc_channel_configuration_form(command_node, owner, target)) + if (handle_irc_channel_configuration_form(xmpp_component, command_node, owner, target)) { command_node.delete_all_children(); XmlSubNode note(command_node, "note"); @@ -492,7 +512,7 @@ void ConfigureIrcChannelStep2(XmppComponent&, AdhocSession& session, XmlNode& co } } -bool handle_irc_channel_configuration_form(const XmlNode& node, const Jid& requester, const Jid& target) +bool handle_irc_channel_configuration_form(XmppComponent& xmpp_component, const XmlNode& node, const Jid& requester, const Jid& target) { const XmlNode* x = node.get_child("x", "jabber:x:data"); if (x) @@ -500,7 +520,7 @@ bool handle_irc_channel_configuration_form(const XmlNode& node, const Jid& reque if (x->get_tag("type") == "submit") { const Iid iid(target.local, {}); - auto options = Database::get_irc_channel_options(requester.local + "@" + requester.domain, + auto options = Database::get_irc_channel_options(requester.bare(), iid.get_server(), iid.get_local()); for (const XmlNode *field: x->get_children("field", "jabber:x:data")) { @@ -517,6 +537,31 @@ bool handle_irc_channel_configuration_form(const XmlNode& node, const Jid& reque else if (field->get_tag("var") == "persistent" && value) options.col() = to_bool(value->get_inner()); + else if (field->get_tag("var") == "record_history" && + value && !value->get_inner().empty()) + { + OptionalBool& database_value = options.col(); + if (value->get_inner() == "true") + database_value.set_value(true); + else if (value->get_inner() == "false") + database_value.set_value(false); + else + database_value.unset(); + auto& biboumi_component = dynamic_cast(xmpp_component); + Bridge* bridge = biboumi_component.find_user_bridge(requester.bare()); + if (bridge) + { + if (database_value.is_set) + bridge->set_record_history(database_value.value); + else + { // It is unset, we need to fetch the Global option, to + // know if it’s enabled or not + auto g_options = Database::get_global_options(requester.bare()); + bridge->set_record_history(g_options.col()); + } + } + } + } options.save(Database::db); -- cgit v1.2.3