/src/h2o/lib/handler/status/ssl.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2018 Fastly Inc, Ichito Nagata |
3 | | * |
4 | | * Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | | * of this software and associated documentation files (the "Software"), to |
6 | | * deal in the Software without restriction, including without limitation the |
7 | | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
8 | | * sell copies of the Software, and to permit persons to whom the Software is |
9 | | * furnished to do so, subject to the following conditions: |
10 | | * |
11 | | * The above copyright notice and this permission notice shall be included in |
12 | | * all copies or substantial portions of the Software. |
13 | | * |
14 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17 | | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
19 | | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
20 | | * IN THE SOFTWARE. |
21 | | */ |
22 | | |
23 | | #include "h2o.h" |
24 | | #include <inttypes.h> |
25 | | |
26 | | struct st_ssl_status_ctx_t { |
27 | | uint64_t alpn_h1; |
28 | | uint64_t alpn_h2; |
29 | | uint64_t handshake_full; |
30 | | uint64_t handshake_resume; |
31 | | uint64_t handshake_accum_time_full; |
32 | | uint64_t handshake_accum_time_resume; |
33 | | pthread_mutex_t mutex; |
34 | | }; |
35 | | |
36 | | static void ssl_status_per_thread(void *_ssc, h2o_context_t *ctx) |
37 | 0 | { |
38 | 0 | struct st_ssl_status_ctx_t *ssc = _ssc; |
39 | |
|
40 | 0 | pthread_mutex_lock(&ssc->mutex); |
41 | |
|
42 | 0 | ssc->alpn_h1 += ctx->ssl.alpn_h1; |
43 | 0 | ssc->alpn_h2 += ctx->ssl.alpn_h2; |
44 | 0 | ssc->handshake_full += ctx->ssl.handshake_full; |
45 | 0 | ssc->handshake_resume += ctx->ssl.handshake_resume; |
46 | 0 | ssc->handshake_accum_time_full += ctx->ssl.handshake_accum_time_full; |
47 | 0 | ssc->handshake_accum_time_resume += ctx->ssl.handshake_accum_time_resume; |
48 | |
|
49 | 0 | pthread_mutex_unlock(&ssc->mutex); |
50 | 0 | } |
51 | | |
52 | | static void *ssl_status_init(void) |
53 | 0 | { |
54 | 0 | struct st_ssl_status_ctx_t *ssc = h2o_mem_alloc(sizeof(*ssc)); |
55 | 0 | *ssc = (struct st_ssl_status_ctx_t){0}; |
56 | 0 | pthread_mutex_init(&ssc->mutex, NULL); |
57 | 0 | return ssc; |
58 | 0 | } |
59 | | |
60 | | static h2o_iovec_t ssl_status_final(void *_ssc, h2o_globalconf_t *globalconf, h2o_req_t *req) |
61 | 0 | { |
62 | 0 | struct st_ssl_status_ctx_t *ssc = _ssc; |
63 | 0 | h2o_iovec_t buf; |
64 | |
|
65 | 0 | #define BUFSIZE (1024) |
66 | 0 | buf.base = h2o_mem_alloc_pool(&req->pool, char, BUFSIZE); |
67 | 0 | buf.len = snprintf(buf.base, BUFSIZE, |
68 | 0 | ",\n" |
69 | 0 | " \"ssl.alpn.h1\": %" PRIu64 ",\n" |
70 | 0 | " \"ssl.alpn.h2\": %" PRIu64 ",\n" |
71 | 0 | " \"ssl.handshake.full\": %" PRIu64 ",\n" |
72 | 0 | " \"ssl.handshake.resume\": %" PRIu64 ",\n" |
73 | 0 | " \"ssl.handshake.accumulated-time.full\": %" PRIu64 ",\n" |
74 | 0 | " \"ssl.handshake.accumulated-time.resume\": %" PRIu64 "\n", |
75 | 0 | ssc->alpn_h1, ssc->alpn_h2, ssc->handshake_full, ssc->handshake_resume, ssc->handshake_accum_time_full, |
76 | 0 | ssc->handshake_accum_time_resume); |
77 | 0 | pthread_mutex_destroy(&ssc->mutex); |
78 | 0 | free(ssc); |
79 | 0 | return buf; |
80 | 0 | #undef BUFSIZE |
81 | 0 | } |
82 | | |
83 | | h2o_status_handler_t h2o_ssl_status_handler = {{H2O_STRLIT("ssl")}, ssl_status_final, ssl_status_init, ssl_status_per_thread}; |