X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fcurl_uploader.cc;h=6fe7aba145c40ecfa2fd91f2ae035dee0d6f0a5b;hb=f706bbb9afd10472e81a051cd5db601d6404377c;hp=82dca98f888c01ae3dfeb2ef17c4cfbfa4d0f888;hpb=8963f0007af1a312017b9627c18b82ec2a577591;p=dcpomatic.git diff --git a/src/lib/curl_uploader.cc b/src/lib/curl_uploader.cc index 82dca98f8..6fe7aba14 100644 --- a/src/lib/curl_uploader.cc +++ b/src/lib/curl_uploader.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington + Copyright (C) 2015-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,19 +18,23 @@ */ + #include "curl_uploader.h" #include "exceptions.h" #include "config.h" #include "cross.h" #include "compose.hpp" +#include "dcpomatic_assert.h" #include #include "i18n.h" + using std::string; using std::cout; using std::function; + static size_t read_callback (void* ptr, size_t size, size_t nmemb, void* object) { @@ -38,11 +42,9 @@ read_callback (void* ptr, size_t size, size_t nmemb, void* object) return u->read_callback (ptr, size, nmemb); } + CurlUploader::CurlUploader (function set_status, function set_progress) : Uploader (set_status, set_progress) - , _file (0) - , _transferred (0) - , _total_size (0) { _curl = curl_easy_init (); if (!_curl) { @@ -54,24 +56,24 @@ CurlUploader::CurlUploader (function set_status, functiontms_user().c_str ()); - curl_easy_setopt (_curl, CURLOPT_PASSWORD, Config::instance()->tms_password().c_str ()); + curl_easy_setopt (_curl, CURLOPT_USERNAME, Config::instance()->tms_user().c_str()); + curl_easy_setopt (_curl, CURLOPT_PASSWORD, Config::instance()->tms_password().c_str()); } + CurlUploader::~CurlUploader () { - if (_file) { - fclose (_file); - } curl_easy_cleanup (_curl); } + void CurlUploader::create_directory (boost::filesystem::path) { /* this is done by libcurl */ } + void CurlUploader::upload_file (boost::filesystem::path from, boost::filesystem::path to, boost::uintmax_t& transferred, boost::uintmax_t total_size) { @@ -81,26 +83,28 @@ CurlUploader::upload_file (boost::filesystem::path from, boost::filesystem::path String::compose ("ftp://%1/%2/%3", Config::instance()->tms_ip(), Config::instance()->tms_path(), to.generic_string ()).c_str () ); - _file = fopen_boost (from, "rb"); - if (!_file) { + dcp::File file(from, "rb"); + if (!file) { throw NetworkError (String::compose (_("Could not open %1 to send"), from)); } + _file = file.get(); _transferred = &transferred; _total_size = total_size; - CURLcode const r = curl_easy_perform (_curl); + auto const r = curl_easy_perform (_curl); if (r != CURLE_OK) { throw NetworkError (String::compose (_("Could not write to remote file (%1)"), curl_easy_strerror (r))); } - fclose (_file); - _file = 0; + _file = nullptr; } + size_t CurlUploader::read_callback (void* ptr, size_t size, size_t nmemb) { - size_t const r = fread (ptr, size, nmemb, _file); + DCPOMATIC_ASSERT (_file); + size_t const r = fread(ptr, size, nmemb, _file); *_transferred += size * nmemb; if (_total_size > 0) {