aboutsummaryrefslogtreecommitdiff
path: root/common.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-19 23:57:36 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-19 23:58:34 +0200
commitb750590f185158e0bca3a5bdb638ac67b42ed263 (patch)
treea7cbf2bc680b7bbbd84bcc3d14b88760707e55a7 /common.c
parent553f06d3ecdb93a9ddbe6c74d4411cc1d8a642a5 (diff)
downloadxK-b750590f185158e0bca3a5bdb638ac67b42ed263.tar.gz
xK-b750590f185158e0bca3a5bdb638ac67b42ed263.tar.xz
xK-b750590f185158e0bca3a5bdb638ac67b42ed263.zip
degesch: allow unterminated CTCP messages
Diffstat (limited to 'common.c')
-rw-r--r--common.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/common.c b/common.c
index 423bb7e..21842ad 100644
--- a/common.c
+++ b/common.c
@@ -741,6 +741,7 @@ struct ctcp_chunk
LIST_HEADER (struct ctcp_chunk)
bool is_extended; ///< Is this a tagged extended message?
+ bool is_partial; ///< Unterminated extended message
struct str tag; ///< The tag, if any
struct str text; ///< Message contents
};
@@ -838,6 +839,9 @@ ctcp_parse (const char *message)
struct ctcp_chunk *result = NULL, *result_tail = NULL;
+ // According to the original CTCP specification we should use
+ // ctcp_intra_decode() on all parts, however no one seems to
+ // use that and it breaks normal text with backslashes
size_t start = 0;
bool in_ctcp = false;
for (size_t i = 0; i < m.len; i++)
@@ -865,15 +869,17 @@ ctcp_parse (const char *message)
LIST_APPEND_WITH_TAIL (result, result_tail, chunk);
}
- // Finish the last text part. We ignore unended tagged chunks.
- // TODO: don't ignore them, e.g. a /me may get cut off
- if (!in_ctcp && start != m.len)
+ // Finish the last part. Unended tagged chunks are marked as such.
+ if (start != m.len)
{
struct ctcp_chunk *chunk = ctcp_chunk_new ();
- // According to the original CTCP specification we should use
- // ctcp_intra_decode() but no one seems to use that and it breaks
- // normal text with backslashes
- str_append_data (&chunk->text, m.str + start, m.len - start);
+ if (in_ctcp)
+ {
+ ctcp_parse_tagged (m.str + start, m.len - start, chunk);
+ chunk->is_partial = true;
+ }
+ else
+ str_append_data (&chunk->text, m.str + start, m.len - start);
LIST_APPEND_WITH_TAIL (result, result_tail, chunk);
}