Exemplo n.º 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;
}
Exemplo n.º 2
0
void efl_egueb_io_request_free(Efl_Egueb_IO_Request *thiz)
{
	/* just mark it for later */
	if (thiz->in_event)
	{
		thiz->destroy = EINA_TRUE;
		thiz->in_event = EINA_FALSE;
		return;
	}

	if (thiz->data)
	{
		if (thiz->descriptor->free)
			thiz->descriptor->free(thiz);
		thiz->data = NULL;
	}

	if (thiz->binbuf)
	{
		eina_binbuf_free(thiz->data);
		thiz->data = NULL;
	}
	if (thiz->conn)
	{
		ecore_con_url_free(thiz->conn);
		thiz->conn = NULL;
	}
	free(thiz);
}
Exemplo n.º 3
0
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();
        }
}
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;
}
Exemplo n.º 5
0
static void
_update_done(void)
{
   if (url_up)
     {
        ecore_con_url_free(url_up);
        url_up = NULL;
     }
}
Exemplo n.º 6
0
/**
 * @brief Frees a Store_Add structure.
 * @param sa Store_Add structure to free.
 */
void
store_add_free(Store_Add *sa)
{
   if (sa->ec) ecore_con_url_free(sa->ec);
   if (sa->data.buf) eina_strbuf_free(sa->data.buf);
   if (sa->ev.ed) ecore_event_handler_del(sa->ev.ed);
   if (sa->ev.ec) ecore_event_handler_del(sa->ev.ec);
   free(sa);
}
Exemplo n.º 7
0
static void
_elm_url_free(Elm_Url *r)
{
   ecore_con_url_free(r->target);
   eina_binbuf_free(r->download);
   ecore_event_handler_del(r->handler.progress);
   ecore_event_handler_del(r->handler.done);
   ecore_event_handler_del(r->handler.data);
   eina_stringshare_del(r->url);
   free(r);
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
CalaosCameraView::~CalaosCameraView()
{
    if (ecurl)
        ecore_con_url_free(ecurl);

    DelMemberObject(clip);
    evas_object_del(clip);
    DelMemberObject(camImage);
    evas_object_del(camImage);

    ecore_event_handler_del(handler_data);
    ecore_event_handler_del(handler_complete);
}
Exemplo n.º 10
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();
}
Exemplo n.º 11
0
EAPI int
ecore_con_url_shutdown(void)
{
   Ecore_Con_Url *url_con;
   Ecore_Fd_Handler *fd_handler;
   if (_init_count == 0) return 0;
   --_init_count;
   if (_init_count) return _init_count;
   if (_curl_timer)
     {
        ecore_timer_del(_curl_timer);
        _curl_timer = NULL;
     }
   EINA_LIST_FREE(_url_con_list, url_con)
     ecore_con_url_free(url_con);
   EINA_LIST_FREE(_fd_hd_list, fd_handler)
     ecore_main_fd_handler_del(fd_handler);
   _c_shutdown();
   ecore_shutdown();
   return 0;
}
Exemplo n.º 12
0
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();
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
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();
        }
}
Exemplo n.º 15
0
void CalaosCameraView::processData()
{
    if (!formatDetected)
    {
        //first frame, we need to look for the boundary
        //and for content-type/content-length if present
        if (buffer.size() < 4)
            return; //need more data

        if (buffer[0] != '-' || buffer[1] != '-')
        {
            //try to detect of the data is directly the jpeg picture
            if (buffer[0] == 0xFF && buffer[1] == 0xD8)
            {
                cWarningDom("camera") << "Data seems to be a single frame.";
                single_frame = true;
            }
            else
            {
                cWarningDom("camera") << "Wrong start of frame, give up!";
                format_error = true;
            }

            formatDetected = true;
            return;
        }

        //search for the line end after the boundary to get the boundary text
        int end, next;
        if (!readEnd(2, end, next))
        {
            if (buffer.size() > 500)
            {
                cWarningDom("camera") << "Boundary not found, give up!";
                format_error = true;
            }

            return; //need more data;
        }

        //get boundary
        boundary = string((char *)&buffer[0], end);

        cDebugDom("camera") << "Found boundary \"" << boundary << "\"";

        int i = next;
        while (readEnd(next, end, next))
        {
            int len = end - i;

            if (len == 0)
            {
                //line is empty, data starts now
                nextDataStart = next;
                formatDetected = true;
                scanpos = 0;
                break;
            }

            if (len > 15)
            {
                string s((char *)&buffer[i], len);
                if (Utils::strStartsWith(s, "Content-Length", Utils::CaseInsensitive))
                {
                    Utils::from_string(s.substr(15), nextContentLength);
                    cDebugDom("camera") << "Found content length header: \"" << nextContentLength << "\"";
                    //nextContentLength = -1; //to test code without content-length header
                }
            }

            i = next;
        }

        if (!formatDetected)
        {
            cWarningDom("camera") << "need more data...";
            return;
        }
    }

    if (formatDetected && !single_frame)
    {
        //we should be positionned at the start of data
        //small check to be sure
        if (buffer.size() <= nextDataStart)
        {
            cWarningDom("camera") << "need more data...";
            return;
        }

        if (!(buffer[nextDataStart] == 0xFF && buffer[nextDataStart + 1] == 0xD8))
        {
            cWarningDom("camera") << "Wrong image data.";
            format_error = true;

            EcoreTimer::singleShot(0, [=]()
            {
                cDebugDom("camera") << "Cancel stream";
                ecore_con_url_free(ecurl);
                ecurl = nullptr;
            });

            return;
        }

        if (nextContentLength >= 0)
        {
            //the content-length is known, fast path
            if ((int)buffer.size() < nextContentLength + nextDataStart + 2)
                return; //need more data

            cDebugDom("camera") << "Set new frame";

            evas_object_image_memfile_set(camImage, &buffer[nextDataStart], nextContentLength, NULL, NULL);
            //evas_object_image_size_get(camImage, &w, &h);

            if (buffer[nextDataStart + nextContentLength] == '\r') //assume a \n always follows \r
                nextContentLength += 2;
            else if (buffer[nextDataStart + nextContentLength] == '\n')
                nextContentLength += 1;

            //remove unused data from buffer
            auto iter = buffer.begin();
            buffer.erase(iter, iter + (nextDataStart + nextContentLength));

            //reset for next frame
            nextContentLength = -1;
            formatDetected = false;
            nextDataStart = 0;
            scanpos = 0;
        }
        else
        {
            uint i = 0;
            cDebugDom("camera") << "scanpos: " << scanpos;
            for (i = nextDataStart + scanpos;
                 i < buffer.size() - boundary.length();i++)
            {
                if (buffer[i] == '-' && buffer[i + 1] == '-' &&
                    !boundary.compare(0, boundary.length(), (const char *)&buffer[i], boundary.length()))
                {
                    //boundary found
                    //check for newline between boundary and data
                    nextContentLength = i - nextDataStart;
                    if (buffer[i - 2] == '\r')
                        nextContentLength -= 2;
                    else if (buffer[i - 1] == '\n')
                        nextContentLength -= 1;

                    evas_object_image_memfile_set(camImage, &buffer[nextDataStart], nextContentLength, NULL, NULL);
                    //evas_object_image_size_get(camImage, &w, &h);

                    if (buffer[nextDataStart + nextContentLength] == '\r') //assume a \n always follows \r
                        nextContentLength += 2;
                    else if (buffer[nextDataStart + nextContentLength] == '\n')
                        nextContentLength += 1;

                    //remove unused data from buffer
                    auto iter = buffer.begin();
                    buffer.erase(iter, iter + (nextDataStart + nextContentLength));

                    //reset for next frame
                    nextContentLength = -1;
                    formatDetected = false;
                    nextDataStart = 0;
                    scanpos = 0;
                    cDebugDom("camera") << "scanpos: " << scanpos << " --> return";
                    return;
                }
            }

            scanpos = i - nextDataStart;
            cDebugDom("camera") << "--> scanpos: " << scanpos;
        }
    }
}
Exemplo n.º 16
0
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;
}
Exemplo n.º 17
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;
}
Exemplo n.º 18
0
void CalaosCameraView::stop()
{
    if (ecurl)
        ecore_con_url_free(ecurl);
    ecurl = nullptr;
}