Mercurial > pidgin.yaz
changeset 30587:52ffd59b26fc
merge of '34e44fc5b81fa29b233deac42ea221cb1c367101'
and '3ccde42b2f5cfa1fae01e997cfa85f4f9b89abe5'
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Thu, 03 Jun 2010 23:13:03 +0000 |
parents | 626480462902 (diff) 98de21a2aa9a (current diff) |
children | 89de882d25b1 ed909ccaeb36 9e7fc6d8ee18 |
files | |
diffstat | 1 files changed, 63 insertions(+), 161 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/util.c Thu Jun 03 04:10:13 2010 +0000 +++ b/libpurple/util.c Thu Jun 03 23:13:03 2010 +0000 @@ -2053,6 +2053,45 @@ return FALSE; } +static const char * +process_link(GString *ret, + const char *start, const char *c, + int matchlen, + const char *urlprefix, + int inside_paren) +{ + char *url_buf, *tmpurlbuf; + const char *t; + + for (t = c;; t++) { + if (!badchar(*t) && !badentity(t)) + continue; + + if (t - c == matchlen) + break; + + if (*t == ',' && *(t + 1) != ' ') { + continue; + } + + if (t > start && *(t - 1) == '.') + t--; + if (t > start && *(t - 1) == ')' && inside_paren > 0) + t--; + + url_buf = g_strndup(c, t - c); + tmpurlbuf = purple_unescape_html(url_buf); + g_string_append_printf(ret, "<A HREF=\"%s%s\">%s</A>", + urlprefix, + tmpurlbuf, url_buf); + g_free(tmpurlbuf); + g_free(url_buf); + return t; + } + + return c; +} + char * purple_markup_linkify(const char *text) { @@ -2100,129 +2139,22 @@ break; } } - } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) || - (!g_ascii_strncasecmp(c, "https://", 8)))) { - t = c; - while (1) { - if (badchar(*t) || badentity(t)) { - - if ((!g_ascii_strncasecmp(c, "http://", 7) && (t - c == 7)) || - (!g_ascii_strncasecmp(c, "https://", 8) && (t - c == 8))) { - break; - } - - if (*(t) == ',' && (*(t + 1) != ' ')) { - t++; - continue; - } - - if (*(t - 1) == '.') - t--; - if ((*(t - 1) == ')' && (inside_paren > 0))) { - t--; - } - - url_buf = g_strndup(c, t - c); - tmpurlbuf = purple_unescape_html(url_buf); - g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", - tmpurlbuf, url_buf); - g_free(url_buf); - g_free(tmpurlbuf); - c = t; - break; - } - t++; - - } - } else if (!g_ascii_strncasecmp(c, "www.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) { - if (c[4] != '.') { - t = c; - while (1) { - if (badchar(*t) || badentity(t)) { - if (t - c == 4) { - break; - } - - if (*(t) == ',' && (*(t + 1) != ' ')) { - t++; - continue; - } - - if (*(t - 1) == '.') - t--; - if ((*(t - 1) == ')' && (inside_paren > 0))) { - t--; - } - url_buf = g_strndup(c, t - c); - tmpurlbuf = purple_unescape_html(url_buf); - g_string_append_printf(ret, - "<A HREF=\"http://%s\">%s</A>", tmpurlbuf, - url_buf); - g_free(url_buf); - g_free(tmpurlbuf); - c = t; - break; - } - t++; - } - } - } else if (!g_ascii_strncasecmp(c, "ftp://", 6) || !g_ascii_strncasecmp(c, "sftp://", 7)) { - t = c; - while (1) { - if (badchar(*t) || badentity(t)) { - - if ((!g_ascii_strncasecmp(c, "ftp://", 6) && (t - c == 6)) || - (!g_ascii_strncasecmp(c, "sftp://", 7) && (t - c == 7))) { - break; - } - - if (*(t - 1) == '.') - t--; - if ((*(t - 1) == ')' && (inside_paren > 0))) { - t--; - } - url_buf = g_strndup(c, t - c); - tmpurlbuf = purple_unescape_html(url_buf); - g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", - tmpurlbuf, url_buf); - g_free(url_buf); - g_free(tmpurlbuf); - c = t; - break; - } - if (!t) - break; - t++; - - } - } else if (!g_ascii_strncasecmp(c, "ftp.", 4) && (c == text || badchar(c[-1]) || badentity(c-1))) { - if (c[4] != '.') { - t = c; - while (1) { - if (badchar(*t) || badentity(t)) { - if (t - c == 4) { - break; - } - if (*(t - 1) == '.') - t--; - if ((*(t - 1) == ')' && (inside_paren > 0))) { - t--; - } - url_buf = g_strndup(c, t - c); - tmpurlbuf = purple_unescape_html(url_buf); - g_string_append_printf(ret, - "<A HREF=\"ftp://%s\">%s</A>", tmpurlbuf, - url_buf); - g_free(url_buf); - g_free(tmpurlbuf); - c = t; - break; - } - if (!t) - break; - t++; - } - } + } else if (!g_ascii_strncasecmp(c, "http://", 7)) { + c = process_link(ret, text, c, 7, "", inside_paren); + } else if (!g_ascii_strncasecmp(c, "https://", 8)) { + c = process_link(ret, text, c, 8, "", inside_paren); + } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) { + c = process_link(ret, text, c, 6, "", inside_paren); + } else if (!g_ascii_strncasecmp(c, "sftp://", 7)) { + c = process_link(ret, text, c, 7, "", inside_paren); + } else if (!g_ascii_strncasecmp(c, "file://", 7)) { + c = process_link(ret, text, c, 7, "", inside_paren); + } else if (!g_ascii_strncasecmp(c, "www.", 4) && c[4] != '.' && (c == text || badchar(c[-1]) || badentity(c-1))) { + c = process_link(ret, text, c, 4, "http://", inside_paren); + } else if (!g_ascii_strncasecmp(c, "ftp.", 4) && c[4] != '.' && (c == text || badchar(c[-1]) || badentity(c-1))) { + c = process_link(ret, text, c, 4, "ftp://", inside_paren); + } else if (!g_ascii_strncasecmp(c, "xmpp:", 5) && (c == text || badchar(c[-1]) || badentity(c-1))) { + c = process_link(ret, text, c, 5, "", inside_paren); } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) { t = c; while (1) { @@ -2231,7 +2163,7 @@ if (t - c == 7) { break; } - if (*(t - 1) == '.') + if (t > text && *(t - 1) == '.') t--; if ((d = strstr(c + 7, "?")) != NULL && d < t) url_buf = g_strndup(c + 7, d - c - 7); @@ -2251,43 +2183,7 @@ c = t; break; } - if (!t) - break; t++; - - } - } else if ((*c=='x') && (!g_ascii_strncasecmp(c, "xmpp:", 5)) && - (c == text || badchar(c[-1]) || badentity(c-1))) { - t = c; - while (1) { - if (badchar(*t) || badentity(t)) { - - if (t - c == 5) { - break; - } - - if (*(t) == ',' && (*(t + 1) != ' ')) { - t++; - continue; - } - - if (*(t - 1) == '.') - t--; - if ((*(t - 1) == ')' && (inside_paren > 0))) { - t--; - } - - url_buf = g_strndup(c, t - c); - tmpurlbuf = purple_unescape_html(url_buf); - g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>", - tmpurlbuf, url_buf); - g_free(url_buf); - g_free(tmpurlbuf); - c = t; - break; - } - t++; - } } else if (c != text && (*c == '@')) { int flag; @@ -4960,7 +4856,13 @@ } } } - +#ifdef _WIN32 + /* File/Directory names in windows cannot end in periods/spaces. + * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx + */ + while (j > 0 && (buf[j - 1] == '.' || buf[j - 1] == ' ')) + j--; +#endif buf[j] = '\0'; return buf;