Mercurial > pidgin
comparison src/log.c @ 7616:a4acf41898c1
[gaim-migrate @ 8240]
wouldn't it be cool if logging just worked? If it didn't leak, and didn't
crash, and sort-by-log-size worked as an added bonus?
i should have gotten a bounty declared on this first ;-)
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 23 Nov 2003 22:55:41 +0000 |
parents | 62d11301b8a6 |
children | 53e38b1ce00a |
comparison
equal
deleted
inserted
replaced
7615:310013ee693e | 7616:a4acf41898c1 |
---|---|
79 gaim_str_strip_cr(ret); | 79 gaim_str_strip_cr(ret); |
80 return ret; | 80 return ret; |
81 } | 81 } |
82 return (_("<b><font color=\"red\">The logger has no read function</font></b>")); | 82 return (_("<b><font color=\"red\">The logger has no read function</font></b>")); |
83 } | 83 } |
84 | 84 |
85 int gaim_log_get_size(GaimLog *log) | 85 int gaim_log_get_size(GaimLog *log) |
86 { | 86 { |
87 g_return_val_if_fail(log && log->logger, 0); | 87 g_return_val_if_fail(log && log->logger, 0); |
88 if (log->logger->size) | 88 if (log->logger->size) |
89 return log->logger->size(log); | 89 return log->logger->size(log); |
92 | 92 |
93 int gaim_log_get_total_size(const char *name, GaimAccount *account) | 93 int gaim_log_get_total_size(const char *name, GaimAccount *account) |
94 { | 94 { |
95 GList *logs = gaim_log_get_logs(name, account); | 95 GList *logs = gaim_log_get_logs(name, account); |
96 int size = 0; | 96 int size = 0; |
97 | 97 |
98 | |
98 while (logs) { | 99 while (logs) { |
99 GList *logs2 = logs->next; | 100 GList *logs2 = logs->next; |
100 GaimLog *log = (GaimLog*)(logs->data); | 101 GaimLog *log = (GaimLog*)(logs->data); |
101 size += gaim_log_get_size(log); | 102 size += gaim_log_get_size(log); |
102 g_free(log->name); | 103 g_free(log->name); |
103 g_free(log); | 104 g_free(log); |
104 g_list_free_1(logs); | 105 g_list_free_1(logs); |
105 logs = logs2; | 106 logs = logs2; |
106 } | 107 } |
108 | |
107 return size; | 109 return size; |
108 } | 110 } |
109 | 111 |
110 /**************************************************************************** | 112 /**************************************************************************** |
111 * LOGGER FUNCTIONS ********************************************************* | 113 * LOGGER FUNCTIONS ********************************************************* |
233 | 235 |
234 /**************************************************************************** | 236 /**************************************************************************** |
235 * LOGGERS ****************************************************************** | 237 * LOGGERS ****************************************************************** |
236 ****************************************************************************/ | 238 ****************************************************************************/ |
237 | 239 |
240 struct generic_logger_data { | |
241 char *path; | |
242 FILE *file; | |
243 }; | |
244 | |
238 static GList *log_lister_common(const char *screenname, GaimAccount *account, const char *ext, GaimLogLogger *logger) | 245 static GList *log_lister_common(const char *screenname, GaimAccount *account, const char *ext, GaimLogLogger *logger) |
239 { | 246 { |
240 GDir *dir; | 247 GDir *dir; |
241 GList *list = NULL; | 248 GList *list = NULL; |
242 const char *filename, *tmp; | 249 const char *filename, *tmp; |
256 tmp = filename + (strlen(filename) - strlen(ext)); | 263 tmp = filename + (strlen(filename) - strlen(ext)); |
257 if (tmp > filename && !strcmp(tmp, ext)) { | 264 if (tmp > filename && !strcmp(tmp, ext)) { |
258 const char *l = filename; | 265 const char *l = filename; |
259 struct tm time; | 266 struct tm time; |
260 GaimLog *log; | 267 GaimLog *log; |
268 struct generic_logger_data *data; | |
261 char d[5]; | 269 char d[5]; |
262 | 270 |
263 strncpy(d, l, 4); | 271 strncpy(d, l, 4); |
264 d[4] = '\0'; | 272 d[4] = '\0'; |
265 time.tm_year = atoi(d) - 1900; | 273 time.tm_year = atoi(d) - 1900; |
285 strncpy(d, l, 2); | 293 strncpy(d, l, 2); |
286 time.tm_sec = atoi(d); | 294 time.tm_sec = atoi(d); |
287 l = l + 2; | 295 l = l + 2; |
288 log = gaim_log_new(GAIM_LOG_IM, screenname, account, mktime(&time)); | 296 log = gaim_log_new(GAIM_LOG_IM, screenname, account, mktime(&time)); |
289 log->logger = logger; | 297 log->logger = logger; |
290 log->logger_data = g_build_filename(path, filename, NULL); | 298 log->logger_data = data = g_new0(struct generic_logger_data, 1); |
299 data->path = g_build_filename(path, filename, NULL); | |
291 list = g_list_append(list, log); | 300 list = g_list_append(list, log); |
292 } | 301 } |
293 } | 302 } |
294 g_dir_close(dir); | 303 g_dir_close(dir); |
295 g_free(path); | 304 g_free(path); |
296 return list; | 305 return list; |
297 } | 306 } |
298 | 307 |
299 /* Only to be used with logs listed from log_lister_common */ | 308 /* Only to be used with logs listed from log_lister_common */ |
300 int log_sizer_common(GaimLog *log) | 309 int log_sizer_common(GaimLog *log) |
301 { | 310 { |
302 struct stat st; | 311 struct stat st; |
303 | 312 struct generic_logger_data *data = log->logger_data; |
304 if (stat((char*)(log->logger_data), &st)) | 313 |
314 if (!data->path || stat(data->path, &st)) | |
305 st.st_size = 0; | 315 st.st_size = 0; |
306 | 316 |
307 return st.st_size; | 317 return st.st_size; |
308 } | 318 } |
309 | 319 |
411 static void html_logger_write(GaimLog *log, GaimMessageFlags type, | 421 static void html_logger_write(GaimLog *log, GaimMessageFlags type, |
412 const char *from, time_t time, const char *message) | 422 const char *from, time_t time, const char *message) |
413 { | 423 { |
414 GaimConnection *gc = gaim_account_get_connection(log->account); | 424 GaimConnection *gc = gaim_account_get_connection(log->account); |
415 char date[64]; | 425 char date[64]; |
416 if(!log->logger_data) { | 426 struct generic_logger_data *data = log->logger_data; |
427 if(data) { | |
417 /* This log is new */ | 428 /* This log is new */ |
418 char *ud = gaim_user_dir(); | 429 char *ud = gaim_user_dir(); |
419 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); | 430 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); |
420 char *chat; | 431 char *chat; |
421 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO | 432 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO |
437 g_free(guy); | 448 g_free(guy); |
438 | 449 |
439 filename = g_build_filename(dir, date, NULL); | 450 filename = g_build_filename(dir, date, NULL); |
440 g_free(dir); | 451 g_free(dir); |
441 | 452 |
442 log->logger_data = fopen(filename, "a"); | 453 log->logger_data = data = g_new0(struct generic_logger_data, 1); |
443 if (!log->logger_data) { | 454 |
455 data->file = fopen(filename, "a"); | |
456 if (!data->file) { | |
444 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | 457 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); |
445 g_free(filename); | 458 g_free(filename); |
446 return; | 459 return; |
447 } | 460 } |
448 g_free(filename); | 461 g_free(filename); |
449 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); | 462 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
450 fprintf(log->logger_data, "<html><head><title>"); | 463 fprintf(data->file, "<html><head><title>"); |
451 fprintf(log->logger_data, "Conversation with %s at %s on %s (%s)", | 464 fprintf(data->file, "Conversation with %s at %s on %s (%s)", |
452 log->name, date, gaim_account_get_username(log->account), prpl); | 465 log->name, date, gaim_account_get_username(log->account), prpl); |
453 fprintf(log->logger_data, "</title></head><body>"); | 466 fprintf(data->file, "</title></head><body>"); |
454 fprintf(log->logger_data, | 467 fprintf(data->file, |
455 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", | 468 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", |
456 log->name, date, gaim_account_get_username(log->account), prpl); | 469 log->name, date, gaim_account_get_username(log->account), prpl); |
457 } | 470 } |
458 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | 471 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); |
459 if (type & GAIM_MESSAGE_SYSTEM) | 472 if (type & GAIM_MESSAGE_SYSTEM) |
460 fprintf(log->logger_data, "(%s)<b> %s</b><br/>\n", date, message); | 473 fprintf(data->file, "(%s)<b> %s</b><br/>\n", date, message); |
461 else if (type & GAIM_MESSAGE_WHISPER) | 474 else if (type & GAIM_MESSAGE_WHISPER) |
462 fprintf(log->logger_data, "<font color=\"#6C2585\">(%s)<b> %s:</b></font> %s<br/>\n", | 475 fprintf(data->file, "<font color=\"#6C2585\">(%s)<b> %s:</b></font> %s<br/>\n", |
463 date, from, message); | 476 date, from, message); |
464 else if (type & GAIM_MESSAGE_AUTO_RESP) { | 477 else if (type & GAIM_MESSAGE_AUTO_RESP) { |
465 if (type & GAIM_MESSAGE_SEND) | 478 if (type & GAIM_MESSAGE_SEND) |
466 fprintf(log->logger_data, _("<font color=\"#16569E\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message); | 479 fprintf(data->file, _("<font color=\"#16569E\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message); |
467 else if (type & GAIM_MESSAGE_RECV) | 480 else if (type & GAIM_MESSAGE_RECV) |
468 fprintf(log->logger_data, _("<font color=\"#A82F2F\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message); | 481 fprintf(data->file, _("<font color=\"#A82F2F\">(%s) <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, message); |
469 } else if (type & GAIM_MESSAGE_RECV) { | 482 } else if (type & GAIM_MESSAGE_RECV) { |
470 char *msg = g_strdup(message); | 483 char *msg = g_strdup(message); |
471 if(gaim_message_meify(msg, -1)) | 484 if(gaim_message_meify(msg, -1)) |
472 fprintf(log->logger_data, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", | 485 fprintf(data->file, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", |
473 date, from, gc->prpl->info->name, msg); | 486 date, from, gc->prpl->info->name, msg); |
474 else | 487 else |
475 fprintf(log->logger_data, "<font color=\"#A82F2F\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", | 488 fprintf(data->file, "<font color=\"#A82F2F\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", |
476 date, from, gc->prpl->info->name, msg); | 489 date, from, gc->prpl->info->name, msg); |
477 g_free(msg); | 490 g_free(msg); |
478 } else if (type & GAIM_MESSAGE_SEND) { | 491 } else if (type & GAIM_MESSAGE_SEND) { |
479 char *msg = g_strdup(message); | 492 char *msg = g_strdup(message); |
480 if(gaim_message_meify(msg, -1)) | 493 if(gaim_message_meify(msg, -1)) |
481 fprintf(log->logger_data, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", | 494 fprintf(data->file, "<font color=\"#6C2585\">(%s) <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", |
482 date, from, gc->prpl->info->name, msg); | 495 date, from, gc->prpl->info->name, msg); |
483 else | 496 else |
484 fprintf(log->logger_data, "<font color=\"#16569E\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", | 497 fprintf(data->file, "<font color=\"#16569E\">(%s) <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", |
485 date, from, gc->prpl->info->name, msg); | 498 date, from, gc->prpl->info->name, msg); |
486 g_free(msg); | 499 g_free(msg); |
487 } | 500 } |
488 fflush(log->logger_data); | 501 fflush(data->file); |
489 } | 502 } |
490 | 503 |
491 static void html_logger_finalize(GaimLog *log) | 504 static void html_logger_finalize(GaimLog *log) |
492 { | 505 { |
493 if (log->logger_data) { | 506 struct generic_logger_data *data = log->logger_data; |
494 fprintf(log->logger_data, "</body></html>"); | 507 if (data) { |
495 fclose(log->logger_data); | 508 if(data->file) { |
509 fprintf(data->file, "</body></html>"); | |
510 fclose(data->file); | |
511 } | |
512 g_free(data->path); | |
496 } | 513 } |
497 } | 514 } |
498 | 515 |
499 static GList *html_logger_list(const char *sn, GaimAccount *account) | 516 static GList *html_logger_list(const char *sn, GaimAccount *account) |
500 { | 517 { |
502 } | 519 } |
503 | 520 |
504 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) | 521 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
505 { | 522 { |
506 char *read, *minus_header; | 523 char *read, *minus_header; |
524 struct generic_logger_data *data = log->logger_data; | |
507 *flags = GAIM_LOG_READ_NO_NEWLINE; | 525 *flags = GAIM_LOG_READ_NO_NEWLINE; |
508 if (!log->logger_data) | 526 if (!data || !data->path) |
509 return g_strdup(_("<font color=\"red\"><b>log->logger_data was NULL!</b></font>")); | 527 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); |
510 if (g_file_get_contents((char *)log->logger_data, &read, NULL, NULL)) { | 528 if (g_file_get_contents(data->path, &read, NULL, NULL)) { |
511 minus_header = strchr(read, '\n'); | 529 minus_header = strchr(read, '\n'); |
512 if (!minus_header) | 530 if (!minus_header) |
513 minus_header = g_strdup(read); | 531 minus_header = g_strdup(read); |
514 else | 532 else |
515 minus_header = g_strdup(minus_header + 1); | 533 minus_header = g_strdup(minus_header + 1); |
540 GaimMessageFlags type, | 558 GaimMessageFlags type, |
541 const char *from, time_t time, const char *message) | 559 const char *from, time_t time, const char *message) |
542 { | 560 { |
543 char date[64]; | 561 char date[64]; |
544 char *stripped = NULL; | 562 char *stripped = NULL; |
545 if (!log->logger_data) { | 563 struct generic_logger_data *data = log->logger_data; |
564 if (!data) { | |
546 /* This log is new. We could use the loggers 'new' function, but | 565 /* This log is new. We could use the loggers 'new' function, but |
547 * creating a new file there would result in empty files in the case | 566 * creating a new file there would result in empty files in the case |
548 * that you open a convo with someone, but don't say anything. | 567 * that you open a convo with someone, but don't say anything. |
549 */ | 568 */ |
550 char *ud = gaim_user_dir(); | 569 char *ud = gaim_user_dir(); |
568 g_free(guy); | 587 g_free(guy); |
569 | 588 |
570 filename = g_build_filename(dir, date, NULL); | 589 filename = g_build_filename(dir, date, NULL); |
571 g_free(dir); | 590 g_free(dir); |
572 | 591 |
573 log->logger_data = fopen(filename, "a"); | 592 log->logger_data = data = g_new0(struct generic_logger_data, 1); |
574 if (!log->logger_data) { | 593 |
594 data->file = fopen(filename, "a"); | |
595 if (!data->file) { | |
575 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | 596 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); |
576 g_free(filename); | 597 g_free(filename); |
577 return; | 598 return; |
578 } | 599 } |
579 g_free(filename); | 600 g_free(filename); |
580 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); | 601 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
581 fprintf(log->logger_data, "Conversation with %s at %s on %s (%s)\n", | 602 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
582 log->name, date, gaim_account_get_username(log->account), prpl); | 603 log->name, date, gaim_account_get_username(log->account), prpl); |
583 } | 604 } |
584 | 605 |
585 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | 606 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); |
586 stripped = gaim_markup_strip_html(message); | 607 stripped = gaim_markup_strip_html(message); |
587 if (type & GAIM_MESSAGE_SEND || | 608 if (type & GAIM_MESSAGE_SEND || |
588 type & GAIM_MESSAGE_RECV) { | 609 type & GAIM_MESSAGE_RECV) { |
589 if (type & GAIM_MESSAGE_AUTO_RESP) { | 610 if (type & GAIM_MESSAGE_AUTO_RESP) { |
590 fprintf(log->logger_data, _("(%s) %s <AUTO-REPLY>: %s\n"), date, from, stripped); | 611 fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, from, stripped); |
591 } else { | 612 } else { |
592 if(gaim_message_meify(stripped, -1)) | 613 if(gaim_message_meify(stripped, -1)) |
593 fprintf(log->logger_data, "(%s) ***%s %s\n", date, from, | 614 fprintf(data->file, "(%s) ***%s %s\n", date, from, |
594 stripped); | 615 stripped); |
595 else | 616 else |
596 fprintf(log->logger_data, "(%s) %s: %s\n", date, from, | 617 fprintf(data->file, "(%s) %s: %s\n", date, from, |
597 stripped); | 618 stripped); |
598 } | 619 } |
599 } else if (type & GAIM_MESSAGE_SYSTEM) | 620 } else if (type & GAIM_MESSAGE_SYSTEM) |
600 fprintf(log->logger_data, "(%s) %s\n", date, stripped); | 621 fprintf(data->file, "(%s) %s\n", date, stripped); |
601 else if (type & GAIM_MESSAGE_NO_LOG) { | 622 else if (type & GAIM_MESSAGE_NO_LOG) { |
602 /* This shouldn't happen */ | 623 /* This shouldn't happen */ |
603 g_free(stripped); | 624 g_free(stripped); |
604 return; | 625 return; |
605 } else if (type & GAIM_MESSAGE_WHISPER) | 626 } else if (type & GAIM_MESSAGE_WHISPER) |
606 fprintf(log->logger_data, "(%s) *%s* %s", date, from, stripped); | 627 fprintf(data->file, "(%s) *%s* %s", date, from, stripped); |
607 else | 628 else |
608 fprintf(log->logger_data, "(%s) %s%s %s\n", date, from ? from : "", from ? ":" : "", stripped); | 629 fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", from ? ":" : "", stripped); |
609 | 630 |
610 fflush(log->logger_data); | 631 fflush(data->file); |
611 g_free(stripped); | 632 g_free(stripped); |
612 } | 633 } |
613 | 634 |
614 static void txt_logger_finalize(GaimLog *log) | 635 static void txt_logger_finalize(GaimLog *log) |
615 { | 636 { |
616 if (log->logger_data) | 637 struct generic_logger_data *data = log->logger_data; |
617 fclose(log->logger_data); | 638 if (data) { |
639 if(data->file) | |
640 fclose(data->file); | |
641 if(data->path) | |
642 g_free(data->path); | |
643 } | |
618 } | 644 } |
619 | 645 |
620 static GList *txt_logger_list(const char *sn, GaimAccount *account) | 646 static GList *txt_logger_list(const char *sn, GaimAccount *account) |
621 { | 647 { |
622 return log_lister_common(sn, account, ".txt", &txt_logger); | 648 return log_lister_common(sn, account, ".txt", &txt_logger); |
623 } | 649 } |
624 | 650 |
625 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) | 651 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
626 { | 652 { |
627 char *read, *minus_header; | 653 char *read, *minus_header; |
654 struct generic_logger_data *data = log->logger_data; | |
628 *flags = 0; | 655 *flags = 0; |
629 if (!log->logger_data) | 656 if (!data || !data->path) |
630 return g_strdup(_("<font color=\"red\"><b>log->logger_data was NULL!</b></font>")); | 657 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); |
631 if (g_file_get_contents((char *)log->logger_data, &read, NULL, NULL)) { | 658 if (g_file_get_contents(data->path, &read, NULL, NULL)) { |
632 minus_header = strchr(read, '\n'); | 659 minus_header = strchr(read, '\n'); |
633 if (!minus_header) | 660 if (!minus_header) |
634 minus_header = g_strdup(read); | 661 minus_header = g_strdup(read); |
635 else | 662 else |
636 minus_header = g_strdup(minus_header + 1); | 663 minus_header = g_strdup(minus_header + 1); |
726 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | 753 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); |
727 log->logger = &old_logger; | 754 log->logger = &old_logger; |
728 | 755 |
729 data = g_new0(struct old_logger_data, 1); | 756 data = g_new0(struct old_logger_data, 1); |
730 data->offset = offset; | 757 data->offset = offset; |
731 data->path = path; | 758 data->path = g_strdup(path); |
732 log->logger_data = data; | 759 log->logger_data = data; |
733 | 760 |
734 | 761 |
735 g_snprintf(convostart, length, "%s", temp); | 762 g_snprintf(convostart, length, "%s", temp); |
736 sscanf(convostart, "%*s %s %s %d:%d:%d %s", | 763 sscanf(convostart, "%*s %s %s %d:%d:%d %s", |
739 g_date_set_parse(&gdate, date); | 766 g_date_set_parse(&gdate, date); |
740 tm.tm_mday = g_date_get_day(&gdate); | 767 tm.tm_mday = g_date_get_day(&gdate); |
741 tm.tm_mon = g_date_get_month(&gdate) - 1; | 768 tm.tm_mon = g_date_get_month(&gdate) - 1; |
742 tm.tm_year = g_date_get_year(&gdate) - 1900; | 769 tm.tm_year = g_date_get_year(&gdate) - 1900; |
743 log->time = mktime(&tm); | 770 log->time = mktime(&tm); |
771 g_free(date); | |
744 | 772 |
745 } | 773 } |
746 } | 774 } |
747 | 775 |
748 if (data) { | 776 if (data) { |
751 list = g_list_append(list, log); | 779 list = g_list_append(list, log); |
752 else | 780 else |
753 gaim_log_free(log); | 781 gaim_log_free(log); |
754 } | 782 } |
755 | 783 |
784 g_free(path); | |
756 fclose(file); | 785 fclose(file); |
757 return list; | 786 return list; |
758 } | 787 } |
759 | 788 |
760 char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) | 789 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
761 { | 790 { |
762 struct old_logger_data *data = log->logger_data; | 791 struct old_logger_data *data = log->logger_data; |
763 FILE *file = fopen(data->path, "rb"); | 792 FILE *file = fopen(data->path, "rb"); |
764 char *read = g_malloc(data->length + 1); | 793 char *read = g_malloc(data->length + 1); |
765 fseek(file, data->offset, SEEK_SET); | 794 fseek(file, data->offset, SEEK_SET); |
769 if(strstr(read, "<BR>")) | 798 if(strstr(read, "<BR>")) |
770 *flags |= GAIM_LOG_READ_NO_NEWLINE; | 799 *flags |= GAIM_LOG_READ_NO_NEWLINE; |
771 return read; | 800 return read; |
772 } | 801 } |
773 | 802 |
774 int old_logger_size (GaimLog *log) | 803 static int old_logger_size (GaimLog *log) |
775 { | 804 { |
776 struct old_logger_data *data = log->logger_data; | 805 struct old_logger_data *data = log->logger_data; |
777 return data->length; | 806 return data ? data->length : 0; |
807 } | |
808 | |
809 static void old_logger_finalize(GaimLog *log) | |
810 { | |
811 struct old_logger_data *data = log->logger_data; | |
812 g_free(data->path); | |
813 g_free(data); | |
778 } | 814 } |
779 | 815 |
780 static GaimLogLogger old_logger = { | 816 static GaimLogLogger old_logger = { |
781 "old logger", "old", | 817 "old logger", "old", |
782 NULL, NULL, NULL, | 818 NULL, NULL, |
819 old_logger_finalize, | |
783 old_logger_list, | 820 old_logger_list, |
784 old_logger_read | 821 old_logger_read, |
822 old_logger_size | |
785 }; | 823 }; |