Mercurial > pidgin.yaz
comparison libpurple/plugins/log_reader.c @ 32337:5cb66143ae2a
propagate from branch 'im.pidgin.pidgin' (head 8f0dbb75e0842b6df34c773ceb3a62e07819c532)
to branch 'im.pidgin.pidgin.mxit' (head 58ce8d40af953c67a284a42e026ccdbfd25ffaa8)
author | andrew.victor@mxit.com |
---|---|
date | Fri, 12 Aug 2011 21:41:34 +0000 |
parents | b863432e81d1 |
children | 61ce89013291 |
comparison
equal
deleted
inserted
replaced
32336:88a1d883e65f | 32337:5cb66143ae2a |
---|---|
1452 { | 1452 { |
1453 const char *link; | 1453 const char *link; |
1454 const char *footer = NULL; | 1454 const char *footer = NULL; |
1455 GString *temp = NULL; | 1455 GString *temp = NULL; |
1456 | 1456 |
1457 if ((c = strstr(c, "\n"))) | 1457 /* There's always a trailing '\n' at the end of the file (see above), so |
1458 { | 1458 * just quit out if we don't find another, because we're at the end. |
1459 *c = '\0'; | 1459 */ |
1460 c++; | 1460 c = strchr(c, '\n'); |
1461 } | 1461 if (!c) |
1462 break; | |
1463 | |
1464 *c = '\0'; | |
1465 c++; | |
1462 | 1466 |
1463 /* Convert links. | 1467 /* Convert links. |
1464 * | 1468 * |
1465 * The format is (Link: URL)URL | 1469 * The format is (Link: URL)URL |
1466 * So, I want to find each occurance of "(Link: " and replace that chunk with: | 1470 * So, I want to find each occurance of "(Link: " and replace that chunk with: |
1480 if (*link) | 1484 if (*link) |
1481 { | 1485 { |
1482 char *end_paren; | 1486 char *end_paren; |
1483 char *space; | 1487 char *space; |
1484 | 1488 |
1485 if (!(end_paren = strstr(link, ")"))) | 1489 if (!(end_paren = strchr(link, ')'))) |
1486 { | 1490 { |
1487 /* Something is not as we expect. Bail out. */ | 1491 /* Something is not as we expect. Bail out. */ |
1488 break; | 1492 break; |
1489 } | 1493 } |
1490 | 1494 |
1491 if (!temp) | 1495 if (!temp) |
1492 temp = g_string_sized_new(c ? (c - 1 - line) : strlen(line)); | 1496 temp = g_string_sized_new(strlen(line)); |
1493 | 1497 |
1494 g_string_append_len(temp, line, (tmp - line)); | 1498 g_string_append_len(temp, line, (tmp - line)); |
1495 | 1499 |
1496 /* Start an <a> tag. */ | 1500 /* Start an <a> tag. */ |
1497 g_string_append(temp, "<a href=\""); | 1501 g_string_append(temp, "<a href=\""); |
1502 /* Finish the <a> tag. */ | 1506 /* Finish the <a> tag. */ |
1503 g_string_append(temp, "\">"); | 1507 g_string_append(temp, "\">"); |
1504 | 1508 |
1505 /* The \r is a bit of a hack to keep there from being a \r in | 1509 /* The \r is a bit of a hack to keep there from being a \r in |
1506 * the link text, which may not matter. */ | 1510 * the link text, which may not matter. */ |
1507 if ((space = strstr(end_paren, " ")) || (space = strstr(end_paren, "\r"))) | 1511 if ((space = strchr(end_paren, ' ')) || (space = strchr(end_paren, '\r'))) |
1508 { | 1512 { |
1509 g_string_append_len(temp, end_paren + 1, space - end_paren - 1); | 1513 g_string_append_len(temp, end_paren + 1, space - end_paren - 1); |
1510 | 1514 |
1511 /* Close the <a> tag. */ | 1515 /* Close the <a> tag. */ |
1512 g_string_append(temp, "</a>"); | 1516 g_string_append(temp, "</a>"); |
1537 } | 1541 } |
1538 | 1542 |
1539 if (*line == '[') { | 1543 if (*line == '[') { |
1540 const char *timestamp; | 1544 const char *timestamp; |
1541 | 1545 |
1542 if ((timestamp = strstr(line, "]"))) { | 1546 if ((timestamp = strchr(line, ']'))) { |
1543 line++; | 1547 line++; |
1544 /* TODO: Parse the timestamp and convert it to Purple's format. */ | 1548 /* TODO: Parse the timestamp and convert it to Purple's format. */ |
1545 g_string_append(formatted, "<font size=\"2\">("); | 1549 g_string_append(formatted, "<font size=\"2\">("); |
1546 g_string_append_len(formatted, line, (timestamp - line)); | 1550 g_string_append_len(formatted, line, (timestamp - line)); |
1547 g_string_append(formatted,")</font> "); | 1551 g_string_append(formatted,")</font> "); |
1656 "<span style=\"color: #A82F2F;\">" | 1660 "<span style=\"color: #A82F2F;\">" |
1657 "<b>%s</b></span>: ", alias); | 1661 "<b>%s</b></span>: ", alias); |
1658 } | 1662 } |
1659 } | 1663 } |
1660 } else { | 1664 } else { |
1661 const char *line2 = strstr(line, ":"); | 1665 const char *line2 = strchr(line, ':'); |
1662 if (line2) { | 1666 if (line2) { |
1663 const char *acct_name; | 1667 const char *acct_name; |
1664 line2++; | 1668 line2++; |
1665 line = line2; | 1669 line = line2; |
1666 acct_name = purple_account_get_alias(log->account); | 1670 acct_name = purple_account_get_alias(log->account); |
1817 start_log = contents; | 1821 start_log = contents; |
1818 while (main_cycle) { | 1822 while (main_cycle) { |
1819 | 1823 |
1820 gboolean add_new_log = FALSE; | 1824 gboolean add_new_log = FALSE; |
1821 | 1825 |
1822 if (*c) { | 1826 if (c && *c) { |
1823 if (purple_str_has_prefix(c, QIP_LOG_IN_MESSAGE) || | 1827 if (purple_str_has_prefix(c, QIP_LOG_IN_MESSAGE) || |
1824 purple_str_has_prefix(c, QIP_LOG_OUT_MESSAGE)) { | 1828 purple_str_has_prefix(c, QIP_LOG_OUT_MESSAGE)) { |
1825 | 1829 |
1826 char *tmp; | 1830 char *tmp; |
1827 | 1831 |
1828 new_line = c; | 1832 new_line = c; |
1829 | 1833 |
1830 /* find EOL */ | 1834 /* find EOL */ |
1831 c = strstr(c, "\n"); | 1835 c = strchr(c, '\n'); |
1832 c++; | 1836 c++; |
1833 | 1837 |
1834 /* Find the last '(' character. */ | 1838 /* Find the last '(' character. */ |
1835 if ((tmp = strstr(c, "\n")) != NULL) { | 1839 if ((tmp = strchr(c, '\n')) != NULL) { |
1836 while (*tmp && *tmp != '(') --tmp; | 1840 while (*tmp && *tmp != '(') --tmp; |
1837 c = tmp; | 1841 c = tmp; |
1838 } else { | 1842 } else { |
1839 while (*c) | 1843 while (*c) |
1840 c++; | 1844 c++; |
1900 | 1904 |
1901 prev_tm = tm; | 1905 prev_tm = tm; |
1902 start_log = new_line; | 1906 start_log = new_line; |
1903 } | 1907 } |
1904 | 1908 |
1905 if (*c) { | 1909 if (c && *c) { |
1906 /* find EOF */ | 1910 /* find EOF */ |
1907 c = strstr(c, "\n"); | 1911 if ((c = strchr(c, '\n'))) |
1908 c++; | 1912 c++; |
1909 } | 1913 } |
1910 } | 1914 } |
1911 | 1915 |
1912 g_free(contents); | 1916 g_free(contents); |
1913 g_free(path); | 1917 g_free(path); |
1981 const char *buddy_name; | 1985 const char *buddy_name; |
1982 | 1986 |
1983 is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC); | 1987 is_in_message = purple_str_has_prefix(line, QIP_LOG_IN_MESSAGE_ESC); |
1984 | 1988 |
1985 /* find EOL */ | 1989 /* find EOL */ |
1986 c = strstr(c, "\n"); | 1990 c = strchr(c, '\n'); |
1987 | 1991 |
1988 /* XXX: Do we need buddy_name when we have buddy->alias? */ | 1992 /* XXX: Do we need buddy_name when we have buddy->alias? */ |
1989 buddy_name = ++c; | 1993 buddy_name = ++c; |
1990 | 1994 |
1991 /* Find the last '(' character. */ | 1995 /* Find the last '(' character. */ |
1992 if ((tmp = strstr(c, "\n")) != NULL) { | 1996 if ((tmp = strchr(c, '\n')) != NULL) { |
1993 while (*tmp && *tmp != '(') --tmp; | 1997 while (*tmp && *tmp != '(') --tmp; |
1994 c = tmp; | 1998 c = tmp; |
1995 } else { | 1999 } else { |
1996 while (*c) | 2000 while (*c) |
1997 c++; | 2001 c++; |
2040 "<span style=\"color: #16569E;\">" | 2044 "<span style=\"color: #16569E;\">" |
2041 "<b>%s</b></span>: ", acct_name); | 2045 "<b>%s</b></span>: ", acct_name); |
2042 } | 2046 } |
2043 | 2047 |
2044 /* find EOF */ | 2048 /* find EOF */ |
2045 c = strstr(c, "\n"); | 2049 c = strchr(c, '\n'); |
2046 line = ++c; | 2050 line = ++c; |
2047 } | 2051 } |
2048 } | 2052 } |
2049 } else { | 2053 } else { |
2050 if ((c = strstr(c, "\n"))) | 2054 if ((c = strchr(c, '\n'))) |
2051 *c = '\0'; | 2055 *c = '\0'; |
2052 | 2056 |
2053 if (line[0] != '\n' && line[0] != '\r') { | 2057 if (line[0] != '\n' && line[0] != '\r') { |
2054 | 2058 |
2055 g_string_append(formatted, line); | 2059 g_string_append(formatted, line); |
2184 " path = (%s)," | 2188 " path = (%s)," |
2185 " offset = (%d)," | 2189 " offset = (%d)," |
2186 " length = (%d)\n", | 2190 " length = (%d)\n", |
2187 sn, data->path, data->offset, data->length); | 2191 sn, data->path, data->offset, data->length); |
2188 } | 2192 } |
2189 c = strstr(c, "\n"); | 2193 c = strchr(c, '\n'); |
2190 c++; | 2194 c++; |
2191 } | 2195 } |
2192 | 2196 |
2193 /* I've seen the file end without the AMSN_LOG_CONV_END bit */ | 2197 /* I've seen the file end without the AMSN_LOG_CONV_END bit */ |
2194 if (found_start) { | 2198 if (found_start) { |
2340 start = contents; | 2344 start = contents; |
2341 while (start && *start) { | 2345 while (start && *start) { |
2342 char *end; | 2346 char *end; |
2343 char *old_tag; | 2347 char *old_tag; |
2344 char *tag; | 2348 char *tag; |
2345 end = strstr(start, "\n"); | 2349 end = strchr(start, '\n'); |
2346 if (!end) | 2350 if (!end) |
2347 break; | 2351 break; |
2348 *end = '\0'; | 2352 *end = '\0'; |
2349 if (purple_str_has_prefix(start, AMSN_LOG_FORMAT_TAG) && in_span) { | 2353 if (purple_str_has_prefix(start, AMSN_LOG_FORMAT_TAG) && in_span) { |
2350 /* New format for this line */ | 2354 /* New format for this line */ |