cpw.nader.asynclogging-3: 1cd18905: Made log_set_hash, log_set_equal, and lo...

morshed.nader at gmail.com morshed.nader at gmail.com
Wed Jan 12 02:48:05 EST 2011


----------------------------------------------------------------------
Revision: 1cd18905a16f75ffabad7d206b627b85002a9f68
Parent:   d391849d1a12d2b06369ddbe61863301ae24268e
Author:   morshed.nader at gmail.com
Date:     01/12/11 00:54:01
Branch:   im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/1cd18905a16f75ffabad7d206b627b85002a9f68

Changelog: 

Made log_set_hash, log_set_equal, and log_add_log_set_to_hash all be exposed in log.h
Moved _process_txt_log back into log.c and exposed it
Cleaned up PurpleOldLog a bit and made it compile (Still converting the rest of it to use the gio API)

Changes against parent d391849d1a12d2b06369ddbe61863301ae24268e

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

-------------- next part --------------
============================================================
--- libpurple/log.c	ecd3ffe6abccd197d553c72ad7b33f0eebfda9b4
+++ libpurple/log.c	736f1a0f941f986bc5068e5dd2676e7d176d7208
@@ -163,10 +163,6 @@ static void purple_logger_total_size_cal
 static void thread_write_callback_data_free(gpointer);
 static void purple_logger_total_size_callback_data_free(gpointer);
 
-static guint log_set_hash(gconstpointer);
-static gboolean log_set_equal(gconstpointer, gconstpointer);
-static void log_add_log_set_to_hash(GHashTable *, PurpleLogSet *);
-
 static GHashTable *log_get_log_sets_common(GCancellable *, GError **);
 static void log_get_log_sets_common_thread(GSimpleAsyncResult *, GObject *, GCancellable *);
 static void log_get_log_sets_common_async(gint, GCancellable *, GAsyncReadyCallback, gpointer);
@@ -1106,8 +1102,8 @@ purple_log_get_total_size(PurpleLog *log
 			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);
+				g_list_foreach(logs, (GFunc) g_object_unref, NULL);
+				g_list_free(logs);
 
 				return -1;
 			}
@@ -1216,8 +1212,8 @@ total_size_thread(GSimpleAsyncResult *si
 			if (size < 0) {
 				g_simple_async_result_set_from_error(simple, error);
 
-				for ( ; logs != NULL; logs = g_list_delete_link(logs, logs))
-					g_object_unref(logs->data);
+				g_list_foreach(logs, (GFunc) g_object_unref, NULL);
+				g_list_free(logs);
 
 				return;
 			}
@@ -1400,8 +1396,8 @@ purple_log_get_activity_score(PurpleLogC
 				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);
+					g_list_foreach(logs, (GFunc) g_object_unref, NULL);
+					g_list_free(logs);
 
 					return -1;
 				}
