From 29de485a466327433ec7fe2ab9db67a1820534df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Piwi=C5=84ski?= Date: Mon, 16 Dec 2019 22:43:40 +0100 Subject: [PATCH 01/25] unescape Backslash char in UTF8 unescape method --- CONTRIBUTORS | 1 + Foundation/src/UTF8String.cpp | 79 +++++++++++++-------- Foundation/testsuite/src/UTF8StringTest.cpp | 2 + 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 7a74a9cc0..102a4a299 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -50,3 +50,4 @@ Jeff Adams Martin Osborne Björn Schramke Francis Andre +Kacper Piwiński diff --git a/Foundation/src/UTF8String.cpp b/Foundation/src/UTF8String.cpp index e5020695a..d9336f3b2 100644 --- a/Foundation/src/UTF8String.cpp +++ b/Foundation/src/UTF8String.cpp @@ -32,11 +32,11 @@ namespace int UTF8::icompare(const std::string& str, std::string::size_type pos, std::string::size_type n, std::string::const_iterator it2, std::string::const_iterator end2) -{ +{ std::string::size_type sz = str.size(); if (pos > sz) pos = sz; if (pos + n > sz) n = sz - pos; - TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8); + TextIterator uit1(str.begin() + pos, str.begin() + pos + n, utf8); TextIterator uend1(str.begin() + pos + n); TextIterator uit2(it2, end2, utf8); TextIterator uend2(end2); @@ -50,7 +50,7 @@ int UTF8::icompare(const std::string& str, std::string::size_type pos, std::stri return 1; ++uit1; ++uit2; } - + if (uit1 == uend1) return uit2 == uend2 ? 0 : -1; else @@ -162,9 +162,9 @@ std::string& UTF8::toLowerInPlace(std::string& str) void UTF8::removeBOM(std::string& str) { - if (str.size() >= 3 - && static_cast(str[0]) == 0xEF - && static_cast(str[1]) == 0xBB + if (str.size() >= 3 + && static_cast(str[0]) == 0xEF + && static_cast(str[1]) == 0xBB && static_cast(str[2]) == 0xBF) { str.erase(0, 3); @@ -264,42 +264,74 @@ std::string UTF8::unescape(const std::string::const_iterator& begin, const std:: //Invalid sequence! } - if (*it == 'n') + switch (*it) + { + case 'U': + { + char digs[9]; + std::memset(digs, 0, 9); + unsigned int dno = 0; + + it++; + while (it != end && Ascii::isHexDigit(*it) && dno < 8) + { + digs[dno++] = *it++; + } + if (dno > 0) + { + ch = std::strtol(digs, NULL, 16); + } + break; + } + case '\\': + { + ch = '\\'; + it++; + break; + } + case 'n': { ch = '\n'; it++; + break; } - else if (*it == 't') + case 't': { ch = '\t'; it++; + break; } - else if (*it == 'r') + case 'r': { ch = '\r'; it++; + break; } - else if (*it == 'b') + case 'b': { ch = '\b'; it++; + break; } - else if (*it == 'f') + case 'f': { ch = '\f'; it++; + break; } - else if (*it == 'v') + case 'v': { ch = '\v'; it++; + break; } - else if (*it == 'a') + case 'a': { ch = '\a'; it++; + break; } - else if (*it == 'u') + case 'u': { char digs[5]; std::memset(digs, 0, 5); @@ -345,23 +377,14 @@ std::string UTF8::unescape(const std::string::const_iterator& begin, const std:: } } } + break; } - else if (*it == 'U') + default: { - char digs[9]; - std::memset(digs, 0, 9); - unsigned int dno = 0; - - it++; - while (it != end && Ascii::isHexDigit(*it) && dno < 8) - { - digs[dno++] = *it++; - } - if (dno > 0) - { - ch = std::strtol(digs, NULL, 16); - } + //Invalid sequence! + break; } + }//end switch } unsigned char utf8[4]; diff --git a/Foundation/testsuite/src/UTF8StringTest.cpp b/Foundation/testsuite/src/UTF8StringTest.cpp index 42a48fbcf..6799ff35d 100644 --- a/Foundation/testsuite/src/UTF8StringTest.cpp +++ b/Foundation/testsuite/src/UTF8StringTest.cpp @@ -96,9 +96,11 @@ void UTF8StringTest::testUnescape() { std::string s1("A \\t, a \\u000B, and an \\u0007 walk into a |, and the barman says \\u0402"); std::string s2("A \\t, a \\v, and an \\a walk into a |, and the barman says \\u0402"); + std::string s3("\\\\"); assertTrue (UTF8::unescape(s1) == "A \t, a \v, and an \a walk into a |, and the barman says \xD0\x82"); assertTrue (UTF8::unescape(s2) == "A \t, a \v, and an \a walk into a |, and the barman says \xD0\x82"); + assertTrue (UTF8::unescape(s3) == "\\"); } From 42629d1ed44baac89e09d4a56f9c73638c54ebfd Mon Sep 17 00:00:00 2001 From: Ludovic LIEVRE Date: Fri, 10 Jan 2020 09:54:19 +0000 Subject: [PATCH 02/25] add an option to force the use of PollingDirectoryWatcherStrategy on Linux --- Foundation/include/Poco/Config.h | 5 ++++- Foundation/src/DirectoryWatcher.cpp | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Foundation/include/Poco/Config.h b/Foundation/include/Poco/Config.h index 7dbe01823..4f46dc3a2 100644 --- a/Foundation/include/Poco/Config.h +++ b/Foundation/include/Poco/Config.h @@ -104,7 +104,10 @@ // Define to disable compilation of DirectoryWatcher // on platforms with no inotify. -// #define POCO_NO_INOTIFY +//#define POCO_NO_INOTIFY + +// Define to force the use of PollingDirectoryWatcher +#define POCO_DW_FORCE_POLLING // Following are options to remove certain features diff --git a/Foundation/src/DirectoryWatcher.cpp b/Foundation/src/DirectoryWatcher.cpp index 8c8dc4674..ab52ad454 100644 --- a/Foundation/src/DirectoryWatcher.cpp +++ b/Foundation/src/DirectoryWatcher.cpp @@ -252,7 +252,7 @@ private: }; -#elif POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID +#elif (POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID) && !defined(POCO_DW_FORCE_POLLING) class LinuxDirectoryWatcherStrategy: public DirectoryWatcherStrategy @@ -572,7 +572,7 @@ void DirectoryWatcher::init() #if POCO_OS == POCO_OS_WINDOWS_NT _pStrategy = new WindowsDirectoryWatcherStrategy(*this); -#elif POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID +#elif (POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID) && !defined(POCO_DW_FORCE_POLLING) _pStrategy = new LinuxDirectoryWatcherStrategy(*this); #elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD _pStrategy = new BSDDirectoryWatcherStrategy(*this); From b651764007b5676bfabad7f6d01495caa148a450 Mon Sep 17 00:00:00 2001 From: Ludovic LIEVRE Date: Wed, 15 Jan 2020 21:38:51 +0000 Subject: [PATCH 03/25] Option to force PollingDirectoryWatcherStrategy Add an option to force the use of PollingDirectoryWatcherStrategy Should work on any platform (Not Linux only) See previous PR on this topic : https://github.com/pocoproject/poco/pull/2881 On Linux, inotfy does not work for network volumes (such as NFS). See https://stackoverflow.com/questions/4231243/inotify-with-nfs By adding flag POCO_DW_FORCE_POLLING in Foundation/Config.h, the use of PollingDirectoryWatcherStrategy is forced. This is not the same behavior as flag POCO_NO_INOTIFY. This only disables compilation of DirectoryWatcher. --- Foundation/include/Poco/Config.h | 2 +- Foundation/src/DirectoryWatcher.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Foundation/include/Poco/Config.h b/Foundation/include/Poco/Config.h index 4f46dc3a2..ce57cb3f5 100644 --- a/Foundation/include/Poco/Config.h +++ b/Foundation/include/Poco/Config.h @@ -107,7 +107,7 @@ //#define POCO_NO_INOTIFY // Define to force the use of PollingDirectoryWatcher -#define POCO_DW_FORCE_POLLING +// #define POCO_DW_FORCE_POLLING // Following are options to remove certain features diff --git a/Foundation/src/DirectoryWatcher.cpp b/Foundation/src/DirectoryWatcher.cpp index ab52ad454..58dc9b4b3 100644 --- a/Foundation/src/DirectoryWatcher.cpp +++ b/Foundation/src/DirectoryWatcher.cpp @@ -150,7 +150,7 @@ private: }; -#if POCO_OS == POCO_OS_WINDOWS_NT +#if (POCO_OS == POCO_OS_WINDOWS_NT) && !defined(POCO_DW_FORCE_POLLING) class WindowsDirectoryWatcherStrategy: public DirectoryWatcherStrategy @@ -380,7 +380,7 @@ private: }; -#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD +#elif (POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD) && !defined(POCO_DW_FORCE_POLLING) class BSDDirectoryWatcherStrategy: public DirectoryWatcherStrategy @@ -570,11 +570,11 @@ void DirectoryWatcher::init() if (!_directory.isDirectory()) throw Poco::InvalidArgumentException("not a directory", _directory.path()); -#if POCO_OS == POCO_OS_WINDOWS_NT +#if (POCO_OS == POCO_OS_WINDOWS_NT) && !defined(POCO_DW_FORCE_POLLING) _pStrategy = new WindowsDirectoryWatcherStrategy(*this); #elif (POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID) && !defined(POCO_DW_FORCE_POLLING) _pStrategy = new LinuxDirectoryWatcherStrategy(*this); -#elif POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD +#elif (POCO_OS == POCO_OS_MAC_OS_X || POCO_OS == POCO_OS_FREE_BSD) && !defined(POCO_DW_FORCE_POLLING) _pStrategy = new BSDDirectoryWatcherStrategy(*this); #else _pStrategy = new PollingDirectoryWatcherStrategy(*this); From 15e96159e29be71ce8fed23f9b67172bfb302cf9 Mon Sep 17 00:00:00 2001 From: Ludovic LIEVRE Date: Wed, 15 Jan 2020 21:38:51 +0000 Subject: [PATCH 04/25] Option to force PollingDirectoryWatcherStrategy Add an option to force the use of PollingDirectoryWatcherStrategy Should work on any platform (Not Linux only) See previous PR on this topic : https://github.com/pocoproject/poco/pull/2881 On Linux, inotfy does not work for network volumes (such as NFS). See https://stackoverflow.com/questions/4231243/inotify-with-nfs By adding flag POCO_DW_FORCE_POLLING in Foundation/Config.h, the use of PollingDirectoryWatcherStrategy is forced. This is not the same behavior as flag POCO_NO_INOTIFY. This only disables compilation of DirectoryWatcher. --- Foundation/include/Poco/Config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Foundation/include/Poco/Config.h b/Foundation/include/Poco/Config.h index ce57cb3f5..7a21b7033 100644 --- a/Foundation/include/Poco/Config.h +++ b/Foundation/include/Poco/Config.h @@ -104,7 +104,7 @@ // Define to disable compilation of DirectoryWatcher // on platforms with no inotify. -//#define POCO_NO_INOTIFY +// #define POCO_NO_INOTIFY // Define to force the use of PollingDirectoryWatcher // #define POCO_DW_FORCE_POLLING From 854bf4d79f7efce77e19aee735f22ae4ff0ab558 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Thu, 16 Jan 2020 19:55:06 +0100 Subject: [PATCH 05/25] few PostgreSQL fixes --- Data/PostgreSQL/Makefile | 33 ++++++++++++++++-- .../include/Poco/Data/PostgreSQL/Binder.h | 6 ++-- Data/PostgreSQL/src/Binder.cpp | 6 ++-- Data/PostgreSQL/testsuite/Makefile | 34 +++++++++++++++++-- .../testsuite/src/PostgreSQLTest.cpp | 34 +++++++++++++------ 5 files changed, 91 insertions(+), 22 deletions(-) diff --git a/Data/PostgreSQL/Makefile b/Data/PostgreSQL/Makefile index 8e95b8f42..518325476 100644 --- a/Data/PostgreSQL/Makefile +++ b/Data/PostgreSQL/Makefile @@ -6,9 +6,38 @@ include $(POCO_BASE)/build/rules/global -INCLUDE += -I/usr/include/postgresql -I/usr/local/include/postgresql -I/usr/local/postgresql/include -I/opt/postgresql/include +ifeq (0, $(shell test -e /usr/include/postgresql; echo $$?)) +INCLUDE += -I/usr/include/postgresql +endif +ifeq (0, $(shell test -e /usr/local/include/postgresql; echo $$?)) +INCLUDE += -I/usr/local/include/postgresql +endif +ifeq (0, $(shell test -e /usr/local/postgresql/include; echo $$?)) +INCLUDE += -I/usr/local/postgresql/include +endif +ifeq (0, $(shell test -e /opt/postgresql/include; echo $$?)) +INCLUDE += -I/opt/postgresql/include +endif +ifeq (0, $(shell test -e /usr/local/opt/libpq/include; echo $$?)) +INCLUDE += -I/usr/local/opt/libpq/include +endif -SYSLIBS += -L/usr/lib$(LIB64SUFFIX)/postgresql -L/usr/local/lib$(LIB64SUFFIX)/postgresql -L/usr/local/postgresql/lib$(LIB64SUFFIX) -L/opt/postgresql/lib$(LIB64SUFFIX) -lpq +ifeq (0, $(shell test -e /usr/lib$(LIB64SUFFIX)/postgresql; echo $$?)) +SYSLIBS += -L/usr/lib$(LIB64SUFFIX)/postgresql +endif +ifeq (0, $(shell test -e /usr/local/lib$(LIB64SUFFIX)/postgresql; echo $$?)) +SYSLIBS += -L/usr/local/lib$(LIB64SUFFIX)/postgresql +endif +ifeq (0, $(shell test -e /usr/local/postgresql/lib$(LIB64SUFFIX); echo $$?)) +SYSLIBS += -L/usr/local/postgresql/lib$(LIB64SUFFIX) +endif +ifeq (0, $(shell test -e /opt/postgresql/lib$(LIB64SUFFIX); echo $$?)) +SYSLIBS += -L/opt/postgresql/lib$(LIB64SUFFIX) +endif +ifeq (0, $(shell test -e /opt/postgresql/lib$(LIB64SUFFIX); echo $$?)) +SYSLIBS += -L/opt/postgresql/lib$(LIB64SUFFIX) +endif +SYSLIBS += -lpq objects = Extractor Binder SessionImpl Connector \ PostgreSQLStatementImpl PostgreSQLException \ diff --git a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h index 3ad3fcc91..6b3aa966a 100644 --- a/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h +++ b/Data/PostgreSQL/include/Poco/Data/PostgreSQL/Binder.h @@ -213,11 +213,11 @@ public: virtual void bind(std::size_t pos, const std::list