~singpolyma/biboumi

43b5b696a311e1dbaa2623284eed042b4ca24dc5 — louiz’ 6 years ago 9f7782b
Add some scopes around various XmlSubNode
1 files changed, 196 insertions(+), 168 deletions(-)

M src/xmpp/biboumi_adhoc_commands.cpp
M src/xmpp/biboumi_adhoc_commands.cpp => src/xmpp/biboumi_adhoc_commands.cpp +196 -168
@@ 122,45 122,48 @@ void ConfigureGlobalStep1(XmppComponent&, AdhocSession& session, XmlNode& comman
  XmlSubNode instructions(x, "instructions");
  instructions.set_inner("Edit the form, to configure your global settings for the component.");

  XmlSubNode max_histo_length(x, "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";

  {
    XmlSubNode value(max_histo_length, "value");
    value.set_inner(std::to_string(options.col<Database::MaxHistoryLength>()));
    XmlSubNode max_histo_length(x, "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";
    {
      XmlSubNode value(max_histo_length, "value");
      value.set_inner(std::to_string(options.col<Database::MaxHistoryLength>()));
    }
  }

  XmlSubNode record_history(x, "field");
  record_history["var"] = "record_history";
  record_history["type"] = "boolean";
  record_history["label"] = "Record history";
  record_history["desc"] = "Whether to save the messages into the database, or not";

  {
    XmlSubNode value(record_history, "value");
    value.set_name("value");
    if (options.col<Database::RecordHistory>())
      value.set_inner("true");
    else
      value.set_inner("false");
    XmlSubNode record_history(x, "field");
    record_history["var"] = "record_history";
    record_history["type"] = "boolean";
    record_history["label"] = "Record history";
    record_history["desc"] = "Whether to save the messages into the database, or not";
    {
      XmlSubNode value(record_history, "value");
      value.set_name("value");
      if (options.col<Database::RecordHistory>())
        value.set_inner("true");
      else
        value.set_inner("false");
    }
  }

  XmlSubNode persistent(x, "field");
  persistent["var"] = "persistent";
  persistent["type"] = "boolean";
  persistent["label"] = "Make all channels persistent";
  persistent["desc"] = "If true, all channels will be persistent";

  {
    XmlSubNode value(persistent, "value");
    value.set_name("value");
    if (options.col<Database::Persistent>())
      value.set_inner("true");
    else
      value.set_inner("false");
    XmlSubNode persistent(x, "field");
    persistent["var"] = "persistent";
    persistent["type"] = "boolean";
    persistent["label"] = "Make all channels persistent";
    persistent["desc"] = "If true, all channels will be persistent";
    {
      XmlSubNode value(persistent, "value");
      value.set_name("value");
      if (options.col<Database::Persistent>())
        value.set_inner("true");
      else
        value.set_inner("false");
    }
  }
}



@@ 224,96 227,112 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com
  XmlSubNode instructions(x, "instructions");
  instructions.set_inner("Edit the form, to configure the settings of the IRC server "s + server_domain);

  XmlSubNode ports(x, "field");
  ports["var"] = "ports";
  ports["type"] = "text-multi";
  ports["label"] = "Ports";
  ports["desc"] = "List of ports to try, without TLS. Defaults: 6667.";
  for (const auto& val: utils::split(options.col<Database::Ports>(), ';', false))
    {
      XmlSubNode ports_value(ports, "value");
      ports_value.set_inner(val);
    }
  {
    XmlSubNode ports(x, "field");
    ports["var"] = "ports";
    ports["type"] = "text-multi";
    ports["label"] = "Ports";
    ports["desc"] = "List of ports to try, without TLS. Defaults: 6667.";
    for (const auto& val: utils::split(options.col<Database::Ports>(), ';', false))
      {
        XmlSubNode ports_value(ports, "value");
        ports_value.set_inner(val);
      }
  }

#ifdef BOTAN_FOUND
  XmlSubNode tls_ports(x, "field");
  tls_ports["var"] = "tls_ports";
  tls_ports["type"] = "text-multi";
  tls_ports["label"] = "TLS ports";
  tls_ports["desc"] = "List of ports to try, with TLS. Defaults: 6697, 6670.";
  for (const auto& val: utils::split(options.col<Database::TlsPorts>(), ';', false))
    {
      XmlSubNode tls_ports_value(tls_ports, "value");
      tls_ports_value.set_inner(val);
    }
  {
    XmlSubNode tls_ports(x, "field");
    tls_ports["var"] = "tls_ports";
    tls_ports["type"] = "text-multi";
    tls_ports["label"] = "TLS ports";
    tls_ports["desc"] = "List of ports to try, with TLS. Defaults: 6697, 6670.";
    for (const auto& val: utils::split(options.col<Database::TlsPorts>(), ';', false))
      {
        XmlSubNode tls_ports_value(tls_ports, "value");
        tls_ports_value.set_inner(val);
      }
  }

  XmlSubNode verify_cert(x, "field");
  verify_cert["var"] = "verify_cert";
  verify_cert["type"] = "boolean";
  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.col<Database::VerifyCert>())
    verify_cert_value.set_inner("true");
  else
    verify_cert_value.set_inner("false");
  {
    XmlSubNode verify_cert(x, "field");
    verify_cert["var"] = "verify_cert";
    verify_cert["type"] = "boolean";
    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.col<Database::VerifyCert>())
      verify_cert_value.set_inner("true");
    else
      verify_cert_value.set_inner("false");
  }

  XmlSubNode fingerprint(x, "field");
  fingerprint["var"] = "fingerprint";
  fingerprint["type"] = "text-single";
  fingerprint["label"] = "SHA-1 fingerprint of the TLS certificate to trust.";
  if (!options.col<Database::TrustedFingerprint>().empty())
    {
      XmlSubNode fingerprint_value(fingerprint, "value");
      fingerprint_value.set_inner(options.col<Database::TrustedFingerprint>());
    }
  {
    XmlSubNode fingerprint(x, "field");
    fingerprint["var"] = "fingerprint";
    fingerprint["type"] = "text-single";
    fingerprint["label"] = "SHA-1 fingerprint of the TLS certificate to trust.";
    if (!options.col<Database::TrustedFingerprint>().empty())
      {
        XmlSubNode fingerprint_value(fingerprint, "value");
        fingerprint_value.set_inner(options.col<Database::TrustedFingerprint>());
      }
  }
