nghttpx: Add BlockAllocator version of util::formax_hex
This commit is contained in:
parent
5e03b6a0db
commit
e1a865c406
|
@ -178,6 +178,7 @@ int main(int argc, char *argv[]) {
|
||||||
!CU_add_test(pSuite, "util_strifind", shrpx::test_util_strifind) ||
|
!CU_add_test(pSuite, "util_strifind", shrpx::test_util_strifind) ||
|
||||||
!CU_add_test(pSuite, "util_random_alpha_digit",
|
!CU_add_test(pSuite, "util_random_alpha_digit",
|
||||||
shrpx::test_util_random_alpha_digit) ||
|
shrpx::test_util_random_alpha_digit) ||
|
||||||
|
!CU_add_test(pSuite, "util_format_hex", shrpx::test_util_format_hex) ||
|
||||||
!CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) ||
|
!CU_add_test(pSuite, "gzip_inflate", test_nghttp2_gzip_inflate) ||
|
||||||
!CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) ||
|
!CU_add_test(pSuite, "buffer_write", nghttp2::test_buffer_write) ||
|
||||||
!CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) ||
|
!CU_add_test(pSuite, "pool_recycle", nghttp2::test_pool_recycle) ||
|
||||||
|
|
|
@ -1522,4 +1522,6 @@ void ClientHandler::set_tls_sni(const StringRef &sni) {
|
||||||
|
|
||||||
StringRef ClientHandler::get_tls_sni() const { return sni_; }
|
StringRef ClientHandler::get_tls_sni() const { return sni_; }
|
||||||
|
|
||||||
|
BlockAllocator &ClientHandler::get_block_allocator() { return balloc_; }
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
|
@ -162,6 +162,8 @@ public:
|
||||||
// Returns TLS SNI extension value client sent in this connection.
|
// Returns TLS SNI extension value client sent in this connection.
|
||||||
StringRef get_tls_sni() const;
|
StringRef get_tls_sni() const;
|
||||||
|
|
||||||
|
BlockAllocator &get_block_allocator();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BlockAllocator balloc_;
|
BlockAllocator balloc_;
|
||||||
Connection conn_;
|
Connection conn_;
|
||||||
|
|
|
@ -243,6 +243,7 @@ int tls_session_new_cb(SSL *ssl, SSL_SESSION *session) {
|
||||||
auto handler = static_cast<ClientHandler *>(conn->data);
|
auto handler = static_cast<ClientHandler *>(conn->data);
|
||||||
auto worker = handler->get_worker();
|
auto worker = handler->get_worker();
|
||||||
auto dispatcher = worker->get_session_cache_memcached_dispatcher();
|
auto dispatcher = worker->get_session_cache_memcached_dispatcher();
|
||||||
|
auto &balloc = handler->get_block_allocator();
|
||||||
|
|
||||||
const unsigned char *id;
|
const unsigned char *id;
|
||||||
unsigned int idlen;
|
unsigned int idlen;
|
||||||
|
@ -256,7 +257,8 @@ int tls_session_new_cb(SSL *ssl, SSL_SESSION *session) {
|
||||||
auto req = make_unique<MemcachedRequest>();
|
auto req = make_unique<MemcachedRequest>();
|
||||||
req->op = MEMCACHED_OP_ADD;
|
req->op = MEMCACHED_OP_ADD;
|
||||||
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
||||||
req->key += util::format_hex(id, idlen);
|
req->key +=
|
||||||
|
util::format_hex(balloc, StringRef{id, static_cast<size_t>(idlen)});
|
||||||
|
|
||||||
auto sessionlen = i2d_SSL_SESSION(session, nullptr);
|
auto sessionlen = i2d_SSL_SESSION(session, nullptr);
|
||||||
req->value.resize(sessionlen);
|
req->value.resize(sessionlen);
|
||||||
|
@ -295,6 +297,7 @@ SSL_SESSION *tls_session_get_cb(SSL *ssl,
|
||||||
auto handler = static_cast<ClientHandler *>(conn->data);
|
auto handler = static_cast<ClientHandler *>(conn->data);
|
||||||
auto worker = handler->get_worker();
|
auto worker = handler->get_worker();
|
||||||
auto dispatcher = worker->get_session_cache_memcached_dispatcher();
|
auto dispatcher = worker->get_session_cache_memcached_dispatcher();
|
||||||
|
auto &balloc = handler->get_block_allocator();
|
||||||
|
|
||||||
if (conn->tls.cached_session) {
|
if (conn->tls.cached_session) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
|
@ -318,7 +321,8 @@ SSL_SESSION *tls_session_get_cb(SSL *ssl,
|
||||||
auto req = make_unique<MemcachedRequest>();
|
auto req = make_unique<MemcachedRequest>();
|
||||||
req->op = MEMCACHED_OP_GET;
|
req->op = MEMCACHED_OP_GET;
|
||||||
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
req->key = MEMCACHED_SESSION_CACHE_KEY_PREFIX.str();
|
||||||
req->key += util::format_hex(id, idlen);
|
req->key +=
|
||||||
|
util::format_hex(balloc, StringRef{id, static_cast<size_t>(idlen)});
|
||||||
req->cb = [conn](MemcachedRequest *, MemcachedResult res) {
|
req->cb = [conn](MemcachedRequest *, MemcachedResult res) {
|
||||||
if (LOG_ENABLED(INFO)) {
|
if (LOG_ENABLED(INFO)) {
|
||||||
LOG(INFO) << "Memcached: returned status code " << res.status_code;
|
LOG(INFO) << "Memcached: returned status code " << res.status_code;
|
||||||
|
|
15
src/util.cc
15
src/util.cc
|
@ -379,6 +379,21 @@ std::string format_hex(const unsigned char *s, size_t len) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringRef format_hex(BlockAllocator &balloc, const StringRef &s) {
|
||||||
|
auto iov = make_byte_ref(balloc, s.size() * 2 + 1);
|
||||||
|
auto p = iov.base;
|
||||||
|
|
||||||
|
for (auto cc : s) {
|
||||||
|
uint8_t c = cc;
|
||||||
|
*p++ = LOWER_XDIGITS[c >> 4];
|
||||||
|
*p++ = LOWER_XDIGITS[c & 0xf];
|
||||||
|
}
|
||||||
|
|
||||||
|
*p = '\0';
|
||||||
|
|
||||||
|
return StringRef{iov.base, p};
|
||||||
|
}
|
||||||
|
|
||||||
void to_token68(std::string &base64str) {
|
void to_token68(std::string &base64str) {
|
||||||
std::transform(std::begin(base64str), std::end(base64str),
|
std::transform(std::begin(base64str), std::end(base64str),
|
||||||
std::begin(base64str), [](char c) {
|
std::begin(base64str), [](char c) {
|
||||||
|
|
|
@ -145,6 +145,8 @@ template <size_t N> std::string format_hex(const std::array<uint8_t, N> &s) {
|
||||||
return format_hex(s.data(), s.size());
|
return format_hex(s.data(), s.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringRef format_hex(BlockAllocator &balloc, const StringRef &s);
|
||||||
|
|
||||||
std::string http_date(time_t t);
|
std::string http_date(time_t t);
|
||||||
|
|
||||||
// Returns given time |t| from epoch in Common Log format (e.g.,
|
// Returns given time |t| from epoch in Common Log format (e.g.,
|
||||||
|
|
|
@ -552,4 +552,12 @@ void test_util_random_alpha_digit(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_util_format_hex(void) {
|
||||||
|
BlockAllocator balloc(4096, 4096);
|
||||||
|
|
||||||
|
CU_ASSERT("0ff0" ==
|
||||||
|
util::format_hex(balloc, StringRef::from_lit("\x0f\xf0")));
|
||||||
|
CU_ASSERT("" == util::format_hex(balloc, StringRef::from_lit("")));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
|
@ -63,6 +63,7 @@ void test_util_make_http_hostport(void);
|
||||||
void test_util_make_hostport(void);
|
void test_util_make_hostport(void);
|
||||||
void test_util_strifind(void);
|
void test_util_strifind(void);
|
||||||
void test_util_random_alpha_digit(void);
|
void test_util_random_alpha_digit(void);
|
||||||
|
void test_util_format_hex(void);
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue