From 335da0ba7a9c65707507ebfcf793456c694f91e0 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Sun, 13 Dec 2015 00:02:42 +0200 Subject: [PATCH] Fix number conversions in core --- pdns/botan110signers.cc | 10 ++++----- pdns/botansigners.cc | 4 ++-- pdns/communicator.cc | 1 - pdns/cryptoppsigners.cc | 6 +++--- pdns/dbdnsseckeeper.cc | 4 ++-- pdns/devpollmplexer.cc | 3 +-- pdns/dns.cc | 5 ++--- pdns/dnsbackend.cc | 10 ++++----- pdns/dnsdist-lua.cc | 12 +++++------ pdns/dnsdist.cc | 2 +- pdns/dnsparser.cc | 19 +++++++++-------- pdns/dnsparser.hh | 7 +++---- pdns/dnsrecords.cc | 2 +- pdns/dnsrecords.hh | 1 - pdns/dnssecinfra.cc | 20 +++++++++--------- pdns/dynhandler.cc | 2 +- pdns/dynloader.cc | 2 +- pdns/epollmplexer.cc | 3 +-- pdns/gss_context.hh | 2 +- pdns/iputils.hh | 11 +++++----- pdns/json.cc | 4 ++-- pdns/kqueuemplexer.cc | 1 - pdns/lua-iputils.cc | 2 +- pdns/lua-recursor.cc | 2 +- pdns/mastercommunicator.cc | 1 - pdns/mbedtlssigners.cc | 6 +++--- pdns/misc.cc | 25 ++++++++++++++--------- pdns/mplexer.hh | 7 +++---- pdns/namespaces.hh | 2 -- pdns/nproxy.cc | 4 ++-- pdns/packethandler.cc | 2 +- pdns/pdns_hw.cc | 3 +-- pdns/pdns_recursor.cc | 11 +++++----- pdns/pdnsutil.cc | 36 ++++++++++++++++----------------- pdns/pkcs11signers.cc | 10 ++++----- pdns/pollmplexer.cc | 5 ++--- pdns/portsmplexer.cc | 3 +-- pdns/rcpgenerator.cc | 37 +++++++++++++++++----------------- pdns/rec_channel_rec.cc | 15 +++++++------- pdns/reczones.cc | 10 ++++----- pdns/resolver.cc | 2 +- pdns/saxfr.cc | 4 ++-- pdns/secpoll-auth.cc | 2 +- pdns/secpoll-recursor.cc | 2 +- pdns/selectmplexer.cc | 5 ++--- pdns/serialtweaker.cc | 2 +- pdns/signingpipe.cc | 2 +- pdns/slavecommunicator.cc | 1 - pdns/sodiumsigners.cc | 4 ++-- pdns/syncres.cc | 6 +++--- pdns/tcpreceiver.cc | 4 ++-- pdns/test-dnsrecords_cc.cc | 6 +++--- pdns/test-packetcache_cc.cc | 12 +++++------ pdns/test-zoneparser_tng_cc.cc | 5 ++--- pdns/validate.cc | 14 ++++++------- pdns/webserver.cc | 2 +- pdns/ws-auth.cc | 18 ++++++++--------- pdns/ws-recursor.cc | 2 +- pdns/zone2json.cc | 2 +- pdns/zone2sql.cc | 6 +++--- pdns/zoneparser-tng.cc | 11 +++++----- 61 files changed, 203 insertions(+), 221 deletions(-) diff --git a/pdns/botan110signers.cc b/pdns/botan110signers.cc index d3a8299776..eed7f75547 100644 --- a/pdns/botan110signers.cc +++ b/pdns/botan110signers.cc @@ -107,7 +107,7 @@ DNSCryptoKeyEngine::storvector_t GOSTDNSCryptoKeyEngine::convertToISCVector() co void GOSTDNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, std::map& stormap ) { - drc.d_algorithm = atoi(stormap["algorithm"].c_str()); + drc.d_algorithm = pdns_stou(stormap["algorithm"]); string privateKey=stormap["gostasn1"]; //cerr<<"PrivateKey.size() = "<(algorithm)); + throw runtime_error("Requested for unknown EC domain parameters for algorithm "+to_string(algorithm)); } void ECDSADNSCryptoKeyEngine::create(unsigned int bits) @@ -305,7 +305,7 @@ void ECDSADNSCryptoKeyEngine::create(unsigned int bits) params = getECParams(14); } else { - throw runtime_error("Unknown key length of "+lexical_cast(bits)+" bits requested from ECDSA class"); + throw runtime_error("Unknown key length of "+to_string(bits)+" bits requested from ECDSA class"); } d_key = shared_ptr(new ECDSA_PrivateKey(rng, params)); } @@ -347,9 +347,9 @@ void ECDSADNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, std::map(drc.d_algorithm)+" to a "+lexical_cast(d_algorithm)+" key!"); + throw runtime_error("Tried to feed an algorithm "+to_string(drc.d_algorithm)+" to a "+to_string(d_algorithm)+" key!"); string privateKey=stormap["privatekey"]; BigInt bigint((byte*)privateKey.c_str(), privateKey.length()); diff --git a/pdns/botansigners.cc b/pdns/botansigners.cc index 282192232c..f637a85572 100644 --- a/pdns/botansigners.cc +++ b/pdns/botansigners.cc @@ -78,7 +78,7 @@ BigInt fromRaw(const std::string& raw) DNSCryptoKeyEngine::storvector_t BotanRSADNSCryptoKeyEngine::convertToISCVector() const { storvector_t storvect; - string algorithm = lexical_cast(d_algorithm); + string algorithm = std::to_string(d_algorithm); if(d_algorithm == 5 || d_algorithm ==7 ) algorithm += " (RSASHA1)"; else if(d_algorithm == 8) @@ -120,7 +120,7 @@ void BotanRSADNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, std::map // #include "namespaces.hh" diff --git a/pdns/cryptoppsigners.cc b/pdns/cryptoppsigners.cc index 0c4a95d86f..93497a861c 100644 --- a/pdns/cryptoppsigners.cc +++ b/pdns/cryptoppsigners.cc @@ -45,7 +45,7 @@ private: template void CryptoPPECDSADNSCryptoKeyEngine::create(unsigned int bits) { if(bits != BITS) - throw runtime_error("This CryptoPP class can only hosts keys of length "+lexical_cast(BITS)); + throw runtime_error("This CryptoPP class can only hosts keys of length "+to_string(BITS)); AutoSeededRandomPool prng; privatekey_t* privateKey = new privatekey_t(); CryptoPP::OID oid=CURVE(); @@ -68,7 +68,7 @@ DNSCryptoKeyEngine::storvector_t CryptoPPECDSADNSCryptoKeyEngine(d_algorithm); + string algostr=to_string(d_algorithm); if(d_algorithm==13) algostr+=" (ECDSAP256SHA256)"; else if(d_algorithm==14) @@ -102,7 +102,7 @@ void CryptoPPECDSADNSCryptoKeyEngine::fromISCMap(DNSKEYRecord publickey_t* publicKey = new publickey_t(); d_key->MakePublicKey(*publicKey); d_pubkey = shared_ptr(publicKey); - drc.d_algorithm = atoi(stormap["algorithm"].c_str()); + drc.d_algorithm = pdns_stou(stormap["algorithm"]); } template diff --git a/pdns/dbdnsseckeeper.cc b/pdns/dbdnsseckeeper.cc index 393001541f..c49df1de00 100644 --- a/pdns/dbdnsseckeeper.cc +++ b/pdns/dbdnsseckeeper.cc @@ -85,7 +85,7 @@ bool DNSSECKeeper::addKey(const DNSName& name, bool keyOrZone, int algorithm, in else if(algorithm == 14) // ECDSAP384SHA384 bits = 384; else { - throw runtime_error("Can't guess key size for algorithm "+lexical_cast(algorithm)); + throw runtime_error("Can't guess key size for algorithm "+std::to_string(algorithm)); } } } @@ -158,7 +158,7 @@ DNSSECPrivateKey DNSSECKeeper::getKeyById(const DNSName& zname, unsigned int id) return dpk; } - throw runtime_error("Can't find a key with id "+lexical_cast(id)+" for zone '"+zname.toString()+"'"); + throw runtime_error("Can't find a key with id "+std::to_string(id)+" for zone '"+zname.toString()+"'"); } diff --git a/pdns/devpollmplexer.cc b/pdns/devpollmplexer.cc index 53c39f30d4..d3995e9c1a 100644 --- a/pdns/devpollmplexer.cc +++ b/pdns/devpollmplexer.cc @@ -7,7 +7,6 @@ #include #include #include "misc.hh" -#include #include "syncres.hh" #include "namespaces.hh" @@ -75,7 +74,7 @@ void DevPollFDMultiplexer::addFD(callbackmap_t& cbmap, int fd, callbackfunc_t to void DevPollFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd) { if(!cbmap.erase(fd)) - throw FDMultiplexerException("Tried to remove unlisted fd "+lexical_cast(fd)+ " from multiplexer"); + throw FDMultiplexerException("Tried to remove unlisted fd "+std::to_string(fd)+ " from multiplexer"); struct pollfd devent; devent.fd=fd; diff --git a/pdns/dns.cc b/pdns/dns.cc index e466b11fff..f36738ce59 100644 --- a/pdns/dns.cc +++ b/pdns/dns.cc @@ -6,7 +6,6 @@ #include #include #include -#include #include #include "dnsparser.hh" @@ -38,7 +37,7 @@ std::vector RCode::rcodes_s = boost::assign::list_of std::string RCode::to_s(unsigned short rcode) { if (rcode > RCode::rcodes_s.size()-1 ) - return std::string("Err#")+boost::lexical_cast(rcode); + return std::string("Err#")+std::to_string(rcode); return RCode::rcodes_s[rcode]; } @@ -58,7 +57,7 @@ public: { if(offset < d_length) return d_ptr[offset]; - throw runtime_error("out of bounds: "+boost::lexical_cast(offset)+" >= " + boost::lexical_cast(d_length)); + throw runtime_error("out of bounds: "+std::to_string(offset)+" >= " + std::to_string(d_length)); } private: const char* d_ptr; diff --git a/pdns/dnsbackend.cc b/pdns/dnsbackend.cc index 3e96807a05..296577d045 100644 --- a/pdns/dnsbackend.cc +++ b/pdns/dnsbackend.cc @@ -351,19 +351,19 @@ void fillSOAData(const string &content, SOAData &data) if(pleft>1) data.hostmaster=DNSName(attodot(parts[1])); // ahu@ds9a.nl -> ahu.ds9a.nl, piet.puk@ds9a.nl -> piet\.puk.ds9a.nl - data.serial = pleft > 2 ? pdns_strtoui(parts[2].c_str(), NULL, 10) : 0; + data.serial = pleft > 2 ? pdns_stou(parts[2]) : 0; if (data.serial == UINT_MAX && errno == ERANGE) throw PDNSException("serial number too large in '"+parts[2]+"'"); - data.refresh = pleft > 3 ? atoi(parts[3].c_str()) + data.refresh = pleft > 3 ? pdns_stou(parts[3]) : ::arg().asNum("soa-refresh-default"); - data.retry = pleft > 4 ? atoi(parts[4].c_str()) + data.retry = pleft > 4 ? pdns_stou(parts[4].c_str()) : ::arg().asNum("soa-retry-default"); - data.expire = pleft > 5 ? atoi(parts[5].c_str()) + data.expire = pleft > 5 ? pdns_stou(parts[5].c_str()) : ::arg().asNum("soa-expire-default"); - data.default_ttl = pleft > 6 ?atoi(parts[6].c_str()) + data.default_ttl = pleft > 6 ? pdns_stou(parts[6].c_str()) : ::arg().asNum("soa-minimum-ttl"); } diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index 43b1326a1c..a42caf8d89 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -132,7 +132,7 @@ vector> setupLua(bool client, const std::string& confi } if(vars.count("qps")) { - int qps=boost::lexical_cast(boost::get(vars["qps"])); + int qps=std::stoi(boost::get(vars["qps"])); ret->qps=QPSLimiter(qps, qps); } @@ -147,23 +147,23 @@ vector> setupLua(bool client, const std::string& confi } if(vars.count("order")) { - ret->order=boost::lexical_cast(boost::get(vars["order"])); + ret->order=std::stoi(boost::get(vars["order"])); } if(vars.count("weight")) { - ret->weight=boost::lexical_cast(boost::get(vars["weight"])); + ret->weight=std::stoi(boost::get(vars["weight"])); } if(vars.count("retries")) { - ret->retries=boost::lexical_cast(boost::get(vars["retries"])); + ret->retries=std::stoi(boost::get(vars["retries"])); } if(vars.count("tcpSendTimeout")) { - ret->tcpSendTimeout=boost::lexical_cast(boost::get(vars["tcpSendTimeout"])); + ret->tcpSendTimeout=std::stoi(boost::get(vars["tcpSendTimeout"])); } if(vars.count("tcpRecvTimeout")) { - ret->tcpRecvTimeout=boost::lexical_cast(boost::get(vars["tcpRecvTimeout"])); + ret->tcpRecvTimeout=std::stoi(boost::get(vars["tcpRecvTimeout"])); } if(vars.count("name")) { diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 69ef44e8ab..8ebd3354c4 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -575,7 +575,7 @@ try break; case DNSAction::Action::Delay: - delayMsec = atoi(ruleresult.c_str()); // sorry + delayMsec = static_cast(pdns_stou(ruleresult)); // sorry break; case DNSAction::Action::Allow: case DNSAction::Action::None: diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 03d4b1338c..2d636d82fc 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -22,7 +22,6 @@ #include "dnsparser.hh" #include "dnswriter.hh" -#include #include #include @@ -43,9 +42,9 @@ public: vector parts; stringtok(parts, zone); if(parts.size()!=3 && !(parts.size()==2 && equals(parts[1],"0")) ) - throw MOADNSException("Unknown record was stored incorrectly, need 3 fields, got "+lexical_cast(parts.size())+": "+zone ); + throw MOADNSException("Unknown record was stored incorrectly, need 3 fields, got "+std::to_string(parts.size())+": "+zone ); const string& relevant=(parts.size() > 2) ? parts[2] : ""; - unsigned int total=atoi(parts[1].c_str()); + unsigned int total=pdns_stou(parts[1]); if(relevant.size()!=2*total) throw MOADNSException((boost::format("invalid unknown record length for label %s: size not equal to length field (%d != %d)") % d_dr.d_name.toString() % relevant.size() % (2*total)).str()); string out; @@ -240,7 +239,7 @@ void MOADNSParser::init(const char *packet, unsigned int len) memcpy(&d_header, packet, sizeof(dnsheader)); if(d_header.opcode != Opcode::Query && d_header.opcode != Opcode::Notify && d_header.opcode != Opcode::Update) - throw MOADNSException("Can't parse non-query packet with opcode="+ lexical_cast(d_header.opcode)); + throw MOADNSException("Can't parse non-query packet with opcode="+ std::to_string(d_header.opcode)); d_header.qdcount=ntohs(d_header.qdcount); d_header.ancount=ntohs(d_header.ancount); @@ -300,8 +299,8 @@ void MOADNSParser::init(const char *packet, unsigned int len) #if 0 if(pr.d_pos!=contentlen) { - throw MOADNSException("Packet ("+d_qname+"|#"+lexical_cast(d_qtype)+") has trailing garbage ("+ lexical_cast(pr.d_pos) + " < " + - lexical_cast(contentlen) + ")"); + throw MOADNSException("Packet ("+d_qname+"|#"+std::to_string(d_qtype)+") has trailing garbage ("+ std::to_string(pr.d_pos) + " < " + + std::to_string(contentlen) + ")"); } #endif } @@ -318,8 +317,8 @@ void MOADNSParser::init(const char *packet, unsigned int len) } } else { - throw MOADNSException("Error parsing packet of "+lexical_cast(len)+" bytes (rd="+ - lexical_cast(d_header.rd)+ + throw MOADNSException("Error parsing packet of "+std::to_string(len)+" bytes (rd="+ + std::to_string(d_header.rd)+ "), out of bounds: "+string(re.what())); } } @@ -622,8 +621,8 @@ private: { d_notyouroffset += by; if(d_notyouroffset > d_packet.length()) - throw std::out_of_range("dns packet out of range: "+lexical_cast(d_notyouroffset) +" > " - + lexical_cast(d_packet.length()) ); + throw std::out_of_range("dns packet out of range: "+std::to_string(d_notyouroffset) +" > " + + std::to_string(d_packet.length()) ); } std::string& d_packet; diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 50e2410506..17d2a57fa8 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -32,7 +32,6 @@ // #include #include "misc.hh" -#include #include #include #include "dns.hh" @@ -220,7 +219,7 @@ public: return iter->second.second; if(boost::starts_with(name, "TYPE")) - return atoi(name.c_str()+4); + return pdns_stou(name.substr(4)); throw runtime_error("Unknown DNS type '"+name+"'"); } @@ -229,8 +228,8 @@ public: { t2namemap_t::const_iterator iter = getT2Namemap().find(make_pair(classnum, num)); if(iter == getT2Namemap().end()) - return "TYPE" + lexical_cast(num); - // throw runtime_error("Unknown DNS type with numerical id "+lexical_cast(num)); + return "TYPE" + std::to_string(num); + // throw runtime_error("Unknown DNS type with numerical id "+std::to_string(num)); return iter->second; } diff --git a/pdns/dnsrecords.cc b/pdns/dnsrecords.cc index 80db44fd84..5e89bbc312 100644 --- a/pdns/dnsrecords.cc +++ b/pdns/dnsrecords.cc @@ -136,7 +136,7 @@ ComboAddress AAAARecordContent::getCA(int port) const void ARecordContent::doRecordCheck(const DNSRecord& dr) { if(dr.d_clen!=4) - throw MOADNSException("Wrong size for A record ("+lexical_cast(dr.d_clen)+")"); + throw MOADNSException("Wrong size for A record ("+std::to_string(dr.d_clen)+")"); } boilerplate_conv(AAAA, QType::AAAA, conv.xfrIP6(d_ip6); ); diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index 768ddeb237..0cdff09b8c 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -26,7 +26,6 @@ #include "dnsparser.hh" #include "dnswriter.hh" #include "rcpgenerator.hh" -#include #include #include #include "namespaces.hh" diff --git a/pdns/dnssecinfra.cc b/pdns/dnssecinfra.cc index 357f20a007..05d3cfc230 100644 --- a/pdns/dnssecinfra.cc +++ b/pdns/dnssecinfra.cc @@ -61,8 +61,8 @@ DNSCryptoKeyEngine* DNSCryptoKeyEngine::makeFromISCString(DNSKEYRecordContent& d tie(key,value)=splitField(sline, ':'); trim(value); if(pdns_iequals(key,"algorithm")) { - algorithm = atoi(value.c_str()); - stormap["algorithm"]=lexical_cast(algorithm); + algorithm = pdns_stou(value); + stormap["algorithm"]=std::to_string(algorithm); continue; } else if (pdns_iequals(key,"pin")) { stormap["pin"]=value; @@ -127,7 +127,7 @@ DNSCryptoKeyEngine* DNSCryptoKeyEngine::make(unsigned int algo) if(iter != makers.end()) return (iter->second)(algo); else { - throw runtime_error("Request to create key object for unknown algorithm number "+lexical_cast(algo)); + throw runtime_error("Request to create key object for unknown algorithm number "+std::to_string(algo)); } } @@ -206,7 +206,7 @@ pair DNSCryptoKeyEngine::testMakers(unsigned int alg else if(algo == 14) // ECDSAP384SHA384 bits = 384; else - throw runtime_error("Can't guess key size for algorithm "+lexical_cast(algo)); + throw runtime_error("Can't guess key size for algorithm "+std::to_string(algo)); dckeCreate->create(bits); @@ -221,8 +221,8 @@ pair DNSCryptoKeyEngine::testMakers(unsigned int alg tie(key,value)=splitField(sline, ':'); trim(value); if(pdns_iequals(key,"algorithm")) { - algorithm = atoi(value.c_str()); - stormap["algorithm"]=lexical_cast(algorithm); + algorithm = pdns_stou(value); + stormap["algorithm"]=std::to_string(algorithm); continue; } else if (pdns_iequals(key,"pin")) { stormap["pin"]=value; @@ -231,8 +231,8 @@ pair DNSCryptoKeyEngine::testMakers(unsigned int alg stormap["engine"]=value; continue; } else if (pdns_iequals(key,"slot")) { - int slot = atoi(value.c_str()); - stormap["slot"]=lexical_cast(slot); + int slot = std::stoi(value); + stormap["slot"]=std::to_string(slot); continue; } else if (pdns_iequals(key,"label")) { stormap["label"]=value; @@ -350,7 +350,7 @@ DSRecordContent makeDSFromDNSKey(const DNSName& qname, const DNSKEYRecordContent dsrc.d_digest = dpk->hash(toHash); } else - throw std::runtime_error("Asked to a DS of unknown digest type " + lexical_cast(digest)+"\n"); + throw std::runtime_error("Asked to a DS of unknown digest type " + std::to_string(digest)+"\n"); dsrc.d_algorithm= drc.d_algorithm; dsrc.d_digesttype=digest; @@ -480,7 +480,7 @@ void decodeDERIntegerSequence(const std::string& input, vector& output) for(;;) { uint8_t kind = de.getByte(); if(kind != 0x02) - throw runtime_error("DER Sequence contained non-INTEGER component: "+lexical_cast((unsigned int)kind) ); + throw runtime_error("DER Sequence contained non-INTEGER component: "+std::to_string(static_cast(kind)) ); len = de.getLength(); ret = de.getBytes(len); output.push_back(ret); diff --git a/pdns/dynhandler.cc b/pdns/dynhandler.cc index 5c0f5819ef..e141c54856 100644 --- a/pdns/dynhandler.cc +++ b/pdns/dynhandler.cc @@ -384,7 +384,7 @@ string DLTokenLogin(const vector&parts, Utility::pid_t ppid) return "PKCS#11 support not compiled in"; #else if (parts.size() != 4) { - return "invalid number of parameters, needs 4, got " + boost::lexical_cast(parts.size()); + return "invalid number of parameters, needs 4, got " + std::to_string(parts.size()); } if (PKCS11ModuleSlotLogin(parts[1], parts[2], parts[3])) { diff --git a/pdns/dynloader.cc b/pdns/dynloader.cc index a079c2fa30..282b919bec 100644 --- a/pdns/dynloader.cc +++ b/pdns/dynloader.cc @@ -106,7 +106,7 @@ int main(int argc, char **argv) else { uint16_t port; try { - port = lexical_cast(::arg()["remote-port"]); + port = static_cast(pdns_stou(::arg()["remote-port"])); } catch(...) { cerr<<"Unable to convert '"<<::arg()["remote-port"]<<"' to a port number for connecting to remote PowerDNS\n"; diff --git a/pdns/epollmplexer.cc b/pdns/epollmplexer.cc index c647ae9900..67a9d36418 100644 --- a/pdns/epollmplexer.cc +++ b/pdns/epollmplexer.cc @@ -6,7 +6,6 @@ #include #include #include "misc.hh" -#include #include "syncres.hh" #ifdef __linux__ #include @@ -95,7 +94,7 @@ void EpollFDMultiplexer::addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo void EpollFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd) { if(!cbmap.erase(fd)) - throw FDMultiplexerException("Tried to remove unlisted fd "+lexical_cast(fd)+ " from multiplexer"); + throw FDMultiplexerException("Tried to remove unlisted fd "+std::to_string(fd)+ " from multiplexer"); struct epoll_event dummy; dummy.events = 0; diff --git a/pdns/gss_context.hh b/pdns/gss_context.hh index da47631251..7cc4ff3966 100644 --- a/pdns/gss_context.hh +++ b/pdns/gss_context.hh @@ -91,7 +91,7 @@ public: buffer.value = (void*)name.c_str(); maj = gss_import_name(&min, &buffer, (gss_OID)GSS_KRB5_NT_PRINCIPAL_NAME, &comp); if (maj != GSS_S_COMPLETE) - throw PDNSException("Could not import " + name + ": " + boost::lexical_cast(maj) + string(",") + boost::lexical_cast(min)); + throw PDNSException("Could not import " + name + ": " + std::to_string(maj) + string(",") + std::to_string(min)); // do comparison maj = gss_compare_name(&min, d_name, comp, &result); gss_release_name(&min, &comp); diff --git a/pdns/iputils.hh b/pdns/iputils.hh index 63662128ac..e15d26a954 100644 --- a/pdns/iputils.hh +++ b/pdns/iputils.hh @@ -34,10 +34,9 @@ #include "misc.hh" #include #include - +#include #include #include -#include #include "namespaces.hh" @@ -220,9 +219,9 @@ union ComboAddress { string toStringWithPort() const { if(sin4.sin_family==AF_INET) - return toString() + ":" + boost::lexical_cast(ntohs(sin4.sin_port)); + return toString() + ":" + std::to_string(ntohs(sin4.sin_port)); else - return "["+toString() + "]:" + boost::lexical_cast(ntohs(sin4.sin_port)); + return "["+toString() + "]:" + std::to_string(ntohs(sin4.sin_port)); } void truncate(unsigned int bits); @@ -280,7 +279,7 @@ public: d_network=makeComboAddress(split.first); if(!split.second.empty()) { - d_bits = lexical_cast(split.second); + d_bits = pdns_stou(split.second); if(d_bits<32) d_mask=~(0xFFFFFFFF>>d_bits); else @@ -344,7 +343,7 @@ public: string toString() const { - return d_network.toString()+"/"+boost::lexical_cast((unsigned int)d_bits); + return d_network.toString()+"/"+std::to_string((unsigned int)d_bits); } string toStringNoMask() const diff --git a/pdns/json.cc b/pdns/json.cc index 2124f8d323..ee6022afea 100644 --- a/pdns/json.cc +++ b/pdns/json.cc @@ -41,7 +41,7 @@ int intFromJson(const Value& container, const char* key) if (val.IsInt()) { return val.GetInt(); } else if (val.IsString()) { - return atoi(val.GetString()); + return std::stoi(val.GetString()); } else { throw JsonException("Key '" + string(key) + "' not an Integer or not present"); } @@ -56,7 +56,7 @@ int intFromJson(const Value& container, const char* key, const int default_value if (val.IsInt()) { return val.GetInt(); } else if (val.IsString()) { - return atoi(val.GetString()); + return std::stoi(val.GetString()); } else { // TODO: check if value really isn't present return default_value; diff --git a/pdns/kqueuemplexer.cc b/pdns/kqueuemplexer.cc index 6d469baae4..e6ef8a3fd0 100644 --- a/pdns/kqueuemplexer.cc +++ b/pdns/kqueuemplexer.cc @@ -6,7 +6,6 @@ #include #include #include "misc.hh" -#include #include "syncres.hh" #include #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) diff --git a/pdns/lua-iputils.cc b/pdns/lua-iputils.cc index 95a98bba10..61c9185d17 100644 --- a/pdns/lua-iputils.cc +++ b/pdns/lua-iputils.cc @@ -277,7 +277,7 @@ int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret) if(pos == string::npos || pos + 2 > addr.size() || addr[pos+1]!=':') return -1; ourAddr.assign(addr.c_str() + 1, pos-1); - port = atoi(addr.c_str()+pos+2); + port = pdns_stou(addr.substr(pos+2)); } ret->sin6_scope_id=0; ret->sin6_family=AF_INET6; diff --git a/pdns/lua-recursor.cc b/pdns/lua-recursor.cc index 56c02ca216..36f9aafd31 100644 --- a/pdns/lua-recursor.cc +++ b/pdns/lua-recursor.cc @@ -142,7 +142,7 @@ int getFakePTRRecords(const DNSName& qname, const std::string& prefix, vector(strtol(parts[n*2].c_str(), 0, 16) + 16*strtol(parts[n*2+1].c_str(), 0, 16)); + std::to_string(std::stol(parts[n*2], 0, 16) + 16*std::stol(parts[n*2+1], 0, 16)); newquery.append(1,'.'); } newquery += "in-addr.arpa."; diff --git a/pdns/mastercommunicator.cc b/pdns/mastercommunicator.cc index 181fab1370..7fa27ebc55 100644 --- a/pdns/mastercommunicator.cc +++ b/pdns/mastercommunicator.cc @@ -38,7 +38,6 @@ #include "dns.hh" #include "arguments.hh" #include "packetcache.hh" -#include #include "namespaces.hh" diff --git a/pdns/mbedtlssigners.cc b/pdns/mbedtlssigners.cc index 6e89a0688a..9af1205f79 100644 --- a/pdns/mbedtlssigners.cc +++ b/pdns/mbedtlssigners.cc @@ -206,7 +206,7 @@ std::string RSADNSCryptoKeyEngine::hash(const std::string& toHash) const mbedtls_sha512((unsigned char*)toHash.c_str(), toHash.length(), hash, 0); return string((char*)hash, sizeof(hash)); } - throw runtime_error("mbed TLS hashing method can't hash algorithm "+lexical_cast(d_algorithm)); + throw runtime_error("mbed TLS hashing method can't hash algorithm "+std::to_string(d_algorithm)); } @@ -223,7 +223,7 @@ DNSCryptoKeyEngine::storvector_t RSADNSCryptoKeyEngine::convertToISCVector() con ("Exponent2",&d_context.DQ) ("Coefficient",&d_context.QP); - string algorithm=lexical_cast(d_algorithm); + string algorithm=std::to_string(d_algorithm); switch(d_algorithm) { case 5: case 7 : @@ -262,7 +262,7 @@ void RSADNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, std::map1) - st.port=atoi(parts[1].c_str()); + st.port=pdns_stou(parts[1]); } static void parseService6(const string &descr, ServiceTuple &st) @@ -313,7 +313,7 @@ static void parseService6(const string &descr, ServiceTuple &st) st.host=descr.substr(1, pos-1); if(pos + 2 < descr.length()) - st.port=atoi(descr.c_str() + pos +2); + st.port=pdns_stou(descr.substr(pos+2)); } @@ -760,7 +760,7 @@ int makeIPv6sockaddr(const std::string& addr, struct sockaddr_in6* ret) if(pos == string::npos || pos + 2 > addr.size() || addr[pos+1]!=':') return -1; ourAddr.assign(addr.c_str() + 1, pos-1); - port = atoi(addr.c_str()+pos+2); + port = pdns_stou(addr.substr(pos+2)); } ret->sin6_scope_id=0; ret->sin6_family=AF_INET6; @@ -1091,13 +1091,13 @@ uint64_t udpErrorStats(const std::string& str) if(parts.size() < 7) break; if(str=="udp-rcvbuf-errors") - return boost::lexical_cast(parts[5]); + return std::stoull(parts[5]); else if(str=="udp-sndbuf-errors") - return boost::lexical_cast(parts[6]); + return std::stoull(parts[6]); else if(str=="udp-noport-errors") - return boost::lexical_cast(parts[2]); + return std::stoull(parts[2]); else if(str=="udp-in-errors") - return boost::lexical_cast(parts[3]); + return std::stoull(parts[3]); else return 0; } @@ -1152,7 +1152,12 @@ uint64_t getOpenFileDescriptors(const std::string&) struct dirent *entry; int ret=0; while((entry = readdir(dirhdl))) { - uint32_t num = atoi(entry->d_name); + uint32_t num; + try { + num = pdns_stou(entry->d_name); + } catch (...) { + continue; // was not a number. + } if(std::to_string(num) == entry->d_name) ret++; } @@ -1175,7 +1180,7 @@ uint64_t getRealMemoryUsage(const std::string&) string header("Private_Dirty:"); while(getline(ifs, line)) { if(boost::starts_with(line, header)) { - bytes += atoi(line.c_str() + header.length() +1)*1024; + bytes += std::stoull(line.substr(header.length() + 1))*1024; } } return bytes; @@ -1270,7 +1275,7 @@ gid_t strToGID(const string &str) return result; } -unsigned int pdns_stou(const std::string& str, size_t * idx, int base); +unsigned int pdns_stou(const std::string& str, size_t * idx, int base) { if (str.empty()) return 0; // compability unsigned long result = std::stoul(str, idx, base); diff --git a/pdns/mplexer.hh b/pdns/mplexer.hh index 850ebcb474..13541259ba 100644 --- a/pdns/mplexer.hh +++ b/pdns/mplexer.hh @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -87,7 +86,7 @@ public: virtual funcparam_t& getReadParameter(int fd) { if(!d_readCallbacks.count(fd)) - throw FDMultiplexerException("attempt to look up data in multiplexer for unlisted fd "+boost::lexical_cast(fd)); + throw FDMultiplexerException("attempt to look up data in multiplexer for unlisted fd "+std::to_string(fd)); return d_readCallbacks[fd].d_parameter; } @@ -129,14 +128,14 @@ protected: memset(&cb.d_ttd, 0, sizeof(cb.d_ttd)); if(cbmap.count(fd)) - throw FDMultiplexerException("Tried to add fd "+boost::lexical_cast(fd)+ " to multiplexer twice"); + throw FDMultiplexerException("Tried to add fd "+std::to_string(fd)+ " to multiplexer twice"); cbmap[fd]=cb; } void accountingRemoveFD(callbackmap_t& cbmap, int fd) { if(!cbmap.erase(fd)) - throw FDMultiplexerException("Tried to remove unlisted fd "+boost::lexical_cast(fd)+ " from multiplexer"); + throw FDMultiplexerException("Tried to remove unlisted fd "+std::to_string(fd)+ " from multiplexer"); } }; diff --git a/pdns/namespaces.hh b/pdns/namespaces.hh index 84f95d44c5..4e66d52a38 100644 --- a/pdns/namespaces.hh +++ b/pdns/namespaces.hh @@ -1,6 +1,5 @@ #ifndef PDNS_NAMESPACES_HH #define PDNS_NAMESPACES_HH -#include #include #include @@ -37,7 +36,6 @@ using std::min; // these are a bit scary, everybody uses 'min' using std::max; using std::string; -using boost::lexical_cast; using boost::tie; using std::shared_ptr; using std::unique_ptr; diff --git a/pdns/nproxy.cc b/pdns/nproxy.cc index 1b496df66f..c82468e76a 100644 --- a/pdns/nproxy.cc +++ b/pdns/nproxy.cc @@ -275,7 +275,7 @@ try if(g_vm.count("setgid")) { if(setgid(g_vm["setgid"].as()) < 0) - throw runtime_error("while changing gid to "+boost::lexical_cast(g_vm["setgid"].as())); + throw runtime_error("while changing gid to "+std::to_string(g_vm["setgid"].as())); syslogFmt(boost::format("Changed gid to %d") % g_vm["setgid"].as()); if(setgroups(0, NULL) < 0) throw runtime_error("while dropping supplementary groups"); @@ -283,7 +283,7 @@ try if(g_vm.count("setuid")) { if(setuid(g_vm["setuid"].as()) < 0) - throw runtime_error("while changing uid to "+boost::lexical_cast(g_vm["setuid"].as())); + throw runtime_error("while changing uid to "+std::to_string(g_vm["setuid"].as())); syslogFmt(boost::format("Changed uid to %d") % g_vm["setuid"].as()); } diff --git a/pdns/packethandler.cc b/pdns/packethandler.cc index ae0e9796c1..d6217e412d 100644 --- a/pdns/packethandler.cc +++ b/pdns/packethandler.cc @@ -221,7 +221,7 @@ bool PacketHandler::addCDS(DNSPacket *p, DNSPacket *r, const SOAData& sd) continue; } for(auto const &digestAlgo : digestAlgos){ - rr.content=makeDSFromDNSKey(p->qdomain, value.first.getDNSKEY(), lexical_cast(digestAlgo)).getZoneRepresentation(); + rr.content=makeDSFromDNSKey(p->qdomain, value.first.getDNSKEY(), std::stoi(digestAlgo)).getZoneRepresentation(); r->addRecord(rr); haveOne=true; } diff --git a/pdns/pdns_hw.cc b/pdns/pdns_hw.cc index acfa45c860..8ae0f05e04 100644 --- a/pdns/pdns_hw.cc +++ b/pdns/pdns_hw.cc @@ -1,7 +1,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include #include #include #include @@ -18,6 +17,6 @@ int main() { ostringstream str; - str << "Everything is ok!"<< boost::lexical_cast("") <<"\n"; + str << "Everything is ok!"<<"\n"; // FIXME400: boost test? exit(0); } diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index 30387464f3..b92e30c987 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -56,7 +56,6 @@ extern SortList g_sortlist; #include #include #include -#include #include #include #ifdef MALLOC_TRACE @@ -382,7 +381,7 @@ public: { socks_t::iterator i=d_socks.find(fd); if(i==d_socks.end()) { - throw PDNSException("Trying to return a socket (fd="+lexical_cast(fd)+") not in the pool"); + throw PDNSException("Trying to return a socket (fd="+std::to_string(fd)+") not in the pool"); } returnSocketLocked(i); } @@ -414,7 +413,7 @@ public: return ret; if(ret<0) - throw PDNSException("Making a socket for resolver (family = "+lexical_cast(family)+"): "+stringerror()); + throw PDNSException("Making a socket for resolver (family = "+std::to_string(family)+"): "+stringerror()); setCloseOnExec(ret); @@ -974,7 +973,7 @@ void makeControlChannelSocket(int processNum=-1) { string sockname=::arg()["socket-dir"]+"/"+s_programname; if(processNum >= 0) - sockname += "."+lexical_cast(processNum); + sockname += "."+std::to_string(processNum); sockname+=".controlsocket"; s_rcc.listen(sockname); @@ -1421,7 +1420,7 @@ void makeUDPServerSockets() int socklen=sin.sin4.sin_family==AF_INET ? sizeof(sin.sin4) : sizeof(sin.sin6); if (::bind(fd, (struct sockaddr *)&sin, socklen)<0) - throw PDNSException("Resolver binding to server socket on port "+ lexical_cast(st.port) +" for "+ st.host+": "+stringerror()); + throw PDNSException("Resolver binding to server socket on port "+ std::to_string(st.port) +" for "+ st.host+": "+stringerror()); setNonBlocking(fd); @@ -2023,7 +2022,7 @@ static void checkLinuxIPv6Limits() #ifdef __linux__ string line; if(readFileIfThere("/proc/sys/net/ipv6/route/max_size", &line)) { - int lim=atoi(line.c_str()); + int lim=std::stoi(line); if(lim < 16384) { L<(random()))+domain); + B.lookup(QType(QType::A), DNSName(std::to_string(random()))+domain); while(B.get(rr)) { } misses++; @@ -796,7 +796,7 @@ void listKey(DomainInfo const &di, DNSSECKeeper& dk, bool printHeader = true) { cout<<(key.second.keyOrZone ? "KSK" : "ZSK")<<" "; - spacelen = (lexical_cast(key.first.getKey()->getBits()).length() >= 8) ? 1 : 8 - lexical_cast(key.first.getKey()->getBits()).length(); + spacelen = (std::to_string(key.first.getKey()->getBits()).length() >= 8) ? 1 : 8 - std::to_string(key.first.getKey()->getBits()).length(); if (key.first.getKey()->getBits() < 1) { cout<<"invalid "<= 13) ? 1 : 13 - algname.length(); cout<(key.second.id).length() > 5) ? 1 : 5 - lexical_cast(key.second.id).length(); + spacelen = (std::to_string(key.second.id).length() > 5) ? 1 : 5 - std::to_string(key.second.id).length(); cout<(cmds[1]))) + if (testAlgorithm(pdns_stou(cmds[1]))) return 0; return 1; } @@ -1587,7 +1587,7 @@ try cerr << "Syntax: pdnsutil test-speed numcores [signing-server]"< 3) ? cmds[3] : "", atoi(cmds[2].c_str())); + testSpeed(dk, DNSName(cmds[1]), (cmds.size() > 3) ? cmds[3] : "", pdns_stou(cmds[2])); } else if(cmds[0] == "verify-crypto") { if(cmds.size() != 2) { @@ -1621,7 +1621,7 @@ try return 0; } DNSName zone(cmds[1]); - unsigned int id=atoi(cmds[2].c_str()); + unsigned int id=pdns_stou(cmds[2]); if(!id) { cerr<<"Invalid KEY-ID"<convertToISC() < key(DNSCryptoKeyEngine::makeFromPEMString(drc, raw)); dpk.setKey(key); - dpk.d_algorithm = atoi(cmds[3].c_str()); + dpk.d_algorithm = pdns_stou(cmds[3]); if(dpk.d_algorithm == 7) dpk.d_algorithm = 5; @@ -2058,7 +2058,7 @@ try } DNSName zone(cmds[1]); - unsigned int id=atoi(cmds[2].c_str()); + unsigned int id=pdns_stou(cmds[2]); DNSSECPrivateKey dpk=dk.getKeyById(zone, id); cout << zone<<" IN DNSKEY "<0) { algorithm = tmp_algo; - } else if(atoi(cmds[n].c_str())) - bits = atoi(cmds[n].c_str()); + } else if(pdns_stou(cmds[n])) + bits = pdns_stou(cmds[n]); else { cerr<<"Unknown algorithm, key flag or size '"<(algorithm)); + throw runtime_error("Can't guess key size for algorithm "+std::to_string(algorithm)); } } } @@ -2420,7 +2420,7 @@ try return 1; } - id = boost::lexical_cast(cmds[3]); + id = pdns_stou(cmds[3]); std::vector keys; if (!B.getDomainKeys(zone, 0, keys)) { cerr << "No keys found for zone " << zone << std::endl; @@ -2442,7 +2442,7 @@ try return 1; } if (cmds.size() > 4) { - bits = boost::lexical_cast(cmds[4]); + bits = pdns_stou(cmds[4]); } if (bits < 1) { cerr << "Invalid bit size " << bits << "given, must be positive integer"; diff --git a/pdns/pkcs11signers.cc b/pdns/pkcs11signers.cc index 1ecaec880d..2276781d11 100644 --- a/pdns/pkcs11signers.cc +++ b/pdns/pkcs11signers.cc @@ -231,7 +231,7 @@ class Pkcs11Slot { d_logged_in = !((tokenInfo.flags & CKF_LOGIN_REQUIRED) == CKF_LOGIN_REQUIRED); } else { logError("C_GetTokenInfo"); - throw PDNSException("Cannot get token info for slot " + boost::lexical_cast(slot)); + throw PDNSException("Cannot get token info for slot " + std::to_string(slot)); } } @@ -658,7 +658,7 @@ CK_RV Pkcs11Slot::HuntSlot(const string& tokenId, CK_SLOT_ID &slotId, _CK_SLOT_I // see if we can find it with slotId try { - slotId = boost::lexical_cast(tokenId); + slotId = std::stoi(tokenId); if ((err = functions->C_GetSlotInfo(slotId, info))) { L<(tokenId)); + tidx.append(tokenId); tidx.append("|"); tidx.append(label); std::map >::iterator tokenIter; @@ -930,7 +930,7 @@ DNSCryptoKeyEngine::storvector_t PKCS11DNSCryptoKeyEngine::convertToISCVector() outputs_t outputs; boost::assign::push_back(storvect) - (make_pair("Algorithm", boost::lexical_cast(d_algorithm))) + (make_pair("Algorithm", std::to_string(d_algorithm))) (make_pair("Engine", d_module)) (make_pair("Slot", d_slot_id)) (make_pair("PIN", d_pin)) @@ -939,7 +939,7 @@ DNSCryptoKeyEngine::storvector_t PKCS11DNSCryptoKeyEngine::convertToISCVector() }; void PKCS11DNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, stormap_t& stormap) { - drc.d_algorithm = atoi(stormap["algorithm"].c_str()); + drc.d_algorithm = pdns_stou(stormap["algorithm"]); d_module = stormap["engine"]; d_slot_id = stormap["slot"]; boost::trim(d_slot_id); diff --git a/pdns/pollmplexer.cc b/pdns/pollmplexer.cc index 5b38341bb6..08f126eb4e 100644 --- a/pdns/pollmplexer.cc +++ b/pdns/pollmplexer.cc @@ -6,7 +6,6 @@ #include #include #include "misc.hh" -#include #include "syncres.hh" #include "utility.hh" #include "namespaces.hh" @@ -32,7 +31,7 @@ void PollFDMultiplexer::addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo, cb.d_parameter=parameter; memset(&cb.d_ttd, 0, sizeof(cb.d_ttd)); if(cbmap.count(fd)) - throw FDMultiplexerException("Tried to add fd "+lexical_cast(fd)+ " to multiplexer twice"); + throw FDMultiplexerException("Tried to add fd "+std::to_string(fd)+ " to multiplexer twice"); cbmap[fd]=cb; } @@ -42,7 +41,7 @@ void PollFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd) d_iter++; if(!cbmap.erase(fd)) - throw FDMultiplexerException("Tried to remove unlisted fd "+lexical_cast(fd)+ " from multiplexer"); + throw FDMultiplexerException("Tried to remove unlisted fd "+std::to_string(fd)+ " from multiplexer"); } bool pollfdcomp(const struct pollfd& a, const struct pollfd& b) diff --git a/pdns/portsmplexer.cc b/pdns/portsmplexer.cc index 03ad0ed0d7..58d05f7eee 100644 --- a/pdns/portsmplexer.cc +++ b/pdns/portsmplexer.cc @@ -11,7 +11,6 @@ #include #include "misc.hh" -#include #include "syncres.hh" #include "namespaces.hh" @@ -75,7 +74,7 @@ void PortsFDMultiplexer::addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toDo void PortsFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd) { if(!cbmap.erase(fd)) - throw FDMultiplexerException("Tried to remove unlisted fd "+lexical_cast(fd)+ " from multiplexer"); + throw FDMultiplexerException("Tried to remove unlisted fd "+std::to_string(fd)+ " from multiplexer"); if(port_dissociate(d_portfd, PORT_SOURCE_FD, fd) < 0 && errno != ENOENT) // it appears under some circumstances, ENOENT will be returned, without this being an error. Apache has this same "fix" throw FDMultiplexerException("Removing fd from port set: "+stringerror()); diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index dbb30ec0e9..dd34186de3 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -27,7 +27,6 @@ #include "dnsparser.hh" #include "misc.hh" #include "utility.hh" -#include #include #include #include "base32.hh" @@ -41,6 +40,8 @@ RecordTextReader::RecordTextReader(const string& str, const string& zone) : d_st void RecordTextReader::xfr48BitInt(uint64_t &val) { xfr64BitInt(val); + if (val > 281474976710655LL) + throw RecordTextException("Overflow reading 48 bit integer from record content"); // fixme improve } void RecordTextReader::xfr64BitInt(uint64_t &val) @@ -48,12 +49,12 @@ void RecordTextReader::xfr64BitInt(uint64_t &val) skipSpaces(); if(!isdigit(d_string.at(d_pos))) - throw RecordTextException("expected digits at position "+lexical_cast(d_pos)+" in '"+d_string+"'"); + throw RecordTextException("expected digits at position "+std::to_string(d_pos)+" in '"+d_string+"'"); - char *endptr; - val=strtoull(d_string.c_str() + d_pos, &endptr, 10); + size_t pos; + val=std::stoull(d_string.substr(d_pos), &pos); - d_pos = endptr - d_string.c_str(); + d_pos += pos; } @@ -62,14 +63,12 @@ void RecordTextReader::xfr32BitInt(uint32_t &val) skipSpaces(); if(!isdigit(d_string.at(d_pos))) - throw RecordTextException("expected digits at position "+lexical_cast(d_pos)+" in '"+d_string+"'"); + throw RecordTextException("expected digits at position "+std::to_string(d_pos)+" in '"+d_string+"'"); - char *endptr; - unsigned long ret=pdns_strtoui(d_string.c_str() + d_pos, &endptr, 10); - if (ret == UINT_MAX && errno == ERANGE) throw RecordTextException("serial number too large in '"+d_string+"'"); - val=ret; - - d_pos = endptr - d_string.c_str(); + size_t pos; + val=pdns_stou(d_string.substr(d_pos), &pos); + + d_pos += pos; } void RecordTextReader::xfrTime(uint32_t &val) @@ -98,7 +97,7 @@ void RecordTextReader::xfrIP(uint32_t &val) skipSpaces(); if(!isdigit(d_string.at(d_pos))) - throw RecordTextException("while parsing IP address, expected digits at position "+lexical_cast(d_pos)+" in '"+d_string+"'"); + throw RecordTextException("while parsing IP address, expected digits at position "+std::to_string(d_pos)+" in '"+d_string+"'"); uint32_t octet=0; val=0; @@ -149,7 +148,7 @@ void RecordTextReader::xfrIP6(std::string &val) len++); if(!len) - throw RecordTextException("while parsing IPv6 address, expected xdigits at position "+lexical_cast(d_pos)+" in '"+d_string+"'"); + throw RecordTextException("while parsing IPv6 address, expected xdigits at position "+std::to_string(d_pos)+" in '"+d_string+"'"); // end of value is here, try parse as IPv6 string address=d_string.substr(d_pos, len); @@ -245,7 +244,7 @@ void RecordTextReader::xfrBlobNoSpaces(string& val, int len) { B64Decode(tmp, val); if (len>-1 && val.size() != static_cast(len)) - throw RecordTextException("Record length "+lexical_cast(val.size()) + " does not match expected length '"+lexical_cast(len)); + throw RecordTextException("Record length "+std::to_string(val.size()) + " does not match expected length '"+std::to_string(len)); } void RecordTextReader::xfrBlob(string& val, int) @@ -273,7 +272,7 @@ static inline uint8_t hextodec(uint8_t val) else if(val >= 'a' && val<='f') return 10+(val-'a'); else - throw RecordTextException("Unknown hexadecimal character '"+lexical_cast(val)+"'"); + throw RecordTextException("Unknown hexadecimal character '"+std::to_string(val)+"'"); } @@ -355,7 +354,7 @@ void RecordTextReader::xfrText(string& val, bool multi) d_pos = d_end; break; } - throw RecordTextException("Data field in DNS should start with quote (\") at position "+lexical_cast(d_pos)+" of '"+d_string+"'"); + throw RecordTextException("Data field in DNS should start with quote (\") at position "+std::to_string(d_pos)+" of '"+d_string+"'"); } val.append(1, '"'); while(++d_pos < d_end && d_string[d_pos]!='"') { @@ -407,7 +406,7 @@ void RecordTextWriter::xfr48BitInt(const uint64_t& val) { if(!d_string.empty()) d_string.append(1,' '); - d_string+=lexical_cast(val); + d_string+=std::to_string(val); } @@ -415,7 +414,7 @@ void RecordTextWriter::xfr32BitInt(const uint32_t& val) { if(!d_string.empty()) d_string.append(1,' '); - d_string+=lexical_cast(val); + d_string+=std::to_string(val); } void RecordTextWriter::xfrType(const uint16_t& val) diff --git a/pdns/rec_channel_rec.cc b/pdns/rec_channel_rec.cc index e2050f1315..c80d643971 100644 --- a/pdns/rec_channel_rec.cc +++ b/pdns/rec_channel_rec.cc @@ -3,7 +3,6 @@ #endif #include "utility.hh" #include "rec_channel.hh" -#include #include #include #ifdef MALLOC_TRACE @@ -71,15 +70,15 @@ map getAllStatsMap() map ret; for(const auto& the32bits : d_get32bitpointers) { - ret.insert(make_pair(the32bits.first, lexical_cast(*the32bits.second))); + ret.insert(make_pair(the32bits.first, std::to_string(*the32bits.second))); } for(const auto& the64bits : d_get64bitpointers) { - ret.insert(make_pair(the64bits.first, lexical_cast(*the64bits.second))); + ret.insert(make_pair(the64bits.first, std::to_string(*the64bits.second))); } for(const auto& the32bitmembers : d_get32bitmembers) { if(the32bitmembers.first == "cache-bytes" || the32bitmembers.first=="packetcache-bytes") continue; // too slow for 'get-all' - ret.insert(make_pair(the32bitmembers.first, lexical_cast(the32bitmembers.second()))); + ret.insert(make_pair(the32bitmembers.first, std::to_string(the32bitmembers.second()))); } return ret; } @@ -103,7 +102,7 @@ string doGet(T begin, T end) for(T i=begin; i != end; ++i) { optional num=get(*i); if(num) - ret+=lexical_cast(*num)+"\n"; + ret+=std::to_string(*num)+"\n"; else ret+="UNKNOWN\n"; } @@ -182,7 +181,7 @@ string doDumpNSSpeeds(T begin, T end) catch(...){} close(fd); - return "dumped "+lexical_cast(total)+" records\n"; + return "dumped "+std::to_string(total)+" records\n"; } template @@ -204,7 +203,7 @@ string doDumpCache(T begin, T end) catch(...){} close(fd); - return "dumped "+lexical_cast(total)+" records\n"; + return "dumped "+std::to_string(total)+" records\n"; } template @@ -303,7 +302,7 @@ string setMinimumTTL(T begin, T end) { if(end-begin != 1) return "Need to supply new minimum TTL number\n"; - SyncRes::s_minimumTTL = atoi(begin->c_str()); + SyncRes::s_minimumTTL = pdns_stou(*begin); return "New minimum TTL: " + std::to_string(SyncRes::s_minimumTTL) + "\n"; } diff --git a/pdns/reczones.cc b/pdns/reczones.cc index e665c569ac..0d71d8021f 100644 --- a/pdns/reczones.cc +++ b/pdns/reczones.cc @@ -201,14 +201,14 @@ ComboAddress parseIPAndPort(const std::string& input, uint16_t port) try { // case 2 both=splitField(input,':'); - uint16_t newport=boost::lexical_cast(both.second); + uint16_t newport=static_cast(pdns_stou(both.second)); return ComboAddress(both.first, newport); } catch(...){} if(input[0]=='[') { // case 4 both=splitField(input.substr(1),']'); - return ComboAddress(both.first, both.second.empty() ? port : boost::lexical_cast(both.second.substr(1))); + return ComboAddress(both.first, both.second.empty() ? port : static_cast(pdns_stou(both.second.substr(1)))); } return ComboAddress(input, port); // case 3 @@ -464,7 +464,7 @@ SyncRes::domainmap_t* parseAuthAndForwards() ad.d_rdForward = false; if(domain.empty()) { delete newMap; - throw PDNSException("Error parsing line "+lexical_cast(linenum)+" of " +::arg()["forward-zones-file"]); + throw PDNSException("Error parsing line "+std::to_string(linenum)+" of " +::arg()["forward-zones-file"]); } try { @@ -472,7 +472,7 @@ SyncRes::domainmap_t* parseAuthAndForwards() } catch(...) { delete newMap; - throw PDNSException("Conversion error parsing line "+lexical_cast(linenum)+" of " +::arg()["forward-zones-file"]); + throw PDNSException("Conversion error parsing line "+std::to_string(linenum)+" of " +::arg()["forward-zones-file"]); } (*newMap)[DNSName(domain)]=ad; @@ -528,7 +528,7 @@ SyncRes::domainmap_t* parseAuthAndForwards() parts[0]="192.168"; makeIPToNamesZone(newMap, parts); for(int n=16; n < 32; n++) { - parts[0]="172."+lexical_cast(n); + parts[0]="172."+std::to_string(n); makeIPToNamesZone(newMap,parts); } } diff --git a/pdns/resolver.cc b/pdns/resolver.cc index 5bf0c65bd5..d0eafe6ecb 100644 --- a/pdns/resolver.cc +++ b/pdns/resolver.cc @@ -360,7 +360,7 @@ void Resolver::getSoaSerial(const string &ipport, const DNSName &domain, uint32_ if(parts.size()<3) throw ResolverException("Query to '" + ipport + "' for SOA of '" + domain.toString() + "' produced an unparseable response"); - *serial=(uint32_t)atol(parts[2].c_str()); + *serial=pdns_stou(parts[2]); } AXFRRetriever::AXFRRetriever(const ComboAddress& remote, diff --git a/pdns/saxfr.cc b/pdns/saxfr.cc index 08fa33b610..b5c0d75054 100644 --- a/pdns/saxfr.cc +++ b/pdns/saxfr.cc @@ -164,7 +164,7 @@ try MOADNSParser mdp(string(creply, len)); if (mdp.d_header.rcode != 0) { - throw PDNSException(string("Remote server refused: ") + boost::lexical_cast(mdp.d_header.rcode)); + throw PDNSException(string("Remote server refused: ") + std::to_string(mdp.d_header.rcode)); } for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) { if(i->first.d_type != QType::TKEY) continue; @@ -231,7 +231,7 @@ try MOADNSParser mdp(packet); if (mdp.d_header.rcode != 0) { - throw PDNSException(string("Remote server refused: ") + boost::lexical_cast(mdp.d_header.rcode)); + throw PDNSException(string("Remote server refused: ") + std::to_string(mdp.d_header.rcode)); } for(MOADNSParser::answers_t::const_iterator i=mdp.d_answers.begin(); i!=mdp.d_answers.end(); ++i) { if (i->first.d_type == QType::TSIG) { diff --git a/pdns/secpoll-auth.cc b/pdns/secpoll-auth.cc index 5d4e3785cc..e3db28b15b 100644 --- a/pdns/secpoll-auth.cc +++ b/pdns/secpoll-auth.cc @@ -161,7 +161,7 @@ void doSecPoll(bool first) pair split = splitField(content, ' '); - security_status = atoi(split.first.c_str()); + security_status = std::stoi(split.first); g_security_message = split.second; } diff --git a/pdns/secpoll-recursor.cc b/pdns/secpoll-recursor.cc index cc211c1934..bccfd4a8f2 100644 --- a/pdns/secpoll-recursor.cc +++ b/pdns/secpoll-recursor.cc @@ -45,7 +45,7 @@ void doSecPoll(time_t* last_secpoll) pair split = splitField(content, ' '); - g_security_status = atoi(split.first.c_str()); + g_security_status = std::stoi(split.first); g_security_message = split.second; *last_secpoll=now.tv_sec; diff --git a/pdns/selectmplexer.cc b/pdns/selectmplexer.cc index bb20b095e1..34aa0fc3f3 100644 --- a/pdns/selectmplexer.cc +++ b/pdns/selectmplexer.cc @@ -5,7 +5,6 @@ #include "sstuff.hh" #include #include "misc.hh" -#include #include "syncres.hh" #include "utility.hh" @@ -32,7 +31,7 @@ void SelectFDMultiplexer::addFD(callbackmap_t& cbmap, int fd, callbackfunc_t toD cb.d_parameter=parameter; memset(&cb.d_ttd, 0, sizeof(cb.d_ttd)); if(cbmap.count(fd)) - throw FDMultiplexerException("Tried to add fd "+lexical_cast(fd)+ " to multiplexer twice"); + throw FDMultiplexerException("Tried to add fd "+std::to_string(fd)+ " to multiplexer twice"); cbmap[fd]=cb; } @@ -42,7 +41,7 @@ void SelectFDMultiplexer::removeFD(callbackmap_t& cbmap, int fd) d_iter++; if(!cbmap.erase(fd)) - throw FDMultiplexerException("Tried to remove unlisted fd "+lexical_cast(fd)+ " from multiplexer"); + throw FDMultiplexerException("Tried to remove unlisted fd "+std::to_string(fd)+ " from multiplexer"); } int SelectFDMultiplexer::run(struct timeval* now) diff --git a/pdns/serialtweaker.cc b/pdns/serialtweaker.cc index fbbecce26f..2a7f4e135e 100644 --- a/pdns/serialtweaker.cc +++ b/pdns/serialtweaker.cc @@ -127,7 +127,7 @@ uint32_t calculateIncreaseSOA(SOAData sd, const string& increaseKind, const stri localtime_r(&now, &tm); boost::format fmt("%04d%02d%02d%02d"); string newdate = (fmt % (tm.tm_year + 1900) % (tm.tm_mon + 1) % tm.tm_mday % 1).str(); - uint32_t new_serial = atol(newdate.c_str()); + uint32_t new_serial = pdns_stou(newdate); if (new_serial <= sd.serial) { new_serial = sd.serial + 1; } diff --git a/pdns/signingpipe.cc b/pdns/signingpipe.cc index b0b5f447da..71d0f997ec 100644 --- a/pdns/signingpipe.cc +++ b/pdns/signingpipe.cc @@ -161,7 +161,7 @@ pair, vector > ChunkedSigningPipe::waitForRW(bool rd, bool wr, int res = poll(&pfds[0], pfds.size(), (seconds < 0) ? -1 : (seconds * 1000)); // -1 = infinite if(res < 0) - unixDie("polling for activity from signers, "+lexical_cast(d_sockets.size())); + unixDie("polling for activity from signers, "+std::to_string(d_sockets.size())); pair, vector > vects; for(unsigned int n = 0; n < pfds.size(); ++n) if(pfds[n].revents & POLLIN) diff --git a/pdns/slavecommunicator.cc b/pdns/slavecommunicator.cc index fb7bdf4310..40dd15948c 100644 --- a/pdns/slavecommunicator.cc +++ b/pdns/slavecommunicator.cc @@ -40,7 +40,6 @@ #include "arguments.hh" #include "packetcache.hh" -#include #include "base64.hh" #include "inflighter.cc" #include "lua-auth.hh" diff --git a/pdns/sodiumsigners.cc b/pdns/sodiumsigners.cc index a7db67900e..7c6d744dae 100644 --- a/pdns/sodiumsigners.cc +++ b/pdns/sodiumsigners.cc @@ -38,7 +38,7 @@ private: void SodiumED25519DNSCryptoKeyEngine::create(unsigned int bits) { if(bits != crypto_sign_ed25519_SEEDBYTES * 8) { - throw runtime_error("Unsupported key length of "+lexical_cast(bits)+" bits requested, SodiumED25519 class"); + throw runtime_error("Unsupported key length of "+std::to_string(bits)+" bits requested, SodiumED25519 class"); } crypto_sign_ed25519_keypair(d_pubkey, d_seckey); } @@ -74,7 +74,7 @@ void SodiumED25519DNSCryptoKeyEngine::fromISCMap(DNSKEYRecordContent& drc, std:: PrivateKey: GU6SnQ/Ou+xC5RumuIUIuJZteXT2z0O/ok1s38Et6mQ= */ - drc.d_algorithm = atoi(stormap["algorithm"].c_str()); + drc.d_algorithm = pdns_stou(stormap["algorithm"]); string privateKey = stormap["privatekey"]; if (privateKey.length() != crypto_sign_ed25519_SEEDBYTES) diff --git a/pdns/syncres.cc b/pdns/syncres.cc index 7f6baaf960..4ee8524d00 100644 --- a/pdns/syncres.cc +++ b/pdns/syncres.cc @@ -1024,7 +1024,7 @@ int SyncRes::doResolveAt(set nameservers, DNSName auth, bool flawedNSSe } else { s_outqueries++; d_outqueries++; - if(d_outqueries + d_throttledqueries > s_maxqperq) throw ImmediateServFailException("more than "+lexical_cast(s_maxqperq)+" (max-qperq) queries sent while resolving "+qname.toString()); + if(d_outqueries + d_throttledqueries > s_maxqperq) throw ImmediateServFailException("more than "+std::to_string(s_maxqperq)+" (max-qperq) queries sent while resolving "+qname.toString()); TryTCP: if(doTCP) { LOG(prefix<toStringWithPort() < nameservers, DNSName auth, bool flawedNSSe } if(s_maxtotusec && d_totUsec > s_maxtotusec) - throw ImmediateServFailException("Too much time waiting for "+qname.toString()+"|"+qtype.getName()+", timeouts: "+boost::lexical_cast(d_timeouts) +", throttles: "+boost::lexical_cast(d_throttledqueries) + ", queries: "+lexical_cast(d_outqueries)+", "+lexical_cast(d_totUsec/1000)+"msec"); + throw ImmediateServFailException("Too much time waiting for "+qname.toString()+"|"+qtype.getName()+", timeouts: "+std::to_string(d_timeouts) +", throttles: "+std::to_string(d_throttledqueries) + ", queries: "+std::to_string(d_outqueries)+", "+std::to_string(d_totUsec/1000)+"msec"); if(d_pdl && d_pdl->preoutquery(*remoteIP, d_requestor, qname, qtype, lwr.d_records, resolveret)) { LOG(prefix< nameservers, DNSName auth, bool flawedNSSe continue; } -// if(d_timeouts + 0.5*d_throttledqueries > 6.0 && d_timeouts > 2) throw ImmediateServFailException("Too much work resolving "+qname+"|"+qtype.getName()+", timeouts: "+boost::lexical_cast(d_timeouts) +", throttles: "+boost::lexical_cast(d_throttledqueries)); +// if(d_timeouts + 0.5*d_throttledqueries > 6.0 && d_timeouts > 2) throw ImmediateServFailException("Too much work resolving "+qname+"|"+qtype.getName()+", timeouts: "+std::to_string(d_timeouts) +", throttles: "+std::to_string(d_throttledqueries)); if(lwr.d_rcode==RCode::ServFail || lwr.d_rcode==RCode::Refused) { LOG(prefix<toString()<<" returned a "<< (lwr.d_rcode==RCode::ServFail ? "ServFail" : "Refused") << ", trying sibling IP or NS"< q, int ou vector digestAlgos; stringtok(digestAlgos, publishCDS, ", "); for(auto const &digestAlgo : digestAlgos) { - rr.content=makeDSFromDNSKey(target, value.first.getDNSKEY(), lexical_cast(digestAlgo)).getZoneRepresentation(); + rr.content=makeDSFromDNSKey(target, value.first.getDNSKEY(), pdns_stou(digestAlgo)).getZoneRepresentation(); cds.push_back(rr); } } @@ -1002,7 +1002,7 @@ int TCPNameserver::doIXFR(shared_ptr q, int outsock) vectorparts; stringtok(parts, rr->d_content->getZoneRepresentation()); if (parts.size() >= 3) { - serial=atoi(parts[2].c_str()); + serial=pdns_stou(parts[2]); } else { L<setRcode(RCode::FormErr); diff --git a/pdns/test-dnsrecords_cc.cc b/pdns/test-dnsrecords_cc.cc index b134256591..77e17bed61 100644 --- a/pdns/test-dnsrecords_cc.cc +++ b/pdns/test-dnsrecords_cc.cc @@ -221,7 +221,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) { } } -bool test_dnsrecords_cc_predicate( std::runtime_error const &ex ) { return true; } +bool test_dnsrecords_cc_predicate( std::exception const &ex ) { return true; } // these *MUST NOT* parse properly! BOOST_AUTO_TEST_CASE(test_record_types_bad_values) { @@ -265,10 +265,10 @@ BOOST_AUTO_TEST_CASE(test_record_types_bad_values) { if (val.get<2>()) { bool success=true; - BOOST_WARN_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::runtime_error, test_dnsrecords_cc_predicate ); + BOOST_WARN_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); success=false; }, std::exception, test_dnsrecords_cc_predicate ); if (success==false) REC_FAIL_XSUCCESS2(q.getName() << " test #" << n << " has unexpectedly passed"); // a bad record was detected when it was supposed not to be detected } else { - BOOST_CHECK_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::runtime_error, test_dnsrecords_cc_predicate ); + BOOST_CHECK_EXCEPTION( { boost::scoped_ptr drc(DNSRecordContent::mastermake(q.getCode(), 1, val.get<1>())); pw.startRecord(DNSName("unit.test"), q.getCode()); drc->toPacket(pw); }, std::exception, test_dnsrecords_cc_predicate ); } }; } diff --git a/pdns/test-packetcache_cc.cc b/pdns/test-packetcache_cc.cc index e806ecfa23..ad6353cb16 100644 --- a/pdns/test-packetcache_cc.cc +++ b/pdns/test-packetcache_cc.cc @@ -39,7 +39,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { int counter=0; try { for(counter = 0; counter < 100000; ++counter) { - DNSName a=DNSName("hello ")+DNSName(boost::lexical_cast(counter)); + DNSName a=DNSName("hello ")+DNSName(std::to_string(counter)); BOOST_CHECK_EQUAL(DNSName(a.toString()), a); PC.insert(a, QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); @@ -52,7 +52,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { int delcounter=0; for(delcounter=0; delcounter < counter/100; ++delcounter) { - DNSName a=DNSName("hello ")+DNSName(boost::lexical_cast(delcounter)); + DNSName a=DNSName("hello ")+DNSName(std::to_string(delcounter)); PC.purge(a.toString()); } @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { vector entry; int expected=counter-delcounter; for(; delcounter < counter; ++delcounter) { - if(PC.getEntry(DNSName("hello ")+DNSName(boost::lexical_cast(delcounter)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { + if(PC.getEntry(DNSName("hello ")+DNSName(std::to_string(delcounter)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { matches++; } } @@ -83,7 +83,7 @@ try { unsigned int offset=(unsigned int)(unsigned long)a; for(unsigned int counter=0; counter < 100000; ++counter) - g_PC->insert(DNSName("hello ")+DNSName(boost::lexical_cast(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); + g_PC->insert(DNSName("hello ")+DNSName(std::to_string(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, "something", 3600, 1); return 0; } catch(PDNSException& e) { @@ -99,7 +99,7 @@ try unsigned int offset=(unsigned int)(unsigned long)a; vector entry; for(unsigned int counter=0; counter < 100000; ++counter) - if(!g_PC->getEntry(DNSName("hello ")+DNSName(boost::lexical_cast(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { + if(!g_PC->getEntry(DNSName("hello ")+DNSName(std::to_string(counter+offset)), QType(QType::A), PacketCache::QUERYCACHE, entry, 1)) { g_missing++; } return 0; @@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheClean) { PacketCache PC; for(unsigned int counter = 0; counter < 1000000; ++counter) { - PC.insert(DNSName("hello ")+DNSName(boost::lexical_cast(counter)), QType(QType::A), PacketCache::QUERYCACHE, "something", 1, 1); + PC.insert(DNSName("hello ")+DNSName(std::to_string(counter)), QType(QType::A), PacketCache::QUERYCACHE, "something", 1, 1); } sleep(1); diff --git a/pdns/test-zoneparser_tng_cc.cc b/pdns/test-zoneparser_tng_cc.cc index bc785186d0..f45de57a03 100644 --- a/pdns/test-zoneparser_tng_cc.cc +++ b/pdns/test-zoneparser_tng_cc.cc @@ -9,7 +9,6 @@ #include #include #include -#include #include "dns.hh" #include "zoneparser-tng.hh" #include "dnsrecords.hh" @@ -35,10 +34,10 @@ BOOST_AUTO_TEST_CASE(test_tng_record_types) { while(zp.get(rr)) { // make sure these concur. std::string host, type, data; - int ttl; + unsigned int ttl; std::getline(ifs, host, ' '); std::getline(ifs, type, ' '); - ttl = boost::lexical_cast(type); + ttl = pdns_stou(type); std::getline(ifs, type, ' '); std::getline(ifs, type, ' '); std::getline(ifs, data, '\n'); diff --git a/pdns/validate.cc b/pdns/validate.cc index b2e213d923..e37933eaf5 100644 --- a/pdns/validate.cc +++ b/pdns/validate.cc @@ -114,7 +114,7 @@ void validateWithKeySet(const cspmap_t& rrsets, cspmap_t& validated, const keyse ; // cerr<<"signature invalid"<d_type != QType::DNSKEY) { dotEdge(signature->d_signer, - "DNSKEY", signature->d_signer, lexical_cast(signature->d_tag), + "DNSKEY", signature->d_signer, std::to_string(signature->d_tag), DNSRecordContent::NumberToType(signature->d_type), i->first.first, "", isValid ? "green" : "red"); } @@ -201,7 +201,7 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset) auto drc=getRR (rec); tkeys.insert(*drc); // cerr<<"Inserting key with tag "<getTag()<<": "<getZoneRepresentation()<(drc->getTag()), (boost::format("tag=%d, algo=%d") % drc->getTag() % static_cast(drc->d_algorithm)).str()); + dotNode("DNSKEY", qname, std::to_string(drc->getTag()), (boost::format("tag=%d, algo=%d") % drc->getTag() % static_cast(drc->d_algorithm)).str()); toSign.push_back(rec.d_content); toSignTags.push_back(drc->getTag()); @@ -231,13 +231,13 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset) // cerr<<"got valid DNSKEY (it matches the DS) for "<(dsrc.d_tag)*/, (boost::format("tag=%d, digest algo=%d, algo=%d") % dsrc.d_tag % static_cast(dsrc.d_digesttype) % static_cast(dsrc.d_algorithm)).str()); + dotNode("DS", qname, "" /*std::to_string(dsrc.d_tag)*/, (boost::format("tag=%d, digest algo=%d, algo=%d") % dsrc.d_tag % static_cast(dsrc.d_digesttype) % static_cast(dsrc.d_algorithm)).str()); } else { // cerr<<"DNSKEY did not match the DS, parent DS: "< "<(dsrc.d_digesttype)<<"\" ]; label = \"zone: "<(dsrc.d_tag)*/, "DNSKEY", qname, lexical_cast(drc.getTag()), isValid ? "green" : "red"); + dotEdge(DNSName("."), "DS", qname, "" /*std::to_string(dsrc.d_tag)*/, "DNSKEY", qname, std::to_string(drc.getTag()), isValid ? "green" : "red"); // dotNode("DNSKEY", qname, (boost::format("tag=%d, algo=%d") % drc.getTag() % static_cast(drc.d_algorithm)).str()); } } @@ -269,8 +269,8 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset) } for(uint16_t tag : toSignTags) { dotEdge(qname, - "DNSKEY", qname, lexical_cast(i->d_tag), - "DNSKEY", qname, lexical_cast(tag), isValid ? "green" : "red"); + "DNSKEY", qname, std::to_string(i->d_tag), + "DNSKEY", qname, std::to_string(tag), isValid ? "green" : "red"); } if(isValid) @@ -328,7 +328,7 @@ vState getKeysFor(DNSRecordOracle& dro, const DNSName& zone, keyset_t &keyset) dsmap.insert(make_pair(dsrc->d_tag, *dsrc)); // dotEdge(keyqname, // "DNSKEY", keyqname, , - // "DS", qname, lexical_cast(dsrc.d_tag)); + // "DS", qname, std::to_string(dsrc.d_tag)); // cout<<" "< "<(resp.body.size()); + resp.headers["Content-Length"] = std::to_string(resp.body.size()); } return resp; diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 6f7a2659b4..aa9ceb48ec 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -210,9 +210,9 @@ void AuthWebServer::indexfunction(HttpRequest* req, HttpResponse* resp) return; } if(!req->getvars["resizering"].empty()){ - int size=atoi(req->getvars["size"].c_str()); + int size=std::stoi(req->getvars["size"]); if (S.ringExists(req->getvars["resizering"]) && size > 0 && size <= 500000) - S.resizeRing(req->getvars["resizering"], atoi(req->getvars["size"].c_str())); + S.resizeRing(req->getvars["resizering"], std::stoi(req->getvars["size"])); resp->status = 301; resp->headers["Location"] = req->url.path; return; @@ -399,11 +399,11 @@ void productServerStatisticsFetch(map& out) { vector items = S.getEntries(); for(const string& item : items) { - out[item] = lexical_cast(S.read(item)); + out[item] = std::to_string(S.read(item)); } // add uptime - out["uptime"] = lexical_cast(time(0) - s_starttime); + out["uptime"] = std::to_string(time(0) - s_starttime); } static void gatherRecords(const Value& container, vector& new_records, vector& new_ptrs) { @@ -538,8 +538,8 @@ static void apiZoneCryptokeys(HttpRequest* req, HttpResponse* resp) { for(DNSSECKeeper::keyset_t::value_type value : keyset) { if (req->parameters.count("key_id")) { - int keyid = lexical_cast(req->parameters["key_id"]); - int curid = lexical_cast(value.second.id); + int keyid = std::stoi(req->parameters["key_id"]); + int curid = value.second.id; if (keyid != curid) continue; } @@ -552,7 +552,7 @@ static void apiZoneCryptokeys(HttpRequest* req, HttpResponse* resp) { Value dnskey(value.first.getDNSKEY().getZoneRepresentation().c_str(), doc.GetAllocator()); key.AddMember("dnskey", dnskey, doc.GetAllocator()); if (req->parameters.count("key_id")) { - DNSSECPrivateKey dpk=dk.getKeyById(zonename, lexical_cast(req->parameters["key_id"])); + DNSSECPrivateKey dpk=dk.getKeyById(zonename, std::stoi(req->parameters["key_id"])); Value content(dpk.getKey()->convertToISC().c_str(), doc.GetAllocator()); key.AddMember("content", content, doc.GetAllocator()); } @@ -1078,7 +1078,7 @@ static void apiServerSearchData(HttpRequest* req, HttpResponse* resp) { if (q.empty()) throw ApiException("Query q can't be blank"); if (sMax.empty() == false) - maxEnts = boost::lexical_cast(sMax); + maxEnts = std::stoi(sMax); if (maxEnts < 1) throw ApiException("Maximum entries must be larger than 0"); @@ -1170,7 +1170,7 @@ void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { int count = PC.purgeExact(canon); map object; - object["count"] = lexical_cast(count); + object["count"] = std::to_string(count); object["result"] = "Flushed cache."; resp->body = returnJsonObject(object); } diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index b818d0cdeb..f26ba23ddd 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -422,7 +422,7 @@ static void apiServerCacheFlush(HttpRequest* req, HttpResponse* resp) { count += broadcastAccFunction(boost::bind(pleaseWipePacketCache, canon, false)); count += broadcastAccFunction(boost::bind(pleaseWipeAndCountNegCache, canon, false)); map object; - object["count"] = lexical_cast(count); + object["count"] = std::to_string(count); object["result"] = "Flushed cache."; resp->body = returnJsonObject(object); } diff --git a/pdns/zone2json.cc b/pdns/zone2json.cc index 30b5fc5e90..fc56921585 100644 --- a/pdns/zone2json.cc +++ b/pdns/zone2json.cc @@ -59,7 +59,7 @@ static Json::object emitRecord(const string& zoneName, const DNSName &DNSqname, g_numRecords++; string content(ocontent); if(qtype == "MX" || qtype == "SRV") { - prio=atoi(content.c_str()); + prio=pdns_stou(content); string::size_type pos = content.find_first_not_of("0123456789"); if(pos != string::npos) diff --git a/pdns/zone2sql.cc b/pdns/zone2sql.cc index b38207663f..d675051218 100644 --- a/pdns/zone2sql.cc +++ b/pdns/zone2sql.cc @@ -173,7 +173,7 @@ static void emitRecord(const string& zoneName, const DNSName &DNSqname, const st return; // NSECs do not go in the database if((qtype == "MX" || qtype == "SRV") && g_mode!=ORACLE) { - prio=atoi(content.c_str()); + prio=pdns_stou(content); string::size_type pos = content.find_first_not_of("0123456789"); if(pos != string::npos) @@ -259,8 +259,8 @@ static void emitRecord(const string& zoneName, const DNSName &DNSqname, const st stringtok(parts, content); cout<<"INSERT INTO soa(origin, ns, mbox, serial, refresh, retry, expire, minimum, ttl) VALUES("<< - sqlstr(toLower(zoneNameDot))<<", "< #include -#include ZoneParserTNG::ZoneParserTNG(const string& fname, const DNSName& zname, const string& reldir) : d_reldir(reldir), d_zonename(zname), d_defaultttl(3600), @@ -98,7 +97,7 @@ unsigned int ZoneParserTNG::makeTTLFromZone(const string& str) if(str.empty()) return 0; - unsigned int val=atoi(str.c_str()); + unsigned int val=pdns_stou(str); char lc=toupper(str[str.length()-1]); if(!isdigit(lc)) switch(lc) { @@ -163,7 +162,7 @@ bool ZoneParserTNG::getTemplateLine() } if(c=='$') { if(pos + 1 == part.size() || part[pos+1]!='{') { // a trailing $, or not followed by { - outpart.append(lexical_cast(d_templatecounter)); + outpart.append(std::to_string(d_templatecounter)); continue; } @@ -245,9 +244,9 @@ DNSName ZoneParserTNG::getZoneName() string ZoneParserTNG::getLineOfFile() { if (d_zonedata.size() > 0) - return "on line "+lexical_cast(std::distance(d_zonedata.begin(), d_zonedataline))+" of given string"; + return "on line "+std::to_string(std::distance(d_zonedata.begin(), d_zonedataline))+" of given string"; - return "on line "+lexical_cast(d_filestates.top().d_lineno)+" of file '"+d_filestates.top().d_filename+"'"; + return "on line "+std::to_string(d_filestates.top().d_lineno)+" of file '"+d_filestates.top().d_filename+"'"; } // ODD: this function never fills out the prio field! rest of pdns compensates though @@ -444,7 +443,7 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment) rr.content.append(1,' '); if(n > 1) - rr.content+=lexical_cast(makeTTLFromZone(recparts[n])); + rr.content+=std::to_string(makeTTLFromZone(recparts[n])); else rr.content+=recparts[n]; -- 2.47.2