pidgin/pidgin

Parents a3d49ff045a8
Children 012857bbfc69
Remove the old logger which means you can longer read old logs. This is fine since purple3 no longerg uses the share config directory as purple2 and in fact requires the ui to set it. This means old data won't be there.
  • +0 -435
    libpurple/log.c
  • --- a/libpurple/log.c Thu Feb 20 23:56:05 2020 -0600
    +++ b/libpurple/log.c Thu Mar 12 23:04:27 2020 -0500
    @@ -27,14 +27,12 @@
    #include "log.h"
    #include "prefs.h"
    #include "util.h"
    -#include "stringref.h"
    #include "time.h"
    static GSList *loggers = NULL;
    static PurpleLogLogger *html_logger;
    static PurpleLogLogger *txt_logger;
    -static PurpleLogLogger *old_logger;
    struct _purple_logsize_user {
    char *name;
    @@ -53,13 +51,6 @@
    static char *html_logger_read(PurpleLog *log, PurpleLogReadFlags *flags);
    static int html_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account);
    -static GList *old_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account);
    -static int old_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account);
    -static char * old_logger_read (PurpleLog *log, PurpleLogReadFlags *flags);
    -static int old_logger_size (PurpleLog *log);
    -static void old_logger_get_log_sets(PurpleLogSetCallback cb, GHashTable *sets);
    -static void old_logger_finalize(PurpleLog *log);
    -
    static gsize txt_logger_write(PurpleLog *log, PurpleMessageFlags type,
    const char *from, GDateTime *time, const char *message);
    static void txt_logger_finalize(PurpleLog *log);
    @@ -637,18 +628,6 @@
    purple_log_common_is_deletable);
    purple_log_logger_add(txt_logger);
    - old_logger = purple_log_logger_new("old", _("Old flat format"), 9,
    - NULL,
    - NULL,
    - old_logger_finalize,
    - old_logger_list,
    - old_logger_read,
    - old_logger_size,
    - old_logger_total_size,
    - NULL,
    - old_logger_get_log_sets);
    - purple_log_logger_add(old_logger);
    -
    purple_signal_register(handle, "log-timestamp",
    purple_marshal_POINTER__POINTER_POINTER_BOOLEAN,
    G_TYPE_STRING, 3,
    @@ -681,10 +660,6 @@
    purple_log_logger_free(txt_logger);
    txt_logger = NULL;
    - purple_log_logger_remove(old_logger);
    - purple_log_logger_free(old_logger);
    - old_logger = NULL;
    -
    g_hash_table_destroy(logsize_users);
    g_hash_table_destroy(logsize_users_decayed);
    }
    @@ -1504,413 +1479,3 @@
    {
    return purple_log_common_total_sizer(type, name, account, ".txt");
    }
    -
    -
    -/****************
    - * OLD LOGGER ***
    - ****************/
    -
    -/* The old logger doesn't write logs, only reads them. This is to include
    - * old logs in the log viewer transparently.
    - */
    -
    -struct old_logger_data {
    - PurpleStringref *pathref;
    - int offset;
    - int length;
    -};
    -
    -static GList *old_logger_list(PurpleLogType type, const char *sn, PurpleAccount *account)
    -{
    - char *logfile = g_strdup_printf("%s.log", purple_normalize(account, sn));
    - char *pathstr = g_build_filename(purple_data_dir(), "logs", logfile, NULL);
    - PurpleStringref *pathref = purple_stringref_new(pathstr);
    - GStatBuf st;
    - time_t log_last_modified;
    - FILE *index;
    - FILE *file;
    - int file_fd, index_fd;
    - char *index_tmp;
    - char buf[BUF_LONG];
    - gint year, month, day, hour, minute, second;
    - char month_str[4];
    - struct old_logger_data *data = NULL;
    - int logfound = 0;
    - int lastoff = 0;
    - int newlen;
    - GDateTime *lasttime = NULL;
    -
    - PurpleLog *log = NULL;
    - GList *list = NULL;
    -
    - g_free(logfile);
    -
    - file_fd = g_open(purple_stringref_value(pathref), 0, O_RDONLY);
    - if (file_fd == -1 || (file = fdopen(file_fd, "rb")) == NULL) {
    - purple_debug_error("log",
    - "Failed to open log file \"%s\" for reading: %s\n",
    - purple_stringref_value(pathref), g_strerror(errno));
    - purple_stringref_unref(pathref);
    - g_free(pathstr);
    - return NULL;
    - }
    - if (_purple_fstat(file_fd, &st) == -1) {
    - purple_stringref_unref(pathref);
    - g_free(pathstr);
    - fclose(file);
    - return NULL;
    - } else
    - log_last_modified = st.st_mtime;
    -
    - /* Change the .log extension to .idx */
    - strcpy(pathstr + strlen(pathstr) - 3, "idx");
    -
    - index_fd = g_open(pathstr, 0, O_RDONLY);
    - if (index_fd != -1) {
    - if (_purple_fstat(index_fd, &st) != 0) {
    - close(index_fd);
    - index_fd = -1;
    - }
    - }
    -
    - if (index_fd != -1) {
    - if (st.st_mtime < log_last_modified)
    - {
    - purple_debug_warning("log", "Index \"%s\" exists, but is older than the log.\n", pathstr);
    - close(index_fd);
    - }
    - else
    - {
    - /* The index file exists and is at least as new as the log, so open it. */
    - if (!(index = fdopen(index_fd, "rb"))) {
    - purple_debug_error("log", "Failed to open index file \"%s\" for reading: %s\n",
    - pathstr, g_strerror(errno));
    -
    - /* Fall through so that we'll parse the log file. */
    - } else {
    - purple_debug_info("log", "Using index: %s\n", pathstr);
    - g_free(pathstr);
    - while (fgets(buf, BUF_LONG, index))
    - {
    - unsigned long idx_time;
    - if (sscanf(buf, "%d\t%d\t%lu", &lastoff, &newlen, &idx_time) == 3)
    - {
    - log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, NULL);
    - log->logger = old_logger;
    - log->time = g_date_time_new_from_unix_local(idx_time);
    -
    - /* IMPORTANT: Always set all members of struct old_logger_data */
    - data = g_slice_new(struct 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);
    - }
    - }
    - fclose(index);
    - purple_stringref_unref(pathref);
    -
    - fclose(file);
    - return list;
    - }
    - }
    - }
    -
    - index_tmp = g_strdup_printf("%s.XXXXXX", pathstr);
    - if ((index_fd = g_mkstemp(index_tmp)) == -1) {
    - purple_debug_error("log", "Failed to open index temp file: %s\n",
    - g_strerror(errno));
    - g_free(pathstr);
    - g_free(index_tmp);
    - index = NULL;
    - } else {
    - if ((index = fdopen(index_fd, "wb")) == NULL)
    - {
    - purple_debug_error("log", "Failed to fdopen() index temp file: %s\n",
    - g_strerror(errno));
    - close(index_fd);
    - if (index_tmp != NULL)
    - {
    - g_unlink(index_tmp);
    - g_free(index_tmp);
    - }
    - g_free(pathstr);
    - }
    - }
    -
    - while (fgets(buf, BUF_LONG, file)) {
    - if (strstr(buf, "---- New C") != NULL) {
    - int length;
    - int offset;
    - char convostart[32];
    - char *temp = strchr(buf, '@');
    -
    - if (temp == NULL || strlen(temp) < 2)
    - continue;
    -
    - temp++;
    - length = strcspn(temp, "-");
    - if (length > 31) length = 31;
    -
    - offset = ftell(file);
    -
    - if (logfound) {
    - newlen = offset - lastoff - length;
    - if(strstr(buf, "----</H3><BR>")) {
    - newlen -=
    - sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") +
    - sizeof("----</H3><BR>") - 2;
    - } else {
    - newlen -=
    - sizeof("---- New Conversation @ ") + sizeof("----") - 2;
    - }
    -
    - if(strchr(buf, '\r'))
    - newlen--;
    -
    - if (newlen != 0) {
    - log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, lasttime);
    - log->logger = old_logger;
    -
    - /* IMPORTANT: Always set all members of struct old_logger_data */
    - data = g_slice_new(struct 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);
    -
    - if (index != NULL) {
    - fprintf(index, "%d\t%d\t%" G_GINT64_FORMAT "\n",
    - data->offset, data->length,
    - g_date_time_to_unix(log->time));
    - }
    - }
    - }
    -
    - logfound = 1;
    - lastoff = offset;
    -
    - g_snprintf(convostart, length, "%s", temp);
    - year = month = day = hour = minute = second = 0;
    - if (sscanf(convostart, "%*s %3s %d %d:%d:%d %d", month_str,
    - &day, &hour, &minute, &second, &year) != 6)
    - {
    - purple_debug_warning("log", "invalid date format\n");
    - }
    - /* Ugly hack, in case current locale is not English */
    - month = purple_time_parse_month(month_str);
    - if (lasttime)
    - g_date_time_unref(lasttime);
    - lasttime = g_date_time_new_local(year, month, day,
    - hour, minute, second);
    - }
    - }
    -
    - if (logfound) {
    - if ((newlen = ftell(file) - lastoff) != 0) {
    - log = purple_log_new(PURPLE_LOG_IM, sn, account, NULL, lasttime);
    - log->logger = old_logger;
    -
    - /* IMPORTANT: Always set all members of struct old_logger_data */
    - data = g_slice_new(struct 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);
    -
    - if (index != NULL) {
    - fprintf(index, "%d\t%d\t%" G_GINT64_FORMAT "\n", data->offset,
    - data->length, g_date_time_to_unix(log->time));
    - }
    - }
    - }
    -
    - if (lasttime)
    - g_date_time_unref(lasttime);
    - purple_stringref_unref(pathref);
    - fclose(file);
    - if (index != NULL)
    - {
    - fclose(index);
    -
    - if (index_tmp == NULL)
    - {
    - g_free(pathstr);
    - g_return_val_if_reached(list);
    - }
    -
    - if (g_rename(index_tmp, pathstr))
    - {
    - purple_debug_warning("log", "Failed to rename index temp file \"%s\" to \"%s\": %s\n",
    - index_tmp, pathstr, g_strerror(errno));
    - g_unlink(index_tmp);
    - }
    - else
    - purple_debug_info("log", "Built index: %s\n", pathstr);
    -
    - g_free(index_tmp);
    - g_free(pathstr);
    - }
    - return list;
    -}
    -
    -static int old_logger_total_size(PurpleLogType type, const char *name, PurpleAccount *account)
    -{
    - char *logfile = g_strdup_printf("%s.log", purple_normalize(account, name));
    - char *pathstr = g_build_filename(purple_data_dir(), "logs", logfile, NULL);
    - int size;
    - GStatBuf st;
    -
    - if (g_stat(pathstr, &st))
    - size = 0;
    - else
    - size = st.st_size;
    -
    - g_free(logfile);
    - g_free(pathstr);
    -
    - return size;
    -}
    -
    -static char * old_logger_read (PurpleLog *log, PurpleLogReadFlags *flags)
    -{
    - size_t result;
    - struct old_logger_data *data = log->logger_data;
    - const char *path = purple_stringref_value(data->pathref);
    - FILE *file = g_fopen(path, "rb");
    - char *read;
    -
    - g_return_val_if_fail(file, g_strdup(""));
    - read = g_malloc(data->length + 1);
    -
    - if (fseek(file, data->offset, SEEK_SET) != 0)
    - result = 0;
    - else
    - result = fread(read, data->length, 1, file);
    - if (result != 1)
    - purple_debug_error("log", "Unable to read from log file: %s\n", path);
    - fclose(file);
    - read[data->length] = '\0';
    - *flags = 0;
    - if (strstr(read, "<BR>"))
    - {
    - *flags |= PURPLE_LOG_READ_NO_NEWLINE;
    - return read;
    - }
    -
    - return process_txt_log(read, NULL);
    -}
    -
    -static int old_logger_size (PurpleLog *log)
    -{
    - struct old_logger_data *data = log->logger_data;
    - return data ? data->length : 0;
    -}
    -
    -static void old_logger_get_log_sets(PurpleLogSetCallback cb, GHashTable *sets)
    -{
    - char *log_path = g_build_filename(purple_data_dir(), "logs", NULL);
    - GDir *log_dir = g_dir_open(log_path, 0, NULL);
    - gchar *name;
    - PurpleBlistNode *gnode, *cnode, *bnode;
    -
    - g_free(log_path);
    - if (log_dir == NULL)
    - return;
    -
    - /* 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) {
    - size_t len;
    - gchar *ext;
    - PurpleLogSet *set;
    - gboolean found = FALSE;
    -
    - /* Unescape the filename. */
    - name = g_strdup(purple_unescape_filename(name));
    -
    - /* Get the (possibly new) length of name. */
    - len = strlen(name);
    -
    - if (len < 5) {
    - g_free(name);
    - continue;
    - }
    -
    - /* Make sure we're dealing with a log file. */
    - ext = &name[len - 4];
    - if (!purple_strequal(ext, ".log")) {
    - g_free(name);
    - continue;
    - }
    -
    - /* IMPORTANT: Always set all members of PurpleLogSet */
    - set = g_slice_new(PurpleLogSet);
    -
    - /* Chat for .chat at the end of the name to determine the type. */
    - *ext = '\0';
    - set->type = PURPLE_LOG_IM;
    - if (len > 9) {
    - char *tmp = &name[len - 9];
    - if (purple_strequal(tmp, ".chat")) {
    - set->type = PURPLE_LOG_CHAT;
    - *tmp = '\0';
    - }
    - }
    -
    - set->name = set->normalized_name = name;
    -
    - /* Search the buddy list to find the account and to determine if this is a buddy. */
    - for (gnode = purple_blist_get_default_root();
    - !found && gnode != NULL;
    - gnode = purple_blist_node_get_sibling_next(gnode)) {
    - if (!PURPLE_IS_GROUP(gnode))
    - continue;
    -
    - for (cnode = purple_blist_node_get_first_child(gnode);
    - !found && cnode != NULL;
    - cnode = purple_blist_node_get_sibling_next(cnode))
    - {
    - if (!PURPLE_IS_CONTACT(cnode))
    - continue;
    -
    - for (bnode = purple_blist_node_get_first_child(cnode);
    - !found && bnode != NULL;
    - bnode = purple_blist_node_get_sibling_next(bnode))
    - {
    - PurpleBuddy *buddy = (PurpleBuddy *)bnode;
    -
    - if (purple_strequal(purple_buddy_get_name(buddy), name)) {
    - set->account = purple_buddy_get_account(buddy);
    - set->buddy = TRUE;
    - found = TRUE;
    - }
    - }
    - }
    - }
    -
    - if (!found)
    - {
    - set->account = NULL;
    - set->buddy = FALSE;
    - }
    -
    - cb(sets, set);
    - }
    - g_dir_close(log_dir);
    -}
    -
    -static void old_logger_finalize(PurpleLog *log)
    -{
    - struct old_logger_data *data = log->logger_data;
    - purple_stringref_unref(data->pathref);
    - g_slice_free(struct old_logger_data, data);
    -}