cpw.nader.asynclogging-3: f2afaea6: Cleaned up htmllog.c's long lines
morshed.nader at gmail.com
morshed.nader at gmail.com
Sun Apr 24 20:20:53 EDT 2011
----------------------------------------------------------------------
Revision: f2afaea6474b27bf73f6f0e12c09ad50a001d265
Parent: 00a2a8fadb9b08522a39733057f60c8f24c038d4
Author: morshed.nader at gmail.com
Date: 03/30/11 20:46:13
Branch: im.pidgin.cpw.nader.asynclogging-3
URL: http://d.pidgin.im/viewmtn/revision/info/f2afaea6474b27bf73f6f0e12c09ad50a001d265
Changelog:
Cleaned up htmllog.c's long lines
Moved convert_image_tags into htmllog.c
Moved _convert_image_tags and _process_txt_log's definitions from log.h into internal.h
Changes against parent 00a2a8fadb9b08522a39733057f60c8f24c038d4
patched libpurple/htmllog.c
patched libpurple/internal.h
patched libpurple/log.c
patched libpurple/log.h
-------------- next part --------------
============================================================
--- libpurple/log.c a38886da463eaa94472d64e153d5cc9d3b167c02
+++ libpurple/log.c 57aabc8fcc5479f546ae74f30499f0aef77c221d
@@ -35,7 +35,6 @@
#include "oldlog.h"
#include "prefs.h"
#include "util.h"
-#include "stringref.h"
#include "imgstore.h"
#include "time.h"
@@ -2477,95 +2476,6 @@ _process_txt_log(gchar *txt, gchar *to_f
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 *
-_convert_image_tags(const PurpleLog *log, const gchar *msg)
-{
- GString *newmsg = NULL;
- GData *attributes;
- const gchar *tmp = msg, *start, *end;
-
- while (purple_markup_find_tag("img", tmp, &start, &end, &attributes)) {
- gchar *idstr = NULL;
- gint imgid = 0;
-
- if (newmsg == NULL)
- newmsg = g_string_new("");
-
- /* copy any text before the img tag */
- if (tmp < start)
- g_string_append_len(newmsg, tmp, start - tmp);
-
- if ((idstr = g_datalist_get_data(&attributes, "id")) != NULL)
- imgid = atoi(idstr);
-
- if (imgid != 0) {
- PurpleAccount *account = purple_log_get_account(log);
- PurpleLogChatType chat_type = purple_log_get_chat_type(log);
- PurpleStoredImage *image = purple_imgstore_find_by_id(imgid);
- gchar *new_filename = NULL, *path = NULL, *dir;
- const gchar *name = purple_log_get_name(log);
- gconstpointer image_data;
- size_t image_byte_count;
-
- if (image == NULL) {
- /* This should never happen. */
- /* This *does* happen for failed Direct-IMs -DAA */
- g_string_free(newmsg, TRUE);
- g_return_val_if_reached((gchar *) msg);
- }
-
- image_data = purple_imgstore_get_data(image);
- image_byte_count = purple_imgstore_get_size(image);
- dir = purple_log_get_log_dir(chat_type, name, account);
- new_filename = purple_util_get_image_filename(image_data, image_byte_count);
-
- path = g_build_filename(dir, new_filename, NULL);
-
- /* Only save unique files. */
- if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
- FILE *image_file = g_fopen(path, "wb");
-
- if (image_file != NULL) {
- if (!fwrite(image_data, image_byte_count, 1, image_file)) {
- purple_debug_error("log", "Error writing %s: %s\n",
- path, g_strerror(errno));
- fclose(image_file);
-
- /* Attempt to not leave half-written files around. */
- unlink(path);
- } else {
- purple_debug_info("log", "Wrote image file: %s\n", path);
- fclose(image_file);
- }
- } else {
- purple_debug_error("log", "Unable to create file %s: %s\n",
- path, g_strerror(errno));
- }
- }
-
- /* Write the new image tag */
- g_string_append_printf(newmsg, "<IMG SRC=\"%s\">", new_filename);
- g_free(new_filename);
- g_free(path);
- }
-
- /* Continue from the end of the tag */
- tmp = end + 1;
- }
-
- if (newmsg == NULL) {
- /* No images were found to change. */
- return (gchar *) msg;
- }
-
- /* Append any remaining message data */
- g_string_append(newmsg, tmp);
-
- return g_string_free(newmsg, FALSE);
-}
-
/* This will build log sets for all loggers that use the common logger
* functions because they use the same directory structure. */
static GHashTable *
============================================================
--- libpurple/internal.h 2ee8baef9be5112821565c23be222415cdc85f99
+++ libpurple/internal.h 0860eb521edad6cc997dd404224f2decc4419218
@@ -224,5 +224,7 @@ void _purple_log_add_log_set_to_hash(GHa
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);
+gchar *_log_get_timestamp(PurpleLog *log, time_t when);
+gchar *_process_txt_log(gchar *, gchar *);
#endif /* _PURPLE_INTERNAL_H_ */
============================================================
--- libpurple/log.h 02694a4598106ad9644bf47873506fe874cb5f57
+++ libpurple/log.h 3bf31a6bd648f5d2eb65bf56e8599cd8359bbae8
@@ -391,12 +391,6 @@ G_CONST_RETURN struct tm *purple_log_get
*/
G_CONST_RETURN struct tm *purple_log_get_tm(const PurpleLog *log);
-
-gchar *_log_get_timestamp(PurpleLog *log, time_t when);
-gchar *_convert_image_tags(const PurpleLog *log, const gchar *msg);
-gchar *_process_txt_log(gchar *, gchar *);
-
-
/**
* Writes to a log file. Assumes you have checked preferences already.
*
============================================================
--- libpurple/htmllog.c 08ebd87762fb3793424b7b975337bcc019dacb94
+++ libpurple/htmllog.c 86140bda016b8a24e5a5317649eed75dc6153edc
@@ -25,16 +25,22 @@
*/
#include "internal.h"
+#include "debug.h"
#include "htmllog.h"
G_DEFINE_TYPE (PurpleHtmlLog, purple_html_log, PURPLE_TYPE_COMMON_LOG)
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(PurpleLog *, PurpleLogChatType, const gchar *, PurpleAccount *, GCancellable *, GError **);
-static GList *purple_html_log_list_syslog(PurpleLog *, PurpleAccount *, 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(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 *);
static void
@@ -61,20 +67,115 @@ PurpleLog *
}
PurpleLog *
-purple_html_log_new(PurpleLogChatType type, const gchar *name, PurpleAccount *account,
- PurpleConversation *conv, time_t time, const struct tm *tm)
+purple_html_log_new(PurpleLogChatType type, const gchar *name,
+ PurpleAccount *account, PurpleConversation *conv, time_t time,
+ const struct tm *tm)
{
- return purple_common_log_new(PURPLE_TYPE_HTML_LOG, type, name, account, conv, time, tm);
+ return purple_common_log_new(PURPLE_TYPE_HTML_LOG, type, name, account,
+ conv, time, tm);
}
static gboolean
-purple_html_log_create(PurpleLog *log, GCancellable *cancellable, GError **error)
+purple_html_log_create(PurpleLog *log, GCancellable *cancellable,
+ GError **error)
{
return purple_log_common_writer(log, ".html", cancellable, error);
}
+/* 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(). */
+static gchar *
+convert_image_tags(const PurpleLog *log, const gchar *msg)
+{
+ GString *newmsg = NULL;
+ GData *attributes;
+ const gchar *tmp = msg, *start, *end;
+
+ while (purple_markup_find_tag("img", tmp, &start, &end, &attributes)) {
+ gchar *idstr = NULL;
+ gint imgid = 0;
+
+ if (newmsg == NULL)
+ newmsg = g_string_new("");
+
+ /* copy any text before the img tag */
+ if (tmp < start)
+ g_string_append_len(newmsg, tmp, start - tmp);
+
+ if ((idstr = g_datalist_get_data(&attributes, "id")) != NULL)
+ imgid = atoi(idstr);
+
+ if (imgid != 0) {
+ PurpleAccount *account = purple_log_get_account(log);
+ PurpleLogChatType chat_type = purple_log_get_chat_type(log);
+ PurpleStoredImage *image = purple_imgstore_find_by_id(imgid);
+ gchar *new_filename = NULL, *path = NULL, *dir;
+ const gchar *name = purple_log_get_name(log);
+ gconstpointer image_data;
+ size_t image_byte_count;
+
+ if (image == NULL) {
+ /* This should never happen. */
+ /* This *does* happen for failed Direct-IMs -DAA */
+ g_string_free(newmsg, TRUE);
+ g_return_val_if_reached((gchar *) msg);
+ }
+
+ image_data = purple_imgstore_get_data(image);
+ image_byte_count = purple_imgstore_get_size(image);
+ dir = purple_log_get_log_dir(chat_type, name, account);
+ new_filename = purple_util_get_image_filename(image_data,
+ image_byte_count);
+
+ path = g_build_filename(dir, new_filename, NULL);
+
+ /* Only save unique files. */
+ if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
+ FILE *image_file = g_fopen(path, "wb");
+
+ if (image_file != NULL) {
+ if (!fwrite(image_data, image_byte_count, 1, image_file)) {
+ purple_debug_error("log", "Error writing %s: %s\n",
+ path, g_strerror(errno));
+ fclose(image_file);
+
+ /* Attempt to not leave half-written files around. */
+ unlink(path);
+ } else {
+ purple_debug_info("log", "Wrote image file: %s\n", path);
+ fclose(image_file);
+ }
+ } else {
+ purple_debug_error("log", "Unable to create file %s: %s\n",
+ path, g_strerror(errno));
+ }
+ }
+
+ /* Write the new image tag */
+ g_string_append_printf(newmsg, "<IMG SRC=\"%s\">", new_filename);
+ g_free(new_filename);
+ g_free(path);
+ }
+
+ /* Continue from the end of the tag */
+ tmp = end + 1;
+ }
+
+ if (newmsg == NULL) {
+ /* No images were found to change. */
+ return (gchar *) msg;
+ }
+
+ /* Append any remaining message data */
+ g_string_append(newmsg, tmp);
+
+ return g_string_free(newmsg, FALSE);
+}
+
static gssize
-purple_html_log_write(PurpleLog *log, PurpleMessageFlags type, const gchar *from, time_t time, const gchar *message, GCancellable *cancellable, GError **error)
+purple_html_log_write(PurpleLog *log, PurpleMessageFlags type,
+ const gchar *from, time_t time, const gchar *message,
+ GCancellable *cancellable, GError **error)
{
GFile *file;
GFileOutputStream *stream;
@@ -133,7 +234,8 @@ purple_html_log_write(PurpleLog *log, Pu
date_full = purple_date_format_full(localtime(&log_time));
if (purple_log_get_chat_type(log) == PURPLE_LOG_SYSTEM)
- header = g_strdup_printf("System log for account %s (%s) connected at %s",
+ header = g_strdup_printf("System log for account %s (%s) "
+ "connected at %s",
purple_account_get_username(account), prpl, date_full);
else
header = g_strdup_printf("Conversation with %s at %s on %s (%s)",
@@ -166,7 +268,7 @@ purple_html_log_write(PurpleLog *log, Pu
}
escaped_from = g_markup_escape_text(from, -1);
- image_corrected_msg = _convert_image_tags(log, message);
+ image_corrected_msg = convert_image_tags(log, message);
purple_markup_html_to_xhtml(image_corrected_msg, &msg_fixed, NULL);
/* Yes, this breaks encapsulation. But it's a static function and
@@ -180,7 +282,8 @@ purple_html_log_write(PurpleLog *log, Pu
line = g_strdup_printf("---- %s @ %s ----<br/>\n", msg_fixed, date);
} else {
if (type & PURPLE_MESSAGE_SYSTEM)
- line = g_strdup_printf("<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed);
+ line = g_strdup_printf("<font size=\"2\">(%s)</font><b> %s"
+ "</b><br/>\n", date, msg_fixed);
else if (type & PURPLE_MESSAGE_RAW)
line = g_strdup_printf("<font size=\"2\">(%s)</font> %s<br/>\n",
date, msg_fixed);
@@ -244,19 +347,24 @@ static GList *
}
static GList *
-purple_html_log_list(PurpleLog *log, PurpleLogChatType type, const gchar *sn, PurpleAccount *account, GCancellable *cancellable, GError **error)
+purple_html_log_list(PurpleLog *log, PurpleLogChatType type, const gchar *sn,
+ PurpleAccount *account, GCancellable *cancellable, GError **error)
{
- return purple_log_common_lister(type, sn, account, ".html", PURPLE_TYPE_HTML_LOG, cancellable, error);
+ return purple_log_common_lister(type, sn, account, ".html",
+ PURPLE_TYPE_HTML_LOG, cancellable, error);
}
static GList *
-purple_html_log_list_syslog(PurpleLog *log, PurpleAccount *account, GCancellable *cancellable, GError **error)
+purple_html_log_list_syslog(PurpleLog *log, PurpleAccount *account,
+ GCancellable *cancellable, GError **error)
{
- return purple_log_common_lister(PURPLE_LOG_SYSTEM, ".system", account, ".html", PURPLE_TYPE_HTML_LOG, cancellable, error);
+ return purple_log_common_lister(PURPLE_LOG_SYSTEM, ".system", account,
+ ".html", PURPLE_TYPE_HTML_LOG, cancellable, error);
}
static gchar *
-purple_html_log_read(PurpleLog *log, PurpleLogReadFlags *flags, GCancellable *cancellable, GError **error)
+purple_html_log_read(PurpleLog *log, PurpleLogReadFlags *flags,
+ GCancellable *cancellable, GError **error)
{
GFile *file;
gchar *read, *minus_header;
@@ -293,9 +401,12 @@ static gssize
}
static gssize
-purple_html_log_total_size(PurpleLog *log, 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);
+ return purple_log_common_total_sizer(type, name, account, ".html",
+ cancellable, error);
}
static void
More information about the Commits
mailing list