From: <ro...@us...> - 2006-07-04 23:14:38
|
Revision: 16427 Author: roast Date: 2006-07-04 16:14:32 -0700 (Tue, 04 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16427&view=rev Log Message: ----------- txt_logger now uses giochannels too; txt_logger_writer bug now frees all data when it prematurely exists; removed gaim_common_log_writer's compensating checking 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:51:43 UTC (rev 16426) +++ branches/soc-2006-file-loggers/src/log.c 2006-07-04 23:14:32 UTC (rev 16427) @@ -720,15 +720,9 @@ log->logger_data = data = g_slice_new0(GaimLogCommonLoggerData); - if (current_logger == xml_logger || current_logger == html_logger) { - data->channel = g_io_channel_new_file(path, "w+", NULL); - } - else { - data->file = g_fopen(path, "w+"); - } + data->channel = g_io_channel_new_file(path, "w+", NULL); - // they can't be /both/ null - if (data->channel == NULL && data->file == NULL) { + if (data->channel == NULL) { gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", path); @@ -1420,9 +1414,11 @@ GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); GaimLogCommonLoggerData *data = log->logger_data; char *stripped = NULL; + gsize written = 0, written_buf = 0; + GString *writebuf = g_string_new(""); + GIOStatus iostat; + GError *gerror = NULL; - gsize written = 0; - if (data == NULL) { /* 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 @@ -1435,58 +1431,75 @@ 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; if (log->type == GAIM_LOG_SYSTEM) - written += fprintf(data->file, "System log for account %s (%s) connected at %s\n", - gaim_account_get_username(log->account), prpl, - gaim_date_format_full(localtime(&log->time))); + g_string_printf(writebuf, "System log for account %s (%s) connected at %s\n", + gaim_account_get_username(log->account), prpl, + gaim_date_format_full(localtime(&log->time))); else - written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", - log->name, gaim_date_format_full(localtime(&log->time)), - gaim_account_get_username(log->account), prpl); + g_string_printf(writebuf, "Conversation with %s at %s on %s (%s)\n", + log->name, gaim_date_format_full(localtime(&log->time)), + gaim_account_get_username(log->account), prpl); + + 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; + } + else 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; stripped = gaim_markup_strip_html(message); date = log_get_timestamp(log, time); if(log->type == GAIM_LOG_SYSTEM){ - written += fprintf(data->file, "---- %s @ %s ----\n", stripped, date); - } else { - if (type & GAIM_MESSAGE_SEND || - type & GAIM_MESSAGE_RECV) { - if (type & GAIM_MESSAGE_AUTO_RESP) { - written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, - from, stripped); - } else { - if(gaim_message_meify(stripped, -1)) - written += fprintf(data->file, "(%s) ***%s %s\n", date, from, - stripped); - else - written += fprintf(data->file, "(%s) %s: %s\n", date, from, - stripped); - } - } else if (type & GAIM_MESSAGE_SYSTEM) - written += fprintf(data->file, "(%s) %s\n", date, stripped); - else if (type & GAIM_MESSAGE_NO_LOG) { - /* This shouldn't happen */ - g_free(stripped); - return written; - } else if (type & GAIM_MESSAGE_WHISPER) - written += fprintf(data->file, "(%s) *%s* %s", date, from, stripped); + g_string_printf(writebuf, "---- %s @ %s ----\n", stripped, date); + } else if (type & GAIM_MESSAGE_SEND || type & GAIM_MESSAGE_RECV) { + if (type & GAIM_MESSAGE_AUTO_RESP) + g_string_printf(writebuf, _("(%s) %s <AUTO-REPLY>: %s\n"), date, from, stripped); + else if(gaim_message_meify(stripped, -1)) + g_string_printf(writebuf, "(%s) ***%s %s\n", date, from, stripped); else - written += fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", - from ? ":" : "", stripped); - } + g_string_printf(writebuf, "(%s) %s: %s\n", date, from, stripped); + } else if (type & GAIM_MESSAGE_SYSTEM) + g_string_printf(writebuf, "(%s) %s\n", date, stripped); + else if (type & GAIM_MESSAGE_NO_LOG) { + /* This shouldn't happen */ + g_free(date); + g_free(stripped); + g_string_free(writebuf, TRUE); + return written; + } else if (type & GAIM_MESSAGE_WHISPER) + g_string_printf(writebuf, "(%s) *%s* %s", date, from, stripped); + else + g_string_printf(writebuf, "(%s) %s%s %s\n", date, from ? from : "", from ? ":" : "", stripped); + g_free(date); g_free(stripped); - 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", "txt_logger_write could not write the message to the logfile: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + else written += written_buf; + + iostat = g_io_channel_flush(data->channel, &gerror); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log", "txt_logger_write could not flush the logfile: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + + g_string_free(writebuf, TRUE); return written; } @@ -1494,8 +1507,17 @@ { GaimLogCommonLoggerData *data = log->logger_data; if (data) { - if(data->file) - fclose(data->file); + if(data->channel) { + GIOStatus iostat; + 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", "txt_logger_finalize could not shutdown the logfile: %s\n", gerror->message); + g_error_free(gerror); + gerror = NULL; + } + } if(data->path) g_free(data->path); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |