aboutsummaryrefslogtreecommitdiff
path: root/xC.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-10 18:48:15 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-10 18:51:27 +0200
commit7d5e63be1fd6602ab8e62316202924b316c7436f (patch)
tree035bed03f6b4e8041c106d023bf6310f5c588f78 /xC.c
parente7d0f2380eb00610d335d87dd0656e50840aa8c0 (diff)
downloadxK-7d5e63be1fd6602ab8e62316202924b316c7436f.tar.gz
xK-7d5e63be1fd6602ab8e62316202924b316c7436f.tar.xz
xK-7d5e63be1fd6602ab8e62316202924b316c7436f.zip
xC: deal with so far unexpected multiline messages
And get rid of an outdated unmarked TODO comment.
Diffstat (limited to 'xC.c')
-rw-r--r--xC.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/xC.c b/xC.c
index eedb769..c440abc 100644
--- a/xC.c
+++ b/xC.c
@@ -9075,12 +9075,21 @@ irc_autosplit_message (struct server *s, const char *message,
- 1 - (int) strlen (s->irc_user_host)
- 1 - fixed_part;
- // However we don't always have the full info for message splitting
- if (!space_in_one_message)
- strv_append (output, message);
- else if (!wrap_message (message, space_in_one_message, output, e))
- return false;
- return true;
+ // Multiline messages can be triggered through hooks and plugins.
+ struct strv lines = strv_make ();
+ cstr_split (message, "\r\n", false, &lines);
+ bool success = true;
+ for (size_t i = 0; i < lines.len; i++)
+ {
+ // We don't always have the full info for message splitting.
+ if (!space_in_one_message)
+ strv_append (output, lines.vector[i]);
+ else if (!(success =
+ wrap_message (lines.vector[i], space_in_one_message, output, e)))
+ break;
+ }
+ strv_free (&lines);
+ return success;
}
static void
@@ -9089,12 +9098,11 @@ send_autosplit_message (struct server *s,
const char *prefix, const char *suffix)
{
struct buffer *buffer = str_map_find (&s->irc_buffer_map, target);
+
+ // "COMMAND target * :prefix*suffix"
int fixed_part = strlen (command) + 1 + strlen (target) + 1 + 1
+ strlen (prefix) + strlen (suffix);
- // We might also want to preserve attributes across splits but
- // that would make this code a lot more complicated
-
struct strv lines = strv_make ();
struct error *e = NULL;
if (!irc_autosplit_message (s, message, fixed_part, &lines, &e))