/pidgin/main: b76dd48063d6: Fix issue #4753 with IRC message tru...
Senya <[email protected]> Sun, 28 Aug 2016 12:19:48 -0400
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: b76dd48063d6fa9b37f9e210a8dea34c759c8ecf Author: Senya <[email protected]> Date: 2016-08-20 23:00 +0000 Branch: irc-len-fix-bp URL: https://hg.pidgin.im/pidgin/main/rev/b76dd48063d6 Description: 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 diffstat: libpurple/protocols/irc/cmds.c | 22 +++++++++++++++++++--- libpurple/protocols/irc/irc.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diffs (63 lines): diff --git a/libpurple/protocols/irc/cmds.c b/libpurple/protocols/irc/cmds.c --- a/libpurple/protocols/irc/cmds.c +++ b/libpurple/protocols/irc/cmds.c @@ -424,18 +424,29 @@ int irc_cmd_ping(struct irc_conn *irc, c 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")) @@ -446,9 +457,14 @@ int irc_cmd_privmsg(struct irc_conn *irc 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 --- a/libpurple/protocols/irc/irc.h +++ b/libpurple/protocols/irc/irc.h @@ -46,6 +46,8 @@ #define IRC_INITIAL_BUFSIZE 1024 +#define IRC_MAX_MSG_SIZE 512 + #define IRC_NAMES_FLAG "irc-namelist" _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits