コード例 #1
0
ファイル: FileDownloader.cpp プロジェクト: meyerv/calaos_base
void FileDownloader::Cancel()
{
        if (!url_con)
                return;

        ecore_con_url_free(url_con);
        url_con = NULL;
        fclose(dl_file);

        if (dest.empty())
                ecore_file_unlink(tmpFile.c_str());

        Utils::logger("downloader") << Priority::DEBUG
                        << "FileDownloader: Download aborted! (" << url << ")"
                        << log4cpp::eol;

        IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                  "aborted",
                                  IPCData(new string(url), new DeletorT<string *>()),
                                  true);

        cb_signal.emit("aborted", &url);
        cb_signal_user.emit("aborted", &url, user_data);

        if (auto_destroy)
        {
                Destroy();
        }
}
コード例 #2
0
static Eina_Bool
_ephoto_on_config_save(void *data)
{
   Ephoto *ephoto = data;
   Eet_File *ef;
   char buf[4096], buf2[4096];

   snprintf(buf, sizeof(buf), "%s/.config/ephoto/ephoto.cfg", getenv("HOME"));
   snprintf(buf2, sizeof(buf2), "%s.tmp", buf);

   ef = eet_open(buf2, EET_FILE_MODE_WRITE);
   if (!ef) goto save_end;

   eet_data_write(ef, edd, "config", ephoto->config, 1);
   if (eet_close(ef)) goto save_end;

   if (!ecore_file_mv(buf2, buf)) goto save_end;

   INF("Config saved");

save_end:
   ecore_file_unlink(buf2);

   if (save_timer)
     {
        ecore_timer_del(save_timer);
        save_timer = NULL;
     }

   return ECORE_CALLBACK_CANCEL;
}
コード例 #3
0
void Config::saveStateCache()
{
    Eet_File *ef;
    std::string file = Utils::getCacheFile("iostates.cache");
    std::string tmp = file + "_tmp";
    ConfigStateCache *cache;

    cache = new ConfigStateCache;
    cache->version = CONFIG_STATES_CACHE_VERSION;
    cache->states = cache_states;

    ef = eet_open(tmp.c_str(), EET_FILE_MODE_WRITE);
    if (!ef)
    {
        cWarning() <<  "Could not open iostates.cache for write !";
        delete cache;
        return;
    }

    Eina_Bool ret = eet_data_write(ef, edd_cache, "calaos/states/cache", cache, EINA_TRUE);

    eet_close(ef);
    delete cache;

    if (ret)
    {
        ecore_file_unlink(file.c_str());
        ecore_file_mv(tmp.c_str(), file.c_str());
    }

    cInfo() <<  "State cache file written successfully (" << file << ")";
}
コード例 #4
0
void Config::SaveConfigRule()
{
    std::string file = Utils::getConfigFile(RULES_CONFIG);
    std::string tmp = file + "_tmp";

    cInfo() <<  "Saving " << file << "...";

    TiXmlDocument document;
    TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "UTF-8", "");
    TiXmlElement *rulesnode = new TiXmlElement("calaos:rules");
    rulesnode->SetAttribute("xmlns:calaos", "http://www.calaos.fr");
    document.LinkEndChild(decl);
    document.LinkEndChild(rulesnode);

    for (int i = 0;i < ListeRule::Instance().size();i++)
    {
        Rule *rule = ListeRule::Instance().get_rule(i);
        rule->SaveToXml(rulesnode);
    }

    if (document.SaveFile(tmp))
    {
        ecore_file_unlink(file.c_str());
        ecore_file_mv(tmp.c_str(), file.c_str());
    }

    cInfo() <<  "Done.";
}
コード例 #5
0
int
main(void)
{
   double start;
   Eina_Hash *headers;

   eina_init();
   ecore_init();
   ecore_file_init();

   if (ecore_file_exists(DST))
     ecore_file_unlink(DST);

   start = ecore_time_get();

   if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, NULL))
     {
        printf("Download started successfully:\n  URL: %s\n  DEST: %s\n", URL, DST);
        ecore_main_loop_begin();
        printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
        printf("Downloaded %lld bytes\n", ecore_file_size(DST));
     }
   else
     {
        printf("Error, can't start download\n");
        goto done;
     }

   headers = eina_hash_string_small_new(NULL);
   eina_hash_add(headers, "Content-type", "application/x-gzip");

   if (ecore_file_download_full(URL, DST_MIME, completion_cb, progress_cb, NULL, NULL, headers))
     {
        printf("Download started successfully:\n  URL: %s\n  DEST: %s\n", URL, DST_MIME);
        ecore_main_loop_begin();
        printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
        printf("Downloaded %lld bytes\n", ecore_file_size(DST));
     }
   else
     {
        printf("Error, can't start download\n");
        goto done;
     }

