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