Skip to content

Commit

Permalink
Merge pull request #14970 from neheb/jj
Browse files Browse the repository at this point in the history
boost > std optional
  • Loading branch information
Habbie authored Jan 10, 2025
2 parents eac13ac + 3e4597f commit 746bb23
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 31 deletions.
8 changes: 5 additions & 3 deletions modules/geoipbackend/geoipbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,8 @@ static string queryGeoIP(const Netmask& addr, GeoIPInterface::GeoIPQueryAttribut
break;
case GeoIPInterface::Location:
double lat = 0, lon = 0;
boost::optional<int> alt, prec;
std::optional<int> alt;
std::optional<int> prec;
if (addr.isIPv6())
found = gi->queryLocationV6(gl, ip, lat, lon, alt, prec);
else
Expand Down Expand Up @@ -691,7 +692,7 @@ string getGeoForLua(const std::string& ip, int qaint)
}

static bool queryGeoLocation(const Netmask& addr, GeoIPNetmask& gl, double& lat, double& lon,
boost::optional<int>& alt, boost::optional<int>& prec)
std::optional<int>& alt, std::optional<int>& prec)
{
for (auto const& gi : s_geoip_files) {
string val;
Expand All @@ -708,7 +709,8 @@ static bool queryGeoLocation(const Netmask& addr, GeoIPNetmask& gl, double& lat,
string GeoIPBackend::format2str(string sformat, const Netmask& addr, GeoIPNetmask& gl, const GeoIPDomain& dom)
{
string::size_type cur, last;
boost::optional<int> alt, prec;
std::optional<int> alt;
std::optional<int> prec;
double lat, lon;
time_t t = time(nullptr);
GeoIPNetmask tmp_gl; // largest wins
Expand Down
4 changes: 2 additions & 2 deletions modules/geoipbackend/geoipinterface-dat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class GeoIPInterfaceDAT : public GeoIPInterface

bool queryLocationV6(GeoIPNetmask& gl, const string& ip,
double& latitude, double& longitude,
boost::optional<int>& /* alt */, boost::optional<int>& /* prec */) override
std::optional<int>& /* alt */, std::optional<int>& /* prec */) override
{
if (d_db_type == GEOIP_REGION_EDITION_REV0 || d_db_type == GEOIP_REGION_EDITION_REV1 || d_db_type == GEOIP_CITY_EDITION_REV0_V6 || d_db_type == GEOIP_CITY_EDITION_REV1_V6) {
std::unique_ptr<GeoIPRecord, geoiprecord_deleter> gir(GeoIP_record_by_addr_v6(d_gi.get(), ip.c_str()));
Expand All @@ -449,7 +449,7 @@ class GeoIPInterfaceDAT : public GeoIPInterface

bool queryLocation(GeoIPNetmask& gl, const string& ip,
double& latitude, double& longitude,
boost::optional<int>& /* alt */, boost::optional<int>& /* prec */) override
std::optional<int>& /* alt */, std::optional<int>& /* prec */) override
{
if (d_db_type == GEOIP_REGION_EDITION_REV0 || d_db_type == GEOIP_REGION_EDITION_REV1 || d_db_type == GEOIP_CITY_EDITION_REV0 || d_db_type == GEOIP_CITY_EDITION_REV1) {
std::unique_ptr<GeoIPRecord, geoiprecord_deleter> gir(GeoIP_record_by_addr(d_gi.get(), ip.c_str()));
Expand Down
4 changes: 2 additions & 2 deletions modules/geoipbackend/geoipinterface-mmdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class GeoIPInterfaceMMDB : public GeoIPInterface

bool queryLocation(GeoIPNetmask& gl, const string& ip,
double& latitude, double& longitude,
boost::optional<int>& /* alt */, boost::optional<int>& prec) override
std::optional<int>& /* alt */, std::optional<int>& prec) override
{
MMDB_entry_data_s data;
MMDB_lookup_result_s res;
Expand All @@ -228,7 +228,7 @@ class GeoIPInterfaceMMDB : public GeoIPInterface

bool queryLocationV6(GeoIPNetmask& gl, const string& ip,
double& latitude, double& longitude,
boost::optional<int>& /* alt */, boost::optional<int>& prec) override
std::optional<int>& /* alt */, std::optional<int>& prec) override
{
MMDB_entry_data_s data;
MMDB_lookup_result_s res;
Expand Down
4 changes: 2 additions & 2 deletions modules/geoipbackend/geoipinterface.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public:
virtual bool queryCityV6(string& ret, GeoIPNetmask& gl, const string& ip) = 0;
virtual bool queryLocation(GeoIPNetmask& gl, const string& ip,
double& latitude, double& longitude,
boost::optional<int>& alt, boost::optional<int>& prec)
std::optional<int>& alt, std::optional<int>& prec)
= 0;
virtual bool queryLocationV6(GeoIPNetmask& gl, const string& ip,
double& latitude, double& longitude,
boost::optional<int>& alt, boost::optional<int>& prec)
std::optional<int>& alt, std::optional<int>& prec)
= 0;

virtual ~GeoIPInterface() = default;
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-dynblocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void DynBlockRulesGroup::processResponseRules(counts_t& counts, StatNode& root,

if (suffixMatchRuleMatches) {
const bool hit = ringEntry.isACacheHit();
root.submit(ringEntry.name, ((ringEntry.dh.rcode == 0 && ringEntry.usec == std::numeric_limits<unsigned int>::max()) ? -1 : ringEntry.dh.rcode), ringEntry.size, hit, boost::none);
root.submit(ringEntry.name, ((ringEntry.dh.rcode == 0 && ringEntry.usec == std::numeric_limits<unsigned int>::max()) ? -1 : ringEntry.dh.rcode), ringEntry.size, hit, std::nullopt);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnsdistdist/dnsdist-lua-inspection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void statNodeRespRing(statvisitor_t visitor, uint64_t seconds)
}

const bool hit = entry.isACacheHit();
root.submit(entry.name, ((entry.dh.rcode == 0 && entry.usec == std::numeric_limits<unsigned int>::max()) ? -1 : entry.dh.rcode), entry.size, hit, boost::none);
root.submit(entry.name, ((entry.dh.rcode == 0 && entry.usec == std::numeric_limits<unsigned int>::max()) ? -1 : entry.dh.rcode), entry.size, hit, std::nullopt);
}
}

Expand Down
4 changes: 2 additions & 2 deletions pdns/sdig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static const string nameForClass(QClass qclass, uint16_t qtype)
static std::unordered_set<uint16_t> s_expectedIDs;

static void fillPacket(vector<uint8_t>& packet, const string& q, const string& t,
bool dnssec, const boost::optional<Netmask>& ednsnm,
bool dnssec, const std::optional<Netmask>& ednsnm,
bool recurse, QClass qclass, uint8_t opcode, uint16_t qid)
{
DNSPacketWriter pw(packet, DNSName(q), DNSRecordContent::TypeToNumber(t), qclass, opcode);
Expand Down Expand Up @@ -203,7 +203,7 @@ try {
bool fastOpen = false;
bool insecureDoT = false;
bool fromstdin = false;
boost::optional<Netmask> ednsnm;
std::optional<Netmask> ednsnm;
QClass qclass = QClass::IN;
uint8_t opcode = 0;
string proxyheader;
Expand Down
4 changes: 2 additions & 2 deletions pdns/statnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void StatNode::visit(const visitor_t& visitor, Stat& newstat, unsigned int depth
newstat += childstat;
}

void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const boost::optional<const ComboAddress&>& remote)
void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const std::optional<ComboAddress>& remote)
{
// cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
std::vector<string> tmp = domain.getRawLabels();
Expand All @@ -67,7 +67,7 @@ void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool
www.powerdns.com.
*/

void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const boost::optional<const ComboAddress&>& remote, unsigned int count, bool hit)
void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const std::optional<ComboAddress>& remote, unsigned int count, bool hit)
{
// cerr<<"Submit called for domain='"<<domain<<"': ";
// for(const std::string& n : labels)
Expand Down
4 changes: 2 additions & 2 deletions pdns/statnode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public:
std::string fullname;
uint8_t labelsCount{0};

void submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const boost::optional<const ComboAddress&>& remote);
void submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const std::optional<ComboAddress>& remote);
Stat print(unsigned int depth=0, Stat newstat=Stat(), bool silent=false) const;
void visit(const visitor_t& visitor, Stat& newstat, unsigned int depth = 0) const;
bool empty() const
Expand All @@ -75,5 +75,5 @@ public:
children_t children;

private:
void submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const boost::optional<const ComboAddress&>& remote, unsigned int count, bool hit);
void submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const std::optional<ComboAddress>& remote, unsigned int count, bool hit);
};
28 changes: 14 additions & 14 deletions pdns/ws-auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -713,13 +713,13 @@ static bool isZoneApiRectifyEnabled(const DomainInfo& domainInfo)
return api_rectify == "1";
}

