Support Dolby-style WAV back surround names when guessing mappings (#2427).
[dcpomatic.git] / src / lib / curl_uploader.cc
index 60835bea716cc6eab0e696f738dc95550ad06863..389a5d6de50b45859401feb829713f6e793a6ccd 100644 (file)
 
 
 #include "curl_uploader.h"
+#include "dcpomatic_log.h"
 #include "exceptions.h"
 #include "config.h"
 #include "cross.h"
 #include "compose.hpp"
+#include "dcpomatic_assert.h"
 #include <iostream>
 
 #include "i18n.h"
@@ -42,6 +44,13 @@ read_callback (void* ptr, size_t size, size_t nmemb, void* object)
 }
 
 
+static int
+curl_debug_shim (CURL* curl, curl_infotype type, char* data, size_t size, void* userp)
+{
+       return reinterpret_cast<CurlUploader*>(userp)->debug(curl, type, data, size);
+}
+
+
 CurlUploader::CurlUploader (function<void (string)> set_status, function<void (float)> set_progress)
        : Uploader (set_status, set_progress)
 {
@@ -57,14 +66,17 @@ CurlUploader::CurlUploader (function<void (string)> set_status, function<void (f
        curl_easy_setopt (_curl, CURLOPT_READDATA, this);
        curl_easy_setopt (_curl, CURLOPT_USERNAME, Config::instance()->tms_user().c_str());
        curl_easy_setopt (_curl, CURLOPT_PASSWORD, Config::instance()->tms_password().c_str());
+       if (!Config::instance()->tms_passive()) {
+               curl_easy_setopt(_curl, CURLOPT_FTPPORT, "-");
+       }
+       curl_easy_setopt(_curl, CURLOPT_VERBOSE, 1L);
+       curl_easy_setopt(_curl, CURLOPT_DEBUGFUNCTION, curl_debug_shim);
+       curl_easy_setopt(_curl, CURLOPT_DEBUGDATA, this);
 }
 
 
 CurlUploader::~CurlUploader ()
 {
-       if (_file) {
-               fclose (_file);
-       }
        curl_easy_cleanup (_curl);
 }
 
@@ -85,10 +97,11 @@ 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;
 
@@ -97,15 +110,15 @@ CurlUploader::upload_file (boost::filesystem::path from, boost::filesystem::path
                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) {
@@ -114,3 +127,14 @@ CurlUploader::read_callback (void* ptr, size_t size, size_t nmemb)
 
        return r;
 }
+
+
+int
+CurlUploader::debug(CURL *, curl_infotype type, char* data, size_t size)
+{
+       if (type == CURLINFO_TEXT && size > 0) {
+               LOG_GENERAL("CurlUploader: %1", string(data, size - 1));
+       }
+       return 0;
+}
+