summaryrefslogtreecommitdiff
path: root/zen
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2019-08-15 15:51:34 -0400
committerB Stack <bgstack15@gmail.com>2019-08-15 15:51:39 -0400
commit17994eb3eda9d2be9aad55dae41562ce13531d99 (patch)
treeafc54ec004ab863262f5621fbf282c42fdff29cc /zen
parentMerge branch '10.14' into 'master' (diff)
downloadFreeFileSync-17994eb3eda9d2be9aad55dae41562ce13531d99.tar.gz
FreeFileSync-17994eb3eda9d2be9aad55dae41562ce13531d99.tar.bz2
FreeFileSync-17994eb3eda9d2be9aad55dae41562ce13531d99.zip
add upstream 10.15
Diffstat (limited to 'zen')
-rw-r--r--zen/base64.h2
-rw-r--r--zen/basic_math.h4
-rw-r--r--zen/dir_watcher.h4
-rw-r--r--zen/guid.h7
-rw-r--r--zen/http.cpp13
-rw-r--r--zen/json.h6
-rw-r--r--zen/open_ssl.cpp38
-rw-r--r--zen/open_ssl.h7
-rw-r--r--zen/process_priority.cpp2
-rw-r--r--zen/shell_execute.h2
-rw-r--r--zen/stl_tools.h2
-rw-r--r--zen/type_traits.h4
-rw-r--r--zen/utf.h4
-rw-r--r--zen/zstring.cpp2
14 files changed, 71 insertions, 26 deletions
diff --git a/zen/base64.h b/zen/base64.h
index 54a0a98b..623f8f7f 100644
--- a/zen/base64.h
+++ b/zen/base64.h
@@ -13,7 +13,7 @@
namespace zen
{
-//http://en.wikipedia.org/wiki/Base64
+//https://en.wikipedia.org/wiki/Base64
/*
Usage:
const std::string input = "Sample text";
diff --git a/zen/basic_math.h b/zen/basic_math.h
index 75f5d3b8..b9be28be 100644
--- a/zen/basic_math.h
+++ b/zen/basic_math.h
@@ -254,7 +254,7 @@ double median(RandomAccessIterator first, RandomAccessIterator last) //note: inv
template <class RandomAccessIterator> inline
double mad(RandomAccessIterator first, RandomAccessIterator last) //note: invalidates input range!
{
- //http://en.wikipedia.org/wiki/Median_absolute_deviation
+ //https://en.wikipedia.org/wiki/Median_absolute_deviation
const size_t n = last - first;
if (n == 0)
return 0;
@@ -277,7 +277,7 @@ double mad(RandomAccessIterator first, RandomAccessIterator last) //note: invali
template <class InputIterator> inline
double stdDeviation(InputIterator first, InputIterator last, double* arithMean)
{
- //implementation minimizing rounding errors, see: http://en.wikipedia.org/wiki/Standard_deviation
+ //implementation minimizing rounding errors, see: https://en.wikipedia.org/wiki/Standard_deviation
//combined with technique avoiding overflow, see: http://www.netlib.org/blas/dnrm2.f -> only 10% performance degradation
size_t n = 0;
diff --git a/zen/dir_watcher.h b/zen/dir_watcher.h
index f552e2b2..875a0098 100644
--- a/zen/dir_watcher.h
+++ b/zen/dir_watcher.h
@@ -17,8 +17,8 @@
namespace zen
{
//Windows: ReadDirectoryChangesW https://msdn.microsoft.com/en-us/library/aa365465
-//Linux: inotify http://linux.die.net/man/7/inotify
-//OS X: kqueue http://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/kqueue.2.html
+//Linux: inotify https://linux.die.net/man/7/inotify
+//OS X: kqueue https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/kqueue.2.html
//watch directory including subdirectories
/*
diff --git a/zen/guid.h b/zen/guid.h
index c89e8082..657ed07a 100644
--- a/zen/guid.h
+++ b/zen/guid.h
@@ -8,7 +8,7 @@
#define GUID_H_80425780237502345
#include <fcntl.h> //open
- #include <unistd.h> //close
+ #include <unistd.h> //close, getentropy
#include <zen/sys_error.h>
//#include <uuid/uuid.h> -> uuid_generate(), uuid_unparse(); avoid additional dependency for "sudo apt-get install uuid-dev"
@@ -19,6 +19,11 @@ inline
std::string generateGUID() //creates a 16-byte GUID
{
std::string guid(16, '\0');
+
+#ifndef __GLIBC__
+#error Where is GLIB?
+#endif
+
#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25) //getentropy() requires glibc 2.25 (ldd --version) PS: CentOS 7 is on 2.17
if (::getentropy(&guid[0], guid.size()) != 0) //"The maximum permitted value for the length argument is 256"
throw std::runtime_error(std::string(__FILE__) + "[" + numberTo<std::string>(__LINE__) + "] Failed to generate GUID." +
diff --git a/zen/http.cpp b/zen/http.cpp
index 43c9dcbf..d4c30741 100644
--- a/zen/http.cpp
+++ b/zen/http.cpp
@@ -46,9 +46,9 @@ public:
else //HTTP default port: 80, see %WINDIR%\system32\drivers\etc\services
socket_ = std::make_unique<Socket>(server, Zstr("http")); //throw SysError
- //we don't support "chunked transfer encoding" => HTTP 1.0
+ //we don't support "chunked and gzip transfer encoding" => HTTP 1.0
std::map<std::string, std::string, LessAsciiNoCase> headers;
- headers["Host" ] = utfTo<std::string>(server); //only required for HTTP/1.1
+ headers["Host" ] = utfTo<std::string>(server); //only required for HTTP/1.1 but a few servers expect it even for HTTP/1.0
headers["User-Agent"] = utfTo<std::string>(userAgent);
headers["Accept" ] = "*/*"; //won't hurt?
@@ -234,7 +234,7 @@ std::unique_ptr<HttpInputStream::Impl> sendHttpRequestImpl(const Zstring& url,
{
auto response = std::make_unique<HttpInputStream::Impl>(urlRed, postParams, false /*disableGetCache*/, userAgent, caCertFilePath, notifyUnbufferedIO); //throw SysError
- //http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
+ //https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection
const int statusCode = response->getStatusCode();
if (statusCode / 100 == 3) //e.g. 301, 302, 303, 307... we're not too greedy since we check location, too!
{
@@ -271,11 +271,10 @@ std::string urlencode(const std::string& str)
out += c;
else
{
- const std::pair<char, char> hex = hexify(c);
-
+ const auto [high, low] = hexify(c);
out += '%';
- out += hex.first;
- out += hex.second;
+ out += high;
+ out += low;
}
return out;
}
diff --git a/zen/json.h b/zen/json.h
index 374a3f14..9b85ccb9 100644
--- a/zen/json.h
+++ b/zen/json.h
@@ -104,10 +104,10 @@ std::string jsonEscape(const std::string& str)
else if (static_cast<unsigned char>(c) < 32)
{
- const auto hexDigits = hexify(c);
+ const auto [high, low] = hexify(c);
output += "\\u00";
- output += hexDigits.first;
- output += hexDigits.second;
+ output += high;
+ output += low;
}
else
output += c;
diff --git a/zen/open_ssl.cpp b/zen/open_ssl.cpp
index 0f07e5e3..f3fd7219 100644
--- a/zen/open_ssl.cpp
+++ b/zen/open_ssl.cpp
@@ -12,8 +12,44 @@
using namespace zen;
+#ifndef OPENSSL_THREADS
+ #error FFS, we are royally screwed!
+#endif
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+ #error OpenSSL version too old
+#endif
+
+
+void zen::openSslInit()
+{
+ //official Wiki: https://wiki.openssl.org/index.php/Library_Initialization
+ //see apps_shutdown(): https://github.com/openssl/openssl/blob/master/apps/openssl.c
+ //see Curl_ossl_cleanup(): https://github.com/curl/curl/blob/master/lib/vtls/openssl.c
+
+ //excplicitly init OpenSSL on main thread: seems to initialize atomically! But it still might help to avoid issues:
+ [[maybe_unused]] const int rv = ::OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, nullptr);
+ assert(rv == 1); //https://www.openssl.org/docs/man1.1.0/ssl/OPENSSL_init_ssl.html
+}
+
+
+void zen::openSslTearDown() {}
+//OpenSSL 1.1.0+ deprecates all clean up functions
+//=> so much the theory, in practice it leaks, of course: https://github.com/openssl/openssl/issues/6283
+//=> OpenSslThreadCleanUp
+
namespace
{
+struct OpenSslThreadCleanUp
+{
+ ~OpenSslThreadCleanUp()
+ {
+ ::OPENSSL_thread_stop();
+ }
+};
+thread_local OpenSslThreadCleanUp tearDownOpenSslThreadData;
+
+
/* Sign a file using SHA-256:
openssl dgst -sha256 -sign private.pem -out file.sig file.txt
@@ -468,7 +504,7 @@ public:
throw SysError(formatLastOpenSSLError(L"BIO_up_ref"));
::SSL_set0_wbio(ssl_, bio); //pass ownership
- assert(::SSL_get_mode(ssl_) == SSL_MODE_AUTO_RETRY); //verify OpenSSL default
+ assert(::SSL_get_mode(ssl_) == SSL_MODE_AUTO_RETRY); //verify OpenSSL default
::SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE);
if (::SSL_set_tlsext_host_name(ssl_, server.c_str()) != 1) //enable SNI (Server Name Indication)
diff --git a/zen/open_ssl.h b/zen/open_ssl.h
index 5bf4e9ce..350e3776 100644
--- a/zen/open_ssl.h
+++ b/zen/open_ssl.h
@@ -11,8 +11,13 @@
#include <zen/sys_error.h>
-namespace zen //init OpenSSL before use!
+namespace zen
{
+//init OpenSSL before use!
+void openSslInit();
+void openSslTearDown();
+
+
enum class RsaStreamType
{
pkix, //base-64-encoded SubjectPublicKeyInfo structure ("BEGIN PUBLIC KEY")
diff --git a/zen/process_priority.cpp b/zen/process_priority.cpp
index e925f142..f80dd022 100644
--- a/zen/process_priority.cpp
+++ b/zen/process_priority.cpp
@@ -24,7 +24,7 @@ ScheduleForBackgroundProcessing::~ScheduleForBackgroundProcessing() {};
/*
struct ScheduleForBackgroundProcessing
{
- - required functions ioprio_get/ioprio_set are not part of glibc: http://linux.die.net/man/2/ioprio_set
+ - required functions ioprio_get/ioprio_set are not part of glibc: https://linux.die.net/man/2/ioprio_set
- and probably never will: http://sourceware.org/bugzilla/show_bug.cgi?id=4464
- /usr/include/linux/ioprio.h not available on Ubuntu, so we can't use it instead
diff --git a/zen/shell_execute.h b/zen/shell_execute.h
index 19945a0b..4875a039 100644
--- a/zen/shell_execute.h
+++ b/zen/shell_execute.h
@@ -41,7 +41,7 @@ void shellExecute(const Zstring& command, ExecutionType type, bool hideConsole)
const int rv = ::system(command.c_str()); //do NOT use std::system as its documentation says nothing about "WEXITSTATUS(rv)", etc...
if (rv == -1 || WEXITSTATUS(rv) == 127)
throw FileError(_("Incorrect command line:") + L"\n" + utfTo<std::wstring>(command));
- //http://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)"
+ //https://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)"
//Bonus: For an incorrect command line /bin/sh also returns with 127!
}
else
diff --git a/zen/stl_tools.h b/zen/stl_tools.h
index f1ab7c16..15e7f7ca 100644
--- a/zen/stl_tools.h
+++ b/zen/stl_tools.h
@@ -283,7 +283,7 @@ void mergeTraversal(Iterator first1, Iterator last1,
}
-//FNV-1a: http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
+//FNV-1a: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
template <class Num, class ByteIterator> inline
Num hashBytes(ByteIterator first, ByteIterator last)
{
diff --git a/zen/type_traits.h b/zen/type_traits.h
index 8783cb6a..9823bb44 100644
--- a/zen/type_traits.h
+++ b/zen/type_traits.h
@@ -9,7 +9,7 @@
#include <type_traits>
-//http://en.cppreference.com/w/cpp/header/type_traits
+//https://en.cppreference.com/w/cpp/header/type_traits
namespace zen
{
@@ -43,7 +43,7 @@ constexpr S arrayAccumulate(T (&arr)[N])
return sum;
}
-//Herb Sutter's signedness conversion helpers: http://herbsutter.com/2013/06/13/gotw-93-solution-auto-variables-part-2/
+//Herb Sutter's signedness conversion helpers: https://herbsutter.com/2013/06/13/gotw-93-solution-auto-variables-part-2/
template<class T> inline auto makeSigned (T t) { return static_cast<std::make_signed_t <T>>(t); }
template<class T> inline auto makeUnsigned(T t) { return static_cast<std::make_unsigned_t<T>>(t); }
diff --git a/zen/utf.h b/zen/utf.h
index 37a866ab..75bf7424 100644
--- a/zen/utf.h
+++ b/zen/utf.h
@@ -58,7 +58,7 @@ static_assert(LEAD_SURROGATE + TRAIL_SURROGATE + TRAIL_SURROGATE_MAX + REPLACEME
template <class Function> inline
void codePointToUtf16(CodePoint cp, Function writeOutput) //"writeOutput" is a unary function taking a Char16
{
- //http://en.wikipedia.org/wiki/UTF-16
+ //https://en.wikipedia.org/wiki/UTF-16
if (cp < LEAD_SURROGATE)
writeOutput(static_cast<Char16>(cp));
else if (cp <= TRAIL_SURROGATE_MAX) //invalid code point
@@ -141,7 +141,7 @@ private:
template <class Function> inline
void codePointToUtf8(CodePoint cp, Function writeOutput) //"writeOutput" is a unary function taking a Char8
{
- //http://en.wikipedia.org/wiki/UTF-8
+ //https://en.wikipedia.org/wiki/UTF-8
//assert(cp < LEAD_SURROGATE || TRAIL_SURROGATE_MAX < cp); //code points [0xd800, 0xdfff] are reserved for UTF-16 and *should* not be encoded in UTF-8
if (cp < 0x80)
diff --git a/zen/zstring.cpp b/zen/zstring.cpp
index 3b33a21b..ad736d04 100644
--- a/zen/zstring.cpp
+++ b/zen/zstring.cpp
@@ -8,7 +8,7 @@
#include <stdexcept>
#include "utf.h"
- #include <gtk/gtk.h>
+#include <glib.h>
#include "sys_error.h"
using namespace zen;
bgstack15