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