mirror of
https://github.com/weechat/weechat.git
synced 2026-06-30 23:06:38 +02:00
relay: actually use the client status "waiting_auth" in irc and weechat protocols (closes #1358)
Now the status "waiting_auth" is used and displayed in the relay buffer. When a client connects, there are now 2 messages (except for irc protocol if there's no password required): relay: new client on port 9000: 1/weechat/1.2.3.4 (waiting auth) relay: client 1/weechat/1.2.3.4 authenticated If the authentication fails, the messages are: relay: new client on port 9000: 1/weechat/1.2.3.4 (waiting auth) =!= relay: authentication failed with client 1/weechat/1.2.3.4
This commit is contained in:
@@ -1430,6 +1430,7 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
|
||||
weechat_hook_signal_send ("relay_client_auth_ok",
|
||||
WEECHAT_HOOK_SIGNAL_POINTER,
|
||||
client);
|
||||
relay_client_set_status (client, RELAY_STATUS_CONNECTED);
|
||||
}
|
||||
free (password);
|
||||
}
|
||||
@@ -1903,6 +1904,18 @@ relay_irc_alloc_with_infolist (struct t_relay_client *client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the client initial status: it can be "waiting_auth" or "connected",
|
||||
* depending if a password is expected or not.
|
||||
*/
|
||||
|
||||
enum t_relay_status
|
||||
relay_irc_get_initial_status (struct t_relay_client *client)
|
||||
{
|
||||
return (RELAY_IRC_DATA(client, password_ok)) ?
|
||||
RELAY_STATUS_CONNECTED : RELAY_STATUS_WAITING_AUTH;
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees relay data specific to IRC protocol.
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define WEECHAT_PLUGIN_RELAY_IRC_H
|
||||
|
||||
struct t_relay_client;
|
||||
enum t_relay_status;
|
||||
|
||||
#define RELAY_IRC_DATA(client, var) \
|
||||
(((struct t_relay_irc_data *)client->protocol_data)->var)
|
||||
@@ -69,6 +70,7 @@ extern void relay_irc_close_connection (struct t_relay_client *client);
|
||||
extern void relay_irc_alloc (struct t_relay_client *client);
|
||||
extern void relay_irc_alloc_with_infolist (struct t_relay_client *client,
|
||||
struct t_infolist *infolist);
|
||||
extern enum t_relay_status relay_irc_get_initial_status (struct t_relay_client *client);
|
||||
extern void relay_irc_free (struct t_relay_client *client);
|
||||
extern int relay_irc_add_to_infolist (struct t_infolist_item *item,
|
||||
struct t_relay_client *client);
|
||||
|
||||
@@ -253,7 +253,21 @@ relay_client_handshake_timer_cb (const void *pointer, void *data,
|
||||
weechat_unhook (client->hook_timer_handshake);
|
||||
client->hook_timer_handshake = NULL;
|
||||
client->gnutls_handshake_ok = 1;
|
||||
relay_client_set_status (client, RELAY_STATUS_CONNECTED);
|
||||
switch (client->protocol)
|
||||
{
|
||||
case RELAY_PROTOCOL_WEECHAT:
|
||||
relay_client_set_status (
|
||||
client,
|
||||
relay_weechat_get_initial_status (client));
|
||||
break;
|
||||
case RELAY_PROTOCOL_IRC:
|
||||
relay_client_set_status (
|
||||
client,
|
||||
relay_irc_get_initial_status (client));
|
||||
break;
|
||||
case RELAY_NUM_PROTOCOLS:
|
||||
break;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -577,8 +591,15 @@ relay_client_recv_cb (const void *pointer, void *data, int fd)
|
||||
|
||||
client = (struct t_relay_client *)pointer;
|
||||
|
||||
if (client->status != RELAY_STATUS_CONNECTED)
|
||||
/*
|
||||
* data can be received only during authentication
|
||||
* or if connected (authentication was OK)
|
||||
*/
|
||||
if ((client->status != RELAY_STATUS_WAITING_AUTH)
|
||||
&& (client->status != RELAY_STATUS_CONNECTED))
|
||||
{
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
#ifdef HAVE_GNUTLS
|
||||
if (client->ssl)
|
||||
@@ -1248,7 +1269,7 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
new_client->address = strdup ((address && address[0]) ?
|
||||
address : "local");
|
||||
new_client->real_ip = NULL;
|
||||
new_client->status = RELAY_STATUS_CONNECTED;
|
||||
new_client->status = RELAY_STATUS_CONNECTING;
|
||||
new_client->protocol = server->protocol;
|
||||
new_client->protocol_string = (server->protocol_string) ? strdup (server->protocol_string) : NULL;
|
||||
new_client->protocol_args = (server->protocol_args) ? strdup (server->protocol_args) : NULL;
|
||||
@@ -1336,9 +1357,19 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
{
|
||||
case RELAY_PROTOCOL_WEECHAT:
|
||||
relay_weechat_alloc (new_client);
|
||||
if (!new_client->ssl)
|
||||
{
|
||||
new_client->status =
|
||||
relay_weechat_get_initial_status (new_client);
|
||||
}
|
||||
break;
|
||||
case RELAY_PROTOCOL_IRC:
|
||||
relay_irc_alloc (new_client);
|
||||
if (!new_client->ssl)
|
||||
{
|
||||
new_client->status =
|
||||
relay_irc_get_initial_status (new_client);
|
||||
}
|
||||
break;
|
||||
case RELAY_NUM_PROTOCOLS:
|
||||
break;
|
||||
@@ -1357,23 +1388,27 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
|
||||
if (server->unix_socket)
|
||||
{
|
||||
weechat_printf_date_tags (NULL, 0, "relay_client",
|
||||
_("%s: new client on path %s: %s%s%s"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
server->path,
|
||||
RELAY_COLOR_CHAT_CLIENT,
|
||||
new_client->desc,
|
||||
RELAY_COLOR_CHAT);
|
||||
weechat_printf_date_tags (
|
||||
NULL, 0, "relay_client",
|
||||
_("%s: new client on path %s: %s%s%s (%s)"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
server->path,
|
||||
RELAY_COLOR_CHAT_CLIENT,
|
||||
new_client->desc,
|
||||
RELAY_COLOR_CHAT,
|
||||
_(relay_client_status_string[new_client->status]));
|
||||
}
|
||||
else
|
||||
{
|
||||
weechat_printf_date_tags (NULL, 0, "relay_client",
|
||||
_("%s: new client on port %s: %s%s%s"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
server->path,
|
||||
RELAY_COLOR_CHAT_CLIENT,
|
||||
new_client->desc,
|
||||
RELAY_COLOR_CHAT);
|
||||
weechat_printf_date_tags (
|
||||
NULL, 0, "relay_client",
|
||||
_("%s: new client on port %s: %s%s%s (%s)"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
server->path,
|
||||
RELAY_COLOR_CHAT_CLIENT,
|
||||
new_client->desc,
|
||||
RELAY_COLOR_CHAT,
|
||||
_(relay_client_status_string[new_client->status]));
|
||||
}
|
||||
|
||||
new_client->hook_fd = weechat_hook_fd (new_client->sock,
|
||||
@@ -1511,7 +1546,17 @@ relay_client_set_status (struct t_relay_client *client,
|
||||
|
||||
client->status = status;
|
||||
|
||||
if (RELAY_CLIENT_HAS_ENDED(client))
|
||||
if (client->status == RELAY_STATUS_CONNECTED)
|
||||
{
|
||||
weechat_printf_date_tags (
|
||||
NULL, 0, "relay_client",
|
||||
_("%s: client %s%s%s authenticated"),
|
||||
RELAY_PLUGIN_NAME,
|
||||
RELAY_COLOR_CHAT_CLIENT,
|
||||
client->desc,
|
||||
RELAY_COLOR_CHAT);
|
||||
}
|
||||
else if (RELAY_CLIENT_HAS_ENDED(client))
|
||||
{
|
||||
client->end_time = time (NULL);
|
||||
|
||||
|
||||
@@ -418,6 +418,7 @@ RELAY_WEECHAT_PROTOCOL_CALLBACK(init)
|
||||
weechat_hook_signal_send ("relay_client_auth_ok",
|
||||
WEECHAT_HOOK_SIGNAL_POINTER,
|
||||
client);
|
||||
relay_client_set_status (client, RELAY_STATUS_CONNECTED);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -266,6 +266,21 @@ relay_weechat_alloc_with_infolist (struct t_relay_client *client,
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the client initial status: it is always "waiting_auth" for weechat
|
||||
* protocol because we always expect the "init" command, even without any
|
||||
* password.
|
||||
*/
|
||||
|
||||
enum t_relay_status
|
||||
relay_weechat_get_initial_status (struct t_relay_client *client)
|
||||
{
|
||||
/* make C compiler happy */
|
||||
(void) client;
|
||||
|
||||
return RELAY_STATUS_WAITING_AUTH;
|
||||
}
|
||||
|
||||
/*
|
||||
* Frees relay data specific to WeeChat protocol.
|
||||
*/
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define WEECHAT_PLUGIN_RELAY_WEECHAT_H
|
||||
|
||||
struct t_relay_client;
|
||||
enum t_relay_status;
|
||||
|
||||
#define RELAY_WEECHAT_DATA(client, var) \
|
||||
(((struct t_relay_weechat_data *)client->protocol_data)->var)
|
||||
@@ -62,6 +63,7 @@ extern void relay_weechat_close_connection (struct t_relay_client *client);
|
||||
extern void relay_weechat_alloc (struct t_relay_client *client);
|
||||
extern void relay_weechat_alloc_with_infolist (struct t_relay_client *client,
|
||||
struct t_infolist *infolist);
|
||||
extern enum t_relay_status relay_weechat_get_initial_status (struct t_relay_client *client);
|
||||
extern void relay_weechat_free (struct t_relay_client *client);
|
||||
extern int relay_weechat_add_to_infolist (struct t_infolist_item *item,
|
||||
struct t_relay_client *client);
|
||||
|
||||
Reference in New Issue
Block a user