From 5dd27040511ca10f9dcf6385b16f4e728fbf7cfb Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 2 Oct 2016 22:19:31 +0900 Subject: [PATCH] nghttpx: Use StringRef for tls.npn_list --- src/shrpx.cc | 2 +- src/shrpx_config.cc | 2 +- src/shrpx_config.h | 2 +- src/shrpx_ssl.cc | 12 +++++------- src/shrpx_ssl.h | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index f561b583..677974da 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -2445,7 +2445,7 @@ int process_options(Config *config, auto &tlsconf = config->tls; if (tlsconf.npn_list.empty()) { - tlsconf.npn_list = util::parse_config_str_list(DEFAULT_NPN_LIST); + tlsconf.npn_list = util::split_str(DEFAULT_NPN_LIST, ','); } if (tlsconf.tls_proto_list.empty()) { tlsconf.tls_proto_list = diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index ae262557..066aa731 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -2305,7 +2305,7 @@ int parse_config(Config *config, int optid, const StringRef &opt, LOG(WARN) << opt << ": not implemented yet"; return 0; case SHRPX_OPTID_NPN_LIST: - config->tls.npn_list = util::parse_config_str_list(optarg); + config->tls.npn_list = util::split_str(optarg, ','); return 0; case SHRPX_OPTID_TLS_PROTO_LIST: diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 54f8275b..b3c98ed8 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -526,7 +526,7 @@ struct TLSConfig { std::vector alpn_prefs; // list of supported NPN/ALPN protocol strings in the order of // preference. - std::vector npn_list; + std::vector npn_list; // list of supported SSL/TLS protocol strings. std::vector tls_proto_list; BIO_METHOD *bio_method; diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index 1e283e0d..a53dbe62 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -103,7 +103,7 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) { } // namespace int set_alpn_prefs(std::vector &out, - const std::vector &protos) { + const std::vector &protos) { size_t len = 0; for (const auto &proto : protos) { @@ -125,8 +125,7 @@ int set_alpn_prefs(std::vector &out, for (const auto &proto : protos) { *ptr++ = proto.size(); - memcpy(ptr, proto.c_str(), proto.size()); - ptr += proto.size(); + ptr = std::copy(std::begin(proto), std::end(proto), ptr); } return 0; @@ -469,8 +468,7 @@ int alpn_select_proto_cb(SSL *ssl, const unsigned char **out, auto proto_len = *p; if (proto_id + proto_len <= end && - util::streq(StringRef{target_proto_id}, - StringRef{proto_id, proto_len})) { + util::streq(target_proto_id, StringRef{proto_id, proto_len})) { *out = reinterpret_cast(proto_id); *outlen = proto_len; @@ -1320,10 +1318,10 @@ int cert_lookup_tree_add_cert_from_x509(CertLookupTree *lt, size_t idx, return 0; } -bool in_proto_list(const std::vector &protos, +bool in_proto_list(const std::vector &protos, const StringRef &needle) { for (auto &proto : protos) { - if (util::streq(StringRef{proto}, needle)) { + if (util::streq(proto, needle)) { return true; } } diff --git a/src/shrpx_ssl.h b/src/shrpx_ssl.h index b3952239..010072a6 100644 --- a/src/shrpx_ssl.h +++ b/src/shrpx_ssl.h @@ -167,7 +167,7 @@ int cert_lookup_tree_add_cert_from_x509(CertLookupTree *lt, size_t idx, // Returns true if |proto| is included in the // protocol list |protos|. -bool in_proto_list(const std::vector &protos, +bool in_proto_list(const std::vector &protos, const StringRef &proto); // Returns true if security requirement for HTTP/2 is fulfilled. @@ -179,7 +179,7 @@ bool check_http2_requirement(SSL *ssl); long int create_tls_proto_mask(const std::vector &tls_proto_list); int set_alpn_prefs(std::vector &out, - const std::vector &protos); + const std::vector &protos); // Setups server side SSL_CTX. This function inspects get_config() // and if upstream_no_tls is true, returns nullptr. Otherwise