| 35 |
35 |
| 36 static GaimLogLogger html_logger; |
36 static GaimLogLogger html_logger; |
| 37 static GaimLogLogger txt_logger; |
37 static GaimLogLogger txt_logger; |
| 38 static GaimLogLogger old_logger; |
38 static GaimLogLogger old_logger; |
| 39 |
39 |
| |
40 struct _gaim_logsize_user { |
| |
41 char *name; |
| |
42 GaimAccount *account; |
| |
43 }; |
| |
44 static GHashTable *logsize_users = NULL; |
| |
45 |
| |
46 |
| 40 /************************************************************************** |
47 /************************************************************************** |
| 41 * PUBLIC LOGGING FUNCTIONS *********************************************** |
48 * PUBLIC LOGGING FUNCTIONS *********************************************** |
| 42 **************************************************************************/ |
49 **************************************************************************/ |
| 43 |
50 |
| 44 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time) |
51 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time) |
| 45 { |
52 { |
| 46 GaimLog *log = g_new0(GaimLog, 1); |
53 GaimLog *log = g_new0(GaimLog, 1); |
| 47 log->name = g_strdup(name); |
54 log->name = g_strdup(gaim_normalize(account, name)); |
| 48 log->account = account; |
55 log->account = account; |
| 49 log->time = time; |
56 log->time = time; |
| 50 log->type = type; |
57 log->type = type; |
| 51 log->logger_data = NULL; |
58 log->logger_data = NULL; |
| 52 log->logger = gaim_log_logger_get(); |
59 log->logger = gaim_log_logger_get(); |
| 65 } |
72 } |
| 66 |
73 |
| 67 void gaim_log_write(GaimLog *log, GaimMessageFlags type, |
74 void gaim_log_write(GaimLog *log, GaimMessageFlags type, |
| 68 const char *from, time_t time, const char *message) |
75 const char *from, time_t time, const char *message) |
| 69 { |
76 { |
| |
77 struct _gaim_logsize_user lu; |
| |
78 |
| 70 g_return_if_fail(log); |
79 g_return_if_fail(log); |
| 71 g_return_if_fail(log->logger); |
80 g_return_if_fail(log->logger); |
| 72 g_return_if_fail(log->logger->write); |
81 g_return_if_fail(log->logger->write); |
| 73 |
82 |
| 74 if ((log->type == GAIM_LOG_IM && gaim_prefs_get_bool("/core/logging/log_ims")) || |
83 if ((log->type == GAIM_LOG_IM && |
| 75 (log->type == GAIM_LOG_CHAT && gaim_prefs_get_bool("/core/logging/log_chats")) || |
84 gaim_prefs_get_bool("/core/logging/log_ims")) || |
| 76 + (log->type == GAIM_LOG_SYSTEM && gaim_prefs_get_bool("/core/logging/log_system"))) |
85 (log->type == GAIM_LOG_CHAT && |
| |
86 gaim_prefs_get_bool("/core/logging/log_chats")) || |
| |
87 (log->type == GAIM_LOG_SYSTEM && |
| |
88 gaim_prefs_get_bool("/core/logging/log_system"))) { |
| 77 (log->logger->write)(log, type, from, time, message); |
89 (log->logger->write)(log, type, from, time, message); |
| |
90 lu.name = g_strdup(gaim_normalize(log->account, log->name)); |
| |
91 lu.account = log->account; |
| |
92 g_hash_table_remove(logsize_users, &lu); |
| |
93 g_free(lu.name); |
| |
94 } |
| 78 } |
95 } |
| 79 |
96 |
| 80 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags) |
97 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags) |
| 81 { |
98 { |
| 82 GaimLogReadFlags mflags; |
99 GaimLogReadFlags mflags; |
| 96 if (log->logger->size) |
113 if (log->logger->size) |
| 97 return log->logger->size(log); |
114 return log->logger->size(log); |
| 98 return 0; |
115 return 0; |
| 99 } |
116 } |
| 100 |
117 |
| |
118 static guint _gaim_logsize_user_hash(struct _gaim_logsize_user *lu) |
| |
119 { |
| |
120 return g_str_hash(lu->name); |
| |
121 } |
| |
122 |
| |
123 static guint _gaim_logsize_user_equal(struct _gaim_logsize_user *lu1, |
| |
124 struct _gaim_logsize_user *lu2) |
| |
125 { |
| |
126 return ((!strcmp(lu1->name, lu2->name)) && lu1->account == lu2->account); |
| |
127 } |
| |
128 |
| |
129 static void _gaim_logsize_user_free_key(struct _gaim_logsize_user *lu) |
| |
130 { |
| |
131 g_free(lu->name); |
| |
132 g_free(lu); |
| |
133 } |
| |
134 |
| 101 int gaim_log_get_total_size(const char *name, GaimAccount *account) |
135 int gaim_log_get_total_size(const char *name, GaimAccount *account) |
| 102 { |
136 { |
| 103 int size = 0; |
137 int size; |
| 104 GSList *n; |
138 GSList *n; |
| 105 |
139 struct _gaim_logsize_user *lu; |
| 106 for (n = loggers; n; n = n->next) { |
140 |
| 107 GaimLogLogger *logger = n->data; |
141 lu = g_new(struct _gaim_logsize_user, 1); |
| 108 |
142 lu->name = g_strdup(gaim_normalize(account, name)); |
| 109 if(logger->total_size){ |
143 lu->account = account; |
| 110 size += (logger->total_size)(name, account); |
144 |
| 111 } else if(logger->list) { |
145 if((size = GPOINTER_TO_INT(g_hash_table_lookup(logsize_users, lu)))) { |
| 112 GList *logs = (logger->list)(name, account); |
146 g_free(lu->name); |
| 113 int this_size = 0; |
147 g_free(lu); |
| 114 |
148 } else { |
| 115 while (logs) { |
149 for (n = loggers; n; n = n->next) { |
| 116 GList *logs2 = logs->next; |
150 GaimLogLogger *logger = n->data; |
| 117 GaimLog *log = (GaimLog*)(logs->data); |
151 |
| 118 this_size += gaim_log_get_size(log); |
152 if(logger->total_size){ |
| 119 gaim_log_free(log); |
153 size += (logger->total_size)(name, account); |
| 120 g_list_free_1(logs); |
154 } else if(logger->list) { |
| 121 logs = logs2; |
155 GList *logs = (logger->list)(name, account); |
| |
156 int this_size = 0; |
| |
157 |
| |
158 while (logs) { |
| |
159 GList *logs2 = logs->next; |
| |
160 GaimLog *log = (GaimLog*)(logs->data); |
| |
161 this_size += gaim_log_get_size(log); |
| |
162 gaim_log_free(log); |
| |
163 g_list_free_1(logs); |
| |
164 logs = logs2; |
| |
165 } |
| |
166 |
| |
167 size += this_size; |
| 122 } |
168 } |
| 123 |
169 } |
| 124 size += this_size; |
170 |
| 125 } |
171 g_hash_table_replace(logsize_users, lu, GINT_TO_POINTER(size)); |
| 126 } |
172 } |
| 127 |
|
| 128 return size; |
173 return size; |
| 129 } |
174 } |
| 130 |
175 |
| 131 /**************************************************************************** |
176 /**************************************************************************** |
| 132 * LOGGER FUNCTIONS ********************************************************* |
177 * LOGGER FUNCTIONS ********************************************************* |
| 267 gaim_log_logger_add(&txt_logger); |
312 gaim_log_logger_add(&txt_logger); |
| 268 gaim_log_logger_add(&old_logger); |
313 gaim_log_logger_add(&old_logger); |
| 269 gaim_prefs_connect_callback("/core/logging/format", |
314 gaim_prefs_connect_callback("/core/logging/format", |
| 270 logger_pref_cb, NULL); |
315 logger_pref_cb, NULL); |
| 271 gaim_prefs_trigger_callback("/core/logging/format"); |
316 gaim_prefs_trigger_callback("/core/logging/format"); |
| |
317 |
| |
318 logsize_users = g_hash_table_new_full((GHashFunc)_gaim_logsize_user_hash, |
| |
319 (GEqualFunc)_gaim_logsize_user_equal, |
| |
320 (GDestroyNotify)_gaim_logsize_user_free_key, NULL); |
| 272 } |
321 } |
| 273 |
322 |
| 274 /**************************************************************************** |
323 /**************************************************************************** |
| 275 * LOGGERS ****************************************************************** |
324 * LOGGERS ****************************************************************** |
| 276 ****************************************************************************/ |
325 ****************************************************************************/ |