コード例 #1
0
int
ef_cb_efreet_cache_home(void)
{
   const char *tmp;
   int ret = 1;

   efreet_shutdown();
   setenv("XDG_CACHE_HOME", "/var/tmp", 1);
   efreet_init();

   tmp = efreet_cache_home_get();
   if (strcmp(tmp, "/var/tmp"))
     {
        printf("efreet_cache_home_get() returned incorrect "
               "value (%s) on XDG_CACHE_HOME=/var/tmp\n", tmp);
        ret = 0;
     }

   /* reset efreet here so we can set a new home dir */
   efreet_shutdown();
   unsetenv("XDG_CACHE_HOME");
   setenv("HOME", "/home/tmp", 1);
   efreet_init();

   tmp = efreet_cache_home_get();
   if (strcmp(tmp, "/home/tmp/.cache"))
     {
        printf("efreet_cache_home_get() returned incorrect "
               "value (%s) on blank XDG_CACHE_HOME\n", tmp);
        ret = 0;
     }

   /* reset efreet here so we can set a new home dir */
   efreet_shutdown();
   unsetenv("XDG_CACHE_HOME");
   unsetenv("HOME");
#ifdef _WIN32
   unsetenv("USERPROFILE");
#endif
   efreet_init();

   tmp = efreet_cache_home_get();
   if (strcmp(tmp, "/tmp/.cache"))
     {
        printf("efreet_cache_home_get() returned incorrect "
               "value (%s) on blank XDG_CACHE_HOME and blank HOME\n", tmp);
        ret = 0;
     }

   return ret;
}
コード例 #2
0
/*
 * Needs EAPI because of helper binaries
 */
EAPI const char *
efreet_desktop_util_cache_file(void)
{
    char tmp[PATH_MAX] = { '\0' };
    const char *cache_dir, *lang, *country, *modifier;

    if (cache_file) return cache_file;

    cache_dir = efreet_cache_home_get();
    lang = efreet_lang_get();
    country = efreet_lang_country_get();
    modifier = efreet_lang_modifier_get();

    if (lang && country && modifier)
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s@%s.eet", cache_dir, efreet_hostname_get(), lang, country, modifier);
    else if (lang && country)
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s_%s.eet", cache_dir, efreet_hostname_get(), lang, country);
    else if (lang)
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s_%s.eet", cache_dir, efreet_hostname_get(), lang);
    else
        snprintf(tmp, sizeof(tmp), "%s/efreet/desktop_util_%s.eet", cache_dir, efreet_hostname_get());

    cache_file = eina_stringshare_add(tmp);
    return cache_file;
}
コード例 #3
0
static Eet_File *
_open_temp_eet(Eina_Tmpstr **path, const char *rel)
{
   Eet_File *ef;
   int tmpfd;
   char buffer[PATH_MAX];

   {
      char *tmp;

      tmp = strdup(rel);
      snprintf(buffer, sizeof(buffer), "%s/efreet/%s.XXXXXX.cache",
               efreet_cache_home_get(), basename(tmp));
      free(tmp);
   }

   tmpfd = eina_file_mkstemp(buffer, path);
   if (tmpfd < 0) return NULL;
   close(tmpfd);

   ef = eet_open(*path, EET_FILE_MODE_READ_WRITE);
   if (!ef) goto on_error;

   return ef;

 on_error:
   eina_tmpstr_del(*path);
   *path = NULL;

   return NULL;
}
コード例 #4
0
static void
_print_cache_home(void)
{
   const char *s = efreet_cache_home_get();
   if (!s) return;
   fputs(s, stdout);
}
コード例 #5
0
ファイル: utils.c プロジェクト: GeeXboX/enna
int
enna_util_init()
{
    EVT("enna util init");

    /* Prevent multiple loads */
    if (_util_init_count > 0)
        return ++_util_init_count;

    sd = calloc(1, sizeof(Smart_Data));
    sd->cache = eina_stringshare_printf("%s/%s", efreet_cache_home_get(), "/enna");
    sd->config = eina_stringshare_printf("%s/%s", efreet_config_home_get(), "/enna");
    sd->data = eina_stringshare_printf("%s/%s", efreet_data_home_get(), "/enna");

    if (!ecore_file_is_dir(sd->cache))
        ecore_file_mkdir(sd->cache);

    if (!ecore_file_is_dir(sd->config))
        ecore_file_mkdir(sd->config);

    if (!ecore_file_is_dir(sd->data))
        ecore_file_mkdir(sd->data);


    DBG("Set data directory to %s", sd->data);
    DBG("Set config directory to : %s", sd->config);
    DBG("Set cache directory to : %s", sd->cache);

    _util_init_count = 1;
    EVT("enna util init done");

    return 1;
}
コード例 #6
0
ファイル: albumart.c プロジェクト: mjtorn/rage
static char *
_thumbpath(const char *file)
{
   char buf_base[PATH_MAX];
   char buf_file[PATH_MAX];
   unsigned char sum[20];

   if (!sha1((unsigned char *)file, strlen(file), sum)) return NULL;
   snprintf(buf_base, sizeof(buf_base), "%s/rage/albumart/%02x",
            efreet_cache_home_get(), sum[0]);
   if (!ecore_file_mkpath(buf_base)) return NULL;
   snprintf(buf_file, sizeof(buf_base),
            "%s/%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
            "%02x%02x%02x%02x%02x%02x%02x%02x.jpg",
            buf_base,
            sum[1], sum[2], sum[3],
            sum[4], sum[5], sum[6], sum[7],
            sum[8], sum[9], sum[10], sum[11],
            sum[12], sum[13], sum[14], sum[15],
            sum[16], sum[17], sum[18], sum[19]);
   return strdup(buf_file);
}
コード例 #7
0
static int
cache_lock_file(void)
{
    char file[PATH_MAX];
    struct flock fl;
    int lockfd;

    snprintf(file, sizeof(file), "%s/efreet/desktop_data.lock", efreet_cache_home_get());
    lockfd = open(file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
    if (lockfd < 0) return -1;
    efreet_fsetowner(lockfd);

    memset(&fl, 0, sizeof(struct flock));
    fl.l_type = F_WRLCK;
    fl.l_whence = SEEK_SET;
    if (fcntl(lockfd, F_SETLK, &fl) < 0)
    {
        INF("LOCKED! You may want to delete %s if this persists", file);
        close(lockfd);
        return -1;
    }

    return lockfd;
}
コード例 #8
0
ファイル: efreet_cache.c プロジェクト: jgfenix/efl
int
efreet_cache_init(void)
{
    char buf[PATH_MAX];

    _efreet_cache_log_dom = eina_log_domain_register("efreet_cache", EFREET_DEFAULT_LOG_COLOR);
    if (_efreet_cache_log_dom < 0)
        return 0;

    if (!eina_lock_new(&_lock))
    {
        ERR("Could not create lock");
        goto error;
    }

    snprintf(buf, sizeof(buf), "%s/efreet", efreet_cache_home_get());
    if (!ecore_file_mkpath(buf))
    {
        ERR("Failed to create directory '%s'", buf);
    }

    EFREET_EVENT_ICON_CACHE_UPDATE = ecore_event_type_new();
    EFREET_EVENT_DESKTOP_CACHE_UPDATE = ecore_event_type_new();
    EFREET_EVENT_DESKTOP_CACHE_BUILD = ecore_event_type_new();

    themes = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_theme_free));
    icons = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_free));
    fallbacks = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_icon_fallback_free));
    desktops = eina_hash_string_superfast_new(NULL);

    eldbus_init();
    if (efreet_cache_update)
    {
        conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
        if (conn)
        {
            Eldbus_Object *obj;

            obj = eldbus_object_get(conn, BUS, PATH);
            proxy = eldbus_proxy_get(obj, INTERFACE);
            eldbus_proxy_signal_handler_add(proxy, "IconCacheUpdate", icon_cache_update, NULL);
            eldbus_proxy_signal_handler_add(proxy, "DesktopCacheUpdate", desktop_cache_update, NULL);

            eldbus_proxy_call(proxy, "Register", on_send_register, NULL, -1, "s", efreet_language_get());

            /*
             * TODO: Needed?
             eldbus_name_owner_changed_callback_add(conn, BUS, on_name_owner_changed,
             conn, EINA_TRUE);
             */
        }
        else
        {
            /* TODO: Run cache process directly */
        }
    }

    return 1;
error:
    if (themes) eina_hash_free(themes);
    themes = NULL;
    if (icons) eina_hash_free(icons);
    icons = NULL;
    if (fallbacks) eina_hash_free(fallbacks);
    fallbacks = NULL;
    if (desktops) eina_hash_free(desktops);
    desktops = NULL;

    efreet_cache_edd_shutdown();
    return 0;
}
コード例 #9
0
int
main(int argc, char **argv)
{
    /* TODO:
     * - Add file monitor on files, so that we catch changes on files
     *   during whilst this program runs.
     * - Maybe linger for a while to reduce number of cache re-creates.
     */
    Efreet_Cache_Hash hash;
    Efreet_Cache_Version version;
    Eina_List *dirs = NULL;
    Eina_List *systemdirs = NULL;
    Eina_List *extra_dirs = NULL;
    Eina_List *l = NULL;
    Eina_Inarray *stack = NULL;
    int priority = 0;
    char *dir = NULL;
    char *path;
    int lockfd = -1, tmpfd;
    int changed = 0;
    int i;
    char file[PATH_MAX] = { '\0' };
    char util_file[PATH_MAX] = { '\0' };
    mode_t um;

    if (!eina_init()) goto eina_error;
    _efreet_desktop_cache_log_dom =
        eina_log_domain_register("efreet_desktop_cache", EFREET_DEFAULT_LOG_COLOR);
    if (_efreet_desktop_cache_log_dom < 0)
    {
        EINA_LOG_ERR("Efreet: Could not create a log domain for efreet_desktop_cache.");
        return -1;
    }

    for (i = 1; i < argc; i++)
    {
        if (!strcmp(argv[i], "-v"))
            eina_log_domain_level_set("efreet_desktop_cache", EINA_LOG_LEVEL_DBG);
        else if ((!strcmp(argv[i], "-h")) ||
                 (!strcmp(argv[i], "-help")) ||
                 (!strcmp(argv[i], "--h")) ||
                 (!strcmp(argv[i], "--help")))
        {
            printf("Options:\n");
            printf("  -v              Verbose mode\n");
            printf("  -d dir1 dir2    Extra dirs\n");
            exit(0);
        }
        else if (!strcmp(argv[i], "-d"))
        {
            while ((i < (argc - 1)) && (argv[(i + 1)][0] != '-'))
                extra_dirs = eina_list_append(extra_dirs, argv[++i]);
        }
    }
    extra_dirs = eina_list_sort(extra_dirs, -1, EINA_COMPARE_CB(strcmp));

#ifdef HAVE_SYS_RESOURCE_H
    setpriority(PRIO_PROCESS, 0, 19);
#elif _WIN32
    SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
#endif

    /* init external subsystems */
    if (!eet_init()) goto eet_error;
    if (!ecore_init()) goto ecore_error;

    efreet_cache_update = 0;
    /* finish efreet init */
    if (!efreet_init()) goto efreet_error;

    /* create homedir */
    snprintf(file, sizeof(file), "%s/efreet", efreet_cache_home_get());
    if (!ecore_file_exists(file))
    {
        if (!ecore_file_mkpath(file)) goto efreet_error;
        efreet_setowner(file);
    }

    /* lock process, so that we only run one copy of this program */
    lockfd = cache_lock_file();
    if (lockfd == -1) goto efreet_error;

    edd = efreet_desktop_edd();
    if (!edd) goto edd_error;

    /* read user dirs from old cache */
    ef = eet_open(efreet_desktop_util_cache_file(), EET_FILE_MODE_READ);
    if (ef)
    {
        old_file_ids = eet_data_read(ef, efreet_hash_string_edd(), "file_id");
        eet_close(ef);
    }

    /* create cache */
    snprintf(file, sizeof(file), "%s.XXXXXX", efreet_desktop_cache_file());
    /* set secure umask for temporary files */
    um = umask(0077);
    tmpfd = mkstemp(file);
    umask(um);
    if (tmpfd < 0) goto error;
    close(tmpfd);
    ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
    if (!ef) goto error;

    snprintf(util_file, sizeof(util_file), "%s.XXXXXX", efreet_desktop_util_cache_file());
    /* set secure umask for temporary files */
    um = umask(0077);
    tmpfd = mkstemp(util_file);
    umask(um);
    if (tmpfd < 0) goto error;
    close(tmpfd);
    util_ef = eet_open(util_file, EET_FILE_MODE_READ_WRITE);
    if (!util_ef) goto error;

    /* write cache version */
    version.major = EFREET_DESKTOP_UTILS_CACHE_MAJOR;
    version.minor = EFREET_DESKTOP_UTILS_CACHE_MINOR;
    eet_data_write(util_ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1);
    version.major = EFREET_DESKTOP_CACHE_MAJOR;
    version.minor = EFREET_DESKTOP_CACHE_MINOR;
    eet_data_write(ef, efreet_version_edd(), EFREET_CACHE_VERSION, &version, 1);

    desktops = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_desktop_free));

    file_ids = eina_hash_string_superfast_new(NULL);
    paths = eina_hash_string_superfast_new(NULL);

    mime_types = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    categories = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    startup_wm_class = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    generic_name = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    comment = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));
    exec = eina_hash_string_superfast_new(EINA_FREE_CB(efreet_cache_array_string_free));

    dirs = efreet_default_dirs_get(efreet_data_home_get(), efreet_data_dirs_get(),
                                                                    "applications");
    if (!dirs) goto error;
    stack = eina_inarray_new(sizeof(struct stat), 16);
    if (!stack) goto error;

    EINA_LIST_FREE(dirs, path)
     {
        char file_id[PATH_MAX] = { '\0' };

        eina_inarray_flush(stack);
        if (!cache_scan(stack, path, file_id, priority++, 1, &changed))
          goto error;
        systemdirs = eina_list_append(systemdirs, path);
     }
