From dec490ce5f6902cf3ab4bab537d0f460f3e1a047 Mon Sep 17 00:00:00 2001 From: Daniel Kamil Kozar Date: Tue, 20 Feb 2018 19:18:08 +0100 Subject: Write valid HTML log files This patch makes the libpurple HTML log writer create HTML log files which are valid HTML. The simplest log created before the patch caused the W3C Validator to return 1 error and 3 warnings, while the patched version validates without errors or warnings. All credit goes to the original patch author, stars (ticket 17280). --- libpurple/log.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/libpurple/log.c b/libpurple/log.c index ea583fce48..2949f2c8f9 100644 --- a/libpurple/log.c +++ b/libpurple/log.c @@ -1395,8 +1395,8 @@ static gsize html_logger_write(PurpleLog *log, PurpleMessageFlags type, date = purple_date_format_full(localtime(&log->time)); - written += fprintf(data->file, ""); - written += fprintf(data->file, ""); + written += fprintf(data->file, "\n\n\n"); + written += fprintf(data->file, ""); written += fprintf(data->file, ""); if (log->type == PURPLE_LOG_SYSTEM) header = g_strdup_printf("System log for account %s (%s) connected at %s", @@ -1406,8 +1406,8 @@ static gsize html_logger_write(PurpleLog *log, PurpleMessageFlags type, log->name, date, purple_account_get_username(log->account), prpl); written += fprintf(data->file, "%s", header); - written += fprintf(data->file, ""); - written += fprintf(data->file, "

%s

\n", header); + written += fprintf(data->file, "\n\n\n"); + written += fprintf(data->file, "

%s

\n

\n", header); g_free(header); } @@ -1428,39 +1428,39 @@ static gsize html_logger_write(PurpleLog *log, PurpleMessageFlags type, date = log_get_timestamp(log, time); if(log->type == PURPLE_LOG_SYSTEM){ - written += fprintf(data->file, "---- %s @ %s ----
\n", msg_fixed, date); + written += fprintf(data->file, "---- %s @ %s ----
\n", msg_fixed, date); } else { if (type & PURPLE_MESSAGE_SYSTEM) - written += fprintf(data->file, "(%s) %s
\n", date, msg_fixed); + written += fprintf(data->file, "(%s) %s
\n", date, msg_fixed); else if (type & PURPLE_MESSAGE_RAW) - written += fprintf(data->file, "(%s) %s
\n", date, msg_fixed); + written += fprintf(data->file, "(%s) %s
\n", date, msg_fixed); else if (type & PURPLE_MESSAGE_ERROR) - written += fprintf(data->file, "(%s) %s
\n", date, msg_fixed); + written += fprintf(data->file, "(%s) %s
\n", date, msg_fixed); else if (type & PURPLE_MESSAGE_WHISPER) - written += fprintf(data->file, "(%s) %s: %s
\n", + written += fprintf(data->file, "(%s) %s: %s
\n", date, escaped_from, msg_fixed); else if (type & PURPLE_MESSAGE_AUTO_RESP) { if (type & PURPLE_MESSAGE_SEND) - written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s
\n"), date, escaped_from, msg_fixed); + written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s
\n"), date, escaped_from, msg_fixed); else if (type & PURPLE_MESSAGE_RECV) - written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s
\n"), date, escaped_from, msg_fixed); + written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s
\n"), date, escaped_from, msg_fixed); } else if (type & PURPLE_MESSAGE_RECV) { if(purple_message_meify(msg_fixed, -1)) - written += fprintf(data->file, "(%s) ***%s %s
\n", + written += fprintf(data->file, "(%s) ***%s %s
\n", date, escaped_from, msg_fixed); else - written += fprintf(data->file, "(%s) %s: %s
\n", + written += fprintf(data->file, "(%s) %s: %s
\n", date, escaped_from, msg_fixed); } else if (type & PURPLE_MESSAGE_SEND) { if(purple_message_meify(msg_fixed, -1)) - written += fprintf(data->file, "(%s) ***%s %s
\n", + written += fprintf(data->file, "(%s) ***%s %s
\n", date, escaped_from, msg_fixed); else - written += fprintf(data->file, "(%s) %s: %s
\n", + written += fprintf(data->file, "(%s) %s: %s
\n", date, escaped_from, msg_fixed); } else { purple_debug_error("log", "Unhandled message type.\n"); - written += fprintf(data->file, "(%s) %s: %s
\n", + written += fprintf(data->file, "(%s) %s: %s
\n", date, escaped_from, msg_fixed); } } @@ -1477,7 +1477,7 @@ static void html_logger_finalize(PurpleLog *log) PurpleLogCommonLoggerData *data = log->logger_data; if (data) { if(data->file) { - fprintf(data->file, "\n"); + fprintf(data->file, "

\n\n\n"); fclose(data->file); } g_free(data->path); -- cgit v1.2.1 From 49a5d27635ca37342875df13405a816a2b669935 Mon Sep 17 00:00:00 2001 From: Daniel Kamil Kozar Date: Wed, 9 Oct 2019 20:39:11 +0200 Subject: Restore compatibility with gtkimhtml.c gtkimhtml.c treats the first line of the message specially, and the previously introduced changes caused problems with displaying conversation logs when saved in HTML, exactly due to changing where the newlines are stored inside the file. I believe this change brings the best of both worlds by changing the significant part of the HTML markup so the validator is happy, and keeping the stuff that gtkimhtml.c needs in the first line. --- libpurple/log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libpurple/log.c b/libpurple/log.c index 2949f2c8f9..6b912b12ae 100644 --- a/libpurple/log.c +++ b/libpurple/log.c @@ -1395,7 +1395,7 @@ static gsize html_logger_write(PurpleLog *log, PurpleMessageFlags type, date = purple_date_format_full(localtime(&log->time)); - written += fprintf(data->file, "\n\n\n"); + written += fprintf(data->file, ""); written += fprintf(data->file, ""); written += fprintf(data->file, ""); if (log->type == PURPLE_LOG_SYSTEM) @@ -1406,8 +1406,8 @@ static gsize html_logger_write(PurpleLog *log, PurpleMessageFlags type, log->name, date, purple_account_get_username(log->account), prpl); written += fprintf(data->file, "%s", header); - written += fprintf(data->file, "\n\n\n"); - written += fprintf(data->file, "

%s

\n

\n", header); + written += fprintf(data->file, ""); + written += fprintf(data->file, "

%s

\n", header); g_free(header); } -- cgit v1.2.1