#endif
  {
    XmlSubNode pass(x, "field");
    pass["var"] = "pass";
    pass["type"] = "text-private";
    pass["label"] = "Server password";
    pass["desc"] = "Will be used in a PASS command when connecting";
    if (!options.col<Database::Pass>().empty())
      {
        XmlSubNode pass_value(pass, "value");
        pass_value.set_inner(options.col<Database::Pass>());
      }
  }

  XmlSubNode pass(x, "field");
  pass["var"] = "pass";
  pass["type"] = "text-private";
  pass["label"] = "Server password";
  pass["desc"] = "Will be used in a PASS command when connecting";
  if (!options.col<Database::Pass>().empty())
    {
      XmlSubNode pass_value(pass, "value");
      pass_value.set_inner(options.col<Database::Pass>());
    }

  XmlSubNode after_cnt_cmd(x, "field");
  after_cnt_cmd["var"] = "after_connect_command";
  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.col<Database::AfterConnectionCommand>().empty())
    {
      XmlSubNode after_cnt_cmd_value(after_cnt_cmd, "value");
      after_cnt_cmd_value.set_inner(options.col<Database::AfterConnectionCommand>());
    }
  {
    XmlSubNode after_cnt_cmd(x, "field");
    after_cnt_cmd["var"] = "after_connect_command";
    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.col<Database::AfterConnectionCommand>().empty())
      {
        XmlSubNode after_cnt_cmd_value(after_cnt_cmd, "value");
        after_cnt_cmd_value.set_inner(options.col<Database::AfterConnectionCommand>());
      }
  }

  if (Config::get("realname_customization", "true") == "true")
    {
      XmlSubNode username(x, "field");
      username["var"] = "username";
      username["type"] = "text-single";
      username["label"] = "Username";
      if (!options.col<Database::Username>().empty())
        {
          XmlSubNode username_value(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.col<Database::Realname>().empty())
        {
          XmlSubNode realname_value(realname, "value");
          realname_value.set_inner(options.col<Database::Realname>());
        }
      {
        XmlSubNode username(x, "field");
        username["var"] = "username";
        username["type"] = "text-single";
        username["label"] = "Username";
        if (!options.col<Database::Username>().empty())
          {
            XmlSubNode username_value(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.col<Database::Realname>().empty())
          {
            XmlSubNode realname_value(realname, "value");
            realname_value.set_inner(options.col<Database::Realname>());
          }
      }
    }

  {
  XmlSubNode encoding_out(x, "field");
  encoding_out["var"] = "encoding_out";
  encoding_out["type"] = "text-single";


@@ 324,17 343,20 @@ void ConfigureIrcServerStep1(XmppComponent&, AdhocSession& session, XmlNode& com
      XmlSubNode encoding_out_value(encoding_out, "value");
      encoding_out_value.set_inner(options.col<Database::EncodingOut>());
    }
  }

  XmlSubNode encoding_in(x, "field");
  encoding_in["var"] = "encoding_in";
  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.col<Database::EncodingIn>().empty())
    {
      XmlSubNode encoding_in_value(encoding_in, "value");
      encoding_in_value.set_inner(options.col<Database::EncodingIn>());
    }
  {
    XmlSubNode encoding_in(x, "field");
    encoding_in["var"] = "encoding_in";
    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.col<Database::EncodingIn>().empty())
      {
        XmlSubNode encoding_in_value(encoding_in, "value");
        encoding_in_value.set_inner(options.col<Database::EncodingIn>());
      }
  }
}