@@ -1818,8 +1814,8 @@ purple_logs_get_logs(PurpleLogChatType c
 		list = purple_log_get_logs(log, chat_type, name, account, cancellable, error);
 
 		if (list == NULL) {
-			for ( ; logs != NULL; logs = g_list_delete_link(logs, logs))
-				g_object_unref(logs->data);
+			g_list_foreach(logs, (GFunc) g_object_unref, NULL);
+			g_list_free(logs);
 
 			g_object_unref(log);
 
@@ -1960,8 +1956,8 @@ purple_log_set_compare(gconstpointer y, 
 	return (gint) b->type - (gint) a->type;
 }
 
-static guint
-log_set_hash(gconstpointer key)
+guint
+_purple_log_set_hash(gconstpointer key)
 {
 	const PurpleLogSet *set = key;
 
@@ -1971,8 +1967,8 @@ log_set_hash(gconstpointer key)
 	return g_int_hash(&set->type) + g_str_hash(set->name);
 }
 
-static gboolean
-log_set_equal(gconstpointer a, gconstpointer b)
+gboolean
+_purple_log_set_equal(gconstpointer a, gconstpointer b)
 {
 	/* I realize that the choices made for GList and GHashTable
 	 * make sense for those data types, but I wish the comparison
@@ -1980,8 +1976,8 @@ log_set_equal(gconstpointer a, gconstpoi
 	return !purple_log_set_compare(a, b);
 }
 
-static void
-log_add_log_set_to_hash(GHashTable *sets, PurpleLogSet *set)
+void
+_purple_log_add_log_set_to_hash(GHashTable *sets, PurpleLogSet *set)
 {
 	PurpleLogSet *existing_set = g_hash_table_lookup(sets, set);
 
@@ -1996,7 +1992,7 @@ steal_log_sets(gpointer key, gpointer va
 static gboolean
 steal_log_sets(gpointer key, gpointer value, gpointer sets)
 {
-	log_add_log_set_to_hash(sets, key);
+	_purple_log_add_log_set_to_hash(sets, key);
 	return TRUE;
 }
 
@@ -2029,7 +2025,7 @@ purple_logs_get_log_sets(GCancellable *c
 	GError *err = NULL;
 	guint i;
 
-	sets = g_hash_table_new_full(log_set_hash, log_set_equal,
+	sets = g_hash_table_new_full(_purple_log_set_hash, _purple_log_set_equal,
 		(GDestroyNotify) purple_log_set_free, NULL);
 
 	array = purple_log_logger_get_all();
@@ -2131,7 +2127,7 @@ purple_logs_get_log_sets_async(gint io_p
 	callback_data = g_new0(_purple_log_sets_callback_data, 1);
 	callback_data->cb = cb;
 	callback_data->userdata = userdata;
-	callback_data->sets = g_hash_table_new_full(log_set_hash, log_set_equal,
+	callback_data->sets = g_hash_table_new_full(_purple_log_set_hash, _purple_log_set_equal,
 		(GDestroyNotify) purple_log_set_free, NULL);
 
 	/* +1 is need special for log_get_log_sets_common_async call */
@@ -2234,8 +2230,8 @@ purple_logs_get_system_logs(PurpleAccoun
 		list = purple_log_get_system_logs(log, account, cancellable, error);
 
 		if (list == NULL) {
-			for ( ; logs != NULL; logs = g_list_delete_link(logs, logs))
-				g_object_unref(logs->data);
+			g_list_foreach(logs, (GFunc) g_object_unref, NULL);
+			g_list_free(logs);
 
 			g_object_unref(log);
 
@@ -2528,6 +2524,32 @@ _log_get_timestamp(PurpleLog *log, time_
 		return g_strdup(purple_time_format(&tm));
 }
 
+gchar *
+_process_txt_log(gchar *txt, gchar *to_free)
+{
+	gchar *tmp;
+
+	/* The to_free argument allows us to save a
+	 * g_strdup() in some cases. */
+
+	if (to_free == NULL)
+		to_free = txt;
+
+	/* 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;
+}
+
 /* NOTE: This can return msg (which you may or may not want to g_free())
  * NOTE: or a newly allocated string which you MUST g_free(). */
 gchar *
@@ -2834,6 +2856,9 @@ purple_log_common_lister(PurpleLogChatTy
 			g_dir_close(dir);
 			g_free(path);
 
+			g_list_foreach(list, (GFunc) g_object_unref, NULL);
+			g_list_free(list);
+
 			return NULL;
 		}
 
@@ -3227,7 +3252,7 @@ log_get_log_sets_common(GCancellable *ca
 		return NULL;
 	}
 
-	sets = g_hash_table_new_full(log_set_hash, log_set_equal,
+	sets = g_hash_table_new_full(_purple_log_set_hash, _purple_log_set_equal,
 		(GDestroyNotify) purple_log_set_free, NULL);
 
 	while ((protocol = g_dir_read_name(log_dir)) != NULL) {
@@ -3335,7 +3360,7 @@ log_get_log_sets_common(GCancellable *ca
 				else
 					set->buddy = FALSE;
 
-				log_add_log_set_to_hash(sets, set);
+				_purple_log_add_log_set_to_hash(sets, set);
 			}
 
 			g_free(username_path);
============================================================
--- libpurple/log.h	d07ba0d3dff1d7be31f4ec562de6c6efb40fe458
+++ libpurple/log.h	977c0f4af4de0a293e823c61ef5ff6e5ddb1af88
@@ -692,6 +692,13 @@ gint purple_log_compare(gconstpointer y,
  */
 gint purple_log_compare(gconstpointer y, gconstpointer z);
 
+//
+guint _purple_log_set_hash(gconstpointer key);
+//
+gboolean _purple_log_set_equal(gconstpointer a, gconstpointer b);
+//
+void _purple_log_add_log_set_to_hash(GHashTable *sets, PurpleLogSet *set);
+
 /**
  * Implements GCompareFunc for #PurpleLogSet<!-- -->s
  *
@@ -717,6 +724,9 @@ void purple_log_set_free(PurpleLogSet *s
 
 /*@{*/
 
+//
+gchar *_process_txt_log(gchar *, gchar *);
+
 /**
  * Opens a new log file in the standard log location
  * with the given file extension, named for the current time,
============================================================
--- libpurple/oldlog.c	d6149b5e029a1fc0b246ba3b1a30ea9ee80ba73f
+++ libpurple/oldlog.c	c67947f9736e88df27358dd719f50350324b9898
@@ -24,42 +24,70 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
  */
 
+#include "internal.h"
+#include "oldlog.h"
+#include "debug.h"
+#include "stringref.h"
 
-static GList *old_logger_list(PurpleLogType, const gchar *, PurpleAccount *);
-static gint old_logger_total_size(PurpleLogType, const gchar *, PurpleAccount *);
-static gchar *old_logger_read(PurpleLog *, PurpleLogReadFlags *);
-static gint old_logger_size(PurpleLog *);
-static void old_logger_get_log_sets(PurpleLogSetCallback, GHashTable *);
-static void old_logger_finalize(PurpleLog *);
+G_DEFINE_TYPE (PurpleOldLog, purple_old_log, PURPLE_TYPE_LOG)
 
+#define PURPLE_OLD_LOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), PURPLE_TYPE_OLD_LOG, PurpleOldLogPrivate))
+typedef struct _PurpleOldLogPrivate PurpleOldLogPrivate;
 
-/****************
- * OLD LOGGER ***
- ****************/
+struct _PurpleOldLogPrivate {
+	PurpleStringref *pathref;
+	gssize offset;
+	gssize length;
+};
 
+static GList *purple_old_log_list(PurpleLog *, PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
+static gint purple_old_log_total_size(PurpleLog *, PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
+static gchar *purple_old_log_read(PurpleLog *, PurpleLogReadFlags *, GCancellable *, GError **);
+static gssize purple_old_log_size(PurpleLog *, GCancellable *, GError **);
+static GHashTable *purple_old_log_get_log_sets(PurpleLog *, GCancellable *, GError **);
+static void purple_old_log_finalize(GObject *);
+
+
 /* The old logger doesn't write logs, only reads them.  This is to include
  * old logs in the log viewer transparently.
  */
 
-typedef struct {
-	PurpleStringref *pathref;
-	gint offset;
-	gint length;
-} old_logger_data;
+static void
+purple_old_log_class_init(PurpleOldLogClass *class)
+{
+	GObjectClass *gobject_class = G_OBJECT_CLASS(class);
+	PurpleLogClass *log_class = PURPLE_LOG_CLASS(class);
 
+	log_class->logger_name = _("Old flat format");
+	log_class->logger_id = "old";
+
+	log_class->list_fn = purple_old_log_list;
+	log_class->read_fn = purple_old_log_read;
+	log_class->size_fn = purple_old_log_size;
+	log_class->total_size_fn = purple_old_log_total_size;
+	log_class->get_log_sets_fn = purple_old_log_get_log_sets;
+
+	gobject_class->finalize = purple_old_log_finalize;
+
+	g_type_class_add_private(gobject_class, sizeof(PurpleOldLogPrivate));
+}
+
+static void
+purple_old_log_init(PurpleOldLog *old_log)
+{
+}
+
 static GList *
-old_logger_list(PurpleLogType type, const gchar *sn, PurpleAccount *account)
+purple_old_log_list(PurpleLog *log, PurpleLogChatType chat_type, const gchar *sn, PurpleAccount *account, GCancellable *cancellable, GError **error)
 {
-	old_logger_data *data;
 	PurpleStringref *pathref;
-	PurpleLog *log;
-	GList *list;
+	GList *list = NULL;
 	FILE *index, *file;
-	time_t log_last_modified, lasttime;
+	time_t log_last_modified, lasttime = 0;
 	struct stat st;
 	struct tm tm;
 	gchar *logfile, *pathstr, *index_tmp, buf[BUF_LONG], month[4], convostart[32], *temp;
-	gint index_fd, logfound, lastoff, newlen, length, offset;
+	gint index_fd, logfound = 0, lastoff = 0, newlen, length, offset;
 	gulong idx_time;
 
 	logfile = g_strdup_printf("%s.log", purple_normalize(account, sn));
@@ -67,14 +95,6 @@ old_logger_list(PurpleLogType type, cons
 	pathref = purple_stringref_new(pathstr);
 	g_free(logfile);
 
-	log = NULL;
-	list = NULL;
-	data = NULL;
-
-	logfound = 0;
-	lastoff = 0;
-	lasttime = 0;
-
 	if (g_stat(purple_stringref_value(pathref), &st)) {
 		purple_stringref_unref(pathref);
 		g_free(pathstr);
@@ -103,21 +123,14 @@ old_logger_list(PurpleLogType type, cons
 
 				while (fgets(buf, BUF_LONG, index)) {
 					if (sscanf(buf, "%d\t%d\t%lu", &lastoff, &newlen, &idx_time) == 3) {
-						log = purple_log_new(PURPLE_TYPE_OLD_LOG, PURPLE_LOG_IM, sn, account, NULL, -1, NULL);
-						log->time = (time_t) idx_time;
+						PurpleLog *log = purple_log_new(PURPLE_TYPE_OLD_LOG, PURPLE_LOG_IM, sn,
+							account, NULL, idx_time, NULL);
+						PurpleOldLogPrivate *priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
 
-						G_LOCK(old_logger);
-						log->logger = old_logger;
-						G_UNLOCK(old_logger);
+						priv->pathref = purple_stringref_ref(pathref);
+						priv->offset = lastoff;
+						priv->length = newlen;
 
-						/* IMPORTANT: Always set all members of old_logger_data */
-						data = g_slice_new(old_logger_data);
-
-						data->pathref = purple_stringref_ref(pathref);
-						data->offset = lastoff;
-						data->length = newlen;
-
-						log->logger_data = data;
 						list = g_list_prepend(list, log);
 					}
 				}
@@ -192,27 +205,20 @@ old_logger_list(PurpleLogType type, cons
 					newlen--;
 
 				if (newlen != 0) {
-					log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, -1, NULL);
-					log->time = lasttime;
+					PurpleLog *log = purple_log_new(PURPLE_TYPE_OLD_LOG, PURPLE_LOG_IM, sn,
+						account, NULL, lasttime, NULL);
+					PurpleOldLogPrivate *priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
 
-					G_LOCK(old_logger);
-					log->logger = old_logger;
-					G_UNLOCK(old_logger);
+					priv->pathref = purple_stringref_ref(pathref);
+					priv->offset = lastoff;
+					priv->length = newlen;
 
-					/* IMPORTANT: Always set all members of old_logger_data */
-					data = g_slice_new(old_logger_data);
-
-					data->pathref = purple_stringref_ref(pathref);
-					data->offset = lastoff;
-					data->length = newlen;
-
-					log->logger_data = data;
 					list = g_list_prepend(list, log);
 
 					/* XXX: There is apparently Is there a proper way to print a time_t? */
 					if (index != NULL)
-						fprintf(index, "%d\t%d\t%lu\n", data->offset, data->length,
-							(unsigned long)log->time);
+						fprintf(index, "%d\t%d\t%lu\n", priv->offset, priv->length,
+							(unsigned long) purple_log_get_time(log));
 				}
 			}
 
@@ -257,26 +263,20 @@ old_logger_list(PurpleLogType type, cons
 
 	if (logfound) {
 		if ((newlen = ftell(file) - lastoff) != 0) {
-			log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, -1, NULL);
-			log->time = lasttime;
+			PurpleLog *log = purple_log_new(PURPLE_TYPE_OLD_LOG, PURPLE_LOG_IM, sn,
+				account, NULL, lasttime, NULL);
+			PurpleOldLogPrivate *priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
 
-			G_LOCK(old_logger);
-			log->logger = old_logger;
-			G_UNLOCK(old_logger);
+			priv->pathref = purple_stringref_ref(pathref);
+			priv->offset = lastoff;
+			priv->length = newlen;
 
-			/* IMPORTANT: Always set all members of old_logger_data */
-			data = g_slice_new(old_logger_data);
-
-			data->pathref = purple_stringref_ref(pathref);
-			data->offset = lastoff;
-			data->length = newlen;
-
-			log->logger_data = data;
 			list = g_list_prepend(list, log);
 
 			/* XXX: Is there a proper way to print a time_t? */
 			if (index != NULL)
-				fprintf(index, "%d\t%d\t%d\n", data->offset, data->length, (gint) log->time);
+				fprintf(index, "%d\t%d\t%d\n", priv->offset, priv->length,
+					(gint) purple_log_get_time(log));
 		}
 	}
 
@@ -305,99 +305,143 @@ old_logger_list(PurpleLogType type, cons
 	return list;
 }
 
-static gint
-old_logger_total_size(PurpleLogType type, const gchar *name, PurpleAccount *account)
+static gssize
+purple_old_log_total_size(PurpleLog *log, PurpleLogChatType chat_type, const gchar *name, PurpleAccount *account, GCancellable *cancellable, GError **error)
 {
+	/* Yes, only one file. */
+	GFile *file;
+	GFileInfo *info;
 	gchar *logfile, *pathstr;
-	gint size;
-	struct stat st;
+	guint64 file_size;
 
 	logfile = g_strdup_printf("%s.log", purple_normalize(account, name));
 	pathstr = g_build_filename(purple_user_dir(), "logs", logfile, NULL);
 
-	if (g_stat(pathstr, &st))
-		size = 0;
-	else
-		size = st.st_size;
+	file = g_file_new_for_path(pathstr);
 
 	g_free(logfile);
 	g_free(pathstr);
 
-	return size;
+	info = g_file_query_info(file, G_FILE_ATTRIBUTE_STANDARD_SIZE,
+		G_FILE_QUERY_INFO_NONE, cancellable, error);
+
+	if (info == NULL) {
+		g_object_unref(file);
+
+		return -1;
+	}
+
+	file_size = g_file_info_get_attribute_uint64(info,
+		G_FILE_ATTRIBUTE_STANDARD_SIZE);
+
+	g_object_unref(info);
+	g_object_unref(file);
+
+	return file_size;
 }
 
 static gchar *
-old_logger_read(PurpleLog *log, PurpleLogReadFlags *flags)
+purple_old_log_read(PurpleLog *log, PurpleLogReadFlags *flags, GCancellable *cancellable, GError **error)
 {
-	size_t result;
-	old_logger_data *data;
+	PurpleOldLogPrivate *priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
 	const gchar *path;
-	FILE *file;
+	GFile *file;
+	GFileInputStream *file_stream;
+	GInputStream *stream;
 	gchar *read;
+	gssize result;
 
-	data = log->logger_data;
-	path = purple_stringref_value(data->pathref);
-	file = g_fopen(path, "rb");
-	read = g_malloc(data->length + 1);
+	path = purple_stringref_value(priv->pathref);
+	file = g_file_new_for_path(path);
+	file_stream = g_file_read(file, cancellable, error);
 
-	fseek(file, data->offset, SEEK_SET);
-	result = fread(read, data->length, 1, file);
+	if (file_stream == NULL) {
+		g_object_unref(file);
 
-	if (result != 1)
-		purple_debug_error("log", "Unable to read from log file: %s\n", path);
+		return NULL;
+	}
 
-	fclose(file);
-	read[data->length] = '\0';
+	stream = G_INPUT_STREAM(file_stream);
+	result = g_input_stream_skip(stream, priv->offset, cancellable, error);
 
-	if (flags != NULL)
-		*flags = 0;
+	if (result < 0) {
+		g_object_unref(file);
+		g_object_unref(stream);
 
-	if (strstr(read, "<BR>")) {
-		if (flags != NULL)
-			*flags |= PURPLE_LOG_READ_NO_NEWLINE;
+		return NULL;
+	}
 
-		return read;
+	read = g_malloc(priv->length + 1);
+	result = g_input_stream_read(stream, read, priv->length, cancellable, error);
+
+	if (result < 0) {
+		g_free(read);
+		g_object_unref(file);
+		g_object_unref(stream);
+
+		return NULL;
 	}
 
+	g_object_unref(file);
+	g_object_unref(stream);
+
+	read[priv->length] = '\0';
+
+	if (flags != NULL) {
+		if (strstr(read, "<BR>"))
+			*flags = PURPLE_LOG_READ_NO_NEWLINE;
+		else
+			*flags = 0;
+	}
+
 	purple_str_strip_char(read, '\r');
 
-	return process_txt_log(read, NULL);
+	return _process_txt_log(read, NULL);
 }
 
-static gint
-old_logger_size(PurpleLog *log)
+static gssize
+purple_old_log_size(PurpleLog *log, GCancellable *cancellable, GError **error)
 {
-	old_logger_data *data;
+	PurpleOldLogPrivate *priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
 
-	data = log->logger_data;
-
-	return data ? data->length : 0;
+	return priv->length;
 }
 
-static void
-old_logger_get_log_sets(PurpleLogSetCallback cb, GHashTable *sets)
+static GHashTable *
+purple_old_log_get_log_sets(PurpleLog *log, GCancellable *cancellable, GError **error)
 {
 	PurpleBlistNode *gnode, *cnode, *bnode;
 	PurpleBuddy *buddy;
 	PurpleLogSet *set;
 	GDir *log_dir;
+	GHashTable *sets;
+	const gchar *filename;
 	gchar *log_path, *name, *tmp, *ext;
 	size_t len;
 	gboolean found;
 
 	log_path = g_build_filename(purple_user_dir(), "logs", NULL);
-	log_dir = g_dir_open(log_path, 0, NULL);
+	log_dir = g_dir_open(log_path, 0, error);
 	g_free(log_path);
 
 	if (log_dir == NULL)
-		return;
+		return NULL;
 
-	/* Don't worry about the cast, name will be filled with a dynamically allocated data shortly. */
-	while ((name = (gchar *) g_dir_read_name(log_dir)) != NULL) {
+	sets = g_hash_table_new_full(_purple_log_set_hash, _purple_log_set_equal,
+		(GDestroyNotify) purple_log_set_free, NULL);
+
+	while ((filename = g_dir_read_name(log_dir)) != NULL) {
+		if (g_cancellable_set_error_if_cancelled(cancellable, error)) {
+			g_dir_close(log_dir);
+			g_hash_table_destroy(sets);
+
+			return NULL;
+		}
+
 		found = FALSE;
 
 		/* Unescape the filename. */
-		name = g_strdup(purple_unescape_filename(name));
+		name = g_strdup(purple_unescape_filename(filename));
 
 		/* Get the (possibly new) length of name. */
 		len = strlen(name);
@@ -408,7 +452,8 @@ old_logger_get_log_sets(PurpleLogSetCall
 		}
 
 		/* Make sure we're dealing with a log file. */
-		ext = &name[len - 4];
+		ext = name + len - 4;
+
 		if (!purple_strequal(ext, ".log")) {
 			g_free(name);
 			continue;
@@ -422,7 +467,8 @@ old_logger_get_log_sets(PurpleLogSetCall
 		set->type = PURPLE_LOG_IM;
 
 		if (len > 9) {
-			tmp = &name[len - 9];
+			tmp = name + len - 9;
+
 			if (purple_strequal(tmp, ".chat")) {
 				set->type = PURPLE_LOG_CHAT;
 				*tmp = '\0';
@@ -433,21 +479,24 @@ old_logger_get_log_sets(PurpleLogSetCall
 
 		/* Search the buddy list to find the account and to determine if this is a buddy. */
 		for (gnode = purple_blist_get_root();
-		     !found && gnode != NULL;
-			 gnode = purple_blist_node_get_sibling_next(gnode)) {
+			!found && gnode != NULL;
+			gnode = purple_blist_node_get_sibling_next(gnode))
+		{
 			if (!PURPLE_BLIST_NODE_IS_GROUP(gnode))
 				continue;
 
 			for (cnode = purple_blist_node_get_first_child(gnode);
-			     !found && cnode != NULL;
-				 cnode = purple_blist_node_get_sibling_next(cnode)) {
+				!found && cnode != NULL;
+				cnode = purple_blist_node_get_sibling_next(cnode))
+			{
 				if (!PURPLE_BLIST_NODE_IS_CONTACT(cnode))
 					continue;
 
 				for (bnode = purple_blist_node_get_first_child(cnode);
-				     !found && bnode != NULL;
-					 bnode = purple_blist_node_get_sibling_next(bnode)) {
-					buddy = (PurpleBuddy *) bnode;
+					!found && bnode != NULL;
+					bnode = purple_blist_node_get_sibling_next(bnode))
+				{
+					buddy = PURPLE_BUDDY(bnode);
 
 					if (purple_strequal(purple_buddy_get_name(buddy), name)) {
 						set->account = purple_buddy_get_account(buddy);
@@ -459,22 +508,44 @@ old_logger_get_log_sets(PurpleLogSetCall
 		}
 
 		if (!found) {
-			set->account = NULL;
-			set->buddy = FALSE;
+			purple_log_set_free(set);
+			continue;
 		}
 
-		cb(sets, set);
+		_purple_log_add_log_set_to_hash(sets, set);
 	}
 
 	g_dir_close(log_dir);
+
+	return sets;
 }
 
 static void
-old_logger_finalize(PurpleLog *log)
+purple_old_log_finalize(GObject *object)
 {
-	old_logger_data *data = log->logger_data;
+	PurpleLog *log = PURPLE_LOG(object);
+	PurpleOldLogPrivate *priv = PURPLE_OLD_LOG_GET_PRIVATE(log);
 
-	purple_stringref_unref(data->pathref);
-	g_slice_free(old_logger_data, data);
+	purple_stringref_unref(priv->pathref);
+
+	G_OBJECT_CLASS(purple_old_log_parent_class)->finalize(object);
 }
 
+void
+purple_old_log_system_init(void)
+{
+	purple_prefs_add_string("/purple/logging/format", "old");
+}
+
+void *
+purple_old_log_system_get_handle(void)
+{
+	static gint handle;
+
+	return &handle;
+}
+
+void
+purple_old_log_system_uninit(void)
+{
+}
============================================================
--- libpurple/txtlog.c	80facd735d7f5fcb13f4207012b64a11fadc4008
+++ libpurple/txtlog.c	d4dfea4a810d83bb0f83388b712f50a9d8c9255f
@@ -32,7 +32,6 @@ static GList *purple_txt_log_list(Purple
 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 **);
@@ -225,32 +224,6 @@ static gchar *
 }
 
 static gchar *
-process_txt_log(gchar *txt, gchar *to_free)
-{
-	gchar *tmp;
-
-	/* The to_free argument allows us to save a
-	 * g_strdup() in some cases. */
-
-	if (to_free == NULL)
-		to_free = txt;
-
-	/* 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;
-}
-
-static gchar *
 purple_txt_log_read(PurpleLog *log, PurpleLogReadFlags *flags, GCancellable *cancellable, GError **error)
 {
 	PurpleLogCommonLoggerData *data = purple_log_get_logger_data(log);
@@ -277,16 +250,13 @@ purple_txt_log_read(PurpleLog *log, Purp
 		return NULL;
 	}
 
+	purple_str_strip_char(read, '\r');
 	minus_header = strchr(read, '\n');
 
 	if (minus_header != NULL)
-		read = process_txt_log(minus_header + 1, read);
+		return _process_txt_log(minus_header + 1, read);
 	else
-		read = process_txt_log(read, NULL);
-
-	purple_str_strip_char(read, '\r');
-
-	return read;
+		return _process_txt_log(read, NULL);
 }
 
 static gssize


More information about the Commits mailing list