Mercurial > pidgin.yaz
annotate src/log.c @ 13106:a0a4b44239e8
[gaim-migrate @ 15468]
I was reading the gettext man page and it pointed out that it should be typed as const char *, but it's char * to avoid warnings in code predating ANSI C. So, for the heck of it, I changed added a cast in internal.h. As it turns out, there was a lot of code that relied on this. In the interest of type safety, I've fixed all the warnings. I feel this improved a number of function signatures (in terms of typing clarity). Flame me if you object.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 02 Feb 2006 21:34:43 +0000 |
parents | e1e5462b7d81 |
children | fcde3faa1f57 |
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)); | |
13076
f3abb141042a
[gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents:
13069
diff
changeset
|
121 } else { |
f3abb141042a
[gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents:
13069
diff
changeset
|
122 g_free(lu->name); |
f3abb141042a
[gaim-migrate @ 15438]
Richard Laager <rlaager@wiktel.com>
parents:
13069
diff
changeset
|
123 g_free(lu); |
13059 | 124 } |
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 } | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
13104
diff
changeset
|
137 return g_strdup(_("<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 { | |
13077
64ca89ffc639
[gaim-migrate @ 15439]
Richard Laager <rlaager@wiktel.com>
parents:
13076
diff
changeset
|
157 return (lu1->account == lu2->account && (!strcmp(lu1->name, lu2->name))); |
8635 | 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); |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
588 if (date != NULL) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
589 return date; |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
590 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
591 if (log->type == GAIM_LOG_SYSTEM || time(NULL) > when + 20*60) |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
592 return g_strdup(gaim_date_format_long(&tm)); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
593 else |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
594 return g_strdup(gaim_time_format(&tm)); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
595 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
596 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
597 void gaim_log_common_writer(GaimLog *log, const char *ext) |
9763 | 598 { |
10822 | 599 GaimLogCommonLoggerData *data = log->logger_data; |
9763 | 600 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
601 if (data == NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
602 { |
9763 | 603 /* This log is new */ |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
604 char *dir; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
605 const char *date; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
606 char *filename; |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
607 char *path; |
10577 | 608 |
9923 | 609 dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
10577 | 610 if (dir == NULL) |
611 return; | |
612 | |
9923 | 613 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
9763 | 614 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
615 date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S", localtime(&log->time)); |
9763 | 616 |
617 filename = g_strdup_printf("%s%s", date, ext ? ext : ""); | |
618 | |
619 path = g_build_filename(dir, filename, NULL); | |
620 g_free(dir); | |
621 g_free(filename); | |
622 | |
10822 | 623 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
9763 | 624 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
625 data->file = g_fopen(path, "a"); |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
626 if (data->file == NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
627 { |
9763 | 628 gaim_debug(GAIM_DEBUG_ERROR, "log", |
9892 | 629 "Could not create log file %s\n", path); |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
630 |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
631 if (log->conv != NULL) |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
632 gaim_conversation_write(log->conv, NULL, _("Logging of this conversation failed."), |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
633 GAIM_MESSAGE_ERROR, time(NULL)); |
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
634 |
9763 | 635 g_free(path); |
636 return; | |
637 } | |
638 g_free(path); | |
10577 | 639 } |
9763 | 640 } |
641 | |
10822 | 642 GList *gaim_log_common_lister(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger) |
7431 | 643 { |
644 GDir *dir; | |
645 GList *list = NULL; | |
7628 | 646 const char *filename; |
8111 | 647 char *path; |
648 | |
649 if(!account) | |
650 return NULL; | |
651 | |
9923 | 652 path = gaim_log_get_log_dir(type, name, account); |
10577 | 653 if (path == NULL) |
654 return NULL; | |
7447 | 655 |
12969
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
656 if (!(dir = g_dir_open(path, 0, NULL))) |
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
657 { |
7431 | 658 g_free(path); |
659 return NULL; | |
660 } | |
8898 | 661 |
12969
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
662 while ((filename = g_dir_read_name(dir))) |
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
663 { |
8577 | 664 if (gaim_str_has_suffix(filename, ext) && |
12969
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
665 strlen(filename) >= (17 + strlen(ext))) |
b98a28bf29d9
[gaim-migrate @ 15322]
Richard Laager <rlaager@wiktel.com>
parents:
12958
diff
changeset
|
666 { |
7431 | 667 GaimLog *log; |
10822 | 668 GaimLogCommonLoggerData *data; |
8577 | 669 time_t stamp = gaim_str_to_time(filename, FALSE); |
7431 | 670 |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
671 log = gaim_log_new(type, name, account, NULL, stamp); |
7431 | 672 log->logger = logger; |
10822 | 673 log->logger_data = data = g_new0(GaimLogCommonLoggerData, 1); |
7616 | 674 data->path = g_build_filename(path, filename, NULL); |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
675 list = g_list_prepend(list, log); |
4184 | 676 } |
677 } | |
7431 | 678 g_dir_close(dir); |
7447 | 679 g_free(path); |
7431 | 680 return list; |
681 } | |
4184 | 682 |
10822 | 683 int gaim_log_common_sizer(GaimLog *log) |
7556 | 684 { |
685 struct stat st; | |
10822 | 686 GaimLogCommonLoggerData *data = log->logger_data; |
7556 | 687 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
688 if (!data->path || g_stat(data->path, &st)) |
7556 | 689 st.st_size = 0; |
690 | |
691 return st.st_size; | |
692 } | |
693 | |
11025 | 694 /* This will build log sets for all loggers that use the common logger |
695 * functions because they use the same directory structure. */ | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
696 static void log_get_log_sets_common(GHashTable *sets) |
11025 | 697 { |
698 gchar *log_path = g_build_filename(gaim_user_dir(), "logs", NULL); | |
699 GDir *log_dir = g_dir_open(log_path, 0, NULL); | |
700 const gchar *protocol; | |
701 | |
702 if (log_dir == NULL) { | |
703 g_free(log_path); | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
704 return; |
11025 | 705 } |
706 | |
707 while ((protocol = g_dir_read_name(log_dir)) != NULL) { | |
708 gchar *protocol_path = g_build_filename(log_path, protocol, NULL); | |
709 GDir *protocol_dir; | |
710 const gchar *username; | |
711 gchar *protocol_unescaped; | |
712 GList *account_iter; | |
713 GList *accounts = NULL; | |
714 | |
715 if ((protocol_dir = g_dir_open(protocol_path, 0, NULL)) == NULL) { | |
716 g_free(protocol_path); | |
717 continue; | |
718 } | |
719 | |
720 /* Using g_strdup() to cover the one-in-a-million chance that a | |
721 * prpl's list_icon function uses gaim_unescape_filename(). */ | |
722 protocol_unescaped = g_strdup(gaim_unescape_filename(protocol)); | |
723 | |
724 /* Find all the accounts for protocol. */ | |
725 for (account_iter = gaim_accounts_get_all() ; account_iter != NULL ; account_iter = account_iter->next) { | |
726 GaimPlugin *prpl; | |
727 GaimPluginProtocolInfo *prpl_info; | |
728 | |
729 prpl = gaim_find_prpl(gaim_account_get_protocol_id((GaimAccount *)account_iter->data)); | |
730 if (!prpl) | |
731 continue; | |
732 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl); | |
733 | |
734 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
|
735 accounts = g_list_prepend(accounts, account_iter->data); |
11025 | 736 } |
737 g_free(protocol_unescaped); | |
738 | |
739 while ((username = g_dir_read_name(protocol_dir)) != NULL) { | |
740 gchar *username_path = g_build_filename(protocol_path, username, NULL); | |
741 GDir *username_dir; | |
742 const gchar *username_unescaped; | |
743 GaimAccount *account = NULL; | |
744 gchar *name; | |
745 | |
746 if ((username_dir = g_dir_open(username_path, 0, NULL)) == NULL) { | |
747 g_free(username_path); | |
748 continue; | |
749 } | |
750 | |
751 /* Find the account for username in the list of accounts for protocol. */ | |
752 username_unescaped = gaim_unescape_filename(username); | |
753 for (account_iter = g_list_first(accounts) ; account_iter != NULL ; account_iter = account_iter->next) { | |
754 if (!strcmp(((GaimAccount *)account_iter->data)->username, username_unescaped)) { | |
755 account = account_iter->data; | |
756 break; | |
757 } | |
758 } | |
759 | |
760 /* Don't worry about the cast, name will point to dynamically allocated memory shortly. */ | |
761 while ((name = (gchar *)g_dir_read_name(username_dir)) != NULL) { | |
762 size_t len; | |
763 GaimLogSet *set = g_new0(GaimLogSet, 1); | |
764 | |
765 /* Unescape the filename. */ | |
766 name = g_strdup(gaim_unescape_filename(name)); | |
767 | |
768 /* Get the (possibly new) length of name. */ | |
769 len = strlen(name); | |
770 | |
771 set->account = account; | |
772 set->name = name; | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
773 set->normalized_name = g_strdup(gaim_normalize(account, name)); |
11025 | 774 |
775 /* Chat for .chat or .system at the end of the name to determine the type. */ | |
776 set->type = GAIM_LOG_IM; | |
777 if (len > 7) { | |
778 gchar *tmp = &name[len - 7]; | |
779 if (!strcmp(tmp, ".system")) { | |
780 set->type = GAIM_LOG_SYSTEM; | |
781 *tmp = '\0'; | |
782 } | |
783 } | |
784 if (len > 5) { | |
785 gchar *tmp = &name[len - 5]; | |
786 if (!strcmp(tmp, ".chat")) { | |
787 set->type = GAIM_LOG_CHAT; | |
788 *tmp = '\0'; | |
789 } | |
790 } | |
791 | |
792 /* Determine if this (account, name) combination exists as a buddy. */ | |
11458
4db38b374d3f
[gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents:
11292
diff
changeset
|
793 if (account != NULL) |
4db38b374d3f
[gaim-migrate @ 13697]
Richard Laager <rlaager@wiktel.com>
parents:
11292
diff
changeset
|
794 set->buddy = (gaim_find_buddy(account, name) != NULL); |
11025 | 795 |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
796 log_add_log_set_to_hash(sets, set); |
11025 | 797 } |
798 g_free(username_path); | |
799 g_dir_close(username_dir); | |
800 } | |
801 g_free(protocol_path); | |
802 g_dir_close(protocol_dir); | |
803 } | |
804 g_free(log_path); | |
805 g_dir_close(log_dir); | |
806 } | |
807 | |
7431 | 808 #if 0 /* Maybe some other time. */ |
7443 | 809 /**************** |
7431 | 810 ** XML LOGGER ** |
811 ****************/ | |
812 | |
813 static const char *str_from_msg_type (GaimMessageFlags type) | |
814 { | |
7443 | 815 |
7431 | 816 return ""; |
7443 | 817 |
7431 | 818 } |
819 | |
7443 | 820 static void xml_logger_write(GaimLog *log, |
821 GaimMessageFlags type, | |
7431 | 822 const char *from, time_t time, const char *message) |
823 { | |
824 char *xhtml = NULL; | |
10577 | 825 |
7431 | 826 if (!log->logger_data) { |
827 /* This log is new. We could use the loggers 'new' function, but | |
828 * creating a new file there would result in empty files in the case | |
829 * that you open a convo with someone, but don't say anything. | |
830 */ | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
831 const char *date; |
9923 | 832 char *dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
7431 | 833 FILE *file; |
10577 | 834 |
835 if (dir == NULL) | |
836 return; | |
837 | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
838 date = gaim_utf8_strftime("%Y-%m-%d.%H%M%S.xml", localtime(&log->time)); |
7443 | 839 |
7612 | 840 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
7443 | 841 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
842 char *filename = g_build_filename(dir, date, NULL); |
7431 | 843 g_free(dir); |
7443 | 844 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
845 log->logger_data = g_fopen(filename, "a"); |
7431 | 846 if (!log->logger_data) { |
847 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | |
7564 | 848 g_free(filename); |
7431 | 849 return; |
850 } | |
7564 | 851 g_free(filename); |
7431 | 852 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" |
853 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); | |
7443 | 854 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
855 date = gaim_utf8_strftime("%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
7431 | 856 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", |
857 date, log->name, prpl); | |
858 } | |
7443 | 859 |
9923 | 860 /* if we can't write to the file, give up before we hurt ourselves */ |
861 if(!data->file) | |
862 return; | |
863 | |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
864 date = log_get_timestamp(log, time); |
12692
4da7062a06c2
[gaim-migrate @ 15035]
Richard Laager <rlaager@wiktel.com>
parents:
12574
diff
changeset
|
865 |
7431 | 866 gaim_markup_html_to_xhtml(message, &xhtml, NULL); |
867 if (from) | |
7443 | 868 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n", |
869 str_from_msg_type(type), | |
7431 | 870 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
871 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
872 from, date, xhtml); | |
873 else | |
7443 | 874 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n", |
875 str_from_msg_type(type), | |
7431 | 876 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
877 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
7443 | 878 date, xhtml): |
7431 | 879 fflush(log->logger_data); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
880 g_free(date); |
7431 | 881 g_free(xhtml); |
7443 | 882 } |
883 | |
7431 | 884 static void xml_logger_finalize(GaimLog *log) |
885 { | |
886 if (log->logger_data) { | |
887 fprintf(log->logger_data, "</conversation>\n"); | |
888 fclose(log->logger_data); | |
889 log->logger_data = NULL; | |
890 } | |
891 } | |
7443 | 892 |
8898 | 893 static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 894 { |
10822 | 895 return gaim_log_common_lister(type, sn, account, ".xml", &xml_logger); |
4184 | 896 } |
897 | |
7431 | 898 static GaimLogLogger xml_logger = { |
899 N_("XML"), "xml", | |
900 NULL, | |
901 xml_logger_write, | |
902 xml_logger_finalize, | |
903 xml_logger_list, | |
8096 | 904 NULL, |
11025 | 905 NULL, |
7431 | 906 NULL |
907 }; | |
908 #endif | |
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
909 |
7431 | 910 /**************************** |
7457 | 911 ** HTML LOGGER ************* |
912 ****************************/ | |
913 | |
13059 | 914 static gsize html_logger_write(GaimLog *log, GaimMessageFlags type, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
915 const char *from, time_t time, const char *message) |
7457 | 916 { |
9763 | 917 char *msg_fixed; |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
918 char *date; |
9613 | 919 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
10822 | 920 GaimLogCommonLoggerData *data = log->logger_data; |
13059 | 921 gsize written = 0; |
9613 | 922 |
7618 | 923 if(!data) { |
9763 | 924 const char *prpl = |
925 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
926 const char *date; |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
927 gaim_log_common_writer(log, ".html"); |
7457 | 928 |
9763 | 929 data = log->logger_data; |
7457 | 930 |
9763 | 931 /* if we can't write to the file, give up before we hurt ourselves */ |
932 if(!data->file) | |
13059 | 933 return 0; |
7616 | 934 |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
935 date = gaim_date_format_full(log->time); |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
936 |
13059 | 937 written += fprintf(data->file, "<html><head>"); |
938 written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"); | |
939 written += fprintf(data->file, "<title>"); | |
940 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)", | |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
941 log->name, date, gaim_account_get_username(log->account), prpl); |
13059 | 942 written += fprintf(data->file, "</title></head><body>"); |
943 written += fprintf(data->file, | |
7457 | 944 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
945 log->name, date, gaim_account_get_username(log->account), prpl); |
7457 | 946 } |
7623 | 947 |
9892 | 948 /* if we can't write to the file, give up before we hurt ourselves */ |
949 if(!data->file) | |
13059 | 950 return 0; |
9892 | 951 |
7882 | 952 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
953 date = log_get_timestamp(log, time); |
7882 | 954 |
8577 | 955 if(log->type == GAIM_LOG_SYSTEM){ |
13059 | 956 written += fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); |
8577 | 957 } else { |
958 if (type & GAIM_MESSAGE_SYSTEM) | |
13059 | 959 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
|
960 else if (type & GAIM_MESSAGE_ERROR) |
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
961 written += fprintf(data->file, "<font color=\"#FF0000\"><font size=\"2\">(%s)</font><b> %s</b></font><br/>\n", date, msg_fixed); |
8577 | 962 else if (type & GAIM_MESSAGE_WHISPER) |
13059 | 963 written += fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", |
8577 | 964 date, from, msg_fixed); |
965 else if (type & GAIM_MESSAGE_AUTO_RESP) { | |
966 if (type & GAIM_MESSAGE_SEND) | |
13059 | 967 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 | 968 else if (type & GAIM_MESSAGE_RECV) |
13059 | 969 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 | 970 } else if (type & GAIM_MESSAGE_RECV) { |
971 if(gaim_message_meify(msg_fixed, -1)) | |
13059 | 972 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
10645 | 973 date, from, msg_fixed); |
8577 | 974 else |
13059 | 975 written += fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
10645 | 976 date, from, msg_fixed); |
8577 | 977 } else if (type & GAIM_MESSAGE_SEND) { |
978 if(gaim_message_meify(msg_fixed, -1)) | |
13059 | 979 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
10645 | 980 date, from, msg_fixed); |
8577 | 981 else |
13059 | 982 written += fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
10645 | 983 date, from, msg_fixed); |
13069
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
984 } else { |
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
985 gaim_debug_error("log", "Unhandled message type."); |
42c62476b61b
[gaim-migrate @ 15431]
Richard Laager <rlaager@wiktel.com>
parents:
13068
diff
changeset
|
986 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
|
987 date, from, msg_fixed); |
8577 | 988 } |
7564 | 989 } |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
990 g_free(date); |
7882 | 991 g_free(msg_fixed); |
7616 | 992 fflush(data->file); |
13059 | 993 |
994 return written; | |
7457 | 995 } |
996 | |
997 static void html_logger_finalize(GaimLog *log) | |
998 { | |
10822 | 999 GaimLogCommonLoggerData *data = log->logger_data; |
7616 | 1000 if (data) { |
1001 if(data->file) { | |
12881
7e45ccd91e58
[gaim-migrate @ 15233]
Richard Laager <rlaager@wiktel.com>
parents:
12834
diff
changeset
|
1002 fprintf(data->file, "</body></html>\n"); |
7616 | 1003 fclose(data->file); |
1004 } | |
1005 g_free(data->path); | |
7752 | 1006 g_free(data); |
7463 | 1007 } |
7457 | 1008 } |
1009 | |
8898 | 1010 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7457 | 1011 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1012 return gaim_log_common_lister(type, sn, account, ".html", html_logger); |
7457 | 1013 } |
1014 | |
8573 | 1015 static GList *html_logger_list_syslog(GaimAccount *account) |
1016 { | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1017 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".html", html_logger); |
8573 | 1018 } |
1019 | |
7457 | 1020 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
1021 { | |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1022 char *read; |
10822 | 1023 GaimLogCommonLoggerData *data = log->logger_data; |
7457 | 1024 *flags = GAIM_LOG_READ_NO_NEWLINE; |
7616 | 1025 if (!data || !data->path) |
1026 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
1027 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1028 char *minus_header = strchr(read, '\n'); |
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1029 |
7457 | 1030 if (!minus_header) |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1031 return read; |
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1032 |
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1033 minus_header = g_strdup(minus_header + 1); |
7457 | 1034 g_free(read); |
12958
6910db1ae6a1
[gaim-migrate @ 15311]
Richard Laager <rlaager@wiktel.com>
parents:
12881
diff
changeset
|
1035 |
7457 | 1036 return minus_header; |
1037 } | |
8578 | 1038 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
7457 | 1039 } |
1040 | |
1041 | |
1042 | |
1043 /**************************** | |
7431 | 1044 ** PLAIN TEXT LOGGER ******* |
1045 ****************************/ | |
4184 | 1046 |
13059 | 1047 static gsize txt_logger_write(GaimLog *log, |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1048 GaimMessageFlags type, |
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1049 const char *from, time_t time, const char *message) |
7431 | 1050 { |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1051 char *date; |
9763 | 1052 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
10822 | 1053 GaimLogCommonLoggerData *data = log->logger_data; |
9763 | 1054 char *stripped = NULL; |
1055 | |
13059 | 1056 gsize written = 0; |
1057 | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1058 if (data == NULL) { |
7431 | 1059 /* This log is new. We could use the loggers 'new' function, but |
1060 * creating a new file there would result in empty files in the case | |
1061 * that you open a convo with someone, but don't say anything. | |
1062 */ | |
9763 | 1063 const char *prpl = |
1064 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
1065 gaim_log_common_writer(log, ".txt"); |
8898 | 1066 |
9763 | 1067 data = log->logger_data; |
7436 | 1068 |
9763 | 1069 /* if we can't write to the file, give up before we hurt ourselves */ |
1070 if(!data->file) | |
13059 | 1071 return 0; |
7616 | 1072 |
13059 | 1073 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
13104
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
1074 log->name, gaim_date_format_full(log->time), |
e1e5462b7d81
[gaim-migrate @ 15466]
Richard Laager <rlaager@wiktel.com>
parents:
13077
diff
changeset
|
1075 gaim_account_get_username(log->account), prpl); |
7431 | 1076 } |
7436 | 1077 |
7623 | 1078 /* if we can't write to the file, give up before we hurt ourselves */ |
1079 if(!data->file) | |
13059 | 1080 return 0; |
7623 | 1081 |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1082 stripped = gaim_markup_strip_html(message); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1083 date = log_get_timestamp(log, time); |
12692
4da7062a06c2
[gaim-migrate @ 15035]
Richard Laager <rlaager@wiktel.com>
parents:
12574
diff
changeset
|
1084 |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1085 if(log->type == GAIM_LOG_SYSTEM){ |
13059 | 1086 written += fprintf(data->file, "---- %s @ %s ----\n", stripped, date); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1087 } else { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1088 if (type & GAIM_MESSAGE_SEND || |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1089 type & GAIM_MESSAGE_RECV) { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1090 if (type & GAIM_MESSAGE_AUTO_RESP) { |
13059 | 1091 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
|
1092 from, stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1093 } else { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1094 if(gaim_message_meify(stripped, -1)) |
13059 | 1095 written += fprintf(data->file, "(%s) ***%s %s\n", date, from, |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1096 stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1097 else |
13059 | 1098 written += fprintf(data->file, "(%s) %s: %s\n", date, from, |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1099 stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1100 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1101 } else if (type & GAIM_MESSAGE_SYSTEM) |
13059 | 1102 written += fprintf(data->file, "(%s) %s\n", date, stripped); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1103 else if (type & GAIM_MESSAGE_NO_LOG) { |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1104 /* This shouldn't happen */ |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1105 g_free(stripped); |
13059 | 1106 return written; |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1107 } else if (type & GAIM_MESSAGE_WHISPER) |
13059 | 1108 written += fprintf(data->file, "(%s) *%s* %s", date, from, stripped); |
12737
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1109 else |
13059 | 1110 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
|
1111 from ? ":" : "", stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1112 } |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1113 g_free(date); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1114 g_free(stripped); |
a1e241dd50b6
[gaim-migrate @ 15082]
Richard Laager <rlaager@wiktel.com>
parents:
12692
diff
changeset
|
1115 fflush(data->file); |
13059 | 1116 |
1117 return written; | |
7431 | 1118 } |
1119 | |
1120 static void txt_logger_finalize(GaimLog *log) | |
1121 { | |
10822 | 1122 GaimLogCommonLoggerData *data = log->logger_data; |
7616 | 1123 if (data) { |
1124 if(data->file) | |
1125 fclose(data->file); | |
1126 if(data->path) | |
1127 g_free(data->path); | |
7752 | 1128 g_free(data); |
7616 | 1129 } |
7431 | 1130 } |
1131 | |
8898 | 1132 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 1133 { |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1134 return gaim_log_common_lister(type, sn, account, ".txt", txt_logger); |
7431 | 1135 } |
1136 | |
8573 | 1137 static GList *txt_logger_list_syslog(GaimAccount *account) |
1138 { | |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1139 return gaim_log_common_lister(GAIM_LOG_SYSTEM, ".system", account, ".txt", txt_logger); |
8573 | 1140 } |
1141 | |
7431 | 1142 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
1143 { | |
8517 | 1144 char *read, *minus_header, *minus_header2; |
10822 | 1145 GaimLogCommonLoggerData *data = log->logger_data; |
7457 | 1146 *flags = 0; |
7616 | 1147 if (!data || !data->path) |
1148 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
1149 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
7431 | 1150 minus_header = strchr(read, '\n'); |
1151 if (!minus_header) | |
1152 minus_header = g_strdup(read); | |
7436 | 1153 else |
7431 | 1154 minus_header = g_strdup(minus_header + 1); |
1155 g_free(read); | |
10732
c4cb90065e1d
[gaim-migrate @ 12334]
Luke Schierer <lschiere@pidgin.im>
parents:
10645
diff
changeset
|
1156 minus_header2 = g_markup_escape_text(minus_header, -1); |
8517 | 1157 g_free(minus_header); |
1158 return minus_header2; | |
7431 | 1159 } |
8578 | 1160 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
7436 | 1161 } |
7431 | 1162 |
11503
cd0c8830d881
[gaim-migrate @ 13748]
Richard Laager <rlaager@wiktel.com>
parents:
11458
diff
changeset
|
1163 |
7431 | 1164 |
1165 /**************** | |
1166 * OLD LOGGER *** | |
1167 ****************/ | |
1168 | |
1169 /* The old logger doesn't write logs, only reads them. This is to include | |
1170 * old logs in the log viewer transparently. | |
1171 */ | |
1172 | |
1173 struct old_logger_data { | |
7764 | 1174 GaimStringref *pathref; |
7431 | 1175 int offset; |
1176 int length; | |
1177 }; | |
1178 | |
8898 | 1179 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
7431 | 1180 { |
1181 FILE *file; | |
1182 char buf[BUF_LONG]; | |
1183 struct tm tm; | |
7761 | 1184 char month[4]; |
7431 | 1185 struct old_logger_data *data = NULL; |
1186 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); | |
7764 | 1187 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); |
1188 GaimStringref *pathref = gaim_stringref_new(pathstr); | |
7431 | 1189 char *newlog; |
7761 | 1190 int logfound = 0; |
1191 int lastoff = 0; | |
1192 int newlen; | |
7791 | 1193 time_t lasttime = 0; |
7431 | 1194 |
1195 GaimLog *log = NULL; | |
1196 GList *list = NULL; | |
1197 | |
7473 | 1198 g_free(logfile); |
7764 | 1199 g_free(pathstr); |
7473 | 1200 |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1201 if (!(file = g_fopen(gaim_stringref_value(pathref), "rb"))) { |
7764 | 1202 gaim_stringref_unref(pathref); |
7431 | 1203 return NULL; |
7447 | 1204 } |
7436 | 1205 |
7431 | 1206 while (fgets(buf, BUF_LONG, file)) { |
1207 if ((newlog = strstr(buf, "---- New C"))) { | |
1208 int length; | |
1209 int offset; | |
1210 char convostart[32]; | |
1211 char *temp = strchr(buf, '@'); | |
7436 | 1212 |
7431 | 1213 if (temp == NULL || strlen(temp) < 2) |
1214 continue; | |
7436 | 1215 |
7431 | 1216 temp++; |
1217 length = strcspn(temp, "-"); | |
1218 if (length > 31) length = 31; | |
7436 | 1219 |
7431 | 1220 offset = ftell(file); |
7436 | 1221 |
7761 | 1222 if (logfound) { |
1223 newlen = offset - lastoff - length; | |
7436 | 1224 if(strstr(buf, "----</H3><BR>")) { |
7761 | 1225 newlen -= |
1226 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + | |
1227 sizeof("----</H3><BR>") - 2; | |
7436 | 1228 } else { |
7761 | 1229 newlen -= |
1230 sizeof("---- New Conversation @ ") + sizeof("----") - 2; | |
7436 | 1231 } |
1232 | |
7461 | 1233 if(strchr(buf, '\r')) |
7770 | 1234 newlen--; |
7461 | 1235 |
7761 | 1236 if (newlen != 0) { |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
1237 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
|
1238 log->logger = old_logger; |
7761 | 1239 log->time = lasttime; |
1240 data = g_new0(struct old_logger_data, 1); | |
1241 data->offset = lastoff; | |
1242 data->length = newlen; | |
7764 | 1243 data->pathref = gaim_stringref_ref(pathref); |
7761 | 1244 log->logger_data = data; |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
1245 list = g_list_prepend(list, log); |
7761 | 1246 } |
7431 | 1247 } |
1248 | |
7761 | 1249 logfound = 1; |
1250 lastoff = offset; | |
7436 | 1251 |
7431 | 1252 g_snprintf(convostart, length, "%s", temp); |
7676 | 1253 sscanf(convostart, "%*s %s %d %d:%d:%d %d", |
1254 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year); | |
1255 /* Ugly hack, in case current locale is not English */ | |
1256 if (strcmp(month, "Jan") == 0) { | |
1257 tm.tm_mon= 0; | |
1258 } else if (strcmp(month, "Feb") == 0) { | |
1259 tm.tm_mon = 1; | |
1260 } else if (strcmp(month, "Mar") == 0) { | |
1261 tm.tm_mon = 2; | |
1262 } else if (strcmp(month, "Apr") == 0) { | |
1263 tm.tm_mon = 3; | |
1264 } else if (strcmp(month, "May") == 0) { | |
1265 tm.tm_mon = 4; | |
1266 } else if (strcmp(month, "Jun") == 0) { | |
1267 tm.tm_mon = 5; | |
1268 } else if (strcmp(month, "Jul") == 0) { | |
1269 tm.tm_mon = 6; | |
1270 } else if (strcmp(month, "Aug") == 0) { | |
1271 tm.tm_mon = 7; | |
1272 } else if (strcmp(month, "Sep") == 0) { | |
1273 tm.tm_mon = 8; | |
1274 } else if (strcmp(month, "Oct") == 0) { | |
1275 tm.tm_mon = 9; | |
1276 } else if (strcmp(month, "Nov") == 0) { | |
1277 tm.tm_mon = 10; | |
1278 } else if (strcmp(month, "Dec") == 0) { | |
1279 tm.tm_mon = 11; | |
1280 } | |
1281 tm.tm_year -= 1900; | |
7761 | 1282 lasttime = mktime(&tm); |
4184 | 1283 } |
1284 } | |
7613 | 1285 |
7761 | 1286 if (logfound) { |
1287 if ((newlen = ftell(file) - lastoff) != 0) { | |
11292
ef9280fdc511
[gaim-migrate @ 13492]
Richard Laager <rlaager@wiktel.com>
parents:
11256
diff
changeset
|
1288 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
|
1289 log->logger = old_logger; |
7761 | 1290 log->time = lasttime; |
1291 data = g_new0(struct old_logger_data, 1); | |
1292 data->offset = lastoff; | |
1293 data->length = newlen; | |
7764 | 1294 data->pathref = gaim_stringref_ref(pathref); |
7761 | 1295 log->logger_data = data; |
11703
a53cef8bd22b
[gaim-migrate @ 13994]
Richard Laager <rlaager@wiktel.com>
parents:
11698
diff
changeset
|
1296 list = g_list_prepend(list, log); |
7761 | 1297 } |
7613 | 1298 } |
1299 | |
7764 | 1300 gaim_stringref_unref(pathref); |
7431 | 1301 fclose(file); |
1302 return list; | |
4184 | 1303 } |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1304 |
8898 | 1305 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account) |
8096 | 1306 { |
1307 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name)); | |
1308 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); | |
1309 int size; | |
1310 struct stat st; | |
1311 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1312 if (g_stat(pathstr, &st)) |
8096 | 1313 size = 0; |
1314 else | |
1315 size = st.st_size; | |
1316 | |
1317 g_free(logfile); | |
1318 g_free(pathstr); | |
1319 | |
1320 return size; | |
1321 } | |
1322 | |
7616 | 1323 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1324 { |
7431 | 1325 struct old_logger_data *data = log->logger_data; |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10577
diff
changeset
|
1326 FILE *file = g_fopen(gaim_stringref_value(data->pathref), "rb"); |
10906 | 1327 char *tmp, *read = g_malloc(data->length + 1); |
7431 | 1328 fseek(file, data->offset, SEEK_SET); |
1329 fread(read, data->length, 1, file); | |
8370 | 1330 fclose(file); |
7431 | 1331 read[data->length] = '\0'; |
7436 | 1332 *flags = 0; |
1333 if(strstr(read, "<BR>")) | |
1334 *flags |= GAIM_LOG_READ_NO_NEWLINE; | |
10906 | 1335 else { |
1336 tmp = g_markup_escape_text(read, -1); | |
1337 g_free(read); | |
1338 read = tmp; | |
1339 } | |
7431 | 1340 return read; |
1341 } | |
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
1342 |
7616 | 1343 static int old_logger_size (GaimLog *log) |
7556 | 1344 { |
1345 struct old_logger_data *data = log->logger_data; | |
7616 | 1346 return data ? data->length : 0; |
1347 } | |
1348 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1349 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets) |
11025 | 1350 { |
1351 char *log_path = g_build_filename(gaim_user_dir(), "logs", NULL); | |
1352 GDir *log_dir = g_dir_open(log_path, 0, NULL); | |
1353 gchar *name; | |
1354 GaimBlistNode *gnode, *cnode, *bnode; | |
1355 | |
1356 g_free(log_path); | |
1357 if (log_dir == NULL) | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1358 return; |
11025 | 1359 |
1360 /* Don't worry about the cast, name will be filled with a dynamically allocated data shortly. */ | |
1361 while ((name = (gchar *)g_dir_read_name(log_dir)) != NULL) { | |
1362 size_t len; | |
1363 gchar *ext; | |
1364 GaimLogSet *set; | |
1365 gboolean found = FALSE; | |
1366 | |
1367 /* Unescape the filename. */ | |
1368 name = g_strdup(gaim_unescape_filename(name)); | |
1369 | |
1370 /* Get the (possibly new) length of name. */ | |
1371 len = strlen(name); | |
1372 | |
1373 if (len < 5) { | |
1374 g_free(name); | |
1375 continue; | |
1376 } | |
1377 | |
1378 /* Make sure we're dealing with a log file. */ | |
1379 ext = &name[len - 4]; | |
1380 if (strcmp(ext, ".log")) { | |
1381 g_free(name); | |
1382 continue; | |
1383 } | |
1384 | |
1385 set = g_new0(GaimLogSet, 1); | |
1386 | |
1387 /* Chat for .chat at the end of the name to determine the type. */ | |
1388 *ext = '\0'; | |
1389 set->type = GAIM_LOG_IM; | |
1390 if (len > 9) { | |
1391 char *tmp = &name[len - 9]; | |
1392 if (!strcmp(tmp, ".chat")) { | |
1393 set->type = GAIM_LOG_CHAT; | |
1394 *tmp = '\0'; | |
1395 } | |
1396 } | |
1397 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1398 set->name = set->normalized_name = name; |
11025 | 1399 |
1400 /* Search the buddy list to find the account and to determine if this is a buddy. */ | |
1401 for (gnode = gaim_get_blist()->root; !found && gnode != NULL; gnode = gnode->next) | |
1402 { | |
1403 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
1404 continue; | |
1405 | |
1406 for (cnode = gnode->child; !found && cnode != NULL; cnode = cnode->next) | |
1407 { | |
1408 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
1409 continue; | |
1410 | |
1411 for (bnode = cnode->child; !found && bnode != NULL; bnode = bnode->next) | |
1412 { | |
1413 GaimBuddy *buddy = (GaimBuddy *)bnode; | |
1414 | |
1415 if (!strcmp(buddy->name, name)) { | |
1416 set->account = buddy->account; | |
1417 set->buddy = TRUE; | |
1418 found = TRUE; | |
1419 } | |
1420 } | |
1421 } | |
1422 } | |
1423 | |
11177
3924db2b1ca8
[gaim-migrate @ 13285]
Richard Laager <rlaager@wiktel.com>
parents:
11094
diff
changeset
|
1424 cb(sets, set); |
11025 | 1425 } |
1426 g_dir_close(log_dir); | |
1427 } | |
1428 | |
7616 | 1429 static void old_logger_finalize(GaimLog *log) |
1430 { | |
1431 struct old_logger_data *data = log->logger_data; | |
7764 | 1432 gaim_stringref_unref(data->pathref); |
7616 | 1433 g_free(data); |
7556 | 1434 } |