diff options
author | Senya <senya@riseup.net> | 2016-08-20 23:00:56 +0000 |
---|---|---|
committer | Senya <senya@riseup.net> | 2016-08-20 23:00:56 +0000 |
commit | b7ae42889643058e5014416c47752f48b1fc1f51 (patch) | |
tree | 44ef7f6207e87a493497b9aada02048ae47a03c3 | |
parent | 7a73b11f2a342ee25da00299b27ef8bfd6c2d453 (diff) | |
download | pidgin-b7ae42889643058e5014416c47752f48b1fc1f51.tar.gz |
Fix issue #4753 with IRC message truncation
This patch changes function irc_cmd_privmsg so that it splits a
message to parts and sends them one by one, thus avoiding the limit
of 512 bytes in a message of IRC protocol, like all modern IRC clients
do.
see https://developer.pidgin.im/ticket/4753
-rw-r--r-- | libpurple/protocols/irc/cmds.c | 22 | ||||
-rw-r--r-- | libpurple/protocols/irc/irc.h | 2 |
2 files changed, 21 insertions, 3 deletions
diff --git a/libpurple/protocols/irc/cmds.c b/libpurple/protocols/irc/cmds.c index 99caf6b3f8..0cc5ae2231 100644 --- a/libpurple/protocols/irc/cmds.c +++ b/libpurple/protocols/irc/cmds.c @@ -422,18 +422,29 @@ int irc_cmd_ping(struct irc_conn *irc, const char *cmd, const char *target, cons int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, const char **args) { + int max_privmsg_arg_len; const char *cur, *end; + gchar *salvaged; char *msg, *buf; if (!args || !args[0] || !args[1]) return 0; - cur = args[1]; - end = args[1]; + max_privmsg_arg_len = IRC_MAX_MSG_SIZE - strlen(args[0]) - 64; + salvaged = purple_utf8_salvage(args[1]); + cur = salvaged; + end = salvaged; while (*end && *cur) { end = strchr(cur, '\n'); if (!end) end = cur + strlen(cur); + if (end - cur > max_privmsg_arg_len) { + /* this call is used to find the last valid character position in the first + * max_privmsg_arg_len bytes of the utf-8 message + */ + g_utf8_validate(cur, max_privmsg_arg_len, &end); + } + msg = g_strndup(cur, end - cur); if(!strcmp(cmd, "notice")) @@ -444,9 +455,14 @@ int irc_cmd_privmsg(struct irc_conn *irc, const char *cmd, const char *target, c irc_send(irc, buf); g_free(msg); g_free(buf); - cur = end + 1; + cur = end; + if(*cur == '\n') { + cur++; + } } + g_free(salvaged); + return 0; } diff --git a/libpurple/protocols/irc/irc.h b/libpurple/protocols/irc/irc.h index 46c09ee6e2..6c1864d7da 100644 --- a/libpurple/protocols/irc/irc.h +++ b/libpurple/protocols/irc/irc.h @@ -55,6 +55,8 @@ #define IRC_INITIAL_BUFSIZE 1024 +#define IRC_MAX_MSG_SIZE 512 + #define IRC_NAMES_FLAG "irc-namelist" enum { IRC_USEROPT_SERVER, IRC_USEROPT_PORT, IRC_USEROPT_CHARSET }; |