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