degesch: allow unterminated CTCP messages

This commit is contained in:
Přemysl Eric Janouch 2015-07-19 23:57:36 +02:00
parent 553f06d3ec
commit b750590f18
1 changed files with 13 additions and 7 deletions

View File

@ -741,6 +741,7 @@ struct ctcp_chunk
LIST_HEADER (struct ctcp_chunk) LIST_HEADER (struct ctcp_chunk)
bool is_extended; ///< Is this a tagged extended message? bool is_extended; ///< Is this a tagged extended message?
bool is_partial; ///< Unterminated extended message
struct str tag; ///< The tag, if any struct str tag; ///< The tag, if any
struct str text; ///< Message contents struct str text; ///< Message contents
}; };
@ -838,6 +839,9 @@ ctcp_parse (const char *message)
struct ctcp_chunk *result = NULL, *result_tail = NULL; 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; size_t start = 0;
bool in_ctcp = false; bool in_ctcp = false;
for (size_t i = 0; i < m.len; i++) 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); LIST_APPEND_WITH_TAIL (result, result_tail, chunk);
} }
// Finish the last text part. We ignore unended tagged chunks. // Finish the last part. Unended tagged chunks are marked as such.
// TODO: don't ignore them, e.g. a /me may get cut off if (start != m.len)
if (!in_ctcp && start != m.len)
{ {
struct ctcp_chunk *chunk = ctcp_chunk_new (); struct ctcp_chunk *chunk = ctcp_chunk_new ();
// According to the original CTCP specification we should use if (in_ctcp)
// ctcp_intra_decode() but no one seems to use that and it breaks {
// normal text with backslashes ctcp_parse_tagged (m.str + start, m.len - start, chunk);
str_append_data (&chunk->text, m.str + start, m.len - start); chunk->is_partial = true;
}
else
str_append_data (&chunk->text, m.str + start, m.len - start);
LIST_APPEND_WITH_TAIL (result, result_tail, chunk); LIST_APPEND_WITH_TAIL (result, result_tail, chunk);
} }