Mercurial > pidgin.yaz
annotate 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 |
rev | line source |
---|---|
7431 | 1 /** |
2 * @file log.c Logging API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
7436 | 10 * |
7431 | 11 * This program is free software; you can redistribute it and/or modify |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
4184 | 24 */ |
4195 | 25 |
7431 | 26 #include "account.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
27 #include "debug.h" |
7431 | 28 #include "internal.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
29 #include "log.h" |
5548 | 30 #include "prefs.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
31 #include "util.h" |
7764 | 32 #include "stringref.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
33 |
8096 | 34 static GSList *loggers = NULL; |
35 | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
36 static GaimLogLogger *html_logger; |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
37 static GaimLogLogger *txt_logger; |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
38 static GaimLogLogger *old_logger; |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
39 |
8635 | 40 struct _gaim_logsize_user { |
41 char *name; | |
42 GaimAccount *account; | |
43 }; | |
44 static GHashTable *logsize_users = NULL; | |
45 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
46 static void log_get_log_sets_common(GHashTable *sets); |
8635 | 47 |
13059 | 48 static gsize html_logger_write(GaimLog *log, GaimMessageFlags type, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
49 const char *from, time_t time, const char *message); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
50 static void html_logger_finalize(GaimLog *log); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
51 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
52 static GList *html_logger_list_syslog(GaimAccount *account); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
53 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
54 |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
55 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
56 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
57 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
58 static int old_logger_size (GaimLog *log); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
59 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
60 static void old_logger_finalize(GaimLog *log); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
61 |
13059 | 62 static gsize txt_logger_write(GaimLog *log, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
63 GaimMessageFlags type, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
64 const char *from, time_t time, const char *message); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
65 static void txt_logger_finalize(GaimLog *log); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
66 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
67 static GList *txt_logger_list_syslog(GaimAccount *account); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
68 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
69 |
7431 | 70 /************************************************************************** |
71 * PUBLIC LOGGING FUNCTIONS *********************************************** | |
72 **************************************************************************/ | |
4184 | 73 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
74 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
75 GaimConversation *conv, time_t time, const struct tm *tm) |
7431 | 76 { |
77 GaimLog *log = g_new0(GaimLog, 1); | |
8635 | 78 log->name = g_strdup(gaim_normalize(account, name)); |
7431 | 79 log->account = account; |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
80 log->conv = conv; |
7431 | 81 log->time = time; |
8573 | 82 log->type = type; |
8096 | 83 log->logger_data = NULL; |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
84 if (tm != NULL) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
85 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
86 log->tm = g_new0(struct tm, 1); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
87 *(log->tm) = *tm; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
88 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
89 #ifdef HAVE_STRUCT_TM_TM_ZONE |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
90 /* XXX: This is so wrong... */ |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
91 if (log->tm->tm_zone != NULL) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
92 log->tm->tm_zone = (const char *)g_strdup(log->tm->tm_zone); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
93 #endif |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
94 } |
7431 | 95 log->logger = gaim_log_logger_get(); |
7440 | 96 if (log->logger && log->logger->create) |
97 log->logger->create(log); | |
7431 | 98 return log; |
4184 | 99 } |
100 | |
7431 | 101 void gaim_log_free(GaimLog *log) |
4184 | 102 { |
7431 | 103 g_return_if_fail(log); |
104 if (log->logger && log->logger->finalize) | |
105 log->logger->finalize(log); | |
106 g_free(log->name); | |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
107 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
108 if (log->tm != NULL) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
109 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
110 #ifdef HAVE_STRUCT_TM_TM_ZONE |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
111 /* XXX: This is so wrong... */ |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
112 g_free((char *)log->tm->tm_zone); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
113 #endif |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
114 g_free(log->tm); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
115 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
116 |
7431 | 117 g_free(log); |
118 } | |
7436 | 119 |
120 void gaim_log_write(GaimLog *log, GaimMessageFlags type, | |
7431 | 121 const char *from, time_t time, const char *message) |
122 { | |
10173 | 123 struct _gaim_logsize_user *lu; |
13059 | 124 gsize written, total = 0; |
125 gpointer ptrsize; | |
10173 | 126 |
7431 | 127 g_return_if_fail(log); |
128 g_return_if_fail(log->logger); | |
7442 | 129 g_return_if_fail(log->logger->write); |
7431 | 130 |
13059 | 131 written = (log->logger->write)(log, type, from, time, message); |
10171
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
132 |
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
133 lu = g_new(struct _gaim_logsize_user, 1); |
9892 | 134 |
10171
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
135 lu->name = g_strdup(gaim_normalize(log->account, log->name)); |
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
136 lu->account = log->account; |
13059 | 137 |
138 if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) { | |
139 total = GPOINTER_TO_INT(ptrsize); | |
140 total += written; | |
141 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(total)); | |
13076
f3abb141042a
[gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents:
13069
diff
changeset
|
142 } else { |
f3abb141042a
[gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents:
13069
diff
changeset
|
143 g_free(lu->name); |
f3abb141042a
[gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents:
13069
diff
changeset
|
144 g_free(lu); |
13059 | 145 } |
146 | |
4184 | 147 } |
148 | |
7431 | 149 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags) |
4184 | 150 { |
7542 | 151 GaimLogReadFlags mflags; |
7431 | 152 g_return_val_if_fail(log && log->logger, NULL); |
7462 | 153 if (log->logger->read) { |
7535 | 154 char *ret = (log->logger->read)(log, flags ? flags : &mflags); |
11920 | 155 gaim_str_strip_char(ret, '\r'); |
7462 | 156 return ret; |
157 } | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
158 return g_strdup(_("<b><font color=\"red\">The logger has no read function</font></b>")); |
4184 | 159 } |
7616 | 160 |
7556 | 161 int gaim_log_get_size(GaimLog *log) |
162 { | |
163 g_return_val_if_fail(log && log->logger, 0); | |
8096 | 164 |
7556 | 165 if (log->logger->size) |
166 return log->logger->size(log); | |
167 return 0; | |
168 } | |
169 | |
8635 | 170 static guint _gaim_logsize_user_hash(struct _gaim_logsize_user *lu) |
171 { | |
172 return g_str_hash(lu->name); | |
173 } | |
174 | |
175 static guint _gaim_logsize_user_equal(struct _gaim_logsize_user *lu1, | |
176 struct _gaim_logsize_user *lu2) | |
177 { | |
13077
64ca89ffc639
[gaim-migrate @ 15439]
Richard Laager <rlaager@wiktel.com>
parents:
13076
diff
changeset
|
178 return (lu1->account == lu2->account && (!strcmp(lu1->name, lu2->name))); |
8635 | 179 } |
180 | |
181 static void _gaim_logsize_user_free_key(struct _gaim_logsize_user *lu) | |
182 { | |
183 g_free(lu->name); | |
184 g_free(lu); | |
185 } | |
186 | |
8898 | 187 int gaim_log_get_total_size(GaimLogType type, const char *name, GaimAccount *account) |
7556 | 188 { |
9677 | 189 gpointer ptrsize; |
190 int size = 0; | |
8096 | 191 GSList *n; |
8635 | 192 struct _gaim_logsize_user *lu; |
8096 | 193 |
8635 | 194 lu = g_new(struct _gaim_logsize_user, 1); |
195 lu->name = g_strdup(gaim_normalize(account, name)); | |
196 lu->account = account; | |
197 | |
9677 | 198 if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) { |
199 size = GPOINTER_TO_INT(ptrsize); | |
8635 | 200 g_free(lu->name); |
201 g_free(lu); | |
202 } else { | |
203 for (n = loggers; n; n = n->next) { | |
204 GaimLogLogger *logger = n->data; | |
7616 | 205 |
8635 | 206 if(logger->total_size){ |
8898 | 207 size += (logger->total_size)(type, name, account); |
8635 | 208 } else if(logger->list) { |
8898 | 209 GList *logs = (logger->list)(type, name, account); |
8635 | 210 int this_size = 0; |
211 | |
212 while (logs) { | |
213 GList *logs2 = logs->next; | |
214 GaimLog *log = (GaimLog*)(logs->data); | |
215 this_size += gaim_log_get_size(log); | |
216 gaim_log_free(log); | |
217 g_list_free_1(logs); | |
218 logs = logs2; | |
219 } | |
220 | |
221 size += this_size; | |
8096 | 222 } |
8635 | 223 } |
8096 | 224 |
8635 | 225 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(size)); |
7556 | 226 } |
227 return size; | |
228 } | |
4184 | 229 |
10822 | 230 char * |
10577 | 231 gaim_log_get_log_dir(GaimLogType type, const char *name, GaimAccount *account) |
232 { | |
233 GaimPlugin *prpl; | |
234 GaimPluginProtocolInfo *prpl_info; | |
235 const char *prpl_name; | |
236 char *acct_name; | |
9926 | 237 const char *target; |
10577 | 238 char *dir; |
9926 | 239 |
10577 | 240 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account)); |
241 if (!prpl) | |
242 return NULL; | |
243 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
244 prpl_name = prpl_info->list_icon(account, NULL); | |
245 | |
246 acct_name = g_strdup(gaim_escape_filename(gaim_normalize(account, | |
247 gaim_account_get_username(account)))); | |
9923 | 248 |
249 if (type == GAIM_LOG_CHAT) { | |
250 char *temp = g_strdup_printf("%s.chat", gaim_normalize(account, name)); | |
9926 | 251 target = gaim_escape_filename(temp); |
9923 | 252 g_free(temp); |
253 } else if(type == GAIM_LOG_SYSTEM) { | |
9926 | 254 target = ".system"; |
9923 | 255 } else { |
9926 | 256 target = gaim_escape_filename(gaim_normalize(account, name)); |
9923 | 257 } |
258 | |
10577 | 259 dir = g_build_filename(gaim_user_dir(), "logs", prpl_name, acct_name, target, NULL); |
9926 | 260 |
9923 | 261 g_free(acct_name); |
10577 | 262 |
9923 | 263 return dir; |
264 } | |
265 | |
7431 | 266 /**************************************************************************** |
267 * LOGGER FUNCTIONS ********************************************************* | |
268 ****************************************************************************/ | |
4184 | 269 |
7431 | 270 static GaimLogLogger *current_logger = NULL; |
7436 | 271 |
7431 | 272 static void logger_pref_cb(const char *name, GaimPrefType type, |
12816 | 273 gconstpointer value, gpointer data) |
7431 | 274 { |
275 GaimLogLogger *logger; | |
276 GSList *l = loggers; | |
277 while (l) { | |
278 logger = l->data; | |
279 if (!strcmp(logger->id, value)) { | |
280 gaim_log_logger_set(logger); | |
281 return; | |
4184 | 282 } |
7431 | 283 l = l->next; |
284 } | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
285 gaim_log_logger_set(txt_logger); |
7431 | 286 } |
4184 | 287 |
288 | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
289 GaimLogLogger *gaim_log_logger_new(const char *id, const char *name, int functions, ...) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
290 { |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
291 #if 0 |
8898 | 292 void(*create)(GaimLog *), |
13068
78fa9502715b
[gaim-migrate @ 15430]
Richard Laager <rlaager@wiktel.com>
parents:
13059
diff
changeset
|
293 gsize(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *), |
8898 | 294 void(*finalize)(GaimLog *), |
295 GList*(*list)(GaimLogType type, const char*, GaimAccount*), | |
296 char*(*read)(GaimLog*, GaimLogReadFlags*), | |
11025 | 297 int(*size)(GaimLog*), |
298 int(*total_size)(GaimLogType type, const char *name, GaimAccount *account), | |
299 GList*(*list_syslog)(GaimAccount *account), | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
300 void(*get_log_sets)(GaimLogSetCallback cb, GHashTable *sets)) |
7431 | 301 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
302 #endif |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
303 GaimLogLogger *logger; |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
304 va_list args; |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
305 |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
306 g_return_val_if_fail(id != NULL, NULL); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
307 g_return_val_if_fail(name != NULL, NULL); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
308 g_return_val_if_fail(functions >= 1, NULL); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
309 |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
310 logger = g_new0(GaimLogLogger, 1); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
311 logger->id = g_strdup(id); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
312 logger->name = g_strdup(name); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
313 |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
314 va_start(args, functions); |
11025 | 315 |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
316 if (functions >= 1) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
317 logger->create = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
318 if (functions >= 2) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
319 logger->write = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
320 if (functions >= 3) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
321 logger->finalize = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
322 if (functions >= 4) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
323 logger->list = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
324 if (functions >= 5) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
325 logger->read = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
326 if (functions >= 6) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
327 logger->size = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
328 if (functions >= 7) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
329 logger->total_size = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
330 if (functions >= 8) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
331 logger->list_syslog = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
332 if (functions >= 9) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
333 logger->get_log_sets = va_arg(args, void *); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
334 |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
335 if (functions > 9) |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
336 gaim_debug_info("log", "Dropping new functions for logger: %s (%s)\n", name, id); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
337 |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
338 va_end(args); |
11025 | 339 |
7431 | 340 return logger; |
4184 | 341 } |
342 | |
7431 | 343 void gaim_log_logger_free(GaimLogLogger *logger) |
4184 | 344 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
345 g_free(logger->name); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
346 g_free(logger->id); |
7431 | 347 g_free(logger); |
348 } | |
4184 | 349 |
7431 | 350 void gaim_log_logger_add (GaimLogLogger *logger) |
351 { | |
352 g_return_if_fail(logger); | |
353 if (g_slist_find(loggers, logger)) | |
354 return; | |
355 loggers = g_slist_append(loggers, logger); | |
356 } | |
357 | |
358 void gaim_log_logger_remove (GaimLogLogger *logger) | |
359 { | |
360 g_return_if_fail(logger); | |
12574 | 361 loggers = g_slist_remove(loggers, logger); |
4184 | 362 } |
363 | |
7431 | 364 void gaim_log_logger_set (GaimLogLogger *logger) |
4184 | 365 { |
7431 | 366 g_return_if_fail(logger); |
367 current_logger = logger; | |
7436 | 368 } |
4184 | 369 |
7431 | 370 GaimLogLogger *gaim_log_logger_get() |
371 { | |
372 return current_logger; | |
373 } | |
4184 | 374 |
7431 | 375 GList *gaim_log_logger_get_options(void) |
376 { | |
377 GSList *n; | |
378 GList *list = NULL; | |
379 GaimLogLogger *data; | |
4184 | 380 |
7431 | 381 for (n = loggers; n; n = n->next) { |
382 data = n->data; | |
383 if (!data->write) | |
384 continue; | |
12241
4777c5912068
[gaim-migrate @ 14543]
Richard Laager <rlaager@wiktel.com>
parents:
12240
diff
changeset
|
385 list = g_list_append(list, data->name); |
7431 | 386 list = g_list_append(list, data->id); |
4184 | 387 } |
388 | |
7431 | 389 return list; |
390 } | |
391 | |
8573 | 392 gint gaim_log_compare(gconstpointer y, gconstpointer z) |
7431 | 393 { |
7436 | 394 const GaimLog *a = y; |
395 const GaimLog *b = z; | |
396 | |
7431 | 397 return b->time - a->time; |
398 } | |
399 | |
8898 | 400 GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account) |
7431 | 401 { |
402 GList *logs = NULL; | |
403 GSList *n; | |
404 for (n = loggers; n; n = n->next) { | |
405 GaimLogLogger *logger = n->data; | |
406 if (!logger->list) | |
407 continue; | |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
408 logs = g_list_concat(logger->list(type, name, account), logs); |
7431 | 409 } |
7436 | 410 |
8573 | 411 return g_list_sort(logs, gaim_log_compare); |
412 } | |
413 | |
11025 | 414 gint gaim_log_set_compare(gconstpointer y, gconstpointer z) |
415 { | |
416 const GaimLogSet *a = y; | |
417 const GaimLogSet *b = z; | |
418 gint ret = 0; | |
419 | |
420 /* This logic seems weird at first... | |
421 * If either account is NULL, we pretend the accounts are | |
422 * equal. This allows us to detect duplicates that will | |
423 * exist if one logger knows the account and another | |
424 * doesn't. */ | |
425 if (a->account != NULL && b->account != NULL) { | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
426 ret = strcmp(gaim_account_get_username(a->account), gaim_account_get_username(b->account)); |
11025 | 427 if (ret != 0) |
428 return ret; | |
429 } | |
430 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
431 ret = strcmp(a->normalized_name, b->normalized_name); |
11025 | 432 if (ret != 0) |
433 return ret; | |
434 | |
435 return (gint)b->type - (gint)a->type; | |
436 } | |
437 | |
11677 | 438 static guint |
439 log_set_hash(gconstpointer key) | |
11025 | 440 { |
441 const GaimLogSet *set = key; | |
442 | |
443 /* The account isn't hashed because we need GaimLogSets with NULL accounts | |
444 * to be found when we search by a GaimLogSet that has a non-NULL account | |
445 * but the same type and name. */ | |
446 return g_int_hash((gint *)&set->type) + g_str_hash(set->name); | |
447 } | |
448 | |
11677 | 449 static gboolean |
450 log_set_equal(gconstpointer a, gconstpointer b) | |
11025 | 451 { |
452 /* I realize that the choices made for GList and GHashTable | |
453 * make sense for those data types, but I wish the comparison | |
454 * functions were compatible. */ | |
455 return !gaim_log_set_compare(a, b); | |
456 } | |
457 | |
11677 | 458 static void |
459 log_add_log_set_to_hash(GHashTable *sets, GaimLogSet *set) | |
11025 | 460 { |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
461 GaimLogSet *existing_set = g_hash_table_lookup(sets, set); |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
462 |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
463 if (existing_set == NULL) |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
464 g_hash_table_insert(sets, set, set); |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
465 else if (existing_set->account == NULL && set->account != NULL) |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
466 g_hash_table_replace(sets, set, set); |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
467 else |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
468 gaim_log_set_free(set); |
11025 | 469 } |
470 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
471 GHashTable *gaim_log_get_log_sets(void) |
11025 | 472 { |
473 GSList *n; | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
474 GHashTable *sets = g_hash_table_new_full(log_set_hash, log_set_equal, |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
475 (GDestroyNotify)gaim_log_set_free, NULL); |
11025 | 476 |
477 /* Get the log sets from all the loggers. */ | |
478 for (n = loggers; n; n = n->next) { | |
479 GaimLogLogger *logger = n->data; | |
480 | |
481 if (!logger->get_log_sets) | |
482 continue; | |
483 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
484 logger->get_log_sets(log_add_log_set_to_hash, sets); |
11025 | 485 } |
486 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
487 log_get_log_sets_common(sets); |
11025 | 488 |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
489 /* Return the GHashTable of unique GaimLogSets. */ |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
490 return sets; |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
491 } |
11025 | 492 |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
493 void gaim_log_set_free(GaimLogSet *set) |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
494 { |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
495 g_return_if_fail(set != NULL); |
11025 | 496 |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
497 g_free(set->name); |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
498 if (set->normalized_name != set->name) |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
499 g_free(set->normalized_name); |
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
500 g_free(set); |
11025 | 501 } |
502 | |
8573 | 503 GList *gaim_log_get_system_logs(GaimAccount *account) |
504 { | |
505 GList *logs = NULL; | |
506 GSList *n; | |
507 for (n = loggers; n; n = n->next) { | |
508 GaimLogLogger *logger = n->data; | |
509 if (!logger->list_syslog) | |
510 continue; | |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
511 logs = g_list_concat(logger->list_syslog(account), logs); |
8573 | 512 } |
513 | |
514 return g_list_sort(logs, gaim_log_compare); | |
7431 | 515 } |
516 | |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
517 /**************************************************************************** |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
518 * LOG SUBSYSTEM ************************************************************ |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
519 ****************************************************************************/ |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
520 |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
521 void * |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
522 gaim_log_get_handle(void) |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
523 { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
524 static int handle; |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
525 |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
526 return &handle; |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
527 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
528 |
7431 | 529 void gaim_log_init(void) |
7436 | 530 { |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
531 void *handle = gaim_log_get_handle(); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
532 |
7431 | 533 gaim_prefs_add_none("/core/logging"); |
7555 | 534 gaim_prefs_add_bool("/core/logging/log_ims", FALSE); |
535 gaim_prefs_add_bool("/core/logging/log_chats", FALSE); | |
8573 | 536 gaim_prefs_add_bool("/core/logging/log_system", FALSE); |
537 | |
7431 | 538 gaim_prefs_add_string("/core/logging/format", "txt"); |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
539 |
12240 | 540 html_logger = gaim_log_logger_new("html", _("HTML"), 8, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
541 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
542 html_logger_write, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
543 html_logger_finalize, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
544 html_logger_list, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
545 html_logger_read, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
546 gaim_log_common_sizer, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
547 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
548 html_logger_list_syslog); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
549 gaim_log_logger_add(html_logger); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
550 |
12240 | 551 txt_logger = gaim_log_logger_new("txt", _("Plain text"), 8, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
552 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
553 txt_logger_write, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
554 txt_logger_finalize, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
555 txt_logger_list, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
556 txt_logger_read, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
557 gaim_log_common_sizer, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
558 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
559 txt_logger_list_syslog); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
560 gaim_log_logger_add(txt_logger); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
561 |
12240 | 562 old_logger = gaim_log_logger_new("old", _("Old Gaim"), 9, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
563 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
564 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
565 old_logger_finalize, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
566 old_logger_list, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
567 old_logger_read, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
568 old_logger_size, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
569 old_logger_total_size, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
570 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
571 old_logger_get_log_sets); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
572 gaim_log_logger_add(old_logger); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
573 |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
574 gaim_signal_register(handle, "log-timestamp", |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
575 gaim_marshal_POINTER__POINTER_POINTER, |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
576 gaim_value_new(GAIM_TYPE_POINTER), 2, |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
577 gaim_value_new(GAIM_TYPE_SUBTYPE, |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
578 GAIM_SUBTYPE_LOG), |
12834
03ff00e0bb84
[gaim-migrate @ 15182]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
579 gaim_value_new(GAIM_TYPE_BOXED, |
03ff00e0bb84
[gaim-migrate @ 15182]
Richard Laager <rlaager@wiktel.com>
parents:
12816
diff
changeset
|
580 "struct tm *")); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
581 |
10087 | 582 gaim_prefs_connect_callback(NULL, "/core/logging/format", |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
583 logger_pref_cb, NULL); |
7431 | 584 gaim_prefs_trigger_callback("/core/logging/format"); |
8635 | 585 |
586 logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash, | |
587 (GEqualFunc)_gaim_logsize_user_equal, | |
588 (GDestroyNotify)_gaim_logsize_user_free_key, NULL); | |
7431 | 589 } |
590 | |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
591 void |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
592 gaim_log_uninit(void) |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
593 { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
594 gaim_signals_unregister_by_instance(gaim_log_get_handle()); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
595 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
596 |
7431 | 597 /**************************************************************************** |
598 * LOGGERS ****************************************************************** | |
599 ****************************************************************************/ | |
600 | |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
601 static char *log_get_timestamp(GaimLog *log, time_t when) |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
602 { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
603 char *date; |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
604 struct tm tm = *(localtime(&when)); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
605 |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
606 date = gaim_signal_emit_return_1(gaim_log_get_handle(), |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
607 "log-timestamp", |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
608 log, &tm); |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
609 if (date != NULL) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
610 return date; |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
611 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
612 if (log->type == GAIM_LOG_SYSTEM || time(NULL) > when + 20*60) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
613 return g_strdup(gaim_date_format_long(&tm)); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
614 else |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
615 return g_strdup(gaim_time_format(&tm)); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
616 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
617 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
618 void gaim_log_common_writer(GaimLog *log, const char *ext) |
9763 | 619 { |
10822 | 620 GaimLogCommonLoggerData *data = log->logger_data; |
9763 | 621 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
622 if (data == NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
623 { |
9763 | 624 /* This log is new */ |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
625 char *dir; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
626 const char *date; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
627 char *filename; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
628 char *path; |
10577 | 629 |
9923 | 630 dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
10577 | 631 if (dir == NULL) |
632 return; | |
633 | |
9923 | 634 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
9763 | 635 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
636 date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S", localtime(&log->time)); |
9763 | 637 |
638 filename = g_strdup_printf("%s%s", date, ext ? ext : ""); | |
639 | |
640 path = g_build_filename(dir, filename, NULL); | |
641 g_free(dir); | |
642 g_free(filename); | |
643 | |
10822 | 644 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
9763 | 645 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
646 data->file = g_fopen(path, "a"); |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
647 if (data->file == NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
648 { |
9763 | 649 gaim_debug(GAIM_DEBUG_ERROR, "log", |
9892 | 650 "Could not create log file %s\n", path); |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
651 |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
652 if (log->conv != NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
653 gaim_conversation_write(log->conv, NULL, _("Logging of this conversation failed."), |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
654 GAIM_MESSAGE_ERROR, time(NULL)); |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
655 |
9763 | 656 g_free(path); |
657 return; | |
658 } | |
659 g_free(path); | |
10577 | 660 } |
9763 | 661 } |
662 | |
10822 | 663 GList *gaim_log_common_lister(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger) |
7431 | 664 { |
665 GDir *dir; | |
666 GList *list = NULL; | |
7628 | 667 const char *filename; |
8111 | 668 char *path; |
669 | |
670 if(!account) | |
671 return NULL; | |
672 | |
9923 | 673 path = gaim_log_get_log_dir(type, name, account); |
10577 | 674 if (path == NULL) |
675 return NULL; | |
7447 | 676 |
12969
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
677 if (!(dir = g_dir_open(path, 0, NULL))) |
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
678 { |
7431 | 679 g_free(path); |
680 return NULL; | |
681 } | |
8898 | 682 |
12969
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
683 while ((filename = g_dir_read_name(dir))) |
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
684 { |
8577 | 685 if (gaim_str_has_suffix(filename, ext) && |
12969
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
686 strlen(filename) >= (17 + strlen(ext))) |
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
687 { |
7431 | 688 GaimLog *log; |
10822 | 689 GaimLogCommonLoggerData *data; |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
690 #if defined (HAVE_TM_GMTOFF) && defined (HAVE_STRUCT_TM_TM_ZONE) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
691 struct tm tm; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
692 long tz_off; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
693 const char *rest; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
694 time_t stamp = gaim_str_to_time(filename, FALSE, &tm, &tz_off, &rest); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
695 char *end; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
696 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
697 /* As zero is a valid offset, GAIM_NO_TZ_OFF means no offset was |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
698 * provided. See util.h. Yes, it's kinda ugly. */ |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
699 if (tz_off != GAIM_NO_TZ_OFF) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
700 tm.tm_gmtoff = tz_off - tm.tm_gmtoff; |
7431 | 701 |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
702 if (rest == NULL || (end = strchr(rest, '.')) == NULL) |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
703 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
704 log = gaim_log_new(type, name, account, NULL, stamp, NULL); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
705 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
706 else |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
707 { |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
708 char *tmp = g_strndup(rest, end - rest); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
709 tm.tm_zone = tmp; |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
710 log = gaim_log_new(type, name, account, NULL, stamp, &tm); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
711 g_free(tmp); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
712 } |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
713 #else |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
714 time_t stamp = gaim_str_to_time(filename, FALSE, NULL, NULL, NULL); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
715 |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
716 log = gaim_log_new(type, name, account, NULL, stamp, NULL); |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
717 #endif |
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
718 |
7431 | 719 log->logger = logger; |
10822 | 720 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
7616 | 721 data->path = g_build_filename(path, filename, NULL); |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
722 list = g_list_prepend(list, log); |
4184 | 723 } |
724 } | |
7431 | 725 g_dir_close(dir); |
7447 | 726 g_free(path); |
7431 | 727 return list; |
728 } | |
4184 | 729 |
10822 | 730 int gaim_log_common_sizer(GaimLog *log) |
7556 | 731 { |
732 struct stat st; | |
10822 | 733 GaimLogCommonLoggerData *data = log->logger_data; |
7556 | 734 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
735 if (!data->path || g_stat(data->path, &st)) |
7556 | 736 st.st_size = 0; |
737 | |
738 return st.st_size; | |
739 } | |
740 | |
11025 | 741 /* This will build log sets for all loggers that use the common logger |
742 * functions because they use the same directory structure. */ | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
743 static void log_get_log_sets_common(GHashTable *sets) |
11025 | 744 { |
745 gchar *log_path = g_build_filename(gaim_user_dir(), "logs", NULL); | |
746 GDir *log_dir = g_dir_open(log_path, 0, NULL); | |
747 const gchar *protocol; | |
748 | |
749 if (log_dir == NULL) { | |
750 g_free(log_path); | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
751 return; |
11025 | 752 } |
753 | |
754 while ((protocol = g_dir_read_name(log_dir)) != NULL) { | |
755 gchar *protocol_path = g_build_filename(log_path, protocol, NULL); | |
756 GDir *protocol_dir; | |
757 const gchar *username; | |
758 gchar *protocol_unescaped; | |
759 GList *account_iter; | |
760 GList *accounts = NULL; | |
761 | |
762 if ((protocol_dir = g_dir_open(protocol_path, 0, NULL)) == NULL) { | |
763 g_free(protocol_path); | |
764 continue; | |
765 } | |
766 | |
767 /* Using g_strdup() to cover the one-in-a-million chance that a | |
768 * prpl's list_icon function uses gaim_unescape_filename(). */ | |
769 protocol_unescaped = g_strdup(gaim_unescape_filename(protocol)); | |
770 | |
771 /* Find all the accounts for protocol. */ | |
772 for (account_iter = gaim_accounts_get_all() ; account_iter != NULL ; account_iter = account_iter->next) { | |
773 GaimPlugin *prpl; | |
774 GaimPluginProtocolInfo *prpl_info; | |
775 | |
776 prpl = gaim_find_prpl(gaim_account_get_protocol_id((GaimAccount *)account_iter->data)); | |
777 if (!prpl) | |
778 continue; | |
779 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
780 | |
781 if (!strcmp(protocol_unescaped, prpl_info->list_icon((GaimAccount *)account_iter->data, NULL))) | |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
782 accounts = g_list_prepend(accounts, account_iter->data); |
11025 | 783 } |
784 g_free(protocol_unescaped); | |
785 | |
786 while ((username = g_dir_read_name(protocol_dir)) != NULL) { | |
787 gchar *username_path = g_build_filename(protocol_path, username, NULL); | |
788 GDir *username_dir; | |
789 const gchar *username_unescaped; | |
790 GaimAccount *account = NULL; | |
791 gchar *name; | |
792 | |
793 if ((username_dir = g_dir_open(username_path, 0, NULL)) == NULL) { | |
794 g_free(username_path); | |
795 continue; | |
796 } | |
797 | |
798 /* Find the account for username in the list of accounts for protocol. */ | |
799 username_unescaped = gaim_unescape_filename(username); | |
800 for (account_iter = g_list_first(accounts) ; account_iter != NULL ; account_iter = account_iter->next) { | |
801 if (!strcmp(((GaimAccount *)account_iter->data)->username, username_unescaped)) { | |
802 account = account_iter->data; | |
803 break; | |
804 } | |
805 } | |
806 | |
807 /* Don't worry about the cast, name will point to dynamically allocated memory shortly. */ | |
808 while ((name = (gchar *)g_dir_read_name(username_dir)) != NULL) { | |
809 size_t len; | |
810 GaimLogSet *set = g_new0(GaimLogSet, 1); | |
811 | |
812 /* Unescape the filename. */ | |
813 name = g_strdup(gaim_unescape_filename(name)); | |
814 | |
815 /* Get the (possibly new) length of name. */ | |
816 len = strlen(name); | |
817 | |
818 set->account = account; | |
819 set->name = name; | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
820 set->normalized_name = g_strdup(gaim_normalize(account, name)); |
11025 | 821 |
822 /* Chat for .chat or .system at the end of the name to determine the type. */ | |
823 set->type = GAIM_LOG_IM; | |
824 if (len > 7) { | |
825 gchar *tmp = &name[len - 7]; | |
826 if (!strcmp(tmp, ".system")) { | |
827 set->type = GAIM_LOG_SYSTEM; | |
828 *tmp = '\0'; | |
829 } | |
830 } | |
831 if (len > 5) { | |
832 gchar *tmp = &name[len - 5]; | |
833 if (!strcmp(tmp, ".chat")) { | |
834 set->type = GAIM_LOG_CHAT; | |
835 *tmp = '\0'; | |
836 } | |
837 } | |
838 | |
839 /* Determine if this (account, name) combination exists as a buddy. */ | |
11458
4db38b374d3f
[gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents:
11292
diff
changeset
|
840 if (account != NULL) |
4db38b374d3f
[gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents:
11292
diff
changeset
|
841 set->buddy = (gaim_find_buddy(account, name) != NULL); |
11025 | 842 |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
843 log_add_log_set_to_hash(sets, set); |
11025 | 844 } |
845 g_free(username_path); | |
846 g_dir_close(username_dir); | |
847 } | |
848 g_free(protocol_path); | |
849 g_dir_close(protocol_dir); | |
850 } | |
851 g_free(log_path); | |
852 g_dir_close(log_dir); | |
853 } | |
854 | |
7431 | 855 #if 0 /* Maybe some other time. */ |
7443 | 856 /**************** |
7431 | 857 ** XML LOGGER ** |
858 ****************/ | |
859 | |
860 static const char *str_from_msg_type (GaimMessageFlags type) | |
861 { | |
7443 | 862 |
7431 | 863 return ""; |
7443 | 864 |
7431 | 865 } |
866 | |
7443 | 867 static void xml_logger_write(GaimLog *log, |
868 GaimMessageFlags type, | |
7431 | 869 const char *from, time_t time, const char *message) |
870 { | |
871 char *xhtml = NULL; | |
10577 | 872 |
7431 | 873 if (!log->logger_data) { |
874 /* This log is new. We could use the loggers 'new' function, but | |
875 * creating a new file there would result in empty files in the case | |
876 * that you open a convo with someone, but don't say anything. | |
877 */ | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
878 const char *date; |
9923 | 879 char *dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
7431 | 880 FILE *file; |
10577 | 881 |
882 if (dir == NULL) | |
883 return; | |
884 | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
885 date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S.xml", localtime(&log->time)); |
7443 | 886 |
7612 | 887 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
7443 | 888 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
889 char *filename = g_build_filename(dir, date, NULL); |
7431 | 890 g_free(dir); |
7443 | 891 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
892 log->logger_data = g_fopen(filename, "a"); |
7431 | 893 if (!log->logger_data) { |
894 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | |
7564 | 895 g_free(filename); |
7431 | 896 return; |
897 } | |
7564 | 898 g_free(filename); |
7431 | 899 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" |
900 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); | |
7443 | 901 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
902 date = gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
7431 | 903 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", |
904 date, log->name, prpl); | |
905 } | |
7443 | 906 |
9923 | 907 /* if we can't write to the file, give up before we hurt ourselves */ |
908 if(!data->file) | |
909 return; | |
910 | |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
911 date = log_get_timestamp(log, time); |
12692
4da7062a06c2
[gaim-migrate @ 15035]
Richard Laager <rlaager@wiktel.com>
parents:
12574
diff
changeset
|
912 |
7431 | 913 gaim_markup_html_to_xhtml(message, &xhtml, NULL); |
914 if (from) | |
7443 | 915 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n", |
916 str_from_msg_type(type), | |
7431 | 917 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
918 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
919 from, date, xhtml); | |
920 else | |
7443 | 921 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n", |
922 str_from_msg_type(type), | |
7431 | 923 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
924 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
7443 | 925 date, xhtml): |
7431 | 926 fflush(log->logger_data); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
927 g_free(date); |
7431 | 928 g_free(xhtml); |
7443 | 929 } |
930 | |
7431 | 931 static void xml_logger_finalize(GaimLog *log) |
932 { | |
933 if (log->logger_data) { | |
934 fprintf(log->logger_data, "</conversation>\n"); | |
935 fclose(log->logger_data); | |
936 log->logger_data = NULL; | |
937 } | |
938 } | |
7443 | 939 |
8898 | 940 static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 941 { |
10822 | 942 return gaim_log_common_lister(type, sn, account, ".xml", &xml_logger); |
4184 | 943 } |
944 | |
7431 | 945 static GaimLogLogger xml_logger = { |
946 N_("XML"), "xml", | |
947 NULL, | |
948 xml_logger_write, | |
949 xml_logger_finalize, | |
950 xml_logger_list, | |
8096 | 951 NULL, |
11025 | 952 NULL, |
7431 | 953 NULL |
954 }; | |
955 #endif | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
956 |
7431 | 957 /**************************** |
7457 | 958 ** HTML LOGGER ************* |
959 ****************************/ | |
960 | |
13059 | 961 static gsize html_logger_write(GaimLog *log, GaimMessageFlags type, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
962 const char *from, time_t time, const char *message) |
7457 | 963 { |
9763 | 964 char *msg_fixed; |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
965 char *date; |
9613 | 966 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
10822 | 967 GaimLogCommonLoggerData *data = log->logger_data; |
13059 | 968 gsize written = 0; |
9613 | 969 |
7618 | 970 if(!data) { |
9763 | 971 const char *prpl = |
972 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
973 const char *date; |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
974 gaim_log_common_writer(log, ".html"); |
7457 | 975 |
9763 | 976 data = log->logger_data; |
7457 | 977 |
9763 | 978 /* if we can't write to the file, give up before we hurt ourselves */ |
979 if(!data->file) | |
13059 | 980 return 0; |
7616 | 981 |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
982 date = gaim_date_format_full(localtime(&log->time)); |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
983 |
13059 | 984 written += fprintf(data->file, "<html><head>"); |
985 written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"); | |
986 written += fprintf(data->file, "<title>"); | |
987 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)", | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
988 log->name, date, gaim_account_get_username(log->account), prpl); |
13059 | 989 written += fprintf(data->file, "</title></head><body>"); |
990 written += fprintf(data->file, | |
7457 | 991 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
992 log->name, date, gaim_account_get_username(log->account), prpl); |
7457 | 993 } |
7623 | 994 |
9892 | 995 /* if we can't write to the file, give up before we hurt ourselves */ |
996 if(!data->file) | |
13059 | 997 return 0; |
9892 | 998 |
7882 | 999 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1000 date = log_get_timestamp(log, time); |
7882 | 1001 |
8577 | 1002 if(log->type == GAIM_LOG_SYSTEM){ |
13059 | 1003 written += fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); |
8577 | 1004 } else { |
1005 if (type & GAIM_MESSAGE_SYSTEM) | |
13059 | 1006 written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); |
13069
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
1007 else if (type & GAIM_MESSAGE_ERROR) |
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
1008 written += fprintf(data->file, "<font color=\"#FF0000\"><font size=\"2\">(%s)</font><b> %s</b></font><br/>\n", date, msg_fixed); |
8577 | 1009 else if (type & GAIM_MESSAGE_WHISPER) |
13059 | 1010 written += fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", |
8577 | 1011 date, from, msg_fixed); |
1012 else if (type & GAIM_MESSAGE_AUTO_RESP) { | |
1013 if (type & GAIM_MESSAGE_SEND) | |
13059 | 1014 written += fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); |
8577 | 1015 else if (type & GAIM_MESSAGE_RECV) |
13059 | 1016 written += fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); |
8577 | 1017 } else if (type & GAIM_MESSAGE_RECV) { |
1018 if(gaim_message_meify(msg_fixed, -1)) | |
13059 | 1019 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
10645 | 1020 date, from, msg_fixed); |
8577 | 1021 else |
13059 | 1022 written += fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
10645 | 1023 date, from, msg_fixed); |
8577 | 1024 } else if (type & GAIM_MESSAGE_SEND) { |
1025 if(gaim_message_meify(msg_fixed, -1)) | |
13059 | 1026 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
10645 | 1027 date, from, msg_fixed); |
8577 | 1028 else |
13059 | 1029 written += fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
10645 | 1030 date, from, msg_fixed); |
13069
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
1031 } else { |
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
1032 gaim_debug_error("log", "Unhandled message type."); |
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
1033 written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", |
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
1034 date, from, msg_fixed); |
8577 | 1035 } |
7564 | 1036 } |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1037 g_free(date); |
7882 | 1038 g_free(msg_fixed); |
7616 | 1039 fflush(data->file); |
13059 | 1040 |
1041 return written; | |
7457 | 1042 } |
1043 | |
1044 static void html_logger_finalize(GaimLog *log) | |
1045 { | |
10822 | 1046 GaimLogCommonLoggerData *data = log->logger_data; |
7616 | 1047 if (data) { |
1048 if(data->file) { | |
12881
7e45ccd91e58
[gaim-migrate @ 15233]
Richard Laager <rlaager@wiktel.com>
parents:
12834
diff
changeset
|
1049 fprintf(data->file, "</body></html>\n"); |
7616 | 1050 fclose(data->file); |
1051 } | |
1052 g_free(data->path); | |
7752 | 1053 g_free(data); |
7463 | 1054 } |
7457 | 1055 } |
1056 | |
8898 | 1057 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7457 | 1058 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1059 return gaim_log_common_lister(type, sn, account, ".html", html_logger); |
7457 | 1060 } |
1061 | |
8573 | 1062 static GList *html_logger_list_syslog(GaimAccount *account) |
1063 { | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1064 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".html", html_logger); |
8573 | 1065 } |
1066 | |
7457 | 1067 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
1068 { | |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1069 char *read; |
10822 | 1070 GaimLogCommonLoggerData *data = log->logger_data; |
7457 | 1071 *flags = GAIM_LOG_READ_NO_NEWLINE; |
7616 | 1072 if (!data || !data->path) |
1073 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
1074 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1075 char *minus_header = strchr(read, '\n'); |
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1076 |
7457 | 1077 if (!minus_header) |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1078 return read; |
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1079 |
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1080 minus_header = g_strdup(minus_header + 1); |
7457 | 1081 g_free(read); |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1082 |
7457 | 1083 return minus_header; |
1084 } | |
8578 | 1085 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
7457 | 1086 } |
1087 | |
1088 | |
1089 | |
1090 /**************************** | |
7431 | 1091 ** PLAIN TEXT LOGGER ******* |
1092 ****************************/ | |
4184 | 1093 |
13059 | 1094 static gsize txt_logger_write(GaimLog *log, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1095 GaimMessageFlags type, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1096 const char *from, time_t time, const char *message) |
7431 | 1097 { |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1098 char *date; |
9763 | 1099 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
10822 | 1100 GaimLogCommonLoggerData *data = log->logger_data; |
9763 | 1101 char *stripped = NULL; |
1102 | |
13059 | 1103 gsize written = 0; |
1104 | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1105 if (data == NULL) { |
7431 | 1106 /* This log is new. We could use the loggers 'new' function, but |
1107 * creating a new file there would result in empty files in the case | |
1108 * that you open a convo with someone, but don't say anything. | |
1109 */ | |
9763 | 1110 const char *prpl = |
1111 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
1112 gaim_log_common_writer(log, ".txt"); |
8898 | 1113 |
9763 | 1114 data = log->logger_data; |
7436 | 1115 |
9763 | 1116 /* if we can't write to the file, give up before we hurt ourselves */ |
1117 if(!data->file) | |
13059 | 1118 return 0; |
7616 | 1119 |
13059 | 1120 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
1121 log->name, gaim_date_format_full(localtime(&log->time)), |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
1122 gaim_account_get_username(log->account), prpl); |
7431 | 1123 } |
7436 | 1124 |
7623 | 1125 /* if we can't write to the file, give up before we hurt ourselves */ |
1126 if(!data->file) | |
13059 | 1127 return 0; |
7623 | 1128 |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1129 stripped = gaim_markup_strip_html(message); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1130 date = log_get_timestamp(log, time); |
12692
4da7062a06c2
[gaim-migrate @ 15035]
Richard Laager <rlaager@wiktel.com>
parents:
12574
diff
changeset
|
1131 |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1132 if(log->type == GAIM_LOG_SYSTEM){ |
13059 | 1133 written += fprintf(data->file, "---- %s @ %s ----\n", stripped, date); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1134 } else { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1135 if (type & GAIM_MESSAGE_SEND || |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1136 type & GAIM_MESSAGE_RECV) { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1137 if (type & GAIM_MESSAGE_AUTO_RESP) { |
13059 | 1138 written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1139 from, stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1140 } else { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1141 if(gaim_message_meify(stripped, -1)) |
13059 | 1142 written += fprintf(data->file, "(%s) ***%s %s\n", date, from, |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1143 stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1144 else |
13059 | 1145 written += fprintf(data->file, "(%s) %s: %s\n", date, from, |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1146 stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1147 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1148 } else if (type & GAIM_MESSAGE_SYSTEM) |
13059 | 1149 written += fprintf(data->file, "(%s) %s\n", date, stripped); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1150 else if (type & GAIM_MESSAGE_NO_LOG) { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1151 /* This shouldn't happen */ |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1152 g_free(stripped); |
13059 | 1153 return written; |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1154 } else if (type & GAIM_MESSAGE_WHISPER) |
13059 | 1155 written += fprintf(data->file, "(%s) *%s* %s", date, from, stripped); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1156 else |
13059 | 1157 written += fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1158 from ? ":" : "", stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1159 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1160 g_free(date); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1161 g_free(stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1162 fflush(data->file); |
13059 | 1163 |
1164 return written; | |
7431 | 1165 } |
1166 | |
1167 static void txt_logger_finalize(GaimLog *log) | |
1168 { | |
10822 | 1169 GaimLogCommonLoggerData *data = log->logger_data; |
7616 | 1170 if (data) { |
1171 if(data->file) | |
1172 fclose(data->file); | |
1173 if(data->path) | |
1174 g_free(data->path); | |
7752 | 1175 g_free(data); |
7616 | 1176 } |
7431 | 1177 } |
1178 | |
8898 | 1179 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 1180 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1181 return gaim_log_common_lister(type, sn, account, ".txt", txt_logger); |
7431 | 1182 } |
1183 | |
8573 | 1184 static GList *txt_logger_list_syslog(GaimAccount *account) |
1185 { | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1186 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".txt", txt_logger); |
8573 | 1187 } |
1188 | |
7431 | 1189 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
1190 { | |
8517 | 1191 char *read, *minus_header, *minus_header2; |
10822 | 1192 GaimLogCommonLoggerData *data = log->logger_data; |
7457 | 1193 *flags = 0; |
7616 | 1194 if (!data || !data->path) |
1195 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
1196 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
7431 | 1197 minus_header = strchr(read, '\n'); |
1198 if (!minus_header) | |
1199 minus_header = g_strdup(read); | |
7436 | 1200 else |
7431 | 1201 minus_header = g_strdup(minus_header + 1); |
1202 g_free(read); | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10645
diff
changeset
|
1203 minus_header2 = g_markup_escape_text(minus_header, -1); |
8517 | 1204 g_free(minus_header); |
1205 return minus_header2; | |
7431 | 1206 } |
8578 | 1207 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
7436 | 1208 } |
7431 | 1209 |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1210 |
7431 | 1211 |
1212 /**************** | |
1213 * OLD LOGGER *** | |
1214 ****************/ | |
1215 | |
1216 /* The old logger doesn't write logs, only reads them. This is to include | |
1217 * old logs in the log viewer transparently. | |
1218 */ | |
1219 | |
1220 struct old_logger_data { | |
7764 | 1221 GaimStringref *pathref; |
7431 | 1222 int offset; |
1223 int length; | |
1224 }; | |
1225 | |
8898 | 1226 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 1227 { |
1228 FILE *file; | |
1229 char buf[BUF_LONG]; | |
1230 struct tm tm; | |
7761 | 1231 char month[4]; |
7431 | 1232 struct old_logger_data *data = NULL; |
1233 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); | |
7764 | 1234 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); |
1235 GaimStringref *pathref = gaim_stringref_new(pathstr); | |
7431 | 1236 char *newlog; |
7761 | 1237 int logfound = 0; |
1238 int lastoff = 0; | |
1239 int newlen; | |
7791 | 1240 time_t lasttime = 0; |
7431 | 1241 |
1242 GaimLog *log = NULL; | |
1243 GList *list = NULL; | |
1244 | |
7473 | 1245 g_free(logfile); |
7764 | 1246 g_free(pathstr); |
7473 | 1247 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1248 if (!(file = g_fopen(gaim_stringref_value(pathref), "rb"))) { |
7764 | 1249 gaim_stringref_unref(pathref); |
7431 | 1250 return NULL; |
7447 | 1251 } |
7436 | 1252 |
7431 | 1253 while (fgets(buf, BUF_LONG, file)) { |
1254 if ((newlog = strstr(buf, "---- New C"))) { | |
1255 int length; | |
1256 int offset; | |
1257 char convostart[32]; | |
1258 char *temp = strchr(buf, '@'); | |
7436 | 1259 |
7431 | 1260 if (temp == NULL || strlen(temp) < 2) |
1261 continue; | |
7436 | 1262 |
7431 | 1263 temp++; |
1264 length = strcspn(temp, "-"); | |
1265 if (length > 31) length = 31; | |
7436 | 1266 |
7431 | 1267 offset = ftell(file); |
7436 | 1268 |
7761 | 1269 if (logfound) { |
1270 newlen = offset - lastoff - length; | |
7436 | 1271 if(strstr(buf, "----</H3><BR>")) { |
7761 | 1272 newlen -= |
1273 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + | |
1274 sizeof("----</H3><BR>") - 2; | |
7436 | 1275 } else { |
7761 | 1276 newlen -= |
1277 sizeof("---- New Conversation @ ") + sizeof("----") - 2; | |
7436 | 1278 } |
1279 | |
7461 | 1280 if(strchr(buf, '\r')) |
7770 | 1281 newlen--; |
7461 | 1282 |
7761 | 1283 if (newlen != 0) { |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
1284 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL); |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1285 log->logger = old_logger; |
7761 | 1286 log->time = lasttime; |
1287 data = g_new0(struct old_logger_data, 1); | |
1288 data->offset = lastoff; | |
1289 data->length = newlen; | |
7764 | 1290 data->pathref = gaim_stringref_ref(pathref); |
7761 | 1291 log->logger_data = data; |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
1292 list = g_list_prepend(list, log); |
7761 | 1293 } |
7431 | 1294 } |
1295 | |
7761 | 1296 logfound = 1; |
1297 lastoff = offset; | |
7436 | 1298 |
7431 | 1299 g_snprintf(convostart, length, "%s", temp); |
7676 | 1300 sscanf(convostart, "%*s %s %d %d:%d:%d %d", |
1301 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year); | |
1302 /* Ugly hack, in case current locale is not English */ | |
1303 if (strcmp(month, "Jan") == 0) { | |
1304 tm.tm_mon= 0; | |
1305 } else if (strcmp(month, "Feb") == 0) { | |
1306 tm.tm_mon = 1; | |
1307 } else if (strcmp(month, "Mar") == 0) { | |
1308 tm.tm_mon = 2; | |
1309 } else if (strcmp(month, "Apr") == 0) { | |
1310 tm.tm_mon = 3; | |
1311 } else if (strcmp(month, "May") == 0) { | |
1312 tm.tm_mon = 4; | |
1313 } else if (strcmp(month, "Jun") == 0) { | |
1314 tm.tm_mon = 5; | |
1315 } else if (strcmp(month, "Jul") == 0) { | |
1316 tm.tm_mon = 6; | |
1317 } else if (strcmp(month, "Aug") == 0) { | |
1318 tm.tm_mon = 7; | |
1319 } else if (strcmp(month, "Sep") == 0) { | |
1320 tm.tm_mon = 8; | |
1321 } else if (strcmp(month, "Oct") == 0) { | |
1322 tm.tm_mon = 9; | |
1323 } else if (strcmp(month, "Nov") == 0) { | |
1324 tm.tm_mon = 10; | |
1325 } else if (strcmp(month, "Dec") == 0) { | |
1326 tm.tm_mon = 11; | |
1327 } | |
1328 tm.tm_year -= 1900; | |
7761 | 1329 lasttime = mktime(&tm); |
4184 | 1330 } |
1331 } | |
7613 | 1332 |
7761 | 1333 if (logfound) { |
1334 if ((newlen = ftell(file) - lastoff) != 0) { | |
13119
fcde3faa1f57
[gaim-migrate @ 15481]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
1335 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, -1, NULL); |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1336 log->logger = old_logger; |
7761 | 1337 log->time = lasttime; |
1338 data = g_new0(struct old_logger_data, 1); | |
1339 data->offset = lastoff; | |
1340 data->length = newlen; | |
7764 | 1341 data->pathref = gaim_stringref_ref(pathref); |
7761 | 1342 log->logger_data = data; |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
1343 list = g_list_prepend(list, log); |
7761 | 1344 } |
7613 | 1345 } |
1346 | |
7764 | 1347 gaim_stringref_unref(pathref); |
7431 | 1348 fclose(file); |
1349 return list; | |
4184 | 1350 } |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1351 |
8898 | 1352 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account) |
8096 | 1353 { |
1354 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name)); | |
1355 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); | |
1356 int size; | |
1357 struct stat st; | |
1358 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1359 if (g_stat(pathstr, &st)) |
8096 | 1360 size = 0; |
1361 else | |
1362 size = st.st_size; | |
1363 | |
1364 g_free(logfile); | |
1365 g_free(pathstr); | |
1366 | |
1367 return size; | |
1368 } | |
1369 | |
7616 | 1370 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1371 { |
7431 | 1372 struct old_logger_data *data = log->logger_data; |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1373 FILE *file = g_fopen(gaim_stringref_value(data->pathref), "rb"); |
10906 | 1374 char *tmp, *read = g_malloc(data->length + 1); |
7431 | 1375 fseek(file, data->offset, SEEK_SET); |
1376 fread(read, data->length, 1, file); | |
8370 | 1377 fclose(file); |
7431 | 1378 read[data->length] = '\0'; |
7436 | 1379 *flags = 0; |
1380 if(strstr(read, "<BR>")) | |
1381 *flags |= GAIM_LOG_READ_NO_NEWLINE; | |
10906 | 1382 else { |
1383 tmp = g_markup_escape_text(read, -1); | |
1384 g_free(read); | |
1385 read = tmp; | |
1386 } | |
7431 | 1387 return read; |
1388 } | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1389 |
7616 | 1390 static int old_logger_size (GaimLog *log) |
7556 | 1391 { |
1392 struct old_logger_data *data = log->logger_data; | |
7616 | 1393 return data ? data->length : 0; |
1394 } | |
1395 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1396 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets) |
11025 | 1397 { |
1398 char *log_path = g_build_filename(gaim_user_dir(), "logs", NULL); | |
1399 GDir *log_dir = g_dir_open(log_path, 0, NULL); | |
1400 gchar *name; | |
1401 GaimBlistNode *gnode, *cnode, *bnode; | |
1402 | |
1403 g_free(log_path); | |
1404 if (log_dir == NULL) | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1405 return; |
11025 | 1406 |
1407 /* Don't worry about the cast, name will be filled with a dynamically allocated data shortly. */ | |
1408 while ((name = (gchar *)g_dir_read_name(log_dir)) != NULL) { | |
1409 size_t len; | |
1410 gchar *ext; | |
1411 GaimLogSet *set; | |
1412 gboolean found = FALSE; | |
1413 | |
1414 /* Unescape the filename. */ | |
1415 name = g_strdup(gaim_unescape_filename(name)); | |
1416 | |
1417 /* Get the (possibly new) length of name. */ | |
1418 len = strlen(name); | |
1419 | |
1420 if (len < 5) { | |
1421 g_free(name); | |
1422 continue; | |
1423 } | |
1424 | |
1425 /* Make sure we're dealing with a log file. */ | |
1426 ext = &name[len - 4]; | |
1427 if (strcmp(ext, ".log")) { | |
1428 g_free(name); | |
1429 continue; | |
1430 } | |
1431 | |
1432 set = g_new0(GaimLogSet, 1); | |
1433 | |
1434 /* Chat for .chat at the end of the name to determine the type. */ | |
1435 *ext = '\0'; | |
1436 set->type = GAIM_LOG_IM; | |
1437 if (len > 9) { | |
1438 char *tmp = &name[len - 9]; | |
1439 if (!strcmp(tmp, ".chat")) { | |
1440 set->type = GAIM_LOG_CHAT; | |
1441 *tmp = '\0'; | |
1442 } | |
1443 } | |
1444 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1445 set->name = set->normalized_name = name; |
11025 | 1446 |
1447 /* Search the buddy list to find the account and to determine if this is a buddy. */ | |
1448 for (gnode = gaim_get_blist()->root; !found && gnode != NULL; gnode = gnode->next) | |
1449 { | |
1450 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
1451 continue; | |
1452 | |
1453 for (cnode = gnode->child; !found && cnode != NULL; cnode = cnode->next) | |
1454 { | |
1455 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
1456 continue; | |
1457 | |
1458 for (bnode = cnode->child; !found && bnode != NULL; bnode = bnode->next) | |
1459 { | |
1460 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
1461 | |
1462 if (!strcmp(buddy->name, name)) { | |
1463 set->account = buddy->account; | |
1464 set->buddy = TRUE; | |
1465 found = TRUE; | |
1466 } | |
1467 } | |
1468 } | |
1469 } | |
1470 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1471 cb(sets, set); |
11025 | 1472 } |
1473 g_dir_close(log_dir); | |
1474 } | |
1475 | |
7616 | 1476 static void old_logger_finalize(GaimLog *log) |
1477 { | |
1478 struct old_logger_data *data = log->logger_data; | |
7764 | 1479 gaim_stringref_unref(data->pathref); |
7616 | 1480 g_free(data); |
7556 | 1481 } |