summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2020-04-12 17:46:46 +0200
committerSébastien Helleu <flashcode@flashtux.org>2020-04-12 17:46:46 +0200
commit7ddc815726da0f471cbd92896da383bc8bed81f4 (patch)
tree1f55443f261d3c4834705a6b9e3f8bd721267a80 /src
parent07505bb53cbb7c159eaeb52699121903f3001602 (diff)
downloadweechat-7ddc815726da0f471cbd92896da383bc8bed81f4.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/plugins/relay/irc/relay-irc.c13
-rw-r--r--src/plugins/relay/irc/relay-irc.h2
-rw-r--r--src/plugins/relay/relay-client.c81
-rw-r--r--src/plugins/relay/weechat/relay-weechat-protocol.c1
-rw-r--r--src/plugins/relay/weechat/relay-weechat.c15
-rw-r--r--src/plugins/relay/weechat/relay-weechat.h2
6 files changed, 96 insertions, 18 deletions
diff --git a/src/plugins/relay/irc/relay-irc.c b/src/plugins/relay/irc/relay-irc.c
index fea36430c..81f493c78 100644
--- a/src/plugins/relay/irc/relay-irc.c
+++ b/src/plugins/relay/irc/relay-irc.c
@@ -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);
}
@@ -1904,6 +1905,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.
*/
diff --git a/src/plugins/relay/irc/relay-irc.h b/src/plugins/relay/irc/relay-irc.h
index b0de0e786..095fc6691 100644
--- a/src/plugins/relay/irc/relay-irc.h
+++ b/src/plugins/relay/irc/relay-irc.h
@@ -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);
diff --git a/src/plugins/relay/relay-client.c b/src/plugins/relay/relay-client.c
index bc339254d..28c336220 100644
--- a/src/plugins/relay/relay-client.c
+++ b/src/plugins/relay/relay-client.c
@@ -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);
diff --git a/src/plugins/relay/weechat/relay-weechat-protocol.c b/src/plugins/relay/weechat/relay-weechat-protocol.c
index 0c897a6d3..205029f66 100644
--- a/src/plugins/relay/weechat/relay-weechat-protocol.c
+++ b/src/plugins/relay/weechat/relay-weechat-protocol.c
@@ -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
{
diff --git a/src/plugins/relay/weechat/relay-weechat.c b/src/plugins/relay/weechat/relay-weechat.c
index 5373bcb61..8f05c4872 100644
--- a/src/plugins/relay/weechat/relay-weechat.c
+++ b/src/plugins/relay/weechat/relay-weechat.c
@@ -267,6 +267,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.
*/
diff --git a/src/plugins/relay/weechat/relay-weechat.h b/src/plugins/relay/weechat/relay-weechat.h
index 11f4762f2..62f2fc40a 100644
--- a/src/plugins/relay/weechat/relay-weechat.h
+++ b/src/plugins/relay/weechat/relay-weechat.h
@@ -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);