diff options
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/biboumi_adhoc_commands.cpp | 141 | ||||
-rw-r--r-- | src/xmpp/biboumi_adhoc_commands.hpp | 2 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.cpp | 18 | ||||
-rw-r--r-- | src/xmpp/biboumi_component.hpp | 4 |
4 files changed, 103 insertions, 62 deletions
diff --git a/src/xmpp/biboumi_adhoc_commands.cpp b/src/xmpp/biboumi_adhoc_commands.cpp index ab28cfd..ad4faf8 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<Database::MaxHistoryLength>())); } 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<Database::RecordHistory>()) 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<Database::MaxHistoryLength>() = 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<Database::RecordHistory>() = 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<Database::RecordHistory>()); } } - 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<Database::Ports>(), ';', 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<Database::TlsPorts>(), ';', 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<Database::VerifyCert>()) 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<Database::TrustedFingerprint>().empty()) { XmlSubNode fingerprint_value(fingerprint, "value"); - fingerprint_value.set_inner(options.trustedFingerprint.value()); + fingerprint_value.set_inner(options.col<Database::TrustedFingerprint>()); } #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<Database::Pass>().empty()) { XmlSubNode pass_value(pass, "value"); - pass_value.set_inner(options.pass.value()); + pass_value.set_inner(options.col<Database::Pass>()); } 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<Database::AfterConnectionCommand>().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<Database::AfterConnectionCommand>()); } 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<Database::Username>().empty()) { XmlSubNode username_value(username, "value"); - username_value.set_inner(options.username.value()); + username_value.set_inner(options.col<Database::Username>()); } XmlSubNode realname(x, "field"); realname["var"] = "realname"; realname["type"] = "text-single"; realname["label"] = "Realname"; - if (!options.realname.value().empty()) + if (!options.col<Database::Realname>().empty()) { XmlSubNode realname_value(realname, "value"); - realname_value.set_inner(options.realname.value()); + realname_value.set_inner(options.col<Database::Realname>()); } } @@ -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<Database::EncodingOut>().empty()) { XmlSubNode encoding_out_value(encoding_out, "value"); - encoding_out_value.set_inner(options.encodingOut.value()); + encoding_out_value.set_inner(options.col<Database::EncodingOut>()); } 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<Database::EncodingIn>().empty()) { XmlSubNode encoding_in_value(encoding_in, "value"); - encoding_in_value.set_inner(options.encodingIn.value()); + encoding_in_value.set_inner(options.col<Database::EncodingIn>()); } } @@ -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<Database::Ports>() = 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<Database::TlsPorts>() = 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<Database::VerifyCert>() = val; } else if (field->get_tag("var") == "fingerprint" && value && !value->get_inner().empty()) { - options.trustedFingerprint = value->get_inner(); + options.col<Database::TrustedFingerprint>() = 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<Database::Pass>() = value->get_inner(); else if (field->get_tag("var") == "after_connect_command" && value && !value->get_inner().empty()) - options.afterConnectionCommand = value->get_inner(); + options.col<Database::AfterConnectionCommand>() = 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<Database::Username>() = username; } else if (field->get_tag("var") == "realname" && value && !value->get_inner().empty()) - options.realname = value->get_inner(); + options.col<Database::Realname>() = value->get_inner(); else if (field->get_tag("var") == "encoding_out" && value && !value->get_inner().empty()) - options.encodingOut = value->get_inner(); + options.col<Database::EncodingOut>() = value->get_inner(); else if (field->get_tag("var") == "encoding_in" && value && !value->get_inner().empty()) - options.encodingIn = value->get_inner(); + options.col<Database::EncodingIn>() = value->get_inner(); } - options.update(); + options.save(Database::db); command_node.delete_all_children(); XmlSubNode note(command_node, "note"); @@ -436,15 +434,35 @@ 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<Database::RecordHistoryOptional>().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"; 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<Database::EncodingOut>().empty()) { XmlSubNode encoding_out_value(encoding_out, "value"); - encoding_out_value.set_inner(options.encodingOut.value()); + encoding_out_value.set_inner(options.col<Database::EncodingOut>()); } XmlSubNode encoding_in(x, "field"); @@ -452,10 +470,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<Database::EncodingIn>().empty()) { XmlSubNode encoding_in_value(encoding_in, "value"); - encoding_in_value.set_inner(options.encodingIn.value()); + encoding_in_value.set_inner(options.col<Database::EncodingIn>()); } XmlSubNode persistent(x, "field"); @@ -466,19 +484,19 @@ 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<Database::Persistent>()) value.set_inner("true"); else value.set_inner("false"); } } -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"); @@ -494,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) @@ -502,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")) { @@ -510,18 +528,43 @@ 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<Database::EncodingOut>() = value->get_inner(); else if (field->get_tag("var") == "encoding_in" && value && !value->get_inner().empty()) - options.encodingIn = value->get_inner(); + options.col<Database::EncodingIn>() = value->get_inner(); else if (field->get_tag("var") == "persistent" && value) - options.persistent = to_bool(value->get_inner()); + options.col<Database::Persistent>() = to_bool(value->get_inner()); + else if (field->get_tag("var") == "record_history" && + value && !value->get_inner().empty()) + { + OptionalBool& database_value = options.col<Database::RecordHistoryOptional>(); + 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<BiboumiComponent&>(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<Database::RecordHistory>()); + } + } + } + } - options.update(); + options.save(Database::db); } return true; } diff --git a/src/xmpp/biboumi_adhoc_commands.hpp b/src/xmpp/biboumi_adhoc_commands.hpp index 7d29cc2..cb6acb9 100644 --- a/src/xmpp/biboumi_adhoc_commands.hpp +++ b/src/xmpp/biboumi_adhoc_commands.hpp @@ -20,7 +20,7 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com void ConfigureIrcChannelStep1(XmppComponent&, AdhocSession& session, XmlNode& command_node); void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester, const Jid& target); void ConfigureIrcChannelStep2(XmppComponent&, AdhocSession& session, XmlNode& command_node); -bool handle_irc_channel_configuration_form(const XmlNode& node, const Jid& requester, const Jid& target); +bool handle_irc_channel_configuration_form(XmppComponent&, const XmlNode& node, const Jid& requester, const Jid& target); void DisconnectUserFromServerStep1(XmppComponent&, AdhocSession& session, XmlNode& command_node); void DisconnectUserFromServerStep2(XmppComponent&, AdhocSession& session, XmlNode& command_node); diff --git a/src/xmpp/biboumi_component.cpp b/src/xmpp/biboumi_component.cpp index ca3a887..32f3968 100644 --- a/src/xmpp/biboumi_component.cpp +++ b/src/xmpp/biboumi_component.cpp @@ -18,8 +18,6 @@ #include <biboumi.h> -#include <uuid/uuid.h> - #ifdef SYSTEMD_FOUND # include <systemd/sd-daemon.h> #endif @@ -648,9 +646,9 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) limit = 100; } const auto lines = Database::get_muc_logs(from.bare(), iid.get_local(), iid.get_server(), limit, start, end); - for (const db::MucLogLine& line: lines) + for (const Database::MucLogLine& line: lines) { - if (!line.nick.value().empty()) + if (!line.col<Database::Nick>().empty()) this->send_archived_message(line, to.full(), from.full(), query_id); } this->send_iq_result_full_jid(id, from.full(), to.full()); @@ -659,7 +657,7 @@ bool BiboumiComponent::handle_mam_request(const Stanza& stanza) return false; } -void BiboumiComponent::send_archived_message(const db::MucLogLine& log_line, const std::string& from, const std::string& to, +void BiboumiComponent::send_archived_message(const Database::MucLogLine& log_line, const std::string& from, const std::string& to, const std::string& queryid) { Stanza message("message"); @@ -671,22 +669,22 @@ void BiboumiComponent::send_archived_message(const db::MucLogLine& log_line, con result["xmlns"] = MAM_NS; if (!queryid.empty()) result["queryid"] = queryid; - result["id"] = log_line.uuid.value(); + result["id"] = log_line.col<Database::Uuid>(); XmlSubNode forwarded(result, "forwarded"); forwarded["xmlns"] = FORWARD_NS; XmlSubNode delay(forwarded, "delay"); delay["xmlns"] = DELAY_NS; - delay["stamp"] = utils::to_string(log_line.date.value().timeStamp()); + delay["stamp"] = utils::to_string(log_line.col<Database::Date>()); XmlSubNode submessage(forwarded, "message"); submessage["xmlns"] = CLIENT_NS; - submessage["from"] = from + "/" + log_line.nick.value(); + submessage["from"] = from + "/" + log_line.col<Database::Nick>(); submessage["type"] = "groupchat"; XmlSubNode body(submessage, "body"); - body.set_inner(log_line.body.value()); + body.set_inner(log_line.col<Database::Body>()); } this->send_stanza(message); } @@ -721,7 +719,7 @@ bool BiboumiComponent::handle_room_configuration_form(const XmlNode& query, cons return false; Jid requester(from); - if (!handle_irc_channel_configuration_form(query, requester, to)) + if (!handle_irc_channel_configuration_form(*this, query, requester, to)) return false; Stanza iq("iq"); diff --git a/src/xmpp/biboumi_component.hpp b/src/xmpp/biboumi_component.hpp index ac9bde4..87311f9 100644 --- a/src/xmpp/biboumi_component.hpp +++ b/src/xmpp/biboumi_component.hpp @@ -1,6 +1,6 @@ #pragma once - +#include <database/database.hpp> #include <xmpp/xmpp_component.hpp> #include <xmpp/jid.hpp> @@ -96,7 +96,7 @@ public: #ifdef USE_DATABASE bool handle_mam_request(const Stanza& stanza); - void send_archived_message(const db::MucLogLine& log_line, const std::string& from, const std::string& to, + void send_archived_message(const Database::MucLogLine& log_line, const std::string& from, const std::string& to, const std::string& queryid); bool handle_room_configuration_form_request(const std::string& from, const Jid& to, const std::string& id); bool handle_room_configuration_form(const XmlNode& query, const std::string& from, const Jid& to, const std::string& id); |