comparison src/log.c @ 9763:b85df3f44350

[gaim-migrate @ 10631] "Can someone test this patch, diff'ed with 0.81 (anoncvs is down, as usual). http://javabsp.org/software/gaim/syslog_fd_leak.diff This keeps the double .system 0 length files from being created everytime you list the system log, which for some reason aren't closed (although reading from the code, they should be). Anyhow, since they are not created anymore, they won't waste any fd's. Another change that I've made, previously gaim is logging chats to logs/<prpl>/<my sn>.chat/<chatroom name>/<date-time>, now it's logging to logs/<prpl>/<my sn>/<chatroom name>.chat>/<date-time>. I think this makes more sense. Oh, and gaim_normalize is not meant to be called a second time while expecting the value of the first call to remain what it should be." --Ka-Hing Cheung committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 16 Aug 2004 03:24:00 +0000
parents 70ff55c0939b
children 34b468bdc1c5
comparison
equal deleted inserted replaced
9762:3f97624e7753 9763:b85df3f44350
330 struct generic_logger_data { 330 struct generic_logger_data {
331 char *path; 331 char *path;
332 FILE *file; 332 FILE *file;
333 }; 333 };
334 334
335 static void log_writer_common(GaimLog *log, GaimMessageFlags type,
336 const char *prpl, time_t time,
337 const char *ext)
338 {
339 char date[64];
340 struct generic_logger_data *data = log->logger_data;
341
342 if(!data) {
343 /* This log is new */
344 char *ud = gaim_user_dir();
345 char *acct_name = g_strdup(gaim_normalize(log->account,
346 gaim_account_get_username(log->account)));
347 char *target;
348 char *dir;
349 char *filename, *path;
350
351 printf("%s\n", acct_name);
352
353 if (log->type == GAIM_LOG_CHAT) {
354 target = g_strdup_printf("%s.chat", gaim_normalize(log->account,
355 log->name));
356 } else if(log->type == GAIM_LOG_SYSTEM) {
357 target = g_strdup(".system");
358 } else {
359 target = g_strdup(gaim_normalize(log->account, log->name));
360 }
361
362 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S", localtime(&log->time));
363
364 dir = g_build_filename(ud, "logs",
365 prpl, acct_name, target, NULL);
366 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
367 g_free(target);
368 g_free(acct_name);
369
370 filename = g_strdup_printf("%s%s", date, ext ? ext : "");
371
372 path = g_build_filename(dir, filename, NULL);
373 g_free(dir);
374 g_free(filename);
375
376 log->logger_data = data = g_new0(struct generic_logger_data, 1);
377
378 data->file = fopen(path, "a");
379 if (!data->file) {
380 gaim_debug(GAIM_DEBUG_ERROR, "log",
381 "Could not create log file %s\n", filename);
382 g_free(path);
383 return;
384 }
385 g_free(path);
386 }
387 }
388
335 static GList *log_lister_common(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger) 389 static GList *log_lister_common(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger)
336 { 390 {
337 GDir *dir; 391 GDir *dir;
338 GList *list = NULL; 392 GList *list = NULL;
339 const char *filename; 393 const char *filename;
503 ****************************/ 557 ****************************/
504 558
505 static void html_logger_write(GaimLog *log, GaimMessageFlags type, 559 static void html_logger_write(GaimLog *log, GaimMessageFlags type,
506 const char *from, time_t time, const char *message) 560 const char *from, time_t time, const char *message)
507 { 561 {
562 char *msg_fixed;
508 char date[64]; 563 char date[64];
509 char *msg_fixed;
510 struct generic_logger_data *data = log->logger_data;
511 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); 564 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account));
512 const char *prpl_name = plugin->info->name; 565 const char *prpl_name = plugin->info->name;
566 struct generic_logger_data *data = log->logger_data;
513 567
514 if(!data) { 568 if(!data) {
515 /* This log is new */ 569 const char *prpl =
516 char *ud = gaim_user_dir(); 570 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
517 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); 571 log_writer_common(log, type, prpl, time, ".html");
518 char *chat; 572
519 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); 573 data = log->logger_data;
520 char *dir; 574
521 char *filename; 575 /* if we can't write to the file, give up before we hurt ourselves */
522 576 if(!data->file)
523 if (log->type == GAIM_LOG_CHAT) {
524 chat = g_strdup_printf("%s.chat", guy);
525 g_free(guy);
526 guy = chat;
527 }
528
529 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.html", localtime(&log->time));
530
531 dir = g_build_filename(ud, "logs",
532 prpl, guy, gaim_normalize(log->account, log->name), NULL);
533 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
534 g_free(guy);
535
536 filename = g_build_filename(dir, date, NULL);
537 g_free(dir);
538
539 log->logger_data = data = g_new0(struct generic_logger_data, 1);
540
541 data->file = fopen(filename, "a");
542 if (!data->file) {
543 gaim_debug(GAIM_DEBUG_ERROR, "log",
544 "Could not create log file %s\n", filename);
545 g_free(filename);
546 return; 577 return;
547 } 578
548 g_free(filename);
549 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); 579 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time));
550 fprintf(data->file, "<html><head><title>"); 580 fprintf(data->file, "<html><head><title>");
551 fprintf(data->file, "Conversation with %s at %s on %s (%s)", 581 fprintf(data->file, "Conversation with %s at %s on %s (%s)",
552 log->name, date, gaim_account_get_username(log->account), prpl); 582 log->name, date, gaim_account_get_username(log->account), prpl);
553 fprintf(data->file, "</title></head><body>"); 583 fprintf(data->file, "</title></head><body>");
554 fprintf(data->file, 584 fprintf(data->file,
555 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", 585 "<h3>Conversation with %s at %s on %s (%s)</h3>\n",
556 log->name, date, gaim_account_get_username(log->account), prpl); 586 log->name, date, gaim_account_get_username(log->account), prpl);
557 } 587
558 588 }
559 /* if we can't write to the file, give up before we hurt ourselves */
560 if(!data->file)
561 return;
562 589
563 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); 590 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL);
564 591
565 if(log->type == GAIM_LOG_SYSTEM){ 592 if(log->type == GAIM_LOG_SYSTEM){
566 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time)); 593 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&time));
640 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); 667 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path);
641 } 668 }
642 669
643 static void html_logger_create(GaimLog *log) 670 static void html_logger_create(GaimLog *log)
644 { 671 {
645 if(log->type == GAIM_LOG_SYSTEM){
646 char date[64];
647 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
648 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL);
649 char *ud = gaim_user_dir();
650 char *dir = g_build_filename(ud, "logs", prpl, log->name, ".system", NULL);
651 char *filename;
652 struct generic_logger_data *data;
653
654 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
655 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.html", localtime(&log->time));
656 filename = g_build_filename(dir, date, NULL);
657 g_free(dir);
658
659 log->logger_data = data = g_new0(struct generic_logger_data, 1);
660
661 data->file = fopen(filename, "a");
662 if (!data->file) {
663 gaim_debug(GAIM_DEBUG_ERROR, "log",
664 "Could not create log file %s\n", filename);
665 g_free(filename);
666 return;
667 }
668 fprintf(data->file, "<html><head><title>");
669 fprintf(data->file, "System Log for %s (%s)",
670 gaim_account_get_username(log->account), prpl);
671 fprintf(data->file, "</title></head><body>");
672 g_free(filename);
673 }
674 } 672 }
675 673
676 static GaimLogLogger html_logger = { 674 static GaimLogLogger html_logger = {
677 N_("HTML"), "html", 675 N_("HTML"), "html",
678 html_logger_create, 676 html_logger_create,
695 static void txt_logger_write(GaimLog *log, 693 static void txt_logger_write(GaimLog *log,
696 GaimMessageFlags type, 694 GaimMessageFlags type,
697 const char *from, time_t time, const char *message) 695 const char *from, time_t time, const char *message)
698 { 696 {
699 char date[64]; 697 char date[64];
698 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account));
699 struct generic_logger_data *data = log->logger_data;
700 char *stripped = NULL; 700 char *stripped = NULL;
701 struct generic_logger_data *data = log->logger_data; 701
702 if (!data) { 702 if(!data) {
703 /* This log is new. We could use the loggers 'new' function, but 703 /* This log is new. We could use the loggers 'new' function, but
704 * creating a new file there would result in empty files in the case 704 * creating a new file there would result in empty files in the case
705 * that you open a convo with someone, but don't say anything. 705 * that you open a convo with someone, but don't say anything.
706 *
707 * The log is also not a system log. Because if it is, data would
708 * be created in txt_logger_create
709 */ 706 */
710 char *ud = gaim_user_dir(); 707 const char *prpl =
711 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); 708 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL);
712 char *chat; 709 log_writer_common(log, type, prpl, time, ".txt");
713 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO 710
714 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL); 711 data = log->logger_data;
715 char *dir; 712
716 char *filename; 713 /* if we can't write to the file, give up before we hurt ourselves */
717 714 if(!data->file)
718 if (log->type == GAIM_LOG_CHAT) {
719 chat = g_strdup_printf("%s.chat", guy);
720 g_free(guy);
721 guy = chat;
722 }
723
724 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.txt", localtime(&log->time));
725
726 dir = g_build_filename(ud, "logs",
727 prpl, guy, gaim_normalize(log->account, log->name), NULL);
728 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
729 g_free(guy);
730
731 filename = g_build_filename(dir, date, NULL);
732 g_free(dir);
733
734 log->logger_data = data = g_new0(struct generic_logger_data, 1);
735
736 data->file = fopen(filename, "a");
737 if (!data->file) {
738 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename);
739 g_free(filename);
740 return; 715 return;
741 } 716
742 g_free(filename);
743 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); 717 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time));
744 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", 718 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n",
745 log->name, date, gaim_account_get_username(log->account), prpl); 719 log->name, date, gaim_account_get_username(log->account), prpl);
746 } 720 }
747 721
829 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); 803 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path);
830 } 804 }
831 805
832 static void txt_logger_create(GaimLog *log) 806 static void txt_logger_create(GaimLog *log)
833 { 807 {
834 if(log->type == GAIM_LOG_SYSTEM){
835 char date[64];
836 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO
837 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL);
838 char *ud = gaim_user_dir();
839 char *dir = g_build_filename(ud, "logs", prpl, log->name, ".system", NULL);
840 char *filename;
841 struct generic_logger_data *data;
842
843 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
844 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.txt", localtime(&log->time));
845 filename = g_build_filename(dir, date, NULL);
846 g_free(dir);
847
848 log->logger_data = data = g_new0(struct generic_logger_data, 1);
849
850 data->file = fopen(filename, "a");
851 if (!data->file) {
852 gaim_debug(GAIM_DEBUG_ERROR, "log",
853 "Could not create log file %s\n", filename);
854 g_free(filename);
855 return;
856 }
857 g_free(filename);
858 }
859 } 808 }
860 809
861 static GaimLogLogger txt_logger = { 810 static GaimLogLogger txt_logger = {
862 N_("Plain text"), "txt", 811 N_("Plain text"), "txt",
863 txt_logger_create, 812 txt_logger_create,