Merge branch 'poco-1.10.0' into devel

This commit is contained in:
Günter Obiltschnig 2020-01-22 11:20:59 +01:00
commit adc99f0198
57 changed files with 814 additions and 525 deletions

View File

@ -50,3 +50,4 @@ Jeff Adams
Martin Osborne
Björn Schramke
Francis Andre
Kacper Piwiński

View File

@ -90,9 +90,21 @@ public:
/// Creates a new CipherKeyImpl object. Autoinitializes key and
/// initialization vector.
CipherKey(const CipherKey& other);
/// Copy constructor.
CipherKey(CipherKey&& other) noexcept;
/// Copy constructor.
~CipherKey();
/// Destroys the CipherKeyImpl.
CipherKey& operator = (const CipherKey& other);
/// Assignment.
CipherKey& operator = (CipherKey&& other) noexcept;
/// Move assignment.
const std::string& name() const;
/// Returns the name of the Cipher.

View File

@ -32,7 +32,7 @@ class X509Certificate;
class PKCS12Container;
class Crypto_API ECKey : public KeyPair
class Crypto_API ECKey: public KeyPair
/// This class stores an EC key pair, consisting
/// of private and public key. Storage of the private
/// key is optional.
@ -73,9 +73,21 @@ public:
/// If a private key is specified, you don't need to specify a public key file.
/// OpenSSL will auto-create the public key from the private key.
ECKey(const ECKey& key);
/// Creates the ECKey by copying another one.
ECKey(ECKey&& key) noexcept;
/// Creates the ECKey by moving another one.
~ECKey();
/// Destroys the ECKey.
ECKey& operator = (const ECKey& other);
/// Assignment.
ECKey& operator = (ECKey&& other) noexcept;
/// Move assignment.
ECKeyImpl::Ptr impl() const;
/// Returns the impl object.
@ -97,9 +109,6 @@ public:
static bool hasCurve(const std::string& name);
/// Returns true if the named curve is found,
/// false otherwise.
private:
ECKeyImpl::Ptr _pImpl;
};
@ -108,7 +117,7 @@ private:
//
inline ECKeyImpl::Ptr ECKey::impl() const
{
return _pImpl;
return KeyPair::impl().cast<ECKeyImpl>();
}

View File

@ -1,7 +1,6 @@
//
// KeyPair.h
//
//
// Library: Crypto
// Package: CryptoCore
// Module: KeyPair
@ -48,6 +47,18 @@ public:
explicit KeyPair(KeyPairImpl::Ptr pKeyPairImpl = 0);
/// Extracts the RSA public key from the given certificate.
KeyPair(const KeyPair& other);
/// Copy constructor.
KeyPair(KeyPair&& other) noexcept;
/// Move constructor.
KeyPair& operator = (const KeyPair& other);
/// Assignment.
KeyPair& operator = (KeyPair&& other) noexcept;
/// Move assignment.
virtual ~KeyPair();
/// Destroys the KeyPair.
@ -87,7 +98,6 @@ private:
//
// inlines
//
inline int KeyPair::size() const
{
return _pImpl->size();
@ -115,6 +125,7 @@ inline const std::string& KeyPair::name() const
return _pImpl->name();
}
inline KeyPairImpl::Ptr KeyPair::impl() const
{
return _pImpl;

View File

@ -31,7 +31,7 @@ class X509Certificate;
class PKCS12Container;
class Crypto_API RSAKey : public KeyPair
class Crypto_API RSAKey: public KeyPair
/// This class stores an RSA key pair, consisting
/// of private and public key. Storage of the private
/// key is optional.
@ -90,9 +90,21 @@ public:
/// If a private key is specified, you don't need to specify a public key file.
/// OpenSSL will auto-create the public key from the private key.
RSAKey(const RSAKey& other);
/// Copy constructor.
RSAKey(RSAKey&& other) noexcept;
/// Move constructor.
~RSAKey();
/// Destroys the RSAKey.
RSAKey& operator = (const RSAKey& other);
/// Assignment.
RSAKey& operator = (RSAKey&& other) noexcept;
/// Move assignment.
RSAKeyImpl::ByteVec modulus() const;
/// Returns the RSA modulus.
@ -104,9 +116,6 @@ public:
RSAKeyImpl::Ptr impl() const;
/// Returns the impl object.
private:
RSAKeyImpl::Ptr _pImpl;
};
@ -115,7 +124,7 @@ private:
//
inline RSAKeyImpl::Ptr RSAKey::impl() const
{
return _pImpl;
return KeyPair::impl().cast<RSAKeyImpl>();
}

View File

@ -41,9 +41,38 @@ CipherKey::CipherKey(const std::string& name):
}
CipherKey::CipherKey(const CipherKey& other):
_pImpl(other._pImpl)
{
}
CipherKey::CipherKey(CipherKey&& other) noexcept:
_pImpl(std::move(other._pImpl))
{
}
CipherKey::~CipherKey()
{
}
CipherKey& CipherKey::operator = (const CipherKey& other)
{
if (&other != this)
{
_pImpl = other._pImpl;
}
return *this;
}
CipherKey& CipherKey::operator = (CipherKey&& other) noexcept
{
_pImpl = std::move(other._pImpl);
return *this;
}
} } // namespace Poco::Crypto

View File

