mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 00:03:12 +02:00
irc: add server option "split_msg_max_length"
This commit is contained in:
@@ -4969,6 +4969,15 @@ irc_command_display_server (struct t_irc_server *server, int with_detail)
|
||||
weechat_printf (NULL, " notify . . . . . . . : %s'%s'",
|
||||
IRC_COLOR_CHAT_VALUE,
|
||||
weechat_config_string (server->options[IRC_SERVER_OPTION_NOTIFY]));
|
||||
|
||||
/* split_msg_max_length */
|
||||
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH]))
|
||||
weechat_printf (NULL, " split_msg_max_length : (%d)",
|
||||
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH));
|
||||
else
|
||||
weechat_printf (NULL, " split_msg_max_length : %s%d",
|
||||
IRC_COLOR_CHAT_VALUE,
|
||||
weechat_config_integer (server->options[IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -995,6 +995,8 @@ irc_config_server_check_value_cb (const void *pointer, void *data,
|
||||
{
|
||||
int index_option, proxy_found;
|
||||
const char *pos_error, *proxy_name;
|
||||
char *error;
|
||||
long number;
|
||||
struct t_infolist *infolist;
|
||||
#ifdef HAVE_GNUTLS
|
||||
char *fingerprint_eval, **fingerprints, *str_sizes;
|
||||
@@ -1127,6 +1129,31 @@ irc_config_server_check_value_cb (const void *pointer, void *data,
|
||||
}
|
||||
#endif /* HAVE_GNUTLS */
|
||||
break;
|
||||
case IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH:
|
||||
if (!value || !value[0])
|
||||
break;
|
||||
error = NULL;
|
||||
number = strtol (value, &error, 10);
|
||||
if (!error || error[0])
|
||||
{
|
||||
/*
|
||||
* not a valid number, but we return 1 (OK) to let WeeChat
|
||||
* display the appropriate error
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
if ((number < 0)
|
||||
|| ((number > 0) && (number < 128))
|
||||
|| (number > 4096))
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: invalid length for split, it must be "
|
||||
"either 0 or any integer between 128 and 4096"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2264,6 +2291,29 @@ irc_config_server_new_option (struct t_config_file *config_file,
|
||||
callback_change_data,
|
||||
NULL, NULL, NULL);
|
||||
break;
|
||||
case IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH:
|
||||
new_option = weechat_config_new_option (
|
||||
config_file, section,
|
||||
option_name, "integer",
|
||||
N_("split outgoing IRC messages to fit in this number of chars; "
|
||||
"the default value is 512, this is a safe and recommended "
|
||||
"value); "
|
||||
"value 0 disables the split (not recommended, unless you "
|
||||
"know what you do); allowed values are 0 or "
|
||||
"any integer between 128 and 4096; "
|
||||
"this option should be changed only on non-standard IRC "
|
||||
"servers, for example gateways like bitlbee"),
|
||||
NULL, 0, 4096,
|
||||
default_value, value,
|
||||
null_value_allowed,
|
||||
callback_check_value,
|
||||
callback_check_value_pointer,
|
||||
callback_check_value_data,
|
||||
callback_change,
|
||||
callback_change_pointer,
|
||||
callback_change_data,
|
||||
NULL, NULL, NULL);
|
||||
break;
|
||||
case IRC_SERVER_NUM_OPTIONS:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -898,7 +898,7 @@ irc_info_init ()
|
||||
&irc_info_info_hashtable_irc_message_parse_cb, NULL, NULL);
|
||||
weechat_hook_info_hashtable (
|
||||
"irc_message_split",
|
||||
N_("split an IRC message (to fit in 512 bytes)"),
|
||||
N_("split an IRC message (to fit in 512 bytes by default)"),
|
||||
N_("\"message\": IRC message, \"server\": server name (optional)"),
|
||||
/* TRANSLATORS: please do not translate key names (enclosed by quotes) */
|
||||
N_("\"msg1\" ... \"msgN\": messages to send (without final \"\\r\\n\"), "
|
||||
|
||||
@@ -139,7 +139,8 @@ irc_input_user_message_display (struct t_gui_buffer *buffer, int action,
|
||||
}
|
||||
|
||||
/*
|
||||
* Sends a PRIVMSG message, and split it if message size is > 512 bytes.
|
||||
* Sends a PRIVMSG message, and split it if message size is > 512 bytes
|
||||
* (by default).
|
||||
*
|
||||
* Warning: this function makes temporary changes in "message".
|
||||
*/
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
|
||||
#include "../weechat-plugin.h"
|
||||
#include "irc.h"
|
||||
#include "irc-server.h"
|
||||
#include "irc-channel.h"
|
||||
#include "irc-config.h"
|
||||
#include "irc-server.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -653,13 +654,14 @@ irc_message_split_string (struct t_hashtable *hashtable,
|
||||
const char *arguments,
|
||||
const char *suffix,
|
||||
const char delimiter,
|
||||
int max_length_host)
|
||||
int max_length_host,
|
||||
int max_length)
|
||||
{
|
||||
const char *pos, *pos_max, *pos_next, *pos_last_delim;
|
||||
char message[1024], *dup_arguments;
|
||||
int max_length, number;
|
||||
char message[8192], *dup_arguments;
|
||||
int number;
|
||||
|
||||
max_length = 510;
|
||||
max_length -= 2; /* by default: 512 - 2 = 510 bytes */
|
||||
if (max_length_host >= 0)
|
||||
max_length -= max_length_host;
|
||||
else
|
||||
@@ -753,12 +755,15 @@ irc_message_split_string (struct t_hashtable *hashtable,
|
||||
int
|
||||
irc_message_split_join (struct t_hashtable *hashtable,
|
||||
const char *tags, const char *host,
|
||||
const char *arguments)
|
||||
const char *arguments,
|
||||
int max_length)
|
||||
{
|
||||
int number, channels_count, keys_count, length, length_no_channel;
|
||||
int length_to_add, index_channel;
|
||||
char **channels, **keys, *pos, *str;
|
||||
char msg_to_send[2048], keys_to_add[2048];
|
||||
char msg_to_send[16384], keys_to_add[16384];
|
||||
|
||||
max_length -= 2; /* by default: 512 - 2 = 510 bytes */
|
||||
|
||||
number = 1;
|
||||
|
||||
@@ -799,7 +804,8 @@ irc_message_split_join (struct t_hashtable *hashtable,
|
||||
length_to_add = 1 + strlen (channels[index_channel]);
|
||||
if (index_channel < keys_count)
|
||||
length_to_add += 1 + strlen (keys[index_channel]);
|
||||
if ((length + length_to_add < 510) || (length == length_no_channel))
|
||||
if ((length + length_to_add < max_length)
|
||||
|| (length == length_no_channel))
|
||||
{
|
||||
if (length + length_to_add < (int)sizeof (msg_to_send))
|
||||
{
|
||||
@@ -864,9 +870,10 @@ int
|
||||
irc_message_split_privmsg_notice (struct t_hashtable *hashtable,
|
||||
char *tags, char *host, char *command,
|
||||
char *target, char *arguments,
|
||||
int max_length_host)
|
||||
int max_length_host,
|
||||
int max_length)
|
||||
{
|
||||
char prefix[512], suffix[2], *pos, saved_char;
|
||||
char prefix[4096], suffix[2], *pos, saved_char;
|
||||
int length, rc;
|
||||
|
||||
/*
|
||||
@@ -903,7 +910,7 @@ irc_message_split_privmsg_notice (struct t_hashtable *hashtable,
|
||||
|
||||
rc = irc_message_split_string (hashtable, tags, host, command, target,
|
||||
prefix, arguments, suffix,
|
||||
' ', max_length_host);
|
||||
' ', max_length_host, max_length);
|
||||
|
||||
return rc;
|
||||
}
|
||||
@@ -919,9 +926,9 @@ irc_message_split_privmsg_notice (struct t_hashtable *hashtable,
|
||||
int
|
||||
irc_message_split_005 (struct t_hashtable *hashtable,
|
||||
char *tags, char *host, char *command, char *target,
|
||||
char *arguments)
|
||||
char *arguments, int max_length)
|
||||
{
|
||||
char *pos, suffix[512];
|
||||
char *pos, suffix[4096];
|
||||
|
||||
/*
|
||||
* 005 message looks like:
|
||||
@@ -941,7 +948,8 @@ irc_message_split_005 (struct t_hashtable *hashtable,
|
||||
}
|
||||
|
||||
return irc_message_split_string (hashtable, tags, host, command, target,
|
||||
NULL, arguments, suffix, ' ', -1);
|
||||
NULL, arguments, suffix, ' ', -1,
|
||||
max_length);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -951,6 +959,10 @@ irc_message_split_005 (struct t_hashtable *hashtable,
|
||||
* "\r\n", so full size is 512 bytes (the user data does not include the
|
||||
* optional tags before the host).
|
||||
*
|
||||
* The 512 max length is the default (recommended) and can be changed with the
|
||||
* server option called "split_msg_max_length" (0 to disable completely the
|
||||
* split).
|
||||
*
|
||||
* The split takes care about type of message to do a split at best place in
|
||||
* message.
|
||||
*
|
||||
@@ -972,9 +984,10 @@ struct t_hashtable *
|
||||
irc_message_split (struct t_irc_server *server, const char *message)
|
||||
{
|
||||
struct t_hashtable *hashtable;
|
||||
char **argv, **argv_eol, *tags, *host, *command, *arguments, target[512];
|
||||
char **argv, **argv_eol, *tags, *host, *command, *arguments, target[4096];
|
||||
char *pos, monitor_action[3];
|
||||
int split_ok, argc, index_args, max_length_nick, max_length_host;
|
||||
int split_msg_max_length;
|
||||
|
||||
split_ok = 0;
|
||||
tags = NULL;
|
||||
@@ -984,9 +997,22 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
argv = NULL;
|
||||
argv_eol = NULL;
|
||||
|
||||
if (server)
|
||||
{
|
||||
split_msg_max_length = IRC_SERVER_OPTION_INTEGER(
|
||||
server, IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH);
|
||||
}
|
||||
else
|
||||
{
|
||||
split_msg_max_length = 512; /* max length by default */
|
||||
}
|
||||
|
||||
/* debug message */
|
||||
if (weechat_irc_plugin->debug >= 2)
|
||||
weechat_printf (NULL, "irc_message_split: message='%s'", message);
|
||||
{
|
||||
weechat_printf (NULL, "irc_message_split: message='%s', max length=%d",
|
||||
message, split_msg_max_length);
|
||||
}
|
||||
|
||||
hashtable = weechat_hashtable_new (32,
|
||||
WEECHAT_HASHTABLE_STRING,
|
||||
@@ -1030,6 +1056,10 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
index_args = 1;
|
||||
}
|
||||
|
||||
/* split disabled? just add the message as-is */
|
||||
if (split_msg_max_length == 0)
|
||||
goto end;
|
||||
|
||||
max_length_nick = (server && (server->nick_max_length > 0)) ?
|
||||
server->nick_max_length : 16;
|
||||
max_length_host = 1 + /* ":" */
|
||||
@@ -1049,7 +1079,7 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
hashtable, tags, host, command, NULL, ":",
|
||||
(argv_eol[index_args][0] == ':') ?
|
||||
argv_eol[index_args] + 1 : argv_eol[index_args],
|
||||
NULL, ' ', max_length_host);
|
||||
NULL, ' ', max_length_host, split_msg_max_length);
|
||||
}
|
||||
else if (weechat_strcasecmp (command, "monitor") == 0)
|
||||
{
|
||||
@@ -1064,7 +1094,8 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
"%c ", argv_eol[index_args][0]);
|
||||
split_ok = irc_message_split_string (
|
||||
hashtable, tags, host, command, NULL, monitor_action,
|
||||
argv_eol[index_args] + 2, NULL, ',', max_length_host);
|
||||
argv_eol[index_args] + 2, NULL, ',', max_length_host,
|
||||
split_msg_max_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1072,17 +1103,17 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
hashtable, tags, host, command, NULL, ":",
|
||||
(argv_eol[index_args][0] == ':') ?
|
||||
argv_eol[index_args] + 1 : argv_eol[index_args],
|
||||
NULL, ',', max_length_host);
|
||||
NULL, ',', max_length_host, split_msg_max_length);
|
||||
}
|
||||
}
|
||||
else if (weechat_strcasecmp (command, "join") == 0)
|
||||
{
|
||||
/* JOIN #channel1,#channel2,#channel3 key1,key2 */
|
||||
if (strlen (message) > 510)
|
||||
if ((int)strlen (message) > split_msg_max_length - 2)
|
||||
{
|
||||
/* split join if it's more than 510 bytes */
|
||||
/* split join if it's too long */
|
||||
split_ok = irc_message_split_join (hashtable, tags, host,
|
||||
arguments);
|
||||
arguments, split_msg_max_length);
|
||||
}
|
||||
}
|
||||
else if ((weechat_strcasecmp (command, "privmsg") == 0)
|
||||
@@ -1098,7 +1129,7 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
hashtable, tags, host, command, argv[index_args],
|
||||
(argv_eol[index_args + 1][0] == ':') ?
|
||||
argv_eol[index_args + 1] + 1 : argv_eol[index_args + 1],
|
||||
max_length_host);
|
||||
max_length_host, split_msg_max_length);
|
||||
}
|
||||
}
|
||||
else if (weechat_strcasecmp (command, "005") == 0)
|
||||
@@ -1109,7 +1140,8 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
split_ok = irc_message_split_005 (
|
||||
hashtable, tags, host, command, argv[index_args],
|
||||
(argv_eol[index_args + 1][0] == ':') ?
|
||||
argv_eol[index_args + 1] + 1 : argv_eol[index_args + 1]);
|
||||
argv_eol[index_args + 1] + 1 : argv_eol[index_args + 1],
|
||||
split_msg_max_length);
|
||||
}
|
||||
}
|
||||
else if (weechat_strcasecmp (command, "353") == 0)
|
||||
@@ -1128,7 +1160,7 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
hashtable, tags, host, command, target, ":",
|
||||
(argv_eol[index_args + 2][0] == ':') ?
|
||||
argv_eol[index_args + 2] + 1 : argv_eol[index_args + 2],
|
||||
NULL, ' ', -1);
|
||||
NULL, ' ', -1, split_msg_max_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1141,7 +1173,7 @@ irc_message_split (struct t_irc_server *server, const char *message)
|
||||
hashtable, tags, host, command, target, ":",
|
||||
(argv_eol[index_args + 3][0] == ':') ?
|
||||
argv_eol[index_args + 3] + 1 : argv_eol[index_args + 3],
|
||||
NULL, ' ', -1);
|
||||
NULL, ' ', -1, split_msg_max_length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,7 @@ char *irc_server_options[IRC_SERVER_NUM_OPTIONS][2] =
|
||||
{ "msg_part", "WeeChat ${info:version}" },
|
||||
{ "msg_quit", "WeeChat ${info:version}" },
|
||||
{ "notify", "" },
|
||||
{ "split_msg_max_length", "512" },
|
||||
};
|
||||
|
||||
char *irc_server_casemapping_string[IRC_SERVER_NUM_CASEMAPPING] =
|
||||
@@ -2489,7 +2490,10 @@ irc_server_sendf (struct t_irc_server *server, int flags, const char *tags,
|
||||
(new_msg) ? new_msg : items[i],
|
||||
NULL);
|
||||
|
||||
/* split message if needed (max is 512 bytes including final "\r\n") */
|
||||
/*
|
||||
* split message if needed (max is 512 bytes by default,
|
||||
* including the final "\r\n")
|
||||
*/
|
||||
hashtable = irc_message_split (server,
|
||||
(new_msg) ? new_msg : items[i]);
|
||||
if (hashtable)
|
||||
|
||||
@@ -84,6 +84,7 @@ enum t_irc_server_option
|
||||
IRC_SERVER_OPTION_MSG_PART, /* default part message */
|
||||
IRC_SERVER_OPTION_MSG_QUIT, /* default quit message */
|
||||
IRC_SERVER_OPTION_NOTIFY, /* notify list */
|
||||
IRC_SERVER_OPTION_SPLIT_MSG_MAX_LENGTH, /* max length of messages */
|
||||
/* number of server options */
|
||||
IRC_SERVER_NUM_OPTIONS,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user