static void extractDomainInfoFromDocument(const Json& document, boost::optional<DomainInfo::DomainKind>& kind, boost::optional<vector<ComboAddress>>& primaries, boost::optional<DNSName>& catalog, boost::optional<string>& account)
static void extractDomainInfoFromDocument(const Json& document, std::optional<DomainInfo::DomainKind>& kind, std::optional<vector<ComboAddress>>& primaries, std::optional<DNSName>& catalog, std::optional<string>& account)
{
if (document["kind"].is_string()) {
kind = DomainInfo::stringToKind(stringFromJson(document, "kind"));
}
else {
kind = boost::none;
kind = std::nullopt;
}

if (document["masters"].is_array()) {
Expand All @@ -738,22 +738,22 @@ static void extractDomainInfoFromDocument(const Json& document, boost::optional<
}
}
else {
primaries = boost::none;
primaries = std::nullopt;
}

if (document["catalog"].is_string()) {
string catstring = document["catalog"].string_value();
catalog = (!catstring.empty() ? DNSName(catstring) : DNSName());
}
else {
catalog = boost::none;
catalog = std::nullopt;
}

if (document["account"].is_string()) {
account = document["account"].string_value();
}
else {
account = boost::none;
account = std::nullopt;
}
}

Expand All @@ -778,10 +778,10 @@ static void extractJsonTSIGKeyIds(UeberBackend& backend, const Json& jsonArray,
// Must be called within backend transaction.
static void updateDomainSettingsFromDocument(UeberBackend& backend, DomainInfo& domainInfo, const DNSName& zonename, const Json& document, bool zoneWasModified)
{
boost::optional<DomainInfo::DomainKind> kind;
boost::optional<vector<ComboAddress>> primaries;
boost::optional<DNSName> catalog;
boost::optional<string> account;
std::optional<DomainInfo::DomainKind> kind;
std::optional<vector<ComboAddress>> primaries;
std::optional<DNSName> catalog;
std::optional<string> account;

extractDomainInfoFromDocument(document, kind, primaries, catalog, account);

Expand Down Expand Up @@ -1875,10 +1875,10 @@ static void apiServerZonesPOST(HttpRequest* req, HttpResponse* resp)
throw HttpConflictException();
}

boost::optional<DomainInfo::DomainKind> kind;
boost::optional<vector<ComboAddress>> primaries;
boost::optional<DNSName> catalog;
boost::optional<string> account;
std::optional<DomainInfo::DomainKind> kind;
std::optional<vector<ComboAddress>> primaries;
std::optional<DNSName> catalog;
std::optional<string> account;
extractDomainInfoFromDocument(document, kind, primaries, catalog, account);

// validate 'kind' is set
Expand Down Expand Up @@ -2011,7 +2011,7 @@ static void apiServerZonesPOST(HttpRequest* req, HttpResponse* resp)
}

// no going back after this
if (!backend.createDomain(zonename, kind.get_value_or(DomainInfo::Native), primaries.get_value_or(vector<ComboAddress>()), account.get_value_or(""))) {
if (!backend.createDomain(zonename, kind.value_or(DomainInfo::Native), primaries.value_or(vector<ComboAddress>()), account.value_or(""))) {
throw ApiException("Creating domain '" + zonename.toString() + "' failed: backend refused");
}

Expand Down

0 comments on commit 746bb23

Please sign in to comment.