Mercurial > pidgin
annotate src/log.c @ 8608:bcff148ebd71
[gaim-migrate @ 9359]
should probly make note of that
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Wed, 07 Apr 2004 23:51:33 +0000 |
| parents | 089a3400b2aa |
| children | d4f6b9aa4cc8 |
| 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); |
| 7431 | 302 |
| 7447 | 303 g_free(me); |
| 304 | |
| 7431 | 305 if (!(dir = g_dir_open(path, 0, NULL))) { |
| 306 g_free(path); | |
| 307 return NULL; | |
| 308 } | |
| 309 while ((filename = g_dir_read_name(dir))) { | |
| 8577 | 310 if (gaim_str_has_suffix(filename, ext) && |
| 311 strlen(filename) == 17 + strlen(ext)) { | |
| 7431 | 312 GaimLog *log; |
| 7616 | 313 struct generic_logger_data *data; |
| 8577 | 314 time_t stamp = gaim_str_to_time(filename, FALSE); |
| 7431 | 315 |
| 8577 | 316 log = gaim_log_new(GAIM_LOG_IM, screenname, account, stamp); |
| 7431 | 317 log->logger = logger; |
| 7616 | 318 log->logger_data = data = g_new0(struct generic_logger_data, 1); |
| 319 data->path = g_build_filename(path, filename, NULL); | |
| 7431 | 320 list = g_list_append(list, log); |
| 4184 | 321 } |
| 322 } | |
| 7431 | 323 g_dir_close(dir); |
| 7447 | 324 g_free(path); |
| 7431 | 325 return list; |
| 326 } | |
| 4184 | 327 |
| 7556 | 328 /* Only to be used with logs listed from log_lister_common */ |
| 7616 | 329 int log_sizer_common(GaimLog *log) |
| 7556 | 330 { |
| 331 struct stat st; | |
| 7616 | 332 struct generic_logger_data *data = log->logger_data; |
| 7556 | 333 |
| 7616 | 334 if (!data->path || stat(data->path, &st)) |
| 7556 | 335 st.st_size = 0; |
| 336 | |
| 337 return st.st_size; | |
| 338 } | |
| 339 | |
| 7431 | 340 #if 0 /* Maybe some other time. */ |
| 7443 | 341 /**************** |
| 7431 | 342 ** XML LOGGER ** |
| 343 ****************/ | |
| 344 | |
| 345 static const char *str_from_msg_type (GaimMessageFlags type) | |
| 346 { | |
| 7443 | 347 |
| 7431 | 348 return ""; |
| 7443 | 349 |
| 7431 | 350 } |
| 351 | |
| 7443 | 352 static void xml_logger_write(GaimLog *log, |
| 353 GaimMessageFlags type, | |
| 7431 | 354 const char *from, time_t time, const char *message) |
| 355 { | |
| 356 char date[64]; | |
| 357 char *xhtml = NULL; | |
| 358 if (!log->logger_data) { | |
| 359 /* This log is new. We could use the loggers 'new' function, but | |
| 360 * creating a new file there would result in empty files in the case | |
| 361 * that you open a convo with someone, but don't say anything. | |
| 362 */ | |
| 363 char *ud = gaim_user_dir(); | |
| 364 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); | |
| 365 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO | |
| 366 (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL); | |
| 367 char *dir; | |
| 368 FILE *file; | |
| 369 | |
| 7453 | 370 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time)); |
| 7443 | 371 |
| 372 dir = g_build_filename(ud, "logs", | |
| 7431 | 373 prpl, guy, gaim_normalize(log->account, log->name), NULL); |
| 7612 | 374 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
| 7447 | 375 g_free(guy); |
| 7443 | 376 |
| 7431 | 377 char *filename = g_build_filename(dir, date, NULL); |
| 378 g_free(dir); | |
| 7443 | 379 |
| 7431 | 380 log->logger_data = fopen(filename, "a"); |
| 381 if (!log->logger_data) { | |
| 382 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | |
| 7564 | 383 g_free(filename); |
| 7431 | 384 return; |
| 385 } | |
| 7564 | 386 g_free(filename); |
| 7431 | 387 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" |
| 388 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); | |
| 7443 | 389 |
| 7453 | 390 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
| 7431 | 391 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", |
| 392 date, log->name, prpl); | |
| 393 } | |
| 7443 | 394 |
| 7453 | 395 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); |
| 7431 | 396 gaim_markup_html_to_xhtml(message, &xhtml, NULL); |
| 397 if (from) | |
| 7443 | 398 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n", |
| 399 str_from_msg_type(type), | |
| 7431 | 400 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
| 401 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
| 402 from, date, xhtml); | |
| 403 else | |
| 7443 | 404 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n", |
| 405 str_from_msg_type(type), | |
| 7431 | 406 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
| 407 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
| 7443 | 408 date, xhtml): |
| 7431 | 409 fflush(log->logger_data); |
| 410 g_free(xhtml); | |
| 7443 | 411 } |
| 412 | |
| 7431 | 413 static void xml_logger_finalize(GaimLog *log) |
| 414 { | |
| 415 if (log->logger_data) { | |
| 416 fprintf(log->logger_data, "</conversation>\n"); | |
| 417 fclose(log->logger_data); | |
| 418 log->logger_data = NULL; | |
| 419 } | |
| 420 } | |
| 7443 | 421 |
| 7431 | 422 static GList *xml_logger_list(const char *sn, GaimAccount *account) |
| 423 { | |
| 424 return log_lister_common(sn, account, ".xml", &xml_logger); | |
| 4184 | 425 } |
| 426 | |
| 7431 | 427 static GaimLogLogger xml_logger = { |
| 428 N_("XML"), "xml", | |
| 429 NULL, | |
| 430 xml_logger_write, | |
| 431 xml_logger_finalize, | |
| 432 xml_logger_list, | |
| 8096 | 433 NULL, |
| 7431 | 434 NULL |
| 435 }; | |
| 436 #endif | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
437 |
| 7431 | 438 /**************************** |
| 7457 | 439 ** HTML LOGGER ************* |
| 440 ****************************/ | |
| 441 | |
| 442 static void html_logger_write(GaimLog *log, GaimMessageFlags type, | |
| 443 const char *from, time_t time, const char *message) | |
| 444 { | |
| 7489 | 445 GaimConnection *gc = gaim_account_get_connection(log->account); |
| 7457 | 446 char date[64]; |
| 7882 | 447 char *msg_fixed; |
| 7616 | 448 struct generic_logger_data *data = log->logger_data; |
| 7618 | 449 if(!data) { |
| 7457 | 450 /* This log is new */ |
| 451 char *ud = gaim_user_dir(); | |
| 452 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); | |
| 7553 | 453 char *chat; |
| 7457 | 454 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO |
| 7956 | 455 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL); |
| 7457 | 456 char *dir; |
| 457 char *filename; | |
| 458 | |
| 7553 | 459 if (log->type == GAIM_LOG_CHAT) { |
| 460 chat = g_strdup_printf("%s.chat", guy); | |
| 461 g_free(guy); | |
| 462 guy = chat; | |
| 463 } | |
| 464 | |
| 7457 | 465 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.html", localtime(&log->time)); |
| 466 | |
| 467 dir = g_build_filename(ud, "logs", | |
| 468 prpl, guy, gaim_normalize(log->account, log->name), NULL); | |
| 7612 | 469 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
| 7457 | 470 g_free(guy); |
| 471 | |
| 472 filename = g_build_filename(dir, date, NULL); | |
| 473 g_free(dir); | |
| 474 | |
| 7616 | 475 log->logger_data = data = g_new0(struct generic_logger_data, 1); |
| 476 | |
| 477 data->file = fopen(filename, "a"); | |
| 478 if (!data->file) { | |
| 7623 | 479 gaim_debug(GAIM_DEBUG_ERROR, "log", |
| 480 "Could not create log file %s\n", filename); | |
| 7564 | 481 g_free(filename); |
| 7457 | 482 return; |
| 483 } | |
| 484 g_free(filename); | |
| 485 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); | |
| 7616 | 486 fprintf(data->file, "<html><head><title>"); |
| 487 fprintf(data->file, "Conversation with %s at %s on %s (%s)", | |
| 7457 | 488 log->name, date, gaim_account_get_username(log->account), prpl); |
| 7616 | 489 fprintf(data->file, "</title></head><body>"); |
| 490 fprintf(data->file, | |
| 7457 | 491 "<h3>Conversation with %s at %s on %s (%s)</h3>\n", |
| 492 log->name, date, gaim_account_get_username(log->account), prpl); | |
| 493 } | |
| 7623 | 494 |
| 495 /* if we can't write to the file, give up before we hurt ourselves */ | |
| 496 if(!data->file) | |
| 497 return; | |
| 498 | |
| 7882 | 499 gaim_markup_html_to_xhtml(message, &msg_fixed, NULL); |
| 500 | |
| 8577 | 501 if(log->type == GAIM_LOG_SYSTEM){ |
| 502 strftime(date, sizeof(date), "%c", localtime(&time)); | |
| 503 fprintf(data->file, "---- %s @ %s ----<br/>\n", msg_fixed, date); | |
| 504 } else { | |
| 505 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | |
| 506 if (type & GAIM_MESSAGE_SYSTEM) | |
| 507 fprintf(data->file, "<font size=\"2\">(%s)</font><b> %s</b><br/>\n", date, msg_fixed); | |
| 508 else if (type & GAIM_MESSAGE_WHISPER) | |
| 509 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font><b> %s:</b></font> %s<br/>\n", | |
| 510 date, from, msg_fixed); | |
| 511 else if (type & GAIM_MESSAGE_AUTO_RESP) { | |
| 512 if (type & GAIM_MESSAGE_SEND) | |
| 513 fprintf(data->file, _("<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | |
| 514 else if (type & GAIM_MESSAGE_RECV) | |
| 515 fprintf(data->file, _("<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s <AUTO-REPLY>:</b></font> %s<br/>\n"), date, from, msg_fixed); | |
| 516 } else if (type & GAIM_MESSAGE_RECV) { | |
| 517 if(gaim_message_meify(msg_fixed, -1)) | |
| 518 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 519 date, from, gc->prpl->info->name, msg_fixed); | |
| 520 else | |
| 521 fprintf(data->file, "<font color=\"#A82F2F\"><font size=\"2\">(%s)</font> <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 522 date, from, gc->prpl->info->name, msg_fixed); | |
| 523 } else if (type & GAIM_MESSAGE_SEND) { | |
| 524 if(gaim_message_meify(msg_fixed, -1)) | |
| 525 fprintf(data->file, "<font color=\"#6C2585\"><font size=\"2\">(%s)</font> <b>***%s</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 526 date, from, gc->prpl->info->name, msg_fixed); | |
| 527 else | |
| 528 fprintf(data->file, "<font color=\"#16569E\"><font size=\"2\">(%s)</font> <b>%s:</b></font> <font sml=\"%s\">%s</font><br/>\n", | |
| 529 date, from, gc->prpl->info->name, msg_fixed); | |
| 530 } | |
| 7564 | 531 } |
| 8573 | 532 |
| 7882 | 533 g_free(msg_fixed); |
| 7616 | 534 fflush(data->file); |
| 7457 | 535 } |
| 536 | |
| 537 static void html_logger_finalize(GaimLog *log) | |
| 538 { | |
| 7616 | 539 struct generic_logger_data *data = log->logger_data; |
| 540 if (data) { | |
| 541 if(data->file) { | |
| 542 fprintf(data->file, "</body></html>"); | |
| 543 fclose(data->file); | |
| 544 } | |
| 545 g_free(data->path); | |
| 7752 | 546 g_free(data); |
| 7463 | 547 } |
| 7457 | 548 } |
| 549 | |
| 550 static GList *html_logger_list(const char *sn, GaimAccount *account) | |
| 551 { | |
| 552 return log_lister_common(sn, account, ".html", &html_logger); | |
| 553 } | |
| 554 | |
| 8573 | 555 static GList *html_logger_list_syslog(GaimAccount *account) |
| 556 { | |
| 557 return log_lister_common(".system", account, ".html", &html_logger); | |
| 558 } | |
| 559 | |
| 7457 | 560 static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
| 561 { | |
| 562 char *read, *minus_header; | |
| 7616 | 563 struct generic_logger_data *data = log->logger_data; |
| 7457 | 564 *flags = GAIM_LOG_READ_NO_NEWLINE; |
| 7616 | 565 if (!data || !data->path) |
| 566 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
| 567 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
| 7457 | 568 minus_header = strchr(read, '\n'); |
| 569 if (!minus_header) | |
| 570 minus_header = g_strdup(read); | |
| 571 else | |
| 572 minus_header = g_strdup(minus_header + 1); | |
| 573 g_free(read); | |
| 574 return minus_header; | |
| 575 } | |
| 8578 | 576 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
| 7457 | 577 } |
| 578 | |
| 8573 | 579 static void html_logger_create(GaimLog *log) |
| 580 { | |
| 581 if(log->type == GAIM_LOG_SYSTEM){ | |
| 582 char date[64]; | |
| 583 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO | |
| 584 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL); | |
| 585 char *ud = gaim_user_dir(); | |
| 586 char *dir = g_build_filename(ud, "logs", prpl, log->name, ".system", NULL); | |
| 587 char *filename; | |
| 588 struct generic_logger_data *data; | |
| 589 | |
| 590 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 591 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.html", localtime(&log->time)); | |
| 592 filename = g_build_filename(dir, date, NULL); | |
| 593 g_free(dir); | |
| 594 | |
| 595 log->logger_data = data = g_new0(struct generic_logger_data, 1); | |
| 596 | |
| 597 data->file = fopen(filename, "a"); | |
| 598 if (!data->file) { | |
| 599 gaim_debug(GAIM_DEBUG_ERROR, "log", | |
| 600 "Could not create log file %s\n", filename); | |
| 601 g_free(filename); | |
| 602 return; | |
| 603 } | |
| 604 fprintf(data->file, "<html><head><title>"); | |
| 605 fprintf(data->file, "System Log for %s (%s)", | |
| 606 gaim_account_get_username(log->account), prpl); | |
| 607 fprintf(data->file, "</title></head><body>"); | |
| 608 g_free(filename); | |
| 609 } | |
| 610 } | |
| 611 | |
| 7457 | 612 static GaimLogLogger html_logger = { |
| 613 N_("HTML"), "html", | |
| 8573 | 614 html_logger_create, |
| 7457 | 615 html_logger_write, |
| 616 html_logger_finalize, | |
| 617 html_logger_list, | |
| 7556 | 618 html_logger_read, |
| 8096 | 619 log_sizer_common, |
| 8573 | 620 NULL, |
| 621 html_logger_list_syslog | |
| 7457 | 622 }; |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 /**************************** | |
| 7431 | 628 ** PLAIN TEXT LOGGER ******* |
| 629 ****************************/ | |
| 4184 | 630 |
| 7436 | 631 static void txt_logger_write(GaimLog *log, |
| 632 GaimMessageFlags type, | |
| 7431 | 633 const char *from, time_t time, const char *message) |
| 634 { | |
| 635 char date[64]; | |
| 636 char *stripped = NULL; | |
| 7616 | 637 struct generic_logger_data *data = log->logger_data; |
| 638 if (!data) { | |
| 7431 | 639 /* This log is new. We could use the loggers 'new' function, but |
| 640 * creating a new file there would result in empty files in the case | |
| 641 * that you open a convo with someone, but don't say anything. | |
| 8573 | 642 * |
| 643 * The log is also not system log. Because if it is, data would be | |
| 644 * created in txt_logger_create | |
| 7431 | 645 */ |
| 646 char *ud = gaim_user_dir(); | |
| 7473 | 647 char *filename; |
| 7431 | 648 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); |
| 7553 | 649 char *chat; |
| 7431 | 650 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO |
| 7956 | 651 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL); |
| 7431 | 652 char *dir; |
| 7436 | 653 |
| 7553 | 654 if (log->type == GAIM_LOG_CHAT) { |
| 655 chat = g_strdup_printf("%s.chat", guy); | |
| 656 g_free(guy); | |
| 657 guy = chat; | |
| 658 } | |
| 7453 | 659 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.txt", localtime(&log->time)); |
| 7436 | 660 |
| 661 dir = g_build_filename(ud, "logs", | |
| 7431 | 662 prpl, guy, gaim_normalize(log->account, log->name), NULL); |
| 7612 | 663 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); |
| 7447 | 664 g_free(guy); |
| 7436 | 665 |
| 7473 | 666 filename = g_build_filename(dir, date, NULL); |
| 7431 | 667 g_free(dir); |
| 7436 | 668 |
| 7616 | 669 log->logger_data = data = g_new0(struct generic_logger_data, 1); |
| 670 | |
| 671 data->file = fopen(filename, "a"); | |
| 672 if (!data->file) { | |
| 7431 | 673 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); |
| 7564 | 674 g_free(filename); |
| 7431 | 675 return; |
| 4184 | 676 } |
| 7447 | 677 g_free(filename); |
| 7453 | 678 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&log->time)); |
| 7616 | 679 fprintf(data->file, "Conversation with %s at %s on %s (%s)\n", |
| 7431 | 680 log->name, date, gaim_account_get_username(log->account), prpl); |
| 681 } | |
| 7436 | 682 |
| 7623 | 683 /* if we can't write to the file, give up before we hurt ourselves */ |
| 684 if(!data->file) | |
| 685 return; | |
| 686 | |
| 8573 | 687 stripped = gaim_markup_strip_html(message); |
| 688 | |
| 689 if(log->type == GAIM_LOG_SYSTEM){ | |
| 690 strftime(date, sizeof(date), "%c", localtime(&time)); | |
| 691 fprintf(data->file, "---- %s @ %s ----\n", stripped, date); | |
| 692 } else { | |
| 693 strftime(date, sizeof(date), "%H:%M:%S", localtime(&time)); | |
| 694 if (type & GAIM_MESSAGE_SEND || | |
| 695 type & GAIM_MESSAGE_RECV) { | |
| 696 if (type & GAIM_MESSAGE_AUTO_RESP) { | |
| 697 fprintf(data->file, _("(%s) %s <AUTO-REPLY>: %s\n"), date, | |
| 698 from, stripped); | |
| 699 } else { | |
| 700 if(gaim_message_meify(stripped, -1)) | |
| 701 fprintf(data->file, "(%s) ***%s %s\n", date, from, | |
| 702 stripped); | |
| 703 else | |
| 704 fprintf(data->file, "(%s) %s: %s\n", date, from, | |
| 705 stripped); | |
| 706 } | |
| 707 } else if (type & GAIM_MESSAGE_SYSTEM) | |
| 708 fprintf(data->file, "(%s) %s\n", date, stripped); | |
| 709 else if (type & GAIM_MESSAGE_NO_LOG) { | |
| 710 /* This shouldn't happen */ | |
| 711 g_free(stripped); | |
| 712 return; | |
| 713 } else if (type & GAIM_MESSAGE_WHISPER) | |
| 714 fprintf(data->file, "(%s) *%s* %s", date, from, stripped); | |
| 715 else | |
| 716 fprintf(data->file, "(%s) %s%s %s\n", date, from ? from : "", | |
| 717 from ? ":" : "", stripped); | |
| 718 } | |
| 719 | |
| 720 fflush(data->file); | |
| 721 g_free(stripped); | |
| 7431 | 722 } |
| 723 | |
| 724 static void txt_logger_finalize(GaimLog *log) | |
| 725 { | |
| 7616 | 726 struct generic_logger_data *data = log->logger_data; |
| 727 if (data) { | |
| 728 if(data->file) | |
| 729 fclose(data->file); | |
| 730 if(data->path) | |
| 731 g_free(data->path); | |
| 7752 | 732 g_free(data); |
| 7616 | 733 } |
| 7431 | 734 } |
| 735 | |
| 736 static GList *txt_logger_list(const char *sn, GaimAccount *account) | |
| 737 { | |
| 738 return log_lister_common(sn, account, ".txt", &txt_logger); | |
| 739 } | |
| 740 | |
| 8573 | 741 static GList *txt_logger_list_syslog(GaimAccount *account) |
| 742 { | |
| 743 return log_lister_common(".system", account, ".txt", &txt_logger); | |
| 744 } | |
| 745 | |
| 7431 | 746 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) |
| 747 { | |
| 8517 | 748 char *read, *minus_header, *minus_header2; |
| 7616 | 749 struct generic_logger_data *data = log->logger_data; |
| 7457 | 750 *flags = 0; |
| 7616 | 751 if (!data || !data->path) |
| 752 return g_strdup(_("<font color=\"red\"><b>Unable to find log path!</b></font>")); | |
| 753 if (g_file_get_contents(data->path, &read, NULL, NULL)) { | |
| 7431 | 754 minus_header = strchr(read, '\n'); |
| 755 if (!minus_header) | |
| 756 minus_header = g_strdup(read); | |
| 7436 | 757 else |
| 7431 | 758 minus_header = g_strdup(minus_header + 1); |
| 759 g_free(read); | |
| 8517 | 760 minus_header2 = gaim_escape_html(minus_header); |
| 761 g_free(minus_header); | |
| 762 return minus_header2; | |
| 7431 | 763 } |
| 8578 | 764 return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); |
| 7436 | 765 } |
| 7431 | 766 |
| 8573 | 767 static void txt_logger_create(GaimLog *log) |
| 768 { | |
| 769 if(log->type == GAIM_LOG_SYSTEM){ | |
| 770 char date[64]; | |
| 771 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO | |
| 772 (gaim_find_prpl(gaim_account_get_protocol_id(log->account)))->list_icon(log->account, NULL); | |
| 773 char *ud = gaim_user_dir(); | |
| 774 char *dir = g_build_filename(ud, "logs", prpl, log->name, ".system", NULL); | |
| 775 char *filename; | |
| 776 struct generic_logger_data *data; | |
| 777 | |
| 778 gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 779 strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.txt", localtime(&log->time)); | |
| 780 filename = g_build_filename(dir, date, NULL); | |
| 781 g_free(dir); | |
| 782 | |
| 783 log->logger_data = data = g_new0(struct generic_logger_data, 1); | |
| 784 | |
| 785 data->file = fopen(filename, "a"); | |
| 786 if (!data->file) { | |
| 787 gaim_debug(GAIM_DEBUG_ERROR, "log", | |
| 788 "Could not create log file %s\n", filename); | |
| 789 g_free(filename); | |
| 790 return; | |
| 791 } | |
| 792 g_free(filename); | |
| 793 } | |
| 794 } | |
| 795 | |
| 7431 | 796 static GaimLogLogger txt_logger = { |
| 797 N_("Plain text"), "txt", | |
| 8573 | 798 txt_logger_create, |
| 7431 | 799 txt_logger_write, |
| 800 txt_logger_finalize, | |
| 801 txt_logger_list, | |
| 7556 | 802 txt_logger_read, |
| 8096 | 803 log_sizer_common, |
| 8573 | 804 NULL, |
| 805 txt_logger_list_syslog | |
| 7431 | 806 }; |
| 807 | |
| 808 /**************** | |
| 809 * OLD LOGGER *** | |
| 810 ****************/ | |
| 811 | |
| 812 /* The old logger doesn't write logs, only reads them. This is to include | |
| 813 * old logs in the log viewer transparently. | |
| 814 */ | |
| 815 | |
| 816 struct old_logger_data { | |
| 7764 | 817 GaimStringref *pathref; |
| 7431 | 818 int offset; |
| 819 int length; | |
| 820 }; | |
| 821 | |
| 7436 | 822 static GList *old_logger_list(const char *sn, GaimAccount *account) |
| 7431 | 823 { |
| 824 FILE *file; | |
| 825 char buf[BUF_LONG]; | |
| 826 struct tm tm; | |
| 7761 | 827 char month[4]; |
| 7431 | 828 struct old_logger_data *data = NULL; |
| 829 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); | |
| 7764 | 830 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); |
| 831 GaimStringref *pathref = gaim_stringref_new(pathstr); | |
| 7431 | 832 char *newlog; |
| 7761 | 833 int logfound = 0; |
| 834 int lastoff = 0; | |
| 835 int newlen; | |
| 7791 | 836 time_t lasttime = 0; |
| 7431 | 837 |
| 838 GaimLog *log = NULL; | |
| 839 GList *list = NULL; | |
| 840 | |
| 7473 | 841 g_free(logfile); |
| 7764 | 842 g_free(pathstr); |
| 7473 | 843 |
| 7764 | 844 if (!(file = fopen(gaim_stringref_value(pathref), "rb"))) { |
| 845 gaim_stringref_unref(pathref); | |
| 7431 | 846 return NULL; |
| 7447 | 847 } |
| 7436 | 848 |
| 7431 | 849 while (fgets(buf, BUF_LONG, file)) { |
| 850 if ((newlog = strstr(buf, "---- New C"))) { | |
| 851 int length; | |
| 852 int offset; | |
| 853 char convostart[32]; | |
| 854 char *temp = strchr(buf, '@'); | |
| 7436 | 855 |
| 7431 | 856 if (temp == NULL || strlen(temp) < 2) |
| 857 continue; | |
| 7436 | 858 |
| 7431 | 859 temp++; |
| 860 length = strcspn(temp, "-"); | |
| 861 if (length > 31) length = 31; | |
| 7436 | 862 |
| 7431 | 863 offset = ftell(file); |
| 7436 | 864 |
| 7761 | 865 if (logfound) { |
| 866 newlen = offset - lastoff - length; | |
| 7436 | 867 if(strstr(buf, "----</H3><BR>")) { |
| 7761 | 868 newlen -= |
| 869 sizeof("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + | |
| 870 sizeof("----</H3><BR>") - 2; | |
| 7436 | 871 } else { |
| 7761 | 872 newlen -= |
| 873 sizeof("---- New Conversation @ ") + sizeof("----") - 2; | |
| 7436 | 874 } |
| 875 | |
| 7461 | 876 if(strchr(buf, '\r')) |
| 7770 | 877 newlen--; |
| 7461 | 878 |
| 7761 | 879 if (newlen != 0) { |
| 880 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | |
| 881 log->logger = &old_logger; | |
| 882 log->time = lasttime; | |
| 883 data = g_new0(struct old_logger_data, 1); | |
| 884 data->offset = lastoff; | |
| 885 data->length = newlen; | |
| 7764 | 886 data->pathref = gaim_stringref_ref(pathref); |
| 7761 | 887 log->logger_data = data; |
| 7431 | 888 list = g_list_append(list, log); |
| 7761 | 889 } |
| 7431 | 890 } |
| 891 | |
| 7761 | 892 logfound = 1; |
| 893 lastoff = offset; | |
| 7436 | 894 |
| 7431 | 895 g_snprintf(convostart, length, "%s", temp); |
| 7676 | 896 sscanf(convostart, "%*s %s %d %d:%d:%d %d", |
| 897 month, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, &tm.tm_year); | |
| 898 /* Ugly hack, in case current locale is not English */ | |
| 899 if (strcmp(month, "Jan") == 0) { | |
| 900 tm.tm_mon= 0; | |
| 901 } else if (strcmp(month, "Feb") == 0) { | |
| 902 tm.tm_mon = 1; | |
| 903 } else if (strcmp(month, "Mar") == 0) { | |
| 904 tm.tm_mon = 2; | |
| 905 } else if (strcmp(month, "Apr") == 0) { | |
| 906 tm.tm_mon = 3; | |
| 907 } else if (strcmp(month, "May") == 0) { | |
| 908 tm.tm_mon = 4; | |
| 909 } else if (strcmp(month, "Jun") == 0) { | |
| 910 tm.tm_mon = 5; | |
| 911 } else if (strcmp(month, "Jul") == 0) { | |
| 912 tm.tm_mon = 6; | |
| 913 } else if (strcmp(month, "Aug") == 0) { | |
| 914 tm.tm_mon = 7; | |
| 915 } else if (strcmp(month, "Sep") == 0) { | |
| 916 tm.tm_mon = 8; | |
| 917 } else if (strcmp(month, "Oct") == 0) { | |
| 918 tm.tm_mon = 9; | |
| 919 } else if (strcmp(month, "Nov") == 0) { | |
| 920 tm.tm_mon = 10; | |
| 921 } else if (strcmp(month, "Dec") == 0) { | |
| 922 tm.tm_mon = 11; | |
| 923 } | |
| 924 tm.tm_year -= 1900; | |
| 7761 | 925 lasttime = mktime(&tm); |
| 4184 | 926 } |
| 927 } | |
| 7613 | 928 |
| 7761 | 929 if (logfound) { |
| 930 if ((newlen = ftell(file) - lastoff) != 0) { | |
| 931 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | |
| 932 log->logger = &old_logger; | |
| 933 log->time = lasttime; | |
| 934 data = g_new0(struct old_logger_data, 1); | |
| 935 data->offset = lastoff; | |
| 936 data->length = newlen; | |
| 7764 | 937 data->pathref = gaim_stringref_ref(pathref); |
| 7761 | 938 log->logger_data = data; |
| 7613 | 939 list = g_list_append(list, log); |
| 7761 | 940 } |
| 7613 | 941 } |
| 942 | |
| 7764 | 943 gaim_stringref_unref(pathref); |
| 7431 | 944 fclose(file); |
| 945 return list; | |
| 4184 | 946 } |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
947 |
| 8096 | 948 static int old_logger_total_size(const char *name, GaimAccount *account) |
| 949 { | |
| 950 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, name)); | |
| 951 char *pathstr = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); | |
| 952 int size; | |
| 953 struct stat st; | |
| 954 | |
| 955 if (stat(pathstr, &st)) | |
| 956 size = 0; | |
| 957 else | |
| 958 size = st.st_size; | |
| 959 | |
| 960 g_free(logfile); | |
| 961 g_free(pathstr); | |
| 962 | |
| 963 return size; | |
| 964 } | |
| 965 | |
| 7616 | 966 static char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
967 { |
| 7431 | 968 struct old_logger_data *data = log->logger_data; |
| 7764 | 969 FILE *file = fopen(gaim_stringref_value(data->pathref), "rb"); |
| 7431 | 970 char *read = g_malloc(data->length + 1); |
| 971 fseek(file, data->offset, SEEK_SET); | |
| 972 fread(read, data->length, 1, file); | |
| 8370 | 973 fclose(file); |
| 7431 | 974 read[data->length] = '\0'; |
| 7436 | 975 *flags = 0; |
| 976 if(strstr(read, "<BR>")) | |
| 977 *flags |= GAIM_LOG_READ_NO_NEWLINE; | |
| 7431 | 978 return read; |
| 979 } | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
980 |
| 7616 | 981 static int old_logger_size (GaimLog *log) |
| 7556 | 982 { |
| 983 struct old_logger_data *data = log->logger_data; | |
| 7616 | 984 return data ? data->length : 0; |
| 985 } | |
| 986 | |
| 987 static void old_logger_finalize(GaimLog *log) | |
| 988 { | |
| 989 struct old_logger_data *data = log->logger_data; | |
| 7764 | 990 gaim_stringref_unref(data->pathref); |
| 7616 | 991 g_free(data); |
| 7556 | 992 } |
| 993 | |
| 7431 | 994 static GaimLogLogger old_logger = { |
| 995 "old logger", "old", | |
| 7616 | 996 NULL, NULL, |
| 997 old_logger_finalize, | |
| 7431 | 998 old_logger_list, |
| 7616 | 999 old_logger_read, |
| 8096 | 1000 old_logger_size, |
| 8573 | 1001 old_logger_total_size, |
| 1002 NULL | |
| 7431 | 1003 }; |
