コード例 #1
0
void CalaosCameraView::play()
{
    if (ecurl)
        ecore_con_url_free(ecurl);

    ecurl = ecore_con_url_new(cameraUrl.c_str());
    if (!ecurl)
    {
        cErrorDom("camera") << "Failed to create ecore_con_url!";
        return;
    }
    ecore_con_url_data_set(ecurl, this);
    ecore_con_url_ssl_verify_peer_set(ecurl, false);

    single_frame = false;
    buffer.clear();
    formatDetected = false;
    format_error = false;
    nextContentLength = -1;

    if (!ecore_con_url_get(ecurl))
    {
        cErrorDom("camera") << "Could not realize request!";
        ecore_con_url_free(ecurl);
        ecurl = nullptr;
    }

    cDebugDom("camera") << "Request started to " << cameraUrl;
}
コード例 #2
0
ファイル: cosm.c プロジェクト: alexandre72/edams
/*
 *Add location feed to cosm. Return EINA_TRUE if success.
 */
Eina_Bool
cosm_location_feed_add(Location *location)
{
	Ecore_Con_Url *cosm_url = NULL;
	char *s;

	//Don't add cosm url feed if already there...
	if(!location || (location_cosm_feedid_get(location) != 0) || !edams_settings_cosm_apikey_get())
		return EINA_FALSE;

	debug(MSG_COSM, _("Creating cosm feed '%s'..."), location_name_get(location));

   	ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, (Ecore_Event_Handler_Cb)_url_feed_add_complete_cb,NULL);
   	cosm_url = ecore_con_url_custom_new("http://api.cosm.com/v2/feeds", "POST");
   	if (!cosm_url)
     {
		debug(MSG_COSM, _("Can't create Ecore_Con_Url object"));
		return EINA_FALSE;
     }
	//ecore_con_url_verbose_set(cosm_url, edams_settings_debug_get());
   	ecore_con_url_additional_header_add(cosm_url, "X-ApiKey", edams_settings_cosm_apikey_get());;
    ecore_con_url_data_set(cosm_url, (void*)location);

    char *locale = setlocale(LC_NUMERIC, NULL);
     setlocale(LC_NUMERIC, "POSIX");

	cJSON *root,*fmt;
	root=cJSON_CreateObject();
	asprintf(&s, "%s sensor.basic", location_name_get(location));
	cJSON_AddItemToObject(root, "title", cJSON_CreateString(s));
	FREE(s);
	cJSON_AddItemToObject(root, "version", cJSON_CreateString("1.0.0"));
	cJSON_AddItemToObject(root, "location", fmt=cJSON_CreateObject());
	cJSON_AddStringToObject(fmt, "name", location_name_get(location));
	//cJSON_AddStringToObject(fmt, "description", location_description_get(location));
	cJSON_AddStringToObject(fmt, "disposition", "fixed");
	cJSON_AddStringToObject(fmt, "exposure", "indoor");
	cJSON_AddStringToObject(fmt, "domain", "physical");

	if(location_latitude_get(location) != -1)
		cJSON_AddNumberToObject(fmt, "lat", location_latitude_get(location));

	if(location_longitude_get(location) != -1)
		cJSON_AddNumberToObject(fmt, "lon", location_longitude_get(location));

	s = cJSON_PrintUnformatted(root);
	cJSON_Delete(root);
    setlocale(LC_NUMERIC, locale);

	if(!ecore_con_url_post(cosm_url, (void*)s, strlen(s), NULL))
	{
		debug(MSG_COSM, _("Can't realize url PUT request"));
		return EINA_FALSE;
	}
	FREE(s);

	return EINA_TRUE;
}/*cosm_location_feed_add*/
コード例 #3
0
END_TEST
#endif

