#include "net/dns/nsswitch_reader.h"
#include <string>
#include <string_view>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_POSIX)
#include <netdb.h>
#endif
namespace net {
namespace {
#ifdef _PATH_NSSWITCH_CONF
constexpr base::FilePath::CharType kNsswitchPath[] =
FILE_PATH_LITERAL(_PATH_NSSWITCH_CONF);
#else
constexpr base::FilePath::CharType kNsswitchPath[] =
FILE_PATH_LITERAL("/etc/nsswitch.conf");
#endif
constexpr size_t kMaxFileSize = …;
std::string ReadNsswitch() { … }
std::string_view SkipRestOfLine(std::string_view text) { … }
std::string_view FindDatabase(std::string_view text,
std::string_view database_name) { … }
NsswitchReader::ServiceAction TokenizeAction(std::string_view action_column) { … }
std::vector<NsswitchReader::ServiceAction> TokenizeActions(
std::string_view actions) { … }
NsswitchReader::ServiceSpecification TokenizeService(
std::string_view service_column) { … }
std::string_view GetActionsStringAndRemoveBrackets(std::string_view database,
size_t& out_num_bytes) { … }
std::vector<NsswitchReader::ServiceSpecification> TokenizeDatabase(
std::string_view database) { … }
std::vector<NsswitchReader::ServiceSpecification> GetDefaultHosts() { … }
}
NsswitchReader::ServiceSpecification::ServiceSpecification(
Service service,
std::vector<ServiceAction> actions)
: … { … }
NsswitchReader::ServiceSpecification::~ServiceSpecification() = default;
NsswitchReader::ServiceSpecification::ServiceSpecification(
const ServiceSpecification&) = default;
NsswitchReader::ServiceSpecification&
NsswitchReader::ServiceSpecification::operator=(const ServiceSpecification&) =
default;
NsswitchReader::ServiceSpecification::ServiceSpecification(
ServiceSpecification&&) = default;
NsswitchReader::ServiceSpecification&
NsswitchReader::ServiceSpecification::operator=(ServiceSpecification&&) =
default;
NsswitchReader::NsswitchReader()
: … { … }
NsswitchReader::~NsswitchReader() = default;
std::vector<NsswitchReader::ServiceSpecification>
NsswitchReader::ReadAndParseHosts() { … }
}