@ -22,47 +22,49 @@ namespace Crypto {
ECKey::ECKey(const EVPPKey& key):
KeyPair(new ECKeyImpl(key)),
_pImpl(KeyPair::impl().cast<ECKeyImpl>())
KeyPair(new ECKeyImpl(key))
{
}
ECKey::ECKey(const X509Certificate& cert):
KeyPair(new ECKeyImpl(cert)),
_pImpl(KeyPair::impl().cast<ECKeyImpl>())
KeyPair(new ECKeyImpl(cert))
{
}
ECKey::ECKey(const PKCS12Container& cont):
KeyPair(new ECKeyImpl(cont)),
_pImpl(KeyPair::impl().cast<ECKeyImpl>())
KeyPair(new ECKeyImpl(cont))
{
}
ECKey::ECKey(const std::string& eccGroup):
KeyPair(new ECKeyImpl(OBJ_txt2nid(eccGroup.c_str()))),
_pImpl(KeyPair::impl().cast<ECKeyImpl>())
KeyPair(new ECKeyImpl(OBJ_txt2nid(eccGroup.c_str())))
{
}
ECKey::ECKey(const std::string& publicKeyFile,
const std::string& privateKeyFile,
const std::string& privateKeyPassphrase):
KeyPair(new ECKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)),
_pImpl(KeyPair::impl().cast<ECKeyImpl>())
ECKey::ECKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
KeyPair(new ECKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase))
{
}
ECKey::ECKey(std::istream* pPublicKeyStream,
std::istream* pPrivateKeyStream,
const std::string& privateKeyPassphrase):
KeyPair(new ECKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)),
_pImpl(KeyPair::impl().cast<ECKeyImpl>())
ECKey::ECKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
KeyPair(new ECKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase))
{
}
ECKey::ECKey(const ECKey& other):
KeyPair(other)
{
}
ECKey::ECKey(ECKey&& other) noexcept:
KeyPair(std::move(other))
{
}
@ -72,4 +74,18 @@ ECKey::~ECKey()
}
ECKey& ECKey::operator = (const ECKey& other)
{
KeyPair::operator = (other);
return *this;
}
ECKey& ECKey::operator = (ECKey&& other) noexcept
{
KeyPair::operator = (std::move(other));
return *this;
}
} } // namespace Poco::Crypto

View File

@ -93,7 +93,6 @@ EVPPKey::EVPPKey(EVPPKey&& other) noexcept:
_pEVPPKey(other._pEVPPKey)
{
other._pEVPPKey = nullptr;
poco_check_ptr(_pEVPPKey);
}
@ -109,7 +108,6 @@ EVPPKey& EVPPKey::operator = (EVPPKey&& other) noexcept
{
_pEVPPKey = other._pEVPPKey;
other._pEVPPKey = nullptr;
poco_check_ptr(_pEVPPKey);
return *this;
}

View File

@ -1,7 +1,6 @@
//
// KeyPair.cpp
//
//
// Library: Crypto
// Package: CryptoCore
// Module: KeyPair
@ -21,7 +20,20 @@ namespace Poco {
namespace Crypto {
KeyPair::KeyPair(KeyPairImpl::Ptr pKeyPairImpl): _pImpl(pKeyPairImpl)
KeyPair::KeyPair(KeyPairImpl::Ptr pKeyPairImpl):
_pImpl(pKeyPairImpl)
{
}
KeyPair::KeyPair(const KeyPair& other):
_pImpl(other._pImpl)
{
}
KeyPair::KeyPair(KeyPair&& other) noexcept:
_pImpl(std::move(other._pImpl))
{
}
@ -31,4 +43,21 @@ KeyPair::~KeyPair()
}
KeyPair& KeyPair::operator = (const KeyPair& other)
{
if (&other != this)
{
_pImpl = other._pImpl;
}
return *this;
}
KeyPair& KeyPair::operator = (KeyPair&& other) noexcept
{
_pImpl = std::move(other._pImpl);
return *this;
}
} } // namespace Poco::Crypto

View File

@ -73,6 +73,17 @@ PKCS12Container::PKCS12Container(const PKCS12Container& other):
}
PKCS12Container::PKCS12Container(PKCS12Container&& other) noexcept:
_pKey(other._pKey),
_pX509Cert(std::move(other._pX509Cert)),
_caCertList(std::move(other._caCertList)),
_caCertNames(std::move(other._caCertNames)),
_pkcsFriendlyName(std::move(other._pkcsFriendlyName))
{
other._pKey = nullptr;
}
PKCS12Container& PKCS12Container::operator = (const PKCS12Container& other)
{
if (&other != this)
@ -88,17 +99,6 @@ PKCS12Container& PKCS12Container::operator = (const PKCS12Container& other)
}
PKCS12Container::PKCS12Container(PKCS12Container&& other) noexcept:
_pKey(other._pKey),
_pX509Cert(std::move(other._pX509Cert)),
_caCertList(std::move(other._caCertList)),
_caCertNames(std::move(other._caCertNames)),
_pkcsFriendlyName(std::move(other._pkcsFriendlyName))
{
other._pKey = nullptr;
}
PKCS12Container& PKCS12Container::operator = (PKCS12Container&& other) noexcept
{
if (_pKey) EVP_PKEY_free(_pKey);

View File

@ -21,43 +21,49 @@ namespace Crypto {
RSAKey::RSAKey(const EVPPKey& key):
KeyPair(new RSAKeyImpl(key)),
_pImpl(KeyPair::impl().cast<RSAKeyImpl>())
KeyPair(new RSAKeyImpl(key))
{
}
RSAKey::RSAKey(const X509Certificate& cert):
KeyPair(new RSAKeyImpl(cert)),
_pImpl(KeyPair::impl().cast<RSAKeyImpl>())
KeyPair(new RSAKeyImpl(cert))
{
}
RSAKey::RSAKey(const PKCS12Container& cont):
KeyPair(new RSAKeyImpl(cont)),
_pImpl(KeyPair::impl().cast<RSAKeyImpl>())
KeyPair(new RSAKeyImpl(cont))
{
}
RSAKey::RSAKey(KeyLength keyLength, Exponent exp):
KeyPair(new RSAKeyImpl(keyLength, (exp == EXP_LARGE) ? RSA_F4 : RSA_3)),
_pImpl(KeyPair::impl().cast<RSAKeyImpl>())
KeyPair(new RSAKeyImpl(keyLength, (exp == EXP_LARGE) ? RSA_F4 : RSA_3))
{
}
RSAKey::RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase):
KeyPair(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)),
_pImpl(KeyPair::impl().cast<RSAKeyImpl>())
KeyPair(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase))
{
}
RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase):
KeyPair(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)),
_pImpl(KeyPair::impl().cast<RSAKeyImpl>())
KeyPair(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase))
{
}
RSAKey::RSAKey(const RSAKey& other):
KeyPair(other)
{
}
RSAKey::RSAKey(RSAKey&& other) noexcept:
KeyPair(std::move(other))
{
}
@ -66,21 +72,36 @@ RSAKey::~RSAKey()
{
}
RSAKey& RSAKey::operator = (const RSAKey& other)
{
KeyPair::operator = (other);
return *this;
}
RSAKey& RSAKey::operator = (RSAKey&& other) noexcept
{
KeyPair::operator = (std::move(other));
return *this;
}
RSAKeyImpl::ByteVec RSAKey::modulus() const
{
return _pImpl->modulus();
return impl()->modulus();
}
RSAKeyImpl::ByteVec RSAKey::encryptionExponent() const
{
return _pImpl->encryptionExponent();
return impl()->encryptionExponent();
}
RSAKeyImpl::ByteVec RSAKey::decryptionExponent() const
{
return _pImpl->decryptionExponent();
return impl()->decryptionExponent();
}

View File

@ -29,12 +29,14 @@
#include <openssl/evp.h>
#include <openssl/bn.h>
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#define ASN1_STRING_get0_data ASN1_STRING_data
#define X509_get0_notBefore X509_get_notBefore
#define X509_get0_notAfter X509_get_notAfter
#endif
namespace Poco {
namespace Crypto {
@ -113,6 +115,7 @@ X509Certificate& X509Certificate::operator = (X509Certificate&& cert) noexcept
_issuerName = std::move(cert._issuerName);
_subjectName = std::move(cert._subjectName);
_serialNumber = std::move(cert._serialNumber);
if (_pCert) X509_free(_pCert);
_pCert = cert._pCert; cert._pCert = nullptr;
return *this;
}
@ -302,7 +305,18 @@ Poco::DateTime X509Certificate::validFrom() const
const ASN1_TIME* certTime = X509_get0_notBefore(_pCert);
std::string dateTime(reinterpret_cast<char*>(certTime->data));
int tzd;
if (certTime->type == V_ASN1_UTCTIME)
{
return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
}
else if (certTime->type == V_ASN1_GENERALIZEDTIME)
{
return DateTimeParser::parse("%Y%m%d%H%M%S", dateTime, tzd);
}
else
{
throw NotImplementedException("Unsupported date/time format in notBefore");
}
}
@ -311,7 +325,18 @@ Poco::DateTime X509Certificate::expiresOn() const
const ASN1_TIME* certTime = X509_get0_notAfter(_pCert);
std::string dateTime(reinterpret_cast<char*>(certTime->data));
int tzd;
if (certTime->type == V_ASN1_UTCTIME)
{
return DateTimeParser::parse("%y%m%d%H%M%S", dateTime, tzd);
}
else if (certTime->type == V_ASN1_GENERALIZEDTIME)
{
return DateTimeParser::parse("%Y%m%d%H%M%S", dateTime, tzd);
}
else
{
throw NotImplementedException("Unsupported date/time format in notBefore");
}
}

View File

