im.pidgin.pidgin: 2762c6075c0dc52a96098c5478c5bf68cfd890a3
rlaager at pidgin.im
rlaager at pidgin.im
Sat Oct 13 18:00:40 EDT 2007
-----------------------------------------------------------------
Revision: 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Ancestor: 4deed3d2601c30ac4380eb37d703b76b7a66993b
Author: rlaager at pidgin.im
Date: 2007-10-13T21:55:41
Branch: im.pidgin.pidgin
Modified files:
libpurple/plugins/log_reader.c
ChangeLog:
A patch from QuLogic to eliminate some duplication in the aMSN code, also
from QuLogic. Fixes #3497 (again).
-------------- next part --------------
============================================================
--- libpurple/plugins/log_reader.c f937bcfd8babac0ce0b28d236fb0401900c1a72a
+++ libpurple/plugins/log_reader.c 5a4961d4c829f13b002d7612f24eec47b8550f5f
@@ -2095,12 +2095,109 @@ struct amsn_logger_data {
#define AMSN_LOG_CONV_END "|\"LRED[You have closed the window on "
#define AMSN_LOG_CONV_EXTRA "01 Aug 2001 00:00:00]"
+static GList *amsn_logger_parse_file(char *filename, const char *sn, PurpleAccount *account)
+{
+ GList *list = NULL;
+ GError *error;
+ char *contents;
+ struct amsn_logger_data *data;
+ PurpleLog *log;
+
+ purple_debug_info("aMSN logger", "Reading %s\n", filename);
+ error = NULL;
+ if (!g_file_get_contents(filename, &contents, NULL, &error)) {
+ purple_debug_error("aMSN logger",
+ "Couldn't read file %s: %s \n", filename,
+ (error && error->message) ?
+ error->message : "Unknown error");
+ if (error)
+ g_error_free(error);
+ } else {
+ char *c = contents;
+ gboolean found_start = FALSE;
+ char *start_log = c;
+ int offset = 0;
+ struct tm tm;
+ while (c && *c) {
+ if (purple_str_has_prefix(c, AMSN_LOG_CONV_START)) {
+ char month[4];
+ if (sscanf(c + strlen(AMSN_LOG_CONV_START),
+ "%u %3s %u %u:%u:%u",
+ &tm.tm_mday, (char*)&month, &tm.tm_year,
+ &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
+ found_start = FALSE;
+ purple_debug_error("aMSN logger",
+ "Error parsing start date for %s\n",
+ filename);
+ } else {
+ tm.tm_year -= 1900;
+
+ /* Let the C library deal with
+ * daylight savings time.
+ */
+ tm.tm_isdst = -1;
+ tm.tm_mon = get_month(month);
+
+ found_start = TRUE;
+ offset = c - contents;
+ start_log = c;
+ }
+ } else if (purple_str_has_prefix(c, AMSN_LOG_CONV_END) && found_start) {
+ data = g_new0(struct amsn_logger_data, 1);
+ data->path = g_strdup(filename);
+ data->offset = offset;
+ data->length = c - start_log
+ + strlen(AMSN_LOG_CONV_END)
+ + strlen(AMSN_LOG_CONV_EXTRA);
+ log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, mktime(&tm), NULL);
+ log->logger = amsn_logger;
+ log->logger_data = data;
+ list = g_list_prepend(list, log);
+ found_start = FALSE;
+
+ purple_debug_info("aMSN logger",
+ "Found log for %s:"
+ " path = (%s),"
+ " offset = (%d),"
+ " length = (%d)\n",
+ sn, data->path, data->offset, data->length);
+ }
+ c = strstr(c, "\n");
+ c++;
+ }
+
+ /* I've seen the file end without the AMSN_LOG_CONV_END bit */
+ if (found_start) {
+ data = g_new0(struct amsn_logger_data, 1);
+ data->path = g_strdup(filename);
+ data->offset = offset;
+ data->length = c - start_log
+ + strlen(AMSN_LOG_CONV_END)
+ + strlen(AMSN_LOG_CONV_EXTRA);
+ log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, mktime(&tm), NULL);
+ log->logger = amsn_logger;
+ log->logger_data = data;
+ list = g_list_prepend(list, log);
+ found_start = FALSE;
+
+ purple_debug_info("aMSN logger",
+ "Found log for %s:"
+ " path = (%s),"
+ " offset = (%d),"
+ " length = (%d)\n",
+ sn, data->path, data->offset, data->length);
+ }
+ g_free(contents);
+ }
+
+ return list;
+}
+
/* `log_dir`/username at hotmail.com/logs/buddyname at hotmail.com.log */
/* `log_dir`/username at hotmail.com/logs/Month Year/buddyname at hotmail.com.log */
static GList *amsn_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account)
{
GList *list = NULL;
- struct amsn_logger_data *data;
const char *logdir;
char *username;
char *log_path;
@@ -2108,11 +2205,6 @@ static GList *amsn_logger_list(PurpleLog
char *filename;
GDir *dir;
const char *name;
- GError *error;
- char *contents;
- PurpleLog *log;
- GList *files = NULL;
- GList *f;
logdir = purple_prefs_get_string("/plugins/core/log_reader/amsn/log_directory");
@@ -2131,7 +2223,7 @@ static GList *amsn_logger_list(PurpleLog
/* First check in the top-level */
filename = g_build_filename(log_path, buddy_log, NULL);
if (g_file_test(filename, G_FILE_TEST_EXISTS))
- files = g_list_prepend(files, filename);
+ list = amsn_logger_parse_file(filename, sn, account);
else
g_free(filename);
@@ -2141,9 +2233,8 @@ static GList *amsn_logger_list(PurpleLog
while ((name = g_dir_read_name(dir)) != NULL) {
filename = g_build_filename(log_path, name, buddy_log, NULL);
if (g_file_test(filename, G_FILE_TEST_EXISTS))
- files = g_list_prepend(files, filename);
- else
- g_free(filename);
+ list = g_list_concat(list, amsn_logger_parse_file(filename, sn, account));
+ g_free(filename);
}
g_dir_close(dir);
}
@@ -2159,9 +2250,8 @@ static GList *amsn_logger_list(PurpleLog
/* First check in the top-level */
filename = g_build_filename(log_path, buddy_log, NULL);
if (g_file_test(filename, G_FILE_TEST_EXISTS))
- files = g_list_prepend(files, filename);
- else
- g_free(filename);
+ list = g_list_concat(list, amsn_logger_parse_file(filename, sn, account));
+ g_free(filename);
/* Check in previous months */
dir = g_dir_open(log_path, 0, NULL);
@@ -2169,9 +2259,8 @@ static GList *amsn_logger_list(PurpleLog
while ((name = g_dir_read_name(dir)) != NULL) {
filename = g_build_filename(log_path, name, buddy_log, NULL);
if (g_file_test(filename, G_FILE_TEST_EXISTS))
- files = g_list_prepend(files, filename);
- else
- g_free(filename);
+ list = g_list_concat(list, amsn_logger_parse_file(filename, sn, account));
+ g_free(filename);
}
g_dir_close(dir);
}
@@ -2180,100 +2269,6 @@ static GList *amsn_logger_list(PurpleLog
g_free(username);
g_free(buddy_log);
- /* Loop through files looking for logs */
- for(f = g_list_first(files); f; f = g_list_next(f)) {
- filename = f->data;
- purple_debug_info("aMSN logger", "Reading %s\n", filename);
- error = NULL;
- if (!g_file_get_contents(filename, &contents, NULL, &error)) {
- purple_debug_error("aMSN logger",
- "Couldn't read file %s: %s \n", filename,
- (error && error->message) ?
- error->message : "Unknown error");
- if (error)
- g_error_free(error);
- } else {
- char *c = contents;
- gboolean found_start = FALSE;
- char *start_log = c;
- int offset = 0;
- struct tm tm;
- while (c && *c) {
- if (purple_str_has_prefix(c, AMSN_LOG_CONV_START)) {
- char month[4];
- if (sscanf(c + strlen(AMSN_LOG_CONV_START),
- "%u %3s %u %u:%u:%u",
- &tm.tm_mday, (char*)&month, &tm.tm_year,
- &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
- found_start = FALSE;
- purple_debug_error("aMSN logger",
- "Error parsing start date for %s\n",
- filename);
- } else {
- tm.tm_year -= 1900;
-
- /* Let the C library deal with
- * daylight savings time.
- */
- tm.tm_isdst = -1;
- tm.tm_mon = get_month(month);
-
- found_start = TRUE;
- offset = c - contents;
- start_log = c;
- }
- } else if (purple_str_has_prefix(c, AMSN_LOG_CONV_END) && found_start) {
- data = g_new0(struct amsn_logger_data, 1);
- data->path = g_strdup(filename);
- data->offset = offset;
- data->length = c - start_log
- + strlen(AMSN_LOG_CONV_END)
- + strlen(AMSN_LOG_CONV_EXTRA);
- log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, mktime(&tm), NULL);
- log->logger = amsn_logger;
- log->logger_data = data;
- list = g_list_prepend(list, log);
- found_start = FALSE;
-
- purple_debug_info("aMSN logger",
- "Found log for %s:"
- " path = (%s),"
- " offset = (%d),"
- " length = (%d)\n",
- sn, data->path, data->offset, data->length);
- }
- c = strstr(c, "\n");
- c++;
- }
-
- /* I've seen the file end without the AMSN_LOG_CONV_END bit */
- if (found_start) {
- data = g_new0(struct amsn_logger_data, 1);
- data->path = g_strdup(filename);
- data->offset = offset;
- data->length = c - start_log
- + strlen(AMSN_LOG_CONV_END)
- + strlen(AMSN_LOG_CONV_EXTRA);
- log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, mktime(&tm), NULL);
- log->logger = amsn_logger;
- log->logger_data = data;
- list = g_list_prepend(list, log);
- found_start = FALSE;
-
- purple_debug_info("aMSN logger",
- "Found log for %s:"
- " path = (%s),"
- " offset = (%d),"
- " length = (%d)\n",
- sn, data->path, data->offset, data->length);
- }
- g_free(contents);
- }
- g_free(filename);
- }
-
- g_list_free(files);
-
return list;
}
More information about the Commits
mailing list