Mercurial > pidgin
comparison libpurple/plugins/log_reader.c @ 18245:30b67808b85b
Change the purple_debug(level, ...) statements to purple_debug_level(...)
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Sun, 24 Jun 2007 22:19:51 +0000 |
| parents | b7c30039b531 |
| children | e236b3bd4542 |
comparison
equal
deleted
inserted
replaced
| 18244:b7c30039b531 | 18245:30b67808b85b |
|---|---|
| 100 | 100 |
| 101 date += strlen(sn) + 2; | 101 date += strlen(sn) + 2; |
| 102 if (sscanf(date, "%u|%u|%u", | 102 if (sscanf(date, "%u|%u|%u", |
| 103 &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) { | 103 &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) { |
| 104 | 104 |
| 105 purple_debug(PURPLE_DEBUG_ERROR, "Adium log parse", | 105 purple_debug_error("Adium log parse", |
| 106 "Filename timestamp parsing error\n"); | 106 "Filename timestamp parsing error\n"); |
| 107 } else { | 107 } else { |
| 108 char *filename = g_build_filename(path, file, NULL); | 108 char *filename = g_build_filename(path, file, NULL); |
| 109 FILE *handle = g_fopen(filename, "rb"); | 109 FILE *handle = g_fopen(filename, "rb"); |
| 110 char *contents; | 110 char *contents; |
| 111 char *contents2; | 111 char *contents2; |
| 135 contents2++; | 135 contents2++; |
| 136 | 136 |
| 137 if (sscanf(contents2, "%u.%u.%u", | 137 if (sscanf(contents2, "%u.%u.%u", |
| 138 &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) { | 138 &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) { |
| 139 | 139 |
| 140 purple_debug(PURPLE_DEBUG_ERROR, "Adium log parse", | 140 purple_debug_error("Adium log parse", |
| 141 "Contents timestamp parsing error\n"); | 141 "Contents timestamp parsing error\n"); |
| 142 g_free(contents); | 142 g_free(contents); |
| 143 g_free(filename); | 143 g_free(filename); |
| 144 continue; | 144 continue; |
| 145 } | 145 } |
| 146 g_free(contents); | 146 g_free(contents); |
| 165 | 165 |
| 166 date += strlen(sn) + 2; | 166 date += strlen(sn) + 2; |
| 167 if (sscanf(date, "%u|%u|%u", | 167 if (sscanf(date, "%u|%u|%u", |
| 168 &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) { | 168 &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) { |
| 169 | 169 |
| 170 purple_debug(PURPLE_DEBUG_ERROR, "Adium log parse", | 170 purple_debug_error("Adium log parse", |
| 171 "Filename timestamp parsing error\n"); | 171 "Filename timestamp parsing error\n"); |
| 172 } else { | 172 } else { |
| 173 char *filename = g_build_filename(path, file, NULL); | 173 char *filename = g_build_filename(path, file, NULL); |
| 174 FILE *handle = g_fopen(filename, "rb"); | 174 FILE *handle = g_fopen(filename, "rb"); |
| 175 char *contents; | 175 char *contents; |
| 176 char *contents2; | 176 char *contents2; |
| 195 contents2++; | 195 contents2++; |
| 196 | 196 |
| 197 if (sscanf(contents2, "%u.%u.%u", | 197 if (sscanf(contents2, "%u.%u.%u", |
| 198 &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) { | 198 &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) { |
| 199 | 199 |
| 200 purple_debug(PURPLE_DEBUG_ERROR, "Adium log parse", | 200 purple_debug_error("Adium log parse", |
| 201 "Contents timestamp parsing error\n"); | 201 "Contents timestamp parsing error\n"); |
| 202 g_free(contents); | 202 g_free(contents); |
| 203 g_free(filename); | 203 g_free(filename); |
| 204 continue; | 204 continue; |
| 205 } | 205 } |
| 206 | 206 |
| 242 | 242 |
| 243 data = log->logger_data; | 243 data = log->logger_data; |
| 244 | 244 |
| 245 g_return_val_if_fail(data->path != NULL, g_strdup("")); | 245 g_return_val_if_fail(data->path != NULL, g_strdup("")); |
| 246 | 246 |
| 247 purple_debug(PURPLE_DEBUG_INFO, "Adium log read", | 247 purple_debug_info("Adium log read", "Reading %s\n", data->path); |
| 248 "Reading %s\n", data->path); | |
| 249 if (!g_file_get_contents(data->path, &read, &length, &error)) { | 248 if (!g_file_get_contents(data->path, &read, &length, &error)) { |
| 250 purple_debug(PURPLE_DEBUG_ERROR, "Adium log read", | 249 purple_debug_error("Adium log read", "Error reading log\n"); |
| 251 "Error reading log\n"); | |
| 252 if (error) | 250 if (error) |
| 253 g_error_free(error); | 251 g_error_free(error); |
| 254 return g_strdup(""); | 252 return g_strdup(""); |
| 255 } | 253 } |
| 256 | 254 |
| 475 | 473 |
| 476 datetime = xmlnode_get_attrib(message, "DateTime"); | 474 datetime = xmlnode_get_attrib(message, "DateTime"); |
| 477 if (!(datetime && *datetime)) | 475 if (!(datetime && *datetime)) |
| 478 { | 476 { |
| 479 purple_debug_error("MSN log timestamp parse", | 477 purple_debug_error("MSN log timestamp parse", |
| 480 "Attribute missing: %s\n", "DateTime"); | 478 "Attribute missing: %s\n", "DateTime"); |
| 481 return (time_t)0; | 479 return (time_t)0; |
| 482 } | 480 } |
| 483 | 481 |
| 484 stamp = purple_str_to_time(datetime, TRUE, &tm2, NULL, NULL); | 482 stamp = purple_str_to_time(datetime, TRUE, &tm2, NULL, NULL); |
| 485 #ifdef HAVE_TM_GMTOFF | 483 #ifdef HAVE_TM_GMTOFF |
| 496 | 494 |
| 497 date = xmlnode_get_attrib(message, "Date"); | 495 date = xmlnode_get_attrib(message, "Date"); |
| 498 if (!(date && *date)) | 496 if (!(date && *date)) |
| 499 { | 497 { |
| 500 purple_debug_error("MSN log timestamp parse", | 498 purple_debug_error("MSN log timestamp parse", |
| 501 "Attribute missing: %s\n", "Date"); | 499 "Attribute missing: %s\n", "Date"); |
| 502 *tm_out = &tm2; | 500 *tm_out = &tm2; |
| 503 return stamp; | 501 return stamp; |
| 504 } | 502 } |
| 505 | 503 |
| 506 time = xmlnode_get_attrib(message, "Time"); | 504 time = xmlnode_get_attrib(message, "Time"); |
| 507 if (!(time && *time)) | 505 if (!(time && *time)) |
| 508 { | 506 { |
| 509 purple_debug_error("MSN log timestamp parse", | 507 purple_debug_error("MSN log timestamp parse", |
| 510 "Attribute missing: %s\n", "Time"); | 508 "Attribute missing: %s\n", "Time"); |
| 511 *tm_out = &tm2; | 509 *tm_out = &tm2; |
| 512 return stamp; | 510 return stamp; |
| 513 } | 511 } |
| 514 | 512 |
| 515 if (sscanf(date, "%u/%u/%u", &month, &day, &year) != 3) | 513 if (sscanf(date, "%u/%u/%u", &month, &day, &year) != 3) |
| 516 { | 514 { |
| 517 purple_debug_error("MSN log timestamp parse", | 515 purple_debug_error("MSN log timestamp parse", |
| 518 "%s parsing error\n", "Date"); | 516 "%s parsing error\n", "Date"); |
| 519 *tm_out = &tm2; | 517 *tm_out = &tm2; |
| 520 return stamp; | 518 return stamp; |
| 521 } | 519 } |
| 522 else | 520 else |
| 523 { | 521 { |
| 530 } | 528 } |
| 531 | 529 |
| 532 if (sscanf(time, "%u:%u:%u %c", &hour, &min, &sec, &am_pm) != 4) | 530 if (sscanf(time, "%u:%u:%u %c", &hour, &min, &sec, &am_pm) != 4) |
| 533 { | 531 { |
| 534 purple_debug_error("MSN log timestamp parse", | 532 purple_debug_error("MSN log timestamp parse", |
| 535 "%s parsing error\n", "Time"); | 533 "%s parsing error\n", "Time"); |
| 536 *tm_out = &tm2; | 534 *tm_out = &tm2; |
| 537 return stamp; | 535 return stamp; |
| 538 } | 536 } |
| 539 | 537 |
| 540 if (am_pm == 'P') { | 538 if (am_pm == 'P') { |
| 797 g_free(username); | 795 g_free(username); |
| 798 g_free(logfile); | 796 g_free(logfile); |
| 799 logfile = NULL; /* No sense saving the obvious buddy@domain.com. */ | 797 logfile = NULL; /* No sense saving the obvious buddy@domain.com. */ |
| 800 } | 798 } |
| 801 | 799 |
| 802 purple_debug(PURPLE_DEBUG_INFO, "MSN log read", | 800 purple_debug_info("MSN log read", "Reading %s\n", path); |
| 803 "Reading %s\n", path); | |
| 804 if (!g_file_get_contents(path, &contents, &length, &error)) { | 801 if (!g_file_get_contents(path, &contents, &length, &error)) { |
| 805 g_free(path); | 802 g_free(path); |
| 806 purple_debug(PURPLE_DEBUG_ERROR, "MSN log read", | 803 purple_debug_error("MSN log read", "Error reading log\n"); |
| 807 "Error reading log\n"); | |
| 808 if (error) | 804 if (error) |
| 809 g_error_free(error); | 805 g_error_free(error); |
| 810 return list; | 806 return list; |
| 811 } | 807 } |
| 812 g_free(path); | 808 g_free(path); |
| 831 message = xmlnode_get_next_twin(message)) { | 827 message = xmlnode_get_next_twin(message)) { |
| 832 const char *session_id; | 828 const char *session_id; |
| 833 | 829 |
| 834 session_id = xmlnode_get_attrib(message, "SessionID"); | 830 session_id = xmlnode_get_attrib(message, "SessionID"); |
| 835 if (!session_id) { | 831 if (!session_id) { |
| 836 purple_debug(PURPLE_DEBUG_ERROR, "MSN log parse", | 832 purple_debug_error("MSN log parse", |
| 837 "Error parsing message: %s\n", "SessionID missing"); | 833 "Error parsing message: %s\n", "SessionID missing"); |
| 838 continue; | 834 continue; |
| 839 } | 835 } |
| 840 | 836 |
| 841 if (strcmp(session_id, old_session_id)) { | 837 if (strcmp(session_id, old_session_id)) { |
| 842 /* | 838 /* |
| 892 | 888 |
| 893 text = g_string_new(""); | 889 text = g_string_new(""); |
| 894 | 890 |
| 895 if (!data->root || !data->message || !data->session_id) { | 891 if (!data->root || !data->message || !data->session_id) { |
| 896 /* Something isn't allocated correctly. */ | 892 /* Something isn't allocated correctly. */ |
| 897 purple_debug(PURPLE_DEBUG_ERROR, "MSN log parse", | 893 purple_debug_error("MSN log parse", |
| 898 "Error parsing message: %s\n", "Internal variables inconsistent"); | 894 "Error parsing message: %s\n", "Internal variables inconsistent"); |
| 899 data->text = text; | 895 data->text = text; |
| 900 | 896 |
| 901 return text->str; | 897 return text->str; |
| 902 } | 898 } |
| 903 | 899 |
| 920 | 916 |
| 921 new_session_id = xmlnode_get_attrib(message, "SessionID"); | 917 new_session_id = xmlnode_get_attrib(message, "SessionID"); |
| 922 | 918 |
| 923 /* If this triggers, something is wrong with the XML. */ | 919 /* If this triggers, something is wrong with the XML. */ |
| 924 if (!new_session_id) { | 920 if (!new_session_id) { |
| 925 purple_debug(PURPLE_DEBUG_ERROR, "MSN log parse", | 921 purple_debug_error("MSN log parse", |
| 926 "Error parsing message: %s\n", "New SessionID missing"); | 922 "Error parsing message: %s\n", "New SessionID missing"); |
| 927 break; | 923 break; |
| 928 } | 924 } |
| 929 | 925 |
| 930 if (strcmp(new_session_id, data->session_id)) { | 926 if (strcmp(new_session_id, data->session_id)) { |
| 931 /* The session ID differs from the first message. | 927 /* The session ID differs from the first message. |
| 1232 | 1228 |
| 1233 filename = g_strdup_printf("%s.log", buddy_name); | 1229 filename = g_strdup_printf("%s.log", buddy_name); |
| 1234 path = g_build_filename( | 1230 path = g_build_filename( |
| 1235 logdir, prpl_name, filename, NULL); | 1231 logdir, prpl_name, filename, NULL); |
| 1236 | 1232 |
| 1237 purple_debug(PURPLE_DEBUG_INFO, "Trillian log list", | 1233 purple_debug_info("Trillian log list", "Reading %s\n", path); |
| 1238 "Reading %s\n", path); | |
| 1239 /* FIXME: There's really no need to read the entire file at once. | 1234 /* FIXME: There's really no need to read the entire file at once. |
| 1240 * See src/log.c:old_logger_list for a better approach. | 1235 * See src/log.c:old_logger_list for a better approach. |
| 1241 */ | 1236 */ |
| 1242 if (!g_file_get_contents(path, &contents, &length, &error)) { | 1237 if (!g_file_get_contents(path, &contents, &length, &error)) { |
| 1243 if (error) { | 1238 if (error) { |
| 1246 } | 1241 } |
| 1247 g_free(path); | 1242 g_free(path); |
| 1248 | 1243 |
| 1249 path = g_build_filename( | 1244 path = g_build_filename( |
| 1250 logdir, prpl_name, "Query", filename, NULL); | 1245 logdir, prpl_name, "Query", filename, NULL); |
| 1251 purple_debug(PURPLE_DEBUG_INFO, "Trillian log list", | 1246 purple_debug_info("Trillian log list", "Reading %s\n", path); |
| 1252 "Reading %s\n", path); | |
| 1253 if (!g_file_get_contents(path, &contents, &length, &error)) { | 1247 if (!g_file_get_contents(path, &contents, &length, &error)) { |
| 1254 if (error) | 1248 if (error) |
| 1255 g_error_free(error); | 1249 g_error_free(error); |
| 1256 } | 1250 } |
| 1257 } | 1251 } |
| 1277 if (data && !data->length) { | 1271 if (data && !data->length) { |
| 1278 if (!(data->length = last_line_offset - data->offset)) { | 1272 if (!(data->length = last_line_offset - data->offset)) { |
| 1279 /* This log had no data, so we remove it. */ | 1273 /* This log had no data, so we remove it. */ |
| 1280 GList *last = g_list_last(list); | 1274 GList *last = g_list_last(list); |
| 1281 | 1275 |
| 1282 purple_debug(PURPLE_DEBUG_INFO, "Trillian log list", | 1276 purple_debug_info("Trillian log list", |
| 1283 "Empty log. Offset %i\n", data->offset); | 1277 "Empty log. Offset %i\n", data->offset); |
| 1284 | 1278 |
| 1285 trillian_logger_finalize((PurpleLog *)last->data); | 1279 trillian_logger_finalize((PurpleLog *)last->data); |
| 1286 list = g_list_delete_link(list, last); | 1280 list = g_list_delete_link(list, last); |
| 1287 } | 1281 } |
| 1288 } | 1282 } |
| 1342 if (sscanf(timestamp, "%u %u:%u:%u %u", | 1336 if (sscanf(timestamp, "%u %u:%u:%u %u", |
| 1343 &tm.tm_mday, &tm.tm_hour, | 1337 &tm.tm_mday, &tm.tm_hour, |
| 1344 &tm.tm_min, &tm.tm_sec, | 1338 &tm.tm_min, &tm.tm_sec, |
| 1345 &tm.tm_year) != 5) { | 1339 &tm.tm_year) != 5) { |
| 1346 | 1340 |
| 1347 purple_debug(PURPLE_DEBUG_ERROR, | 1341 purple_debug_error("Trillian log timestamp parse", |
| 1348 "Trillian log timestamp parse", | 1342 "Session Start parsing error\n"); |
| 1349 "Session Start parsing error\n"); | |
| 1350 } else { | 1343 } else { |
| 1351 PurpleLog *log; | 1344 PurpleLog *log; |
| 1352 | 1345 |
| 1353 tm.tm_year -= 1900; | 1346 tm.tm_year -= 1900; |
| 1354 | 1347 |
| 1436 | 1429 |
| 1437 g_return_val_if_fail(data->path != NULL, g_strdup("")); | 1430 g_return_val_if_fail(data->path != NULL, g_strdup("")); |
| 1438 g_return_val_if_fail(data->length > 0, g_strdup("")); | 1431 g_return_val_if_fail(data->length > 0, g_strdup("")); |
| 1439 g_return_val_if_fail(data->their_nickname != NULL, g_strdup("")); | 1432 g_return_val_if_fail(data->their_nickname != NULL, g_strdup("")); |
| 1440 | 1433 |
| 1441 purple_debug(PURPLE_DEBUG_INFO, "Trillian log read", | 1434 purple_debug_info("Trillian log read", "Reading %s\n", data->path); |
| 1442 "Reading %s\n", data->path); | |
| 1443 | 1435 |
| 1444 read = g_malloc(data->length + 2); | 1436 read = g_malloc(data->length + 2); |
| 1445 | 1437 |
| 1446 file = g_fopen(data->path, "rb"); | 1438 file = g_fopen(data->path, "rb"); |
| 1447 fseek(file, data->offset, SEEK_SET); | 1439 fseek(file, data->offset, SEEK_SET); |
| 1765 gchar *contents = NULL; | 1757 gchar *contents = NULL; |
| 1766 | 1758 |
| 1767 g_return_val_if_fail(sn != NULL, list); | 1759 g_return_val_if_fail(sn != NULL, list); |
| 1768 g_return_val_if_fail(account != NULL, list); | 1760 g_return_val_if_fail(account != NULL, list); |
| 1769 | 1761 |
| 1770 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | |
| 1771 "arguments not NULL\n"); | |
| 1772 | |
| 1773 /* QIP is ICQ messenger. Should we add prpl-aim? */ | 1762 /* QIP is ICQ messenger. Should we add prpl-aim? */ |
| 1774 if (strcmp(account->protocol_id, "prpl-icq")) | 1763 if (strcmp(account->protocol_id, "prpl-icq")) |
| 1775 return list; | 1764 return list; |
| 1776 | |
| 1777 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | |
| 1778 "protocol is 'prpl-icq'\n"); | |
| 1779 | 1765 |
| 1780 logdir = purple_prefs_get_string("/plugins/core/log_reader/qip/log_directory"); | 1766 logdir = purple_prefs_get_string("/plugins/core/log_reader/qip/log_directory"); |
| 1781 | 1767 |
| 1782 /* By clearing the log directory path, this logger can be (effectively) disabled. */ | 1768 /* By clearing the log directory path, this logger can be (effectively) disabled. */ |
| 1783 if (!*logdir) | 1769 if (!*logdir) |
| 1790 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); | 1776 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin); |
| 1791 if (!prpl_info->list_icon) | 1777 if (!prpl_info->list_icon) |
| 1792 return NULL; | 1778 return NULL; |
| 1793 | 1779 |
| 1794 buddy_name = g_strdup(purple_normalize(account, sn)); | 1780 buddy_name = g_strdup(purple_normalize(account, sn)); |
| 1795 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | |
| 1796 "buddy_name %s\n", buddy_name); | |
| 1797 | 1781 |
| 1798 username = g_strdup(purple_normalize(account, account->username)); | 1782 username = g_strdup(purple_normalize(account, account->username)); |
| 1799 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | |
| 1800 "username %s\n", username); | |
| 1801 | |
| 1802 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | |
| 1803 "sn %s\n", sn); | |
| 1804 | 1783 |
| 1805 filename = g_strdup_printf("%s.txt", buddy_name); | 1784 filename = g_strdup_printf("%s.txt", buddy_name); |
| 1806 path = g_build_filename( | 1785 path = g_build_filename( |
| 1807 logdir, username, "History", filename, NULL); | 1786 logdir, username, "History", filename, NULL); |
| 1808 | 1787 |
| 1809 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1788 purple_debug_info("QIP logger list", "Reading %s\n", path); |
| 1810 "Reading %s\n", path); | |
| 1811 | 1789 |
| 1812 error = NULL; | 1790 error = NULL; |
| 1813 if (!g_file_get_contents(path, &contents, &length, &error)) { | 1791 if (!g_file_get_contents(path, &contents, &length, &error)) { |
| 1814 if (error) { | 1792 if (error) { |
| 1815 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", | 1793 purple_debug_error("QIP logger list", |
| 1816 "Couldn't read file %s \n", path); | 1794 "Couldn't read file %s \n", path); |
| 1817 | 1795 |
| 1818 g_error_free(error); | 1796 g_error_free(error); |
| 1819 } | 1797 } |
| 1820 } else if (contents) { | 1798 } else if (contents) { |
| 1821 struct qip_logger_data *data = NULL; | 1799 struct qip_logger_data *data = NULL; |
| 1822 gchar * utf8_string = NULL; | 1800 gchar * utf8_string = NULL; |
| 1823 | 1801 |
| 1824 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1802 purple_debug_info("QIP logger list", "File %s is found\n", filename); |
| 1825 "File %s is found\n", filename); | |
| 1826 | 1803 |
| 1827 /* We should convert file contents from Cp1251 to UTF-8 codeset */ | 1804 /* We should convert file contents from Cp1251 to UTF-8 codeset */ |
| 1828 error = NULL; | 1805 error = NULL; |
| 1829 if (!(utf8_string = g_convert(contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) { | 1806 if (!(utf8_string = g_convert(contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) { |
| 1830 if (error) { | 1807 if (error) { |
| 1831 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", | 1808 purple_debug_error("QIP logger list", |
| 1832 "Couldn't convert file %s to UTF-8\n", filename); | 1809 "Couldn't convert file %s to UTF-8\n", filename); |
| 1833 g_error_free(error); | 1810 g_error_free(error); |
| 1834 } | 1811 } |
| 1835 } else { | 1812 } else { |
| 1836 struct tm prev_tm; | 1813 struct tm prev_tm; |
| 1837 gboolean prev_tm_init = FALSE; | 1814 gboolean prev_tm_init = FALSE; |
| 1838 gchar *c; | 1815 gchar *c; |
| 1839 gchar *start_log; | 1816 gchar *start_log; |
| 1840 gchar *escaped; | 1817 gchar *escaped; |
| 1841 int offset = 0; | 1818 int offset = 0; |
| 1842 | 1819 |
| 1843 purple_debug(PURPLE_DEBUG_INFO, "QIP logger lise", | 1820 purple_debug_info("QIP logger list", |
| 1844 "File %s converted successfully\n", filename); | 1821 "File %s converted successfully\n", filename); |
| 1845 | 1822 |
| 1846 g_free(contents); | 1823 g_free(contents); |
| 1847 escaped = g_markup_escape_text(utf8_string, -1); | 1824 escaped = g_markup_escape_text(utf8_string, -1); |
| 1848 contents = escaped; | 1825 contents = escaped; |
| 1849 | 1826 |
| 1852 while (*c) { | 1829 while (*c) { |
| 1853 if (purple_str_has_prefix(c, QIP_LOG_IN_MESSAGE_ESC) || | 1830 if (purple_str_has_prefix(c, QIP_LOG_IN_MESSAGE_ESC) || |
| 1854 purple_str_has_prefix(c, QIP_LOG_OUT_MESSAGE_ESC)) { | 1831 purple_str_has_prefix(c, QIP_LOG_OUT_MESSAGE_ESC)) { |
| 1855 gchar *new_line = c; | 1832 gchar *new_line = c; |
| 1856 | 1833 |
| 1857 purple_debug(PURPLE_DEBUG_INFO, "QIP logger lise", | 1834 purple_debug_info("QIP logger list", |
| 1858 "Find message\n", filename); | 1835 "Find message\n", filename); |
| 1859 | 1836 |
| 1860 /* find EOL */ | 1837 /* find EOL */ |
| 1861 c = strstr(c, "\n"); | 1838 c = strstr(c, "\n"); |
| 1862 c++; | 1839 c++; |
| 1863 /* searching '(' character from the end of the line */ | 1840 /* searching '(' character from the end of the line */ |
| 1866 --c; | 1843 --c; |
| 1867 | 1844 |
| 1868 if (*c == '(') { | 1845 if (*c == '(') { |
| 1869 const char *timestamp = ++c; | 1846 const char *timestamp = ++c; |
| 1870 struct tm tm; | 1847 struct tm tm; |
| 1871 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1848 purple_debug_info("QIP logger list", "Timestap found\n"); |
| 1872 "Timestap found\n"); | |
| 1873 | 1849 |
| 1874 /* Parse the time, day, month and year */ | 1850 /* Parse the time, day, month and year */ |
| 1875 if (sscanf(timestamp, "%u:%u:%u %u/%u/%u", | 1851 if (sscanf(timestamp, "%u:%u:%u %u/%u/%u", |
| 1876 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, | 1852 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, |
| 1877 &tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 6) { | 1853 &tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 6) { |
| 1878 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", | 1854 purple_debug_error("QIP logger list", |
| 1879 "Parsing timestamp error\n"); | 1855 "Parsing timestamp error\n"); |
| 1880 } else { | 1856 } else { |
| 1881 /* cos month of year in [0,11] */ | 1857 /* cos month of year in [0,11] */ |
| 1882 tm.tm_mon -= 1; | 1858 tm.tm_mon -= 1; |
| 1883 /* cos years since 1900 */ | 1859 /* cos years since 1900 */ |
| 1884 tm.tm_year -= 1900; | 1860 tm.tm_year -= 1900; |
| 1905 data->path = g_strdup(path); | 1881 data->path = g_strdup(path); |
| 1906 data->length = new_line - start_log; | 1882 data->length = new_line - start_log; |
| 1907 data->offset = offset; | 1883 data->offset = offset; |
| 1908 offset += data->length; | 1884 offset += data->length; |
| 1909 | 1885 |
| 1910 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", | 1886 purple_debug_error("QIP logger list", |
| 1911 "Creating log: path = (%s); length = (%d); offset = (%d)\n", data->path, data->length, data->offset); | 1887 "Creating log: path = (%s); length = (%d); offset = (%d)\n", data->path, data->length, data->offset); |
| 1912 | 1888 |
| 1913 /* XXX: Look into this later... Should we pass in a struct tm? */ | 1889 /* XXX: Look into this later... Should we pass in a struct tm? */ |
| 1914 log = purple_log_new(PURPLE_LOG_IM, | 1890 log = purple_log_new(PURPLE_LOG_IM, |
| 1915 sn, account, NULL, mktime(&prev_tm), NULL); | 1891 sn, account, NULL, mktime(&prev_tm), NULL); |
| 1916 | 1892 |
| 1944 struct qip_logger_data, 1); | 1920 struct qip_logger_data, 1); |
| 1945 data->path = g_strdup(path); | 1921 data->path = g_strdup(path); |
| 1946 data->length = c - start_log; | 1922 data->length = c - start_log; |
| 1947 data->offset = offset; | 1923 data->offset = offset; |
| 1948 offset += data->length; | 1924 offset += data->length; |
| 1949 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", | 1925 purple_debug_error("QIP logger list", |
| 1950 "Creating log: path = (%s); length = (%d); offset = (%d)\n", data->path, data->length, data->offset); | 1926 "Creating log: path = (%s); length = (%d); offset = (%d)\n", data->path, data->length, data->offset); |
| 1951 | 1927 |
| 1952 /* XXX: Look into this later... Should we pass in a struct tm? */ | 1928 /* XXX: Look into this later... Should we pass in a struct tm? */ |
| 1953 log = purple_log_new(PURPLE_LOG_IM, | 1929 log = purple_log_new(PURPLE_LOG_IM, sn, account, |
| 1954 sn, account, NULL, mktime(&prev_tm), NULL); | 1930 NULL, mktime(&prev_tm), NULL); |
| 1955 | 1931 |
| 1956 log->logger = qip_logger; | 1932 log->logger = qip_logger; |
| 1957 log->logger_data = data; | 1933 log->logger_data = data; |
| 1958 | 1934 |
| 1959 list = g_list_append(list, log); | 1935 list = g_list_append(list, log); |
| 1960 } | 1936 } |
| 1961 } | 1937 } |
| 1985 data = log->logger_data; | 1961 data = log->logger_data; |
| 1986 | 1962 |
| 1987 g_return_val_if_fail(data->path != NULL, g_strdup("")); | 1963 g_return_val_if_fail(data->path != NULL, g_strdup("")); |
| 1988 g_return_val_if_fail(data->length > 0, g_strdup("")); | 1964 g_return_val_if_fail(data->length > 0, g_strdup("")); |
| 1989 | 1965 |
| 1990 purple_debug(PURPLE_DEBUG_INFO, "QIP logger read", | 1966 purple_debug_info("QIP logger read", "Reading %s\n", data->path); |
| 1991 "Reading %s\n", data->path); | |
| 1992 | 1967 |
| 1993 error = NULL; | 1968 error = NULL; |
| 1994 if (!g_file_get_contents(data->path, &contents, &length, &error)) | 1969 if (!g_file_get_contents(data->path, &contents, &length, &error)) |
| 1995 if (error) { | 1970 if (error) { |
| 1996 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", | 1971 purple_debug_error("QIP logger list", |
| 1997 "Couldn't read file %s \n", data->path); | 1972 "Couldn't read file %s \n", data->path); |
| 1998 | 1973 |
| 1999 g_error_free(error); | 1974 g_error_free(error); |
| 2000 } | 1975 } |
| 2001 if (contents) { | 1976 if (contents) { |
| 2002 gchar * utf8_string; | 1977 gchar * utf8_string; |
| 2003 | 1978 |
| 2004 /* We should convert file contents from Cp1251 to UTF-8 codeset */ | 1979 /* We should convert file contents from Cp1251 to UTF-8 codeset */ |
| 2005 error = NULL; | 1980 error = NULL; |
| 2006 if (!(utf8_string = g_convert (contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) { | 1981 if (!(utf8_string = g_convert (contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) { |
| 2007 if (error) { | 1982 if (error) { |
| 2008 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger read", | 1983 purple_debug_error("QIP logger read", |
| 2009 "Couldn't convert file %s to UTF-8\n", data->path); | 1984 "Couldn't convert file %s to UTF-8\n", data->path); |
| 2010 g_error_free(error); | 1985 g_error_free(error); |
| 2011 } | 1986 } |
| 2012 } else { | 1987 } else { |
| 2013 char *escaped; | 1988 char *escaped; |
| 2014 char *selected; | 1989 char *selected; |
| 2015 | 1990 |
| 2016 purple_debug(PURPLE_DEBUG_INFO, "QIP logger read", | 1991 purple_debug_info("QIP logger read", |
| 2017 "File %s converted successfully\n", data->path); | 1992 "File %s converted successfully\n", data->path); |
| 2018 | 1993 |
| 2019 g_free(contents); | 1994 g_free(contents); |
| 2020 contents = utf8_string; | 1995 contents = utf8_string; |
| 2021 | 1996 |
| 2022 /* Load miscellaneous data. */ | 1997 /* Load miscellaneous data. */ |
| 2065 | 2040 |
| 2066 timestamp++; | 2041 timestamp++; |
| 2067 | 2042 |
| 2068 /* Parse the time, day, month and year */ | 2043 /* Parse the time, day, month and year */ |
| 2069 if (sscanf(timestamp, "%u:%u:%u", | 2044 if (sscanf(timestamp, "%u:%u:%u", |
| 2070 &hour, &min, &sec) != 3) | 2045 &hour, &min, &sec) != 3) { |
| 2071 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger read", | 2046 purple_debug_error("QIP logger read", |
| 2072 "Parsing timestamp error\n"); | 2047 "Parsing timestamp error\n"); |
| 2073 else { | 2048 } else { |
| 2074 g_string_append(formatted, "<font size=\"2\">"); | 2049 g_string_append(formatted, "<font size=\"2\">"); |
| 2075 g_string_append_printf(formatted, | 2050 g_string_append_printf(formatted, |
| 2076 "(%u:%02u:%02u) %cM ", hour % 12, | 2051 "(%u:%02u:%02u) %cM ", hour % 12, |
| 2077 min, sec, (hour >= 12) ? 'P': 'A'); | 2052 min, sec, (hour >= 12) ? 'P': 'A'); |
| 2078 g_string_append(formatted, "</font> "); | 2053 g_string_append(formatted, "</font> "); |
| 2310 GError *error = NULL; | 2285 GError *error = NULL; |
| 2311 | 2286 |
| 2312 #if 0 && GLIB_CHECK_VERSION(2,6,0) /* FIXME: Not tested yet. */ | 2287 #if 0 && GLIB_CHECK_VERSION(2,6,0) /* FIXME: Not tested yet. */ |
| 2313 GKeyFile *key_file; | 2288 GKeyFile *key_file; |
| 2314 | 2289 |
| 2315 purple_debug(PURPLE_DEBUG_INFO, "Trillian talk.ini read", | 2290 purple_debug_info("Trillian talk.ini read", "Reading %s\n", path); |
| 2316 "Reading %s\n", path); | |
| 2317 | 2291 |
| 2318 error = NULL; | 2292 error = NULL; |
| 2319 if (!g_key_file_load_from_file(key_file, path, G_KEY_FILE_NONE, GError &error)) { | 2293 if (!g_key_file_load_from_file(key_file, path, G_KEY_FILE_NONE, GError &error)) { |
| 2320 purple_debug(PURPLE_DEBUG_ERROR, "Trillian talk.ini read", | 2294 purple_debug_error("Trillian talk.ini read", |
| 2321 "Error reading talk.ini\n"); | 2295 "Error reading talk.ini\n"); |
| 2322 if (error) | 2296 if (error) |
| 2323 g_error_free(error); | 2297 g_error_free(error); |
| 2324 } else { | 2298 } else { |
| 2325 char *logdir = g_key_file_get_string(key_file, "Logging", "Directory", &error); | 2299 char *logdir = g_key_file_get_string(key_file, "Logging", "Directory", &error); |
| 2326 if (error) { | 2300 if (error) { |
| 2327 purple_debug(PURPLE_DEBUG_ERROR, "Trillian talk.ini read", | 2301 purple_debug_error("Trillian talk.ini read", |
| 2328 "Error reading Directory value from Logging section\n"); | 2302 "Error reading Directory value from Logging section\n"); |
| 2329 g_error_free(error); | 2303 g_error_free(error); |
| 2330 } | 2304 } |
| 2331 | 2305 |
| 2332 if (logdir) { | 2306 if (logdir) { |
| 2333 g_strchomp(logdir); | 2307 g_strchomp(logdir); |
| 2334 purple_prefs_add_string( | 2308 purple_prefs_add_string("/plugins/core/log_reader/trillian/log_directory", logdir); |
| 2335 "/plugins/core/log_reader/trillian/log_directory", logdir); | |
| 2336 found = TRUE; | 2309 found = TRUE; |
| 2337 } | 2310 } |
| 2338 | 2311 |
| 2339 g_key_file_free(key_file); | 2312 g_key_file_free(key_file); |
| 2340 } | 2313 } |
| 2341 #else /* !GLIB_CHECK_VERSION(2,6,0) */ | 2314 #else /* !GLIB_CHECK_VERSION(2,6,0) */ |
| 2342 gsize length; | 2315 gsize length; |
| 2343 gchar *contents = NULL; | 2316 gchar *contents = NULL; |
| 2344 | 2317 |
| 2345 purple_debug(PURPLE_DEBUG_INFO, "Trillian talk.ini read", | 2318 purple_debug_info("Trillian talk.ini read", |
| 2346 "Reading %s\n", path); | 2319 "Reading %s\n", path); |
| 2347 if (!g_file_get_contents(path, &contents, &length, &error)) { | 2320 if (!g_file_get_contents(path, &contents, &length, &error)) { |
| 2348 purple_debug(PURPLE_DEBUG_ERROR, "Trillian talk.ini read", | 2321 purple_debug_error("Trillian talk.ini read", |
| 2349 "Error reading talk.ini\n"); | 2322 "Error reading talk.ini\n"); |
| 2350 if (error) | 2323 if (error) |
| 2351 g_error_free(error); | 2324 g_error_free(error); |
| 2352 } else { | 2325 } else { |
| 2353 char *line = contents; | 2326 char *line = contents; |
| 2354 while (*contents) { | 2327 while (*contents) { |
| 2419 #ifdef _WIN32 | 2392 #ifdef _WIN32 |
| 2420 g_free(folder); | 2393 g_free(folder); |
| 2421 } else /* !folder */ | 2394 } else /* !folder */ |
| 2422 path = g_strdup(""); | 2395 path = g_strdup(""); |
| 2423 #endif | 2396 #endif |
| 2424 | |
| 2425 purple_debug(PURPLE_DEBUG_INFO, "QIP log reader", "QIP log directory %s\n", path); | |
| 2426 | 2397 |
| 2427 purple_prefs_add_string("/plugins/core/log_reader/qip/log_directory", path); | 2398 purple_prefs_add_string("/plugins/core/log_reader/qip/log_directory", path); |
| 2428 g_free(path); | 2399 g_free(path); |
| 2429 } | 2400 } |
| 2430 | 2401 |
| 2573 #endif | 2544 #endif |
| 2574 | 2545 |
| 2575 ppref = purple_plugin_pref_new_with_name_and_label( | 2546 ppref = purple_plugin_pref_new_with_name_and_label( |
| 2576 "/plugins/core/log_reader/qip/log_directory", _("QIP")); | 2547 "/plugins/core/log_reader/qip/log_directory", _("QIP")); |
| 2577 purple_plugin_pref_frame_add(frame, ppref); | 2548 purple_plugin_pref_frame_add(frame, ppref); |
| 2578 purple_debug(PURPLE_DEBUG_INFO, "QIP log reader", "QIP creating directory\n"); | |
| 2579 | 2549 |
| 2580 ppref = purple_plugin_pref_new_with_name_and_label( | 2550 ppref = purple_plugin_pref_new_with_name_and_label( |
| 2581 "/plugins/core/log_reader/msn/log_directory", _("MSN Messenger")); | 2551 "/plugins/core/log_reader/msn/log_directory", _("MSN Messenger")); |
| 2582 purple_plugin_pref_frame_add(frame, ppref); | 2552 purple_plugin_pref_frame_add(frame, ppref); |
| 2583 | 2553 |
