diff options
Diffstat (limited to 'backends/cloud/dropbox/curlrequest.cpp')
-rw-r--r-- | backends/cloud/dropbox/curlrequest.cpp | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/backends/cloud/dropbox/curlrequest.cpp b/backends/cloud/dropbox/curlrequest.cpp index 216b56c19e..1dfdd9e25f 100644 --- a/backends/cloud/dropbox/curlrequest.cpp +++ b/backends/cloud/dropbox/curlrequest.cpp @@ -23,55 +23,37 @@ #define FORBIDDEN_SYMBOL_ALLOW_ALL #include "backends/cloud/dropbox/curlrequest.h" +#include "backends/cloud/curl/networkreadstream.h" #include "common/debug.h" #include <curl/curl.h> namespace Cloud { namespace Dropbox { -static size_t curlDataCallback(char *d, size_t n, size_t l, void *p) { - debug("%p got %d more bytes", p, n * l); - return n * l; -} - -CurlRequest::CurlRequest(Callback cb, char *url) : Request(cb), _firstTime(true) { - _curlm = curl_multi_init(); +CurlRequest::CurlRequest(Callback cb, const char *url) : Request(cb), _firstTime(true), _stream(0) { _url = url; } CurlRequest::~CurlRequest() { - curl_multi_cleanup(_curlm); + if (_stream) delete _stream; } -bool CurlRequest::handle() { +bool CurlRequest::handle(ConnectionManager& manager) { if (_firstTime) { - CURL *eh = curl_easy_init(); - curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, curlDataCallback); - curl_easy_setopt(eh, CURLOPT_WRITEDATA, this); - curl_easy_setopt(eh, CURLOPT_HEADER, 0L); - curl_easy_setopt(eh, CURLOPT_URL, _url); - curl_easy_setopt(eh, CURLOPT_VERBOSE, 0L); - curl_multi_add_handle(_curlm, eh); - + _stream = manager.makeRequest(_url); _firstTime = false; } - int U; - curl_multi_perform(_curlm, &U); - - int Q; - CURLMsg *_curlMsg; - while ((_curlMsg = curl_multi_info_read(_curlm, &Q))) { - if (_curlMsg->msg == CURLMSG_DONE) { - CURL *e = _curlMsg->easy_handle; - debug("R: %d - %s\n", _curlMsg->data.result, curl_easy_strerror(_curlMsg->data.result)); - curl_multi_remove_handle(_curlm, e); - curl_easy_cleanup(e); + if (_stream) { + const int kBufSize = 10000; + char buf[kBufSize+1]; + uint32 readBytes = _stream->read(buf, kBufSize); + debug("%d", readBytes); + //if(readBytes != 0) debug("%s", buf); + if(_stream->eos()) { _callback(0); return true; - } else { - debug("E: CURLMsg (%d)\n", _curlMsg->msg); } } |