Mercurial > pidgin.yaz
comparison plugins/log_reader.c @ 11503:cd0c8830d881
[gaim-migrate @ 13748]
Making gaim_log_logger a varargs function so it can be expanded as GaimLogLogger expands, without breaking compatibility. I'm anticipating adding a find() function some day for a database logger. This commit also makes use of gaim_log_logger_new() everywhere it should be used, removing the old static structures.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 11 Sep 2005 05:14:52 +0000 |
parents | b8f6f1fd30c0 |
children | 994f1c7bee8b |
comparison
equal
deleted
inserted
replaced
11502:b858f992b566 | 11503:cd0c8830d881 |
---|---|
24 #ifdef _WIN32 | 24 #ifdef _WIN32 |
25 #include "win32dep.h" | 25 #include "win32dep.h" |
26 #endif | 26 #endif |
27 | 27 |
28 /* Where is the Windows partition mounted? */ | 28 /* Where is the Windows partition mounted? */ |
29 #define LOG_READER_WINDOWS_MOUNT_POINT "/mnt/windows" | 29 #ifndef GAIM_LOG_READER_WINDOWS_MOUNT_POINT |
30 #define GAIM_LOG_READER_WINDOWS_MOUNT_POINT "/mnt/windows" | |
31 #endif | |
30 | 32 |
31 enum name_guesses { | 33 enum name_guesses { |
32 NAME_GUESS_UNKNOWN, | 34 NAME_GUESS_UNKNOWN, |
33 NAME_GUESS_ME, | 35 NAME_GUESS_ME, |
34 NAME_GUESS_THEM | 36 NAME_GUESS_THEM |
41 | 43 |
42 /* The adium logger doesn't write logs, only reads them. This is to include | 44 /* The adium logger doesn't write logs, only reads them. This is to include |
43 * Adium logs in the log viewer transparently. | 45 * Adium logs in the log viewer transparently. |
44 */ | 46 */ |
45 | 47 |
46 static GaimLogLogger adium_logger; | 48 static GaimLogLogger *adium_logger; |
47 | 49 |
48 enum adium_log_type { | 50 enum adium_log_type { |
49 ADIUM_HTML, | 51 ADIUM_HTML, |
50 ADIUM_TEXT, | 52 ADIUM_TEXT, |
51 }; | 53 }; |
153 | 155 |
154 tm.tm_year -= 1900; | 156 tm.tm_year -= 1900; |
155 tm.tm_mon -= 1; | 157 tm.tm_mon -= 1; |
156 | 158 |
157 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, mktime(&tm)); | 159 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, mktime(&tm)); |
158 log->logger = &adium_logger; | 160 log->logger = adium_logger; |
159 log->logger_data = data; | 161 log->logger_data = data; |
160 | 162 |
161 list = g_list_append(list, log); | 163 list = g_list_append(list, log); |
162 } | 164 } |
163 } else if (g_str_has_suffix(file, ".adiumLog")) { | 165 } else if (g_str_has_suffix(file, ".adiumLog")) { |
213 data = g_new0(struct adium_logger_data, 1); | 215 data = g_new0(struct adium_logger_data, 1); |
214 data->path = filename; | 216 data->path = filename; |
215 data->type = ADIUM_TEXT; | 217 data->type = ADIUM_TEXT; |
216 | 218 |
217 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, mktime(&tm)); | 219 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, mktime(&tm)); |
218 log->logger = &adium_logger; | 220 log->logger = adium_logger; |
219 log->logger_data = data; | 221 log->logger_data = data; |
220 | 222 |
221 list = g_list_append(list, log); | 223 list = g_list_append(list, log); |
222 } | 224 } |
223 } | 225 } |
316 data = log->logger_data; | 318 data = log->logger_data; |
317 | 319 |
318 g_free(data->path); | 320 g_free(data->path); |
319 } | 321 } |
320 | 322 |
321 static GaimLogLogger adium_logger = { | |
322 N_("Adium Log Reader"), "adium", | |
323 NULL, NULL, | |
324 adium_logger_finalize, | |
325 adium_logger_list, | |
326 adium_logger_read, | |
327 adium_logger_size, | |
328 NULL, | |
329 NULL, | |
330 NULL | |
331 }; | |
332 | |
333 | 323 |
334 /***************************************************************************** | 324 /***************************************************************************** |
335 * Fire Logger * | 325 * Fire Logger * |
336 *****************************************************************************/ | 326 *****************************************************************************/ |
337 | 327 |
338 /* The fire logger doesn't write logs, only reads them. This is to include | 328 /* The fire logger doesn't write logs, only reads them. This is to include |
339 * Fire logs in the log viewer transparently. | 329 * Fire logs in the log viewer transparently. |
340 */ | 330 */ |
341 | 331 |
342 static GaimLogLogger fire_logger; | 332 static GaimLogLogger *fire_logger; |
343 | 333 |
344 struct fire_logger_data { | 334 struct fire_logger_data { |
345 }; | 335 }; |
346 | 336 |
347 static GList *fire_logger_list(GaimLogType type, const char *sn, GaimAccount *account) | 337 static GList *fire_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
348 { | 338 { |
349 // TODO: Do something here. | 339 /* TODO: Do something here. */ |
350 return NULL; | 340 return NULL; |
351 } | 341 } |
352 | 342 |
353 static char * fire_logger_read (GaimLog *log, GaimLogReadFlags *flags) | 343 static char * fire_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
354 { | 344 { |
356 | 346 |
357 g_return_val_if_fail(log != NULL, g_strdup("")); | 347 g_return_val_if_fail(log != NULL, g_strdup("")); |
358 | 348 |
359 data = log->logger_data; | 349 data = log->logger_data; |
360 | 350 |
361 // TODO: Do something here. | 351 /* TODO: Do something here. */ |
362 return g_strdup(""); | 352 return g_strdup(""); |
363 } | 353 } |
364 | 354 |
365 static int fire_logger_size (GaimLog *log) | 355 static int fire_logger_size (GaimLog *log) |
366 { | 356 { |
367 g_return_val_if_fail(log != NULL, 0); | 357 g_return_val_if_fail(log != NULL, 0); |
368 | 358 |
369 if (gaim_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) | 359 if (gaim_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) |
370 return 0; | 360 return 0; |
371 | 361 |
372 // TODO: Do something here. | 362 /* TODO: Do something here. */ |
373 return 0; | 363 return 0; |
374 } | 364 } |
375 | 365 |
376 static void fire_logger_finalize(GaimLog *log) | 366 static void fire_logger_finalize(GaimLog *log) |
377 { | 367 { |
378 g_return_if_fail(log != NULL); | 368 g_return_if_fail(log != NULL); |
379 | 369 |
380 // TODO: Do something here. | 370 /* TODO: Do something here. */ |
381 } | 371 } |
382 | |
383 static GaimLogLogger fire_logger = { | |
384 N_("Fire Log Reader"), "fire", | |
385 NULL, NULL, | |
386 fire_logger_finalize, | |
387 fire_logger_list, | |
388 fire_logger_read, | |
389 fire_logger_size, | |
390 NULL, | |
391 NULL, | |
392 NULL | |
393 }; | |
394 | 372 |
395 | 373 |
396 /***************************************************************************** | 374 /***************************************************************************** |
397 * Messenger Plus! Logger * | 375 * Messenger Plus! Logger * |
398 *****************************************************************************/ | 376 *****************************************************************************/ |
399 | 377 |
400 /* The messenger_plus logger doesn't write logs, only reads them. This is to include | 378 /* The messenger_plus logger doesn't write logs, only reads them. This is to include |
401 * Messenger Plus! logs in the log viewer transparently. | 379 * Messenger Plus! logs in the log viewer transparently. |
402 */ | 380 */ |
403 | 381 |
404 static GaimLogLogger messenger_plus_logger; | 382 static GaimLogLogger *messenger_plus_logger; |
405 | 383 |
406 struct messenger_plus_logger_data { | 384 struct messenger_plus_logger_data { |
407 }; | 385 }; |
408 | 386 |
409 static GList *messenger_plus_logger_list(GaimLogType type, const char *sn, GaimAccount *account) | 387 static GList *messenger_plus_logger_list(GaimLogType type, const char *sn, GaimAccount *account) |
410 { | 388 { |
411 // TODO: Do something here. | 389 /* TODO: Do something here. */ |
412 return NULL; | 390 return NULL; |
413 } | 391 } |
414 | 392 |
415 static char * messenger_plus_logger_read (GaimLog *log, GaimLogReadFlags *flags) | 393 static char * messenger_plus_logger_read (GaimLog *log, GaimLogReadFlags *flags) |
416 { | 394 { |
418 | 396 |
419 g_return_val_if_fail(log != NULL, g_strdup("")); | 397 g_return_val_if_fail(log != NULL, g_strdup("")); |
420 | 398 |
421 data = log->logger_data; | 399 data = log->logger_data; |
422 | 400 |
423 // TODO: Do something here. | 401 /* TODO: Do something here. */ |
424 return g_strdup(""); | 402 return g_strdup(""); |
425 } | 403 } |
426 | 404 |
427 static int messenger_plus_logger_size (GaimLog *log) | 405 static int messenger_plus_logger_size (GaimLog *log) |
428 { | 406 { |
429 g_return_val_if_fail(log != NULL, 0); | 407 g_return_val_if_fail(log != NULL, 0); |
430 | 408 |
431 if (gaim_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) | 409 if (gaim_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) |
432 return 0; | 410 return 0; |
433 | 411 |
434 // TODO: Do something here. | 412 /* TODO: Do something here. */ |
435 return 0; | 413 return 0; |
436 } | 414 } |
437 | 415 |
438 static void messenger_plus_logger_finalize(GaimLog *log) | 416 static void messenger_plus_logger_finalize(GaimLog *log) |
439 { | 417 { |
440 g_return_if_fail(log != NULL); | 418 g_return_if_fail(log != NULL); |
441 | 419 |
442 // TODO: Do something here. | 420 /* TODO: Do something here. */ |
443 } | 421 } |
444 | |
445 static GaimLogLogger messenger_plus_logger = { | |
446 N_("Messenger Plus Log Reader"), "messenger_plus", | |
447 NULL, NULL, | |
448 messenger_plus_logger_finalize, | |
449 messenger_plus_logger_list, | |
450 messenger_plus_logger_read, | |
451 messenger_plus_logger_size, | |
452 NULL, | |
453 NULL, | |
454 NULL | |
455 }; | |
456 | 422 |
457 | 423 |
458 /***************************************************************************** | 424 /***************************************************************************** |
459 * MSN Messenger Logger * | 425 * MSN Messenger Logger * |
460 *****************************************************************************/ | 426 *****************************************************************************/ |
461 | 427 |
462 /* The msn logger doesn't write logs, only reads them. This is to include | 428 /* The msn logger doesn't write logs, only reads them. This is to include |
463 * MSN Messenger message histories in the log viewer transparently. | 429 * MSN Messenger message histories in the log viewer transparently. |
464 */ | 430 */ |
465 | 431 |
466 static GaimLogLogger msn_logger; | 432 static GaimLogLogger *msn_logger; |
467 | 433 |
468 struct msn_logger_data { | 434 struct msn_logger_data { |
469 xmlnode *root; | 435 xmlnode *root; |
470 xmlnode *message; | 436 xmlnode *message; |
471 const char *session_id; | 437 const char *session_id; |
763 data->session_id = session_id; | 729 data->session_id = session_id; |
764 data->text = NULL; | 730 data->text = NULL; |
765 data->last_log = FALSE; | 731 data->last_log = FALSE; |
766 | 732 |
767 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, msn_logger_parse_timestamp(message)); | 733 log = gaim_log_new(GAIM_LOG_IM, sn, account, NULL, msn_logger_parse_timestamp(message)); |
768 log->logger = &msn_logger; | 734 log->logger = msn_logger; |
769 log->logger_data = data; | 735 log->logger_data = data; |
770 | 736 |
771 list = g_list_append(list, log); | 737 list = g_list_append(list, log); |
772 } | 738 } |
773 old_session_id = session_id; | 739 old_session_id = session_id; |
1061 | 1027 |
1062 if (data->text) | 1028 if (data->text) |
1063 g_string_free(data->text, FALSE); | 1029 g_string_free(data->text, FALSE); |
1064 } | 1030 } |
1065 | 1031 |
1066 static GaimLogLogger msn_logger = { | |
1067 N_("MSN Log Reader"), "msn", | |
1068 NULL, NULL, | |
1069 msn_logger_finalize, | |
1070 msn_logger_list, | |
1071 msn_logger_read, | |
1072 msn_logger_size, | |
1073 NULL, | |
1074 NULL, | |
1075 NULL | |
1076 }; | |
1077 | |
1078 | 1032 |
1079 /***************************************************************************** | 1033 /***************************************************************************** |
1080 * Trillian Logger * | 1034 * Trillian Logger * |
1081 *****************************************************************************/ | 1035 *****************************************************************************/ |
1082 | 1036 |
1083 /* The trillian logger doesn't write logs, only reads them. This is to include | 1037 /* The trillian logger doesn't write logs, only reads them. This is to include |
1084 * Trillian logs in the log viewer transparently. | 1038 * Trillian logs in the log viewer transparently. |
1085 */ | 1039 */ |
1086 | 1040 |
1087 static GaimLogLogger trillian_logger; | 1041 static GaimLogLogger *trillian_logger; |
1088 static void trillian_logger_finalize(GaimLog *log); | 1042 static void trillian_logger_finalize(GaimLog *log); |
1089 | 1043 |
1090 struct trillian_logger_data { | 1044 struct trillian_logger_data { |
1091 char *path; /* FIXME: Change this to use GaimStringref like log.c:old_logger_list */ | 1045 char *path; /* FIXME: Change this to use GaimStringref like log.c:old_logger_list */ |
1092 int offset; | 1046 int offset; |
1289 data->their_nickname = | 1243 data->their_nickname = |
1290 g_strdup(their_nickname); | 1244 g_strdup(their_nickname); |
1291 | 1245 |
1292 log = gaim_log_new(GAIM_LOG_IM, | 1246 log = gaim_log_new(GAIM_LOG_IM, |
1293 sn, account, NULL, mktime(&tm)); | 1247 sn, account, NULL, mktime(&tm)); |
1294 log->logger = &trillian_logger; | 1248 log->logger = trillian_logger; |
1295 log->logger_data = data; | 1249 log->logger_data = data; |
1296 | 1250 |
1297 list = g_list_append(list, log); | 1251 list = g_list_append(list, log); |
1298 } | 1252 } |
1299 } | 1253 } |
1430 while (*timestamp && *timestamp != ']') | 1384 while (*timestamp && *timestamp != ']') |
1431 timestamp++; | 1385 timestamp++; |
1432 if (*timestamp == ']') { | 1386 if (*timestamp == ']') { |
1433 *timestamp = '\0'; | 1387 *timestamp = '\0'; |
1434 line++; | 1388 line++; |
1435 // TODO: Parse the timestamp and convert it to Gaim's format. | 1389 /* TODO: Parse the timestamp and convert it to Gaim's format. */ |
1436 g_string_append_printf(formatted, | 1390 g_string_append_printf(formatted, |
1437 "<font size=\"2\">(%s)</font> ", line); | 1391 "<font size=\"2\">(%s)</font> ", line); |
1438 line = timestamp; | 1392 line = timestamp; |
1439 if (line[1] && line[2]) | 1393 if (line[1] && line[2]) |
1440 line += 2; | 1394 line += 2; |
1600 g_free(data->path); | 1554 g_free(data->path); |
1601 g_free(data->their_nickname); | 1555 g_free(data->their_nickname); |
1602 | 1556 |
1603 } | 1557 } |
1604 | 1558 |
1605 static GaimLogLogger trillian_logger = { | |
1606 N_("Trillian Log Reader"), "trillian", | |
1607 NULL, NULL, | |
1608 trillian_logger_finalize, | |
1609 trillian_logger_list, | |
1610 trillian_logger_read, | |
1611 trillian_logger_size, | |
1612 NULL, | |
1613 NULL, | |
1614 NULL | |
1615 }; | |
1616 | |
1617 | 1559 |
1618 /***************************************************************************** | 1560 /***************************************************************************** |
1619 * Plugin Code * | 1561 * Plugin Code * |
1620 *****************************************************************************/ | 1562 *****************************************************************************/ |
1621 | 1563 |
1684 #endif | 1626 #endif |
1685 path = g_build_filename( | 1627 path = g_build_filename( |
1686 #ifdef _WIN32 | 1628 #ifdef _WIN32 |
1687 folder, | 1629 folder, |
1688 #else | 1630 #else |
1689 LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", | 1631 GAIM_LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", |
1690 g_get_user_name(), "My Documents", | 1632 g_get_user_name(), "My Documents", |
1691 #endif | 1633 #endif |
1692 "My Chat Logs", NULL); | 1634 "My Chat Logs", NULL); |
1693 #ifdef _WIN32 | 1635 #ifdef _WIN32 |
1694 g_free(folder); | 1636 g_free(folder); |
1710 #endif | 1652 #endif |
1711 path = g_build_filename( | 1653 path = g_build_filename( |
1712 #ifdef _WIN32 | 1654 #ifdef _WIN32 |
1713 folder, | 1655 folder, |
1714 #else | 1656 #else |
1715 LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", | 1657 GAIM_LOG_READER_WINDOWS_MOUNT_POINT, "Documents and Settings", |
1716 g_get_user_name(), "My Documents", | 1658 g_get_user_name(), "My Documents", |
1717 #endif | 1659 #endif |
1718 "My Received Files", NULL); | 1660 "My Received Files", NULL); |
1719 #ifdef _WIN32 | 1661 #ifdef _WIN32 |
1720 g_free(folder); | 1662 g_free(folder); |
1863 #endif | 1805 #endif |
1864 path = g_build_filename( | 1806 path = g_build_filename( |
1865 #ifdef _WIN32 | 1807 #ifdef _WIN32 |
1866 folder, | 1808 folder, |
1867 #else | 1809 #else |
1868 LOG_READER_WINDOWS_MOUNT_POINT, "Program Files", | 1810 GAIM_LOG_READER_WINDOWS_MOUNT_POINT, "Program Files", |
1869 #endif | 1811 #endif |
1870 "Trillian", "users", "default", "logs", NULL); | 1812 "Trillian", "users", "default", "logs", NULL); |
1871 #ifdef _WIN32 | 1813 #ifdef _WIN32 |
1872 g_free(folder); | 1814 g_free(folder); |
1873 } else /* !folder */ | 1815 } else /* !folder */ |
1885 static gboolean | 1827 static gboolean |
1886 plugin_load(GaimPlugin *plugin) | 1828 plugin_load(GaimPlugin *plugin) |
1887 { | 1829 { |
1888 g_return_val_if_fail(plugin != NULL, FALSE); | 1830 g_return_val_if_fail(plugin != NULL, FALSE); |
1889 | 1831 |
1890 gaim_log_logger_add(&adium_logger); | 1832 adium_logger = gaim_log_logger_new("adium", "Adium", 6, |
1891 gaim_log_logger_add(&fire_logger); | 1833 NULL, |
1892 gaim_log_logger_add(&messenger_plus_logger); | 1834 NULL, |
1893 gaim_log_logger_add(&msn_logger); | 1835 adium_logger_finalize, |
1894 gaim_log_logger_add(&trillian_logger); | 1836 adium_logger_list, |
1837 adium_logger_read, | |
1838 adium_logger_size); | |
1839 gaim_log_logger_add(adium_logger); | |
1840 | |
1841 fire_logger = gaim_log_logger_new("fire", "Fire", 6, | |
1842 NULL, | |
1843 NULL, | |
1844 fire_logger_finalize, | |
1845 fire_logger_list, | |
1846 fire_logger_read, | |
1847 fire_logger_size); | |
1848 gaim_log_logger_add(fire_logger); | |
1849 | |
1850 messenger_plus_logger = gaim_log_logger_new("messenger_plus", "Messenger Plus!", 6, | |
1851 NULL, | |
1852 NULL, | |
1853 messenger_plus_logger_finalize, | |
1854 messenger_plus_logger_list, | |
1855 messenger_plus_logger_read, | |
1856 messenger_plus_logger_size); | |
1857 gaim_log_logger_add(messenger_plus_logger); | |
1858 | |
1859 msn_logger = gaim_log_logger_new("msn", "MSN Messenger", 6, | |
1860 NULL, | |
1861 NULL, | |
1862 msn_logger_finalize, | |
1863 msn_logger_list, | |
1864 msn_logger_read, | |
1865 msn_logger_size); | |
1866 gaim_log_logger_add(msn_logger); | |
1867 | |
1868 trillian_logger = gaim_log_logger_new("trillian", "Trillian", 6, | |
1869 NULL, | |
1870 NULL, | |
1871 trillian_logger_finalize, | |
1872 trillian_logger_list, | |
1873 trillian_logger_read, | |
1874 trillian_logger_size); | |
1875 gaim_log_logger_add(trillian_logger); | |
1895 | 1876 |
1896 return TRUE; | 1877 return TRUE; |
1897 } | 1878 } |
1898 | 1879 |
1899 static gboolean | 1880 static gboolean |
1900 plugin_unload(GaimPlugin *plugin) | 1881 plugin_unload(GaimPlugin *plugin) |
1901 { | 1882 { |
1902 g_return_val_if_fail(plugin != NULL, FALSE); | 1883 g_return_val_if_fail(plugin != NULL, FALSE); |
1903 | 1884 |
1904 gaim_log_logger_remove(&adium_logger); | 1885 gaim_log_logger_remove(adium_logger); |
1905 gaim_log_logger_remove(&fire_logger); | 1886 gaim_log_logger_remove(fire_logger); |
1906 gaim_log_logger_remove(&messenger_plus_logger); | 1887 gaim_log_logger_remove(messenger_plus_logger); |
1907 gaim_log_logger_remove(&msn_logger); | 1888 gaim_log_logger_remove(msn_logger); |
1908 gaim_log_logger_remove(&trillian_logger); | 1889 gaim_log_logger_remove(trillian_logger); |
1909 | 1890 |
1910 return TRUE; | 1891 return TRUE; |
1911 } | 1892 } |
1912 | 1893 |
1913 static GaimPluginPrefFrame * | 1894 static GaimPluginPrefFrame * |
1989 N_("When viewing logs, this plugin will include " | 1970 N_("When viewing logs, this plugin will include " |
1990 "logs from other IM clients. Currently, this " | 1971 "logs from other IM clients. Currently, this " |
1991 "includes Adium, Fire, Messenger Plus!, " | 1972 "includes Adium, Fire, Messenger Plus!, " |
1992 "MSN Messenger, and Trillian."), | 1973 "MSN Messenger, and Trillian."), |
1993 | 1974 |
1994 "Richard Laager <rlaager@bigfoot.com>", /**< author */ | 1975 "Richard Laager <rlaager@users.sf.net>", /**< author */ |
1995 GAIM_WEBSITE, /**< homepage */ | 1976 GAIM_WEBSITE, /**< homepage */ |
1996 plugin_load, /**< load */ | 1977 plugin_load, /**< load */ |
1997 plugin_unload, /**< unload */ | 1978 plugin_unload, /**< unload */ |
1998 NULL, /**< destroy */ | 1979 NULL, /**< destroy */ |
1999 NULL, /**< ui_info */ | 1980 NULL, /**< ui_info */ |