From: <ro...@us...> - 2006-07-04 22:22:49
|
Revision: 16423 Author: roast Date: 2006-07-04 15:22:45 -0700 (Tue, 04 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16423&view=rev Log Message: ----------- using GString to build write buffer instead of a static 2048byte block 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:12:58 UTC (rev 16422) +++ branches/soc-2006-file-loggers/src/log.c 2006-07-04 22:22:45 UTC (rev 16423) @@ -1020,10 +1020,12 @@ GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); GaimLogCommonLoggerData *data = log->logger_data; gsize written = 0, written_buf = 0; - char writebuf[4096]; + GString *writebuf; GIOStatus iostat; GError *gerror = NULL; + writebuf = g_string_new(""); + /* This log is new. We could use the loggers 'new' function, but * creating a new file there would result in empty files in the case * that you open a convo with someone, but don't say anything. @@ -1038,14 +1040,14 @@ // if file doesn't exist, die if (!data->channel) return 0; - g_snprintf(writebuf, sizeof(writebuf), - "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" - "<chat service=\"%s\" account=\"%s\" version=\"0.3.1-04\"%s>\n" - "\t<event time=\"%s\" type=\"logStart\" />\n", - prpl, gaim_account_get_username(log->account), - log->type == GAIM_LOG_SYSTEM ? "gaim:logtype=\"system\"" : "", date); + g_string_printf(writebuf, + "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" + "<chat service=\"%s\" account=\"%s\" version=\"0.3.1-04\"%s>\n" + "\t<event time=\"%s\" type=\"logStart\" />\n", + prpl, gaim_account_get_username(log->account), + log->type == GAIM_LOG_SYSTEM ? "gaim:logtype=\"system\"" : "", date); - iostat = g_io_channel_write_chars(data->channel, writebuf, -1, &written_buf, &gerror); + iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, &written_buf, &gerror); if (iostat == G_IO_STATUS_ERROR) { gaim_debug_info("log", "xml_logger_write could not write to new file: %s\n", gerror->message); g_error_free(gerror); @@ -1062,16 +1064,16 @@ gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); if (log->type == GAIM_LOG_SYSTEM) { - g_snprintf(writebuf, sizeof(writebuf), "\t<event time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</event>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<event time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</event>\n", date, from, msg_fixed); } else if (type & GAIM_MESSAGE_SYSTEM) { - g_snprintf(writebuf, sizeof(writebuf), "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"system\">%s</message>\n", date, from, msg_fixed); } else if (type & GAIM_MESSAGE_ERROR) { - g_snprintf(writebuf, sizeof(writebuf), "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"error\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"error\">%s</message>\n", date, from, msg_fixed); } else if (type & GAIM_MESSAGE_WHISPER) { - g_snprintf(writebuf, sizeof(writebuf), "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"whisper\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\" gaim:type=\"whisper\">%s</message>\n", date, from, msg_fixed); } else if (type & GAIM_MESSAGE_AUTO_RESP && (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV)) { gboolean recv_from_self = FALSE; @@ -1085,8 +1087,8 @@ } } - g_snprintf(writebuf, sizeof(writebuf), "\t<message time=\"%s\" sender=\"%s\"%s auto=\"true\">%s</message>\n", - date, from, recv_from_self ? " gaim:self=\"true\"" : "", msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\"%s auto=\"true\">%s</message>\n", + date, from, recv_from_self ? " gaim:self=\"true\"" : "", msg_fixed); } else if (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV) { gboolean recv_from_self = FALSE; @@ -1100,15 +1102,15 @@ } } - g_snprintf(writebuf, sizeof(writebuf), "\t<message time=\"%s\" sender=\"%s\"%s>%s</message>\n", + g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\"%s>%s</message>\n", date, from, recv_from_self ? " gaim:self=\"true\"" : "", msg_fixed); } else { gaim_debug_error("log", "Unhandled message type."); - g_snprintf(writebuf, sizeof(writebuf), "\t<message time=\"%s\" sender=\"%s\">%s</message>\n", date, from, msg_fixed); + g_string_printf(writebuf, "\t<message time=\"%s\" sender=\"%s\">%s</message>\n", date, from, msg_fixed); } - iostat = g_io_channel_write_chars(data->channel, writebuf, -1, &written_buf, &gerror); + iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, &written_buf, &gerror); if (iostat == G_IO_STATUS_ERROR) { gaim_debug_info("log", "xml_logger_write could not the message to the logfile: %s\n", gerror->message); g_error_free(gerror); @@ -1120,12 +1122,12 @@ g_free(msg_fixed); // append suffix to file and seek back to keep a valid XML document out of the user space buffer - g_snprintf(writebuf, sizeof(writebuf), - "\t<event time=\"%s\" type=\"logEnd\" />\n" - "</chat>\n", - gaim_utf8_strftime("%Y-%m-%d %H:%M:%S%z", NULL)); + g_string_printf(writebuf, + "\t<event time=\"%s\" type=\"logEnd\" />\n" + "</chat>\n", + gaim_utf8_strftime("%Y-%m-%d %H:%M:%S%z", NULL)); - iostat = g_io_channel_write_chars(data->channel, writebuf, -1, &written_buf, &gerror); + iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, &written_buf, &gerror); if (iostat == G_IO_STATUS_ERROR) { gaim_debug_info("log", "xml_logger_write could not write the tail to the logfile: %s\n", gerror->message); g_error_free(gerror); @@ -1152,18 +1154,21 @@ static void xml_logger_finalize(GaimLog *log) { GaimLogCommonLoggerData *data = log->logger_data; + if (data) { if (data->channel) { - char writebuf[256]; + GString *writebuf; GIOStatus iostat; GError *gerror = NULL; - g_snprintf(writebuf, sizeof(writebuf), - "\t<event time=\"%s\" type=\"logEnd\" />\n" - "</chat>\n", - gaim_utf8_strftime("%Y-%m-%d %H:%M:%S%z", NULL)); + writebuf = g_string_new(""); - iostat = g_io_channel_write_chars(data->channel, writebuf, -1, NULL, &gerror); + g_string_printf(writebuf, + "\t<event time=\"%s\" type=\"logEnd\" />\n" + "</chat>\n", + gaim_utf8_strftime("%Y-%m-%d %H:%M:%S%z", NULL)); + + iostat = g_io_channel_write_chars(data->channel, writebuf->str, -1, NULL, &gerror); if (iostat == G_IO_STATUS_ERROR) { gaim_debug_info("log", "xml_logger_finalize could not write the tail: %s\n", gerror->message); g_error_free(gerror); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |