Commit b0eb68ee authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Convert shrpx_forwarded_node_type to enum class

parent e7b7b037
......@@ -3085,7 +3085,7 @@ int process_options(Config *config,
auto &fwdconf = config->http.forwarded;
if (fwdconf.by_node_type == FORWARDED_NODE_OBFUSCATED &&
if (fwdconf.by_node_type == ForwardedNode::OBFUSCATED &&
fwdconf.by_obfuscated.empty()) {
// 2 for '_' and terminal NULL
auto iov = make_byte_ref(config->balloc, SHRPX_OBFUSCATED_NODE_LENGTH + 2);
......
......@@ -430,7 +430,7 @@ ClientHandler::ClientHandler(Worker *worker, int fd, SSL *ssl,
auto &fwdconf = config->http.forwarded;
if (fwdconf.params & FORWARDED_FOR) {
if (fwdconf.for_node_type == FORWARDED_NODE_OBFUSCATED) {
if (fwdconf.for_node_type == ForwardedNode::OBFUSCATED) {
// 1 for '_'
auto len = SHRPX_OBFUSCATED_NODE_LENGTH + 1;
// 1 for terminating NUL.
......@@ -1490,7 +1490,7 @@ int ClientHandler::proxy_protocol_read() {
auto &fwdconf = config->http.forwarded;
if ((fwdconf.params & FORWARDED_FOR) &&
fwdconf.for_node_type == FORWARDED_NODE_IP) {
fwdconf.for_node_type == ForwardedNode::IP) {
init_forwarded_for(family, ipaddr_);
}
......@@ -1500,7 +1500,7 @@ int ClientHandler::proxy_protocol_read() {
StringRef ClientHandler::get_forwarded_by() const {
auto &fwdconf = get_config()->http.forwarded;
if (fwdconf.by_node_type == FORWARDED_NODE_OBFUSCATED) {
if (fwdconf.by_node_type == ForwardedNode::OBFUSCATED) {
return fwdconf.by_obfuscated;
}
......
......@@ -1195,27 +1195,27 @@ int parse_mapping(Config *config, DownstreamAddrConfig &addr,
} // namespace
namespace {
int parse_forwarded_node_type(const StringRef &optarg) {
ForwardedNode parse_forwarded_node_type(const StringRef &optarg) {
if (util::strieq_l("obfuscated", optarg)) {
return FORWARDED_NODE_OBFUSCATED;
return ForwardedNode::OBFUSCATED;
}
if (util::strieq_l("ip", optarg)) {
return FORWARDED_NODE_IP;
return ForwardedNode::IP;
}
if (optarg.size() < 2 || optarg[0] != '_') {
return -1;
return static_cast<ForwardedNode>(-1);
}
if (std::find_if_not(std::begin(optarg), std::end(optarg), [](char c) {
return util::is_alpha(c) || util::is_digit(c) || c == '.' || c == '_' ||
c == '-';
}) != std::end(optarg)) {
return -1;
return static_cast<ForwardedNode>(-1);
}
return FORWARDED_NODE_OBFUSCATED;
return ForwardedNode::OBFUSCATED;
}
} // namespace
......@@ -3387,7 +3387,7 @@ int parse_config(Config *config, int optid, const StringRef &opt,
case SHRPX_OPTID_FORWARDED_FOR: {
auto type = parse_forwarded_node_type(optarg);
if (type == -1 ||
if (type == static_cast<ForwardedNode>(-1) ||
(optid == SHRPX_OPTID_FORWARDED_FOR && optarg[0] == '_')) {
LOG(ERROR) << opt << ": unknown node type or illegal obfuscated string "
<< optarg;
......@@ -3398,7 +3398,7 @@ int parse_config(Config *config, int optid, const StringRef &opt,
switch (optid) {
case SHRPX_OPTID_FORWARDED_BY:
fwdconf.by_node_type = static_cast<shrpx_forwarded_node_type>(type);
fwdconf.by_node_type = type;
if (optarg[0] == '_') {
fwdconf.by_obfuscated = make_string_ref(config->balloc, optarg);
} else {
......@@ -3406,7 +3406,7 @@ int parse_config(Config *config, int optid, const StringRef &opt,
}
break;
case SHRPX_OPTID_FORWARDED_FOR:
fwdconf.for_node_type = static_cast<shrpx_forwarded_node_type>(type);
fwdconf.for_node_type = type;
break;
}
......
......@@ -409,9 +409,9 @@ enum shrpx_forwarded_param {
FORWARDED_PROTO = 0x8,
};
enum shrpx_forwarded_node_type {
FORWARDED_NODE_OBFUSCATED,
FORWARDED_NODE_IP,
enum class ForwardedNode {
OBFUSCATED,
IP,
};
struct AltSvc {
......@@ -704,10 +704,10 @@ struct HttpConfig {
uint32_t params;
// type of value recorded in "by" parameter of Forwarded header
// field.
shrpx_forwarded_node_type by_node_type;
ForwardedNode by_node_type;
// type of value recorded in "for" parameter of Forwarded header
// field.
shrpx_forwarded_node_type for_node_type;
ForwardedNode for_node_type;
bool strip_incoming;
} forwarded;
struct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment