Mercurial > pidgin
annotate src/log.c @ 10171:829a569993e0
[gaim-migrate @ 11263]
DaSkreech noticed that the per-conversation logs could not over-rule the
global options. I figured out that gaim_log_write was the cause, it was
checking global options but not local ones. Stu determined that these
checks were redundant.
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Thu, 11 Nov 2004 19:00:33 +0000 |
| parents | 9fdbfe832fac |
| children | c754d26fe85e |
| 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 | |
| 7457 | 36 static GaimLogLogger html_logger; |
| 7431 | 37 static GaimLogLogger txt_logger; |
| 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 | |
| 46 | |
| 7431 | 47 /************************************************************************** |
| 48 * PUBLIC LOGGING FUNCTIONS *********************************************** | |
| 49 **************************************************************************/ | |
| 4184 | 50 |
| 7431 | 51 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time) |
| 52 { | |
| 53 GaimLog *log = g_new0(GaimLog, 1); | |
| 8635 | 54 log->name = g_strdup(gaim_normalize(account, name)); |
| 7431 | 55 log->account = account; |
| 56 log->time = time; | |
| 8573 | 57 log->type = type; |
| 8096 | 58 log->logger_data = NULL; |
| 7431 | 59 log->logger = gaim_log_logger_get(); |
| 7440 | 60 if (log->logger && log->logger->create) |
| 61 log->logger->create(log); | |
| 7431 | 62 return log; |
| 4184 | 63 } |
| 64 | |
| 7431 | 65 void gaim_log_free(GaimLog *log) |
| 4184 | 66 { |
| 7431 | 67 g_return_if_fail(log); |
| 68 if (log->logger && log->logger->finalize) | |
| 69 log->logger->finalize(log); | |
| 70 g_free(log->name); | |
| 71 g_free(log); | |
| 72 } | |
| 7436 | 73 |
| 74 void gaim_log_write(GaimLog *log, GaimMessageFlags type, | |
| 7431 | 75 const char *from, time_t time, const char *message) |
| 76 { | |
| 77 g_return_if_fail(log); | |
| 78 g_return_if_fail(log->logger); | |
| 7442 | 79 g_return_if_fail(log->logger->write); |
| 7431 | 80 |
|
10171
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
81 struct _gaim_logsize_user *lu; |
|
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
82 (log->logger->write)(log, type, from, time, message); |
|
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
83 |
|
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
84 lu = g_new(struct _gaim_logsize_user, 1); |
| 9892 | 85 |
|
10171
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
86 lu->name = g_strdup(gaim_normalize(log->account, log->name)); |
|
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
87 lu->account = log->account; |
|
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
88 g_hash_table_remove(logsize_users, lu); |
|
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
89 g_free(lu->name); |
|
829a569993e0
[gaim-migrate @ 11263]
Luke Schierer <lschiere@pidgin.im>
parents:
10087
diff
changeset
|
90 g_free(lu); |
| 9892 | 91 |
| 4184 | 92 } |
| 93 | |
| 7431 | 94 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags) |
| 4184 | 95 { |
| 7542 | 96 GaimLogReadFlags mflags; |
| 7431 | 97 g_return_val_if_fail(log && log->logger, NULL); |
| 7462 | 98 if (log->logger->read) { |
| 7535 | 99 char *ret = (log->logger->read)(log, flags ? flags : &mflags); |
|
7478
3c21f3084ff0
[gaim-migrate @ 8091]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7473
diff
changeset
|
100 gaim_str_strip_cr(ret); |
| 7462 | 101 return ret; |
| 102 } | |
| 7470 | 103 return (_("<b><font color=\"red\">The logger has no read function</font></b>")); |
| 4184 | 104 } |
| 7616 | 105 |
| 7556 | 106 int gaim_log_get_size(GaimLog *log) |
| 107 { | |
| 108 g_return_val_if_fail(log && log->logger, 0); | |
| 8096 | 109 |
| 7556 | 110 if (log->logger->size) |
| 111 return log->logger->size(log); | |
| 112 return 0; | |
| 113 } | |
| 114 | |
| 8635 | 115 static guint _gaim_logsize_user_hash(struct _gaim_logsize_user *lu) |
| 116 { | |
| 117 return g_str_hash(lu->name); | |
| 118 } | |
| 119 | |
| 120 static guint _gaim_logsize_user_equal(struct _gaim_logsize_user *lu1, | |
| 121 struct _gaim_logsize_user *lu2) | |
| 122 { | |
| 123 return ((!strcmp(lu1->name, lu2->name)) && lu1->account == lu2->account); | |
| 124 } | |
| 125 | |
| 126 static void _gaim_logsize_user_free_key(struct _gaim_logsize_user *lu) | |
| 127 { | |
| 128 g_free(lu->name); | |
| 129 g_free(lu); | |
| 130 } | |
| 131 | |
| 8898 | 132 int gaim_log_get_total_size(GaimLogType type, const char *name, GaimAccount *account) |
| 7556 | 133 { |
| 9677 | 134 gpointer ptrsize; |
| 135 int size = 0; | |
| 8096 | 136 GSList *n; |
| 8635 | 137 struct _gaim_logsize_user *lu; |
| 8096 | 138 |
| 8635 | 139 lu = g_new(struct _gaim_logsize_user, 1); |
| 140 lu->name = g_strdup(gaim_normalize(account, name)); | |
| 141 lu->account = account; | |
| 142 | |
| 9677 | 143 if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) { |
| 144 size = GPOINTER_TO_INT(ptrsize); | |
| 8635 | 145 g_free(lu->name); |
| 146 g_free(lu); | |
| 147 } else { | |
| 148 for (n = loggers; n; n = n->next) { | |
| 149 GaimLogLogger *logger = n->data; | |
| 7616 | 150 |
| 8635 | 151 if(logger->total_size){ |
| 8898 | 152 size += (logger->total_size)(type, name, account); |
| 8635 | 153 } else if(logger->list) { |
| 8898 | 154 GList *logs = (logger->list)(type, name, account); |
| 8635 | 155 int this_size = 0; |
| 156 | |
| 157 while (logs) { | |
| 158 GList *logs2 = logs->next; | |
| 159 GaimLog *log = (GaimLog*)(logs->data); | |
| 160 this_size += gaim_log_get_size(log); | |
| 161 gaim_log_free(log); | |
| 162 g_list_free_1(logs); | |
| 163 logs = logs2; | |
| 164 } | |
| 165 | |
| 166 size += this_size; | |
| 8096 | 167 } |
| 8635 | 168 } |
| 8096 | 169 |
| 8635 | 170 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(size)); |
| 7556 | 171 } |
| 172 return size; | |
| 173 } | |
| 4184 | 174 |
| 9923 | 175 static char* gaim_log_get_log_dir(GaimLogType type, const char *name, GaimAccount *account) { |
| 9926 | 176 char *acct_name = g_strdup(gaim_escape_filename(gaim_normalize(account, |
| 177 gaim_account_get_username(account)))); | |
| 178 const char *target; | |
| 9923 | 179 /* does this seem like a bad way to get this component of the path to anyone else? --Nathan */ |
| 9977 | 180 /* XXX: this is in fact a HORRIBLE way to do this, because if we can't find the prpl (plugin won't load) then this goes BOOM. Someone make a better way...*/ |
| 9923 | 181 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO( |
| 182 gaim_find_prpl(gaim_account_get_protocol_id(account)) | |
| 183 )->list_icon(account, NULL); | |
| 9926 | 184 |
| 9923 | 185 char *dir; |
| 186 | |
| 187 if (type == GAIM_LOG_CHAT) { | |
| 188 char *temp = g_strdup_printf("%s.chat", gaim_normalize(account, name)); | |
| 9926 | 189 target = gaim_escape_filename(temp); |
| 9923 | 190 g_free(temp); |
| 191 } else if(type == GAIM_LOG_SYSTEM) { | |
| 9926 | 192 target = ".system"; |
| 9923 | 193 } else { |
| 9926 | 194 target = gaim_escape_filename(gaim_normalize(account, name)); |
| 9923 | 195 } |
| 196 | |
| 197 | |
| 198 dir = g_build_filename(gaim_user_dir(), "logs", prpl, acct_name, target, NULL); | |
| 9926 | 199 |
| 9923 | 200 g_free(acct_name); |
| 201 return dir; | |
| 202 } | |
| 203 | |
| 7431 | 204 /**************************************************************************** |
| 205 * LOGGER FUNCTIONS ********************************************************* | |
| 206 ****************************************************************************/ | |
| 4184 | 207 |
| 7431 | 208 static GaimLogLogger *current_logger = NULL; |
| 7436 | 209 |
| 7431 | 210 static void logger_pref_cb(const char *name, GaimPrefType type, |
| 211 gpointer value, gpointer data) | |
| 212 { | |
| 213 GaimLogLogger *logger; | |
| 214 GSList *l = loggers; | |
| 215 while (l) { | |
| 216 logger = l->data; | |
| 217 if (!strcmp(logger->id, value)) { | |
| 218 gaim_log_logger_set(logger); | |
| 219 return; | |
| 4184 | 220 } |
| 7431 | 221 l = l->next; |
| 222 } | |
| 223 gaim_log_logger_set(&txt_logger); | |
| 224 } | |
| 4184 | 225 |
| 226 | |
| 8898 | 227 GaimLogLogger *gaim_log_logger_new( |
| 228 void(*create)(GaimLog *), | |
| 229 void(*write)(GaimLog *, GaimMessageFlags, const char *, time_t, const char *), | |
| 230 void(*finalize)(GaimLog *), | |
| 231 GList*(*list)(GaimLogType type, const char*, GaimAccount*), | |
| 232 char*(*read)(GaimLog*, GaimLogReadFlags*), | |
| 233 int(*size)(GaimLog*)) | |
| 7431 | 234 { |
| 235 GaimLogLogger *logger = g_new0(GaimLogLogger, 1); | |
| 7440 | 236 logger->create = create; |
| 7431 | 237 logger->write = write; |
| 238 logger->finalize = finalize; | |
| 239 logger->list = list; | |
| 240 logger->read = read; | |
| 7556 | 241 logger->size = size; |
| 7431 | 242 return logger; |
| 4184 | 243 } |
| 244 | |
| 7431 | 245 void gaim_log_logger_free(GaimLogLogger *logger) |
| 4184 | 246 { |
| 7431 | 247 g_free(logger); |
| 248 } | |
| 4184 | 249 |
| 7431 | 250 void gaim_log_logger_add (GaimLogLogger *logger) |
| 251 { | |
| 252 g_return_if_fail(logger); | |
| 253 if (g_slist_find(loggers, logger)) | |
| 254 return; | |
| 255 loggers = g_slist_append(loggers, logger); | |
| 256 } | |
| 257 | |
| 258 void gaim_log_logger_remove (GaimLogLogger *logger) | |
| 259 { | |
| 260 g_return_if_fail(logger); | |
| 261 g_slist_remove(loggers, logger); | |
| 4184 | 262 } |
| 263 | |
| 7431 | 264 void gaim_log_logger_set (GaimLogLogger *logger) |
| 4184 | 265 { |
| 7431 | 266 g_return_if_fail(logger); |
| 267 current_logger = logger; | |
| 7436 | 268 } |
| 4184 | 269 |
| 7431 | 270 GaimLogLogger *gaim_log_logger_get() |
| 271 { | |
| 272 return current_logger; | |
| 273 } | |
| 4184 | 274 |
| 7431 | 275 GList *gaim_log_logger_get_options(void) |
| 276 { | |
| 277 GSList *n; | |
| 278 GList *list = NULL; | |
| 279 GaimLogLogger *data; | |
| 4184 | 280 |
| 7431 | 281 for (n = loggers; n; n = n->next) { |
| 282 data = n->data; | |
| 283 if (!data->write) | |
| 284 continue; | |
| 7494 | 285 list = g_list_append(list, _(data->name)); |
| 7431 | 286 list = g_list_append(list, data->id); |
| 4184 | 287 } |
| 288 | |
| 7431 | 289 return list; |
| 290 } | |
| 291 | |
| 8573 | 292 gint gaim_log_compare(gconstpointer y, gconstpointer z) |
| 7431 | 293 { |
| 7436 | 294 const GaimLog *a = y; |
| 295 const GaimLog *b = z; | |
| 296 | |
| 7431 | 297 return b->time - a->time; |
| 298 } | |
| 299 | |
| 8898 | 300 GList *gaim_log_get_logs(GaimLogType type, const char *name, GaimAccount *account) |
| 7431 | 301 { |
| 302 GList *logs = NULL; | |
| 303 GSList *n; | |
| 304 for (n = loggers; n; n = n->next) { | |
| 305 GaimLogLogger *logger = n->data; | |
| 306 if (!logger->list) | |
| 307 continue; | |
| 8898 | 308 logs = g_list_concat(logs, logger->list(type, name, account)); |
| 7431 | 309 } |
| 7436 | 310 |
| 8573 | 311 return g_list_sort(logs, gaim_log_compare); |
| 312 } | |
| 313 | |
| 314 GList *gaim_log_get_system_logs(GaimAccount *account) | |
| 315 { | |
| 316 GList *logs = NULL; | |
| 317 GSList *n; | |
| 318 for (n = loggers; n; n = n->next) { | |
| 319 GaimLogLogger *logger = n->data; | |
| 320 if (!logger->list_syslog) | |
| 321 continue; | |
| 322 logs = g_list_concat(logs, logger->list_syslog(account)); | |
| 323 } | |
| 324 | |
| 325 return g_list_sort(logs, gaim_log_compare); | |
| 7431 | 326 } |
| 327 | |
| 328 void gaim_log_init(void) | |
| 7436 | 329 { |
| 7431 | 330 gaim_prefs_add_none("/core/logging"); |
| 7555 | 331 gaim_prefs_add_bool("/core/logging/log_ims", FALSE); |
| 332 gaim_prefs_add_bool("/core/logging/log_chats", FALSE); | |
| 8573 | 333 gaim_prefs_add_bool("/core/logging/log_system", FALSE); |
| 334 gaim_prefs_add_bool("/core/logging/log_signon_signoff", FALSE); | |
| 335 gaim_prefs_add_bool("/core/logging/log_idle_state", FALSE); | |
| 336 gaim_prefs_add_bool("/core/logging/log_away_state", FALSE); | |
| 337 gaim_prefs_add_bool("/core/logging/log_own_states", FALSE); | |
| 338 | |
| 7431 | 339 gaim_prefs_add_string("/core/logging/format", "txt"); |
| 7457 | 340 gaim_log_logger_add(&html_logger); |
| 7431 | 341 gaim_log_logger_add(&txt_logger); |
| 342 gaim_log_logger_add(&old_logger); | |
| 10087 | 343 gaim_prefs_connect_callback(NULL, "/core/logging/format", |
| 7431 | 344 logger_pref_cb, NULL); |
| 345 gaim_prefs_trigger_callback("/core/logging/format"); | |
| 8635 | 346 |
| 347 logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash, | |
| 348 (GEqualFunc)_gaim_logsize_user_equal, | |
| 349 (GDestroyNotify)_gaim_logsize_user_free_key, NULL); | |
| 7431 | 350 } |
| 351 | |
| 352 /**************************************************************************** | |
| 353 * LOGGERS ****************************************************************** | |
| 354 ****************************************************************************/ | |
| 355 | |
| 7616 | 356 struct generic_logger_data { |
| 357 char *path; | |
| 358 FILE *file; | |
| 359 }; | |
| 360 | |
| 9763 | 361 static void log_writer_common(GaimLog *log, GaimMessageFlags type, |
| 9923 | 362 time_t time, const char *ext) |
| 9763 | 363 { |
| 364 char date[64]; | |
| 365 struct generic_logger_data *data = log->logger_data; | |
| 366 | |
| 367 if(!data) { | |
| 368 /* This log is new */ | |
| 9923 | 369 char *dir, *filename, *path; |
| 370 | |
| 371 dir = gaim_log_get_log_dir(log->type, log->name, log->account); | |
| 372 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 9763 | 373 |
| 374 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S", localtime(&log->time)); | |
| 375 | |
| 376 filename = g_strdup_printf("%s%s", date, ext ? ext : ""); | |
| 377 | |
| 378 path = g_build_filename(dir, filename, NULL); | |
| 379 g_free(dir); | |
| 380 g_free(filename); | |
| 381 | |
| 382 log->logger_data = data = g_new0(struct generic_logger_data, 1); | |
| 383 | |
| 384 data->file = fopen(path, "a"); | |
| 385 if (!data->file) { | |
| 386 gaim_debug(GAIM_DEBUG_ERROR, "log", | |
| 9892 | 387 "Could not create log file %s\n", path); |
| 9763 | 388 g_free(path); |
| 389 return; | |
| 390 } | |
| 391 g_free(path); | |
| 392 } | |
| 393 } | |
| 394 | |
| 8898 | 395 static GList *log_lister_common(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger) |
| 7431 | 396 { |
| 397 GDir *dir; | |
| 398 GList *list = NULL; | |
| 7628 | 399 const char *filename; |
| 8111 | 400 char *path; |
| 401 | |
| 402 if(!account) | |
| 403 return NULL; | |
| 404 | |
| 9923 | 405 path = gaim_log_get_log_dir(type, name, account); |
| 7447 | 406 |
| 7431 | 407 if (!(dir = g_dir_open(path, 0, NULL))) { |
| 408 g_free(path); | |
| 409 return NULL; | |
| 410 } | |
| 8898 | 411 |
| 7431 | 412 while ((filename = g_dir_read_name(dir))) { |
| 8577 | 413 if (gaim_str_has_suffix(filename, ext) && |
| 414 strlen(filename) == 17 + strlen(ext)) { | |
| 7431 | 415 GaimLog *log; |
| 7616 | 416 struct generic_logger_data *data; |
| 8577 | 417 time_t stamp = gaim_str_to_time(filename, FALSE); |
| 7431 | 418 |
| 8898 | 419 log = gaim_log_new(type, name, account, stamp); |
| 7431 | 420 log->logger = logger; |
| 7616 | 421 log->logger_data = data = g_new0(struct generic_logger_data, 1); |
| 422 data->path = g_build_filename(path, filename, NULL); | |
| 7431 | 423 list = g_list_append(list, log); |
| 4184 | 424 } |
| 425 } | |
| 7431 | 426 g_dir_close(dir); |
| 7447 | 427 g_free(path); |
| 7431 | 428 return list; |
| 429 } | |
| 4184 | 430 |
| 7556 | 431 /* Only to be used with logs listed from log_lister_common */ |
| 7616 | 432 int log_sizer_common(GaimLog *log) |
| 7556 | 433 { |
| 434 struct stat st; | |
| 7616 | 435 struct generic_logger_data *data = log->logger_data; |
| 7556 | 436 |
| 7616 | 437 if (!data->path || stat(data->path, &st)) |
| 7556 | 438 st.st_size = 0; |
| 439 | |
| 440 return st.st_size; | |
| 441 } | |
| 442 | |
| 7431 | 443 #if 0 /* Maybe some other time. */ |
| 7443 | 444 /**************** |
| 7431 | 445 ** XML LOGGER ** |
| 446 ****************/ | |
| 447 | |
| 448 static const char *str_from_msg_type (GaimMessageFlags type) | |
| 449 { | |
| 7443 | 450 |
| 7431 | 451 return ""; |
| 7443 | 452 |
| 7431 | 453 } |
| 454 | |
| 7443 | 455 static void xml_logger_write(GaimLog *log, |
| 456 GaimMessageFlags type, | |
| 7431 | 457 const char *from, time_t time, const char *message) |
| 458 { | |
| 459 char date[64]; | |
| 460 char *xhtml = NULL; | |
| 461 if (!log->logger_data) { | |
| 462 /* This log is new. We could use the loggers 'new' function, but | |
| 463 * creating a new file there would result in empty files in the case | |
| 464 * that you open a convo with someone, but don't say anything. | |
| 465 */ | |
| 9923 | 466 char *dir = gaim_log_get_log_dir(log->type, log->name, log->account); |
| 7431 | 467 FILE *file; |
| 7453 | 468 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time)); |
| 7443 | 469 |
| 7612 | 470 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
| 7443 | 471 |
| 7431 | 472 char *filename = g_build_filename(dir, date, NULL); |
| 473 g_free(dir); | |
| 7443 | 474 |
| 7431 | 475 log->logger_data = fopen(filename, "a"); |
| 476 if (!log->logger_data) { | |
| 477 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | |
| 7564 | 478 g_free(filename); |
| 7431 | 479 return; |
| 480 } | |
| 7564 | 481 g_free(filename); |
| 7431 | 482 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" |
| 483 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); | |
| 7443 | 484 |
| 7453 | 485 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
| 7431 | 486 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", |
| 487 date, log->name, prpl); | |
| 488 } | |
| 7443 | 489 |
| 9923 | 490 /* if we can't write to the file, give up before we hurt ourselves */ |
| 491 if(!data->file) | |
| 492 return; | |
| 493 | |
| 7453 | 494 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); |
| 7431 | 495 gaim_markup_html_to_xhtml(message, &xhtml, NULL); |
| 496 if (from) | |
| 7443 | 497 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n", |
| 498 str_from_msg_type(type), | |
| 7431 | 499 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
| 500 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
| 501 from, date, xhtml); | |
| 502 else | |
| 7443 | 503 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n", |
| 504 str_from_msg_type(type), | |
| 7431 | 505 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
| 506 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
| 7443 | 507 date, xhtml): |
| 7431 | 508 fflush(log->logger_data); |
| 509 g_free(xhtml); | |
| 7443 | 510 } |
| 511 | |
| 7431 | 512 static void xml_logger_finalize(GaimLog *log) |
| 513 { | |
| 514 if (log->logger_data) { | |
| 515 fprintf(log->logger_data, "</conversation>\n"); | |
| 516 fclose(log->logger_data); | |
| 517 log->logger_data = NULL; | |
| 518 } | |
| 519 } | |
| 7443 | 520 |
| 8898 | 521 static GList *xml_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
| 7431 | 522 { |
| 8898 | 523 return log_lister_common(type, sn, account, ".xml", &xml_logger); |
| 4184 | 524 } |
| 525 | |
| 7431 | 526 static GaimLogLogger xml_logger = { |
| 527 N_("XML"), "xml", | |
| 528 NULL, | |
| 529 xml_logger_write, | |
| 530 xml_logger_finalize, | |
| 531 xml_logger_list, | |
| 8096 | 532 NULL, |
| 7431 | 533 NULL |
| 534 }; | |
| 535 #endif | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
536 |
| 7431 | 537 /**************************** |
| 7457 | 538 ** HTML LOGGER ************* |
| 539 ****************************/ | |
| 540 | |
| 541 static void html_logger_write(GaimLog *log, GaimMessageFlags type, | |
| 542 const char *from, time_t time, const char *message) | |
| 543 { | |
| 9763 | 544 char *msg_fixed; |
| 7457 | 545 char date[64]; |
| 9613 | 546 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
| 547 const char *prpl_name = plugin->info->name; | |
| 9763 | 548 struct generic_logger_data *data = log->logger_data; |
| 9613 | 549 |
| 7618 | 550 if(!data) { |
| 9763 | 551 const char *prpl = |
| 552 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
| 9923 | 553 log_writer_common(log, type, time, ".html"); |
| 7457 | 554 |
| 9763 | 555 data = log->logger_data; |
| 7457 | 556 |
| 9763 | 557 /* if we can't write to the file, give up before we hurt ourselves */ |
| 558 if(!data->file) | |
| 559 return; | |
| 7616 | 560 |
| 7457 | 561 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
| 7616 | 562 fprintf(data->file, "<html><head><title>"); |
| 563 fprintf(data->file, "Conversation with %s at %s on %s (%s)", | |
| 7457 | 564 log->name, date, gaim_account_get_username(log->account), prpl); |
| 7616 | 565 fprintf(data->file, "</title></head><body>"); |
| 566 fprintf(data->file, | |
| 7457 | 567 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", |
| 568 log->name, date, gaim_account_get_username(log->account), prpl); | |
| 9763 | 569 |
| 7457 | 570 } |
| 7623 | 571 |
| 9892 | 572 /* if we can't write to the file, give up before we hurt ourselves */ |
| 573 if(!data->file) | |
| 574 return; | |
| 575 | |
| 7882 | 576 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); |
| 577 | |
| 8577 | 578 if(log->type == GAIM_LOG_SYSTEM){ |
| 9592 | 579 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); |
| 8577 | 580 fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); |
| 581 } else { | |
| 582 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | |
| 583 if (type & GAIM_MESSAGE_SYSTEM) | |
| 584 fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); | |
| 585 else if (type & GAIM_MESSAGE_WHISPER) | |
| 586 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", | |
| 587 date, from, msg_fixed); | |
| 588 else if (type & GAIM_MESSAGE_AUTO_RESP) { | |
| 589 if (type & GAIM_MESSAGE_SEND) | |
| 590 fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | |
| 591 else if (type & GAIM_MESSAGE_RECV) | |
| 592 fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | |
| 593 } else if (type & GAIM_MESSAGE_RECV) { | |
| 594 if(gaim_message_meify(msg_fixed, -1)) | |
| 595 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 9613 | 596 date, from, prpl_name, msg_fixed); |
| 8577 | 597 else |
| 598 fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 9613 | 599 date, from, prpl_name, msg_fixed); |
| 8577 | 600 } else if (type & GAIM_MESSAGE_SEND) { |
| 601 if(gaim_message_meify(msg_fixed, -1)) | |
| 602 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 9613 | 603 date, from, prpl_name, msg_fixed); |
| 8577 | 604 else |
| 605 fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 9613 | 606 date, from, prpl_name, msg_fixed); |
| 8577 | 607 } |
| 7564 | 608 } |
| 8573 | 609 |
| 7882 | 610 g_free(msg_fixed); |
| 7616 | 611 fflush(data->file); |
| 7457 | 612 } |
| 613 | |
| 614 static void html_logger_finalize(GaimLog *log) | |
| 615 { | |
| 7616 | 616 struct generic_logger_data *data = log->logger_data; |
| 617 if (data) { | |
| 618 if(data->file) { | |
| 619 fprintf(data->file, "</body></html>"); | |
| 620 fclose(data->file); | |
| 621 } | |
| 622 g_free(data->path); | |
| 7752 | 623 g_free(data); |
| 7463 | 624 } |
| 7457 | 625 } |
| 626 | |
| 8898 | 627 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
| 7457 | 628 { |
| 8898 | 629 return log_lister_common(type, sn, account, ".html", &html_logger); |
| 7457 | 630 } |
| 631 | |
| 8573 | 632 static GList *html_logger_list_syslog(GaimAccount *account) |
| 633 { | |
| 8898 | 634 return log_lister_common(GAIM_LOG_SYSTEM, ".system", account, ".html", &html_logger); |
| 8573 | 635 } |
| 636 | |
| 7457 | 637 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
| 638 { | |
| 639 char *read, *minus_header; | |
| 7616 | 640 struct generic_logger_data *data = log->logger_data; |
| 7457 | 641 *flags = GAIM_LOG_READ_NO_NEWLINE; |
| 7616 | 642 if (!data || !data->path) |
| 643 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
| 644 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
| 7457 | 645 minus_header = strchr(read, '\n'); |
| 646 if (!minus_header) | |
| 647 minus_header = g_strdup(read); | |
| 648 else | |
| 649 minus_header = g_strdup(minus_header + 1); | |
| 650 g_free(read); | |
| 651 return minus_header; | |
| 652 } | |
| 8578 | 653 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
| 7457 | 654 } |
| 655 | |
| 656 static GaimLogLogger html_logger = { | |
| 657 N_("HTML"), "html", | |
| 9819 | 658 NULL, |
| 7457 | 659 html_logger_write, |
| 660 html_logger_finalize, | |
| 661 html_logger_list, | |
| 7556 | 662 html_logger_read, |
| 8096 | 663 log_sizer_common, |
| 8573 | 664 NULL, |
| 665 html_logger_list_syslog | |
| 7457 | 666 }; |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 /**************************** | |
| 7431 | 672 ** PLAIN TEXT LOGGER ******* |
| 673 ****************************/ | |
| 4184 | 674 |
| 7436 | 675 static void txt_logger_write(GaimLog *log, |
| 676 GaimMessageFlags type, | |
| 7431 | 677 const char *from, time_t time, const char *message) |
| 678 { | |
| 679 char date[64]; | |
| 9763 | 680 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
| 7616 | 681 struct generic_logger_data *data = log->logger_data; |
| 9763 | 682 char *stripped = NULL; |
| 683 | |
| 684 if(!data) { | |
| 7431 | 685 /* This log is new. We could use the loggers 'new' function, but |
| 686 * creating a new file there would result in empty files in the case | |
| 687 * that you open a convo with someone, but don't say anything. | |
| 688 */ | |
| 9763 | 689 const char *prpl = |
| 690 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | |
| 9923 | 691 log_writer_common(log, type, time, ".txt"); |
| 8898 | 692 |
| 9763 | 693 data = log->logger_data; |
| 7436 | 694 |
| 9763 | 695 /* if we can't write to the file, give up before we hurt ourselves */ |
| 696 if(!data->file) | |
| 697 return; | |
| 7616 | 698 |
| 7453 | 699 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
| 7616 | 700 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
| 7431 | 701 log->name, date, gaim_account_get_username(log->account), prpl); |
| 702 } | |
| 7436 | 703 |
| 7623 | 704 /* if we can't write to the file, give up before we hurt ourselves */ |
| 705 if(!data->file) | |
| 706 return; | |
| 707 | |
| 8573 | 708 stripped = gaim_markup_strip_html(message); |
| 709 | |
| 710 if(log->type == GAIM_LOG_SYSTEM){ | |
| 9592 | 711 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); |
| 8573 | 712 fprintf(data->file, "---- %s @ %s ----\n", stripped, date); |
| 713 } else { | |
| 714 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | |
| 715 if (type & GAIM_MESSAGE_SEND || | |
| 716 type & GAIM_MESSAGE_RECV) { | |
| 717 if (type & GAIM_MESSAGE_AUTO_RESP) { | |
| 718 fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, | |
| 719 from, stripped); | |
| 720 } else { | |
| 721 if(gaim_message_meify(stripped, -1)) | |
| 722 fprintf(data->file, "(%s) ***%s %s\n", date, from, | |
| 723 stripped); | |
| 724 else | |
| 725 fprintf(data->file, "(%s) %s: %s\n", date, from, | |
| 726 stripped); | |
| 727 } | |
| 728 } else if (type & GAIM_MESSAGE_SYSTEM) | |
| 729 fprintf(data->file, "(%s) %s\n", date, stripped); | |
| 730 else if (type & GAIM_MESSAGE_NO_LOG) { | |
| 731 /* This shouldn't happen */ | |
| 732 g_free(stripped); | |
| 733 return; | |
| 734 } else if (type & GAIM_MESSAGE_WHISPER) | |
| 735 fprintf(data->file, "(%s) *%s* %s", date, from, stripped); | |
| 736 else | |
| 737 fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", | |
| 738 from ? ":" : "", stripped); | |
| 739 } | |
| 740 | |
| 741 fflush(data->file); | |
| 742 g_free(stripped); | |
| 7431 | 743 } |
| 744 | |
| 745 static void txt_logger_finalize(GaimLog *log) | |
| 746 { | |
| 7616 | 747 struct generic_logger_data *data = log->logger_data; |
| 748 if (data) { | |
| 749 if(data->file) | |
| 750 fclose(data->file); | |
| 751 if(data->path) | |
| 752 g_free(data->path); | |
| 7752 | 753 g_free(data); |
| 7616 | 754 } |
| 7431 | 755 } |
| 756 | |
| 8898 | 757 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
| 7431 | 758 { |
| 8898 | 759 return log_lister_common(type, sn, account, ".txt", &txt_logger); |
| 7431 | 760 } |
| 761 | |
| 8573 | 762 static GList *txt_logger_list_syslog(GaimAccount *account) |
| 763 { | |
| 8898 | 764 return log_lister_common(GAIM_LOG_SYSTEM, ".system", account, ".txt", &txt_logger); |
| 8573 | 765 } |
| 766 | |
| 7431 | 767 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
| 768 { | |
| 8517 | 769 char *read, *minus_header, *minus_header2; |
| 7616 | 770 struct generic_logger_data *data = log->logger_data; |
| 7457 | 771 *flags = 0; |
| 7616 | 772 if (!data || !data->path) |
| 773 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
| 774 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
| 7431 | 775 minus_header = strchr(read, '\n'); |
| 776 if (!minus_header) | |
| 777 minus_header = g_strdup(read); | |
| 7436 | 778 else |
| 7431 | 779 minus_header = g_strdup(minus_header + 1); |
| 780 g_free(read); | |
| 8517 | 781 minus_header2 = gaim_escape_html(minus_header); |
| 782 g_free(minus_header); | |
| 783 return minus_header2; | |
| 7431 | 784 } |
| 8578 | 785 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
| 7436 | 786 } |
| 7431 | 787 |
| 788 static GaimLogLogger txt_logger = { | |
| 789 N_("Plain text"), "txt", | |
| 9819 | 790 NULL, |
| 7431 | 791 txt_logger_write, |
| 792 txt_logger_finalize, | |
| 793 txt_logger_list, | |
| 7556 | 794 txt_logger_read, |
| 8096 | 795 log_sizer_common, |
| 8573 | 796 NULL, |
| 797 txt_logger_list_syslog | |
| 7431 | 798 }; |
| 799 | |
| 800 /**************** | |
| 801 * OLD LOGGER *** | |
| 802 ****************/ | |
| 803 | |
| 804 /* The old logger doesn't write logs, only reads them. This is to include | |
| 805 * old logs in the log viewer transparently. | |
| 806 */ | |
| 807 | |
| 808 struct old_logger_data { | |
| 7764 | 809 GaimStringref *pathref; |
| 7431 | 810 int offset; |
| 811 int length; | |
| 812 }; | |
| 813 | |
| 8898 | 814 static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
| 7431 | 815 { |
| 816 FILE *file; | |
| 817 char buf[BUF_LONG]; | |
| 818 struct tm tm; | |
| 7761 | 819 char month[4]; |
| 7431 | 820 struct old_logger_data *data = NULL; |
| 821 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); | |
| 7764 | 822 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); |
| 823 GaimStringref *pathref = gaim_stringref_new(pathstr); | |
| 7431 | 824 char *newlog; |
| 7761 | 825 int logfound = 0; |
| 826 int lastoff = 0; | |
| 827 int newlen; | |
| 7791 | 828 time_t lasttime = 0; |
| 7431 | 829 |
| 830 GaimLog *log = NULL; | |
| 831 GList *list = NULL; | |
| 832 | |
| 7473 | 833 g_free(logfile); |
| 7764 | 834 g_free(pathstr); |
| 7473 | 835 |
| 7764 | 836 if (!(file = fopen(gaim_stringref_value(pathref), "rb"))) { |
| 837 gaim_stringref_unref(pathref); | |
| 7431 | 838 return NULL; |
| 7447 | 839 } |
| 7436 | 840 |
| 7431 | 841 while (fgets(buf, BUF_LONG, file)) { |
| 842 if ((newlog = strstr(buf, "---- New C"))) { | |
| 843 int length; | |
| 844 int offset; | |
| 845 char convostart[32]; | |
| 846 char *temp = strchr(buf, '@'); | |
| 7436 | 847 |
| 7431 | 848 if (temp == NULL || strlen(temp) < 2) |
| 849 continue; | |
| 7436 | 850 |
| 7431 | 851 temp++; |
| 852 length = strcspn(temp, "-"); | |
| 853 if (length > 31) length = 31; | |
| 7436 | 854 |
| 7431 | 855 offset = ftell(file); |
| 7436 | 856 |
| 7761 | 857 if (logfound) { |
| 858 newlen = offset - lastoff - length; | |
| 7436 | 859 if(strstr(buf, "----</H3><BR>")) { |
| 7761 | 860 newlen -= |
| 861 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + | |
| 862 sizeof("----</H3><BR>") - 2; | |
| 7436 | 863 } else { |
| 7761 | 864 newlen -= |
| 865 sizeof("---- New Conversation @ ") + sizeof("----") - 2; | |
| 7436 | 866 } |
| 867 | |
| 7461 | 868 if(strchr(buf, '\r')) |
| 7770 | 869 newlen--; |
| 7461 | 870 |
| 7761 | 871 if (newlen != 0) { |
| 872 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | |
| 873 log->logger = &old_logger; | |
| 874 log->time = lasttime; | |
| 875 data = g_new0(struct old_logger_data, 1); | |
| 876 data->offset = lastoff; | |
| 877 data->length = newlen; | |
| 7764 | 878 data->pathref = gaim_stringref_ref(pathref); |
| 7761 | 879 log->logger_data = data; |
| 7431 | 880 list = g_list_append(list, log); |
| 7761 | 881 } |
| 7431 | 882 } |
| 883 | |
| 7761 | 884 logfound = 1; |
| 885 lastoff = offset; | |
| 7436 | 886 |
| 7431 | 887 g_snprintf(convostart, length, "%s", temp); |
| 7676 | 888 sscanf(convostart, "%*s %s %d %d:%d:%d %d", |
| 889 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year); | |
| 890 /* Ugly hack, in case current locale is not English */ | |
| 891 if (strcmp(month, "Jan") == 0) { | |
| 892 tm.tm_mon= 0; | |
| 893 } else if (strcmp(month, "Feb") == 0) { | |
| 894 tm.tm_mon = 1; | |
| 895 } else if (strcmp(month, "Mar") == 0) { | |
| 896 tm.tm_mon = 2; | |
| 897 } else if (strcmp(month, "Apr") == 0) { | |
| 898 tm.tm_mon = 3; | |
| 899 } else if (strcmp(month, "May") == 0) { | |
| 900 tm.tm_mon = 4; | |
| 901 } else if (strcmp(month, "Jun") == 0) { | |
| 902 tm.tm_mon = 5; | |
| 903 } else if (strcmp(month, "Jul") == 0) { | |
| 904 tm.tm_mon = 6; | |
| 905 } else if (strcmp(month, "Aug") == 0) { | |
| 906 tm.tm_mon = 7; | |
| 907 } else if (strcmp(month, "Sep") == 0) { | |
| 908 tm.tm_mon = 8; | |
| 909 } else if (strcmp(month, "Oct") == 0) { | |
| 910 tm.tm_mon = 9; | |
| 911 } else if (strcmp(month, "Nov") == 0) { | |
| 912 tm.tm_mon = 10; | |
| 913 } else if (strcmp(month, "Dec") == 0) { | |
| 914 tm.tm_mon = 11; | |
| 915 } | |
| 916 tm.tm_year -= 1900; | |
| 7761 | 917 lasttime = mktime(&tm); |
| 4184 | 918 } |
| 919 } | |
| 7613 | 920 |
| 7761 | 921 if (logfound) { |
| 922 if ((newlen = ftell(file) - lastoff) != 0) { | |
| 923 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | |
| 924 log->logger = &old_logger; | |
| 925 log->time = lasttime; | |
| 926 data = g_new0(struct old_logger_data, 1); | |
| 927 data->offset = lastoff; | |
| 928 data->length = newlen; | |
| 7764 | 929 data->pathref = gaim_stringref_ref(pathref); |
| 7761 | 930 log->logger_data = data; |
| 7613 | 931 list = g_list_append(list, log); |
| 7761 | 932 } |
| 7613 | 933 } |
| 934 | |
| 7764 | 935 gaim_stringref_unref(pathref); |
| 7431 | 936 fclose(file); |
| 937 return list; | |
| 4184 | 938 } |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
939 |
| 8898 | 940 static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account) |
| 8096 | 941 { |
| 942 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name)); | |
| 943 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); | |
| 944 int size; | |
| 945 struct stat st; | |
| 946 | |
| 947 if (stat(pathstr, &st)) | |
| 948 size = 0; | |
| 949 else | |
| 950 size = st.st_size; | |
| 951 | |
| 952 g_free(logfile); | |
| 953 g_free(pathstr); | |
| 954 | |
| 955 return size; | |
| 956 } | |
| 957 | |
| 7616 | 958 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
959 { |
| 7431 | 960 struct old_logger_data *data = log->logger_data; |
| 7764 | 961 FILE *file = fopen(gaim_stringref_value(data->pathref), "rb"); |
| 7431 | 962 char *read = g_malloc(data->length + 1); |
| 963 fseek(file, data->offset, SEEK_SET); | |
| 964 fread(read, data->length, 1, file); | |
| 8370 | 965 fclose(file); |
| 7431 | 966 read[data->length] = '\0'; |
| 7436 | 967 *flags = 0; |
| 968 if(strstr(read, "<BR>")) | |
| 969 *flags |= GAIM_LOG_READ_NO_NEWLINE; | |
| 7431 | 970 return read; |
| 971 } | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
972 |
| 7616 | 973 static int old_logger_size (GaimLog *log) |
| 7556 | 974 { |
| 975 struct old_logger_data *data = log->logger_data; | |
| 7616 | 976 return data ? data->length : 0; |
| 977 } | |
| 978 | |
| 979 static void old_logger_finalize(GaimLog *log) | |
| 980 { | |
| 981 struct old_logger_data *data = log->logger_data; | |
| 7764 | 982 gaim_stringref_unref(data->pathref); |
| 7616 | 983 g_free(data); |
| 7556 | 984 } |
| 985 | |
| 7431 | 986 static GaimLogLogger old_logger = { |
| 987 "old logger", "old", | |
| 7616 | 988 NULL, NULL, |
| 989 old_logger_finalize, | |
| 7431 | 990 old_logger_list, |
| 7616 | 991 old_logger_read, |
| 8096 | 992 old_logger_size, |
| 8573 | 993 old_logger_total_size, |
| 994 NULL | |
| 7431 | 995 }; |
