diff options
author | Vincent Untz <vuntz@gnome.org> | 2010-02-17 04:32:30 +0100 |
---|---|---|
committer | Vincent Untz <vuntz@gnome.org> | 2010-03-10 03:29:52 +0100 |
commit | 520a9e3bb976b6877ee697ae6f6d0cc5a23b1ba5 (patch) | |
tree | 72c029e93a2593ea3a7da52b1ce6c206c50b2aef /src | |
parent | 0a2a429ca2943f7b329d9a90f4950588a56f9f15 (diff) |
Handle some fdo media types correctly
inode, x-content and x-directory are used already, and should be
considered as special case (even though they haven't be registered with
IANA).
Note that x-directory is discouraged, though, since inode/directory
replaces it.
Diffstat (limited to 'src')
-rw-r--r-- | src/mimeutils.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/src/mimeutils.c b/src/mimeutils.c index 922b36e..dcff352 100644 --- a/src/mimeutils.c +++ b/src/mimeutils.c @@ -38,6 +38,15 @@ #include "mimeutils.h" +/* Not registered with IANA, but used on a free desktop */ +static const char *known_fdo_media_types[] = { + "inode", "x-content" +}; + +static const char *known_old_fdo_media_types[] = { + "x-directory" +}; + /* Defined in RFC 2045/2046 and RFC 2077 */ static const char *registered_discrete_media_types[] = { "application", "audio", "image", "model", "text", "video" @@ -52,12 +61,12 @@ static const char *registered_not_used_media_types[] = { "example" }; -/* TODO: we will break in a few cases, since we're only IANA-aware so far. +/* TODO: we will break in a few cases. * Known cases: - * inode/.*: added by the fdo spec * flv-application/octet-stream: alias in the fdo db * zz-application/zz-winassoc-cdr: alias in the fdo db * misc/ultravox: widely used? + * message/rfc822: should not be discouraged * * TODO: might actually be nice to download at distcheck time all the * registered subtypes and warn when using a non-registered non-experimental @@ -105,6 +114,25 @@ is_valid_media_type (const char *media_type, { unsigned int i; +#define IF_IS_MEDIA_TYPE_IN(list) \ + for (i = 0; i < G_N_ELEMENTS (list); i++) { \ + if (strcmp (media_type, list[i]) == 0) \ + break; \ + } \ + if (i < G_N_ELEMENTS (list)) + + /* Handle known_fdo_media_types before X- types because it contains one X- + * type */ + IF_IS_MEDIA_TYPE_IN (known_fdo_media_types) + return MU_VALID; + + IF_IS_MEDIA_TYPE_IN (known_old_fdo_media_types) { + if (error) + *error = g_strdup_printf ("\"%s\" is an old media type that should be " + "replaced by a modern equivalent", media_type); + return MU_DISCOURAGED; + } + if (g_ascii_strncasecmp (media_type, "X-", 2) == 0) { for (i = 2; media_type[i]; i++) { if (!is_valid_mime_type_char (media_type[i])) @@ -122,13 +150,6 @@ is_valid_media_type (const char *media_type, return MU_DISCOURAGED; } -#define IF_IS_MEDIA_TYPE_IN(list) \ - for (i = 0; i < G_N_ELEMENTS (list); i++) { \ - if (strcmp (media_type, list[i]) == 0) \ - break; \ - } \ - if (i < G_N_ELEMENTS (list)) - IF_IS_MEDIA_TYPE_IN (registered_discrete_media_types) return MU_VALID; |