@ -2482,7 +2482,7 @@ void SQLiteTest::testSQLLogger()
{
AutoPtr<SQLChannel> pChannel = new SQLChannel(Poco::Data::SQLite::Connector::KEY, "dummy.db", "TestSQLChannel");
Logger& root = Logger::root();
root.setChannel(pChannel.get());
root.setChannel(pChannel);
root.setLevel(Message::PRIO_INFORMATION);
root.information("Informational message");

View File

@ -91,6 +91,7 @@ MetaColumn& MetaColumn::operator = (MetaColumn&& other) noexcept
return *this;
}
void MetaColumn::swap(MetaColumn& other)
{
std::swap(_name, other._name);

View File

@ -50,14 +50,14 @@ Session::Session(const std::string& connection,
Session::Session(const Session& other):
_pImpl(other._pImpl),
_statementCreator(other._pImpl)
_statementCreator(other._statementCreator)
{
}
Session::Session(Session&& other) noexcept:
_pImpl(std::move(other._pImpl)),
_statementCreator(std::move(other._pImpl))
_statementCreator(std::move(other._statementCreator))
{
}

View File

@ -182,7 +182,7 @@ public:
AutoPtr& operator = (AutoPtr&& ptr) noexcept
{
if (_ptr) _ptr->release();
_ptr = std::move(ptr._ptr);
_ptr = ptr._ptr;
ptr._ptr = nullptr;
return *this;
}

View File

@ -96,6 +96,9 @@
// on platforms with 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
// to reduce library/executable size for smaller

View File

@ -78,7 +78,7 @@ public:
Message(const Message& msg);
/// Creates a Message by copying another one.
Message(Message&& msg);
Message(Message&& msg) noexcept;
/// Creates a Message by copying another one.
Message(const Message& msg, const std::string& text);
@ -90,7 +90,7 @@ public:
Message& operator = (const Message& msg);
/// Assignment operator.
Message& operator = (Message&& msg);
Message& operator = (Message&& msg) noexcept;
/// Assignment operator.
void swap(Message& msg);

View File

@ -123,7 +123,7 @@ public:
Nullable& assign(C&& value)
/// Assigns a value to the Nullable.
{
_value = value;
_value = std::move(value);
_isNull = false;
return *this;
}
@ -152,7 +152,7 @@ public:
Nullable& operator = (C&& value)
/// Move-assigns a value to the Nullable.
{
return assign(value);
return assign(std::move(value));
}
Nullable& operator = (const Nullable& other)

View File

@ -105,7 +105,7 @@ public:
Optional& assign(C&& value)
/// Moves a value into the Optional.
{
_value = value;
_value = std::move(value);
_isSpecified = true;
return *this;
}
@ -125,7 +125,7 @@ public:
Optional& operator = (C&& value)
{
return assign(value);
return assign(std::move(value));
}
Optional& operator = (const Optional& other)

View File

@ -66,6 +66,11 @@ public:
/// Waits for the process to terminate
/// and returns the exit code of the process.
int tryWait() const;
/// Checks that process is terminated
/// and returns the exit code of the process.
/// If the process is still running, returns -1.
protected:
ProcessHandle(ProcessHandleImpl* pImpl);
@ -211,6 +216,10 @@ public:
/// Waits for the process specified by handle to terminate
/// and returns the exit code of the process.
static int tryWait(const ProcessHandle& handle);
/// Checks that process is finished and returns the exit code of the
/// process. If the process is still running, returns -1.
static bool isRunning(const ProcessHandle& handle);
/// check if the process specified by handle is running or not
///

View File

@ -39,6 +39,7 @@ public:
pid_t id() const;
int wait() const;
int tryWait() const;
private:
pid_t _pid;

View File

@ -41,6 +41,7 @@ public:
int id() const;
int wait() const;
int tryWait() const;
private:
int _pid;

View File

@ -40,6 +40,7 @@ public:
UInt32 id() const;
HANDLE process() const;
int wait() const;
int tryWait() const;
void closeHandle();
private:

View File

@ -40,6 +40,7 @@ public:
UInt32 id() const;
HANDLE process() const;
int wait() const;
int tryWait() const;
void closeHandle();
private:

View File

@ -40,6 +40,7 @@ public:
UInt32 id() const;
HANDLE process() const;
int wait() const;
int tryWait() const;
void closeHandle();
private:

View File

@ -61,7 +61,7 @@ class ReleasePolicy
/// simply uses the delete operator to delete an object.
{
public:
static void release(C* pObj)
static void release(C* pObj) noexcept
/// Delete the object.
/// Note that pObj can be nullptr.
{
@ -75,7 +75,7 @@ class ReleaseArrayPolicy
/// The release policy for SharedPtr holding arrays.
{
public:
static void release(C* pObj)
static void release(C* pObj) noexcept
/// Delete the object.
/// Note that pObj can be nullptr.
{
@ -115,7 +115,9 @@ class SharedPtr
public:
typedef C Type;
SharedPtr(): _pCounter(nullptr), _ptr(nullptr)
SharedPtr():
_pCounter(nullptr),
_ptr(nullptr)
{
}
@ -131,33 +133,32 @@ public:
}
template <class Other, class OtherRP>
SharedPtr(const SharedPtr<Other, RC, OtherRP>& ptr): _pCounter(ptr._pCounter), _ptr(const_cast<Other*>(ptr.get()))
SharedPtr(const SharedPtr<Other, RC, OtherRP>& ptr):
_pCounter(ptr._pCounter),
_ptr(const_cast<Other*>(ptr.get()))
{
if (_pCounter) _pCounter->duplicate();
}
SharedPtr(const SharedPtr& ptr): _pCounter(ptr._pCounter), _ptr(ptr._ptr)
SharedPtr(const SharedPtr& ptr):
_pCounter(ptr._pCounter),
_ptr(ptr._ptr)
{
if (_pCounter) _pCounter->duplicate();
}
SharedPtr(SharedPtr&& ptr) noexcept: _pCounter(std::move(ptr._pCounter)), _ptr(std::move(ptr._ptr))
SharedPtr(SharedPtr&& ptr) noexcept:
_pCounter(ptr._pCounter),
_ptr(ptr._ptr)
{
ptr._pCounter = nullptr;
ptr._ptr = nullptr;
}
~SharedPtr()
{
try
{
release();
}
catch (...)
{
poco_unexpected();
}
}
SharedPtr& assign(C* ptr)
{
@ -223,9 +224,10 @@ public:
SharedPtr& operator = (SharedPtr&& ptr) noexcept
{
_ptr = std::move(ptr._ptr);
_pCounter = std::move(ptr._pCounter);
release();
_ptr = ptr._ptr;
ptr._ptr = nullptr;
_pCounter = ptr._pCounter;
ptr._pCounter = nullptr;
return *this;
}
@ -423,7 +425,7 @@ private:
return _ptr;
}
void release()
void release() noexcept
{
if (_pCounter && _pCounter->release() == 0)
{

View File

@ -78,6 +78,13 @@ public:
/// The UUID::version() method can be used to determine the actual kind of
/// the UUID generated.
void seed(UInt32 n);
/// Seeds the internal pseudo random generator for time-based UUIDs with the given seed.
void seed();
/// Seeds the internal pseudo random generator used for time-based UUIDs
/// with a random seed obtained from a RandomInputStream.
static UUIDGenerator& defaultGenerator();
/// Returns a reference to the default UUIDGenerator.

View File

@ -5,25 +5,7 @@
// Package: Core
// Module: UnWindows
//
// A wrapper around the <windows.h> header file that #undef's some
// of the macros for function names defined by <windows.h> that
// are a frequent source of conflicts (e.g., GetUserName).
//
// Remember, that most of the WIN32 API functions come in two variants,
// an Unicode variant (e.g., GetUserNameA) and an ASCII variant (GetUserNameW).
// There is also a macro (GetUserName) that's either defined to be the Unicode
// name or the ASCII name, depending on whether the UNICODE macro is #define'd
// or not. POCO always calls the Unicode functions directly.
//
// These macro definitions are a frequent case of problems and naming conflicts,
// especially for C++ programmers. Say, you define a class with a member function named
// GetUserName. Depending on whether "Poco/UnWindows.h" has been included by a particular
// translation unit or not, this might be changed to GetUserNameA/GetUserNameW, or not.
// While, due to naming conventions used, this is less of a problem in POCO, some
// of the users of POCO might use a different naming convention where this can become
// a problem.
//
// To disable the #undef's, compile POCO with the POCO_NO_UNWINDOWS macro #define'd.
// Simple wrapper around the <windows.h> header file.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
@ -44,17 +26,6 @@
#endif
// Microsoft Visual C++ includes copies of the Windows header files
// that were current at the time Visual C++ was released.
// The Windows header files use macros to indicate which versions
// of Windows support many programming elements. Therefore, you must
// define these macros to use new functionality introduced in each
// major operating system release. (Individual header files may use
// different macros; therefore, if compilation problems occur, check
// the header file that contains the definition for conditional
// definitions.) For more information, see SdkDdkVer.h.
#if !defined(POCO_NO_WINDOWS_H)
#include <windows.h>
#ifdef __MINGW32__
@ -65,55 +36,4 @@
#endif
#if !defined(POCO_NO_UNWINDOWS)
// A list of annoying macros to #undef.
// Extend as required.
#undef GetBinaryType
#undef GetShortPathName
#undef GetLongPathName
#undef GetEnvironmentStrings
#undef SetEnvironmentStrings
#undef FreeEnvironmentStrings
#undef FormatMessage
#undef EncryptFile
#undef DecryptFile
#undef CreateMutex
#undef OpenMutex
#undef CreateEvent
#undef OpenEvent
#undef CreateSemaphore
#undef OpenSemaphore
#undef LoadLibrary
#undef GetModuleFileName
#undef CreateProcess
#undef GetCommandLine
#undef GetEnvironmentVariable
#undef SetEnvironmentVariable
#undef ExpandEnvironmentStrings
#undef OutputDebugString
#undef FindResource
#undef UpdateResource
#undef FindAtom
#undef AddAtom
#undef GetSystemDirectory
#undef GetTempPath
#undef GetTempFileName
#undef SetCurrentDirectory
#undef GetCurrentDirectory
#undef CreateDirectory
#undef RemoveDirectory
#undef CreateFile
#undef DeleteFile
#undef SearchPath
#undef CopyFile
#undef MoveFile
#undef ReplaceFile
#undef GetComputerName
#undef SetComputerName
#undef GetUserName
#undef LogonUser
#undef GetVersion
#undef GetObject
#endif // POCO_NO_UNWINDOWS
#endif // Foundation_UnWindows_INCLUDED

View File

@ -72,6 +72,8 @@ DirectoryIterator::~DirectoryIterator()
DirectoryIterator& DirectoryIterator::operator = (const DirectoryIterator& it)
{
if (&it != this)
{
if (_pImpl) _pImpl->release();
_pImpl = it._pImpl;
if (_pImpl)
@ -80,6 +82,7 @@ DirectoryIterator& DirectoryIterator::operator = (const DirectoryIterator& it)
_path = it._path;
_file = _path;
}
}
return *this;
}

View File

@ -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
@ -248,7 +248,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
@ -376,7 +376,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
@ -566,11 +566,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
#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);

View File

@ -26,7 +26,7 @@
#if defined(_WIN32_WCE)
#include "Environment_WINCE.cpp"
#else
#include "Environment_WIN32.cpp"
#include "Environment_WIN32U.cpp"
#endif
#endif

View File

@ -82,7 +82,7 @@ Message::Message(const Message& msg):
}
Message::Message(Message&& msg) :
Message::Message(Message&& msg) noexcept:
_source(std::move(msg._source)),
_text(std::move(msg._text)),
_prio(std::move(msg._prio)),
@ -147,10 +147,8 @@ Message& Message::operator = (const Message& msg)
}
Message& Message::operator = (Message&& msg)
Message& Message::operator = (Message&& msg) noexcept
{
if (&msg != this)
{
_source = std::move(msg._source);
_text = std::move(msg._text);
_prio = std::move(msg._prio);
@ -163,7 +161,6 @@ Message& Message::operator = (Message&& msg)
delete _pMap;
_pMap = msg._pMap;
msg._pMap = nullptr;
}
return *this;
}

View File

@ -51,21 +51,34 @@ std::string PathImpl::homeImpl()
{
#if defined(POCO_VXWORKS)
if (EnvironmentImpl::hasImpl("HOME"))
return EnvironmentImpl::getImpl("HOME");
else
return "/";
{
std::string path = EnvironmentImpl::getImpl("HOME");
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] != '/') path.append("/");
return path;
}
else return "/";
#else
std::string path;
if (EnvironmentImpl::hasImpl("HOME"))
{
path = EnvironmentImpl::getImpl("HOME");
}
else
{
struct passwd* pwd = getpwuid(getuid());
if (pwd)
{
path = pwd->pw_dir;
}
else
{
pwd = getpwuid(geteuid());
if (pwd)
path = pwd->pw_dir;
else
path = EnvironmentImpl::getImpl("HOME");
path = "/";
}
}
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] != '/') path.append("/");
@ -78,15 +91,23 @@ std::string PathImpl::configHomeImpl()
{
#if defined(POCO_VXWORKS)
return PathImpl::homeImpl();
#else
#elif POCO_OS == POCO_OS_MAC_OS_X
std::string path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
#if POCO_OS == POCO_OS_MAC_OS_X
path.append("Library/Preferences/");
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_CONFIG_HOME"))
path = EnvironmentImpl::getImpl("XDG_CONFIG_HOME");
if (!path.empty())
return path;
path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
path.append(".config/");
#endif
return path;
#endif
@ -97,15 +118,23 @@ std::string PathImpl::dataHomeImpl()
{
#if defined(POCO_VXWORKS)
return PathImpl::homeImpl();
#else
#elif POCO_OS == POCO_OS_MAC_OS_X
std::string path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
#if POCO_OS == POCO_OS_MAC_OS_X
path.append("Library/Application Support/");
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_DATA_HOME"))
path = EnvironmentImpl::getImpl("XDG_DATA_HOME");
if (!path.empty())
return path;
path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
path.append(".local/share/");
#endif
return path;
#endif
@ -116,15 +145,23 @@ std::string PathImpl::cacheHomeImpl()
{
#if defined(POCO_VXWORKS)
return PathImpl::tempImpl();
#else
#elif POCO_OS == POCO_OS_MAC_OS_X
std::string path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
#if POCO_OS == POCO_OS_MAC_OS_X
path.append("Library/Caches/");
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_CACHE_HOME"))
path = EnvironmentImpl::getImpl("XDG_CACHE_HOME");
if (!path.empty())
return path;
path = PathImpl::homeImpl();
std::string::size_type n = path.size();
if (n > 0 && path[n - 1] == '/')
path.append(".cache/");
#endif
return path;
#endif
@ -219,7 +256,15 @@ std::string PathImpl::expandImpl(const std::string& path)
}
while (it != end)
{
if (*it == '\\')
{
++it;
if (*it == '$')
{
result += *it++;
}
}
else if (*it == '$')
{
std::string var;
++it;
@ -238,6 +283,12 @@ std::string PathImpl::expandImpl(const std::string& path)
}
else result += *it++;
}
std::string::size_type found = result.find("//");
while (found != std::string::npos)
{
result.replace(found, 2, "/");
found = result.find("//", found+1);
}
return result;
}

View File

@ -110,6 +110,12 @@ int ProcessHandle::wait() const
}
int ProcessHandle::tryWait() const
{
return _pImpl->tryWait();
}
//
// Process
//
@ -166,6 +172,12 @@ int Process::wait(const ProcessHandle& handle)
}
int Process::tryWait(const ProcessHandle& handle)
{
return handle.tryWait();
}
void Process::kill(ProcessHandle& handle)
{
killImpl(*handle._pImpl);

View File

@ -66,7 +66,31 @@ int ProcessHandleImpl::wait() const
while (rc < 0 && errno == EINTR);
if (rc != _pid)
throw SystemException("Cannot wait for process", NumberFormatter::format(_pid));
if (WIFEXITED(status)) // normal termination
return WEXITSTATUS(status);
else // termination by a signal
return 256 + WTERMSIG(status);
}
int ProcessHandleImpl::tryWait() const
{
int status;
int rc;
do
{
rc = waitpid(_pid, &status, WNOHANG);
}
while (rc < 0 && errno == EINTR);
if (rc == 0)
return -1;
if (rc != _pid)
throw SystemException("Cannot wait for process", NumberFormatter::format(_pid));
if (WIFEXITED(status)) // normal termination
return WEXITSTATUS(status);
else // termination by a signal
return 256 + WTERMSIG(status);
}

