2009-04-20 16:20:40 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2011-08-18 00:35:48 -07:00
|
|
|
#include <unistd.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <fnmatch.h>
|
2013-03-15 01:44:26 -07:00
|
|
|
|
2010-11-26 13:32:34 -08:00
|
|
|
#include <Ecore.h>
|
2010-11-25 15:52:57 -08:00
|
|
|
#include <Ecore_File.h>
|
|
|
|
|
2011-02-05 11:05:55 -08:00
|
|
|
/* define macros and variable for using the eina logging system */
|
|
|
|
#define EFREET_MODULE_LOG_DOM _efreet_mime_log_dom
|
|
|
|
static int _efreet_mime_log_dom = -1;
|
|
|
|
|
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
|
|
|
|
2016-08-22 19:59:37 -07:00
|
|
|
static Eina_List *magics = NULL; // contains Efreet_Mime_Magic structs
|
|
|
|
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
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
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-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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
unsigned int priority;
|
|
|
|
const char *mime;
|
|
|
|
Eina_List *entries;
|
2007-07-01 09:32:34 -07:00
|
|
|
};
|
2007-06-30 22:10:14 -07:00
|
|
|
|
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
|
|
|
{
|
2012-09-20 17:03:18 -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
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_INLIST; /* node of mime_icons_lru */
|
|
|
|
Eina_Inlist *list;
|
|
|
|
const char *mime;
|
|
|
|
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
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_INLIST;
|
|
|
|
const char *icon;
|
|
|
|
const char *theme;
|
|
|
|
unsigned int size;
|
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 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,
|
2012-09-20 17:03:18 -07:00
|
|
|
unsigned int start,
|
|
|
|
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_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);
|
|
|
|
|
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);
|
|
|
|
|
2016-08-22 19:59:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static Eina_File *mimedb = NULL;
|
|
|
|
static unsigned char *mimedb_ptr = NULL;
|
|
|
|
static size_t mimedb_size = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_efreet_mimedb_shutdown(void)
|
|
|
|
{
|
|
|
|
if (mimedb)
|
|
|
|
{
|
|
|
|
if (mimedb_ptr) eina_file_map_free(mimedb, mimedb_ptr);
|
|
|
|
eina_file_close(mimedb);
|
|
|
|
mimedb = NULL;
|
|
|
|
mimedb_ptr = NULL;
|
|
|
|
mimedb_size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_efreet_mimedb_update(void)
|
|
|
|
{
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
|
|
|
|
if (mimedb)
|
|
|
|
{
|
|
|
|
if (mimedb_ptr) eina_file_map_free(mimedb, mimedb_ptr);
|
|
|
|
eina_file_close(mimedb);
|
|
|
|
mimedb = NULL;
|
|
|
|
mimedb_ptr = NULL;
|
|
|
|
mimedb_size = 0;
|
|
|
|
}
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
snprintf(buf, sizeof(buf), "%s/efreet/mime_cache_%s.be.dat",
|
|
|
|
efreet_cache_home_get(), efreet_hostname_get());
|
|
|
|
#else
|
|
|
|
snprintf(buf, sizeof(buf), "%s/efreet/mime_cache_%s.le.dat",
|
|
|
|
efreet_cache_home_get(), efreet_hostname_get());
|
|
|
|
#endif
|
|
|
|
mimedb = eina_file_open(buf, EINA_FALSE);
|
|
|
|
if (mimedb)
|
|
|
|
{
|
|
|
|
mimedb_ptr = eina_file_map_all(mimedb, EINA_FILE_POPULATE);
|
|
|
|
if (mimedb_ptr)
|
|
|
|
{
|
|
|
|
mimedb_size = eina_file_size_get(mimedb);
|
2016-08-26 06:53:05 -07:00
|
|
|
if ((mimedb_size >= (16 + 4 + 4 + 4) &&
|
2016-08-22 19:59:37 -07:00
|
|
|
(!strncmp((char *)mimedb_ptr, "EfrEeT-MiMeS-001", 16))))
|
|
|
|
{
|
|
|
|
// load ok - magic fine. more sanity checks?
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eina_file_map_free(mimedb, mimedb_ptr);
|
|
|
|
mimedb_ptr = NULL;
|
|
|
|
eina_file_close(mimedb);
|
|
|
|
mimedb = NULL;
|
|
|
|
mimedb_size = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
eina_file_close(mimedb);
|
|
|
|
mimedb = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_efreet_mimedb_str_get(unsigned int offset)
|
|
|
|
{
|
|
|
|
if (offset < (16 + 4 + 4 + 4)) return NULL;
|
|
|
|
if (offset >= mimedb_size) return NULL;
|
|
|
|
return (const char *)(mimedb_ptr + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
_efreet_mimedb_uint_get(unsigned int index)
|
|
|
|
// index is the unit NUMBER AFTER the header
|
|
|
|
{
|
|
|
|
unsigned int *ptr;
|
|
|
|
ptr = ((unsigned int *)(mimedb_ptr + 16)) + index;
|
|
|
|
if ((size_t)(((unsigned char *)ptr) - mimedb_ptr) >= (mimedb_size - 4))
|
|
|
|
return 0;
|
|
|
|
return *ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
_efreet_mimedb_mime_count(void)
|
|
|
|
{
|
|
|
|
return _efreet_mimedb_uint_get(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** currently unused - here for symmetry and future use
|
|
|
|
static const char *
|
|
|
|
_efreet_mimedb_mime_get(unsigned int num)
|
|
|
|
{
|
|
|
|
unsigned int offset = _efreet_mimedb_uint_get
|
|
|
|
(1 + num);
|
|
|
|
return _efreet_mimedb_str_get(offset);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
_efreet_mimedb_extn_count(void)
|
|
|
|
{
|
|
|
|
return _efreet_mimedb_uint_get(1 + _efreet_mimedb_mime_count());
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_efreet_mimedb_extn_get(unsigned int num)
|
|
|
|
{
|
|
|
|
unsigned int offset = _efreet_mimedb_uint_get
|
|
|
|
(1 + _efreet_mimedb_mime_count() + 1 + (num * 2));
|
|
|
|
return _efreet_mimedb_str_get(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_efreet_mimedb_extn_mime_get(unsigned int num)
|
|
|
|
{
|
|
|
|
unsigned int offset = _efreet_mimedb_uint_get
|
|
|
|
(1 + _efreet_mimedb_mime_count() + 1 + (num * 2) + 1);
|
|
|
|
return _efreet_mimedb_str_get(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_efreet_mimedb_extn_find(const char *extn)
|
|
|
|
{
|
|
|
|
unsigned int i, begin, end;
|
|
|
|
const char *s;
|
|
|
|
|
|
|
|
// binary search keys to get value
|
|
|
|
begin = 0;
|
|
|
|
end = _efreet_mimedb_extn_count();
|
|
|
|
i = (begin + end) / 2;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
s = _efreet_mimedb_extn_get(i);
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
int v = strcmp(extn, s);
|
|
|
|
if (v < 0)
|
|
|
|
{
|
|
|
|
end = i;
|
|
|
|
i = (begin + end) / 2;
|
|
|
|
if ((end - begin) == 0) break;
|
|
|
|
}
|
|
|
|
else if (v > 0)
|
|
|
|
{
|
|
|
|
if ((end - begin) > 1)
|
|
|
|
{
|
|
|
|
begin = i;
|
|
|
|
i = (begin + end) / 2;
|
|
|
|
if (i == end) break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((end - begin) == 0) break;
|
|
|
|
begin = end;
|
|
|
|
i = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (v == 0)
|
|
|
|
return _efreet_mimedb_extn_mime_get(i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
_efreet_mimedb_glob_count(void)
|
|
|
|
{
|
|
|
|
return _efreet_mimedb_uint_get
|
|
|
|
(1 + _efreet_mimedb_mime_count() +
|
|
|
|
1 + (_efreet_mimedb_extn_count() * 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_efreet_mimedb_glob_get(unsigned int num)
|
|
|
|
{
|
|
|
|
unsigned int offset = _efreet_mimedb_uint_get
|
|
|
|
(1 + _efreet_mimedb_mime_count() +
|
|
|
|
1 + (_efreet_mimedb_extn_count() * 2) +
|
|
|
|
1 + (num * 2));
|
|
|
|
return _efreet_mimedb_str_get(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
_efreet_mimedb_glob_mime_get(unsigned int num)
|
|
|
|
{
|
|
|
|
unsigned int offset = _efreet_mimedb_uint_get
|
|
|
|
(1 + _efreet_mimedb_mime_count() +
|
|
|
|
1 + (_efreet_mimedb_extn_count() * 2) +
|
|
|
|
1 + (num * 2) + 1);
|
|
|
|
return _efreet_mimedb_str_get(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** --------------------------------- **/
|
|
|
|
|
2020-05-10 03:47:58 -07:00
|
|
|
int
|
|
|
|
efreet_internal_mime_init(void)
|
2007-09-06 09:15:10 -07:00
|
|
|
{
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
_efreet_mime_log_dom = eina_log_domain_register
|
2010-10-07 15:22:33 -07:00
|
|
|
("efreet_mime", EFREET_DEFAULT_LOG_COLOR);
|
2009-09-21 09:36:29 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (_efreet_mime_log_dom < 0)
|
|
|
|
{
|
2011-03-18 12:47:57 -07:00
|
|
|
EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_mime.");
|
2010-02-04 01:12:35 -08:00
|
|
|
goto shutdown_efreet;
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
2009-09-21 09:36:29 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
efreet_mime_endianess = efreet_mime_endian_check();
|
|
|
|
efreet_mime_type_cache_clear();
|
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
|
|
|
|
2016-08-22 19:59:37 -07:00
|
|
|
_efreet_mimedb_update();
|
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!efreet_mime_init_files())
|
|
|
|
goto unregister_log_domain;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2016-08-22 19:59:37 -07:00
|
|
|
_efreet_mime_update_func = _efreet_mimedb_update;
|
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return _efreet_mime_init_count;
|
2009-10-09 23:19:13 -07:00
|
|
|
|
2010-02-04 01:12:35 -08:00
|
|
|
unregister_log_domain:
|
2012-09-20 17:03:18 -07:00
|
|
|
eina_log_domain_unregister(_efreet_mime_log_dom);
|
|
|
|
_efreet_mime_log_dom = -1;
|
2010-02-04 01:12:35 -08:00
|
|
|
shutdown_efreet:
|
2012-09-20 17:03:18 -07:00
|
|
|
return --_efreet_mime_init_count;
|
2020-05-10 03:47:58 -07:00
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2020-05-10 03:47:58 -07:00
|
|
|
int
|
|
|
|
efreet_internal_mime_shutdown(void)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2017-10-06 09:53:15 -07:00
|
|
|
if (_efreet_mime_init_count == 0)
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Init count not greater than 0 in shutdown.");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (--_efreet_mime_init_count != 0)
|
|
|
|
return _efreet_mime_init_count;
|
|
|
|
|
2016-08-22 19:59:37 -07:00
|
|
|
_efreet_mimedb_shutdown();
|
|
|
|
_efreet_mime_update_func = NULL;
|
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
efreet_mime_icons_debug();
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
IF_FREE_LIST(magics, efreet_mime_magic_free);
|
|
|
|
IF_FREE_HASH(mime_icons);
|
|
|
|
eina_log_domain_unregister(_efreet_mime_log_dom);
|
|
|
|
_efreet_mime_log_dom = -1;
|
|
|
|
|
|
|
|
return _efreet_mime_init_count;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
2020-05-10 03:47:58 -07:00
|
|
|
EAPI int
|
|
|
|
efreet_mime_init(void)
|
|
|
|
{
|
|
|
|
return efreet_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
efreet_mime_shutdown(void)
|
|
|
|
{
|
|
|
|
return efreet_shutdown();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
const char *type = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
2016-08-23 18:00:50 -07:00
|
|
|
if (!mimedb_ptr) return NULL;
|
2010-08-09 12:31:18 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if ((type = efreet_mime_special_check(file)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Check magics with priority > 80 */
|
|
|
|
if ((type = efreet_mime_magic_check_priority(file, 0, 80)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Check globs */
|
|
|
|
if ((type = efreet_mime_globs_type_get(file)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Check rest of magics */
|
|
|
|
if ((type = efreet_mime_magic_check_priority(file, 80, 0)))
|
|
|
|
return type;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return efreet_mime_fallback_check(file);
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
const char *icon = NULL;
|
|
|
|
char *data;
|
|
|
|
Eina_List *icons = NULL;
|
|
|
|
const char *env = NULL;
|
|
|
|
char *p = NULL, *pp = NULL, *ppp = NULL;
|
|
|
|
char buf[PATH_MAX];
|
|
|
|
const char *cache;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(mime, NULL);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL);
|
|
|
|
|
|
|
|
mime = eina_stringshare_add(mime);
|
|
|
|
theme = eina_stringshare_add(theme);
|
|
|
|
cache = efreet_mime_icon_entry_find(mime, theme, size);
|
|
|
|
if (cache)
|
|
|
|
{
|
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_stringshare_del(mime);
|
|
|
|
eina_stringshare_del(theme);
|
2011-02-03 11:58:04 -08:00
|
|
|
return cache;
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -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++;
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
icons = eina_list_append(icons, p);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Environment Based icon names */
|
|
|
|
if ((env = efreet_desktop_environment_get()))
|
|
|
|
{
|
2007-07-17 12:21:20 -07:00
|
|
|
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));
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Mime prefixed icon names */
|
|
|
|
snprintf(buf, sizeof(buf), "mime-%s", p);
|
|
|
|
icons = eina_list_append(icons, strdup(buf));
|
2007-07-17 12:21:20 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Generic icons */
|
|
|
|
pp = strdup(p);
|
|
|
|
while ((ppp = strrchr(pp, '-')))
|
|
|
|
{
|
2007-07-17 12:21:20 -07:00
|
|
|
*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));
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
FREE(pp);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Search for icons using list */
|
|
|
|
icon = efreet_icon_list_find(theme, icons, size);
|
|
|
|
while (icons)
|
|
|
|
{
|
* 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
|
|
|
data = eina_list_data_get(icons);
|
|
|
|
free(data);
|
|
|
|
icons = eina_list_remove_list(icons, icons);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
efreet_mime_icon_entry_add(mime, eina_stringshare_add(icon), theme, size);
|
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
|
|
|
|
2012-09-20 17:03:18 -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)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
if (mime_icons)
|
|
|
|
{
|
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;
|
2012-09-20 17:03:18 -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)
|
|
|
|
{
|
2012-09-20 17:03:18 -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-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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
|
|
|
return efreet_mime_magic_check_priority(file, 0, 0);
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
char *sl, *p;
|
2016-08-22 19:59:37 -07:00
|
|
|
const char *s, *mime;
|
|
|
|
char *ext;
|
|
|
|
unsigned int i, n;
|
2012-09-20 17:03:18 -07:00
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
2016-08-23 18:00:50 -07:00
|
|
|
if (!mimedb_ptr) return NULL;
|
2012-09-20 17:03:18 -07:00
|
|
|
|
|
|
|
/* Check in the extension hash for the type */
|
|
|
|
ext = strchr(file, '.');
|
|
|
|
if (ext)
|
|
|
|
{
|
2007-08-12 12:28:02 -07:00
|
|
|
sl = alloca(strlen(ext) + 1);
|
|
|
|
for (s = ext, p = sl; *s; s++, p++) *p = tolower(*s);
|
|
|
|
*p = 0;
|
|
|
|
p = sl;
|
|
|
|
while (p)
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
p++;
|
2016-08-22 19:59:37 -07:00
|
|
|
if (p && (mime = _efreet_mimedb_extn_find(p))) return mime;
|
2012-09-20 17:03:18 -07:00
|
|
|
p = strchr(p, '.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-22 19:59:37 -07:00
|
|
|
// Fallback to the other globs if not found
|
|
|
|
n = _efreet_mimedb_glob_count();
|
|
|
|
for (i = 0; i < n; i++)
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
2016-08-22 19:59:37 -07:00
|
|
|
s = _efreet_mimedb_glob_get(i);
|
|
|
|
if (efreet_mime_glob_match(file, s))
|
|
|
|
return _efreet_mimedb_glob_mime_get(i);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
ext = alloca(strlen(file) + 1);
|
|
|
|
for (s = file, p = ext; *s; s++, p++) *p = tolower(*s);
|
|
|
|
*p = 0;
|
2016-08-22 19:59:37 -07:00
|
|
|
for (i = 0; i < n; i++)
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
2016-08-22 19:59:37 -07:00
|
|
|
s = _efreet_mimedb_glob_get(i);
|
|
|
|
if (efreet_mime_glob_case_match(ext, s))
|
|
|
|
return _efreet_mimedb_glob_mime_get(i);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
return NULL;
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
|
|
|
return efreet_mime_special_check(file);
|
2007-07-05 20:01:21 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(file, NULL);
|
|
|
|
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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
int test = 1;
|
|
|
|
return (*((char*)(&test)));
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param datadirs List of XDG data dirs
|
|
|
|
* @param datahome Path to XDG data home directory
|
2007-06-30 22:10:14 -07:00
|
|
|
* @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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Eina_List *l;
|
|
|
|
char buf[4096];
|
|
|
|
const char *datadir = NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
while (magics)
|
|
|
|
{
|
* 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_magic_free(eina_list_data_get(magics));
|
|
|
|
magics = eina_list_remove_list(magics, magics);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
datadir = datahome;
|
|
|
|
snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
|
|
|
|
efreet_mime_shared_mimeinfo_magic_load(buf);
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_LIST_FOREACH(datadirs, l, 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
|
|
|
snprintf(buf, sizeof(buf), "%s/mime/magic", datadir);
|
|
|
|
efreet_mime_shared_mimeinfo_magic_load(buf);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param datadirs List of XDG data dirs
|
|
|
|
* @param datahome Path to XDG data home directory
|
2007-06-30 22:10:14 -07:00
|
|
|
* @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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Eina_List *datadirs = NULL;
|
2016-08-22 19:59:37 -07:00
|
|
|
const char *datahome;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!(datahome = efreet_data_home_get()))
|
|
|
|
return 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!(datadirs = efreet_data_dirs_get()))
|
|
|
|
return 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
efreet_mime_load_magics(datadirs, datahome);
|
|
|
|
|
2016-08-22 19:59:37 -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");
|
2012-09-20 17:03:18 -07:00
|
|
|
_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");
|
|
|
|
|
|
|
|
return 1;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08: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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
struct stat s;
|
|
|
|
int path_len = 0;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2018-01-29 04:39:28 -08:00
|
|
|
/* no symlink on Windows */
|
2010-11-26 09:05:16 -08:00
|
|
|
#ifdef _WIN32
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!stat(file, &s))
|
2010-11-26 09:05:16 -08:00
|
|
|
#else
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!lstat(file, &s))
|
2010-11-26 09:05:16 -08:00
|
|
|
#endif
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
if (S_ISREG(s.st_mode))
|
2007-06-30 22:10:14 -07:00
|
|
|
return NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2009-04-20 16:20:40 -07:00
|
|
|
#ifndef _WIN32
|
2012-09-20 17:03:18 -07:00
|
|
|
if (S_ISLNK(s.st_mode))
|
|
|
|
return _mime_inode_symlink;
|
2009-04-20 16:20:40 -07:00
|
|
|
#endif
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -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
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (S_ISDIR(s.st_mode))
|
|
|
|
{
|
|
|
|
struct stat s2;
|
|
|
|
char parent[PATH_MAX];
|
|
|
|
char path[PATH_MAX];
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
strncpy(path, file, PATH_MAX);
|
2013-08-07 01:52:02 -07:00
|
|
|
path[PATH_MAX - 1] = '\0';
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
path_len = strlen(file);
|
|
|
|
strncpy(parent, path, PATH_MAX);
|
2013-08-07 01:52:02 -07:00
|
|
|
parent[PATH_MAX - 1] = '\0';
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Kill any trailing slash */
|
2016-07-04 23:56:43 -07:00
|
|
|
if (parent[path_len - 1] == '/')
|
|
|
|
parent[--path_len] = '\0';
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* Truncate to last slash */
|
2016-07-04 23:56:43 -07:00
|
|
|
while ((path_len > 0) &&
|
|
|
|
(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
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!stat(file, &s2))
|
2010-11-26 09:05:16 -08:00
|
|
|
#else
|
2012-10-18 01:09:54 -07:00
|
|
|
if (!lstat(parent, &s2))
|
2010-11-26 09:05:16 -08:00
|
|
|
#endif
|
2012-10-18 01:09:54 -07:00
|
|
|
{
|
|
|
|
if (s.st_dev != s2.st_dev)
|
|
|
|
return _mime_inode_mountpoint;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return _mime_inode_directory;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return NULL;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
2007-07-03 10:55:20 -07:00
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @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)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
FILE *f = NULL;
|
|
|
|
char buf[32];
|
|
|
|
int i;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (ecore_file_can_exec(file))
|
|
|
|
return _mime_application_x_executable;
|
2010-08-29 01:47:27 -07:00
|
|
|
|
2015-12-03 00:32:39 -08:00
|
|
|
if (!(f = fopen(file, "rb"))) return NULL;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
i = fread(buf, 1, sizeof(buf), f);
|
|
|
|
fclose(f);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (i == 0) return _mime_application_octet_stream;
|
2008-08-02 15:09:04 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/*
|
|
|
|
* Check for ASCII control characters in the first 32 bytes.
|
|
|
|
* Line Feeds, carriage returns, and tabs are ignored as they are
|
|
|
|
* quite common in text files in the first 32 chars.
|
|
|
|
*/
|
|
|
|
for (i -= 1; i >= 0; --i)
|
|
|
|
{
|
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 */
|
2012-09-20 17:03:18 -07:00
|
|
|
return _mime_application_octet_stream;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return _mime_text_plain;
|
2007-07-03 10:55:20 -07:00
|
|
|
}
|
|
|
|
|
2007-06-30 22:10:14 -07:00
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param in Number to count the digits
|
2007-06-30 22:10:14 -07:00
|
|
|
* @return Returns number of digits
|
|
|
|
* @brief Calculates and returns the number of digits
|
|
|
|
* in a number.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
efreet_mime_count_digits(int in)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
int i = 1, j = in;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (j < 10) return 1;
|
|
|
|
while ((j /= 10) > 0) ++i;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return i;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @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)
|
|
|
|
{
|
2013-06-26 20:23:33 -07:00
|
|
|
Eina_File *f;
|
|
|
|
void *data;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!file) return;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2013-06-26 20:23:33 -07:00
|
|
|
f = eina_file_open(file, EINA_FALSE);
|
|
|
|
if (!f) return ;
|
2012-05-23 13:10:27 -07:00
|
|
|
|
2013-06-26 20:23:33 -07:00
|
|
|
data = eina_file_map_all(f, EINA_FILE_WILLNEED);
|
|
|
|
if (!data) goto end;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2013-06-26 20:23:33 -07:00
|
|
|
efreet_mime_shared_mimeinfo_magic_parse(data, eina_file_size_get(f));
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2013-06-26 20:23:33 -07:00
|
|
|
eina_file_map_free(f, data);
|
|
|
|
end:
|
|
|
|
eina_file_close(f);
|
2007-07-03 09:10:30 -07:00
|
|
|
}
|
|
|
|
|
2007-09-06 09:15:10 -07:00
|
|
|
/**
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param data The data from the file
|
2007-07-03 09:10:30 -07:00
|
|
|
* @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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Efreet_Mime_Magic *mime = NULL;
|
|
|
|
Efreet_Mime_Magic_Entry *entry = NULL;
|
|
|
|
char *ptr;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
ptr = data;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
/* make sure we're a magic file */
|
|
|
|
if (!ptr || (size < 12) || strncmp(ptr, "MIME-Magic\0\n", 12))
|
|
|
|
return;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
ptr += 12;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
for (; (ptr - data) < size; )
|
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
if (*ptr == '[')
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
char *val, buf[512];
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
mime = NEW(Efreet_Mime_Magic, 1);
|
|
|
|
magics = eina_list_append(magics, mime);
|
2007-07-03 07:12:12 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
val = ++ptr;
|
|
|
|
while ((*val != ':')) val++;
|
|
|
|
memcpy(&buf, ptr, val - ptr);
|
|
|
|
buf[val - ptr] = '\0';
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
mime->priority = atoi(buf);
|
|
|
|
ptr = ++val;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
while ((*val != ']')) val++;
|
|
|
|
memcpy(&buf, ptr, val - ptr);
|
|
|
|
buf[val - ptr] = '\0';
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
mime->mime = eina_stringshare_add(buf);
|
|
|
|
ptr = ++val;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
while (*ptr != '\n') ptr++;
|
|
|
|
ptr++;
|
|
|
|
}
|
2007-07-03 09:10:30 -07:00
|
|
|
else
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
short tshort;
|
2008-04-06 22:52:45 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!mime) continue;
|
|
|
|
if (!entry)
|
|
|
|
{
|
|
|
|
if (!(entry = NEW(Efreet_Mime_Magic_Entry, 1)))
|
|
|
|
{
|
|
|
|
IF_FREE_LIST(magics, efreet_mime_magic_free);
|
|
|
|
return;
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -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;
|
|
|
|
|
|
|
|
mime->entries = eina_list_append(mime->entries, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(*ptr)
|
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
case '>':
|
2012-09-20 17:03:18 -07:00
|
|
|
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 '=':
|
2012-09-20 17:03:18 -07:00
|
|
|
ptr++;
|
2009-03-23 05:19:31 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
tshort = 0;
|
|
|
|
memcpy(&tshort, ptr, sizeof(short));
|
2019-02-01 03:04:17 -08:00
|
|
|
entry->value_len = eina_ntohs(tshort);
|
2012-09-20 17:03:18 -07:00
|
|
|
ptr += 2;
|
2007-07-01 09:32:34 -07:00
|
|
|
|
2013-07-16 03:49:31 -07:00
|
|
|
entry->value = NEW(char, entry->value_len);
|
2012-09-20 17:03:18 -07:00
|
|
|
memcpy(entry->value, ptr, entry->value_len);
|
|
|
|
ptr += entry->value_len;
|
|
|
|
break;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
|
|
|
case '&':
|
2012-09-20 17:03:18 -07:00
|
|
|
ptr++;
|
2013-07-16 03:49:31 -07:00
|
|
|
entry->mask = NEW(char, entry->value_len);
|
2012-09-20 17:03:18 -07:00
|
|
|
memcpy(entry->mask, ptr, entry->value_len);
|
|
|
|
ptr += entry->value_len;
|
|
|
|
break;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
|
|
|
case '~':
|
2012-09-20 17:03:18 -07:00
|
|
|
ptr++;
|
|
|
|
entry->word_size = atoi(ptr);
|
|
|
|
if ((entry->word_size != 0) && (((entry->word_size != 1)
|
|
|
|
&& (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;
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (efreet_mime_endianess == EFREET_ENDIAN_LITTLE)
|
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < entry->value_len; j += entry->word_size)
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
if (entry->word_size == 2)
|
|
|
|
{
|
|
|
|
((short*)entry->value)[j] =
|
2019-02-01 03:04:17 -08:00
|
|
|
eina_ntohs(((short*)entry->value)[j]);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (entry->mask)
|
2007-09-06 09:15:10 -07:00
|
|
|
((short*)entry->mask)[j] =
|
2019-02-01 03:04:17 -08:00
|
|
|
eina_ntohs(((short*)entry->mask)[j]);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
else if (entry->word_size == 4)
|
|
|
|
{
|
|
|
|
((int*)entry->value)[j] =
|
2019-02-01 03:04:17 -08:00
|
|
|
eina_ntohl(((int*)entry->value)[j]);
|
2012-09-20 17:03:18 -07:00
|
|
|
|
|
|
|
if (entry->mask)
|
2008-04-06 16:02:54 -07:00
|
|
|
((int*)entry->mask)[j] =
|
2019-02-01 03:04:17 -08:00
|
|
|
eina_ntohl(((int*)entry->mask)[j]);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -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 '+':
|
2012-09-20 17:03:18 -07:00
|
|
|
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':
|
2012-09-20 17:03:18 -07:00
|
|
|
ptr++;
|
|
|
|
entry = NULL;
|
|
|
|
break;
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2007-07-03 09:10:30 -07:00
|
|
|
default:
|
2012-09-20 17:03:18 -07:00
|
|
|
if (isdigit(*ptr))
|
|
|
|
{
|
2007-07-03 09:10:30 -07:00
|
|
|
entry->indent = atoi(ptr);
|
|
|
|
ptr += efreet_mime_count_digits(entry->indent);
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
if (entry)
|
|
|
|
{
|
|
|
|
IF_FREE(entry->value);
|
|
|
|
IF_FREE(entry->mask);
|
|
|
|
FREE(entry);
|
|
|
|
}
|
|
|
|
*/
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param file File to check
|
|
|
|
* @param start Start priority, if 0 start at beginning
|
|
|
|
* @param end End priority, should be less then start
|
2007-06-30 22:10:14 -07:00
|
|
|
* 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,
|
2012-09-20 17:03:18 -07:00
|
|
|
unsigned int start,
|
|
|
|
unsigned int end)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Efreet_Mime_Magic *m = NULL;
|
|
|
|
Efreet_Mime_Magic_Entry *e = NULL;
|
|
|
|
Eina_List *l, *ll;
|
2016-11-14 15:16:32 -08:00
|
|
|
Eina_File *f = NULL;
|
|
|
|
const char *mem = NULL;
|
|
|
|
size_t sz;
|
|
|
|
unsigned int i = 0, offset = 0,level = 0, match = 0;
|
2012-09-20 17:03:18 -07:00
|
|
|
const char *last_mime = NULL;
|
2013-08-07 01:57:13 -07:00
|
|
|
int c;
|
2016-11-14 15:16:32 -08:00
|
|
|
char v;
|
2014-04-17 10:34:33 -07:00
|
|
|
|
2016-11-14 15:16:32 -08:00
|
|
|
if (!magics) return NULL;
|
2012-09-20 17:03:18 -07:00
|
|
|
|
2016-11-14 15:16:32 -08:00
|
|
|
f = eina_file_open(file, EINA_FALSE);
|
2012-09-20 17:03:18 -07:00
|
|
|
if (!f) return NULL;
|
|
|
|
|
2016-11-14 15:16:32 -08:00
|
|
|
mem = eina_file_map_all(f, EINA_FILE_RANDOM);
|
|
|
|
if (!mem) goto end;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2016-11-14 15:16:32 -08:00
|
|
|
sz = eina_file_size_get(f);
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_LIST_FOREACH(magics, l, m)
|
|
|
|
{
|
2007-06-30 22:10:14 -07:00
|
|
|
if ((start != 0) && (m->priority > start))
|
2012-09-20 17:03:18 -07:00
|
|
|
continue;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
|
|
|
if (m->priority < end)
|
2012-09-20 17:03:18 -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)
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
if ((level < e->indent) && !match)
|
|
|
|
continue;
|
2007-07-02 13:08:35 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if ((level >= e->indent) && !match)
|
2016-11-14 15:16:32 -08:00
|
|
|
{
|
|
|
|
level = e->indent;
|
|
|
|
}
|
2012-09-20 17:03:18 -07:00
|
|
|
else if ((level > e->indent) && match)
|
|
|
|
{
|
2016-11-14 15:16:32 -08:00
|
|
|
goto end;
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
for (offset = e->offset; offset < e->offset + e->range_len; offset++)
|
|
|
|
{
|
2016-11-14 15:16:32 -08:00
|
|
|
if (offset + e->value_len >= sz) break;
|
2007-07-03 09:10:30 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
match = 1;
|
|
|
|
for (i = 0; i < e->value_len; ++i)
|
2007-06-30 22:10:14 -07:00
|
|
|
{
|
2016-11-14 15:16:32 -08:00
|
|
|
c = mem[offset + i];
|
2012-09-20 17:03:18 -07:00
|
|
|
|
|
|
|
v = e->value[i];
|
2016-11-14 15:16:32 -08:00
|
|
|
if (e->mask) c &= e->mask[i];
|
2012-09-20 17:03:18 -07:00
|
|
|
|
|
|
|
if (!(c == v))
|
|
|
|
{
|
|
|
|
match = 0;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (match)
|
|
|
|
{
|
|
|
|
level += 1;
|
|
|
|
last_mime = m->mime;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-11 07:26:53 -07:00
|
|
|
|
2016-11-14 15:16:32 -08:00
|
|
|
if (match) break;
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
|
2016-11-14 15:16:32 -08:00
|
|
|
end:
|
|
|
|
if (mem) eina_file_map_free(f, (void*) mem);
|
|
|
|
|
|
|
|
eina_file_close(f);
|
|
|
|
|
|
|
|
return last_mime;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param data Data pointer that is being destroyed
|
2007-06-30 22:10:14 -07:00
|
|
|
* @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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Efreet_Mime_Magic *m = data;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
IF_RELEASE(m->mime);
|
|
|
|
IF_FREE_LIST(m->entries, efreet_mime_magic_entry_free);
|
|
|
|
IF_FREE(m);
|
2007-07-02 21:47:29 -07:00
|
|
|
}
|
2007-06-30 22:10:14 -07:00
|
|
|
|
2007-07-02 21:47:29 -07:00
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param data Data pointer that is being destroyed
|
2007-07-02 21:47:29 -07:00
|
|
|
* @return Returns no value
|
|
|
|
* @brief Callback for magic entry destroy
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
efreet_mime_magic_entry_free(void *data)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Efreet_Mime_Magic_Entry *e = data;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2012-09-20 17:03:18 -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
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param str String (filename) to match
|
|
|
|
* @param glob Glob to match str to
|
2007-06-30 22:10:14 -07:00
|
|
|
* @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)
|
|
|
|
{
|
2012-09-20 17:03:18 -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;
|
2012-09-20 17:03:18 -07:00
|
|
|
}
|
|
|
|
if (!fnmatch(glob, str, 0)) return 1;
|
|
|
|
return 0;
|
2007-06-30 22:10:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param str String (filename) to match
|
|
|
|
* @param glob Glob to match str to
|
2007-06-30 22:10:14 -07:00
|
|
|
* @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)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
const char *p;
|
|
|
|
char *tglob, *tp;
|
2007-08-12 12:28:02 -07:00
|
|
|
|
2012-09-20 17:03:18 -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;
|
2012-09-20 17:03:18 -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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Eina_Inlist *l;
|
|
|
|
static double old = 0;
|
|
|
|
int todo;
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
if (now - old < EFREET_MIME_ICONS_FLUSH_TIMEOUT)
|
|
|
|
return;
|
|
|
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
todo = eina_hash_population(mime_icons) - EFREET_MIME_ICONS_MAX_POPULATION;
|
|
|
|
if (todo <= 0)
|
|
|
|
return;
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
l = mime_icons_lru->last; /* mime_icons_lru is not NULL, since todo > 0 */
|
|
|
|
for (; todo > 0; todo--)
|
|
|
|
{
|
2009-03-03 14:38:21 -08:00
|
|
|
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;
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
efreet_mime_icons_debug();
|
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_free(Efreet_Mime_Icon_Entry *node)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
eina_stringshare_del(node->icon);
|
|
|
|
eina_stringshare_del(node->theme);
|
|
|
|
free(node);
|
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)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
while (entry->list)
|
|
|
|
{
|
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 *n = (Efreet_Mime_Icon_Entry *)entry->list;
|
|
|
|
entry->list = eina_inlist_remove(entry->list, entry->list);
|
|
|
|
efreet_mime_icon_entry_free(n);
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
eina_stringshare_del(entry->mime);
|
|
|
|
free(entry);
|
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 Efreet_Mime_Icon_Entry *
|
|
|
|
efreet_mime_icon_entry_new(const char *icon,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Efreet_Mime_Icon_Entry *entry;
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
entry = malloc(sizeof(*entry));
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
entry->icon = icon;
|
|
|
|
entry->theme = theme;
|
|
|
|
entry->size = size;
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return entry;
|
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_add(const char *mime,
|
|
|
|
const char *icon,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Efreet_Mime_Icon_Entry_Head *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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
n = efreet_mime_icon_entry_new(icon, theme, size);
|
|
|
|
if (!n)
|
|
|
|
return;
|
|
|
|
entry = eina_hash_find(mime_icons, mime);
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
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);
|
2012-09-20 17:03:18 -07: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)
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
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);
|
2012-09-20 17:03:18 -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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
entry->timestamp = ecore_loop_time_get();
|
|
|
|
efreet_mime_icons_flush(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
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
efreet_mime_icon_entry_find(const char *mime,
|
|
|
|
const char *theme,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
Efreet_Mime_Icon_Entry_Head *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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
entry = eina_hash_find(mime_icons, mime);
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
EINA_INLIST_FOREACH(entry->list, 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 ((n->theme == theme) && (n->size == size))
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
Eina_Inlist *l;
|
2009-03-03 14:38:21 -08:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
l = EINA_INLIST_GET(n);
|
|
|
|
if (entry->list != l)
|
|
|
|
entry->list = eina_inlist_promote(entry->list, l);
|
2009-03-03 14:38:21 -08:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
l = EINA_INLIST_GET(entry);
|
|
|
|
if (mime_icons_lru != l)
|
|
|
|
mime_icons_lru = eina_inlist_promote(mime_icons_lru, l);
|
2009-03-03 14:38:21 -08:00
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
entry->timestamp = ecore_loop_time_get();
|
|
|
|
return 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
|
|
|
|
2012-09-20 17:03:18 -07:00
|
|
|
return NULL;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
|
|
{
|
2012-09-20 17:03:18 -07:00
|
|
|
double now = ecore_loop_time_get();
|
|
|
|
Efreet_Mime_Icon_Entry_Head *entry;
|
|
|
|
EINA_INLIST_FOREACH(mime_icons_lru, entry)
|
|
|
|
{
|
2009-03-03 14:38:21 -08:00
|
|
|
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))
|
2012-09-20 17:03:18 -07:00
|
|
|
{
|
|
|
|
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)
|
2012-09-20 17:03:18 -07:00
|
|
|
DBG("\tsize: %3u theme: '%s' icon: '%s'",
|
|
|
|
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
|