From: <ro...@us...> - 2006-07-04 22:45:54
|
Revision: 16425 Author: roast Date: 2006-07-04 15:45:48 -0700 (Tue, 04 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16425&view=rev Log Message: ----------- html_logger now writes using giochannel Modified Paths: -------------- branches/soc-2006-file-loggers/src/log.c Modified: branches/soc-2006-file-loggers/src/log.c =================================================================== --- branches/soc-2006-file-loggers/src/log.c 2006-07-04 22:32:05 UTC (rev 16424) +++ branches/soc-2006-file-loggers/src/log.c 2006-07-04 22:45:48 UTC (rev 16425) @@ -720,7 +720,7 @@ log->logger_data = data = g_slice_new0(GaimLogCommonLoggerData); - if (current_logger == xml_logger) { + if (current_logger == xml_logger || current_logger == html_logger) { data->channel = g_io_channel_new_file(path, "w+", NULL); } else { @@ -1234,87 +1234,112 @@ { char *msg_fixed; char *date; - char *header; GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); GaimLogCommonLoggerData *data = log->logger_data; - gsize written = 0; + gsize written = 0, written_buf = 0; + GString *writebuf = g_string_new(""); + GIOStatus iostat; + GError *gerror = NULL; if(!data) { const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); const char *date; + char *header; + gaim_log_common_writer(log, ".html"); data = log->logger_data; /* if we can't write to the file, give up before we hurt ourselves */ - if(!data->file) + if(!data->channel) return 0; date = gaim_date_format_full(localtime(&log->time)); - written += fprintf(data->file, "<html><head>"); - written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"); - written += fprintf(data->file, "<title>"); + g_string_printf(writebuf, + "<html><head>" + "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">" + "<title>"); + if (log->type == GAIM_LOG_SYSTEM) header = g_strdup_printf("System log for account %s (%s) connected at %s", gaim_account_get_username(log->account), prpl, date); else header = g_strdup_printf("Conversation with %s at %s on %s (%s)", - log->name, date, gaim_account_get_username(log->account), prpl); + log->name, date, gaim_account_get_username(log->account), prpl); - written += fprintf(data->file, "%s", header); - written += fprintf(data->file, "</title></head><body>"); - written += fprintf(data->file, "<h3>%s</h3>\n", header); + g_string_append_printf(writebuf, "%s" "</title></head><body>" "<h3>%s</h3>\n", header, header); g_free(header); + + iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, &written_buf, &gerror); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log", "html_logger_write could not write to a new file: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + written += written_buf; } /* if we can't write to the file, give up before we hurt ourselves */ - if(!data->file) + if(!data->channel) return 0; gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); date = log_get_timestamp(log, time); if(log->type == GAIM_LOG_SYSTEM){ - written += fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); + g_string_printf(writebuf, "---- %s @ %s ----<br/>\n", msg_fixed, date); + } else if (type & GAIM_MESSAGE_SYSTEM) + g_string_printf(writebuf, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); + else if (type & GAIM_MESSAGE_ERROR) + g_string_printf(writebuf, "<font color=\"#FF0000\"><font size=\"2\">(%s)</font><b> %s</b></font><br/>\n", date, msg_fixed); + else if (type & GAIM_MESSAGE_WHISPER) + g_string_printf(writebuf, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", + date, from, msg_fixed); + else if (type & GAIM_MESSAGE_AUTO_RESP) { + if (type & GAIM_MESSAGE_SEND) + g_string_printf(writebuf, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); + else if (type & GAIM_MESSAGE_RECV) + g_string_printf(writebuf, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); + } else if (type & GAIM_MESSAGE_RECV) { + if(gaim_message_meify(msg_fixed, -1)) + g_string_printf(writebuf, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", + date, from, msg_fixed); + else + g_string_printf(writebuf, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", + date, from, msg_fixed); + } else if (type & GAIM_MESSAGE_SEND) { + if(gaim_message_meify(msg_fixed, -1)) + g_string_printf(writebuf, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", + date, from, msg_fixed); + else + g_string_printf(writebuf, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", + date, from, msg_fixed); } else { - if (type & GAIM_MESSAGE_SYSTEM) - written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); - else if (type & GAIM_MESSAGE_ERROR) - written += fprintf(data->file, "<font color=\"#FF0000\"><font size=\"2\">(%s)</font><b> %s</b></font><br/>\n", date, msg_fixed); - else if (type & GAIM_MESSAGE_WHISPER) - written += fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", - date, from, msg_fixed); - else if (type & GAIM_MESSAGE_AUTO_RESP) { - if (type & GAIM_MESSAGE_SEND) - written += fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); - else if (type & GAIM_MESSAGE_RECV) - written += fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); - } else if (type & GAIM_MESSAGE_RECV) { - if(gaim_message_meify(msg_fixed, -1)) - written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", - date, from, msg_fixed); - else - written += fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", - date, from, msg_fixed); - } else if (type & GAIM_MESSAGE_SEND) { - if(gaim_message_meify(msg_fixed, -1)) - written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", - date, from, msg_fixed); - else - written += fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", - date, from, msg_fixed); - } else { - gaim_debug_error("log", "Unhandled message type."); - written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", - date, from, msg_fixed); - } + gaim_debug_error("log", "Unhandled message type."); + g_string_printf(writebuf, "<font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", + date, from, msg_fixed); } g_free(date); g_free(msg_fixed); - fflush(data->file); + iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, &written_buf, &gerror); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log", "html_logger_write could not write the message to the logfile: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + written += written_buf; + + iostat = g_io_channel_flush(data->channel, &gerror); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log", "xml_logger_write could not flush the logfile: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + + g_string_free(writebuf, TRUE); return written; } @@ -1322,9 +1347,24 @@ { GaimLogCommonLoggerData *data = log->logger_data; if (data) { - if(data->file) { - fprintf(data->file, "</body></html>\n"); - fclose(data->file); + if(data->channel) { + GIOStatus iostat; + GError *gerror = NULL; + + iostat = g_io_channel_write_chars(data->channel, "</body></html>\n", -1, NULL, &gerror); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log", "html_logger_finalize could not write the tail: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + + iostat = g_io_channel_shutdown(data->channel, TRUE, &gerror); // this may cause hanging + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log", "html_logger_finalize could not shutdown the logfile: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + } g_free(data->path); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |