summaryrefslogtreecommitdiff
path: root/src/xmpp/biboumi_adhoc_commands.cpp
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2016-08-22 00:38:44 +0200
committerlouiz’ <louiz@louiz.org>2016-08-22 00:38:44 +0200
commit6776b827d243ec0e018eac8233c5df402030640e (patch)
tree261c35a77dacc928270601ac56424cab82de5b59 /src/xmpp/biboumi_adhoc_commands.cpp
parent992fa938951558f4515145c9b82af0123c979a29 (diff)
downloadbiboumi-6776b827d243ec0e018eac8233c5df402030640e.tar.gz
biboumi-6776b827d243ec0e018eac8233c5df402030640e.tar.bz2
biboumi-6776b827d243ec0e018eac8233c5df402030640e.tar.xz
biboumi-6776b827d243ec0e018eac8233c5df402030640e.zip
Add a global configure ad-hoc command, with max history length
Diffstat (limited to 'src/xmpp/biboumi_adhoc_commands.cpp')
-rw-r--r--src/xmpp/biboumi_adhoc_commands.cpp74
1 files changed, 68 insertions, 6 deletions
diff --git a/src/xmpp/biboumi_adhoc_commands.cpp b/src/xmpp/biboumi_adhoc_commands.cpp
index b14081f..2050edf 100644
--- a/src/xmpp/biboumi_adhoc_commands.cpp
+++ b/src/xmpp/biboumi_adhoc_commands.cpp
@@ -11,10 +11,6 @@
#include <database/database.hpp>
#endif
-#include <louloulibs.h>
-
-#include <algorithm>
-
using namespace std::string_literals;
void DisconnectUserStep1(XmppComponent& xmpp_component, AdhocSession&, XmlNode& command_node)
@@ -114,6 +110,72 @@ void DisconnectUserStep2(XmppComponent& xmpp_component, AdhocSession& session, X
}
#ifdef USE_DATABASE
+
+void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& command_node)
+{
+ const Jid owner(session.get_owner_jid());
+ const Jid target(session.get_target_jid());
+
+ auto options = Database::get_global_options(owner.bare());
+
+ XmlNode x("jabber:x:data:x");
+ x["type"] = "form";
+ XmlNode title("title");
+ title.set_inner("Configure some global default settings.");
+ x.add_child(std::move(title));
+ XmlNode instructions("instructions");
+ instructions.set_inner("Edit the form, to configure your global settings for the component.");
+ x.add_child(std::move(instructions));
+
+ XmlNode required("required");
+
+ XmlNode max_histo_length("field");
+ max_histo_length["var"] = "max_history_length";
+ max_histo_length["type"] = "text-single";
+ max_histo_length["label"] = "Max history length";
+ max_histo_length["desc"] = "The maximum number of lines in the history that the server sends when joining a channel";
+
+ XmlNode max_histo_length_value("value");
+ max_histo_length_value.set_inner(std::to_string(options.maxHistoryLength.value()));
+ max_histo_length.add_child(std::move(max_histo_length_value));
+ x.add_child(std::move(max_histo_length));
+
+ command_node.add_child(std::move(x));
+}
+
+void ConfigureGlobalStep2(XmppComponent&, AdhocSession& session, XmlNode& command_node)
+{
+ const XmlNode* x = command_node.get_child("x", "jabber:x:data");
+ if (x)
+ {
+ const Jid owner(session.get_owner_jid());
+ auto options = Database::get_global_options(owner.bare());
+ for (const XmlNode* field: x->get_children("field", "jabber:x:data"))
+ {
+ const XmlNode* value = field->get_child("value", "jabber:x:data");
+
+ if (field->get_tag("var") == "max_history_length" &&
+ value && !value->get_inner().empty())
+ options.maxHistoryLength = value->get_inner();
+ }
+
+ options.update();
+
+ command_node.delete_all_children();
+ XmlNode note("note");
+ note["type"] = "info";
+ note.set_inner("Configuration successfully applied.");
+ command_node.add_child(std::move(note));
+ return;
+ }
+ XmlNode error(ADHOC_NS":error");
+ error["type"] = "modify";
+ XmlNode condition(STANZA_NS":bad-request");
+ error.add_child(std::move(condition));
+ command_node.add_child(std::move(error));
+ session.terminate();
+}
+
void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& command_node)
{
const Jid owner(session.get_owner_jid());
@@ -315,7 +377,7 @@ void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& com
}
else if (field->get_tag("var") == "verify_cert" && value
- && !value->get_inner().empty())
+ && !value->get_inner().empty())
{
auto val = to_bool(value->get_inner());
options.verifyCert = val;
@@ -442,7 +504,7 @@ void ConfigureIrcChannelStep2(XmppComponent&, AdhocSession& session, XmlNode& co
const XmlNode* value = field->get_child("value", "jabber:x:data");
if (field->get_tag("var") == "encoding_out" &&
- value && !value->get_inner().empty())
+ value && !value->get_inner().empty())
options.encodingOut = value->get_inner();
else if (field->get_tag("var") == "encoding_in" &&