2009-04-20 16:20:40 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-28 22:29:05 -07:00
|
|
|
#ifdef HAVE_ALLOCA_H
|
|
|
|
# include <alloca.h>
|
|
|
|
#elif defined __GNUC__
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
#elif defined _AIX
|
|
|
|
# define alloca __alloca
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
# include <malloc.h>
|
|
|
|
# define alloca _alloca
|
|
|
|
#else
|
|
|
|
# include <stddef.h>
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
# endif
|
|
|
|
void *alloca (size_t);
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2007-07-05 20:01:21 -07:00
|
|
|
#include <sys/types.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <sys/stat.h>
|
2007-07-05 20:01:21 -07:00
|
|
|
#include <sys/time.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <unistd.h>
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
#include <time.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <fnmatch.h>
|
2010-01-04 18:15:41 -08:00
|
|
|
#include <limits.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include <winsock2.h>
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 23:16:19 -07:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
2009-04-20 16:20:40 -07:00
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
|
2010-11-26 13:32:34 -08:00
|
|
|
#include <Ecore.h>
|
2010-11-25 15:52:57 -08:00
|
|
|
#include <Ecore_File.h>
|
|
|
|
|
2010-11-22 12:49:08 -08:00
|
|
|
#include "Efreet.h"
|
|
|
|
#include "Efreet_Mime.h"
|
2009-04-20 16:20:40 -07:00
|
|
|
#include "efreet_private.h"
|
2007-06-30 22:10:14 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
static Eina_List *globs = NULL; /* contains Efreet_Mime_Glob structs */
|
|
|
|
static Eina_List *magics = NULL; /* contains Efreet_Mime_Magic structs */
|
2008-12-17 07:33:43 -08:00
|
|
|
static Eina_Hash *wild = NULL; /* contains *.ext and mime.types globs*/
|
|
|
|
static Eina_Hash *monitors = NULL; /* contains file monitors */
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
static Eina_Hash *mime_icons = NULL; /* contains cache with mime->icons */
|
2009-03-03 14:38:21 -08:00
|
|
|
static Eina_Inlist *mime_icons_lru = NULL;
|
2009-10-09 23:19:13 -07:00
|
|
|
static unsigned int _efreet_mime_init_count = 0;
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2010-05-05 13:55:14 -07:00
|
|
|
static const char *_mime_inode_symlink = NULL;
|
|
|
|
static const char *_mime_inode_fifo = NULL;
|
|
|
|
static const char *_mime_inode_chardevice = NULL;
|
|
|
|
static const char *_mime_inode_blockdevice = NULL;
|
|
|
|
static const char *_mime_inode_socket = NULL;
|
|
|
|
static const char *_mime_inode_mountpoint = NULL;
|
|
|
|
static const char *_mime_inode_directory = NULL;
|
|
|
|
static const char *_mime_application_x_executable = NULL;
|
|
|
|
static const char *_mime_application_octet_stream = NULL;
|
|
|
|
static const char *_mime_text_plain = NULL;
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
/**
|
2007-07-01 09:32:34 -07:00
|
|
|
* @internal
|
2007-06-30 22:10:14 -07:00
|
|
|
* @brief Holds whether we are big/little endian
|
|
|
|
* @note This is set during efreet_mime_init based on
|
|
|
|
* a runtime check.
|
|
|
|
*/
|
2007-09-06 09:15:10 -07:00
|
|
|
static enum
|
|
|
|
{
|
|
|
|
EFREET_ENDIAN_BIG = 0,
|
|
|
|
EFREET_ENDIAN_LITTLE = 1
|
2007-07-02 13:08:35 -07:00
|
|
|
} efreet_mime_endianess = EFREET_ENDIAN_BIG;
|
2007-06-30 22:10:14 -07:00
|
|
|
|
|
|
|
/*
|
2007-09-06 09:15:10 -07:00
|
|
|
* Buffer sized used for magic checks. The default is good enough for the
|
2007-07-01 09:32:34 -07:00
|
|
|
* current set of magic rules. This setting is only here for the future.
|
|
|
|
*/
|
2007-06-30 22:10:14 -07:00
|
|
|
#define EFREET_MIME_MAGIC_BUFFER_SIZE 512
|
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
/*
|
|
|
|
* Minimum timeout in seconds between mime-icons cache flush.
|
|
|
|
*/
|
|
|
|
#define EFREET_MIME_ICONS_FLUSH_TIMEOUT 60
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timeout in seconds, when older mime-icons items are expired.
|
|
|
|
*/
|
|
|
|
#define EFREET_MIME_ICONS_EXPIRE_TIMEOUT 600
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mime-icons maximum population.
|
|
|
|
*/
|
|
|
|
#define EFREET_MIME_ICONS_MAX_POPULATION 512
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If defined, dump mime-icons statistics after flush.
|
|
|
|
*/
|
|
|
|
//#define EFREET_MIME_ICONS_DEBUG
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
/**
|
|
|
|
* Efreet_Mime_Glob
|
|
|
|
* @brief A parsed representation of a globs file
|
|
|
|
*/
|
2007-07-01 09:32:34 -07:00
|
|
|
typedef struct Efreet_Mime_Glob Efreet_Mime_Glob;
|
|
|
|
struct Efreet_Mime_Glob
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
const char *glob;
|
|
|
|
const char *mime;
|
2007-07-01 09:32:34 -07:00
|
|
|
};
|
2007-06-30 22:10:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Efreet_Mime_Magic
|
|
|
|
* @brief A parsed representation of a magic file section
|
|
|
|
*/
|
2007-07-01 09:32:34 -07:00
|
|
|
typedef struct Efreet_Mime_Magic Efreet_Mime_Magic;
|
|
|
|
struct Efreet_Mime_Magic
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
unsigned int priority;
|
|
|
|
const char *mime;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *entries;
|
2007-07-01 09:32:34 -07:00
|
|
|
};
|
2007-06-30 22:10:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Efreet_Mime_Magic_Entry
|
|
|
|
* @brief A parsed representation of a magic file entry
|
|
|
|
*/
|
2007-07-01 09:32:34 -07:00
|
|
|
typedef struct Efreet_Mime_Magic_Entry Efreet_Mime_Magic_Entry;
|
|
|
|
struct Efreet_Mime_Magic_Entry
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
unsigned int indent;
|
|
|
|
unsigned int offset;
|
|
|
|
unsigned int word_size;
|
|
|
|
unsigned int range_len;
|
|
|
|
unsigned short value_len;
|
|
|
|
char *mask;
|
|
|
|
char *value;
|
2007-07-01 09:32:34 -07:00
|
|
|
};
|
2007-06-30 22:10:14 -07:00
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
typedef struct Efreet_Mime_Icon_Entry_Head Efreet_Mime_Icon_Entry_Head;
|
|
|
|
struct Efreet_Mime_Icon_Entry_Head
|
|
|
|
{
|
2009-03-03 14:38:21 -08:00
|
|
|
EINA_INLIST; /* node of mime_icons_lru */
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
Eina_Inlist *list;
|
|
|
|
const char *mime;
|
2010-09-28 10:53:15 -07:00
|
|
|
double timestamp;
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct Efreet_Mime_Icon_Entry Efreet_Mime_Icon_Entry;
|
|
|
|
struct Efreet_Mime_Icon_Entry
|
|
|
|
{
|
|
|
|
EINA_INLIST;
|
|
|
|
const char *icon;
|
|
|
|
const char *theme;
|
|
|
|
unsigned int size;
|
|
|
|
};
|
|
|
|
|
2009-09-21 09:36:29 -07:00
|
|
|
/* define macros and variable for using the eina logging system */
|
|
|
|
|
2010-08-29 01:47:27 -07:00
|
|
|
#ifdef EFREET_MODULE_LOG_DOM
|
2009-09-21 09:36:29 -07:00
|
|
|
#undef EFREET_MODULE_LOG_DOM
|
|
|
|
#endif
|
|
|
|
#define EFREET_MODULE_LOG_DOM _efreet_mime_log_dom
|
|
|
|
static int _efreet_mime_log_dom = -1;
|
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
static int efreet_mime_glob_remove(const char *glob);
|
|
|
|
static void efreet_mime_mime_types_load(const char *file);
|
|
|
|
static void efreet_mime_shared_mimeinfo_globs_load(const char *file);
|
|
|
|
static void efreet_mime_shared_mimeinfo_magic_load(const char *file);
|
|
|
|
static void efreet_mime_shared_mimeinfo_magic_parse(char *data, int size);
|
2007-09-06 09:15:10 -07:00
|
|
|
static const char *efreet_mime_magic_check_priority(const char *file,
|
|
|
|
unsigned int start,
|
2007-06-30 22:10:14 -07:00
|
|
|
unsigned int end);
|
2007-07-03 09:10:30 -07:00
|
|
|
static int efreet_mime_init_files(void);
|
2007-07-03 11:01:56 -07:00
|
|
|
static const char *efreet_mime_special_check(const char *file);
|
|
|
|
static const char *efreet_mime_fallback_check(const char *file);
|
2007-07-03 09:10:30 -07:00
|
|
|
static void efreet_mime_glob_free(void *data);
|
|
|
|
static void efreet_mime_magic_free(void *data);
|
|
|
|
static void efreet_mime_magic_entry_free(void *data);
|
|
|
|
static int efreet_mime_glob_match(const char *str, const char *glob);
|
|
|
|
static int efreet_mime_glob_case_match(char *str, const char *glob);
|
|
|
|
static int efreet_mime_endian_check(void);
|
|
|
|
|
|
|
|
static void efreet_mime_monitor_add(const char *file);
|
2007-09-06 09:15:10 -07:00
|
|
|
static void efreet_mime_cb_update_file(void *data,
|
2007-07-02 15:01:44 -07:00
|
|
|
Ecore_File_Monitor *monitor,
|
2007-09-06 09:15:10 -07:00
|
|
|
Ecore_File_Event event,
|
2007-07-02 15:01:44 -07:00
|
|
|
const char *path);
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2010-09-28 10:53:15 -07:00
|
|
|
static void efreet_mime_icons_flush(double now);
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
static void efreet_mime_icon_entry_head_free(Efreet_Mime_Icon_Entry_Head *entry);
|
|
|
|
static void efreet_mime_icon_entry_add(const char *mime,
|
|
|
|
const char *icon,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size);
|
|
|
|
static const char *efreet_mime_icon_entry_find(const char *mime,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size);
|
|
|
|
static void efreet_mime_icons_debug(void);
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
/**
|
|
|
|
* @return Returns 1 on success or 0 on failure
|
|
|
|
* @brief Initializes the efreet mime settings
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI int
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_mime_init(void)
|
2007-09-06 09:15:10 -07:00
|
|
|
{
|
2009-10-09 23:19:13 -07:00
|
|
|
if (++_efreet_mime_init_count != 1)
|
|
|
|
return _efreet_mime_init_count;
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!ecore_init())
|
2009-10-09 23:19:13 -07:00
|
|
|
return --_efreet_mime_init_count;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!ecore_file_init())
|
2009-10-09 23:19:13 -07:00
|
|
|
goto shutdown_ecore;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!efreet_init())
|
2009-10-09 23:19:13 -07:00
|
|
|
goto shutdown_ecore_file;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-10-07 15:22:33 -07:00
|
|
|
_efreet_mime_log_dom = eina_log_domain_register
|
|
|
|
("efreet_mime", EFREET_DEFAULT_LOG_COLOR);
|
2009-09-21 09:36:29 -07:00
|
|
|
|
2010-08-29 01:47:27 -07:00
|
|
|
if (_efreet_mime_log_dom < 0)
|
2009-10-09 23:19:13 -07:00
|
|
|
{
|
2010-10-07 15:22:33 -07:00
|
|
|
ERROR("Efreet: Could not create a log domain for efreet_mime.");
|
2010-02-04 01:12:35 -08:00
|
|
|
goto shutdown_efreet;
|
2009-10-09 23:19:13 -07:00
|
|
|
}
|
2009-09-21 09:36:29 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_mime_endianess = efreet_mime_endian_check();
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2008-12-17 07:33:43 -08:00
|
|
|
monitors = eina_hash_string_superfast_new(EINA_FREE_CB(ecore_file_monitor_del));
|
2007-09-06 09:15:10 -07:00
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
efreet_mime_type_cache_clear();
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!efreet_mime_init_files())
|
2009-10-09 23:19:13 -07:00
|
|
|
goto unregister_log_domain;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2009-10-09 23:19:13 -07:00
|
|
|
return _efreet_mime_init_count;
|
|
|
|
|
2010-02-04 01:12:35 -08:00
|
|
|
unregister_log_domain:
|
2009-10-09 23:19:13 -07:00
|
|
|
eina_log_domain_unregister(_efreet_mime_log_dom);
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_efreet:
|
2009-10-09 23:19:13 -07:00
|
|
|
efreet_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_ecore_file:
|
2009-10-09 23:19:13 -07:00
|
|
|
ecore_file_shutdown();
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_ecore:
|
2009-10-09 23:19:13 -07:00
|
|
|
ecore_shutdown();
|
|
|
|
|
|
|
|
return --_efreet_mime_init_count;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Cleans up the efreet mime settings system
|
|
|
|
*/
|
2009-10-09 23:19:13 -07:00
|
|
|
EAPI int
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_mime_shutdown(void)
|
|
|
|
{
|
2009-10-09 23:19:13 -07:00
|
|
|
if (--_efreet_mime_init_count != 0)
|
|
|
|
return _efreet_mime_init_count;
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
|
|
|
efreet_mime_icons_debug();
|
|
|
|
|
2010-05-05 13:55:14 -07:00
|
|
|
IF_RELEASE(_mime_inode_symlink);
|
|
|
|
IF_RELEASE(_mime_inode_fifo);
|
|
|
|
IF_RELEASE(_mime_inode_chardevice);
|
|
|
|
IF_RELEASE(_mime_inode_blockdevice);
|
|
|
|
IF_RELEASE(_mime_inode_socket);
|
|
|
|
IF_RELEASE(_mime_inode_mountpoint);
|
|
|
|
IF_RELEASE(_mime_inode_directory);
|
|
|
|
IF_RELEASE(_mime_application_x_executable);
|
|
|
|
IF_RELEASE(_mime_application_octet_stream);
|
|
|
|
IF_RELEASE(_mime_text_plain);
|
|
|
|
|
2009-03-23 05:19:31 -07:00
|
|
|
IF_FREE_LIST(globs, efreet_mime_glob_free);
|
|
|
|
IF_FREE_LIST(magics, efreet_mime_magic_free);
|
2007-07-02 15:01:44 -07:00
|
|
|
IF_FREE_HASH(monitors);
|
2007-07-26 04:30:10 -07:00
|
|
|
IF_FREE_HASH(wild);
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
IF_FREE_HASH(mime_icons);
|
2009-09-21 09:36:29 -07:00
|
|
|
eina_log_domain_unregister(_efreet_mime_log_dom);
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_shutdown();
|
|
|
|
ecore_file_shutdown();
|
|
|
|
ecore_shutdown();
|
2009-10-09 23:19:13 -07:00
|
|
|
|
|
|
|
return _efreet_mime_init_count;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-07-17 12:21:20 -07:00
|
|
|
* @param file: The file to find the mime type
|
2007-06-30 22:10:14 -07:00
|
|
|
* @return Returns mime type as a string
|
|
|
|
* @brief Retreive the mime type of a file
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-07-02 21:47:29 -07:00
|
|
|
efreet_mime_type_get(const char *file)
|
2007-09-06 09:15:10 -07:00
|
|
|
{
|
2007-07-01 09:32:34 -07:00
|
|
|
const char *type = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-08-09 12:31:18 -07:00
|
|
|
if (!file)
|
|
|
|
return NULL;
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if ((type = efreet_mime_special_check(file)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2008-08-02 15:09:04 -07:00
|
|
|
/* Check magics with priority > 80 */
|
2007-07-02 21:47:29 -07:00
|
|
|
if ((type = efreet_mime_magic_check_priority(file, 0, 80)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2008-08-02 15:09:04 -07:00
|
|
|
/* Check globs */
|
2007-07-05 20:01:21 -07:00
|
|
|
if ((type = efreet_mime_globs_type_get(file)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2008-08-02 15:09:04 -07:00
|
|
|
/* Check rest of magics */
|
2007-07-05 20:01:21 -07:00
|
|
|
if ((type = efreet_mime_magic_check_priority(file, 80, 0)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-05 20:01:21 -07:00
|
|
|
return efreet_mime_fallback_check(file);
|
|
|
|
}
|
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
/**
|
2008-08-02 14:48:44 -07:00
|
|
|
* @param mime: The name of the mime type
|
|
|
|
* @param theme: The name of the theme to search icons in
|
|
|
|
* @param size: The wanted size of the icon
|
2007-07-17 12:21:20 -07:00
|
|
|
* @return Returns mime type icon path as a string
|
|
|
|
* @brief Retreive the mime type icon for a file
|
|
|
|
*/
|
2010-11-09 12:15:55 -08:00
|
|
|
EAPI const char *
|
2008-08-14 13:48:41 -07:00
|
|
|
efreet_mime_type_icon_get(const char *mime, const char *theme, unsigned int size)
|
2007-07-17 12:21:20 -07:00
|
|
|
{
|
2010-11-09 12:15:55 -08:00
|
|
|
const char *icon = NULL;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
char *data;
|
|
|
|
Eina_List *icons = NULL;
|
2007-07-17 12:21:20 -07:00
|
|
|
const char *env = NULL;
|
|
|
|
char *p = NULL, *pp = NULL, *ppp = NULL;
|
|
|
|
char buf[PATH_MAX];
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
const char *cache;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
if (!mime || !theme || !size)
|
|
|
|
return NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
mime = eina_stringshare_add(mime);
|
|
|
|
theme = eina_stringshare_add(theme);
|
|
|
|
cache = efreet_mime_icon_entry_find(mime, theme, size);
|
|
|
|
if (cache)
|
|
|
|
{
|
|
|
|
eina_stringshare_del(mime);
|
|
|
|
eina_stringshare_del(theme);
|
|
|
|
return strdup(cache);
|
|
|
|
}
|
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
/* Standard icon name */
|
|
|
|
p = strdup(mime);
|
|
|
|
pp = p;
|
|
|
|
while (*pp)
|
|
|
|
{
|
2008-08-02 15:09:04 -07:00
|
|
|
if (*pp == '/') *pp = '-';
|
2007-07-17 12:21:20 -07:00
|
|
|
pp++;
|
|
|
|
}
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
icons = eina_list_append(icons, p);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
/* Environment Based icon names */
|
|
|
|
if ((env = efreet_desktop_environment_get()))
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s-mime-%s", env, p);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
icons = eina_list_append(icons, strdup(buf));
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s-%s", env, p);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
icons = eina_list_append(icons, strdup(buf));
|
2007-07-17 12:21:20 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
/* Mime prefixed icon names */
|
|
|
|
snprintf(buf, sizeof(buf), "mime-%s", p);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
icons = eina_list_append(icons, strdup(buf));
|
2007-07-17 12:21:20 -07:00
|
|
|
|
|
|
|
/* Generic icons */
|
|
|
|
pp = strdup(p);
|
|
|
|
while ((ppp = strrchr(pp, '-')))
|
|
|
|
{
|
|
|
|
*ppp = '\0';
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2009-08-20 20:03:59 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s-x-generic", pp);
|
|
|
|
icons = eina_list_append(icons, strdup(buf));
|
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s-generic", pp);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
icons = eina_list_append(icons, strdup(buf));
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s", pp);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
icons = eina_list_append(icons, strdup(buf));
|
2007-07-17 12:21:20 -07:00
|
|
|
}
|
|
|
|
FREE(pp);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-17 12:21:20 -07:00
|
|
|
/* Search for icons using list */
|
|
|
|
icon = efreet_icon_list_find(theme, icons, size);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
while (icons)
|
|
|
|
{
|
|
|
|
data = eina_list_data_get(icons);
|
|
|
|
free(data);
|
|
|
|
icons = eina_list_remove_list(icons, icons);
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
efreet_mime_icon_entry_add(mime, eina_stringshare_add(icon), theme, size);
|
|
|
|
|
2007-07-26 04:30:10 -07:00
|
|
|
return icon;
|
2007-07-17 12:21:20 -07:00
|
|
|
}
|
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
EAPI void
|
|
|
|
efreet_mime_type_cache_clear(void)
|
|
|
|
{
|
|
|
|
if (mime_icons)
|
2009-03-03 14:38:21 -08:00
|
|
|
{
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
eina_hash_free(mime_icons);
|
2009-03-03 14:38:21 -08:00
|
|
|
mime_icons_lru = NULL;
|
|
|
|
}
|
2009-06-19 08:00:38 -07:00
|
|
|
mime_icons = eina_hash_stringshared_new(EINA_FREE_CB(efreet_mime_icon_entry_head_free));
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
efreet_mime_type_cache_flush(void)
|
|
|
|
{
|
2010-09-28 10:53:15 -07:00
|
|
|
efreet_mime_icons_flush(ecore_loop_time_get());
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-05 20:01:21 -07:00
|
|
|
/**
|
|
|
|
* @param file: The file to check the mime type
|
|
|
|
* @return Returns mime type as a string
|
|
|
|
* @brief Retreive the mime type of a file using magic
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-08-12 22:33:26 -07:00
|
|
|
efreet_mime_magic_type_get(const char *file)
|
2007-07-05 20:01:21 -07:00
|
|
|
{
|
2007-09-06 09:15:10 -07:00
|
|
|
return efreet_mime_magic_check_priority(file, 0, 0);
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param file: The file to check the mime type
|
|
|
|
* @return Returns mime type as a string
|
|
|
|
* @brief Retreive the mime type of a file using globs
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-08-12 22:33:26 -07:00
|
|
|
efreet_mime_globs_type_get(const char *file)
|
2007-07-05 20:01:21 -07:00
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *l;
|
2007-08-12 12:28:02 -07:00
|
|
|
Efreet_Mime_Glob *g;
|
2007-08-12 22:36:03 -07:00
|
|
|
char *sl, *p;
|
|
|
|
const char *s;
|
|
|
|
char *ext, *mime;
|
2007-08-12 12:28:02 -07:00
|
|
|
|
2008-08-02 15:09:04 -07:00
|
|
|
/* Check in the extension hash for the type */
|
2010-08-09 12:31:18 -07:00
|
|
|
if (!file) return NULL;
|
|
|
|
|
2007-08-12 12:28:02 -07:00
|
|
|
ext = strchr(file, '.');
|
|
|
|
if (ext)
|
|
|
|
{
|
|
|
|
sl = alloca(strlen(ext) + 1);
|
|
|
|
for (s = ext, p = sl; *s; s++, p++) *p = tolower(*s);
|
|
|
|
*p = 0;
|
|
|
|
p = sl;
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
p++;
|
2008-12-17 07:33:43 -08:00
|
|
|
if (p && (mime = eina_hash_find(wild, p))) return mime;
|
2007-08-12 12:28:02 -07:00
|
|
|
p = strchr(p, '.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-02 15:09:04 -07:00
|
|
|
/* Fallback to the other globs if not found */
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(globs, l, g)
|
2007-08-12 12:28:02 -07:00
|
|
|
{
|
2007-07-02 21:47:29 -07:00
|
|
|
if (efreet_mime_glob_match(file, g->glob))
|
2007-08-12 12:28:02 -07:00
|
|
|
return g->mime;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext = alloca(strlen(file) + 1);
|
|
|
|
for (s = file, p = ext; *s; s++, p++) *p = tolower(*s);
|
|
|
|
*p = 0;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(globs, l, g)
|
2007-08-12 12:28:02 -07:00
|
|
|
{
|
2007-08-12 03:00:02 -07:00
|
|
|
if (efreet_mime_glob_case_match(ext, g->glob))
|
2007-08-12 12:28:02 -07:00
|
|
|
return g->mime;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
return NULL;
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param file: The file to check the mime type
|
|
|
|
* @return Returns mime type as a string
|
|
|
|
* @brief Retreive the special mime type of a file
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-08-12 22:33:26 -07:00
|
|
|
efreet_mime_special_type_get(const char *file)
|
2007-07-05 20:01:21 -07:00
|
|
|
{
|
|
|
|
return efreet_mime_special_check(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param file: The file to check the mime type
|
|
|
|
* @return Returns mime type as a string
|
|
|
|
* @brief Retreive the fallback mime type of a file
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-08-12 22:33:26 -07:00
|
|
|
efreet_mime_fallback_type_get(const char *file)
|
2007-07-05 20:01:21 -07:00
|
|
|
{
|
2007-07-03 10:55:20 -07:00
|
|
|
return efreet_mime_fallback_check(file);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns the endianess
|
|
|
|
* @brief Retreive the endianess of the machine
|
|
|
|
*/
|
2007-07-01 09:32:34 -07:00
|
|
|
static int
|
|
|
|
efreet_mime_endian_check(void)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
int test = 1;
|
|
|
|
return (*((char*)(&test)));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param file: File to monitor
|
2007-07-02 15:01:44 -07:00
|
|
|
* @return Returns no value.
|
|
|
|
* @brief Creates a new file monitor if we aren't already monitoring the
|
|
|
|
* given file
|
2007-06-30 22:10:14 -07:00
|
|
|
*/
|
2007-07-02 15:01:44 -07:00
|
|
|
static void
|
2007-09-06 09:15:10 -07:00
|
|
|
efreet_mime_monitor_add(const char *file)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
Ecore_File_Monitor *fm = NULL;
|
|
|
|
|
2007-07-02 15:01:44 -07:00
|
|
|
/* if this is already in our hash then we're already monitoring so no
|
|
|
|
* reason to re-monitor */
|
2008-12-17 07:33:43 -08:00
|
|
|
if (eina_hash_find(monitors, file))
|
2007-07-02 15:01:44 -07:00
|
|
|
return;
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2007-07-02 15:01:44 -07:00
|
|
|
if ((fm = ecore_file_monitor_add(file, efreet_mime_cb_update_file, NULL)))
|
2009-08-28 22:29:05 -07:00
|
|
|
{
|
|
|
|
eina_hash_del(monitors, file, NULL);
|
|
|
|
eina_hash_add(monitors, file, fm);
|
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param datadirs: List of XDG data dirs
|
|
|
|
* @param datahome: Path to XDG data home directory
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Read all glob files in XDG data/home dirs.
|
|
|
|
* Also reads the /etc/mime.types file.
|
|
|
|
*/
|
|
|
|
static void
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
efreet_mime_load_globs(Eina_List *datadirs, const char *datahome)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *l;
|
2007-06-30 22:10:14 -07:00
|
|
|
char buf[4096];
|
|
|
|
const char *datadir = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-05 20:01:21 -07:00
|
|
|
IF_FREE_HASH(wild);
|
2008-12-17 07:33:43 -08:00
|
|
|
wild = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
while (globs)
|
|
|
|
{
|
|
|
|
efreet_mime_glob_free(eina_list_data_get(globs));
|
|
|
|
globs = eina_list_remove_list(globs, globs);
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-05 20:01:21 -07:00
|
|
|
/*
|
|
|
|
* This is here for legacy reasons. It is mentioned briefly
|
|
|
|
* in the spec and seems to still be quite valid. It is
|
|
|
|
* loaded first so the globs files will override anything
|
|
|
|
* in here.
|
|
|
|
*/
|
|
|
|
efreet_mime_mime_types_load("/etc/mime.types");
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-02 13:16:23 -07:00
|
|
|
datadir = datahome;
|
2009-08-28 22:29:05 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/mime/globs", datadir);
|
|
|
|
efreet_mime_shared_mimeinfo_globs_load(buf);
|
2007-07-02 13:08:35 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(datadirs, l, datadir)
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/mime/globs", datadir);
|
|
|
|
efreet_mime_shared_mimeinfo_globs_load(buf);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param datadirs: List of XDG data dirs
|
|
|
|
* @param datahome: Path to XDG data home directory
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Read all magic files in XDG data/home dirs.
|
|
|
|
*/
|
2007-09-06 09:15:10 -07:00
|
|
|
static void
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
efreet_mime_load_magics(Eina_List *datadirs, const char *datahome)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *l;
|
2007-06-30 22:10:14 -07:00
|
|
|
char buf[4096];
|
|
|
|
const char *datadir = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
while (magics)
|
|
|
|
{
|
|
|
|
efreet_mime_magic_free(eina_list_data_get(magics));
|
|
|
|
magics = eina_list_remove_list(magics, magics);
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-02 13:08:35 -07:00
|
|
|
datadir = datahome;
|
2009-08-28 22:29:05 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
|
|
|
|
efreet_mime_shared_mimeinfo_magic_load(buf);
|
2007-06-30 22:10:14 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(datadirs, l, datadir)
|
|
|
|
{
|
|
|
|
snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
|
|
|
|
efreet_mime_shared_mimeinfo_magic_load(buf);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param data: Data pointer passed to monitor_add
|
|
|
|
* @param monitor: Ecore_File_Monitor associated with this event
|
|
|
|
* @param event: The type of event
|
|
|
|
* @param path: Path to the file that was updated
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Callback for all file monitors. Just reloads the appropriate
|
|
|
|
* list depending on which file changed. If it was a magic file
|
|
|
|
* only the magic list is updated. If it was a glob file or /etc/mime.types,
|
|
|
|
* the globs are updated.
|
|
|
|
*/
|
|
|
|
static void
|
2007-09-06 09:15:10 -07:00
|
|
|
efreet_mime_cb_update_file(void *data __UNUSED__,
|
2007-06-30 22:10:14 -07:00
|
|
|
Ecore_File_Monitor *monitor __UNUSED__,
|
2007-09-06 09:15:10 -07:00
|
|
|
Ecore_File_Event event __UNUSED__,
|
2007-06-30 22:10:14 -07:00
|
|
|
const char *path)
|
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *datadirs = NULL;
|
2007-06-30 22:10:14 -07:00
|
|
|
const char *datahome = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!(datahome = efreet_data_home_get()))
|
|
|
|
return;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!(datadirs = efreet_data_dirs_get()))
|
|
|
|
return;
|
|
|
|
|
2007-07-01 09:32:34 -07:00
|
|
|
if (strstr(path, "magic"))
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_mime_load_magics(datadirs, datahome);
|
2007-09-06 09:15:10 -07:00
|
|
|
else
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_mime_load_globs(datadirs, datahome);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param datadirs: List of XDG data dirs
|
|
|
|
* @param datahome: Path to XDG data home directory
|
|
|
|
* @return Returns 1 on success, 0 on failure
|
|
|
|
* @brief Initializes globs, magics, and monitors lists.
|
|
|
|
*/
|
|
|
|
static int
|
2007-07-01 09:32:34 -07:00
|
|
|
efreet_mime_init_files(void)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *l;
|
|
|
|
Eina_List *datadirs = NULL;
|
2007-06-30 22:10:14 -07:00
|
|
|
char buf[PATH_MAX];
|
2007-07-02 13:08:35 -07:00
|
|
|
const char *datahome, *datadir = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!(datahome = efreet_data_home_get()))
|
|
|
|
return 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!(datadirs = efreet_data_dirs_get()))
|
|
|
|
return 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Add our file monitors
|
2007-07-02 15:01:44 -07:00
|
|
|
* We watch the directories so we can watch for new files
|
2007-09-06 09:15:10 -07:00
|
|
|
*/
|
2007-07-02 13:08:35 -07:00
|
|
|
datadir = datahome;
|
2009-12-23 12:55:23 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%s/mime", datadir);
|
2009-08-28 22:29:05 -07:00
|
|
|
efreet_mime_monitor_add(buf);
|
2007-07-02 13:08:35 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(datadirs, l, datadir)
|
|
|
|
{
|
2009-12-23 12:55:23 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%s/mime", datadir);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
efreet_mime_monitor_add(buf);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
efreet_mime_monitor_add("/etc/mime.types");
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-02 13:08:35 -07:00
|
|
|
/* Load our mime information */
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_mime_load_globs(datadirs, datahome);
|
|
|
|
efreet_mime_load_magics(datadirs, datahome);
|
2007-07-02 13:08:35 -07:00
|
|
|
|
2010-05-05 13:55:14 -07:00
|
|
|
_mime_inode_symlink = eina_stringshare_add("inode/symlink");
|
|
|
|
_mime_inode_fifo = eina_stringshare_add("inode/fifo");
|
|
|
|
_mime_inode_chardevice = eina_stringshare_add("inode/chardevice");
|
|
|
|
_mime_inode_blockdevice = eina_stringshare_add("inode/blockdevice");
|
|
|
|
_mime_inode_socket = eina_stringshare_add("inode/socket");
|
|
|
|
_mime_inode_mountpoint = eina_stringshare_add("inode/mountpoint");
|
|
|
|
_mime_inode_directory = eina_stringshare_add("inode/directory");
|
|
|
|
_mime_application_x_executable = eina_stringshare_add("application/x-executable");
|
|
|
|
_mime_application_octet_stream = eina_stringshare_add("application/octet-stream");
|
|
|
|
_mime_text_plain = eina_stringshare_add("text/plain");
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2007-07-03 10:55:20 -07:00
|
|
|
* @param file: File to examine
|
2007-06-30 22:10:14 -07:00
|
|
|
* @return Returns mime type if special file, else NULL
|
|
|
|
* @brief Returns a mime type based on the stat of a file.
|
|
|
|
* This is used first to catch directories and other special
|
|
|
|
* files. A NULL return doesn't necessarily mean failure, but
|
|
|
|
* can also mean the file is regular.
|
|
|
|
* @note Mapping of file types to mime types:
|
|
|
|
* Stat Macro File Type Mime Type
|
2007-07-01 09:32:34 -07:00
|
|
|
* S_IFREG regular NULL
|
|
|
|
* S_IFIFO named pipe (fifo) inode/fifo
|
|
|
|
* S_IFCHR character special inode/chardevice
|
|
|
|
* S_IFDIR directory inode/directory
|
|
|
|
* S_IFBLK block special inode/blockdevice
|
|
|
|
* S_IFLNK symbolic link inode/symlink
|
|
|
|
* S_IFSOCK socket inode/socket
|
2007-06-30 22:10:14 -07:00
|
|
|
*
|
|
|
|
* This function can also return inode/mount-point.
|
|
|
|
* This is calculated by comparing the st_dev of the directory
|
|
|
|
* against that of it's parent directory. If they differ it
|
|
|
|
* is considered a mount point.
|
|
|
|
*/
|
2007-07-01 09:32:34 -07:00
|
|
|
static const char *
|
2007-06-30 22:10:14 -07:00
|
|
|
efreet_mime_special_check(const char *file)
|
2007-09-06 09:15:10 -07:00
|
|
|
{
|
2007-06-30 22:10:14 -07:00
|
|
|
struct stat s;
|
|
|
|
int path_len = 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-11-26 09:05:16 -08:00
|
|
|
/* no link on Windows < Vista */
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (!stat(file, &s))
|
|
|
|
#else
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!lstat(file, &s))
|
2010-11-26 09:05:16 -08:00
|
|
|
#endif
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
if (S_ISREG(s.st_mode))
|
|
|
|
return NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2009-04-20 16:20:40 -07:00
|
|
|
#ifndef _WIN32
|
2007-06-30 22:10:14 -07:00
|
|
|
if (S_ISLNK(s.st_mode))
|
2010-06-24 18:44:30 -07:00
|
|
|
return _mime_inode_symlink;
|
2009-04-20 16:20:40 -07:00
|
|
|
#endif
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (S_ISFIFO(s.st_mode))
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_inode_fifo;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (S_ISCHR(s.st_mode))
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_inode_chardevice;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (S_ISBLK(s.st_mode))
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_inode_blockdevice;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2009-04-20 16:20:40 -07:00
|
|
|
#ifndef _WIN32
|
2007-06-30 22:10:14 -07:00
|
|
|
if (S_ISSOCK(s.st_mode))
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_inode_socket;
|
2009-04-20 16:20:40 -07:00
|
|
|
#endif
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (S_ISDIR(s.st_mode))
|
|
|
|
{
|
2007-09-06 09:15:10 -07:00
|
|
|
struct stat s2;
|
2007-06-30 22:10:14 -07:00
|
|
|
char parent[PATH_MAX];
|
|
|
|
char path[PATH_MAX];
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
strncpy(path, file, PATH_MAX);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
path_len = strlen(file);
|
|
|
|
strncpy(parent, path, PATH_MAX);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-01 09:32:34 -07:00
|
|
|
/* Kill any trailing slash */
|
2007-09-06 09:15:10 -07:00
|
|
|
parent[--path_len] = '\0';
|
|
|
|
|
2007-07-01 09:32:34 -07:00
|
|
|
/* Truncate to last slash */
|
2007-06-30 22:10:14 -07:00
|
|
|
while (parent[--path_len] != '/') parent[path_len] = '\0';
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-11-26 09:05:16 -08:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (!stat(file, &s2))
|
|
|
|
#else
|
2007-06-30 22:10:14 -07:00
|
|
|
if (!lstat(parent, &s2))
|
2010-11-26 09:05:16 -08:00
|
|
|
#endif
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
if (s.st_dev != s2.st_dev)
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_inode_mountpoint;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_inode_directory;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-07-03 10:55:20 -07:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param file: File to examine
|
2007-07-03 11:01:56 -07:00
|
|
|
* @return Returns mime type or NULL if the file doesn't exist
|
2007-09-06 09:15:10 -07:00
|
|
|
* @brief Returns text/plain if the file appears to contain text and
|
2007-07-03 11:01:56 -07:00
|
|
|
* returns application/octet-stream if it appears to be binary.
|
2007-07-03 10:55:20 -07:00
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
efreet_mime_fallback_check(const char *file)
|
|
|
|
{
|
|
|
|
FILE *f = NULL;
|
|
|
|
char buf[32];
|
2007-07-03 11:01:56 -07:00
|
|
|
int i;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2009-09-13 17:28:51 -07:00
|
|
|
if (ecore_file_can_exec(file))
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_application_x_executable;
|
2010-08-29 01:47:27 -07:00
|
|
|
|
2008-08-02 15:09:04 -07:00
|
|
|
if (!(f = fopen(file, "r"))) return NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 11:01:56 -07:00
|
|
|
i = fread(buf, 1, sizeof(buf), f);
|
2007-07-03 10:55:20 -07:00
|
|
|
fclose(f);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-05-05 13:55:14 -07:00
|
|
|
if (i == 0) return _mime_application_octet_stream;
|
2008-08-02 15:09:04 -07:00
|
|
|
|
2007-07-03 10:55:20 -07:00
|
|
|
/*
|
|
|
|
* Check for ASCII control characters in the first 32 bytes.
|
2007-07-17 12:21:20 -07:00
|
|
|
* Line Feeds, carriage returns, and tabs are ignored as they are
|
|
|
|
* quite common in text files in the first 32 chars.
|
2007-07-03 10:55:20 -07:00
|
|
|
*/
|
2007-07-03 11:01:56 -07:00
|
|
|
for (i -= 1; i >= 0; --i)
|
2007-07-03 10:55:20 -07:00
|
|
|
{
|
2007-09-06 09:15:10 -07:00
|
|
|
if ((buf[i] < 0x20) &&
|
2007-07-17 12:21:20 -07:00
|
|
|
(buf[i] != '\n') && /* Line Feed */
|
|
|
|
(buf[i] != '\r') && /* Carriage Return */
|
|
|
|
(buf[i] != '\t')) /* Tab */
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_application_octet_stream;
|
2007-07-03 10:55:20 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-05-05 13:55:14 -07:00
|
|
|
return _mime_text_plain;
|
2007-07-03 10:55:20 -07:00
|
|
|
}
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param glob: Glob to search for
|
|
|
|
* @return Returns 1 on success, 0 on failure
|
|
|
|
* @brief Removes a glob from the list
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
efreet_mime_glob_remove(const char *glob)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Glob *mime = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2009-03-26 10:56:51 -07:00
|
|
|
if ((mime = eina_list_search_unsorted(globs, EINA_COMPARE_CB(strcmp), glob)))
|
2009-08-28 22:29:05 -07:00
|
|
|
{
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
globs = eina_list_remove(globs, mime);
|
2009-08-28 22:29:05 -07:00
|
|
|
IF_RELEASE(mime->glob);
|
|
|
|
IF_RELEASE(mime->mime);
|
|
|
|
FREE(mime);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param file: mime.types file to load
|
|
|
|
* @return Returns no value
|
2007-09-06 09:15:10 -07:00
|
|
|
* @brief Loads values from a mime.types style file
|
2007-06-30 22:10:14 -07:00
|
|
|
* into the globs list.
|
|
|
|
* @note Format:
|
|
|
|
* application/msaccess mdb
|
|
|
|
* application/msword doc dot
|
|
|
|
*/
|
|
|
|
static void
|
2007-07-01 09:32:34 -07:00
|
|
|
efreet_mime_mime_types_load(const char *file)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
FILE *f = NULL;
|
2007-07-05 20:01:21 -07:00
|
|
|
char buf[4096], mimetype[4096];
|
2007-07-01 09:32:34 -07:00
|
|
|
char ext[4096], *p = NULL, *pp = NULL;
|
2007-06-30 22:10:14 -07:00
|
|
|
|
|
|
|
f = fopen(file, "rb");
|
|
|
|
if (!f) return;
|
|
|
|
while (fgets(buf, sizeof(buf), f))
|
|
|
|
{
|
|
|
|
p = buf;
|
|
|
|
while (isspace(*p) && (*p != 0) && (*p != '\n')) p++;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (*p == '#') continue;
|
|
|
|
if ((*p == '\n') || (*p == 0)) continue;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
pp = p;
|
|
|
|
while (!isspace(*p) && (*p != 0) && (*p != '\n')) p++;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if ((*p == '\n') || (*p == 0)) continue;
|
|
|
|
strncpy(mimetype, pp, (p - pp));
|
|
|
|
mimetype[p - pp] = 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
do
|
|
|
|
{
|
|
|
|
while (isspace(*p) && (*p != 0) && (*p != '\n')) p++;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if ((*p == '\n') || (*p == 0)) break;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
pp = p;
|
|
|
|
while (!isspace(*p) && (*p != 0) && (*p != '\n')) p++;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
strncpy(ext, pp, (p - pp));
|
|
|
|
ext[p - pp] = 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2010-02-04 01:12:35 -08:00
|
|
|
eina_hash_del(wild, ext, NULL);
|
2008-12-17 07:33:43 -08:00
|
|
|
eina_hash_add(wild, ext, (void*)eina_stringshare_add(mimetype));
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
while ((*p != '\n') && (*p != 0));
|
|
|
|
}
|
2007-08-12 12:28:02 -07:00
|
|
|
fclose(f);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param file: globs file to load
|
|
|
|
* @return Returns no value
|
2007-09-06 09:15:10 -07:00
|
|
|
* @brief Loads values from a mime.types style file
|
2007-06-30 22:10:14 -07:00
|
|
|
* into the globs list.
|
|
|
|
* @note Format:
|
|
|
|
* text/vnd.wap.wml:*.wml
|
|
|
|
* application/x-7z-compressed:*.7z
|
|
|
|
* application/vnd.corel-draw:*.cdr
|
|
|
|
* text/spreadsheet:*.sylk
|
|
|
|
*/
|
|
|
|
static void
|
2007-07-01 09:32:34 -07:00
|
|
|
efreet_mime_shared_mimeinfo_globs_load(const char *file)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
FILE *f = NULL;
|
|
|
|
char buf[4096], mimetype[4096], ext[4096], *p, *pp;
|
|
|
|
Efreet_Mime_Glob *mime = NULL;
|
|
|
|
|
|
|
|
f = fopen(file, "rb");
|
|
|
|
if (!f) return;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
while (fgets(buf, sizeof(buf), f))
|
|
|
|
{
|
|
|
|
p = buf;
|
|
|
|
while (isspace(*p) && (*p != 0) && (*p != '\n')) p++;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if (*p == '#') continue;
|
|
|
|
if ((*p == '\n') || (*p == 0)) continue;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
pp = p;
|
|
|
|
while ((*p != ':') && (*p != 0) && (*p != '\n')) p++;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if ((*p == '\n') || (*p == 0)) continue;
|
|
|
|
strncpy(mimetype, pp, (p - pp));
|
|
|
|
mimetype[p - pp] = 0;
|
|
|
|
p++;
|
|
|
|
pp = ext;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
while ((*p != 0) && (*p != '\n'))
|
|
|
|
{
|
|
|
|
*pp = *p;
|
|
|
|
pp++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pp = 0;
|
|
|
|
|
2007-08-12 12:18:16 -07:00
|
|
|
if (ext[0] == '*' && ext[1] == '.')
|
2007-09-06 09:15:10 -07:00
|
|
|
{
|
2008-12-17 07:33:43 -08:00
|
|
|
eina_hash_del(wild, &(ext[2]), NULL);
|
|
|
|
eina_hash_add(wild, &(ext[2]),
|
2010-02-04 01:12:35 -08:00
|
|
|
(void*)eina_stringshare_add(mimetype));
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
|
|
|
else
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2007-07-05 20:01:21 -07:00
|
|
|
mime = NEW(Efreet_Mime_Glob, 1);
|
|
|
|
if (mime)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2008-10-15 07:48:03 -07:00
|
|
|
mime->mime = eina_stringshare_add(mimetype);
|
|
|
|
mime->glob = eina_stringshare_add(ext);
|
2007-07-05 20:01:21 -07:00
|
|
|
if ((!mime->mime) || (!mime->glob))
|
|
|
|
{
|
|
|
|
IF_RELEASE(mime->mime);
|
|
|
|
IF_RELEASE(mime->glob);
|
|
|
|
FREE(mime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
efreet_mime_glob_remove(ext);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
globs = eina_list_append(globs, mime);
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param in: Number to count the digits
|
|
|
|
* @return Returns number of digits
|
|
|
|
* @brief Calculates and returns the number of digits
|
|
|
|
* in a number.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
efreet_mime_count_digits(int in)
|
|
|
|
{
|
2007-07-02 13:08:35 -07:00
|
|
|
int i = 1, j = in;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-02 13:08:35 -07:00
|
|
|
if (j < 10) return 1;
|
|
|
|
while ((j /= 10) > 0) ++i;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-02 13:08:35 -07:00
|
|
|
return i;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param file: File to parse
|
2007-07-03 09:10:30 -07:00
|
|
|
* @return Returns no value
|
|
|
|
* @brief Loads a magic file and adds information to magics list
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
efreet_mime_shared_mimeinfo_magic_load(const char *file)
|
|
|
|
{
|
|
|
|
int fd = -1, size;
|
|
|
|
char *data = (void *)-1;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
if (!file) return;
|
|
|
|
|
|
|
|
size = ecore_file_size(file);
|
|
|
|
if (size <= 0) return;
|
|
|
|
|
|
|
|
fd = open(file, O_RDONLY);
|
|
|
|
if (fd == -1) return;
|
|
|
|
|
|
|
|
data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
2008-05-28 19:00:04 -07:00
|
|
|
if (data == MAP_FAILED)
|
2007-07-03 09:10:30 -07:00
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
efreet_mime_shared_mimeinfo_magic_parse(data, size);
|
|
|
|
|
|
|
|
munmap(data, size);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2007-09-06 09:15:10 -07:00
|
|
|
/**
|
2007-07-03 09:10:30 -07:00
|
|
|
* @param data: The data from the file
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Parses a magic file
|
2007-06-30 22:10:14 -07:00
|
|
|
* @note Format:
|
|
|
|
*
|
|
|
|
* ----------------------------------------------------------------------
|
2007-07-01 09:32:34 -07:00
|
|
|
* | HEX | ASCII |
|
2007-06-30 22:10:14 -07:00
|
|
|
* ----------------------------------------------------------------------
|
|
|
|
* |4D 49 4D 45 2D 4D 61 67 69 63 00 0A 5B 39 30 3A | MIME-Magic..[90: |
|
|
|
|
* |61 70 70 6C 69 63 61 74 69 6F 6E 2F 64 6F 63 62 | application/docb |
|
|
|
|
* |6F 6F 6B 2B 78 6D 6C 5D 0A 3E 30 3D 00 05 3C 3F | ook+xml].>0=..<? |
|
|
|
|
* |78 6D 6C 0A 31 3E 30 3D 00 19 2D 2F 2F 4F 41 53 | xml.1>0=..-//OAS |
|
|
|
|
* |49 53 2F 2F 44 54 44 20 44 6F 63 42 6F 6F 6B 20 | IS//DTD DocBook |
|
|
|
|
* |58 4D 4C 2B 31 30 31 0A 31 3E 30 3D 00 17 2D 2F | XML+101.1>0=..-/ |
|
|
|
|
* ----------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* indent
|
2007-09-06 09:15:10 -07:00
|
|
|
* The nesting depth of the rule, corresponding to the number of '>'
|
2007-06-30 22:10:14 -07:00
|
|
|
* characters in the traditional file format.
|
2007-09-06 09:15:10 -07:00
|
|
|
* ">" start-offset
|
2007-06-30 22:10:14 -07:00
|
|
|
* The offset into the file to look for a match.
|
|
|
|
* "=" value
|
2007-09-06 09:15:10 -07:00
|
|
|
* Two bytes giving the (big-endian) length of the value, followed by the
|
|
|
|
* value itself.
|
|
|
|
* "&" mask
|
|
|
|
* The mask, which (if present) is exactly the same length as the value.
|
|
|
|
* "~" word-size
|
2007-06-30 22:10:14 -07:00
|
|
|
* On little-endian machines, the size of each group to byte-swap.
|
2007-09-06 09:15:10 -07:00
|
|
|
* "+" range-length
|
2007-06-30 22:10:14 -07:00
|
|
|
* The length of the region in the file to check.
|
|
|
|
*
|
2007-09-06 09:15:10 -07:00
|
|
|
* The indent, range-length, word-size and mask components are optional.
|
|
|
|
* If missing, indent defaults to 0, range-length to 1, the word-size to 1,
|
|
|
|
* and the mask to all 'one' bits. In our case, mask is null as it is
|
2010-09-08 04:27:59 -07:00
|
|
|
* quicker, uses less memory and will achieve the same exact effect.
|
2007-06-30 22:10:14 -07:00
|
|
|
*/
|
|
|
|
static void
|
2007-07-03 09:10:30 -07:00
|
|
|
efreet_mime_shared_mimeinfo_magic_parse(char *data, int size)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
Efreet_Mime_Magic *mime = NULL;
|
|
|
|
Efreet_Mime_Magic_Entry *entry = NULL;
|
2007-07-03 09:10:30 -07:00
|
|
|
char *ptr;
|
|
|
|
|
|
|
|
ptr = data;
|
|
|
|
|
|
|
|
/* make sure we're a magic file */
|
2007-09-15 02:51:19 -07:00
|
|
|
if (!ptr || (size < 12) || strncmp(ptr, "MIME-Magic\0\n", 12))
|
2007-07-03 09:10:30 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
ptr += 12;
|
|
|
|
|
|
|
|
for (; (ptr - data) < size; )
|
2007-07-02 13:08:35 -07:00
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
if (*ptr == '[')
|
2007-07-02 13:08:35 -07:00
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
char *val, buf[512];
|
|
|
|
|
|
|
|
mime = NEW(Efreet_Mime_Magic, 1);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
magics = eina_list_append(magics, mime);
|
2007-07-03 07:12:12 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
val = ++ptr;
|
|
|
|
while ((*val != ':')) val++;
|
|
|
|
memcpy(&buf, ptr, val - ptr);
|
|
|
|
buf[val - ptr] = '\0';
|
|
|
|
|
|
|
|
mime->priority = atoi(buf);
|
|
|
|
ptr = ++val;
|
|
|
|
|
|
|
|
while ((*val != ']')) val++;
|
|
|
|
memcpy(&buf, ptr, val - ptr);
|
|
|
|
buf[val - ptr] = '\0';
|
|
|
|
|
2008-10-15 07:48:03 -07:00
|
|
|
mime->mime = eina_stringshare_add(buf);
|
2007-07-03 09:10:30 -07:00
|
|
|
ptr = ++val;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
while (*ptr != '\n') ptr++;
|
2009-07-11 07:23:36 -07:00
|
|
|
ptr++;
|
2007-07-03 09:10:30 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-06 22:52:45 -07:00
|
|
|
short tshort;
|
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
if (!mime) continue;
|
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
if (!(entry = NEW(Efreet_Mime_Magic_Entry, 1)))
|
|
|
|
{
|
2009-03-23 05:19:31 -07:00
|
|
|
IF_FREE_LIST(magics, efreet_mime_magic_free);
|
2007-07-03 09:10:30 -07:00
|
|
|
return;
|
2007-07-03 07:12:12 -07:00
|
|
|
}
|
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
entry->indent = 0;
|
|
|
|
entry->offset = 0;
|
|
|
|
entry->value_len = 0;
|
|
|
|
entry->word_size = 1;
|
|
|
|
entry->range_len = 1;
|
|
|
|
entry->mask = NULL;
|
|
|
|
entry->value = NULL;
|
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
mime->entries = eina_list_append(mime->entries, entry);
|
2010-02-04 01:12:35 -08:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
switch(*ptr)
|
|
|
|
{
|
|
|
|
case '>':
|
|
|
|
ptr ++;
|
|
|
|
entry->offset = atoi(ptr);
|
|
|
|
ptr += efreet_mime_count_digits(entry->offset);
|
|
|
|
break;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
case '=':
|
|
|
|
ptr++;
|
2009-03-23 05:19:31 -07:00
|
|
|
|
2010-07-25 13:25:40 -07:00
|
|
|
tshort = 0;
|
2008-04-06 22:52:45 -07:00
|
|
|
memcpy(&tshort, ptr, sizeof(short));
|
2008-04-06 16:02:54 -07:00
|
|
|
entry->value_len = ntohs(tshort);
|
2007-07-03 09:10:30 -07:00
|
|
|
ptr += 2;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
entry->value = NEW(1, entry->value_len);
|
|
|
|
memcpy(entry->value, ptr, entry->value_len);
|
|
|
|
ptr += entry->value_len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '&':
|
|
|
|
ptr++;
|
|
|
|
entry->mask = NEW(1, entry->value_len);
|
|
|
|
memcpy(entry->mask, ptr, entry->value_len);
|
|
|
|
ptr += entry->value_len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '~':
|
|
|
|
ptr++;
|
|
|
|
entry->word_size = atoi(ptr);
|
2010-01-15 12:51:34 -08:00
|
|
|
if ((entry->word_size != 0) && (((entry->word_size != 1)
|
2010-02-04 01:12:35 -08:00
|
|
|
&& (entry->word_size != 2)
|
|
|
|
&& (entry->word_size != 4))
|
|
|
|
|| (entry->value_len % entry->word_size)))
|
2007-07-03 09:10:30 -07:00
|
|
|
{
|
|
|
|
/* Invalid, Destroy */
|
|
|
|
FREE(entry->value);
|
|
|
|
FREE(entry->mask);
|
|
|
|
FREE(entry);
|
|
|
|
|
|
|
|
while (*ptr != '\n') ptr++;
|
|
|
|
break;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
if (efreet_mime_endianess == EFREET_ENDIAN_LITTLE)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < entry->value_len; j += entry->word_size)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
if (entry->word_size == 2)
|
|
|
|
{
|
2007-09-06 09:15:10 -07:00
|
|
|
((short*)entry->value)[j] =
|
2007-06-30 22:10:14 -07:00
|
|
|
ntohs(((short*)entry->value)[j]);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
if (entry->mask)
|
2007-09-06 09:15:10 -07:00
|
|
|
((short*)entry->mask)[j] =
|
2007-06-30 22:10:14 -07:00
|
|
|
ntohs(((short*)entry->mask)[j]);
|
2007-07-03 09:10:30 -07:00
|
|
|
}
|
|
|
|
else if (entry->word_size == 4)
|
|
|
|
{
|
2008-04-06 16:02:54 -07:00
|
|
|
((int*)entry->value)[j] =
|
|
|
|
ntohl(((int*)entry->value)[j]);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
if (entry->mask)
|
2008-04-06 16:02:54 -07:00
|
|
|
((int*)entry->mask)[j] =
|
|
|
|
ntohl(((int*)entry->mask)[j]);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
}
|
2007-07-03 09:10:30 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
ptr += efreet_mime_count_digits(entry->word_size);
|
|
|
|
break;
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
case '+':
|
|
|
|
ptr++;
|
|
|
|
entry->range_len = atoi(ptr);
|
|
|
|
ptr += efreet_mime_count_digits(entry->range_len);
|
|
|
|
break;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
case '\n':
|
|
|
|
ptr++;
|
|
|
|
entry = NULL;
|
|
|
|
break;
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
default:
|
|
|
|
if (isdigit(*ptr))
|
|
|
|
{
|
|
|
|
entry->indent = atoi(ptr);
|
|
|
|
ptr += efreet_mime_count_digits(entry->indent);
|
|
|
|
}
|
|
|
|
break;
|
2007-07-03 07:12:12 -07:00
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
2007-07-03 09:10:30 -07:00
|
|
|
}
|
2009-03-23 03:27:54 -07:00
|
|
|
/*
|
2007-07-03 06:59:40 -07:00
|
|
|
if (entry)
|
2007-07-03 06:41:44 -07:00
|
|
|
{
|
|
|
|
IF_FREE(entry->value);
|
|
|
|
IF_FREE(entry->mask);
|
2007-07-03 06:59:40 -07:00
|
|
|
FREE(entry);
|
2007-07-03 06:41:44 -07:00
|
|
|
}
|
2009-03-23 03:27:54 -07:00
|
|
|
*/
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param file: File to check
|
|
|
|
* @param start: Start priority, if 0 start at beginning
|
|
|
|
* @param end: End priority, should be less then start
|
|
|
|
* unless start
|
|
|
|
* @return Returns mime type for file if found, NULL if not
|
|
|
|
* @brief Applies magic rules to a file given a start and end priority
|
|
|
|
*/
|
2007-07-01 09:32:34 -07:00
|
|
|
static const char *
|
2007-09-06 09:15:10 -07:00
|
|
|
efreet_mime_magic_check_priority(const char *file,
|
|
|
|
unsigned int start,
|
2007-06-30 22:10:14 -07:00
|
|
|
unsigned int end)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Magic *m = NULL;
|
|
|
|
Efreet_Mime_Magic_Entry *e = NULL;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
Eina_List *l, *ll;
|
2007-07-01 09:32:34 -07:00
|
|
|
FILE *f = NULL;
|
2007-06-30 22:10:14 -07:00
|
|
|
unsigned int i = 0, offset = 0,level = 0, match = 0, bytes_read = 0;
|
|
|
|
const char *last_mime = NULL;
|
2007-07-01 09:32:34 -07:00
|
|
|
char c, v, buf[EFREET_MIME_MAGIC_BUFFER_SIZE];
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
f = fopen(file, "rb");
|
|
|
|
if (!f) return NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
if (!magics)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-13 16:23:13 -07:00
|
|
|
if ((bytes_read = fread(buf, 1, sizeof(buf), f)) == 0)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(magics, l, m)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
if ((start != 0) && (m->priority > start))
|
|
|
|
continue;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
|
|
|
if (m->priority < end)
|
2007-06-30 22:10:14 -07:00
|
|
|
break;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
EINA_LIST_FOREACH(m->entries, ll, e)
|
2007-09-06 09:15:10 -07:00
|
|
|
{
|
2007-06-30 22:10:14 -07:00
|
|
|
if ((level < e->indent) && !match)
|
|
|
|
continue;
|
2007-07-02 13:08:35 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
if ((level >= e->indent) && !match)
|
|
|
|
level = e->indent;
|
2007-07-02 13:08:35 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
else if ((level > e->indent) && match)
|
|
|
|
{
|
|
|
|
fclose(f);
|
2010-07-25 13:25:40 -07:00
|
|
|
return last_mime;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
for (offset = e->offset; offset < e->offset + e->range_len; offset++)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2007-09-06 09:15:10 -07:00
|
|
|
if (((offset + e->value_len) > bytes_read) &&
|
2007-07-02 13:08:35 -07:00
|
|
|
(fseek(f, offset, SEEK_SET) == -1))
|
2007-06-30 22:10:14 -07:00
|
|
|
break;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2007-07-01 09:32:34 -07:00
|
|
|
match = 1;
|
|
|
|
for (i = 0; i < e->value_len; ++i)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
if (offset + e->value_len > bytes_read)
|
2007-06-30 22:10:14 -07:00
|
|
|
c = fgetc(f);
|
|
|
|
else
|
2007-07-01 09:32:34 -07:00
|
|
|
c = buf[offset + i];
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
v = e->value[i];
|
2007-07-03 09:10:30 -07:00
|
|
|
if (e->mask) v &= e->mask[i];
|
2007-06-30 22:10:14 -07:00
|
|
|
|
|
|
|
if (!(c == v))
|
|
|
|
{
|
|
|
|
match = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
|
|
|
if (match)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
level += 1;
|
|
|
|
last_mime = m->mime;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-11 07:26:53 -07:00
|
|
|
|
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
fclose(f);
|
|
|
|
return last_mime;
|
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
fclose(f);
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param data: Data pointer that is being destroyed
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Callback for globs destroy
|
|
|
|
*/
|
|
|
|
static void
|
2007-07-01 09:32:34 -07:00
|
|
|
efreet_mime_glob_free(void *data)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
Efreet_Mime_Glob *m = data;
|
|
|
|
|
|
|
|
IF_RELEASE(m->mime);
|
|
|
|
IF_RELEASE(m->glob);
|
2007-07-02 21:47:29 -07:00
|
|
|
IF_FREE(m);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param data: Data pointer that is being destroyed
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Callback for magics destroy
|
|
|
|
*/
|
|
|
|
static void
|
2007-07-01 09:32:34 -07:00
|
|
|
efreet_mime_magic_free(void *data)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
|
|
|
Efreet_Mime_Magic *m = data;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
IF_RELEASE(m->mime);
|
2010-08-03 04:44:55 -07:00
|
|
|
IF_FREE_LIST(m->entries, efreet_mime_magic_entry_free);
|
2007-07-02 21:47:29 -07:00
|
|
|
IF_FREE(m);
|
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2007-07-02 21:47:29 -07:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param data: Data pointer that is being destroyed
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Callback for magic entry destroy
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
efreet_mime_magic_entry_free(void *data)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Magic_Entry *e = data;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-07-02 21:47:29 -07:00
|
|
|
IF_FREE(e->mask);
|
|
|
|
IF_FREE(e->value);
|
|
|
|
IF_FREE(e);
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
2007-07-02 21:47:29 -07:00
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param str: String (filename) to match
|
|
|
|
* @param glob: Glob to match str to
|
|
|
|
* @return Returns 1 on success, 0 on failure
|
|
|
|
* @brief Compares str to glob, case sensitive
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
efreet_mime_glob_match(const char *str, const char *glob)
|
|
|
|
{
|
2007-08-12 12:28:02 -07:00
|
|
|
if (!str || !glob) return 0;
|
|
|
|
if (glob[0] == 0)
|
|
|
|
{
|
2007-08-12 03:00:02 -07:00
|
|
|
if (str[0] == 0) return 1;
|
2007-06-30 22:10:14 -07:00
|
|
|
return 0;
|
2007-08-12 12:28:02 -07:00
|
|
|
}
|
|
|
|
if (!fnmatch(glob, str, 0)) return 1;
|
|
|
|
return 0;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param str: String (filename) to match
|
|
|
|
* @param glob: Glob to match str to
|
|
|
|
* @return Returns 1 on success, 0 on failure
|
2007-08-12 03:00:02 -07:00
|
|
|
* @brief Compares str to glob, case insensitive (expects str already in lower case)
|
2007-06-30 22:10:14 -07:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
efreet_mime_glob_case_match(char *str, const char *glob)
|
|
|
|
{
|
2007-08-12 12:28:02 -07:00
|
|
|
const char *p;
|
|
|
|
char *tglob, *tp;
|
|
|
|
|
|
|
|
if (!str || !glob) return 0;
|
|
|
|
if (glob[0] == 0)
|
|
|
|
{
|
2007-08-12 03:00:02 -07:00
|
|
|
if (str[0] == 0) return 1;
|
2007-06-30 22:10:14 -07:00
|
|
|
return 0;
|
2007-08-12 12:28:02 -07:00
|
|
|
}
|
|
|
|
tglob = alloca(strlen(glob) + 1);
|
|
|
|
for (tp = tglob, p = glob; *p; p++, tp++) *tp = tolower(*p);
|
|
|
|
*tp = 0;
|
|
|
|
if (!fnmatch(str, tglob, 0)) return 1;
|
|
|
|
return 0;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
|
|
|
static void
|
2010-09-28 10:53:15 -07:00
|
|
|
efreet_mime_icons_flush(double now)
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
{
|
2009-03-03 14:38:21 -08:00
|
|
|
Eina_Inlist *l;
|
2010-09-28 10:53:15 -07:00
|
|
|
static double old = 0;
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
int todo;
|
|
|
|
|
|
|
|
if (now - old < EFREET_MIME_ICONS_FLUSH_TIMEOUT)
|
|
|
|
return;
|
2009-03-03 14:38:21 -08:00
|
|
|
old = now;
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
|
|
|
todo = eina_hash_population(mime_icons) - EFREET_MIME_ICONS_MAX_POPULATION;
|
|
|
|
if (todo <= 0)
|
|
|
|
return;
|
|
|
|
|
2009-03-03 14:38:21 -08:00
|
|
|
l = mime_icons_lru->last; /* mime_icons_lru is not NULL, since todo > 0 */
|
|
|
|
for (; todo > 0; todo--)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Icon_Entry_Head *entry = (Efreet_Mime_Icon_Entry_Head *)l;
|
|
|
|
Eina_Inlist *prev = l->prev;
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
2009-03-03 14:38:21 -08:00
|
|
|
mime_icons_lru = eina_inlist_remove(mime_icons_lru, l);
|
|
|
|
eina_hash_del_by_key(mime_icons, entry->mime);
|
|
|
|
l = prev;
|
|
|
|
}
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
|
|
|
efreet_mime_icons_debug();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
efreet_mime_icon_entry_free(Efreet_Mime_Icon_Entry *node)
|
|
|
|
{
|
|
|
|
eina_stringshare_del(node->icon);
|
|
|
|
eina_stringshare_del(node->theme);
|
|
|
|
free(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
efreet_mime_icon_entry_head_free(Efreet_Mime_Icon_Entry_Head *entry)
|
|
|
|
{
|
|
|
|
while (entry->list)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Icon_Entry *n = (Efreet_Mime_Icon_Entry *)entry->list;
|
|
|
|
entry->list = eina_inlist_remove(entry->list, entry->list);
|
|
|
|
efreet_mime_icon_entry_free(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_stringshare_del(entry->mime);
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Efreet_Mime_Icon_Entry *
|
|
|
|
efreet_mime_icon_entry_new(const char *icon,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Icon_Entry *entry;
|
|
|
|
|
|
|
|
entry = malloc(sizeof(*entry));
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
entry->icon = icon;
|
|
|
|
entry->theme = theme;
|
|
|
|
entry->size = size;
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
efreet_mime_icon_entry_add(const char *mime,
|
|
|
|
const char *icon,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Icon_Entry_Head *entry;
|
|
|
|
Efreet_Mime_Icon_Entry *n;
|
|
|
|
|
|
|
|
n = efreet_mime_icon_entry_new(icon, theme, size);
|
|
|
|
if (!n)
|
|
|
|
return;
|
|
|
|
entry = eina_hash_find(mime_icons, mime);
|
|
|
|
|
|
|
|
if (entry)
|
2009-03-03 14:38:21 -08:00
|
|
|
{
|
|
|
|
Eina_Inlist *l;
|
|
|
|
|
|
|
|
l = EINA_INLIST_GET(n);
|
|
|
|
entry->list = eina_inlist_prepend(entry->list, l);
|
|
|
|
|
|
|
|
l = EINA_INLIST_GET(entry);
|
|
|
|
mime_icons_lru = eina_inlist_promote(mime_icons_lru, l);
|
|
|
|
}
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
else
|
|
|
|
{
|
2009-03-03 14:38:21 -08:00
|
|
|
Eina_Inlist *l;
|
|
|
|
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
entry = malloc(sizeof(*entry));
|
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
efreet_mime_icon_entry_free(n);
|
|
|
|
return;
|
|
|
|
}
|
2009-03-03 14:38:21 -08:00
|
|
|
|
|
|
|
l = EINA_INLIST_GET(n);
|
|
|
|
entry->list = eina_inlist_prepend(NULL, l);
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
entry->mime = mime;
|
|
|
|
eina_hash_direct_add(mime_icons, mime, entry);
|
2009-03-03 14:38:21 -08:00
|
|
|
|
|
|
|
l = EINA_INLIST_GET(entry);
|
|
|
|
mime_icons_lru = eina_inlist_prepend(mime_icons_lru, l);
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
}
|
|
|
|
|
2010-09-28 10:53:15 -07:00
|
|
|
entry->timestamp = ecore_loop_time_get();
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
efreet_mime_icons_flush(entry->timestamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
efreet_mime_icon_entry_find(const char *mime,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Icon_Entry_Head *entry;
|
|
|
|
Efreet_Mime_Icon_Entry *n;
|
|
|
|
|
|
|
|
entry = eina_hash_find(mime_icons, mime);
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
EINA_INLIST_FOREACH(entry->list, n)
|
|
|
|
{
|
|
|
|
if ((n->theme == theme) && (n->size == size))
|
|
|
|
{
|
2009-03-03 14:38:21 -08:00
|
|
|
Eina_Inlist *l;
|
|
|
|
|
|
|
|
l = EINA_INLIST_GET(n);
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
if (entry->list != l)
|
|
|
|
entry->list = eina_inlist_promote(entry->list, l);
|
2009-03-03 14:38:21 -08:00
|
|
|
|
|
|
|
l = EINA_INLIST_GET(entry);
|
|
|
|
if (mime_icons_lru != l)
|
|
|
|
mime_icons_lru = eina_inlist_promote(mime_icons_lru, l);
|
|
|
|
|
2010-09-28 10:53:15 -07:00
|
|
|
entry->timestamp = ecore_loop_time_get();
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
return n->icon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef EFREET_MIME_ICONS_DEBUG
|
2009-03-03 14:38:21 -08:00
|
|
|
static void
|
|
|
|
efreet_mime_icons_debug(void)
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
{
|
2010-09-28 10:53:15 -07:00
|
|
|
double now = ecore_loop_time_get();
|
2009-03-03 14:38:21 -08:00
|
|
|
Efreet_Mime_Icon_Entry_Head *entry;
|
|
|
|
EINA_INLIST_FOREACH(mime_icons_lru, entry)
|
|
|
|
{
|
|
|
|
Efreet_Mime_Icon_Entry *n;
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
2009-03-03 14:38:21 -08:00
|
|
|
if ((now > 0) &&
|
|
|
|
(now - entry->timestamp >= EFREET_MIME_ICONS_EXPIRE_TIMEOUT))
|
|
|
|
{
|
|
|
|
puts("*** FOLLOWING ENTRIES ARE AGED AND CAN BE EXPIRED ***");
|
|
|
|
now = 0;
|
|
|
|
}
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
2009-09-21 09:36:29 -07:00
|
|
|
DBG("mime-icon entry: '%s' last used: %s",
|
2010-02-04 01:12:35 -08:00
|
|
|
entry->mime, ctime(&entry->timestamp));
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
|
2009-03-03 14:38:21 -08:00
|
|
|
EINA_INLIST_FOREACH(entry->list, n)
|
2009-09-21 09:36:29 -07:00
|
|
|
DBG("\tsize: %3u theme: '%s' icon: '%s'",
|
2009-03-03 14:38:21 -08:00
|
|
|
n->theme, n->size, n->icon);
|
|
|
|
}
|
efreet mime types icon cache.
This cache is very simple and should work fine when system does not
change, it keeps a direct association of mime-types and found icons,
remembering theme and icon size. Search is very fast since it uses
stringshared strings and thus direct pointer comparison in hash
search. We could optimize it even more if we assumed stringshared
strings to come in, so no need to eina_stringshare_add() (which is a
hash per se), using just eina_stringshare_ref().
Cache population is limited to compile-time value and just values
older than a given threshold are deleted. I do not keep a LRU explicit
list, so you might have some old but unused items always alive. I
don't find this too bad, sure it will consume more memory, but will
not hurt performance. We can change this to purge all expired items by
not checking for number of items to remove, removing all that match.
Next I plan to find out a good way to cache and speed up file->mime
discovery. I plan to do auto-generated state-machine to match
extensions, so you don't need to check the same extension character
more than once. Example:
Input: bla.edc
Extensions: edc edj eps png bmp
It would first try to match against 'e', 'p' and 'b'. It will match
'e' and then check for 'd' (edc or edj) or 'p' (eps). It will match
'd' and then check for 'c' or 'j'. This will reduce number of
comparisons considerably.
As I'm running out of time (4am, not much time left on this month), I
could use some help here.
SVN revision: 39343
2009-03-02 23:20:21 -08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void
|
|
|
|
efreet_mime_icons_debug(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|