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