From 1beb1e938fe979fb8051126218295fbd878ad9b0 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 7 Sep 2016 21:28:02 +0100 Subject: make GTK frontend mime type processing use explicit ascii processing --- frontends/gtk/fetch.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'frontends/gtk') diff --git a/frontends/gtk/fetch.c b/frontends/gtk/fetch.c index 6b6e41d39..154f43708 100644 --- a/frontends/gtk/fetch.c +++ b/frontends/gtk/fetch.c @@ -17,12 +17,24 @@ * along with this program. If not, see . */ +/** + * \file + * file extension to mimetype mapping for the GTK frontend + * + * allows GTK frontend to map file extension to mime types using a + * default builtin list and /etc/mime.types file if present. + * + * mime type and content type handling is derived from the BNF in + * RFC822 section 3.3, RFC2045 section 5.1 and RFC6838 section + * 4.2. Upshot is their charset and parsing is all a strict subset of + * ASCII hence not using locale dependant ctype functions for parsing. + */ + #include #include #include #include #include -#include #include #include #include @@ -32,6 +44,7 @@ #include "utils/filepath.h" #include "utils/file.h" #include "utils/nsurl.h" +#include "utils/ascii.h" #include "netsurf/fetch.h" #include "gtk/gui.h" @@ -50,15 +63,6 @@ void gtk_fetch_filetype_init(const char *mimefile) mime_hash = hash_create(HASH_SIZE); - /* first, check to see if /etc/mime.types in preference */ - - if ((stat("/etc/mime.types", &statbuf) == 0) && - S_ISREG(statbuf.st_mode)) { - mimefile = "/etc/mime.types"; - } - - fh = fopen(mimefile, "r"); - /* Some OSes (mentioning no Solarises) have a worthlessly tiny * /etc/mime.types that don't include essential things, so we * pre-seed our hash with the essentials. These will get @@ -78,6 +82,13 @@ void gtk_fetch_filetype_init(const char *mimefile) hash_add(mime_hash, "spr", "image/x-riscos-sprite"); hash_add(mime_hash, "bmp", "image/bmp"); + /* first, check to see if /etc/mime.types in preference */ + if ((stat("/etc/mime.types", &statbuf) == 0) && + S_ISREG(statbuf.st_mode)) { + mimefile = "/etc/mime.types"; + } + + fh = fopen(mimefile, "r"); if (fh == NULL) { LOG("Unable to open a mime.types file, so using a minimal one for you."); return; @@ -93,7 +104,7 @@ void gtk_fetch_filetype_init(const char *mimefile) ptr = line; /* search for the first non-whitespace character */ - while (isspace(*ptr)) { + while (ascii_is_space(*ptr)) { ptr++; } @@ -106,7 +117,9 @@ void gtk_fetch_filetype_init(const char *mimefile) /* search for the first non-whitespace char or NUL or * NL */ - while (*ptr && (!isspace(*ptr)) && *ptr != '\n') { + while (*ptr && + (!ascii_is_space(*ptr)) && + *ptr != '\n') { ptr++; } @@ -121,7 +134,7 @@ void gtk_fetch_filetype_init(const char *mimefile) /* search for the first non-whitespace character which * will be the first filename extenion */ - while (isspace(*ptr)) { + while (ascii_is_space(*ptr)) { ptr++; } @@ -132,7 +145,7 @@ void gtk_fetch_filetype_init(const char *mimefile) * NUL or NL which is the end of the ext. */ while (*ptr && - (!isspace(*ptr)) && + (!ascii_is_space(*ptr)) && *ptr != '\n') { ptr++; } @@ -153,7 +166,7 @@ void gtk_fetch_filetype_init(const char *mimefile) * NUL or NL, to find start of next ext. */ while (*ptr && - (isspace(*ptr)) && + (ascii_is_space(*ptr)) && *ptr != '\n') { ptr++; } @@ -221,7 +234,7 @@ const char *fetch_filetype(const char *unix_path) */ lowerchar = ext; while (*lowerchar) { - *lowerchar = tolower(*lowerchar); + *lowerchar = ascii_to_lower(*lowerchar); lowerchar++; } -- cgit v1.2.3