C++11 tidying.
[dcpomatic.git] / src / lib / curl_uploader.cc
index b05608536bccdeccb59c4926915961a2200af110..60835bea716cc6eab0e696f738dc95550ad06863 100644 (file)
@@ -1,33 +1,38 @@
 /*
-    Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net>
 
-    This program is free software; you can redistribute it and/or modify
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
+    DCP-o-matic is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 
+
 #include "curl_uploader.h"
 #include "exceptions.h"
 #include "config.h"
 #include "cross.h"
 #include "compose.hpp"
+#include <iostream>
 
 #include "i18n.h"
 
+
 using std::string;
 using std::cout;
-using boost::function;
+using std::function;
+
 
 static size_t
 read_callback (void* ptr, size_t size, size_t nmemb, void* object)
@@ -36,11 +41,9 @@ read_callback (void* ptr, size_t size, size_t nmemb, void* object)
        return u->read_callback (ptr, size, nmemb);
 }
 
+
 CurlUploader::CurlUploader (function<void (string)> set_status, function<void (float)> set_progress)
        : Uploader (set_status, set_progress)
-       , _file (0)
-       , _transferred (0)
-       , _total_size (0)
 {
        _curl = curl_easy_init ();
        if (!_curl) {
@@ -52,10 +55,11 @@ CurlUploader::CurlUploader (function<void (string)> set_status, function<void (f
        curl_easy_setopt (_curl, CURLOPT_UPLOAD, 1L);
        curl_easy_setopt (_curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
        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 ());
+       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) {
@@ -64,18 +68,21 @@ CurlUploader::~CurlUploader ()
        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)
 {
        curl_easy_setopt (
                _curl, CURLOPT_URL,
-               String::compose ("ftp://%1/%2/%3", Config::instance()->tms_ip(), Config::instance()->tms_path(), to.string ()).c_str ()
+               /* Use generic_string so that we get forward-slashes in the path, even on Windows */
+               String::compose ("ftp://%1/%2/%3", Config::instance()->tms_ip(), Config::instance()->tms_path(), to.generic_string ()).c_str ()
                );
 
        _file = fopen_boost (from, "rb");
@@ -85,14 +92,16 @@ CurlUploader::upload_file (boost::filesystem::path from, boost::filesystem::path
        _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;
 }
 
+
 size_t
 CurlUploader::read_callback (void* ptr, size_t size, size_t nmemb)
 {