comparison src/log.c @ 13119:fcde3faa1f57

[gaim-migrate @ 15481] This adds support for displaying log timestamps in their original timezone. If your OS's definition of struct tm sucks, then the log timestamps will show up in your local timezone, but converted, so the time is accurate. Yay! Anyway, this all works, as I've renamed lots of my log files locally, but currently, there's no code to save new logs in this name format. That's held up on a portability issue and backwards compatibility issue. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Sat, 04 Feb 2006 20:55:52 +0000
parents a0a4b44239e8
children 0d755026832c
comparison
equal deleted inserted replaced
13118:8855973b487b 13119:fcde3faa1f57
70 /************************************************************************** 70 /**************************************************************************
71 * PUBLIC LOGGING FUNCTIONS *********************************************** 71 * PUBLIC LOGGING FUNCTIONS ***********************************************
72 **************************************************************************/ 72 **************************************************************************/
73 73
74 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, 74 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account,
75 GaimConversation *conv, time_t time) 75 GaimConversation *conv, time_t time, const struct tm *tm)
76 { 76 {
77 GaimLog *log = g_new0(GaimLog, 1); 77 GaimLog *log = g_new0(GaimLog, 1);
78 log->name = g_strdup(gaim_normalize(account, name)); 78 log->name = g_strdup(gaim_normalize(account, name));
79 log->account = account; 79 log->account = account;
80 log->conv = conv; 80 log->conv = conv;
81 log->time = time; 81 log->time = time;
82 log->type = type; 82 log->type = type;
83 log->logger_data = NULL; 83 log->logger_data = NULL;
84 if (tm != NULL)
85 {
86 log->tm = g_new0(struct tm, 1);
87 *(log->tm) = *tm;
88
89 #ifdef HAVE_STRUCT_TM_TM_ZONE
90 /* XXX: This is so wrong... */
91 if (log->tm->tm_zone != NULL)
92 log->tm->tm_zone = (const char *)g_strdup(log->tm->tm_zone);
93 #endif
94 }
84 log->logger = gaim_log_logger_get(); 95 log->logger = gaim_log_logger_get();
85 if (log->logger && log->logger->create) 96 if (log->logger && log->logger->create)
86 log->logger->create(log); 97 log->logger->create(log);
87 return log; 98 return log;
88 } 99 }
91 { 102 {
92 g_return_if_fail(log); 103 g_return_if_fail(log);
93 if (log->logger && log->logger->finalize) 104 if (log->logger && log->logger->finalize)
94 log->logger->finalize(log); 105 log->logger->finalize(log);
95 g_free(log->name); 106 g_free(log->name);
107
108 if (log->tm != NULL)
109 {
110 #ifdef HAVE_STRUCT_TM_TM_ZONE
111 /* XXX: This is so wrong... */
112 g_free((char *)log->tm->tm_zone);
113 #endif
114 g_free(log->tm);
115 }
116
96 g_free(log); 117 g_free(log);
97 } 118 }
98 119
99 void gaim_log_write(GaimLog *log, GaimMessageFlags type, 120 void gaim_log_write(GaimLog *log, GaimMessageFlags type,
100 const char *from, time_t time, const char *message) 121 const char *from, time_t time, const char *message)
664 if (gaim_str_has_suffix(filename, ext) && 685 if (gaim_str_has_suffix(filename, ext) &&
665 strlen(filename) >= (17 + strlen(ext))) 686 strlen(filename) >= (17 + strlen(ext)))
666 { 687 {
667 GaimLog *log; 688 GaimLog *log;
668 GaimLogCommonLoggerData *data; 689 GaimLogCommonLoggerData *data;
669 time_t stamp = gaim_str_to_time(filename, FALSE); 690 #if defined (HAVE_TM_GMTOFF) && defined (HAVE_STRUCT_TM_TM_ZONE)
670 691 struct tm tm;
671 log = gaim_log_new(type, name, account, NULL, stamp); 692 long tz_off;
693 const char *rest;
694 time_t stamp = gaim_str_to_time(filename, FALSE, &tm, &tz_off, &rest);
695 char *end;
696
697 /* As zero is a valid offset, GAIM_NO_TZ_OFF means no offset was
698 * provided. See util.h. Yes, it's kinda ugly. */
699 if (tz_off != GAIM_NO_TZ_OFF)
700 tm.tm_gmtoff = tz_off - tm.tm_gmtoff;
701
702 if (rest == NULL || (end = strchr(rest, '.')) == NULL)
703 {
704 log = gaim_log_new(type, name, account, NULL, stamp, NULL);
705 }
706 else
707 {
708 char *tmp = g_strndup(rest, end - rest);
709 tm.tm_zone = tmp;
710 log = gaim_log_new(type, name, account, NULL, stamp, &tm);
711 g_free(tmp);
712 }
713 #else
714 time_t stamp = gaim_str_to_time(filename, FALSE, NULL, NULL, NULL);
715
716 log = gaim_log_new(type, name, account, NULL, stamp, NULL);
717 #endif
718
672 log->logger = logger; 719 log->logger = logger;
673 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); 720 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1);
674 data->path = g_build_filename(path, filename, NULL); 721 data->path = g_build_filename(path, filename, NULL);
675 list = g_list_prepend(list, log); 722 list = g_list_prepend(list, log);
676 } 723 }
930 977
931 /* if we can't write to the file, give up before we hurt ourselves */ 978 /* if we can't write to the file, give up before we hurt ourselves */
932 if(!data->file) 979 if(!data->file)
933 return 0; 980 return 0;
934 981
935 date = gaim_date_format_full(log->time); 982 date = gaim_date_format_full(localtime(&log->time));
936 983
937 written += fprintf(data->file, "<html><head>"); 984 written += fprintf(data->file, "<html><head>");
938 written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"); 985 written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">");
939 written += fprintf(data->file, "<title>"); 986 written += fprintf(data->file, "<title>");
940 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)", 987 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)",
1069 /* if we can't write to the file, give up before we hurt ourselves */ 1116 /* if we can't write to the file, give up before we hurt ourselves */
1070 if(!data->file) 1117 if(!data->file)
1071 return 0; 1118 return 0;
1072 1119
1073 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", 1120 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n",
1074 log->name, gaim_date_format_full(log->time), 1121 log->name, gaim_date_format_full(localtime(&log->time)),
1075 gaim_account_get_username(log->account), prpl); 1122 gaim_account_get_username(log->account), prpl);
1076 } 1123 }
1077 1124
1078 /* if we can't write to the file, give up before we hurt ourselves */ 1125 /* if we can't write to the file, give up before we hurt ourselves */
1079 if(!data->file) 1126 if(!data->file)
1232 1279
1233 if(strchr(buf, '\r')) 1280 if(strchr(buf, '\r'))
1234 newlen--; 1281 newlen--;
1235 1282
1236 if (newlen != 0) { 1283 if (newlen != 0) {
1237 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1); 1284 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
1238 log->logger = old_logger; 1285 log->logger = old_logger;
1239 log->time = lasttime; 1286 log->time = lasttime;
1240 data = g_new0(struct old_logger_data, 1); 1287 data = g_new0(struct old_logger_data, 1);
1241 data->offset = lastoff; 1288 data->offset = lastoff;
1242 data->length = newlen; 1289 data->length = newlen;
1283 } 1330 }
1284 } 1331 }
1285 1332
1286 if (logfound) { 1333 if (logfound) {
1287 if ((newlen = ftell(file) - lastoff) != 0) { 1334 if ((newlen = ftell(file) - lastoff) != 0) {
1288 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1); 1335 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL);
1289 log->logger = old_logger; 1336 log->logger = old_logger;
1290 log->time = lasttime; 1337 log->time = lasttime;
1291 data = g_new0(struct old_logger_data, 1); 1338 data = g_new0(struct old_logger_data, 1);
1292 data->offset = lastoff; 1339 data->offset = lastoff;
1293 data->length = newlen; 1340 data->length = newlen;