From: <ro...@us...> - 2006-08-02 02:23:10
|
Revision: 16611 Author: roast Date: 2006-08-01 19:23:04 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16611&view=rev Log Message: ----------- log_reader: adium_logger_read() now uses giochannels Modified Paths: -------------- branches/soc-2006-file-loggers/plugins/log_reader.c Modified: branches/soc-2006-file-loggers/plugins/log_reader.c =================================================================== --- branches/soc-2006-file-loggers/plugins/log_reader.c 2006-08-01 19:52:51 UTC (rev 16610) +++ branches/soc-2006-file-loggers/plugins/log_reader.c 2006-08-02 02:23:04 UTC (rev 16611) @@ -238,51 +238,57 @@ static char *adium_logger_read (GaimLog *log, GaimLogReadFlags *flags) { struct adium_logger_data *data; - GError *error = NULL; gchar *read = NULL; - gsize length; + int filedes = 0; + GIOChannel *channel; + + // covered by gaim_log_read g_return_val_if_fail(log != NULL, g_strdup("")); data = log->logger_data; - g_return_val_if_fail(data->path != NULL, g_strdup("")); + g_return_val_if_fail(data->path != NULL, g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>"))); - gaim_debug(GAIM_DEBUG_INFO, "Adium log read", - "Reading %s\n", data->path); - if (!g_file_get_contents(data->path, &read, &length, &error)) { - gaim_debug(GAIM_DEBUG_ERROR, "Adium log read", - "Error reading log\n"); - if (error) - g_error_free(error); - return g_strdup(""); - } + gaim_debug(GAIM_DEBUG_INFO, "Adium log read", "Reading %s\n", data->path); - if (data->type != ADIUM_HTML) { - char *escaped = g_markup_escape_text(read, -1); - g_free(read); - read = escaped; - } + if ((filedes = open(data->path, O_RDONLY))) { + channel = g_io_channel_unix_new(filedes); + if (g_io_channel_read_to_end(channel, &read, NULL, NULL) == G_IO_STATUS_NORMAL) { + if (data->type != ADIUM_HTML) { + char *escaped = g_markup_escape_text(read, -1); + g_free(read); + read = escaped; + } + #ifdef WIN32 - /* This problem only seems to show up on Windows. - * The BOM is displaying as a space at the beginning of the log. - */ - if (gaim_str_has_prefix(read, "\xef\xbb\xbf")) - { - /* FIXME: This feels so wrong... */ - char *temp = g_strdup(&(read[3])); - g_free(read); - read = temp; - } + /* This problem only seems to show up on Windows. + * The BOM is displaying as a space at the beginning of the log. + */ + if (gaim_str_has_prefix(read, "\xef\xbb\xbf")) { + /* FIXME: This feels so wrong... */ + char *temp = g_strdup(&(read[3])); + g_free(read); + read = temp; + } #endif - /* TODO: Apply formatting. - * Replace the above hack with something better, since we'll - * be looping over the entire log file contents anyway. - */ + /* TODO: Apply formatting. + * Replace the above hack with something better, since we'll + * be looping over the entire log file contents anyway. + */ - return read; + g_io_channel_shutdown(channel, FALSE, NULL); + close(filedes); + return read; + } + + close(filedes); // closed when g_io_channel_unix_new fails + } + + gaim_debug(GAIM_DEBUG_ERROR, "Adium log read", "Error reading log\n"); + return g_strdup_printf(_("<font color=\"red\"><b>Could not read Adium log file: %s</b></font>"), data->path); } static int adium_logger_size (GaimLog *log) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ro...@us...> - 2006-08-02 02:42:19
|
Revision: 16612 Author: roast Date: 2006-08-01 19:42:14 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16612&view=rev Log Message: ----------- log_reader: trillian_logger_read() now uses giochannels Modified Paths: -------------- branches/soc-2006-file-loggers/plugins/log_reader.c Modified: branches/soc-2006-file-loggers/plugins/log_reader.c =================================================================== --- branches/soc-2006-file-loggers/plugins/log_reader.c 2006-08-02 02:23:04 UTC (rev 16611) +++ branches/soc-2006-file-loggers/plugins/log_reader.c 2006-08-02 02:42:14 UTC (rev 16612) @@ -1279,7 +1279,9 @@ { struct trillian_logger_data *data; char *read; - FILE *file; + int filedes = 0; + GIOChannel *channel; + GIOStatus iostat; GaimBuddy *buddy; char *escaped; GString *formatted; @@ -1299,10 +1301,33 @@ read = g_malloc(data->length + 2); - file = g_fopen(data->path, "rb"); - fseek(file, data->offset, SEEK_SET); - fread(read, data->length, 1, file); - fclose(file); + // try to open the file + if (!(filedes = open(data->path, O_RDONLY))) { + return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); + } + // create the giochannel + channel = g_io_channel_unix_new(filedes); + // read from it + if (g_io_channel_read_to_end(channel, &read, NULL, NULL) != G_IO_STATUS_NORMAL) { + // if reading the file wasn't successful... + close(filedes); + return g_strdup("Trillian Log Failed to read the file"); + } + // seek to the right position + iostat = g_io_channel_seek_position(channel, data->offset, G_SEEK_SET, NULL); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log_reader", "trillian_logger_read could not seek to the right place to read data from\n"); + return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); + } + // read data->length long + iostat = g_io_channel_read_chars(channel, read, data->length, NULL, NULL); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log_reader", "trillian_logger_read could not read data from the logfile\n"); + return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); + } + // we're done reading + g_io_channel_shutdown(channel, FALSE, NULL); + close(filedes); if (read[data->length-1] == '\n') { read[data->length] = '\0'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |