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