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