2005-01-14 [colin] 0.9.13cvs32
authorColin Leroy <colin@colino.net>
Fri, 14 Jan 2005 07:47:59 +0000 (07:47 +0000)
committerColin Leroy <colin@colino.net>
Fri, 14 Jan 2005 07:47:59 +0000 (07:47 +0000)
* src/msgcache.c
Fix possible double free, avoid putting 8k on the stack
* src/html.c
* src/html.h
Fix links spanning over lines, add some entities
* AUTHORS
Both patches by Rich Coe <Richard.Coe@med.ge.com>

AUTHORS
ChangeLog.claws
PATCHSETS
configure.ac
src/html.c
src/html.h
src/msgcache.c

diff --git a/AUTHORS b/AUTHORS
index d54ce8e..4afbe4f 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -216,3 +216,4 @@ contributors (beside the above; based on Changelog)
        IWAMOTO Kouichi
        Alex S Moore
        Felix Eckhofer
+       Rich Coe
index f9ba194..662c333 100644 (file)
@@ -1,3 +1,13 @@
+2005-01-14 [colin]     0.9.13cvs32
+
+       * src/msgcache.c
+               Fix possible double free, avoid putting 8k on the stack
+       * src/html.c
+       * src/html.h
+               Fix links spanning over lines, add some entities
+       * AUTHORS
+               Both patches by Rich Coe <Richard.Coe@med.ge.com>
+
 2005-01-09 [thorsten]  0.9.13cvs31
 
        * tools/calypso_convert.pl
index de2be7c..33a10bf 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.453 -r 1.454 ChangeLog; cvs diff -u -r 1.448 -r 1.449 ChangeLog.jp; cvs diff -u -r 1.73 -r 1.74 src/pop.c; cvs diff -u -r 1.23 -r 1.24 src/pop.h; ) > 0.9.13cvs29.patchset
 ( cvs diff -u -r 1.7 -r 1.8 src/prefs_filtering_action.c; ) > 0.9.13cvs30.patchset
 ( cvs diff -u -r 1.1 -r 1.2 tools/calypso_convert.pl; ) > 0.9.13cvs31.patchset
+( cvs diff -u -r 1.29 -r 1.30 src/msgcache.c; cvs diff -u -r 1.14 -r 1.15 src/html.c; cvs diff -u -r 1.3 -r 1.4 src/html.h; cvs diff -u -r 1.126 -r 1.127 AUTHORS; ) > 0.9.13cvs32.patchset
index 01f6b69..9d18879 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=13
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=31
+EXTRA_VERSION=32
 EXTRA_RELEASE=
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
index 47d6adc..fa32337 100644 (file)
@@ -405,12 +405,16 @@ gchar *html_parse(HTMLParser *parser)
 
        while (*parser->bufp != '\0') {
                switch (*parser->bufp) {
-               case '<':
-                       if (parser->str->len == 0)
-                               html_parse_tag(parser);
-                       else
-                               return parser->str->str;
-                       break;
+               case '<': {
+                       HTMLState st;
+                       st = html_parse_tag(parser);
+                       /* when we see an href, we need to flush the str
+                        * buffer.  Then collect all the chars until we
+                        * see the end anchor tag
+                        */
+                       if (HTML_HREF_BEG == st || HTML_HREF == st)
+                           return parser->str->str;
+                       } break;
                case '&':
                        html_parse_special(parser);
                        break;
@@ -632,12 +636,10 @@ static HTMLState html_parse_tag(HTMLParser *parser)
                        g_free(parser->href);
                        parser->href =
                                g_strdup(((HTMLAttr *)tag->attr->data)->value);
-                       parser->state = HTML_HREF;
+                       parser->state = HTML_HREF_BEG;
                }
        } else if (!strcmp(tag->name, "/a")) {
-               g_free(parser->href);
-               parser->href = NULL;
-               parser->state = HTML_NORMAL;
+               parser->state = HTML_HREF;
        } else if (!strcmp(tag->name, "p")) {
                parser->space = FALSE;
                if (!parser->empty_line) {
@@ -731,6 +733,69 @@ static void html_parse_special(HTMLParser *parser)
                        html_append_char(parser, ch);
                        parser->state = HTML_NORMAL;
                        return;
+               } else {
+                   char *symb = NULL;
+                   switch (ch) {
+                   /* http://www.w3schools.com/html/html_entitiesref.asp */
+                   case 338:   /* capital ligature OE  &OElig;  */
+                       symb = "OE";  break;
+                   case 339:   /* small ligature OE    &oelig;  */
+                       symb = "oe";  break;
+                   case 352:   /* capital S w/caron    &Scaron; */
+                   case 353:   /* small S w/caron      &scaron; */
+                   case 376:   /* cap Y w/ diaeres     &Yuml;   */
+                       break;
+                   case 710:   /* circumflex accent    &circ;   */
+                       symb = "^";  break;
+                   case 732:   /* small tilde          &tilde;  */
+                       symb = "~";  break;
+                   case 8194:  /* en space             &ensp;   */
+                   case 8195:  /* em space             &emsp;   */
+                   case 8201:  /* thin space           &thinsp; */
+                       symb = " ";  break;
+                   case 8204:  /* zero width non-joiner &zwnj;  */
+                   case 8205:  /* zero width joiner    &zwj;    */
+                   case 8206:  /* l-t-r mark           &lrm;    */
+                   case 8207:  /* r-t-l mark           &rlm     */
+                       break;
+                   case 8211:  /* en dash              &ndash;  */
+                       symb = "-";  break;
+                   case 8212:  /* em dash              &mdash;  */
+                       symb = "--";  break;
+                   case 8216:  /* l single quot mark   &lsquo;  */
+                       symb = "`";  break;
+                   case 8217:  /* r single quot mark   &rsquo;  */
+                       symb = "'";  break;
+                   case 8218:  /* single low-9 quot    &sbquo;  */
+                       symb = ",";  break;
+                   case 8220:  /* l double quot mark   &ldquo;  */
+                       symb = "``";  break;
+                   case 8221:  /* r double quot mark   &rdquo;  */
+                       symb = "''";  break;
+                   case 8222:  /* double low-9 quot    &bdquo;  */
+                       symb = ",,";  break;
+                   case 8224:  /* dagger               &dagger; */
+                   case 8225:  /* double dagger        &Dagger; */
+                       break;
+                   case 8230:  /* horizontal ellipsis  &hellip; */
+                       symb = "...";  break;
+                   case 8240:  /* per mile             &permil; */
+                       symb = "\%o";  break;
+                   case 8249:  /* l-pointing angle quot &lsaquo; */
+                       symb = "<";  break;
+                   case 8250:  /* r-pointing angle quot &rsaquo; */
+                       symb = ">";  break;
+                   case 8364:  /* euro                 &euro;   */
+                       symb = "&euro";  break;
+                   case 8482:  /* trademark            &trade;  */
+                       symb  = "(TM)";  break;
+                   default: break;
+                   }
+                   if (symb) {
+                       html_append_str(parser, symb, -1);
+                       parser->state = HTML_NORMAL;
+                       return;
+                   }
                }
        }
 