コード例 #10
0
String WebsiteDataStore::cacheDirectoryFileSystemRepresentation(const String& directoryName)
{
    return WebCore::pathByAppendingComponent(String::fromUTF8(efreet_cache_home_get()), directoryName);
}
コード例 #11
0
WK_EXPORT int WebProcessMainEfl(int argc, char* argv[])
{
    // WebProcess should be launched with an option.
    if (argc != 2)
        return 1;

    if (!eina_init())
        return 1;

    if (!ecore_init()) {
        // Could not init ecore.
        eina_shutdown();
        return 1;
    }

#ifdef HAVE_ECORE_X
    XSetExtensionErrorHandler(dummyExtensionErrorHandler);

    if (!ecore_x_init(0)) {
        // Could not init ecore_x.
        // PlatformScreenEfl and systemBeep() functions
        // depend on ecore_x functionality.
        ecore_shutdown();
        eina_shutdown();
        return 1;
    }
#endif

#if !GLIB_CHECK_VERSION(2, 35, 0)
    g_type_init();
#endif

    if (!ecore_main_loop_glib_integrate())
        return 1;

    JSC::initializeThreading();
    WTF::initializeMainThread();

    RunLoop::initializeMainRunLoop();

    SoupSession* session = WebCore::ResourceHandle::defaultSession();
    const char* httpProxy = getenv("http_proxy");
    if (httpProxy) {
        const char* noProxy = getenv("no_proxy");
        SoupProxyURIResolver* resolverEfl = soupProxyResolverWkNew(httpProxy, noProxy);
        soup_session_add_feature(session, SOUP_SESSION_FEATURE(resolverEfl));
        g_object_unref(resolverEfl);
    }

    // Set SOUP cache.
    String soupCacheDirectory = String::fromUTF8(efreet_cache_home_get()) + "/WebKitEfl";
    SoupCache* soupCache = soup_cache_new(soupCacheDirectory.utf8().data(), SOUP_CACHE_SINGLE_USER);
    soup_session_add_feature(session, SOUP_SESSION_FEATURE(soupCache));
    soup_cache_load(soupCache);

    int socket = atoi(argv[1]);

    ChildProcessInitializationParameters parameters;
    parameters.connectionIdentifier = socket;

    WebProcess::shared().initialize(parameters);

    RunLoop::run();

    soup_cache_flush(soupCache);
    soup_cache_dump(soupCache);
    g_object_unref(soupCache);

    ecore_x_shutdown();
    ecore_shutdown();
    eina_shutdown();

    return 0;

}
コード例 #12
0
ファイル: e_utils.c プロジェクト: FlorentRevest/Enlightenment
E_API char *
e_util_shell_env_path_eval(const char *path)
{
   /* evaluate things like:
    * $HOME/bling -> /home/user/bling
    * $HOME/bin/$HOSTNAME/blah -> /home/user/bin/localhost/blah
    * etc. etc.
    */
   const char *p, *v2, *v1 = NULL;
   char buf[PATH_MAX], *pd, *s, *vp;
   char *v = NULL;
   int esc = 0, invar = 0;

   for (p = path, pd = buf; (pd < (buf + sizeof(buf) - 1)); p++)
     {
        if (invar)
          {
             if (!((isalnum(*p)) || (*p == '_')))
               {
                  v2 = p;
                  invar = 0;
                  if ((v2 - v1) > 1)
                    {
                       s = alloca(v2 - v1);
                       strncpy(s, v1 + 1, v2 - v1 - 1);
                       s[v2 - v1 - 1] = 0;
                       if (strncmp(s, "XDG", 3))
                         v = getenv(s);
                       else
                         {
                            if (!strcmp(s, "XDG_CONFIG_HOME"))
                              v = (char *)efreet_config_home_get();
                            else if (!strcmp(s, "XDG_CACHE_HOME"))
                              v = (char *)efreet_cache_home_get();
                            else if (!strcmp(s, "XDG_DATA_HOME"))
                              v = (char *)efreet_data_home_get();
                            else if (!strcmp(s, "XDG_DESKTOP_DIR"))
                              v = (char *)efreet_desktop_dir_get();
                            else if (!strcmp(s, "XDG_DOWNLOAD_DIR"))
                              v = (char *)efreet_download_dir_get();
                            else if (!strcmp(s, "XDG_TEMPLATES_DIR"))
                              v = (char *)efreet_templates_dir_get();
                            else if (!strcmp(s, "XDG_PUBLICSHARE_DIR"))
                              v = (char *)efreet_public_share_dir_get();
                            else if (!strcmp(s, "XDG_DOCUMENTS_DIR"))
                              v = (char *)efreet_documents_dir_get();
                            else if (!strcmp(s, "XDG_MUSIC_DIR"))
                              v = (char *)efreet_music_dir_get();
                            else if (!strcmp(s, "XDG_PICTURES_DIR"))
                              v = (char *)efreet_pictures_dir_get();
                            else if (!strcmp(s, "XDG_VIDEOS_DIR"))
                              v = (char *)efreet_videos_dir_get();
                            else if (!strcmp(s, "XDG_RUNTIME_DIR"))
                              v = (char *)efreet_runtime_dir_get();
                         }

                       if (v)
                         {
                            vp = v;
                            while ((*vp) && (pd < (buf + sizeof(buf) - 1)))
                              {
                                 *pd = *vp;
                                 vp++;
                                 pd++;
                              }
                         }
                    }
                  if (pd < (buf + sizeof(buf) - 1))
                    {
                       *pd = *p;
                       pd++;
                    }
               }
          }
        else
          {
             if (esc)
               {
                  *pd = *p;
                  pd++;
               }
             else
               {
                  if (*p == '\\') esc = 1;
                  else if (*p == '$')
                    {
                       invar = 1;
                       v1 = p;
                    }
                  else
                    {
                       *pd = *p;
                       pd++;
                    }
               }
          }
        if (*p == 0) break;
     }
   *pd = 0;
   return strdup(buf);
}
コード例 #13
0
ファイル: WebContextEfl.cpp プロジェクト: Wrichik1999/webkit
String WebContext::platformDefaultApplicationCacheDirectory() const
{
    return String::fromUTF8(efreet_cache_home_get()) + "/WebKitEfl/Applications";
}