~singpolyma/biboumi

f904d57940699e332f75a77062912431c6e51188 — Florent Le Coz 7 years ago f6d9b7d
Provide username and realname IRC server options

Used in the USER command when connecting to the IRC server, instead of the
first nick.

fix #3028
4 files changed, 62 insertions(+), 1 deletions(-)

M CMakeLists.txt
M database/database.xml
M src/irc/irc_client.cpp
M src/xmpp/biboumi_adhoc_commands.cpp
M CMakeLists.txt => CMakeLists.txt +16 -1
@@ 43,7 43,8 @@ endif()
set(SOFTWARE_VERSION
  ${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}${${PROJECT_NAME}_VERSION_SUFFIX})

# To be able to include the config.h file generated by cmake
include(CheckFunctionExists)
check_function_exists(ppoll HAVE_PPOLL_FUNCTION)

# To be able to include the config.h and other files generated by cmake
include_directories("${CMAKE_CURRENT_BINARY_DIR}/src/")


@@ 121,6 122,7 @@ target_link_libraries(xmpp xmpplib bridge network utils logger)
if(USE_DATABASE)
  target_link_libraries(xmpp database)
endif()

#
## bridge
#


@@ 181,4 183,17 @@ add_custom_target(dist
  | xz > ${CMAKE_CURRENT_BINARY_DIR}/${ARCHIVE_NAME}.tar.xz
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})

if(BOTAN_FOUND)
  set(STR_WITH_BOTAN "Botan: yes")
else()
  set(STR_WITH_BOTAN "Botan: no")
endif()
if(CARES_FOUND)
  set(STR_WITH_CARES "c-ares: yes")
else()
  set(STR_WITH_CARES "c-ares: no")
endif()
add_custom_target(PrintBuildParameters ALL
  ${CMAKE_COMMAND} -E cmake_echo_color --cyan "Compiling ${PROJECT_NAME} with ${STR_WITH_BOTAN}, ${STR_WITH_CARES}")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/biboumi.h.cmake ${CMAKE_BINARY_DIR}/src/biboumi.h)
\ No newline at end of file

M database/database.xml => database/database.xml +2 -0
@@ 10,6 10,8 @@
    <field name="afterConnectionCommand" type="string" length="510" default=""/>
    <field name="tlsPorts" type="string" length="4096" default="6697;6670" />
    <field name="ports" type="string" length="4096" default="6667" />
    <field name="username" type="string" length="1024" default=""/>
    <field name="realname" type="string" length="1024" default=""/>

    <index unique="true">
      <indexfield name="owner"/>

M src/irc/irc_client.cpp => src/irc/irc_client.cpp +10 -0
@@ 116,7 116,17 @@ void IrcClient::on_connected()
    this->send_pass_command(options.pass.value());
#endif
  this->send_nick_command(this->username);
#ifdef USE_DATABASE
  std::string username = this->username;
  if (!options.username.value().empty())
    username = options.username.value();
  std::string realname = this->username;
  if (!options.realname.value().empty())
    realname = options.realname.value();
  this->send_user_command(username, realname);
#else
  this->send_user_command(this->username, this->username);
#endif // USE_DATABASE
  this->send_gateway_message("Connected to IRC server"s + (this->use_tls ? " (encrypted)": "") + ".");
  this->send_pending_data();
}

M src/xmpp/biboumi_adhoc_commands.cpp => src/xmpp/biboumi_adhoc_commands.cpp +34 -0
@@ 189,6 189,32 @@ void ConfigureIrcServerStep1(XmppComponent*, AdhocSession& session, XmlNode& com
  after_cnt_cmd.add_child(required);
  x.add_child(std::move(after_cnt_cmd));

  XmlNode username("field");
  username["var"] = "username";
  username["type"] = "text-single";
  username["label"] = "Username";
  if (!options.username.value().empty())
    {
      XmlNode username_value("value");
      username_value.set_inner(options.username.value());
      username.add_child(std::move(username_value));
    }
  username.add_child(required);
  x.add_child(std::move(username));

  XmlNode realname("field");
  realname["var"] = "realname";
  realname["type"] = "text-single";
  realname["label"] = "Realname";
  if (!options.realname.value().empty())
    {
      XmlNode realname_value("value");
      realname_value.set_inner(options.realname.value());
      realname.add_child(std::move(realname_value));
    }
  realname.add_child(required);
  x.add_child(std::move(realname));

  command_node.add_child(std::move(x));
}



@@ 230,6 256,14 @@ void ConfigureIrcServerStep2(XmppComponent*, AdhocSession& session, XmlNode& com
          else if (field->get_tag("var") == "after_connect_command" &&
                   value && !value->get_inner().empty())
            options.afterConnectionCommand = value->get_inner();

          else if (field->get_tag("var") == "username" &&
                   value && !value->get_inner().empty())
            options.username = value->get_inner();

          else if (field->get_tag("var") == "realname" &&
                   value && !value->get_inner().empty())
            options.realname = value->get_inner();
        }

      options.update();