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; }
static Eina_Bool _url_compl_cb(void *data, int type EINA_UNUSED, void *event_info) { url_test *info = data; Ecore_Con_Event_Url_Complete *ev = event_info; printf("Total downloaded bytes = %d\n", ecore_con_url_received_bytes_get(ev->url_con)); if (info->_tmpfd) { _free_url_test(info); ecore_con_url_free(ev->url_con); } else { fail_unless(ecore_con_url_url_set(ev->url_con, "ftp://ftp.kernel.org/pub/linux/kernel/README")); ecore_con_url_verbose_set (ev->url_con, EINA_FALSE); info->_tmpfd = eina_file_mkstemp("ecore_con_test_XXXXXX.html", &(info->_test_file)); if (info->_tmpfd < 0) { free(info); ecore_con_url_free(ev->url_con); fail(); } ecore_con_url_fd_set(ev->url_con, info->_tmpfd); if (!ecore_con_url_get(ev->url_con)) { _free_url_test(info); ecore_con_url_free(ev->url_con); fail(); } } return EINA_FALSE; }
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; }