|
@@ -18,7 +18,7 @@ namespace oxygine
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const unsigned int ID_DONE = sysEventID('C', 'D', 'N');
|
|
const unsigned int ID_DONE = sysEventID('C', 'D', 'N');
|
|
|
- const unsigned int ID_PROGRESS = sysEventID('C', 'P', 'R');
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
void mainThreadFunc(const ThreadDispatcher::message& msg)
|
|
void mainThreadFunc(const ThreadDispatcher::message& msg)
|
|
|
{
|
|
{
|
|
@@ -62,12 +62,6 @@ namespace oxygine
|
|
|
|
|
|
|
|
task->releaseRef();
|
|
task->releaseRef();
|
|
|
} break;
|
|
} break;
|
|
|
-
|
|
|
|
|
- case ID_PROGRESS:
|
|
|
|
|
- {
|
|
|
|
|
- HttpRequestTaskCURL* task = (HttpRequestTaskCURL*)msg.cbData;
|
|
|
|
|
- //task->dispatchProgress((int)(size_t)msg.arg2, (int)(size_t)msg.arg1);
|
|
|
|
|
- } break;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -131,6 +125,7 @@ namespace oxygine
|
|
|
{
|
|
{
|
|
|
if (msg->msg == CURLMSG_DONE)
|
|
if (msg->msg == CURLMSG_DONE)
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
#ifdef OX_HAS_CPP11 //msg broken in VS2010
|
|
#ifdef OX_HAS_CPP11 //msg broken in VS2010
|
|
|
curl_multi_remove_handle(multi_handle, msg->easy_handle);
|
|
curl_multi_remove_handle(multi_handle, msg->easy_handle);
|
|
|
core::getMainThreadDispatcher().postCallback(ID_DONE, msg->easy_handle, (void*)msg->data.result, mainThreadFunc, 0);
|
|
core::getMainThreadDispatcher().postCallback(ID_DONE, msg->easy_handle, (void*)msg->data.result, mainThreadFunc, 0);
|
|
@@ -164,23 +159,6 @@ namespace oxygine
|
|
|
multi_handle = 0;
|
|
multi_handle = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- size_t HttpRequestTaskCURL::cbXRefInfoFunction(void* userData, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
|
|
|
|
- {
|
|
|
|
|
- return ((HttpRequestTaskCURL*)userData)->_cbXRefInfoFunction(dltotal, dlnow);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- size_t HttpRequestTaskCURL::_cbXRefInfoFunction(curl_off_t dltotal, curl_off_t dlnow)
|
|
|
|
|
- {
|
|
|
|
|
- core::getMainThreadDispatcher().postCallback(ID_PROGRESS, (void*)dltotal, (void*)dlnow, mainThreadFunc, this);
|
|
|
|
|
-
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- int HttpRequestTaskCURL::cbProgressFunction(void* userData, double dltotal, double dlnow, double ultotal, double ulnow)
|
|
|
|
|
- {
|
|
|
|
|
- return ((HttpRequestTaskCURL*)userData)->_cbXRefInfoFunction((curl_off_t) dltotal, (curl_off_t)dlnow);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
size_t HttpRequestTaskCURL::cbWriteFunction(char* d, size_t n, size_t l, void* userData)
|
|
size_t HttpRequestTaskCURL::cbWriteFunction(char* d, size_t n, size_t l, void* userData)
|
|
|
{
|
|
{
|
|
@@ -191,7 +169,8 @@ namespace oxygine
|
|
|
size_t HttpRequestTaskCURL::_cbWriteFunction(char* d, size_t n, size_t l)
|
|
size_t HttpRequestTaskCURL::_cbWriteFunction(char* d, size_t n, size_t l)
|
|
|
{
|
|
{
|
|
|
size_t size = n * l;
|
|
size_t size = n * l;
|
|
|
- if (!_continueDownload || _ok)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (_ok)
|
|
|
write(d, size);
|
|
write(d, size);
|
|
|
|
|
|
|
|
return size;
|
|
return size;
|
|
@@ -206,17 +185,24 @@ namespace oxygine
|
|
|
size_t HttpRequestTaskCURL::_cbHeaderFunction(char* d, size_t n, size_t l)
|
|
size_t HttpRequestTaskCURL::_cbHeaderFunction(char* d, size_t n, size_t l)
|
|
|
{
|
|
{
|
|
|
size_t s = n*l;
|
|
size_t s = n*l;
|
|
|
- if (_continueDownload && !_ok)
|
|
|
|
|
|
|
+ if (s > 255)//ignore unknown headers
|
|
|
|
|
+ return s;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ int contentLength = 0;
|
|
|
|
|
+ if (sscanf(d, "Content-Length: %d", &contentLength) == 1)
|
|
|
|
|
+ {
|
|
|
|
|
+ _expectedContentSize = contentLength;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int responseCode = 0;
|
|
|
|
|
+ if (sscanf(d, "HTTP/1.1 %d ", &responseCode) == 1 ||
|
|
|
|
|
+ sscanf(d, "HTTP/1.0 %d ", &responseCode) == 1)
|
|
|
{
|
|
{
|
|
|
- const char *GOOD1 = "HTTP/1.1 200 ";
|
|
|
|
|
- const char *GOOD2 = "HTTP/1.1 206 ";
|
|
|
|
|
- if (s >= sizeof(GOOD1) && (
|
|
|
|
|
- memcmp(d, GOOD1, sizeof(GOOD1)) == 0 ||
|
|
|
|
|
- memcmp(d, GOOD2, sizeof(GOOD2)) == 0))
|
|
|
|
|
- {
|
|
|
|
|
- _ok = true;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ _responseCode = responseCode;
|
|
|
|
|
+ _ok = _responseCodeChecker(_responseCode);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return s;
|
|
return s;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -250,14 +236,7 @@ namespace oxygine
|
|
|
|
|
|
|
|
curl_easy_setopt(_easy, CURLOPT_NOPROGRESS, 0);
|
|
curl_easy_setopt(_easy, CURLOPT_NOPROGRESS, 0);
|
|
|
|
|
|
|
|
-#ifdef CURLOPT_XFERINFOFUNCTION
|
|
|
|
|
- curl_easy_setopt(_easy, CURLOPT_XFERINFOFUNCTION, HttpRequestTaskCURL::cbXRefInfoFunction);
|
|
|
|
|
- curl_easy_setopt(_easy, CURLOPT_XFERINFODATA, this);
|
|
|
|
|
-#else
|
|
|
|
|
|
|
|
|
|
- curl_easy_setopt(_easy, CURLOPT_PROGRESSFUNCTION, HttpRequestTaskCURL::cbProgressFunction);
|
|
|
|
|
- curl_easy_setopt(_easy, CURLOPT_PROGRESSDATA, this);
|
|
|
|
|
-#endif
|
|
|
|
|
curl_easy_setopt(_easy, CURLOPT_FOLLOWLOCATION, true);
|
|
curl_easy_setopt(_easy, CURLOPT_FOLLOWLOCATION, true);
|
|
|
|
|
|
|
|
|
|
|