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; }
/*============================================================================* * Global * *============================================================================*/ Efl_Egueb_IO_Request * efl_egueb_io_request_new(Egueb_Dom_String *location, const Efl_Egueb_IO_Request_Descriptor *descriptor, void *data) { Efl_Egueb_IO_Request *thiz; const char *filename; if (!location) return NULL; filename = egueb_dom_string_chars_get(location); thiz = calloc(1, sizeof(Efl_Egueb_IO_Request)); thiz->descriptor = descriptor; thiz->data = data; if (!strncmp(filename, "file://", 7)) { Enesim_Stream *s; s = enesim_stream_file_new(filename + 7, "r"); if (s) { DBG("Data '%s' loaded correctly", filename); thiz->in_event = EINA_TRUE; if (thiz->descriptor->completion) thiz->descriptor->completion(thiz, s); enesim_stream_unref(s); thiz->in_event = EINA_FALSE; } } else if (!strncmp(filename, "http://", 7)) { thiz->conn = ecore_con_url_new(filename); thiz->binbuf = eina_binbuf_new(); ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _efl_egueb_io_request_url_completion_cb, thiz); ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _efl_egueb_io_request_url_data_cb, thiz); ecore_con_url_get(thiz->conn); } else { WRN("Unsupported schema '%s'", filename); free(thiz); thiz = NULL; goto done; } if (thiz->destroy) { efl_egueb_io_request_free(thiz); return NULL; } done: return thiz; }
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(); }
Elm_Url * _elm_url_download(const char *url, Elm_Url_Done done_cb, Elm_Url_Cancel cancel_cb, Elm_Url_Progress progress_cb, const void *data) { Ecore_Con_Url *target; Elm_Url *r; ecore_con_url_init(); target = ecore_con_url_new(url); if (!target) goto on_error; #if defined(HAVE_GETUID) && defined(HAVE_GETEUID) if (getuid() == geteuid()) #endif { if (getenv("http_proxy")) ecore_con_url_proxy_set(target, getenv("http_proxy")); if (getenv("https_proxy")) ecore_con_url_proxy_set(target, getenv("https_proxy")); if (getenv("ftp_proxy")) ecore_con_url_proxy_set(target, getenv("ftp_proxy")); } r = malloc(sizeof (Elm_Url)); if (!r) goto on_error; r->url = eina_stringshare_add(url); r->cb.done = done_cb; r->cb.cancel = cancel_cb; r->cb.progress = progress_cb; r->data = data; r->download = eina_binbuf_new(); r->target = target; r->handler.progress = ecore_event_handler_add(ECORE_CON_EVENT_URL_PROGRESS, _elm_url_progress, r); r->handler.done = ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _elm_url_done, r); r->handler.data = ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _elm_url_data, r); if (!ecore_con_url_get(r->target)) { _elm_url_free(r); cancel_cb((void*) data, NULL, -1); return NULL; } return r; on_error: ecore_con_url_shutdown(); cancel_cb((void*) data, NULL, -1); return NULL; }
static Ecore_Con_Url * _fetch(Eina_Strbuf *sb) { Ecore_Con_Url *f; const char *qs; qs = eina_strbuf_string_get(sb); if (!qs) return NULL; f = ecore_con_url_new(qs); if (!f) return NULL; ecore_con_url_additional_header_add (f, "user-agent", "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"); ecore_con_url_get(f); return f; }
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"); }
END_TEST START_TEST(ecore_con_test_ecore_con_url_create) { Ecore_Con_Url *url; int ret; ret = eina_init(); fail_if(ret != 1); ret = ecore_con_url_init(); fail_if(ret != 1); url = ecore_con_url_new("http://google.com"); fail_if(!url); ecore_con_url_free(url); ret = ecore_con_url_shutdown(); fail_if(ret != 0); ret = eina_shutdown(); }
/** * Creates a custom connection object. * * Creates and initializes a new Ecore_Con_Url for a custom request (e.g. HEAD, * SUBSCRIBE and other obscure HTTP requests). This object should be used like * one created with ecore_con_url_new(). * * @param url URL that will receive requests * @param custom_request Custom request (e.g. GET, POST, HEAD, PUT, etc) * * @return NULL on error, a new Ecore_Con_Url on success. * * @ingroup Ecore_Con_Url_Group * * @see ecore_con_url_new() * @see ecore_con_url_url_set() */ EAPI Ecore_Con_Url * ecore_con_url_custom_new(const char *url, const char *custom_request) { #ifdef HAVE_CURL Ecore_Con_Url *url_con; if (!url) return NULL; if (!custom_request) return NULL; url_con = ecore_con_url_new(url); if (!url_con) return NULL; curl_easy_setopt(url_con->curl_easy, CURLOPT_CUSTOMREQUEST, custom_request); return url_con; #else return NULL; url = NULL; custom_request = NULL; #endif }
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; }
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; }
/** * @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; }