[Scummvm-git-logs] scummvm master -> 6fa7322a6a21e8f5ce5bd976da098761eca1f831
bluegr
bluegr at gmail.com
Sun Nov 3 18:48:38 CET 2019
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
47b67342d6 NETWORKING: Improve libcurl error handling
6fa7322a6a NETWORKING: Try loading the CA bundle from DATA_PATH
Commit: 47b67342d6205b2491a49d0da2183b921c73ee46
https://github.com/scummvm/scummvm/commit/47b67342d6205b2491a49d0da2183b921c73ee46
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2019-11-03T19:48:34+02:00
Commit Message:
NETWORKING: Improve libcurl error handling
Error messages for failed requests are now printed as warnings.
Changed paths:
backends/networking/curl/connectionmanager.cpp
backends/networking/curl/networkreadstream.cpp
backends/networking/curl/networkreadstream.h
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp
index 34a9701..557fcf0 100644
--- a/backends/networking/curl/connectionmanager.cpp
+++ b/backends/networking/curl/connectionmanager.cpp
@@ -184,20 +184,19 @@ void ConnectionManager::processTransfers() {
int messagesInQueue;
CURLMsg *curlMsg;
while ((curlMsg = curl_multi_info_read(_multi, &messagesInQueue))) {
- CURL *easyHandle = curlMsg->easy_handle;
+ if (curlMsg->msg == CURLMSG_DONE) {
+ CURL *easyHandle = curlMsg->easy_handle;
- NetworkReadStream *stream;
- curl_easy_getinfo(easyHandle, CURLINFO_PRIVATE, &stream);
- if (stream)
- stream->finished();
+ NetworkReadStream *stream = nullptr;
+ curl_easy_getinfo(easyHandle, CURLINFO_PRIVATE, &stream);
- if (curlMsg->msg == CURLMSG_DONE) {
- debug(9, "ConnectionManager: SUCCESS (%d - %s)", curlMsg->data.result, curl_easy_strerror(curlMsg->data.result));
+ if (stream)
+ stream->finished(curlMsg->data.result);
+
+ curl_multi_remove_handle(_multi, easyHandle);
} else {
- warning("ConnectionManager: FAILURE (CURLMsg (%d))", curlMsg->msg);
+ warning("Unknown libcurl message type %d", curlMsg->msg);
}
-
- curl_multi_remove_handle(_multi, easyHandle);
}
}
diff --git a/backends/networking/curl/networkreadstream.cpp b/backends/networking/curl/networkreadstream.cpp
index 59d2a54..b41a3c3 100644
--- a/backends/networking/curl/networkreadstream.cpp
+++ b/backends/networking/curl/networkreadstream.cpp
@@ -26,6 +26,7 @@
#include "backends/networking/curl/networkreadstream.h"
#include "backends/networking/curl/connectionmanager.h"
#include "base/version.h"
+#include "common/debug.h"
namespace Networking {
@@ -64,6 +65,7 @@ int NetworkReadStream::curlProgressCallbackOlder(void *p, double dltotal, double
void NetworkReadStream::init(const char *url, curl_slist *headersList, const byte *buffer, uint32 bufferSize, bool uploading, bool usingPatch, bool post) {
_eos = _requestComplete = false;
+ _errorBuffer = (char *)calloc(CURL_ERROR_SIZE, 1);
_sendingContentsBuffer = nullptr;
_sendingContentsSize = _sendingContentsPos = 0;
_progressDownloaded = _progressTotal = 0;
@@ -77,6 +79,7 @@ void NetworkReadStream::init(const char *url, curl_slist *headersList, const byt
curl_easy_setopt(_easy, CURLOPT_HEADERDATA, this);
curl_easy_setopt(_easy, CURLOPT_HEADERFUNCTION, curlHeadersCallback);
curl_easy_setopt(_easy, CURLOPT_URL, url);
+ curl_easy_setopt(_easy, CURLOPT_ERRORBUFFER, _errorBuffer);
curl_easy_setopt(_easy, CURLOPT_VERBOSE, 0L);
curl_easy_setopt(_easy, CURLOPT_FOLLOWLOCATION, 1L); //probably it's OK to have it always on
curl_easy_setopt(_easy, CURLOPT_HTTPHEADER, headersList);
@@ -120,6 +123,7 @@ void NetworkReadStream::init(const char *url, curl_slist *headersList, const byt
void NetworkReadStream::init(const char *url, curl_slist *headersList, Common::HashMap<Common::String, Common::String> formFields, Common::HashMap<Common::String, Common::String> formFiles) {
_eos = _requestComplete = false;
+ _errorBuffer = (char *)calloc(CURL_ERROR_SIZE, 1);
_sendingContentsBuffer = nullptr;
_sendingContentsSize = _sendingContentsPos = 0;
_progressDownloaded = _progressTotal = 0;
@@ -133,6 +137,7 @@ void NetworkReadStream::init(const char *url, curl_slist *headersList, Common::H
curl_easy_setopt(_easy, CURLOPT_HEADERDATA, this);
curl_easy_setopt(_easy, CURLOPT_HEADERFUNCTION, curlHeadersCallback);
curl_easy_setopt(_easy, CURLOPT_URL, url);
+ curl_easy_setopt(_easy, CURLOPT_ERRORBUFFER, _errorBuffer);
curl_easy_setopt(_easy, CURLOPT_VERBOSE, 0L);
curl_easy_setopt(_easy, CURLOPT_FOLLOWLOCATION, 1L); //probably it's OK to have it always on
curl_easy_setopt(_easy, CURLOPT_HTTPHEADER, headersList);
@@ -205,6 +210,7 @@ NetworkReadStream::~NetworkReadStream() {
if (_easy)
curl_easy_cleanup(_easy);
free(_bufferCopy);
+ free(_errorBuffer);
}
bool NetworkReadStream::eos() const {
@@ -223,8 +229,18 @@ uint32 NetworkReadStream::read(void *dataPtr, uint32 dataSize) {
return actuallyRead;
}
-void NetworkReadStream::finished() {
+void NetworkReadStream::finished(uint32 errorCode) {
_requestComplete = true;
+
+ char *url = nullptr;
+ curl_easy_getinfo(_easy, CURLINFO_EFFECTIVE_URL, &url);
+
+ if (errorCode == CURLE_OK) {
+ debug(9, "NetworkReadStream: %s - Request succeeded", url);
+ } else {
+ warning("NetworkReadStream: %s - Request failed (%d - %s)", url, errorCode,
+ strlen(_errorBuffer) ? _errorBuffer : curl_easy_strerror((CURLcode)errorCode));
+ }
}
long NetworkReadStream::httpResponseCode() const {
diff --git a/backends/networking/curl/networkreadstream.h b/backends/networking/curl/networkreadstream.h
index 7d19286..468fce7 100644
--- a/backends/networking/curl/networkreadstream.h
+++ b/backends/networking/curl/networkreadstream.h
@@ -38,6 +38,7 @@ class NetworkReadStream: public Common::ReadStream {
CURL *_easy;
Common::MemoryReadWriteStream _backingStream;
bool _eos, _requestComplete;
+ char *_errorBuffer;
const byte *_sendingContentsBuffer;
uint32 _sendingContentsSize;
uint32 _sendingContentsPos;
@@ -111,7 +112,7 @@ public:
*
* @note It's called on failure too.
*/
- void finished();
+ void finished(uint32 errorCode);
/**
* Returns HTTP response code from inner CURL handle.
Commit: 6fa7322a6a21e8f5ce5bd976da098761eca1f831
https://github.com/scummvm/scummvm/commit/6fa7322a6a21e8f5ce5bd976da098761eca1f831
Author: Bastien Bouclet (bastien.bouclet at gmail.com)
Date: 2019-11-03T19:48:34+02:00
Commit Message:
NETWORKING: Try loading the CA bundle from DATA_PATH
Changed paths:
backends/networking/curl/connectionmanager.cpp
backends/networking/curl/connectionmanager.h
backends/networking/curl/networkreadstream.cpp
diff --git a/backends/networking/curl/connectionmanager.cpp b/backends/networking/curl/connectionmanager.cpp
index 557fcf0..21381d9 100644
--- a/backends/networking/curl/connectionmanager.cpp
+++ b/backends/networking/curl/connectionmanager.cpp
@@ -26,6 +26,7 @@
#include "backends/networking/curl/connectionmanager.h"
#include "backends/networking/curl/networkreadstream.h"
#include "common/debug.h"
+#include "common/fs.h"
#include "common/system.h"
#include "common/timer.h"
@@ -98,6 +99,29 @@ uint32 ConnectionManager::getCloudRequestsPeriodInMicroseconds() {
return TIMER_INTERVAL * CLOUD_PERIOD;
}
+const char *ConnectionManager::getCaCertPath() {
+#if defined(DATA_PATH)
+ static enum {
+ kNotInitialized,
+ kFileNotFound,
+ kFileExists
+ } state = kNotInitialized;
+
+ if (state == kNotInitialized) {
+ Common::FSNode node(DATA_PATH"/cacert.pem");
+ state = node.exists() ? kFileExists : kFileNotFound;
+ }
+
+ if (state == kFileExists) {
+ return DATA_PATH"/cacert.pem";
+ } else {
+ return nullptr;
+ }
+#else
+ return nullptr;
+#endif
+}
+
//private goes here:
void connectionsThread(void *ignored) {
diff --git a/backends/networking/curl/connectionmanager.h b/backends/networking/curl/connectionmanager.h
index 6c261b8..a01d115 100644
--- a/backends/networking/curl/connectionmanager.h
+++ b/backends/networking/curl/connectionmanager.h
@@ -118,6 +118,9 @@ public:
Common::String urlEncode(Common::String s) const;
static uint32 getCloudRequestsPeriodInMicroseconds();
+
+ /** Return the path to the CA certificates bundle. */
+ static const char *getCaCertPath();
};
/** Shortcut for accessing the connection manager. */
diff --git a/backends/networking/curl/networkreadstream.cpp b/backends/networking/curl/networkreadstream.cpp
index b41a3c3..b8f06b7 100644
--- a/backends/networking/curl/networkreadstream.cpp
+++ b/backends/networking/curl/networkreadstream.cpp
@@ -91,6 +91,11 @@ void NetworkReadStream::init(const char *url, curl_slist *headersList, const byt
curl_easy_setopt(_easy, CURLOPT_SSL_VERIFYPEER, 0);
#endif
+ const char *caCertPath = ConnMan.getCaCertPath();
+ if (caCertPath) {
+ curl_easy_setopt(_easy, CURLOPT_CAINFO, caCertPath);
+ }
+
#if LIBCURL_VERSION_NUM >= 0x072000
// CURLOPT_XFERINFOFUNCTION introduced in libcurl 7.32.0
// CURLOPT_PROGRESSFUNCTION is used as a backup plan in case older version is used
@@ -149,6 +154,11 @@ void NetworkReadStream::init(const char *url, curl_slist *headersList, Common::H
curl_easy_setopt(_easy, CURLOPT_SSL_VERIFYPEER, 0);
#endif
+ const char *caCertPath = ConnMan.getCaCertPath();
+ if (caCertPath) {
+ curl_easy_setopt(_easy, CURLOPT_CAINFO, caCertPath);
+ }
+
#if LIBCURL_VERSION_NUM >= 0x072000
// CURLOPT_XFERINFOFUNCTION introduced in libcurl 7.32.0
// CURLOPT_PROGRESSFUNCTION is used as a backup plan in case older version is used
More information about the Scummvm-git-logs
mailing list