static Eina_Bool __upload_completed_cb(void *data, int type, Ecore_Con_Event_Url_Complete *ev) { char buf[BUFFER_SIZE_MAX]; const Eina_List *headers = NULL, *it; const char *header = NULL; Share_Data *sd = NULL; json_object_put(jarray); jarray = NULL; json_object_put(jparent); jparent = NULL; if (ev->status != 200) { LOG("E_SHARE/" DROPNAME ": This is not supposed to happen. The server returned status code: %d\n", ev->status); return ECORE_CALLBACK_RENEW; } headers = ecore_con_url_response_headers_get(ev->url_con); EINA_LIST_FOREACH(headers, it, header) { if (strncmp(header, RECOGNITION_STRING, (sizeof(RECOGNITION_STRING) - 1)) == 0) { sd = ecore_con_url_data_get(ev->url_con); strlcpy(buf, (char*)(header + sizeof(RECOGNITION_STRING) - 1), sizeof(buf)); asprintf(&sd->url, "%s", buf); e_share_upload_completed(sd); ecore_con_url_free(ev->url_con); break; } } return ECORE_CALLBACK_CANCEL; }
static Eina_Bool _complete_cb(void *data, int type, void *event) { Ecore_Con_Event_Url_Complete *ev = reinterpret_cast<Ecore_Con_Event_Url_Complete *>(event); FileDownloader *fd = reinterpret_cast<FileDownloader *>(data); if (data == ecore_con_url_data_get(ev->url_con)) { fd->completeCb(ev->status); } return ECORE_CALLBACK_RENEW; }
static Eina_Bool _progress_cb(void *data, int type, void *event) { Ecore_Con_Event_Url_Progress *ev = reinterpret_cast<Ecore_Con_Event_Url_Progress *>(event); FileDownloader *fd = reinterpret_cast<FileDownloader *>(data); if (data == ecore_con_url_data_get(ev->url_con)) { fd->progressCb(ev->down.now, ev->down.total); } return ECORE_CALLBACK_RENEW; }
Eina_Bool _url_complete_cb(void *data, int type, void *event_info) { Ecore_Con_Event_Url_Complete *url_complete = reinterpret_cast<Ecore_Con_Event_Url_Complete *>(event_info); CalaosCameraView *view = reinterpret_cast<CalaosCameraView *>(data); if (view != ecore_con_url_data_get(url_complete->url_con)) return true; cDebugDom("camera") << "completed: " << view->buffer.size(); view->requestCompleted(); return true; }
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(); }
static Eina_Bool _url_complete_cb(void *data, int type, void *event_info) { Ecore_Con_Event_Url_Complete *url_complete = event_info; struct _request *req = ecore_con_url_data_get(url_complete->url_con); int nbytes = ecore_con_url_received_bytes_get(url_complete->url_con); printf("\n"); printf("download completed with status code: %d\n", url_complete->status); printf("Total size of downloaded file: %ld bytes\n", req->size); printf("Total size of downloaded file: %d bytes " "(from received_bytes_get)\n", nbytes); ecore_main_loop_quit(); return EINA_TRUE; }
Eina_Bool _url_data_cb(void *data, int type, void *event_info) { Ecore_Con_Event_Url_Data *url_data = reinterpret_cast<Ecore_Con_Event_Url_Data *>(event_info); CalaosCameraView *view = reinterpret_cast<CalaosCameraView *>(data); if (view != ecore_con_url_data_get(url_data->url_con)) return true; view->buffer.reserve(view->buffer.size() + url_data->size); std::copy(url_data->data, url_data->data + url_data->size, std::back_inserter(view->buffer)); if (view->headers.size() <= 0) { const Eina_List *headers, *l; void *str; headers = ecore_con_url_response_headers_get(url_data->url_con); EINA_LIST_FOREACH(headers, l, str) { if (!str) continue; string s((char *)str); vector<string> tokens; Utils::replace_str(s, "\n", ""); Utils::replace_str(s, "\r", ""); Utils::split(s, tokens, ":", 2); string key = tokens[0]; Utils::trim_left(key, " "); Utils::trim_right(key, " "); string val = tokens[1]; Utils::trim_left(val, " "); Utils::trim_right(val, " "); cDebugDom("camera") << "add key: \"" << key << "\" with value: \"" << val << "\""; view->headers.Add(key, val); } } view->processData(); return true; }
static Eina_Bool _url_progress_cb(void *data, int type, void *event_info) { Ecore_Con_Event_Url_Progress *url_progress = event_info; float percent; if (url_progress->down.total > 0) { struct _request *req = ecore_con_url_data_get(url_progress->url_con); req->size = url_progress->down.now; percent = (url_progress->down.now / url_progress->down.total) * 100; printf("Total of download complete: %0.1f (%0.0f)%%\n", percent, url_progress->down.now); } return EINA_TRUE; }