diff --git a/.clang-format b/.clang-format index 0a415c6b..668693a5 100644 --- a/.clang-format +++ b/.clang-format @@ -78,6 +78,7 @@ PointerAlignment: Right ReflowComments: true SortIncludes: false SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true SpaceBeforeAssignmentOperators: true SpaceBeforeParens: ControlStatements SpaceInEmptyParentheses: false diff --git a/doc/sources/contribute.rst b/doc/sources/contribute.rst index c2d301dd..059d0c4b 100644 --- a/doc/sources/contribute.rst +++ b/doc/sources/contribute.rst @@ -26,8 +26,7 @@ Coding style We use clang-format to format source code consistently. The clang-format configuration file .clang-format is located at the root directory. Since clang-format produces slightly different results -between versions, we currently use clang-format which comes with -clang-3.9. +between versions, we currently use clang-format 4.0. To detect any violation to the coding style, we recommend to setup git pre-commit hook to check coding style of the changes you introduced. @@ -35,7 +34,7 @@ The pre-commit file is located at the root directory. Copy it under .git/hooks and make sure that it is executable. The pre-commit script uses clang-format-diff.py to detect any style errors. If it is not in your PATH or it exists under different name (e.g., -clang-format-diff-3.9 in debian), either add it to PATH variable or +clang-format-diff-4.0 in debian), either add it to PATH variable or add git option ``clangformatdiff.binary`` to point to the script. For emacs users, integrating clang-format to emacs is very easy. diff --git a/lib/nghttp2_hd.c b/lib/nghttp2_hd.c index e9a109dc..1eb3be33 100644 --- a/lib/nghttp2_hd.c +++ b/lib/nghttp2_hd.c @@ -662,9 +662,9 @@ static int hd_context_init(nghttp2_hd_context *context, nghttp2_mem *mem) { context->mem = mem; context->bad = 0; context->hd_table_bufsize_max = NGHTTP2_HD_DEFAULT_MAX_BUFFER_SIZE; - rv = hd_ringbuf_init(&context->hd_table, context->hd_table_bufsize_max / - NGHTTP2_HD_ENTRY_OVERHEAD, - mem); + rv = hd_ringbuf_init( + &context->hd_table, + context->hd_table_bufsize_max / NGHTTP2_HD_ENTRY_OVERHEAD, mem); if (rv != 0) { return rv; } diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index d4408ab3..ea7bfa0e 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -5590,8 +5590,8 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, iframe->max_niv = iframe->frame.hd.length / NGHTTP2_FRAME_SETTINGS_ENTRY_LENGTH + 1; - iframe->iv = nghttp2_mem_malloc(mem, sizeof(nghttp2_settings_entry) * - iframe->max_niv); + iframe->iv = nghttp2_mem_malloc( + mem, sizeof(nghttp2_settings_entry) * iframe->max_niv); if (!iframe->iv) { return NGHTTP2_ERR_NOMEM; @@ -6054,9 +6054,10 @@ ssize_t nghttp2_session_mem_recv(nghttp2_session *session, const uint8_t *in, /* Use promised stream ID for PUSH_PROMISE */ rv = nghttp2_session_add_rst_stream( - session, iframe->frame.hd.type == NGHTTP2_PUSH_PROMISE - ? iframe->frame.push_promise.promised_stream_id - : iframe->frame.hd.stream_id, + session, + iframe->frame.hd.type == NGHTTP2_PUSH_PROMISE + ? iframe->frame.push_promise.promised_stream_id + : iframe->frame.hd.stream_id, NGHTTP2_INTERNAL_ERROR); if (nghttp2_is_fatal(rv)) { return rv; diff --git a/src/HttpServer.cc b/src/HttpServer.cc index deb50d1c..8466fec0 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -2197,8 +2197,9 @@ int HttpServer::run() { return -1; } if (config_->verify_client) { - SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | - SSL_VERIFY_FAIL_IF_NO_PEER_CERT, + SSL_CTX_set_verify(ssl_ctx, + SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | + SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verify_callback); } diff --git a/src/h2load.cc b/src/h2load.cc index 51da4e44..492d8d9f 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -1859,8 +1859,9 @@ int main(int argc, char **argv) { {"encoder-header-table-size", required_argument, &flag, 8}, {nullptr, 0, nullptr, 0}}; int option_index = 0; - auto c = getopt_long(argc, argv, "hvW:c:d:m:n:p:t:w:H:i:r:T:N:B:", - long_options, &option_index); + auto c = + getopt_long(argc, argv, "hvW:c:d:m:n:p:t:w:H:i:r:T:N:B:", long_options, + &option_index); if (c == -1) { break; } diff --git a/src/http2.cc b/src/http2.cc index 5d677ade..9ee1679b 100644 --- a/src/http2.cc +++ b/src/http2.cc @@ -448,9 +448,9 @@ void copy_headers_to_nva(std::vector &nva, void copy_headers_to_nva_nocopy(std::vector &nva, const HeaderRefs &headers, uint32_t flags) { - copy_headers_to_nva_internal(nva, headers, NGHTTP2_NV_FLAG_NO_COPY_NAME | - NGHTTP2_NV_FLAG_NO_COPY_VALUE, - flags); + copy_headers_to_nva_internal( + nva, headers, + NGHTTP2_NV_FLAG_NO_COPY_NAME | NGHTTP2_NV_FLAG_NO_COPY_VALUE, flags); } void build_http1_headers_from_headers(DefaultMemchunks *buf, @@ -1624,9 +1624,9 @@ StringRef path_join(BlockAllocator &balloc, const StringRef &base_path, const StringRef &base_query, const StringRef &rel_path, const StringRef &rel_query) { auto res = make_byte_ref( - balloc, std::max(static_cast(1), base_path.size()) + - rel_path.size() + 1 + - std::max(base_query.size(), rel_query.size()) + 1); + balloc, + std::max(static_cast(1), base_path.size()) + rel_path.size() + 1 + + std::max(base_query.size(), rel_query.size()) + 1); auto p = res.base; if (rel_path.empty()) { diff --git a/src/nghttp.cc b/src/nghttp.cc index ef120572..84b0ddda 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -2791,8 +2791,9 @@ int main(int argc, char **argv) { {"encoder-header-table-size", required_argument, &flag, 14}, {nullptr, 0, nullptr, 0}}; int option_index = 0; - int c = getopt_long(argc, argv, "M:Oab:c:d:m:np:r:hH:vst:uw:yW:", - long_options, &option_index); + int c = + getopt_long(argc, argv, "M:Oab:c:d:m:np:r:hH:vst:uw:yW:", long_options, + &option_index); if (c == -1) { break; } diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 558f6220..56876738 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -816,9 +816,9 @@ int on_stream_close_callback(nghttp2_session *session, int32_t stream_id, uint32_t error_code, void *user_data) { auto http2session = static_cast(user_data); if (LOG_ENABLED(INFO)) { - SSLOG(INFO, http2session) << "Stream stream_id=" << stream_id - << " is being closed with error code " - << error_code; + SSLOG(INFO, http2session) + << "Stream stream_id=" << stream_id + << " is being closed with error code " << error_code; } auto sd = static_cast( nghttp2_session_get_stream_user_data(session, stream_id)); @@ -1152,8 +1152,8 @@ int on_response_headers(Http2Session *http2session, Downstream *downstream, } downstream->set_request_state(Downstream::HEADER_COMPLETE); if (LOG_ENABLED(INFO)) { - SSLOG(INFO, http2session) << "HTTP upgrade success. stream_id=" - << frame->hd.stream_id; + SSLOG(INFO, http2session) + << "HTTP upgrade success. stream_id=" << frame->hd.stream_id; } } else { auto content_length = resp.fs.header(http2::HD_CONTENT_LENGTH); diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 905de09f..561fcbe3 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -1006,8 +1006,8 @@ int ensure_max_header_fields(const Downstream *downstream, if (resp.fs.num_fields() >= httpconf.max_response_header_fields) { if (LOG_ENABLED(INFO)) { - DLOG(INFO, downstream) << "Too many header field num=" - << resp.fs.num_fields() + 1; + DLOG(INFO, downstream) + << "Too many header field num=" << resp.fs.num_fields() + 1; } return -1; } diff --git a/src/shrpx_http_test.cc b/src/shrpx_http_test.cc index a93ab9e4..eaf67adc 100644 --- a/src/shrpx_http_test.cc +++ b/src/shrpx_http_test.cc @@ -43,8 +43,9 @@ void test_shrpx_http_create_forwarded(void) { CU_ASSERT("by=\"example.com:3000\";for=\"[::1]\";host=\"www.example.com\";" "proto=https" == - http::create_forwarded(balloc, FORWARDED_BY | FORWARDED_FOR | - FORWARDED_HOST | FORWARDED_PROTO, + http::create_forwarded(balloc, + FORWARDED_BY | FORWARDED_FOR | + FORWARDED_HOST | FORWARDED_PROTO, StringRef::from_lit("example.com:3000"), StringRef::from_lit("[::1]"), StringRef::from_lit("www.example.com"), @@ -68,11 +69,12 @@ void test_shrpx_http_create_forwarded(void) { StringRef::from_lit("[::1]"), StringRef::from_lit("_hidden"), StringRef::from_lit(""), StringRef::from_lit(""))); - CU_ASSERT("" == http::create_forwarded( - balloc, FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | - FORWARDED_PROTO, - StringRef::from_lit(""), StringRef::from_lit(""), - StringRef::from_lit(""), StringRef::from_lit(""))); + CU_ASSERT("" == + http::create_forwarded( + balloc, + FORWARDED_BY | FORWARDED_FOR | FORWARDED_HOST | FORWARDED_PROTO, + StringRef::from_lit(""), StringRef::from_lit(""), + StringRef::from_lit(""), StringRef::from_lit(""))); } void test_shrpx_http_create_via_header_value(void) { diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index e5239d7d..976904ed 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -150,8 +150,8 @@ int htp_hdr_keycb(http_parser *htp, const char *data, size_t len) { } else { if (req.fs.num_fields() >= httpconf.max_request_header_fields) { if (LOG_ENABLED(INFO)) { - ULOG(INFO, upstream) << "Too many header field num=" - << req.fs.num_fields() + 1; + ULOG(INFO, upstream) + << "Too many header field num=" << req.fs.num_fields() + 1; } downstream->set_request_state( Downstream::HTTP1_REQUEST_HEADER_TOO_LARGE); @@ -166,8 +166,8 @@ int htp_hdr_keycb(http_parser *htp, const char *data, size_t len) { } else { if (req.fs.num_fields() >= httpconf.max_request_header_fields) { if (LOG_ENABLED(INFO)) { - ULOG(INFO, upstream) << "Too many header field num=" - << req.fs.num_fields() + 1; + ULOG(INFO, upstream) + << "Too many header field num=" << req.fs.num_fields() + 1; } return -1; } diff --git a/src/shrpx_log.h b/src/shrpx_log.h index 974c8de6..3a923778 100644 --- a/src/shrpx_log.h +++ b/src/shrpx_log.h @@ -62,14 +62,14 @@ using namespace nghttp2; // Upstream log #define ULOG(SEVERITY, UPSTREAM) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[UPSTREAM:" << UPSTREAM \ - << "]" \ - " ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) \ + << "[UPSTREAM:" << UPSTREAM << "]" \ + " ") // Downstream log #define DLOG(SEVERITY, DOWNSTREAM) \ - (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[DOWNSTREAM:" << DOWNSTREAM \ - << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) \ + << "[DOWNSTREAM:" << DOWNSTREAM << "] ") // Downstream connection log #define DCLOG(SEVERITY, DCONN) \ diff --git a/src/shrpx_memcached_connection.cc b/src/shrpx_memcached_connection.cc index c5e79ce2..d087ac83 100644 --- a/src/shrpx_memcached_connection.cc +++ b/src/shrpx_memcached_connection.cc @@ -538,8 +538,8 @@ int MemcachedConnection::parse_packet() { if (LOG_ENABLED(INFO)) { if (parse_state_.status_code) { - MCLOG(INFO, this) << "response returned error status: " - << parse_state_.status_code; + MCLOG(INFO, this) + << "response returned error status: " << parse_state_.status_code; } } diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 47a0af39..904d0839 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -880,8 +880,8 @@ ssize_t spdy_data_read_callback(spdylay_session *session, int32_t stream_id, } else { // For tunneling, issue RST_STREAM to finish the stream. if (LOG_ENABLED(INFO)) { - ULOG(INFO, upstream) << "RST_STREAM to tunneled stream stream_id=" - << stream_id; + ULOG(INFO, upstream) + << "RST_STREAM to tunneled stream stream_id=" << stream_id; } upstream->rst_stream( downstream, infer_upstream_rst_stream_status_code( diff --git a/src/shrpx_tls.cc b/src/shrpx_tls.cc index 7d70b167..ff342b57 100644 --- a/src/shrpx_tls.cc +++ b/src/shrpx_tls.cc @@ -857,8 +857,9 @@ SSL_CTX *create_ssl_context(const char *private_key_file, const char *cert_file, } SSL_CTX_set_client_CA_list(ssl_ctx, list); } - SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | - SSL_VERIFY_FAIL_IF_NO_PEER_CERT, + SSL_CTX_set_verify(ssl_ctx, + SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | + SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verify_callback); } SSL_CTX_set_tlsext_servername_callback(ssl_ctx, servername_callback); @@ -996,8 +997,8 @@ SSL_CTX *create_ssl_client_context( SSL_CTX_set_options(ssl_ctx, ssl_opts | tlsconf.tls_proto_mask); - SSL_CTX_set_session_cache_mode(ssl_ctx, SSL_SESS_CACHE_CLIENT | - SSL_SESS_CACHE_NO_INTERNAL_STORE); + SSL_CTX_set_session_cache_mode( + ssl_ctx, SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_NO_INTERNAL_STORE); SSL_CTX_sess_set_new_cb(ssl_ctx, tls_session_client_new_cb); if (nghttp2::tls::ssl_ctx_set_proto_versions( diff --git a/tests/nghttp2_hd_test.c b/tests/nghttp2_hd_test.c index 2f77a7a4..0408bf59 100644 --- a/tests/nghttp2_hd_test.c +++ b/tests/nghttp2_hd_test.c @@ -295,10 +295,11 @@ void test_nghttp2_hd_inflate_indname_inc(void) { assert_nv_equal(&nv, out.nva, 1, mem); CU_ASSERT(1 == inflater.ctx.hd_table.len); CU_ASSERT(62 == nghttp2_hd_inflate_get_num_table_entries(&inflater)); - assert_nv_equal(&nv, nghttp2_hd_inflate_get_table_entry( - &inflater, NGHTTP2_STATIC_TABLE_LENGTH + - inflater.ctx.hd_table.len), - 1, mem); + assert_nv_equal( + &nv, + nghttp2_hd_inflate_get_table_entry( + &inflater, NGHTTP2_STATIC_TABLE_LENGTH + inflater.ctx.hd_table.len), + 1, mem); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); @@ -424,10 +425,11 @@ void test_nghttp2_hd_inflate_newname_inc(void) { CU_ASSERT(1 == out.nvlen); assert_nv_equal(&nv, out.nva, 1, mem); CU_ASSERT(1 == inflater.ctx.hd_table.len); - assert_nv_equal(&nv, nghttp2_hd_inflate_get_table_entry( - &inflater, NGHTTP2_STATIC_TABLE_LENGTH + - inflater.ctx.hd_table.len), - 1, mem); + assert_nv_equal( + &nv, + nghttp2_hd_inflate_get_table_entry( + &inflater, NGHTTP2_STATIC_TABLE_LENGTH + inflater.ctx.hd_table.len), + 1, mem); nva_out_reset(&out, mem); nghttp2_bufs_free(&bufs); diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 28ca0ac6..f01571a8 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -6484,8 +6484,8 @@ void test_nghttp2_session_flow_control_data_recv(void) { nghttp2_frame_pack_frame_hd(data, &hd); CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == - nghttp2_session_mem_recv(session, data, NGHTTP2_MAX_PAYLOADLEN + - NGHTTP2_FRAME_HDLEN)); + nghttp2_session_mem_recv( + session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); /* Since this is the last frame, stream-level WINDOW_UPDATE is not @@ -6503,8 +6503,8 @@ void test_nghttp2_session_flow_control_data_recv(void) { sending DATA frames. Without calculating connection-level window, the subsequent flow control gets confused. */ CU_ASSERT(NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN == - nghttp2_session_mem_recv(session, data, NGHTTP2_MAX_PAYLOADLEN + - NGHTTP2_FRAME_HDLEN)); + nghttp2_session_mem_recv( + session, data, NGHTTP2_MAX_PAYLOADLEN + NGHTTP2_FRAME_HDLEN)); item = nghttp2_session_get_next_ob_item(session); CU_ASSERT(NGHTTP2_WINDOW_UPDATE == item->frame.hd.type);