diff options
author | Alexander Tkachev | 2016-06-10 15:01:56 +0600 |
---|---|---|
committer | Alexander Tkachev | 2016-08-24 16:07:55 +0600 |
commit | 3e6503743c2f5d90c64bf37e943338c33fc58d2b (patch) | |
tree | 3255606a88811badf45f14b4fa8cbbdc56d30964 /backends/networking | |
parent | 6a93e8dd09ae2eeab616d14189a58633fd928c07 (diff) | |
download | scummvm-rg350-3e6503743c2f5d90c64bf37e943338c33fc58d2b.tar.gz scummvm-rg350-3e6503743c2f5d90c64bf37e943338c33fc58d2b.tar.bz2 scummvm-rg350-3e6503743c2f5d90c64bf37e943338c33fc58d2b.zip |
CLOUD: Add Request::date()
Used in SavesSyncRequest to update Storage's last sync date.
Diffstat (limited to 'backends/networking')
-rw-r--r-- | backends/networking/curl/curlrequest.cpp | 19 | ||||
-rw-r--r-- | backends/networking/curl/curlrequest.h | 1 | ||||
-rw-r--r-- | backends/networking/curl/request.cpp | 2 | ||||
-rw-r--r-- | backends/networking/curl/request.h | 14 |
4 files changed, 36 insertions, 0 deletions
diff --git a/backends/networking/curl/curlrequest.cpp b/backends/networking/curl/curlrequest.cpp index 6ef0e346af..3a143e5af8 100644 --- a/backends/networking/curl/curlrequest.cpp +++ b/backends/networking/curl/curlrequest.cpp @@ -66,6 +66,25 @@ void CurlRequest::restart() { //with no stream available next handle() will create another one } +Common::String CurlRequest::date() const { + if (_stream) { + Common::String headers = _stream->responseHeaders(); + const char *cstr = headers.c_str(); + const char *position = strstr(cstr, "Date: "); + + if (position) { + Common::String result = ""; + char c; + for (const char *i = position + 6; c = *i, c != 0; ++i) { + if (c == '\n' || c == '\r') break; + result += c; + } + return result; + } + } + return ""; +} + void CurlRequest::setHeaders(Common::Array<Common::String> &headers) { curl_slist_free_all(_headersList); _headersList = nullptr; diff --git a/backends/networking/curl/curlrequest.h b/backends/networking/curl/curlrequest.h index 5c06b58107..68ea3a58d7 100644 --- a/backends/networking/curl/curlrequest.h +++ b/backends/networking/curl/curlrequest.h @@ -55,6 +55,7 @@ public: virtual void handle(); virtual void restart(); + virtual Common::String date() const; /** Replaces all headers with the passed array of headers. */ virtual void setHeaders(Common::Array<Common::String> &headers); diff --git a/backends/networking/curl/request.cpp b/backends/networking/curl/request.cpp index d2f91586a0..4a2704fc76 100644 --- a/backends/networking/curl/request.cpp +++ b/backends/networking/curl/request.cpp @@ -60,6 +60,8 @@ void Request::retry(uint32 seconds) { RequestState Request::state() const { return _state; } +Common::String Request::date() const { return ""; } + void Request::finishError(ErrorResponse error) { _state = FINISHED; if (_errorCallback) (*_errorCallback)(error); diff --git a/backends/networking/curl/request.h b/backends/networking/curl/request.h index de5308fa52..6a1bc12594 100644 --- a/backends/networking/curl/request.h +++ b/backends/networking/curl/request.h @@ -182,6 +182,20 @@ public: /** Returns Request's current state. */ RequestState state() const; + + /** + * Return date this Request received from server. + * It could be extracted from "Date" header, + * which is kept in NetworkReadStream. + * + * @note not all Requests do that, so "" is returned + * to indicate the date is unknown. That's also true + * if no server response available or no "Date" header + * was passed. + * + * @returns date from "Date" response header. + */ + virtual Common::String date() const; }; } // End of namespace Networking |