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