From c7f8f82d632f3d205ef6de6377115ea0f7536302 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 22 Mar 2013 19:26:20 +0100 Subject: Use actual curl message for errors regarding URLs --- src/uscxml/Interpreter.cpp | 3 +++ src/uscxml/URL.cpp | 10 +++++----- src/uscxml/URL.h | 12 ++++++++++-- test/src/test-url.cpp | 1 + 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index d5c8b7f..0c466c9 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -87,6 +87,9 @@ Interpreter* Interpreter::fromURI(const std::string& uri) { // use curl for everything else std::stringstream ss; ss << absUrl; + if (absUrl.downloadFailed()) { + return NULL; + } ss.seekg(0); inputSource.setByteStream(ss); } diff --git a/src/uscxml/URL.cpp b/src/uscxml/URL.cpp index 7036e0a..a31b0c4 100644 --- a/src/uscxml/URL.cpp +++ b/src/uscxml/URL.cpp @@ -106,10 +106,10 @@ void URLImpl::downloadCompleted() { } } -void URLImpl::downloadFailed(int errorCode) { +void URLImpl::downloadFailed(CURLcode errorCode) { tthread::lock_guard lock(_mutex); - LOG(ERROR) << "Downloading " << asString() << " failed: " << strerror(errorCode); + LOG(ERROR) << "Downloading " << asString() << " failed: " << curl_easy_strerror(errorCode); _hasFailed = true; _isDownloaded = false; @@ -392,7 +392,7 @@ void URLFetcher::breakURL(URL& url) { tthread::lock_guard lock(instance->_mutex); if (instance->_handlesToURLs.find(handle) != instance->_handlesToURLs.end()) { - url.downloadFailed(0); + url.downloadFailed(CURLE_OK); curl_multi_remove_handle(instance->_multiHandle, handle); instance->_handlesToURLs.erase(handle); } @@ -496,6 +496,8 @@ void URLFetcher::perform() { curl_multi_remove_handle(_multiHandle, msg->easy_handle); _handlesToURLs.erase(msg->easy_handle); break; + default: + LOG(ERROR) << "Unhandled curl status"; case CURLM_BAD_HANDLE: case CURLM_BAD_EASY_HANDLE: case CURLM_OUT_OF_MEMORY: @@ -506,8 +508,6 @@ void URLFetcher::perform() { _handlesToURLs[msg->easy_handle].downloadFailed(msg->data.result); curl_multi_remove_handle(_multiHandle, msg->easy_handle); _handlesToURLs.erase(msg->easy_handle); - default: - LOG(ERROR) << "Unhandled curl status"; break; } } else { diff --git a/src/uscxml/URL.h b/src/uscxml/URL.h index 0e47607..61a225c 100644 --- a/src/uscxml/URL.h +++ b/src/uscxml/URL.h @@ -83,7 +83,11 @@ public: void downloadStarted(); void downloadCompleted(); - void downloadFailed(int errorCode); + void downloadFailed(CURLcode errorCode); + + bool downloadFailed() { + return _hasFailed; + } friend class URLFetcher; @@ -186,6 +190,10 @@ public: _impl->removeMonitor(monitor); } + bool downloadFailed() { + return _impl->downloadFailed(); + } + const bool isAbsolute() const { return _impl->isAbsolute(); } @@ -218,7 +226,7 @@ protected: void downloadCompleted() { return _impl->downloadCompleted(); } - void downloadFailed(int errorCode) { + void downloadFailed(CURLcode errorCode) { return _impl->downloadFailed(errorCode); } diff --git a/test/src/test-url.cpp b/test/src/test-url.cpp index 7b72250..f2d0cb9 100644 --- a/test/src/test-url.cpp +++ b/test/src/test-url.cpp @@ -26,6 +26,7 @@ int main(int argc, char** argv) { { Interpreter* interpreter = Interpreter::fromURI("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-execution.scxml"); + assert(interpreter); interpreter->interpret(); delete interpreter; } -- cgit v0.12