done:
   if (headers) eina_hash_free(headers);
   ecore_file_shutdown();
   ecore_shutdown();
   eina_shutdown();
   return 0;
}
コード例 #6
0
static void
_ex_file_download_dialog_response(Etk_Object *obj, int response_id, void *data)
{
   switch(response_id)
     {
      case ETK_RESPONSE_CANCEL:
	 ecore_file_download_abort_all();
	 ecore_file_unlink(data);
	 E_FREE(data);
	 etk_object_destroy(ETK_OBJECT(obj));
	 break;
      default:
	 break;
     }
}
コード例 #7
0
ファイル: ecore_file.c プロジェクト: caivega/efl-1
/**
 * @brief Delete the given directory and all its contents.
 *
 * @param  dir The name of the directory to delete.
 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
 *
 * This function delete @p dir and all its contents. If @p dir is a
 * link only the link is removed. It returns @c EINA_TRUE on success,
 * @c EINA_FALSE otherwise.
 */
EAPI Eina_Bool
ecore_file_recursive_rm(const char *dir)
{
   struct stat st;

#ifdef _WIN32
   char buf[PATH_MAX];

   if (readlink(dir, buf, sizeof(buf) - 1) > 0)
     return ecore_file_unlink(dir);
   if (stat(dir, &st) == -1)
     return EINA_FALSE;
#else
   if (lstat(dir, &st) == -1)
     return EINA_FALSE;
#endif

   if (S_ISDIR(st.st_mode))
     {
        Eina_File_Direct_Info *info;
        Eina_Iterator *it;
        int ret;

        ret = 1;
        it = eina_file_direct_ls(dir);
        EINA_ITERATOR_FOREACH(it, info)
          {
             if (!ecore_file_recursive_rm(info->path))
               ret = 0;
          }
        eina_iterator_free(it);

        if (!ecore_file_rmdir(dir)) ret = 0;
        if (ret)
            return EINA_TRUE;
        else
            return EINA_FALSE;
     }
コード例 #8
0
ファイル: FileDownloader.cpp プロジェクト: meyerv/calaos_base
void FileDownloader::completeCb(int status)
{
        ecore_con_url_free(url_con);
        url_con = NULL;

        fclose(dl_file);

        if (status >= 400 || status < 100)
        {
                string err = "Error code : " + Utils::to_string(status);

                IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                          "failed",
                                          IPCData(new string(err), new DeletorT<string *>()),
                                          true);

                cb_signal.emit("failed", &err);
                cb_signal_user.emit("failed", &err, user_data);

                Utils::logger("downloader") << Priority::ERROR
                                << "Download failed: " << err
                                << log4cpp::eol;

                if (dest.empty())
                        ecore_file_unlink(tmpFile.c_str());

                return;
        }

        Utils::logger("downloader") << Priority::DEBUG
                        << "FileDownloader: Download done. (" << url << ")"
                        << log4cpp::eol;

        if (!dest.empty())
        {
                IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                          "done",
                                          IPCData(new string(dest), new DeletorT<string *>()),
                                          true);

                cb_signal.emit("done", &dest);
                cb_signal_user.emit("done", &dest, user_data);
        }
        else
        {
                Buffer_CURL buff;

                dl_file = fopen(tmpFile.c_str(), "rb");
                fseek(dl_file, 0, SEEK_END);
                buff.bufsize = ftell(dl_file);
                fseek(dl_file, 0, SEEK_SET);
                buff.buffer = (char *)malloc(buff.bufsize);
                if (fread(buff.buffer, buff.bufsize, 1, dl_file) <= 0)
                        Utils::logger("downloader") << Priority::CRIT
                                        << "FileDownloader: fread failed ! (" << url << ")"
                                        << log4cpp::eol;
                fclose(dl_file);

                ecore_file_unlink(tmpFile.c_str());

                IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                          "done",
                                          IPCData(new Buffer_CURL(buff), new DeletorT<Buffer_CURL *>()),
                                          true);

                cb_signal.emit("done", &buff);
                cb_signal_user.emit("done", &buff, user_data);

                if (buff.buffer)
                        free(buff.buffer);
        }

        if (auto_destroy)
        {
                Destroy();
        }
}
コード例 #9
0
ファイル: FileDownloader.cpp プロジェクト: meyerv/calaos_base
bool FileDownloader::Start()
{
        Utils::logger("downloader") << Priority::DEBUG << "FileDownloader: Start download (" << url << ")" << log4cpp::eol;

        if (url_con)
        {
                Utils::logger("downloader") << Priority::WARN
                                << "A download is already in progress..."
                                << log4cpp::eol;

                return false;
        }

        url_con = ecore_con_url_new(url.c_str());
        if (!url_con)
        {
                string err = "Failed to create Ecore_Con_Url";

                IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                          "failed",
                                          IPCData(new string(err), new DeletorT<string *>()),
                                          true);

                cb_signal.emit("failed", &err);
                cb_signal_user.emit("failed", &err, user_data);

                Utils::logger("downloader") << Priority::ERROR
                                << "Download failed: " << err
                                << log4cpp::eol;

                return false;
        }

        if (dest.empty())
        {
                //Create a temporary file for download
                int cpt = 0;

                //Get a temporary filename
                do
                {
                        tmpFile = "/tmp/calaos" + Utils::to_string(getpid()) + "_download_tmp_";
                        tmpFile += Utils::to_string(cpt);
                        cpt++;
                }
                while (ecore_file_exists(tmpFile.c_str()));

                dl_file = fopen(tmpFile.c_str(), "wb");
        }
        else
        {
                dl_file = fopen(dest.c_str(), "wb");
        }

        if (!dl_file)
        {
                string err = "Failed to open file";

                IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                          "failed",
                                          IPCData(new string(err), new DeletorT<string *>()),
                                          true);

                cb_signal.emit("failed", &err);
                cb_signal_user.emit("failed", &err, user_data);

                Utils::logger("downloader") << Priority::ERROR
                                << "Download failed: " << err
                                << log4cpp::eol;

                ecore_con_url_free(url_con);
                url_con = NULL;

                return false;
        }

        ecore_con_url_fd_set(url_con, fileno(dl_file));
        ecore_con_url_data_set(url_con, this);
        ecore_con_url_ssl_verify_peer_set(url_con, false);

        bool ret = false;
        if (postData.empty())
        {
                ret = ecore_con_url_get(url_con);
        }
        else
        {
                ret = ecore_con_url_post(url_con, postData.c_str(), postData.length(), postContentType.c_str());
        }

        if (!ret)
        {
                string err = "Failed to call GET/POST";

                IPC::Instance().SendEvent("downloader::" + Utils::to_string(this),
                                          "failed",
                                          IPCData(new string(err), new DeletorT<string *>()),
                                          true);

                cb_signal.emit("failed", &err);
                cb_signal_user.emit("failed", &err, user_data);

                Utils::logger("downloader") << Priority::ERROR
                                << "Download failed: " << err
                                << log4cpp::eol;

                ecore_con_url_free(url_con);
                url_con = NULL;
                fclose(dl_file);

                if (dest.empty())
                        ecore_file_unlink(tmpFile.c_str());

                return false;
        }

        return true;
}
コード例 #10
0
JsonApiHandlerHttp::~JsonApiHandlerHttp()
{
    delete cameraDl;
    ecore_event_handler_del(exe_handler);
    ecore_file_unlink(tempfname.c_str());
}