View File

@ -45,6 +45,12 @@ int ProcessHandleImpl::wait() const
}
int ProcessHandleImpl::tryWait() const
{
throw Poco::NotImplementedException("Process::tryWait()");
}
//
// ProcessImpl
//

View File

@ -74,6 +74,18 @@ int ProcessHandleImpl::wait() const
}
int ProcessHandleImpl::tryWait() const
{
DWORD exitCode;
if (GetExitCodeProcess(_hProcess, &exitCode) == 0)
throw SystemException("Cannot get exit code for process", NumberFormatter::format(_pid));
if (exitCode == STILL_ACTIVE)
return -1;
else
return exitCode;
}
//
// ProcessImpl
//

View File

@ -78,6 +78,18 @@ int ProcessHandleImpl::wait() const
}
int ProcessHandleImpl::tryWait() const
{
DWORD exitCode;
if (GetExitCodeProcess(_hProcess, &exitCode) == 0)
throw SystemException("Cannot get exit code for process", NumberFormatter::format(_pid));
if (exitCode == STILL_ACTIVE)
return -1;
else
return exitCode;
}
//
// ProcessImpl
//

View File

@ -73,6 +73,18 @@ int ProcessHandleImpl::wait() const
}
int ProcessHandleImpl::tryWait() const
{
DWORD exitCode;
if (GetExitCodeProcess(_hProcess, &exitCode) == 0)
throw SystemException("Cannot get exit code for process", NumberFormatter::format(_pid));
if (exitCode == STILL_ACTIVE)
return -1;
else
return exitCode;
}
//
// ProcessImpl
//