START_TEST(ecore_con_test_ecore_con_url_download)
{
   Ecore_Con_Url *url;
   url_test *info;
   int ret;
#ifdef ECORE_CON_HTTP_TEST_URL
   const char link[] = ECORE_CON_HTTP_TEST_URL;
#else
   const char link[] = DEFAULT_LINK;
#endif
   char url_data[] = "test";

   ret = eina_init();
   fail_if(ret != 1);
   ret = ecore_con_url_init();
   fail_if(ret != 1);

   url = ecore_con_url_new(link);
   fail_if(!url);

   ecore_con_url_verbose_set(url, EINA_TRUE);

   fail_if (strcmp(ecore_con_url_url_get(url), link));

   ecore_con_url_data_set(url, url_data);
   fail_if (strcmp(ecore_con_url_data_get(url), url_data));

   info = (url_test *) malloc(sizeof(url_test));
   info->_tmpfd = 0;

   if (!ecore_con_url_get(url))
     {
        close(info->_tmpfd);
        free(info);
        ecore_con_url_free(url);
        fail();
     }
    else
     {
        ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
                                _url_compl_cb, info);
     }

   ret = ecore_con_url_shutdown();
   fail_if(ret != 0);
   ret = eina_shutdown();
}
コード例 #4
0
void sourcedrop_share(Share_Data *sd)
{
    Ecore_Con_Url *request_url = NULL;
    char post_data[BUFFER_SIZE_MAX];
    const char *json_encoded = NULL;
    char *url_encoded = NULL;

    EINA_SAFETY_ON_NULL_RETURN(sd);

    json_encoded = json_encode(sd->name, sd->content);
    request_url = ecore_con_url_new(SOURCEDROP_URL);
    url_encoded = url_encode(json_encoded);
    snprintf(post_data, (sizeof(post_data) - 1), "data=%s", url_encoded);
    free(url_encoded);
    ecore_con_url_data_set(request_url, (void*)sd);
    ecore_con_url_post(request_url, (void*)post_data, sizeof(post_data), "application/x-www-form-urlencoded"); 
}
コード例 #5
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;
}
コード例 #6
0
int
main(int argc, const char *argv[])
{
   Ecore_Con_Url *ec_url = NULL;
   struct _request *req;
   int fd;
   const char *filename = "downloadedfile.dat";

   if (argc < 2)
     {
        printf("need one parameter: <url>\n");
        return -1;
     }

   fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);

   if (fd == -1)
     {
        printf("error: could not open file for writing: \"%s\"\n",
               filename);
        return -1;
     }

   ecore_init();
   ecore_con_init();
   ecore_con_url_init();

   ec_url = ecore_con_url_new(argv[1]);
   if (!ec_url)
     {
        printf("error when creating ecore con url object.\n");
        goto end;
     }

   req = malloc(sizeof(*req));
   req->size = 0;
   ecore_con_url_data_set(ec_url, req);

   ecore_con_url_fd_set(ec_url, fd);

   ecore_event_handler_add(ECORE_CON_EVENT_URL_PROGRESS, _url_progress_cb, NULL);
   ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);

   if (!ecore_con_url_get(ec_url))
     {
        printf("could not realize request.\n");
        goto free_ec_url;
     }

   ecore_main_loop_begin();

free_ec_url:
   free(req);
   ecore_con_url_free(ec_url);
end:

   close(fd);
   ecore_con_url_shutdown();
   ecore_con_shutdown();
   ecore_shutdown();

   return 0;
}
コード例 #7
0
ファイル: store_main.c プロジェクト: gfriloux/smman
/**
 * @brief Store given data to store's url.
 * @param store Store structure.
 * @param buf Buffer to store.
 * @param len Length of @buf.
 * @param done_cb Callback to call when data is stored.
 * @param error_cb Callback to call if an error occured.
 * @param data Data to pass to callbacks.
 * @return EINA_TRUE if we try to store data.
 *         EINA_FALSE if an error occured when creating storing process.
 */
Eina_Bool
store_add(Store *store,
          const char *buf,
          size_t len,
          Store_Done_Cb done_cb,
          Store_Error_Cb error_cb,
          const void *data)
{
   Store_Add *sa;
   Eina_Bool r;

   sa = calloc(1, sizeof(Store_Add));
   if (!sa)
     {
        ERR("Failed to allocate Store_Add structure");
        return EINA_FALSE;
     }

   sa->ec = ecore_con_url_new(store->url);
   if (!sa->ec)
     {
        ERR("Failed to create ecore_con_url object");
        goto sa_free;
     }

   sa->data.buf = eina_strbuf_new();
   if (!sa->data.buf)
     {
        ERR("Failed to allocate storage buffer");
        goto sa_con_url_free;
     }

   sa->ev.ed = ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA,
                                       store_event_data, sa);
   if (!sa->ev.ed)
     {
        ERR("Failed to create event handler");
        goto sa_buf_free;
     }
   sa->ev.ec = ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
                                       store_event_complete, sa);
   if (!sa->ev.ec)
     {
        ERR("Failed to create event handler");
        goto sa_event_handler_free_ed;
     }

   sa->store = store;
   sa->cb.done = done_cb;
   sa->cb.error = error_cb;
   sa->cb.data = data;
   sa->data.sent = strdup(buf);
   DBG("store[%p] sa[%p] buf[%s]", store, sa, buf);
   ecore_con_url_data_set(sa->ec, sa);
   ecore_con_url_timeout_set(sa->ec, 10.0);
   r = ecore_con_url_post(sa->ec, buf, len, "text/json");
   if (!r)
     {
        ERR("Failed to issue POST method");
        goto sa_event_handler_free_ec;
     }

   return EINA_TRUE;

sa_event_handler_free_ec:
   ecore_event_handler_del(sa->ev.ec);
sa_event_handler_free_ed:
   ecore_event_handler_del(sa->ev.ed);
sa_buf_free:
   eina_strbuf_free(sa->data.buf);
sa_con_url_free:
   ecore_con_url_free(sa->ec);
sa_free:
   free(sa);
   return EINA_FALSE;
}