comparison src/log.c @ 7764:88886239f31e

[gaim-migrate @ 8409] Move old_logger to stringrefs for paths committer: Tailor Script <tailor@pidgin.im>
author Ethan Blanton <elb@pidgin.im>
date Fri, 05 Dec 2003 16:57:00 +0000
parents 946120d41b77
children 41bcf3f62563
comparison
equal deleted inserted replaced
7763:dc79649b829d 7764:88886239f31e
25 #include "debug.h" 25 #include "debug.h"
26 #include "internal.h" 26 #include "internal.h"
27 #include "log.h" 27 #include "log.h"
28 #include "prefs.h" 28 #include "prefs.h"
29 #include "util.h" 29 #include "util.h"
30 #include "stringref.h"
30 31
31 static GaimLogLogger html_logger; 32 static GaimLogLogger html_logger;
32 static GaimLogLogger txt_logger; 33 static GaimLogLogger txt_logger;
33 static GaimLogLogger old_logger; 34 static GaimLogLogger old_logger;
34 35
694 /* The old logger doesn't write logs, only reads them. This is to include 695 /* The old logger doesn't write logs, only reads them. This is to include
695 * old logs in the log viewer transparently. 696 * old logs in the log viewer transparently.
696 */ 697 */
697 698
698 struct old_logger_data { 699 struct old_logger_data {
699 char *path; 700 GaimStringref *pathref;
700 int offset; 701 int offset;
701 int length; 702 int length;
702 }; 703 };
703 704
704 static GList *old_logger_list(const char *sn, GaimAccount *account) 705 static GList *old_logger_list(const char *sn, GaimAccount *account)
707 char buf[BUF_LONG]; 708 char buf[BUF_LONG];
708 struct tm tm; 709 struct tm tm;
709 char month[4]; 710 char month[4];
710 struct old_logger_data *data = NULL; 711 struct old_logger_data *data = NULL;
711 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); 712 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn));
712 char *path = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); 713 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL);
714 GaimStringref *pathref = gaim_stringref_new(pathstr);
713 char *newlog; 715 char *newlog;
714 int logfound = 0; 716 int logfound = 0;
715 int lastoff = 0; 717 int lastoff = 0;
716 int newlen; 718 int newlen;
717 time_t lasttime; 719 time_t lasttime;
718 720
719 GaimLog *log = NULL; 721 GaimLog *log = NULL;
720 GList *list = NULL; 722 GList *list = NULL;
721 723
722 g_free(logfile); 724 g_free(logfile);
723 725 g_free(pathstr);
724 if (!(file = fopen(path, "rb"))) { 726
725 g_free(path); 727 if (!(file = fopen(gaim_stringref_value(pathref), "rb"))) {
728 gaim_stringref_unref(pathref);
726 return NULL; 729 return NULL;
727 } 730 }
728 731
729 while (fgets(buf, BUF_LONG, file)) { 732 while (fgets(buf, BUF_LONG, file)) {
730 if ((newlog = strstr(buf, "---- New C"))) { 733 if ((newlog = strstr(buf, "---- New C"))) {
761 log->logger = &old_logger; 764 log->logger = &old_logger;
762 log->time = lasttime; 765 log->time = lasttime;
763 data = g_new0(struct old_logger_data, 1); 766 data = g_new0(struct old_logger_data, 1);
764 data->offset = lastoff; 767 data->offset = lastoff;
765 data->length = newlen; 768 data->length = newlen;
766 data->path = g_strdup(path); 769 data->pathref = gaim_stringref_ref(pathref);
767 log->logger_data = data; 770 log->logger_data = data;
768 list = g_list_append(list, log); 771 list = g_list_append(list, log);
769 } 772 }
770 } 773 }
771 774
812 log->logger = &old_logger; 815 log->logger = &old_logger;
813 log->time = lasttime; 816 log->time = lasttime;
814 data = g_new0(struct old_logger_data, 1); 817 data = g_new0(struct old_logger_data, 1);
815 data->offset = lastoff; 818 data->offset = lastoff;
816 data->length = newlen; 819 data->length = newlen;
817 data->path = g_strdup(path); 820 data->pathref = gaim_stringref_ref(pathref);
818 log->logger_data = data; 821 log->logger_data = data;
819 list = g_list_append(list, log); 822 list = g_list_append(list, log);
820 } 823 }
821 } 824 }
822 825
823 g_free(path); 826 gaim_stringref_unref(pathref);
824 fclose(file); 827 fclose(file);
825 return list; 828 return list;
826 } 829 }
827 830
828 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) 831 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags)
829 { 832 {
830 struct old_logger_data *data = log->logger_data; 833 struct old_logger_data *data = log->logger_data;
831 FILE *file = fopen(data->path, "rb"); 834 FILE *file = fopen(gaim_stringref_value(data->pathref), "rb");
832 char *read = g_malloc(data->length + 1); 835 char *read = g_malloc(data->length + 1);
833 fseek(file, data->offset, SEEK_SET); 836 fseek(file, data->offset, SEEK_SET);
834 fread(read, data->length, 1, file); 837 fread(read, data->length, 1, file);
835 read[data->length] = '\0'; 838 read[data->length] = '\0';
836 *flags = 0; 839 *flags = 0;
846 } 849 }
847 850
848 static void old_logger_finalize(GaimLog *log) 851 static void old_logger_finalize(GaimLog *log)
849 { 852 {
850 struct old_logger_data *data = log->logger_data; 853 struct old_logger_data *data = log->logger_data;
851 g_free(data->path); 854 gaim_stringref_unref(data->pathref);
852 g_free(data); 855 g_free(data);
853 } 856 }
854 857
855 static GaimLogLogger old_logger = { 858 static GaimLogLogger old_logger = {
856 "old logger", "old", 859 "old logger", "old",