Skip to content

Commit

Permalink
relay: wait for message CAP END before sending join of channels and b…
Browse files Browse the repository at this point in the history
…acklog to the client (closes #223)
  • Loading branch information
flashcode committed Dec 7, 2014
1 parent 72e6b3d commit 1f1611c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 48 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.asciidoc
Expand Up @@ -74,6 +74,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
* irc: fix translation of CTCP PING reply (closes #137)
* lua: add detection of Lua 5.2
* python: fix Python detection with Homebrew (closes #217)
* relay: wait for message CAP END before sending join of channels and backlog
to the client (closes #223)
* relay: send messages "_buffer_localvar_*" and "_buffer_type_changed" with
sync "buffers" (closes #191)
* relay: don't remove relay from config when the binding fails (closes #225)
Expand Down
71 changes: 25 additions & 46 deletions src/plugins/relay/irc/relay-irc.c
Expand Up @@ -1195,28 +1195,6 @@ relay_irc_hook_signals (struct t_relay_client *client)
client);
}

/*
* Timer called to hooks signals and send joins for all channels to client.
*/

int
relay_irc_timer_hooks_and_joins_cb (void *data, int remaining_calls)
{
/* make C compiler happy */
(void) remaining_calls;

if (relay_client_valid (data))
{
/* hook signals */
relay_irc_hook_signals (data);

/* send JOIN for all channels on server to client */
relay_irc_send_join_channels (data);
}

return WEECHAT_RC_OK;
}

/*
* Processes the "CAP" irc command (received from client)
*/
Expand Down Expand Up @@ -1244,6 +1222,8 @@ relay_irc_recv_command_capab (struct t_relay_client *client,
(RELAY_IRC_DATA(client, nick)) ? RELAY_IRC_DATA(client, nick) : "nick",
str_capab);
}
if (!RELAY_IRC_DATA(client, connected))
RELAY_IRC_DATA(client, cap_ls_received) = 1;
}
else if (weechat_strncasecmp (arguments, "req ", 4) == 0)
{
Expand Down Expand Up @@ -1286,6 +1266,11 @@ relay_irc_recv_command_capab (struct t_relay_client *client,
weechat_string_free_split (capabs);
}
}
else if (weechat_strcasecmp (arguments, "end") == 0)
{
if (!RELAY_IRC_DATA(client, connected))
RELAY_IRC_DATA(client, cap_end_received) = 1;
}
}

/*
Expand Down Expand Up @@ -1432,7 +1417,9 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
}
}
if (RELAY_IRC_DATA(client, nick)
&& RELAY_IRC_DATA(client, user_received))
&& RELAY_IRC_DATA(client, user_received)
&& (!RELAY_IRC_DATA(client, cap_ls_received)
|| RELAY_IRC_DATA(client, cap_end_received)))
{
/* disconnect client if password was not received or wrong */
if (!RELAY_IRC_DATA(client, password_ok))
Expand Down Expand Up @@ -1531,17 +1518,11 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
RELAY_IRC_DATA(client, address),
RELAY_IRC_DATA(client, nick));

/*
* hook a timer which will hook signals and send JOIN for all
* channels to client (a timer is needed because we may not have
* received the server capabilities yet, like server-time)
*/
if (RELAY_IRC_DATA(client, hook_timer_signals_joins))
weechat_unhook (RELAY_IRC_DATA(client, hook_timer_signals_joins));
RELAY_IRC_DATA(client, hook_timer_signals_joins) =
weechat_hook_timer (500, 0, 1,
&relay_irc_timer_hooks_and_joins_cb,
client);
/* hook signals */
relay_irc_hook_signals (client);