void ConfigureIrcServerStep2(XmppComponent&, AdhocSession& session, XmlNode& command_node)


@@ 444,7 466,6 @@ void insert_irc_channel_configuration_form(XmlNode& node, const Jid& requester, 

  auto options = Database::get_irc_channel_options_with_server_default(requester.local + "@" + requester.domain,
                                                                       iid.get_server(), iid.get_local());

  XmlSubNode x(node, "jabber:x:data:x");
  x["type"] = "form";
  XmlSubNode title(x, "title");


@@ 452,60 473,67 @@ 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());
    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);
      }
  }
  // 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.col<Database::EncodingOut>().empty())
      {
        XmlSubNode encoding_out_value(encoding_out, "value");
        encoding_out_value.set_inner(options.col<Database::EncodingOut>());
      }
  }

  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.col<Database::EncodingOut>().empty())
    {
      XmlSubNode encoding_out_value(encoding_out, "value");
      encoding_out_value.set_inner(options.col<Database::EncodingOut>());
    }
  {
    XmlSubNode encoding_in(x, "field");
    encoding_in["var"] = "encoding_in";
    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.col<Database::EncodingIn>().empty())
      {
        XmlSubNode encoding_in_value(encoding_in, "value");
        encoding_in_value.set_inner(options.col<Database::EncodingIn>());
      }
  }

  XmlSubNode encoding_in(x, "field");
  encoding_in["var"] = "encoding_in";
  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.col<Database::EncodingIn>().empty())
  {
    XmlSubNode persistent(x, "field");
    persistent["var"] = "persistent";
    persistent["type"] = "boolean";
    persistent["desc"] = "If set to true, when all XMPP clients have left this channel, biboumi will stay idle in it, without sending a PART command.";
    persistent["label"] = "Persistent";
    {
      XmlSubNode encoding_in_value(encoding_in, "value");
      encoding_in_value.set_inner(options.col<Database::EncodingIn>());
      XmlSubNode value(persistent, "value");
      value.set_name("value");
      if (options.col<Database::Persistent>())
        value.set_inner("true");
      else
        value.set_inner("false");
    }

  XmlSubNode persistent(x, "field");
  persistent["var"] = "persistent";
  persistent["type"] = "boolean";
  persistent["desc"] = "If set to true, when all XMPP clients have left this channel, biboumi will stay idle in it, without sending a PART command.";
  persistent["label"] = "Persistent";
  {
    XmlSubNode value(persistent, "value");
    value.set_name("value");
    if (options.col<Database::Persistent>())
      value.set_inner("true");
    else
      value.set_inner("false");
  }
}