index 7267c17..c7e1a75 100644 (file)
@@ -38,7 +38,8 @@ typedef enum
        HTML_UNKNOWN,
        HTML_CONV_FAILED,
        HTML_ERR,
-       HTML_EOF
+       HTML_EOF,
+       HTML_HREF_BEG
 } HTMLState;
 
 typedef struct _HTMLParser     HTMLParser;
index 07893a5..1c7229a 100644 (file)
@@ -237,9 +237,10 @@ gint msgcache_get_memory_usage(MsgCache *cache)
 #define READ_CACHE_DATA_INT(n, fp) \
 { \
        guint32 idata; \
+       size_t ni; \
  \
-       if (fread(&idata, sizeof(idata), 1, fp) != 1) { \
-               g_warning("Cache data is corrupted\n"); \
+       if (sizeof(idata) != (ni = fread(&idata, 1, sizeof(idata), fp))) { \
+               g_warning("read_int: Cache data corrupted, read %d of %d at offset %d\n", ni, sizeof(idata), ftell(fp)); \
                procmsg_msginfo_free(msginfo); \
                error = TRUE; \
                break; \
@@ -322,55 +323,39 @@ static FILE *msgcache_open_data_file(const gchar *file, gint version,
        return fp;
 }
 
-static gint msgcache_read_cache_data_str(FILE *fp, gchar **str, StringConverter *conv)
+static gint 
+msgcache_read_cache_data_str(FILE *fp, gchar **str, StringConverter *conv)
 {
-       gchar buf[BUFFSIZE], *tmpstr = NULL;
-       gint ret = 0;
-       guint32 len;
-
-       if (fread(&len, sizeof(len), 1, fp) == 1) {
-               if (len > G_MAXINT)
-                       ret = -1;
-               else {
-                       gchar *tmp = NULL;
-
-                       while (len > 0) {
-                               size_t size = MIN(len, BUFFSIZE - 1);
-
-                               if (fread(buf, size, 1, fp) != 1) {
-                                       ret = -1;
-                                       if (tmp) g_free(tmp);
-                                       tmpstr = NULL;
-                                       break;
-                               }
-
-                               buf[size] = '\0';
-                               if (tmp) {
-                                       *str = g_strconcat(tmp, buf, NULL);
-                                       g_free(tmp);
-                                       tmp = tmpstr;
-                               } else
-                                       tmp = tmpstr = g_strdup(buf);
-
-                               len -= size;
-                       }
-               }
-       } else
-               ret = -1;
-
-       if (ret < 0)
-               g_warning("Cache data is corrupted\n");
-
-       if (tmpstr != NULL && conv != NULL) {
-               *str = conv->convert(conv, tmpstr);
-               g_free(tmpstr);
-       } else if (tmpstr != NULL) {
-               *str = g_strdup(tmpstr);
-               g_free(tmpstr);
-       } else
-               *str = NULL;
-
-       return ret;
+    gchar *tmpstr = NULL;
+    size_t ni;
+    guint32 len;
+
+    *str = NULL;
+    if (sizeof(len) != (ni = fread(&len, 1, sizeof(len), fp))
+       || len > G_MAXINT) {
+       g_warning("read_data_str: Cache data (len) corrupted, read %d of %d bytes at offset %d\n", 
+               ni, sizeof(len), ftell(fp));
+       return -1;
+    }
+    if (0 == len)
+       return 0;
+    tmpstr = g_malloc(len + 1);
+
+    if (len != (ni = fread(tmpstr, 1, len, fp))) {
+       g_warning("read_data_str: Cache data corrupted, read %d of %d bytes at offset %d\n", 
+               ni, len, ftell(fp));
+       g_free(tmpstr);
+       return -1;
+    }
+    tmpstr[len] = 0;
+
+    if (conv != NULL) {
+           *str = conv->convert(conv, tmpstr);
+           g_free(tmpstr);
+    } else 
+           *str = tmpstr;
+
+    return 0;
 }
 
 gchar *strconv_strdup_convert(StringConverter *conv, gchar *srcstr)