From f173eab9da9f84cb8349b78efb1ae8ac0a7ca7fe Mon Sep 17 00:00:00 2001 From: Jan Willamowius Date: Wed, 22 Nov 2023 03:35:54 +0100 Subject: [PATCH] C++17 support --- ProxyChannel.cxx | 4 ++++ RasSrv.cxx | 38 ++++++++++++++++++++++++++++++++++++- Routing.cxx | 2 -- Toolkit.cxx | 20 +++++++++++++++++++- Toolkit.h | 2 -- capctrl.cxx | 23 ++++++++++++++++++++++- clirw.cxx | 23 ++++++++++++++++++++++- factory.h | 9 +++++++++ ipauth.cxx | 9 ++++++++- stl_supp.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 169 insertions(+), 10 deletions(-) diff --git a/ProxyChannel.cxx b/ProxyChannel.cxx index ac11bbf1..f3063df4 100644 --- a/ProxyChannel.cxx +++ b/ProxyChannel.cxx @@ -17818,7 +17818,11 @@ bool H245ProxyHandler::RemoveLogicalChannel(WORD flcn) return false; } LogicalChannel * lc = iter->second; +#if (__cplusplus >= 201703L) // C++17 + siterator i = find_if(sessionIDs.begin(), sessionIDs.end(), bind(compare_lc, std::placeholders::_1, lc)); +#else siterator i = find_if(sessionIDs.begin(), sessionIDs.end(), bind2nd(std::ptr_fun(compare_lc), lc)); +#endif if (i != sessionIDs.end()) sessionIDs.erase(i); logicalChannels.erase(iter); diff --git a/RasSrv.cxx b/RasSrv.cxx index 17518a1d..baa52ed1 100644 --- a/RasSrv.cxx +++ b/RasSrv.cxx @@ -2,7 +2,7 @@ // // RAS Server for GNU Gatekeeper // -// Copyright (c) 2000-2021, Jan Willamowius +// Copyright (c) 2000-2023, Jan Willamowius // Copyright (c) Citron Network Inc. 2001-2003 // // This work is published under the GNU Public License version 2 (GPLv2) @@ -1009,7 +1009,11 @@ void RasServer::LoadConfig() for (int i = 0; i < hsize; ++i) { Address addr(GKHome[i]); +#if (__cplusplus >= 201703L) // C++17 + ifiterator iter = find_if(interfaces.begin(), interfaces.end(), bind(mem_fn(&GkInterface::IsBoundTo), std::placeholders::_1, &addr)); +#else ifiterator iter = find_if(interfaces.begin(), interfaces.end(), bind2nd(mem_fun(&GkInterface::IsBoundTo), &addr)); +#endif if (iter == interfaces.end()) { GkInterface *gkif = CreateInterface(addr); if (gkif->CreateListeners(this)) { @@ -1161,12 +1165,20 @@ GkInterface *RasServer::SelectInterface(const Address & addr) if (interfaces.empty()) return NULL; // prefer the interface that actually has the IP bound to it +#if (__cplusplus >= 201703L) // C++17 + ifiterator iter = find_if(interfaces.begin(), interfaces.end(), bind(mem_fn(&GkInterface::IsBoundTo), std::placeholders::_1, &addr)); +#else ifiterator iter = find_if(interfaces.begin(), interfaces.end(), bind2nd(mem_fun(&GkInterface::IsBoundTo), &addr)); +#endif if (iter != interfaces.end()) { return *iter; } // otherwise use an interface that can reach the IP +#if (__cplusplus >= 201703L) // C++17 + iter = find_if(interfaces.begin(), interfaces.end(), bind(mem_fn(&GkInterface::IsReachable), std::placeholders::_1, &addr)); +#else iter = find_if(interfaces.begin(), interfaces.end(), bind2nd(mem_fun(&GkInterface::IsReachable), &addr)); +#endif if (iter != interfaces.end()) { return *iter; } @@ -1718,9 +1730,17 @@ void RasServer::CreateRasJob(GatekeeperMessage * msg, bool syncronous) PWaitAndSignal rlock(requests_mutex); PWaitAndSignal hlock(handlers_mutex); if (RasMsg *ras = RasFactory::Create(tag, msg)) { +#if (__cplusplus >= 201703L) // C++17 + std::list::iterator iter = find_if(handlers.begin(), handlers.end(), bind(mem_fn(&RasHandler::IsExpected), std::placeholders::_1, ras)); +#else std::list::iterator iter = find_if(handlers.begin(), handlers.end(), bind2nd(mem_fun(&RasHandler::IsExpected), ras)); +#endif if (iter == handlers.end()) { +#if (__cplusplus >= 201703L) // C++17 + std::list::iterator i = find_if(requests.begin(), requests.end(), bind(mem_fn(&RasMsg::EqualTo), std::placeholders::_1, ras)); +#else std::list::iterator i = find_if(requests.begin(), requests.end(), bind2nd(mem_fun(&RasMsg::EqualTo), ras)); +#endif if (i != requests.end() && !(*i)->IsDone()) { PTRACE(2, "RAS\tDuplicate " << msg->GetTagName() << ", deleted"); delete ras; @@ -1753,7 +1773,11 @@ void RasServer::CleanUp() { PWaitAndSignal lock(requests_mutex); if (!requests.empty()) { +#if (__cplusplus >= 201703L) // C++17 + std::list::iterator iter = partition(requests.begin(), requests.end(), mem_fn(&RasMsg::IsDone)); +#else std::list::iterator iter = partition(requests.begin(), requests.end(), mem_fun(&RasMsg::IsDone)); +#endif DeleteObjects(requests.begin(), iter); requests.erase(requests.begin(), iter); } @@ -4844,7 +4868,11 @@ template<> bool RasPDU::Process() // find the neighbor this comes from NeighborList::List & neighbors = *RasServer::Instance()->GetNeighbors(); +#if (__cplusplus >= 201703L) // C++17 + NeighborList::List::iterator iter = find_if(neighbors.begin(), neighbors.end(), bind(mem_fn(&Neighbors::Neighbor::IsFrom), std::placeholders::_1, &m_msg->m_peerAddr)); +#else NeighborList::List::iterator iter = find_if(neighbors.begin(), neighbors.end(), bind2nd(mem_fun(&Neighbors::Neighbor::IsFrom), &m_msg->m_peerAddr)); +#endif Neighbors::Neighbor * from_neighbor = NULL; bool neighbor_authenticated = true; if (iter != neighbors.end()) @@ -4899,7 +4927,11 @@ template<> bool RasPDU::Process() && (request.m_cryptoTokens[0].GetTag() == H225_CryptoH323Token::e_cryptoGKPwdHash)) { H225_CryptoH323Token_cryptoGKPwdHash & token = request.m_cryptoTokens[0]; PString gkid = token.m_gatekeeperId; +#if (__cplusplus >= 201703L) // C++17 + NeighborList::List::iterator iter = find_if(neighbors.begin(), neighbors.end(), bind(mem_fn(&Neighbors::Neighbor::IsTraversalUser), std::placeholders::_1, &gkid)); +#else NeighborList::List::iterator iter = find_if(neighbors.begin(), neighbors.end(), bind2nd(mem_fun(&Neighbors::Neighbor::IsTraversalUser), &gkid)); +#endif if (iter != neighbors.end()) { from_neighbor = (*iter); neighbor_authenticated = from_neighbor->Authenticate(this); @@ -4967,7 +4999,11 @@ template<> bool RasPDU::Process() #ifdef HAS_H46018 // check if it belongs to a neighbor SCI and use the keepAliveInterval NeighborList::List & neighbors = *RasServer::Instance()->GetNeighbors(); +#if (__cplusplus >= 201703L) // C++17 + NeighborList::List::iterator iter = find_if(neighbors.begin(), neighbors.end(), bind(mem_fn(&Neighbors::Neighbor::IsFrom), std::placeholders::_1, &m_msg->m_peerAddr)); +#else NeighborList::List::iterator iter = find_if(neighbors.begin(), neighbors.end(), bind2nd(mem_fun(&Neighbors::Neighbor::IsFrom), &m_msg->m_peerAddr)); +#endif if (iter != neighbors.end()) { if (request.HasOptionalField(H225_ServiceControlResponse::e_result)) { if (request.m_result.GetTag() == H225_ServiceControlResponse_result::e_started) { diff --git a/Routing.cxx b/Routing.cxx index 60b012a9..5921f320 100644 --- a/Routing.cxx +++ b/Routing.cxx @@ -38,8 +38,6 @@ #include #endif // HAS_LIBCURL -#include - using std::string; using std::vector; using std::list; diff --git a/Toolkit.cxx b/Toolkit.cxx index 8ce3c94a..5778d52a 100644 --- a/Toolkit.cxx +++ b/Toolkit.cxx @@ -23,6 +23,9 @@ #if !defined(_WIN32) && !defined(_WIN64) #include #endif // _WIN32 +#if (__cplusplus >= 201703L) // C++17 +#include +#endif #include "stl_supp.h" #include "gktimer.h" #include "h323util.h" @@ -476,7 +479,11 @@ PIPSocket::Address Toolkit::RouteTable::GetLocalAddress(const Address & addr) co if (addr << m_internalnetworks[j]) { // check if internal network is in route table, but don't use the default route RouteEntry *entry = find_if(rtable_begin, rtable_end, +#if (__cplusplus >= 201703L) // C++17 + bind(mem_fn(&RouteEntry::CompareWithoutMask), std::placeholders::_1, &addr)); +#else bind2nd(mem_fun_ref(&RouteEntry::CompareWithoutMask), &addr)); +#endif if ((entry != rtable_end) && (entry->GetNetMask() != INADDR_ANY) #ifdef hasIPV6 && (entry->GetNetMask() != in6addr_any) @@ -517,7 +524,11 @@ PIPSocket::Address Toolkit::RouteTable::GetLocalAddress(const Address & addr) co } } RouteEntry *entry = find_if(rtable_begin, rtable_end, +#if (__cplusplus >= 201703L) // C++17 + bind(mem_fn(&RouteEntry::CompareWithMask), std::placeholders::_1, &addr)); +#else bind2nd(mem_fun_ref(&RouteEntry::CompareWithMask), &addr)); +#endif if (entry != rtable_end) { return entry->GetDestination(); } @@ -3659,8 +3670,15 @@ bool Toolkit::GetH46023STUN(const PIPSocket::Address & addr, H323TransportAddres int intID = m_ProxyCriterion.IsInternal(addr); std::map >::iterator inf = m_H46023STUN.find(intID); if (inf != m_H46023STUN.end()) { - if (inf->second.size() > 1) + if (inf->second.size() > 1) { +#if (__cplusplus >= 201703L) // C++17 + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(inf->second.begin(), inf->second.end(), g); +#else std::random_shuffle(inf->second.begin(), inf->second.end()); +#endif + } stun = inf->second.front(); return true; } diff --git a/Toolkit.h b/Toolkit.h index a4d8ef37..6ce1c261 100644 --- a/Toolkit.h +++ b/Toolkit.h @@ -32,8 +32,6 @@ extern "C" { #include #include #include -// on Windows PTLib 2.10.x doesn't set an #pragma include_alias for this file, -// so the OpenSSL include dir must be added to IDE settings #include // needed for certificate check } #endif diff --git a/capctrl.cxx b/capctrl.cxx index d9717760..d6726471 100644 --- a/capctrl.cxx +++ b/capctrl.cxx @@ -6,7 +6,7 @@ * $Id$ * * Copyright (c) 2006, Michal Zygmuntowicz - * Copyright (c) 2008-2016, Jan Willamowius + * Copyright (c) 2008-2023, Jan Willamowius * * This work is published under the GNU Public License version 2 (GPLv2) * see file COPYING for details. @@ -31,7 +31,14 @@ namespace { // greater operators for sorting route lists +#if (__cplusplus >= 201703L) +struct IpRule_greater { + typedef CapacityControl::IpCallVolume first_argument_type; + typedef CapacityControl::IpCallVolume second_argument_type; + typedef bool result_type; +#else struct IpRule_greater : public std::binary_function { +#endif bool operator()(const CapacityControl::IpCallVolume &e1, const CapacityControl::IpCallVolume &e2) const { @@ -49,7 +56,14 @@ struct IpRule_greater : public std::binary_function= 201703L) +struct H323IdRule_greater { + typedef CapacityControl::H323IdCallVolume first_argument_type; + typedef CapacityControl::H323IdCallVolume second_argument_type; + typedef bool result_type; +#else struct H323IdRule_greater : public std::binary_function { +#endif bool operator()(const CapacityControl::H323IdCallVolume & e1, const CapacityControl::H323IdCallVolume & e2) const { @@ -57,7 +71,14 @@ struct H323IdRule_greater : public std::binary_function= 201703L) +struct CLIRule_greater { + typedef CapacityControl::CLICallVolume first_argument_type; + typedef CapacityControl::CLICallVolume second_argument_type; + typedef bool result_type; +#else struct CLIRule_greater : public std::binary_function { +#endif bool operator()(const CapacityControl::CLICallVolume & e1, const CapacityControl::CLICallVolume & e2) const { diff --git a/clirw.cxx b/clirw.cxx index 67511879..4872d544 100644 --- a/clirw.cxx +++ b/clirw.cxx @@ -6,7 +6,7 @@ * $Id$ * * Copyright (c) 2005, Michal Zygmuntowicz - * Copyright (c) 2007-2013, Jan Willamowius + * Copyright (c) 2007-2023, Jan Willamowius * * This work is published under the GNU Public License version 2 (GPLv2) * see file COPYING for details. @@ -102,7 +102,14 @@ PString CLIRewrite::RewriteRule::AsString() const } namespace { +#if (__cplusplus >= 201703L) // C++17 +struct RewriteRule_greater { + typedef CLIRewrite::RewriteRule first_argument_type; + typedef CLIRewrite::RewriteRule second_argument_type; + typedef bool result_type; +#else struct RewriteRule_greater : public std::binary_function { +#endif bool operator()(const CLIRewrite::RewriteRule &e1, const CLIRewrite::RewriteRule &e2) const { @@ -116,7 +123,14 @@ struct RewriteRule_greater : public std::binary_function= 201703L) // C++17 +struct SingleIpRule_greater { + typedef CLIRewrite::SingleIpRule first_argument_type; + typedef CLIRewrite::SingleIpRule second_argument_type; + typedef bool result_type; +#else struct SingleIpRule_greater : public std::binary_function { +#endif bool operator()(const CLIRewrite::SingleIpRule &e1, const CLIRewrite::SingleIpRule &e2) const { @@ -134,7 +148,14 @@ struct SingleIpRule_greater : public std::binary_function= 201703L) // C++17 +struct DoubleIpRule_greater { + typedef CLIRewrite::DoubleIpRule first_argument_type; + typedef CLIRewrite::DoubleIpRule second_argument_type; + typedef bool result_type; +#else struct DoubleIpRule_greater : public std::binary_function { +#endif bool operator()(const CLIRewrite::DoubleIpRule &e1, const CLIRewrite::DoubleIpRule &e2) const { diff --git a/factory.h b/factory.h index 3c7110df..494234e6 100644 --- a/factory.h +++ b/factory.h @@ -99,10 +99,19 @@ factory.h(135) Init Can't create SampleC with 3 parameter(s) namespace std { +#if (__cplusplus >= 201703L) // C++17 +template<> struct less { + typedef const char * first_argument_type; + typedef const char * second_argument_type; + typedef bool result_type; + bool operator()(const char *s1, const char *s2) const { return (strcmp(s1, s2) < 0); } +}; +#else // gcc 3.x said specialization can't be put in different namespace template<> struct less : public binary_function { bool operator()(const char *s1, const char *s2) const { return (strcmp(s1, s2) < 0); } }; +#endif } diff --git a/ipauth.cxx b/ipauth.cxx index e12f6f9c..931211a8 100644 --- a/ipauth.cxx +++ b/ipauth.cxx @@ -6,7 +6,7 @@ * @(#) $Id$ * * Copyright (c) 2005, Michal Zygmuntowicz - * Copyright (c) 2006-2016, Jan Willamowius + * Copyright (c) 2006-2023, Jan Willamowius * * This work is published under the GNU Public License version 2 (GPLv2) * see file COPYING for details. @@ -194,7 +194,14 @@ int IPAuthBase::Check( namespace { const char *FileIPAuthSecName = "FileIPAuth"; +#if (__cplusplus >= 201703L) // C++17 +struct IPAuthEntry_greater { + typedef FileIPAuth::IPAuthEntry first_argument_type; + typedef FileIPAuth::IPAuthEntry second_argument_type; + typedef bool result_type; +#else struct IPAuthEntry_greater : public binary_function { +#endif bool operator()( const FileIPAuth::IPAuthEntry & a, diff --git a/stl_supp.h b/stl_supp.h index 81b061be..06401298 100644 --- a/stl_supp.h +++ b/stl_supp.h @@ -4,7 +4,7 @@ // // Supplementary of STL // -// Copyright (c) 2001-2018, Jan Willamowius +// Copyright (c) 2001-2023, Jan Willamowius // // Part of this code is adapted from the SGI implementation // @@ -23,12 +23,15 @@ #include #include + // Composition adapter is not part of C++ standard #if !defined(__GNUC__) || (defined(__GNUC__) && __GNUC__ >= 3) template class unary_compose +#if (__cplusplus < 201703L) : public std::unary_function +#endif { protected: _Operation1 __op1; @@ -55,7 +58,11 @@ using std::compose1; // since VC6 didn't support partial specialization, use different names template +#if (__cplusplus >= 201703L) // C++17 +class mem_vfun_t { +#else class mem_vfun_t : public std::unary_function<_Tp*,void> { +#endif public: explicit mem_vfun_t(void (_Tp::*__pf)()) : _M_f(__pf) {} void operator()(_Tp* __p) const { (__p->*_M_f)(); } @@ -64,7 +71,11 @@ class mem_vfun_t : public std::unary_function<_Tp*,void> { }; template +#if (__cplusplus >= 201703L) // C++17 +class const_mem_vfun_t { +#else class const_mem_vfun_t : public std::unary_function { +#endif public: explicit const_mem_vfun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {} void operator()(const _Tp* __p) const { (__p->*_M_f)(); } @@ -73,7 +84,11 @@ class const_mem_vfun_t : public std::unary_function { }; template +#if (__cplusplus >= 201703L) // C++17 +class mem_vfun_ref_t { +#else class mem_vfun_ref_t : public std::unary_function<_Tp,void> { +#endif public: explicit mem_vfun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {} void operator()(_Tp& __r) const { (__r.*_M_f)(); } @@ -82,7 +97,11 @@ class mem_vfun_ref_t : public std::unary_function<_Tp,void> { }; template +#if (__cplusplus >= 201703L) // C++17 +class const_mem_vfun_ref_t { +#else class const_mem_vfun_ref_t : public std::unary_function<_Tp,void> { +#endif public: explicit const_mem_vfun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {} void operator()(const _Tp& __r) const { (__r.*_M_f)(); } @@ -91,7 +110,11 @@ class const_mem_vfun_ref_t : public std::unary_function<_Tp,void> { }; template +#if (__cplusplus >= 201703L) // C++17 +class mem_vfun1_t { +#else class mem_vfun1_t : public std::binary_function<_Tp*,_Arg,void> { +#endif public: explicit mem_vfun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {} void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } @@ -100,7 +123,11 @@ class mem_vfun1_t : public std::binary_function<_Tp*,_Arg,void> { }; template +#if (__cplusplus >= 201703L) // C++17 +class const_mem_vfun1_t { +#else class const_mem_vfun1_t : public std::binary_function { +#endif public: explicit const_mem_vfun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } @@ -109,7 +136,11 @@ class const_mem_vfun1_t : public std::binary_function { }; template +#if (__cplusplus >= 201703L) // C++17 +class mem_vfun1_ref_t { +#else class mem_vfun1_ref_t : public std::binary_function<_Tp,_Arg,void> { +#endif public: explicit mem_vfun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {} void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } @@ -118,7 +149,11 @@ class mem_vfun1_ref_t : public std::binary_function<_Tp,_Arg,void> { }; template +#if (__cplusplus >= 201703L) // C++17 +class const_mem_vfun1_ref_t { +#else class const_mem_vfun1_ref_t : public std::binary_function<_Tp,_Arg,void> { +#endif public: explicit const_mem_vfun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {} void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } @@ -157,7 +192,11 @@ inline const_mem_vfun1_ref_t<_Tp,_Arg> mem_vfun_ref(void (_Tp::*__f)(_Arg) const // end of partial specialization +#if (__cplusplus >= 201703L) // C++17 +struct str_prefix_greater { +#else struct str_prefix_greater : public std::binary_function { +#endif bool operator()(const std::string& s1, const std::string& s2) const { @@ -168,7 +207,11 @@ struct str_prefix_greater : public std::binary_function= 201703L) // C++17 +struct str_prefix_lesser { +#else struct str_prefix_lesser : public std::binary_function { +#endif bool operator()(const std::string& s1, const std::string& s2) const { @@ -179,7 +222,11 @@ struct str_prefix_lesser : public std::binary_function= 201703L) // C++17 +struct pstr_prefix_lesser { +#else struct pstr_prefix_lesser : public std::binary_function { +#endif bool operator()(const PString& s1, const PString& s2) const {