gkdbus: Fix underflow and unreachable code bug
[platform/upstream/glib.git] / gio / xdgmime / xdgmime.h
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* xdgmime.h: XDG Mime Spec mime resolver.  Based on version 0.11 of the spec.
3  *
4  * More info can be found at http://www.freedesktop.org/standards/
5  * 
6  * Copyright (C) 2003  Red Hat, Inc.
7  * Copyright (C) 2003  Jonathan Blandford <jrb@alum.mit.edu>
8  *
9  * SPDX-License-Identifier: LGPL-2.1-or-later or AFL-2.0
10  */
11
12
13 #ifndef __XDG_MIME_H__
14 #define __XDG_MIME_H__
15
16 #include <stdlib.h>
17 #include <sys/stat.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif /* __cplusplus */
22
23 #ifdef XDG_PREFIX
24 #define XDG_ENTRY(func) _XDG_ENTRY2(XDG_PREFIX,func)
25 #define _XDG_ENTRY2(prefix,func) _XDG_ENTRY3(prefix,func)
26 #define _XDG_ENTRY3(prefix,func) prefix##_##func
27
28 #define XDG_RESERVED_ENTRY(func) _XDG_RESERVED_ENTRY2(XDG_PREFIX,func)
29 #define _XDG_RESERVED_ENTRY2(prefix,func) _XDG_RESERVED_ENTRY3(prefix,func)
30 #define _XDG_RESERVED_ENTRY3(prefix,func) _##prefix##_##func
31 #endif
32
33 typedef void (*XdgMimeCallback) (void *user_data);
34 typedef void (*XdgMimeDestroy)  (void *user_data);
35
36   
37 #ifdef XDG_PREFIX
38 #define xdg_mime_get_mime_type_for_data       XDG_ENTRY(get_mime_type_for_data)
39 #define xdg_mime_get_mime_type_for_file       XDG_ENTRY(get_mime_type_for_file)
40 #define xdg_mime_get_mime_type_from_file_name XDG_ENTRY(get_mime_type_from_file_name)
41 #define xdg_mime_get_mime_types_from_file_name XDG_ENTRY(get_mime_types_from_file_name)
42 #define xdg_mime_is_valid_mime_type           XDG_ENTRY(is_valid_mime_type)
43 #define xdg_mime_mime_type_equal              XDG_ENTRY(mime_type_equal)
44 #define xdg_mime_media_type_equal             XDG_ENTRY(media_type_equal)
45 #define xdg_mime_mime_type_subclass           XDG_ENTRY(mime_type_subclass)
46 #define xdg_mime_get_mime_parents             XDG_ENTRY(get_mime_parents)
47 #define xdg_mime_list_mime_parents            XDG_ENTRY(list_mime_parents)
48 #define xdg_mime_unalias_mime_type            XDG_ENTRY(unalias_mime_type)
49 #define xdg_mime_get_max_buffer_extents       XDG_ENTRY(get_max_buffer_extents)
50 #define xdg_mime_shutdown                     XDG_ENTRY(shutdown)
51 #define xdg_mime_dump                         XDG_ENTRY(dump)
52 #define xdg_mime_register_reload_callback     XDG_ENTRY(register_reload_callback)
53 #define xdg_mime_remove_callback              XDG_ENTRY(remove_callback)
54 #define xdg_mime_type_unknown                 XDG_ENTRY(type_unknown)
55 #define xdg_mime_type_empty                   XDG_ENTRY(type_empty)
56 #define xdg_mime_type_textplain               XDG_ENTRY(type_textplain)
57 #define xdg_mime_get_icon                     XDG_ENTRY(get_icon)
58 #define xdg_mime_get_generic_icon             XDG_ENTRY(get_generic_icon)
59
60 #define _xdg_mime_mime_type_equal             XDG_RESERVED_ENTRY(mime_type_equal)
61 #define _xdg_mime_mime_type_subclass          XDG_RESERVED_ENTRY(mime_type_subclass)
62 #define _xdg_mime_unalias_mime_type           XDG_RESERVED_ENTRY(unalias_mime_type)  
63 #endif
64
65 extern const char xdg_mime_type_unknown[];
66 extern const char xdg_mime_type_empty[];
67 extern const char xdg_mime_type_textplain[];
68 #define XDG_MIME_TYPE_UNKNOWN xdg_mime_type_unknown
69 #define XDG_MIME_TYPE_EMPTY xdg_mime_type_empty
70 #define XDG_MIME_TYPE_TEXTPLAIN xdg_mime_type_textplain
71
72 const char  *xdg_mime_get_mime_type_for_data       (const void *data,
73                                                     size_t      len,
74                                                     int        *result_prio);
75 const char  *xdg_mime_get_mime_type_for_file       (const char *file_name,
76                                                     struct stat *statbuf);
77 const char  *xdg_mime_get_mime_type_from_file_name (const char *file_name);
78 int          xdg_mime_get_mime_types_from_file_name(const char *file_name,
79                                                     const char *mime_types[],
80                                                     int         n_mime_types);
81 int          xdg_mime_is_valid_mime_type           (const char *mime_type);
82 int          xdg_mime_mime_type_equal              (const char *mime_a,
83                                                     const char *mime_b);
84 int          xdg_mime_media_type_equal             (const char *mime_a,
85                                                     const char *mime_b);
86 int          xdg_mime_mime_type_subclass           (const char *mime_a,
87                                                     const char *mime_b);
88   /* xdg_mime_get_mime_parents() is deprecated since it does
89    * not work correctly with caches. Use xdg_mime_list_parents() 
90    * instead, but notice that that function expects you to free
91    * the array it returns. 
92    */
93 const char **xdg_mime_get_mime_parents             (const char *mime);
94 char **      xdg_mime_list_mime_parents            (const char *mime);
95 const char  *xdg_mime_unalias_mime_type            (const char *mime);
96 const char  *xdg_mime_get_icon                     (const char *mime);
97 const char  *xdg_mime_get_generic_icon             (const char *mime);
98 int          xdg_mime_get_max_buffer_extents       (void);
99 void         xdg_mime_shutdown                     (void);
100 void         xdg_mime_dump                         (void);
101 int          xdg_mime_register_reload_callback     (XdgMimeCallback  callback,
102                                                     void            *data,
103                                                     XdgMimeDestroy   destroy);
104 void         xdg_mime_remove_callback              (int              callback_id);
105
106 void xdg_mime_set_dirs (const char * const *dirs);
107
108    /* Private versions of functions that don't call xdg_mime_init () */
109 int          _xdg_mime_mime_type_equal             (const char *mime_a,
110                                                     const char *mime_b);
111 int          _xdg_mime_mime_type_subclass          (const char *mime,
112                                                     const char *base,
113                                                     const char ***seen);
114 const char  *_xdg_mime_unalias_mime_type           (const char *mime);
115
116
117 #ifdef __cplusplus
118 }
119 #endif /* __cplusplus */
120 #endif /* __XDG_MIME_H__ */