Changes to libdcp API.
[dcpomatic.git] / src / lib / internet.cc
index c28e650fdd92f4514bb850dacd13c7869b040ad4..b4395fd212c732b3d66da2cb00f07bad34e77dd2 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 #include <boost/function.hpp>
 #include <boost/optional.hpp>
 #include <boost/filesystem.hpp>
+#include <boost/algorithm/string.hpp>
 #include <curl/curl.h>
 #include <zip.h>
-#include "util.h"
+#include "scoped_temporary.h"
+#include "compose.hpp"
 #include "safe_stringstream.h"
 
 #include "i18n.h"
@@ -32,6 +34,7 @@ using std::string;
 using std::list;
 using boost::optional;
 using boost::function;
+using boost::algorithm::trim;
 
 static size_t
 get_from_zip_url_data (void* buffer, size_t size, size_t nmemb, void* stream)
@@ -56,6 +59,8 @@ get_from_zip_url (string url, string file, function<void (boost::filesystem::pat
        curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, get_from_zip_url_data);
        curl_easy_setopt (curl, CURLOPT_WRITEDATA, f);
        curl_easy_setopt (curl, CURLOPT_FTP_USE_EPSV, 0);
+       /* Maximum time is 20s */
+       curl_easy_setopt (curl, CURLOPT_TIMEOUT, 20);
 
        CURLcode const cr = curl_easy_perform (curl);
 
@@ -117,6 +122,8 @@ ftp_ls (string url)
                url += "/";
        }
        curl_easy_setopt (curl, CURLOPT_URL, url.c_str ());
+       /* 20s timeout */
+       curl_easy_setopt (curl, CURLOPT_TIMEOUT, 20);
 
        string ls_raw;
        struct curl_slist* commands = 0;
@@ -133,7 +140,8 @@ ftp_ls (string url)
        SafeStringStream s (ls_raw);
        list<string> ls;
        while (s.good ()) {
-               string const line = s.getline ();
+               string line = s.getline ();
+               trim (line);
                if (line.length() > 55) {
                        string const file = line.substr (55);
                        if (file != "." && file != "..") {