summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorDaniel Juyung Seo <seojuyung2@gmail.com>2012-09-21 00:03:18 +0000
committerDaniel Juyung Seo <seojuyung2@gmail.com>2012-09-21 00:03:18 +0000
commitc01f421317842ad6e95f81300498e80147f65ce7 (patch)
tree2a52e2c56322ce655a23f6e05982212d65c3dc1e /legacy/efreet
parentbe7b396171610f7dfe95b71654547aa40fd53916 (diff)
efreet: Fixed formatting.
SVN revision: 76923
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/src/lib/efreet.c302
-rw-r--r--legacy/efreet/src/lib/efreet_mime.c1386
2 files changed, 844 insertions, 844 deletions
diff --git a/legacy/efreet/src/lib/efreet.c b/legacy/efreet/src/lib/efreet.c
index c48223f37a..e6199efa3e 100644
--- a/legacy/efreet/src/lib/efreet.c
+++ b/legacy/efreet/src/lib/efreet.c
@@ -57,140 +57,140 @@ EAPI int
57efreet_init(void) 57efreet_init(void)
58{ 58{
59#ifndef _WIN32 59#ifndef _WIN32
60 char *tmp; 60 char *tmp;
61#endif 61#endif
62 62
63 if (++_efreet_init_count != 1) 63 if (++_efreet_init_count != 1)
64 return _efreet_init_count; 64 return _efreet_init_count;
65 65
66#ifndef _WIN32 66#ifndef _WIN32
67 /* Find users real uid and gid */ 67 /* Find users real uid and gid */
68 tmp = getenv("SUDO_UID"); 68 tmp = getenv("SUDO_UID");
69 if (tmp) 69 if (tmp)
70 ruid = strtoul(tmp, NULL, 10); 70 ruid = strtoul(tmp, NULL, 10);
71 else 71 else
72 ruid = getuid(); 72 ruid = getuid();
73 73
74 tmp = getenv("SUDO_GID"); 74 tmp = getenv("SUDO_GID");
75 if (tmp) 75 if (tmp)
76 rgid = strtoul(tmp, NULL, 10); 76 rgid = strtoul(tmp, NULL, 10);
77 else 77 else
78 rgid = getgid(); 78 rgid = getgid();
79#endif 79#endif
80 80
81 if (!eina_init()) 81 if (!eina_init())
82 return --_efreet_init_count; 82 return --_efreet_init_count;
83 if (!eet_init()) 83 if (!eet_init())
84 goto shutdown_eina; 84 goto shutdown_eina;
85 if (!ecore_init()) 85 if (!ecore_init())
86 goto shutdown_eet; 86 goto shutdown_eet;
87 if (!ecore_file_init()) 87 if (!ecore_file_init())
88 goto shutdown_ecore; 88 goto shutdown_ecore;
89 89
90 if (!efreet_base_init()) 90 if (!efreet_base_init())
91 goto shutdown_ecore_file; 91 goto shutdown_ecore_file;
92 92
93 if (!efreet_cache_init()) 93 if (!efreet_cache_init())
94 goto shutdown_efreet_base; 94 goto shutdown_efreet_base;
95 95
96 if (!efreet_xml_init()) 96 if (!efreet_xml_init())
97 goto shutdown_efreet_cache; 97 goto shutdown_efreet_cache;
98 98
99 if (!efreet_icon_init()) 99 if (!efreet_icon_init())
100 goto shutdown_efreet_xml; 100 goto shutdown_efreet_xml;
101 101
102 if (!efreet_ini_init()) 102 if (!efreet_ini_init())
103 goto shutdown_efreet_icon; 103 goto shutdown_efreet_icon;
104 104
105 if (!efreet_desktop_init()) 105 if (!efreet_desktop_init())
106 goto shutdown_efreet_ini; 106 goto shutdown_efreet_ini;
107 107
108 if (!efreet_menu_init()) 108 if (!efreet_menu_init())
109 goto shutdown_efreet_desktop; 109 goto shutdown_efreet_desktop;
110 110
111 if (!efreet_util_init()) 111 if (!efreet_util_init())
112 goto shutdown_efreet_menu; 112 goto shutdown_efreet_menu;
113 113
114#ifdef ENABLE_NLS 114#ifdef ENABLE_NLS
115 bindtextdomain(PACKAGE, LOCALE_DIR); 115 bindtextdomain(PACKAGE, LOCALE_DIR);
116 bind_textdomain_codeset(PACKAGE, "UTF-8"); 116 bind_textdomain_codeset(PACKAGE, "UTF-8");
117#endif 117#endif
118 118
119 return _efreet_init_count; 119 return _efreet_init_count;
120 120
121shutdown_efreet_menu: 121shutdown_efreet_menu:
122 efreet_menu_shutdown(); 122 efreet_menu_shutdown();
123shutdown_efreet_desktop: 123shutdown_efreet_desktop:
124 efreet_desktop_shutdown(); 124 efreet_desktop_shutdown();
125shutdown_efreet_ini: 125shutdown_efreet_ini:
126 efreet_ini_shutdown(); 126 efreet_ini_shutdown();
127shutdown_efreet_icon: 127shutdown_efreet_icon:
128 efreet_icon_shutdown(); 128 efreet_icon_shutdown();
129shutdown_efreet_xml: 129shutdown_efreet_xml:
130 efreet_xml_shutdown(); 130 efreet_xml_shutdown();
131shutdown_efreet_cache: 131shutdown_efreet_cache:
132 efreet_cache_shutdown(); 132 efreet_cache_shutdown();
133shutdown_efreet_base: 133shutdown_efreet_base:
134 efreet_base_shutdown(); 134 efreet_base_shutdown();
135shutdown_ecore_file: 135shutdown_ecore_file:
136 ecore_file_shutdown(); 136 ecore_file_shutdown();
137shutdown_ecore: 137shutdown_ecore:
138 ecore_shutdown(); 138 ecore_shutdown();
139shutdown_eet: 139shutdown_eet:
140 eet_shutdown(); 140 eet_shutdown();
141shutdown_eina: 141shutdown_eina:
142 eina_shutdown(); 142 eina_shutdown();
143 143
144 return --_efreet_init_count; 144 return --_efreet_init_count;
145} 145}
146 146
147EAPI int 147EAPI int
148efreet_shutdown(void) 148efreet_shutdown(void)
149{ 149{
150 if (_efreet_init_count <= 0) 150 if (_efreet_init_count <= 0)
151 { 151 {
152 EINA_LOG_ERR("Init count not greater than 0 in shutdown."); 152 EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
153 return 0; 153 return 0;
154 } 154 }
155 if (--_efreet_init_count != 0) 155 if (--_efreet_init_count != 0)
156 return _efreet_init_count; 156 return _efreet_init_count;
157 157
158 efreet_util_shutdown(); 158 efreet_util_shutdown();
159 efreet_menu_shutdown(); 159 efreet_menu_shutdown();
160 efreet_desktop_shutdown(); 160 efreet_desktop_shutdown();
161 efreet_ini_shutdown(); 161 efreet_ini_shutdown();
162 efreet_icon_shutdown(); 162 efreet_icon_shutdown();
163 efreet_xml_shutdown(); 163 efreet_xml_shutdown();
164 efreet_cache_shutdown(); 164 efreet_cache_shutdown();
165 efreet_base_shutdown(); 165 efreet_base_shutdown();
166 166
167 IF_RELEASE(efreet_lang); 167 IF_RELEASE(efreet_lang);
168 IF_RELEASE(efreet_lang_country); 168 IF_RELEASE(efreet_lang_country);
169 IF_RELEASE(efreet_lang_modifier); 169 IF_RELEASE(efreet_lang_modifier);
170 efreet_parsed_locale = 0; /* reset this in case they init efreet again */ 170 efreet_parsed_locale = 0; /* reset this in case they init efreet again */
171 171
172 ecore_file_shutdown(); 172 ecore_file_shutdown();
173 ecore_shutdown(); 173 ecore_shutdown();
174 eet_shutdown(); 174 eet_shutdown();
175 eina_shutdown(); 175 eina_shutdown();
176 176
177 return _efreet_init_count; 177 return _efreet_init_count;
178} 178}
179 179
180EAPI void 180EAPI void
181efreet_lang_reset(void) 181efreet_lang_reset(void)
182{ 182{
183 IF_RELEASE(efreet_lang); 183 IF_RELEASE(efreet_lang);
184 IF_RELEASE(efreet_lang_country); 184 IF_RELEASE(efreet_lang_country);
185 IF_RELEASE(efreet_lang_modifier); 185 IF_RELEASE(efreet_lang_modifier);
186 efreet_parsed_locale = 0; /* reset this in case they init efreet again */ 186 efreet_parsed_locale = 0; /* reset this in case they init efreet again */
187 187
188 efreet_dirs_reset(); 188 efreet_dirs_reset();
189 efreet_cache_desktop_close(); 189 efreet_cache_desktop_close();
190 efreet_cache_desktop_update(); 190 efreet_cache_desktop_update();
191} 191}
192 192
193 /** 193/**
194 * @internal 194 * @internal
195 * @return Returns the current users language setting or NULL if none set 195 * @return Returns the current users language setting or NULL if none set
196 * @brief Retrieves the current language setting 196 * @brief Retrieves the current language setting
@@ -198,10 +198,10 @@ efreet_lang_reset(void)
198const char * 198const char *
199efreet_lang_get(void) 199efreet_lang_get(void)
200{ 200{
201 if (efreet_parsed_locale) return efreet_lang; 201 if (efreet_parsed_locale) return efreet_lang;
202 202
203 efreet_parse_locale(); 203 efreet_parse_locale();
204 return efreet_lang; 204 return efreet_lang;
205} 205}
206 206
207/** 207/**
@@ -212,10 +212,10 @@ efreet_lang_get(void)
212const char * 212const char *
213efreet_lang_country_get(void) 213efreet_lang_country_get(void)
214{ 214{
215 if (efreet_parsed_locale) return efreet_lang_country; 215 if (efreet_parsed_locale) return efreet_lang_country;
216 216
217 efreet_parse_locale(); 217 efreet_parse_locale();
218 return efreet_lang_country; 218 return efreet_lang_country;
219} 219}
220 220
221/** 221/**
@@ -227,10 +227,10 @@ efreet_lang_country_get(void)
227const char * 227const char *
228efreet_lang_modifier_get(void) 228efreet_lang_modifier_get(void)
229{ 229{
230 if (efreet_parsed_locale) return efreet_lang_modifier; 230 if (efreet_parsed_locale) return efreet_lang_modifier;
231 231
232 efreet_parse_locale(); 232 efreet_parse_locale();
233 return efreet_lang_modifier; 233 return efreet_lang_modifier;
234} 234}
235 235
236/** 236/**
@@ -242,15 +242,15 @@ efreet_lang_modifier_get(void)
242static void 242static void
243efreet_parse_locale(void) 243efreet_parse_locale(void)
244{ 244{
245 efreet_parsed_locale = 1; 245 efreet_parsed_locale = 1;
246 246
247 if (efreet_parse_locale_setting("LANG")) 247 if (efreet_parse_locale_setting("LANG"))
248 return; 248 return;
249 249
250 if (efreet_parse_locale_setting("LC_ALL")) 250 if (efreet_parse_locale_setting("LC_ALL"))
251 return; 251 return;
252 252
253 efreet_parse_locale_setting("LC_MESSAGES"); 253 efreet_parse_locale_setting("LC_MESSAGES");
254} 254}
255 255
256/** 256/**
@@ -263,46 +263,46 @@ efreet_parse_locale(void)
263static int 263static int
264efreet_parse_locale_setting(const char *env) 264efreet_parse_locale_setting(const char *env)
265{ 265{
266 int found = 0; 266 int found = 0;
267 char *setting; 267 char *setting;
268 char *p; 268 char *p;
269 size_t len; 269 size_t len;
270 270
271 p = getenv(env); 271 p = getenv(env);
272 if (!p) return 0; 272 if (!p) return 0;
273 len = strlen(p) + 1; 273 len = strlen(p) + 1;
274 setting = alloca(len); 274 setting = alloca(len);
275 memcpy(setting, p, len); 275 memcpy(setting, p, len);
276 276
277 /* pull the modifier off the end */ 277 /* pull the modifier off the end */
278 p = strrchr(setting, '@'); 278 p = strrchr(setting, '@');
279 if (p) 279 if (p)
280 { 280 {
281 *p = '\0'; 281 *p = '\0';
282 efreet_lang_modifier = eina_stringshare_add(p + 1); 282 efreet_lang_modifier = eina_stringshare_add(p + 1);
283 found = 1; 283 found = 1;
284 } 284 }
285 285
286 /* if there is an encoding we ignore it */ 286 /* if there is an encoding we ignore it */
287 p = strrchr(setting, '.'); 287 p = strrchr(setting, '.');
288 if (p) *p = '\0'; 288 if (p) *p = '\0';
289 289
290 /* get the country if available */ 290 /* get the country if available */
291 p = strrchr(setting, '_'); 291 p = strrchr(setting, '_');
292 if (p) 292 if (p)
293 { 293 {
294 *p = '\0'; 294 *p = '\0';
295 efreet_lang_country = eina_stringshare_add(p + 1); 295 efreet_lang_country = eina_stringshare_add(p + 1);
296 found = 1; 296 found = 1;
297 } 297 }
298 298
299 if (*setting != '\0') 299 if (*setting != '\0')
300 { 300 {
301 efreet_lang = eina_stringshare_add(setting); 301 efreet_lang = eina_stringshare_add(setting);
302 found = 1; 302 found = 1;
303 } 303 }
304 304
305 return found; 305 return found;
306} 306}
307 307
308/** 308/**
@@ -317,26 +317,26 @@ efreet_parse_locale_setting(const char *env)
317size_t 317size_t
318efreet_array_cat(char *buffer, size_t size, const char *strs[]) 318efreet_array_cat(char *buffer, size_t size, const char *strs[])
319{ 319{
320 int i; 320 int i;
321 size_t n; 321 size_t n;
322 for (i = 0, n = 0; n < size && strs[i]; i++) 322 for (i = 0, n = 0; n < size && strs[i]; i++)
323 { 323 {
324 n += eina_strlcpy(buffer + n, strs[i], size - n); 324 n += eina_strlcpy(buffer + n, strs[i], size - n);
325 } 325 }
326 return n; 326 return n;
327} 327}
328 328
329#ifndef _WIN32 329#ifndef _WIN32
330EAPI void 330EAPI void
331efreet_fsetowner(int fd) 331efreet_fsetowner(int fd)
332{ 332{
333 struct stat st; 333 struct stat st;
334 334
335 if (fd < 0) return; 335 if (fd < 0) return;
336 if (fstat(fd, &st) < 0) return; 336 if (fstat(fd, &st) < 0) return;
337 if (st.st_uid == ruid) return; 337 if (st.st_uid == ruid) return;
338 338
339 if (fchown(fd, ruid, rgid) != 0) return; 339 if (fchown(fd, ruid, rgid) != 0) return;
340} 340}
341#else 341#else
342EAPI void 342EAPI void
@@ -349,14 +349,14 @@ efreet_fsetowner(int fd __UNUSED__)
349EAPI void 349EAPI void
350efreet_setowner(const char *path) 350efreet_setowner(const char *path)
351{ 351{
352 EINA_SAFETY_ON_NULL_RETURN(path); 352 EINA_SAFETY_ON_NULL_RETURN(path);
353 353
354 int fd; 354 int fd;
355 355
356 fd = open(path, O_RDONLY); 356 fd = open(path, O_RDONLY);
357 if (fd < 0) return; 357 if (fd < 0) return;
358 efreet_fsetowner(fd); 358 efreet_fsetowner(fd);
359 close(fd); 359 close(fd);
360} 360}
361#else 361#else
362EAPI void 362EAPI void
diff --git a/legacy/efreet/src/lib/efreet_mime.c b/legacy/efreet/src/lib/efreet_mime.c
index 12bad3f9fd..89271b6364 100644
--- a/legacy/efreet/src/lib/efreet_mime.c
+++ b/legacy/efreet/src/lib/efreet_mime.c
@@ -76,8 +76,8 @@ static const char *_mime_text_plain = NULL;
76 */ 76 */
77static enum 77static enum
78{ 78{
79 EFREET_ENDIAN_BIG = 0, 79 EFREET_ENDIAN_BIG = 0,
80 EFREET_ENDIAN_LITTLE = 1 80 EFREET_ENDIAN_LITTLE = 1
81} efreet_mime_endianess = EFREET_ENDIAN_BIG; 81} efreet_mime_endianess = EFREET_ENDIAN_BIG;
82 82
83/* 83/*
@@ -109,46 +109,46 @@ static enum
109typedef struct Efreet_Mime_Glob Efreet_Mime_Glob; 109typedef struct Efreet_Mime_Glob Efreet_Mime_Glob;
110struct Efreet_Mime_Glob 110struct Efreet_Mime_Glob
111{ 111{
112 const char *glob; 112 const char *glob;
113 const char *mime; 113 const char *mime;
114}; 114};
115 115
116typedef struct Efreet_Mime_Magic Efreet_Mime_Magic; 116typedef struct Efreet_Mime_Magic Efreet_Mime_Magic;
117struct Efreet_Mime_Magic 117struct Efreet_Mime_Magic
118{ 118{
119 unsigned int priority; 119 unsigned int priority;
120 const char *mime; 120 const char *mime;
121 Eina_List *entries; 121 Eina_List *entries;
122}; 122};
123 123
124typedef struct Efreet_Mime_Magic_Entry Efreet_Mime_Magic_Entry; 124typedef struct Efreet_Mime_Magic_Entry Efreet_Mime_Magic_Entry;
125struct Efreet_Mime_Magic_Entry 125struct Efreet_Mime_Magic_Entry
126{ 126{
127 unsigned int indent; 127 unsigned int indent;
128 unsigned int offset; 128 unsigned int offset;
129 unsigned int word_size; 129 unsigned int word_size;
130 unsigned int range_len; 130 unsigned int range_len;
131 unsigned short value_len; 131 unsigned short value_len;
132 char *mask; 132 char *mask;
133 char *value; 133 char *value;
134}; 134};
135 135
136typedef struct Efreet_Mime_Icon_Entry_Head Efreet_Mime_Icon_Entry_Head; 136typedef struct Efreet_Mime_Icon_Entry_Head Efreet_Mime_Icon_Entry_Head;
137struct Efreet_Mime_Icon_Entry_Head 137struct Efreet_Mime_Icon_Entry_Head
138{ 138{
139 EINA_INLIST; /* node of mime_icons_lru */ 139 EINA_INLIST; /* node of mime_icons_lru */
140 Eina_Inlist *list; 140 Eina_Inlist *list;
141 const char *mime; 141 const char *mime;
142 double timestamp; 142 double timestamp;
143}; 143};
144 144
145typedef struct Efreet_Mime_Icon_Entry Efreet_Mime_Icon_Entry; 145typedef struct Efreet_Mime_Icon_Entry Efreet_Mime_Icon_Entry;
146struct Efreet_Mime_Icon_Entry 146struct Efreet_Mime_Icon_Entry
147{ 147{
148 EINA_INLIST; 148 EINA_INLIST;
149 const char *icon; 149 const char *icon;
150 const char *theme; 150 const char *theme;
151 unsigned int size; 151 unsigned int size;
152}; 152};
153 153
154static int efreet_mime_glob_remove(const char *glob); 154static int efreet_mime_glob_remove(const char *glob);
@@ -157,8 +157,8 @@ static void efreet_mime_shared_mimeinfo_globs_load(const char *file);
157static void efreet_mime_shared_mimeinfo_magic_load(const char *file); 157static void efreet_mime_shared_mimeinfo_magic_load(const char *file);
158static void efreet_mime_shared_mimeinfo_magic_parse(char *data, int size); 158static void efreet_mime_shared_mimeinfo_magic_parse(char *data, int size);
159static const char *efreet_mime_magic_check_priority(const char *file, 159static const char *efreet_mime_magic_check_priority(const char *file,
160 unsigned int start, 160 unsigned int start,
161 unsigned int end); 161 unsigned int end);
162static int efreet_mime_init_files(void); 162static int efreet_mime_init_files(void);
163static const char *efreet_mime_special_check(const char *file); 163static const char *efreet_mime_special_check(const char *file);
164static const char *efreet_mime_fallback_check(const char *file); 164static const char *efreet_mime_fallback_check(const char *file);
@@ -171,9 +171,9 @@ static int efreet_mime_endian_check(void);
171 171
172static void efreet_mime_monitor_add(const char *file); 172static void efreet_mime_monitor_add(const char *file);
173static void efreet_mime_cb_update_file(void *data, 173static void efreet_mime_cb_update_file(void *data,
174 Ecore_File_Monitor *monitor, 174 Ecore_File_Monitor *monitor,
175 Ecore_File_Event event, 175 Ecore_File_Event event,
176 const char *path); 176 const char *path);
177 177
178static void efreet_mime_icons_flush(double now); 178static void efreet_mime_icons_flush(double now);
179static void efreet_mime_icon_entry_head_free(Efreet_Mime_Icon_Entry_Head *entry); 179static void efreet_mime_icon_entry_head_free(Efreet_Mime_Icon_Entry_Head *entry);
@@ -189,166 +189,166 @@ static void efreet_mime_icons_debug(void);
189EAPI int 189EAPI int
190efreet_mime_init(void) 190efreet_mime_init(void)
191{ 191{
192 if (++_efreet_mime_init_count != 1) 192 if (++_efreet_mime_init_count != 1)
193 return _efreet_mime_init_count; 193 return _efreet_mime_init_count;
194 194
195 if (!ecore_init()) 195 if (!ecore_init())
196 return --_efreet_mime_init_count; 196 return --_efreet_mime_init_count;
197 197
198 if (!ecore_file_init()) 198 if (!ecore_file_init())
199 goto shutdown_ecore; 199 goto shutdown_ecore;
200 200
201 if (!efreet_init()) 201 if (!efreet_init())
202 goto shutdown_ecore_file; 202 goto shutdown_ecore_file;
203 203
204 _efreet_mime_log_dom = eina_log_domain_register 204 _efreet_mime_log_dom = eina_log_domain_register
205 ("efreet_mime", EFREET_DEFAULT_LOG_COLOR); 205 ("efreet_mime", EFREET_DEFAULT_LOG_COLOR);
206 206
207 if (_efreet_mime_log_dom < 0) 207 if (_efreet_mime_log_dom < 0)
208 { 208 {
209 EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_mime."); 209 EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_mime.");
210 goto shutdown_efreet; 210 goto shutdown_efreet;
211 } 211 }
212 212
213 efreet_mime_endianess = efreet_mime_endian_check(); 213 efreet_mime_endianess = efreet_mime_endian_check();
214 214
215 monitors = eina_hash_string_superfast_new(EINA_FREE_CB(ecore_file_monitor_del)); 215 monitors = eina_hash_string_superfast_new(EINA_FREE_CB(ecore_file_monitor_del));
216 216
217 efreet_mime_type_cache_clear(); 217 efreet_mime_type_cache_clear();
218 218
219 if (!efreet_mime_init_files()) 219 if (!efreet_mime_init_files())
220 goto unregister_log_domain; 220 goto unregister_log_domain;
221 221
222 return _efreet_mime_init_count; 222 return _efreet_mime_init_count;
223 223
224unregister_log_domain: 224unregister_log_domain:
225 eina_log_domain_unregister(_efreet_mime_log_dom); 225 eina_log_domain_unregister(_efreet_mime_log_dom);
226 _efreet_mime_log_dom = -1; 226 _efreet_mime_log_dom = -1;
227shutdown_efreet: 227shutdown_efreet:
228 efreet_shutdown(); 228 efreet_shutdown();
229shutdown_ecore_file: 229shutdown_ecore_file:
230 ecore_file_shutdown(); 230 ecore_file_shutdown();
231shutdown_ecore: 231shutdown_ecore:
232 ecore_shutdown(); 232 ecore_shutdown();
233 233
234 return --_efreet_mime_init_count; 234 return --_efreet_mime_init_count;
235} 235}
236 236
237EAPI int 237EAPI int
238efreet_mime_shutdown(void) 238efreet_mime_shutdown(void)
239{ 239{
240 if (_efreet_mime_init_count <= 0) 240 if (_efreet_mime_init_count <= 0)
241 { 241 {
242 EINA_LOG_ERR("Init count not greater than 0 in shutdown."); 242 EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
243 return 0; 243 return 0;
244 } 244 }
245 if (--_efreet_mime_init_count != 0) 245 if (--_efreet_mime_init_count != 0)
246 return _efreet_mime_init_count; 246 return _efreet_mime_init_count;
247 247
248 efreet_mime_icons_debug(); 248 efreet_mime_icons_debug();
249 249
250 IF_RELEASE(_mime_inode_symlink); 250 IF_RELEASE(_mime_inode_symlink);
251 IF_RELEASE(_mime_inode_fifo); 251 IF_RELEASE(_mime_inode_fifo);
252 IF_RELEASE(_mime_inode_chardevice); 252 IF_RELEASE(_mime_inode_chardevice);
253 IF_RELEASE(_mime_inode_blockdevice); 253 IF_RELEASE(_mime_inode_blockdevice);
254 IF_RELEASE(_mime_inode_socket); 254 IF_RELEASE(_mime_inode_socket);
255 IF_RELEASE(_mime_inode_mountpoint); 255 IF_RELEASE(_mime_inode_mountpoint);
256 IF_RELEASE(_mime_inode_directory); 256 IF_RELEASE(_mime_inode_directory);
257 IF_RELEASE(_mime_application_x_executable); 257 IF_RELEASE(_mime_application_x_executable);
258 IF_RELEASE(_mime_application_octet_stream); 258 IF_RELEASE(_mime_application_octet_stream);
259 IF_RELEASE(_mime_text_plain); 259 IF_RELEASE(_mime_text_plain);
260 260
261 IF_FREE_LIST(globs, efreet_mime_glob_free); 261 IF_FREE_LIST(globs, efreet_mime_glob_free);
262 IF_FREE_LIST(magics, efreet_mime_magic_free); 262 IF_FREE_LIST(magics, efreet_mime_magic_free);
263 IF_FREE_HASH(monitors); 263 IF_FREE_HASH(monitors);
264 IF_FREE_HASH(wild); 264 IF_FREE_HASH(wild);
265 IF_FREE_HASH(mime_icons); 265 IF_FREE_HASH(mime_icons);
266 eina_log_domain_unregister(_efreet_mime_log_dom); 266 eina_log_domain_unregister(_efreet_mime_log_dom);
267 _efreet_mime_log_dom = -1; 267 _efreet_mime_log_dom = -1;
268 efreet_shutdown(); 268 efreet_shutdown();
269 ecore_file_shutdown(); 269 ecore_file_shutdown();
270 ecore_shutdown(); 270 ecore_shutdown();
271 271
272 return _efreet_mime_init_count; 272 return _efreet_mime_init_count;
273} 273}
274 274
275EAPI const char * 275EAPI const char *
276efreet_mime_type_get(const char *file) 276efreet_mime_type_get(const char *file)
277{ 277{
278 const char *type = NULL; 278 const char *type = NULL;
279 279
280 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); 280 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
281 281
282 if ((type = efreet_mime_special_check(file))) 282 if ((type = efreet_mime_special_check(file)))
283 return type; 283 return type;
284 284
285 /* Check magics with priority > 80 */ 285 /* Check magics with priority > 80 */
286 if ((type = efreet_mime_magic_check_priority(file, 0, 80))) 286 if ((type = efreet_mime_magic_check_priority(file, 0, 80)))
287 return type; 287 return type;
288 288
289 /* Check globs */ 289 /* Check globs */
290 if ((type = efreet_mime_globs_type_get(file))) 290 if ((type = efreet_mime_globs_type_get(file)))
291 return type; 291 return type;
292 292
293 /* Check rest of magics */ 293 /* Check rest of magics */
294 if ((type = efreet_mime_magic_check_priority(file, 80, 0))) 294 if ((type = efreet_mime_magic_check_priority(file, 80, 0)))
295 return type; 295 return type;
296 296
297 return efreet_mime_fallback_check(file); 297 return efreet_mime_fallback_check(file);
298} 298}
299 299
300EAPI const char * 300EAPI const char *
301efreet_mime_type_icon_get(const char *mime, const char *theme, unsigned int size) 301efreet_mime_type_icon_get(const char *mime, const char *theme, unsigned int size)
302{ 302{
303 const char *icon = NULL; 303 const char *icon = NULL;
304 char *data; 304 char *data;
305 Eina_List *icons = NULL; 305 Eina_List *icons = NULL;
306 const char *env = NULL; 306 const char *env = NULL;
307 char *p = NULL, *pp = NULL, *ppp = NULL; 307 char *p = NULL, *pp = NULL, *ppp = NULL;
308 char buf[PATH_MAX]; 308 char buf[PATH_MAX];
309 const char *cache; 309 const char *cache;
310 310
311 EINA_SAFETY_ON_NULL_RETURN_VAL(mime, NULL); 311 EINA_SAFETY_ON_NULL_RETURN_VAL(mime, NULL);
312 EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL); 312 EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL);
313 313
314 mime = eina_stringshare_add(mime); 314 mime = eina_stringshare_add(mime);
315 theme = eina_stringshare_add(theme); 315 theme = eina_stringshare_add(theme);
316 cache = efreet_mime_icon_entry_find(mime, theme, size); 316 cache = efreet_mime_icon_entry_find(mime, theme, size);
317 if (cache) 317 if (cache)
318 { 318 {
319 eina_stringshare_del(mime); 319 eina_stringshare_del(mime);
320 eina_stringshare_del(theme); 320 eina_stringshare_del(theme);
321 return cache; 321 return cache;
322 } 322 }
323 323
324 /* Standard icon name */ 324 /* Standard icon name */
325 p = strdup(mime); 325 p = strdup(mime);
326 pp = p; 326 pp = p;
327 while (*pp) 327 while (*pp)
328 { 328 {
329 if (*pp == '/') *pp = '-'; 329 if (*pp == '/') *pp = '-';
330 pp++; 330 pp++;
331 } 331 }
332 icons = eina_list_append(icons, p); 332 icons = eina_list_append(icons, p);
333 333
334 /* Environment Based icon names */ 334 /* Environment Based icon names */
335 if ((env = efreet_desktop_environment_get())) 335 if ((env = efreet_desktop_environment_get()))
336 { 336 {
337 snprintf(buf, sizeof(buf), "%s-mime-%s", env, p); 337 snprintf(buf, sizeof(buf), "%s-mime-%s", env, p);
338 icons = eina_list_append(icons, strdup(buf)); 338 icons = eina_list_append(icons, strdup(buf));
339 339
340 snprintf(buf, sizeof(buf), "%s-%s", env, p); 340 snprintf(buf, sizeof(buf), "%s-%s", env, p);
341 icons = eina_list_append(icons, strdup(buf)); 341 icons = eina_list_append(icons, strdup(buf));
342 } 342 }
343 343
344 /* Mime prefixed icon names */ 344 /* Mime prefixed icon names */
345 snprintf(buf, sizeof(buf), "mime-%s", p); 345 snprintf(buf, sizeof(buf), "mime-%s", p);
346 icons = eina_list_append(icons, strdup(buf)); 346 icons = eina_list_append(icons, strdup(buf));
347 347
348 /* Generic icons */ 348 /* Generic icons */
349 pp = strdup(p); 349 pp = strdup(p);
350 while ((ppp = strrchr(pp, '-'))) 350 while ((ppp = strrchr(pp, '-')))
351 { 351 {
352 *ppp = '\0'; 352 *ppp = '\0';
353 353
354 snprintf(buf, sizeof(buf), "%s-x-generic", pp); 354 snprintf(buf, sizeof(buf), "%s-x-generic", pp);
@@ -359,105 +359,105 @@ efreet_mime_type_icon_get(const char *mime, const char *theme, unsigned int size
359 359
360 snprintf(buf, sizeof(buf), "%s", pp); 360 snprintf(buf, sizeof(buf), "%s", pp);
361 icons = eina_list_append(icons, strdup(buf)); 361 icons = eina_list_append(icons, strdup(buf));
362 } 362 }
363 FREE(pp); 363 FREE(pp);
364 364
365 /* Search for icons using list */ 365 /* Search for icons using list */
366 icon = efreet_icon_list_find(theme, icons, size); 366 icon = efreet_icon_list_find(theme, icons, size);
367 while (icons) 367 while (icons)
368 { 368 {
369 data = eina_list_data_get(icons); 369 data = eina_list_data_get(icons);
370 free(data); 370 free(data);
371 icons = eina_list_remove_list(icons, icons); 371 icons = eina_list_remove_list(icons, icons);
372 } 372 }
373 373
374 efreet_mime_icon_entry_add(mime, eina_stringshare_add(icon), theme, size); 374 efreet_mime_icon_entry_add(mime, eina_stringshare_add(icon), theme, size);
375 375
376 return icon; 376 return icon;
377} 377}
378 378
379EAPI void 379EAPI void
380efreet_mime_type_cache_clear(void) 380efreet_mime_type_cache_clear(void)
381{ 381{
382 if (mime_icons) 382 if (mime_icons)
383 { 383 {
384 eina_hash_free(mime_icons); 384 eina_hash_free(mime_icons);
385 mime_icons_lru = NULL; 385 mime_icons_lru = NULL;
386 } 386 }
387 mime_icons = eina_hash_stringshared_new(EINA_FREE_CB(efreet_mime_icon_entry_head_free)); 387 mime_icons = eina_hash_stringshared_new(EINA_FREE_CB(efreet_mime_icon_entry_head_free));
388} 388}
389 389
390EAPI void 390EAPI void
391efreet_mime_type_cache_flush(void) 391efreet_mime_type_cache_flush(void)
392{ 392{
393 efreet_mime_icons_flush(ecore_loop_time_get()); 393 efreet_mime_icons_flush(ecore_loop_time_get());
394} 394}
395 395
396 396
397EAPI const char * 397EAPI const char *
398efreet_mime_magic_type_get(const char *file) 398efreet_mime_magic_type_get(const char *file)
399{ 399{
400 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); 400 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
401 return efreet_mime_magic_check_priority(file, 0, 0); 401 return efreet_mime_magic_check_priority(file, 0, 0);
402} 402}
403 403
404EAPI const char * 404EAPI const char *
405efreet_mime_globs_type_get(const char *file) 405efreet_mime_globs_type_get(const char *file)
406{ 406{
407 Eina_List *l; 407 Eina_List *l;
408 Efreet_Mime_Glob *g; 408 Efreet_Mime_Glob *g;
409 char *sl, *p; 409 char *sl, *p;
410 const char *s; 410 const char *s;
411 char *ext, *mime; 411 char *ext, *mime;
412 412
413 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); 413 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
414 414
415 /* Check in the extension hash for the type */ 415 /* Check in the extension hash for the type */
416 ext = strchr(file, '.'); 416 ext = strchr(file, '.');
417 if (ext) 417 if (ext)
418 { 418 {
419 sl = alloca(strlen(ext) + 1); 419 sl = alloca(strlen(ext) + 1);
420 for (s = ext, p = sl; *s; s++, p++) *p = tolower(*s); 420 for (s = ext, p = sl; *s; s++, p++) *p = tolower(*s);
421 *p = 0; 421 *p = 0;
422 p = sl; 422 p = sl;
423 while (p) 423 while (p)
424 { 424 {
425 p++; 425 p++;
426 if (p && (mime = eina_hash_find(wild, p))) return mime; 426 if (p && (mime = eina_hash_find(wild, p))) return mime;
427 p = strchr(p, '.'); 427 p = strchr(p, '.');
428 } 428 }
429 } 429 }
430 430
431 /* Fallback to the other globs if not found */ 431 /* Fallback to the other globs if not found */
432 EINA_LIST_FOREACH(globs, l, g) 432 EINA_LIST_FOREACH(globs, l, g)
433 { 433 {
434 if (efreet_mime_glob_match(file, g->glob)) 434 if (efreet_mime_glob_match(file, g->glob))
435 return g->mime; 435 return g->mime;
436 } 436 }
437 437
438 ext = alloca(strlen(file) + 1); 438 ext = alloca(strlen(file) + 1);
439 for (s = file, p = ext; *s; s++, p++) *p = tolower(*s); 439 for (s = file, p = ext; *s; s++, p++) *p = tolower(*s);
440 *p = 0; 440 *p = 0;
441 EINA_LIST_FOREACH(globs, l, g) 441 EINA_LIST_FOREACH(globs, l, g)
442 { 442 {
443 if (efreet_mime_glob_case_match(ext, g->glob)) 443 if (efreet_mime_glob_case_match(ext, g->glob))
444 return g->mime; 444 return g->mime;
445 } 445 }
446 return NULL; 446 return NULL;
447} 447}
448 448
449EAPI const char * 449EAPI const char *
450efreet_mime_special_type_get(const char *file) 450efreet_mime_special_type_get(const char *file)
451{ 451{
452 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); 452 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
453 return efreet_mime_special_check(file); 453 return efreet_mime_special_check(file);
454} 454}
455 455
456EAPI const char * 456EAPI const char *
457efreet_mime_fallback_type_get(const char *file) 457efreet_mime_fallback_type_get(const char *file)
458{ 458{
459 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL); 459 EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
460 return efreet_mime_fallback_check(file); 460 return efreet_mime_fallback_check(file);
461} 461}
462 462
463/** 463/**
@@ -468,8 +468,8 @@ efreet_mime_fallback_type_get(const char *file)
468static int 468static int
469efreet_mime_endian_check(void) 469efreet_mime_endian_check(void)
470{ 470{
471 int test = 1; 471 int test = 1;
472 return (*((char*)(&test))); 472 return (*((char*)(&test)));
473} 473}
474 474
475/** 475/**
@@ -482,18 +482,18 @@ efreet_mime_endian_check(void)
482static void 482static void
483efreet_mime_monitor_add(const char *file) 483efreet_mime_monitor_add(const char *file)
484{ 484{
485 Ecore_File_Monitor *fm = NULL; 485 Ecore_File_Monitor *fm = NULL;
486 486
487 /* if this is already in our hash then we're already monitoring so no 487 /* if this is already in our hash then we're already monitoring so no
488 * reason to re-monitor */ 488 * reason to re-monitor */
489 if (eina_hash_find(monitors, file)) 489 if (eina_hash_find(monitors, file))
490 return; 490 return;
491 491
492 if ((fm = ecore_file_monitor_add(file, efreet_mime_cb_update_file, NULL))) 492 if ((fm = ecore_file_monitor_add(file, efreet_mime_cb_update_file, NULL)))
493 { 493 {
494 eina_hash_del(monitors, file, NULL); 494 eina_hash_del(monitors, file, NULL);
495 eina_hash_add(monitors, file, fm); 495 eina_hash_add(monitors, file, fm);
496 } 496 }
497} 497}
498 498
499/** 499/**
@@ -507,35 +507,35 @@ efreet_mime_monitor_add(const char *file)
507static void 507static void
508efreet_mime_load_globs(Eina_List *datadirs, const char *datahome) 508efreet_mime_load_globs(Eina_List *datadirs, const char *datahome)
509{ 509{
510 Eina_List *l; 510 Eina_List *l;
511 char buf[4096]; 511 char buf[4096];
512 const char *datadir = NULL; 512 const char *datadir = NULL;
513 513
514 IF_FREE_HASH(wild); 514 IF_FREE_HASH(wild);
515 wild = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del)); 515 wild = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
516 while (globs) 516 while (globs)
517 { 517 {
518 efreet_mime_glob_free(eina_list_data_get(globs)); 518 efreet_mime_glob_free(eina_list_data_get(globs));
519 globs = eina_list_remove_list(globs, globs); 519 globs = eina_list_remove_list(globs, globs);
520 } 520 }
521 521
522 /* 522 /*
523 * This is here for legacy reasons. It is mentioned briefly 523 * This is here for legacy reasons. It is mentioned briefly
524 * in the spec and seems to still be quite valid. It is 524 * in the spec and seems to still be quite valid. It is
525 * loaded first so the globs files will override anything 525 * loaded first so the globs files will override anything
526 * in here. 526 * in here.
527 */ 527 */
528 efreet_mime_mime_types_load("/etc/mime.types"); 528 efreet_mime_mime_types_load("/etc/mime.types");
529 529
530 datadir = datahome; 530 datadir = datahome;
531 snprintf(buf, sizeof(buf), "%s/mime/globs", datadir); 531 snprintf(buf, sizeof(buf), "%s/mime/globs", datadir);
532 efreet_mime_shared_mimeinfo_globs_load(buf); 532 efreet_mime_shared_mimeinfo_globs_load(buf);
533 533
534 EINA_LIST_FOREACH(datadirs, l, datadir) 534 EINA_LIST_FOREACH(datadirs, l, datadir)
535 { 535 {
536 snprintf(buf, sizeof(buf), "%s/mime/globs", datadir); 536 snprintf(buf, sizeof(buf), "%s/mime/globs", datadir);
537 efreet_mime_shared_mimeinfo_globs_load(buf); 537 efreet_mime_shared_mimeinfo_globs_load(buf);
538 } 538 }
539} 539}
540 540
541/** 541/**
@@ -548,25 +548,25 @@ efreet_mime_load_globs(Eina_List *datadirs, const char *datahome)
548static void 548static void
549efreet_mime_load_magics(Eina_List *datadirs, const char *datahome) 549efreet_mime_load_magics(Eina_List *datadirs, const char *datahome)
550{ 550{
551 Eina_List *l; 551 Eina_List *l;
552 char buf[4096]; 552 char buf[4096];
553 const char *datadir = NULL; 553 const char *datadir = NULL;
554 554
555 while (magics) 555 while (magics)
556 { 556 {
557 efreet_mime_magic_free(eina_list_data_get(magics)); 557 efreet_mime_magic_free(eina_list_data_get(magics));
558 magics = eina_list_remove_list(magics, magics); 558 magics = eina_list_remove_list(magics, magics);
559 } 559 }
560 560
561 datadir = datahome; 561 datadir = datahome;
562 snprintf(buf, sizeof(buf), "%s/mime/magic", datadir); 562 snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
563 efreet_mime_shared_mimeinfo_magic_load(buf); 563 efreet_mime_shared_mimeinfo_magic_load(buf);
564 564
565 EINA_LIST_FOREACH(datadirs, l, datadir) 565 EINA_LIST_FOREACH(datadirs, l, datadir)
566 { 566 {
567 snprintf(buf, sizeof(buf), "%s/mime/magic", datadir); 567 snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
568 efreet_mime_shared_mimeinfo_magic_load(buf); 568 efreet_mime_shared_mimeinfo_magic_load(buf);
569 } 569 }
570} 570}
571 571
572/** 572/**
@@ -583,23 +583,23 @@ efreet_mime_load_magics(Eina_List *datadirs, const char *datahome)
583 */ 583 */
584static void 584static void
585efreet_mime_cb_update_file(void *data __UNUSED__, 585efreet_mime_cb_update_file(void *data __UNUSED__,
586 Ecore_File_Monitor *monitor __UNUSED__, 586 Ecore_File_Monitor *monitor __UNUSED__,
587 Ecore_File_Event event __UNUSED__, 587 Ecore_File_Event event __UNUSED__,
588 const char *path) 588 const char *path)
589{ 589{
590 Eina_List *datadirs = NULL; 590 Eina_List *datadirs = NULL;
591 const char *datahome = NULL; 591 const char *datahome = NULL;
592 592
593 if (!(datahome = efreet_data_home_get())) 593 if (!(datahome = efreet_data_home_get()))
594 return; 594 return;
595 595
596 if (!(datadirs = efreet_data_dirs_get())) 596 if (!(datadirs = efreet_data_dirs_get()))
597 return; 597 return;
598 598
599 if (strstr(path, "magic")) 599 if (strstr(path, "magic"))
600 efreet_mime_load_magics(datadirs, datahome); 600 efreet_mime_load_magics(datadirs, datahome);
601 else 601 else
602 efreet_mime_load_globs(datadirs, datahome); 602 efreet_mime_load_globs(datadirs, datahome);
603} 603}
604 604
605/** 605/**
@@ -612,48 +612,48 @@ efreet_mime_cb_update_file(void *data __UNUSED__,
612static int 612static int
613efreet_mime_init_files(void) 613efreet_mime_init_files(void)
614{ 614{
615 Eina_List *l; 615 Eina_List *l;
616 Eina_List *datadirs = NULL; 616 Eina_List *datadirs = NULL;
617 char buf[PATH_MAX]; 617 char buf[PATH_MAX];
618 const char *datahome, *datadir = NULL; 618 const char *datahome, *datadir = NULL;
619 619
620 if (!(datahome = efreet_data_home_get())) 620 if (!(datahome = efreet_data_home_get()))
621 return 0; 621 return 0;
622 622
623 if (!(datadirs = efreet_data_dirs_get())) 623 if (!(datadirs = efreet_data_dirs_get()))
624 return 0; 624 return 0;
625 625
626 /* 626 /*
627 * Add our file monitors 627 * Add our file monitors
628 * We watch the directories so we can watch for new files 628 * We watch the directories so we can watch for new files
629 */ 629 */
630 datadir = datahome; 630 datadir = datahome;
631 snprintf(buf, sizeof(buf), "%s/mime", datadir); 631 snprintf(buf, sizeof(buf), "%s/mime", datadir);
632 efreet_mime_monitor_add(buf); 632 efreet_mime_monitor_add(buf);
633 633
634 EINA_LIST_FOREACH(datadirs, l, datadir) 634 EINA_LIST_FOREACH(datadirs, l, datadir)
635 { 635 {
636 snprintf(buf, sizeof(buf), "%s/mime", datadir); 636 snprintf(buf, sizeof(buf), "%s/mime", datadir);
637 efreet_mime_monitor_add(buf); 637 efreet_mime_monitor_add(buf);
638 } 638 }
639 efreet_mime_monitor_add("/etc/mime.types"); 639 efreet_mime_monitor_add("/etc/mime.types");
640 640
641 /* Load our mime information */ 641 /* Load our mime information */
642 efreet_mime_load_globs(datadirs, datahome); 642 efreet_mime_load_globs(datadirs, datahome);
643 efreet_mime_load_magics(datadirs, datahome); 643 efreet_mime_load_magics(datadirs, datahome);
644 644
645 _mime_inode_symlink = eina_stringshare_add("inode/symlink"); 645 _mime_inode_symlink = eina_stringshare_add("inode/symlink");
646 _mime_inode_fifo = eina_stringshare_add("inode/fifo"); 646 _mime_inode_fifo = eina_stringshare_add("inode/fifo");
647 _mime_inode_chardevice = eina_stringshare_add("inode/chardevice"); 647 _mime_inode_chardevice = eina_stringshare_add("inode/chardevice");
648 _mime_inode_blockdevice = eina_stringshare_add("inode/blockdevice"); 648 _mime_inode_blockdevice = eina_stringshare_add("inode/blockdevice");
649 _mime_inode_socket = eina_stringshare_add("inode/socket"); 649 _mime_inode_socket = eina_stringshare_add("inode/socket");
650 _mime_inode_mountpoint = eina_stringshare_add("inode/mountpoint"); 650 _mime_inode_mountpoint = eina_stringshare_add("inode/mountpoint");
651 _mime_inode_directory = eina_stringshare_add("inode/directory"); 651 _mime_inode_directory = eina_stringshare_add("inode/directory");
652 _mime_application_x_executable = eina_stringshare_add("application/x-executable"); 652 _mime_application_x_executable = eina_stringshare_add("application/x-executable");
653 _mime_application_octet_stream = eina_stringshare_add("application/octet-stream"); 653 _mime_application_octet_stream = eina_stringshare_add("application/octet-stream");
654 _mime_text_plain = eina_stringshare_add("text/plain"); 654 _mime_text_plain = eina_stringshare_add("text/plain");
655 655
656 return 1; 656 return 1;
657} 657}
658 658
659/** 659/**
@@ -682,72 +682,72 @@ efreet_mime_init_files(void)
682static const char * 682static const char *
683efreet_mime_special_check(const char *file) 683efreet_mime_special_check(const char *file)
684{ 684{
685 struct stat s; 685 struct stat s;
686 int path_len = 0; 686 int path_len = 0;
687 687
688 /* no link on Windows < Vista */ 688 /* no link on Windows < Vista */
689#ifdef _WIN32 689#ifdef _WIN32
690 if (!stat(file, &s)) 690 if (!stat(file, &s))
691#else 691#else
692 if (!lstat(file, &s)) 692 if (!lstat(file, &s))
693#endif 693#endif
694 { 694 {
695 if (S_ISREG(s.st_mode)) 695 if (S_ISREG(s.st_mode))
696 return NULL; 696 return NULL;
697 697
698#ifndef _WIN32 698#ifndef _WIN32
699 if (S_ISLNK(s.st_mode)) 699 if (S_ISLNK(s.st_mode))
700 return _mime_inode_symlink; 700 return _mime_inode_symlink;
701#endif 701#endif
702 702
703 if (S_ISFIFO(s.st_mode)) 703 if (S_ISFIFO(s.st_mode))
704 return _mime_inode_fifo; 704 return _mime_inode_fifo;
705 705
706 if (S_ISCHR(s.st_mode)) 706 if (S_ISCHR(s.st_mode))
707 return _mime_inode_chardevice; 707 return _mime_inode_chardevice;
708 708
709 if (S_ISBLK(s.st_mode)) 709 if (S_ISBLK(s.st_mode))
710 return _mime_inode_blockdevice; 710 return _mime_inode_blockdevice;
711 711
712#ifndef _WIN32 712#ifndef _WIN32
713 if (S_ISSOCK(s.st_mode)) 713 if (S_ISSOCK(s.st_mode))
714 return _mime_inode_socket; 714 return _mime_inode_socket;
715#endif 715#endif
716 716
717 if (S_ISDIR(s.st_mode)) 717 if (S_ISDIR(s.st_mode))
718 { 718 {
719 struct stat s2; 719 struct stat s2;
720 char parent[PATH_MAX]; 720 char parent[PATH_MAX];
721 char path[PATH_MAX]; 721 char path[PATH_MAX];
722 722
723 strncpy(path, file, PATH_MAX); 723 strncpy(path, file, PATH_MAX);
724 724
725 path_len = strlen(file); 725 path_len = strlen(file);
726 strncpy(parent, path, PATH_MAX); 726 strncpy(parent, path, PATH_MAX);
727 727
728 /* Kill any trailing slash */ 728 /* Kill any trailing slash */
729 parent[--path_len] = '\0'; 729 parent[--path_len] = '\0';
730 730
731 /* Truncate to last slash */ 731 /* Truncate to last slash */
732 while (parent[--path_len] != '/') parent[path_len] = '\0'; 732 while (parent[--path_len] != '/') parent[path_len] = '\0';
733 733
734#ifdef _WIN32 734#ifdef _WIN32
735 if (!stat(file, &s2)) 735 if (!stat(file, &s2))
736#else 736#else
737 if (!lstat(parent, &s2)) 737 if (!lstat(parent, &s2))
738#endif 738#endif
739 { 739 {
740 if (s.st_dev != s2.st_dev) 740 if (s.st_dev != s2.st_dev)
741 return _mime_inode_mountpoint; 741 return _mime_inode_mountpoint;
742 } 742 }
743 743
744 return _mime_inode_directory; 744 return _mime_inode_directory;
745 } 745 }
746 746
747 return NULL; 747 return NULL;
748 } 748 }
749 749
750 return NULL; 750 return NULL;
751} 751}
752 752
753/** 753/**
@@ -760,35 +760,35 @@ efreet_mime_special_check(const char *file)
760static const char * 760static const char *
761efreet_mime_fallback_check(const char *file) 761efreet_mime_fallback_check(const char *file)
762{ 762{
763 FILE *f = NULL; 763 FILE *f = NULL;
764 char buf[32]; 764 char buf[32];
765 int i; 765 int i;
766 766
767 if (ecore_file_can_exec(file)) 767 if (ecore_file_can_exec(file))
768 return _mime_application_x_executable; 768 return _mime_application_x_executable;
769 769
770 if (!(f = fopen(file, "r"))) return NULL; 770 if (!(f = fopen(file, "r"))) return NULL;
771 771
772 i = fread(buf, 1, sizeof(buf), f); 772 i = fread(buf, 1, sizeof(buf), f);
773 fclose(f); 773 fclose(f);
774 774
775 if (i == 0) return _mime_application_octet_stream; 775 if (i == 0) return _mime_application_octet_stream;
776 776
777 /* 777 /*
778 * Check for ASCII control characters in the first 32 bytes. 778 * Check for ASCII control characters in the first 32 bytes.
779 * Line Feeds, carriage returns, and tabs are ignored as they are 779 * Line Feeds, carriage returns, and tabs are ignored as they are
780 * quite common in text files in the first 32 chars. 780 * quite common in text files in the first 32 chars.
781 */ 781 */
782 for (i -= 1; i >= 0; --i) 782 for (i -= 1; i >= 0; --i)
783 { 783 {
784 if ((buf[i] < 0x20) && 784 if ((buf[i] < 0x20) &&
785 (buf[i] != '\n') && /* Line Feed */ 785 (buf[i] != '\n') && /* Line Feed */
786 (buf[i] != '\r') && /* Carriage Return */ 786 (buf[i] != '\r') && /* Carriage Return */
787 (buf[i] != '\t')) /* Tab */ 787 (buf[i] != '\t')) /* Tab */
788 return _mime_application_octet_stream; 788 return _mime_application_octet_stream;
789 } 789 }
790 790
791 return _mime_text_plain; 791 return _mime_text_plain;
792} 792}
793 793
794/** 794/**
@@ -800,18 +800,18 @@ efreet_mime_fallback_check(const char *file)
800static int 800static int
801efreet_mime_glob_remove(const char *glob) 801efreet_mime_glob_remove(const char *glob)
802{ 802{
803 Efreet_Mime_Glob *mime = NULL; 803 Efreet_Mime_Glob *mime = NULL;
804 804
805 if ((mime = eina_list_search_unsorted(globs, EINA_COMPARE_CB(strcmp), glob))) 805 if ((mime = eina_list_search_unsorted(globs, EINA_COMPARE_CB(strcmp), glob)))
806 { 806 {
807 globs = eina_list_remove(globs, mime); 807 globs = eina_list_remove(globs, mime);
808 IF_RELEASE(mime->glob); 808 IF_RELEASE(mime->glob);
809 IF_RELEASE(mime->mime); 809 IF_RELEASE(mime->mime);
810 FREE(mime); 810 FREE(mime);
811 return 1; 811 return 1;
812 } 812 }
813 813
814 return 0; 814 return 0;
815} 815}
816 816
817static inline const char * 817static inline const char *
@@ -918,15 +918,15 @@ efreet_mime_mime_types_load(const char *file)
918static void 918static void
919efreet_mime_shared_mimeinfo_globs_load(const char *file) 919efreet_mime_shared_mimeinfo_globs_load(const char *file)
920{ 920{
921 FILE *f = NULL; 921 FILE *f = NULL;
922 char buf[4096], mimetype[4096], ext[4096], *p, *pp; 922 char buf[4096], mimetype[4096], ext[4096], *p, *pp;
923 Efreet_Mime_Glob *mime = NULL; 923 Efreet_Mime_Glob *mime = NULL;
924 924
925 f = fopen(file, "rb"); 925 f = fopen(file, "rb");
926 if (!f) return; 926 if (!f) return;
927 927
928 while (fgets(buf, sizeof(buf), f)) 928 while (fgets(buf, sizeof(buf), f))
929 { 929 {
930 p = buf; 930 p = buf;
931 while (isspace(*p) && (*p != 0) && (*p != '\n')) p++; 931 while (isspace(*p) && (*p != 0) && (*p != '\n')) p++;
932 932
@@ -943,43 +943,43 @@ efreet_mime_shared_mimeinfo_globs_load(const char *file)
943 pp = ext; 943 pp = ext;
944 944
945 while ((*p != 0) && (*p != '\n')) 945 while ((*p != 0) && (*p != '\n'))
946 { 946 {
947 *pp = *p; 947 *pp = *p;
948 pp++; 948 pp++;
949 p++; 949 p++;
950 } 950 }
951 951
952 *pp = 0; 952 *pp = 0;
953 953
954 if (ext[0] == '*' && ext[1] == '.') 954 if (ext[0] == '*' && ext[1] == '.')
955 { 955 {
956 eina_hash_del(wild, &(ext[2]), NULL); 956 eina_hash_del(wild, &(ext[2]), NULL);
957 eina_hash_add(wild, &(ext[2]), 957 eina_hash_add(wild, &(ext[2]),
958 (void*)eina_stringshare_add(mimetype)); 958 (void*)eina_stringshare_add(mimetype));
959 } 959 }
960 else 960 else
961 { 961 {
962 mime = NEW(Efreet_Mime_Glob, 1); 962 mime = NEW(Efreet_Mime_Glob, 1);
963 if (mime) 963 if (mime)
964 { 964 {
965 mime->mime = eina_stringshare_add(mimetype); 965 mime->mime = eina_stringshare_add(mimetype);
966 mime->glob = eina_stringshare_add(ext); 966 mime->glob = eina_stringshare_add(ext);
967 if ((!mime->mime) || (!mime->glob)) 967 if ((!mime->mime) || (!mime->glob))
968 { 968 {
969 IF_RELEASE(mime->mime); 969 IF_RELEASE(mime->mime);
970 IF_RELEASE(mime->glob); 970 IF_RELEASE(mime->glob);
971 FREE(mime); 971 FREE(mime);
972 } 972 }
973 else 973 else
974 { 974 {
975 efreet_mime_glob_remove(ext); 975 efreet_mime_glob_remove(ext);
976 globs = eina_list_append(globs, mime); 976 globs = eina_list_append(globs, mime);
977 } 977 }
978 } 978 }
979 } 979 }
980 } 980 }
981 981
982 fclose(f); 982 fclose(f);
983} 983}
984 984
985/** 985/**
@@ -992,12 +992,12 @@ efreet_mime_shared_mimeinfo_globs_load(const char *file)
992static int 992static int
993efreet_mime_count_digits(int in) 993efreet_mime_count_digits(int in)
994{ 994{
995 int i = 1, j = in; 995 int i = 1, j = in;
996 996
997 if (j < 10) return 1; 997 if (j < 10) return 1;
998 while ((j /= 10) > 0) ++i; 998 while ((j /= 10) > 0) ++i;
999 999
1000 return i; 1000 return i;
1001} 1001}
1002 1002
1003/** 1003/**
@@ -1009,31 +1009,31 @@ efreet_mime_count_digits(int in)
1009static void 1009static void
1010efreet_mime_shared_mimeinfo_magic_load(const char *file) 1010efreet_mime_shared_mimeinfo_magic_load(const char *file)
1011{ 1011{
1012 int fd = -1, size; 1012 int fd = -1, size;
1013 char *data = (void *)-1; 1013 char *data = (void *)-1;
1014 1014
1015 if (!file) return; 1015 if (!file) return;
1016 1016
1017 size = ecore_file_size(file); 1017 size = ecore_file_size(file);
1018 if (size <= 0) return; 1018 if (size <= 0) return;
1019 1019
1020 fd = open(file, O_RDONLY); 1020 fd = open(file, O_RDONLY);
1021 if (fd == -1) return; 1021 if (fd == -1) return;
1022 1022
1023 /* let's make mmap safe and just get 0 pages for IO erro */ 1023 /* let's make mmap safe and just get 0 pages for IO erro */
1024 eina_mmap_safety_enabled_set(EINA_TRUE); 1024 eina_mmap_safety_enabled_set(EINA_TRUE);
1025 1025
1026 data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); 1026 data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
1027 if (data == MAP_FAILED) 1027 if (data == MAP_FAILED)
1028 { 1028 {
1029 close(fd); 1029 close(fd);
1030 return; 1030 return;
1031 } 1031 }
1032 1032
1033 efreet_mime_shared_mimeinfo_magic_parse(data, size); 1033 efreet_mime_shared_mimeinfo_magic_parse(data, size);
1034 1034
1035 munmap(data, size); 1035 munmap(data, size);
1036 close(fd); 1036 close(fd);
1037} 1037}
1038 1038
1039/** 1039/**
@@ -1076,105 +1076,105 @@ efreet_mime_shared_mimeinfo_magic_load(const char *file)
1076static void 1076static void
1077efreet_mime_shared_mimeinfo_magic_parse(char *data, int size) 1077efreet_mime_shared_mimeinfo_magic_parse(char *data, int size)
1078{ 1078{
1079 Efreet_Mime_Magic *mime = NULL; 1079 Efreet_Mime_Magic *mime = NULL;
1080 Efreet_Mime_Magic_Entry *entry = NULL; 1080 Efreet_Mime_Magic_Entry *entry = NULL;
1081 char *ptr; 1081 char *ptr;
1082 1082
1083 ptr = data; 1083 ptr = data;
1084 1084
1085 /* make sure we're a magic file */ 1085 /* make sure we're a magic file */
1086 if (!ptr || (size < 12) || strncmp(ptr, "MIME-Magic\0\n", 12)) 1086 if (!ptr || (size < 12) || strncmp(ptr, "MIME-Magic\0\n", 12))
1087 return; 1087 return;
1088 1088
1089 ptr += 12; 1089 ptr += 12;
1090 1090
1091 for (; (ptr - data) < size; ) 1091 for (; (ptr - data) < size; )
1092 { 1092 {
1093 if (*ptr == '[') 1093 if (*ptr == '[')
1094 { 1094 {
1095 char *val, buf[512]; 1095 char *val, buf[512];
1096 1096
1097 mime = NEW(Efreet_Mime_Magic, 1); 1097 mime = NEW(Efreet_Mime_Magic, 1);
1098 magics = eina_list_append(magics, mime); 1098 magics = eina_list_append(magics, mime);
1099 1099
1100 val = ++ptr; 1100 val = ++ptr;
1101 while ((*val != ':')) val++; 1101 while ((*val != ':')) val++;
1102 memcpy(&buf, ptr, val - ptr); 1102 memcpy(&buf, ptr, val - ptr);
1103 buf[val - ptr] = '\0'; 1103 buf[val - ptr] = '\0';
1104 1104
1105 mime->priority = atoi(buf); 1105 mime->priority = atoi(buf);
1106 ptr = ++val; 1106 ptr = ++val;
1107 1107
1108 while ((*val != ']')) val++; 1108 while ((*val != ']')) val++;
1109 memcpy(&buf, ptr, val - ptr); 1109 memcpy(&buf, ptr, val - ptr);
1110 buf[val - ptr] = '\0'; 1110 buf[val - ptr] = '\0';
1111 1111
1112 mime->mime = eina_stringshare_add(buf); 1112 mime->mime = eina_stringshare_add(buf);
1113 ptr = ++val; 1113 ptr = ++val;
1114 1114
1115 while (*ptr != '\n') ptr++; 1115 while (*ptr != '\n') ptr++;
1116 ptr++; 1116 ptr++;
1117 } 1117 }
1118 else 1118 else
1119 { 1119 {
1120 short tshort; 1120 short tshort;
1121 1121
1122 if (!mime) continue; 1122 if (!mime) continue;
1123 if (!entry) 1123 if (!entry)
1124 { 1124 {
1125 if (!(entry = NEW(Efreet_Mime_Magic_Entry, 1))) 1125 if (!(entry = NEW(Efreet_Mime_Magic_Entry, 1)))
1126 { 1126 {
1127 IF_FREE_LIST(magics, efreet_mime_magic_free); 1127 IF_FREE_LIST(magics, efreet_mime_magic_free);
1128 return; 1128 return;
1129 } 1129 }
1130
1131 entry->indent = 0;
1132 entry->offset = 0;
1133 entry->value_len = 0;
1134 entry->word_size = 1;
1135 entry->range_len = 1;
1136 entry->mask = NULL;
1137 entry->value = NULL;
1138
1139 mime->entries = eina_list_append(mime->entries, entry);
1140 }
1141 1130
1142 switch(*ptr) 1131 entry->indent = 0;
1143 { 1132 entry->offset = 0;
1133 entry->value_len = 0;
1134 entry->word_size = 1;
1135 entry->range_len = 1;
1136 entry->mask = NULL;
1137 entry->value = NULL;
1138
1139 mime->entries = eina_list_append(mime->entries, entry);
1140 }
1141
1142 switch(*ptr)
1143 {
1144 case '>': 1144 case '>':
1145 ptr ++; 1145 ptr ++;
1146 entry->offset = atoi(ptr); 1146 entry->offset = atoi(ptr);
1147 ptr += efreet_mime_count_digits(entry->offset); 1147 ptr += efreet_mime_count_digits(entry->offset);
1148 break; 1148 break;
1149 1149
1150 case '=': 1150 case '=':
1151 ptr++; 1151 ptr++;
1152 1152
1153 tshort = 0; 1153 tshort = 0;
1154 memcpy(&tshort, ptr, sizeof(short)); 1154 memcpy(&tshort, ptr, sizeof(short));
1155 entry->value_len = ntohs(tshort); 1155 entry->value_len = ntohs(tshort);
1156 ptr += 2; 1156 ptr += 2;
1157 1157
1158 entry->value = NEW(1, entry->value_len); 1158 entry->value = NEW(1, entry->value_len);
1159 memcpy(entry->value, ptr, entry->value_len); 1159 memcpy(entry->value, ptr, entry->value_len);
1160 ptr += entry->value_len; 1160 ptr += entry->value_len;
1161 break; 1161 break;
1162 1162
1163 case '&': 1163 case '&':
1164 ptr++; 1164 ptr++;
1165 entry->mask = NEW(1, entry->value_len); 1165 entry->mask = NEW(1, entry->value_len);
1166 memcpy(entry->mask, ptr, entry->value_len); 1166 memcpy(entry->mask, ptr, entry->value_len);
1167 ptr += entry->value_len; 1167 ptr += entry->value_len;
1168 break; 1168 break;
1169 1169
1170 case '~': 1170 case '~':
1171 ptr++; 1171 ptr++;
1172 entry->word_size = atoi(ptr); 1172 entry->word_size = atoi(ptr);
1173 if ((entry->word_size != 0) && (((entry->word_size != 1) 1173 if ((entry->word_size != 0) && (((entry->word_size != 1)
1174 && (entry->word_size != 2) 1174 && (entry->word_size != 2)
1175 && (entry->word_size != 4)) 1175 && (entry->word_size != 4))
1176 || (entry->value_len % entry->word_size))) 1176 || (entry->value_len % entry->word_size)))
1177 { 1177 {
1178 /* Invalid, Destroy */ 1178 /* Invalid, Destroy */
1179 FREE(entry->value); 1179 FREE(entry->value);
1180 FREE(entry->mask); 1180 FREE(entry->mask);
@@ -1182,67 +1182,67 @@ efreet_mime_shared_mimeinfo_magic_parse(char *data, int size)
1182 1182
1183 while (*ptr != '\n') ptr++; 1183 while (*ptr != '\n') ptr++;
1184 break; 1184 break;
1185 } 1185 }
1186 1186
1187 if (efreet_mime_endianess == EFREET_ENDIAN_LITTLE) 1187 if (efreet_mime_endianess == EFREET_ENDIAN_LITTLE)
1188 { 1188 {
1189 int j; 1189 int j;
1190 1190
1191 for (j = 0; j < entry->value_len; j += entry->word_size) 1191 for (j = 0; j < entry->value_len; j += entry->word_size)
1192 { 1192 {
1193 if (entry->word_size == 2) 1193 if (entry->word_size == 2)
1194 { 1194 {
1195 ((short*)entry->value)[j] = 1195 ((short*)entry->value)[j] =
1196 ntohs(((short*)entry->value)[j]); 1196 ntohs(((short*)entry->value)[j]);
1197 1197
1198 if (entry->mask) 1198 if (entry->mask)
1199 ((short*)entry->mask)[j] = 1199 ((short*)entry->mask)[j] =
1200 ntohs(((short*)entry->mask)[j]); 1200 ntohs(((short*)entry->mask)[j]);
1201 } 1201 }
1202 else if (entry->word_size == 4) 1202 else if (entry->word_size == 4)
1203 { 1203 {
1204 ((int*)entry->value)[j] = 1204 ((int*)entry->value)[j] =
1205 ntohl(((int*)entry->value)[j]); 1205 ntohl(((int*)entry->value)[j]);
1206 1206
1207 if (entry->mask) 1207 if (entry->mask)
1208 ((int*)entry->mask)[j] = 1208 ((int*)entry->mask)[j] =
1209 ntohl(((int*)entry->mask)[j]); 1209 ntohl(((int*)entry->mask)[j]);
1210 } 1210 }
1211 } 1211 }
1212 } 1212 }
1213 1213
1214 ptr += efreet_mime_count_digits(entry->word_size); 1214 ptr += efreet_mime_count_digits(entry->word_size);
1215 break; 1215 break;
1216 1216
1217 case '+': 1217 case '+':
1218 ptr++; 1218 ptr++;
1219 entry->range_len = atoi(ptr); 1219 entry->range_len = atoi(ptr);
1220 ptr += efreet_mime_count_digits(entry->range_len); 1220 ptr += efreet_mime_count_digits(entry->range_len);
1221 break; 1221 break;
1222 1222
1223 case '\n': 1223 case '\n':
1224 ptr++; 1224 ptr++;
1225 entry = NULL; 1225 entry = NULL;
1226 break; 1226 break;
1227 1227
1228 default: 1228 default:
1229 if (isdigit(*ptr)) 1229 if (isdigit(*ptr))
1230 { 1230 {
1231 entry->indent = atoi(ptr); 1231 entry->indent = atoi(ptr);
1232 ptr += efreet_mime_count_digits(entry->indent); 1232 ptr += efreet_mime_count_digits(entry->indent);
1233 } 1233 }
1234 break; 1234 break;
1235 } 1235 }
1236 } 1236 }
1237 } 1237 }
1238/* 1238 /*
1239 if (entry) 1239 if (entry)
1240 { 1240 {
1241 IF_FREE(entry->value); 1241 IF_FREE(entry->value);
1242 IF_FREE(entry->mask); 1242 IF_FREE(entry->mask);
1243 FREE(entry); 1243 FREE(entry);
1244 } 1244 }
1245 */ 1245 */
1246} 1246}
1247 1247
1248/** 1248/**
@@ -1256,96 +1256,96 @@ efreet_mime_shared_mimeinfo_magic_parse(char *data, int size)
1256 */ 1256 */
1257static const char * 1257static const char *
1258efreet_mime_magic_check_priority(const char *file, 1258efreet_mime_magic_check_priority(const char *file,
1259 unsigned int start, 1259 unsigned int start,
1260 unsigned int end) 1260 unsigned int end)
1261{ 1261{
1262 Efreet_Mime_Magic *m = NULL; 1262 Efreet_Mime_Magic *m = NULL;
1263 Efreet_Mime_Magic_Entry *e = NULL; 1263 Efreet_Mime_Magic_Entry *e = NULL;
1264 Eina_List *l, *ll; 1264 Eina_List *l, *ll;
1265 FILE *f = NULL; 1265 FILE *f = NULL;
1266 unsigned int i = 0, offset = 0,level = 0, match = 0, bytes_read = 0; 1266 unsigned int i = 0, offset = 0,level = 0, match = 0, bytes_read = 0;
1267 const char *last_mime = NULL; 1267 const char *last_mime = NULL;
1268 char c, v, buf[EFREET_MIME_MAGIC_BUFFER_SIZE]; 1268 char c, v, buf[EFREET_MIME_MAGIC_BUFFER_SIZE];
1269 1269
1270 f = fopen(file, "rb"); 1270 f = fopen(file, "rb");
1271 if (!f) return NULL; 1271 if (!f) return NULL;
1272 1272
1273 if (!magics) 1273 if (!magics)
1274 { 1274 {
1275 fclose(f); 1275 fclose(f);
1276 return NULL; 1276 return NULL;
1277 } 1277 }
1278 1278
1279 if ((bytes_read = fread(buf, 1, sizeof(buf), f)) == 0) 1279 if ((bytes_read = fread(buf, 1, sizeof(buf), f)) == 0)
1280 { 1280 {
1281 fclose(f); 1281 fclose(f);
1282 return NULL; 1282 return NULL;
1283 } 1283 }
1284 1284
1285 EINA_LIST_FOREACH(magics, l, m) 1285 EINA_LIST_FOREACH(magics, l, m)
1286 { 1286 {
1287 if ((start != 0) && (m->priority > start)) 1287 if ((start != 0) && (m->priority > start))
1288 continue; 1288 continue;
1289 1289
1290 if (m->priority < end) 1290 if (m->priority < end)
1291 break; 1291 break;
1292 1292
1293 EINA_LIST_FOREACH(m->entries, ll, e) 1293 EINA_LIST_FOREACH(m->entries, ll, e)
1294 { 1294 {
1295 if ((level < e->indent) && !match) 1295 if ((level < e->indent) && !match)
1296 continue; 1296 continue;
1297 1297
1298 if ((level >= e->indent) && !match) 1298 if ((level >= e->indent) && !match)
1299 level = e->indent; 1299 level = e->indent;
1300 1300
1301 else if ((level > e->indent) && match) 1301 else if ((level > e->indent) && match)
1302 { 1302 {
1303 fclose(f); 1303 fclose(f);
1304 return last_mime; 1304 return last_mime;
1305 } 1305 }
1306 1306
1307 for (offset = e->offset; offset < e->offset + e->range_len; offset++) 1307 for (offset = e->offset; offset < e->offset + e->range_len; offset++)
1308 { 1308 {
1309 if (((offset + e->value_len) > bytes_read) && 1309 if (((offset + e->value_len) > bytes_read) &&
1310 (fseek(f, offset, SEEK_SET) == -1)) 1310 (fseek(f, offset, SEEK_SET) == -1))
1311 break; 1311 break;
1312 1312
1313 match = 1; 1313 match = 1;
1314 for (i = 0; i < e->value_len; ++i) 1314 for (i = 0; i < e->value_len; ++i)
1315 {
1316 if (offset + e->value_len > bytes_read)
1317 c = fgetc(f);
1318 else
1319 c = buf[offset + i];
1320
1321 v = e->value[i];
1322 if (e->mask) v &= e->mask[i];
1323
1324 if (!(c == v))
1325 { 1315 {
1326 match = 0; 1316 if (offset + e->value_len > bytes_read)
1327 break; 1317 c = fgetc(f);
1318 else
1319 c = buf[offset + i];
1320
1321 v = e->value[i];
1322 if (e->mask) v &= e->mask[i];
1323
1324 if (!(c == v))
1325 {
1326 match = 0;
1327 break;
1328 }
1328 } 1329 }
1329 }
1330 1330
1331 if (match) 1331 if (match)
1332 { 1332 {
1333 level += 1; 1333 level += 1;
1334 last_mime = m->mime; 1334 last_mime = m->mime;
1335 break; 1335 break;
1336 } 1336 }
1337 } 1337 }
1338 } 1338 }
1339 1339
1340 if (match) 1340 if (match)
1341 { 1341 {
1342 fclose(f); 1342 fclose(f);
1343 return last_mime; 1343 return last_mime;
1344 } 1344 }
1345 } 1345 }
1346 fclose(f); 1346 fclose(f);
1347 1347
1348 return NULL; 1348 return NULL;
1349} 1349}
1350 1350
1351/** 1351/**
@@ -1357,11 +1357,11 @@ efreet_mime_magic_check_priority(const char *file,
1357static void 1357static void
1358efreet_mime_glob_free(void *data) 1358efreet_mime_glob_free(void *data)
1359{ 1359{
1360 Efreet_Mime_Glob *m = data; 1360 Efreet_Mime_Glob *m = data;
1361 1361
1362 IF_RELEASE(m->mime); 1362 IF_RELEASE(m->mime);
1363 IF_RELEASE(m->glob); 1363 IF_RELEASE(m->glob);
1364 IF_FREE(m); 1364 IF_FREE(m);
1365} 1365}
1366 1366
1367/** 1367/**
@@ -1373,11 +1373,11 @@ efreet_mime_glob_free(void *data)
1373static void 1373static void
1374efreet_mime_magic_free(void *data) 1374efreet_mime_magic_free(void *data)
1375{ 1375{
1376 Efreet_Mime_Magic *m = data; 1376 Efreet_Mime_Magic *m = data;
1377 1377
1378 IF_RELEASE(m->mime); 1378 IF_RELEASE(m->mime);
1379 IF_FREE_LIST(m->entries, efreet_mime_magic_entry_free); 1379 IF_FREE_LIST(m->entries, efreet_mime_magic_entry_free);
1380 IF_FREE(m); 1380 IF_FREE(m);
1381} 1381}
1382 1382
1383/** 1383/**
@@ -1389,11 +1389,11 @@ efreet_mime_magic_free(void *data)
1389static void 1389static void
1390efreet_mime_magic_entry_free(void *data) 1390efreet_mime_magic_entry_free(void *data)
1391{ 1391{
1392 Efreet_Mime_Magic_Entry *e = data; 1392 Efreet_Mime_Magic_Entry *e = data;
1393 1393
1394 IF_FREE(e->mask); 1394 IF_FREE(e->mask);
1395 IF_FREE(e->value); 1395 IF_FREE(e->value);
1396 IF_FREE(e); 1396 IF_FREE(e);
1397} 1397}
1398 1398
1399 1399
@@ -1407,14 +1407,14 @@ efreet_mime_magic_entry_free(void *data)
1407static int 1407static int
1408efreet_mime_glob_match(const char *str, const char *glob) 1408efreet_mime_glob_match(const char *str, const char *glob)
1409{ 1409{
1410 if (!str || !glob) return 0; 1410 if (!str || !glob) return 0;
1411 if (glob[0] == 0) 1411 if (glob[0] == 0)
1412 { 1412 {
1413 if (str[0] == 0) return 1; 1413 if (str[0] == 0) return 1;
1414 return 0; 1414 return 0;
1415 } 1415 }
1416 if (!fnmatch(glob, str, 0)) return 1; 1416 if (!fnmatch(glob, str, 0)) return 1;
1417 return 0; 1417 return 0;
1418} 1418}
1419 1419
1420/** 1420/**
@@ -1427,71 +1427,71 @@ efreet_mime_glob_match(const char *str, const char *glob)
1427static int 1427static int
1428efreet_mime_glob_case_match(char *str, const char *glob) 1428efreet_mime_glob_case_match(char *str, const char *glob)
1429{ 1429{
1430 const char *p; 1430 const char *p;
1431 char *tglob, *tp; 1431 char *tglob, *tp;
1432 1432
1433 if (!str || !glob) return 0; 1433 if (!str || !glob) return 0;
1434 if (glob[0] == 0) 1434 if (glob[0] == 0)
1435 { 1435 {
1436 if (str[0] == 0) return 1; 1436 if (str[0] == 0) return 1;
1437 return 0; 1437 return 0;
1438 } 1438 }
1439 tglob = alloca(strlen(glob) + 1); 1439 tglob = alloca(strlen(glob) + 1);
1440 for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p); 1440 for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p);
1441 *tp = 0; 1441 *tp = 0;
1442 if (!fnmatch(str, tglob, 0)) return 1; 1442 if (!fnmatch(str, tglob, 0)) return 1;
1443 return 0; 1443 return 0;
1444} 1444}
1445 1445
1446static void 1446static void
1447efreet_mime_icons_flush(double now) 1447efreet_mime_icons_flush(double now)
1448{ 1448{
1449 Eina_Inlist *l; 1449 Eina_Inlist *l;
1450 static double old = 0; 1450 static double old = 0;
1451 int todo; 1451 int todo;
1452 1452
1453 if (now - old < EFREET_MIME_ICONS_FLUSH_TIMEOUT) 1453 if (now - old < EFREET_MIME_ICONS_FLUSH_TIMEOUT)
1454 return; 1454 return;
1455 old = now; 1455 old = now;
1456 1456
1457 todo = eina_hash_population(mime_icons) - EFREET_MIME_ICONS_MAX_POPULATION; 1457 todo = eina_hash_population(mime_icons) - EFREET_MIME_ICONS_MAX_POPULATION;
1458 if (todo <= 0) 1458 if (todo <= 0)
1459 return; 1459 return;
1460 1460
1461 l = mime_icons_lru->last; /* mime_icons_lru is not NULL, since todo > 0 */ 1461 l = mime_icons_lru->last; /* mime_icons_lru is not NULL, since todo > 0 */
1462 for (; todo > 0; todo--) 1462 for (; todo > 0; todo--)
1463 { 1463 {
1464 Efreet_Mime_Icon_Entry_Head *entry = (Efreet_Mime_Icon_Entry_Head *)l; 1464 Efreet_Mime_Icon_Entry_Head *entry = (Efreet_Mime_Icon_Entry_Head *)l;
1465 Eina_Inlist *prev = l->prev; 1465 Eina_Inlist *prev = l->prev;
1466 1466
1467 mime_icons_lru = eina_inlist_remove(mime_icons_lru, l); 1467 mime_icons_lru = eina_inlist_remove(mime_icons_lru, l);
1468 eina_hash_del_by_key(mime_icons, entry->mime); 1468 eina_hash_del_by_key(mime_icons, entry->mime);
1469 l = prev; 1469 l = prev;
1470 } 1470 }
1471 1471
1472 efreet_mime_icons_debug(); 1472 efreet_mime_icons_debug();
1473} 1473}
1474 1474
1475static void 1475static void
1476efreet_mime_icon_entry_free(Efreet_Mime_Icon_Entry *node) 1476efreet_mime_icon_entry_free(Efreet_Mime_Icon_Entry *node)
1477{ 1477{
1478 eina_stringshare_del(node->icon); 1478 eina_stringshare_del(node->icon);
1479 eina_stringshare_del(node->theme); 1479 eina_stringshare_del(node->theme);
1480 free(node); 1480 free(node);
1481} 1481}
1482 1482
1483static void 1483static void
1484efreet_mime_icon_entry_head_free(Efreet_Mime_Icon_Entry_Head *entry) 1484efreet_mime_icon_entry_head_free(Efreet_Mime_Icon_Entry_Head *entry)
1485{ 1485{
1486 while (entry->list) 1486 while (entry->list)
1487 { 1487 {
1488 Efreet_Mime_Icon_Entry *n = (Efreet_Mime_Icon_Entry *)entry->list; 1488 Efreet_Mime_Icon_Entry *n = (Efreet_Mime_Icon_Entry *)entry->list;
1489 entry->list = eina_inlist_remove(entry->list, entry->list); 1489 entry->list = eina_inlist_remove(entry->list, entry->list);
1490 efreet_mime_icon_entry_free(n); 1490 efreet_mime_icon_entry_free(n);
1491 } 1491 }
1492 1492
1493 eina_stringshare_del(entry->mime); 1493 eina_stringshare_del(entry->mime);
1494 free(entry); 1494 free(entry);
1495} 1495}
1496 1496
1497static Efreet_Mime_Icon_Entry * 1497static Efreet_Mime_Icon_Entry *
@@ -1499,17 +1499,17 @@ efreet_mime_icon_entry_new(const char *icon,
1499 const char *theme, 1499 const char *theme,
1500 unsigned int size) 1500 unsigned int size)
1501{ 1501{
1502 Efreet_Mime_Icon_Entry *entry; 1502 Efreet_Mime_Icon_Entry *entry;
1503 1503
1504 entry = malloc(sizeof(*entry)); 1504 entry = malloc(sizeof(*entry));
1505 if (!entry) 1505 if (!entry)
1506 return NULL; 1506 return NULL;
1507 1507
1508 entry->icon = icon; 1508 entry->icon = icon;
1509 entry->theme = theme; 1509 entry->theme = theme;
1510 entry->size = size; 1510 entry->size = size;
1511 1511
1512 return entry; 1512 return entry;
1513} 1513}
1514 1514
1515static void 1515static void
@@ -1518,16 +1518,16 @@ efreet_mime_icon_entry_add(const char *mime,
1518 const char *theme, 1518 const char *theme,
1519 unsigned int size) 1519 unsigned int size)
1520{ 1520{
1521 Efreet_Mime_Icon_Entry_Head *entry; 1521 Efreet_Mime_Icon_Entry_Head *entry;
1522 Efreet_Mime_Icon_Entry *n; 1522 Efreet_Mime_Icon_Entry *n;
1523 1523
1524 n = efreet_mime_icon_entry_new(icon, theme, size); 1524 n = efreet_mime_icon_entry_new(icon, theme, size);
1525 if (!n) 1525 if (!n)
1526 return; 1526 return;
1527 entry = eina_hash_find(mime_icons, mime); 1527 entry = eina_hash_find(mime_icons, mime);
1528 1528
1529 if (entry) 1529 if (entry)
1530 { 1530 {
1531 Eina_Inlist *l; 1531 Eina_Inlist *l;
1532 1532
1533 l = EINA_INLIST_GET(n); 1533 l = EINA_INLIST_GET(n);
@@ -1535,17 +1535,17 @@ efreet_mime_icon_entry_add(const char *mime,
1535 1535
1536 l = EINA_INLIST_GET(entry); 1536 l = EINA_INLIST_GET(entry);
1537 mime_icons_lru = eina_inlist_promote(mime_icons_lru, l); 1537 mime_icons_lru = eina_inlist_promote(mime_icons_lru, l);
1538 } 1538 }
1539 else 1539 else
1540 { 1540 {
1541 Eina_Inlist *l; 1541 Eina_Inlist *l;
1542 1542
1543 entry = malloc(sizeof(*entry)); 1543 entry = malloc(sizeof(*entry));
1544 if (!entry) 1544 if (!entry)
1545 { 1545 {
1546 efreet_mime_icon_entry_free(n); 1546 efreet_mime_icon_entry_free(n);
1547 return; 1547 return;
1548 } 1548 }
1549 1549
1550 l = EINA_INLIST_GET(n); 1550 l = EINA_INLIST_GET(n);
1551 entry->list = eina_inlist_prepend(NULL, l); 1551 entry->list = eina_inlist_prepend(NULL, l);
@@ -1554,10 +1554,10 @@ efreet_mime_icon_entry_add(const char *mime,
1554 1554
1555 l = EINA_INLIST_GET(entry); 1555 l = EINA_INLIST_GET(entry);
1556 mime_icons_lru = eina_inlist_prepend(mime_icons_lru, l); 1556 mime_icons_lru = eina_inlist_prepend(mime_icons_lru, l);
1557 } 1557 }
1558 1558
1559 entry->timestamp = ecore_loop_time_get(); 1559 entry->timestamp = ecore_loop_time_get();
1560 efreet_mime_icons_flush(entry->timestamp); 1560 efreet_mime_icons_flush(entry->timestamp);
1561} 1561}
1562 1562
1563static const char * 1563static const char *
@@ -1565,59 +1565,59 @@ efreet_mime_icon_entry_find(const char *mime,
1565 const char *theme, 1565 const char *theme,
1566 unsigned int size) 1566 unsigned int size)
1567{ 1567{
1568 Efreet_Mime_Icon_Entry_Head *entry; 1568 Efreet_Mime_Icon_Entry_Head *entry;
1569 Efreet_Mime_Icon_Entry *n; 1569 Efreet_Mime_Icon_Entry *n;
1570 1570
1571 entry = eina_hash_find(mime_icons, mime); 1571 entry = eina_hash_find(mime_icons, mime);
1572 if (!entry) 1572 if (!entry)
1573 return NULL; 1573 return NULL;
1574 1574
1575 EINA_INLIST_FOREACH(entry->list, n) 1575 EINA_INLIST_FOREACH(entry->list, n)
1576 { 1576 {
1577 if ((n->theme == theme) && (n->size == size)) 1577 if ((n->theme == theme) && (n->size == size))
1578 { 1578 {
1579 Eina_Inlist *l; 1579 Eina_Inlist *l;
1580 1580
1581 l = EINA_INLIST_GET(n); 1581 l = EINA_INLIST_GET(n);
1582 if (entry->list != l) 1582 if (entry->list != l)
1583 entry->list = eina_inlist_promote(entry->list, l); 1583 entry->list = eina_inlist_promote(entry->list, l);
1584 1584
1585 l = EINA_INLIST_GET(entry); 1585 l = EINA_INLIST_GET(entry);
1586 if (mime_icons_lru != l) 1586 if (mime_icons_lru != l)
1587 mime_icons_lru = eina_inlist_promote(mime_icons_lru, l); 1587 mime_icons_lru = eina_inlist_promote(mime_icons_lru, l);
1588 1588
1589 entry->timestamp = ecore_loop_time_get(); 1589 entry->timestamp = ecore_loop_time_get();
1590 return n->icon; 1590 return n->icon;
1591 } 1591 }
1592 } 1592 }
1593 1593
1594 return NULL; 1594 return NULL;
1595} 1595}
1596 1596
1597#ifdef EFREET_MIME_ICONS_DEBUG 1597#ifdef EFREET_MIME_ICONS_DEBUG
1598static void 1598static void
1599efreet_mime_icons_debug(void) 1599efreet_mime_icons_debug(void)
1600{ 1600{
1601 double now = ecore_loop_time_get(); 1601 double now = ecore_loop_time_get();
1602 Efreet_Mime_Icon_Entry_Head *entry; 1602 Efreet_Mime_Icon_Entry_Head *entry;
1603 EINA_INLIST_FOREACH(mime_icons_lru, entry) 1603 EINA_INLIST_FOREACH(mime_icons_lru, entry)
1604 { 1604 {
1605 Efreet_Mime_Icon_Entry *n; 1605 Efreet_Mime_Icon_Entry *n;
1606 1606
1607 if ((now > 0) && 1607 if ((now > 0) &&
1608 (now - entry->timestamp >= EFREET_MIME_ICONS_EXPIRE_TIMEOUT)) 1608 (now - entry->timestamp >= EFREET_MIME_ICONS_EXPIRE_TIMEOUT))
1609 { 1609 {
1610 puts("*** FOLLOWING ENTRIES ARE AGED AND CAN BE EXPIRED ***"); 1610 puts("*** FOLLOWING ENTRIES ARE AGED AND CAN BE EXPIRED ***");
1611 now = 0; 1611 now = 0;
1612 } 1612 }
1613 1613
1614 DBG("mime-icon entry: '%s' last used: %s", 1614 DBG("mime-icon entry: '%s' last used: %s",
1615 entry->mime, ctime(&entry->timestamp)); 1615 entry->mime, ctime(&entry->timestamp));
1616 1616
1617 EINA_INLIST_FOREACH(entry->list, n) 1617 EINA_INLIST_FOREACH(entry->list, n)
1618 DBG("\tsize: %3u theme: '%s' icon: '%s'", 1618 DBG("\tsize: %3u theme: '%s' icon: '%s'",
1619 n->theme, n->size, n->icon); 1619 n->theme, n->size, n->icon);
1620 } 1620 }
1621} 1621}
1622#else 1622#else
1623static void 1623static void