From bfc26e82997aa86460eedd182abc1a3814d5d107 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 14 Feb 2016 20:59:10 +0900 Subject: [PATCH] nghttpx: Use ImmutableString to store memcached server host --- src/shrpx.cc | 16 ++++++++-------- src/shrpx_config.cc | 4 ++-- src/shrpx_config.h | 8 ++++++-- src/shrpx_ssl.cc | 2 +- src/shrpx_worker.cc | 4 ++-- src/shrpx_worker_process.cc | 4 ++-- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index ee05263b..33272f97 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -2220,10 +2220,10 @@ void process_options( { auto &memcachedconf = tlsconf.session_cache.memcached; - if (memcachedconf.host) { - auto hostport = - util::make_hostport(memcachedconf.host.get(), memcachedconf.port); - if (resolve_hostname(&memcachedconf.addr, memcachedconf.host.get(), + if (!memcachedconf.host.empty()) { + auto hostport = util::make_hostport(StringRef{memcachedconf.host}, + memcachedconf.port); + if (resolve_hostname(&memcachedconf.addr, memcachedconf.host.c_str(), memcachedconf.port, memcachedconf.family) == -1) { LOG(FATAL) << "Resolving memcached address for TLS session cache failed: " @@ -2238,10 +2238,10 @@ void process_options( { auto &memcachedconf = tlsconf.ticket.memcached; - if (memcachedconf.host) { - auto hostport = - util::make_hostport(memcachedconf.host.get(), memcachedconf.port); - if (resolve_hostname(&memcachedconf.addr, memcachedconf.host.get(), + if (!memcachedconf.host.empty()) { + auto hostport = util::make_hostport(StringRef{memcachedconf.host}, + memcachedconf.port); + if (resolve_hostname(&memcachedconf.addr, memcachedconf.host.c_str(), memcachedconf.port, memcachedconf.family) == -1) { LOG(FATAL) << "Resolving memcached address for TLS ticket key failed: " << hostport; diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index 5e6236c3..20d30c86 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -2154,7 +2154,7 @@ int parse_config(const char *opt, const char *optarg, } auto &memcachedconf = mod_config()->tls.session_cache.memcached; - memcachedconf.host = strcopy(host); + memcachedconf.host = host; memcachedconf.port = port; return 0; @@ -2166,7 +2166,7 @@ int parse_config(const char *opt, const char *optarg, } auto &memcachedconf = mod_config()->tls.ticket.memcached; - memcachedconf.host = strcopy(host); + memcachedconf.host = host; memcachedconf.port = port; return 0; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index b81f8e1d..e5a21241 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -343,7 +343,9 @@ struct TLSConfig { struct { Address addr; uint16_t port; - std::unique_ptr host; + // Hostname of memcached server. This is also used as SNI field + // if TLS is enabled. + ImmutableString host; // Client private key and certificate for authentication ImmutableString private_key_file; ImmutableString cert_file; @@ -370,7 +372,9 @@ struct TLSConfig { struct { Address addr; uint16_t port; - std::unique_ptr host; + // Hostname of memcached server. This is also used as SNI field + // if TLS is enabled. + ImmutableString host; // Client private key and certificate for authentication ImmutableString private_key_file; ImmutableString cert_file; diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index 5d8a2360..afbcbb15 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -485,7 +485,7 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file SSL_CTX_set_session_id_context(ssl_ctx, sid_ctx, sizeof(sid_ctx) - 1); SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_SERVER); - if (tlsconf.session_cache.memcached.host) { + if (!tlsconf.session_cache.memcached.host.empty()) { SSL_CTX_sess_set_new_cb(ssl_ctx, tls_session_new_cb); SSL_CTX_sess_set_get_cb(ssl_ctx, tls_session_get_cb); } diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index e663eace..83cfff9b 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -91,11 +91,11 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx, auto &session_cacheconf = get_config()->tls.session_cache; - if (session_cacheconf.memcached.host) { + if (!session_cacheconf.memcached.host.empty()) { session_cache_memcached_dispatcher_ = make_unique( &session_cacheconf.memcached.addr, loop, tls_session_cache_memcached_ssl_ctx, - session_cacheconf.memcached.host.get(), &mcpool_); + StringRef{session_cacheconf.memcached.host}, &mcpool_); } auto &downstreamconf = get_config()->conn.downstream; diff --git a/src/shrpx_worker_process.cc b/src/shrpx_worker_process.cc index 26863d82..f7dacc7c 100644 --- a/src/shrpx_worker_process.cc +++ b/src/shrpx_worker_process.cc @@ -427,7 +427,7 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { auto &ticketconf = get_config()->tls.ticket; auto &memcachedconf = ticketconf.memcached; - if (ticketconf.memcached.host) { + if (!memcachedconf.host.empty()) { SSL_CTX *ssl_ctx = nullptr; if (memcachedconf.tls) { @@ -437,7 +437,7 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { conn_handler.set_tls_ticket_key_memcached_dispatcher( make_unique( &ticketconf.memcached.addr, loop, ssl_ctx, - StringRef(memcachedconf.host.get()), &mcpool)); + StringRef{memcachedconf.host}, &mcpool)); ev_timer_init(&renew_ticket_key_timer, memcached_get_ticket_key_cb, 0., 0.);