diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-03-06 20:34:05 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-03-06 20:34:05 (GMT) |
commit | 81079295b8be14128b7e532d504b32280360532e (patch) | |
tree | 649f93c2059dcc2a7cf5bd4ace17c18c6913ac64 /src/uscxml/URL.cpp | |
parent | e385ba8adb0c77fea20c58c45b966193c23a4570 (diff) | |
download | uscxml-81079295b8be14128b7e532d504b32280360532e.zip uscxml-81079295b8be14128b7e532d504b32280360532e.tar.gz uscxml-81079295b8be14128b7e532d504b32280360532e.tar.bz2 |
Fixed issue with temporary files
Diffstat (limited to 'src/uscxml/URL.cpp')
-rw-r--r-- | src/uscxml/URL.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/uscxml/URL.cpp b/src/uscxml/URL.cpp index 1f180e4..4a4440d 100644 --- a/src/uscxml/URL.cpp +++ b/src/uscxml/URL.cpp @@ -26,10 +26,14 @@ namespace uscxml { URLImpl::URLImpl(const std::string& url) : _handle(NULL), _uri(url), _isDownloaded(false), _hasFailed(false) { - _handle = curl_easy_init(); - if (_handle == NULL) { - LOG(ERROR) << "curl_easy_init returned NULL, this is bad!"; + std::stringstream ss(_uri.path()); + std::string item; + while(std::getline(ss, item, '/')) { + if (item.length() == 0) + continue; + _pathComponents.push_back(item); } + } URLImpl::~URLImpl() { @@ -37,6 +41,15 @@ URLImpl::~URLImpl() { curl_easy_cleanup(_handle); } +CURL* URLImpl::getCurlHandle() { + if (_handle == NULL) { + _handle = curl_easy_init(); + if (_handle == NULL) + LOG(ERROR) << "curl_easy_init returned NULL, this is bad!"; + } + return _handle; +} + size_t URLImpl::writeHandler(void *ptr, size_t size, size_t nmemb, void *userdata) { URLImpl* url = (URLImpl*)userdata; url->_inContent.write((char*)ptr, size * nmemb); @@ -304,13 +317,13 @@ void URLFetcher::fetchURL(URL& url) { URLFetcher* instance = getInstance(); tthread::lock_guard<tthread::recursive_mutex> lock(instance->_mutex); - assert(url._impl->_handle != NULL); - if (url._impl->_handle == NULL) + CURL* handle = url._impl->getCurlHandle(); + assert(handle != NULL); + if (handle == NULL) return; - if (instance->_handlesToURLs.find(url._impl->_handle) == instance->_handlesToURLs.end()) { + if (instance->_handlesToURLs.find(handle) == instance->_handlesToURLs.end()) { CURLcode curlError; - CURL* handle = url._impl->_handle; (curlError = curl_easy_setopt(handle, CURLOPT_URL, url.asString().c_str())) == CURLE_OK || LOG(ERROR) << "Cannot set url to " << url.asString() << ": " << curl_easy_strerror(curlError); @@ -372,7 +385,7 @@ void URLFetcher::fetchURL(URL& url) { void URLFetcher::breakURL(URL& url) { URLFetcher* instance = getInstance(); - CURL* handle = url._impl->_handle; + CURL* handle = url._impl->getCurlHandle(); tthread::lock_guard<tthread::recursive_mutex> lock(instance->_mutex); if (instance->_handlesToURLs.find(handle) != instance->_handlesToURLs.end()) { |