summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-config.c9
-rw-r--r--src/plugins/irc/irc-config.h1
-rw-r--r--src/plugins/irc/irc-protocol.c5
-rw-r--r--src/plugins/irc/irc-server.c55
-rw-r--r--src/plugins/irc/irc-server.h5
5 files changed, 67 insertions, 8 deletions
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 8ca836f7b..c3db51202 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -87,6 +87,7 @@ struct t_config_option *irc_config_color_item_channel_modes;
/* IRC config, network section */
+struct t_config_option *irc_config_network_connection_timeout;
struct t_config_option *irc_config_network_default_msg_part;
struct t_config_option *irc_config_network_default_msg_quit;
struct t_config_option *irc_config_network_away_check;
@@ -1626,6 +1627,14 @@ irc_config_init ()
return 0;
}
+ irc_config_network_connection_timeout = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "connection_timeout", "integer",
+ N_("timeout (in seconds) between TCP connection to server and message "
+ "001 received, if this timeout is reached before 001 message is "
+ "received, WeeChat will disconnect from server"),
+ NULL, 1, 3600, "60", NULL, 0, NULL, NULL,
+ NULL, NULL, NULL, NULL);
irc_config_network_default_msg_part = weechat_config_new_option (
irc_config_file, ptr_section,
"default_msg_part", "string",
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index 0fa164a33..e11100c5a 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -105,6 +105,7 @@ extern struct t_config_option *irc_config_color_input_nick;
extern struct t_config_option *irc_config_color_item_away;
extern struct t_config_option *irc_config_color_item_channel_modes;
+extern struct t_config_option *irc_config_network_connection_timeout;
extern struct t_config_option *irc_config_network_default_msg_part;
extern struct t_config_option *irc_config_network_default_msg_quit;
extern struct t_config_option *irc_config_network_away_check;
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 42f6e52ab..1e047f12d 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -1790,6 +1790,11 @@ irc_protocol_cmd_001 (struct t_irc_server *server, const char *command,
/* connection to IRC server is ok! */
server->is_connected = 1;
+ if (server->hook_timer_connection)
+ {
+ weechat_unhook (server->hook_timer_connection);
+ server->hook_timer_connection = NULL;
+ }
server->lag_next_check = time (NULL) +
weechat_config_integer (irc_config_network_lag_check);
irc_server_set_buffer_title (server);
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 81172b43a..db86dd6e5 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -320,6 +320,7 @@ irc_server_alloc (const char *name)
new_server->sock = -1;
new_server->hook_connect = NULL;
new_server->hook_fd = NULL;
+ new_server->hook_timer_connection = NULL;
new_server->hook_timer_sasl = NULL;
new_server->is_connected = 0;
new_server->ssl_connected = 0;
@@ -714,6 +715,8 @@ irc_server_free_data (struct t_irc_server *server)
weechat_unhook (server->hook_connect);
if (server->hook_fd)
weechat_unhook (server->hook_fd);
+ if (server->hook_timer_connection)
+ weechat_unhook (server->hook_timer_connection);
if (server->hook_timer_sasl)
weechat_unhook (server->hook_timer_sasl);
if (server->unterminated_message)
@@ -1659,7 +1662,7 @@ irc_server_msgq_flush ()
*/
int
-irc_server_recv_cb (void *arg_server, int fd)
+irc_server_recv_cb (void *data, int fd)
{
struct t_irc_server *server;
static char buffer[4096 + 2];
@@ -1668,7 +1671,7 @@ irc_server_recv_cb (void *arg_server, int fd)
/* make C compiler happy */
(void) fd;
- server = (struct t_irc_server *)arg_server;
+ server = (struct t_irc_server *)data;
if (!server)
return WEECHAT_RC_ERROR;
@@ -1731,6 +1734,38 @@ irc_server_recv_cb (void *arg_server, int fd)
}
/*
+ * irc_server_timer_connection_cb: callback for server connection
+ * it is called if WeeChat is TCP-connected to
+ * server, but did not receive message 001
+ */
+
+int
+irc_server_timer_connection_cb (void *data, int remaining_calls)
+{
+ struct t_irc_server *server;
+
+ /* make C compiler happy */
+ (void) remaining_calls;
+
+ server = (struct t_irc_server *)data;
+
+ if (!server)
+ return WEECHAT_RC_ERROR;
+
+ server->hook_timer_connection = NULL;
+
+ if (!server->is_connected)
+ {
+ weechat_printf (server->buffer,
+ _("%s%s: connection timeout (message 001 not received)"),
+ weechat_prefix ("error"), IRC_PLUGIN_NAME);
+ irc_server_disconnect (server, 1);
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* irc_server_timer_sasl_cb: callback for SASL authentication timer
* it is called if there is a timeout with SASL
* authentication
@@ -1740,14 +1775,14 @@ irc_server_recv_cb (void *arg_server, int fd)
*/
int
-irc_server_timer_sasl_cb (void *arg_server, int remaining_calls)
+irc_server_timer_sasl_cb (void *data, int remaining_calls)
{
struct t_irc_server *server;
/* make C compiler happy */
(void) remaining_calls;
- server = (struct t_irc_server *)arg_server;
+ server = (struct t_irc_server *)data;
if (!server)
return WEECHAT_RC_ERROR;
@@ -1990,6 +2025,13 @@ irc_server_login (struct t_irc_server *server)
server->addresses_array[server->index_current_address],
(realname && realname[0]) ?
realname : "weechat");
+
+ if (server->hook_timer_connection)
+ weechat_unhook (server->hook_timer_connection);
+ server->hook_timer_connection = weechat_hook_timer (weechat_config_integer (irc_config_network_connection_timeout) * 1000,
+ 0, 1,
+ &irc_server_timer_connection_cb,
+ server);
}
/*
@@ -2020,13 +2062,13 @@ irc_server_switch_address (struct t_irc_server *server)
*/
int
-irc_server_connect_cb (void *arg_server, int status, int gnutls_rc,
+irc_server_connect_cb (void *data, int status, int gnutls_rc,
const char *error, const char *ip_address)
{
struct t_irc_server *server;
const char *proxy;
- server = (struct t_irc_server *)arg_server;
+ server = (struct t_irc_server *)data;
proxy = IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_PROXY);
@@ -3645,6 +3687,7 @@ irc_server_print_log ()
weechat_log_printf (" sock . . . . . . . . : %d", ptr_server->sock);
weechat_log_printf (" hook_connect . . . . : 0x%lx", ptr_server->hook_connect);
weechat_log_printf (" hook_fd. . . . . . . : 0x%lx", ptr_server->hook_fd);
+ weechat_log_printf (" hook_timer_connection: 0x%lx", ptr_server->hook_timer_connection);
weechat_log_printf (" hook_timer_sasl. . . : 0x%lx", ptr_server->hook_timer_sasl);
weechat_log_printf (" is_connected . . . . : %d", ptr_server->is_connected);
weechat_log_printf (" ssl_connected. . . . : %d", ptr_server->ssl_connected);
diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h
index 0581fb555..32fb57aa2 100644
--- a/src/plugins/irc/irc-server.h
+++ b/src/plugins/irc/irc-server.h
@@ -121,6 +121,7 @@ struct t_irc_server
int sock; /* socket for server (IPv4 or IPv6) */
struct t_hook *hook_connect; /* connection hook */
struct t_hook *hook_fd; /* hook for server socket */
+ struct t_hook *hook_timer_connection; /* timer for connection */
struct t_hook *hook_timer_sasl; /* timer for SASL authentication */
int is_connected; /* 1 if WeeChat is connected to server */
int ssl_connected; /* = 1 if connected with SSL */
@@ -204,8 +205,8 @@ extern struct t_gui_buffer *irc_server_create_buffer (struct t_irc_server *serve
extern int irc_server_connect (struct t_irc_server *server);
extern void irc_server_auto_connect ();
extern void irc_server_autojoin_channels ();
-extern int irc_server_recv_cb (void *arg_server, int fd);
-extern int irc_server_timer_sasl_cb (void *arg_server, int remaining_calls);
+extern int irc_server_recv_cb (void *data, int fd);
+extern int irc_server_timer_sasl_cb (void *data, int remaining_calls);
extern int irc_server_timer_cb (void *data, int remaining_calls);
extern int irc_server_timer_check_away_cb (void *data, int remaining_calls);
extern void irc_server_outqueue_free_all (struct t_irc_server *server,