comparison src/gtkimhtml.c @ 8473:12fe38c195a6

[gaim-migrate @ 9206] " You can once again show how evil you are by typing >:) and getting it to render in spite of escaped HTML. This patch changes around the parsing code to catch smileys before eating just any HTML entity we bump into on the street. We try to catch entities at the beginning of smileys first, and if we're sure they're not smileys, then we eat them for breakfast. The patch also deals with eating any subsequent entities that may appear in any smileys (like :-&) so we don't end up with trailing leftovers. This patch description is making me hungry. FYI, I know this gtkimhtml is supposed to be not gaim dependent, but both the gaim_* functions that were preexisting and newly used in gtkimhtml code are all non-gaim dependent utility functions from util.c, so I felt their use was justified and acceptable." --Kevin Stange committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Fri, 19 Mar 2004 17:34:33 +0000
parents 5562e8a74c94
children 6d0869404696
comparison
equal deleted inserted replaced
8472:6d1c5321c55e 8473:12fe38c195a6
997 gint *len) 997 gint *len)
998 { 998 {
999 GtkSmileyTree *tree; 999 GtkSmileyTree *tree;
1000 GtkIMHtmlFontDetail *font; 1000 GtkIMHtmlFontDetail *font;
1001 char *sml = NULL; 1001 char *sml = NULL;
1002 char *unescaped = NULL;
1002 1003
1003 if (fonts) { 1004 if (fonts) {
1004 font = fonts->data; 1005 font = fonts->data;
1005 sml = font->sml; 1006 sml = font->sml;
1006 } 1007 }
1011 tree = g_hash_table_lookup(imhtml->smiley_data, sml); 1012 tree = g_hash_table_lookup(imhtml->smiley_data, sml);
1012 } 1013 }
1013 if (tree == NULL) 1014 if (tree == NULL)
1014 return FALSE; 1015 return FALSE;
1015 1016
1016 *len = gtk_smiley_tree_lookup (tree, text); 1017 unescaped = gaim_unescape_html(text);
1018 *len = gtk_smiley_tree_lookup (tree, unescaped);
1019 g_free(unescaped);
1017 return (*len > 0); 1020 return (*len > 0);
1018 } 1021 }
1019 1022
1020 GdkPixbufAnimation * 1023 GdkPixbufAnimation *
1021 gtk_smiley_tree_image (GtkIMHtml *imhtml, 1024 gtk_smiley_tree_image (GtkIMHtml *imhtml,
1915 } 1918 }
1916 c += tlen; 1919 c += tlen;
1917 pos += tlen; 1920 pos += tlen;
1918 if(tag) 1921 if(tag)
1919 g_free(tag); /* This was allocated back in VALID_TAG() */ 1922 g_free(tag); /* This was allocated back in VALID_TAG() */
1923 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) {
1924 GtkIMHtmlFontDetail *fd;
1925
1926 gchar *sml = NULL;
1927 gchar *unescaped = NULL;
1928 gint length = 0;
1929 if (fonts) {
1930 fd = fonts->data;
1931 sml = fd->sml;
1932 }
1933 if (url)
1934 gtk_imhtml_insert_link(imhtml, url, ws);
1935 else {
1936 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos);
1937 }
1938 unescaped = gaim_unescape_html(c);
1939 wpos = g_snprintf (ws, smilelen + 1, "%s", unescaped);
1940 g_free(unescaped);
1941
1942 gtk_imhtml_insert_smiley(imhtml, sml, ws);
1943
1944 ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
1945 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
1946
1947 while(length < smilelen)
1948 {
1949 if(*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
1950 c += tlen;
1951 pos += tlen;
1952 } else {
1953 c++;
1954 pos++;
1955 }
1956 length++;
1957 }
1958
1959 wpos = 0;
1960 ws[0] = 0;
1920 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) { 1961 } else if (*c == '&' && gtk_imhtml_is_amp_escape (c, &amp, &tlen)) {
1921 while(*amp) { 1962 while(*amp) {
1922 ws [wpos++] = *amp++; 1963 ws [wpos++] = *amp++;
1923 } 1964 }
1924 c += tlen; 1965 c += tlen;
1943 copied into the ws array. 1984 copied into the ws array.
1944 */ 1985 */
1945 ws [wpos++] = *c++; 1986 ws [wpos++] = *c++;
1946 pos++; 1987 pos++;
1947 } 1988 }
1948 } else if (imhtml->show_smileys && (gtk_imhtml_is_smiley (imhtml, fonts, c, &smilelen) || gtk_imhtml_is_smiley(imhtml, NULL, c, &smilelen))) {
1949 GtkIMHtmlFontDetail *fd;
1950
1951 gchar *sml = NULL;
1952 if (fonts) {
1953 fd = fonts->data;
1954 sml = fd->sml;
1955 }
1956 if (url)
1957 gtk_imhtml_insert_link(imhtml, url, ws);
1958 else {
1959 gtk_text_buffer_insert(imhtml->text_buffer, &iter, ws, wpos);
1960 }
1961 wpos = g_snprintf (ws, smilelen + 1, "%s", c);
1962 gtk_imhtml_insert_smiley(imhtml, sml, ws);
1963
1964 ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
1965 gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &iter, ins);
1966
1967 c += smilelen;
1968 pos += smilelen;
1969 wpos = 0;
1970 ws[0] = 0;
1971 } else if (*c) { 1989 } else if (*c) {
1972 ws [wpos++] = *c++; 1990 ws [wpos++] = *c++;
1973 pos++; 1991 pos++;
1974 } else { 1992 } else {
1975 break; 1993 break;