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