mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 16:23:14 +02:00
tests: add tests on relay "irc" protocol
This commit is contained in:
@@ -59,13 +59,13 @@ relay_irc_command_relayed (const char *irc_command)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (irc_command)
|
||||
if (!irc_command)
|
||||
return 0;
|
||||
|
||||
for (i = 0; relay_irc_relay_commands[i]; i++)
|
||||
{
|
||||
for (i = 0; relay_irc_relay_commands[i]; i++)
|
||||
{
|
||||
if (weechat_strcasecmp (relay_irc_relay_commands[i], irc_command) == 0)
|
||||
return 1;
|
||||
}
|
||||
if (weechat_strcasecmp (relay_irc_relay_commands[i], irc_command) == 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* command must NOT be relayed to client */
|
||||
@@ -85,16 +85,16 @@ relay_irc_command_ignored (const char *irc_command)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (irc_command)
|
||||
if (!irc_command)
|
||||
return 0;
|
||||
|
||||
for (i = 0; relay_irc_ignore_commands[i]; i++)
|
||||
{
|
||||
for (i = 0; relay_irc_ignore_commands[i]; i++)
|
||||
{
|
||||
if (weechat_strcasecmp (relay_irc_ignore_commands[i], irc_command) == 0)
|
||||
return 1;
|
||||
}
|
||||
if (weechat_strcasecmp (relay_irc_ignore_commands[i], irc_command) == 0)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* command must NOT be relayed to client */
|
||||
/* command must be ignored */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -158,6 +158,9 @@ relay_irc_message_parse (const char *message)
|
||||
{
|
||||
struct t_hashtable *hash_msg, *hash_parsed;
|
||||
|
||||
if (!message)
|
||||
return NULL;
|
||||
|
||||
hash_msg = NULL;
|
||||
hash_parsed = NULL;
|
||||
|
||||
@@ -384,30 +387,30 @@ relay_irc_tag_relay_client_id (const char *tags)
|
||||
|
||||
result = -1;
|
||||
|
||||
if (tags && tags[0])
|
||||
if (!tags || !tags[0])
|
||||
return result;
|
||||
|
||||
argv = weechat_string_split (tags, ",", NULL,
|
||||
WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
|
||||
0, &argc);
|
||||
if (argv)
|
||||
{
|
||||
argv = weechat_string_split (tags, ",", NULL,
|
||||
WEECHAT_STRING_SPLIT_STRIP_LEFT
|
||||
| WEECHAT_STRING_SPLIT_STRIP_RIGHT
|
||||
| WEECHAT_STRING_SPLIT_COLLAPSE_SEPS,
|
||||
0, &argc);
|
||||
if (argv)
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
for (i = 0; i < argc; i++)
|
||||
if (strncmp (argv[i], "relay_client_", 13) == 0)
|
||||
{
|
||||
if (strncmp (argv[i], "relay_client_", 13) == 0)
|
||||
error = NULL;
|
||||
number = strtol (argv[i] + 13, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
error = NULL;
|
||||
number = strtol (argv[i] + 13, &error, 10);
|
||||
if (error && !error[0])
|
||||
{
|
||||
result = number;
|
||||
break;
|
||||
}
|
||||
result = number;
|
||||
break;
|
||||
}
|
||||
}
|
||||
weechat_string_free_split (argv);
|
||||
}
|
||||
weechat_string_free_split (argv);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -1189,7 +1192,7 @@ relay_irc_send_join_channels (struct t_relay_client *client)
|
||||
|
||||
void
|
||||
relay_irc_input_send (struct t_relay_client *client, const char *irc_channel,
|
||||
char *options, const char *format, ...)
|
||||
const char *options, const char *format, ...)
|
||||
{
|
||||
char buf_beginning[1024], *buf;
|
||||
int length_beginning, length_vbuffer;
|
||||
@@ -1459,11 +1462,7 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
|
||||
/* server capabilities */
|
||||
if (irc_command && (weechat_strcasecmp (irc_command, "cap") == 0))
|
||||
{
|
||||
if (num_params > 0)
|
||||
{
|
||||
relay_irc_recv_command_capab (client,
|
||||
num_params, (const char **)params);
|
||||
}
|
||||
relay_irc_recv_command_capab (client, num_params, (const char **)params);
|
||||
}
|
||||
/* if client is not yet "connected" */
|
||||
if (!RELAY_IRC_DATA(client, connected))
|
||||
@@ -1541,6 +1540,7 @@ relay_irc_recv (struct t_relay_client *client, const char *data)
|
||||
RELAY_IRC_DATA(client, address));
|
||||
relay_client_set_status (client,
|
||||
RELAY_STATUS_DISCONNECTED);
|
||||
weechat_infolist_free (infolist_server);
|
||||
goto end;
|
||||
}
|
||||
if (num_params > 0)
|
||||
|
||||
@@ -591,6 +591,9 @@ relay_client_recv_cb (const void *pointer, void *data, int fd)
|
||||
|
||||
client = (struct t_relay_client *)pointer;
|
||||
|
||||
if (client->sock < 0)
|
||||
return WEECHAT_RC_OK;
|
||||
|
||||
/*
|
||||
* data can be received only during authentication
|
||||
* or if connected (authentication was OK)
|
||||
@@ -800,15 +803,19 @@ relay_client_send_outqueue (struct t_relay_client *client)
|
||||
{
|
||||
if (client->tls)
|
||||
{
|
||||
num_sent = gnutls_record_send (client->gnutls_sess,
|
||||
client->outqueue->data,
|
||||
client->outqueue->data_size);
|
||||
num_sent = (client->sock >= 0) ?
|
||||
gnutls_record_send (client->gnutls_sess,
|
||||
client->outqueue->data,
|
||||
client->outqueue->data_size) :
|
||||
client->outqueue->data_size;
|
||||
}
|
||||
else
|
||||
{
|
||||
num_sent = send (client->sock,
|
||||
client->outqueue->data,
|
||||
client->outqueue->data_size, 0);
|
||||
num_sent = (client->sock >= 0) ?
|
||||
send (client->sock,
|
||||
client->outqueue->data,
|
||||
client->outqueue->data_size, 0) :
|
||||
client->outqueue->data_size;
|
||||
}
|
||||
if (num_sent >= 0)
|
||||
{
|
||||
@@ -1138,9 +1145,16 @@ relay_client_send (struct t_relay_client *client,
|
||||
else
|
||||
{
|
||||
if (client->tls)
|
||||
num_sent = gnutls_record_send (client->gnutls_sess, ptr_data, data_size);
|
||||
{
|
||||
num_sent = (client->sock >= 0) ?
|
||||
gnutls_record_send (client->gnutls_sess, ptr_data, data_size) :
|
||||
data_size;
|
||||
}
|
||||
else
|
||||
num_sent = send (client->sock, ptr_data, data_size, 0);
|
||||
{
|
||||
num_sent = (client->sock >= 0) ?
|
||||
send (client->sock, ptr_data, data_size, 0) : data_size;
|
||||
}
|
||||
|
||||
if (num_sent >= 0)
|
||||
{
|
||||
@@ -1307,6 +1321,7 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
new_client->sock = sock;
|
||||
new_client->server_port = server->port;
|
||||
new_client->tls = server->tls;
|
||||
new_client->gnutls_sess = NULL;
|
||||
new_client->hook_timer_handshake = NULL;
|
||||
new_client->gnutls_handshake_ok = 0;
|
||||
new_client->websocket = RELAY_CLIENT_WEBSOCKET_NOT_USED;
|
||||
@@ -1464,10 +1479,13 @@ relay_client_new (int sock, const char *address, struct t_relay_server *server)
|
||||
_(relay_client_status_string[new_client->status]));
|
||||
}
|
||||
|
||||
new_client->hook_fd = weechat_hook_fd (new_client->sock,
|
||||
1, 0, 0,
|
||||
&relay_client_recv_cb,
|
||||
new_client, NULL);
|
||||
if (new_client->sock >= 0)
|
||||
{
|
||||
new_client->hook_fd = weechat_hook_fd (new_client->sock,
|
||||
1, 0, 0,
|
||||
&relay_client_recv_cb,
|
||||
new_client, NULL);
|
||||
}
|
||||
|
||||
relay_client_count++;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user