diff options
author | Sebastian Thorarensen <sebth@naju.se> | 2014-06-13 06:39:02 +0200 |
---|---|---|
committer | Sebastian Thorarensen <sebth@naju.se> | 2014-07-06 23:24:09 +0200 |
commit | e6147fb8f2764392dd685fd8b28f1d69527609cd (patch) | |
tree | f24e6037b6bd3ac4b1d73949e0f82325a31e26ac /src/core/misc.c | |
parent | 43baf71efd8d7323a2d6ae939c3c6350fef70f72 (diff) | |
download | irssi-e6147fb8f2764392dd685fd8b28f1d69527609cd.zip |
Properly split long IRC messages
This commit adds handling of long IRC messages to the core. In contrast
to the `splitlong.pl' plugin, multi-byte encoded and recoded messages
are properly split.
To allow for this, a new function has been added to the server struct:
`split_message'. `split_message' returns a string array with the message
splitted to substrings of a length that the server can handle. If a
protocol module doesn't have any limit, it can simply return a singleton
array with a copy of the message.
The `MSG' chat command now calls `split_message' before `send_message',
and emits `message own_public' / `message own_private' with each
substring, so that the string splitting will be visible in the UI.
`split_message' in the IRC module uses `recode_split' which in turn uses
iconv to properly split multi-byte encoded (and recoded) messages.
Diffstat (limited to 'src/core/misc.c')
-rw-r--r-- | src/core/misc.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/core/misc.c b/src/core/misc.c index 8d821ecc..19789f64 100644 --- a/src/core/misc.c +++ b/src/core/misc.c @@ -966,3 +966,20 @@ char *ascii_strdown(char *str) *s = g_ascii_tolower (*s); return str; } + +char **strsplit_len(const char *str, int len) +{ + char **ret; + int n = strlen(str) / len; + int i; + + if (strlen(str) % len) + n++; + + ret = g_new(char *, n + 1); + for (i = 0; i < n; i++, str += len) + ret[i] = g_strndup(str, len); + ret[n] = NULL; + + return ret; +} |