cpw.nader.asynclogging-3: d391849d: Made txtlog.c compile without errors

morshed.nader at gmail.com morshed.nader at gmail.com
Tue Jan 11 23:28:12 EST 2011


----------------------------------------------------------------------
Revision: d391849d1a12d2b06369ddbe61863301ae24268e
Parent:   a2b193a64b7890e064a8c48e37b0c2b0f753a329
Author:   morshed.nader at gmail.com
Date:     01/11/11 23:20:38
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/d391849d1a12d2b06369ddbe61863301ae24268e

Changelog: 

Made txtlog.c compile without errors
Updated purple_logs_get_total_size and added purple_log_get_total_size
Fixed purple_html_log_create returning gssize and not gboolean
Updated the #includes in all the log extenders to only use glib-object.h

Changes against parent a2b193a64b7890e064a8c48e37b0c2b0f753a329

  patched  libpurple/htmllog.c
  patched  libpurple/htmllog.h
  patched  libpurple/log.c
  patched  libpurple/log.h
  patched  libpurple/oldlog.h
  patched  libpurple/txtlog.c
  patched  libpurple/txtlog.h

-------------- next part --------------
============================================================
--- libpurple/log.c	424796426e3e320407321fa814e3a278daa110c1
+++ libpurple/log.c	ecd3ffe6abccd197d553c72ad7b33f0eebfda9b4
@@ -1083,15 +1083,53 @@ gssize
 }
 
 gssize
