mirror of
https://github.com/irssi/irssi.git
synced 2026-08-11 04:43:34 +02:00
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.
This commit is contained in:
parent
43baf71efd
commit
e6147fb8f2
7 changed files with 147 additions and 5 deletions
|
|
@ -102,6 +102,30 @@ static void send_message(SERVER_REC *server, const char *target,
|
|||
g_free(recoded);
|
||||
}
|
||||
|
||||
static char **split_message(SERVER_REC *server, const char *target,
|
||||
const char *msg)
|
||||
{
|
||||
IRC_SERVER_REC *ircserver = IRC_SERVER(server);
|
||||
int userhostlen = 63; /* Maximum length defined by protocol. */
|
||||
|
||||
g_return_val_if_fail(ircserver != NULL, NULL);
|
||||
g_return_val_if_fail(target != NULL, NULL);
|
||||
g_return_val_if_fail(msg != NULL, NULL);
|
||||
|
||||
/*
|
||||
* If we have joined a channel, userhost will be set, so we can
|
||||
* calculate the exact maximum length.
|
||||
*/
|
||||
if (ircserver->userhost != NULL)
|
||||
userhostlen = strlen(ircserver->userhost);
|
||||
|
||||
/* length calculation shamelessly stolen from splitlong.pl */
|
||||
return recode_split(SERVER(server), msg, target,
|
||||
510 - strlen(":! PRIVMSG :") -
|
||||
strlen(ircserver->nick) - userhostlen -
|
||||
strlen(target));
|
||||
}
|
||||
|
||||
static void server_init(IRC_SERVER_REC *server)
|
||||
{
|
||||
IRC_SERVER_CONNECT_REC *conn;
|
||||
|
|
@ -288,6 +312,7 @@ static void sig_connected(IRC_SERVER_REC *server)
|
|||
|
||||
server->isnickflag = isnickflag_func;
|
||||
server->ischannel = ischannel_func;
|
||||
server->split_message = split_message;
|
||||
server->send_message = send_message;
|
||||
server->query_find_func =
|
||||
(QUERY_REC *(*)(SERVER_REC *, const char *)) irc_query_find;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue