diff options
-rw-r--r-- | base/third_party/xdg_mime/README.chromium | 8 | ||||
-rw-r--r-- | base/third_party/xdg_mime/compile.patch | 10 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmime.c | 24 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmime.h | 6 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimealias.c | 2 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimecache.c | 161 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimeglob.c | 175 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimeglob.h | 6 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimeicon.c | 2 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimeint.c | 17 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimeint.h | 1 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimemagic.c | 2 | ||||
-rw-r--r-- | base/third_party/xdg_mime/xdgmimeparent.c | 2 |
13 files changed, 294 insertions, 122 deletions
diff --git a/base/third_party/xdg_mime/README.chromium b/base/third_party/xdg_mime/README.chromium index 74913ff..29d239a 100644 --- a/base/third_party/xdg_mime/README.chromium +++ b/base/third_party/xdg_mime/README.chromium @@ -3,12 +3,8 @@ URL: http://freedesktop.org License: Academic Free License version 2.0 or LGPL v2 The code in this directory is synced from: -http://svn.gnome.org/svn/glib/trunk/gio/xdgmime/ -@ r7784 on 2009/05/11. -This version contains some bugfixes to the original code. - -The above link is dead and the code is now hosted at -http://cgit.freedesktop.org/xdg/xdgmime. +git://anongit.freedesktop.org/xdg/xdgmime +@ 2cdd8d36d7930d5a594587286cb1949ff62f7027 on 2012/08/06. In addition, we have the following patch(es): - compile.patch: small tweaks to make the code compile. diff --git a/base/third_party/xdg_mime/compile.patch b/base/third_party/xdg_mime/compile.patch index 7b3a09e..cd055ed 100644 --- a/base/third_party/xdg_mime/compile.patch +++ b/base/third_party/xdg_mime/compile.patch @@ -15,13 +15,3 @@ } - - ---- a/xdgmimeglob.c -+++ b/xdgmimeglob.c -@@ -375,7 +375,6 @@ - int i, n; - MimeWeight mimes[10]; - int n_mimes = 10; -- xdg_unichar_t *ucs4; - int len; - - /* First, check the literals */ diff --git a/base/third_party/xdg_mime/xdgmime.c b/base/third_party/xdg_mime/xdgmime.c index c9bcfba..c7b16bb 100644 --- a/base/third_party/xdg_mime/xdgmime.c +++ b/base/third_party/xdg_mime/xdgmime.c @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include "xdgmime.h" @@ -64,6 +64,8 @@ XdgMimeCache **_caches = NULL; static int n_caches = 0; const char xdg_mime_type_unknown[] = "application/octet-stream"; +const char xdg_mime_type_empty[] = "application/x-zerosize"; +const char xdg_mime_type_textplain[] = "text/plain"; enum @@ -165,7 +167,7 @@ xdg_mime_init_from_directory (const char *directory) strcpy (file_name, directory); strcat (file_name, "/mime/globs2"); if (stat (file_name, &st) == 0) { - _xdg_mime_glob_read_from_file (global_hash, file_name); + _xdg_mime_glob_read_from_file (global_hash, file_name, TRUE); xdg_dir_time_list_add (file_name, st.st_mtime); } else @@ -175,7 +177,7 @@ xdg_mime_init_from_directory (const char *directory) strcpy (file_name, directory); strcat (file_name, "/mime/globs"); if (stat (file_name, &st) == 0) { - _xdg_mime_glob_read_from_file (global_hash, file_name); + _xdg_mime_glob_read_from_file (global_hash, file_name, FALSE); xdg_dir_time_list_add (file_name, st.st_mtime); } else @@ -467,17 +469,23 @@ xdg_mime_get_mime_type_for_data (const void *data, { const char *mime_type; + if (len == 0) + { + *result_prio = 100; + return XDG_MIME_TYPE_EMPTY; + } + xdg_mime_init (); if (_caches) - return _xdg_mime_cache_get_mime_type_for_data (data, len, result_prio); - - mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len, result_prio, NULL, 0); + mime_type = _xdg_mime_cache_get_mime_type_for_data (data, len, result_prio); + else + mime_type = _xdg_mime_magic_lookup_data (global_magic, data, len, result_prio, NULL, 0); if (mime_type) return mime_type; - return XDG_MIME_TYPE_UNKNOWN; + return _xdg_binary_or_text_fallback(data, len); } const char * @@ -556,7 +564,7 @@ xdg_mime_get_mime_type_for_file (const char *file_name, if (mime_type) return mime_type; - return XDG_MIME_TYPE_UNKNOWN; + return _xdg_binary_or_text_fallback(data, bytes_read); } const char * diff --git a/base/third_party/xdg_mime/xdgmime.h b/base/third_party/xdg_mime/xdgmime.h index d3031a3..6a34edf 100644 --- a/base/third_party/xdg_mime/xdgmime.h +++ b/base/third_party/xdg_mime/xdgmime.h @@ -68,6 +68,8 @@ typedef void (*XdgMimeDestroy) (void *user_data); #define xdg_mime_register_reload_callback XDG_ENTRY(register_reload_callback) #define xdg_mime_remove_callback XDG_ENTRY(remove_callback) #define xdg_mime_type_unknown XDG_ENTRY(type_unknown) +#define xdg_mime_type_empty XDG_ENTRY(type_empty) +#define xdg_mime_type_textplain XDG_ENTRY(type_textplain) #define xdg_mime_get_icon XDG_ENTRY(get_icon) #define xdg_mime_get_generic_icon XDG_ENTRY(get_generic_icon) @@ -77,7 +79,11 @@ typedef void (*XdgMimeDestroy) (void *user_data); #endif extern const char xdg_mime_type_unknown[]; +extern const char xdg_mime_type_empty[]; +extern const char xdg_mime_type_textplain[]; #define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown +#define XDG_MIME_TYPE_EMPTY xdg_mime_type_empty +#define XDG_MIME_TYPE_TEXTPLAIN xdg_mime_type_textplain const char *xdg_mime_get_mime_type_for_data (const void *data, size_t len, diff --git a/base/third_party/xdg_mime/xdgmimealias.c b/base/third_party/xdg_mime/xdgmimealias.c index c33adfa..07d89eb 100644 --- a/base/third_party/xdg_mime/xdgmimealias.c +++ b/base/third_party/xdg_mime/xdgmimealias.c @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include "xdgmimealias.h" diff --git a/base/third_party/xdg_mime/xdgmimecache.c b/base/third_party/xdg_mime/xdgmimecache.c index e26a8be..ddb8754 100644 --- a/base/third_party/xdg_mime/xdgmimecache.c +++ b/base/third_party/xdg_mime/xdgmimecache.c @@ -25,13 +25,12 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> #include <fcntl.h> #include <unistd.h> @@ -45,7 +44,7 @@ #ifdef HAVE_MMAP #include <sys/mman.h> #else -#warning Building xdgmime without MMAP support. Binary "mime.info" cache files will not be used. +#warning Building xdgmime without MMAP support. Binary "mime.cache" files will not be used. #endif #include <sys/stat.h> @@ -75,11 +74,13 @@ #endif #define MAJOR_VERSION 1 -#define MINOR_VERSION 1 +#define MINOR_VERSION_MIN 1 +#define MINOR_VERSION_MAX 2 struct _XdgMimeCache { int ref_count; + int minor; size_t size; char *buffer; @@ -118,6 +119,7 @@ _xdg_mime_cache_new_from_file (const char *file_name) int fd = -1; struct stat st; char *buffer = NULL; + int minor; /* Open the file and map it into memory */ fd = open (file_name, O_RDONLY|_O_BINARY, 0); @@ -133,9 +135,11 @@ _xdg_mime_cache_new_from_file (const char *file_name) if (buffer == MAP_FAILED) goto done; + minor = GET_UINT16 (buffer, 2); /* Verify version */ if (GET_UINT16 (buffer, 0) != MAJOR_VERSION || - GET_UINT16 (buffer, 2) != MINOR_VERSION) + (minor < MINOR_VERSION_MIN || + minor > MINOR_VERSION_MAX)) { munmap (buffer, st.st_size); @@ -143,6 +147,7 @@ _xdg_mime_cache_new_from_file (const char *file_name) } cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache)); + cache->minor = minor; cache->ref_count = 1; cache->buffer = buffer; cache->size = st.st_size; @@ -170,7 +175,7 @@ cache_magic_matchlet_compare_to_data (XdgMimeCache *cache, int i, j; - for (i = range_start; i <= range_start + range_length; i++) + for (i = range_start; i < range_start + range_length; i++) { int valid_matchlet = TRUE; @@ -191,16 +196,9 @@ cache_magic_matchlet_compare_to_data (XdgMimeCache *cache, } else { - for (j = 0; j < data_length; j++) - { - if (((unsigned char *)cache->buffer)[data_offset + j] != ((unsigned char *) data)[j + i]) - { - valid_matchlet = FALSE; - break; - } - } + valid_matchlet = memcmp(cache->buffer + data_offset, data + i, data_length) == 0; } - + if (valid_matchlet) return TRUE; } @@ -357,7 +355,8 @@ typedef struct { static int cache_glob_lookup_literal (const char *file_name, const char *mime_types[], - int n_mime_types) + int n_mime_types, + int case_sensitive_check) { const char *ptr; int i, min, max, mid, cmp; @@ -378,17 +377,25 @@ cache_glob_lookup_literal (const char *file_name, offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * mid); ptr = cache->buffer + offset; cmp = strcmp (ptr, file_name); - + if (cmp < 0) min = mid + 1; else if (cmp > 0) max = mid - 1; else { - offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * mid + 4); - mime_types[0] = (const char *)(cache->buffer + offset); - - return 1; + int weight = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * mid + 8); + int case_sensitive = weight & 0x100; + weight = weight & 0xff; + + if (case_sensitive_check || !case_sensitive) + { + offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * mid + 4); + mime_types[0] = (const char *)(cache->buffer + offset); + + return 1; + } + return 0; } } } @@ -399,7 +406,8 @@ cache_glob_lookup_literal (const char *file_name, static int cache_glob_lookup_fnmatch (const char *file_name, MimeWeight mime_types[], - int n_mime_types) + int n_mime_types, + int case_sensitive_check) { const char *mime_type; const char *ptr; @@ -419,15 +427,19 @@ cache_glob_lookup_fnmatch (const char *file_name, xdg_uint32_t offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * j); xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * j + 4); int weight = GET_UINT32 (cache->buffer, list_offset + 4 + 12 * j + 8); + int case_sensitive = weight & 0x100; + weight = weight & 0xff; ptr = cache->buffer + offset; mime_type = cache->buffer + mimetype_offset; - - /* FIXME: Not UTF-8 safe */ - if (fnmatch (ptr, file_name, 0) == 0) + if (case_sensitive_check || !case_sensitive) { - mime_types[n].mime = mime_type; - mime_types[n].weight = weight; - n++; + /* FIXME: Not UTF-8 safe */ + if (fnmatch (ptr, file_name, 0) == 0) + { + mime_types[n].mime = mime_type; + mime_types[n].weight = weight; + n++; + } } } @@ -444,7 +456,7 @@ cache_glob_node_lookup_suffix (XdgMimeCache *cache, xdg_uint32_t offset, const char *file_name, int len, - int ignore_case, + int case_sensitive_check, MimeWeight mime_types[], int n_mime_types) { @@ -454,12 +466,11 @@ cache_glob_node_lookup_suffix (XdgMimeCache *cache, xdg_uint32_t n_children; xdg_uint32_t child_offset; int weight; + int case_sensitive; int min, max, mid, n, i; character = file_name[len - 1]; - if (ignore_case) - character = tolower (character); assert (character != 0); @@ -485,7 +496,7 @@ cache_glob_node_lookup_suffix (XdgMimeCache *cache, n = cache_glob_node_lookup_suffix (cache, n_children, child_offset, file_name, len, - ignore_case, + case_sensitive_check, mime_types, n_mime_types); } @@ -500,10 +511,15 @@ cache_glob_node_lookup_suffix (XdgMimeCache *cache, mimetype_offset = GET_UINT32 (cache->buffer, child_offset + 12 * i + 4); weight = GET_UINT32 (cache->buffer, child_offset + 12 * i + 8); + case_sensitive = weight & 0x100; + weight = weight & 0xff; - mime_types[n].mime = cache->buffer + mimetype_offset; - mime_types[n].weight = weight; - n++; + if (case_sensitive_check || !case_sensitive) + { + mime_types[n].mime = cache->buffer + mimetype_offset; + mime_types[n].weight = weight; + n++; + } i++; } } @@ -548,7 +564,23 @@ static int compare_mime_weight (const void *a, const void *b) const MimeWeight *aa = (const MimeWeight *)a; const MimeWeight *bb = (const MimeWeight *)b; - return aa->weight - bb->weight; + return bb->weight - aa->weight; +} + +#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z') +static char * +ascii_tolower (const char *str) +{ + char *p, *lower; + + lower = strdup (str); + p = lower; + while (*p != 0) + { + char c = *p; + *p++ = ISUPPER (c) ? c - 'A' + 'a' : c; + } + return lower; } static int @@ -561,23 +593,40 @@ cache_glob_lookup_file_name (const char *file_name, int n_mimes = 10; int i; int len; - + char *lower_case; + assert (file_name != NULL && n_mime_types > 0); /* First, check the literals */ - n = cache_glob_lookup_literal (file_name, mime_types, n_mime_types); + + lower_case = ascii_tolower (file_name); + + n = cache_glob_lookup_literal (lower_case, mime_types, n_mime_types, FALSE); if (n > 0) - return n; + { + free (lower_case); + return n; + } - len = strlen (file_name); - n = cache_glob_lookup_suffix (file_name, len, FALSE, mimes, n_mimes); + n = cache_glob_lookup_literal (file_name, mime_types, n_mime_types, TRUE); + if (n > 0) + { + free (lower_case); + return n; + } + len = strlen (file_name); + n = cache_glob_lookup_suffix (lower_case, len, FALSE, mimes, n_mimes); if (n == 0) n = cache_glob_lookup_suffix (file_name, len, TRUE, mimes, n_mimes); - + /* Last, try fnmatch */ if (n == 0) - n = cache_glob_lookup_fnmatch (file_name, mimes, n_mimes); + n = cache_glob_lookup_fnmatch (lower_case, mimes, n_mimes, FALSE); + if (n == 0) + n = cache_glob_lookup_fnmatch (file_name, mimes, n_mimes, TRUE); + + free (lower_case); qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight); @@ -639,18 +688,28 @@ cache_get_mime_type_for_data (const void *data, if (result_prio) *result_prio = priority; - + if (priority > 0) - return mime_type; + { + /* Pick glob-result R where mime_type inherits from R */ + for (n = 0; n < n_mime_types; n++) + { + if (mime_types[n] && _xdg_mime_cache_mime_type_subclass(mime_types[n], mime_type)) + return mime_types[n]; + } + /* Return magic match */ + return mime_type; + } + + /* Pick first glob result, as fallback */ for (n = 0; n < n_mime_types; n++) { - if (mime_types[n]) - return mime_types[n]; + return mime_types[n]; } - return XDG_MIME_TYPE_UNKNOWN; + return NULL; } const char * @@ -695,6 +754,9 @@ _xdg_mime_cache_get_mime_type_for_file (const char *file_name, statbuf = &buf; } + if (statbuf->st_size == 0) + return XDG_MIME_TYPE_EMPTY; + if (!S_ISREG (statbuf->st_mode)) return XDG_MIME_TYPE_UNKNOWN; @@ -724,6 +786,9 @@ _xdg_mime_cache_get_mime_type_for_file (const char *file_name, mime_type = cache_get_mime_type_for_data (data, bytes_read, NULL, mime_types, n); + if (!mime_type) + mime_type = _xdg_binary_or_text_fallback(data, bytes_read); + free (data); fclose (file); diff --git a/base/third_party/xdg_mime/xdgmimeglob.c b/base/third_party/xdg_mime/xdgmimeglob.c index d7c79b1..f8434bc 100644 --- a/base/third_party/xdg_mime/xdgmimeglob.c +++ b/base/third_party/xdg_mime/xdgmimeglob.c @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include "xdgmimeglob.h" @@ -36,7 +36,6 @@ #include <assert.h> #include <string.h> #include <fnmatch.h> -#include <ctype.h> #ifndef FALSE #define FALSE (0) @@ -54,6 +53,7 @@ struct XdgGlobHashNode xdg_unichar_t character; const char *mime_type; int weight; + int case_sensitive; XdgGlobHashNode *next; XdgGlobHashNode *child; }; @@ -62,6 +62,7 @@ struct XdgGlobList const char *data; const char *mime_type; int weight; + int case_sensitive; XdgGlobList *next; }; @@ -111,15 +112,27 @@ static XdgGlobList * _xdg_glob_list_append (XdgGlobList *glob_list, void *data, const char *mime_type, - int weight) + int weight, + int case_sensitive) { XdgGlobList *new_element; XdgGlobList *tmp_element; + tmp_element = glob_list; + while (tmp_element != NULL) + { + if (strcmp (tmp_element->data, data) == 0 && + strcmp (tmp_element->mime_type, mime_type) == 0) + return glob_list; + + tmp_element = tmp_element->next; + } + new_element = _xdg_glob_list_new (); new_element->data = data; new_element->mime_type = mime_type; new_element->weight = weight; + new_element->case_sensitive = case_sensitive; if (glob_list == NULL) return new_element; @@ -168,7 +181,8 @@ static XdgGlobHashNode * _xdg_glob_hash_insert_ucs4 (XdgGlobHashNode *glob_hash_node, xdg_unichar_t *text, const char *mime_type, - int weight) + int weight, + int case_sensitive) { XdgGlobHashNode *node; xdg_unichar_t character; @@ -232,11 +246,11 @@ _xdg_glob_hash_insert_ucs4 (XdgGlobHashNode *glob_hash_node, { if (node->mime_type) { - if (strcmp (node->mime_type, mime_type)) + if (strcmp (node->mime_type, mime_type) != 0) { XdgGlobHashNode *child; int found_node = FALSE; - + child = node->child; while (child && child->character == 0) { @@ -254,6 +268,7 @@ _xdg_glob_hash_insert_ucs4 (XdgGlobHashNode *glob_hash_node, child->character = 0; child->mime_type = strdup (mime_type); child->weight = weight; + child->case_sensitive = case_sensitive; child->child = NULL; child->next = node->child; node->child = child; @@ -264,11 +279,12 @@ _xdg_glob_hash_insert_ucs4 (XdgGlobHashNode *glob_hash_node, { node->mime_type = strdup (mime_type); node->weight = weight; + node->case_sensitive = case_sensitive; } } else { - node->child = _xdg_glob_hash_insert_ucs4 (node->child, text, mime_type, weight); + node->child = _xdg_glob_hash_insert_ucs4 (node->child, text, mime_type, weight, case_sensitive); } return glob_hash_node; } @@ -278,7 +294,8 @@ static XdgGlobHashNode * _xdg_glob_hash_insert_text (XdgGlobHashNode *glob_hash_node, const char *text, const char *mime_type, - int weight) + int weight, + int case_sensitive) { XdgGlobHashNode *node; xdg_unichar_t *unitext; @@ -286,7 +303,7 @@ _xdg_glob_hash_insert_text (XdgGlobHashNode *glob_hash_node, unitext = _xdg_convert_to_ucs4 (text, &len); _xdg_reverse_ucs4 (unitext, len); - node = _xdg_glob_hash_insert_ucs4 (glob_hash_node, unitext, mime_type, weight); + node = _xdg_glob_hash_insert_ucs4 (glob_hash_node, unitext, mime_type, weight, case_sensitive); free (unitext); return node; } @@ -300,7 +317,7 @@ static int _xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node, const char *file_name, int len, - int ignore_case, + int case_sensitive_check, MimeWeight mime_types[], int n_mime_types) { @@ -312,8 +329,6 @@ _xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node, return 0; character = file_name[len - 1]; - if (ignore_case) - character = tolower(character); for (node = glob_hash_node; node && character >= node->character; node = node->next) { @@ -326,13 +341,15 @@ _xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node, n = _xdg_glob_hash_node_lookup_file_name (node->child, file_name, len, - ignore_case, + case_sensitive_check, mime_types, n_mime_types); } if (n == 0) { - if (node->mime_type) + if (node->mime_type && + (case_sensitive_check || + !node->case_sensitive)) { mime_types[n].mime = node->mime_type; mime_types[n].weight = node->weight; @@ -341,7 +358,9 @@ _xdg_glob_hash_node_lookup_file_name (XdgGlobHashNode *glob_hash_node, node = node->child; while (n < n_mime_types && node && node->character == 0) { - if (node->mime_type) + if (node->mime_type && + (case_sensitive_check || + !node->case_sensitive)) { mime_types[n].mime = node->mime_type; mime_types[n].weight = node->weight; @@ -362,7 +381,23 @@ static int compare_mime_weight (const void *a, const void *b) const MimeWeight *aa = (const MimeWeight *)a; const MimeWeight *bb = (const MimeWeight *)b; - return aa->weight - bb->weight; + return bb->weight - aa->weight; +} + +#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z') +static char * +ascii_tolower (const char *str) +{ + char *p, *lower; + + lower = strdup (str); + p = lower; + while (*p != 0) + { + char c = *p; + *p++ = ISUPPER (c) ? c - 'A' + 'a' : c; + } + return lower; } int @@ -376,6 +411,7 @@ _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, MimeWeight mimes[10]; int n_mimes = 10; int len; + char *lower_case; /* First, check the literals */ @@ -383,17 +419,32 @@ _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, n = 0; + lower_case = ascii_tolower (file_name); + for (list = glob_hash->literal_list; list; list = list->next) { if (strcmp ((const char *)list->data, file_name) == 0) { mime_types[0] = list->mime_type; + free (lower_case); + return 1; + } + } + + for (list = glob_hash->literal_list; list; list = list->next) + { + if (!list->case_sensitive && + strcmp ((const char *)list->data, lower_case) == 0) + { + mime_types[0] = list->mime_type; + free (lower_case); return 1; } } + len = strlen (file_name); - n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, FALSE, + n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, lower_case, len, FALSE, mimes, n_mimes); if (n == 0) n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, file_name, len, TRUE, @@ -411,6 +462,7 @@ _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, } } } + free (lower_case); qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight); @@ -493,7 +545,8 @@ void _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash, const char *glob, const char *mime_type, - int weight) + int weight, + int case_sensitive) { XdgGlobType type; @@ -505,13 +558,13 @@ _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash, switch (type) { case XDG_GLOB_LITERAL: - glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, strdup (glob), strdup (mime_type), weight); + glob_hash->literal_list = _xdg_glob_list_append (glob_hash->literal_list, strdup (glob), strdup (mime_type), weight, case_sensitive); break; case XDG_GLOB_SIMPLE: - glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type, weight); + glob_hash->simple_node = _xdg_glob_hash_insert_text (glob_hash->simple_node, glob + 1, mime_type, weight, case_sensitive); break; case XDG_GLOB_FULL: - glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, strdup (glob), strdup (mime_type), weight); + glob_hash->full_list = _xdg_glob_list_append (glob_hash->full_list, strdup (glob), strdup (mime_type), weight, case_sensitive); break; } } @@ -555,10 +608,12 @@ _xdg_glob_hash_dump (XdgGlobHash *glob_hash) void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, - const char *file_name) + const char *file_name, + int version_two) { FILE *glob_file; char line[255]; + char *p; glob_file = fopen (file_name, "r"); @@ -569,33 +624,67 @@ _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, * Blah */ while (fgets (line, 255, glob_file) != NULL) { - char *colon, *colon2; - char *mimetype, *glob; + char *colon; + char *mimetype, *glob, *end; int weight; + int case_sensitive; - if (line[0] == '#') + if (line[0] == '#' || line[0] == 0) continue; - colon = strchr (line, ':'); + end = line + strlen(line) - 1; + if (*end == '\n') + *end = 0; + + p = line; + if (version_two) + { + colon = strchr (p, ':'); + if (colon == NULL) + continue; + *colon = 0; + weight = atoi (p); + p = colon + 1; + } + else + weight = 50; + + colon = strchr (p, ':'); if (colon == NULL) continue; - *(colon++) = '\0'; - colon[strlen (colon) -1] = '\0'; - colon2 = strchr (colon, ':'); - if (colon2) - { - *(colon2++) = '\000'; - weight = atoi (line); - mimetype = colon; - glob = colon2; - } - else - { - weight = 50; - mimetype = line; - glob = colon; - } - _xdg_glob_hash_append_glob (glob_hash, glob, mimetype, weight); + *colon = 0; + + mimetype = p; + p = colon + 1; + glob = p; + case_sensitive = FALSE; + + colon = strchr (p, ':'); + if (version_two && colon != NULL) + { + char *flag; + + /* We got flags */ + *colon = 0; + p = colon + 1; + + /* Flags end at next colon */ + colon = strchr (p, ':'); + if (colon != NULL) + *colon = 0; + + flag = strstr (p, "cs"); + if (flag != NULL && + /* Start or after comma */ + (flag == p || + flag[-1] == ',') && + /* ends with comma or end of string */ + (flag[2] == 0 || + flag[2] == ',')) + case_sensitive = TRUE; + } + + _xdg_glob_hash_append_glob (glob_hash, glob, mimetype, weight, case_sensitive); } fclose (glob_file); diff --git a/base/third_party/xdg_mime/xdgmimeglob.h b/base/third_party/xdg_mime/xdgmimeglob.h index df8dc79..0018292 100644 --- a/base/third_party/xdg_mime/xdgmimeglob.h +++ b/base/third_party/xdg_mime/xdgmimeglob.h @@ -51,7 +51,8 @@ typedef enum #endif void _xdg_mime_glob_read_from_file (XdgGlobHash *glob_hash, - const char *file_name); + const char *file_name, + int version_two); XdgGlobHash *_xdg_glob_hash_new (void); void _xdg_glob_hash_free (XdgGlobHash *glob_hash); int _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, @@ -61,7 +62,8 @@ int _xdg_glob_hash_lookup_file_name (XdgGlobHash *glob_hash, void _xdg_glob_hash_append_glob (XdgGlobHash *glob_hash, const char *glob, const char *mime_type, - int weight); + int weight, + int case_sensitive); XdgGlobType _xdg_glob_determine_type (const char *glob); void _xdg_glob_hash_dump (XdgGlobHash *glob_hash); diff --git a/base/third_party/xdg_mime/xdgmimeicon.c b/base/third_party/xdg_mime/xdgmimeicon.c index 16db843..05c9473 100644 --- a/base/third_party/xdg_mime/xdgmimeicon.c +++ b/base/third_party/xdg_mime/xdgmimeicon.c @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include "xdgmimeicon.h" diff --git a/base/third_party/xdg_mime/xdgmimeint.c b/base/third_party/xdg_mime/xdgmimeint.c index b2aa956..cf789d9 100644 --- a/base/third_party/xdg_mime/xdgmimeint.c +++ b/base/third_party/xdg_mime/xdgmimeint.c @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include "xdgmimeint.h" @@ -189,3 +189,18 @@ _xdg_reverse_ucs4 (xdg_unichar_t *source, int len) } } +const char * +_xdg_binary_or_text_fallback(const void *data, size_t len) +{ + unsigned char *chardata; + int i; + + chardata = (unsigned char *) data; + for (i = 0; i < 32 && i < len; ++i) + { + if (chardata[i] < 32 && chardata[i] != 9 && chardata[i] != 10 && chardata[i] != 13) + return XDG_MIME_TYPE_UNKNOWN; /* binary data */ + } + + return XDG_MIME_TYPE_TEXTPLAIN; +} diff --git a/base/third_party/xdg_mime/xdgmimeint.h b/base/third_party/xdg_mime/xdgmimeint.h index 232c808..9e8b2cb 100644 --- a/base/third_party/xdg_mime/xdgmimeint.h +++ b/base/third_party/xdg_mime/xdgmimeint.h @@ -73,5 +73,6 @@ int _xdg_utf8_validate (const char *source); xdg_unichar_t *_xdg_convert_to_ucs4 (const char *source, int *len); void _xdg_reverse_ucs4 (xdg_unichar_t *source, int len); const char *_xdg_get_base_name (const char *file_name); +const char *_xdg_binary_or_text_fallback(const void *data, size_t len); #endif /* __XDG_MIME_INT_H__ */ diff --git a/base/third_party/xdg_mime/xdgmimemagic.c b/base/third_party/xdg_mime/xdgmimemagic.c index ae1093a..a2320f5 100644 --- a/base/third_party/xdg_mime/xdgmimemagic.c +++ b/base/third_party/xdg_mime/xdgmimemagic.c @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include <assert.h> diff --git a/base/third_party/xdg_mime/xdgmimeparent.c b/base/third_party/xdg_mime/xdgmimeparent.c index 52d3c0c..511bbac 100644 --- a/base/third_party/xdg_mime/xdgmimeparent.c +++ b/base/third_party/xdg_mime/xdgmimeparent.c @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include <config.h> #endif #include "xdgmimeparent.h" |