Mercurial > pidgin
comparison src/log.c @ 13059:1b71ad2eccdb
[gaim-migrate @ 15421]
At work, my home directory and all my logs live on a network share. Talking with someone wtih a lot of log files has gotten incredibly painful with sort-by-log turned on. This keeps us from constantly re-scanning 80 gazillion log files to find out if they're the same size.
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Sat, 28 Jan 2006 05:42:38 +0000 |
| parents | b98a28bf29d9 |
| children | 78fa9502715b |
comparison
equal
deleted
inserted
replaced
| 13058:256abf4dd912 | 13059:1b71ad2eccdb |
|---|---|
| 43 }; | 43 }; |
| 44 static GHashTable *logsize_users = NULL; | 44 static GHashTable *logsize_users = NULL; |
| 45 | 45 |
| 46 static void log_get_log_sets_common(GHashTable *sets); | 46 static void log_get_log_sets_common(GHashTable *sets); |
| 47 | 47 |
| 48 static void html_logger_write(GaimLog *log, GaimMessageFlags type, | 48 static gsize html_logger_write(GaimLog *log, GaimMessageFlags type, |
| 49 const char *from, time_t time, const char *message); | 49 const char *from, time_t time, const char *message); |
| 50 static void html_logger_finalize(GaimLog *log); | 50 static void html_logger_finalize(GaimLog *log); |
| 51 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account); | 51 static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account); |
| 52 static GList *html_logger_list_syslog(GaimAccount *account); | 52 static GList *html_logger_list_syslog(GaimAccount *account); |
| 53 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags); | 53 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags); |
| 57 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags); | 57 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags); |
| 58 static int old_logger_size (GaimLog *log); | 58 static int old_logger_size (GaimLog *log); |
| 59 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets); | 59 static void old_logger_get_log_sets(GaimLogSetCallback cb, GHashTable *sets); |
| 60 static void old_logger_finalize(GaimLog *log); | 60 static void old_logger_finalize(GaimLog *log); |
| 61 | 61 |
| 62 static void txt_logger_write(GaimLog *log, | 62 static gsize txt_logger_write(GaimLog *log, |
| 63 GaimMessageFlags type, | 63 GaimMessageFlags type, |
| 64 const char *from, time_t time, const char *message); | 64 const char *from, time_t time, const char *message); |
| 65 static void txt_logger_finalize(GaimLog *log); | 65 static void txt_logger_finalize(GaimLog *log); |
| 66 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account); | 66 static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account); |
| 67 static GList *txt_logger_list_syslog(GaimAccount *account); | 67 static GList *txt_logger_list_syslog(GaimAccount *account); |
| 98 | 98 |
| 99 void gaim_log_write(GaimLog *log, GaimMessageFlags type, | 99 void gaim_log_write(GaimLog *log, GaimMessageFlags type, |
| 100 const char *from, time_t time, const char *message) | 100 const char *from, time_t time, const char *message) |
| 101 { | 101 { |
| 102 struct _gaim_logsize_user *lu; | 102 struct _gaim_logsize_user *lu; |
| 103 gsize written, total = 0; | |
| 104 gpointer ptrsize; | |
| 103 | 105 |
| 104 g_return_if_fail(log); | 106 g_return_if_fail(log); |
| 105 g_return_if_fail(log->logger); | 107 g_return_if_fail(log->logger); |
| 106 g_return_if_fail(log->logger->write); | 108 g_return_if_fail(log->logger->write); |
| 107 | 109 |
| 108 (log->logger->write)(log, type, from, time, message); | 110 written = (log->logger->write)(log, type, from, time, message); |
| 109 | 111 |
| 110 lu = g_new(struct _gaim_logsize_user, 1); | 112 lu = g_new(struct _gaim_logsize_user, 1); |
| 111 | 113 |
| 112 lu->name = g_strdup(gaim_normalize(log->account, log->name)); | 114 lu->name = g_strdup(gaim_normalize(log->account, log->name)); |
| 113 lu->account = log->account; | 115 lu->account = log->account; |
| 114 g_hash_table_remove(logsize_users, lu); | 116 |
| 117 if(g_hash_table_lookup_extended(logsize_users, lu, NULL, &ptrsize)) { | |
| 118 total = GPOINTER_TO_INT(ptrsize); | |
| 119 total += written; | |
| 120 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(total)); | |
| 121 } | |
| 122 | |
| 115 g_free(lu->name); | 123 g_free(lu->name); |
| 116 g_free(lu); | 124 g_free(lu); |
| 117 | 125 |
| 118 } | 126 } |
| 119 | 127 |
| 906 | 914 |
| 907 /**************************** | 915 /**************************** |
| 908 ** HTML LOGGER ************* | 916 ** HTML LOGGER ************* |
| 909 ****************************/ | 917 ****************************/ |
| 910 | 918 |
| 911 static void html_logger_write(GaimLog *log, GaimMessageFlags type, | 919 static gsize html_logger_write(GaimLog *log, GaimMessageFlags type, |
| 912 const char *from, time_t time, const char *message) | 920 const char *from, time_t time, const char *message) |
| 913 { | 921 { |
| 914 char *msg_fixed; | 922 char *msg_fixed; |
| 915 char *date; | 923 char *date; |
| 916 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); | 924 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
| 917 GaimLogCommonLoggerData *data = log->logger_data; | 925 GaimLogCommonLoggerData *data = log->logger_data; |
| 926 gsize written = 0; | |
| 918 | 927 |
| 919 if(!data) { | 928 if(!data) { |
| 920 char buf[64]; | 929 char buf[64]; |
| 921 const char *prpl = | 930 const char *prpl = |
| 922 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); | 931 GAIM_PLUGIN_PROTOCOL_INFO(plugin)->list_icon(log->account, NULL); |
| 924 | 933 |
| 925 data = log->logger_data; | 934 data = log->logger_data; |
| 926 | 935 |
| 927 /* if we can't write to the file, give up before we hurt ourselves */ | 936 /* if we can't write to the file, give up before we hurt ourselves */ |
| 928 if(!data->file) | 937 if(!data->file) |
| 929 return; | 938 return 0; |
| 930 | 939 |
| 931 strftime(buf, sizeof(buf), "%c", localtime(&log->time)); | 940 strftime(buf, sizeof(buf), "%c", localtime(&log->time)); |
| 932 fprintf(data->file, "<html><head>"); | 941 written += fprintf(data->file, "<html><head>"); |
| 933 fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"); | 942 written += fprintf(data->file, "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"); |
| 934 fprintf(data->file, "<title>"); | 943 written += fprintf(data->file, "<title>"); |
| 935 fprintf(data->file, "Conversation with %s at %s on %s (%s)", | 944 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)", |
| 936 log->name, buf, gaim_account_get_username(log->account), prpl); | 945 log->name, buf, gaim_account_get_username(log->account), prpl); |
| 937 fprintf(data->file, "</title></head><body>"); | 946 written += fprintf(data->file, "</title></head><body>"); |
| 938 fprintf(data->file, | 947 written += fprintf(data->file, |
| 939 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", | 948 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", |
| 940 log->name, buf, gaim_account_get_username(log->account), prpl); | 949 log->name, buf, gaim_account_get_username(log->account), prpl); |
| 941 } | 950 } |
| 942 | 951 |
| 943 /* if we can't write to the file, give up before we hurt ourselves */ | 952 /* if we can't write to the file, give up before we hurt ourselves */ |
| 944 if(!data->file) | 953 if(!data->file) |
| 945 return; | 954 return 0; |
| 946 | 955 |
| 947 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); | 956 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); |
| 948 date = log_get_timestamp(log, time); | 957 date = log_get_timestamp(log, time); |
| 949 | 958 |
| 950 if(log->type == GAIM_LOG_SYSTEM){ | 959 if(log->type == GAIM_LOG_SYSTEM){ |
| 951 fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); | 960 written += fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); |
| 952 } else { | 961 } else { |
| 953 if (type & GAIM_MESSAGE_SYSTEM) | 962 if (type & GAIM_MESSAGE_SYSTEM) |
| 954 fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); | 963 written += fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); |
| 955 else if (type & GAIM_MESSAGE_WHISPER) | 964 else if (type & GAIM_MESSAGE_WHISPER) |
| 956 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", | 965 written += fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", |
| 957 date, from, msg_fixed); | 966 date, from, msg_fixed); |
| 958 else if (type & GAIM_MESSAGE_AUTO_RESP) { | 967 else if (type & GAIM_MESSAGE_AUTO_RESP) { |
| 959 if (type & GAIM_MESSAGE_SEND) | 968 if (type & GAIM_MESSAGE_SEND) |
| 960 fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | 969 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); |
| 961 else if (type & GAIM_MESSAGE_RECV) | 970 else if (type & GAIM_MESSAGE_RECV) |
| 962 fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | 971 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); |
| 963 } else if (type & GAIM_MESSAGE_RECV) { | 972 } else if (type & GAIM_MESSAGE_RECV) { |
| 964 if(gaim_message_meify(msg_fixed, -1)) | 973 if(gaim_message_meify(msg_fixed, -1)) |
| 965 fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", | 974 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
| 966 date, from, msg_fixed); | 975 date, from, msg_fixed); |
| 967 else | 976 else |
| 968 fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", | 977 written += fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
| 969 date, from, msg_fixed); | 978 date, from, msg_fixed); |
| 970 } else if (type & GAIM_MESSAGE_SEND) { | 979 } else if (type & GAIM_MESSAGE_SEND) { |
| 971 if(gaim_message_meify(msg_fixed, -1)) | 980 if(gaim_message_meify(msg_fixed, -1)) |
| 972 fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", | 981 written += fprintf(data->file, "<font color=\"#062585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> %s<br/>\n", |
| 973 date, from, msg_fixed); | 982 date, from, msg_fixed); |
| 974 else | 983 else |
| 975 fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", | 984 written += fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> %s<br/>\n", |
| 976 date, from, msg_fixed); | 985 date, from, msg_fixed); |
| 977 } | 986 } |
| 978 } | 987 } |
| 979 g_free(date); | 988 g_free(date); |
| 980 g_free(msg_fixed); | 989 g_free(msg_fixed); |
| 981 fflush(data->file); | 990 fflush(data->file); |
| 991 | |
| 992 return written; | |
| 982 } | 993 } |
| 983 | 994 |
| 984 static void html_logger_finalize(GaimLog *log) | 995 static void html_logger_finalize(GaimLog *log) |
| 985 { | 996 { |
| 986 GaimLogCommonLoggerData *data = log->logger_data; | 997 GaimLogCommonLoggerData *data = log->logger_data; |
| 1029 | 1040 |
| 1030 /**************************** | 1041 /**************************** |
| 1031 ** PLAIN TEXT LOGGER ******* | 1042 ** PLAIN TEXT LOGGER ******* |
| 1032 ****************************/ | 1043 ****************************/ |
| 1033 | 1044 |
| 1034 static void txt_logger_write(GaimLog *log, | 1045 static gsize txt_logger_write(GaimLog *log, |
| 1035 GaimMessageFlags type, | 1046 GaimMessageFlags type, |
| 1036 const char *from, time_t time, const char *message) | 1047 const char *from, time_t time, const char *message) |
| 1037 { | 1048 { |
| 1038 char *date; | 1049 char *date; |
| 1039 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); | 1050 GaimPlugin *plugin = gaim_find_prpl(gaim_account_get_protocol_id(log->account)); |
| 1040 GaimLogCommonLoggerData *data = log->logger_data; | 1051 GaimLogCommonLoggerData *data = log->logger_data; |
| 1041 char *stripped = NULL; | 1052 char *stripped = NULL; |
| 1053 | |
| 1054 gsize written = 0; | |
| 1042 | 1055 |
| 1043 if (data == NULL) { | 1056 if (data == NULL) { |
| 1044 /* This log is new. We could use the loggers 'new' function, but | 1057 /* This log is new. We could use the loggers 'new' function, but |
| 1045 * creating a new file there would result in empty files in the case | 1058 * creating a new file there would result in empty files in the case |
| 1046 * that you open a convo with someone, but don't say anything. | 1059 * that you open a convo with someone, but don't say anything. |
| 1052 | 1065 |
| 1053 data = log->logger_data; | 1066 data = log->logger_data; |
| 1054 | 1067 |
| 1055 /* if we can't write to the file, give up before we hurt ourselves */ | 1068 /* if we can't write to the file, give up before we hurt ourselves */ |
| 1056 if(!data->file) | 1069 if(!data->file) |
| 1057 return; | 1070 return 0; |
| 1058 | 1071 |
| 1059 strftime(buf, sizeof(buf), "%c", localtime(&log->time)); | 1072 strftime(buf, sizeof(buf), "%c", localtime(&log->time)); |
| 1060 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", | 1073 written += fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
| 1061 log->name, buf, gaim_account_get_username(log->account), prpl); | 1074 log->name, buf, gaim_account_get_username(log->account), prpl); |
| 1062 } | 1075 } |
| 1063 | 1076 |
| 1064 /* if we can't write to the file, give up before we hurt ourselves */ | 1077 /* if we can't write to the file, give up before we hurt ourselves */ |
| 1065 if(!data->file) | 1078 if(!data->file) |
| 1066 return; | 1079 return 0; |
| 1067 | 1080 |
| 1068 stripped = gaim_markup_strip_html(message); | 1081 stripped = gaim_markup_strip_html(message); |
| 1069 date = log_get_timestamp(log, time); | 1082 date = log_get_timestamp(log, time); |
| 1070 | 1083 |
| 1071 if(log->type == GAIM_LOG_SYSTEM){ | 1084 if(log->type == GAIM_LOG_SYSTEM){ |
| 1072 fprintf(data->file, "---- %s @ %s ----\n", stripped, date); | 1085 written += fprintf(data->file, "---- %s @ %s ----\n", stripped, date); |
| 1073 } else { | 1086 } else { |
| 1074 if (type & GAIM_MESSAGE_SEND || | 1087 if (type & GAIM_MESSAGE_SEND || |
| 1075 type & GAIM_MESSAGE_RECV) { | 1088 type & GAIM_MESSAGE_RECV) { |
| 1076 if (type & GAIM_MESSAGE_AUTO_RESP) { | 1089 if (type & GAIM_MESSAGE_AUTO_RESP) { |
| 1077 fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, | 1090 written += fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, |
| 1078 from, stripped); | 1091 from, stripped); |
| 1079 } else { | 1092 } else { |
| 1080 if(gaim_message_meify(stripped, -1)) | 1093 if(gaim_message_meify(stripped, -1)) |
| 1081 fprintf(data->file, "(%s) ***%s %s\n", date, from, | 1094 written += fprintf(data->file, "(%s) ***%s %s\n", date, from, |
| 1082 stripped); | 1095 stripped); |
| 1083 else | 1096 else |
| 1084 fprintf(data->file, "(%s) %s: %s\n", date, from, | 1097 written += fprintf(data->file, "(%s) %s: %s\n", date, from, |
| 1085 stripped); | 1098 stripped); |
| 1086 } | 1099 } |
| 1087 } else if (type & GAIM_MESSAGE_SYSTEM) | 1100 } else if (type & GAIM_MESSAGE_SYSTEM) |
| 1088 fprintf(data->file, "(%s) %s\n", date, stripped); | 1101 written += fprintf(data->file, "(%s) %s\n", date, stripped); |
| 1089 else if (type & GAIM_MESSAGE_NO_LOG) { | 1102 else if (type & GAIM_MESSAGE_NO_LOG) { |
| 1090 /* This shouldn't happen */ | 1103 /* This shouldn't happen */ |
| 1091 g_free(stripped); | 1104 g_free(stripped); |
| 1092 return; | 1105 return written; |
| 1093 } else if (type & GAIM_MESSAGE_WHISPER) | 1106 } else if (type & GAIM_MESSAGE_WHISPER) |
| 1094 fprintf(data->file, "(%s) *%s* %s", date, from, stripped); | 1107 written += fprintf(data->file, "(%s) *%s* %s", date, from, stripped); |
| 1095 else | 1108 else |
| 1096 fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", | 1109 written += fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", |
| 1097 from ? ":" : "", stripped); | 1110 from ? ":" : "", stripped); |
| 1098 } | 1111 } |
| 1099 g_free(date); | 1112 g_free(date); |
| 1100 g_free(stripped); | 1113 g_free(stripped); |
| 1101 fflush(data->file); | 1114 fflush(data->file); |
| 1115 | |
| 1116 return written; | |
| 1102 } | 1117 } |
| 1103 | 1118 |
| 1104 static void txt_logger_finalize(GaimLog *log) | 1119 static void txt_logger_finalize(GaimLog *log) |
| 1105 { | 1120 { |
| 1106 GaimLogCommonLoggerData *data = log->logger_data; | 1121 GaimLogCommonLoggerData *data = log->logger_data; |
