2009-04-20 16:20:40 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2010-11-25 15:48:59 -08:00
|
|
|
#undef alloca
|
|
|
|
#ifdef HAVE_ALLOCA_H
|
|
|
|
# include <alloca.h>
|
|
|
|
#elif defined __GNUC__
|
|
|
|
# define alloca __builtin_alloca
|
|
|
|
#elif defined _AIX
|
|
|
|
# define alloca __alloca
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
# include <malloc.h>
|
|
|
|
# define alloca _alloca
|
|
|
|
#else
|
|
|
|
# include <stddef.h>
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
# endif
|
|
|
|
void *alloca (size_t);
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2010-03-29 13:14:43 -07:00
|
|
|
#include <limits.h>
|
2010-12-04 08:02:20 -08:00
|
|
|
#include <unistd.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
|
2011-02-05 11:05:55 -08:00
|
|
|
/* define macros and variable for using the eina logging system */
|
|
|
|
#define EFREET_MODULE_LOG_DOM _efreet_base_log_dom
|
|
|
|
static int _efreet_base_log_dom = -1;
|
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
#include "Efreet.h"
|
|
|
|
#include "efreet_private.h"
|
|
|
|
|
2010-05-29 01:30:06 -07:00
|
|
|
static Efreet_Version _version = { VMAJ, VMIN, VMIC, VREV };
|
|
|
|
EAPI Efreet_Version *efreet_version = &_version;
|
|
|
|
|
2009-06-20 09:18:17 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
# define EFREET_PATH_SEP ';'
|
|
|
|
#else
|
|
|
|
# define EFREET_PATH_SEP ':'
|
|
|
|
#endif
|
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
static const char *efreet_home_dir = NULL;
|
|
|
|
static const char *xdg_data_home = NULL;
|
|
|
|
static const char *xdg_config_home = NULL;
|
|
|
|
static const char *xdg_cache_home = NULL;
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
static Eina_List *xdg_data_dirs = NULL;
|
|
|
|
static Eina_List *xdg_config_dirs = NULL;
|
2010-12-04 08:02:20 -08:00
|
|
|
static const char *hostname = NULL;
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
static const char *efreet_dir_get(const char *key, const char *fallback);
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
static Eina_List *efreet_dirs_get(const char *key,
|
2007-02-03 05:05:30 -08:00
|
|
|
const char *fallback);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns 1 on success or 0 on failure
|
|
|
|
* @brief Initializes the efreet base settings
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
efreet_base_init(void)
|
|
|
|
{
|
2010-10-07 15:22:33 -07:00
|
|
|
_efreet_base_log_dom = eina_log_domain_register
|
|
|
|
("efreet_base", EFREET_DEFAULT_LOG_COLOR);
|
2009-10-09 23:19:13 -07:00
|
|
|
if (_efreet_base_log_dom < 0)
|
|
|
|
{
|
2010-02-04 01:12:35 -08:00
|
|
|
ERROR("Efreet: Could not create a log domain for efreet_base.\n");
|
|
|
|
return 0;
|
2009-10-09 23:19:13 -07:00
|
|
|
}
|
2007-02-03 05:05:30 -08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns no value
|
2007-06-30 22:10:14 -07:00
|
|
|
* @brief Cleans up the efreet base settings system
|
2007-02-03 05:05:30 -08:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
efreet_base_shutdown(void)
|
|
|
|
{
|
|
|
|
IF_RELEASE(efreet_home_dir);
|
|
|
|
IF_RELEASE(xdg_data_home);
|
|
|
|
IF_RELEASE(xdg_config_home);
|
|
|
|
IF_RELEASE(xdg_cache_home);
|
|
|
|
|
2009-03-23 05:19:31 -07:00
|
|
|
IF_FREE_LIST(xdg_data_dirs, eina_stringshare_del);
|
|
|
|
IF_FREE_LIST(xdg_config_dirs, eina_stringshare_del);
|
2007-02-03 05:05:30 -08:00
|
|
|
|
2010-12-04 08:02:20 -08:00
|
|
|
IF_RELEASE(hostname);
|
|
|
|
|
2009-10-09 23:19:13 -07:00
|
|
|
eina_log_domain_unregister(_efreet_base_log_dom);
|
2007-02-03 05:05:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns the users home directory
|
|
|
|
* @brief Gets the users home directory and returns it.
|
2010-03-01 10:16:32 -08:00
|
|
|
*
|
|
|
|
* Needs EAPI because of helper binaries
|
2007-02-03 05:05:30 -08:00
|
|
|
*/
|
2010-03-01 10:16:32 -08:00
|
|
|
EAPI const char *
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_home_dir_get(void)
|
|
|
|
{
|
|
|
|
if (efreet_home_dir) return efreet_home_dir;
|
|
|
|
|
|
|
|
efreet_home_dir = getenv("HOME");
|
2009-06-20 09:18:17 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
if (!efreet_home_dir || efreet_home_dir[0] == '\0')
|
|
|
|
efreet_home_dir = getenv("USERPROFILE");
|
|
|
|
#endif
|
2007-02-03 05:05:30 -08:00
|
|
|
if (!efreet_home_dir || efreet_home_dir[0] == '\0')
|
|
|
|
efreet_home_dir = "/tmp";
|
|
|
|
|
2010-03-02 12:07:41 -08:00
|
|
|
efreet_home_dir = eina_stringshare_add(efreet_home_dir);
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
return efreet_home_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Returns the XDG Data Home directory
|
|
|
|
* @brief Retrieves the XDG Data Home directory
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_data_home_get(void)
|
|
|
|
{
|
|
|
|
if (xdg_data_home) return xdg_data_home;
|
|
|
|
xdg_data_home = efreet_dir_get("XDG_DATA_HOME", "/.local/share");
|
|
|
|
return xdg_data_home;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
* 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
|
|
|
* @return Returns the Eina_List of preference ordered extra data directories
|
|
|
|
* @brief Returns the Eina_List of prefernece oredred extra data
|
2007-02-03 05:05:30 -08:00
|
|
|
* directories
|
|
|
|
*
|
|
|
|
* @note The returned list is static inside Efreet. If you add/remove from the
|
|
|
|
* list then the next call to efreet_data_dirs_get() will return your
|
|
|
|
* modified values. DO NOT free this list.
|
|
|
|
*/
|
* 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
|
|
|
EAPI Eina_List *
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_data_dirs_get(void)
|
|
|
|
{
|
2009-06-20 09:18:17 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
char buf[4096];
|
|
|
|
#endif
|
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
if (xdg_data_dirs) return xdg_data_dirs;
|
2009-06-20 09:18:17 -07:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
2010-01-23 10:55:27 -08:00
|
|
|
snprintf(buf, 4096, "%s\\Efl;" PACKAGE_DATA_DIR ";/usr/share;/usr/local/share", getenv("APPDATA"));
|
2009-06-20 09:18:17 -07:00
|
|
|
xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS", buf);
|
|
|
|
#else
|
2007-09-06 09:15:10 -07:00
|
|
|
xdg_data_dirs = efreet_dirs_get("XDG_DATA_DIRS",
|
2010-01-23 10:55:27 -08:00
|
|
|
PACKAGE_DATA_DIR ":/usr/share:/usr/local/share");
|
2009-06-20 09:18:17 -07:00
|
|
|
#endif
|
2007-02-03 05:05:30 -08:00
|
|
|
return xdg_data_dirs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Returns the XDG Config Home directory
|
|
|
|
* @brief Retrieves the XDG Config Home directory
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_config_home_get(void)
|
|
|
|
{
|
|
|
|
if (xdg_config_home) return xdg_config_home;
|
|
|
|
xdg_config_home = efreet_dir_get("XDG_CONFIG_HOME", "/.config");
|
|
|
|
return xdg_config_home;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
* 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
|
|
|
* @return Returns the Eina_List of preference ordered extra config directories
|
2009-04-16 10:45:57 -07:00
|
|
|
* @brief Returns the Eina_List of prefernece ordered extra config
|
2007-02-03 05:05:30 -08:00
|
|
|
* directories
|
|
|
|
*
|
|
|
|
* @note The returned list is static inside Efreet. If you add/remove from the
|
|
|
|
* list then the next call to efreet_config_dirs_get() will return your
|
|
|
|
* modified values. DO NOT free this list.
|
|
|
|
*/
|
* 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
|
|
|
EAPI Eina_List *
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_config_dirs_get(void)
|
|
|
|
{
|
|
|
|
if (xdg_config_dirs) return xdg_config_dirs;
|
|
|
|
xdg_config_dirs = efreet_dirs_get("XDG_CONFIG_DIRS", "/etc/xdg");
|
|
|
|
return xdg_config_dirs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Returns the XDG Cache Home directory
|
|
|
|
* @brief Retrieves the XDG Cache Home directory
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI const char *
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_cache_home_get(void)
|
|
|
|
{
|
|
|
|
if (xdg_cache_home) return xdg_cache_home;
|
|
|
|
xdg_cache_home = efreet_dir_get("XDG_CACHE_HOME", "/.cache");
|
|
|
|
return xdg_cache_home;
|
|
|
|
}
|
|
|
|
|
2010-12-04 08:02:20 -08:00
|
|
|
/**
|
|
|
|
* @return Returns the current hostname
|
|
|
|
* @brief Returns the current hostname or empty string if not found
|
|
|
|
*/
|
|
|
|
EAPI const char *
|
|
|
|
efreet_hostname_get(void)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (hostname) return hostname;
|
|
|
|
if (gethostname(buf, sizeof(buf)) < 0)
|
|
|
|
hostname = eina_stringshare_add("");
|
|
|
|
else
|
|
|
|
hostname = eina_stringshare_add(buf);
|
|
|
|
return hostname;
|
|
|
|
}
|
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param key The environemnt key to lookup
|
|
|
|
* @param fallback The fallback value to use
|
2007-02-03 05:05:30 -08:00
|
|
|
* @return Returns the directory related to the given key or the fallback
|
|
|
|
* @brief This trys to determine the correct directory name given the
|
|
|
|
* environment key @a key and fallbacks @a fallback.
|
|
|
|
*/
|
|
|
|
static const char *
|
|
|
|
efreet_dir_get(const char *key, const char *fallback)
|
|
|
|
{
|
|
|
|
char *dir;
|
|
|
|
const char *t;
|
|
|
|
|
|
|
|
dir = getenv(key);
|
|
|
|
if (!dir || dir[0] == '\0')
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
const char *user;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
user = efreet_home_dir_get();
|
|
|
|
len = strlen(user) + strlen(fallback) + 1;
|
2010-08-03 12:31:34 -07:00
|
|
|
dir = malloc(len);
|
|
|
|
if (!dir) return NULL;
|
2007-02-03 05:05:30 -08:00
|
|
|
snprintf(dir, len, "%s%s", user, fallback);
|
|
|
|
|
2010-03-02 12:07:41 -08:00
|
|
|
t = eina_stringshare_add(dir);
|
2007-02-03 05:05:30 -08:00
|
|
|
FREE(dir);
|
|
|
|
}
|
2010-03-02 12:07:41 -08:00
|
|
|
else t = eina_stringshare_add(dir);
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
2011-01-27 09:49:45 -08:00
|
|
|
* @param key The environment key to lookup
|
|
|
|
* @param fallback The fallback value to use
|
2007-02-03 05:05:30 -08:00
|
|
|
* @return Returns a list of directories specified by the given key @a key
|
|
|
|
* or from the list of fallbacks in @a fallback.
|
|
|
|
* @brief Creates a list of directories as given in the environment key @a
|
|
|
|
* key or from the fallbacks in @a fallback
|
|
|
|
*/
|
* estickies,
* etk,
* PROTO/exalt,
* E-MODULES-EXTRA/diskio,
* E-MODULES-EXTRA/drawer,
* E-MODULES-EXTRA/penguins,
* E-MODULES-EXTRA/slideshow,
* E-MODULES-EXTRA/mail,
* E-MODULES-EXTRA/forecasts,
* E-MODULES-EXTRA/iiirk,
* E-MODULES-EXTRA/places,
* e,
* ewl,
* ecore,
* elitaire,
* entrance,
* e_dbus,
* efreet: Here we go, move from Ecore_List to Eina_List.
NOTE: This patch is huge, I did test it a lot, and I hope nothing is
broken. But if you think something change after this commit, please
contact me ASAP.
SVN revision: 39200
2009-02-25 03:03:47 -08:00
|
|
|
static Eina_List *
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_dirs_get(const char *key, const char *fallback)
|
|
|
|
{
|
* 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 *dirs = NULL;
|
2007-02-03 05:05:30 -08:00
|
|
|
const char *path;
|
2010-03-30 05:22:15 -07:00
|
|
|
char *tmp, *s, *p;
|
2010-11-24 02:33:30 -08:00
|
|
|
char ts[PATH_MAX];
|
2010-03-30 05:22:15 -07:00
|
|
|
size_t len;
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
path = getenv(key);
|
|
|
|
if (!path || (path[0] == '\0')) path = fallback;
|
|
|
|
|
|
|
|
if (!path) return dirs;
|
|
|
|
|
2010-03-30 05:22:15 -07:00
|
|
|
len = strlen(path) + 1;
|
|
|
|
tmp = alloca(len);
|
|
|
|
memcpy(tmp, path, len);
|
2007-02-03 05:05:30 -08:00
|
|
|
s = tmp;
|
2009-06-20 09:18:17 -07:00
|
|
|
p = strchr(s, EFREET_PATH_SEP);
|
2007-02-03 05:05:30 -08:00
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
2009-03-26 10:56:51 -07:00
|
|
|
if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
|
2010-05-16 12:36:42 -07:00
|
|
|
{
|
2010-05-16 10:11:38 -07:00
|
|
|
// resolve path properly/fully to remove path//path2 to
|
|
|
|
// path/path2, path/./path2 to path/path2 etc.
|
2010-11-24 02:33:30 -08:00
|
|
|
if (realpath(s, ts))
|
2010-05-16 12:36:42 -07:00
|
|
|
dirs = eina_list_append(dirs, (void *)eina_stringshare_add(ts));
|
|
|
|
}
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
s = ++p;
|
2009-06-20 09:18:17 -07:00
|
|
|
p = strchr(s, EFREET_PATH_SEP);
|
2007-02-03 05:05:30 -08:00
|
|
|
}
|
2009-03-26 10:56:51 -07:00
|
|
|
if (!eina_list_search_unsorted(dirs, EINA_COMPARE_CB(strcmp), s))
|
2010-11-06 07:44:11 -07:00
|
|
|
{
|
|
|
|
// resolve path properly/fully to remove path//path2 to
|
|
|
|
// path/path2, path/./path2 to path/path2 etc.
|
2010-11-24 02:33:30 -08:00
|
|
|
if (realpath(s, ts))
|
2010-11-06 07:44:11 -07:00
|
|
|
dirs = eina_list_append(dirs, (void *)eina_stringshare_add(ts));
|
|
|
|
}
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
return dirs;
|
|
|
|
}
|