nghttpx: Code cleanup

This commit is contained in:
Tatsuhiro Tsujikawa 2014-01-18 16:32:22 +09:00
parent 2a95da6bee
commit 50dd7ada50
1 changed files with 60 additions and 85 deletions

View File

@ -828,35 +828,34 @@ int main(int argc, char **argv)
} }
switch(c) { switch(c) {
case 'D': case 'D':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_DAEMON, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_DAEMON, "yes");
break; break;
case 'L': case 'L':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_LOG_LEVEL, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_LOG_LEVEL, optarg);
break; break;
case 'b': case 'b':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_BACKEND, optarg);
break; break;
case 'c': case 'c':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS, cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_MAX_CONCURRENT_STREAMS, optarg);
optarg));
break; break;
case 'f': case 'f':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND, optarg);
break; break;
case 'h': case 'h':
print_help(std::cout); print_help(std::cout);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
case 'k': case 'k':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_INSECURE, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_INSECURE, "yes");
break; break;
case 'n': case 'n':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_WORKERS, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_WORKERS, optarg);
break; break;
case 'p': case 'p':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_CLIENT_PROXY, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PROXY, "yes");
break; break;
case 's': case 's':
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_HTTP2_PROXY, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_PROXY, "yes");
break; break;
case 'v': case 'v':
print_version(std::cout); print_version(std::cout);
@ -868,52 +867,44 @@ int main(int argc, char **argv)
switch(flag) { switch(flag) {
case 1: case 1:
// --add-x-forwarded-for // --add-x-forwarded-for
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_ADD_X_FORWARDED_FOR, cmdcfgs.emplace_back(SHRPX_OPT_ADD_X_FORWARDED_FOR, "yes");
"yes"));
break; break;
case 2: case 2:
// --frontend-http2-read-timeout // --frontend-http2-read-timeout
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT, cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_READ_TIMEOUT, optarg);
optarg));
break; break;
case 3: case 3:
// --frontend-read-timeout // --frontend-read-timeout
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND_READ_TIMEOUT, cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_READ_TIMEOUT, optarg);
optarg));
break; break;
case 4: case 4:
// --frontend-write-timeout // --frontend-write-timeout
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND_WRITE_TIMEOUT, cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_WRITE_TIMEOUT, optarg);
optarg));
break; break;
case 5: case 5:
// --backend-read-timeout // --backend-read-timeout
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_READ_TIMEOUT, cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_READ_TIMEOUT, optarg);
optarg));
break; break;
case 6: case 6:
// --backend-write-timeout // --backend-write-timeout
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_WRITE_TIMEOUT, cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_WRITE_TIMEOUT, optarg);
optarg));
break; break;
case 7: case 7:
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_ACCESSLOG, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_ACCESSLOG, "yes");
break; break;
case 8: case 8:
// --backend-keep-alive-timeout // --backend-keep-alive-timeout
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT, cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_KEEP_ALIVE_TIMEOUT, optarg);
optarg));
break; break;
case 9: case 9:
// --frontend-http2-window-bits // --frontend-http2-window-bits
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS, cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_WINDOW_BITS, optarg);
optarg));
break; break;
case 10: case 10:
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_PID_FILE, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_PID_FILE, optarg);
break; break;
case 11: case 11:
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_USER, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_USER, optarg);
break; break;
case 12: case 12:
// --conf // --conf
@ -921,157 +912,143 @@ int main(int argc, char **argv)
break; break;
case 13: case 13:
// --syslog // --syslog
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_SYSLOG, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_SYSLOG, "yes");
break; break;
case 14: case 14:
// --syslog-facility // --syslog-facility
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_SYSLOG_FACILITY, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_SYSLOG_FACILITY, optarg);
break; break;
case 15: case 15:
// --backlog // --backlog
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKLOG, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_BACKLOG, optarg);
break; break;
case 16: case 16:
// --ciphers // --ciphers
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_CIPHERS, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_CIPHERS, optarg);
break; break;
case 17: case 17:
// --client // --client
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_CLIENT, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_CLIENT, "yes");
break; break;
case 18: case 18:
// --backend-http2-window-bits // --backend-http2-window-bits
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS, cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_WINDOW_BITS, optarg);
optarg));
break; break;
case 19: case 19:
// --cacert // --cacert
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_CACERT, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_CACERT, optarg);
break; break;
case 20: case 20:
// --backend-ipv4 // --backend-ipv4
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_IPV4, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV4, "yes");
break; break;
case 21: case 21:
// --backend-ipv6 // --backend-ipv6
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_IPV6, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_IPV6, "yes");
break; break;
case 22: case 22:
// --private-key-passwd-file // --private-key-passwd-file
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE, cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_PASSWD_FILE, optarg);
optarg));
break; break;
case 23: case 23:
// --no-via // --no-via
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_NO_VIA, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_NO_VIA, "yes");
break; break;
case 24: case 24:
// --subcert // --subcert
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_SUBCERT, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_SUBCERT, optarg);
break; break;
case 25: case 25:
// --http2-bridge // --http2-bridge
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_HTTP2_BRIDGE, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_BRIDGE, "yes");
break; break;
case 26: case 26:
// --backend-http-proxy-uri // --backend-http-proxy-uri
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_HTTP_PROXY_URI, cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP_PROXY_URI, optarg);
optarg));
break; break;
case 27: case 27:
// --backend-no-tls // --backend-no-tls
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_NO_TLS, cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_NO_TLS, "yes");
"yes"));
break; break;
case 29: case 29:
// --frontend-no-tls // --frontend-no-tls
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_FRONTEND_NO_TLS, cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_NO_TLS, "yes");
"yes"));
break; break;
case 31: case 31:
// --backend-tls-sni-field // --backend-tls-sni-field
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_BACKEND_TLS_SNI_FIELD, cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_TLS_SNI_FIELD, optarg);
optarg));
break; break;
case 32: case 32:
// --honor-cipher-order // --honor-cipher-order
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_HONOR_CIPHER_ORDER, cmdcfgs.emplace_back(SHRPX_OPT_HONOR_CIPHER_ORDER, "yes");
"yes"));
break; break;
case 33: case 33:
// --dh-param-file // --dh-param-file
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_DH_PARAM_FILE, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_DH_PARAM_FILE, optarg);
break; break;
case 34: case 34:
// --read-rate // --read-rate
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_READ_RATE, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_READ_RATE, optarg);
break; break;
case 35: case 35:
// --read-burst // --read-burst
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_READ_BURST, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_READ_BURST, optarg);
break; break;
case 36: case 36:
// --write-rate // --write-rate
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_WRITE_RATE, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_WRITE_RATE, optarg);
break; break;
case 37: case 37:
// --write-burst // --write-burst
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_WRITE_BURST, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_WRITE_BURST, optarg);
break; break;
case 38: case 38:
// --npn-list // --npn-list
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_NPN_LIST, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_NPN_LIST, optarg);
break; break;
case 39: case 39:
// --verify-client // --verify-client
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_VERIFY_CLIENT, "yes")); cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT, "yes");
break; break;
case 40: case 40:
// --verify-client-cacert // --verify-client-cacert
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_VERIFY_CLIENT_CACERT, cmdcfgs.emplace_back(SHRPX_OPT_VERIFY_CLIENT_CACERT, optarg);
optarg));
break; break;
case 41: case 41:
// --client-private-key-file // --client-private-key-file
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE, cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_PRIVATE_KEY_FILE, optarg);
optarg));
break; break;
case 42: case 42:
// --client-cert-file // --client-cert-file
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_CLIENT_CERT_FILE, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_CLIENT_CERT_FILE, optarg);
break; break;
case 43: case 43:
// --frontend-http2-dump-request-header // --frontend-http2-dump-request-header
cmdcfgs.push_back(std::make_pair cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER,
(SHRPX_OPT_FRONTEND_HTTP2_DUMP_REQUEST_HEADER, optarg);
optarg));
break; break;
case 44: case 44:
// --frontend-http2-dump-response-header // --frontend-http2-dump-response-header
cmdcfgs.push_back(std::make_pair cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER,
(SHRPX_OPT_FRONTEND_HTTP2_DUMP_RESPONSE_HEADER, optarg);
optarg));
break; break;
case 45: case 45:
// --http2-no-cookie-crumbling // --http2-no-cookie-crumbling
cmdcfgs.push_back(std::make_pair cmdcfgs.emplace_back(SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING, "yes");
(SHRPX_OPT_HTTP2_NO_COOKIE_CRUMBLING, "yes"));
break; break;
case 46: case 46:
// --frontend-http2-connection-window-bits // --frontend-http2-connection-window-bits
cmdcfgs.push_back(std::make_pair cmdcfgs.emplace_back(SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS,
(SHRPX_OPT_FRONTEND_HTTP2_CONNECTION_WINDOW_BITS, optarg);
optarg));
break; break;
case 47: case 47:
// --backend-http2-connection-window-bits // --backend-http2-connection-window-bits
cmdcfgs.push_back(std::make_pair cmdcfgs.emplace_back(SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS,
(SHRPX_OPT_BACKEND_HTTP2_CONNECTION_WINDOW_BITS, optarg);
optarg));
break; break;
case 48: case 48:
// --tls-proto-list // --tls-proto-list
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_TLS_PROTO_LIST, optarg)); cmdcfgs.emplace_back(SHRPX_OPT_TLS_PROTO_LIST, optarg);
break; break;
default: default:
break; break;
@ -1098,10 +1075,8 @@ int main(int argc, char **argv)
} }
if(argc - optind >= 2) { if(argc - optind >= 2) {
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_PRIVATE_KEY_FILE, cmdcfgs.emplace_back(SHRPX_OPT_PRIVATE_KEY_FILE, argv[optind++]);
argv[optind++])); cmdcfgs.emplace_back(SHRPX_OPT_CERTIFICATE_FILE, argv[optind++]);
cmdcfgs.push_back(std::make_pair(SHRPX_OPT_CERTIFICATE_FILE,
argv[optind++]));
} }
for(size_t i = 0, len = cmdcfgs.size(); i < len; ++i) { for(size_t i = 0, len = cmdcfgs.size(); i < len; ++i) {