comparison libpurple/plugins/log_reader.c @ 18248:ab761acbc614

Remove trailing whitespace.
author Richard Laager <rlaager@wiktel.com>
date Sun, 24 Jun 2007 23:40:09 +0000
parents 97671eb4991e
children 35d981091506
comparison
equal deleted inserted replaced
18247:97671eb4991e 18248:ab761acbc614
1286 } else if (line[0] && line[1] && line[2] && 1286 } else if (line[0] && line[1] && line[2] &&
1287 purple_str_has_prefix(&line[3], "sion Start ")) { 1287 purple_str_has_prefix(&line[3], "sion Start ")) {
1288 /* The conditional is to make sure we're not reading off 1288 /* The conditional is to make sure we're not reading off
1289 * the end of the string. We don't want strlen(), as that'd 1289 * the end of the string. We don't want strlen(), as that'd
1290 * have to count the whole string needlessly. 1290 * have to count the whole string needlessly.
1291 * 1291 *
1292 * The odd check here is because a Session Start at the 1292 * The odd check here is because a Session Start at the
1293 * beginning of the file can be overwritten with a UTF-8 1293 * beginning of the file can be overwritten with a UTF-8
1294 * byte order mark. Yes, it's weird. 1294 * byte order mark. Yes, it's weird.
1295 */ 1295 */
1296 char *their_nickname = line; 1296 char *their_nickname = line;
1480 * <a href=" 1480 * <a href="
1481 * Then, replace the next ")" with: 1481 * Then, replace the next ")" with:
1482 * "> 1482 * ">
1483 * Then, replace the next " " (or add this if the end-of-line is reached) with: 1483 * Then, replace the next " " (or add this if the end-of-line is reached) with:
1484 * </a> 1484 * </a>
1485 * 1485 *
1486 * As implemented, this isn't perfect, but it should cover common cases. 1486 * As implemented, this isn't perfect, but it should cover common cases.
1487 */ 1487 */
1488 while (line && (link = strstr(line, "(Link: "))) 1488 while (line && (link = strstr(line, "(Link: ")))
1489 { 1489 {
1490 const char *tmp = link; 1490 const char *tmp = link;
1737 #define QIP_LOG_TIMEOUT (60*60) 1737 #define QIP_LOG_TIMEOUT (60*60)
1738 1738
1739 static PurpleLogLogger *qip_logger; 1739 static PurpleLogLogger *qip_logger;
1740 1740
1741 struct qip_logger_data { 1741 struct qip_logger_data {
1742 1742
1743 char *path; /* FIXME: Change this to use PurpleStringref like log.c:old_logger_list */ 1743 char *path; /* FIXME: Change this to use PurpleStringref like log.c:old_logger_list */
1744 int offset; 1744 int offset;
1745 int length; 1745 int length;
1746 }; 1746 };
1747 1747
1792 path = g_build_filename(logdir, username, "History", filename, NULL); 1792 path = g_build_filename(logdir, username, "History", filename, NULL);
1793 g_free(username); 1793 g_free(username);
1794 g_free(filename); 1794 g_free(filename);
1795 1795
1796 purple_debug_info("QIP logger list", "Reading %s\n", path); 1796 purple_debug_info("QIP logger list", "Reading %s\n", path);
1797 1797
1798 error = NULL; 1798 error = NULL;
1799 if (!g_file_get_contents(path, &contents, &length, &error)) { 1799 if (!g_file_get_contents(path, &contents, &length, &error)) {
1800 purple_debug_error("QIP logger list", 1800 purple_debug_error("QIP logger list",
1801 "Couldn't read file %s: %s \n", path, error->message); 1801 "Couldn't read file %s: %s \n", path, error->message);
1802 g_error_free(error); 1802 g_error_free(error);
1806 } 1806 }
1807 1807
1808 g_return_val_if_fail(contents != NULL, list); 1808 g_return_val_if_fail(contents != NULL, list);
1809 1809
1810 purple_debug_info("QIP logger list", "File %s is found\n", path); 1810 purple_debug_info("QIP logger list", "File %s is found\n", path);
1811 1811
1812 /* Convert file contents from Cp1251 to UTF-8 codeset */ 1812 /* Convert file contents from Cp1251 to UTF-8 codeset */
1813 error = NULL; 1813 error = NULL;
1814 if (!(utf8_string = g_convert(contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) { 1814 if (!(utf8_string = g_convert(contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) {
1815 purple_debug_error("QIP logger list", 1815 purple_debug_error("QIP logger list",
1816 "Couldn't convert file %s to UTF-8: %s\n", path, error->message); 1816 "Couldn't convert file %s to UTF-8: %s\n", path, error->message);
1818 1818
1819 g_free(path); 1819 g_free(path);
1820 g_free(contents); 1820 g_free(contents);
1821 return list; 1821 return list;
1822 } 1822 }
1823 1823
1824 g_free(contents); 1824 g_free(contents);
1825 contents = g_markup_escape_text(utf8_string, -1); 1825 contents = g_markup_escape_text(utf8_string, -1);
1826 g_free(utf8_string); 1826 g_free(utf8_string);
1827 1827
1828 c = contents; 1828 c = contents;
1829 start_log = contents; 1829 start_log = contents;
1830 while (*c) { 1830 while (*c) {
1831 if (purple_str_has_prefix(c, QIP_LOG_IN_MESSAGE_ESC) || 1831 if (purple_str_has_prefix(c, QIP_LOG_IN_MESSAGE_ESC) ||
1832 purple_str_has_prefix(c, QIP_LOG_OUT_MESSAGE_ESC)) { 1832 purple_str_has_prefix(c, QIP_LOG_OUT_MESSAGE_ESC)) {
1833 1833
1834 gchar *new_line = c; 1834 gchar *new_line = c;
1835 1835
1836 /* find EOL */ 1836 /* find EOL */
1837 c = strstr(c, "\n"); 1837 c = strstr(c, "\n");
1838 c++; 1838 c++;
1839 1839
1840 /* Find the last '(' character. */ 1840 /* Find the last '(' character. */
1848 } 1848 }
1849 1849
1850 if (c != NULL) { 1850 if (c != NULL) {
1851 const char *timestamp = ++c; 1851 const char *timestamp = ++c;
1852 struct tm tm; 1852 struct tm tm;
1853 1853
1854 /* Parse the time, day, month and year */ 1854 /* Parse the time, day, month and year */
1855 if (sscanf(timestamp, "%u:%u:%u %u/%u/%u", 1855 if (sscanf(timestamp, "%u:%u:%u %u/%u/%u",
1856 &tm.tm_hour, &tm.tm_min, &tm.tm_sec, 1856 &tm.tm_hour, &tm.tm_min, &tm.tm_sec,
1857 &tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 6) { 1857 &tm.tm_mday, &tm.tm_mon, &tm.tm_year) != 6) {
1858 1858
1859 purple_debug_error("QIP logger list", 1859 purple_debug_error("QIP logger list",
1860 "Parsing timestamp error\n"); 1860 "Parsing timestamp error\n");
1861 } else { 1861 } else {
1862 tm.tm_mon -= 1; 1862 tm.tm_mon -= 1;
1863 tm.tm_year -= 1900; 1863 tm.tm_year -= 1900;
1864 1864
1865 /* Let the C library deal with 1865 /* Let the C library deal with
1866 * daylight savings time. */ 1866 * daylight savings time. */
1867 tm.tm_isdst = -1; 1867 tm.tm_isdst = -1;
1868 1868
1869 if (!prev_tm_init) { 1869 if (!prev_tm_init) {
1870 prev_tm = tm; 1870 prev_tm = tm;
1871 prev_tm_init = TRUE; 1871 prev_tm_init = TRUE;
1872 } else { 1872 } else {
1873 double time_diff = difftime(mktime(&tm), mktime(&prev_tm)); 1873 double time_diff = difftime(mktime(&tm), mktime(&prev_tm));
1874 1874
1875 if (time_diff > QIP_LOG_TIMEOUT) { 1875 if (time_diff > QIP_LOG_TIMEOUT) {
1876 PurpleLog *log; 1876 PurpleLog *log;
1877 1877
1878 /* filling data */ 1878 /* filling data */
1879 data = g_new0(struct qip_logger_data, 1); 1879 data = g_new0(struct qip_logger_data, 1);
1880 data->path = g_strdup(path); 1880 data->path = g_strdup(path);
1881 data->length = new_line - start_log; 1881 data->length = new_line - start_log;
1882 data->offset = offset; 1882 data->offset = offset;
1883 offset += data->length; 1883 offset += data->length;
1884 1884
1885 purple_debug_error("QIP logger list", 1885 purple_debug_error("QIP logger list",
1886 "Creating log: path = (%s); length = (%d); offset = (%d)\n", data->path, data->length, data->offset); 1886 "Creating log: path = (%s); length = (%d); offset = (%d)\n", data->path, data->length, data->offset);
1887 1887
1888 /* XXX: Look into this later... Should we pass in a struct tm? */ 1888 /* XXX: Look into this later... Should we pass in a struct tm? */
1889 log = purple_log_new(PURPLE_LOG_IM, sn, account, 1889 log = purple_log_new(PURPLE_LOG_IM, sn, account,
1890 NULL, mktime(&prev_tm), NULL); 1890 NULL, mktime(&prev_tm), NULL);
1891 1891
1892 log->logger = qip_logger; 1892 log->logger = qip_logger;
1893 log->logger_data = data; 1893 log->logger_data = data;
1894 1894
1895 list = g_list_append(list, log); 1895 list = g_list_append(list, log);
1896 1896
1897 prev_tm = tm; 1897 prev_tm = tm;
1898 start_log = new_line; 1898 start_log = new_line;
1899 } 1899 }
1900 } 1900 }
1901 1901
1902 /* find EOF */ 1902 /* find EOF */
1903 c = strstr(c, "\n"); 1903 c = strstr(c, "\n");
1904 c++; 1904 c++;
1905 } 1905 }
1906 } 1906 }
1907 } else { 1907 } else {
1908 c = strstr(c, "\n"); 1908 c = strstr(c, "\n");
1909 c++; 1909 c++;
1910 } 1910 }
1911 } 1911 }
1912 1912
1913 /* adding last log */ 1913 /* adding last log */
1914 if (prev_tm_init) { 1914 if (prev_tm_init) {
1915 PurpleLog *log; 1915 PurpleLog *log;
1916 1916
1917 /* filling data */ 1917 /* filling data */
1918 data = g_new0( 1918 data = g_new0(
1919 struct qip_logger_data, 1); 1919 struct qip_logger_data, 1);
1920 data->path = g_strdup(path); 1920 data->path = g_strdup(path);
1921 data->length = c - start_log; 1921 data->length = c - start_log;
1936 1936
1937 g_free(contents); 1937 g_free(contents);
1938 g_free(path); 1938 g_free(path);
1939 return list; 1939 return list;
1940 } 1940 }
1941 1941
1942 static char * qip_logger_read (PurpleLog *log, PurpleLogReadFlags *flags) 1942 static char * qip_logger_read (PurpleLog *log, PurpleLogReadFlags *flags)
1943 { 1943 {
1944 struct qip_logger_data *data; 1944 struct qip_logger_data *data;
1945 PurpleBuddy *buddy; 1945 PurpleBuddy *buddy;
1946 GString *formatted; 1946 GString *formatted;
1947 char *c; 1947 char *c;
1948 const char *line; 1948 const char *line;
1949 GError *error = NULL; 1949 GError *error = NULL;
1950 gchar *contents = NULL; 1950 gchar *contents = NULL;
1951 gsize length; 1951 gsize length;
1952 1952
1953 g_return_val_if_fail(log != NULL, g_strdup("")); 1953 g_return_val_if_fail(log != NULL, g_strdup(""));
1954 1954
1955 data = log->logger_data; 1955 data = log->logger_data;
1956 1956
1957 g_return_val_if_fail(data->path != NULL, g_strdup("")); 1957 g_return_val_if_fail(data->path != NULL, g_strdup(""));
1958 g_return_val_if_fail(data->length > 0, g_strdup("")); 1958 g_return_val_if_fail(data->length > 0, g_strdup(""));
1959 1959
1960 purple_debug_info("QIP logger read", "Reading %s\n", data->path); 1960 purple_debug_info("QIP logger read", "Reading %s\n", data->path);
1961 1961
1962 error = NULL; 1962 error = NULL;
1963 if (!g_file_get_contents(data->path, &contents, &length, &error)) 1963 if (!g_file_get_contents(data->path, &contents, &length, &error))
1964 if (error) { 1964 if (error) {
1965 purple_debug_error("QIP logger list", 1965 purple_debug_error("QIP logger list",
1966 "Couldn't read file %s \n", data->path); 1966 "Couldn't read file %s \n", data->path);
1967 1967
1968 g_error_free(error); 1968 g_error_free(error);
1969 } 1969 }
1970 if (contents) { 1970 if (contents) {
1971 gchar * utf8_string; 1971 gchar * utf8_string;
1972 1972
1973 /* We should convert file contents from Cp1251 to UTF-8 codeset */ 1973 /* We should convert file contents from Cp1251 to UTF-8 codeset */
1974 error = NULL; 1974 error = NULL;
1975 if (!(utf8_string = g_convert (contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) { 1975 if (!(utf8_string = g_convert (contents, length, "UTF-8", "Cp1251", NULL, NULL, &error))) {
1976 if (error) { 1976 if (error) {
1977 purple_debug_error("QIP logger read", 1977 purple_debug_error("QIP logger read",
1982 char *escaped; 1982 char *escaped;
1983 char *selected; 1983 char *selected;
1984 1984
1985 purple_debug_info("QIP logger read", 1985 purple_debug_info("QIP logger read",
1986 "File %s converted successfully\n", data->path); 1986 "File %s converted successfully\n", data->path);
1987 1987
1988 g_free(contents); 1988 g_free(contents);
1989 contents = utf8_string; 1989 contents = utf8_string;
1990 1990
1991 /* Load miscellaneous data. */ 1991 /* Load miscellaneous data. */
1992 buddy = purple_find_buddy(log->account, log->name); 1992 buddy = purple_find_buddy(log->account, log->name);
1993 1993
1994 escaped = g_markup_escape_text(contents, -1); 1994 escaped = g_markup_escape_text(contents, -1);
1995 g_free(contents); 1995 g_free(contents);
1996 contents = escaped; 1996 contents = escaped;
1997 1997
1998 selected = g_strndup(contents + data->offset, data->length + 2); 1998 selected = g_strndup(contents + data->offset, data->length + 2);
1999 selected[data->length] = '\n'; 1999 selected[data->length] = '\n';
2000 selected[data->length + 1] = '\0'; 2000 selected[data->length + 1] = '\0';
2001 2001
2002 g_free(contents); 2002 g_free(contents);
2003 contents = selected; 2003 contents = selected;
2004 2004
2005 /* Apply formatting... */ 2005 /* Apply formatting... */
2006 formatted = g_string_sized_new(strlen(contents)); 2006 formatted = g_string_sized_new(strlen(contents));
2007 c = contents; 2007 c = contents;
2008 line = contents; 2008 line = contents;
2009 2009
2010 while (*c) { 2010 while (*c) {
2011 gboolean is_in_message = FALSE; 2011 gboolean is_in_message = FALSE;
2012 2012
2013 if (purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC) || 2013 if (purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC) ||
2014 purple_str_has_prefix(line, QIP_LOG_OUT_MESSAGE_ESC)) { 2014 purple_str_has_prefix(line, QIP_LOG_OUT_MESSAGE_ESC)) {
2015 const char *buddy_name; 2015 const char *buddy_name;
2016 is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC); 2016 is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC);
2017 2017
2018 /* find EOL */ 2018 /* find EOL */
2019 c = strstr(c, "\n"); 2019 c = strstr(c, "\n");
2020 2020
2021 /* XXX: Do we need buddy_name when we have buddy->alias? */ 2021 /* XXX: Do we need buddy_name when we have buddy->alias? */
2022 buddy_name = ++c; 2022 buddy_name = ++c;
2023 2023
2024 /* searching '(' character from the end of the line */ 2024 /* searching '(' character from the end of the line */
2025 c = strstr(c, "\n"); 2025 c = strstr(c, "\n");
2026 while (*c && *c != '(') 2026 while (*c && *c != '(')
2027 --c; 2027 --c;
2028 2028
2029 if (*c == '(') { 2029 if (*c == '(') {
2030 const char *timestamp = c; 2030 const char *timestamp = c;
2031 int hour; 2031 int hour;
2032 int min; 2032 int min;
2033 int sec; 2033 int sec;
2034 2034
2035 timestamp++; 2035 timestamp++;
2036 2036
2037 /* Parse the time, day, month and year */ 2037 /* Parse the time, day, month and year */
2038 if (sscanf(timestamp, "%u:%u:%u", 2038 if (sscanf(timestamp, "%u:%u:%u",
2039 &hour, &min, &sec) != 3) { 2039 &hour, &min, &sec) != 3) {
2040 purple_debug_error("QIP logger read", 2040 purple_debug_error("QIP logger read",
2041 "Parsing timestamp error\n"); 2041 "Parsing timestamp error\n");
2042 } else { 2042 } else {
2043 g_string_append(formatted, "<font size=\"2\">"); 2043 g_string_append(formatted, "<font size=\"2\">");
2044 g_string_append_printf(formatted, 2044 g_string_append_printf(formatted,
2045 "(%u:%02u:%02u) %cM ", hour % 12, 2045 "(%u:%02u:%02u) %cM ", hour % 12,
2046 min, sec, (hour >= 12) ? 'P': 'A'); 2046 min, sec, (hour >= 12) ? 'P': 'A');
2047 g_string_append(formatted, "</font> "); 2047 g_string_append(formatted, "</font> ");
2048 2048
2049 if (is_in_message) { 2049 if (is_in_message) {
2050 if (buddy_name != NULL && buddy->alias) { 2050 if (buddy_name != NULL && buddy->alias) {
2051 g_string_append_printf(formatted, 2051 g_string_append_printf(formatted,
2052 "<span style=\"color: #A82F2F;\">" 2052 "<span style=\"color: #A82F2F;\">"
2053 "<b>%s</b></span>: ", buddy->alias); 2053 "<b>%s</b></span>: ", buddy->alias);
2054 } 2054 }
2055 } else { 2055 } else {
2056 const char *acct_name; 2056 const char *acct_name;
2060 2060
2061 g_string_append_printf(formatted, 2061 g_string_append_printf(formatted,
2062 "<span style=\"color: #16569E;\">" 2062 "<span style=\"color: #16569E;\">"
2063 "<b>%s</b></span>: ", acct_name); 2063 "<b>%s</b></span>: ", acct_name);
2064 } 2064 }
2065 2065
2066 /* find EOF */ 2066 /* find EOF */
2067 c = strstr(c, "\n"); 2067 c = strstr(c, "\n");
2068 line = ++c; 2068 line = ++c;
2069 } 2069 }
2070 } 2070 }
2071 } else { 2071 } else {
2072 if ((c = strstr(c, "\n"))) 2072 if ((c = strstr(c, "\n")))
2073 *c = '\0'; 2073 *c = '\0';
2074 2074
2075 if (line[0] != '\n' && line[0] != '\r') { 2075 if (line[0] != '\n' && line[0] != '\r') {
2076 2076
2077 g_string_append(formatted, line); 2077 g_string_append(formatted, line);
2078 g_string_append_c(formatted, '\n'); 2078 g_string_append_c(formatted, '\n');
2079 } 2079 }
2080 line = ++c; 2080 line = ++c;
2081 } 2081 }
2099 2099
2100 if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) { 2100 if (purple_prefs_get_bool("/plugins/core/log_reader/fast_sizes")) {
2101 return data ? data->length : 0; 2101 return data ? data->length : 0;
2102 } 2102 }
2103 2103
2104 text = qip_logger_read(log, NULL); 2104 text = qip_logger_read(log, NULL);
2105 size = strlen(text); 2105 size = strlen(text);
2106 g_free(text); 2106 g_free(text);
2107 2107
2108 return size; 2108 return size;
2109 } 2109 }
2281 2281
2282 #if 0 && GLIB_CHECK_VERSION(2,6,0) /* FIXME: Not tested yet. */ 2282 #if 0 && GLIB_CHECK_VERSION(2,6,0) /* FIXME: Not tested yet. */
2283 GKeyFile *key_file; 2283 GKeyFile *key_file;
2284 2284
2285 purple_debug_info("Trillian talk.ini read", "Reading %s\n", path); 2285 purple_debug_info("Trillian talk.ini read", "Reading %s\n", path);
2286 2286
2287 error = NULL; 2287 error = NULL;
2288 if (!g_key_file_load_from_file(key_file, path, G_KEY_FILE_NONE, GError &error)) { 2288 if (!g_key_file_load_from_file(key_file, path, G_KEY_FILE_NONE, GError &error)) {
2289 purple_debug_error("Trillian talk.ini read", 2289 purple_debug_error("Trillian talk.ini read",
2290 "Error reading talk.ini\n"); 2290 "Error reading talk.ini\n");
2291 if (error) 2291 if (error)
2370 #endif 2370 #endif
2371 2371
2372 /* Add QIP log directory preference. */ 2372 /* Add QIP log directory preference. */
2373 purple_prefs_add_none("/plugins/core/log_reader/qip"); 2373 purple_prefs_add_none("/plugins/core/log_reader/qip");
2374 2374
2375 #ifdef _WIN32 2375 #ifdef _WIN32
2376 /* Calculate default Messenger Plus! log directory. */ 2376 /* Calculate default Messenger Plus! log directory. */
2377 folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES); 2377 folder = wpurple_get_special_folder(CSIDL_PROGRAM_FILES);
2378 if (folder) { 2378 if (folder) {
2379 #endif 2379 #endif
2380 path = g_build_filename( 2380 path = g_build_filename(
2381 #ifdef _WIN32 2381 #ifdef _WIN32
2382 folder, 2382 folder,
2383 #else 2383 #else
2384 PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, "Program Files", 2384 PURPLE_LOG_READER_WINDOWS_MOUNT_POINT, "Program Files",
2385 #endif 2385 #endif
2386 "QIP", "Users", NULL); 2386 "QIP", "Users", NULL);
2433 messenger_plus_logger_finalize, 2433 messenger_plus_logger_finalize,
2434 messenger_plus_logger_list, 2434 messenger_plus_logger_list,
2435 messenger_plus_logger_read, 2435 messenger_plus_logger_read,
2436 messenger_plus_logger_size); 2436 messenger_plus_logger_size);
2437 purple_log_logger_add(messenger_plus_logger); 2437 purple_log_logger_add(messenger_plus_logger);
2438 2438
2439 #endif 2439 #endif
2440 2440
2441 /* The names of IM clients are marked for translation at the request of 2441 /* The names of IM clients are marked for translation at the request of
2442 translators who wanted to transliterate them. Many translators 2442 translators who wanted to transliterate them. Many translators
2443 choose to leave them alone. Choose what's best for your language. */ 2443 choose to leave them alone. Choose what's best for your language. */
2447 qip_logger_finalize, 2447 qip_logger_finalize,
2448 qip_logger_list, 2448 qip_logger_list,
2449 qip_logger_read, 2449 qip_logger_read,
2450 qip_logger_size); 2450 qip_logger_size);
2451 purple_log_logger_add(qip_logger); 2451 purple_log_logger_add(qip_logger);
2452 2452
2453 /* The names of IM clients are marked for translation at the request of 2453 /* The names of IM clients are marked for translation at the request of
2454 translators who wanted to transliterate them. Many translators 2454 translators who wanted to transliterate them. Many translators
2455 choose to leave them alone. Choose what's best for your language. */ 2455 choose to leave them alone. Choose what's best for your language. */
2456 msn_logger = purple_log_logger_new("msn", _("MSN Messenger"), 6, 2456 msn_logger = purple_log_logger_new("msn", _("MSN Messenger"), 6,
2457 NULL, 2457 NULL,