diff --git a/src/h2load.cc b/src/h2load.cc index 14b1fca4..7966e8eb 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -1956,7 +1956,7 @@ int main(int argc, char **argv) { break; case 4: // npn-list option - config.npn_list = util::parse_config_str_list(optarg); + config.npn_list = util::parse_config_str_list(StringRef{optarg}); break; case 5: // rate-period @@ -1968,7 +1968,8 @@ int main(int argc, char **argv) { break; case 6: // --h1 - config.npn_list = util::parse_config_str_list("http/1.1"); + config.npn_list = + util::parse_config_str_list(StringRef::from_lit("http/1.1")); config.no_tls_proto = Config::PROTO_HTTP1_1; break; } @@ -1992,7 +1993,8 @@ int main(int argc, char **argv) { } if (config.npn_list.empty()) { - config.npn_list = util::parse_config_str_list(DEFAULT_NPN_LIST); + config.npn_list = + util::parse_config_str_list(StringRef::from_lit(DEFAULT_NPN_LIST)); } // serialize the APLN tokens diff --git a/src/shrpx.cc b/src/shrpx.cc index f02e21af..8da4fafe 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1115,7 +1115,8 @@ void fill_default_config() { auto &loggingconf = mod_config()->logging; { auto &accessconf = loggingconf.access; - accessconf.format = parse_log_format(DEFAULT_ACCESSLOG_FORMAT); + accessconf.format = + parse_log_format(StringRef::from_lit(DEFAULT_ACCESSLOG_FORMAT)); auto &errorconf = loggingconf.error; errorconf.file = "/dev/stderr"; @@ -1908,11 +1909,10 @@ Misc: } // namespace namespace { -void process_options( - int argc, char **argv, - std::vector> &cmdcfgs) { +void process_options(int argc, char **argv, + std::vector> &cmdcfgs) { if (conf_exists(get_config()->conf_path.c_str())) { - std::set include_set; + std::set include_set; if (load_config(get_config()->conf_path.c_str(), include_set) == -1) { LOG(FATAL) << "Failed to load configuration from " << get_config()->conf_path; @@ -1922,19 +1922,18 @@ void process_options( } if (argc - optind >= 2) { - cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_FILE, argv[optind++]); - cmdcfgs.emplace_back(SHRPX_OPT_CERTIFICATE_FILE, argv[optind++]); + cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_FILE, StringRef{argv[optind++]}); + cmdcfgs.emplace_back(SHRPX_OPT_CERTIFICATE_FILE, StringRef{argv[optind++]}); } // Reopen log files using configurations in file reopen_log_files(); { - std::set include_set; + std::set include_set; - for (size_t i = 0, len = cmdcfgs.size(); i < len; ++i) { - if (parse_config(cmdcfgs[i].first, cmdcfgs[i].second, include_set) == - -1) { + for (auto &p : cmdcfgs) { + if (parse_config(p.first, p.second, include_set) == -1) { LOG(FATAL) << "Failed to parse command-line argument."; exit(EXIT_FAILURE); } @@ -2024,11 +2023,12 @@ void process_options( auto &tlsconf = mod_config()->tls; if (tlsconf.npn_list.empty()) { - tlsconf.npn_list = util::parse_config_str_list(DEFAULT_NPN_LIST); + tlsconf.npn_list = + util::parse_config_str_list(StringRef::from_lit(DEFAULT_NPN_LIST)); } if (tlsconf.tls_proto_list.empty()) { - tlsconf.tls_proto_list = - util::parse_config_str_list(DEFAULT_TLS_PROTO_LIST); + tlsconf.tls_proto_list = util::parse_config_str_list( + StringRef::from_lit(DEFAULT_TLS_PROTO_LIST)); } tlsconf.tls_proto_mask = ssl::create_tls_proto_mask(tlsconf.tls_proto_list); @@ -2330,156 +2330,181 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } - std::vector> cmdcfgs; + std::vector> cmdcfgs; while (1) { static int flag = 0; static option long_options[] = { - {SHRPX_OPT_DAEMON, no_argument, nullptr, 'D'}, - {SHRPX_OPT_LOG_LEVEL, required_argument, nullptr, 'L'}, - {SHRPX_OPT_BACKEND, required_argument, nullptr, 'b'}, - {SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS, required_argument, nullptr, - 'c'}, - {SHRPX_OPT_FRONTEND, required_argument, nullptr, 'f'}, + {SHRPX_OPT_DAEMON.c_str(), no_argument, nullptr, 'D'}, + {SHRPX_OPT_LOG_LEVEL.c_str(), required_argument, nullptr, 'L'}, + {SHRPX_OPT_BACKEND.c_str(), required_argument, nullptr, 'b'}, + {SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS.c_str(), required_argument, + nullptr, 'c'}, + {SHRPX_OPT_FRONTEND.c_str(), required_argument, nullptr, 'f'}, {"help", no_argument, nullptr, 'h'}, - {SHRPX_OPT_INSECURE, no_argument, nullptr, 'k'}, - {SHRPX_OPT_WORKERS, required_argument, nullptr, 'n'}, - {SHRPX_OPT_CLIENT_PROXY, no_argument, nullptr, 'p'}, - {SHRPX_OPT_HTTP2_PROXY, no_argument, nullptr, 's'}, + {SHRPX_OPT_INSECURE.c_str(), no_argument, nullptr, 'k'}, + {SHRPX_OPT_WORKERS.c_str(), required_argument, nullptr, 'n'}, + {SHRPX_OPT_CLIENT_PROXY.c_str(), no_argument, nullptr, 'p'}, + {SHRPX_OPT_HTTP2_PROXY.c_str(), no_argument, nullptr, 's'}, {"version", no_argument, nullptr, 'v'}, - {SHRPX_OPT_FRONTEND_FRAME_DEBUG, no_argument, nullptr, 'o'}, - {SHRPX_OPT_ADD_X_FORWARDED_FOR, no_argument, &flag, 1}, - {SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT, required_argument, &flag, 2}, - {SHRPX_OPT_FRONTEND_READ_TIMEOUT, required_argument, &flag, 3}, - {SHRPX_OPT_FRONTEND_WRITE_TIMEOUT, required_argument, &flag, 4}, - {SHRPX_OPT_BACKEND_READ_TIMEOUT, required_argument, &flag, 5}, - {SHRPX_OPT_BACKEND_WRITE_TIMEOUT, required_argument, &flag, 6}, - {SHRPX_OPT_ACCESSLOG_FILE, required_argument, &flag, 7}, - {SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT, required_argument, &flag, 8}, - {SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS, required_argument, &flag, 9}, - {SHRPX_OPT_PID_FILE, required_argument, &flag, 10}, - {SHRPX_OPT_USER, required_argument, &flag, 11}, + {SHRPX_OPT_FRONTEND_FRAME_DEBUG.c_str(), no_argument, nullptr, 'o'}, + {SHRPX_OPT_ADD_X_FORWARDED_FOR.c_str(), no_argument, &flag, 1}, + {SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT.c_str(), required_argument, + &flag, 2}, + {SHRPX_OPT_FRONTEND_READ_TIMEOUT.c_str(), required_argument, &flag, 3}, + {SHRPX_OPT_FRONTEND_WRITE_TIMEOUT.c_str(), required_argument, &flag, 4}, + {SHRPX_OPT_BACKEND_READ_TIMEOUT.c_str(), required_argument, &flag, 5}, + {SHRPX_OPT_BACKEND_WRITE_TIMEOUT.c_str(), required_argument, &flag, 6}, + {SHRPX_OPT_ACCESSLOG_FILE.c_str(), required_argument, &flag, 7}, + {SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT.c_str(), required_argument, &flag, + 8}, + {SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS.c_str(), required_argument, &flag, + 9}, + {SHRPX_OPT_PID_FILE.c_str(), required_argument, &flag, 10}, + {SHRPX_OPT_USER.c_str(), required_argument, &flag, 11}, {"conf", required_argument, &flag, 12}, - {SHRPX_OPT_SYSLOG_FACILITY, required_argument, &flag, 14}, - {SHRPX_OPT_BACKLOG, required_argument, &flag, 15}, - {SHRPX_OPT_CIPHERS, required_argument, &flag, 16}, - {SHRPX_OPT_CLIENT, no_argument, &flag, 17}, - {SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS, required_argument, &flag, 18}, - {SHRPX_OPT_CACERT, required_argument, &flag, 19}, - {SHRPX_OPT_BACKEND_IPV4, no_argument, &flag, 20}, - {SHRPX_OPT_BACKEND_IPV6, no_argument, &flag, 21}, - {SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE, required_argument, &flag, 22}, - {SHRPX_OPT_NO_VIA, no_argument, &flag, 23}, - {SHRPX_OPT_SUBCERT, required_argument, &flag, 24}, - {SHRPX_OPT_HTTP2_BRIDGE, no_argument, &flag, 25}, - {SHRPX_OPT_BACKEND_HTTP_PROXY_URI, required_argument, &flag, 26}, - {SHRPX_OPT_BACKEND_NO_TLS, no_argument, &flag, 27}, - {SHRPX_OPT_FRONTEND_NO_TLS, no_argument, &flag, 29}, - {SHRPX_OPT_BACKEND_TLS_SNI_FIELD, required_argument, &flag, 31}, - {SHRPX_OPT_DH_PARAM_FILE, required_argument, &flag, 33}, - {SHRPX_OPT_READ_RATE, required_argument, &flag, 34}, - {SHRPX_OPT_READ_BURST, required_argument, &flag, 35}, - {SHRPX_OPT_WRITE_RATE, required_argument, &flag, 36}, - {SHRPX_OPT_WRITE_BURST, required_argument, &flag, 37}, - {SHRPX_OPT_NPN_LIST, required_argument, &flag, 38}, - {SHRPX_OPT_VERIFY_CLIENT, no_argument, &flag, 39}, - {SHRPX_OPT_VERIFY_CLIENT_CACERT, required_argument, &flag, 40}, - {SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE, required_argument, &flag, 41}, - {SHRPX_OPT_CLIENT_CERT_FILE, required_argument, &flag, 42}, - {SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER, required_argument, &flag, - 43}, - {SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER, required_argument, - &flag, 44}, - {SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING, no_argument, &flag, 45}, - {SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS, required_argument, - &flag, 46}, - {SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS, required_argument, - &flag, 47}, - {SHRPX_OPT_TLS_PROTO_LIST, required_argument, &flag, 48}, - {SHRPX_OPT_PADDING, required_argument, &flag, 49}, - {SHRPX_OPT_WORKER_READ_RATE, required_argument, &flag, 50}, - {SHRPX_OPT_WORKER_READ_BURST, required_argument, &flag, 51}, - {SHRPX_OPT_WORKER_WRITE_RATE, required_argument, &flag, 52}, - {SHRPX_OPT_WORKER_WRITE_BURST, required_argument, &flag, 53}, - {SHRPX_OPT_ALTSVC, required_argument, &flag, 54}, - {SHRPX_OPT_ADD_RESPONSE_HEADER, required_argument, &flag, 55}, - {SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS, required_argument, &flag, 56}, - {SHRPX_OPT_ACCESSLOG_SYSLOG, no_argument, &flag, 57}, - {SHRPX_OPT_ERRORLOG_FILE, required_argument, &flag, 58}, - {SHRPX_OPT_ERRORLOG_SYSLOG, no_argument, &flag, 59}, - {SHRPX_OPT_STREAM_READ_TIMEOUT, required_argument, &flag, 60}, - {SHRPX_OPT_STREAM_WRITE_TIMEOUT, required_argument, &flag, 61}, - {SHRPX_OPT_NO_LOCATION_REWRITE, no_argument, &flag, 62}, - {SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_HOST, required_argument, &flag, - 63}, - {SHRPX_OPT_LISTENER_DISABLE_TIMEOUT, required_argument, &flag, 64}, - {SHRPX_OPT_STRIP_INCOMING_X_FORWARDED_FOR, no_argument, &flag, 65}, - {SHRPX_OPT_ACCESSLOG_FORMAT, required_argument, &flag, 66}, - {SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND, required_argument, - &flag, 67}, - {SHRPX_OPT_TLS_TICKET_KEY_FILE, required_argument, &flag, 68}, - {SHRPX_OPT_RLIMIT_NOFILE, required_argument, &flag, 69}, - {SHRPX_OPT_BACKEND_RESPONSE_BUFFER, required_argument, &flag, 71}, - {SHRPX_OPT_BACKEND_REQUEST_BUFFER, required_argument, &flag, 72}, - {SHRPX_OPT_NO_HOST_REWRITE, no_argument, &flag, 73}, - {SHRPX_OPT_NO_SERVER_PUSH, no_argument, &flag, 74}, - {SHRPX_OPT_BACKEND_HTTP2_CONNECTIONS_PER_WORKER, required_argument, - &flag, 76}, - {SHRPX_OPT_FETCH_OCSP_RESPONSE_FILE, required_argument, &flag, 77}, - {SHRPX_OPT_OCSP_UPDATE_INTERVAL, required_argument, &flag, 78}, - {SHRPX_OPT_NO_OCSP, no_argument, &flag, 79}, - {SHRPX_OPT_HEADER_FIELD_BUFFER, required_argument, &flag, 80}, - {SHRPX_OPT_MAX_HEADER_FIELDS, required_argument, &flag, 81}, - {SHRPX_OPT_ADD_REQUEST_HEADER, required_argument, &flag, 82}, - {SHRPX_OPT_INCLUDE, required_argument, &flag, 83}, - {SHRPX_OPT_TLS_TICKET_KEY_CIPHER, required_argument, &flag, 84}, - {SHRPX_OPT_HOST_REWRITE, no_argument, &flag, 85}, - {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED, required_argument, &flag, 86}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED, required_argument, &flag, 87}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_INTERVAL, required_argument, &flag, - 88}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_RETRY, required_argument, &flag, - 89}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_FAIL, required_argument, &flag, - 90}, - {SHRPX_OPT_MRUBY_FILE, required_argument, &flag, 91}, - {SHRPX_OPT_ACCEPT_PROXY_PROTOCOL, no_argument, &flag, 93}, - {SHRPX_OPT_FASTOPEN, required_argument, &flag, 94}, - {SHRPX_OPT_TLS_DYN_REC_WARMUP_THRESHOLD, required_argument, &flag, 95}, - {SHRPX_OPT_TLS_DYN_REC_IDLE_TIMEOUT, required_argument, &flag, 96}, - {SHRPX_OPT_ADD_FORWARDED, required_argument, &flag, 97}, - {SHRPX_OPT_STRIP_INCOMING_FORWARDED, no_argument, &flag, 98}, - {SHRPX_OPT_FORWARDED_BY, required_argument, &flag, 99}, - {SHRPX_OPT_FORWARDED_FOR, required_argument, &flag, 100}, - {SHRPX_OPT_RESPONSE_HEADER_FIELD_BUFFER, required_argument, &flag, 101}, - {SHRPX_OPT_MAX_RESPONSE_HEADER_FIELDS, required_argument, &flag, 102}, - {SHRPX_OPT_NO_HTTP2_CIPHER_BLACK_LIST, no_argument, &flag, 103}, - {SHRPX_OPT_REQUEST_HEADER_FIELD_BUFFER, required_argument, &flag, 104}, - {SHRPX_OPT_MAX_REQUEST_HEADER_FIELDS, required_argument, &flag, 105}, - {SHRPX_OPT_BACKEND_HTTP1_TLS, no_argument, &flag, 106}, - {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_TLS, no_argument, &flag, 108}, - {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE, required_argument, - &flag, 109}, - {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE, + {SHRPX_OPT_SYSLOG_FACILITY.c_str(), required_argument, &flag, 14}, + {SHRPX_OPT_BACKLOG.c_str(), required_argument, &flag, 15}, + {SHRPX_OPT_CIPHERS.c_str(), required_argument, &flag, 16}, + {SHRPX_OPT_CLIENT.c_str(), no_argument, &flag, 17}, + {SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS.c_str(), required_argument, &flag, + 18}, + {SHRPX_OPT_CACERT.c_str(), required_argument, &flag, 19}, + {SHRPX_OPT_BACKEND_IPV4.c_str(), no_argument, &flag, 20}, + {SHRPX_OPT_BACKEND_IPV6.c_str(), no_argument, &flag, 21}, + {SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE.c_str(), required_argument, &flag, + 22}, + {SHRPX_OPT_NO_VIA.c_str(), no_argument, &flag, 23}, + {SHRPX_OPT_SUBCERT.c_str(), required_argument, &flag, 24}, + {SHRPX_OPT_HTTP2_BRIDGE.c_str(), no_argument, &flag, 25}, + {SHRPX_OPT_BACKEND_HTTP_PROXY_URI.c_str(), required_argument, &flag, + 26}, + {SHRPX_OPT_BACKEND_NO_TLS.c_str(), no_argument, &flag, 27}, + {SHRPX_OPT_FRONTEND_NO_TLS.c_str(), no_argument, &flag, 29}, + {SHRPX_OPT_BACKEND_TLS_SNI_FIELD.c_str(), required_argument, &flag, 31}, + {SHRPX_OPT_DH_PARAM_FILE.c_str(), required_argument, &flag, 33}, + {SHRPX_OPT_READ_RATE.c_str(), required_argument, &flag, 34}, + {SHRPX_OPT_READ_BURST.c_str(), required_argument, &flag, 35}, + {SHRPX_OPT_WRITE_RATE.c_str(), required_argument, &flag, 36}, + {SHRPX_OPT_WRITE_BURST.c_str(), required_argument, &flag, 37}, + {SHRPX_OPT_NPN_LIST.c_str(), required_argument, &flag, 38}, + {SHRPX_OPT_VERIFY_CLIENT.c_str(), no_argument, &flag, 39}, + {SHRPX_OPT_VERIFY_CLIENT_CACERT.c_str(), required_argument, &flag, 40}, + {SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE.c_str(), required_argument, &flag, + 41}, + {SHRPX_OPT_CLIENT_CERT_FILE.c_str(), required_argument, &flag, 42}, + {SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER.c_str(), + required_argument, &flag, 43}, + {SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER.c_str(), + required_argument, &flag, 44}, + {SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING.c_str(), no_argument, &flag, 45}, + {SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS.c_str(), + required_argument, &flag, 46}, + {SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS.c_str(), + required_argument, &flag, 47}, + {SHRPX_OPT_TLS_PROTO_LIST.c_str(), required_argument, &flag, 48}, + {SHRPX_OPT_PADDING.c_str(), required_argument, &flag, 49}, + {SHRPX_OPT_WORKER_READ_RATE.c_str(), required_argument, &flag, 50}, + {SHRPX_OPT_WORKER_READ_BURST.c_str(), required_argument, &flag, 51}, + {SHRPX_OPT_WORKER_WRITE_RATE.c_str(), required_argument, &flag, 52}, + {SHRPX_OPT_WORKER_WRITE_BURST.c_str(), required_argument, &flag, 53}, + {SHRPX_OPT_ALTSVC.c_str(), required_argument, &flag, 54}, + {SHRPX_OPT_ADD_RESPONSE_HEADER.c_str(), required_argument, &flag, 55}, + {SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS.c_str(), required_argument, + &flag, 56}, + {SHRPX_OPT_ACCESSLOG_SYSLOG.c_str(), no_argument, &flag, 57}, + {SHRPX_OPT_ERRORLOG_FILE.c_str(), required_argument, &flag, 58}, + {SHRPX_OPT_ERRORLOG_SYSLOG.c_str(), no_argument, &flag, 59}, + {SHRPX_OPT_STREAM_READ_TIMEOUT.c_str(), required_argument, &flag, 60}, + {SHRPX_OPT_STREAM_WRITE_TIMEOUT.c_str(), required_argument, &flag, 61}, + {SHRPX_OPT_NO_LOCATION_REWRITE.c_str(), no_argument, &flag, 62}, + {SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_HOST.c_str(), + required_argument, &flag, 63}, + {SHRPX_OPT_LISTENER_DISABLE_TIMEOUT.c_str(), required_argument, &flag, + 64}, + {SHRPX_OPT_STRIP_INCOMING_X_FORWARDED_FOR.c_str(), no_argument, &flag, + 65}, + {SHRPX_OPT_ACCESSLOG_FORMAT.c_str(), required_argument, &flag, 66}, + {SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND.c_str(), + required_argument, &flag, 67}, + {SHRPX_OPT_TLS_TICKET_KEY_FILE.c_str(), required_argument, &flag, 68}, + {SHRPX_OPT_RLIMIT_NOFILE.c_str(), required_argument, &flag, 69}, + {SHRPX_OPT_BACKEND_RESPONSE_BUFFER.c_str(), required_argument, &flag, + 71}, + {SHRPX_OPT_BACKEND_REQUEST_BUFFER.c_str(), required_argument, &flag, + 72}, + {SHRPX_OPT_NO_HOST_REWRITE.c_str(), no_argument, &flag, 73}, + {SHRPX_OPT_NO_SERVER_PUSH.c_str(), no_argument, &flag, 74}, + {SHRPX_OPT_BACKEND_HTTP2_CONNECTIONS_PER_WORKER.c_str(), + required_argument, &flag, 76}, + {SHRPX_OPT_FETCH_OCSP_RESPONSE_FILE.c_str(), required_argument, &flag, + 77}, + {SHRPX_OPT_OCSP_UPDATE_INTERVAL.c_str(), required_argument, &flag, 78}, + {SHRPX_OPT_NO_OCSP.c_str(), no_argument, &flag, 79}, + {SHRPX_OPT_HEADER_FIELD_BUFFER.c_str(), required_argument, &flag, 80}, + {SHRPX_OPT_MAX_HEADER_FIELDS.c_str(), required_argument, &flag, 81}, + {SHRPX_OPT_ADD_REQUEST_HEADER.c_str(), required_argument, &flag, 82}, + {SHRPX_OPT_INCLUDE.c_str(), required_argument, &flag, 83}, + {SHRPX_OPT_TLS_TICKET_KEY_CIPHER.c_str(), required_argument, &flag, 84}, + {SHRPX_OPT_HOST_REWRITE.c_str(), no_argument, &flag, 85}, + {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED.c_str(), required_argument, + &flag, 86}, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED.c_str(), required_argument, &flag, + 87}, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_INTERVAL.c_str(), required_argument, + &flag, 88}, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_RETRY.c_str(), + required_argument, &flag, 89}, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_FAIL.c_str(), required_argument, + &flag, 90}, + {SHRPX_OPT_MRUBY_FILE.c_str(), required_argument, &flag, 91}, + {SHRPX_OPT_ACCEPT_PROXY_PROTOCOL.c_str(), no_argument, &flag, 93}, + {SHRPX_OPT_FASTOPEN.c_str(), required_argument, &flag, 94}, + {SHRPX_OPT_TLS_DYN_REC_WARMUP_THRESHOLD.c_str(), required_argument, + &flag, 95}, + {SHRPX_OPT_TLS_DYN_REC_IDLE_TIMEOUT.c_str(), required_argument, &flag, + 96}, + {SHRPX_OPT_ADD_FORWARDED.c_str(), required_argument, &flag, 97}, + {SHRPX_OPT_STRIP_INCOMING_FORWARDED.c_str(), no_argument, &flag, 98}, + {SHRPX_OPT_FORWARDED_BY.c_str(), required_argument, &flag, 99}, + {SHRPX_OPT_FORWARDED_FOR.c_str(), required_argument, &flag, 100}, + {SHRPX_OPT_RESPONSE_HEADER_FIELD_BUFFER.c_str(), required_argument, + &flag, 101}, + {SHRPX_OPT_MAX_RESPONSE_HEADER_FIELDS.c_str(), required_argument, &flag, + 102}, + {SHRPX_OPT_NO_HTTP2_CIPHER_BLACK_LIST.c_str(), no_argument, &flag, 103}, + {SHRPX_OPT_REQUEST_HEADER_FIELD_BUFFER.c_str(), required_argument, + &flag, 104}, + {SHRPX_OPT_MAX_REQUEST_HEADER_FIELDS.c_str(), required_argument, &flag, + 105}, + {SHRPX_OPT_BACKEND_HTTP1_TLS.c_str(), no_argument, &flag, 106}, + {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_TLS.c_str(), no_argument, &flag, + 108}, + {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE.c_str(), + required_argument, &flag, 109}, + {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE.c_str(), required_argument, &flag, 110}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_TLS, no_argument, &flag, 111}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_CERT_FILE, required_argument, &flag, - 112}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE, required_argument, - &flag, 113}, - {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY, required_argument, - &flag, 114}, - {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_TLS.c_str(), no_argument, &flag, + 111}, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_CERT_FILE.c_str(), + required_argument, &flag, 112}, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE.c_str(), + required_argument, &flag, 113}, + {SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY.c_str(), + required_argument, &flag, 114}, + {SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY.c_str(), required_argument, &flag, 115}, - {SHRPX_OPT_BACKEND_ADDRESS_FAMILY, required_argument, &flag, 116}, - {SHRPX_OPT_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS, required_argument, - &flag, 117}, - {SHRPX_OPT_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS, required_argument, - &flag, 118}, - {SHRPX_OPT_BACKEND_CONNECTIONS_PER_FRONTEND, required_argument, &flag, - 119}, - {SHRPX_OPT_BACKEND_TLS, no_argument, &flag, 120}, - {SHRPX_OPT_BACKEND_CONNECTIONS_PER_HOST, required_argument, &flag, 121}, - {SHRPX_OPT_ERROR_PAGE, required_argument, &flag, 122}, + {SHRPX_OPT_BACKEND_ADDRESS_FAMILY.c_str(), required_argument, &flag, + 116}, + {SHRPX_OPT_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS.c_str(), + required_argument, &flag, 117}, + {SHRPX_OPT_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS.c_str(), + required_argument, &flag, 118}, + {SHRPX_OPT_BACKEND_CONNECTIONS_PER_FRONTEND.c_str(), required_argument, + &flag, 119}, + {SHRPX_OPT_BACKEND_TLS.c_str(), no_argument, &flag, 120}, + {SHRPX_OPT_BACKEND_CONNECTIONS_PER_HOST.c_str(), required_argument, + &flag, 121}, + {SHRPX_OPT_ERROR_PAGE.c_str(), required_argument, &flag, 122}, {nullptr, 0, nullptr, 0}}; int option_index = 0; @@ -2490,37 +2515,39 @@ int main(int argc, char **argv) { } switch (c) { case 'D': - cmdcfgs.emplace_back(SHRPX_OPT_DAEMON, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_DAEMON, StringRef::from_lit("yes")); break; case 'L': - cmdcfgs.emplace_back(SHRPX_OPT_LOG_LEVEL, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_LOG_LEVEL, StringRef{optarg}); break; case 'b': - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND, StringRef{optarg}); break; case 'c': - cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS, + StringRef{optarg}); break; case 'f': - cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND, StringRef{optarg}); break; case 'h': print_help(std::cout); exit(EXIT_SUCCESS); case 'k': - cmdcfgs.emplace_back(SHRPX_OPT_INSECURE, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_INSECURE, StringRef::from_lit("yes")); break; case 'n': - cmdcfgs.emplace_back(SHRPX_OPT_WORKERS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WORKERS, StringRef{optarg}); break; case 'o': - cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_FRAME_DEBUG, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_FRAME_DEBUG, + StringRef::from_lit("yes")); break; case 'p': - cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PROXY, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PROXY, StringRef::from_lit("yes")); break; case 's': - cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_PROXY, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_PROXY, StringRef::from_lit("yes")); break; case 'v': print_version(std::cout); @@ -2532,44 +2559,51 @@ int main(int argc, char **argv) { switch (flag) { case 1: // --add-x-forwarded-for - cmdcfgs.emplace_back(SHRPX_OPT_ADD_X_FORWARDED_FOR, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_ADD_X_FORWARDED_FOR, + StringRef::from_lit("yes")); break; case 2: // --frontend-http2-read-timeout - cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT, + StringRef{optarg}); break; case 3: // --frontend-read-timeout - cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_READ_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_READ_TIMEOUT, + StringRef{optarg}); break; case 4: // --frontend-write-timeout - cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_WRITE_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_WRITE_TIMEOUT, + StringRef{optarg}); break; case 5: // --backend-read-timeout - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_READ_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_READ_TIMEOUT, StringRef{optarg}); break; case 6: // --backend-write-timeout - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_WRITE_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_WRITE_TIMEOUT, + StringRef{optarg}); break; case 7: - cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_FILE, StringRef{optarg}); break; case 8: // --backend-keep-alive-timeout - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT, + StringRef{optarg}); break; case 9: // --frontend-http2-window-bits - cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS, + StringRef{optarg}); break; case 10: - cmdcfgs.emplace_back(SHRPX_OPT_PID_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_PID_FILE, StringRef{optarg}); break; case 11: - cmdcfgs.emplace_back(SHRPX_OPT_USER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_USER, StringRef{optarg}); break; case 12: // --conf @@ -2577,430 +2611,474 @@ int main(int argc, char **argv) { break; case 14: // --syslog-facility - cmdcfgs.emplace_back(SHRPX_OPT_SYSLOG_FACILITY, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_SYSLOG_FACILITY, StringRef{optarg}); break; case 15: // --backlog - cmdcfgs.emplace_back(SHRPX_OPT_BACKLOG, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKLOG, StringRef{optarg}); break; case 16: // --ciphers - cmdcfgs.emplace_back(SHRPX_OPT_CIPHERS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_CIPHERS, StringRef{optarg}); break; case 17: // --client - cmdcfgs.emplace_back(SHRPX_OPT_CLIENT, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_CLIENT, StringRef::from_lit("yes")); break; case 18: // --backend-http2-window-bits - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS, + StringRef{optarg}); break; case 19: // --cacert - cmdcfgs.emplace_back(SHRPX_OPT_CACERT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_CACERT, StringRef{optarg}); break; case 20: // --backend-ipv4 - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV4, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV4, + StringRef::from_lit("yes")); break; case 21: // --backend-ipv6 - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV6, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV6, + StringRef::from_lit("yes")); break; case 22: // --private-key-passwd-file - cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE, + StringRef{optarg}); break; case 23: // --no-via - cmdcfgs.emplace_back(SHRPX_OPT_NO_VIA, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_NO_VIA, StringRef::from_lit("yes")); break; case 24: // --subcert - cmdcfgs.emplace_back(SHRPX_OPT_SUBCERT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_SUBCERT, StringRef{optarg}); break; case 25: // --http2-bridge - cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_BRIDGE, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_BRIDGE, + StringRef::from_lit("yes")); break; case 26: // --backend-http-proxy-uri - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP_PROXY_URI, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP_PROXY_URI, + StringRef{optarg}); break; case 27: // --backend-no-tls - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_NO_TLS, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_NO_TLS, + StringRef::from_lit("yes")); break; case 29: // --frontend-no-tls - cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_NO_TLS, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_NO_TLS, + StringRef::from_lit("yes")); break; case 31: // --backend-tls-sni-field - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_TLS_SNI_FIELD, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_TLS_SNI_FIELD, + StringRef{optarg}); break; case 33: // --dh-param-file - cmdcfgs.emplace_back(SHRPX_OPT_DH_PARAM_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_DH_PARAM_FILE, StringRef{optarg}); break; case 34: // --read-rate - cmdcfgs.emplace_back(SHRPX_OPT_READ_RATE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_READ_RATE, StringRef{optarg}); break; case 35: // --read-burst - cmdcfgs.emplace_back(SHRPX_OPT_READ_BURST, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_READ_BURST, StringRef{optarg}); break; case 36: // --write-rate - cmdcfgs.emplace_back(SHRPX_OPT_WRITE_RATE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WRITE_RATE, StringRef{optarg}); break; case 37: // --write-burst - cmdcfgs.emplace_back(SHRPX_OPT_WRITE_BURST, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WRITE_BURST, StringRef{optarg}); break; case 38: // --npn-list - cmdcfgs.emplace_back(SHRPX_OPT_NPN_LIST, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_NPN_LIST, StringRef{optarg}); break; case 39: // --verify-client - cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT, + StringRef::from_lit("yes")); break; case 40: // --verify-client-cacert - cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT_CACERT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT_CACERT, StringRef{optarg}); break; case 41: // --client-private-key-file - cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE, + StringRef{optarg}); break; case 42: // --client-cert-file - cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_CERT_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_CERT_FILE, StringRef{optarg}); break; case 43: // --frontend-http2-dump-request-header cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER, - optarg); + StringRef{optarg}); break; case 44: // --frontend-http2-dump-response-header cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER, - optarg); + StringRef{optarg}); break; case 45: // --http2-no-cookie-crumbling - cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING, + StringRef::from_lit("yes")); break; case 46: // --frontend-http2-connection-window-bits cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS, - optarg); + StringRef{optarg}); break; case 47: // --backend-http2-connection-window-bits cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS, - optarg); + StringRef{optarg}); break; case 48: // --tls-proto-list - cmdcfgs.emplace_back(SHRPX_OPT_TLS_PROTO_LIST, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_PROTO_LIST, StringRef{optarg}); break; case 49: // --padding - cmdcfgs.emplace_back(SHRPX_OPT_PADDING, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_PADDING, StringRef{optarg}); break; case 50: // --worker-read-rate - cmdcfgs.emplace_back(SHRPX_OPT_WORKER_READ_RATE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WORKER_READ_RATE, StringRef{optarg}); break; case 51: // --worker-read-burst - cmdcfgs.emplace_back(SHRPX_OPT_WORKER_READ_BURST, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WORKER_READ_BURST, StringRef{optarg}); break; case 52: // --worker-write-rate - cmdcfgs.emplace_back(SHRPX_OPT_WORKER_WRITE_RATE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WORKER_WRITE_RATE, StringRef{optarg}); break; case 53: // --worker-write-burst - cmdcfgs.emplace_back(SHRPX_OPT_WORKER_WRITE_BURST, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WORKER_WRITE_BURST, StringRef{optarg}); break; case 54: // --altsvc - cmdcfgs.emplace_back(SHRPX_OPT_ALTSVC, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ALTSVC, StringRef{optarg}); break; case 55: // --add-response-header - cmdcfgs.emplace_back(SHRPX_OPT_ADD_RESPONSE_HEADER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ADD_RESPONSE_HEADER, StringRef{optarg}); break; case 56: // --worker-frontend-connections - cmdcfgs.emplace_back(SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS, + StringRef{optarg}); break; case 57: // --accesslog-syslog - cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_SYSLOG, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_SYSLOG, + StringRef::from_lit("yes")); break; case 58: // --errorlog-file - cmdcfgs.emplace_back(SHRPX_OPT_ERRORLOG_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ERRORLOG_FILE, StringRef{optarg}); break; case 59: // --errorlog-syslog - cmdcfgs.emplace_back(SHRPX_OPT_ERRORLOG_SYSLOG, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_ERRORLOG_SYSLOG, + StringRef::from_lit("yes")); break; case 60: // --stream-read-timeout - cmdcfgs.emplace_back(SHRPX_OPT_STREAM_READ_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_STREAM_READ_TIMEOUT, StringRef{optarg}); break; case 61: // --stream-write-timeout - cmdcfgs.emplace_back(SHRPX_OPT_STREAM_WRITE_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_STREAM_WRITE_TIMEOUT, StringRef{optarg}); break; case 62: // --no-location-rewrite - cmdcfgs.emplace_back(SHRPX_OPT_NO_LOCATION_REWRITE, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_NO_LOCATION_REWRITE, + StringRef::from_lit("yes")); break; case 63: // --backend-http1-connections-per-host cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_HOST, - optarg); + StringRef{optarg}); break; case 64: // --listener-disable-timeout - cmdcfgs.emplace_back(SHRPX_OPT_LISTENER_DISABLE_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_LISTENER_DISABLE_TIMEOUT, + StringRef{optarg}); break; case 65: // --strip-incoming-x-forwarded-for - cmdcfgs.emplace_back(SHRPX_OPT_STRIP_INCOMING_X_FORWARDED_FOR, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_STRIP_INCOMING_X_FORWARDED_FOR, + StringRef::from_lit("yes")); break; case 66: // --accesslog-format - cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_FORMAT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG_FORMAT, StringRef{optarg}); break; case 67: // --backend-http1-connections-per-frontend cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND, - optarg); + StringRef{optarg}); break; case 68: // --tls-ticket-key-file - cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_FILE, StringRef{optarg}); break; case 69: // --rlimit-nofile - cmdcfgs.emplace_back(SHRPX_OPT_RLIMIT_NOFILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_RLIMIT_NOFILE, StringRef{optarg}); break; case 71: // --backend-response-buffer - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_RESPONSE_BUFFER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_RESPONSE_BUFFER, + StringRef{optarg}); break; case 72: // --backend-request-buffer - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_REQUEST_BUFFER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_REQUEST_BUFFER, + StringRef{optarg}); break; case 73: // --no-host-rewrite - cmdcfgs.emplace_back(SHRPX_OPT_NO_HOST_REWRITE, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_NO_HOST_REWRITE, + StringRef::from_lit("yes")); break; case 74: // --no-server-push - cmdcfgs.emplace_back(SHRPX_OPT_NO_SERVER_PUSH, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_NO_SERVER_PUSH, + StringRef::from_lit("yes")); break; case 76: // --backend-http2-connections-per-worker cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_CONNECTIONS_PER_WORKER, - optarg); + StringRef{optarg}); break; case 77: // --fetch-ocsp-response-file - cmdcfgs.emplace_back(SHRPX_OPT_FETCH_OCSP_RESPONSE_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FETCH_OCSP_RESPONSE_FILE, + StringRef{optarg}); break; case 78: // --ocsp-update-interval - cmdcfgs.emplace_back(SHRPX_OPT_OCSP_UPDATE_INTERVAL, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_OCSP_UPDATE_INTERVAL, StringRef{optarg}); break; case 79: // --no-ocsp - cmdcfgs.emplace_back(SHRPX_OPT_NO_OCSP, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_NO_OCSP, StringRef::from_lit("yes")); break; case 80: // --header-field-buffer - cmdcfgs.emplace_back(SHRPX_OPT_HEADER_FIELD_BUFFER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_HEADER_FIELD_BUFFER, StringRef{optarg}); break; case 81: // --max-header-fields - cmdcfgs.emplace_back(SHRPX_OPT_MAX_HEADER_FIELDS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_MAX_HEADER_FIELDS, StringRef{optarg}); break; case 82: // --add-request-header - cmdcfgs.emplace_back(SHRPX_OPT_ADD_REQUEST_HEADER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ADD_REQUEST_HEADER, StringRef{optarg}); break; case 83: // --include - cmdcfgs.emplace_back(SHRPX_OPT_INCLUDE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_INCLUDE, StringRef{optarg}); break; case 84: // --tls-ticket-key-cipher - cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_CIPHER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_CIPHER, + StringRef{optarg}); break; case 85: // --host-rewrite - cmdcfgs.emplace_back(SHRPX_OPT_HOST_REWRITE, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_HOST_REWRITE, + StringRef::from_lit("yes")); break; case 86: // --tls-session-cache-memcached - cmdcfgs.emplace_back(SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED, + StringRef{optarg}); break; case 87: // --tls-ticket-key-memcached - cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED, + StringRef{optarg}); break; case 88: // --tls-ticket-key-memcached-interval cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_INTERVAL, - optarg); + StringRef{optarg}); break; case 89: // --tls-ticket-key-memcached-max-retry cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_RETRY, - optarg); + StringRef{optarg}); break; case 90: // --tls-ticket-key-memcached-max-fail cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_FAIL, - optarg); + StringRef{optarg}); break; case 91: // --mruby-file - cmdcfgs.emplace_back(SHRPX_OPT_MRUBY_FILE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_MRUBY_FILE, StringRef{optarg}); break; case 93: // --accept-proxy-protocol - cmdcfgs.emplace_back(SHRPX_OPT_ACCEPT_PROXY_PROTOCOL, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_ACCEPT_PROXY_PROTOCOL, + StringRef::from_lit("yes")); break; case 94: // --fastopen - cmdcfgs.emplace_back(SHRPX_OPT_FASTOPEN, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FASTOPEN, StringRef{optarg}); break; case 95: // --tls-dyn-rec-warmup-threshold - cmdcfgs.emplace_back(SHRPX_OPT_TLS_DYN_REC_WARMUP_THRESHOLD, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_DYN_REC_WARMUP_THRESHOLD, + StringRef{optarg}); break; case 96: // --tls-dyn-rec-idle-timeout - cmdcfgs.emplace_back(SHRPX_OPT_TLS_DYN_REC_IDLE_TIMEOUT, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_DYN_REC_IDLE_TIMEOUT, + StringRef{optarg}); break; case 97: // --add-forwarded - cmdcfgs.emplace_back(SHRPX_OPT_ADD_FORWARDED, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ADD_FORWARDED, StringRef{optarg}); break; case 98: // --strip-incoming-forwarded - cmdcfgs.emplace_back(SHRPX_OPT_STRIP_INCOMING_FORWARDED, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_STRIP_INCOMING_FORWARDED, + StringRef::from_lit("yes")); break; case 99: // --forwarded-by - cmdcfgs.emplace_back(SHRPX_OPT_FORWARDED_BY, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FORWARDED_BY, StringRef{optarg}); break; case 100: // --forwarded-for - cmdcfgs.emplace_back(SHRPX_OPT_FORWARDED_FOR, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_FORWARDED_FOR, StringRef{optarg}); break; case 101: // --response-header-field-buffer - cmdcfgs.emplace_back(SHRPX_OPT_RESPONSE_HEADER_FIELD_BUFFER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_RESPONSE_HEADER_FIELD_BUFFER, + StringRef{optarg}); break; case 102: // --max-response-header-fields - cmdcfgs.emplace_back(SHRPX_OPT_MAX_RESPONSE_HEADER_FIELDS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_MAX_RESPONSE_HEADER_FIELDS, + StringRef{optarg}); break; case 103: // --no-http2-cipher-black-list - cmdcfgs.emplace_back(SHRPX_OPT_NO_HTTP2_CIPHER_BLACK_LIST, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_NO_HTTP2_CIPHER_BLACK_LIST, + StringRef::from_lit("yes")); break; case 104: // --request-header-field-buffer - cmdcfgs.emplace_back(SHRPX_OPT_REQUEST_HEADER_FIELD_BUFFER, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_REQUEST_HEADER_FIELD_BUFFER, + StringRef{optarg}); break; case 105: // --max-request-header-fields - cmdcfgs.emplace_back(SHRPX_OPT_MAX_REQUEST_HEADER_FIELDS, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_MAX_REQUEST_HEADER_FIELDS, + StringRef{optarg}); break; case 106: // --backend-http1-tls - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP1_TLS, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP1_TLS, + StringRef::from_lit("yes")); break; case 108: // --tls-session-cache-memcached-tls - cmdcfgs.emplace_back(SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_TLS, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_TLS, + StringRef::from_lit("yes")); break; case 109: // --tls-session-cache-memcached-cert-file cmdcfgs.emplace_back(SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE, - optarg); + StringRef{optarg}); break; case 110: // --tls-session-cache-memcached-private-key-file cmdcfgs.emplace_back( - SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE, optarg); + SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE, + StringRef{optarg}); break; case 111: // --tls-ticket-key-memcached-tls - cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_TLS, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_TLS, + StringRef::from_lit("yes")); break; case 112: // --tls-ticket-key-memcached-cert-file cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_CERT_FILE, - optarg); + StringRef{optarg}); break; case 113: // --tls-ticket-key-memcached-private-key-file cmdcfgs.emplace_back( - SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE, optarg); + SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE, + StringRef{optarg}); break; case 114: // --tls-ticket-key-memcached-address-family cmdcfgs.emplace_back(SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY, - optarg); + StringRef{optarg}); break; case 115: // --tls-session-cache-memcached-address-family cmdcfgs.emplace_back( - SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY, optarg); + SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY, + StringRef{optarg}); break; case 116: // --backend-address-family - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_ADDRESS_FAMILY, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_ADDRESS_FAMILY, + StringRef{optarg}); break; case 117: // --frontend-http2-max-concurrent-streams cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS, - optarg); + StringRef{optarg}); break; case 118: // --backend-http2-max-concurrent-streams cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS, - optarg); + StringRef{optarg}); break; case 119: // --backend-connections-per-frontend cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_CONNECTIONS_PER_FRONTEND, - optarg); + StringRef{optarg}); break; case 120: // --backend-tls - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_TLS, "yes"); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_TLS, StringRef::from_lit("yes")); break; case 121: // --backend-connections-per-host - cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_CONNECTIONS_PER_HOST, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_CONNECTIONS_PER_HOST, + StringRef{optarg}); break; case 122: // --error-page - cmdcfgs.emplace_back(SHRPX_OPT_ERROR_PAGE, optarg); + cmdcfgs.emplace_back(SHRPX_OPT_ERROR_PAGE, StringRef{optarg}); break; default: break; diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 7f329b04..9ba424f5 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -78,7 +78,7 @@ TicketKeys::~TicketKeys() { namespace { int split_host_port(char *host, size_t hostlen, uint16_t *port_ptr, - const StringRef &hostport, const char *opt) { + const StringRef &hostport, const StringRef &opt) { // host and port in |hostport| is separated by single ','. auto sep = std::find(std::begin(hostport), std::end(hostport), ','); if (sep == std::end(hostport)) { @@ -106,9 +106,9 @@ int split_host_port(char *host, size_t hostlen, uint16_t *port_ptr, } // namespace namespace { -bool is_secure(const char *filename) { +bool is_secure(const StringRef &filename) { struct stat buf; - int rv = stat(filename, &buf); + int rv = stat(filename.c_str(), &buf); if (rv == 0) { if ((buf.st_mode & S_IRWXU) && !(buf.st_mode & S_IRWXG) && !(buf.st_mode & S_IRWXO)) { @@ -219,29 +219,33 @@ FILE *open_file_for_write(const char *filename) { return f; } -std::string read_passwd_from_file(const char *filename) { +namespace { +// Read passwd from |filename| +std::string read_passwd_from_file(const StringRef &opt, + const StringRef &filename) { std::string line; if (!is_secure(filename)) { - LOG(ERROR) << "Private key passwd file " << filename + LOG(ERROR) << opt << ": Private key passwd file " << filename << " has insecure mode."; return line; } - std::ifstream in(filename, std::ios::binary); + std::ifstream in(filename.c_str(), std::ios::binary); if (!in) { - LOG(ERROR) << "Could not open key passwd file " << filename; + LOG(ERROR) << opt << ": Could not open key passwd file " << filename; return line; } std::getline(in, line); return line; } +} // namespace -Headers::value_type parse_header(const char *optarg) { - const auto *colon = strchr(optarg, ':'); +Headers::value_type parse_header(const StringRef &optarg) { + auto colon = std::find(std::begin(optarg), std::end(optarg), ':'); - if (colon == nullptr || colon == optarg) { + if (colon == std::end(optarg) || colon == std::begin(optarg)) { return {"", ""}; } @@ -249,29 +253,24 @@ Headers::value_type parse_header(const char *optarg) { for (; *value == '\t' || *value == ' '; ++value) ; - auto p = - Header(std::string(optarg, colon), std::string(value, strlen(value))); + auto p = Header(std::string{std::begin(optarg), colon}, + std::string{value, std::end(optarg)}); util::inp_strlower(p.name); if (!nghttp2_check_header_name( reinterpret_cast(p.name.c_str()), p.name.size()) || !nghttp2_check_header_value( reinterpret_cast(p.value.c_str()), p.value.size())) { - return Header(); + return Header{}; } return p; } template -int parse_uint(T *dest, const char *opt, const char *optarg) { - char *end = nullptr; - - errno = 0; - - auto val = strtol(optarg, &end, 10); - - if (!optarg[0] || errno != 0 || *end || val < 0) { +int parse_uint(T *dest, const StringRef &opt, const StringRef &optarg) { + auto val = util::parse_uint(optarg); + if (val == -1) { LOG(ERROR) << opt << ": bad value. Specify an integer >= 0."; return -1; } @@ -283,7 +282,8 @@ int parse_uint(T *dest, const char *opt, const char *optarg) { namespace { template -int parse_uint_with_unit(T *dest, const char *opt, const char *optarg) { +int parse_uint_with_unit(T *dest, const StringRef &opt, + const StringRef &optarg) { auto n = util::parse_uint_with_unit(optarg); if (n == -1) { LOG(ERROR) << opt << ": bad value: '" << optarg << "'"; @@ -296,8 +296,10 @@ int parse_uint_with_unit(T *dest, const char *opt, const char *optarg) { } } // namespace +// Parses |optarg| as signed integer. This requires |optarg| to be +// NULL-terminated string. template -int parse_int(T *dest, const char *opt, const char *optarg) { +int parse_int(T *dest, const StringRef &opt, const char *optarg) { char *end = nullptr; errno = 0; @@ -442,10 +444,10 @@ bool var_token(char c) { } } // namespace -std::vector parse_log_format(const char *optarg) { - auto literal_start = optarg; - auto p = optarg; - auto eop = p + strlen(optarg); +std::vector parse_log_format(const StringRef &optarg) { + auto literal_start = std::begin(optarg); + auto p = literal_start; + auto eop = std::end(optarg); auto res = std::vector(); @@ -467,7 +469,7 @@ std::vector parse_log_format(const char *optarg) { ; if (p == eop || *p != '}') { - LOG(WARN) << "Missing '}' after " << std::string(var_start, p); + LOG(WARN) << "Missing '}' after " << StringRef{var_start, p}; continue; } @@ -499,7 +501,7 @@ std::vector parse_log_format(const char *optarg) { } } else { LOG(WARN) << "Unrecognized log format variable: " - << std::string(var_name, var_namelen); + << StringRef{var_name, var_namelen}; continue; } } @@ -534,16 +536,17 @@ std::vector parse_log_format(const char *optarg) { } namespace { -int parse_address_family(int *dest, const char *opt, const char *optarg) { - if (util::strieq("auto", optarg)) { +int parse_address_family(int *dest, const StringRef &opt, + const StringRef &optarg) { + if (util::strieq_l("auto", optarg)) { *dest = AF_UNSPEC; return 0; } - if (util::strieq("IPv4", optarg)) { + if (util::strieq_l("IPv4", optarg)) { *dest = AF_INET; return 0; } - if (util::strieq("IPv6", optarg)) { + if (util::strieq_l("IPv6", optarg)) { *dest = AF_INET6; return 0; } @@ -554,7 +557,8 @@ int parse_address_family(int *dest, const char *opt, const char *optarg) { } // namespace namespace { -int parse_duration(ev_tstamp *dest, const char *opt, const char *optarg) { +int parse_duration(ev_tstamp *dest, const StringRef &opt, + const StringRef &optarg) { auto t = util::parse_duration_with_unit(optarg); if (t == std::numeric_limits::infinity()) { LOG(ERROR) << opt << ": bad value: '" << optarg << "'"; @@ -791,12 +795,12 @@ int parse_mapping(const DownstreamAddrConfig &addr, } // namespace namespace { -int parse_forwarded_node_type(const std::string &optarg) { - if (util::strieq(optarg, "obfuscated")) { +int parse_forwarded_node_type(const StringRef &optarg) { + if (util::strieq_l("obfuscated", optarg)) { return FORWARDED_NODE_OBFUSCATED; } - if (util::strieq(optarg, "ip")) { + if (util::strieq_l("ip", optarg)) { return FORWARDED_NODE_IP; } @@ -816,16 +820,15 @@ int parse_forwarded_node_type(const std::string &optarg) { } // namespace namespace { -int parse_error_page(std::vector &error_pages, const char *opt, - const char *optarg) { - auto arg = StringRef{optarg}; - auto eq = std::find(std::begin(arg), std::end(arg), '='); - if (eq == std::end(arg) || eq + 1 == std::end(arg)) { - LOG(ERROR) << opt << ": bad value: '" << arg << "'"; +int parse_error_page(std::vector &error_pages, const StringRef &opt, + const StringRef &optarg) { + auto eq = std::find(std::begin(optarg), std::end(optarg), '='); + if (eq == std::end(optarg) || eq + 1 == std::end(optarg)) { + LOG(ERROR) << opt << ": bad value: '" << optarg << "'"; return -1; } - auto codestr = StringRef{std::begin(arg), eq}; + auto codestr = StringRef{std::begin(optarg), eq}; unsigned int code; if (codestr == "*") { @@ -841,7 +844,7 @@ int parse_error_page(std::vector &error_pages, const char *opt, code = static_cast(n); } - auto path = StringRef{eq + 1, std::end(arg)}; + auto path = StringRef{eq + 1, std::end(optarg)}; std::vector content; auto fd = open(path.c_str(), O_RDONLY); @@ -1734,26 +1737,25 @@ int option_lookup_token(const char *name, size_t namelen) { } } // namespace -int parse_config(const char *opt, const char *optarg, - std::set &included_set) { +int parse_config(const StringRef &opt, const StringRef &optarg, + std::set &included_set) { char host[NI_MAXHOST]; uint16_t port; - auto optid = option_lookup_token(opt, strlen(opt)); + auto optid = option_lookup_token(opt.c_str(), opt.size()); switch (optid) { case SHRPX_OPTID_BACKEND: { - auto src = StringRef{optarg}; - auto addr_end = std::find(std::begin(src), std::end(src), ';'); + auto addr_end = std::find(std::begin(optarg), std::end(optarg), ';'); DownstreamAddrConfig addr{}; - if (util::istarts_with_l(src, SHRPX_UNIX_PATH_PREFIX)) { - auto path = std::begin(src) + str_size(SHRPX_UNIX_PATH_PREFIX); + if (util::istarts_with_l(optarg, SHRPX_UNIX_PATH_PREFIX)) { + auto path = std::begin(optarg) + str_size(SHRPX_UNIX_PATH_PREFIX); addr.host = ImmutableString(path, addr_end); addr.host_unix = true; } else { if (split_host_port(host, sizeof(host), &port, - StringRef{std::begin(src), addr_end}, opt) == -1) { + StringRef{std::begin(optarg), addr_end}, opt) == -1) { return -1; } @@ -1761,13 +1763,14 @@ int parse_config(const char *opt, const char *optarg, addr.port = port; } - auto mapping = addr_end == std::end(src) ? addr_end : addr_end + 1; - auto mapping_end = std::find(mapping, std::end(src), ';'); + auto mapping = addr_end == std::end(optarg) ? addr_end : addr_end + 1; + auto mapping_end = std::find(mapping, std::end(optarg), ';'); - auto params = mapping_end == std::end(src) ? mapping_end : mapping_end + 1; + auto params = + mapping_end == std::end(optarg) ? mapping_end : mapping_end + 1; if (parse_mapping(addr, StringRef{mapping, mapping_end}, - StringRef{params, std::end(src)}) != 0) { + StringRef{params, std::end(optarg)}) != 0) { return -1; } @@ -1776,9 +1779,8 @@ int parse_config(const char *opt, const char *optarg, case SHRPX_OPTID_FRONTEND: { auto &listenerconf = mod_config()->conn.listener; - auto src = StringRef{optarg}; - auto addr_end = std::find(std::begin(src), std::end(src), ';'); - auto src_params = StringRef{addr_end, std::end(src)}; + auto addr_end = std::find(std::begin(optarg), std::end(optarg), ';'); + auto src_params = StringRef{addr_end, std::end(optarg)}; UpstreamParams params{}; params.tls = true; @@ -1791,8 +1793,8 @@ int parse_config(const char *opt, const char *optarg, addr.fd = -1; addr.tls = params.tls; - if (util::istarts_with_l(src, SHRPX_UNIX_PATH_PREFIX)) { - auto path = std::begin(src) + str_size(SHRPX_UNIX_PATH_PREFIX); + if (util::istarts_with_l(optarg, SHRPX_UNIX_PATH_PREFIX)) { + auto path = std::begin(optarg) + str_size(SHRPX_UNIX_PATH_PREFIX); addr.host = ImmutableString{path, addr_end}; addr.host_unix = true; @@ -1802,7 +1804,7 @@ int parse_config(const char *opt, const char *optarg, } if (split_host_port(host, sizeof(host), &port, - StringRef{std::begin(src), addr_end}, opt) == -1) { + StringRef{std::begin(optarg), addr_end}, opt) == -1) { return -1; } @@ -1858,11 +1860,11 @@ int parse_config(const char *opt, const char *optarg, return 0; case SHRPX_OPTID_DAEMON: - mod_config()->daemon = util::strieq(optarg, "yes"); + mod_config()->daemon = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_HTTP2_PROXY: - mod_config()->http2_proxy = util::strieq(optarg, "yes"); + mod_config()->http2_proxy = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_HTTP2_BRIDGE: @@ -1874,15 +1876,15 @@ int parse_config(const char *opt, const char *optarg, "backend=,;;proto=h2 and backend-tls"; return -1; case SHRPX_OPTID_ADD_X_FORWARDED_FOR: - mod_config()->http.xff.add = util::strieq(optarg, "yes"); + mod_config()->http.xff.add = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_STRIP_INCOMING_X_FORWARDED_FOR: - mod_config()->http.xff.strip_incoming = util::strieq(optarg, "yes"); + mod_config()->http.xff.strip_incoming = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_NO_VIA: - mod_config()->http.no_via = util::strieq(optarg, "yes"); + mod_config()->http.no_via = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_FRONTEND_HTTP2_READ_TIMEOUT: @@ -1907,11 +1909,12 @@ int parse_config(const char *opt, const char *optarg, return parse_duration(&mod_config()->http2.timeout.stream_write, opt, optarg); case SHRPX_OPTID_ACCESSLOG_FILE: - mod_config()->logging.access.file = optarg; + mod_config()->logging.access.file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_ACCESSLOG_SYSLOG: - mod_config()->logging.access.syslog = util::strieq(optarg, "yes"); + mod_config()->logging.access.syslog = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_ACCESSLOG_FORMAT: @@ -1919,16 +1922,17 @@ int parse_config(const char *opt, const char *optarg, return 0; case SHRPX_OPTID_ERRORLOG_FILE: - mod_config()->logging.error.file = optarg; + mod_config()->logging.error.file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_ERRORLOG_SYSLOG: - mod_config()->logging.error.syslog = util::strieq(optarg, "yes"); + mod_config()->logging.error.syslog = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_FASTOPEN: { int n; - if (parse_int(&n, opt, optarg) != 0) { + if (parse_int(&n, opt, optarg.c_str()) != 0) { return -1; } @@ -2009,15 +2013,16 @@ int parse_config(const char *opt, const char *optarg, "default. See also " << SHRPX_OPT_BACKEND_TLS; return 0; case SHRPX_OPTID_BACKEND_TLS_SNI_FIELD: - mod_config()->tls.backend_sni_name = optarg; + mod_config()->tls.backend_sni_name = optarg.str(); return 0; case SHRPX_OPTID_PID_FILE: - mod_config()->pid_file = optarg; + mod_config()->pid_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_USER: { - auto pwd = getpwnam(optarg); + auto pwd = getpwnam(optarg.c_str()); if (!pwd) { LOG(ERROR) << opt << ": failed to get uid from " << optarg << ": " << strerror(errno); @@ -2030,11 +2035,12 @@ int parse_config(const char *opt, const char *optarg, return 0; } case SHRPX_OPTID_PRIVATE_KEY_FILE: - mod_config()->tls.private_key_file = optarg; + mod_config()->tls.private_key_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_PRIVATE_KEY_PASSWD_FILE: { - auto passwd = read_passwd_from_file(optarg); + auto passwd = read_passwd_from_file(opt, optarg); if (passwd.empty()) { LOG(ERROR) << opt << ": Couldn't read key file's passwd from " << optarg; return -1; @@ -2044,22 +2050,40 @@ int parse_config(const char *opt, const char *optarg, return 0; } case SHRPX_OPTID_CERTIFICATE_FILE: - mod_config()->tls.cert_file = optarg; + mod_config()->tls.cert_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_DH_PARAM_FILE: - mod_config()->tls.dh_param_file = optarg; + mod_config()->tls.dh_param_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_SUBCERT: { // Private Key file and certificate file separated by ':'. - const char *sp = strchr(optarg, ':'); - if (sp) { - std::string keyfile(optarg, sp); - // TODO Do we need private key for subcert? - mod_config()->tls.subcerts.emplace_back(keyfile, sp + 1); + auto sp = std::find(std::begin(optarg), std::end(optarg), ':'); + if (sp == std::end(optarg)) { + LOG(ERROR) << opt << ": missing ':' in " << optarg; + return -1; } + auto private_key_file = StringRef{std::begin(optarg), sp}; + + if (private_key_file.empty()) { + LOG(ERROR) << opt << ": missing private key file: " << optarg; + return -1; + } + + auto cert_file = StringRef{sp + 1, std::end(optarg)}; + + if (cert_file.empty()) { + LOG(ERROR) << opt << ": missing certificate file: " << optarg; + return -1; + } + + mod_config()->tls.subcerts.emplace_back(private_key_file.str(), + cert_file.str()); + return 0; } case SHRPX_OPTID_SYSLOG_FACILITY: { @@ -2074,7 +2098,7 @@ int parse_config(const char *opt, const char *optarg, } case SHRPX_OPTID_BACKLOG: { int n; - if (parse_int(&n, opt, optarg) != 0) { + if (parse_int(&n, opt, optarg.c_str()) != 0) { return -1; } @@ -2089,7 +2113,8 @@ int parse_config(const char *opt, const char *optarg, return 0; } case SHRPX_OPTID_CIPHERS: - mod_config()->tls.ciphers = optarg; + mod_config()->tls.ciphers = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_CLIENT: @@ -2097,11 +2122,12 @@ int parse_config(const char *opt, const char *optarg, "backend=,;;proto=h2 and backend-tls"; return -1; case SHRPX_OPTID_INSECURE: - mod_config()->tls.insecure = util::strieq(optarg, "yes"); + mod_config()->tls.insecure = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_CACERT: - mod_config()->tls.cacert = optarg; + mod_config()->tls.cacert = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_BACKEND_IPV4: @@ -2125,19 +2151,18 @@ int parse_config(const char *opt, const char *optarg, proxy = {}; // parse URI and get hostname, port and optionally userinfo. http_parser_url u{}; - int rv = http_parser_parse_url(optarg, strlen(optarg), 0, &u); + int rv = http_parser_parse_url(optarg.c_str(), optarg.size(), 0, &u); if (rv == 0) { - std::string val; if (u.field_set & UF_USERINFO) { - http2::copy_url_component(val, &u, UF_USERINFO, optarg); + auto uf = util::get_uri_field(optarg.c_str(), u, UF_USERINFO); // Surprisingly, u.field_set & UF_USERINFO is nonzero even if // userinfo component is empty string. - if (!val.empty()) { - proxy.userinfo = util::percent_decode(std::begin(val), std::end(val)); + if (!uf.empty()) { + proxy.userinfo = util::percent_decode(std::begin(uf), std::end(uf)); } } if (u.field_set & UF_HOST) { - http2::copy_url_component(proxy.host, &u, UF_HOST, optarg); + http2::copy_url_component(proxy.host, &u, UF_HOST, optarg.c_str()); } else { LOG(ERROR) << opt << ": no hostname specified"; return -1; @@ -2188,42 +2213,47 @@ int parse_config(const char *opt, const char *optarg, return 0; case SHRPX_OPTID_VERIFY_CLIENT: - mod_config()->tls.client_verify.enabled = util::strieq(optarg, "yes"); + mod_config()->tls.client_verify.enabled = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_VERIFY_CLIENT_CACERT: - mod_config()->tls.client_verify.cacert = optarg; + mod_config()->tls.client_verify.cacert = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_CLIENT_PRIVATE_KEY_FILE: - mod_config()->tls.client.private_key_file = optarg; + mod_config()->tls.client.private_key_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_CLIENT_CERT_FILE: - mod_config()->tls.client.cert_file = optarg; + mod_config()->tls.client.cert_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_FRONTEND_HTTP2_DUMP_REQUEST_HEADER: - mod_config()->http2.upstream.debug.dump.request_header_file = optarg; + mod_config()->http2.upstream.debug.dump.request_header_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER: - mod_config()->http2.upstream.debug.dump.response_header_file = optarg; + mod_config()->http2.upstream.debug.dump.response_header_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_HTTP2_NO_COOKIE_CRUMBLING: - mod_config()->http2.no_cookie_crumbling = util::strieq(optarg, "yes"); + mod_config()->http2.no_cookie_crumbling = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_FRONTEND_FRAME_DEBUG: mod_config()->http2.upstream.debug.frame_debug = - util::strieq(optarg, "yes"); + util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_PADDING: return parse_uint(&mod_config()->padding, opt, optarg); case SHRPX_OPTID_ALTSVC: { - auto tokens = util::parse_config_str_list(optarg); + auto tokens = util::split_str(optarg, ','); if (tokens.size() < 2) { // Requires at least protocol_id and port @@ -2239,7 +2269,7 @@ int parse_config(const char *opt, const char *optarg, int port; - if (parse_uint(&port, opt, tokens[1].c_str()) != 0) { + if (parse_uint(&port, opt, tokens[1]) != 0) { return -1; } @@ -2251,16 +2281,16 @@ int parse_config(const char *opt, const char *optarg, AltSvc altsvc{}; - altsvc.protocol_id = std::move(tokens[0]); + altsvc.protocol_id = tokens[0].str(); altsvc.port = port; - altsvc.service = std::move(tokens[1]); + altsvc.service = tokens[1].str(); if (tokens.size() > 2) { - altsvc.host = std::move(tokens[2]); + altsvc.host = tokens[2].str(); if (tokens.size() > 3) { - altsvc.origin = std::move(tokens[3]); + altsvc.origin = tokens[3].str(); } } @@ -2286,7 +2316,7 @@ int parse_config(const char *opt, const char *optarg, return parse_uint(&mod_config()->conn.upstream.worker_connections, opt, optarg); case SHRPX_OPTID_NO_LOCATION_REWRITE: - mod_config()->http.no_location_rewrite = util::strieq(optarg, "yes"); + mod_config()->http.no_location_rewrite = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_NO_HOST_REWRITE: @@ -2328,7 +2358,7 @@ int parse_config(const char *opt, const char *optarg, return parse_duration(&mod_config()->conn.listener.timeout.sleep, opt, optarg); case SHRPX_OPTID_TLS_TICKET_KEY_FILE: - mod_config()->tls.ticket.files.push_back(optarg); + mod_config()->tls.ticket.files.push_back(optarg.str()); return 0; case SHRPX_OPTID_RLIMIT_NOFILE: { int n; @@ -2370,20 +2400,21 @@ int parse_config(const char *opt, const char *optarg, } case SHRPX_OPTID_NO_SERVER_PUSH: - mod_config()->http2.no_server_push = util::strieq(optarg, "yes"); + mod_config()->http2.no_server_push = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_BACKEND_HTTP2_CONNECTIONS_PER_WORKER: LOG(WARN) << opt << ": deprecated."; return 0; case SHRPX_OPTID_FETCH_OCSP_RESPONSE_FILE: - mod_config()->tls.ocsp.fetch_ocsp_response_file = optarg; + mod_config()->tls.ocsp.fetch_ocsp_response_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_OCSP_UPDATE_INTERVAL: return parse_duration(&mod_config()->tls.ocsp.update_interval, opt, optarg); case SHRPX_OPTID_NO_OCSP: - mod_config()->tls.ocsp.disabled = util::strieq(optarg, "yes"); + mod_config()->tls.ocsp.disabled = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_HEADER_FIELD_BUFFER: @@ -2412,7 +2443,7 @@ int parse_config(const char *opt, const char *optarg, } included_set.insert(optarg); - auto rv = load_config(optarg, included_set); + auto rv = load_config(optarg.c_str(), included_set); included_set.erase(optarg); if (rv != 0) { @@ -2422,9 +2453,9 @@ int parse_config(const char *opt, const char *optarg, return 0; } case SHRPX_OPTID_TLS_TICKET_KEY_CIPHER: - if (util::strieq(optarg, "aes-128-cbc")) { + if (util::strieq_l("aes-128-cbc", optarg)) { mod_config()->tls.ticket.cipher = EVP_aes_128_cbc(); - } else if (util::strieq(optarg, "aes-256-cbc")) { + } else if (util::strieq_l("aes-256-cbc", optarg)) { mod_config()->tls.ticket.cipher = EVP_aes_256_cbc(); } else { LOG(ERROR) << opt @@ -2435,14 +2466,13 @@ int parse_config(const char *opt, const char *optarg, return 0; case SHRPX_OPTID_HOST_REWRITE: - mod_config()->http.no_host_rewrite = !util::strieq(optarg, "yes"); + mod_config()->http.no_host_rewrite = !util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED: case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED: { - auto src = StringRef{optarg}; - auto addr_end = std::find(std::begin(src), std::end(src), ';'); - auto src_params = StringRef{addr_end, std::end(src)}; + auto addr_end = std::find(std::begin(optarg), std::end(optarg), ';'); + auto src_params = StringRef{addr_end, std::end(optarg)}; MemcachedConnectionParams params{}; if (parse_memcached_connection_params(params, src_params, StringRef{opt}) != @@ -2451,7 +2481,7 @@ int parse_config(const char *opt, const char *optarg, } if (split_host_port(host, sizeof(host), &port, - StringRef{std::begin(src), addr_end}, opt) == -1) { + StringRef{std::begin(optarg), addr_end}, opt) == -1) { return -1; } @@ -2510,7 +2540,8 @@ int parse_config(const char *opt, const char *optarg, case SHRPX_OPTID_MRUBY_FILE: #ifdef HAVE_MRUBY - mod_config()->mruby_file = optarg; + mod_config()->mruby_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; #else // !HAVE_MRUBY LOG(WARN) << opt << ": ignored because mruby support is disabled at build time."; @@ -2518,26 +2549,26 @@ int parse_config(const char *opt, const char *optarg, return 0; case SHRPX_OPTID_ACCEPT_PROXY_PROTOCOL: mod_config()->conn.upstream.accept_proxy_protocol = - util::strieq(optarg, "yes"); + util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_ADD_FORWARDED: { auto &fwdconf = mod_config()->http.forwarded; fwdconf.params = FORWARDED_NONE; - for (const auto ¶m : util::parse_config_str_list(optarg)) { - if (util::strieq(param, "by")) { + for (const auto ¶m : util::split_str(optarg, ',')) { + if (util::strieq_l("by", param)) { fwdconf.params |= FORWARDED_BY; continue; } - if (util::strieq(param, "for")) { + if (util::strieq_l("for", param)) { fwdconf.params |= FORWARDED_FOR; continue; } - if (util::strieq(param, "host")) { + if (util::strieq_l("host", param)) { fwdconf.params |= FORWARDED_HOST; continue; } - if (util::strieq(param, "proto")) { + if (util::strieq_l("proto", param)) { fwdconf.params |= FORWARDED_PROTO; continue; } @@ -2550,7 +2581,7 @@ int parse_config(const char *opt, const char *optarg, return 0; } case SHRPX_OPTID_STRIP_INCOMING_FORWARDED: - mod_config()->http.forwarded.strip_incoming = util::strieq(optarg, "yes"); + mod_config()->http.forwarded.strip_incoming = util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_FORWARDED_BY: @@ -2570,7 +2601,7 @@ int parse_config(const char *opt, const char *optarg, case SHRPX_OPTID_FORWARDED_BY: fwdconf.by_node_type = static_cast(type); if (optarg[0] == '_') { - fwdconf.by_obfuscated = optarg; + fwdconf.by_obfuscated = optarg.str(); } else { fwdconf.by_obfuscated = ""; } @@ -2583,7 +2614,8 @@ int parse_config(const char *opt, const char *optarg, return 0; } case SHRPX_OPTID_NO_HTTP2_CIPHER_BLACK_LIST: - mod_config()->tls.no_http2_cipher_black_list = util::strieq(optarg, "yes"); + mod_config()->tls.no_http2_cipher_black_list = + util::strieq_l("yes", optarg); return 0; case SHRPX_OPTID_BACKEND_HTTP1_TLS: @@ -2596,11 +2628,13 @@ int parse_config(const char *opt, const char *optarg, << SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED; return 0; case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE: - mod_config()->tls.session_cache.memcached.cert_file = optarg; + mod_config()->tls.session_cache.memcached.cert_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE: - mod_config()->tls.session_cache.memcached.private_key_file = optarg; + mod_config()->tls.session_cache.memcached.private_key_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_TLS: @@ -2608,11 +2642,13 @@ int parse_config(const char *opt, const char *optarg, << SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED; return 0; case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_CERT_FILE: - mod_config()->tls.ticket.memcached.cert_file = optarg; + mod_config()->tls.ticket.memcached.cert_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE: - mod_config()->tls.ticket.memcached.private_key_file = optarg; + mod_config()->tls.ticket.memcached.private_key_file = + ImmutableString{std::begin(optarg), std::end(optarg)}; return 0; case SHRPX_OPTID_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY: @@ -2643,7 +2679,7 @@ int parse_config(const char *opt, const char *optarg, return -1; } -int load_config(const char *filename, std::set &include_set) { +int load_config(const char *filename, std::set &include_set) { std::ifstream in(filename, std::ios::binary); if (!in) { LOG(ERROR) << "Could not open config file " << filename; @@ -2656,155 +2692,153 @@ int load_config(const char *filename, std::set &include_set) { if (line.empty() || line[0] == '#') { continue; } - size_t i; - size_t size = line.size(); - for (i = 0; i < size && line[i] != '='; ++i) - ; - if (i == size) { + auto eq = std::find(std::begin(line), std::end(line), '='); + if (eq == std::end(line)) { LOG(ERROR) << "Bad configuration format in " << filename << " at line " << linenum; return -1; } - line[i] = '\0'; - auto s = line.c_str(); - if (parse_config(s, s + i + 1, include_set) == -1) { + *eq = '\0'; + + if (parse_config(StringRef{std::begin(line), eq}, + StringRef{eq + 1, std::end(line)}, include_set) != 0) { return -1; } } return 0; } -const char *str_syslog_facility(int facility) { +StringRef str_syslog_facility(int facility) { switch (facility) { case (LOG_AUTH): - return "auth"; + return StringRef::from_lit("auth"); #ifdef LOG_AUTHPRIV case (LOG_AUTHPRIV): - return "authpriv"; + return StringRef::from_lit("authpriv"); #endif // LOG_AUTHPRIV case (LOG_CRON): - return "cron"; + return StringRef::from_lit("cron"); case (LOG_DAEMON): - return "daemon"; + return StringRef::from_lit("daemon"); #ifdef LOG_FTP case (LOG_FTP): - return "ftp"; + return StringRef::from_lit("ftp"); #endif // LOG_FTP case (LOG_KERN): - return "kern"; + return StringRef::from_lit("kern"); case (LOG_LOCAL0): - return "local0"; + return StringRef::from_lit("local0"); case (LOG_LOCAL1): - return "local1"; + return StringRef::from_lit("local1"); case (LOG_LOCAL2): - return "local2"; + return StringRef::from_lit("local2"); case (LOG_LOCAL3): - return "local3"; + return StringRef::from_lit("local3"); case (LOG_LOCAL4): - return "local4"; + return StringRef::from_lit("local4"); case (LOG_LOCAL5): - return "local5"; + return StringRef::from_lit("local5"); case (LOG_LOCAL6): - return "local6"; + return StringRef::from_lit("local6"); case (LOG_LOCAL7): - return "local7"; + return StringRef::from_lit("local7"); case (LOG_LPR): - return "lpr"; + return StringRef::from_lit("lpr"); case (LOG_MAIL): - return "mail"; + return StringRef::from_lit("mail"); case (LOG_SYSLOG): - return "syslog"; + return StringRef::from_lit("syslog"); case (LOG_USER): - return "user"; + return StringRef::from_lit("user"); case (LOG_UUCP): - return "uucp"; + return StringRef::from_lit("uucp"); default: - return "(unknown)"; + return StringRef::from_lit("(unknown)"); } } -int int_syslog_facility(const char *strfacility) { - if (util::strieq(strfacility, "auth")) { +int int_syslog_facility(const StringRef &strfacility) { + if (util::strieq_l("auth", strfacility)) { return LOG_AUTH; } #ifdef LOG_AUTHPRIV - if (util::strieq(strfacility, "authpriv")) { + if (util::strieq_l("authpriv", strfacility)) { return LOG_AUTHPRIV; } #endif // LOG_AUTHPRIV - if (util::strieq(strfacility, "cron")) { + if (util::strieq_l("cron", strfacility)) { return LOG_CRON; } - if (util::strieq(strfacility, "daemon")) { + if (util::strieq_l("daemon", strfacility)) { return LOG_DAEMON; } #ifdef LOG_FTP - if (util::strieq(strfacility, "ftp")) { + if (util::strieq_l("ftp", strfacility)) { return LOG_FTP; } #endif // LOG_FTP - if (util::strieq(strfacility, "kern")) { + if (util::strieq_l("kern", strfacility)) { return LOG_KERN; } - if (util::strieq(strfacility, "local0")) { + if (util::strieq_l("local0", strfacility)) { return LOG_LOCAL0; } - if (util::strieq(strfacility, "local1")) { + if (util::strieq_l("local1", strfacility)) { return LOG_LOCAL1; } - if (util::strieq(strfacility, "local2")) { + if (util::strieq_l("local2", strfacility)) { return LOG_LOCAL2; } - if (util::strieq(strfacility, "local3")) { + if (util::strieq_l("local3", strfacility)) { return LOG_LOCAL3; } - if (util::strieq(strfacility, "local4")) { + if (util::strieq_l("local4", strfacility)) { return LOG_LOCAL4; } - if (util::strieq(strfacility, "local5")) { + if (util::strieq_l("local5", strfacility)) { return LOG_LOCAL5; } - if (util::strieq(strfacility, "local6")) { + if (util::strieq_l("local6", strfacility)) { return LOG_LOCAL6; } - if (util::strieq(strfacility, "local7")) { + if (util::strieq_l("local7", strfacility)) { return LOG_LOCAL7; } - if (util::strieq(strfacility, "lpr")) { + if (util::strieq_l("lpr", strfacility)) { return LOG_LPR; } - if (util::strieq(strfacility, "mail")) { + if (util::strieq_l("mail", strfacility)) { return LOG_MAIL; } - if (util::strieq(strfacility, "news")) { + if (util::strieq_l("news", strfacility)) { return LOG_NEWS; } - if (util::strieq(strfacility, "syslog")) { + if (util::strieq_l("syslog", strfacility)) { return LOG_SYSLOG; } - if (util::strieq(strfacility, "user")) { + if (util::strieq_l("user", strfacility)) { return LOG_USER; } - if (util::strieq(strfacility, "uucp")) { + if (util::strieq_l("uucp", strfacility)) { return LOG_UUCP; } diff --git a/src/shrpx_config.h b/src/shrpx_config.h index d7984b6d..37dc0e5e 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -71,173 +71,212 @@ class CertLookupTree; constexpr char SHRPX_UNIX_PATH_PREFIX[] = "unix:"; -constexpr char SHRPX_OPT_PRIVATE_KEY_FILE[] = "private-key-file"; -constexpr char SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE[] = "private-key-passwd-file"; -constexpr char SHRPX_OPT_CERTIFICATE_FILE[] = "certificate-file"; -constexpr char SHRPX_OPT_DH_PARAM_FILE[] = "dh-param-file"; -constexpr char SHRPX_OPT_SUBCERT[] = "subcert"; -constexpr char SHRPX_OPT_BACKEND[] = "backend"; -constexpr char SHRPX_OPT_FRONTEND[] = "frontend"; -constexpr char SHRPX_OPT_WORKERS[] = "workers"; -constexpr char SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS[] = - "http2-max-concurrent-streams"; -constexpr char SHRPX_OPT_LOG_LEVEL[] = "log-level"; -constexpr char SHRPX_OPT_DAEMON[] = "daemon"; -constexpr char SHRPX_OPT_HTTP2_PROXY[] = "http2-proxy"; -constexpr char SHRPX_OPT_HTTP2_BRIDGE[] = "http2-bridge"; -constexpr char SHRPX_OPT_CLIENT_PROXY[] = "client-proxy"; -constexpr char SHRPX_OPT_ADD_X_FORWARDED_FOR[] = "add-x-forwarded-for"; -constexpr char SHRPX_OPT_STRIP_INCOMING_X_FORWARDED_FOR[] = - "strip-incoming-x-forwarded-for"; -constexpr char SHRPX_OPT_NO_VIA[] = "no-via"; -constexpr char SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT[] = - "frontend-http2-read-timeout"; -constexpr char SHRPX_OPT_FRONTEND_READ_TIMEOUT[] = "frontend-read-timeout"; -constexpr char SHRPX_OPT_FRONTEND_WRITE_TIMEOUT[] = "frontend-write-timeout"; -constexpr char SHRPX_OPT_BACKEND_READ_TIMEOUT[] = "backend-read-timeout"; -constexpr char SHRPX_OPT_BACKEND_WRITE_TIMEOUT[] = "backend-write-timeout"; -constexpr char SHRPX_OPT_STREAM_READ_TIMEOUT[] = "stream-read-timeout"; -constexpr char SHRPX_OPT_STREAM_WRITE_TIMEOUT[] = "stream-write-timeout"; -constexpr char SHRPX_OPT_ACCESSLOG_FILE[] = "accesslog-file"; -constexpr char SHRPX_OPT_ACCESSLOG_SYSLOG[] = "accesslog-syslog"; -constexpr char SHRPX_OPT_ACCESSLOG_FORMAT[] = "accesslog-format"; -constexpr char SHRPX_OPT_ERRORLOG_FILE[] = "errorlog-file"; -constexpr char SHRPX_OPT_ERRORLOG_SYSLOG[] = "errorlog-syslog"; -constexpr char SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT[] = - "backend-keep-alive-timeout"; -constexpr char SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS[] = - "frontend-http2-window-bits"; -constexpr char SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS[] = - "backend-http2-window-bits"; -constexpr char SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS[] = - "frontend-http2-connection-window-bits"; -constexpr char SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS[] = - "backend-http2-connection-window-bits"; -constexpr char SHRPX_OPT_FRONTEND_NO_TLS[] = "frontend-no-tls"; -constexpr char SHRPX_OPT_BACKEND_NO_TLS[] = "backend-no-tls"; -constexpr char SHRPX_OPT_BACKEND_TLS_SNI_FIELD[] = "backend-tls-sni-field"; -constexpr char SHRPX_OPT_PID_FILE[] = "pid-file"; -constexpr char SHRPX_OPT_USER[] = "user"; -constexpr char SHRPX_OPT_SYSLOG_FACILITY[] = "syslog-facility"; -constexpr char SHRPX_OPT_BACKLOG[] = "backlog"; -constexpr char SHRPX_OPT_CIPHERS[] = "ciphers"; -constexpr char SHRPX_OPT_CLIENT[] = "client"; -constexpr char SHRPX_OPT_INSECURE[] = "insecure"; -constexpr char SHRPX_OPT_CACERT[] = "cacert"; -constexpr char SHRPX_OPT_BACKEND_IPV4[] = "backend-ipv4"; -constexpr char SHRPX_OPT_BACKEND_IPV6[] = "backend-ipv6"; -constexpr char SHRPX_OPT_BACKEND_HTTP_PROXY_URI[] = "backend-http-proxy-uri"; -constexpr char SHRPX_OPT_READ_RATE[] = "read-rate"; -constexpr char SHRPX_OPT_READ_BURST[] = "read-burst"; -constexpr char SHRPX_OPT_WRITE_RATE[] = "write-rate"; -constexpr char SHRPX_OPT_WRITE_BURST[] = "write-burst"; -constexpr char SHRPX_OPT_WORKER_READ_RATE[] = "worker-read-rate"; -constexpr char SHRPX_OPT_WORKER_READ_BURST[] = "worker-read-burst"; -constexpr char SHRPX_OPT_WORKER_WRITE_RATE[] = "worker-write-rate"; -constexpr char SHRPX_OPT_WORKER_WRITE_BURST[] = "worker-write-burst"; -constexpr char SHRPX_OPT_NPN_LIST[] = "npn-list"; -constexpr char SHRPX_OPT_TLS_PROTO_LIST[] = "tls-proto-list"; -constexpr char SHRPX_OPT_VERIFY_CLIENT[] = "verify-client"; -constexpr char SHRPX_OPT_VERIFY_CLIENT_CACERT[] = "verify-client-cacert"; -constexpr char SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE[] = "client-private-key-file"; -constexpr char SHRPX_OPT_CLIENT_CERT_FILE[] = "client-cert-file"; -constexpr char SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER[] = - "frontend-http2-dump-request-header"; -constexpr char SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER[] = - "frontend-http2-dump-response-header"; -constexpr char SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING[] = - "http2-no-cookie-crumbling"; -constexpr char SHRPX_OPT_FRONTEND_FRAME_DEBUG[] = "frontend-frame-debug"; -constexpr char SHRPX_OPT_PADDING[] = "padding"; -constexpr char SHRPX_OPT_ALTSVC[] = "altsvc"; -constexpr char SHRPX_OPT_ADD_REQUEST_HEADER[] = "add-request-header"; -constexpr char SHRPX_OPT_ADD_RESPONSE_HEADER[] = "add-response-header"; -constexpr char SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS[] = - "worker-frontend-connections"; -constexpr char SHRPX_OPT_NO_LOCATION_REWRITE[] = "no-location-rewrite"; -constexpr char SHRPX_OPT_NO_HOST_REWRITE[] = "no-host-rewrite"; -constexpr char SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_HOST[] = - "backend-http1-connections-per-host"; -constexpr char SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND[] = - "backend-http1-connections-per-frontend"; -constexpr char SHRPX_OPT_LISTENER_DISABLE_TIMEOUT[] = - "listener-disable-timeout"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_FILE[] = "tls-ticket-key-file"; -constexpr char SHRPX_OPT_RLIMIT_NOFILE[] = "rlimit-nofile"; -constexpr char SHRPX_OPT_BACKEND_REQUEST_BUFFER[] = "backend-request-buffer"; -constexpr char SHRPX_OPT_BACKEND_RESPONSE_BUFFER[] = "backend-response-buffer"; -constexpr char SHRPX_OPT_NO_SERVER_PUSH[] = "no-server-push"; -constexpr char SHRPX_OPT_BACKEND_HTTP2_CONNECTIONS_PER_WORKER[] = - "backend-http2-connections-per-worker"; -constexpr char SHRPX_OPT_FETCH_OCSP_RESPONSE_FILE[] = - "fetch-ocsp-response-file"; -constexpr char SHRPX_OPT_OCSP_UPDATE_INTERVAL[] = "ocsp-update-interval"; -constexpr char SHRPX_OPT_NO_OCSP[] = "no-ocsp"; -constexpr char SHRPX_OPT_HEADER_FIELD_BUFFER[] = "header-field-buffer"; -constexpr char SHRPX_OPT_MAX_HEADER_FIELDS[] = "max-header-fields"; -constexpr char SHRPX_OPT_INCLUDE[] = "include"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_CIPHER[] = "tls-ticket-key-cipher"; -constexpr char SHRPX_OPT_HOST_REWRITE[] = "host-rewrite"; -constexpr char SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED[] = - "tls-session-cache-memcached"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED[] = - "tls-ticket-key-memcached"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_INTERVAL[] = - "tls-ticket-key-memcached-interval"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_RETRY[] = - "tls-ticket-key-memcached-max-retry"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_FAIL[] = - "tls-ticket-key-memcached-max-fail"; -constexpr char SHRPX_OPT_MRUBY_FILE[] = "mruby-file"; -constexpr char SHRPX_OPT_ACCEPT_PROXY_PROTOCOL[] = "accept-proxy-protocol"; -constexpr char SHRPX_OPT_FASTOPEN[] = "fastopen"; -constexpr char SHRPX_OPT_TLS_DYN_REC_WARMUP_THRESHOLD[] = - "tls-dyn-rec-warmup-threshold"; -constexpr char SHRPX_OPT_TLS_DYN_REC_IDLE_TIMEOUT[] = - "tls-dyn-rec-idle-timeout"; -constexpr char SHRPX_OPT_ADD_FORWARDED[] = "add-forwarded"; -constexpr char SHRPX_OPT_STRIP_INCOMING_FORWARDED[] = - "strip-incoming-forwarded"; -constexpr static char SHRPX_OPT_FORWARDED_BY[] = "forwarded-by"; -constexpr char SHRPX_OPT_FORWARDED_FOR[] = "forwarded-for"; -constexpr char SHRPX_OPT_REQUEST_HEADER_FIELD_BUFFER[] = - "request-header-field-buffer"; -constexpr char SHRPX_OPT_MAX_REQUEST_HEADER_FIELDS[] = - "max-request-header-fields"; -constexpr char SHRPX_OPT_RESPONSE_HEADER_FIELD_BUFFER[] = - "response-header-field-buffer"; -constexpr char SHRPX_OPT_MAX_RESPONSE_HEADER_FIELDS[] = - "max-response-header-fields"; -constexpr char SHRPX_OPT_NO_HTTP2_CIPHER_BLACK_LIST[] = - "no-http2-cipher-black-list"; -constexpr char SHRPX_OPT_BACKEND_HTTP1_TLS[] = "backend-http1-tls"; -constexpr char SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_TLS[] = - "tls-session-cache-memcached-tls"; -constexpr char SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE[] = - "tls-session-cache-memcached-cert-file"; -constexpr char SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE[] = - "tls-session-cache-memcached-private-key-file"; -constexpr char SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY[] = - "tls-session-cache-memcached-address-family"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_TLS[] = - "tls-ticket-key-memcached-tls"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_CERT_FILE[] = - "tls-ticket-key-memcached-cert-file"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE[] = - "tls-ticket-key-memcached-private-key-file"; -constexpr char SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY[] = - "tls-ticket-key-memcached-address-family"; -constexpr char SHRPX_OPT_BACKEND_ADDRESS_FAMILY[] = "backend-address-family"; -constexpr char SHRPX_OPT_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS[] = - "frontend-http2-max-concurrent-streams"; -constexpr char SHRPX_OPT_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS[] = - "backend-http2-max-concurrent-streams"; -constexpr char SHRPX_OPT_BACKEND_CONNECTIONS_PER_FRONTEND[] = - "backend-connections-per-frontend"; -constexpr char SHRPX_OPT_BACKEND_TLS[] = "backend-tls"; -constexpr char SHRPX_OPT_BACKEND_CONNECTIONS_PER_HOST[] = - "backend-connections-per-host"; -constexpr char SHRPX_OPT_ERROR_PAGE[] = "error-page"; +constexpr auto SHRPX_OPT_PRIVATE_KEY_FILE = + StringRef::from_lit("private-key-file"); +constexpr auto SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE = + StringRef::from_lit("private-key-passwd-file"); +constexpr auto SHRPX_OPT_CERTIFICATE_FILE = + StringRef::from_lit("certificate-file"); +constexpr auto SHRPX_OPT_DH_PARAM_FILE = StringRef::from_lit("dh-param-file"); +constexpr auto SHRPX_OPT_SUBCERT = StringRef::from_lit("subcert"); +constexpr auto SHRPX_OPT_BACKEND = StringRef::from_lit("backend"); +constexpr auto SHRPX_OPT_FRONTEND = StringRef::from_lit("frontend"); +constexpr auto SHRPX_OPT_WORKERS = StringRef::from_lit("workers"); +constexpr auto SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS = + StringRef::from_lit("http2-max-concurrent-streams"); +constexpr auto SHRPX_OPT_LOG_LEVEL = StringRef::from_lit("log-level"); +constexpr auto SHRPX_OPT_DAEMON = StringRef::from_lit("daemon"); +constexpr auto SHRPX_OPT_HTTP2_PROXY = StringRef::from_lit("http2-proxy"); +constexpr auto SHRPX_OPT_HTTP2_BRIDGE = StringRef::from_lit("http2-bridge"); +constexpr auto SHRPX_OPT_CLIENT_PROXY = StringRef::from_lit("client-proxy"); +constexpr auto SHRPX_OPT_ADD_X_FORWARDED_FOR = + StringRef::from_lit("add-x-forwarded-for"); +constexpr auto SHRPX_OPT_STRIP_INCOMING_X_FORWARDED_FOR = + StringRef::from_lit("strip-incoming-x-forwarded-for"); +constexpr auto SHRPX_OPT_NO_VIA = StringRef::from_lit("no-via"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT = + StringRef::from_lit("frontend-http2-read-timeout"); +constexpr auto SHRPX_OPT_FRONTEND_READ_TIMEOUT = + StringRef::from_lit("frontend-read-timeout"); +constexpr auto SHRPX_OPT_FRONTEND_WRITE_TIMEOUT = + StringRef::from_lit("frontend-write-timeout"); +constexpr auto SHRPX_OPT_BACKEND_READ_TIMEOUT = + StringRef::from_lit("backend-read-timeout"); +constexpr auto SHRPX_OPT_BACKEND_WRITE_TIMEOUT = + StringRef::from_lit("backend-write-timeout"); +constexpr auto SHRPX_OPT_STREAM_READ_TIMEOUT = + StringRef::from_lit("stream-read-timeout"); +constexpr auto SHRPX_OPT_STREAM_WRITE_TIMEOUT = + StringRef::from_lit("stream-write-timeout"); +constexpr auto SHRPX_OPT_ACCESSLOG_FILE = StringRef::from_lit("accesslog-file"); +constexpr auto SHRPX_OPT_ACCESSLOG_SYSLOG = + StringRef::from_lit("accesslog-syslog"); +constexpr auto SHRPX_OPT_ACCESSLOG_FORMAT = + StringRef::from_lit("accesslog-format"); +constexpr auto SHRPX_OPT_ERRORLOG_FILE = StringRef::from_lit("errorlog-file"); +constexpr auto SHRPX_OPT_ERRORLOG_SYSLOG = + StringRef::from_lit("errorlog-syslog"); +constexpr auto SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT = + StringRef::from_lit("backend-keep-alive-timeout"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS = + StringRef::from_lit("frontend-http2-window-bits"); +constexpr auto SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS = + StringRef::from_lit("backend-http2-window-bits"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS = + StringRef::from_lit("frontend-http2-connection-window-bits"); +constexpr auto SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS = + StringRef::from_lit("backend-http2-connection-window-bits"); +constexpr auto SHRPX_OPT_FRONTEND_NO_TLS = + StringRef::from_lit("frontend-no-tls"); +constexpr auto SHRPX_OPT_BACKEND_NO_TLS = StringRef::from_lit("backend-no-tls"); +constexpr auto SHRPX_OPT_BACKEND_TLS_SNI_FIELD = + StringRef::from_lit("backend-tls-sni-field"); +constexpr auto SHRPX_OPT_PID_FILE = StringRef::from_lit("pid-file"); +constexpr auto SHRPX_OPT_USER = StringRef::from_lit("user"); +constexpr auto SHRPX_OPT_SYSLOG_FACILITY = + StringRef::from_lit("syslog-facility"); +constexpr auto SHRPX_OPT_BACKLOG = StringRef::from_lit("backlog"); +constexpr auto SHRPX_OPT_CIPHERS = StringRef::from_lit("ciphers"); +constexpr auto SHRPX_OPT_CLIENT = StringRef::from_lit("client"); +constexpr auto SHRPX_OPT_INSECURE = StringRef::from_lit("insecure"); +constexpr auto SHRPX_OPT_CACERT = StringRef::from_lit("cacert"); +constexpr auto SHRPX_OPT_BACKEND_IPV4 = StringRef::from_lit("backend-ipv4"); +constexpr auto SHRPX_OPT_BACKEND_IPV6 = StringRef::from_lit("backend-ipv6"); +constexpr auto SHRPX_OPT_BACKEND_HTTP_PROXY_URI = + StringRef::from_lit("backend-http-proxy-uri"); +constexpr auto SHRPX_OPT_READ_RATE = StringRef::from_lit("read-rate"); +constexpr auto SHRPX_OPT_READ_BURST = StringRef::from_lit("read-burst"); +constexpr auto SHRPX_OPT_WRITE_RATE = StringRef::from_lit("write-rate"); +constexpr auto SHRPX_OPT_WRITE_BURST = StringRef::from_lit("write-burst"); +constexpr auto SHRPX_OPT_WORKER_READ_RATE = + StringRef::from_lit("worker-read-rate"); +constexpr auto SHRPX_OPT_WORKER_READ_BURST = + StringRef::from_lit("worker-read-burst"); +constexpr auto SHRPX_OPT_WORKER_WRITE_RATE = + StringRef::from_lit("worker-write-rate"); +constexpr auto SHRPX_OPT_WORKER_WRITE_BURST = + StringRef::from_lit("worker-write-burst"); +constexpr auto SHRPX_OPT_NPN_LIST = StringRef::from_lit("npn-list"); +constexpr auto SHRPX_OPT_TLS_PROTO_LIST = StringRef::from_lit("tls-proto-list"); +constexpr auto SHRPX_OPT_VERIFY_CLIENT = StringRef::from_lit("verify-client"); +constexpr auto SHRPX_OPT_VERIFY_CLIENT_CACERT = + StringRef::from_lit("verify-client-cacert"); +constexpr auto SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE = + StringRef::from_lit("client-private-key-file"); +constexpr auto SHRPX_OPT_CLIENT_CERT_FILE = + StringRef::from_lit("client-cert-file"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER = + StringRef::from_lit("frontend-http2-dump-request-header"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER = + StringRef::from_lit("frontend-http2-dump-response-header"); +constexpr auto SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING = + StringRef::from_lit("http2-no-cookie-crumbling"); +constexpr auto SHRPX_OPT_FRONTEND_FRAME_DEBUG = + StringRef::from_lit("frontend-frame-debug"); +constexpr auto SHRPX_OPT_PADDING = StringRef::from_lit("padding"); +constexpr auto SHRPX_OPT_ALTSVC = StringRef::from_lit("altsvc"); +constexpr auto SHRPX_OPT_ADD_REQUEST_HEADER = + StringRef::from_lit("add-request-header"); +constexpr auto SHRPX_OPT_ADD_RESPONSE_HEADER = + StringRef::from_lit("add-response-header"); +constexpr auto SHRPX_OPT_WORKER_FRONTEND_CONNECTIONS = + StringRef::from_lit("worker-frontend-connections"); +constexpr auto SHRPX_OPT_NO_LOCATION_REWRITE = + StringRef::from_lit("no-location-rewrite"); +constexpr auto SHRPX_OPT_NO_HOST_REWRITE = + StringRef::from_lit("no-host-rewrite"); +constexpr auto SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_HOST = + StringRef::from_lit("backend-http1-connections-per-host"); +constexpr auto SHRPX_OPT_BACKEND_HTTP1_CONNECTIONS_PER_FRONTEND = + StringRef::from_lit("backend-http1-connections-per-frontend"); +constexpr auto SHRPX_OPT_LISTENER_DISABLE_TIMEOUT = + StringRef::from_lit("listener-disable-timeout"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_FILE = + StringRef::from_lit("tls-ticket-key-file"); +constexpr auto SHRPX_OPT_RLIMIT_NOFILE = StringRef::from_lit("rlimit-nofile"); +constexpr auto SHRPX_OPT_BACKEND_REQUEST_BUFFER = + StringRef::from_lit("backend-request-buffer"); +constexpr auto SHRPX_OPT_BACKEND_RESPONSE_BUFFER = + StringRef::from_lit("backend-response-buffer"); +constexpr auto SHRPX_OPT_NO_SERVER_PUSH = StringRef::from_lit("no-server-push"); +constexpr auto SHRPX_OPT_BACKEND_HTTP2_CONNECTIONS_PER_WORKER = + StringRef::from_lit("backend-http2-connections-per-worker"); +constexpr auto SHRPX_OPT_FETCH_OCSP_RESPONSE_FILE = + StringRef::from_lit("fetch-ocsp-response-file"); +constexpr auto SHRPX_OPT_OCSP_UPDATE_INTERVAL = + StringRef::from_lit("ocsp-update-interval"); +constexpr auto SHRPX_OPT_NO_OCSP = StringRef::from_lit("no-ocsp"); +constexpr auto SHRPX_OPT_HEADER_FIELD_BUFFER = + StringRef::from_lit("header-field-buffer"); +constexpr auto SHRPX_OPT_MAX_HEADER_FIELDS = + StringRef::from_lit("max-header-fields"); +constexpr auto SHRPX_OPT_INCLUDE = StringRef::from_lit("include"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_CIPHER = + StringRef::from_lit("tls-ticket-key-cipher"); +constexpr auto SHRPX_OPT_HOST_REWRITE = StringRef::from_lit("host-rewrite"); +constexpr auto SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED = + StringRef::from_lit("tls-session-cache-memcached"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED = + StringRef::from_lit("tls-ticket-key-memcached"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_INTERVAL = + StringRef::from_lit("tls-ticket-key-memcached-interval"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_RETRY = + StringRef::from_lit("tls-ticket-key-memcached-max-retry"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_MAX_FAIL = + StringRef::from_lit("tls-ticket-key-memcached-max-fail"); +constexpr auto SHRPX_OPT_MRUBY_FILE = StringRef::from_lit("mruby-file"); +constexpr auto SHRPX_OPT_ACCEPT_PROXY_PROTOCOL = + StringRef::from_lit("accept-proxy-protocol"); +constexpr auto SHRPX_OPT_FASTOPEN = StringRef::from_lit("fastopen"); +constexpr auto SHRPX_OPT_TLS_DYN_REC_WARMUP_THRESHOLD = + StringRef::from_lit("tls-dyn-rec-warmup-threshold"); +constexpr auto SHRPX_OPT_TLS_DYN_REC_IDLE_TIMEOUT = + StringRef::from_lit("tls-dyn-rec-idle-timeout"); +constexpr auto SHRPX_OPT_ADD_FORWARDED = StringRef::from_lit("add-forwarded"); +constexpr auto SHRPX_OPT_STRIP_INCOMING_FORWARDED = + StringRef::from_lit("strip-incoming-forwarded"); +constexpr auto SHRPX_OPT_FORWARDED_BY = StringRef::from_lit("forwarded-by"); +constexpr auto SHRPX_OPT_FORWARDED_FOR = StringRef::from_lit("forwarded-for"); +constexpr auto SHRPX_OPT_REQUEST_HEADER_FIELD_BUFFER = + StringRef::from_lit("request-header-field-buffer"); +constexpr auto SHRPX_OPT_MAX_REQUEST_HEADER_FIELDS = + StringRef::from_lit("max-request-header-fields"); +constexpr auto SHRPX_OPT_RESPONSE_HEADER_FIELD_BUFFER = + StringRef::from_lit("response-header-field-buffer"); +constexpr auto SHRPX_OPT_MAX_RESPONSE_HEADER_FIELDS = + StringRef::from_lit("max-response-header-fields"); +constexpr auto SHRPX_OPT_NO_HTTP2_CIPHER_BLACK_LIST = + StringRef::from_lit("no-http2-cipher-black-list"); +constexpr auto SHRPX_OPT_BACKEND_HTTP1_TLS = + StringRef::from_lit("backend-http1-tls"); +constexpr auto SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_TLS = + StringRef::from_lit("tls-session-cache-memcached-tls"); +constexpr auto SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_CERT_FILE = + StringRef::from_lit("tls-session-cache-memcached-cert-file"); +constexpr auto SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_PRIVATE_KEY_FILE = + StringRef::from_lit("tls-session-cache-memcached-private-key-file"); +constexpr auto SHRPX_OPT_TLS_SESSION_CACHE_MEMCACHED_ADDRESS_FAMILY = + StringRef::from_lit("tls-session-cache-memcached-address-family"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_TLS = + StringRef::from_lit("tls-ticket-key-memcached-tls"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_CERT_FILE = + StringRef::from_lit("tls-ticket-key-memcached-cert-file"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_PRIVATE_KEY_FILE = + StringRef::from_lit("tls-ticket-key-memcached-private-key-file"); +constexpr auto SHRPX_OPT_TLS_TICKET_KEY_MEMCACHED_ADDRESS_FAMILY = + StringRef::from_lit("tls-ticket-key-memcached-address-family"); +constexpr auto SHRPX_OPT_BACKEND_ADDRESS_FAMILY = + StringRef::from_lit("backend-address-family"); +constexpr auto SHRPX_OPT_FRONTEND_HTTP2_MAX_CONCURRENT_STREAMS = + StringRef::from_lit("frontend-http2-max-concurrent-streams"); +constexpr auto SHRPX_OPT_BACKEND_HTTP2_MAX_CONCURRENT_STREAMS = + StringRef::from_lit("backend-http2-max-concurrent-streams"); +constexpr auto SHRPX_OPT_BACKEND_CONNECTIONS_PER_FRONTEND = + StringRef::from_lit("backend-connections-per-frontend"); +constexpr auto SHRPX_OPT_BACKEND_TLS = StringRef::from_lit("backend-tls"); +constexpr auto SHRPX_OPT_BACKEND_CONNECTIONS_PER_HOST = + StringRef::from_lit("backend-connections-per-host"); +constexpr auto SHRPX_OPT_ERROR_PAGE = StringRef::from_lit("error-page"); constexpr size_t SHRPX_OBFUSCATED_NODE_LENGTH = 8; @@ -628,30 +667,27 @@ void create_config(); // returns 0 if it succeeds, or -1. The |included_set| contains the // all paths already included while processing this configuration, to // avoid loop in --include option. -int parse_config(const char *opt, const char *optarg, - std::set &included_set); +int parse_config(const StringRef &opt, const StringRef &optarg, + std::set &included_set); // Loads configurations from |filename| and stores them in statically // allocated Config object. This function returns 0 if it succeeds, or // -1. See parse_config() for |include_set|. -int load_config(const char *filename, std::set &include_set); - -// Read passwd from |filename| -std::string read_passwd_from_file(const char *filename); +int load_config(const char *filename, std::set &include_set); // Parses header field in |optarg|. We expect header field is formed // like "NAME: VALUE". We require that NAME is non empty string. ":" // is allowed at the start of the NAME, but NAME == ":" is not // allowed. This function returns pair of NAME and VALUE. -Headers::value_type parse_header(const char *optarg); +Headers::value_type parse_header(const StringRef &optarg); -std::vector parse_log_format(const char *optarg); +std::vector parse_log_format(const StringRef &optarg); // Returns string for syslog |facility|. -const char *str_syslog_facility(int facility); +StringRef str_syslog_facility(int facility); // Returns integer value of syslog |facility| string. -int int_syslog_facility(const char *strfacility); +int int_syslog_facility(const StringRef &strfacility); FILE *open_file_for_write(const char *filename); diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index ae699e8b..de42adae 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -53,7 +53,10 @@ using namespace nghttp2; namespace shrpx { namespace { -const char *SEVERITY_STR[] = {"INFO", "NOTICE", "WARN", "ERROR", "FATAL"}; +const StringRef SEVERITY_STR[] = { + StringRef::from_lit("INFO"), StringRef::from_lit("NOTICE"), + StringRef::from_lit("WARN"), StringRef::from_lit("ERROR"), + StringRef::from_lit("FATAL")}; } // namespace namespace { @@ -70,9 +73,9 @@ int Log::severity_thres_ = NOTICE; void Log::set_severity_level(int severity) { severity_thres_ = severity; } -int Log::set_severity_level_by_name(const char *name) { +int Log::set_severity_level_by_name(const StringRef &name) { for (size_t i = 0, max = array_size(SEVERITY_STR); i < max; ++i) { - if (strcmp(SEVERITY_STR[i], name) == 0) { + if (name == SEVERITY_STR[i]) { severity_thres_ = i; return 0; } @@ -119,10 +122,10 @@ Log::~Log() { if (errorconf.syslog) { if (severity_ == NOTICE) { syslog(severity_to_syslog_level(severity_), "[%s] %s", - SEVERITY_STR[severity_], stream_.str().c_str()); + SEVERITY_STR[severity_].c_str(), stream_.str().c_str()); } else { syslog(severity_to_syslog_level(severity_), "[%s] %s (%s:%d)", - SEVERITY_STR[severity_], stream_.str().c_str(), filename_, + SEVERITY_STR[severity_].c_str(), stream_.str().c_str(), filename_, linenum_); } @@ -136,16 +139,18 @@ Log::~Log() { auto &time_local = lgconf->time_local_str; if (severity_ == NOTICE) { - rv = snprintf(buf, sizeof(buf), "%s PID%d [%s%s%s] %s\n", - time_local.c_str(), get_config()->pid, - tty ? SEVERITY_COLOR[severity_] : "", SEVERITY_STR[severity_], - tty ? "\033[0m" : "", stream_.str().c_str()); + rv = + snprintf(buf, sizeof(buf), "%s PID%d [%s%s%s] %s\n", time_local.c_str(), + get_config()->pid, tty ? SEVERITY_COLOR[severity_] : "", + SEVERITY_STR[severity_].c_str(), tty ? "\033[0m" : "", + stream_.str().c_str()); } else { rv = snprintf(buf, sizeof(buf), "%s PID%d [%s%s%s] %s%s:%d%s %s\n", time_local.c_str(), get_config()->pid, - tty ? SEVERITY_COLOR[severity_] : "", SEVERITY_STR[severity_], - tty ? "\033[0m" : "", tty ? "\033[1;30m" : "", filename_, - linenum_, tty ? "\033[0m" : "", stream_.str().c_str()); + tty ? SEVERITY_COLOR[severity_] : "", + SEVERITY_STR[severity_].c_str(), tty ? "\033[0m" : "", + tty ? "\033[1;30m" : "", filename_, linenum_, + tty ? "\033[0m" : "", stream_.str().c_str()); } if (rv < 0) { diff --git a/src/shrpx_log.h b/src/shrpx_log.h index 7cb00fde..24867b0b 100644 --- a/src/shrpx_log.h +++ b/src/shrpx_log.h @@ -97,7 +97,7 @@ public: return *this; } static void set_severity_level(int severity); - static int set_severity_level_by_name(const char *name); + static int set_severity_level_by_name(const StringRef &name); static bool log_enabled(int severity) { return severity >= severity_thres_; } private: diff --git a/src/util.cc b/src/util.cc index 2351d011..b1234574 100644 --- a/src/util.cc +++ b/src/util.cc @@ -878,34 +878,12 @@ std::vector split_str(const StringRef &s, char delim) { return list; } -std::vector> split_config_str_list(const char *s, - char delim) { - size_t len = 1; - auto last = s + strlen(s); - for (const char *first = s, *d = nullptr; - (d = std::find(first, last, delim)) != last; ++len, first = d + 1) - ; - - auto list = std::vector>(len); - - len = 0; - for (auto first = s;; ++len) { - auto stop = std::find(first, last, delim); - list[len] = {first, stop}; - if (stop == last) { - break; - } - first = stop + 1; - } - return list; -} - -std::vector parse_config_str_list(const char *s, char delim) { - auto ranges = split_config_str_list(s, delim); +std::vector parse_config_str_list(const StringRef &s, char delim) { + auto sublist = split_str(s, delim); auto res = std::vector(); - res.reserve(ranges.size()); - for (const auto &range : ranges) { - res.emplace_back(range.first, range.second); + res.reserve(sublist.size()); + for (const auto &s : sublist) { + res.emplace_back(std::begin(s), std::end(s)); } return res; } @@ -1011,9 +989,16 @@ std::pair parse_uint_digits(const void *ss, size_t len) { } // namespace int64_t parse_uint_with_unit(const char *s) { + return parse_uint_with_unit(reinterpret_cast(s), strlen(s)); +} + +int64_t parse_uint_with_unit(const StringRef &s) { + return parse_uint_with_unit(s.byte(), s.size()); +} + +int64_t parse_uint_with_unit(const uint8_t *s, size_t len) { int64_t n; size_t i; - auto len = strlen(s); std::tie(n, i) = parse_uint_digits(s, len); if (n == -1) { return -1; @@ -1071,10 +1056,19 @@ int64_t parse_uint(const uint8_t *s, size_t len) { } double parse_duration_with_unit(const char *s) { + return parse_duration_with_unit(reinterpret_cast(s), + strlen(s)); +} + +double parse_duration_with_unit(const StringRef &s) { + return parse_duration_with_unit(s.byte(), s.size()); +} + +double parse_duration_with_unit(const uint8_t *s, size_t len) { constexpr auto max = std::numeric_limits::max(); int64_t n; size_t i; - auto len = strlen(s); + std::tie(n, i) = parse_uint_digits(s, len); if (n == -1) { goto fail; diff --git a/src/util.h b/src/util.h index 37f7b529..4c554e0d 100644 --- a/src/util.h +++ b/src/util.h @@ -584,19 +584,11 @@ bool select_protocol(const unsigned char **out, unsigned char *outlen, // HTTP/2 protocol identifier. std::vector get_default_alpn(); -template using Range = std::pair; - // Parses delimited strings in |s| and returns the array of substring, // delimited by |delim|. The any white spaces around substring are // treated as a part of substring. -std::vector parse_config_str_list(const char *s, char delim = ','); - -// Parses delimited strings in |s| and returns the array of pointers, -// each element points to the beginning and one beyond last of -// substring in |s|. The delimiter is given by |delim|. The any -// white spaces around substring are treated as a part of substring. -std::vector> split_config_str_list(const char *s, - char delim); +std::vector parse_config_str_list(const StringRef &s, + char delim = ','); // Parses delimited strings in |s| and returns Substrings in |s| // delimited by |delim|. The any white spaces around substring are @@ -653,10 +645,14 @@ bool ipv6_numeric_addr(const char *host); // 1024 and 1024 * 1024 respectively. If there is an error, returns // -1. int64_t parse_uint_with_unit(const char *s); +// The following overload does not require |s| is NULL terminated. +int64_t parse_uint_with_unit(const uint8_t *s, size_t len); +int64_t parse_uint_with_unit(const StringRef &s); // Parses NULL terminated string |s| as unsigned integer and returns // the parsed integer. If there is an error, returns -1. int64_t parse_uint(const char *s); +// The following overload does not require |s| is NULL terminated. int64_t parse_uint(const uint8_t *s, size_t len); int64_t parse_uint(const std::string &s); int64_t parse_uint(const StringRef &s); @@ -669,6 +665,9 @@ int64_t parse_uint(const StringRef &s); // unit is second. This function returns // std::numeric_limits::infinity() if error occurs. double parse_duration_with_unit(const char *s); +// The following overload does not require |s| is NULL terminated. +double parse_duration_with_unit(const uint8_t *s, size_t len); +double parse_duration_with_unit(const StringRef &s); // Returns string representation of time duration |t|. If t has // fractional part (at least more than or equal to 1e-3), |t| is