int xdg_mime_mime_type_subclass (const char *mime, const char *base) { xdg_mime_init (); return _xdg_mime_mime_type_subclass (mime, base); }
const char * _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic, const void *data, size_t len, const char *mime_types[], int n_mime_types) { XdgMimeMagicMatch *match; const char *mime_type; int n; mime_type = NULL; for (match = mime_magic->match_list; match; match = match->next) { if (_xdg_mime_magic_match_compare_to_data (match, data, len)) { if ((mime_type == NULL) || (_xdg_mime_mime_type_subclass (match->mime_type, mime_type))) { mime_type = match->mime_type; } } else { for (n = 0; n < n_mime_types; n++) { if (mime_types[n] && _xdg_mime_mime_type_equal (mime_types[n], match->mime_type)) mime_types[n] = NULL; } } } if (mime_type == NULL) { for (n = 0; n < n_mime_types; n++) { if (mime_types[n]) mime_type = mime_types[n]; } } return mime_type; }
int _xdg_mime_mime_type_subclass (const char *mime, const char *base) { const char *umime, *ubase; const char **parents; if (_caches) return _xdg_mime_cache_mime_type_subclass (mime, base); umime = _xdg_mime_unalias_mime_type (mime); ubase = _xdg_mime_unalias_mime_type (base); if (strcmp (umime, ubase) == 0) return 1; #if 1 /* Handle supertypes */ if (xdg_mime_is_super_type (ubase) && xdg_mime_media_type_equal (umime, ubase)) return 1; #endif /* Handle special cases text/plain and application/octet-stream */ if (strcmp (ubase, "text/plain") == 0 && strncmp (umime, "text/", 5) == 0) return 1; if (strcmp (ubase, "application/octet-stream") == 0 && strncmp (umime, "inode/", 6) != 0) return 1; parents = _xdg_mime_parent_list_lookup (parent_list, umime); for (; parents && *parents; parents++) { if (_xdg_mime_mime_type_subclass (*parents, ubase)) return 1; } return 0; }
const char * _xdg_mime_magic_lookup_data (XdgMimeMagic *mime_magic, const void *data, size_t len, const char *mime_types[], int n_mime_types) { XdgMimeMagicMatch *match; const char *mime_type; int n; int priority; int had_match; mime_type = NULL; priority = 0; had_match = 0; for (match = mime_magic->match_list; match; match = match->next) { if (_xdg_mime_magic_match_compare_to_data (match, data, len)) { if (!had_match || match->priority > priority || (mime_type != NULL && _xdg_mime_mime_type_subclass (match->mime_type, mime_type))) { mime_type = match->mime_type; priority = match->priority; } /* Is this another match at same priority which is not the same * type again, or a sub-type */ else if (had_match && match->priority == priority && mime_type && strcmp(mime_type, match->mime_type)!=0 && !_xdg_mime_mime_type_subclass (mime_type, match->mime_type)) /* multiple unrelated patterns with the same priority matched, * so we can't tell what type this is. */ mime_type = NULL; had_match = 1; } else { for (n = 0; n < n_mime_types; n++) { if (mime_types[n] && _xdg_mime_mime_type_equal (mime_types[n], match->mime_type)) mime_types[n] = NULL; } } } if (mime_type == NULL) { for (n = 0; n < n_mime_types; n++) { if (mime_types[n]) mime_type = mime_types[n]; } } if (mime_type == NULL) { if(_rox_buffer_looks_like_text(data, len)) mime_type = XDG_MIME_TYPE_UNKNOWN_TEXT; } return mime_type; }