aboutsummaryrefslogtreecommitdiff
path: root/backends/networking/curl
diff options
context:
space:
mode:
authorAlexander Tkachev2016-05-18 14:08:05 +0600
committerAlexander Tkachev2016-08-24 16:07:55 +0600
commite743a65636a674def45e955cb7a5632aead2a033 (patch)
treedf7e6a3d3ea4e612e9810693349bffadbbc2c399 /backends/networking/curl
parent5df8c5140292520bafe92efa94935a776d63d108 (diff)
downloadscummvm-rg350-e743a65636a674def45e955cb7a5632aead2a033.tar.gz
scummvm-rg350-e743a65636a674def45e955cb7a5632aead2a033.tar.bz2
scummvm-rg350-e743a65636a674def45e955cb7a5632aead2a033.zip
CLOUD: Add Dropbox into CloudManager's configs
This commit adds: * ConfMan's new "cloud" domain; * CloudManager's init() method, where it loads keys from "cloud" configs domain; * CurlJsonRequest's addHeader() and addPostField() methods; * temporary Storage's printInfo() method; * DropboxStorage's implementation of printInfo(), which is using access token and user id; * DropboxStorage's loadFromConfig() static method to load access token and user id from configs and create a Storage instance with those; * temporary DropboxStorage's authThroughConsole() static method, which guides user through auth process from the console. So, in CloudManager's init() implementation ScummVM checks that there is "current_storage_type" key in "cloud" domain of configs, and loads corresponding storage if there is such key. If there is no such key, ScummVM offers user to auth with Dropbox. That's done through console, and thus it's temporary (it also requires restarting ScummVM twice and manually editing config.ini file).
Diffstat (limited to 'backends/networking/curl')
-rw-r--r--backends/networking/curl/connectionmanager.cpp4
-rw-r--r--backends/networking/curl/connectionmanager.h3
-rw-r--r--backends/networking/curl/curljsonrequest.cpp16
-rw-r--r--backends/networking/curl/curljsonrequest.h8
-rw-r--r--backends/networking/curl/networkreadstream.cpp7
-rw-r--r--backends/networking/curl/networkreadstream.h3
6 files changed, 34 insertions, 7 deletions
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp
index 8c718e019b..d34eab23e8 100644
--- a/backends/networking/curl/connectionmanager.cpp
+++ b/backends/networking/curl/connectionmanager.cpp
@@ -39,8 +39,8 @@ ConnectionManager::~ConnectionManager() {
curl_global_cleanup();
}
-NetworkReadStream *ConnectionManager::makeRequest(const char *url) {
- NetworkReadStream *stream = new NetworkReadStream(url);
+NetworkReadStream *ConnectionManager::makeRequest(const char *url, curl_slist *headersList, Common::String postFields) {
+ NetworkReadStream *stream = new NetworkReadStream(url, headersList, postFields);
curl_multi_add_handle(_multi, stream->getEasyHandle());
return stream;
}
diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h
index fadcdf1372..b83de6191a 100644
--- a/backends/networking/curl/connectionmanager.h
+++ b/backends/networking/curl/connectionmanager.h
@@ -26,6 +26,7 @@
#include "common/str.h"
typedef void CURLM;
+struct curl_slist;
namespace Networking {
@@ -38,7 +39,7 @@ public:
ConnectionManager();
virtual ~ConnectionManager();
- NetworkReadStream *makeRequest(const char *url);
+ NetworkReadStream *makeRequest(const char *url, curl_slist *headersList, Common::String postFields);
void handle();
};
diff --git a/backends/networking/curl/curljsonrequest.cpp b/backends/networking/curl/curljsonrequest.cpp
index f5a7a7c8d0..0c6363467a 100644
--- a/backends/networking/curl/curljsonrequest.cpp
+++ b/backends/networking/curl/curljsonrequest.cpp
@@ -30,7 +30,7 @@
namespace Networking {
-CurlJsonRequest::CurlJsonRequest(Callback cb, const char *url) : Request(cb), _stream(0), _contentsStream(DisposeAfterUse::YES) {
+CurlJsonRequest::CurlJsonRequest(Callback cb, const char *url) : Request(cb), _stream(0), _headersList(0), _contentsStream(DisposeAfterUse::YES) {
_url = url;
}
@@ -57,7 +57,7 @@ char *CurlJsonRequest::getPreparedContents() {
}
bool CurlJsonRequest::handle(ConnectionManager &manager) {
- if (!_stream) _stream = manager.makeRequest(_url);
+ if (!_stream) _stream = manager.makeRequest(_url, _headersList, _postFields);
if (_stream) {
const int kBufSize = 16*1024;
@@ -83,4 +83,16 @@ bool CurlJsonRequest::handle(ConnectionManager &manager) {
return false;
}
+void CurlJsonRequest::addHeader(Common::String header) {
+ _headersList = curl_slist_append(_headersList, header.c_str());
+}
+
+void CurlJsonRequest::addPostField(Common::String keyValuePair) {
+ if (_postFields == "")
+ _postFields = keyValuePair;
+ else
+ _postFields += "&" + keyValuePair;
+}
+
+
} //end of namespace Networking
diff --git a/backends/networking/curl/curljsonrequest.h b/backends/networking/curl/curljsonrequest.h
index e9634393dc..17df9693f2 100644
--- a/backends/networking/curl/curljsonrequest.h
+++ b/backends/networking/curl/curljsonrequest.h
@@ -26,6 +26,8 @@
#include "backends/cloud/request.h"
#include "common/memstream.h"
+struct curl_slist;
+
namespace Networking {
class NetworkReadStream;
@@ -33,6 +35,8 @@ class NetworkReadStream;
class CurlJsonRequest : public Cloud::Request {
const char *_url;
NetworkReadStream *_stream;
+ curl_slist *_headersList;
+ Common::String _postFields;
Common::MemoryWriteStreamDynamic _contentsStream;
/** Prepares raw bytes from _contentsStream to be parsed with Common::JSON::parse(). */
@@ -43,6 +47,10 @@ public:
virtual ~CurlJsonRequest();
virtual bool handle(ConnectionManager &manager);
+
+ void addHeader(Common::String header);
+
+ void addPostField(Common::String header);
};
} //end of namespace Networking
diff --git a/backends/networking/curl/networkreadstream.cpp b/backends/networking/curl/networkreadstream.cpp
index b8cb81aca2..f2af4fd50c 100644
--- a/backends/networking/curl/networkreadstream.cpp
+++ b/backends/networking/curl/networkreadstream.cpp
@@ -34,7 +34,9 @@ static size_t curlDataCallback(char *d, size_t n, size_t l, void *p) {
return 0;
}
-NetworkReadStream::NetworkReadStream(const char *url): _easy(0), _eos(false), _requestComplete(false) {
+NetworkReadStream::NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields):
+ _easy(0), _eos(false), _requestComplete(false)
+{
_easy = curl_easy_init();
curl_easy_setopt(_easy, CURLOPT_WRITEFUNCTION, curlDataCallback);
curl_easy_setopt(_easy, CURLOPT_WRITEDATA, this); //so callback can call us
@@ -42,6 +44,9 @@ NetworkReadStream::NetworkReadStream(const char *url): _easy(0), _eos(false), _r
curl_easy_setopt(_easy, CURLOPT_HEADER, 0L);
curl_easy_setopt(_easy, CURLOPT_URL, url);
curl_easy_setopt(_easy, CURLOPT_VERBOSE, 0L);
+ curl_easy_setopt(_easy, CURLOPT_HTTPHEADER, headersList);
+ curl_easy_setopt(_easy, CURLOPT_POSTFIELDSIZE, postFields.size());
+ curl_easy_setopt(_easy, CURLOPT_COPYPOSTFIELDS, postFields.c_str());
}
NetworkReadStream::~NetworkReadStream() {
diff --git a/backends/networking/curl/networkreadstream.h b/backends/networking/curl/networkreadstream.h
index 0333e4fb16..bc4b761ba7 100644
--- a/backends/networking/curl/networkreadstream.h
+++ b/backends/networking/curl/networkreadstream.h
@@ -28,6 +28,7 @@
#include "common/str.h"
typedef void CURL;
+struct curl_slist;
namespace Networking {
@@ -36,7 +37,7 @@ class NetworkReadStream: public Common::MemoryReadWriteStream {
bool _eos, _requestComplete;
public:
- NetworkReadStream(const char *url);
+ NetworkReadStream(const char *url, curl_slist *headersList, Common::String postFields);
virtual ~NetworkReadStream();
CURL *getEasyHandle() const { return _easy; }