Updates to GIO documentation. (#506395, Mikael Hermansson)
[platform/upstream/glib.git] / gio / gcontenttype.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include <config.h>
24 #include <sys/types.h>
25 #include <string.h>
26 #include <stdio.h>
27 #include "gcontenttypeprivate.h"
28 #include "glibintl.h"
29
30 #include "gioalias.h"
31
32 /**
33  * SECTION:gcontenttype
34  * @short_description: Platform-specific content typing
35  * @include: gio.h
36  *
37  * A content type is a platform specific string that defines the type
38  * of a file. On unix it is a mime type, on win32 it is an extension string
39  * like ".doc", ".txt" or a percieved string like "audio". Such strings
40  * can be looked up in the registry at HKEY_CLASSES_ROOT.
41  **/
42
43 #ifdef G_OS_WIN32
44
45 #include <windows.h>
46
47 static char *
48 get_registry_classes_key (const char    *subdir,
49                           const wchar_t *key_name)
50 {
51   wchar_t *wc_key;
52   HKEY reg_key = NULL;
53   DWORD key_type;
54   DWORD nbytes;
55   char *value_utf8;
56
57   value_utf8 = NULL;
58   
59   nbytes = 0;
60   wc_key = g_utf8_to_utf16 (subdir, -1, NULL, NULL, NULL);
61   if (RegOpenKeyExW (HKEY_CLASSES_ROOT, wc_key, 0,
62                      KEY_QUERY_VALUE, &reg_key) == ERROR_SUCCESS &&
63       RegQueryValueExW (reg_key, key_name, 0,
64                         &key_type, NULL, &nbytes) == ERROR_SUCCESS &&
65       key_type == REG_SZ)
66     {
67       wchar_t *wc_temp = g_new (wchar_t, (nbytes+1)/2 + 1);
68       RegQueryValueExW (reg_key, key_name, 0,
69                         &key_type, (LPBYTE) wc_temp, &nbytes);
70       wc_temp[nbytes/2] = '\0';
71       value_utf8 = g_utf16_to_utf8 (wc_temp, -1, NULL, NULL, NULL);
72       g_free (wc_temp);
73     }
74   g_free (wc_key);
75   
76   if (reg_key != NULL)
77     RegCloseKey (reg_key);
78
79   return value_utf8;
80 }
81
82 gboolean
83 g_content_type_equals (const char *type1,
84                        const char *type2)
85 {
86   char *progid1, *progid2;
87   gboolean res;
88   
89   g_return_val_if_fail (type1 != NULL, FALSE);
90   g_return_val_if_fail (type2 != NULL, FALSE);
91
92   if (g_ascii_strcasecmp (type1, type2) == 0)
93     return TRUE;
94
95   res = FALSE;
96   progid1 = get_registry_classes_key (type1, NULL);
97   progid2 = get_registry_classes_key (type2, NULL);
98   if (progid1 != NULL && progid2 != NULL &&
99       strcmp (progid1, progid2) == 0)
100     res = TRUE;
101   g_free (progid1);
102   g_free (progid2);
103   
104   return res;
105 }
106
107 gboolean
108 g_content_type_is_a (const char *type,
109                      const char *supertype)
110 {
111   gboolean res;
112   char *value_utf8;
113
114   g_return_val_if_fail (type != NULL, FALSE);
115   g_return_val_if_fail (supertype != NULL, FALSE);
116
117   if (g_content_type_equals (type, supertype))
118     return TRUE;
119
120   res = FALSE;
121   value_utf8 = get_registry_classes_key (type, L"PerceivedType");
122   if (value_utf8 && strcmp (value_utf8, supertype) == 0)
123     res = TRUE;
124   g_free (value_utf8);
125   
126   return res;
127 }
128
129 gboolean
130 g_content_type_is_unknown (const char *type)
131 {
132   g_return_val_if_fail (type != NULL, FALSE);
133
134   return strcmp ("*", type) == 0;
135 }
136
137 char *
138 g_content_type_get_description (const char *type)
139 {
140   char *progid;
141   char *description;
142
143   g_return_val_if_fail (type != NULL, NULL);
144
145   progid = get_registry_classes_key (type, NULL);
146   if (progid)
147     {
148       description = get_registry_classes_key (progid, NULL);
149       g_free (progid);
150
151       if (description)
152         return description;
153     }
154
155   if (g_content_type_is_unknown (type))
156     return g_strdup (_("Unknown type"));
157   return g_strdup_printf (_("%s filetype"), type);
158 }
159
160 char *
161 g_content_type_get_mime_type (const char *type)
162 {
163   char *mime;
164
165   g_return_val_if_fail (type != NULL, NULL);
166
167   mime = get_registry_classes_key (type, L"Content Type");
168   if (mime)
169     return mime;
170   else if (g_content_type_is_unknown (type))
171     return g_strdup ("application/octet-stream");
172   else if (*type == '.')
173     return g_strdup_printf ("application/x-ext-%s", type+1);
174   /* TODO: Map "image" to "image/ *", etc? */
175
176   return g_strdup ("application/octet-stream");
177 }
178
179 GIcon *
180 g_content_type_get_icon (const char *type)
181 {
182   g_return_val_if_fail (type != NULL, NULL);
183
184   /* TODO: How do we represent icons???
185      In the registry they are the default value of
186      HKEY_CLASSES_ROOT\<progid>\DefaultIcon with typical values like:
187      <type>: <value>
188      REG_EXPAND_SZ: %SystemRoot%\System32\Wscript.exe,3
189      REG_SZ: shimgvw.dll,3
190   */
191   return NULL;
192 }
193
194 gboolean
195 g_content_type_can_be_executable (const char *type)
196 {
197   g_return_val_if_fail (type != NULL, FALSE);
198
199   if (strcmp (type, ".exe") == 0 ||
200       strcmp (type, ".com") == 0 ||
201       strcmp (type, ".bat") == 0)
202     return TRUE;
203   return FALSE;
204 }
205
206 static gboolean
207 looks_like_text (const guchar *data, 
208                  gsize         data_size)
209 {
210   gsize i;
211   guchar c;
212   for (i = 0; i < data_size; i++)
213     {
214       c = data[i];
215       if (g_ascii_iscntrl (c) && !g_ascii_isspace (c))
216         return FALSE;
217     }
218   return TRUE;
219 }
220
221 char *
222 g_content_type_guess (const char   *filename,
223                       const guchar *data,
224                       gsize         data_size,
225                       gboolean     *result_uncertain)
226 {
227   char *basename;
228   char *type;
229   char *dot;
230
231   type = NULL;
232
233   if (filename)
234     {
235       basename = g_path_get_basename (filename);
236       dot = strrchr (basename, '.');
237       if (dot)
238         type = g_strdup (dot);
239       g_free (basename);
240     }
241
242   if (type)
243     return type;
244
245   if (data && looks_like_text (data, data_size))
246     return g_strdup (".txt");
247
248   return g_strdup ("*");
249 }
250
251 GList *
252 g_content_types_get_registered (void)
253 {
254   DWORD index;
255   wchar_t keyname[256];
256   DWORD key_len;
257   char *key_utf8;
258   GList *types;
259
260   types = NULL;
261   index = 0;
262   key_len = 256;
263   while (RegEnumKeyExW(HKEY_CLASSES_ROOT,
264                        index,
265                        keyname,
266                        &key_len,
267                        NULL,
268                        NULL,
269                        NULL,
270                        NULL) == ERROR_SUCCESS)
271     {
272       key_utf8 = g_utf16_to_utf8 (keyname, -1, NULL, NULL, NULL);
273       if (key_utf8)
274         {
275           if (*key_utf8 == '.')
276             types = g_list_prepend (types, key_utf8);
277           else
278             g_free (key_utf8);
279         }
280       index++;
281       key_len = 256;
282     }
283   
284   return g_list_reverse (types);
285 }
286
287 #else /* !G_OS_WIN32 - Unix specific version */
288
289 #include <dirent.h>
290
291 #define XDG_PREFIX _gio_xdg
292 #include "xdgmime/xdgmime.h"
293
294 /* We lock this mutex whenever we modify global state in this module.  */
295 G_LOCK_DEFINE_STATIC (gio_xdgmime);
296
297 gsize
298 _g_unix_content_type_get_sniff_len (void)
299 {
300   gsize size;
301
302   G_LOCK (gio_xdgmime);
303   size = xdg_mime_get_max_buffer_extents ();
304   G_UNLOCK (gio_xdgmime);
305
306   return size;
307 }
308
309 char *
310 _g_unix_content_type_unalias (const char *type)
311 {
312   char *res;
313   
314   G_LOCK (gio_xdgmime);
315   res = g_strdup (xdg_mime_unalias_mime_type (type));
316   G_UNLOCK (gio_xdgmime);
317   
318   return res;
319 }
320
321 char **
322 _g_unix_content_type_get_parents (const char *type)
323 {
324   const char *umime;
325   const char **parents;
326   GPtrArray *array;
327   int i;
328
329   array = g_ptr_array_new ();
330   
331   G_LOCK (gio_xdgmime);
332   
333   umime = xdg_mime_unalias_mime_type (type);
334   g_ptr_array_add (array, g_strdup (umime));
335   
336   parents = xdg_mime_get_mime_parents (umime);
337   for (i = 0; parents && parents[i] != NULL; i++)
338     g_ptr_array_add (array, g_strdup (parents[i]));
339   
340   G_UNLOCK (gio_xdgmime);
341   
342   g_ptr_array_add (array, NULL);
343   
344   return (char **)g_ptr_array_free (array, FALSE);
345 }
346
347 /**
348  * g_content_type_equals:
349  * @type1: a content type string.
350  * @type2: a content type string.
351  *
352  * Compares two content types for equality.
353  *
354  * Returns: %TRUE if the two strings are identical or equivalent,
355  * %FALSE otherwise.
356  **/  
357 gboolean
358 g_content_type_equals (const char *type1,
359                        const char *type2)
360 {
361   gboolean res;
362   
363   g_return_val_if_fail (type1 != NULL, FALSE);
364   g_return_val_if_fail (type2 != NULL, FALSE);
365   
366   G_LOCK (gio_xdgmime);
367   res = xdg_mime_mime_type_equal (type1, type2);
368   G_UNLOCK (gio_xdgmime);
369         
370   return res;
371 }
372
373 /**
374  * g_content_type_is_a:
375  * @type: a content type string. 
376  * @supertype: a string.
377  *
378  * Determines if @type is a subset of @supertype.  
379  *
380  * Returns: %TRUE if @type is a kind of @supertype,
381  * %FALSE otherwise. 
382  **/  
383 gboolean
384 g_content_type_is_a (const char *type,
385                      const char *supertype)
386 {
387   gboolean res;
388     
389   g_return_val_if_fail (type != NULL, FALSE);
390   g_return_val_if_fail (supertype != NULL, FALSE);
391   
392   G_LOCK (gio_xdgmime);
393   res = xdg_mime_mime_type_subclass (type, supertype);
394   G_UNLOCK (gio_xdgmime);
395         
396   return res;
397 }
398
399 /**
400  * g_content_type_is_unknown:
401  * @type: a content type string. 
402  * 
403  * Checks if the content type is the generic "unknown" type.
404  * On unix this is the "application/octet-stream" mimetype,
405  * while on win32 it is "*".
406  * 
407  * Returns: %TRUE if the type is the unknown type.
408  **/  
409 gboolean
410 g_content_type_is_unknown (const char *type)
411 {
412   g_return_val_if_fail (type != NULL, FALSE);
413
414   return strcmp (XDG_MIME_TYPE_UNKNOWN, type) == 0;
415 }
416
417
418 typedef enum {
419   MIME_TAG_TYPE_OTHER,
420   MIME_TAG_TYPE_COMMENT
421 } MimeTagType;
422
423 typedef struct {
424   int current_type;
425   int current_lang_level;
426   int comment_lang_level;
427   char *comment;
428 } MimeParser;
429
430
431 static int
432 language_level (const char *lang)
433 {
434   const char * const *lang_list;
435   int i;
436   
437   /* The returned list is sorted from most desirable to least
438      desirable and always contains the default locale "C". */
439   lang_list = g_get_language_names ();
440   
441   for (i = 0; lang_list[i]; i++)
442     if (strcmp (lang_list[i], lang) == 0)
443       return 1000-i;
444   
445   return 0;
446 }
447
448 static void
449 mime_info_start_element (GMarkupParseContext  *context,
450                          const gchar          *element_name,
451                          const gchar         **attribute_names,
452                          const gchar         **attribute_values,
453                          gpointer              user_data,
454                          GError              **error)
455 {
456   int i;
457   const char *lang;
458   MimeParser *parser = user_data;
459   
460   if (strcmp (element_name, "comment") == 0)
461     {
462       lang = "C";
463       for (i = 0; attribute_names[i]; i++)
464         if (strcmp (attribute_names[i], "xml:lang") == 0)
465           {
466             lang = attribute_values[i];
467             break;
468           }
469       
470       parser->current_lang_level = language_level (lang);
471       parser->current_type = MIME_TAG_TYPE_COMMENT;
472     }
473   else
474     parser->current_type = MIME_TAG_TYPE_OTHER;
475   
476 }
477
478 static void
479 mime_info_end_element (GMarkupParseContext  *context,
480                        const gchar          *element_name,
481                        gpointer              user_data,
482                        GError              **error)
483 {
484   MimeParser *parser = user_data;
485   
486   parser->current_type = MIME_TAG_TYPE_OTHER;
487 }
488
489 static void
490 mime_info_text (GMarkupParseContext  *context,
491                 const gchar          *text,
492                 gsize                 text_len,  
493                 gpointer              user_data,
494                 GError              **error)
495 {
496   MimeParser *parser = user_data;
497
498   if (parser->current_type == MIME_TAG_TYPE_COMMENT &&
499       parser->current_lang_level > parser->comment_lang_level)
500     {
501       g_free (parser->comment);
502       parser->comment = g_strndup (text, text_len);
503       parser->comment_lang_level = parser->current_lang_level;
504     }
505 }
506
507 static char *
508 load_comment_for_mime_helper (const char *dir, 
509                               const char *basename)
510 {
511   GMarkupParseContext *context;
512   char *filename, *data;
513   gsize len;
514   gboolean res;
515   MimeParser parse_data = {0};
516   GMarkupParser parser = {
517     mime_info_start_element,
518     mime_info_end_element,
519     mime_info_text
520   };
521
522   filename = g_build_filename (dir, "mime", basename, NULL);
523   
524   res = g_file_get_contents (filename,  &data,  &len,  NULL);
525   g_free (filename);
526   if (!res)
527     return NULL;
528   
529   context = g_markup_parse_context_new   (&parser, 0, &parse_data, NULL);
530   res = g_markup_parse_context_parse (context, data, len, NULL);
531   g_free (data);
532   g_markup_parse_context_free (context);
533   
534   if (!res)
535     return NULL;
536
537   return parse_data.comment;
538 }
539
540
541 static char *
542 load_comment_for_mime (const char *mimetype)
543 {
544   const char * const* dirs;
545   char *basename;
546   char *comment;
547   int i;
548
549   basename = g_strdup_printf ("%s.xml", mimetype);
550
551   comment = load_comment_for_mime_helper (g_get_user_data_dir (), basename);
552   if (comment)
553     {
554       g_free (basename);
555       return comment;
556     }
557   
558   dirs = g_get_system_data_dirs ();
559
560   for (i = 0; dirs[i] != NULL; i++)
561     {
562       comment = load_comment_for_mime_helper (dirs[i], basename);
563       if (comment)
564         {
565           g_free (basename);
566           return comment;
567         }
568     }
569   g_free (basename);
570   
571   return g_strdup_printf (_("%s type"), mimetype);
572 }
573
574 /**
575  * g_content_type_get_description:
576  * @type: a content type string. 
577  * 
578  * Gets the human readable description of the content type.
579  * 
580  * Returns: a short description of the content type @type. 
581  **/  
582 char *
583 g_content_type_get_description (const char *type)
584 {
585   static GHashTable *type_comment_cache = NULL;
586   char *comment;
587
588   g_return_val_if_fail (type != NULL, NULL);
589   
590   G_LOCK (gio_xdgmime);
591   if (type_comment_cache == NULL)
592     type_comment_cache = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
593
594   comment = g_hash_table_lookup (type_comment_cache, type);
595   comment = g_strdup (comment);
596   G_UNLOCK (gio_xdgmime);
597   
598   if (comment != NULL)
599     return comment;
600
601   comment = load_comment_for_mime (type);
602   
603   G_LOCK (gio_xdgmime);
604   g_hash_table_insert (type_comment_cache,
605                        g_strdup (type),
606                        g_strdup (comment));
607   G_UNLOCK (gio_xdgmime);
608
609   return comment;
610 }
611
612 /**
613  * g_content_type_get_mime_type:
614  * @type: a content type string. 
615  * 
616  * Gets the mime-type for the content type. If one is registered
617  * 
618  * Returns: the registered mime-type for the given @type, or NULL if unknown.
619  **/  
620 char *
621 g_content_type_get_mime_type (const char *type)
622 {
623   g_return_val_if_fail (type != NULL, NULL);
624
625   return g_strdup (type);
626 }
627
628 /**
629  * g_content_type_get_icon:
630  * @type: a content type string.
631  * 
632  * Gets the icon for a content type.
633  * 
634  * Returns: #GIcon corresponding to the content type.
635  **/  
636 GIcon *
637 g_content_type_get_icon (const char *type)
638 {
639   g_return_val_if_fail (type != NULL, NULL);
640
641   /* TODO: Implement */
642   return NULL;
643 }
644
645 /**
646  * g_content_type_can_be_executable:
647  * @type: a content type string.
648  * 
649  * Checks if a content type can be executable. Note that for instance
650  * things like text files can be executables (i.e. scripts and batch files).
651  * 
652  * Returns: %TRUE if the file type corresponds to a type that
653  * can be executable, %FALSE otherwise. 
654  **/  
655 gboolean
656 g_content_type_can_be_executable (const char *type)
657 {
658   g_return_val_if_fail (type != NULL, FALSE);
659
660   if (g_content_type_is_a (type, "application/x-executable")  ||
661       g_content_type_is_a (type, "text/plain"))
662     return TRUE;
663
664   return FALSE;
665 }
666
667 static gboolean
668 looks_like_text (const guchar *data, gsize data_size)
669 {
670   gsize i;
671   for (i = 0; i < data_size; i++)
672     {
673       if g_ascii_iscntrl (data[i])
674         return FALSE;
675     }
676   return TRUE;
677 }
678
679 /**
680  * g_content_type_guess:
681  * @filename: a string.
682  * @data: a stream of data.
683  * @data_size: the size of @data.
684  * @result_uncertain: a flag indicating the certainty of the 
685  * result.
686  * 
687  * Guesses the content type based on example data. If the function is 
688  * uncertain, @result_uncertain will be set to %TRUE.
689  * 
690  * Returns: a string indicating a guessed content type for the 
691  * given data. 
692  **/  
693 char *
694 g_content_type_guess (const char   *filename,
695                       const guchar *data,
696                       gsize         data_size,
697                       gboolean     *result_uncertain)
698 {
699   char *basename;
700   const char *name_mimetypes[10], *sniffed_mimetype;
701   char *mimetype;
702   int i;
703   int n_name_mimetypes;
704   int sniffed_prio;
705
706   sniffed_prio = 0;
707   n_name_mimetypes = 0;
708   sniffed_mimetype = XDG_MIME_TYPE_UNKNOWN;
709
710   if (result_uncertain)
711     *result_uncertain = FALSE;
712   
713   G_LOCK (gio_xdgmime);
714   
715   if (filename)
716     {
717       basename = g_path_get_basename (filename);
718       n_name_mimetypes = xdg_mime_get_mime_types_from_file_name (basename, name_mimetypes, 10);
719       g_free (basename);
720     }
721
722   /* Got an extension match, and no conflicts. This is it. */
723   if (n_name_mimetypes == 1)
724     {
725       G_UNLOCK (gio_xdgmime);
726       return g_strdup (name_mimetypes[0]);
727     }
728   
729   if (data)
730     {
731       sniffed_mimetype = xdg_mime_get_mime_type_for_data (data, data_size, &sniffed_prio);
732       if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN &&
733           data &&
734           looks_like_text (data, data_size))
735         sniffed_mimetype = "text/plain";
736     }
737   
738   if (n_name_mimetypes == 0)
739     {
740       if (sniffed_mimetype == XDG_MIME_TYPE_UNKNOWN &&
741           result_uncertain)
742         *result_uncertain = TRUE;
743       
744       mimetype = g_strdup (sniffed_mimetype);
745     }
746   else
747     {
748       mimetype = NULL;
749       if (sniffed_mimetype != XDG_MIME_TYPE_UNKNOWN)
750         {
751           if (sniffed_prio >= 80) /* High priority sniffing match, use that */
752             mimetype = g_strdup (sniffed_mimetype);
753           else
754             {
755               /* There are conflicts between the name matches and we have a sniffed
756                  type, use that as a tie breaker. */
757               
758               for (i = 0; i < n_name_mimetypes; i++)
759                 {
760                   if ( xdg_mime_mime_type_subclass (name_mimetypes[i], sniffed_mimetype))
761                     {
762                       /* This nametype match is derived from (or the same as) the sniffed type).
763                          This is probably it. */
764                       mimetype = g_strdup (name_mimetypes[i]);
765                       break;
766                     }
767                 }
768             }
769         }
770       
771       if (mimetype == NULL)
772         {
773           /* Conflicts, and sniffed type was no help or not there. guess on the first one */
774           mimetype = g_strdup (name_mimetypes[0]);
775           if (result_uncertain)
776             *result_uncertain = TRUE;
777         }
778     }
779   
780   G_UNLOCK (gio_xdgmime);
781
782   return mimetype;
783 }
784
785 static void
786 enumerate_mimetypes_subdir (const char *dir, 
787                             const char *prefix, 
788                             GHashTable *mimetypes)
789 {
790   DIR *d;
791   struct dirent *ent;
792   char *mimetype;
793
794   d = opendir (dir);
795   if (d)
796     {
797       while ((ent = readdir (d)) != NULL)
798         {
799           if (g_str_has_suffix (ent->d_name, ".xml"))
800             {
801               mimetype = g_strdup_printf ("%s/%.*s", prefix, (int) strlen (ent->d_name) - 4, ent->d_name);
802               g_hash_table_insert (mimetypes, mimetype, NULL);
803             }
804         }
805       closedir (d);
806     }
807 }
808
809 static void
810 enumerate_mimetypes_dir (const char *dir, 
811                          GHashTable *mimetypes)
812 {
813   DIR *d;
814   struct dirent *ent;
815   char *mimedir;
816   char *name;
817
818   mimedir = g_build_filename (dir, "mime", NULL);
819   
820   d = opendir (mimedir);
821   if (d)
822     {
823       while ((ent = readdir (d)) != NULL)
824         {
825           if (strcmp (ent->d_name, "packages") != 0)
826             {
827               name = g_build_filename (mimedir, ent->d_name, NULL);
828               if (g_file_test (name, G_FILE_TEST_IS_DIR))
829                 enumerate_mimetypes_subdir (name, ent->d_name, mimetypes);
830               g_free (name);
831             }
832         }
833       closedir (d);
834     }
835   
836   g_free (mimedir);
837 }
838
839 /**
840  * g_content_types_get_registered:
841  * 
842  * Gets a list of strings containing all the registered content types
843  * known to the system. The list and its data should be freed using 
844  * @g_list_foreach(list, g_free, NULL) and @g_list_free(list)
845  * Returns: #GList of the registered content types.
846  **/  
847 GList *
848 g_content_types_get_registered (void)
849 {
850   const char * const* dirs;
851   GHashTable *mimetypes;
852   GHashTableIter iter;
853   gpointer key;
854   int i;
855   GList *l;
856
857   mimetypes = g_hash_table_new (g_str_hash, g_str_equal);
858
859   enumerate_mimetypes_dir (g_get_user_data_dir (), mimetypes);
860   dirs = g_get_system_data_dirs ();
861
862   for (i = 0; dirs[i] != NULL; i++)
863     enumerate_mimetypes_dir (dirs[i], mimetypes);
864
865   l = NULL;
866   g_hash_table_iter_init (&iter, mimetypes);
867   while (g_hash_table_iter_next (&iter, &key, NULL))
868     l = g_list_prepend (l, key);
869
870   g_hash_table_destroy (mimetypes);
871
872   return l;
873 }
874
875 #endif /* Unix version */
876
877 #define __G_CONTENT_TYPE_C__
878 #include "gioaliasdef.c"