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