diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2013-02-23 08:33:38 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2013-02-23 08:33:38 +0100 |
commit | c17d3e155ca4b339de9b863087422b943bf1410b (patch) | |
tree | 387b6ed8ad0a7ff8f280ca58c8cd35f26d650d45 /src/plugins/relay | |
parent | 6394a3d1e1e6b3f8025141edc5e2de392af86c93 (diff) | |
download | weechat-c17d3e155ca4b339de9b863087422b943bf1410b.zip |
relay: add support of multiple servers on same port for irc protocol (the client must send the server in the "PASS" command)
Diffstat (limited to 'src/plugins/relay')
-rw-r--r-- | src/plugins/relay/irc/relay-irc.c | 41 | ||||
-rw-r--r-- | src/plugins/relay/relay-client.h | 1 | ||||
-rw-r--r-- | src/plugins/relay/relay-command.c | 7 | ||||
-rw-r--r-- | src/plugins/relay/relay-config.c | 8 |
4 files changed, 43 insertions, 14 deletions
diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c index 50fd9622d..a33bd9aa4 100644 --- a/src/plugins/relay/irc/relay-irc.c +++ b/src/plugins/relay/irc/relay-irc.c @@ -1149,6 +1149,10 @@ relay_irc_hook_signals (struct t_relay_client *client) { char str_signal_name[128]; + /* do nothing if "protocol_args" (irc server name) is not yet initialized */ + if (!client->protocol_args) + return; + /* * hook signal "xxx,irc_in2_*" to catch IRC data received from * this server @@ -1292,10 +1296,10 @@ void relay_irc_recv (struct t_relay_client *client, const char *data) { char str_time[128], str_signal[128], str_server_channel[256]; - char str_command[128], *target, **irc_argv; + char str_command[128], *target, **irc_argv, *pos; const char *irc_command, *irc_channel, *irc_args, *irc_args2; int irc_argc, redirect_msg; - const char *nick, *irc_is_channel, *isupport, *info; + const char *nick, *irc_is_channel, *isupport, *info, *pos_password; struct t_hashtable *hash_parsed, *hash_redirect; struct t_infolist *infolist_server; @@ -1348,11 +1352,23 @@ relay_irc_recv (struct t_relay_client *client, const char *data) { if (irc_command && (weechat_strcasecmp (irc_command, "pass") == 0)) { - if (!RELAY_IRC_DATA(client, password_ok)) + if (irc_args && irc_args[0]) { - if (irc_args && irc_args[0] + pos_password = (irc_args[0] == ':') ? irc_args + 1 : irc_args; + if (!client->protocol_args) + { + pos = strchr (pos_password, ':'); + if (pos) + { + client->protocol_args = weechat_strndup (pos_password, + pos - pos_password); + relay_client_set_desc (client); + pos_password = pos + 1; + } + } + if (!RELAY_IRC_DATA(client, password_ok) && (strcmp (weechat_config_string (relay_config_network_password), - (irc_args[0] == ':') ? irc_args + 1 : irc_args) == 0)) + pos_password) == 0)) { RELAY_IRC_DATA(client, password_ok) = 1; } @@ -1360,6 +1376,21 @@ relay_irc_recv (struct t_relay_client *client, const char *data) } if (irc_command && (weechat_strcasecmp (irc_command, "user") == 0)) { + /* check if server is known */ + if (!client->protocol_args) + { + relay_irc_sendf (client, + ":%s ERROR :WeeChat: server not specified, " + "command \"PASS server:password\" not received", + RELAY_IRC_DATA(client, address)); + relay_irc_sendf (client, + ":%s ERROR :Closing Link", + RELAY_IRC_DATA(client, address)); + relay_client_set_status (client, + RELAY_STATUS_DISCONNECTED); + goto end; + } + /* check if connection to server is ok */ infolist_server = weechat_infolist_get ("irc_server", NULL, client->protocol_args); diff --git a/src/plugins/relay/relay-client.h b/src/plugins/relay/relay-client.h index 27cd00fca..4556d0b58 100644 --- a/src/plugins/relay/relay-client.h +++ b/src/plugins/relay/relay-client.h @@ -113,6 +113,7 @@ extern int relay_client_count; extern int relay_client_valid (struct t_relay_client *client); extern struct t_relay_client *relay_client_search_by_number (int number); extern struct t_relay_client *relay_client_search_by_id (int id); +extern void relay_client_set_desc (struct t_relay_client *client); extern int relay_client_recv_cb (void *arg_client, int fd); extern int relay_client_send (struct t_relay_client *client, const char *data, int data_size, const char *message_raw_buffer); diff --git a/src/plugins/relay/relay-command.c b/src/plugins/relay/relay-command.c index 2802f75ba..83d90a9f4 100644 --- a/src/plugins/relay/relay-command.c +++ b/src/plugins/relay/relay-command.c @@ -326,7 +326,9 @@ relay_command_init () " ssl: enable SSL\n" "protocol.name: protocol and name to relay:\n" " - protocol \"irc\": name is the " - "server to share\n" + "server to share (optional, if not given, the server " + "name must be sent by client in command \"PASS\", " + "with format: \"PASS server:password\")\n" " - protocol \"weechat\" (name is " "not used)\n" " port: port used for relay\n" @@ -340,6 +342,9 @@ relay_command_init () " /relay add irc.freenode 8000\n" " irc proxy, for server \"freenode\", with SSL:\n" " /relay add ssl.irc.freenode 8001\n" + " irc proxy, for all servers (client will choose), " + "with SSL:\n" + " /relay add ssl.irc 8002\n" " weechat protocol:\n" " /relay add weechat 9000\n" " weechat protocol with SSL:\n" diff --git a/src/plugins/relay/relay-config.c b/src/plugins/relay/relay-config.c index d6092d279..7ad6d4f73 100644 --- a/src/plugins/relay/relay-config.c +++ b/src/plugins/relay/relay-config.c @@ -397,14 +397,6 @@ relay_config_create_option_port (void *data, RELAY_PLUGIN_NAME, protocol); rc = WEECHAT_CONFIG_OPTION_SET_ERROR; } - else if ((protocol_number == RELAY_PROTOCOL_IRC) && !protocol_args) - { - weechat_printf (NULL, _("%s%s: error: name is not required for " - "protocol \"%s\""), - weechat_prefix ("error"), - RELAY_PLUGIN_NAME, protocol); - rc = WEECHAT_CONFIG_OPTION_SET_ERROR; - } } if (rc != WEECHAT_CONFIG_OPTION_SET_ERROR) |