View File

@ -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];

View File

@ -136,6 +136,22 @@ UUID UUIDGenerator::createOne()
}
void UUIDGenerator::seed()
{
Poco::FastMutex::ScopedLock lock(_mutex);
_random.seed();
}
void UUIDGenerator::seed(UInt32 n)
{
Poco::FastMutex::ScopedLock lock(_mutex);
_random.seed(n);
}
namespace
{
static SingletonHolder<UUIDGenerator> sh;

View File

@ -582,7 +582,7 @@ std::string Var::parseJSONString(const std::string& val, std::string::size_type&
++pos;
break;
case '\\':
if (pos < val.size())
if (pos < val.size() - 1)
{
++pos;
switch (val[pos])
@ -606,7 +606,6 @@ std::string Var::parseJSONString(const std::string& val, std::string::size_type&
result += val[pos];
break;
}
break;
}
else
{

View File

@ -38,7 +38,7 @@ void LogStreamTest::testLogStream()
{
AutoPtr<TestChannel> pChannel = new TestChannel;
Logger& root = Logger::root();
root.setChannel(pChannel.get());
root.setChannel(pChannel);
LogStream ls(root);

View File

@ -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) == "\\");
}

View File

@ -2622,6 +2622,10 @@ void VarTest::testJSONDeserializeString()
tst = "{ \"a\" : \"1\", \"b\" : \"2\"\n}";
a = Var::parse(tst);
assertTrue (a.toString() == "{ \"a\" : \"1\", \"b\" : \"2\" }");
tst = "{ \"message\" : \"escape\\b\\f\\n\\r\\t\", \"path\" : \"\\/dev\\/null\" }";
a = Var::parse(tst);
assertTrue(a.toString() == "{ \"message\" : \"escape\\b\\f\\n\\r\\t\", \"path\" : \"\\/dev\\/null\" }");
}

