Mercurial > pidgin
annotate src/log.c @ 7443:df50bd14e161
[gaim-migrate @ 8048]
whitespace
committer: Tailor Script <tailor@pidgin.im>
| author | Luke Schierer <lschiere@pidgin.im> |
|---|---|
| date | Thu, 06 Nov 2003 02:46:07 +0000 |
| parents | d42289ecf0ce |
| children | 0e7a835e2433 |
| rev | line source |
|---|---|
| 7431 | 1 /** |
| 2 * @file log.c Logging API | |
| 3 * @ingroup core | |
| 4 * | |
| 5 * gaim | |
| 6 * | |
| 7 * Copyright (C) 2003 Buzz Lightyear | |
| 7436 | 8 * |
| 7431 | 9 * This program is free software; you can redistribute it and/or modify |
| 10 * it under the terms of the GNU General Public License as published by | |
| 11 * the Free Software Foundation; either version 2 of the License, or | |
| 12 * (at your option) any later version. | |
| 13 * | |
| 14 * This program is distributed in the hope that it will be useful, | |
| 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 * GNU General Public License for more details. | |
| 18 * | |
| 19 * You should have received a copy of the GNU General Public License | |
| 20 * along with this program; if not, write to the Free Software | |
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 4184 | 22 */ |
| 4195 | 23 |
| 7431 | 24 #include "account.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
25 #include "debug.h" |
| 7431 | 26 #include "internal.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
27 #include "log.h" |
| 5548 | 28 #include "prefs.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
29 #include "util.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
30 |
| 7431 | 31 static GaimLogLogger txt_logger; |
| 32 static GaimLogLogger old_logger; | |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5839
diff
changeset
|
33 |
| 7431 | 34 /************************************************************************** |
| 35 * PUBLIC LOGGING FUNCTIONS *********************************************** | |
| 36 **************************************************************************/ | |
| 4184 | 37 |
| 7431 | 38 GaimLog *gaim_log_new(GaimLogType type, const char *name, GaimAccount *account, time_t time) |
| 39 { | |
| 40 GaimLog *log = g_new0(GaimLog, 1); | |
| 41 log->name = g_strdup(name); | |
| 42 log->account = account; | |
| 43 log->time = time; | |
| 44 log->logger = gaim_log_logger_get(); | |
| 7440 | 45 if (log->logger && log->logger->create) |
| 46 log->logger->create(log); | |
| 7431 | 47 return log; |
| 4184 | 48 } |
| 49 | |
| 7431 | 50 void gaim_log_free(GaimLog *log) |
| 4184 | 51 { |
| 7431 | 52 g_return_if_fail(log); |
| 53 if (log->logger && log->logger->finalize) | |
| 54 log->logger->finalize(log); | |
| 55 g_free(log->name); | |
| 56 g_free(log); | |
| 57 } | |
| 7436 | 58 |
| 4184 | 59 |
| 7436 | 60 void gaim_log_write(GaimLog *log, GaimMessageFlags type, |
| 7431 | 61 const char *from, time_t time, const char *message) |
| 62 { | |
| 63 g_return_if_fail(log); | |
| 64 g_return_if_fail(log->logger); | |
| 7442 | 65 g_return_if_fail(log->logger->write); |
| 7431 | 66 |
| 7442 | 67 (log->logger->write)(log, type, from, time, message); |
| 4184 | 68 } |
| 69 | |
| 7431 | 70 char *gaim_log_read(GaimLog *log, GaimLogReadFlags *flags) |
| 4184 | 71 { |
| 7431 | 72 g_return_val_if_fail(log && log->logger, NULL); |
| 7442 | 73 if (log->logger->read) |
| 74 return (log->logger->read)(log, flags); | |
| 7431 | 75 return (_("<b><font color\"=red\">The logger has no read function</font></b>")); |
| 4184 | 76 } |
| 77 | |
| 7431 | 78 /**************************************************************************** |
| 79 * LOGGER FUNCTIONS ********************************************************* | |
| 80 ****************************************************************************/ | |
| 4184 | 81 |
| 7431 | 82 static GaimLogLogger *current_logger = NULL; |
| 83 static GSList *loggers = NULL; | |
| 7436 | 84 |
| 7431 | 85 static void logger_pref_cb(const char *name, GaimPrefType type, |
| 86 gpointer value, gpointer data) | |
| 87 { | |
| 88 GaimLogLogger *logger; | |
| 89 GSList *l = loggers; | |
| 90 while (l) { | |
| 91 logger = l->data; | |
| 92 if (!strcmp(logger->id, value)) { | |
| 93 gaim_log_logger_set(logger); | |
| 94 return; | |
| 4184 | 95 } |
| 7431 | 96 l = l->next; |
| 97 } | |
| 98 gaim_log_logger_set(&txt_logger); | |
| 99 } | |
| 4184 | 100 |
| 101 | |
| 7440 | 102 GaimLogLogger *gaim_log_logger_new(void(*create)(GaimLog *), |
| 7436 | 103 void(*write)(GaimLog *, GaimMessageFlags, const char *, |
| 7431 | 104 time_t, const char *), |
| 105 void(*finalize)(GaimLog *), GList*(*list)(const char*, GaimAccount*), | |
| 106 char*(*read)(GaimLog*, GaimLogReadFlags*)) | |
| 107 { | |
| 108 GaimLogLogger *logger = g_new0(GaimLogLogger, 1); | |
| 7440 | 109 logger->create = create; |
| 7431 | 110 logger->write = write; |
| 111 logger->finalize = finalize; | |
| 112 logger->list = list; | |
| 113 logger->read = read; | |
| 114 return logger; | |
| 4184 | 115 } |
| 116 | |
| 7431 | 117 void gaim_log_logger_free(GaimLogLogger *logger) |
| 4184 | 118 { |
| 7431 | 119 g_free(logger); |
| 120 } | |
| 4184 | 121 |
| 7431 | 122 void gaim_log_logger_add (GaimLogLogger *logger) |
| 123 { | |
| 124 g_return_if_fail(logger); | |
| 125 if (g_slist_find(loggers, logger)) | |
| 126 return; | |
| 127 loggers = g_slist_append(loggers, logger); | |
| 128 } | |
| 129 | |
| 130 void gaim_log_logger_remove (GaimLogLogger *logger) | |
| 131 { | |
| 132 g_return_if_fail(logger); | |
| 133 g_slist_remove(loggers, logger); | |
| 4184 | 134 } |
| 135 | |
| 7431 | 136 void gaim_log_logger_set (GaimLogLogger *logger) |
| 4184 | 137 { |
| 7431 | 138 g_return_if_fail(logger); |
| 139 current_logger = logger; | |
| 7436 | 140 } |
| 4184 | 141 |
| 7431 | 142 GaimLogLogger *gaim_log_logger_get() |
| 143 { | |
| 144 return current_logger; | |
| 145 } | |
| 4184 | 146 |
| 7431 | 147 GList *gaim_log_logger_get_options(void) |
| 148 { | |
| 149 GSList *n; | |
| 150 GList *list = NULL; | |
| 151 GaimLogLogger *data; | |
| 4184 | 152 |
| 7431 | 153 for (n = loggers; n; n = n->next) { |
| 154 data = n->data; | |
| 155 if (!data->write) | |
| 156 continue; | |
| 157 list = g_list_append(list, data->name); | |
| 158 list = g_list_append(list, data->id); | |
| 4184 | 159 } |
| 160 | |
| 7431 | 161 return list; |
| 162 } | |
| 163 | |
| 7436 | 164 static gint log_compare(gconstpointer y, gconstpointer z) |
| 7431 | 165 { |
| 7436 | 166 const GaimLog *a = y; |
| 167 const GaimLog *b = z; | |
| 168 | |
| 7431 | 169 return b->time - a->time; |
| 170 } | |
| 171 | |
| 172 GList *gaim_log_get_logs(const char *name, GaimAccount *account) | |
| 173 { | |
| 174 GList *logs = NULL; | |
| 175 GSList *n; | |
| 176 for (n = loggers; n; n = n->next) { | |
| 177 GaimLogLogger *logger = n->data; | |
| 178 if (!logger->list) | |
| 179 continue; | |
| 180 logs = g_list_concat(logs, logger->list(name, account)); | |
| 181 } | |
| 7436 | 182 |
| 7431 | 183 return g_list_sort(logs, log_compare); |
| 184 } | |
| 185 | |
| 186 void gaim_log_init(void) | |
| 7436 | 187 { |
| 7431 | 188 gaim_prefs_add_none("/core/logging"); |
| 189 gaim_prefs_add_string("/core/logging/format", "txt"); | |
| 190 gaim_log_logger_add(&txt_logger); | |
| 191 gaim_log_logger_add(&old_logger); | |
| 192 gaim_prefs_connect_callback("/core/logging/format", | |
| 193 logger_pref_cb, NULL); | |
| 194 gaim_prefs_trigger_callback("/core/logging/format"); | |
| 195 } | |
| 196 | |
| 197 /**************************************************************************** | |
| 198 * LOGGERS ****************************************************************** | |
| 199 ****************************************************************************/ | |
| 200 | |
| 201 static GList *log_lister_common(const char *screenname, GaimAccount *account, const char *ext, GaimLogLogger *logger) | |
| 202 { | |
| 203 GDir *dir; | |
| 204 GList *list = NULL; | |
| 205 const char *filename; | |
| 206 char *me = g_strdup(gaim_normalize(account, gaim_account_get_username(account))); | |
| 4184 | 207 |
| 7431 | 208 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO |
| 209 (gaim_find_prpl(gaim_account_get_protocol(account)))->list_icon(account, NULL); | |
| 210 char *path = g_build_filename(gaim_user_dir(), "logs", prpl, me, gaim_normalize(account, screenname), NULL); | |
| 211 | |
| 212 if (!(dir = g_dir_open(path, 0, NULL))) { | |
| 213 g_free(path); | |
| 214 g_free(me); | |
| 215 return NULL; | |
| 216 } | |
| 217 while ((filename = g_dir_read_name(dir))) { | |
| 218 if (g_str_has_suffix(filename, ext)) { | |
| 219 const char *l = filename; | |
| 220 struct tm time; | |
| 221 GaimLog *log; | |
| 222 char d[5]; | |
| 7436 | 223 |
| 7431 | 224 strncpy(d, l, 4); |
| 225 d[4] = '\0'; | |
| 226 time.tm_year = atoi(d) - 1900; | |
| 227 l = l + 5; | |
| 228 | |
| 229 strncpy(d, l, 2); | |
| 230 d[2] = '\0'; | |
| 231 time.tm_mon = atoi(d) - 1; | |
| 232 l = l + 3; | |
| 233 | |
| 234 strncpy(d, l, 2); | |
| 235 time.tm_mday = atoi(d); | |
| 236 l = l + 3; | |
| 237 | |
| 238 strncpy(d, l, 2); | |
| 239 time.tm_hour = atoi(d); | |
| 240 l = l + 2; | |
| 7436 | 241 |
| 7431 | 242 strncpy(d, l, 2); |
| 243 time.tm_min = atoi(d); | |
| 244 l = l + 2; | |
| 245 | |
| 246 strncpy(d, l, 2); | |
| 247 time.tm_sec = atoi(d); | |
| 248 l = l + 2; | |
| 249 log = gaim_log_new(GAIM_LOG_IM, screenname, account, mktime(&time)); | |
| 250 log->logger = logger; | |
| 251 log->logger_data = g_build_filename(path, filename, NULL); | |
| 252 list = g_list_append(list, log); | |
| 4184 | 253 } |
| 254 } | |
| 7431 | 255 g_dir_close(dir); |
| 256 return list; | |
| 257 } | |
| 4184 | 258 |
| 7431 | 259 #if 0 /* Maybe some other time. */ |
| 7443 | 260 /**************** |
| 7431 | 261 ** XML LOGGER ** |
| 262 ****************/ | |
| 263 | |
| 264 static const char *str_from_msg_type (GaimMessageFlags type) | |
| 265 { | |
| 7443 | 266 |
| 7431 | 267 return ""; |
| 7443 | 268 |
| 7431 | 269 } |
| 270 | |
| 7443 | 271 static void xml_logger_write(GaimLog *log, |
| 272 GaimMessageFlags type, | |
| 7431 | 273 const char *from, time_t time, const char *message) |
| 274 { | |
| 275 char date[64]; | |
| 276 char *xhtml = NULL; | |
| 277 if (!log->logger_data) { | |
| 278 /* This log is new. We could use the loggers 'new' function, but | |
| 279 * creating a new file there would result in empty files in the case | |
| 280 * that you open a convo with someone, but don't say anything. | |
| 281 */ | |
| 282 char *ud = gaim_user_dir(); | |
| 283 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); | |
| 284 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO | |
| 285 (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL); | |
| 286 char *dir; | |
| 287 FILE *file; | |
| 288 | |
| 289 strftime(date, sizeof(date), "%F.%H%M%S.xml", localtime(&log->time)); | |
| 7443 | 290 |
| 7431 | 291 dir = g_build_filename(ud, "logs", NULL); |
| 292 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 293 g_free(dir); | |
| 7443 | 294 dir = g_build_filename(ud, "logs", |
| 7431 | 295 prpl, NULL); |
| 296 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 297 g_free(dir); | |
| 7443 | 298 dir = g_build_filename(ud, "logs", |
| 7431 | 299 prpl, guy, NULL); |
| 300 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 7443 | 301 g_free(dir); |
| 302 dir = g_build_filename(ud, "logs", | |
| 7431 | 303 prpl, guy, gaim_normalize(log->account, log->name), NULL); |
| 304 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 7443 | 305 |
| 7431 | 306 char *filename = g_build_filename(dir, date, NULL); |
| 307 g_free(dir); | |
| 7443 | 308 |
| 7431 | 309 file = fopen(dir, "r"); |
| 310 if(!file) | |
| 311 mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 312 else | |
| 313 fclose(file); | |
| 7443 | 314 |
| 7431 | 315 log->logger_data = fopen(filename, "a"); |
| 316 if (!log->logger_data) { | |
| 317 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | |
| 318 return; | |
| 319 } | |
| 320 fprintf(log->logger_data, "<?xml version='1.0' encoding='UTF-8' ?>\n" | |
| 321 "<?xml-stylesheet href='file:///usr/src/web/htdocs/log-stylesheet.xsl' type='text/xml' ?>\n"); | |
| 7443 | 322 |
| 7431 | 323 strftime(date, sizeof(date), "%F %T", localtime(&log->time)); |
| 324 fprintf(log->logger_data, "<conversation time='%s' screenname='%s' protocol='%s'>\n", | |
| 325 date, log->name, prpl); | |
| 326 } | |
| 7443 | 327 |
| 7431 | 328 strftime(date, sizeof(date), "%T", localtime(&time)); |
| 329 gaim_markup_html_to_xhtml(message, &xhtml, NULL); | |
| 330 if (from) | |
| 7443 | 331 fprintf(log->logger_data, "<message %s %s from='%s' time='%s'>%s</message>\n", |
| 332 str_from_msg_type(type), | |
| 7431 | 333 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
| 334 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
| 335 from, date, xhtml); | |
| 336 else | |
| 7443 | 337 fprintf(log->logger_data, "<message %s %s time='%s'>%s</message>\n", |
| 338 str_from_msg_type(type), | |
| 7431 | 339 type & GAIM_MESSAGE_SEND ? "direction='sent'" : |
| 340 type & GAIM_MESSAGE_RECV ? "direction='received'" : "", | |
| 7443 | 341 date, xhtml): |
| 7431 | 342 fflush(log->logger_data); |
| 343 g_free(xhtml); | |
| 7443 | 344 } |
| 345 | |
| 7431 | 346 static void xml_logger_finalize(GaimLog *log) |
| 347 { | |
| 348 if (log->logger_data) { | |
| 349 fprintf(log->logger_data, "</conversation>\n"); | |
| 350 fclose(log->logger_data); | |
| 351 log->logger_data = NULL; | |
| 352 } | |
| 353 } | |
| 7443 | 354 |
| 7431 | 355 static GList *xml_logger_list(const char *sn, GaimAccount *account) |
| 356 { | |
| 357 return log_lister_common(sn, account, ".xml", &xml_logger); | |
| 4184 | 358 } |
| 359 | |
| 7431 | 360 static GaimLogLogger xml_logger = { |
| 361 N_("XML"), "xml", | |
| 362 NULL, | |
| 363 xml_logger_write, | |
| 364 xml_logger_finalize, | |
| 365 xml_logger_list, | |
| 366 NULL | |
| 367 }; | |
| 368 #endif | |
|
5563
9eb5b13fd412
[gaim-migrate @ 5965]
Christian Hammond <chipx86@chipx86.com>
parents:
5560
diff
changeset
|
369 |
| 7431 | 370 /**************************** |
| 371 ** PLAIN TEXT LOGGER ******* | |
| 372 ****************************/ | |
| 4184 | 373 |
| 7436 | 374 static void txt_logger_write(GaimLog *log, |
| 375 GaimMessageFlags type, | |
| 7431 | 376 const char *from, time_t time, const char *message) |
| 377 { | |
| 378 char date[64]; | |
| 379 char *stripped = NULL; | |
| 380 if (!log->logger_data) { | |
| 381 /* This log is new. We could use the loggers 'new' function, but | |
| 382 * creating a new file there would result in empty files in the case | |
| 383 * that you open a convo with someone, but don't say anything. | |
| 384 */ | |
| 385 char *ud = gaim_user_dir(); | |
| 386 char *guy = g_strdup(gaim_normalize(log->account, gaim_account_get_username(log->account))); | |
| 387 const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO | |
| 388 (gaim_find_prpl(gaim_account_get_protocol(log->account)))->list_icon(log->account, NULL); | |
| 389 char *dir; | |
| 390 FILE *file; | |
| 7436 | 391 |
| 7431 | 392 strftime(date, sizeof(date), "%F.%H%M%S.txt", localtime(&log->time)); |
| 7436 | 393 |
| 7431 | 394 dir = g_build_filename(ud, "logs", NULL); |
| 395 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 396 g_free(dir); | |
| 7436 | 397 dir = g_build_filename(ud, "logs", |
| 7431 | 398 prpl, NULL); |
| 399 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 400 g_free(dir); | |
| 7436 | 401 dir = g_build_filename(ud, "logs", |
| 7431 | 402 prpl, guy, NULL); |
| 403 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 7436 | 404 g_free(dir); |
| 405 dir = g_build_filename(ud, "logs", | |
| 7431 | 406 prpl, guy, gaim_normalize(log->account, log->name), NULL); |
| 407 mkdir (dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 7436 | 408 |
| 7431 | 409 char *filename = g_build_filename(dir, date, NULL); |
| 410 g_free(dir); | |
| 7436 | 411 |
| 7431 | 412 file = fopen(dir, "r"); |
| 413 if(!file) | |
| 414 mkdir(dir, S_IRUSR | S_IWUSR | S_IXUSR); | |
| 415 else | |
| 416 fclose(file); | |
| 7436 | 417 |
| 7431 | 418 log->logger_data = fopen(filename, "a"); |
| 419 if (!log->logger_data) { | |
| 420 gaim_debug(GAIM_DEBUG_ERROR, "log", "Could not create log file %s\n", filename); | |
| 421 return; | |
| 4184 | 422 } |
| 7431 | 423 strftime(date, sizeof(date), "%F %T", localtime(&log->time)); |
| 424 fprintf(log->logger_data, "Conversation with %s at %s on %s (%s)\n", | |
| 425 log->name, date, gaim_account_get_username(log->account), prpl); | |
| 426 } | |
| 7436 | 427 |
| 7431 | 428 strftime(date, sizeof(date), "%T", localtime(&time)); |
| 429 stripped = gaim_markup_strip_html(message); | |
| 430 fprintf(log->logger_data, "(%s) %s%s %s\n", date, from ? from : "", from ? ":" : "", stripped); | |
| 431 fflush(log->logger_data); | |
| 432 g_free(stripped); | |
| 433 } | |
| 434 | |
| 435 static void txt_logger_finalize(GaimLog *log) | |
| 436 { | |
| 437 if (log->logger_data) | |
| 438 fclose(log->logger_data); | |
| 439 } | |
| 440 | |
| 441 static GList *txt_logger_list(const char *sn, GaimAccount *account) | |
| 442 { | |
| 443 return log_lister_common(sn, account, ".txt", &txt_logger); | |
| 444 } | |
| 445 | |
| 446 static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags) | |
| 447 { | |
| 448 char *read, *minus_header; | |
| 449 if (!log->logger_data) | |
| 450 return g_strdup("<font color='red'><b>log->logger_data was NULL!</b></font>"); | |
| 451 if (g_file_get_contents((char *)log->logger_data, &read, NULL, NULL)) { | |
| 452 minus_header = strchr(read, '\n'); | |
| 453 if (!minus_header) | |
| 454 minus_header = g_strdup(read); | |
| 7436 | 455 else |
| 7431 | 456 minus_header = g_strdup(minus_header + 1); |
| 457 g_free(read); | |
| 458 return minus_header; | |
| 459 } | |
| 460 return g_strdup(_("<font color='red'><b>Could not read file: %s</b></font>")); | |
| 7436 | 461 } |
| 7431 | 462 |
| 463 static GaimLogLogger txt_logger = { | |
| 464 N_("Plain text"), "txt", | |
| 465 NULL, | |
| 466 txt_logger_write, | |
| 467 txt_logger_finalize, | |
| 468 txt_logger_list, | |
| 469 txt_logger_read | |
| 470 }; | |
| 471 | |
| 472 /**************** | |
| 473 * OLD LOGGER *** | |
| 474 ****************/ | |
| 475 | |
| 476 /* The old logger doesn't write logs, only reads them. This is to include | |
| 477 * old logs in the log viewer transparently. | |
| 478 */ | |
| 479 | |
| 480 struct old_logger_data { | |
| 481 char *path; | |
| 482 int offset; | |
| 483 int length; | |
| 484 }; | |
| 485 | |
| 7436 | 486 static GList *old_logger_list(const char *sn, GaimAccount *account) |
| 7431 | 487 { |
| 488 FILE *file; | |
| 489 char buf[BUF_LONG]; | |
| 490 struct tm tm; | |
| 491 struct old_logger_data *data = NULL; | |
| 492 char day[4], month[4], year[5]; | |
| 493 char *logfile = g_strdup_printf("%s.log", gaim_normalize(account, sn)); | |
| 494 char *date; | |
| 495 char *path = g_build_filename(gaim_user_dir(), "logs", logfile, NULL); | |
| 496 char *newlog; | |
| 497 | |
| 498 GaimLog *log = NULL; | |
| 499 GList *list = NULL; | |
| 500 | |
| 501 if (!(file = fopen(path, "r"))) | |
| 502 return NULL; | |
| 7436 | 503 |
| 7431 | 504 while (fgets(buf, BUF_LONG, file)) { |
| 505 if ((newlog = strstr(buf, "---- New C"))) { | |
| 506 int length; | |
| 507 int offset; | |
| 508 GDate gdate; | |
| 509 char convostart[32]; | |
| 510 char *temp = strchr(buf, '@'); | |
| 7436 | 511 |
| 7431 | 512 if (temp == NULL || strlen(temp) < 2) |
| 513 continue; | |
| 7436 | 514 |
| 7431 | 515 temp++; |
| 516 length = strcspn(temp, "-"); | |
| 517 if (length > 31) length = 31; | |
| 7436 | 518 |
| 7431 | 519 offset = ftell(file); |
| 7436 | 520 |
| 7431 | 521 if (data) { |
| 7436 | 522 data->length = offset - data->offset - length; |
| 523 if(strstr(buf, "----</H3><BR>")) { | |
| 524 data->length -= | |
| 525 strlen("<HR><BR><H3 Align=Center> ---- New Conversation @ ") + | |
| 526 strlen("----</H3><BR>"); | |
| 527 } else { | |
| 528 data->length -= | |
| 529 strlen("---- New Conversation @ ") + strlen("----"); | |
| 530 } | |
| 531 | |
| 7431 | 532 if (data->length != 0) |
| 533 list = g_list_append(list, log); | |
| 534 else | |
| 535 gaim_log_free(log); | |
| 536 } | |
| 537 | |
| 538 log = gaim_log_new(GAIM_LOG_IM, sn, account, -1); | |
| 539 log->logger = &old_logger; | |
| 540 | |
| 7436 | 541 data = g_new0(struct old_logger_data, 1); |
| 7431 | 542 data->offset = offset; |
| 543 data->path = path; | |
| 544 log->logger_data = data; | |
| 545 | |
| 7436 | 546 |
| 7431 | 547 g_snprintf(convostart, length, "%s", temp); |
| 548 sscanf(convostart, "%*s %s %s %d:%d:%d %s", | |
| 549 month, day, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, year); | |
| 550 date = g_strdup_printf("%s %s %s", month, day, year); | |
| 551 g_date_set_parse(&gdate, date); | |
| 552 tm.tm_mday = g_date_get_day(&gdate); | |
| 553 tm.tm_mon = g_date_get_month(&gdate) - 1; | |
| 554 tm.tm_year = g_date_get_year(&gdate) - 1900; | |
| 555 log->time = mktime(&tm); | |
| 556 | |
| 4184 | 557 } |
| 558 } | |
| 7431 | 559 fclose(file); |
| 560 return list; | |
| 4184 | 561 } |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
562 |
| 7431 | 563 char * old_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
564 { |
| 7431 | 565 struct old_logger_data *data = log->logger_data; |
| 566 FILE *file = fopen(data->path, "r"); | |
| 567 char *read = g_malloc(data->length + 1); | |
| 568 fseek(file, data->offset, SEEK_SET); | |
| 569 fread(read, data->length, 1, file); | |
| 570 read[data->length] = '\0'; | |
| 7436 | 571 *flags = 0; |
| 572 if(strstr(read, "<BR>")) | |
| 573 *flags |= GAIM_LOG_READ_NO_NEWLINE; | |
| 7431 | 574 return read; |
| 575 } | |
|
4359
5fb47ec9bfe4
[gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
4227
diff
changeset
|
576 |
| 7431 | 577 static GaimLogLogger old_logger = { |
| 578 "old logger", "old", | |
| 579 NULL, NULL, NULL, | |
| 580 old_logger_list, | |
| 581 old_logger_read | |
| 582 }; |
