Mercurial > pidgin.yaz
comparison libpurple/plugins/log_reader.c @ 18171:6935c7bbd310
small coding style changes
| author | Michael Shkutkov <mshkutkov@soc.pidgin.im> |
|---|---|
| date | Thu, 21 Jun 2007 06:05:41 +0000 |
| parents | 179bb0ea89c7 |
| children | 3aa11b0169c9 |
comparison
equal
deleted
inserted
replaced
| 18170:179bb0ea89c7 | 18171:6935c7bbd310 |
|---|---|
| 1743 #define QIP_LOG_OUT_MESSAGE (QIP_LOG_DELIMITER ">-") | 1743 #define QIP_LOG_OUT_MESSAGE (QIP_LOG_DELIMITER ">-") |
| 1744 #define QIP_LOG_IN_MESSAGE_ESC (QIP_LOG_DELIMITER "<-") | 1744 #define QIP_LOG_IN_MESSAGE_ESC (QIP_LOG_DELIMITER "<-") |
| 1745 #define QIP_LOG_OUT_MESSAGE_ESC (QIP_LOG_DELIMITER ">-") | 1745 #define QIP_LOG_OUT_MESSAGE_ESC (QIP_LOG_DELIMITER ">-") |
| 1746 | 1746 |
| 1747 static PurpleLogLogger *qip_logger; | 1747 static PurpleLogLogger *qip_logger; |
| 1748 static void qip_logger_finalize(PurpleLog *log); | |
| 1749 | 1748 |
| 1750 struct qip_logger_data { | 1749 struct qip_logger_data { |
| 1751 | 1750 |
| 1752 char *path; /* FIXME: Change this to use PurpleStringref like log.c:old_logger_list */ | 1751 char *path; /* FIXME: Change this to use PurpleStringref like log.c:old_logger_list */ |
| 1753 int offset; | 1752 int offset; |
| 1771 | 1770 |
| 1772 g_return_val_if_fail(sn != NULL, list); | 1771 g_return_val_if_fail(sn != NULL, list); |
| 1773 g_return_val_if_fail(account != NULL, list); | 1772 g_return_val_if_fail(account != NULL, list); |
| 1774 | 1773 |
| 1775 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1774 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", |
| 1776 "arguments not NULL\n"); | 1775 "arguments not NULL\n"); |
| 1777 | 1776 |
| 1778 /* QIP is ICQ messenger. Should we add prpl-aim? */ | 1777 /* QIP is ICQ messenger. Should we add prpl-aim? */ |
| 1779 if (strcmp(account->protocol_id, "prpl-icq")) | 1778 if (strcmp(account->protocol_id, "prpl-icq")) |
| 1780 return list; | 1779 return list; |
| 1781 | 1780 |
| 1782 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1781 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", |
| 1783 "protocol is 'prpl-icq'\n"); | 1782 "protocol is 'prpl-icq'\n"); |
| 1784 | 1783 |
| 1785 logdir = purple_prefs_get_string("/plugins/core/log_reader/qip/log_directory"); | 1784 logdir = purple_prefs_get_string("/plugins/core/log_reader/qip/log_directory"); |
| 1786 | 1785 |
| 1787 /* By clearing the log directory path, this logger can be (effectively) disabled. */ | 1786 /* By clearing the log directory path, this logger can be (effectively) disabled. */ |
| 1788 if (!*logdir) | 1787 if (!*logdir) |
| 1796 if (!prpl_info->list_icon) | 1795 if (!prpl_info->list_icon) |
| 1797 return NULL; | 1796 return NULL; |
| 1798 | 1797 |
| 1799 buddy_name = g_strdup(purple_normalize(account, sn)); | 1798 buddy_name = g_strdup(purple_normalize(account, sn)); |
| 1800 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1799 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", |
| 1801 "buddy_name %s\n", buddy_name); | 1800 "buddy_name %s\n", buddy_name); |
| 1802 | 1801 |
| 1803 username = g_strdup(purple_normalize(account, account->username)); | 1802 username = g_strdup(purple_normalize(account, account->username)); |
| 1804 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1803 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", |
| 1805 "username %s\n", username); | 1804 "username %s\n", username); |
| 1806 | 1805 |
| 1807 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1806 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", |
| 1808 "sn %s\n", sn); | 1807 "sn %s\n", sn); |
| 1809 | 1808 |
| 1810 filename = g_strdup_printf("%s.txt", buddy_name); | 1809 filename = g_strdup_printf("%s.txt", buddy_name); |
| 1811 path = g_build_filename( | 1810 path = g_build_filename( |
| 1812 logdir, username, "History", filename, NULL); | 1811 logdir, username, "History", filename, NULL); |
| 1812 | |
| 1813 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", | 1813 purple_debug(PURPLE_DEBUG_INFO, "QIP logger list", |
| 1814 "Reading %s\n", path); | 1814 "Reading %s\n", path); |
| 1815 | |
| 1815 if (!g_file_get_contents(path, &contents, &length, &error)) | 1816 if (!g_file_get_contents(path, &contents, &length, &error)) |
| 1816 if (error) | 1817 if (error) |
| 1817 g_error_free(error); | 1818 g_error_free(error); |
| 1818 | 1819 |
| 1819 if (contents) { | 1820 if (contents) { |
| 1838 | 1839 |
| 1839 timestamp++; | 1840 timestamp++; |
| 1840 | 1841 |
| 1841 /* Parse the time, day, month and year */ | 1842 /* Parse the time, day, month and year */ |
| 1842 if (sscanf(timestamp, "%u:%u:%u %u/%u/%u", | 1843 if (sscanf(timestamp, "%u:%u:%u %u/%u/%u", |
| 1843 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, | 1844 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, |
| 1844 &tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 6) { | 1845 &tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 6) { |
| 1845 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", | 1846 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger list", |
| 1846 "Parsing timestamp error\n"); | 1847 "Parsing timestamp error\n"); |
| 1847 } else { | 1848 } else { |
| 1848 PurpleLog *log; | 1849 PurpleLog *log; |
| 1849 | 1850 |
| 1850 | 1851 |
| 1851 /* cos month of year in [0,11] */ | 1852 /* cos month of year in [0,11] */ |
| 1854 tm.tm_year -= 1900; | 1855 tm.tm_year -= 1900; |
| 1855 | 1856 |
| 1856 purple_debug(PURPLE_DEBUG_INFO, | 1857 purple_debug(PURPLE_DEBUG_INFO, |
| 1857 "QIP logger list", | 1858 "QIP logger list", |
| 1858 "Parsing timestamp: %u/%u/%u %u:%u:%u\n", | 1859 "Parsing timestamp: %u/%u/%u %u:%u:%u\n", |
| 1859 tm.tm_year, tm.tm_mon, tm.tm_mday, | 1860 tm.tm_year, tm.tm_mon, tm.tm_mday, |
| 1860 tm.tm_hour, tm.tm_min, tm.tm_sec); | 1861 tm.tm_hour, tm.tm_min, tm.tm_sec); |
| 1861 | 1862 |
| 1862 /* Let the C library deal with | 1863 /* Let the C library deal with |
| 1863 * daylight savings time. | 1864 * daylight savings time. |
| 1864 */ | 1865 */ |
| 1865 tm.tm_isdst = -1; | 1866 tm.tm_isdst = -1; |
| 1941 purple_str_has_prefix(line, QIP_LOG_OUT_MESSAGE_ESC)) { | 1942 purple_str_has_prefix(line, QIP_LOG_OUT_MESSAGE_ESC)) { |
| 1942 const char *buddy_name; | 1943 const char *buddy_name; |
| 1943 is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC); | 1944 is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC); |
| 1944 | 1945 |
| 1945 purple_debug(PURPLE_DEBUG_INFO, "QIP loggger read", | 1946 purple_debug(PURPLE_DEBUG_INFO, "QIP loggger read", |
| 1946 "%s message\n", (is_in_message) ? "incoming" : "Outgoing"); | 1947 "%s message\n", (is_in_message) ? "incoming" : "Outgoing"); |
| 1947 | 1948 |
| 1948 /* find EOL */ | 1949 /* find EOL */ |
| 1949 c = strstr(c, "\n"); | 1950 c = strstr(c, "\n"); |
| 1950 | 1951 |
| 1951 /* XXX: Do we need buddy_name when we have buddy->alias? */ | 1952 /* XXX: Do we need buddy_name when we have buddy->alias? */ |
| 1964 | 1965 |
| 1965 timestamp++; | 1966 timestamp++; |
| 1966 | 1967 |
| 1967 /* Parse the time, day, month and year */ | 1968 /* Parse the time, day, month and year */ |
| 1968 if (sscanf(timestamp, "%u:%u:%u", | 1969 if (sscanf(timestamp, "%u:%u:%u", |
| 1969 &hour, &min, &sec) != 3) | 1970 &hour, &min, &sec) != 3) |
| 1970 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger read", | 1971 purple_debug(PURPLE_DEBUG_ERROR, "QIP logger read", |
| 1971 "Parsing timestamp error\n"); | 1972 "Parsing timestamp error\n"); |
| 1972 else { | 1973 else { |
| 1973 g_string_append(formatted, "<font size=\"2\">"); | 1974 g_string_append(formatted, "<font size=\"2\">"); |
| 1974 g_string_append_printf(formatted, | 1975 g_string_append_printf(formatted, |
| 1975 "(%u:%02u:%02u) %cM ", hour % 12, | 1976 "(%u:%02u:%02u) %cM ", hour % 12, |
| 1976 min, sec, (hour >= 12) ? 'P': 'A'); | 1977 min, sec, (hour >= 12) ? 'P': 'A'); |
| 1977 g_string_append(formatted, "</font> "); | 1978 g_string_append(formatted, "</font> "); |
| 1978 | 1979 |
| 1979 if (is_in_message) { | 1980 if (is_in_message) { |
| 1980 if (buddy_name != NULL && buddy->alias) { | 1981 if (buddy_name != NULL && buddy->alias) { |
| 1981 g_string_append_printf(formatted, | 1982 g_string_append_printf(formatted, |