View File

@ -73,16 +73,16 @@ public:
Array(const Array& copy);
/// Creates an Array by copying another one.
Array(Array&& other);
Array(Array&& other) noexcept;
/// Move constructor
Array& operator=(Array&& other);
/// Move assignment operator.
Array& operator=(const Array& other);
Array& operator = (const Array& other);
/// Assignment operator.
virtual ~Array();
Array& operator = (Array&& other) noexcept;
/// Move assignment operator.
~Array();
/// Destroys the Array.
void setEscapeUnicode(bool escape = true);

View File

@ -84,18 +84,18 @@ public:
/// Struct is not copied to keep the operation as
/// efficient as possible (when needed, it will be generated upon request).
Object(Object&& other);
Object(Object&& other) noexcept;
/// Move constructor
Object &operator =(Object &&other);
// Move asignment operator
virtual ~Object();
~Object();
/// Destroys the Object.
Object &operator =(const Object &other);
Object &operator = (const Object &other);
// Assignment operator
Object &operator = (Object &&other) noexcept;
// Move asignment operator
void setEscapeUnicode(bool escape = true);
/// Sets the flag for escaping unicode.

View File

@ -25,46 +25,50 @@ namespace Poco {
namespace JSON {
Array::Array(int options): _modified(false),
Array::Array(int options):
_modified(false),
_escapeUnicode((options & Poco::JSON_ESCAPE_UNICODE) != 0)
{
}
Array::Array(const Array& other) : _values(other._values),
Array::Array(const Array& other) :
_values(other._values),
_pArray(other._pArray),
_modified(other._modified)
_modified(other._modified),
_escapeUnicode(other._escapeUnicode)
{
}
Array &Array::operator=(const Array& other)
Array::Array(Array&& other) noexcept:
_values(std::move(other._values)),
_pArray(std::move(other._pArray)),
_modified(other._modified),
_escapeUnicode(other._escapeUnicode)
{
}
Array& Array::operator = (const Array& other)
{
if (&other != this)
{
_values = other._values;
_pArray = other._pArray;
_modified = other._modified;
_escapeUnicode = other._escapeUnicode;
}
return *this;
}
Array::Array(Array&& other):
_values(std::move(other._values)),
_pArray(!other._modified ? other._pArray : 0),
_modified(other._modified)
{
_pArray = 0;
}
Array &Array::operator = (Array&& other)
Array& Array::operator = (Array&& other) noexcept
{
_values = std::move(other._values);
_pArray = other._pArray;
other._pArray = 0;
_pArray = std::move(other._pArray);
_modified = other._modified;
_escapeUnicode = other._escapeUnicode;
return *this;
}

View File

@ -42,29 +42,15 @@ Object::Object(const Object& other) : _values(other._values),
}
Object::Object(Object&& other):
Object::Object(Object&& other) noexcept:
_values(std::move(other._values)),
_keys(std::move(other._keys)),
_preserveInsOrder(other._preserveInsOrder),
_escapeUnicode(other._escapeUnicode),
_pStruct(!other._modified ? other._pStruct : 0),
_pStruct(std::move(other._pStruct)),
_pOrdStruct(std::move(other._pOrdStruct)),
_modified(other._modified)
{
other.clear();
}
Object &Object::operator = (Object&& other)
{
_values = other._values;
_preserveInsOrder = other._preserveInsOrder;
syncKeys(other._keys);
_escapeUnicode = other._escapeUnicode;
_pStruct = !other._modified ? other._pStruct : 0;
_modified = other._modified;
other.clear();
return *this;
}
@ -73,7 +59,7 @@ Object::~Object()
}
Object &Object::operator= (const Object &other)
Object &Object::operator = (const Object &other)
{
if (&other != this)
{
@ -88,6 +74,20 @@ Object &Object::operator= (const Object &other)
}
Object& Object::operator = (Object&& other) noexcept
{
_values = std::move(other._values);
_keys = std::move(other._keys);
_preserveInsOrder = other._preserveInsOrder;
_escapeUnicode = other._escapeUnicode;
_pStruct = std::move(other._pStruct);
_pOrdStruct = std::move(other._pOrdStruct);
_modified = other._modified;
return *this;
}
void Object::syncKeys(const KeyList& keys)
{
if(_preserveInsOrder)

View File

@ -435,7 +435,7 @@ void HTMLForm::writeMultipart(std::ostream& ostr)
// count only, don't move stream position
std::streamsize partlen = part.pSource->getContentLength();
if (partlen != PartSource::UNKNOWN_CONTENT_LENGTH)
pCountingOutputStream->addChars(static_cast<int>(partlen));
pCountingOutputStream->addChars(partlen);
else
pCountingOutputStream->setValid(false);
}

View File

@ -310,7 +310,6 @@ std::istream& HTTPClientSession::receiveResponse(HTTPResponse& response)
networkException()->rethrow();
else
throw;
throw;
}
}
while (response.getStatus() == HTTPResponse::HTTP_CONTINUE);

