Mercurial > pidgin.yaz
annotate src/log.c @ 12601:e63fb8e9f4ac
[gaim-migrate @ 14935]
Jason LeBrun wrote to gaim-devel:
"I have found a small quirk in the way gdk_pixbuf_loader works. When you
are using it without signalling, the proper way to use it is to call
gdk_pixbuf_loader_close *before* calling gdk_pixbuf_loader_get_animation
or gdk_pixbuf_loader_get_pixbuf. The call to gdk_pixbuf_loader_close
signals that no more writes will be occuring.
In particular, this affects images that are less than 1k in size. If
gdk_pixbuf_loader_close is not called before _get_animation, the loader
will not return anything unless it has received more than 1k of data
(the file type sniffing buffer size) or it has been closed.
So, the proper order of calls for loaders in the gtk*.c code is:
gdk_pixbuf_loader_new();
gdk_pixbuf_loader_write();
gdk_pixbuf_loader_close();
gdk_pixbuf_loader_get_animation();"
I know we fixed a bug by changing this in one place. I've gone through and updated the rest.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Wed, 21 Dec 2005 18:43:39 +0000 |
parents | a4500bcbec08 |
children | 4da7062a06c2 |
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, |
244 gpointer value, gpointer data) | |
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 | |
488 void gaim_log_init(void) | |
7436 | 489 { |
7431 | 490 gaim_prefs_add_none("/core/logging"); |
7555 | 491 gaim_prefs_add_bool("/core/logging/log_ims", FALSE); |
492 gaim_prefs_add_bool("/core/logging/log_chats", FALSE); | |
8573 | 493 gaim_prefs_add_bool("/core/logging/log_system", FALSE); |
494 | |
7431 | 495 gaim_prefs_add_string("/core/logging/format", "txt"); |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
496 |
12240 | 497 html_logger = gaim_log_logger_new("html", _("HTML"), 8, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
498 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
499 html_logger_write, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
500 html_logger_finalize, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
501 html_logger_list, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
502 html_logger_read, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
503 gaim_log_common_sizer, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
504 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
505 html_logger_list_syslog); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
506 gaim_log_logger_add(html_logger); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
507 |
12240 | 508 txt_logger = gaim_log_logger_new("txt", _("Plain text"), 8, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
509 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
510 txt_logger_write, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
511 txt_logger_finalize, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
512 txt_logger_list, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
513 txt_logger_read, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
514 gaim_log_common_sizer, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
515 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
516 txt_logger_list_syslog); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
517 gaim_log_logger_add(txt_logger); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
518 |
12240 | 519 old_logger = gaim_log_logger_new("old", _("Old Gaim"), 9, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
520 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
521 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
522 old_logger_finalize, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
523 old_logger_list, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
524 old_logger_read, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
525 old_logger_size, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
526 old_logger_total_size, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
527 NULL, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
528 old_logger_get_log_sets); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
529 gaim_log_logger_add(old_logger); |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
530 |
10087 | 531 gaim_prefs_connect_callback(NULL, "/core/logging/format", |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
532 logger_pref_cb, NULL); |
7431 | 533 gaim_prefs_trigger_callback("/core/logging/format"); |
8635 | 534 |
535 logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash, | |
536 (GEqualFunc)_gaim_logsize_user_equal, | |
537 (GDestroyNotify)_gaim_logsize_user_free_key, NULL); | |
7431 | 538 } |
539 | |
540 /**************************************************************************** | |
541 * LOGGERS ****************************************************************** | |
542 ****************************************************************************/ | |
543 | |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
544 void gaim_log_common_writer(GaimLog *log, const char *ext) |
9763 | 545 { |
546 char date[64]; | |
10822 | 547 GaimLogCommonLoggerData *data = log->logger_data; |
9763 | 548 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
549 if (data == NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
550 { |
9763 | 551 /* This log is new */ |
9923 | 552 char *dir, *filename, *path; |
10577 | 553 |
9923 | 554 dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
10577 | 555 if (dir == NULL) |
556 return; | |
557 | |
9923 | 558 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
9763 | 559 |
560 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S", localtime(&log->time)); | |
561 | |
562 filename = g_strdup_printf("%s%s", date, ext ? ext : ""); | |
563 | |
564 path = g_build_filename(dir, filename, NULL); | |
565 g_free(dir); | |
566 g_free(filename); | |
567 | |
10822 | 568 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
9763 | 569 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
570 data->file = g_fopen(path, "a"); |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
571 if (data->file == NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
572 { |
9763 | 573 gaim_debug(GAIM_DEBUG_ERROR, "log", |
9892 | 574 "Could not create log file %s\n", path); |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
575 |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
576 if (log->conv != NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
577 gaim_conversation_write(log->conv, NULL, _("Logging of this conversation failed."), |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
578 GAIM_MESSAGE_ERROR, time(NULL)); |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
579 |
9763 | 580 g_free(path); |
581 return; | |
582 } | |
583 g_free(path); | |
10577 | 584 } |
9763 | 585 } |
586 | |
10822 | 587 GList *gaim_log_common_lister(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger) |
7431 | 588 { |
589 GDir *dir; | |
590 GList *list = NULL; | |
7628 | 591 const char *filename; |
8111 | 592 char *path; |
593 | |
594 if(!account) | |
595 return NULL; | |
596 | |
9923 | 597 path = gaim_log_get_log_dir(type, name, account); |
10577 | 598 if (path == NULL) |
599 return NULL; | |
7447 | 600 |
7431 | 601 if (!(dir = g_dir_open(path, 0, NULL))) { |
602 g_free(path); | |
603 return NULL; | |
604 } | |
8898 | 605 |
7431 | 606 while ((filename = g_dir_read_name(dir))) { |
8577 | 607 if (gaim_str_has_suffix(filename, ext) && |
608 strlen(filename) == 17 + strlen(ext)) { | |
7431 | 609 GaimLog *log; |
10822 | 610 GaimLogCommonLoggerData *data; |
8577 | 611 time_t stamp = gaim_str_to_time(filename, FALSE); |
7431 | 612 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
613 log = gaim_log_new(type, name, account, NULL, stamp); |
7431 | 614 log->logger = logger; |
10822 | 615 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
7616 | 616 data->path = g_build_filename(path, filename, NULL); |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
617 list = g_list_prepend(list, log); |
4184 | 618 } |
619 } | |
7431 | 620 g_dir_close(dir); |
7447 | 621 g_free(path); |
7431 | 622 return list; |
623 } | |
4184 | 624 |
10822 | 625 int gaim_log_common_sizer(GaimLog *log) |
7556 | 626 { |
627 struct stat st; | |
10822 | 628 GaimLogCommonLoggerData *data = log->logger_data; |
7556 | 629 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
630 if (!data->path || g_stat(data->path, &st)) |
7556 | 631 st.st_size = 0; |
632 | |
633 return st.st_size; | |
634 } | |
635 | |
11025 | 636 /* This will build log sets for all loggers that use the common logger |
637 * functions because they use the same directory structure. */ | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
638 static void log_get_log_sets_common(GHashTable *sets) |
11025 | 639 { |
640 gchar *log_path = g_build_filename(gaim_user_dir(), "logs", NULL); | |
641 GDir *log_dir = g_dir_open(log_path, 0, NULL); | |
642 const gchar *protocol; | |
643 | |
644 if (log_dir == NULL) { | |
645 g_free(log_path); | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
646 return; |
11025 | 647 } |
648 | |
649 while ((protocol = g_dir_read_name(log_dir)) != NULL) { | |
650 gchar *protocol_path = g_build_filename(log_path, protocol, NULL); | |
651 GDir *protocol_dir; | |
652 const gchar *username; | |
653 gchar *protocol_unescaped; | |
654 GList *account_iter; | |
655 GList *accounts = NULL; | |
656 | |
657 if ((protocol_dir = g_dir_open(protocol_path, 0, NULL)) == NULL) { | |
658 g_free(protocol_path); | |
659 continue; | |
660 } | |
661 | |
662 /* Using g_strdup() to cover the one-in-a-million chance that a | |
663 * prpl's list_icon function uses gaim_unescape_filename(). */ | |
664 protocol_unescaped = g_strdup(gaim_unescape_filename(protocol)); | |
665 | |
666 /* Find all the accounts for protocol. */ | |
667 for (account_iter = gaim_accounts_get_all() ; account_iter != NULL ; account_iter = account_iter->next) { | |
668 GaimPlugin *prpl; | |
669 GaimPluginProtocolInfo *prpl_info; | |
670 | |
671 prpl = gaim_find_prpl(gaim_account_get_protocol_id((GaimAccount *)account_iter->data)); | |
672 if (!prpl) | |
673 continue; | |
674 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
675 | |
676 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
|
677 accounts = g_list_prepend(accounts, account_iter->data); |
11025 | 678 } |
679 g_free(protocol_unescaped); | |
680 | |
681 while ((username = g_dir_read_name(protocol_dir)) != NULL) { | |
682 gchar *username_path = g_build_filename(protocol_path, username, NULL); | |
683 GDir *username_dir; | |
684 const gchar *username_unescaped; | |
685 GaimAccount *account = NULL; | |
686 gchar *name; | |
687 | |
688 if ((username_dir = g_dir_open(username_path, 0, NULL)) == NULL) { | |
689 g_free(username_path); | |
690 continue; | |
691 } | |
692 | |
693 /* Find the account for username in the list of accounts for protocol. */ | |
694 username_unescaped = gaim_unescape_filename(username); | |
695 for (account_iter = g_list_first(accounts) ; account_iter != NULL ; account_iter = account_iter->next) { | |
696 if (!strcmp(((GaimAccount *)account_iter->data)->username, username_unescaped)) { | |
697 account = account_iter->data; | |
698 break; | |
699 } | |
700 } | |
701 | |
702 /* Don't worry about the cast, name will point to dynamically allocated memory shortly. */ | |
703 while ((name = (gchar *)g_dir_read_name(username_dir)) != NULL) { | |
704 size_t len; | |
705 GaimLogSet *set = g_new0(GaimLogSet, 1); | |
706 | |
707 /* Unescape the filename. */ | |
708 name = g_strdup(gaim_unescape_filename(name)); | |
709 | |
710 /* Get the (possibly new) length of name. */ | |
711 len = strlen(name); | |
712 | |
713 set->account = account; | |
714 set->name = name; | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
715 set->normalized_name = g_strdup(gaim_normalize(account, name)); |
11025 | 716 |
717 /* Chat for .chat or .system at the end of the name to determine the type. */ | |
718 set->type = GAIM_LOG_IM; | |
719 if (len > 7) { | |
720 gchar *tmp = &name[len - 7]; | |
721 if (!strcmp(tmp, ".system")) { | |
722 set->type = GAIM_LOG_SYSTEM; | |
723 *tmp = '\0'; | |
724 } | |
725 } | |
726 if (len > 5) { | |
727 gchar *tmp = &name[len - 5]; | |
728 if (!strcmp(tmp, ".chat")) { | |
729 set->type = GAIM_LOG_CHAT; | |
730 *tmp = '\0'; | |
731 } | |
732 } | |
733 | |
734 /* Determine if this (account, name) combination exists as a buddy. */ | |
11458
4db38b374d3f
[gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents:
11292
diff
changeset
|
735 if (account != NULL) |
4db38b374d3f
[gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents:
11292
diff
changeset
|
736 set->buddy = (gaim_find_buddy(account, name) != NULL); |
11025 | 737 |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
738 log_add_log_set_to_hash(sets, set); |
11025 | 739 } |
740 g_free(username_path); | |
741 g_dir_close(username_dir); | |
742 } | |
743 g_free(protocol_path); | |
744 g_dir_close(protocol_dir); | |
745 } | |
746 g_free(log_path); | |
747 g_dir_close(log_dir); | |
748 } | |
749 | |
7431 | 750 #if 0 /* Maybe some other time. */ |
7443 | 751 /**************** |
7431 | 752 ** XML LOGGER ** |
753 ****************/ | |
754 | |
755 static const char *str_from_msg_type (GaimMessageFlags type) | |
756 { | |
7443 | 757 |
7431 | 758 return ""; |
7443 | 759 |
7431 | 760 } |
761 | |
7443 | 762 static void xml_logger_write(GaimLog *log, |
763 GaimMessageFlags type, | |
7431 | 764 const char *from, time_t time, const char *message) |
765 { | |
766 char date[64]; | |
767 char *xhtml = NULL; | |
10577 | 768 |
7431 | 769 if (!log->logger_data) { |
770 /* This log is new. We could use the loggers 'new' function, but | |
771 * creating a new file there would result in empty files in the case | |
772 * that you open a convo with someone, but don't say anything. | |
773 */ | |
9923 | 774 char *dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
7431 | 775 FILE *file; |
10577 | 776 |
777 if (dir == NULL) | |
778 return; | |
779 | |
7453 | 780 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time)); |
7443 | 781 |
7612 | 782 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
7443 | 783 |
7431 | 784 char *filename = g_build_filename(dir, date, NULL); |
785 g_free(dir); | |
7443 | 786 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
787 log->logger_data = g_fopen(filename, "a"); |
7431 | 788 if (!log->logger_data) { |
789 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | |
7564 | 790 g_free(filename); |
7431 | 791 return; |
792 } | |
7564 | 793 g_free(filename); |
7431 | 794 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" |
795 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); | |
7443 | 796 |
7453 | 797 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
7431 | 798 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", |
799 date, log->name, prpl); | |
800 } | |
7443 | 801 |
9923 | 802 /* if we can't write to the file, give up before we hurt ourselves */ |
803 if(!data->file) | |
804 return; | |
805 | |
7453 | 806 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); |
7431 | 807 gaim_markup_html_to_xhtml(message, &xhtml, NULL); |
808 if (from) | |
7443 | 809 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n", |
810 str_from_msg_type(type), | |
7431 | 811 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
812 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
813 from, date, xhtml); | |
814 else | |
7443 | 815 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n", |
816 str_from_msg_type(type), | |
7431 | 817 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
818 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
7443 | 819 date, xhtml): |
7431 | 820 fflush(log->logger_data); |
821 g_free(xhtml); | |
7443 | 822 } |
823 | |
7431 | 824 static void xml_logger_finalize(GaimLog *log) |
825 { | |
826 if (log->logger_data) { | |
827 fprintf(log->logger_data, "</conversation>\n"); | |
828 fclose(log->logger_data); | |
829 log->logger_data = NULL; | |
830 } | |
831 } | |
7443 | 832 |
8898 | 833 static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 834 { |
10822 | 835 return gaim_log_common_lister(type, sn, account, ".xml", &xml_logger); |
4184 | 836 } |
837 | |
7431 | 838 static GaimLogLogger xml_logger = { |
839 N_("XML"), "xml", | |
840 NULL, | |
841 xml_logger_write, | |
842 xml_logger_finalize, | |
843 xml_logger_list, | |
8096 | 844 NULL, |
11025 | 845 NULL, |
7431 | 846 NULL |
847 }; | |
848 #endif | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
849 |
7431 | 850 /**************************** |
7457 | 851 ** HTML LOGGER ************* |
852 ****************************/ | |
853 | |
854 static void html_logger_write(GaimLog *log, GaimMessageFlags type, | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
855 const char *from, time_t time, const char *message) |
7457 | 856 { |
9763 | 857 char *msg_fixed; |
7457 | 858 char date[64]; |
9613 | 859 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
10822 | 860 GaimLogCommonLoggerData *data = log->logger_data; |
9613 | 861 |
7618 | 862 if(!data) { |
9763 | 863 const char *prpl = |
864 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
865 gaim_log_common_writer(log, ".html"); |
7457 | 866 |
9763 | 867 data = log->logger_data; |
7457 | 868 |
9763 | 869 /* if we can't write to the file, give up before we hurt ourselves */ |
870 if(!data->file) | |
871 return; | |
7616 | 872 |
7457 | 873 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
11092
68652f4ad6a7
[gaim-migrate @ 13115]
Richard Laager <rlaager@wiktel.com>
parents:
11033
diff
changeset
|
874 fprintf(data->file, "<html><head>"); |
11094
59a1ff5a4bae
[gaim-migrate @ 13119]
Richard Laager <rlaager@wiktel.com>
parents:
11092
diff
changeset
|
875 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
|
876 fprintf(data->file, "<title>"); |
7616 | 877 fprintf(data->file, "Conversation with %s at %s on %s (%s)", |
7457 | 878 log->name, date, gaim_account_get_username(log->account), prpl); |
7616 | 879 fprintf(data->file, "</title></head><body>"); |
880 fprintf(data->file, | |
7457 | 881 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", |
882 log->name, date, gaim_account_get_username(log->account), prpl); | |
9763 | 883 |
7457 | 884 } |
7623 | 885 |
9892 | 886 /* if we can't write to the file, give up before we hurt ourselves */ |
887 if(!data->file) | |
888 return; | |
889 | |
7882 | 890 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); |
891 | |
8577 | 892 if(log->type == GAIM_LOG_SYSTEM){ |
9592 | 893 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); |
8577 | 894 fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); |
895 } else { | |
896 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | |
897 if (type & GAIM_MESSAGE_SYSTEM) | |
898 fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); | |
899 else if (type & GAIM_MESSAGE_WHISPER) | |
900 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", | |
901 date, from, msg_fixed); | |
902 else if (type & GAIM_MESSAGE_AUTO_RESP) { | |
903 if (type & GAIM_MESSAGE_SEND) | |
904 fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | |
905 else if (type & GAIM_MESSAGE_RECV) | |
906 fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | |
907 } else if (type & GAIM_MESSAGE_RECV) { | |
908 if(gaim_message_meify(msg_fixed, -1)) | |
10735
a0edd89ddb83
[gaim-migrate @ 12337]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
909 fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
10645 | 910 date, from, msg_fixed); |
8577 | 911 else |
10645 | 912 fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
913 date, from, msg_fixed); | |
8577 | 914 } else if (type & GAIM_MESSAGE_SEND) { |
915 if(gaim_message_meify(msg_fixed, -1)) | |
10735
a0edd89ddb83
[gaim-migrate @ 12337]
Luke Schierer <lschiere@pidgin.im>
parents:
10732
diff
changeset
|
916 fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
10645 | 917 date, from, msg_fixed); |
8577 | 918 else |
10645 | 919 fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
920 date, from, msg_fixed); | |
8577 | 921 } |
7564 | 922 } |
8573 | 923 |
7882 | 924 g_free(msg_fixed); |
7616 | 925 fflush(data->file); |
7457 | 926 } |
927 | |
928 static void html_logger_finalize(GaimLog *log) | |
929 { | |
10822 | 930 GaimLogCommonLoggerData *data = log->logger_data; |
7616 | 931 if (data) { |
932 if(data->file) { | |
933 fprintf(data->file, "</body></html>"); | |
934 fclose(data->file); | |
935 } | |
936 g_free(data->path); | |
7752 | 937 g_free(data); |
7463 | 938 } |
7457 | 939 } |
940 | |
8898 | 941 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7457 | 942 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
943 return gaim_log_common_lister(type, sn, account, ".html", html_logger); |
7457 | 944 } |
945 | |
8573 | 946 static GList *html_logger_list_syslog(GaimAccount *account) |
947 { | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
948 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".html", html_logger); |
8573 | 949 } |
950 | |
7457 | 951 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
952 { | |
953 char *read, *minus_header; | |
10822 | 954 GaimLogCommonLoggerData *data = log->logger_data; |
7457 | 955 *flags = GAIM_LOG_READ_NO_NEWLINE; |
7616 | 956 if (!data || !data->path) |
957 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
958 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
7457 | 959 minus_header = strchr(read, '\n'); |
960 if (!minus_header) | |
961 minus_header = g_strdup(read); | |
962 else | |
963 minus_header = g_strdup(minus_header + 1); | |
964 g_free(read); | |
965 return minus_header; | |
966 } | |
8578 | 967 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
7457 | 968 } |
969 | |
970 | |
971 | |
972 /**************************** | |
7431 | 973 ** PLAIN TEXT LOGGER ******* |
974 ****************************/ | |
4184 | 975 |
7436 | 976 static void txt_logger_write(GaimLog *log, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
977 GaimMessageFlags type, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
978 const char *from, time_t time, const char *message) |
7431 | 979 { |
980 char date[64]; | |
9763 | 981 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
10822 | 982 GaimLogCommonLoggerData *data = log->logger_data; |
9763 | 983 char *stripped = NULL; |
984 | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
985 if (data == NULL) { |
7431 | 986 /* This log is new. We could use the loggers 'new' function, but |
987 * creating a new file there would result in empty files in the case | |
988 * that you open a convo with someone, but don't say anything. | |
989 */ | |
9763 | 990 const char *prpl = |
991 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
992 gaim_log_common_writer(log, ".txt"); |
8898 | 993 |
9763 | 994 data = log->logger_data; |
7436 | 995 |
9763 | 996 /* if we can't write to the file, give up before we hurt ourselves */ |
997 if(!data->file) | |
998 return; | |
7616 | 999 |
7453 | 1000 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
7616 | 1001 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
7431 | 1002 log->name, date, gaim_account_get_username(log->account), prpl); |
1003 } | |
7436 | 1004 |
7623 | 1005 /* if we can't write to the file, give up before we hurt ourselves */ |
1006 if(!data->file) | |
1007 return; | |
1008 | |
8573 | 1009 stripped = gaim_markup_strip_html(message); |
1010 | |
1011 if(log->type == GAIM_LOG_SYSTEM){ | |
9592 | 1012 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); |
8573 | 1013 fprintf(data->file, "---- %s @ %s ----\n", stripped, date); |
1014 } else { | |
1015 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | |
1016 if (type & GAIM_MESSAGE_SEND || | |
1017 type & GAIM_MESSAGE_RECV) { | |
1018 if (type & GAIM_MESSAGE_AUTO_RESP) { | |
1019 fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, | |
1020 from, stripped); | |
1021 } else { | |
1022 if(gaim_message_meify(stripped, -1)) | |
1023 fprintf(data->file, "(%s) ***%s %s\n", date, from, | |
1024 stripped); | |
1025 else | |
1026 fprintf(data->file, "(%s) %s: %s\n", date, from, | |
1027 stripped); | |
1028 } | |
1029 } else if (type & GAIM_MESSAGE_SYSTEM) | |
1030 fprintf(data->file, "(%s) %s\n", date, stripped); | |
1031 else if (type & GAIM_MESSAGE_NO_LOG) { | |
1032 /* This shouldn't happen */ | |
1033 g_free(stripped); | |
1034 return; | |
1035 } else if (type & GAIM_MESSAGE_WHISPER) | |
1036 fprintf(data->file, "(%s) *%s* %s", date, from, stripped); | |
1037 else | |
1038 fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", | |
1039 from ? ":" : "", stripped); | |
1040 } | |
1041 | |
1042 fflush(data->file); | |
1043 g_free(stripped); | |
7431 | 1044 } |
1045 | |
1046 static void txt_logger_finalize(GaimLog *log) | |
1047 { | |
10822 | 1048 GaimLogCommonLoggerData *data = log->logger_data; |
7616 | 1049 if (data) { |
1050 if(data->file) | |
1051 fclose(data->file); | |
1052 if(data->path) | |
1053 g_free(data->path); | |
7752 | 1054 g_free(data); |
7616 | 1055 } |
7431 | 1056 } |
1057 | |
8898 | 1058 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 1059 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1060 return gaim_log_common_lister(type, sn, account, ".txt", txt_logger); |
7431 | 1061 } |
1062 | |
8573 | 1063 static GList *txt_logger_list_syslog(GaimAccount *account) |
1064 { | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1065 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".txt", txt_logger); |
8573 | 1066 } |
1067 | |
7431 | 1068 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
1069 { | |
8517 | 1070 char *read, *minus_header, *minus_header2; |
10822 | 1071 GaimLogCommonLoggerData *data = log->logger_data; |
7457 | 1072 *flags = 0; |
7616 | 1073 if (!data || !data->path) |
1074 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
1075 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
7431 | 1076 minus_header = strchr(read, '\n'); |
1077 if (!minus_header) | |
1078 minus_header = g_strdup(read); | |
7436 | 1079 else |
7431 | 1080 minus_header = g_strdup(minus_header + 1); |
1081 g_free(read); | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10645
diff
changeset
|
1082 minus_header2 = g_markup_escape_text(minus_header, -1); |
8517 | 1083 g_free(minus_header); |
1084 return minus_header2; | |
7431 | 1085 } |
8578 | 1086 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
7436 | 1087 } |
7431 | 1088 |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1089 |
7431 | 1090 |
1091 /**************** | |
1092 * OLD LOGGER *** | |
1093 ****************/ | |
1094 | |
1095 /* The old logger doesn't write logs, only reads them. This is to include | |
1096 * old logs in the log viewer transparently. | |
1097 */ | |
1098 | |
1099 struct old_logger_data { | |
7764 | 1100 GaimStringref *pathref; |
7431 | 1101 int offset; |
1102 int length; | |
1103 }; | |
1104 | |
8898 | 1105 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 1106 { |
1107 FILE *file; | |
1108 char buf[BUF_LONG]; | |
1109 struct tm tm; | |
7761 | 1110 char month[4]; |
7431 | 1111 struct old_logger_data *data = NULL; |
1112 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); | |
7764 | 1113 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); |
1114 GaimStringref *pathref = gaim_stringref_new(pathstr); | |
7431 | 1115 char *newlog; |
7761 | 1116 int logfound = 0; |
1117 int lastoff = 0; | |
1118 int newlen; | |
7791 | 1119 time_t lasttime = 0; |
7431 | 1120 |
1121 GaimLog *log = NULL; | |
1122 GList *list = NULL; | |
1123 | |
7473 | 1124 g_free(logfile); |
7764 | 1125 g_free(pathstr); |
7473 | 1126 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1127 if (!(file = g_fopen(gaim_stringref_value(pathref), "rb"))) { |
7764 | 1128 gaim_stringref_unref(pathref); |
7431 | 1129 return NULL; |
7447 | 1130 } |
7436 | 1131 |
7431 | 1132 while (fgets(buf, BUF_LONG, file)) { |
1133 if ((newlog = strstr(buf, "---- New C"))) { | |
1134 int length; | |
1135 int offset; | |
1136 char convostart[32]; | |
1137 char *temp = strchr(buf, '@'); | |
7436 | 1138 |
7431 | 1139 if (temp == NULL || strlen(temp) < 2) |
1140 continue; | |
7436 | 1141 |
7431 | 1142 temp++; |
1143 length = strcspn(temp, "-"); | |
1144 if (length > 31) length = 31; | |
7436 | 1145 |
7431 | 1146 offset = ftell(file); |
7436 | 1147 |
7761 | 1148 if (logfound) { |
1149 newlen = offset - lastoff - length; | |
7436 | 1150 if(strstr(buf, "----</H3><BR>")) { |
7761 | 1151 newlen -= |
1152 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + | |
1153 sizeof("----</H3><BR>") - 2; | |
7436 | 1154 } else { |
7761 | 1155 newlen -= |
1156 sizeof("---- New Conversation @ ") + sizeof("----") - 2; | |
7436 | 1157 } |
1158 | |
7461 | 1159 if(strchr(buf, '\r')) |
7770 | 1160 newlen--; |
7461 | 1161 |
7761 | 1162 if (newlen != 0) { |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
1163 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
|
1164 log->logger = old_logger; |
7761 | 1165 log->time = lasttime; |
1166 data = g_new0(struct old_logger_data, 1); | |
1167 data->offset = lastoff; | |
1168 data->length = newlen; | |
7764 | 1169 data->pathref = gaim_stringref_ref(pathref); |
7761 | 1170 log->logger_data = data; |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
1171 list = g_list_prepend(list, log); |
7761 | 1172 } |
7431 | 1173 } |
1174 | |
7761 | 1175 logfound = 1; |
1176 lastoff = offset; | |
7436 | 1177 |
7431 | 1178 g_snprintf(convostart, length, "%s", temp); |
7676 | 1179 sscanf(convostart, "%*s %s %d %d:%d:%d %d", |
1180 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year); | |
1181 /* Ugly hack, in case current locale is not English */ | |
1182 if (strcmp(month, "Jan") == 0) { | |
1183 tm.tm_mon= 0; | |
1184 } else if (strcmp(month, "Feb") == 0) { | |
1185 tm.tm_mon = 1; | |
1186 } else if (strcmp(month, "Mar") == 0) { | |
1187 tm.tm_mon = 2; | |
1188 } else if (strcmp(month, "Apr") == 0) { | |
1189 tm.tm_mon = 3; | |
1190 } else if (strcmp(month, "May") == 0) { | |
1191 tm.tm_mon = 4; | |
1192 } else if (strcmp(month, "Jun") == 0) { | |
1193 tm.tm_mon = 5; | |
1194 } else if (strcmp(month, "Jul") == 0) { | |
1195 tm.tm_mon = 6; | |
1196 } else if (strcmp(month, "Aug") == 0) { | |
1197 tm.tm_mon = 7; | |
1198 } else if (strcmp(month, "Sep") == 0) { | |
1199 tm.tm_mon = 8; | |
1200 } else if (strcmp(month, "Oct") == 0) { | |
1201 tm.tm_mon = 9; | |
1202 } else if (strcmp(month, "Nov") == 0) { | |
1203 tm.tm_mon = 10; | |
1204 } else if (strcmp(month, "Dec") == 0) { | |
1205 tm.tm_mon = 11; | |
1206 } | |
1207 tm.tm_year -= 1900; | |
7761 | 1208 lasttime = mktime(&tm); |
4184 | 1209 } |
1210 } | |
7613 | 1211 |
7761 | 1212 if (logfound) { |
1213 if ((newlen = ftell(file) - lastoff) != 0) { | |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
1214 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
|
1215 log->logger = old_logger; |
7761 | 1216 log->time = lasttime; |
1217 data = g_new0(struct old_logger_data, 1); | |
1218 data->offset = lastoff; | |
1219 data->length = newlen; | |
7764 | 1220 data->pathref = gaim_stringref_ref(pathref); |
7761 | 1221 log->logger_data = data; |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
1222 list = g_list_prepend(list, log); |
7761 | 1223 } |
7613 | 1224 } |
1225 | |
7764 | 1226 gaim_stringref_unref(pathref); |
7431 | 1227 fclose(file); |
1228 return list; | |
4184 | 1229 } |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1230 |
8898 | 1231 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account) |
8096 | 1232 { |
1233 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name)); | |
1234 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); | |
1235 int size; | |
1236 struct stat st; | |
1237 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1238 if (g_stat(pathstr, &st)) |
8096 | 1239 size = 0; |
1240 else | |
1241 size = st.st_size; | |
1242 | |
1243 g_free(logfile); | |
1244 g_free(pathstr); | |
1245 | |
1246 return size; | |
1247 } | |
1248 | |
7616 | 1249 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1250 { |
7431 | 1251 struct old_logger_data *data = log->logger_data; |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1252 FILE *file = g_fopen(gaim_stringref_value(data->pathref), "rb"); |
10906 | 1253 char *tmp, *read = g_malloc(data->length + 1); |
7431 | 1254 fseek(file, data->offset, SEEK_SET); |
1255 fread(read, data->length, 1, file); | |
8370 | 1256 fclose(file); |
7431 | 1257 read[data->length] = '\0'; |
7436 | 1258 *flags = 0; |
1259 if(strstr(read, "<BR>")) | |
1260 *flags |= GAIM_LOG_READ_NO_NEWLINE; | |
10906 | 1261 else { |
1262 tmp = g_markup_escape_text(read, -1); | |
1263 g_free(read); | |
1264 read = tmp; | |
1265 } | |
7431 | 1266 return read; |
1267 } | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1268 |
7616 | 1269 static int old_logger_size (GaimLog *log) |
7556 | 1270 { |
1271 struct old_logger_data *data = log->logger_data; | |
7616 | 1272 return data ? data->length : 0; |
1273 } | |
1274 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1275 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets) |
11025 | 1276 { |
1277 char *log_path = g_build_filename(gaim_user_dir(), "logs", NULL); | |
1278 GDir *log_dir = g_dir_open(log_path, 0, NULL); | |
1279 gchar *name; | |
1280 GaimBlistNode *gnode, *cnode, *bnode; | |
1281 | |
1282 g_free(log_path); | |
1283 if (log_dir == NULL) | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1284 return; |
11025 | 1285 |
1286 /* Don't worry about the cast, name will be filled with a dynamically allocated data shortly. */ | |
1287 while ((name = (gchar *)g_dir_read_name(log_dir)) != NULL) { | |
1288 size_t len; | |
1289 gchar *ext; | |
1290 GaimLogSet *set; | |
1291 gboolean found = FALSE; | |
1292 | |
1293 /* Unescape the filename. */ | |
1294 name = g_strdup(gaim_unescape_filename(name)); | |
1295 | |
1296 /* Get the (possibly new) length of name. */ | |
1297 len = strlen(name); | |
1298 | |
1299 if (len < 5) { | |
1300 g_free(name); | |
1301 continue; | |
1302 } | |
1303 | |
1304 /* Make sure we're dealing with a log file. */ | |
1305 ext = &name[len - 4]; | |
1306 if (strcmp(ext, ".log")) { | |
1307 g_free(name); | |
1308 continue; | |
1309 } | |
1310 | |
1311 set = g_new0(GaimLogSet, 1); | |
1312 | |
1313 /* Chat for .chat at the end of the name to determine the type. */ | |
1314 *ext = '\0'; | |
1315 set->type = GAIM_LOG_IM; | |
1316 if (len > 9) { | |
1317 char *tmp = &name[len - 9]; | |
1318 if (!strcmp(tmp, ".chat")) { | |
1319 set->type = GAIM_LOG_CHAT; | |
1320 *tmp = '\0'; | |
1321 } | |
1322 } | |
1323 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1324 set->name = set->normalized_name = name; |
11025 | 1325 |
1326 /* Search the buddy list to find the account and to determine if this is a buddy. */ | |
1327 for (gnode = gaim_get_blist()->root; !found && gnode != NULL; gnode = gnode->next) | |
1328 { | |
1329 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
1330 continue; | |
1331 | |
1332 for (cnode = gnode->child; !found && cnode != NULL; cnode = cnode->next) | |
1333 { | |
1334 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
1335 continue; | |
1336 | |
1337 for (bnode = cnode->child; !found && bnode != NULL; bnode = bnode->next) | |
1338 { | |
1339 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
1340 | |
1341 if (!strcmp(buddy->name, name)) { | |
1342 set->account = buddy->account; | |
1343 set->buddy = TRUE; | |
1344 found = TRUE; | |
1345 } | |
1346 } | |
1347 } | |
1348 } | |
1349 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1350 cb(sets, set); |
11025 | 1351 } |
1352 g_dir_close(log_dir); | |
1353 } | |
1354 | |
7616 | 1355 static void old_logger_finalize(GaimLog *log) |
1356 { | |
1357 struct old_logger_data *data = log->logger_data; | |
7764 | 1358 gaim_stringref_unref(data->pathref); |
7616 | 1359 g_free(data); |
7556 | 1360 } |