+purple_log_get_total_size(PurpleLog *log, PurpleLogChatType chat_type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
+{
+	PurpleLogClass *class;
+
+	g_return_val_if_fail(PURPLE_IS_LOG(log), -1);
+	g_return_val_if_fail(name != NULL, -1);
+	g_return_val_if_fail(account != NULL, -1); // PURPLE_IS_ACCOUNT(account)
+	
+	if (class->total_size_fn){
+		return class->total_size_fn(log, chat_type, name, account, cancellable, error);
+	} else {
+		GList *logs = purple_log_get_logs(log, chat_type, name, account, cancellable, error);
+		gssize size, total = 0;
+
+		if (logs == NULL)
+			return -1;
+
+		for ( ; logs != NULL; logs = g_list_delete_link(logs, logs)) {
+			PurpleLog *log = logs->data;
+
+			size = purple_log_get_size(log, cancellable, error);
+
+			if (size < 0) {
+				for ( ; logs != NULL; logs = g_list_delete_link(logs, logs))
+					g_object_unref(logs->data);
+
+				return -1;
+			}
+
+			total += size;
+			g_object_unref(log);
+		}
+
+		return total;
+	}
+}
+
+gssize
 purple_logs_get_total_size(PurpleLogChatType chat_type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
 {
 	_purple_logsize_user *lu;
 	gpointer ptrsize;
 	gboolean result;
-	gssize size = 0, total = 0;
+	gssize total = 0;
 
-	g_return_val_if_fail(name != NULL, 0);
-	g_return_val_if_fail(account != NULL, 0);
+	g_return_val_if_fail(name != NULL, -1);
+	g_return_val_if_fail(account != NULL, -1); // PURPLE_IS_ACCOUNT(account)
 
 	lu = g_new(_purple_logsize_user, 1);
 	lu->name = g_strdup(purple_normalize(account, name));
@@ -1112,40 +1150,18 @@ purple_logs_get_total_size(PurpleLogChat
 		guint i;
 
 		for (i = 0; i < array->len; i++) {
-			PurpleLogClass *class;
+			PurpleLog *log;
 			GType log_type = g_array_index(array, GType, i);
+			gssize size;
 
-			class = g_type_class_peek(log_type);
+			log = g_object_new(log_type, NULL);
+			size = purple_log_get_total_size(log, chat_type, name, account, cancellable, error);
+			g_object_unref(log);
 
-			if (class->total_size_fn){
-				size = class->total_size_fn(chat_type, name, account, cancellable, error);
+			if (size < 0)
+				return -1;
 
-				if (size < 0)
-					return -1;
-
-				total += size;
-			} else {
-				GList *logs = purple_logs_get_logs(chat_type, name, account, cancellable, error);
-
-				if (logs == NULL)
-					return -1;
-
-				for ( ; logs != NULL; logs = g_list_delete_link(logs, logs)) {
-					PurpleLog *log = logs->data;
-
-					size = purple_log_get_size(log, cancellable, error);
-
-					if (size < 0) {
-						for ( ; logs != NULL; logs = g_list_delete_link(logs, logs))
-							g_object_unref(logs->data);
-
-						return -1;
-					}
-
-					total += size;
-					g_object_unref(log);
-				}
-			}
+			total += size;
 		}
 
 		// purple_debug_info("log", "HASH(purple_log_get_total_size): write size to hash %i {name = \"%s\"\n}", total, name);
@@ -1172,7 +1188,7 @@ total_size_thread(GSimpleAsyncResult *si
 	gssize size;
 
 	if (class->total_size_fn != NULL) {
-		size = class->total_size_fn(chat_type, name, account, cancellable, &error);
+		size = class->total_size_fn(log, chat_type, name, account, cancellable, &error);
 
 		if (size < 0)
 			g_simple_async_result_set_from_error(simple, error);
============================================================
--- libpurple/log.h	cabb0f6e40e0e58bfc63d830436d43461cadebad
+++ libpurple/log.h	d07ba0d3dff1d7be31f4ec562de6c6efb40fe458
@@ -150,7 +150,7 @@ struct _PurpleLogClass {
 
 	/** Returns the total size of all the logs. If this is undefined a default
 	 *  implementation is used */
-	gssize (* total_size_fn) (PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error);
+	gssize (* total_size_fn) (PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error);
 
 	//log is a dummy, only used to keep track of the class
 	void (* total_size_async) (PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data);
@@ -546,6 +546,7 @@ gssize purple_log_get_size_finish(Purple
  *
  * @return             The size in bytes
  */
+gssize purple_log_get_total_size(PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error);
 gssize purple_logs_get_total_size(PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error);
 
 /**
============================================================
--- libpurple/htmllog.c	a253d66d3d8720b4318defa9bc816e79ea5eafb3
+++ libpurple/htmllog.c	d85cee560a9a42057e30dedfaa5b22d31a02d4e8
@@ -26,16 +26,14 @@
 
 #include "internal.h"
 #include "htmllog.h"
-#include "log.h"
-#include "util.h"
 
 G_DEFINE_TYPE (PurpleHtmlLog, purple_html_log, PURPLE_TYPE_LOG)
 
-static gssize purple_html_log_create(PurpleLog *, GCancellable *, GError **);
+static gboolean purple_html_log_create(PurpleLog *, GCancellable *, GError **);
 static gssize purple_html_log_write(PurpleLog *, PurpleMessageFlags, const gchar *, time_t, const gchar *, GCancellable *, GError **);
 static GList *purple_html_log_list(PurpleLog *, PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
 static gchar *purple_html_log_read(PurpleLog *, PurpleLogReadFlags *, GCancellable *, GError **);
-static gssize purple_html_log_total_size(PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
+static gssize purple_html_log_total_size(PurpleLog *, PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
 static GList *purple_html_log_list_syslog(PurpleLog *, PurpleAccount *, GCancellable *, GError **);
 static void purple_html_log_finalize(GObject *);
 
@@ -73,7 +71,7 @@ purple_html_log_new(PurpleLogChatType ty
 	return purple_log_new(PURPLE_TYPE_HTML_LOG, type, name, account, conv, time, tm);
 }
 
-static gssize
+static gboolean
 purple_html_log_create(PurpleLog *log, GCancellable *cancellable, GError **error)
 {
 	return purple_log_common_writer(log, ".html", cancellable, error);
@@ -303,7 +301,7 @@ static gssize
 }
 
 static gssize
-purple_html_log_total_size(PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
+purple_html_log_total_size(PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
 {
 	return purple_log_common_total_sizer(type, name, account, ".html", cancellable, error);
 }
@@ -344,5 +342,4 @@ purple_html_log_system_uninit(void)
 void
 purple_html_log_system_uninit(void)
 {
-	purple_signals_unregister_by_instance(purple_html_log_system_get_handle());
 }
============================================================
--- libpurple/htmllog.h	49ed99ca59a6f1f6ca3b030589a1a79fe25a2916
+++ libpurple/htmllog.h	c0a404ecb318de42b3d33520de5f2a240714e2cf
@@ -28,7 +28,7 @@
 #ifndef _PURPLE_HTML_LOG_H_
 #define _PURPLE_HTML_LOG_H_
 
-#include <gio/gio.h>
+#include <glib-object.h>
 
 #include "log.h"
 
============================================================
--- libpurple/oldlog.h	83c5a5b2951acd1273c990d0bfd090fe94af2442
+++ libpurple/oldlog.h	e6bd78ef0a4c48035707ef9d0a82529459e32954
@@ -28,7 +28,7 @@
 #ifndef _PURPLE_OLD_LOG_H_
 #define _PURPLE_OLD_LOG_H_
 
-#include <gio/gio.h>
+#include <glib-object.h>
 
 #include "log.h"
 
============================================================
--- libpurple/txtlog.c	10c77fb598b266e130a52a4fee474f0515ffbf82
+++ libpurple/txtlog.c	80facd735d7f5fcb13f4207012b64a11fadc4008
@@ -1,182 +1,102 @@
+/**
+ * @file txtlog.c TXT Logger API
+ * @ingroup core
+ */
 
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
 
-static gchar *process_txt_log(gchar *, gchar *);
+#include "internal.h"
+#include "txtlog.h"
 
+G_DEFINE_TYPE (PurpleTxtLog, purple_txt_log, PURPLE_TYPE_LOG)
 
-static gsize txt_logger_write(PurpleLog *, PurpleMessageFlags, const gchar *, time_t,
-	const gchar *);
-static void txt_logger_write_thread(GSimpleAsyncResult *, GObject *, GCancellable *);
-static void txt_logger_write_async(PurpleLog *, PurpleMessageFlags, const gchar *, time_t,
-	const gchar *, gint, GCancellable *, GAsyncReadyCallback, gpointer);
-static void txt_logger_finalize(PurpleLog *);
-static GList *txt_logger_list(PurpleLogType, const gchar *, PurpleAccount *);
-static void txt_logger_list_async(PurpleLogType, const gchar *, PurpleAccount *,
-	gint, GCancellable *, GAsyncReadyCallback, gpointer);
-static GList *txt_logger_list_syslog(PurpleAccount *);
-static void txt_logger_list_syslog_async(PurpleAccount *, gint, GCancellable *,
-	GAsyncReadyCallback, gpointer);
-static gchar *txt_logger_read(PurpleLog *, PurpleLogReadFlags *);
-static void txt_logger_read_thread(GSimpleAsyncResult *, GObject *, GCancellable *);
-static void txt_logger_read_async(PurpleLog *, PurpleLogReadFlags *, gint, GCancellable *,
-	GAsyncReadyCallback, gpointer);
-static gint txt_logger_total_size(PurpleLogType, const gchar *, PurpleAccount *);
-static void txt_logger_total_size_async(PurpleLogType, const gchar *, PurpleAccount *,
-	gint, GCancellable *, GAsyncReadyCallback, gpointer);
+static gboolean purple_txt_log_create(PurpleLog *, GCancellable *, GError **);
+static gssize purple_txt_log_write(PurpleLog *, PurpleMessageFlags, const gchar *, time_t, const gchar *, GCancellable *, GError **);
+static GList *purple_txt_log_list(PurpleLog *, PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
+static gchar *process_txt_log(gchar *, gchar *);
+static gchar *purple_txt_log_read(PurpleLog *, PurpleLogReadFlags *, GCancellable *, GError **);
+static gssize purple_txt_log_total_size(PurpleLog *, PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
+static GList *purple_txt_log_list_syslog(PurpleLog *, PurpleAccount *, GCancellable *, GError **);
+static void purple_txt_log_finalize(GObject *);
 
-
-
-
-
-
-
-
-
-
-
-
-static gchar *
-process_txt_log(gchar *txt, gchar *to_free)
+static void
+purple_txt_log_class_init(PurpleTxtLogClass *class)
 {
-	gchar *tmp;
+	GObjectClass *gobject_class = G_OBJECT_CLASS(class);
+	PurpleLogClass *log_class = PURPLE_LOG_CLASS(class);
 
-	/* The to_free argument allows us to save a
-	 * g_strdup() in some cases. */
+	log_class->logger_name = _("TXT");
+	log_class->logger_id = "txt";
 
-	if (to_free == NULL)
-		to_free = txt;
+	log_class->create_fn = purple_txt_log_create;
+	log_class->write_fn = purple_txt_log_write;
+	log_class->list_fn = purple_txt_log_list;
+	log_class->read_fn = purple_txt_log_read;
+	log_class->size_fn = purple_log_common_sizer;
+	log_class->total_size_fn = purple_txt_log_total_size;
+	log_class->list_syslog_fn = purple_txt_log_list_syslog;
+	log_class->is_removable_fn = purple_log_common_is_removable;
+	log_class->remove_fn = purple_log_common_remover;
 
-	/* g_markup_escape_text requires valid UTF-8 */
-	if (!g_utf8_validate(txt, -1, NULL))
-	{
-		tmp = purple_utf8_salvage(txt);
-		g_free(to_free);
-		to_free = txt = tmp;
-	}
-
-	tmp = g_markup_escape_text(txt, -1);
-	g_free(to_free);
-	txt = purple_markup_linkify(tmp);
-	g_free(tmp);
-
-	return txt;
+	gobject_class->finalize = purple_txt_log_finalize;
 }
 
-
-
-
-
-
-/****************************
- ** PLAIN TEXT LOGGER *******
- ****************************/
-
-static gsize
-txt_logger_write(PurpleLog *log, PurpleMessageFlags type, const gchar *from, time_t time,
-	const gchar *message)
+static void
+purple_txt_log_init(PurpleTxtLog *txt_log)
 {
-	PurplePlugin *plugin;
-	PurpleLogCommonLoggerData *data;
-	const gchar *prpl;
-	gchar *stripped, *date;
-	gsize written;
+}
 
-	plugin = purple_find_prpl(purple_account_get_protocol_id(log->account));
-	data = log->logger_data;
-	stripped = NULL;
-	written = 0;
+PurpleLog *
+purple_txt_log_new(PurpleLogChatType type, const gchar *name, PurpleAccount *account,
+	PurpleConversation *conv, time_t time, const struct tm *tm)
+{
+	return purple_log_new(PURPLE_TYPE_TXT_LOG, type, name, account, conv, time, tm);
+}
 
-	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
-		 * that you open a convo with someone, but don't say anything.
-		 */
-		prpl = PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
-		purple_log_common_writer(log, ".txt");
-
-		data = log->logger_data;
-
-		/* if we can't write to the file, give up before we hurt ourselves */
-		if(!data->file)
-			return 0;
-
-		if (log->type == PURPLE_LOG_SYSTEM)
-			written += fprintf(data->file, "System log for account %s (%s) connected at %s\n",
-				purple_account_get_username(log->account), prpl,
-				purple_date_format_full(localtime(&log->time)));
-		else
-			written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n",
-				log->name, purple_date_format_full(localtime(&log->time)),
-				purple_account_get_username(log->account), prpl);
-	}
-
-	/* if we can't write to the file, give up before we hurt ourselves */
-	if(!data->file)
-		return 0;
-
-	stripped = purple_markup_strip_html(message);
-	date = log_get_timestamp(log, time);
-
-	if(log->type == PURPLE_LOG_SYSTEM){
-		written += fprintf(data->file, "---- %s @ %s ----\n", stripped, date);
-	} else {
-		if (type & PURPLE_MESSAGE_SEND ||
-			type & PURPLE_MESSAGE_RECV) {
-			if (type & PURPLE_MESSAGE_AUTO_RESP) {
-				written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date,
-					from, stripped);
-			} else {
-				if (purple_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 & PURPLE_MESSAGE_SYSTEM ||
-			type & PURPLE_MESSAGE_ERROR ||
-			type & PURPLE_MESSAGE_RAW)
-			written += fprintf(data->file, "(%s) %s\n", date, stripped);
-		else if (type & PURPLE_MESSAGE_NO_LOG) {
-			/* This shouldn't happen */
-			g_free(stripped);
-
-			return written;
-		} else if (type & PURPLE_MESSAGE_WHISPER)
-			written += fprintf(data->file, "(%s) *%s* %s", date, from, stripped);
-		else
-			written += fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "",
-				from ? ":" : "", stripped);
-	}
-
-	g_free(date);
-	g_free(stripped);
-	fflush(data->file);
-
-	return written;
+static gboolean
+purple_txt_log_create(PurpleLog *log, GCancellable *cancellable, GError **error)
+{
+	return purple_log_common_writer(log, ".txt", cancellable, error);
 }
 
-static void
-txt_logger_write_thread(GSimpleAsyncResult *simple, GObject *object, GCancellable *cancellable)
+static gssize
+purple_txt_log_write(PurpleLog *log, PurpleMessageFlags type, const gchar *from, time_t time, const gchar *message, GCancellable *cancellable, GError **error)
 {
-	_purple_log_logger_write_callback_data *callback_data =
-		g_simple_async_result_get_op_res_gpointer(simple);
-	PurpleLog *log = callback_data->log;
-	PurpleLogCommonLoggerData *data = log->logger_data;
-	PurpleLogType type = callback_data->type;
-	GError *err = NULL;
+	PurpleLogChatType chat_type = purple_log_get_chat_type(log);
+	PurpleLogCommonLoggerData *data = purple_log_get_logger_data(log);
 	GFile *file;
 	GFileOutputStream *stream;
 	GOutputStream *out_stream;
-	const gchar *from = callback_data->from, *message = callback_data->message;
 	gchar *stripped = NULL, *date, *line;
 	gssize written, size = 0;
 	gboolean write_header;
 
 	if (type & PURPLE_MESSAGE_NO_LOG) {
-		g_simple_async_result_set_error(simple,
+		g_set_error_literal(error,
 			G_IO_ERROR,
 			G_IO_ERROR_FAILED,
 			_("Trying to log when flagged not to"));
 
-		return;
+		return -1;
 	}
 
 	if (data == NULL) {
@@ -184,75 +104,73 @@ txt_logger_write_thread(GSimpleAsyncResu
 		 * 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.
 		 */
-		purple_log_common_writer(log, ".txt");
-		data = log->logger_data;
+		//Should we be doing this?
+		if (!purple_txt_log_create(log, cancellable, error))
+			return -1;
+
+		data = purple_log_get_logger_data(log);
 		write_header = TRUE;
 	} else
 		write_header = FALSE;
 
 	/* If we can't write to the file, give up before we hurt ourselves */
 	if (data == NULL || data->path == NULL) {
-		g_simple_async_result_set_error(simple,
+		g_set_error_literal(error,
 			G_IO_ERROR,
 			G_IO_ERROR_FAILED,
 			_("Unable to find log path"));
 
-		return;
+		return -1;
 	}
 
 	file = g_file_new_for_path(data->path);
-	stream = g_file_append_to(file, G_FILE_CREATE_NONE, cancellable, &err);
+	stream = g_file_append_to(file, G_FILE_CREATE_NONE, cancellable, error);
 
 	if (stream == NULL) {
-		g_simple_async_result_set_from_error(simple, err);
-
 		g_object_unref(file);
-		g_clear_error(&err);
 
-		return;
+		return -1;
 	}
 
-	g_clear_error(&err);
 	out_stream = G_OUTPUT_STREAM(stream);
 
 	if (write_header) {
+		PurpleAccount *account = purple_log_get_account(log);
 		PurplePlugin *plugin;
 		const gchar *prpl;
+		time_t log_time = purple_log_get_time(log);
 
-		plugin = purple_find_prpl(purple_account_get_protocol_id(log->account));
-		prpl = PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
+		plugin = purple_find_prpl(purple_account_get_protocol_id(account));
+		prpl = PURPLE_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(account, NULL);
 
-		if (log->type == PURPLE_LOG_SYSTEM)
+		if (chat_type == PURPLE_LOG_SYSTEM)
 			line = g_strdup_printf("System log for account %s (%s) connected at %s\n",
-				purple_account_get_username(log->account), prpl,
-				purple_date_format_full(localtime(&log->time)));
+				purple_account_get_username(account), prpl,
+				purple_date_format_full(localtime(&log_time)));
 		else
 			line = g_strdup_printf("Conversation with %s at %s on %s (%s)\n",
-				log->name, purple_date_format_full(localtime(&log->time)),
-				purple_account_get_username(log->account), prpl);
+				purple_log_get_name(log),
+				purple_date_format_full(localtime(&log_time)),
+				purple_account_get_username(account), prpl);
 
 		written = g_output_stream_write(out_stream, line,
-			strlen(line), cancellable, &err);
+			strlen(line), cancellable, error);
 		g_free(line);
 
 		if (written < 0) {
-			g_simple_async_result_set_from_error(simple, err);
-
 			g_object_unref(file);
 			g_object_unref(stream);
-			g_clear_error(&err);
 
-			return;
+			return -1;
 		}
 
-		g_clear_error(&err);
 		size += written;
 	}
 
 	stripped = purple_markup_strip_html(message);
-	date = log_get_timestamp(log, callback_data->time);
+	date = _log_get_timestamp(log, time);
 
-	if (log->type == PURPLE_LOG_SYSTEM)
+	if (chat_type == PURPLE_LOG_SYSTEM)
 		line = g_strdup_printf("---- %s @ %s ----\n", stripped, date);
 	else {
 		if (type & PURPLE_MESSAGE_SEND ||
@@ -278,141 +196,64 @@ txt_logger_write_thread(GSimpleAsyncResu
 	}
 
 	written = g_output_stream_write(out_stream, line, strlen(line),
-		cancellable, &err);
+		cancellable, error);
 
 	if (written < 0)
-		g_simple_async_result_set_from_error(simple, err);
+		size = -1;
 	else
-		g_simple_async_result_set_op_res_gssize(simple, size + written);
+		size += written;
 
-	g_clear_error(&err);
 	g_free(line);
 	g_free(date);
 	g_free(stripped);
 	g_object_unref(file);
 	g_object_unref(stream);
-}
 
-static void
-txt_logger_write_async(PurpleLog *log, PurpleMessageFlags type, const gchar *from, time_t time,
-	const gchar *message, gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb,
-	gpointer userdata)
-{
-	_purple_log_logger_write_callback_data *callback_data;
-	GSimpleAsyncResult *simple;
-
-	callback_data = g_new0(_purple_log_logger_write_callback_data, 1);
-	callback_data->log = log;
-	callback_data->type = type;
-	callback_data->from = g_strdup(from);
-	callback_data->time = time;
-	callback_data->message = g_strdup(message);
-
-	simple = g_simple_async_result_new(NULL, cb, userdata, purple_log_write_async);
-
-	g_simple_async_result_set_op_res_gpointer(simple, callback_data,
-		purple_log_logger_write_callback_data_free);
-	g_simple_async_result_run_in_thread(simple, txt_logger_write_thread,
-		io_priority, cancellable);
-
-	g_object_unref(simple);
+	return size;
 }
 
-static void
-txt_logger_finalize(PurpleLog *log)
-{
-	PurpleLogCommonLoggerData *data = log->logger_data;
-
-	if (data != NULL) {
-		if (data->file != NULL)
-			fclose(data->file);
-
-		g_free(data->path);
-		g_slice_free(PurpleLogCommonLoggerData, data);
-	}
-}
-
 static GList *
-txt_logger_list(PurpleLogType type, const gchar *sn, PurpleAccount *account)
+purple_txt_log_list(PurpleLog *log, PurpleLogChatType type, const gchar *sn, PurpleAccount *account, GCancellable *cancellable, GError **error)
 {
-	GList *list;
-
-	G_LOCK(txt_logger);
-	list = purple_log_common_lister(type, sn, account, ".txt", txt_logger);
-	G_UNLOCK(txt_logger);
-
-	return list;
+	return purple_log_common_lister(type, sn, account, ".txt", PURPLE_TYPE_TXT_LOG, cancellable, error);
 }
 
-static void
-txt_logger_list_async(PurpleLogType type, const gchar *sn, PurpleAccount *account,
-	gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata)
-{
-	G_LOCK(txt_logger);
-	purple_log_common_lister_async(type, sn, account, ".txt", txt_logger,
-		io_priority, cancellable, cb, userdata);
-	G_UNLOCK(txt_logger);
-}
-
 static GList *
-txt_logger_list_syslog(PurpleAccount *account)
+purple_txt_log_list_syslog(PurpleLog *log, PurpleAccount *account, GCancellable *cancellable, GError **error)
 {
-	GList *list;
-
-	G_LOCK(txt_logger);
-	list = purple_log_common_lister(PURPLE_LOG_SYSTEM, ".system", account, ".txt", txt_logger);
-	G_UNLOCK(txt_logger);
-
-	return list;
+	return purple_log_common_lister(PURPLE_LOG_SYSTEM, ".system", account, ".txt", PURPLE_TYPE_TXT_LOG, cancellable, error);
 }
 
-static void
-txt_logger_list_syslog_async(PurpleAccount *account, gint io_priority, GCancellable *cancellable,
-	GAsyncReadyCallback cb, gpointer userdata)
-{
-	G_LOCK(txt_logger);
-	purple_log_common_lister_async(PURPLE_LOG_SYSTEM, ".system", account, ".txt", txt_logger,
-		io_priority, cancellable, cb, userdata);
-	G_UNLOCK(txt_logger);
-}
-
 static gchar *
-txt_logger_read(PurpleLog *log, PurpleLogReadFlags *flags)
+process_txt_log(gchar *txt, gchar *to_free)
 {
-	PurpleLogCommonLoggerData *data;
-	gchar *read, *minus_header;
+	gchar *tmp;
 
-	data = log->logger_data;
+	/* The to_free argument allows us to save a
+	 * g_strdup() in some cases. */
 
-	if (flags != NULL)
-		*flags = 0;
+	if (to_free == NULL)
+		to_free = txt;
 
-	if (!data || !data->path)
-		return g_strdup_printf("<font color=\"red\"><b>%s</b></font>",
-			_("Unable to find log path"));
+	/* g_markup_escape_text requires valid UTF-8 */
+	if (!g_utf8_validate(txt, -1, NULL)) {
+		tmp = purple_utf8_salvage(txt);
+		g_free(to_free);
+		to_free = txt = tmp;
+	}
 
-	if (g_file_get_contents(data->path, &read, NULL, NULL)) {
-		minus_header = strchr(read, '\n');
+	tmp = g_markup_escape_text(txt, -1);
+	g_free(to_free);
+	txt = purple_markup_linkify(tmp);
+	g_free(tmp);
 
-		if (minus_header)
-			return process_txt_log(minus_header + 1, read);
-		else
-			return process_txt_log(read, NULL);
-	}
-
-	return g_strdup_printf("<font color=\"red\"><b>%s: %s</b></font>",
-		_("Could not read file"), data->path);
+	return txt;
 }
 
-static void
-txt_logger_read_thread(GSimpleAsyncResult *simple, GObject *object, GCancellable *cancellable)
+static gchar *
+purple_txt_log_read(PurpleLog *log, PurpleLogReadFlags *flags, GCancellable *cancellable, GError **error)
 {
-	_purple_log_logger_read_callback_data *callback_data =
-		g_simple_async_result_get_op_res_gpointer(simple);
-	PurpleLog *log = callback_data->log;
-	PurpleLogCommonLoggerData *data = log->logger_data;
-	PurpleLogReadFlags *flags = callback_data->flags;
-	GError *err = NULL;
+	PurpleLogCommonLoggerData *data = purple_log_get_logger_data(log);
 	GFile *file;
 	gchar *read, *minus_header;
 
@@ -420,31 +261,22 @@ txt_logger_read_thread(GSimpleAsyncResul
 		*flags = 0;
 
 	if (data == NULL || data->path == NULL) {
-		g_simple_async_result_set_error(simple,
+		g_set_error_literal(error,
 			G_FILE_ERROR,
 			G_IO_ERROR_NOT_FOUND,
-			"<font color=\"red\"><b>%s</b></font>",
 			_("Unable to find log path"));
 
-		return;
+		return NULL;
 	}
 
 	file = g_file_new_for_path(data->path);
 
-	if (!g_file_load_contents(file, cancellable, &read, NULL, NULL, &err)) {
-		g_simple_async_result_set_error(simple,
-			err->domain,
-			err->code,
-			"<font color=\"red\"><b>%s</b></font>",
-			err->message);
+	if (!g_file_load_contents(file, cancellable, &read, NULL, NULL, error)) {
+		g_object_unref(file);
 
-		g_clear_error(&err);
-
-		return;
+		return NULL;
 	}
 
-	g_clear_error(&err);
-
 	minus_header = strchr(read, '\n');
 
 	if (minus_header != NULL)
@@ -454,63 +286,48 @@ txt_logger_read_thread(GSimpleAsyncResul
 
 	purple_str_strip_char(read, '\r');
 
-	g_simple_async_result_set_op_res_gpointer(simple, read, g_free);
+	return read;
 }
 
-static void
-txt_logger_read_async(PurpleLog *log, PurpleLogReadFlags *flags, gint io_priority,
-	GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata)
+static gssize
+purple_txt_log_total_size(PurpleLog *log, PurpleLogChatType type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
 {
-	_purple_log_logger_read_callback_data *callback_data;
-	GSimpleAsyncResult *simple;
+	return purple_log_common_total_sizer(type, name, account, ".txt", cancellable, error);
+}
 
-	callback_data = g_new0(_purple_log_logger_read_callback_data, 1);
-	callback_data->flags = flags;
-	callback_data->log = log;
+static void
+purple_txt_log_finalize(GObject *object)
+{
+	PurpleLog *log = PURPLE_LOG(object);
+	PurpleLogCommonLoggerData *data = purple_log_get_logger_data(log);
 
-	simple = g_simple_async_result_new(NULL, cb, userdata, purple_log_read_async);
+	if (data != NULL) {
+		if (data->file != NULL)
+			fclose(data->file);
 
-	g_simple_async_result_set_op_res_gpointer(simple, callback_data, g_free);
-	g_simple_async_result_run_in_thread(simple, txt_logger_read_thread,
-		io_priority, cancellable);
+		g_free(data->path);
+		g_slice_free(PurpleLogCommonLoggerData, data);
+	}
 
-	g_object_unref(simple);
+	G_OBJECT_CLASS(purple_txt_log_parent_class)->finalize(object);
 }
 
-static gint
-txt_logger_total_size(PurpleLogType type, const gchar *name, PurpleAccount *account)
+void
+purple_txt_log_system_init(void)
 {
-	return purple_log_common_total_sizer(type, name, account, ".txt");
+	purple_prefs_add_string("/purple/logging/format", "txt");
 }
 
-static void
-txt_logger_total_size_async(PurpleLogType type, const gchar *name, PurpleAccount *account,
-	gint io_priority, GCancellable *cancellable, GAsyncReadyCallback cb, gpointer userdata)
+void *
+purple_txt_log_system_get_handle(void)
 {
-	purple_log_common_total_sizer_async(type, name, account, ".txt",
-		io_priority, cancellable, cb, userdata);
-}
+	static gint handle;
 
+	return &handle;
+}
 
+void
+purple_txt_log_system_uninit(void)
+{
+}
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
============================================================
--- libpurple/txtlog.h	01bea99cc3956da3d332ca41cc98bb3e8e90f703
+++ libpurple/txtlog.h	8ea7e9aaafe92ee0f3c464b14bc2a1d04dad0b71
@@ -28,7 +28,7 @@
 #ifndef _PURPLE_TXT_LOG_H_
 #define _PURPLE_TXT_LOG_H_
 
-#include <gio/gio.h>
+#include <glib-object.h>
 
 #include "log.h"
 


More information about the Commits mailing list