View File

@ -1357,14 +1357,17 @@ NetworkInterface::Type fromNative(u_char nativeType)
void setInterfaceParams(struct ifaddrs* iface, NetworkInterfaceImpl& impl)
{
struct sockaddr_dl* sdl = (struct sockaddr_dl*) iface->ifa_addr;
impl.setName(iface->ifa_name);
impl.setDisplayName(iface->ifa_name);
impl.setAdapterName(iface->ifa_name);
impl.setPhyParams();
if (iface->ifa_addr->sa_family == AF_LINK)
{
struct sockaddr_dl* sdl = (struct sockaddr_dl*) iface->ifa_addr;
impl.setMACAddress(LLADDR(sdl), sdl->sdl_alen);
impl.setType(fromNative(sdl->sdl_type));
}
}
@ -1536,9 +1539,12 @@ void setInterfaceParams(struct ifaddrs* iface, NetworkInterfaceImpl& impl)
impl.setPhyParams();
#ifndef POCO_NO_LINUX_IF_PACKET_H
if (iface->ifa_addr->sa_family == AF_PACKET)
{
struct sockaddr_ll* sdl = (struct sockaddr_ll*) iface->ifa_addr;
impl.setMACAddress(sdl->sll_addr, sdl->sll_halen);
impl.setType(fromNative(sdl->sll_hatype));
}
#else
std::string ifPath("/sys/class/net/");
ifPath += iface->ifa_name;

View File

@ -91,7 +91,7 @@ X509Certificate& X509Certificate::operator = (const X509Certificate& cert)
X509Certificate& X509Certificate::operator = (X509Certificate&& cert) noexcept
{
Poco::Crypto::X509Certificate::operator = (cert);
Poco::Crypto::X509Certificate::operator = (std::move(cert));
return *this;
}

View File

@ -84,7 +84,7 @@ private:
const PageReader* _pParent;
std::string _path;
std::string _attrs;
int _line;
std::streamsize _line;
bool _emitLineDirectives;
};

View File

@ -123,7 +123,6 @@ bool SystemConfiguration::getRaw(const std::string& key, std::string& value) con
{
value = Path::dataHome();
}
else if (key == TEMPHOMEDIR)
{
value = Path::tempHome();

View File

@ -19,3 +19,4 @@ class CppUnit::TestCaller<class SystemConfigurationTest>.testProperties
class CppUnit::TestCaller<class WinServiceTest>.testServiceReturnsTrueIfStopped
class CppUnit::TestCaller<class ICMPSocketTest>.testSendToReceiveFrom
class CppUnit::TestCaller<class ICMPSocketTest>.testMTU
class CppUnit::TestCaller<class HTTPSClientSessionTest>.testCachedSession