Skip to content

Commit

Permalink
enh(Poco): Mark deprecated functionality with C++ attributes and reso…
Browse files Browse the repository at this point in the history
…lve internal usage of deprecated functions (#4551)

* enh(poco): Replace deprecated comments with C++ deprecated attribute.

* enh(Poco): Replace some deprecated functionality in Poco sources. (#4426)

* enh(Poco): Replace more deprecated functionality in Poco sources. (#4426)

* fix(CMake): Variable BUILD_SHARED_LIBS must be defined properly to create valid binaries.

* enh: Code improvements done while resolving deprecated functionality (#4426)

* Un-deprecate LocalDateTme (#4426)

* enh(Poco): Replace usage of deprecated functionality with other functions/classes (#4426)

* chore(SSL): temporarily un-deprecate SSL-related functionality (#4426)

* chore(SSL): temporarily un-deprecate old MongoDB protocol functionality (#4426)

* enh(Poco): Minor Hash improvements (#4426)

* enh(Foundation): Compile deprecated hash tests only when POCO_TEST_DEPRECATED is enabled (#4426)

* enh(Net): Compile deprecated Socket::select functionality only when POCO_TEST_DEPRECATED is enabled (#4426)

* enh(Bonjour): Replace deprecated Socket::select with PollSet (#4426)

* enh(Poco): Introduce POCO_DEPRECATED macro to have the ability to disable deprecation warnings in applications (#4426)

* test(ODBC): add few asserts to testStoredProcedureDynamicVar

* fix(ODBC): rename DynamicAny -> DynamicVar in tests

* fix(ODBC): make Dignostics static members inline to prevent explicit instantiation warnings on windows

---------

Co-authored-by: Alex Fabijanic <[email protected]>
  • Loading branch information
matejk and aleks-f committed Jul 29, 2024
1 parent 5117e27 commit f24547c
Show file tree
Hide file tree
Showing 112 changed files with 586 additions and 550 deletions.
7 changes: 1 addition & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ include(GNUInstallDirs)
# Include some common macros to simpilfy the Poco CMake files
include(PocoMacros)

if(POCO_STATIC)
message(WARNING "POCO_STATIC has been deprecated. Please use BUILD_SHARED_LIBS=NO to build static libraries.")
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
else()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

if(MSVC)
option(POCO_MT "Set to OFF|ON (default is OFF) to control build of POCO as /MT instead of /MD" OFF)
Expand Down
4 changes: 2 additions & 2 deletions CppUnit/src/TestCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ void TestCase::assertEquals(const char* expected, const std::string& actual, lon

void TestCase::assertNotNull(const void* pointer, const std::string& pointerExpression, long lineNumber, const std::string& fileName)
{
if (pointer == NULL)
if (pointer == nullptr)
throw CppUnitException(pointerExpression + " must not be NULL", lineNumber, fileName);
}


void TestCase::assertNull(const void* pointer, const std::string& pointerExpression, long lineNumber, const std::string& fileName)
{
if (pointer != NULL)
if (pointer != nullptr)
throw CppUnitException(pointerExpression + " must be NULL", lineNumber, fileName);
}

Expand Down
14 changes: 6 additions & 8 deletions CppUnit/src/TextTestResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,18 @@ void TextTestResult::printErrors(std::ostream& stream)
stream << "There were " << testErrors() << " errors: " << std::endl;

int i = 1;
for (std::vector<TestFailure*>::iterator it = errors().begin(); it != errors().end(); ++it)
for (const auto& failure : errors())
{
TestFailure* failure = *it;
CppUnitException* e = failure->thrownException();

stream << std::setw(2) << i
<< ": "
<< failure->failedTest()->toString() << "\n"
<< " \"" << (e ? e->what() : "") << "\"\n"
<< " \"" << (e ? e->what() : "") << "\"\n"
<< " in \""
<< (e ? e->fileName() : std::string())
<< "\", line ";
if (e == 0)
if (e == nullptr)
{
stream << "0";
}
Expand Down Expand Up @@ -210,10 +209,9 @@ void TextTestResult::printFailures(std::ostream& stream)

int i = 1;

for (std::vector<TestFailure*>::iterator it = failures().begin(); it != failures().end(); ++it)
for (const auto& failure : failures())
{
TestFailure* failure = *it;
CppUnitException* e = failure->thrownException();
CppUnitException* e = failure->thrownException();

stream << std::setw(2) << i
<< ": "
Expand All @@ -222,7 +220,7 @@ void TextTestResult::printFailures(std::ostream& stream)
<< " in \""
<< (e ? e->fileName() : std::string())
<< "\", line ";
if (e == 0)
if (e == nullptr)
{
stream << "0";
}
Expand Down
2 changes: 1 addition & 1 deletion Crypto/include/Poco/Crypto/ECKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ namespace Crypto {
class X509Certificate;
class PKCS12Container;

//class [[deprecated]] ECKey;

//@ deprecated
class Crypto_API ECKey: public KeyPair
/// This class stores an EC key pair, consisting
/// of private and public key. Storage of the private
Expand Down
2 changes: 0 additions & 2 deletions Crypto/include/Poco/Crypto/ECKeyImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/EVPPKey.h"
#include "Poco/Crypto/KeyPairImpl.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <istream>
#include <ostream>
Expand Down
20 changes: 10 additions & 10 deletions Crypto/include/Poco/Crypto/EVPPKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <sstream>
#include <typeinfo>
#include <map>


namespace Poco {
namespace Crypto {

//@deprecated
//class [[deprecated]] ECKey;
//class [[deprecated]] RSAKey;
class ECKey;
//@deprecated
class RSAKey;
class PKCS12Container;
class X509Certificate;
Expand Down Expand Up @@ -93,8 +92,8 @@ class Crypto_API EVPPKey
/// Constructs EVPPKey from EVP_PKEY pointer.
/// The content behind the supplied pointer is internally duplicated.

//@ deprecated
template<typename K>
//[[deprecated]] explicit EVPPKey(K* pKey): _pEVPPKey(EVP_PKEY_new())
explicit EVPPKey(K* pKey): _pEVPPKey(EVP_PKEY_new())
/// Constructs EVPPKey from a "native" OpenSSL (RSA or EC_KEY),
/// or a Poco wrapper (RSAKey, ECKey) key pointer.
Expand Down Expand Up @@ -185,13 +184,16 @@ class Crypto_API EVPPKey
void newECKey(const char* group);
void duplicate(EVP_PKEY* pEVPPKey);

//@ deprecated
//[[deprecated]]
void setKey(ECKey* pKey);
//@ deprecated

//[[deprecated]]
void setKey(RSAKey* pKey);
//@ deprecated

//[[deprecated]]
void setKey(EC_KEY* pKey);
//@ deprecated

//[[deprecated]]
void setKey(RSA* pKey);

static int passCB(char* buf, int size, int, void* pass);
Expand Down Expand Up @@ -336,9 +338,7 @@ class Crypto_API EVPPKey
EVP_PKEY* _pEVPPKey = 0;
static const std::map<int, std::string> KNOWN_TYPES;

//@deprecated
friend class ECKeyImpl;
//@deprecated
friend class RSAKeyImpl;
};

Expand Down
2 changes: 1 addition & 1 deletion Crypto/include/Poco/Crypto/RSADigestEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine
DIGEST_SHA1
};

//@ deprecated
//[[deprecated]] RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1);
RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1);
/// Creates the RSADigestEngine with the given RSA key,
/// using the MD5 or SHA-1 hash algorithm.
Expand Down
6 changes: 3 additions & 3 deletions Crypto/include/Poco/Crypto/RSAKey.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace Crypto {
class X509Certificate;
class PKCS12Container;

//class [[deprecated]] RSAKey;

//@ deprecated
class Crypto_API RSAKey: public KeyPair
/// This class stores an RSA key pair, consisting
/// of private and public key. Storage of the private
Expand Down Expand Up @@ -81,7 +81,7 @@ class Crypto_API RSAKey: public KeyPair
/// OpenSSL will auto-create the public key from the private key.

RSAKey(std::istream* pPublicKeyStream,
std::istream* pPrivateKeyStream = 0,
std::istream* pPrivateKeyStream = nullptr,
const std::string& privateKeyPassphrase = "");
/// Creates the RSAKey, by reading public and private key from the given streams and
/// using the given passphrase for the private key.
Expand Down Expand Up @@ -132,4 +132,4 @@ inline RSAKeyImpl::Ptr RSAKey::impl() const
} } // namespace Poco::Crypto


#endif // Crypto_RSAKey_INCLUDED
#endif // Crypto_RSAKey_INCLUDED
5 changes: 5 additions & 0 deletions Crypto/testsuite/src/ECTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ECTest::~ECTest()
{
}

#if defined(POCO_TEST_DEPRECATED)

void ECTest::testECNewKeys()
{
Expand Down Expand Up @@ -176,6 +177,7 @@ void ECTest::testECDSASignManipulated()
}
}

#endif

void ECTest::setUp()
{
Expand All @@ -191,10 +193,13 @@ CppUnit::Test* ECTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ECTest");

#if defined(POCO_TEST_DEPRECATED)

CppUnit_addTest(pSuite, ECTest, testECNewKeys);
CppUnit_addTest(pSuite, ECTest, testECNewKeysNoPassphrase);
CppUnit_addTest(pSuite, ECTest, testECDSASignSha256);
CppUnit_addTest(pSuite, ECTest, testECDSASignManipulated);

#endif
return pSuite;
}
4 changes: 4 additions & 0 deletions Crypto/testsuite/src/ECTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ class ECTest: public CppUnit::TestCase
ECTest(const std::string& name);
~ECTest();

#if defined(POCO_TEST_DEPRECATED)

void testECNewKeys();
void testECNewKeysNoPassphrase();
void testECDSASignSha256();
void testECDSASignManipulated();

#endif

void setUp();
void tearDown();

Expand Down
4 changes: 2 additions & 2 deletions DNSSD/Bonjour/include/Poco/DNSSD/Bonjour/EventLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DNSSD_Bonjour_API EventLoop: public Poco::Runnable
/// Bonjour machinery.
{
public:
typedef Poco::ScopedLock<EventLoop> ScopedLock;
using ScopedLock = Poco::ScopedLock<EventLoop>;

enum
{
Expand All @@ -51,7 +51,7 @@ class DNSSD_Bonjour_API EventLoop: public Poco::Runnable
EventLoop();
/// Creates the EventLoop.

~EventLoop();
~EventLoop() override;
/// Destroys the EventLoop.

void add(DNSServiceRef sdRef);
Expand Down
68 changes: 30 additions & 38 deletions DNSSD/Bonjour/src/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


#include "Poco/DNSSD/Bonjour/EventLoop.h"
#include "Poco/Net/PollSet.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/StreamSocketImpl.h"
#include <dns_sd.h>
Expand Down Expand Up @@ -46,11 +47,9 @@ EventLoop::~EventLoop()

void EventLoop::shutdown()
{
RefToSock::iterator it = _refs.begin();
RefToSock::iterator itEnd = _refs.end();
for (; it != itEnd; ++it)
for (auto& it: _refs)
{
DNSServiceRefDeallocate(it->first);
DNSServiceRefDeallocate(it.first);
}
_refs.clear();
_sockets.clear();
Expand Down Expand Up @@ -83,7 +82,7 @@ void EventLoop::remove(DNSServiceRef sdRef)

void EventLoop::removeImpl(DNSServiceRef sdRef)
{
RefToSock::iterator it = _refs.find(sdRef);
auto it = _refs.find(sdRef);
if (it != _refs.end())
{
_sockets.erase(it->second);
Expand All @@ -95,59 +94,52 @@ void EventLoop::removeImpl(DNSServiceRef sdRef)

void EventLoop::run()
{
Poco::Net::Socket::SocketList readList;
Poco::Net::Socket::SocketList writeList;
Poco::Net::Socket::SocketList errList;
Poco::Net::PollSet pollSet;

while (!_stop)
{
readList.clear();
if (!_refs.empty() || _refAdded.tryWait(EVENTLOOP_TIMEOUT))
{
Poco::Mutex::ScopedLock lock(_mutex);

RefToSock::const_iterator it = _refs.begin();
RefToSock::const_iterator itEnd = _refs.end();
for (; it != itEnd; ++it)
Poco::Mutex::ScopedLock lock(_mutex);
for (const auto& r: _refs)
{
readList.push_back(it->second);
pollSet.add(r.second, Net::Socket::SELECT_READ);
}
}

if (!readList.empty())
if (!pollSet.empty())
{
Poco::Timespan timeout(1000*EVENTLOOP_TIMEOUT);
int ready = Poco::Net::Socket::select(readList, writeList, errList, timeout);
if (ready > 0)
Poco::Timespan timeout(1000LL * EVENTLOOP_TIMEOUT);
const auto sm = pollSet.poll(timeout);
if (!sm.empty())
{
Poco::Net::Socket::SocketList::iterator it = readList.begin();
Poco::Net::Socket::SocketList::iterator itEnd = readList.end();
for (; it != itEnd; ++it)
for (const auto& it: sm)
{
Poco::Mutex::ScopedLock lock(_mutex);

SockToRef::iterator itSock = _sockets.find(*it);
poco_assert_dbg (itSock != _sockets.end());
RefSet::iterator itSet = _invalidatedRefs.find(itSock->second);
if (itSet != _invalidatedRefs.end())
if (it.second & Net::PollSet::POLL_READ)
{
removeImpl(itSock->second);
_invalidatedRefs.erase(itSet);
}
else
{
DNSServiceProcessResult(itSock->second);
auto& socket = it.first;
const auto itSock = _sockets.find(socket);
poco_assert_dbg (itSock != _sockets.end());
auto itSet = _invalidatedRefs.find(itSock->second);
if (itSet != _invalidatedRefs.end())
{
removeImpl(itSock->second);
_invalidatedRefs.erase(itSet);
}
else
{
DNSServiceProcessResult(itSock->second);
}
}
}
}
}

Poco::Mutex::ScopedLock lock(_mutex);
RefSet::iterator itSet =_invalidatedRefs.begin();
RefSet::iterator itSetEnd = _invalidatedRefs.end();
for (; itSet != itSetEnd; ++itSet)
Poco::Mutex::ScopedLock lock(_mutex);
for (auto& ir: _invalidatedRefs)
{
removeImpl(*itSet);
removeImpl(ir);
}
_invalidatedRefs.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion Data/DataTest/src/SQLExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2983,7 +2983,7 @@ void SQLExecutor::filter(const std::string& query, const std::string& intFldName
{
Statement stmt = (session() << query, now);
RecordSet rset(stmt);
assertTrue (rset.totalRowCount() == 4);
assertTrue (rset.getTotalRowCount() == 4);
RowFilter::Ptr pRF = new RowFilter(&rset);
assertTrue (pRF->isEmpty());
pRF->add(intFldName, RowFilter::VALUE_EQUAL, 1);
Expand Down
8 changes: 4 additions & 4 deletions Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class Diagnostics
{
public:

static const unsigned int SQL_STATE_SIZE = SQL_SQLSTATE_SIZE + 1;
static const unsigned int SQL_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH + 1;
static const unsigned int SQL_NAME_LENGTH = 128;
static const std::string DATA_TRUNCATED;
inline static const unsigned int SQL_STATE_SIZE = SQL_SQLSTATE_SIZE + 1;
inline static const unsigned int SQL_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH + 1;
inline static const unsigned int SQL_NAME_LENGTH = 128;
inline static const std::string DATA_TRUNCATED;

struct DiagnosticFields
{
Expand Down
Loading

0 comments on commit f24547c

Please sign in to comment.