/* send JOIN for all channels on server to client */
relay_irc_send_join_channels (client);
}
}
else
Expand Down Expand Up @@ -1748,11 +1729,6 @@ relay_irc_close_connection (struct t_relay_client *client)
{
RELAY_IRC_DATA(client, connected) = 0;

if (RELAY_IRC_DATA(client, hook_timer_signals_joins))
{
weechat_unhook (RELAY_IRC_DATA(client, hook_timer_signals_joins));
RELAY_IRC_DATA(client, hook_timer_signals_joins) = NULL;
}
if (RELAY_IRC_DATA(client, hook_signal_irc_in2))
{
weechat_unhook (RELAY_IRC_DATA(client, hook_signal_irc_in2));
Expand Down Expand Up @@ -1795,9 +1771,10 @@ relay_irc_alloc (struct t_relay_client *client)
RELAY_IRC_DATA(client, password_ok) = (password && password[0]) ? 0 : 1;
RELAY_IRC_DATA(client, nick) = NULL;
RELAY_IRC_DATA(client, user_received) = 0;
RELAY_IRC_DATA(client, cap_ls_received) = 0;
RELAY_IRC_DATA(client, cap_end_received) = 0;
RELAY_IRC_DATA(client, connected) = 0;
RELAY_IRC_DATA(client, server_capabilities) = 0;
RELAY_IRC_DATA(client, hook_timer_signals_joins) = NULL;
RELAY_IRC_DATA(client, hook_signal_irc_in2) = NULL;
RELAY_IRC_DATA(client, hook_signal_irc_outtags) = NULL;
RELAY_IRC_DATA(client, hook_signal_irc_disc) = NULL;
Expand Down Expand Up @@ -1830,9 +1807,10 @@ relay_irc_alloc_with_infolist (struct t_relay_client *client,
else
RELAY_IRC_DATA(client, nick) = NULL;
RELAY_IRC_DATA(client, user_received) = weechat_infolist_integer (infolist, "user_received");
RELAY_IRC_DATA(client, cap_ls_received) = weechat_infolist_integer (infolist, "cap_ls_received");
RELAY_IRC_DATA(client, cap_end_received) = weechat_infolist_integer (infolist, "cap_end_received");
RELAY_IRC_DATA(client, connected) = weechat_infolist_integer (infolist, "connected");
RELAY_IRC_DATA(client, server_capabilities) = weechat_infolist_integer (infolist, "server_capabilities");
RELAY_IRC_DATA(client, hook_timer_signals_joins) = NULL;
if (RELAY_IRC_DATA(client, connected))
{
relay_irc_hook_signals (client);
Expand Down Expand Up @@ -1860,8 +1838,6 @@ relay_irc_free (struct t_relay_client *client)
free (RELAY_IRC_DATA(client, address));
if (RELAY_IRC_DATA(client, nick))
free (RELAY_IRC_DATA(client, nick));
if (RELAY_IRC_DATA(client, hook_timer_signals_joins))
weechat_unhook (RELAY_IRC_DATA(client, hook_timer_signals_joins));
if (RELAY_IRC_DATA(client, hook_signal_irc_in2))
weechat_unhook (RELAY_IRC_DATA(client, hook_signal_irc_in2));
if (RELAY_IRC_DATA(client, hook_signal_irc_outtags))
Expand Down Expand Up @@ -1900,12 +1876,14 @@ relay_irc_add_to_infolist (struct t_infolist_item *item,
return 0;
if (!weechat_infolist_new_var_integer (item, "user_received", RELAY_IRC_DATA(client, user_received)))
return 0;
if (!weechat_infolist_new_var_integer (item, "cap_ls_received", RELAY_IRC_DATA(client, cap_ls_received)))
return 0;
if (!weechat_infolist_new_var_integer (item, "cap_end_received", RELAY_IRC_DATA(client, cap_end_received)))
return 0;
if (!weechat_infolist_new_var_integer (item, "connected", RELAY_IRC_DATA(client, connected)))
return 0;
if (!weechat_infolist_new_var_integer (item, "server_capabilities", RELAY_IRC_DATA(client, server_capabilities)))
return 0;
if (!weechat_infolist_new_var_pointer (item, "hook_timer_signals_joins", RELAY_IRC_DATA(client, hook_timer_signals_joins)))
return 0;
if (!weechat_infolist_new_var_pointer (item, "hook_signal_irc_in2", RELAY_IRC_DATA(client, hook_signal_irc_in2)))
return 0;
if (!weechat_infolist_new_var_pointer (item, "hook_signal_irc_outtags", RELAY_IRC_DATA(client, hook_signal_irc_outtags)))
Expand All @@ -1931,9 +1909,10 @@ relay_irc_print_log (struct t_relay_client *client)
weechat_log_printf (" password_ok . . . . . . : %d", RELAY_IRC_DATA(client, password_ok));
weechat_log_printf (" nick. . . . . . . . . . : '%s'", RELAY_IRC_DATA(client, nick));
weechat_log_printf (" user_received . . . . . : %d", RELAY_IRC_DATA(client, user_received));
weechat_log_printf (" cap_ls_received . . . . : %d", RELAY_IRC_DATA(client, cap_ls_received));
weechat_log_printf (" cap_end_received. . . . : %d", RELAY_IRC_DATA(client, cap_end_received));
weechat_log_printf (" connected . . . . . . . : %d", RELAY_IRC_DATA(client, connected));
weechat_log_printf (" server_capabilities . . : %d", RELAY_IRC_DATA(client, server_capabilities));
weechat_log_printf (" hook_timer_signals_joins: 0x%lx", RELAY_IRC_DATA(client, hook_timer_signals_joins));
weechat_log_printf (" hook_signal_irc_in2 . . : 0x%lx", RELAY_IRC_DATA(client, hook_signal_irc_in2));
weechat_log_printf (" hook_signal_irc_outtags : 0x%lx", RELAY_IRC_DATA(client, hook_signal_irc_outtags));
weechat_log_printf (" hook_signal_irc_disc. . : 0x%lx", RELAY_IRC_DATA(client, hook_signal_irc_disc));
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/relay/irc/relay-irc.h
Expand Up @@ -32,12 +32,12 @@ struct t_relay_irc_data
int password_ok; /* password received and OK? */
char *nick; /* nick for client */
int user_received; /* command "USER" received */
int cap_ls_received; /* 1 if CAP LS was received */
int cap_end_received; /* 1 if CAP END was received */
int connected; /* 1 if client is connected as IRC */
/* client */
int server_capabilities; /* server capabilities enabled (one */
/* bit per capability) */
struct t_hook *hook_timer_signals_joins;/* timer to hooks signals and */
/* send joins to client */
struct t_hook *hook_signal_irc_in2; /* signal "irc_in2" */
struct t_hook *hook_signal_irc_outtags; /* signal "irc_outtags" */
struct t_hook *hook_signal_irc_disc; /* signal "irc_disconnected" */
Expand Down

0 comments on commit 1f1611c

Please sign in to comment.