libmicrohttpd2

HTTP server C library (MHD 2.x, alpha)
Log | Files | Refs | README | LICENSE

commit 569d0bab033bece386135416bca564c120b41b48
parent 5203e874ff4e07b191ca21862f166632d170715f
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date:   Tue,  7 Jul 2026 02:08:24 +0200

Update and apply uncrustify configuration

Diffstat:
Mcontrib/uncrustify.cfg | 115++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Mdoc/examples/basic-authentication.c | 2+-
Mdoc/examples/basicauthentication.c | 34+++++++++++++++++-----------------
Mdoc/examples/external-select.c | 14+++++++-------
Mdoc/examples/hellobrowser.c | 22+++++++++++-----------
Mdoc/examples/host-example.c | 2+-
Mdoc/examples/init-example.c | 2+-
Mdoc/examples/largepost.c | 42+++++++++++++++++++++---------------------
Mdoc/examples/logging.c | 22+++++++++++-----------
Mdoc/examples/options-example.c | 2+-
Mdoc/examples/responseheaders.c | 28++++++++++++++--------------
Mdoc/examples/sessions.c | 84++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mdoc/examples/simplepost.c | 40++++++++++++++++++++--------------------
Mdoc/examples/tlsauthentication.c | 42+++++++++++++++++++++---------------------
Mdoc/examples/websocket.c | 28++++++++++++++--------------
Msrc/examples2/demo.c | 316++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/examples2/json_echo.c | 56++++++++++++++++++++++++++++----------------------------
Msrc/examples2/minimal_auth_basic.c | 28++++++++++++++--------------
Msrc/examples2/minimal_auth_digest.c | 38+++++++++++++++++++-------------------
Msrc/examples2/minimal_example2.c | 12++++++------
Msrc/incl_priv/autoinit_funcs.h | 227++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/incl_priv/mhd_sys_options.h | 94++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/d_options.rec | 10+++++-----
Msrc/include/mhd_future.h | 21++++++++++-----------
Msrc/include/microhttpd2.h | 358++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/microhttpd2_main.h.in | 224++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/microhttpd2_portability.h | 226++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/microhttpd2_preamble.h.in | 134++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/include/options-generator.c | 68++++++++++++++++++++++++++++++++++----------------------------------
Msrc/include/r_options.rec | 2+-
Msrc/mhd2/action.c | 109+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/mhd2/auth_basic.c | 14+++++++-------
Msrc/mhd2/auth_basic.h | 4++--
Msrc/mhd2/auth_digest.c | 508++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/auth_digest.h | 4++--
Msrc/mhd2/compat_calloc.c | 22+++++++++++-----------
Msrc/mhd2/conn_data_process.c | 52++++++++++++++++++++++++++--------------------------
Msrc/mhd2/conn_data_recv.c | 38+++++++++++++++++++-------------------
Msrc/mhd2/conn_data_send.c | 62+++++++++++++++++++++++++++++++-------------------------------
Msrc/mhd2/conn_get_info.c | 14+++++++-------
Msrc/mhd2/conn_mark_ready.h | 24++++++++++++------------
Msrc/mhd2/conn_timeout.c | 34+++++++++++++++++-----------------
Msrc/mhd2/conn_tls_check.c | 18+++++++++---------
Msrc/mhd2/daemon_add_conn.c | 240++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/daemon_create.c | 8++++----
Msrc/mhd2/daemon_event_update.c | 28++++++++++++++--------------
Msrc/mhd2/daemon_funcs.c | 24++++++++++++------------
Msrc/mhd2/daemon_funcs.h | 8++++----
Msrc/mhd2/daemon_get_info.c | 20++++++++++----------
Msrc/mhd2/daemon_logger.c | 8++++----
Msrc/mhd2/daemon_logger.h | 32+++++++++++++++++---------------
Msrc/mhd2/daemon_logger_default.c | 20++++++++++----------
Msrc/mhd2/daemon_logger_default.h | 8++++----
Msrc/mhd2/daemon_set_options.c | 10+++++-----
Msrc/mhd2/daemon_start.c | 838++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/dcc_action.c | 2+-
Msrc/mhd2/events_process.c | 651++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/extr_events_funcs.c | 2+-
Msrc/mhd2/extr_events_funcs.h | 18+++++++++---------
Msrc/mhd2/h2/h2_action.c | 18+++++++++---------
Msrc/mhd2/h2/h2_app_cb.c | 30+++++++++++++++---------------
Msrc/mhd2/h2/h2_comm.c | 54+++++++++++++++++++++++++++---------------------------
Msrc/mhd2/h2/h2_comm.h | 2+-
Msrc/mhd2/h2/h2_conn_data.h | 4++--
Msrc/mhd2/h2/h2_conn_streams.c | 100++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/h2/h2_conn_streams.h | 4++--
Msrc/mhd2/h2/h2_frame_codec.c | 164++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/h2/h2_frame_codec.h | 14+++++++-------
Msrc/mhd2/h2/h2_frame_init.h | 22+++++++++++-----------
Msrc/mhd2/h2/h2_proc_conn.c | 36++++++++++++++++++------------------
Msrc/mhd2/h2/h2_proc_in.c | 26+++++++++++++-------------
Msrc/mhd2/h2/h2_proc_out.c | 14+++++++-------
Msrc/mhd2/h2/h2_proc_settings.c | 29+++++++++++++++--------------
Msrc/mhd2/h2/h2_reply_funcs.c | 150++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/h2/h2_req_fields.c | 116++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/h2/h2_req_fields.h | 4++--
Msrc/mhd2/h2/h2_req_get_items.c | 40++++++++++++++++++++--------------------
Msrc/mhd2/h2/h2_req_get_items.h | 2+-
Msrc/mhd2/h2/h2_req_items_funcs.c | 47++++++++++++++++++++++++-----------------------
Msrc/mhd2/h2/h2_req_items_funcs.h | 4++--
Msrc/mhd2/h2/h2_settings.h | 10+++++-----
Msrc/mhd2/h2/hpack/h2_huffman_codec.c | 183++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/h2/hpack/h2_huffman_codec.h | 4++--
Msrc/mhd2/h2/hpack/h2_huffman_est.h | 8++++----
Msrc/mhd2/h2/hpack/mhd_hpack_codec.c | 864++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/h2/hpack/mhd_hpack_codec.h | 20++++++++++----------
Msrc/mhd2/http_method.h | 2+-
Msrc/mhd2/http_prot_ver.h | 2+-
Msrc/mhd2/http_status_str.c | 4++--
Msrc/mhd2/lib_get_info.c | 50+++++++++++++++++++++++++-------------------------
Msrc/mhd2/md5_ext.h | 2+-
Msrc/mhd2/md5_ext_mbedtls.c | 2+-
Msrc/mhd2/md5_int.c | 88++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mempool_funcs.c | 160++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/mhd_action.h | 16++++++++--------
Msrc/mhd2/mhd_align.h | 12++++++------
Msrc/mhd2/mhd_assert.h | 30+++++++++++++++---------------
Msrc/mhd2/mhd_assume.h | 8++++----
Msrc/mhd2/mhd_atomic_counter.c | 6+++---
Msrc/mhd2/mhd_atomic_counter.h | 85++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/mhd_auth_digest_hdr.h | 2+-
Msrc/mhd2/mhd_bithelpers.h | 442++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_bool.h | 2+-
Msrc/mhd2/mhd_byteorder.h | 18+++++++++---------
Msrc/mhd2/mhd_cntnr_ptr.h | 12++++++------
Msrc/mhd2/mhd_conn_socket.h | 8++++----
Msrc/mhd2/mhd_connection.h | 12++++++------
Msrc/mhd2/mhd_daemon.h | 84++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_dbg_print.h | 13+++++++------
Msrc/mhd2/mhd_dcc_action.h | 6+++---
Msrc/mhd2/mhd_dlinked_list.h | 207+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_iovec.h | 18+++++++++---------
Msrc/mhd2/mhd_itc.c | 6+++---
Msrc/mhd2/mhd_itc.h | 82++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_itc_types.h | 6+++---
Msrc/mhd2/mhd_lib_init.c | 46+++++++++++++++++++++++-----------------------
Msrc/mhd2/mhd_lib_init_impl.h | 22+++++++++++-----------
Msrc/mhd2/mhd_limits.h | 12++++++------
Msrc/mhd2/mhd_locks.h | 182++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_md5.h | 26+++++++++++++-------------
Msrc/mhd2/mhd_mono_clock.c | 124++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_panic.c | 4++--
Msrc/mhd2/mhd_panic.h | 50+++++++++++++++++++++++++-------------------------
Msrc/mhd2/mhd_post_result.h | 2+-
Msrc/mhd2/mhd_predict.h | 24++++++++++++------------
Msrc/mhd2/mhd_read_file.c | 54+++++++++++++++++++++++++++---------------------------
Msrc/mhd2/mhd_read_file.h | 2+-
Msrc/mhd2/mhd_recv.c | 16++++++++--------
Msrc/mhd2/mhd_recv.h | 2+-
Msrc/mhd2/mhd_request.h | 22+++++++++++-----------
Msrc/mhd2/mhd_response.h | 12++++++------
Msrc/mhd2/mhd_rng.c | 52++++++++++++++++++++++++++--------------------------
Msrc/mhd2/mhd_rng.h | 2+-
Msrc/mhd2/mhd_send.c | 427++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/mhd_send.h | 6+++---
Msrc/mhd2/mhd_sha256.h | 22+++++++++++-----------
Msrc/mhd2/mhd_sha512_256.h | 24++++++++++++------------
Msrc/mhd2/mhd_socket_error_funcs.c | 6+++---
Msrc/mhd2/mhd_socket_type.h | 2+-
Msrc/mhd2/mhd_sockets_funcs.c | 89++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/mhd_sockets_macros.h | 67+++++++++++++++++++++++++++++++++++--------------------------------
Msrc/mhd2/mhd_str.c | 616++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_str.h | 144++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/mhd_str_types.h | 4++--
Msrc/mhd2/mhd_threads.c | 48++++++++++++++++++++++++------------------------
Msrc/mhd2/mhd_threads.h | 99++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/mhd_tls_choice.h | 16++++++++--------
Msrc/mhd2/mhd_tls_common.h | 2+-
Msrc/mhd2/mhd_tls_enums.h | 2+-
Msrc/mhd2/mhd_tls_funcs.h | 14+++++++-------
Msrc/mhd2/mhd_tls_internal.c | 24++++++++++++------------
Msrc/mhd2/mhd_tls_internal.h | 2+-
Msrc/mhd2/mhd_unreachable.h | 8++++----
Msrc/mhd2/post_parser_funcs.c | 408++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/request_auth_get.c | 24++++++++++++------------
Msrc/mhd2/request_auth_get.h | 4++--
Msrc/mhd2/request_funcs.c | 2+-
Msrc/mhd2/request_get_info.c | 8++++----
Msrc/mhd2/request_get_value.c | 50+++++++++++++++++++++++++-------------------------
Msrc/mhd2/request_get_value.h | 20++++++++++----------
Msrc/mhd2/request_resume.c | 8++++----
Msrc/mhd2/respond_with_error.c | 10+++++-----
Msrc/mhd2/respond_with_error.h | 28++++++++++++++--------------
Msrc/mhd2/response_add_header.c | 48+++++++++++++++++++++++++-----------------------
Msrc/mhd2/response_auth_basic.c | 16++++++++--------
Msrc/mhd2/response_auth_digest.c | 56++++++++++++++++++++++++++++----------------------------
Msrc/mhd2/response_auth_digest.h | 2+-
Msrc/mhd2/response_destroy.c | 4++--
Msrc/mhd2/response_from.c | 38+++++++++++++++++++-------------------
Msrc/mhd2/response_from.h | 2+-
Msrc/mhd2/response_funcs.c | 12++++++------
Msrc/mhd2/response_set_options.c | 4++--
Msrc/mhd2/sckt_recv.c | 8++++----
Msrc/mhd2/sckt_recv.h | 2+-
Msrc/mhd2/sckt_send.h | 2+-
Msrc/mhd2/sha256_ext.h | 54+++++++++++++++++++++++++++---------------------------
Msrc/mhd2/sha256_ext_gnutls.c | 4++--
Msrc/mhd2/sha256_ext_mbedtls.c | 2+-
Msrc/mhd2/sha256_int.c | 191+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/sha512_256_ext.h | 48++++++++++++++++++++++++------------------------
Msrc/mhd2/sha512_256_ext_mbedtls.c | 2+-
Msrc/mhd2/sha512_256_int.c | 209+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/stream_funcs.c | 152++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/stream_funcs.h | 28++++++++++++++--------------
Msrc/mhd2/stream_process_reply.c | 276++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/stream_process_reply.h | 1+
Msrc/mhd2/stream_process_request.c | 742++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/stream_process_request.h | 2+-
Msrc/mhd2/stream_process_states.c | 80++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/sys_file_fd.h | 2+-
Msrc/mhd2/sys_ip_headers.h | 22+++++++++++-----------
Msrc/mhd2/sys_kqueue.h | 24++++++++++++------------
Msrc/mhd2/sys_offsetof.h | 2+-
Msrc/mhd2/sys_poll.h | 2+-
Msrc/mhd2/sys_select.h | 2+-
Msrc/mhd2/sys_sendfile.h | 2+-
Msrc/mhd2/sys_sockets_headers.h | 50+++++++++++++++++++++++++-------------------------
Msrc/mhd2/sys_w32_ver.h | 2+-
Msrc/mhd2/tls_gnu_conn_data.h | 2+-
Msrc/mhd2/tls_gnu_daemon_data.h | 2+-
Msrc/mhd2/tls_gnu_funcs.c | 96++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/tls_gnu_funcs.h | 10+++++-----
Msrc/mhd2/tls_gnu_tls_lib.h | 6+++---
Msrc/mhd2/tls_mbed_conn_data.h | 2+-
Msrc/mhd2/tls_mbed_daemon_data.h | 2+-
Msrc/mhd2/tls_mbed_funcs.c | 302+++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/tls_mbed_funcs.h | 8++++----
Msrc/mhd2/tls_mbed_tls_lib.h | 28+++++++++++++---------------
Msrc/mhd2/tls_multi_conn_data.h | 2+-
Msrc/mhd2/tls_multi_daemon_data.h | 2+-
Msrc/mhd2/tls_multi_funcs.c | 52++++++++++++++++++++++++++--------------------------
Msrc/mhd2/tls_multi_funcs.h | 7++++---
Msrc/mhd2/tls_multi_tls_lib.h | 2+-
Msrc/mhd2/tls_open_conn_data.h | 2+-
Msrc/mhd2/tls_open_daemon_data.h | 2+-
Msrc/mhd2/tls_open_funcs.c | 218++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/mhd2/tls_open_funcs.h | 10+++++-----
Msrc/mhd2/tls_open_tls_lib.h | 8++++----
Msrc/mhd2/upgrade_prep.c | 98++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/mhd2/upgrade_prep.h | 2+-
Msrc/mhd2/upgrade_proc.c | 14+++++++-------
Msrc/mhd2/upgraded_net.c | 136++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tests/basic/test_basic_checks.c | 82+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/tests/basic/test_lib_info_version.c | 81++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/tests/client_server/libtest.c | 66+++++++++++++++++++++++++++++++++---------------------------------
Msrc/tests/client_server/libtest_convenience.c | 134++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tests/client_server/libtest_convenience_client_request.c | 177++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/tests/client_server/libtest_convenience_server_reply.c | 108+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Msrc/tests/client_server/test_authentication.c | 20++++++++++----------
Msrc/tests/client_server/test_cert_tls.c | 10+++++-----
Msrc/tests/client_server/test_client_server.c | 28++++++++++++++--------------
Msrc/tests/client_server/test_http2.c | 28++++++++++++++--------------
Msrc/tests/client_server/test_postparser.c | 4++--
Msrc/tests/client_server/test_tls.c | 40++++++++++++++++++++--------------------
Msrc/tests/client_server/test_tls2.c | 40++++++++++++++++++++--------------------
Msrc/tests/mhdt_checks.h | 296+++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tests/mhdt_has_in_name.h | 2+-
Msrc/tests/mhdt_has_param.h | 6+++---
Msrc/tests/raw/test_incompatible.c | 12++++++------
Msrc/tests/raw/test_oom.c | 74+++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/tests/raw/test_raw.c | 128++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tests/unit/unit_h2_huffman_codec.c | 192++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tests/unit/unit_hpack_tables.c | 236++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tests/unit/unit_md5.c | 42+++++++++++++++++++++---------------------
Msrc/tests/unit/unit_sha256.c | 30+++++++++++++++---------------
Msrc/tests/unit/unit_sha512_256.c | 28++++++++++++++--------------
Msrc/tests/unit/unit_str.c | 4++--
Msrc/tests/unit/unit_str_base64.c | 41+++++++++++++++++++++--------------------
Msrc/tests/unit/unit_str_bin_hex.c | 53+++++++++++++++++++++++++++--------------------------
Msrc/tests/unit/unit_str_compare.c | 170+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/tests/unit/unit_str_from_value.c | 174+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/tests/unit/unit_str_pct.c | 173++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/tests/unit/unit_str_quote.c | 135++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msrc/tests/unit/unit_str_to_value.c | 533++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Msrc/tests/unit/unit_str_token.c | 23++++++++++++++---------
Msrc/tests/unit/unit_str_token_remove.c | 39++++++++++++++++++++-------------------
Msrc/tests/unit/unit_str_tokens_remove.c | 42++++++++++++++++++++++++------------------
Msrc/tests/upgrade/test_upgrade.c | 360++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tools/mhdtl_get_cpu_count.c | 168++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/tools/mhdtl_str_to_uint.h | 2+-
Msrc/tools/perf_replies.c | 396++++++++++++++++++++++++++++++++++++++++----------------------------------------
Mw32/common/mhd_config.h | 46+++++++++++++++++++++++-----------------------
262 files changed, 9423 insertions(+), 9211 deletions(-)

diff --git a/contrib/uncrustify.cfg b/contrib/uncrustify.cfg @@ -6,29 +6,47 @@ indent_with_tabs = 0 indent_case_brace = 2 indent_label=-16 +# Keep code lines within the target width. Comments are intentionally only +# minimally formatted and may exceed this width. code_width=80 -#cmd_width=80 +#cmt_width=120 # Leave most comments alone for now cmt_indent_multi=false sp_cmt_cpp_start=add -sp_not=add +sp_not=remove +# Compact "defined(FOO)" in preprocessor conditionals +sp_defined_paren=remove sp_func_call_user_paren_paren=remove -sp_inside_fparen=remove -sp_after_cast=add +sp_after_cast=remove ls_for_split_full=true ls_func_split_full=true -ls_code_width=true +ls_code_width=false -# Arithmetic operations in wrapped expressions should be at the start -# of the line. +# Keep macro bodies stable. This also preserves intentionally dense macro calls +# and avoids bad line splits in long #define bodies. +pp_ignore_define_body=true + +# Keep nested preprocessor directives visibly nested as "# if" while leaving +# global include guards at column 1. +pp_indent=remove +pp_space_after=add +pp_space_count=2 +pp_indent_in_guard=false + +# Operators in wrapped expressions go at the start of the continuation line. +# This is uniform for arithmetic, bitwise, and boolean operators. pos_arith=lead +pos_bool=lead -# Fully parenthesize boolean exprs -mod_full_paren_if_bool=false +# Fully parenthesize boolean expressions in "if" and "return". +# mod_full_paren_assign_bool is intentionally left off: it wraps "for" loop +# increments as "(++i)". mod_full_paren_if_bool does not cover "while". +mod_full_paren_if_bool=true +mod_full_paren_return_bool=true # Braces should be on their own line nl_fdef_brace=add @@ -46,6 +64,7 @@ nl_else_if=remove nl_func_paren=remove nl_assign_brace=remove +nl_after_semicolon=true # No extra newlines that cause noisy diffs nl_start_of_file=remove @@ -61,35 +80,87 @@ sp_inside_paren = remove sp_arith = add sp_arith_additive = add +# Remove misplaced spaces before commas and add missing spaces after commas. +sp_before_comma = remove +sp_after_comma = add + +# C89 forbids a trailing comma after the last enum value: strip it if present. +mod_enum_last_comma = remove + +# Add spaces around explicit enum values: "A = 0". +sp_enum_assign = add + +# Keep a separator between macro names/signatures and replacement lists. +sp_macro = add +sp_macro_func = add + # We want spaces before and after "=" sp_before_assign = add sp_after_assign = add # we want "char *foo;" +sp_before_ptr_star = force +sp_before_unnamed_ptr_star = force +sp_before_qualifier_ptr_star = force +sp_qualifier_unnamed_ptr_star = force sp_after_ptr_star = remove +sp_after_ptr_star_func = remove +sp_after_ptr_star_qualifier = remove +sp_after_ptr_star_trailing = remove sp_between_ptr_star = remove +sp_ptr_star_func_var = remove +sp_ptr_star_func_type = remove +sp_ptr_star_paren = remove +sp_before_ptr_star_func = force +sp_qualifier_ptr_star_func = force +sp_before_ptr_star_trailing = force +sp_qualifier_ptr_star_trailing = force +sp_inside_tparen = remove +sp_after_tparen_close = remove +sp_inside_paren_cast = remove + +# we want "arr[10]" +sp_before_square = remove +sp_before_vardef_square = remove +sp_before_squares = remove +sp_inside_square = remove # we want "if (foo) { ... }" -sp_before_sparen = add +sp_before_sparen = force sp_inside_fparen = remove sp_inside_sparen = remove # add space before function call and decl: "foo (x)" -sp_func_call_paren = add -sp_func_proto_paren = add -sp_func_proto_paren_empty = add -sp_func_def_paren = add -sp_func_def_paren_empty = add - -# We'd want it for "if ( (foo) || (bar) )", but not for "if (m())", -# so as uncrustify doesn't give exactly what we want => ignore -sp_paren_paren = ignore -sp_inside_paren = remove -sp_bool = force +sp_func_call_paren = force +sp_func_proto_paren = force +sp_func_proto_paren_empty = force +sp_func_def_paren = force +sp_func_def_paren_empty = force + +# Keep formatter-generated boolean parentheses compact: +# "if ((a) || (b))", while preserving "if (m ())". +sp_paren_paren = remove +sp_bool = add +sp_compare = add +sp_cond_question = add +sp_cond_colon = add nl_func_type_name = force +nl_func_proto_type_name = force #nl_branch_else = add nl_else_brace = add -nl_elseif_brace = add nl_for_brace = add + +# Treat function annotation macros as qualifiers so uncrustify keeps short +# chains of them together instead of splitting them as return type fragments. +set QUALIFIER MHD_INTERNAL MHD_EXTERN_ MHD_DEPR_FUNC_ MHD_NORETURN_ +set QUALIFIER MHD_FN_CONST_ MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PURE_ +set QUALIFIER MHD_FN_RETURNS_NONNULL_ +set QUALIFIER MHD_FN_PAR_CSTR_ MHD_FN_PAR_FD_READ_ MHD_FN_PAR_FIX_ARR_SIZE_ +set QUALIFIER MHD_FN_PAR_DYN_ARR_SIZE_ +set QUALIFIER MHD_FN_PAR_IN_ MHD_FN_PAR_IN_SIZE_ MHD_FN_PAR_INOUT_ +set QUALIFIER MHD_FN_PAR_INOUT_SIZE_ MHD_FN_PAR_NONNULL_ +set QUALIFIER MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ MHD_FN_PAR_OUT_SIZE_ +set QUALIFIER mhd_FN_OBJ_CONSTRUCTOR mhd_FN_RET_ALIGNED mhd_FN_RET_SIZED +set QUALIFIER mhd_FN_RET_UNALIASED diff --git a/doc/examples/basic-authentication.c b/doc/examples/basic-authentication.c @@ -59,7 +59,7 @@ main () /* We run with everything on default, so port 80, no TLS */ MHD_daemon_start (d); /* Wait for input on stdin */ - (void) getchar (); + (void)getchar (); /* Then just shut everything down */ MHD_daemon_stop (d); return 0; diff --git a/doc/examples/basicauthentication.c b/doc/examples/basicauthentication.c @@ -3,10 +3,10 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> +# include <sys/select.h> +# include <sys/socket.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <microhttpd.h> #include <time.h> @@ -26,11 +26,11 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, struct MHD_BasicAuthInfo *auth_info; enum MHD_Result ret; struct MHD_Response *response; - (void) cls; /* Unused. Silent compiler warning. */ - (void) url; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ - (void) upload_data; /* Unused. Silent compiler warning. */ - (void) upload_data_size; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)url; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ + (void)upload_data; /* Unused. Silent compiler warning. */ + (void)upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (method, "GET")) return MHD_NO; @@ -50,15 +50,15 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, MHD_YES, response); } - else if ((strlen ("root") != auth_info->username_len) || - (0 != memcmp (auth_info->username, "root", - auth_info->username_len)) || - /* The next check against NULL is optional, + else if ((strlen ("root") != auth_info->username_len) + || (0 != memcmp (auth_info->username, "root", + auth_info->username_len)) + ||/* The next check against NULL is optional, * if 'password' is NULL then 'password_len' is always zero. */ - (NULL == auth_info->password) || - (strlen ("pa$$w0rd") != auth_info->password_len) || - (0 != memcmp (auth_info->password, "pa$$w0rd", - auth_info->password_len))) + (NULL == auth_info->password) + || (strlen ("pa$$w0rd") != auth_info->password_len) + || (0 != memcmp (auth_info->password, "pa$$w0rd", + auth_info->password_len))) { static const char *page = "<html><body>Wrong username or password</body></html>"; @@ -91,7 +91,7 @@ main (void) if (NULL == daemon) return 1; - (void) getchar (); + (void)getchar (); MHD_stop_daemon (daemon); return 0; diff --git a/doc/examples/external-select.c b/doc/examples/external-select.c @@ -168,14 +168,14 @@ main () /* This will cause MHD to call the #sock_reg_update_cb() */ MHD_daemon_process_reg_events (daemon, &next_wait); - ts.tv_sec = (time_t) (next_wait / 1000u); - ts.tv_usec = (suseconds_t) ((next_wait % 1000u) * 1000u); + ts.tv_sec = (time_t)(next_wait / 1000u); + ts.tv_usec = (suseconds_t)((next_wait % 1000u) * 1000u); /* Real applications may do nicer error handling here */ - (void) select (max_fd + 1, - &rs, - &ws, - &es, - &ts); + (void)select (max_fd + 1, + &rs, + &ws, + &es, + &ts); if (FD_ISSET (STDIN_FILENO, &rs)) break; /* exit on input on stdin */ diff --git a/doc/examples/hellobrowser.c b/doc/examples/hellobrowser.c @@ -3,10 +3,10 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> +# include <sys/select.h> +# include <sys/socket.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <string.h> #include <microhttpd.h> @@ -23,13 +23,13 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, const char *page = "<html><body>Hello, browser!</body></html>"; struct MHD_Response *response; enum MHD_Result ret; - (void) cls; /* Unused. Silent compiler warning. */ - (void) url; /* Unused. Silent compiler warning. */ - (void) method; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ - (void) upload_data; /* Unused. Silent compiler warning. */ - (void) upload_data_size; /* Unused. Silent compiler warning. */ - (void) req_cls; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)url; /* Unused. Silent compiler warning. */ + (void)method; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ + (void)upload_data; /* Unused. Silent compiler warning. */ + (void)upload_data_size; /* Unused. Silent compiler warning. */ + (void)req_cls; /* Unused. Silent compiler warning. */ response = MHD_create_response_from_buffer_static (strlen (page), page); ret = MHD_queue_response (connection, MHD_HTTP_OK, response); @@ -50,7 +50,7 @@ main (void) if (NULL == daemon) return 1; - (void) getchar (); + (void)getchar (); MHD_stop_daemon (daemon); return 0; diff --git a/doc/examples/host-example.c b/doc/examples/host-example.c @@ -51,7 +51,7 @@ main () /* We run with everything on default, so port 80, no TLS */ MHD_daemon_start (d); /* Wait for input on stdin */ - (void) getchar (); + (void)getchar (); /* Then just shut everything down */ MHD_daemon_stop (d); return 0; diff --git a/doc/examples/init-example.c b/doc/examples/init-example.c @@ -31,7 +31,7 @@ main () /* We run with everything on default, so port 80, no TLS */ MHD_daemon_start (d); /* Wait for input on stdin */ - (void) getchar (); + (void)getchar (); /* Then just shut everything down */ MHD_daemon_stop (d); return 0; diff --git a/doc/examples/largepost.c b/doc/examples/largepost.c @@ -3,10 +3,10 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> +# include <sys/select.h> +# include <sys/socket.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <stdio.h> #include <stdlib.h> @@ -15,7 +15,7 @@ #if defined(_MSC_VER) && _MSC_VER + 0 <= 1800 /* Substitution is OK while return value is not used */ -#define snprintf _snprintf +# define snprintf _snprintf #endif #define PORT 8888 @@ -93,7 +93,7 @@ send_page (struct MHD_Connection *connection, struct MHD_Response *response; response = MHD_create_response_from_buffer_static (strlen (page), page); - if (! response) + if (!response) return MHD_NO; if (MHD_YES != MHD_add_response_header (response, @@ -125,10 +125,10 @@ iterate_post (void *coninfo_cls, { struct connection_info_struct *con_info = coninfo_cls; FILE *fp; - (void) kind; /* Unused. Silent compiler warning. */ - (void) content_type; /* Unused. Silent compiler warning. */ - (void) transfer_encoding; /* Unused. Silent compiler warning. */ - (void) off; /* Unused. Silent compiler warning. */ + (void)kind; /* Unused. Silent compiler warning. */ + (void)content_type; /* Unused. Silent compiler warning. */ + (void)transfer_encoding; /* Unused. Silent compiler warning. */ + (void)off; /* Unused. Silent compiler warning. */ if (0 != strcmp (key, "file")) { @@ -137,7 +137,7 @@ iterate_post (void *coninfo_cls, return MHD_YES; } - if (! con_info->fp) + if (!con_info->fp) { if (0 != con_info->answercode) /* something went wrong */ return MHD_YES; @@ -152,7 +152,7 @@ iterate_post (void *coninfo_cls, but there is no easy fix, short of moving to open(O_EXCL) instead of using fopen(). For the example, we do not care. */ con_info->fp = fopen (filename, "ab"); - if (! con_info->fp) + if (!con_info->fp) { con_info->answerstring = fileioerror; con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; @@ -162,7 +162,7 @@ iterate_post (void *coninfo_cls, if (size > 0) { - if (! fwrite (data, sizeof (char), size, con_info->fp)) + if (!fwrite (data, sizeof (char), size, con_info->fp)) { con_info->answerstring = fileioerror; con_info->answercode = MHD_HTTP_INTERNAL_SERVER_ERROR; @@ -181,9 +181,9 @@ request_completed (void *cls, enum MHD_RequestTerminationCode toe) { struct connection_info_struct *con_info = *req_cls; - (void) cls; /* Unused. Silent compiler warning. */ - (void) connection; /* Unused. Silent compiler warning. */ - (void) toe; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)connection; /* Unused. Silent compiler warning. */ + (void)toe; /* Unused. Silent compiler warning. */ if (NULL == con_info) return; @@ -215,9 +215,9 @@ answer_to_connection (void *cls, size_t *upload_data_size, void **req_cls) { - (void) cls; /* Unused. Silent compiler warning. */ - (void) url; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)url; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ if (NULL == *req_cls) { @@ -241,7 +241,7 @@ answer_to_connection (void *cls, MHD_create_post_processor (connection, POSTBUFFERSIZE, &iterate_post, - (void *) con_info); + (void *)con_info); if (NULL == con_info->postprocessor) { @@ -258,7 +258,7 @@ answer_to_connection (void *cls, con_info->connectiontype = GET; } - *req_cls = (void *) con_info; + *req_cls = (void *)con_info; return MHD_YES; } @@ -343,7 +343,7 @@ main (void) "Failed to start daemon.\n"); return 1; } - (void) getchar (); + (void)getchar (); MHD_stop_daemon (daemon); return 0; } diff --git a/doc/examples/logging.c b/doc/examples/logging.c @@ -3,10 +3,10 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> +# include <sys/select.h> +# include <sys/socket.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <microhttpd.h> #include <stdio.h> @@ -18,8 +18,8 @@ static enum MHD_Result print_out_key (void *cls, enum MHD_ValueKind kind, const char *key, const char *value) { - (void) cls; /* Unused. Silent compiler warning. */ - (void) kind; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)kind; /* Unused. Silent compiler warning. */ printf ("%s: %s\n", key, value); return MHD_YES; } @@ -31,11 +31,11 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, const char *version, const char *upload_data, size_t *upload_data_size, void **req_cls) { - (void) cls; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ - (void) upload_data; /* Unused. Silent compiler warning. */ - (void) upload_data_size; /* Unused. Silent compiler warning. */ - (void) req_cls; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ + (void)upload_data; /* Unused. Silent compiler warning. */ + (void)upload_data_size; /* Unused. Silent compiler warning. */ + (void)req_cls; /* Unused. Silent compiler warning. */ printf ("New %s request for %s using version %s\n", method, url, version); MHD_get_connection_values (connection, MHD_HEADER_KIND, print_out_key, @@ -55,7 +55,7 @@ main (void) if (NULL == daemon) return 1; - (void) getchar (); + (void)getchar (); MHD_stop_daemon (daemon); return 0; diff --git a/doc/examples/options-example.c b/doc/examples/options-example.c @@ -51,7 +51,7 @@ main () } MHD_daemon_start (d); /* Wait for input on stdin */ - (void) getchar (); + (void)getchar (); /* Then just shut everything down */ MHD_daemon_stop (d); return 0; diff --git a/doc/examples/responseheaders.c b/doc/examples/responseheaders.c @@ -3,10 +3,10 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> +# include <sys/select.h> +# include <sys/socket.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <microhttpd.h> #include <time.h> @@ -29,25 +29,25 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, int fd; enum MHD_Result ret; struct stat sbuf; - (void) cls; /* Unused. Silent compiler warning. */ - (void) url; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ - (void) upload_data; /* Unused. Silent compiler warning. */ - (void) upload_data_size; /* Unused. Silent compiler warning. */ - (void) req_cls; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)url; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ + (void)upload_data; /* Unused. Silent compiler warning. */ + (void)upload_data_size; /* Unused. Silent compiler warning. */ + (void)req_cls; /* Unused. Silent compiler warning. */ if (0 != strcmp (method, "GET")) return MHD_NO; - if ( (-1 == (fd = open (FILENAME, O_RDONLY))) || - (0 != fstat (fd, &sbuf)) ) + if ((-1 == (fd = open (FILENAME, O_RDONLY))) + || (0 != fstat (fd, &sbuf))) { const char *errorstr = "<html><body>An internal server error has occurred!\ </body></html>"; /* error accessing file */ if (fd != -1) - (void) close (fd); + (void)close (fd); response = MHD_create_response_from_buffer_static (strlen (errorstr), errorstr); if (NULL != response) @@ -63,7 +63,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, return MHD_NO; } response = - MHD_create_response_from_fd_at_offset64 ((size_t) sbuf.st_size, + MHD_create_response_from_fd_at_offset64 ((size_t)sbuf.st_size, fd, 0); if (MHD_YES != @@ -94,7 +94,7 @@ main (void) if (NULL == daemon) return 1; - (void) getchar (); + (void)getchar (); MHD_stop_daemon (daemon); diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c @@ -167,10 +167,10 @@ get_session (struct MHD_Connection *connection) snprintf (ret->sid, sizeof (ret->sid), "%X%X%X%X", - (unsigned int) rand (), - (unsigned int) rand (), - (unsigned int) rand (), - (unsigned int) rand ()); + (unsigned int)rand (), + (unsigned int)rand (), + (unsigned int)rand (), + (unsigned int)rand ()); ret->rc++; ret->start = time (NULL); ret->next = sessions; @@ -305,19 +305,19 @@ fill_v1_form (const void *cls, char *reply; struct MHD_Response *response; int reply_len; - (void) cls; /* Unused */ + (void)cls; /* Unused */ /* Emulate 'asprintf' */ reply_len = snprintf (NULL, 0, FORM_V1, session->value_1); if (0 > reply_len) return MHD_NO; /* Internal error */ - reply = (char *) malloc ((size_t) ((size_t) reply_len + 1)); + reply = (char *)malloc ((size_t)((size_t)reply_len + 1)); if (NULL == reply) return MHD_NO; /* Out-of-memory error */ if (reply_len != snprintf (reply, - (size_t) (((size_t) reply_len) + 1), + (size_t)(((size_t)reply_len) + 1), FORM_V1, session->value_1)) { @@ -327,8 +327,8 @@ fill_v1_form (const void *cls, /* return static form */ response = - MHD_create_response_from_buffer_with_free_callback ((size_t) reply_len, - (void *) reply, + MHD_create_response_from_buffer_with_free_callback ((size_t)reply_len, + (void *)reply, &free); if (NULL != response) { @@ -374,7 +374,7 @@ fill_v1_v2_form (const void *cls, char *reply; struct MHD_Response *response; int reply_len; - (void) cls; /* Unused */ + (void)cls; /* Unused */ /* Emulate 'asprintf' */ reply_len = snprintf (NULL, 0, FORM_V1_V2, session->value_1, @@ -382,12 +382,12 @@ fill_v1_v2_form (const void *cls, if (0 > reply_len) return MHD_NO; /* Internal error */ - reply = (char *) malloc ((size_t) ((size_t) reply_len + 1)); + reply = (char *)malloc ((size_t)((size_t)reply_len + 1)); if (NULL == reply) return MHD_NO; /* Out-of-memory error */ if (reply_len != snprintf (reply, - (size_t) ((size_t) reply_len + 1), + (size_t)((size_t)reply_len + 1), FORM_V1_V2, session->value_1, session->value_2)) @@ -398,8 +398,8 @@ fill_v1_v2_form (const void *cls, /* return static form */ response = - MHD_create_response_from_buffer_with_free_callback ((size_t) reply_len, - (void *) reply, + MHD_create_response_from_buffer_with_free_callback ((size_t)reply_len, + (void *)reply, &free); if (NULL != response) { @@ -443,8 +443,8 @@ not_found_page (const void *cls, { enum MHD_Result ret; struct MHD_Response *response; - (void) cls; /* Unused. Silent compiler warning. */ - (void) session; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)session; /* Unused. Silent compiler warning. */ /* unsupported HTTP method */ response = MHD_create_response_from_buffer_static (strlen (NOT_FOUND_ERROR), @@ -508,10 +508,10 @@ post_iterator (void *cls, { struct Request *request = cls; struct Session *session = request->session; - (void) kind; /* Unused. Silent compiler warning. */ - (void) filename; /* Unused. Silent compiler warning. */ - (void) content_type; /* Unused. Silent compiler warning. */ - (void) transfer_encoding; /* Unused. Silent compiler warning. */ + (void)kind; /* Unused. Silent compiler warning. */ + (void)filename; /* Unused. Silent compiler warning. */ + (void)content_type; /* Unused. Silent compiler warning. */ + (void)transfer_encoding; /* Unused. Silent compiler warning. */ if (0 == strcmp ("DONE", key)) { @@ -527,7 +527,7 @@ post_iterator (void *cls, if (off >= sizeof(session->value_1) - 1) return MHD_YES; /* Discard extra data */ if (size + off >= sizeof(session->value_1)) - size = (size_t) (sizeof (session->value_1) - off - 1); /* crop extra data */ + size = (size_t)(sizeof (session->value_1) - off - 1); /* crop extra data */ memcpy (&session->value_1[off], data, size); @@ -540,7 +540,7 @@ post_iterator (void *cls, if (off >= sizeof(session->value_2) - 1) return MHD_YES; /* Discard extra data */ if (size + off >= sizeof(session->value_2)) - size = (size_t) (sizeof (session->value_2) - off - 1); /* crop extra data */ + size = (size_t)(sizeof (session->value_2) - off - 1); /* crop extra data */ memcpy (&session->value_2[off], data, size); @@ -602,8 +602,8 @@ create_response (void *cls, struct Session *session; enum MHD_Result ret; unsigned int i; - (void) cls; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ request = *req_cls; if (NULL == request) @@ -661,13 +661,13 @@ create_response (void *cls, url = request->post_url; } - if ( (0 == strcmp (method, MHD_HTTP_METHOD_GET)) || - (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)) ) + if ((0 == strcmp (method, MHD_HTTP_METHOD_GET)) + || (0 == strcmp (method, MHD_HTTP_METHOD_HEAD))) { /* find out which page to serve */ i = 0; - while ( (pages[i].url != NULL) && - (0 != strcmp (pages[i].url, url)) ) + while ((pages[i].url != NULL) + && (0 != strcmp (pages[i].url, url))) i++; ret = pages[i].handler (pages[i].handler_cls, pages[i].mime, @@ -704,9 +704,9 @@ request_completed_callback (void *cls, enum MHD_RequestTerminationCode toe) { struct Request *request = *req_cls; - (void) cls; /* Unused. Silent compiler warning. */ - (void) connection; /* Unused. Silent compiler warning. */ - (void) toe; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)connection; /* Unused. Silent compiler warning. */ + (void)toe; /* Unused. Silent compiler warning. */ if (NULL == request) return; @@ -774,8 +774,8 @@ main (int argc, char *const *argv) printf ("%s PORT\n", argv[0]); return 1; } - if ( (1 != sscanf (argv[1], "%u", &port)) || - (0 == port) || (65535 < port) ) + if ((1 != sscanf (argv[1], "%u", &port)) + || (0 == port) || (65535 < port)) { fprintf (stderr, "Port must be a number between 1 and 65535.\n"); @@ -783,15 +783,15 @@ main (int argc, char *const *argv) } /* initialize PRNG */ - srand ((unsigned int) time (NULL)); + srand ((unsigned int)time (NULL)); d = MHD_start_daemon (MHD_USE_ERROR_LOG, - (uint16_t) port, + (uint16_t)port, NULL, NULL, &create_response, NULL, - MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15, + MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)15, MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL, - MHD_OPTION_APP_FD_SETSIZE, (int) FD_SETSIZE, + MHD_OPTION_APP_FD_SETSIZE, (int)FD_SETSIZE, MHD_OPTION_END); if (NULL == d) return 1; @@ -806,17 +806,17 @@ main (int argc, char *const *argv) break; /* fatal internal error */ if (MHD_get_timeout64 (d, &mhd_timeout) == MHD_YES) { -#if ! defined(_WIN32) || defined(__CYGWIN__) - tv.tv_sec = (time_t) (mhd_timeout / 1000); +#if !defined(_WIN32) || defined(__CYGWIN__) + tv.tv_sec = (time_t)(mhd_timeout / 1000); #else /* Native W32 */ - tv.tv_sec = (long) (mhd_timeout / 1000); + tv.tv_sec = (long)(mhd_timeout / 1000); #endif /* Native W32 */ - tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000; + tv.tv_usec = ((long)(mhd_timeout % 1000)) * 1000; tvp = &tv; } else tvp = NULL; - if (-1 == select ((int) max + 1, &rs, &ws, &es, tvp)) + if (-1 == select ((int)max + 1, &rs, &ws, &es, tvp)) { if (EINTR != errno) fprintf (stderr, diff --git a/doc/examples/simplepost.c b/doc/examples/simplepost.c @@ -3,10 +3,10 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> +# include <sys/select.h> +# include <sys/socket.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <microhttpd.h> #include <stdio.h> @@ -15,7 +15,7 @@ #if defined(_MSC_VER) && _MSC_VER + 0 <= 1800 /* Substitution is OK while return value is not used */ -#define snprintf _snprintf +# define snprintf _snprintf #endif #define PORT 8888 @@ -56,7 +56,7 @@ send_page (struct MHD_Connection *connection, const char *page) response = MHD_create_response_from_buffer_static (strlen (page), page); - if (! response) + if (!response) return MHD_NO; ret = MHD_queue_response (connection, MHD_HTTP_OK, response); @@ -73,11 +73,11 @@ iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, size_t size) { struct connection_info_struct *con_info = coninfo_cls; - (void) kind; /* Unused. Silent compiler warning. */ - (void) filename; /* Unused. Silent compiler warning. */ - (void) content_type; /* Unused. Silent compiler warning. */ - (void) transfer_encoding; /* Unused. Silent compiler warning. */ - (void) off; /* Unused. Silent compiler warning. */ + (void)kind; /* Unused. Silent compiler warning. */ + (void)filename; /* Unused. Silent compiler warning. */ + (void)content_type; /* Unused. Silent compiler warning. */ + (void)transfer_encoding; /* Unused. Silent compiler warning. */ + (void)off; /* Unused. Silent compiler warning. */ if (0 == strcmp (key, "name")) { @@ -85,7 +85,7 @@ iterate_post (void *coninfo_cls, enum MHD_ValueKind kind, const char *key, { char *answerstring; answerstring = malloc (MAXANSWERSIZE); - if (! answerstring) + if (!answerstring) return MHD_NO; snprintf (answerstring, MAXANSWERSIZE, GREETINGPAGE, data); @@ -106,9 +106,9 @@ request_completed (void *cls, struct MHD_Connection *connection, void **req_cls, enum MHD_RequestTerminationCode toe) { struct connection_info_struct *con_info = *req_cls; - (void) cls; /* Unused. Silent compiler warning. */ - (void) connection; /* Unused. Silent compiler warning. */ - (void) toe; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)connection; /* Unused. Silent compiler warning. */ + (void)toe; /* Unused. Silent compiler warning. */ if (NULL == con_info) return; @@ -131,9 +131,9 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, const char *version, const char *upload_data, size_t *upload_data_size, void **req_cls) { - (void) cls; /* Unused. Silent compiler warning. */ - (void) url; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)url; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ if (NULL == *req_cls) { @@ -148,7 +148,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, { con_info->postprocessor = MHD_create_post_processor (connection, POSTBUFFERSIZE, - iterate_post, (void *) con_info); + iterate_post, (void *)con_info); if (NULL == con_info->postprocessor) { @@ -161,7 +161,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, else con_info->connectiontype = GET; - *req_cls = (void *) con_info; + *req_cls = (void *)con_info; return MHD_YES; } @@ -207,7 +207,7 @@ main (void) if (NULL == daemon) return 1; - (void) getchar (); + (void)getchar (); MHD_stop_daemon (daemon); diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c @@ -3,10 +3,10 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> +# include <sys/select.h> +# include <sys/socket.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <microhttpd.h> #include <string.h> @@ -38,7 +38,7 @@ get_file_size (const char *filename) fclose (fp); - return (size_t) size; + return (size_t)size; } else return 0; @@ -57,11 +57,11 @@ load_file (const char *filename) return NULL; fp = fopen (filename, "rb"); - if (! fp) + if (!fp) return NULL; buffer = malloc (size + 1); - if (! buffer) + if (!buffer) { fclose (fp); return NULL; @@ -86,7 +86,7 @@ ask_for_authentication (struct MHD_Connection *connection, const char *realm) struct MHD_Response *response; response = MHD_create_response_empty (MHD_RF_NONE); - if (! response) + if (!response) return MHD_NO; ret = MHD_queue_basic_auth_required_response3 (connection, @@ -110,13 +110,13 @@ is_authenticated (struct MHD_Connection *connection, if (NULL == auth_info) return 0; authenticated = - ( (strlen (username) == auth_info->username_len) && - (0 == memcmp (auth_info->username, username, auth_info->username_len)) && - /* The next check against NULL is optional, + ((strlen (username) == auth_info->username_len) + && (0 == memcmp (auth_info->username, username, auth_info->username_len)) + &&/* The next check against NULL is optional, * if 'password' is NULL then 'password_len' is always zero. */ - (NULL != auth_info->password) && - (strlen (password) == auth_info->password_len) && - (0 == memcmp (auth_info->password, password, auth_info->password_len)) ); + (NULL != auth_info->password) + && (strlen (password) == auth_info->password_len) + && (0 == memcmp (auth_info->password, password, auth_info->password_len))); MHD_free (auth_info); @@ -132,7 +132,7 @@ secret_page (struct MHD_Connection *connection) const char *page = "<html><body>A secret.</body></html>"; response = MHD_create_response_from_buffer_static (strlen (page), page); - if (! response) + if (!response) return MHD_NO; ret = MHD_queue_response (connection, MHD_HTTP_OK, response); @@ -148,11 +148,11 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, const char *version, const char *upload_data, size_t *upload_data_size, void **req_cls) { - (void) cls; /* Unused. Silent compiler warning. */ - (void) url; /* Unused. Silent compiler warning. */ - (void) version; /* Unused. Silent compiler warning. */ - (void) upload_data; /* Unused. Silent compiler warning. */ - (void) upload_data_size; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)url; /* Unused. Silent compiler warning. */ + (void)version; /* Unused. Silent compiler warning. */ + (void)upload_data; /* Unused. Silent compiler warning. */ + (void)upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (method, "GET")) return MHD_NO; @@ -162,7 +162,7 @@ answer_to_connection (void *cls, struct MHD_Connection *connection, return MHD_YES; } - if (! is_authenticated (connection, USER, PASSWORD)) + if (!is_authenticated (connection, USER, PASSWORD)) return ask_for_authentication (connection, REALM); return secret_page (connection); @@ -204,7 +204,7 @@ main (void) return 1; } - (void) getchar (); + (void)getchar (); MHD_stop_daemon (daemon); free (key_pem); diff --git a/doc/examples/websocket.c b/doc/examples/websocket.c @@ -3,11 +3,11 @@ #include <sys/types.h> #ifndef _WIN32 -#include <sys/select.h> -#include <sys/socket.h> -#include <fcntl.h> +# include <sys/select.h> +# include <sys/socket.h> +# include <fcntl.h> #else -#include <winsock2.h> +# include <winsock2.h> #endif #include <microhttpd.h> #include <microhttpd_ws.h> @@ -122,14 +122,14 @@ upgrade_handler (void *cls, /* parse the entire received data */ size_t buf_offset = 0; - while (buf_offset < (size_t) got) + while (buf_offset < (size_t)got) { size_t new_offset = 0; char *frame_data = NULL; size_t frame_len = 0; int status = MHD_websocket_decode (ws, buf + buf_offset, - ((size_t) got) - buf_offset, + ((size_t)got) - buf_offset, &new_offset, &frame_data, &frame_len); @@ -258,7 +258,7 @@ send_all (MHD_socket fd, { ret = send (fd, &buf[off], - (int) (len - off), + (int)(len - off), 0); if (0 > ret) { @@ -293,7 +293,7 @@ make_blocking (MHD_socket fd) #else /* _WIN32 */ unsigned long flags = 0; - if (0 != ioctlsocket (fd, (int) FIONBIO, &flags)) + if (0 != ioctlsocket (fd, (int)FIONBIO, &flags)) abort (); #endif /* _WIN32 */ } @@ -313,9 +313,9 @@ access_handler (void *cls, struct MHD_Response *response; int ret; - (void) cls; /* Unused. Silent compiler warning. */ - (void) upload_data; /* Unused. Silent compiler warning. */ - (void) upload_data_size; /* Unused. Silent compiler warning. */ + (void)cls; /* Unused. Silent compiler warning. */ + (void)upload_data; /* Unused. Silent compiler warning. */ + (void)upload_data_size; /* Unused. Silent compiler warning. */ if (0 != strcmp (method, "GET")) return MHD_NO; /* unexpected method */ @@ -427,8 +427,8 @@ int main (int argc, char *const *argv) { - (void) argc; /* Unused. Silent compiler warning. */ - (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; /* Unused. Silent compiler warning. */ + (void)argv; /* Unused. Silent compiler warning. */ struct MHD_Daemon *daemon; daemon = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD @@ -441,7 +441,7 @@ main (int argc, if (NULL == daemon) return 1; - (void) getc (stdin); + (void)getc (stdin); MHD_stop_daemon (daemon); diff --git a/src/examples2/demo.c b/src/examples2/demo.c @@ -51,7 +51,7 @@ #include <microhttpd2.h> #include <sys/types.h> #include <stdbool.h> -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) # include <unistd.h> #else # include <direct.h> @@ -62,7 +62,7 @@ #include <fcntl.h> #include <sys/stat.h> #include <string.h> -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) # include <dirent.h> #else # include <io.h> @@ -73,11 +73,11 @@ #include <limits.h> #include <ctype.h> #include <errno.h> -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) # include <locale.h> #endif -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) # include <pthread.h> typedef pthread_mutex_t my_mutex_t; # define my_mutex_init(pmtx) ((void) pthread_mutex_init ((pmtx), NULL)) @@ -101,10 +101,10 @@ typedef CRITICAL_SECTION my_mutex_t; #endif #if defined(MHD_CPU_COUNT) && (MHD_CPU_COUNT + 0) < 2 -#undef MHD_CPU_COUNT +# undef MHD_CPU_COUNT #endif -#if ! defined(MHD_CPU_COUNT) -#define MHD_CPU_COUNT 2 +#if !defined(MHD_CPU_COUNT) +# define MHD_CPU_COUNT 2 #endif #ifndef PATH_MAX @@ -129,7 +129,7 @@ typedef CRITICAL_SECTION my_mutex_t; * 16k might be a bit excessive, but ought not hurt performance much anyway, * and should definitively be on the safe side. */ -#define MAGIC_HEADER_SIZE (16 * 1024) +# define MAGIC_HEADER_SIZE (16 * 1024) #endif /* MHD_HAVE_LIBMAGIC */ #if defined(_MSC_VER) && _MSC_VER < 1900 /* Before VS 2015 */ @@ -137,7 +137,7 @@ typedef CRITICAL_SECTION my_mutex_t; # define snprintf _snprintf #endif -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) # define my_mkstemp(tmpl) mkstemp ((tmpl)) #else static int @@ -164,7 +164,7 @@ my_mkstemp (char *tmpl) if (INVALID_HANDLE_VALUE != hndl) { int fd; - fd = _open_osfhandle ((intptr_t) hndl, + fd = _open_osfhandle ((intptr_t)hndl, _O_RDWR | _O_BINARY); if (-1 != fd) { @@ -175,7 +175,7 @@ my_mkstemp (char *tmpl) /* Failure */ CloseHandle (hndl); } - (void) DeleteFileA (tmp_file_name); + (void)DeleteFileA (tmp_file_name); } return -1; } @@ -193,7 +193,7 @@ my_strdup (const char *str) char *str_copy; sz = strlen (str); - str_copy = (char *) malloc (sz); + str_copy = (char *)malloc (sz); if (NULL != str_copy) memcpy (str_copy, str, sz); return str_copy; @@ -346,9 +346,9 @@ mark_as_html (struct MHD_Response *response) { if (NULL == response) return; - (void) MHD_response_add_header (response, - MHD_HTTP_HEADER_CONTENT_TYPE, - "text/html"); + (void)MHD_response_add_header (response, + MHD_HTTP_HEADER_CONTENT_TYPE, + "text/html"); } @@ -411,7 +411,7 @@ static bool list_directory (struct ResponseDataContext *rdc, const char *dirname) { -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) char fullname[PATH_MAX + 1]; struct stat sbuf; DIR *dir; @@ -431,19 +431,19 @@ list_directory (struct ResponseDataContext *rdc, continue; /* ugh, file too long? how can this be!? */ if (0 != stat (fullname, &sbuf)) continue; /* ugh, failed to 'stat' */ - if (! S_ISREG (sbuf.st_mode)) + if (!S_ISREG (sbuf.st_mode)) continue; /* not a regular file, skip */ if (rdc->off + 1024 > rdc->buf_size) { void *r; - if ((2 * rdc->buf_size < rdc->buf_size) || - (2 * rdc->buf_size + 1024) < rdc->buf_size) + if ((2 * rdc->buf_size < rdc->buf_size) + || ((2 * rdc->buf_size + 1024) < rdc->buf_size)) break; /* more than SIZE_T _index_ size? Too big for us */ rdc->buf_size = 2 * rdc->buf_size + 1024; if (NULL == (r = realloc (rdc->buf, rdc->buf_size))) break; /* out of memory */ - rdc->buf = (char *) r; + rdc->buf = (char *)r; } res = snprintf (rdc->buf + rdc->off, rdc->buf_size - rdc->off, @@ -452,20 +452,20 @@ list_directory (struct ResponseDataContext *rdc, de->d_name); if (0 >= res) continue; /* snprintf() error */ - if (rdc->buf_size - rdc->off <= (size_t) res) + if (rdc->buf_size - rdc->off <= (size_t)res) continue; /* buffer too small?? */ - rdc->off += (size_t) res; + rdc->off += (size_t)res; } - (void) closedir (dir); + (void)closedir (dir); #else char search_patt[PATH_MAX + 1]; struct _finddatai64_t finfo; intptr_t dir; if (sizeof(search_patt) <= - (size_t) snprintf (search_patt, - sizeof(search_patt), - "%s\\*", - dirname)) + (size_t)snprintf (search_patt, + sizeof(search_patt), + "%s\\*", + dirname)) return false; if (-1 == (dir = _findfirsti64 (search_patt, &finfo))) @@ -480,13 +480,13 @@ list_directory (struct ResponseDataContext *rdc, { void *r; - if ((2 * rdc->buf_size < rdc->buf_size) || - (2 * rdc->buf_size + 1024) < rdc->buf_size) + if ((2 * rdc->buf_size < rdc->buf_size) + || ((2 * rdc->buf_size + 1024) < rdc->buf_size)) break; /* more than SIZE_T _index_ size? Too big for us */ rdc->buf_size = 2 * rdc->buf_size + 1024; if (NULL == (r = realloc (rdc->buf, rdc->buf_size))) break; /* out of memory */ - rdc->buf = (char *) r; + rdc->buf = (char *)r; } res = snprintf (rdc->buf + rdc->off, rdc->buf_size - rdc->off, @@ -496,13 +496,13 @@ list_directory (struct ResponseDataContext *rdc, finfo.name); if (0 >= res) continue; /* snprintf() error */ - if (rdc->buf_size - rdc->off <= (size_t) res) + if (rdc->buf_size - rdc->off <= (size_t)res) continue; /* buffer too small?? */ - rdc->off += (size_t) res; + rdc->off += (size_t)res; } while (0 == _findnexti64 (dir, &finfo)); - (void) _findclose (dir); + (void)_findclose (dir); #endif return true; } @@ -528,7 +528,7 @@ update_directory (void) rdc.off = 0; rdc.buf_size = initial_allocation; - rdc.buf = (char *) malloc (rdc.buf_size); + rdc.buf = (char *)malloc (rdc.buf_size); if (NULL == rdc.buf) { update_cached_response (NULL); @@ -560,9 +560,9 @@ update_directory (void) language->longname); if (0 >= res) continue; /* snprintf() error */ - if (rdc.buf_size - rdc.off <= (size_t) res) + if (rdc.buf_size - rdc.off <= (size_t)res) continue; /* buffer too small?? */ - rdc.off += (size_t) res; + rdc.off += (size_t)res; for (category_idx = 0; NULL != categories[category_idx]; category_idx++) { category = categories[category_idx]; @@ -570,7 +570,7 @@ update_directory (void) "%s/%s", language->dirname, category); - if ((0 >= res) || (sizeof (dir_name) <= (size_t) res)) + if ((0 >= res) || (sizeof (dir_name) <= (size_t)res)) continue; /* cannot print dir name */ if (0 != stat (dir_name, &sbuf)) continue; /* empty */ @@ -583,12 +583,12 @@ update_directory (void) category); if (0 >= res) continue; /* snprintf() error */ - if (rdc.buf_size - rdc.off <= (size_t) res) + if (rdc.buf_size - rdc.off <= (size_t)res) continue; /* buffer too small?? */ - rdc.off += (size_t) res; + rdc.off += (size_t)res; - if (! list_directory (&rdc, - dir_name)) + if (!list_directory (&rdc, + dir_name)) { free (rdc.buf); update_cached_response (NULL); @@ -617,8 +617,8 @@ update_directory (void) rdc.buf); mark_as_html (response); #ifdef FORCE_CLOSE - (void) MHD_response_set_option (response, - &MHD_R_OPTION_CONN_CLOSE (MHD_YES)); + (void)MHD_response_set_option (response, + &MHD_R_OPTION_CONN_CLOSE (MHD_YES)); #endif update_cached_response (response); } @@ -707,17 +707,17 @@ stream_reader (struct MHD_Request *req, uint_fast64_t off, enum MHD_Bool final_data) { - struct UploadContext *uc = (struct UploadContext *) cls; - - (void) content_type; /* Unused. Silent compiler warning. */ - (void) encoding; /* Unused. Silent compiler warning. */ - (void) off; /* Unused. Silent compiler warning. */ - if ( (0 == strcmp (name->cstr, - "category")) || - (0 == strcmp (name->cstr, - "filename")) || - (0 == strcmp (name->cstr, - "language")) ) + struct UploadContext *uc = (struct UploadContext *)cls; + + (void)content_type; /* Unused. Silent compiler warning. */ + (void)encoding; /* Unused. Silent compiler warning. */ + (void)off; /* Unused. Silent compiler warning. */ + if ((0 == strcmp (name->cstr, + "category")) + || (0 == strcmp (name->cstr, + "filename")) + || (0 == strcmp (name->cstr, + "language"))) { return MHD_upload_action_from_response (req, request_refused_response); @@ -741,12 +741,12 @@ stream_reader (struct MHD_Request *req, { if (0 != filename->len) { - if ( (NULL != strstr (filename->cstr, - "..")) || - (NULL != strchr (filename->cstr, - '/')) || - (NULL != strchr (filename->cstr, - '\\')) ) + if ((NULL != strstr (filename->cstr, + "..")) + || (NULL != strchr (filename->cstr, + '/')) + || (NULL != strchr (filename->cstr, + '\\'))) { return MHD_upload_action_from_response (req, request_refused_response); @@ -766,7 +766,7 @@ stream_reader (struct MHD_Request *req, size_t i; for (i = 0; i < slen; i++) - if (! isprint ((unsigned char) uc->filename[i])) + if (!isprint ((unsigned char)uc->filename[i])) uc->filename[i] = '_'; } uc->fd = my_mkstemp (uc->tmpname); @@ -780,26 +780,26 @@ stream_reader (struct MHD_Request *req, request_refused_response); } } - if ( (0 != size) && -#if ! defined(_WIN32) || defined(__CYGWIN__) - (size != - (size_t) write (uc->fd, - data, - size)) + if ((0 != size) && +#if !defined(_WIN32) || defined(__CYGWIN__) + (size != + (size_t)write (uc->fd, + data, + size)) #else /* Native W32 */ - (size != - (size_t) write (uc->fd, - data, - (unsigned int) size)) + (size != + (size_t)write (uc->fd, + data, + (unsigned int)size)) #endif /* Native W32 */ - ) + ) { /* write failed; likely: disk full */ fprintf (stderr, "Error writing to file `%s': %s\n", uc->tmpname, strerror (errno)); - (void) close (uc->fd); + (void)close (uc->fd); uc->fd = -1; unlink (uc->tmpname); return MHD_upload_action_from_response (req, @@ -807,7 +807,7 @@ stream_reader (struct MHD_Request *req, } if (final_data) { - (void) close (uc->fd); + (void)close (uc->fd); uc->fd = -1; uc->have_file = true; } @@ -834,7 +834,7 @@ static enum MHD_Bool handle_full_upload (void *cls, const struct MHD_PostField *data) { - struct UploadContext *uc = (struct UploadContext *) cls; + struct UploadContext *uc = (struct UploadContext *)cls; int fd; if (0 != strcmp ("upload", @@ -866,14 +866,14 @@ handle_full_upload (void *cls, if (NULL != data->value.cstr) { // FIXME: error handling, ... -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) write (fd, data->value.cstr, data->value.len); #else /* Native W32 */ write (fd, data->value.cstr, - (unsigned int) data->value.len); + (unsigned int)data->value.len); #endif /* Native W32 */ } close (fd); @@ -895,7 +895,7 @@ done_cb (struct MHD_Request *req, void *cls, enum MHD_PostParseResult parsing_result) { - struct UploadContext *uc = (struct UploadContext *) cls; + struct UploadContext *uc = (struct UploadContext *)cls; const struct MHD_UploadAction *ret; struct MHD_StringNullable cat; struct MHD_StringNullable lang; @@ -906,7 +906,7 @@ done_cb (struct MHD_Request *req, { fprintf (stderr, "Upload parsing failed with status %d\n", - (int) parsing_result); + (int)parsing_result); ret = MHD_upload_action_from_response (req, request_refused_response); goto cleanup; @@ -915,33 +915,33 @@ done_cb (struct MHD_Request *req, { fprintf (stderr, "Upload incomplete (fd still open)\n"); - (void) close (uc->fd); + (void)close (uc->fd); if (NULL != uc->filename) { fprintf (stderr, "Upload of file `%s' failed (incomplete or aborted), removing file.\n", uc->filename); } - (void) unlink (uc->tmpname); + (void)unlink (uc->tmpname); ret = MHD_upload_action_from_response (req, internal_error_response); goto cleanup; } - if (! MHD_request_get_value (req, - MHD_VK_POSTDATA, - "category", - &cat) || - ! MHD_request_get_value (req, - MHD_VK_POSTDATA, - "language", - &lang) || - (NULL == cat.cstr) || - (NULL == lang.cstr) ) + if (!MHD_request_get_value (req, + MHD_VK_POSTDATA, + "category", + &cat) + || !MHD_request_get_value (req, + MHD_VK_POSTDATA, + "language", + &lang) + || (NULL == cat.cstr) + || (NULL == lang.cstr)) { fprintf (stderr, "Required argument missing\n"); if (uc->have_file) - (void) unlink (uc->tmpname); + (void)unlink (uc->tmpname); ret = MHD_upload_action_from_response (req, request_refused_response); goto cleanup; @@ -968,19 +968,19 @@ done_cb (struct MHD_Request *req, goto cleanup; } /* create directories -- if they don't exist already */ -#if ! defined(_WIN32) || defined(__CYGWIN__) - (void) mkdir (lang.cstr, - S_IRWXU); +#if !defined(_WIN32) || defined(__CYGWIN__) + (void)mkdir (lang.cstr, + S_IRWXU); #else - (void) mkdir (lang.cstr); + (void)mkdir (lang.cstr); #endif res = snprintf (fn, sizeof (fn), "%s/%s", lang.cstr, cat.cstr); - if ( (0 >= res) || - (sizeof (fn) <= (size_t) res) ) + if ((0 >= res) + || (sizeof (fn) <= (size_t)res)) { fprintf (stderr, "snprintf() failed at %d\n", __LINE__); @@ -988,11 +988,11 @@ done_cb (struct MHD_Request *req, request_refused_response); goto cleanup; } -#if ! defined(_WIN32) || defined(__CYGWIN__) - (void) mkdir (fn, - S_IRWXU); +#if !defined(_WIN32) || defined(__CYGWIN__) + (void)mkdir (fn, + S_IRWXU); #else - (void) mkdir (fn); + (void)mkdir (fn); #endif /* compute filename */ res = snprintf (fn, @@ -1001,8 +1001,8 @@ done_cb (struct MHD_Request *req, lang.cstr, cat.cstr, uc->filename); - if ( (0 >= res) || - (sizeof (fn) <= (size_t) res) ) + if ((0 >= res) + || (sizeof (fn) <= (size_t)res)) { fprintf (stderr, "snprintf() failed at %d\n", __LINE__); @@ -1023,7 +1023,7 @@ done_cb (struct MHD_Request *req, request_refused_response); goto cleanup; } -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) chmod (uc->filename, S_IRUSR | S_IWUSR); #endif @@ -1071,21 +1071,21 @@ generate_page (void *cls, struct MHD_Response *response; const char *url = path->cstr; - (void ) cls; + (void)cls; - if ((0 != upload_size) && - ( (MHD_HTTP_METHOD_GET == method) || - (MHD_HTTP_METHOD_HEAD == method) )) + if ((0 != upload_size) + && ((MHD_HTTP_METHOD_GET == method) + || (MHD_HTTP_METHOD_HEAD == method))) { /* Wrong request, refuse */ return MHD_action_from_response (request, request_refused_response); } - if ( ( (MHD_HTTP_METHOD_GET == method) || - (MHD_HTTP_METHOD_HEAD == method) ) && - (0 != strcmp (url, - "/")) ) + if (((MHD_HTTP_METHOD_GET == method) + || (MHD_HTTP_METHOD_HEAD == method)) + && (0 != strcmp (url, + "/"))) { /* should be file download */ #ifdef MHD_HAVE_LIBMAGIC @@ -1098,25 +1098,25 @@ generate_page (void *cls, fd = -1; buf.st_size = 0; /* Mute compiler warning */ - if ((0 != path->len) && - (NULL == strstr (&url[1], - "..")) && - (0 != url[0]) && - (0 != url[1]) && + if ((0 != path->len) + && (NULL == strstr (&url[1], + "..")) + && (0 != url[0]) + && (0 != url[1]) && #ifdef _WIN32 - ('\\' != url[1]) && - ((3 > path->len) || ':' != url[2]) && + ('\\' != url[1]) + && ((3 > path->len) || ':' != url[2]) && #endif - ('/' != url[1]) ) + ('/' != url[1])) fd = open (url + 1, O_RDONLY); if (-1 != fd) { if ((0 != fstat (fd, &buf)) - || ! my_S_ISREG (buf.st_mode)) + || !my_S_ISREG (buf.st_mode)) { - (void) close (fd); + (void)close (fd); fd = -1; } } @@ -1128,13 +1128,13 @@ generate_page (void *cls, got = read (fd, file_data, sizeof (file_data)); - (void) lseek (fd, - 0, - SEEK_SET); + (void)lseek (fd, + 0, + SEEK_SET); if (0 < got) mime = magic_buffer (magic, file_data, - (size_t) got); + (size_t)got); else #endif /* MHD_HAVE_LIBMAGIC */ mime = NULL; @@ -1167,30 +1167,30 @@ generate_page (void *cls, response = MHD_response_from_fd (MHD_HTTP_STATUS_OK, fd, 0LLU /* offset */, - (uint_fast64_t) buf.st_size); + (uint_fast64_t)buf.st_size); if (NULL == response) { /* internal error (i.e. out of memory) */ - (void) close (fd); + (void)close (fd); return MHD_action_abort_request (request); } /* add mime type if we had one */ if (NULL != mime) - (void) MHD_response_add_header (response, - MHD_HTTP_HEADER_CONTENT_TYPE, - mime); + (void)MHD_response_add_header (response, + MHD_HTTP_HEADER_CONTENT_TYPE, + mime); return MHD_action_from_response (request, response); } - if ( (MHD_HTTP_METHOD_POST == method) && - (0 == strcmp (path->cstr, - "/")) ) + if ((MHD_HTTP_METHOD_POST == method) + && (0 == strcmp (path->cstr, + "/"))) { struct UploadContext *uc; - uc = (struct UploadContext *) malloc (sizeof (struct UploadContext)); + uc = (struct UploadContext *)malloc (sizeof (struct UploadContext)); if (NULL == uc) return MHD_action_abort_request (request); /* out of memory, close connection */ memset (uc, @@ -1208,10 +1208,10 @@ generate_page (void *cls, &done_cb, uc); } - if ( ( (MHD_HTTP_METHOD_GET == method) || - (MHD_HTTP_METHOD_HEAD == method) ) && - (0 == strcmp (url, - "/")) ) + if (((MHD_HTTP_METHOD_GET == method) + || (MHD_HTTP_METHOD_HEAD == method)) + && (0 == strcmp (url, + "/"))) { const struct MHD_Action *ret; @@ -1231,7 +1231,7 @@ generate_page (void *cls, } -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) /** * Function called if we get a SIGPIPE. Does nothing. * @@ -1240,7 +1240,7 @@ generate_page (void *cls, static void catcher (int sig) { - (void) sig; /* Unused. Silent compiler warning. */ + (void)sig; /* Unused. Silent compiler warning. */ /* do nothing */ } @@ -1256,11 +1256,11 @@ ignore_sigpipe (void) sig.sa_handler = &catcher; sigemptyset (&sig.sa_mask); -#ifdef SA_INTERRUPT +# ifdef SA_INTERRUPT sig.sa_flags = SA_INTERRUPT; /* SunOS */ -#else +# else sig.sa_flags = SA_RESTART; -#endif +# endif if (0 != sigaction (SIGPIPE, &sig, &oldsig)) @@ -1271,13 +1271,13 @@ ignore_sigpipe (void) #endif -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) static void set_utf8_locale (void) { if (NULL != setlocale (LC_CTYPE, ".UTF8")) return; /* Success */ - (void) setlocale (LC_CTYPE, "C"); /* A fallback, not really helpful */ + (void)setlocale (LC_CTYPE, "C"); /* A fallback, not really helpful */ } @@ -1300,12 +1300,12 @@ main (int argc, unsigned int port; char dummy; - if ( (argc != 2) || - (1 != sscanf (argv[1], - "%u%c", - &port, - &dummy)) || - (UINT16_MAX < port) ) + if ((argc != 2) + || (1 != sscanf (argv[1], + "%u%c", + &port, + &dummy)) + || (UINT16_MAX < port)) { if (2 == argc) { @@ -1316,15 +1316,15 @@ main (int argc, } port = 8080; } -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) ignore_sigpipe (); #endif -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) set_utf8_locale (); #endif #ifdef MHD_HAVE_LIBMAGIC magic = magic_open (MAGIC_MIME_TYPE); - (void) magic_load (magic, NULL); + (void)magic_load (magic, NULL); #endif /* MHD_HAVE_LIBMAGIC */ my_mutex_init (&mutex); @@ -1371,7 +1371,7 @@ main (int argc, MHD_D_OPTION_DEFAULT_TIMEOUT_MILSEC (120000u), MHD_D_OPTION_CONN_MEMORY_LIMIT (256 * 1024), MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO, - (uint_least16_t) port))) + (uint_least16_t)port))) return 1; #ifdef PRODUCTION if (MHD_SC_OK != @@ -1389,7 +1389,7 @@ main (int argc, fprintf (stderr, "HTTP server running on port %u. Press ENTER to stop the server.\n", port); - (void) getc (stdin); + (void)getc (stdin); MHD_daemon_destroy (d); MHD_response_destroy (file_not_found_response); MHD_response_destroy (request_refused_response); diff --git a/src/examples2/json_echo.c b/src/examples2/json_echo.c @@ -48,7 +48,7 @@ #include <string.h> #include <stdio.h> #include <errno.h> -#if ! defined(_WIN32) || defined (__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) # include <sys/select.h> # include <unistd.h> #else @@ -130,9 +130,9 @@ handle_upload (void *upload_cls, json_error_t err; char *s; struct MHD_Response *response; - (void) upload_cls; /* Unused. Mute compiler warning. */ + (void)upload_cls; /* Unused. Mute compiler warning. */ - j = json_loadb ((char *) content_data, + j = json_loadb ((char *)content_data, content_data_size, 0, &err); @@ -159,8 +159,8 @@ handle_request (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - (void) cls; /* Unused. Mute compiler warning. */ - (void) path; /* Unused. Mute compiler warning. */ + (void)cls; /* Unused. Mute compiler warning. */ + (void)path; /* Unused. Mute compiler warning. */ if (method != MHD_HTTP_METHOD_POST) return MHD_action_from_response (request, @@ -185,7 +185,7 @@ sock_reg_update_cb ( MHD_APP_SOCKET_CNTX_TYPE *app_cntx, struct MHD_EventUpdateContext *ecb_cntx) { - (void) cls; /* Unused. Mute compiler warning. */ + (void)cls; /* Unused. Mute compiler warning. */ #ifdef MHD_SOCKETS_KIND_POSIX /* The value is limited by MHD_D_OPTION_FD_NUMBER_LIMIT() */ assert (fd < FD_SETSIZE); @@ -207,7 +207,7 @@ sock_reg_update_cb ( /* First time, allocate data structure to keep the socket and MHD's context */ app_cntx = - (MHD_APP_SOCKET_CNTX_TYPE *) malloc (sizeof (MHD_APP_SOCKET_CNTX_TYPE)); + (MHD_APP_SOCKET_CNTX_TYPE *)malloc (sizeof (MHD_APP_SOCKET_CNTX_TYPE)); if (NULL == app_cntx) return NULL; /* closes connection */ /* prepend to DLL */ @@ -252,9 +252,9 @@ mark_as_html (struct MHD_Response *response) { if (NULL == response) return; - (void) MHD_response_add_header (response, - MHD_HTTP_HEADER_CONTENT_TYPE, - "text/html"); + (void)MHD_response_add_header (response, + MHD_HTTP_HEADER_CONTENT_TYPE, + "text/html"); } @@ -270,12 +270,12 @@ main (int argc, unsigned int port; char dummy; - if ( (argc != 2) || - (1 != sscanf (argv[1], - "%u%c", - &port, - &dummy)) || - (UINT16_MAX < port) ) + if ((argc != 2) + || (1 != sscanf (argv[1], + "%u%c", + &port, + &dummy)) + || (UINT16_MAX < port)) { if (2 == argc) { @@ -322,7 +322,7 @@ main (int argc, MHD_D_OPTION_DEFAULT_TIMEOUT_MILSEC (120000u), MHD_D_OPTION_CONN_MEMORY_LIMIT (256 * 1024), MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO, - (uint_least16_t) port))) + (uint_least16_t)port))) return 1; if (MHD_SC_OK != MHD_daemon_start (d)) @@ -349,21 +349,21 @@ main (int argc, MHD_daemon_process_reg_events (d, &next_wait); #ifdef MHD_SOCKETS_KIND_POSIX - ts.tv_sec = (time_t) (next_wait / 1000000); + ts.tv_sec = (time_t)(next_wait / 1000000); #else /* W32 */ /* W32 cannot monitor "stdin" with select(). Use poor man replacement. */ if (300000u < next_wait) next_wait = 300000u; - ts.tv_sec = (long) (next_wait / 1000000); + ts.tv_sec = (long)(next_wait / 1000000); #endif /* W32 */ - ts.tv_usec = (long) (next_wait % 1000000); + ts.tv_usec = (long)(next_wait % 1000000); /* Real applications may do nicer error handling here */ - (void) select ((int) max_fd + 1, - &rs, - &ws, - &es, - &ts); + (void)select ((int)max_fd + 1, + &rs, + &ws, + &es, + &ts); #ifdef MHD_SOCKETS_KIND_POSIX if (FD_ISSET (STDIN_FILENO, &rs)) @@ -381,15 +381,15 @@ main (int argc, if (FD_ISSET (pos->fd, &rs)) current_state = - (enum MHD_FdState) (current_state | MHD_FD_STATE_RECV); + (enum MHD_FdState)(current_state | MHD_FD_STATE_RECV); if (FD_ISSET (pos->fd, &ws)) current_state = - (enum MHD_FdState) (current_state | MHD_FD_STATE_SEND); + (enum MHD_FdState)(current_state | MHD_FD_STATE_SEND); if (FD_ISSET (pos->fd, &es)) current_state = - (enum MHD_FdState) (current_state | MHD_FD_STATE_EXCEPT); + (enum MHD_FdState)(current_state | MHD_FD_STATE_EXCEPT); MHD_daemon_event_update (d, pos->ecb_cntx, current_state); diff --git a/src/examples2/minimal_auth_basic.c b/src/examples2/minimal_auth_basic.c @@ -50,10 +50,10 @@ req_cb (void *cls, const struct MHD_AuthBasicCreds *creds; /* a shortcut */ enum MHD_StatusCode res; - (void) cls; - (void) path; - (void) method; - (void) upload_size; /* Unused */ + (void)cls; + (void)path; + (void)method; + (void)upload_size; /* Unused */ res = MHD_request_get_info_dynamic (request, MHD_REQUEST_INFO_DYNAMIC_AUTH_BASIC_CREDS, @@ -81,14 +81,14 @@ req_cb (void *cls, /* Assign result to short-named variable for convenience */ creds = req_data.v_auth_basic_creds; - if ((creds->username.len == allowed_username_len) && - (memcmp (allowed_username, - creds->username.cstr, - creds->username.len) == 0) && - (creds->password.len == allowed_password_len) && - (memcmp (allowed_password, - creds->password.cstr, - creds->password.len) == 0)) + if ((creds->username.len == allowed_username_len) + && (memcmp (allowed_username, + creds->username.cstr, + creds->username.len) == 0) + && (creds->password.len == allowed_password_len) + && (memcmp (allowed_password, + creds->password.cstr, + creds->password.len) == 0)) { /* The client gave the correct username and password */ return MHD_action_from_response ( @@ -143,7 +143,7 @@ main (int argc, d, MHD_D_OPTION_WM_WORKER_THREADS (1), MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO, - (uint_least16_t) port))) + (uint_least16_t)port))) { fprintf (stderr, "Failed to set MHD daemon run parameters.\n"); @@ -160,7 +160,7 @@ main (int argc, { printf ("The MHD daemon is listening on port %d\n" "Press ENTER to stop.\n", port); - (void) fgetc (stdin); + (void)fgetc (stdin); } } printf ("Stopping... "); diff --git a/src/examples2/minimal_auth_digest.c b/src/examples2/minimal_auth_digest.c @@ -24,7 +24,7 @@ #include <stdlib.h> #include <string.h> #include <microhttpd2.h> -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) # include <wincrypt.h> /* For entropy generation */ #else # include <sys/types.h> @@ -56,10 +56,10 @@ req_cb (void *cls, const struct MHD_AuthDigestInfo *uname; /* a shortcut */ enum MHD_StatusCode res; - (void) cls; - (void) path; - (void) method; - (void) upload_size; /* Unused */ + (void)cls; + (void)path; + (void)method; + (void)upload_size; /* Unused */ res = MHD_request_get_info_dynamic (request, @@ -94,10 +94,10 @@ req_cb (void *cls, /* Assign result to short-named variable for convenience */ uname = req_data.v_auth_digest_info; - if ((uname->username.len == allowed_username_len) && - (memcmp (allowed_username, - uname->username.cstr, - uname->username.len) == 0)) + if ((uname->username.len == allowed_username_len) + && (memcmp (allowed_username, + uname->username.cstr, + uname->username.len) == 0)) { /* The client gave the correct username. Check the password match. */ enum MHD_DigestAuthResult auth_res; @@ -181,7 +181,7 @@ main (int argc, "The PORT must be a numeric value between 1 and 65535.\n"); return 2; } - if (! init_entropy_bytes ()) + if (!init_entropy_bytes ()) return 11; d = MHD_daemon_create (&req_cb, @@ -197,7 +197,7 @@ main (int argc, d, MHD_D_OPTION_WM_WORKER_THREADS (1), MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO, - (uint_least16_t) port), + (uint_least16_t)port), MHD_D_OPTION_RANDOM_ENTROPY (sizeof(entropy_bytes), entropy_bytes))) { @@ -216,7 +216,7 @@ main (int argc, { printf ("The MHD daemon is listening on port %d\n" "Press ENTER to stop.\n", port); - (void) fgetc (stdin); + (void)fgetc (stdin); } } printf ("Stopping... "); @@ -235,7 +235,7 @@ main (int argc, static int init_entropy_bytes (void) { -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) int fd; ssize_t len; size_t off; @@ -252,7 +252,7 @@ init_entropy_bytes (void) fprintf (stderr, "Failed to open random data source.\n"); return 0; } - for (off = 0; off < sizeof (entropy_bytes); off += (size_t) len) + for (off = 0; off < sizeof (entropy_bytes); off += (size_t)len) { len = read (fd, entropy_bytes + off, @@ -260,12 +260,12 @@ init_entropy_bytes (void) if (0 >= len) { fprintf (stderr, "Failed to read random data source.\n"); - (void) close (fd); + (void)close (fd); return 0; } } - (void) close (fd); - return ! 0; + (void)close (fd); + return !0; #else /* Native W32 */ HCRYPTPROV cc; BOOL b; @@ -279,10 +279,10 @@ init_entropy_bytes (void) { fprintf (stderr, "Failed to acquire crypto provider context: %lu\n", - (unsigned long) GetLastError ()); + (unsigned long)GetLastError ()); return 0; } - b = CryptGenRandom (cc, sizeof(entropy_bytes), (BYTE *) entropy_bytes); + b = CryptGenRandom (cc, sizeof(entropy_bytes), (BYTE *)entropy_bytes); if (FALSE == b) { fprintf (stderr, diff --git a/src/examples2/minimal_example2.c b/src/examples2/minimal_example2.c @@ -34,10 +34,10 @@ req_cb (void *cls, { static const char res_msg[] = "Hello there!\n"; - (void) cls; - (void) path; - (void) method; - (void) upload_size; /* Unused */ + (void)cls; + (void)path; + (void)method; + (void)upload_size; /* Unused */ return MHD_action_from_response ( request, @@ -83,7 +83,7 @@ main (int argc, d, MHD_D_OPTION_WM_WORKER_THREADS (1), MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO, - (uint_least16_t) port))) + (uint_least16_t)port))) { fprintf (stderr, "Failed to set MHD daemon run parameters.\n"); @@ -100,7 +100,7 @@ main (int argc, { printf ("The MHD daemon is listening on port %d\n" "Press ENTER to stop.\n", port); - (void) fgetc (stdin); + (void)fgetc (stdin); } } printf ("Stopping... "); diff --git a/src/incl_priv/autoinit_funcs.h b/src/incl_priv/autoinit_funcs.h @@ -120,8 +120,8 @@ #endif /* __has_attribute */ #if defined(__GNUC__) && __GNUC__ < 2 \ - && ! defined(AIF_GNUC_ATTR_CONSTR_NOT_SUPPORTED) \ - && ! defined(AIF_GNUC_ATTR_CONSTR_SUPPORTED) + && !defined(AIF_GNUC_ATTR_CONSTR_NOT_SUPPORTED) \ + && !defined(AIF_GNUC_ATTR_CONSTR_SUPPORTED) # define AIF_GNUC_ATTR_CONSTR_NOT_SUPPORTED 1 #endif @@ -130,19 +130,19 @@ #if (defined(AIF_GNUC_ATTR_CONSTR_SUPPORTED) \ || defined(__GNUC__) || defined(__clang__) \ || (defined(__SUNPRO_C) && __SUNPRO_C + 0 >= 0x5100)) && \ - ! defined(AIF_GNUC_ATTR_CONSTR_NOT_SUPPORTED) + !defined(AIF_GNUC_ATTR_CONSTR_NOT_SUPPORTED) -# define AIF_GNUC_SET_INIT_AND_DEINIT(FI,FD) \ - void __attribute__ ((constructor)) AIF_GNUC_init_helper_ ## FI (void); \ - void __attribute__ ((destructor)) AIF_GNUC_deinit_helper_ ## FD (void); \ - void __attribute__ ((constructor)) AIF_GNUC_init_helper_ ## FI (void) \ - { (void) (FI) (); } \ - void __attribute__ ((destructor)) AIF_GNUC_deinit_helper_ ## FD (void) \ - { (void) (FD) (); } \ - struct AIF_GNUC_dummy_str_ ## FI {int i;} +# define AIF_GNUC_SET_INIT_AND_DEINIT(FI, FD) \ + void __attribute__ ((constructor)) AIF_GNUC_init_helper_ ## FI (void); \ + void __attribute__ ((destructor)) AIF_GNUC_deinit_helper_ ## FD (void); \ + void __attribute__ ((constructor)) AIF_GNUC_init_helper_ ## FI (void) \ + { (void) (FI) (); } \ + void __attribute__ ((destructor)) AIF_GNUC_deinit_helper_ ## FD (void) \ + { (void) (FD) (); } \ + struct AIF_GNUC_dummy_str_ ## FI {int i;} #elif defined(_WIN32) && defined(_MSC_FULL_VER) && _MSC_VER + 0 >= 1600 && \ - ! defined(__CYGWIN__) + !defined(__CYGWIN__) /* Make sure that your project/sources define: _LIB if building a static library (_LIB is ignored if _CONSOLE is defined); @@ -154,8 +154,8 @@ # define AIF_STRMACRO(a) AIF_INSTRMACRO (a) /* Expand and strigify */ /* Concatenate macros */ -# define AIF_INCONCAT(a,b) a ## b /* Concatenate helper */ -# define AIF_CONCAT(a,b) AIF_INCONCAT (a,b) /* Expand and concatenate */ +# define AIF_INCONCAT(a, b) a ## b /* Concatenate helper */ +# define AIF_CONCAT(a, b) AIF_INCONCAT (a,b) /* Expand and concatenate */ /* Use "C" linkage for variables to simplify symbols decoration */ # ifdef __cplusplus @@ -168,11 +168,12 @@ /* How variables are decorated by compiler */ # if (defined(_WIN32) || defined(_WIN64)) \ - && ! defined(_M_IX86) && ! defined(_X86_) -# if ! defined(_M_X64) && ! defined(_M_AMD64) && ! defined(_x86_64_) \ - && ! defined(_M_ARM) && ! defined(_M_ARM64) + && !defined(_M_IX86) && !defined(_X86_) +# if !defined(_M_X64) && !defined(_M_AMD64) && !defined(_x86_64_) \ + && !defined(_M_ARM) && !defined(_M_ARM64) # ifndef AUTOINIT_FUNCS_NO_WARNINGS_W32_ARCH -#pragma message(__FILE__ "(" AIF_STRMACRO(__LINE__) ") : warning AIFW001 : " \ +# pragma \ + message(__FILE__ "(" AIF_STRMACRO(__LINE__) ") : warning AIFW001 : " \ "Untested architecture, linker may fail with unresolved symbols") # endif /* ! AUTOINIT_FUNCS_NO_WARNINGS_W32_ARCH */ # endif /* ! _M_X64 && ! _M_AMD64 && ! _x86_64_ && ! _M_ARM && ! _M_ARM64 */ @@ -184,14 +185,14 @@ # define AIF_W32_DECORVARNAME(v) _ ## v # define AIF_W32_VARDECORPREFIXSTR "_" # else -#error Do not know how to decorate symbols for this architecture +# error Do not know how to decorate symbols for this architecture # endif /* Internal variable prefix (can be any) */ # define AIF_W32_INITHELPERVARNAME(f) _aif_init_ptr_ ## f # define AIF_W32_INITHELPERVARNAMEDECORSTR(f) \ - AIF_W32_VARDECORPREFIXSTR AIF_STRMACRO (AIF_W32_INITHELPERVARNAME (f)) + AIF_W32_VARDECORPREFIXSTR AIF_STRMACRO (AIF_W32_INITHELPERVARNAME (f)) /* Sections (segments) for pointers to initialisers */ @@ -220,12 +221,12 @@ void __cdecl FuncName(void) */ /* Note: "extern" with initialisation value means that variable is declared AND defined. */ -# define AIF_W32_INIT_VFPTR_IN_SEG(S,F) \ - __pragma(section(S, long, read)) \ - __pragma(comment(linker, "/INCLUDE:" \ - AIF_W32_INITHELPERVARNAMEDECORSTR (F))) \ - AIF_W32_INITVARDECL __declspec(allocate (S)) void \ - (__cdecl * AIF_W32_INITHELPERVARNAME (F))(void) = &F +# define AIF_W32_INIT_VFPTR_IN_SEG(S, F) \ + __pragma(section(S, long, read)) \ + __pragma(comment(linker, "/INCLUDE:" \ + AIF_W32_INITHELPERVARNAMEDECORSTR (F))) \ + AIF_W32_INITVARDECL __declspec(allocate (S)) void \ + (__cdecl * AIF_W32_INITHELPERVARNAME (F))(void) = &F /* Unsafe sections (segments) for pointers to initialisers with "int" return type */ @@ -245,24 +246,24 @@ /* Startup process is aborted if initialiser returns non-zero */ /* Note: "extern" with initialisation value means that variable is declared AND defined. */ -# define AIF_W32_INIT_IFPTR_IN_SEG(S,F) \ - __pragma(section(S, long, read)) \ - __pragma(comment(linker, \ - "/INCLUDE:" AIF_W32_INITHELPERVARNAMEDECORSTR (F))) \ - AIF_W32_INITVARDECL __declspec(allocate (S)) int \ - (__cdecl * AIF_W32_INITHELPERVARNAME (F))(void) = &F +# define AIF_W32_INIT_IFPTR_IN_SEG(S, F) \ + __pragma(section(S, long, read)) \ + __pragma(comment(linker, \ + "/INCLUDE:" AIF_W32_INITHELPERVARNAMEDECORSTR (F))) \ + AIF_W32_INITVARDECL __declspec(allocate (S)) int \ + (__cdecl * AIF_W32_INITHELPERVARNAME (F))(void) = &F /* Not recommended / unsafe */ /* "lib" initialisers are called before "user" initialisers */ /* "C" initialisers are called before "C++" initialisers */ # define AIF_W32_REG_STAT_INIT_C_USER(F) \ - AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_C_USER,F) + AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_C_USER,F) # define AIF_W32_REG_STAT_INIT_C_LIB(F) \ - AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_C_LIB,F) + AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_C_LIB,F) # define AIF_W32_REG_STAT_INIT_CXX_USER(F) \ - AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_CXX_USER,F) + AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_CXX_USER,F) # define AIF_W32_REG_STAT_INIT_CXX_LIB(F) \ - AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_CXX_LIB,F) + AIF_W32_FPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_CXX_LIB,F) /* Declare macros for different initialisers sections */ @@ -270,11 +271,11 @@ /* Once function is registered as initialiser, it will be called automatically during application startup or library loading */ # define AIF_W32_REG_STAT_INIT_EARLY1(F) \ - AIF_W32_INIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_EARLY1,F) + AIF_W32_INIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_EARLY1,F) # define AIF_W32_REG_STAT_INIT_EARLY2(F) \ - AIF_W32_INIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_EARLY2,F) + AIF_W32_INIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_EARLY2,F) # define AIF_W32_REG_STAT_INIT_LATE(F) \ - AIF_W32_INIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_LATE,F) + AIF_W32_INIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_INIT_LATE,F) # ifndef _DLL /* Sections (segments) for pointers to deinitialisers */ @@ -298,7 +299,7 @@ /* Internal variable prefix (can be any) */ # define AIF_W32_DEINITHELPERVARNAME(f) _aif_deinit_ptr_ ## f # define AIF_W32_DEINITHELPERVARNAMEDECORSTR(f) \ - AIF_W32_VARDECORPREFIXSTR AIF_STRMACRO (AIF_W32_DEINITHELPERVARNAME (f)) + AIF_W32_VARDECORPREFIXSTR AIF_STRMACRO (AIF_W32_DEINITHELPERVARNAME (f)) /* The macro to declare section (segment), put variable pointing to deinit function to chosen segment, force linker to always include variable to @@ -307,23 +308,23 @@ void __cdecl FuncName(void) */ /* Note: "extern" with initialisation value means that variable is declared AND defined. */ -# define AIF_W32_DEINIT_VFPTR_IN_SEG(S,F) \ - __pragma(section(S, long, read)) \ - __pragma(comment(linker, "/INCLUDE:" \ - AIF_W32_DEINITHELPERVARNAMEDECORSTR (F))) \ - AIF_W32_INITVARDECL __declspec(allocate (S)) void \ - (__cdecl * AIF_W32_DEINITHELPERVARNAME (F))(void) = &F +# define AIF_W32_DEINIT_VFPTR_IN_SEG(S, F) \ + __pragma(section(S, long, read)) \ + __pragma(comment(linker, "/INCLUDE:" \ + AIF_W32_DEINITHELPERVARNAMEDECORSTR (F))) \ + AIF_W32_INITVARDECL __declspec(allocate (S)) void \ + (__cdecl * AIF_W32_DEINITHELPERVARNAME (F))(void) = &F /* Declare macros for different deinitialisers sections */ /* Macro can be used several times to register several deinitialisers */ /* Once function is registered as initialiser, it will be called automatically during application shutdown or library unloading */ # define AIF_W32_REG_STAT_DEINIT_EARLY(F) \ - AIF_W32_DEINIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_DEINIT_FIRST,F) + AIF_W32_DEINIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_DEINIT_FIRST,F) # define AIF_W32_REG_STAT_DEINIT_LATE1(F) \ - AIF_W32_DEINIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_DEINIT_SECOND,F) + AIF_W32_DEINIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_DEINIT_SECOND,F) # define AIF_W32_REG_STAT_DEINIT_LATE2(F) \ - AIF_W32_DEINIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_DEINIT_THIRD,F) + AIF_W32_DEINIT_VFPTR_IN_SEG (AIF_W32_SEG_STAT_DEINIT_THIRD,F) # endif /* ! _DLL */ @@ -339,24 +340,24 @@ /* By default C++ static or DLL-library code and any C code and will be registered as early initialiser, while C++ non-library code will be registered as late initialiser */ -# if (! defined(__cplusplus) || \ +# if (!defined(__cplusplus) || \ defined(_LIB) || defined(_USRDLL) || \ defined(AUTOINIT_FUNCS_FORCE_EARLY_INIT)) && \ - ! defined(AUTOINIT_FUNCS_FORCE_LATE_INIT) + !defined(AUTOINIT_FUNCS_FORCE_LATE_INIT) /* Use early initialiser and late deinitialiser */ # if defined(_LIB) || defined(_USRDLL) /* Static or DLL library */ # define AIF_W32_REGISTER_STAT_INIT(F) AIF_W32_REG_STAT_INIT_EARLY1 (F) # ifdef AIF_W32_REG_STAT_DEINIT_LATE2 # define AIF_W32_REGISTER_STAT_DEINIT(F) \ - AIF_W32_REG_STAT_DEINIT_LATE2 (F) + AIF_W32_REG_STAT_DEINIT_LATE2 (F) # endif # else /* Application code */ # define AIF_W32_REGISTER_STAT_INIT(F) AIF_W32_REG_STAT_INIT_EARLY2 (F) # ifdef AIF_W32_REG_STAT_DEINIT_LATE1 # define AIF_W32_REGISTER_STAT_DEINIT(F) \ - AIF_W32_REG_STAT_DEINIT_LATE1 (F) + AIF_W32_REG_STAT_DEINIT_LATE1 (F) # endif # endif # else @@ -364,7 +365,7 @@ # define AIF_W32_REGISTER_STAT_INIT(F) AIF_W32_REG_STAT_INIT_LATE (F) # ifdef AIF_W32_REG_STAT_DEINIT_EARLY # define AIF_W32_REGISTER_STAT_DEINIT(F) \ - AIF_W32_REG_STAT_DEINIT_EARLY (F) + AIF_W32_REG_STAT_DEINIT_EARLY (F) # endif # endif @@ -377,43 +378,43 @@ If it is used, it can save from including an extra header. */ # if defined(AIF_W32_REGISTER_STAT_DEINIT) \ && defined(AUTOINIT_FUNCS_ALLOW_W32_STAT_DEINIT) -# define AIF_W32_SET_STAT_INIT_AND_DEINIT(FI,FD) \ - AIF_W32_INITHELPERFUNCDECL void \ - __cdecl AIF_W32_stat_init_helper_ ## FI (void); \ - AIF_W32_INITHELPERFUNCDECL void \ - __cdecl AIF_W32_stat_deinit_helper_ ## FD (void); \ - AIF_W32_INITHELPERFUNCDECL void \ - __cdecl AIF_W32_stat_init_helper_ ## FI (void) \ - { (void) (FI) (); } \ - AIF_W32_INITHELPERFUNCDECL void \ - __cdecl AIF_W32_stat_deinit_helper_ ## FD (void) \ - { (void) (FD) (); } \ - AIF_W32_REGISTER_STAT_INIT (AIF_W32_stat_init_helper_ ## FI); \ - AIF_W32_REGISTER_STAT_DEINIT (AIF_W32_stat_deinit_helper_ ## FD) +# define AIF_W32_SET_STAT_INIT_AND_DEINIT(FI, FD) \ + AIF_W32_INITHELPERFUNCDECL void \ + __cdecl AIF_W32_stat_init_helper_ ## FI (void); \ + AIF_W32_INITHELPERFUNCDECL void \ + __cdecl AIF_W32_stat_deinit_helper_ ## FD (void); \ + AIF_W32_INITHELPERFUNCDECL void \ + __cdecl AIF_W32_stat_init_helper_ ## FI (void) \ + { (void) (FI) (); } \ + AIF_W32_INITHELPERFUNCDECL void \ + __cdecl AIF_W32_stat_deinit_helper_ ## FD (void) \ + { (void) (FD) (); } \ + AIF_W32_REGISTER_STAT_INIT (AIF_W32_stat_init_helper_ ## FI); \ + AIF_W32_REGISTER_STAT_DEINIT (AIF_W32_stat_deinit_helper_ ## FD) # else /* Note: 'atexit()' is just a wrapper for '_onexit()' on W32 */ # include <stdlib.h> /* required for _onexit() */ -# define AIF_W32_SET_STAT_INIT_AND_DEINIT(FI,FD) \ - AIF_W32_INITHELPERFUNCDECL void \ - __cdecl AIF_W32_stat_init_helper_ ## FI (void); \ - AIF_W32_INITHELPERFUNCDECL int \ - __cdecl AIF_W32_stat_deinit_helper_ ## FD (void); \ - AIF_W32_INITHELPERFUNCDECL void \ - __cdecl AIF_W32_stat_init_helper_ ## FI (void) \ - { (void) (FI) (); \ - _onexit (&AIF_W32_stat_deinit_helper_ ## FD); } \ - AIF_W32_INITHELPERFUNCDECL int \ - __cdecl AIF_W32_stat_deinit_helper_ ## FD (void) \ - { (void) (FD) (); return ! 0; } \ - AIF_W32_REGISTER_STAT_INIT (AIF_W32_stat_init_helper_ ## FI) +# define AIF_W32_SET_STAT_INIT_AND_DEINIT(FI, FD) \ + AIF_W32_INITHELPERFUNCDECL void \ + __cdecl AIF_W32_stat_init_helper_ ## FI (void); \ + AIF_W32_INITHELPERFUNCDECL int \ + __cdecl AIF_W32_stat_deinit_helper_ ## FD (void); \ + AIF_W32_INITHELPERFUNCDECL void \ + __cdecl AIF_W32_stat_init_helper_ ## FI (void) \ + { (void) (FI) (); \ + _onexit (&AIF_W32_stat_deinit_helper_ ## FD); } \ + AIF_W32_INITHELPERFUNCDECL int \ + __cdecl AIF_W32_stat_deinit_helper_ ## FD (void) \ + { (void) (FD) (); return ! 0; } \ + AIF_W32_REGISTER_STAT_INIT (AIF_W32_stat_init_helper_ ## FI) # endif #endif /* _WIN32 && _MSC_VER + 0 >= 1600 && ! _GNUC_ATTR_CONSTR_SUPPORTED */ -#if defined(_WIN32) && ! defined(__CYGWIN__) && \ +#if defined(_WIN32) && !defined(__CYGWIN__) && \ (defined(_USRDLL) || defined(DLL_EXPORT)) # if defined(__MINGW32__) || defined(__MINGW64__) @@ -468,19 +469,19 @@ Define AUTOINIT_FUNCS_USR_DLLMAIN_NAME to user function name if usr_DllMain is not suitable. */ # ifndef AUTOINIT_FUNCS_CALL_USR_DLLMAIN -# define AIF_W32_CALL_USER_DLLMAIN(h,r,p) TRUE +# define AIF_W32_CALL_USER_DLLMAIN(h, r, p) TRUE # else /* AUTOINIT_FUNCS_CALL_USR_DLLMAIN */ # ifndef AUTOINIT_FUNCS_USR_DLLMAIN_NAME # define AIF_W32_USR_DLLMAIN_NAME usr_DllMain # else # define AIF_W32_USR_DLLMAIN_NAME AUTOINIT_FUNCS_USR_DLLMAIN_NAME # endif -# define AIF_W32_CALL_USER_DLLMAIN(h,r,p) \ - AIF_W32_USR_DLLMAIN_NAME ((h),(r),(p)) +# define AIF_W32_CALL_USER_DLLMAIN(h, r, p) \ + AIF_W32_USR_DLLMAIN_NAME ((h),(r),(p)) # ifdef AUTOINIT_FUNCS_DECLARE_USR_DLLMAIN # define AIF_DECL_USR_DLLMAIN \ - BOOL WINAPI AIF_W32_USR_DLLMAIN_NAME (HINSTANCE hinst, DWORD reason, \ - LPVOID pReserved); + BOOL WINAPI AIF_W32_USR_DLLMAIN_NAME (HINSTANCE hinst, DWORD reason, \ + LPVOID pReserved); # endif # endif /* AUTOINIT_FUNCS_CALL_USR_DLLMAIN */ @@ -488,21 +489,21 @@ # define AIF_DECL_USR_DLLMAIN /* empty */ # endif -# define AIF_W32_SET_DLL_INIT_AND_DEINIT(FI,FD) \ - BOOL WINAPI DllMain (HINSTANCE hinst, DWORD reason, LPVOID pReserved); \ - AIF_DECL_USR_DLLMAIN \ - BOOL WINAPI DllMain (HINSTANCE hinst, DWORD reason, LPVOID pReserved) \ - { BOOL aif_ret; (void) hinst; \ - if (AIF_W32_DLL_PROCESS_ATTACH == reason) { \ - (void) (FI) (); \ - aif_ret = AIF_W32_CALL_USER_DLLMAIN (hinst, reason, pReserved); \ - if (! aif_ret && NULL != pReserved) { (void) (FD) (); } } \ - else if (AIF_W32_DLL_PROCESS_DETACH == reason) { \ - aif_ret = AIF_W32_CALL_USER_DLLMAIN (hinst, reason, pReserved); \ - if (AIF_W32_IS_DLL_DEINIT_SAFE (pReserved)) { (void) (FD) (); } } \ - else aif_ret = AIF_W32_CALL_USER_DLLMAIN (hinst, reason, pReserved); \ - return aif_ret; \ - } struct AIF_W32_dummy_strc_ ## FI {int i;} +# define AIF_W32_SET_DLL_INIT_AND_DEINIT(FI, FD) \ + BOOL WINAPI DllMain (HINSTANCE hinst, DWORD reason, LPVOID pReserved); \ + AIF_DECL_USR_DLLMAIN \ + BOOL WINAPI DllMain (HINSTANCE hinst, DWORD reason, LPVOID pReserved) \ + { BOOL aif_ret; (void) hinst; \ + if (AIF_W32_DLL_PROCESS_ATTACH == reason) { \ + (void) (FI) (); \ + aif_ret = AIF_W32_CALL_USER_DLLMAIN (hinst, reason, pReserved); \ + if (! aif_ret && NULL != pReserved) { (void) (FD) (); } } \ + else if (AIF_W32_DLL_PROCESS_DETACH == reason) { \ + aif_ret = AIF_W32_CALL_USER_DLLMAIN (hinst, reason, pReserved); \ + if (AIF_W32_IS_DLL_DEINIT_SAFE (pReserved)) { (void) (FD) (); } } \ + else aif_ret = AIF_W32_CALL_USER_DLLMAIN (hinst, reason, pReserved); \ + return aif_ret; \ + } struct AIF_W32_dummy_strc_ ## FI {int i;} #endif /* _WIN32 && ! __CYGWIN__ && (_USRDLL || DLL_EXPORT) */ @@ -511,26 +512,26 @@ Static registration works for DLL too, but less precise and flexible. */ #if defined(AIF_W32_SET_DLL_INIT_AND_DEINIT) \ - && ! (defined(AUTOINIT_FUNCS_PREFER_STATIC_REG) \ + && !(defined(AUTOINIT_FUNCS_PREFER_STATIC_REG) \ && (defined(AIF_GNUC_SET_INIT_AND_DEINIT) \ || defined(AIF_W32_SET_STAT_INIT_AND_DEINIT))) -# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI,FD) \ - AIF_W32_SET_DLL_INIT_AND_DEINIT (FI,FD) +# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI, FD) \ + AIF_W32_SET_DLL_INIT_AND_DEINIT (FI,FD) /* Indicate that automatic initialisers/deinitialisers are supported */ # define AIF_AUTOINIT_FUNCS_ARE_SUPPORTED 1 #elif defined(AIF_GNUC_SET_INIT_AND_DEINIT) -# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI,FD) \ - AIF_GNUC_SET_INIT_AND_DEINIT (FI,FD) +# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI, FD) \ + AIF_GNUC_SET_INIT_AND_DEINIT (FI,FD) /* Indicate that automatic initialisers/deinitialisers are supported */ # define AIF_AUTOINIT_FUNCS_ARE_SUPPORTED 1 #elif defined(AIF_W32_SET_STAT_INIT_AND_DEINIT) -# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI,FD) \ - AIF_W32_SET_STAT_INIT_AND_DEINIT (FI,FD) +# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI, FD) \ + AIF_W32_SET_STAT_INIT_AND_DEINIT (FI,FD) /* Indicate that automatic initialisers/deinitialisers are supported */ # define AIF_AUTOINIT_FUNCS_ARE_SUPPORTED 1 @@ -540,7 +541,7 @@ this header to abort compilation if automatic initialisers/deinitialisers are not supported */ # ifdef AUTOINIT_FUNCS_EMIT_ERROR_IF_NOT_SUPPORTED -#error User-defined initialiser and deinitialiser functions not supported +# error User-defined initialiser and deinitialiser functions not supported # endif /* AUTOINIT_FUNCS_EMIT_ERROR_IF_NOT_SUPPORTED */ # if defined(__SUNPRO_C) && (defined(sun) || defined(__sun)) \ @@ -551,14 +552,14 @@ /* "#parama fini(func_name)" can be used. "func_name" must be declared. The form is "void func_name(void)". */ # define AIF_PRAGMA_FINI_SUPPORTED 1 -# if ! defined(AUTOINIT_FUNCS_NO_WARNINGS_SUNPRO_C) -#warning Compiler supports "#pragma init(func)" and "#pragma fini(func)" -#warning Use "pragma" to set initialiser and deinitialiser functions +# if !defined(AUTOINIT_FUNCS_NO_WARNINGS_SUNPRO_C) +# warning Compiler supports "#pragma init(func)" and "#pragma fini(func)" +# warning Use "pragma" to set initialiser and deinitialiser functions # endif # endif /* "Not supported" implementation */ -# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI,FD) /* No-op */ +# define AIF_SET_INIT_AND_DEINIT_FUNCS(FI, FD) /* No-op */ /* Indicate that automatic initialisers/deinitialisers are not supported */ # define AIF_AUTOINIT_FUNCS_ARE_NOT_SUPPORTED 1 diff --git a/src/incl_priv/mhd_sys_options.h b/src/incl_priv/mhd_sys_options.h @@ -54,12 +54,12 @@ #define MHD_SYS_OPTIONS_H 1 #if defined(MICROHTTPD2_H) || defined(MICROHTTPD2_PORTABILITY_H) -#error the header "mhd_sys_options.h" must be included before any other header +# error the header "mhd_sys_options.h" must be included before any other header #endif #ifndef HAVE_CONFIG_H # ifndef _MSC_VER -#error HAVE_CONFIG_H must be defined +# error HAVE_CONFIG_H must be defined # endif #endif @@ -78,9 +78,9 @@ # define MHD_VISIBILITY_EXTERN /* empty */ #endif -#if ! defined(_WIN32) || \ - (! defined(DLL_EXPORT) /* Defined by libtool for shared version */ \ - && ! defined(MHD_W32DLL) /* Defined by MS VS projects for MHD DLL */) +#if !defined(_WIN32) || \ + (!defined(DLL_EXPORT) /* Defined by libtool for shared version */ \ + && !defined(MHD_W32DLL) /* Defined by MS VS projects for MHD DLL */) # define MHD_EXPORTED /* empty */ #else # define MHD_EXPORTED __declspec(dllexport) @@ -109,8 +109,8 @@ # ifdef BUILDING_MHD_LIB /* Building MHD itself */ # define MHD_EXTERN_ \ - extern MHD_VISIBILITY_EXTERN MHD_EXPORTED \ - mhd_EXTERNALLY_ACCESSIBLE MHD_EXTERN_USED + extern MHD_VISIBILITY_EXTERN MHD_EXPORTED \ + mhd_EXTERNALLY_ACCESSIBLE MHD_EXTERN_USED # else /* ! BUILDING_MHD_LIB */ /* Test or example code, using MHD as a library */ # define MHD_EXTERN_ extern @@ -176,56 +176,56 @@ #ifdef HAVE_ATTR_ACCESS_READ # define MHD_FN_PAR_IN_(param_num) \ - __attribute__ ((access (read_only,param_num))) + __attribute__ ((access (read_only,param_num))) #else # define MHD_FN_PAR_IN_(param_num) /* empty */ #endif #ifdef HAVE_ATTR_ACCESS_READ_SIZE -# define MHD_FN_PAR_IN_SIZE_(param_num,size_num) \ - __attribute__ ((access (read_only,param_num,size_num))) +# define MHD_FN_PAR_IN_SIZE_(param_num, size_num) \ + __attribute__ ((access (read_only,param_num,size_num))) #else -# define MHD_FN_PAR_IN_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_IN_SIZE_(param_num, size_num) /* empty */ #endif #ifdef HAVE_ATTR_ACCESS_READ_WRITE # define MHD_FN_PAR_OUT_(param_num) \ - __attribute__ ((access (write_only,param_num))) + __attribute__ ((access (write_only,param_num))) #else # define MHD_FN_PAR_OUT_(param_num) /* empty */ #endif #ifdef HAVE_ATTR_ACCESS_WRITE -# define MHD_FN_PAR_OUT_SIZE_(param_num,size_num) \ - __attribute__ ((access (write_only,param_num,size_num))) +# define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) \ + __attribute__ ((access (write_only,param_num,size_num))) #else -# define MHD_FN_PAR_OUT_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) /* empty */ #endif #ifdef HAVE_ATTR_ACCESS_READ_WRITE # define MHD_FN_PAR_INOUT_(param_num) \ - __attribute__ ((access (read_write,param_num))) + __attribute__ ((access (read_write,param_num))) #else # define MHD_FN_PAR_INOUT_(param_num) /* empty */ #endif #ifdef HAVE_ATTR_ACCESS_READ_WRITE_SIZE -# define MHD_FN_PAR_INOUT_SIZE_(param_num,size_num) \ - __attribute__ ((access (read_write,param_num,size_num))) +# define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num) \ + __attribute__ ((access (read_write,param_num,size_num))) #else -# define MHD_FN_PAR_INOUT_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num) /* empty */ #endif #ifdef HAVE_ATTR_FD_ARG_READ # define MHD_FN_PAR_FD_READ_(param_num) \ - __attribute__ ((fd_arg_read (param_num))) + __attribute__ ((fd_arg_read (param_num))) #else # define MHD_FN_PAR_FD_READ_(param_num) /* empty */ #endif #ifdef HAVE_ATTR_NULL_TERM_STR # define MHD_FN_PAR_CSTR_(param_num) \ - __attribute__ ((null_terminated_string_arg (param_num))) + __attribute__ ((null_terminated_string_arg (param_num))) #else # define MHD_FN_PAR_CSTR_(param_num) /* empty */ #endif @@ -282,13 +282,13 @@ * another function @a destructor. */ # define mhd_FN_OBJ_CONSTRUCTOR(destructor) \ - __attribute__((malloc (destructor))) + __attribute__((malloc (destructor))) #else /** * Indicates that function creates the object that must be destructed by * another function @a destructor. */ - # define mhd_FN_OBJ_CONSTRUCTOR(destructor) /* empty */ +# define mhd_FN_OBJ_CONSTRUCTOR(destructor) /* empty */ #endif #ifdef HAVE_ATTR_ENUM_EXTNS_CLOSED @@ -423,7 +423,7 @@ # endif #endif /* mhd_THREADS_KIND_POSIX || mhd_THREADS_KIND_W32 */ -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) /** * Defined if the platform is native W32. * Not define on Cygwin. @@ -469,13 +469,13 @@ #if defined(OS390) -#define _OPEN_THREADS -#define _OPEN_SYS_SOCK_IPV6 -#define _OPEN_MSGQ_EXT -#define _LP64 +# define _OPEN_THREADS +# define _OPEN_SYS_SOCK_IPV6 +# define _OPEN_MSGQ_EXT +# define _LP64 #endif -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) /* Declare POSIX-compatible names */ # define _CRT_DECLARE_NONSTDC_NAMES 1 /* Do not warn about POSIX name usage */ @@ -484,7 +484,7 @@ # define _WIN32_WINNT 0x0600 # else /* _WIN32_WINNT */ # if _WIN32_WINNT < 0x0501 -#error "Headers for Windows XP or later are required" +# error "Headers for Windows XP or later are required" # endif /* _WIN32_WINNT < 0x0501 */ # endif /* _WIN32_WINNT */ # ifndef WIN32_LEAN_AND_MEAN @@ -500,12 +500,12 @@ #endif #if defined(__VXWORKS__) || defined(__vxworks) || defined(OS_VXWORKS) -#define RESTRICT __restrict__ +# define RESTRICT __restrict__ #endif /* __VXWORKS__ || __vxworks || OS_VXWORKS */ #if defined(__linux__) && \ (defined(HAVE_SENDFILE64) || defined(HAVE_LSEEK64) || defined(HAVE_PREAD64)) -# if ! defined(_LARGEFILE64_SOURCE) +# if !defined(_LARGEFILE64_SOURCE) /* On Linux, special macro is required to enable definitions of some xxx64 functions */ # define _LARGEFILE64_SOURCE 1 # endif @@ -513,7 +513,7 @@ #ifdef HAVE_C11_GMTIME_S /* Special macro is required to enable C11 definition of gmtime_s() function */ -#define __STDC_WANT_LIB_EXT1__ 1 +# define __STDC_WANT_LIB_EXT1__ 1 #endif /* HAVE_C11_GMTIME_S */ #if defined(__sun) || defined(__illumos__) @@ -524,8 +524,8 @@ /* Ensure that exactly one of the two macros is always defined */ #if defined(NDEBUG) && defined(_DEBUG) -#error Both _DEBUG and NDEBUG are defined -#elif ! defined(_DEBUG) && ! defined(NDEBUG) +# error Both _DEBUG and NDEBUG are defined +#elif !defined(_DEBUG) && !defined(NDEBUG) # ifndef DEBUG /* Used by some toolchains */ # define NDEBUG 1 /* Use NDEBUG by default */ # else /* DEBUG */ @@ -533,25 +533,25 @@ # endif /* DEBUG */ #endif /* !_DEBUG && !NDEBUG */ -#if ! defined(MHD_CC_OPTIMISE_FOR_SIZE) \ - && ! defined(MHD_CC_OPTIMISE_FOR_SPEED) +#if !defined(MHD_CC_OPTIMISE_FOR_SIZE) \ + && !defined(MHD_CC_OPTIMISE_FOR_SPEED) # if defined(__OPTIMIZE_SIZE__) || defined(__OPTIMISE_SPACE) # define MHD_CC_OPTIMISE_FOR_SIZE 1 # elif defined(__OPTIMIZE__) || defined(__OPTIMISE_TIME) # define MHD_CC_OPTIMISE_FOR_SPEED 1 # endif /* __OPTIMIZE__ */ #elif defined(MHD_CC_OPTIMISE_FOR_SIZE) && defined(MHD_CC_OPTIMISE_FOR_SPEED) -#error MHD_CC_OPTIMISE_FOR_SIZE and MHD_CC_OPTIMISE_FOR_SPEED both defined. +# error MHD_CC_OPTIMISE_FOR_SIZE and MHD_CC_OPTIMISE_FOR_SPEED both defined. #endif #if defined(MHD_FAVOR_FAST_CODE) && defined(MHD_FAVOR_SMALL_CODE) -#error MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined. -#error Cannot favor speed and size at the same time. +# error MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined. +# error Cannot favor speed and size at the same time. #endif /* MHD_FAVOR_FAST_CODE && MHD_FAVOR_SMALL_CODE */ /* Define MHD_FAVOR_FAST_CODE to force fast code path or define MHD_FAVOR_SMALL_CODE to choose compact code path */ -#if ! defined(MHD_FAVOR_FAST_CODE) && ! defined(MHD_FAVOR_SMALL_CODE) +#if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE) /* Try to guess automatically user preferences */ # if defined(MHD_CC_OPTIMISE_FOR_SPEED) # define MHD_FAVOR_FAST_CODE 1 @@ -560,7 +560,7 @@ # endif /* __OPTIMIZE__ */ #endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */ -#if ! defined(MHD_FAVOR_FAST_CODE) && ! defined(MHD_FAVOR_SMALL_CODE) +#if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE) /* Use faster code by default */ # define MHD_FAVOR_FAST_CODE 1 #endif /* !MHD_FAVOR_FAST_CODE && !MHD_FAVOR_SMALL_CODE */ @@ -592,7 +592,7 @@ #else /* ! (MHD_ASAN_ACTIVE && HAVE_SANITIZER_ASAN_INTERFACE_H && (FUNC_ATTR_PTRCOMPARE_WORKS || FUNC_ATTR_NOSANITIZE_WORKS)) */ # ifdef MHD_ASAN_POISON_ACTIVE -#error User memory poisoning is active, but conditions are not suitable +# error User memory poisoning is active, but conditions are not suitable # endif /* MHD_ASAN_POISON_ACTIVE */ #endif /* ! (MHD_ASAN_ACTIVE && HAVE_SANITIZER_ASAN_INTERFACE_H && (FUNC_ATTR_PTRCOMPARE_WORKS || FUNC_ATTR_NOSANITIZE_WORKS)) */ @@ -602,13 +602,13 @@ # define mhd_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE /* empty */ #else /* _MSC_FULL_VER */ # define mhd_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE \ - __pragma(runtime_checks("c", off)) + __pragma(runtime_checks("c", off)) # define mhd_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE \ - __pragma(runtime_checks("c", restore)) + __pragma(runtime_checks("c", restore)) #endif /* _MSC_FULL_VER */ -#if ! defined(mhd_W32_NATIVE) +#if !defined(mhd_W32_NATIVE) /** * Indicate that suppression of SIGPIPE is required for some network * system calls. @@ -670,7 +670,7 @@ # undef _Atomic # define _Atomic /* empty */ # undef MHD_HAVE_C_CONSTEXPR -# if defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 202311) +# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311) # define bool _Bool # define true 1 # define false 0 diff --git a/src/include/d_options.rec b/src/include/d_options.rec @@ -204,9 +204,9 @@ CustomSetter: /* custom setter */ + ++pass_size; /* Space for zero-termination */ + if (NULL != settings->tls_cert_key.v_mem_cert) + free (settings->tls_cert_key.v_mem_cert); // TODO: Support multiple certificates!! -+ settings->tls_cert_key.v_mem_cert = (char *) malloc (cert_size -+ + key_size -+ + pass_size); ++ settings->tls_cert_key.v_mem_cert = (char *)malloc (cert_size ++ + key_size ++ + pass_size); + if (NULL == settings->tls_cert_key.v_mem_cert) + return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; + memcpy (settings->tls_cert_key.v_mem_cert, @@ -283,7 +283,7 @@ CustomSetter: /* custom setter */ + len = strlen (option->val.tls_app_name.v_app_name); + if (128 <= len) + return MHD_SC_CONFIGURATION_PARAM_TOO_LARGE; -+ settings->tls_app_name.v_app_name = (char *) malloc (len + 1u); ++ settings->tls_app_name.v_app_name = (char *)malloc (len + 1u); + if (NULL == settings->tls_app_name.v_app_name) + return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; + memcpy (settings->tls_app_name.v_app_name, @@ -315,7 +315,7 @@ CustomSetter: /* custom setter */ + { + size_t len; + len = strlen (option->val.tls_openssl_def_file.v_pathname); -+ settings->tls_openssl_def_file.v_pathname = (char *) malloc (len + 1u); ++ settings->tls_openssl_def_file.v_pathname = (char *)malloc (len + 1u); + if (NULL == settings->tls_openssl_def_file.v_pathname) + return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; + memcpy (settings->tls_openssl_def_file.v_pathname, diff --git a/src/include/mhd_future.h b/src/include/mhd_future.h @@ -1,8 +1,8 @@ #ifndef MHD_EXTERN_ -# if ! defined(_WIN32) +# if !defined(_WIN32) # define MHD_EXTERN_ extern # else /* defined(_WIN32) */ -# if ! defined(MHD_W32LIB) +# if !defined(MHD_W32LIB) # define MHD_EXTERN_ extern # else /* defined(_WIN32) && efined(MHD_W32LIB) */ /* Define MHD_W32DLL when using MHD as W32 .DLL to speed up linker a little */ @@ -88,19 +88,19 @@ # define MHD_FN_PAR_IN_(param_num) /* empty */ #endif /* !MHD_FN_PAR_IN_ */ #ifndef MHD_FN_PAR_IN_SIZE_ -# define MHD_FN_PAR_IN_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_IN_SIZE_(param_num, size_num) /* empty */ #endif /* !MHD_FN_PAR_IN_SIZE_ */ #ifndef MHD_FN_PAR_OUT_ # define MHD_FN_PAR_OUT_(param_num) /* empty */ #endif /* !MHD_FN_PAR_OUT_ */ #ifndef MHD_FN_PAR_OUT_SIZE_ -# define MHD_FN_PAR_OUT_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) /* empty */ #endif /* !MHD_FN_PAR_OUT_SIZE_ */ #ifndef MHD_FN_PAR_INOUT_ # define MHD_FN_PAR_INOUT_(param_num) /* empty */ #endif /* !MHD_FN_PAR_INOUT_ */ #ifndef MHD_FN_PAR_INOUT_SIZE_ -# define MHD_FN_PAR_INOUT_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num) /* empty */ #endif /* !MHD_FN_PAR_INOUT_SIZE_ */ #ifndef MHD_FN_PAR_FD_READ_ # define MHD_FN_PAR_FD_READ_(param_num) /* empty */ @@ -132,7 +132,6 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_ThreadingPollingMode * and #MHD_process_watched_fds() with edge triggered sockets polling. */ MHD_TM_EXTERNAL_EVENT_LOOP_WFD_EDGE = 11 - , }; /* FUTURE: @@ -187,8 +186,8 @@ MHD_get_watched_fds ( struct MHD_WatchedFD wfds[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)], uint_fast64_t *max_wait) MHD_FN_PAR_NONNULL_ (1) -MHD_FN_PAR_OUT_(3) MHD_FN_PAR_NONNULL_(3) -MHD_FN_PAR_OUT_(4) MHD_FN_PAR_NONNULL_ (4); +MHD_FN_PAR_OUT_ (3) MHD_FN_PAR_NONNULL_ (3) +MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_NONNULL_ (4); enum MHD_WatchedFdAction @@ -256,8 +255,8 @@ MHD_get_watched_fds_update ( struct MHD_WatchedFdUpdate wfdus[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)], uint_fast64_t *max_wait) MHD_FN_PAR_NONNULL_ (1) -MHD_FN_PAR_OUT_(3) MHD_FN_PAR_NONNULL_(3) -MHD_FN_PAR_OUT_(4) MHD_FN_PAR_NONNULL_ (4); +MHD_FN_PAR_OUT_ (3) MHD_FN_PAR_NONNULL_ (3) +MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_NONNULL_ (4); ; @@ -278,7 +277,7 @@ MHD_process_watched_fds ( unsigned int num_elements, const struct MHD_WatchedFD fds[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)]) MHD_FN_PAR_NONNULL_ (1) -MHD_FN_PAR_IN_(3) MHD_FN_PAR_NONNULL_ (3); +MHD_FN_PAR_IN_ (3) MHD_FN_PAR_NONNULL_ (3); // FIXME: convert introspection diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h @@ -186,11 +186,11 @@ MHD_C_DECLARATIONS_START_HERE_ # endif # ifndef MHD_SYS_SOCKET_TYPES_H /* Headers for 'struct sockaddr' */ -# if ! defined(_WIN32) || defined(__CYGWIN__) +# if !defined(_WIN32) || defined(__CYGWIN__) # include <sys/socket.h> # else /* Prevent conflict of <winsock.h> and <winsock2.h> */ -# if ! defined(_WINSOCK2API_) && ! defined(_WINSOCKAPI_) +# if !defined(_WINSOCK2API_) && !defined(_WINSOCKAPI_) # ifndef WIN32_LEAN_AND_MEAN /* Do not use unneeded parts of W32 headers. */ # define WIN32_LEAN_AND_MEAN 1 @@ -228,7 +228,7 @@ enum MHD_Bool }; -#define MHD_BOOL_DEFINED 1 +# define MHD_BOOL_DEFINED 1 #endif /* ! MHD_BOOL_DEFINED */ #ifndef MHD_STRINGS_DEFINED @@ -271,12 +271,12 @@ struct MHD_StringNullable const char *cstr; }; -#define MHD_STRINGS_DEFINED 1 +# define MHD_STRINGS_DEFINED 1 #endif /* ! MHD_STRINGS_DEFINED */ #ifndef MHD_INVALID_SOCKET -# if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET) +# if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) # define MHD_SOCKETS_KIND_POSIX 1 /** * MHD_Socket is a type for socket FDs @@ -302,7 +302,7 @@ typedef SOCKET MHD_Socket; # define MHD_SIZE_UNKNOWN UINT64_MAX #else # define MHD_SIZE_UNKNOWN \ - MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) + MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) #endif @@ -314,7 +314,7 @@ typedef SOCKET MHD_Socket; # define MHD_WAIT_INDEFINITELY UINT64_MAX #else # define MHD_WAIT_INDEFINITELY \ - MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) + MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) #endif @@ -1916,7 +1916,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_Method MHD_HTTP_METHOD_ASTERISK = 9 }; -#define MHD_HTTP_METHOD_DEFINED 1 +# define MHD_HTTP_METHOD_DEFINED 1 #endif /* ! MHD_HTTP_METHOD_DEFINED */ /** @@ -2061,7 +2061,7 @@ enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_HTTP_PostEncoding /** @} */ /* end of group postenc */ -#define MHD_HTTP_POSTENCODING_DEFINED 1 +# define MHD_HTTP_POSTENCODING_DEFINED 1 #endif /* ! MHD_HTTP_POSTENCODING_DEFINED */ @@ -2799,7 +2799,7 @@ enum MHD_FIXED_ENUM_ MHD_FdState /** * Checks whether specific @a state is enabled/set in the @a var */ -#define MHD_FD_STATE_IS_SET(var,state) \ +#define MHD_FD_STATE_IS_SET(var, state) \ (MHD_FD_STATE_NONE != \ ((enum MHD_FdState) (((unsigned int) (var)) \ & ((unsigned int) (state))))) @@ -2824,8 +2824,8 @@ enum MHD_FIXED_ENUM_ MHD_FdState /** * Set/enable specific @a state in the @a var */ -#define MHD_FD_STATE_SET(var,state) \ - ((var) = \ +#define MHD_FD_STATE_SET(var, state) \ + ((var) = \ (enum MHD_FdState) (((unsigned int) var) | ((unsigned int) state))) /** * Set/enable RECV state in the @a var @@ -2844,10 +2844,10 @@ enum MHD_FIXED_ENUM_ MHD_FdState /** * Clear/disable specific @a state in the @a var */ -#define MHD_FD_STATE_CLEAR(var,state) \ - ( (var) = \ - (enum MHD_FdState) \ - (((unsigned int) var) \ +#define MHD_FD_STATE_CLEAR(var, state) \ + ( (var) = \ + (enum MHD_FdState) \ + (((unsigned int) var) \ & ((enum MHD_FdState) (~((unsigned int) state)))) \ ) /** @@ -3119,13 +3119,13 @@ struct MHD_WorkModeWithParam * This is the default mode. * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_PERIODIC() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_PERIODIC) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_PERIODIC() \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_PERIODIC) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3136,15 +3136,15 @@ struct MHD_WorkModeWithParam * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val,cb_cls_val) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL), \ - .params.v_external_event_loop_cb.reg_cb = (cb_val), \ - .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL), \ + .params.v_external_event_loop_cb.reg_cb = (cb_val), \ + .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3155,15 +3155,15 @@ struct MHD_WorkModeWithParam * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val,cb_cls_val) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE), \ - .params.v_external_event_loop_cb.reg_cb = (cb_val), \ - .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE), \ + .params.v_external_event_loop_cb.reg_cb = (cb_val), \ + .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3177,13 +3177,13 @@ struct MHD_WorkModeWithParam * be called. * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_SINGLE_FD_WATCH) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH() \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_SINGLE_FD_WATCH) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3195,14 +3195,14 @@ struct MHD_WorkModeWithParam * @param num_workers the number of worker threads, zero is treated as one * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_WORKER_THREADS(num_workers) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_WORKER_THREADS), \ - .params.num_worker_threads = (num_workers) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_WORKER_THREADS(num_workers) \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_WORKER_THREADS), \ + .params.num_worker_threads = (num_workers) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3212,13 +3212,13 @@ struct MHD_WorkModeWithParam * connection). * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_THREAD_PER_CONNECTION() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_THREAD_PER_CONNECTION) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_THREAD_PER_CONNECTION() \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_THREAD_PER_CONNECTION) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ MHD_NOWARN_UNUSED_FUNC_ @@ -3611,7 +3611,7 @@ enum MHD_FIXED_ENUM_APP_SET_ MHD_ProtocolStrictLevel * Not recommended unless absolutely necessary to communicate with clients * that have severely broken HTTP implementations. */ - MHD_PSL_EXTRA_PERMISSIVE = -3, + MHD_PSL_EXTRA_PERMISSIVE = -3 }; /** @@ -4188,9 +4188,9 @@ struct MHD_RequestEndedData * @ingroup request */ typedef void -(*MHD_RequestEndedCallback) (void *cls, - const struct MHD_RequestEndedData *data, - void *request_app_context); +(*MHD_RequestEndedCallback)(void *cls, + const struct MHD_RequestEndedData *data, + void *request_app_context); #include "microhttpd2_generated_response_options.h" @@ -4936,7 +4936,7 @@ MHD_R_OPTION_TERMINATION_CALLBACK ( * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_DaemonOptionAndValue with requested values */ -#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val,cb_cls_val) \ +#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \ MHD_D_OPTION_WORK_MODE ( \ MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL ((cb_val),(cb_cls_val))) @@ -4949,7 +4949,7 @@ MHD_R_OPTION_TERMINATION_CALLBACK ( * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_DaemonOptionAndValue with requested values */ -#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val,cb_cls_val) \ +#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \ MHD_D_OPTION_WORK_MODE ( \ MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE ((cb_val),(cb_cls_val))) @@ -5049,15 +5049,15 @@ MHD_NOWARN_VARIADIC_MACROS_ * error code otherwise */ # define MHD_DAEMON_SET_OPTIONS(daemon,...) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - MHD_NOWARN_AGGR_DYN_INIT_ \ - MHD_daemon_set_options ( \ - daemon, \ - ((const struct MHD_DaemonOptionAndValue[]) \ - {__VA_ARGS__, MHD_D_OPTION_TERMINATE ()}), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_AGGR_DYN_INIT_ \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + MHD_NOWARN_AGGR_DYN_INIT_ \ + MHD_daemon_set_options ( \ + daemon, \ + ((const struct MHD_DaemonOptionAndValue[]) \ + {__VA_ARGS__, MHD_D_OPTION_TERMINATE ()}), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_AGGR_DYN_INIT_ \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ # elif defined(MHD_USE_CPP_INIT_LIST) MHD_C_DECLARATIONS_FINISH_HERE_ # include <vector> @@ -5079,13 +5079,13 @@ MHD_C_DECLARATIONS_START_HERE_ * error code otherwise */ # define MHD_DAEMON_SET_OPTIONS(daemon,...) \ - MHD_NOWARN_CPP_INIT_LIST_ \ - MHD_daemon_set_options ( \ - daemon, \ - (std::vector<struct MHD_DaemonOptionAndValue> \ - {__VA_ARGS__,MHD_D_OPTION_TERMINATE ()}).data (), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_CPP_INIT_LIST_ + MHD_NOWARN_CPP_INIT_LIST_ \ + MHD_daemon_set_options ( \ + daemon, \ + (std::vector<struct MHD_DaemonOptionAndValue> \ + {__VA_ARGS__,MHD_D_OPTION_TERMINATE ()}).data (), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_CPP_INIT_LIST_ # endif MHD_RESTORE_WARN_VARIADIC_MACROS_ #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ @@ -5274,25 +5274,25 @@ struct MHD_ConnectionOptionAndValue * values */ # define MHD_C_OPTION_TIMEOUT(timeout) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_ConnectionOptionAndValue) \ - { \ - .opt = (MHD_C_O_TIMEOUT), \ - .val.v_timeout = (timeout) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_ConnectionOptionAndValue) \ + { \ + .opt = (MHD_C_O_TIMEOUT), \ + .val.v_timeout = (timeout) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Terminate the list of the options * @return the terminating object of struct MHD_ConnectionOptionAndValue */ # define MHD_C_OPTION_TERMINATE() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_ConnectionOptionAndValue) \ - { \ - .opt = (MHD_C_O_END) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_ConnectionOptionAndValue) \ + { \ + .opt = (MHD_C_O_END) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ MHD_NOWARN_UNUSED_FUNC_ @@ -5391,13 +5391,13 @@ MHD_NOWARN_VARIADIC_MACROS_ * error code otherwise */ # define MHD_CONNECTION_SET_OPTIONS(connection,...) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - MHD_connection_set_options ( \ - daemon, \ - ((const struct MHD_ConnectionOptionAndValue []) \ - {__VA_ARGS__, MHD_C_OPTION_TERMINATE ()}), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + MHD_connection_set_options ( \ + daemon, \ + ((const struct MHD_ConnectionOptionAndValue []) \ + {__VA_ARGS__, MHD_C_OPTION_TERMINATE ()}), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ # elif defined(MHD_USE_CPP_INIT_LIST) MHD_C_DECLARATIONS_FINISH_HERE_ # include <vector> @@ -5418,13 +5418,13 @@ MHD_C_DECLARATIONS_START_HERE_ * error code otherwise */ # define MHD_CONNECTION_SET_OPTIONS(daemon,...) \ - MHD_NOWARN_CPP_INIT_LIST_ \ - MHD_daemon_set_options ( \ - daemon, \ - (std::vector<struct MHD_ConnectionOptionAndValue> \ - {__VA_ARGS__,MHD_C_OPTION_TERMINATE ()}).data (), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_CPP_INIT_LIST_ + MHD_NOWARN_CPP_INIT_LIST_ \ + MHD_daemon_set_options ( \ + daemon, \ + (std::vector<struct MHD_ConnectionOptionAndValue> \ + {__VA_ARGS__,MHD_C_OPTION_TERMINATE ()}).data (), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_CPP_INIT_LIST_ # endif MHD_RESTORE_WARN_VARIADIC_MACROS_ #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ @@ -5595,7 +5595,7 @@ MHD_request_get_values_list ( size_t num_elements, struct MHD_NameValueKind elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)]) MHD_FN_PAR_NONNULL_ (1) -MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_OUT_SIZE_ (4,3); +MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_OUT_SIZE_ (4, 3); /** @@ -5897,7 +5897,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_ProtocolVersion MHD_HTTP_VERSION_FUTURE = 255 /**< Future HTTP version */ }; -#define MHD_HTTP_PROTOCOL_VER_DEFINED 1 +# define MHD_HTTP_PROTOCOL_VER_DEFINED 1 #endif /* ! MHD_HTTP_PROTOCOL_VER_DEFINED */ /** @@ -6083,7 +6083,7 @@ MHD_FN_PAR_NONNULL_ALL_; * error code otherwise * @ingroup response */ -#define MHD_response_set_option(response,option_ptr) \ +#define MHD_response_set_option(response, option_ptr) \ MHD_response_set_options (response,option_ptr,1) @@ -6109,13 +6109,13 @@ MHD_NOWARN_VARIADIC_MACROS_ * error code otherwise */ # define MHD_RESPONSE_SET_OPTIONS(response,...) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - MHD_response_set_options ( \ - response, \ - ((const struct MHD_ResponseOptionAndValue[]) \ - {__VA_ARGS__, MHD_R_OPTION_TERMINATE ()}), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + MHD_response_set_options ( \ + response, \ + ((const struct MHD_ResponseOptionAndValue[]) \ + {__VA_ARGS__, MHD_R_OPTION_TERMINATE ()}), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ # elif defined(MHD_USE_CPP_INIT_LIST) MHD_C_DECLARATIONS_FINISH_HERE_ # include <vector> @@ -6137,13 +6137,13 @@ MHD_C_DECLARATIONS_START_HERE_ * error code otherwise */ # define MHD_RESPONSE_SET_OPTIONS(response,...) \ - MHD_NOWARN_CPP_INIT_LIST_ \ - MHD_response_set_options ( \ - response, \ - (std::vector<struct MHD_ResponseOptionAndValue> \ - {__VA_ARGS__,MHD_R_OPTION_TERMINATE ()}).data (), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_CPP_INIT_LIST_ + MHD_NOWARN_CPP_INIT_LIST_ \ + MHD_response_set_options ( \ + response, \ + (std::vector<struct MHD_ResponseOptionAndValue> \ + {__VA_ARGS__,MHD_R_OPTION_TERMINATE ()}).data (), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_CPP_INIT_LIST_ # endif MHD_RESTORE_WARN_VARIADIC_MACROS_ #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ @@ -6160,9 +6160,9 @@ MHD_RESTORE_WARN_VARIADIC_MACROS_ * @ingroup response */ typedef void -(*MHD_FreeCallback) (void *free_cls); +(*MHD_FreeCallback)(void *free_cls); -#define MHD_FREECALLBACK_DEFINED 1 +# define MHD_FREECALLBACK_DEFINED 1 #endif /* ! MHD_FREECALLBACK_DEFINED */ #ifndef MHD_DYNCONTENTZCIOVEC_DEFINED @@ -6193,7 +6193,7 @@ struct MHD_DynContentZCIoVec void *iov_fcb_cls; }; -#define MHD_DYNCONTENTZCIOVEC_DEFINED 1 +# define MHD_DYNCONTENTZCIOVEC_DEFINED 1 #endif /* ! MHD_DYNCONTENTZCIOVEC_DEFINED */ /** @@ -6260,7 +6260,7 @@ MHD_FN_PAR_CSTR_ (4); * @return the pointer to the action if succeed, * NULL (equivalent of MHD_DCC_action_abort())in case of any error */ -#define MHD_DCC_action_continue_ce(ctx,data_size,chunk_ext) \ +#define MHD_DCC_action_continue_ce(ctx, data_size, chunk_ext) \ MHD_DCC_action_continue_zc ((ctx), (data_size), NULL, (chunk_ext)) @@ -6277,7 +6277,7 @@ MHD_FN_PAR_CSTR_ (4); * @return the pointer to the action if succeed, * NULL (equivalent of MHD_DCC_action_abort())in case of any error */ -#define MHD_DCC_action_continue(ctx,data_size) \ +#define MHD_DCC_action_continue(ctx, data_size) \ MHD_DCC_action_continue_ce ((ctx), (data_size), NULL) @@ -6420,7 +6420,7 @@ MHD_response_from_buffer ( const char *buffer, MHD_FreeCallback free_cb, void *free_cb_cls) -MHD_FN_PAR_IN_SIZE_ (3,2); +MHD_FN_PAR_IN_SIZE_ (3, 2); /** @@ -6468,7 +6468,7 @@ MHD_response_from_buffer_copy ( enum MHD_HTTP_StatusCode sc, size_t buffer_size, const char buffer[MHD_FN_PAR_DYN_ARR_SIZE_ (buffer_size)]) -MHD_FN_PAR_IN_SIZE_ (3,2); +MHD_FN_PAR_IN_SIZE_ (3, 2); /** @@ -6732,13 +6732,13 @@ MHD_FN_PAR_NONNULL_ (1); * @ingroup action */ typedef const struct MHD_UploadAction * -(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (4,3) +(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (4, 3) *MHD_UploadCallback)(void *upload_cls, struct MHD_Request *request, size_t content_data_size, void *content_data); -#define MHD_UPLOADCALLBACK_DEFINED 1 +# define MHD_UPLOADCALLBACK_DEFINED 1 #endif /* ! MHD_UPLOADCALLBACK_DEFINED */ /** @@ -6794,7 +6794,7 @@ MHD_FN_PAR_NONNULL_ (1); * @return NULL on error (out of memory. both @a uc is NULL) * @ingroup action */ -#define MHD_action_process_upload_full(request,buff_size,uc,uc_cls) \ +#define MHD_action_process_upload_full(request, buff_size, uc, uc_cls) \ MHD_action_process_upload (request, buff_size, uc, uc_cls, NULL, NULL) /** @@ -6806,7 +6806,7 @@ MHD_FN_PAR_NONNULL_ (1); * @return NULL on error (out of memory. both @a uc is NULL) * @ingroup action */ -#define MHD_action_process_upload_inc(request,uc,uc_cls) \ +#define MHD_action_process_upload_inc(request, uc, uc_cls) \ MHD_action_process_upload (request, 0, NULL, NULL, uc, uc_cls) #ifndef MHD_POST_PARSE_RESULT_DEFINED @@ -6892,7 +6892,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_PostParseResult }; -#define MHD_POST_PARSE_RESULT_DEFINED 1 +# define MHD_POST_PARSE_RESULT_DEFINED 1 #endif /* ! MHD_POST_PARSE_RESULT_DEFINED */ #ifndef MHD_POST_DATA_READER_DEFINED @@ -6964,7 +6964,7 @@ typedef const struct MHD_UploadAction * void *cls, enum MHD_PostParseResult parsing_result); -#define MHD_POST_DATA_READER_DEFINED 1 +# define MHD_POST_DATA_READER_DEFINED 1 #endif /* ! MHD_POST_DATA_READER_DEFINED */ /** @@ -7066,7 +7066,7 @@ struct MHD_PostField struct MHD_StringNullable transfer_encoding; }; -#define MHD_POSTFILED_DEFINED 1 +# define MHD_POSTFILED_DEFINED 1 #endif /* ! MHD_POSTFILED_DEFINED */ @@ -7125,7 +7125,7 @@ MHD_request_get_post_data_list ( size_t num_elements, struct MHD_PostField elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)]) MHD_FN_PAR_NONNULL_ (1) -MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_SIZE_ (3,2); +MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_SIZE_ (3, 2); /* ***************** (c) WebSocket support ********** */ @@ -7168,7 +7168,7 @@ typedef void struct MHD_Request *MHD_RESTRICT request, struct MHD_UpgradedHandle *MHD_RESTRICT urh); -#define MHD_UPGRADEHANDLER_DEFINED 1 +# define MHD_UPGRADEHANDLER_DEFINED 1 #endif /* ! MHD_UPGRADEHANDLER_DEFINED */ @@ -7205,7 +7205,7 @@ MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request, size_t num_headers, const struct MHD_NameValueCStr *MHD_RESTRICT headers) MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (6,5); +MHD_FN_PAR_IN_SIZE_ (6, 5); /** @@ -7242,7 +7242,7 @@ MHD_upload_action_upgrade ( size_t num_headers, const struct MHD_NameValueCStr *MHD_RESTRICT headers) MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (6,5); +MHD_FN_PAR_IN_SIZE_ (6, 5); /** @@ -7284,7 +7284,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, void *MHD_RESTRICT recv_buf, size_t *MHD_RESTRICT received_size, uint_fast64_t max_wait_millisec) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); @@ -7339,7 +7339,7 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, size_t *MHD_RESTRICT sent_size, uint_fast64_t max_wait_millisec, enum MHD_Bool more_data_to_come) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); @@ -7668,7 +7668,7 @@ MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, size_t bin_buf_size, void *MHD_RESTRICT userhash_bin) MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4); +MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4); /** @@ -7719,7 +7719,7 @@ MHD_digest_auth_calc_userhash_hex ( size_t hex_buf_size, char userhash_hex[MHD_FN_PAR_DYN_ARR_SIZE_ (hex_buf_size)]) MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4); +MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4); /** @@ -8185,7 +8185,7 @@ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4) -MHD_FN_PAR_OUT_SIZE_ (6,5); +MHD_FN_PAR_OUT_SIZE_ (6, 5); /** @@ -8492,9 +8492,9 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_digest_auth_challenge_p(rq, l, o, d, s, q, a, h, u, r) \ - MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ - (a),(h),(u),(r),MHD_NO) +# define MHD_action_digest_auth_challenge_p(rq, l, o, d, s, q, a, h, u, r) \ + MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ + (a),(h),(u),(r),MHD_NO) /** @@ -8558,9 +8558,9 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_digest_auth_challenge_a(rq, l, o, d, s, q, a, h, u, r) \ - MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ - (a),(h),(u),(r),MHD_YES) +# define MHD_action_digest_auth_challenge_a(rq, l, o, d, s, q, a, h, u, r) \ + MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ + (a),(h),(u),(r),MHD_YES) #endif /* ! MHD_NO_STATIC_INLINE */ @@ -8705,8 +8705,8 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_basic_auth_challenge_p(rq, l, u, r) \ - MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_NO) +# define MHD_action_basic_auth_challenge_p(rq, l, u, r) \ + MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_NO) /** * Create action to reply with Basic Authentication "challenge". @@ -8737,8 +8737,8 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_basic_auth_challenge_a(rq, l, u, r) \ - MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_YES) +# define MHD_action_basic_auth_challenge_a(rq, l, u, r) \ + MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_YES) #endif /* ! MHD_NO_STATIC_INLINE */ @@ -9345,7 +9345,7 @@ MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2); * or other error code * @ingroup specialized */ -#define MHD_lib_get_info_fixed(info,output_buf) \ +#define MHD_lib_get_info_fixed(info, output_buf) \ MHD_lib_get_info_fixed_sz ((info),(output_buf),sizeof(*(output_buf))) /* Application may define MHD_NO_STATIC_INLINE macro before including @@ -9373,8 +9373,8 @@ MHD_lib_get_info_ver_num (void) { union MHD_LibInfoFixedData data; data.v_version_num_uint32 = 0; /* Not really necessary */ - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_NUM, \ - &data); /* Never fail */ + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_NUM, \ + &data); /* Never fail */ return data.v_version_num_uint32; } @@ -9501,7 +9501,7 @@ MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2); * or other error code * @ingroup specialized */ -#define MHD_lib_get_info_dynamic(info,output_buf) \ +#define MHD_lib_get_info_dynamic(info, output_buf) \ MHD_lib_get_info_dynamic_sz ((info),(output_buf),sizeof(*(output_buf))) @@ -9771,7 +9771,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_daemon_get_info_fixed(daemon,info_type,output_buf) \ +#define MHD_daemon_get_info_fixed(daemon, info_type, output_buf) \ MHD_daemon_get_info_fixed_sz ((daemon), (info_type), (output_buf), \ sizeof(*(output_buf))) @@ -9901,7 +9901,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_daemon_get_info_dynamic(daemon,info_type,output_buf) \ +#define MHD_daemon_get_info_dynamic(daemon, info_type, output_buf) \ MHD_daemon_get_info_dynamic_sz ((daemon), (info_type), (output_buf), \ sizeof(*(output_buf))) @@ -10070,7 +10070,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_connection_get_info_fixed(connection,info_type,output_buf) \ +#define MHD_connection_get_info_fixed(connection, info_type, output_buf) \ MHD_connection_get_info_fixed_sz ((connection),(info_type), \ (output_buf), sizeof(*(output_buf))) @@ -10328,7 +10328,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_connection_get_info_dynamic(connection,info_type,output_buf) \ +#define MHD_connection_get_info_dynamic(connection, info_type, output_buf) \ MHD_connection_get_info_dynamic_sz ((connection),(info_type), \ (output_buf),sizeof(*(output_buf))) @@ -10423,7 +10423,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_stream_get_info_fixed(stream,info_type,output_buf) \ +#define MHD_stream_get_info_fixed(stream, info_type, output_buf) \ MHD_stream_get_info_fixed_sz ((stream),(info_type),(output_buf), \ sizeof(*(output_buf))) @@ -10510,7 +10510,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_stream_get_info_dynamic(stream,info_type,output_buf) \ +#define MHD_stream_get_info_dynamic(stream, info_type, output_buf) \ MHD_stream_get_info_dynamic_sz ((stream),(info_type),(output_buf), \ sizeof(*(output_buf))) @@ -10663,7 +10663,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_request_get_info_fixed(request,info_type,output_buf) \ +#define MHD_request_get_info_fixed(request, info_type, output_buf) \ MHD_request_get_info_fixed_sz ((request), (info_type), (output_buf), \ sizeof(*(output_buf))) @@ -10996,7 +10996,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_request_get_info_dynamic(request,info_type,output_buf) \ +#define MHD_request_get_info_dynamic(request, info_type, output_buf) \ MHD_request_get_info_dynamic_sz ((request), (info_type), \ (output_buf), \ sizeof(*(output_buf))) @@ -11017,11 +11017,11 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * @ingroup logging */ typedef void -(*MHD_PanicCallback) (void *cls, - const char *file, - const char *func, - unsigned int line, - const char *message); +(*MHD_PanicCallback)(void *cls, + const char *file, + const char *func, + unsigned int line, + const char *message); /** diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in @@ -18,7 +18,7 @@ * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_DaemonOptionAndValue with requested values */ -#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val,cb_cls_val) \ +#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \ MHD_D_OPTION_WORK_MODE ( \ MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL ((cb_val),(cb_cls_val))) @@ -31,7 +31,7 @@ * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_DaemonOptionAndValue with requested values */ -#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val,cb_cls_val) \ +#define MHD_D_OPTION_WM_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \ MHD_D_OPTION_WORK_MODE ( \ MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE ((cb_val),(cb_cls_val))) @@ -131,15 +131,15 @@ MHD_NOWARN_VARIADIC_MACROS_ * error code otherwise */ # define MHD_DAEMON_SET_OPTIONS(daemon,...) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - MHD_NOWARN_AGGR_DYN_INIT_ \ - MHD_daemon_set_options ( \ - daemon, \ - ((const struct MHD_DaemonOptionAndValue[]) \ - {__VA_ARGS__, MHD_D_OPTION_TERMINATE ()}), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_AGGR_DYN_INIT_ \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + MHD_NOWARN_AGGR_DYN_INIT_ \ + MHD_daemon_set_options ( \ + daemon, \ + ((const struct MHD_DaemonOptionAndValue[]) \ + {__VA_ARGS__, MHD_D_OPTION_TERMINATE ()}), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_AGGR_DYN_INIT_ \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ # elif defined(MHD_USE_CPP_INIT_LIST) MHD_C_DECLARATIONS_FINISH_HERE_ # include <vector> @@ -161,13 +161,13 @@ MHD_C_DECLARATIONS_START_HERE_ * error code otherwise */ # define MHD_DAEMON_SET_OPTIONS(daemon,...) \ - MHD_NOWARN_CPP_INIT_LIST_ \ - MHD_daemon_set_options ( \ - daemon, \ - (std::vector<struct MHD_DaemonOptionAndValue> \ - {__VA_ARGS__,MHD_D_OPTION_TERMINATE ()}).data (), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_CPP_INIT_LIST_ + MHD_NOWARN_CPP_INIT_LIST_ \ + MHD_daemon_set_options ( \ + daemon, \ + (std::vector<struct MHD_DaemonOptionAndValue> \ + {__VA_ARGS__,MHD_D_OPTION_TERMINATE ()}).data (), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_CPP_INIT_LIST_ # endif MHD_RESTORE_WARN_VARIADIC_MACROS_ #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ @@ -356,25 +356,25 @@ struct MHD_ConnectionOptionAndValue * values */ # define MHD_C_OPTION_TIMEOUT(timeout) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_ConnectionOptionAndValue) \ - { \ - .opt = (MHD_C_O_TIMEOUT), \ - .val.v_timeout = (timeout) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_ConnectionOptionAndValue) \ + { \ + .opt = (MHD_C_O_TIMEOUT), \ + .val.v_timeout = (timeout) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Terminate the list of the options * @return the terminating object of struct MHD_ConnectionOptionAndValue */ # define MHD_C_OPTION_TERMINATE() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_ConnectionOptionAndValue) \ - { \ - .opt = (MHD_C_O_END) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_ConnectionOptionAndValue) \ + { \ + .opt = (MHD_C_O_END) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ MHD_NOWARN_UNUSED_FUNC_ @@ -473,13 +473,13 @@ MHD_NOWARN_VARIADIC_MACROS_ * error code otherwise */ # define MHD_CONNECTION_SET_OPTIONS(connection,...) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - MHD_connection_set_options ( \ - daemon, \ - ((const struct MHD_ConnectionOptionAndValue []) \ - {__VA_ARGS__, MHD_C_OPTION_TERMINATE ()}), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + MHD_connection_set_options ( \ + daemon, \ + ((const struct MHD_ConnectionOptionAndValue []) \ + {__VA_ARGS__, MHD_C_OPTION_TERMINATE ()}), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ # elif defined(MHD_USE_CPP_INIT_LIST) MHD_C_DECLARATIONS_FINISH_HERE_ # include <vector> @@ -500,13 +500,13 @@ MHD_C_DECLARATIONS_START_HERE_ * error code otherwise */ # define MHD_CONNECTION_SET_OPTIONS(daemon,...) \ - MHD_NOWARN_CPP_INIT_LIST_ \ - MHD_daemon_set_options ( \ - daemon, \ - (std::vector<struct MHD_ConnectionOptionAndValue> \ - {__VA_ARGS__,MHD_C_OPTION_TERMINATE ()}).data (), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_CPP_INIT_LIST_ + MHD_NOWARN_CPP_INIT_LIST_ \ + MHD_daemon_set_options ( \ + daemon, \ + (std::vector<struct MHD_ConnectionOptionAndValue> \ + {__VA_ARGS__,MHD_C_OPTION_TERMINATE ()}).data (), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_CPP_INIT_LIST_ # endif MHD_RESTORE_WARN_VARIADIC_MACROS_ #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ @@ -677,7 +677,7 @@ MHD_request_get_values_list ( size_t num_elements, struct MHD_NameValueKind elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)]) MHD_FN_PAR_NONNULL_ (1) -MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_OUT_SIZE_ (4,3); +MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_OUT_SIZE_ (4, 3); /** @@ -979,7 +979,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_ProtocolVersion MHD_HTTP_VERSION_FUTURE = 255 /**< Future HTTP version */ }; -#define MHD_HTTP_PROTOCOL_VER_DEFINED 1 +# define MHD_HTTP_PROTOCOL_VER_DEFINED 1 #endif /* ! MHD_HTTP_PROTOCOL_VER_DEFINED */ /** @@ -1165,7 +1165,7 @@ MHD_FN_PAR_NONNULL_ALL_; * error code otherwise * @ingroup response */ -#define MHD_response_set_option(response,option_ptr) \ +#define MHD_response_set_option(response, option_ptr) \ MHD_response_set_options (response,option_ptr,1) @@ -1191,13 +1191,13 @@ MHD_NOWARN_VARIADIC_MACROS_ * error code otherwise */ # define MHD_RESPONSE_SET_OPTIONS(response,...) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - MHD_response_set_options ( \ - response, \ - ((const struct MHD_ResponseOptionAndValue[]) \ - {__VA_ARGS__, MHD_R_OPTION_TERMINATE ()}), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ + MHD_NOWARN_COMPOUND_LITERALS_ \ + MHD_response_set_options ( \ + response, \ + ((const struct MHD_ResponseOptionAndValue[]) \ + {__VA_ARGS__, MHD_R_OPTION_TERMINATE ()}), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ # elif defined(MHD_USE_CPP_INIT_LIST) MHD_C_DECLARATIONS_FINISH_HERE_ # include <vector> @@ -1219,13 +1219,13 @@ MHD_C_DECLARATIONS_START_HERE_ * error code otherwise */ # define MHD_RESPONSE_SET_OPTIONS(response,...) \ - MHD_NOWARN_CPP_INIT_LIST_ \ - MHD_response_set_options ( \ - response, \ - (std::vector<struct MHD_ResponseOptionAndValue> \ - {__VA_ARGS__,MHD_R_OPTION_TERMINATE ()}).data (), \ - MHD_OPTIONS_ARRAY_MAX_SIZE) \ - MHD_RESTORE_WARN_CPP_INIT_LIST_ + MHD_NOWARN_CPP_INIT_LIST_ \ + MHD_response_set_options ( \ + response, \ + (std::vector<struct MHD_ResponseOptionAndValue> \ + {__VA_ARGS__,MHD_R_OPTION_TERMINATE ()}).data (), \ + MHD_OPTIONS_ARRAY_MAX_SIZE) \ + MHD_RESTORE_WARN_CPP_INIT_LIST_ # endif MHD_RESTORE_WARN_VARIADIC_MACROS_ #endif /* MHD_USE_VARARG_MACROS && MHD_USE_COMP_LIT_FUNC_PARAMS */ @@ -1242,9 +1242,9 @@ MHD_RESTORE_WARN_VARIADIC_MACROS_ * @ingroup response */ typedef void -(*MHD_FreeCallback) (void *free_cls); +(*MHD_FreeCallback)(void *free_cls); -#define MHD_FREECALLBACK_DEFINED 1 +# define MHD_FREECALLBACK_DEFINED 1 #endif /* ! MHD_FREECALLBACK_DEFINED */ #ifndef MHD_DYNCONTENTZCIOVEC_DEFINED @@ -1275,7 +1275,7 @@ struct MHD_DynContentZCIoVec void *iov_fcb_cls; }; -#define MHD_DYNCONTENTZCIOVEC_DEFINED 1 +# define MHD_DYNCONTENTZCIOVEC_DEFINED 1 #endif /* ! MHD_DYNCONTENTZCIOVEC_DEFINED */ /** @@ -1342,7 +1342,7 @@ MHD_FN_PAR_CSTR_ (4); * @return the pointer to the action if succeed, * NULL (equivalent of MHD_DCC_action_abort())in case of any error */ -#define MHD_DCC_action_continue_ce(ctx,data_size,chunk_ext) \ +#define MHD_DCC_action_continue_ce(ctx, data_size, chunk_ext) \ MHD_DCC_action_continue_zc ((ctx), (data_size), NULL, (chunk_ext)) @@ -1359,7 +1359,7 @@ MHD_FN_PAR_CSTR_ (4); * @return the pointer to the action if succeed, * NULL (equivalent of MHD_DCC_action_abort())in case of any error */ -#define MHD_DCC_action_continue(ctx,data_size) \ +#define MHD_DCC_action_continue(ctx, data_size) \ MHD_DCC_action_continue_ce ((ctx), (data_size), NULL) @@ -1502,7 +1502,7 @@ MHD_response_from_buffer ( const char *buffer, MHD_FreeCallback free_cb, void *free_cb_cls) -MHD_FN_PAR_IN_SIZE_ (3,2); +MHD_FN_PAR_IN_SIZE_ (3, 2); /** @@ -1550,7 +1550,7 @@ MHD_response_from_buffer_copy ( enum MHD_HTTP_StatusCode sc, size_t buffer_size, const char buffer[MHD_FN_PAR_DYN_ARR_SIZE_ (buffer_size)]) -MHD_FN_PAR_IN_SIZE_ (3,2); +MHD_FN_PAR_IN_SIZE_ (3, 2); /** @@ -1814,13 +1814,13 @@ MHD_FN_PAR_NONNULL_ (1); * @ingroup action */ typedef const struct MHD_UploadAction * -(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (4,3) +(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (4, 3) *MHD_UploadCallback)(void *upload_cls, struct MHD_Request *request, size_t content_data_size, void *content_data); -#define MHD_UPLOADCALLBACK_DEFINED 1 +# define MHD_UPLOADCALLBACK_DEFINED 1 #endif /* ! MHD_UPLOADCALLBACK_DEFINED */ /** @@ -1876,7 +1876,7 @@ MHD_FN_PAR_NONNULL_ (1); * @return NULL on error (out of memory. both @a uc is NULL) * @ingroup action */ -#define MHD_action_process_upload_full(request,buff_size,uc,uc_cls) \ +#define MHD_action_process_upload_full(request, buff_size, uc, uc_cls) \ MHD_action_process_upload (request, buff_size, uc, uc_cls, NULL, NULL) /** @@ -1888,7 +1888,7 @@ MHD_FN_PAR_NONNULL_ (1); * @return NULL on error (out of memory. both @a uc is NULL) * @ingroup action */ -#define MHD_action_process_upload_inc(request,uc,uc_cls) \ +#define MHD_action_process_upload_inc(request, uc, uc_cls) \ MHD_action_process_upload (request, 0, NULL, NULL, uc, uc_cls) #ifndef MHD_POST_PARSE_RESULT_DEFINED @@ -1974,7 +1974,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_PostParseResult }; -#define MHD_POST_PARSE_RESULT_DEFINED 1 +# define MHD_POST_PARSE_RESULT_DEFINED 1 #endif /* ! MHD_POST_PARSE_RESULT_DEFINED */ #ifndef MHD_POST_DATA_READER_DEFINED @@ -2046,7 +2046,7 @@ typedef const struct MHD_UploadAction * void *cls, enum MHD_PostParseResult parsing_result); -#define MHD_POST_DATA_READER_DEFINED 1 +# define MHD_POST_DATA_READER_DEFINED 1 #endif /* ! MHD_POST_DATA_READER_DEFINED */ /** @@ -2148,7 +2148,7 @@ struct MHD_PostField struct MHD_StringNullable transfer_encoding; }; -#define MHD_POSTFILED_DEFINED 1 +# define MHD_POSTFILED_DEFINED 1 #endif /* ! MHD_POSTFILED_DEFINED */ @@ -2207,7 +2207,7 @@ MHD_request_get_post_data_list ( size_t num_elements, struct MHD_PostField elements[MHD_FN_PAR_DYN_ARR_SIZE_ (num_elements)]) MHD_FN_PAR_NONNULL_ (1) -MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_SIZE_ (3,2); +MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_SIZE_ (3, 2); /* ***************** (c) WebSocket support ********** */ @@ -2250,7 +2250,7 @@ typedef void struct MHD_Request *MHD_RESTRICT request, struct MHD_UpgradedHandle *MHD_RESTRICT urh); -#define MHD_UPGRADEHANDLER_DEFINED 1 +# define MHD_UPGRADEHANDLER_DEFINED 1 #endif /* ! MHD_UPGRADEHANDLER_DEFINED */ @@ -2287,7 +2287,7 @@ MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request, size_t num_headers, const struct MHD_NameValueCStr *MHD_RESTRICT headers) MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (6,5); +MHD_FN_PAR_IN_SIZE_ (6, 5); /** @@ -2324,7 +2324,7 @@ MHD_upload_action_upgrade ( size_t num_headers, const struct MHD_NameValueCStr *MHD_RESTRICT headers) MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (6,5); +MHD_FN_PAR_IN_SIZE_ (6, 5); /** @@ -2366,7 +2366,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, void *MHD_RESTRICT recv_buf, size_t *MHD_RESTRICT received_size, uint_fast64_t max_wait_millisec) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); @@ -2421,7 +2421,7 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, size_t *MHD_RESTRICT sent_size, uint_fast64_t max_wait_millisec, enum MHD_Bool more_data_to_come) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); @@ -2750,7 +2750,7 @@ MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, size_t bin_buf_size, void *MHD_RESTRICT userhash_bin) MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4); +MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4); /** @@ -2801,7 +2801,7 @@ MHD_digest_auth_calc_userhash_hex ( size_t hex_buf_size, char userhash_hex[MHD_FN_PAR_DYN_ARR_SIZE_ (hex_buf_size)]) MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4); +MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4); /** @@ -3267,7 +3267,7 @@ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4) -MHD_FN_PAR_OUT_SIZE_ (6,5); +MHD_FN_PAR_OUT_SIZE_ (6, 5); /** @@ -3574,9 +3574,9 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_digest_auth_challenge_p(rq, l, o, d, s, q, a, h, u, r) \ - MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ - (a),(h),(u),(r),MHD_NO) +# define MHD_action_digest_auth_challenge_p(rq, l, o, d, s, q, a, h, u, r) \ + MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ + (a),(h),(u),(r),MHD_NO) /** @@ -3640,9 +3640,9 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_digest_auth_challenge_a(rq, l, o, d, s, q, a, h, u, r) \ - MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ - (a),(h),(u),(r),MHD_YES) +# define MHD_action_digest_auth_challenge_a(rq, l, o, d, s, q, a, h, u, r) \ + MHD_action_digest_auth_challenge ((rq),(l),(o),(d),(s),(q), \ + (a),(h),(u),(r),MHD_YES) #endif /* ! MHD_NO_STATIC_INLINE */ @@ -3787,8 +3787,8 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_basic_auth_challenge_p(rq, l, u, r) \ - MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_NO) +# define MHD_action_basic_auth_challenge_p(rq, l, u, r) \ + MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_NO) /** * Create action to reply with Basic Authentication "challenge". @@ -3819,8 +3819,8 @@ MHD_STATIC_INLINE_END_ * to be "destroyed" * @ingroup authentication */ -#define MHD_action_basic_auth_challenge_a(rq, l, u, r) \ - MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_YES) +# define MHD_action_basic_auth_challenge_a(rq, l, u, r) \ + MHD_action_basic_auth_challenge ((rq), (l), (u), (r), MHD_YES) #endif /* ! MHD_NO_STATIC_INLINE */ @@ -4427,7 +4427,7 @@ MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2); * or other error code * @ingroup specialized */ -#define MHD_lib_get_info_fixed(info,output_buf) \ +#define MHD_lib_get_info_fixed(info, output_buf) \ MHD_lib_get_info_fixed_sz ((info),(output_buf),sizeof(*(output_buf))) /* Application may define MHD_NO_STATIC_INLINE macro before including @@ -4455,8 +4455,8 @@ MHD_lib_get_info_ver_num (void) { union MHD_LibInfoFixedData data; data.v_version_num_uint32 = 0; /* Not really necessary */ - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_NUM, \ - &data); /* Never fail */ + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_NUM, \ + &data); /* Never fail */ return data.v_version_num_uint32; } @@ -4583,7 +4583,7 @@ MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_OUT_ (2); * or other error code * @ingroup specialized */ -#define MHD_lib_get_info_dynamic(info,output_buf) \ +#define MHD_lib_get_info_dynamic(info, output_buf) \ MHD_lib_get_info_dynamic_sz ((info),(output_buf),sizeof(*(output_buf))) @@ -4853,7 +4853,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_daemon_get_info_fixed(daemon,info_type,output_buf) \ +#define MHD_daemon_get_info_fixed(daemon, info_type, output_buf) \ MHD_daemon_get_info_fixed_sz ((daemon), (info_type), (output_buf), \ sizeof(*(output_buf))) @@ -4983,7 +4983,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_daemon_get_info_dynamic(daemon,info_type,output_buf) \ +#define MHD_daemon_get_info_dynamic(daemon, info_type, output_buf) \ MHD_daemon_get_info_dynamic_sz ((daemon), (info_type), (output_buf), \ sizeof(*(output_buf))) @@ -5152,7 +5152,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_connection_get_info_fixed(connection,info_type,output_buf) \ +#define MHD_connection_get_info_fixed(connection, info_type, output_buf) \ MHD_connection_get_info_fixed_sz ((connection),(info_type), \ (output_buf), sizeof(*(output_buf))) @@ -5410,7 +5410,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_connection_get_info_dynamic(connection,info_type,output_buf) \ +#define MHD_connection_get_info_dynamic(connection, info_type, output_buf) \ MHD_connection_get_info_dynamic_sz ((connection),(info_type), \ (output_buf),sizeof(*(output_buf))) @@ -5505,7 +5505,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_stream_get_info_fixed(stream,info_type,output_buf) \ +#define MHD_stream_get_info_fixed(stream, info_type, output_buf) \ MHD_stream_get_info_fixed_sz ((stream),(info_type),(output_buf), \ sizeof(*(output_buf))) @@ -5592,7 +5592,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_stream_get_info_dynamic(stream,info_type,output_buf) \ +#define MHD_stream_get_info_dynamic(stream, info_type, output_buf) \ MHD_stream_get_info_dynamic_sz ((stream),(info_type),(output_buf), \ sizeof(*(output_buf))) @@ -5745,7 +5745,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_request_get_info_fixed(request,info_type,output_buf) \ +#define MHD_request_get_info_fixed(request, info_type, output_buf) \ MHD_request_get_info_fixed_sz ((request), (info_type), (output_buf), \ sizeof(*(output_buf))) @@ -6078,7 +6078,7 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * other error codes in case of other errors * @ingroup specialized */ -#define MHD_request_get_info_dynamic(request,info_type,output_buf) \ +#define MHD_request_get_info_dynamic(request, info_type, output_buf) \ MHD_request_get_info_dynamic_sz ((request), (info_type), \ (output_buf), \ sizeof(*(output_buf))) @@ -6099,11 +6099,11 @@ MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_OUT_ (3); * @ingroup logging */ typedef void -(*MHD_PanicCallback) (void *cls, - const char *file, - const char *func, - unsigned int line, - const char *message); +(*MHD_PanicCallback)(void *cls, + const char *file, + const char *func, + unsigned int line, + const char *message); /** diff --git a/src/include/microhttpd2_portability.h b/src/include/microhttpd2_portability.h @@ -40,11 +40,11 @@ #define MICROHTTPD2_PORTABILITY_H 1 #ifndef __cplusplus -# define MHD_STATIC_CAST_(type,value) \ - ((type) (value)) +# define MHD_STATIC_CAST_(type, value) \ + ((type) (value)) #else -# define MHD_STATIC_CAST_(type,value) \ - (static_cast<type>(value)) +# define MHD_STATIC_CAST_(type, value) \ + (static_cast<type>(value)) #endif /** @@ -56,7 +56,7 @@ /* Define MHD_W32DLL when using MHD as W32 .DLL to speed up linker a little */ #ifndef MHD_EXTERN_ -# if ! defined(_WIN32) || ! defined(MHD_W32LIB) +# if !defined(_WIN32) || !defined(MHD_W32LIB) # define MHD_EXTERN_ extern # else /* defined(_WIN32) && defined(MHD_W32LIB) */ # define MHD_EXTERN_ extern __declspec(dllimport) @@ -72,30 +72,30 @@ #define MHD_MACRO_STR_(x) MHD_MACRO_STR__ (x) /* Concatenate macro parameters literally */ -#define MHD_MACRO_CAT__(a,b) a ## b +#define MHD_MACRO_CAT__(a, b) a ## b /* Concatenate macro parameters after expansion */ -#define MHD_MACRO_CAT_(a,b) MHD_MACRO_CAT__ (a,b) +#define MHD_MACRO_CAT_(a, b) MHD_MACRO_CAT__ (a,b) #ifdef __GNUC__ -# define MHD_GNUC_MINV(major,minor) \ - ((__GNUC__ > (major)) || \ - ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor + 0)))) +# define MHD_GNUC_MINV(major, minor) \ + ((__GNUC__ > (major)) || \ + ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor + 0)))) #else /* ! __GNUC__ */ -# define MHD_GNUC_MINV(major,minor) (0) +# define MHD_GNUC_MINV(major, minor) (0) #endif /* ! __GNUC__ */ #ifdef __clang__ -# define MHD_CLANG_MINV(major,minor) \ - ((__clang_major__ > (major)) || \ - ((__clang_major__ == (major)) && (__clang_minor__ >= (minor + 0)))) +# define MHD_CLANG_MINV(major, minor) \ + ((__clang_major__ > (major)) || \ + ((__clang_major__ == (major)) && (__clang_minor__ >= (minor + 0)))) #else /* ! __GNUC__ */ -# define MHD_CLANG_MINV(major,minor) (0) +# define MHD_CLANG_MINV(major, minor) (0) #endif /* ! __GNUC__ */ #if defined(_MSC_FULL_VER) # define MHD_MSC_MINV(version) (_MSC_VER >= (version + 0)) # if defined(_MSC_FULL_VER) \ - && (! defined(__STDC__) || defined(_MSC_EXTENSIONS)) + && (!defined(__STDC__) || defined(_MSC_EXTENSIONS)) /* Visual C with extensions */ # define MHD_HAS_MSC_EXTENSION 1 # endif @@ -103,7 +103,7 @@ # define MHD_MSC_MINV(version) (0) #endif /* ! _MSC_FULL_VER */ -#if defined(__STDC_VERSION__) && ! defined(__cplusplus) +#if defined(__STDC_VERSION__) && !defined(__cplusplus) # define MHD_C_MINV(version) (__STDC_VERSION__ >= (version)) #else # define MHD_C_MINV(version) (0) @@ -116,25 +116,25 @@ #ifndef __cplusplus # define MHD_CXX_MINV(version) (0) -#elif ! defined(_MSC_FULL_VER) || ! defined(_MSVC_LANG) +#elif !defined(_MSC_FULL_VER) || !defined(_MSVC_LANG) # define MHD_CXX_MINV(version) ((__cplusplus + 0) >= version) #else # define MHD_CXX_MINV(version) \ - ((__cplusplus + 0) >= version) || ((_MSVC_LANG + 0) >= version) + ((__cplusplus + 0) >= version) || ((_MSVC_LANG + 0) >= version) #endif /* Use compound literals? */ -#if ! defined(MHD_NO_COMPOUND_LITERALS) -# if ! defined(MHD_USE_COMPOUND_LITERALS) +#if !defined(MHD_NO_COMPOUND_LITERALS) +# if !defined(MHD_USE_COMPOUND_LITERALS) # if MHD_C_MINV_99 # define MHD_USE_COMPOUND_LITERALS 1 -# elif MHD_GNUC_MINV (3,0) && ! defined(__STRICT_ANSI__) +# elif MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__) /* This may warn in "pedantic" compilation mode */ # define MHD_USE_COMPOUND_LITERALS 1 /* Compound literals are an extension */ # define MHD_USE_COMPOUND_LITERALS_EXT 1 # elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1800) \ - && ! defined(__cplusplus) + && !defined(__cplusplus) # define MHD_USE_COMPOUND_LITERALS 1 /* Compound literals are an extension */ # define MHD_USE_COMPOUND_LITERALS_EXT 1 @@ -144,14 +144,14 @@ # endif # endif /* !MHD_USE_COMPOUND_LITERALS */ #elif defined(MHD_USE_COMPOUND_LITERALS) -#error MHD_USE_COMPOUND_LITERALS and MHD_NO_COMPOUND_LITERALS are both defined +# error MHD_USE_COMPOUND_LITERALS and MHD_NO_COMPOUND_LITERALS are both defined #endif /* MHD_NO_COMPOUND_LITERALS */ /* Use compound literals array as function parameter? */ #if defined(MHD_USE_COMPOUND_LITERALS) -# if ! defined(MHD_NO_COMP_LIT_FUNC_PARAMS) -# if ! defined(MHD_USE_COMP_LIT_FUNC_PARAMS) -# if ! defined(__cplusplus) +# if !defined(MHD_NO_COMP_LIT_FUNC_PARAMS) +# if !defined(MHD_USE_COMP_LIT_FUNC_PARAMS) +# if !defined(__cplusplus) /* Compound literals are lvalues and their addresses can be taken */ # define MHD_USE_COMP_LIT_FUNC_PARAMS 1 # elif defined(__llvm__) @@ -163,7 +163,7 @@ # endif # endif # elif defined(MHD_USE_COMP_LIT_FUNC_PARAMS) -#error MHD_USE_COMP_LIT_FUNC_PARAMS and opposite macro are both defined +# error MHD_USE_COMP_LIT_FUNC_PARAMS and opposite macro are both defined # endif #else /* ! MHD_USE_COMPOUND_LITERALS */ # ifndef MHD_NO_COMP_LIT_FUNC_PARAMS @@ -176,15 +176,15 @@ #endif /* ! MHD_USE_COMPOUND_LITERALS */ /* Use designated initializers? */ -#if ! defined(MHD_NO_DESIGNATED_INIT) -# if ! defined(MHD_USE_DESIGNATED_INIT) +#if !defined(MHD_NO_DESIGNATED_INIT) +# if !defined(MHD_USE_DESIGNATED_INIT) # if MHD_C_MINV_99 # define MHD_USE_DESIGNATED_INIT 1 # elif defined(__cplusplus) && defined(__cpp_designated_initializers) # define MHD_USE_DESIGNATED_INIT 1 -# elif (MHD_GNUC_MINV (3,0) && ! defined(__STRICT_ANSI__) \ - && ! defined(__cplusplus)) \ - || (defined(__GNUG__) && MHD_GNUC_MINV (4,7)) +# elif (MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__) \ + && !defined(__cplusplus)) \ + || (defined(__GNUG__) && MHD_GNUC_MINV (4, 7)) /* This may warn in "pedantic" compilation mode */ # define MHD_USE_DESIGNATED_INIT 1 /* Designated initializers are an extension */ @@ -199,11 +199,11 @@ # endif # endif /* !MHD_USE_DESIGNATED_INIT */ #elif defined(MHD_USE_DESIGNATED_INIT) -#error MHD_USE_DESIGNATED_INIT and MHD_NO_DESIGNATED_INIT are both defined +# error MHD_USE_DESIGNATED_INIT and MHD_NO_DESIGNATED_INIT are both defined #endif /* MHD_NO_DESIGNATED_INIT */ /* Use nested designated initializers? */ -#if defined(MHD_USE_DESIGNATED_INIT) && ! defined(__cplusplus) +#if defined(MHD_USE_DESIGNATED_INIT) && !defined(__cplusplus) # ifdef MHD_NO_DESIG_NEST_INIT # undef MHD_NO_DESIG_NEST_INIT # endif @@ -221,8 +221,8 @@ #endif /* ! MHD_USE_DESIGNATED_INIT || __cplusplus */ /* Use C++ initializer lists? */ -#if ! defined(MHD_NO_CPP_INIT_LIST) -# if ! defined(MHD_USE_CPP_INIT_LIST) +#if !defined(MHD_NO_CPP_INIT_LIST) +# if !defined(MHD_USE_CPP_INIT_LIST) # if defined(__cplusplus) && defined(__cpp_initializer_lists) # define MHD_USE_CPP_INIT_LIST 1 # else @@ -230,17 +230,17 @@ # endif # endif #elif defined(MHD_USE_CPP_INIT_LIST) -#error MHD_USE_CPP_INIT_LIST and MHD_NO_CPP_INIT_LIST are both defined +# error MHD_USE_CPP_INIT_LIST and MHD_NO_CPP_INIT_LIST are both defined #endif /* Use variadic arguments macros? */ -#if ! defined(MHD_NO_VARARG_MACROS) -# if ! defined(MHD_USE_VARARG_MACROS) +#if !defined(MHD_NO_VARARG_MACROS) +# if !defined(MHD_USE_VARARG_MACROS) # if MHD_C_MINV_99 # define MHD_USE_VARARG_MACROS 1 # elif MHD_CXX_MINV (201103) # define MHD_USE_VARARG_MACROS 1 -# elif MHD_GNUC_MINV (3,0) && ! defined(__STRICT_ANSI__) +# elif MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__) /* This may warn in "pedantic" compilation mode */ # define MHD_USE_VARARG_MACROS 1 /* Variable arguments macros are an extension */ @@ -255,13 +255,13 @@ # endif # endif /* !MHD_USE_VARARG_MACROS */ #elif defined(MHD_USE_VARARG_MACROS) -#error MHD_USE_VARARG_MACROS and MHD_NO_VARARG_MACROS are both defined +# error MHD_USE_VARARG_MACROS and MHD_NO_VARARG_MACROS are both defined #endif /* MHD_NO_VARARG_MACROS */ /* Use variable-length arrays? */ -#if ! defined(MHD_NO_VLA_TYPES) -# if ! defined(MHD_USE_VLA_TYPES) +#if !defined(MHD_NO_VLA_TYPES) +# if !defined(MHD_USE_VLA_TYPES) # if MHD_C_MINV_23 # define MHD_USE_VLA_TYPES 1 # elif defined(__STDC_NO_VLA__) @@ -277,10 +277,10 @@ # endif # endif #elif defined(MHD_USE_VLA_TYPES) -#error MHD_USE_VLA_TYPES and MHD_NO_VLA_TYPES are both defined +# error MHD_USE_VLA_TYPES and MHD_NO_VLA_TYPES are both defined #endif /* MHD_NO_VARARG_MACROS */ -#if ! defined(MHD_INLINE) +#if !defined(MHD_INLINE) # if defined(inline) /* Assume that proper value of 'inline' was already defined */ # define MHD_INLINE inline @@ -290,7 +290,7 @@ # elif defined(__cplusplus) /* C++ always supports 'inline' */ # define MHD_INLINE inline -# elif MHD_GNUC_MINV (3,0) && ! defined(__STRICT_ANSI__) +# elif MHD_GNUC_MINV (3, 0) && !defined(__STRICT_ANSI__) # define MHD_INLINE __inline__ # elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1400) # define MHD_INLINE __inline @@ -299,15 +299,15 @@ # endif #endif /* MHD_INLINE */ -#if ! defined(MHD_RESTRICT) +#if !defined(MHD_RESTRICT) # if defined(restrict) /* Assume that proper value of 'restrict' was already defined */ # define MHD_RESTRICT restrict # elif MHD_C_MINV_99 /* C99 (and later) supports 'restrict' */ # define MHD_RESTRICT restrict -# elif (MHD_GNUC_MINV (3,0) || MHD_CLANG_MINV (3,0)) \ - && ! defined(__STRICT_ANSI__) +# elif (MHD_GNUC_MINV (3, 0) || MHD_CLANG_MINV (3, 0)) \ + && !defined(__STRICT_ANSI__) # define MHD_RESTRICT __restrict__ # elif defined(MHD_HAS_MSC_EXTENSION) && MHD_MSC_MINV (1400) # define MHD_RESTRICT __restrict @@ -317,68 +317,68 @@ #endif /* MHD_INLINE */ -#if ! defined(MHD_NO__PRAGMA) -# if MHD_GNUC_MINV (4,6) && ! defined(__clang__) +#if !defined(MHD_NO__PRAGMA) +# if MHD_GNUC_MINV (4, 6) && !defined(__clang__) /* '_Pragma()' support was added in GCC 3.0.0 * 'pragma push/pop' support was added in GCC 4.6.0 */ # define MHD_WARN_PUSH_ _Pragma("GCC diagnostic push") # define MHD_WARN_POP_ _Pragma("GCC diagnostic pop") # define MHD_WARN_IGNORE_STYLE_GCC 1 # define MHD_WARN_IGNORE_(warn) \ - _Pragma(MHD_MACRO_STR_(GCC diagnostic ignored warn)) + _Pragma(MHD_MACRO_STR_(GCC diagnostic ignored warn)) # ifdef MHD_USE_VARARG_MACROS_EXT # define MHD_NOWARN_VARIADIC_MACROS_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wvariadic-macros") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wvariadic-macros") # define MHD_RESTORE_WARN_VARIADIC_MACROS_ MHD_WARN_POP_ # endif # define MHD_NOWARN_UNUSED_FUNC_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wunused-function") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wunused-function") # define MHD_RESTORE_WARN_UNUSED_FUNC_ MHD_WARN_POP_ -# if ! MHD_C_MINV_99 -# if MHD_GNUC_MINV (4,8) +# if !MHD_C_MINV_99 +# if MHD_GNUC_MINV (4, 8) # define MHD_NOWARN_AGGR_DYN_INIT_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wpedantic") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wpedantic") # define MHD_RESTORE_WARN_AGGR_DYN_INIT_ MHD_WARN_POP_ # endif # endif -# elif MHD_GNUC_MINV (2,8) && ! defined(__clang__) +# elif MHD_GNUC_MINV (2, 8) && !defined(__clang__) # ifdef MHD_USE_COMPOUND_LITERALS_EXT # define MHD_NOWARN_COMPOUND_LITERALS_ __extension__ # define MHD_RESTORE_WARN_COMPOUND_LITERALS_ /* empty */ # endif -# elif MHD_CLANG_MINV (3,1) +# elif MHD_CLANG_MINV (3, 1) # define MHD_WARN_PUSH_ _Pragma("clang diagnostic push") # define MHD_WARN_POP_ _Pragma("clang diagnostic pop") # define MHD_WARN_IGNORE_STYLE_GCC 1 # define MHD_WARN_IGNORE_(warn) \ - _Pragma(MHD_MACRO_STR_(clang diagnostic ignored warn)) + _Pragma(MHD_MACRO_STR_(clang diagnostic ignored warn)) # ifdef MHD_USE_VARARG_MACROS_EXT # define MHD_NOWARN_VARIADIC_MACROS_ \ - MHD_WARN_PUSH_ \ - MHD_WARN_IGNORE_ ("-Wvariadic-macros") \ - MHD_WARN_IGNORE_ ("-Wc++98-compat-pedantic") + MHD_WARN_PUSH_ \ + MHD_WARN_IGNORE_ ("-Wvariadic-macros") \ + MHD_WARN_IGNORE_ ("-Wc++98-compat-pedantic") # define MHD_RESTORE_WARN_VARIADIC_MACROS_ MHD_WARN_POP_ # else /* ! MHD_USE_VARARG_MACROS_EXT */ # define MHD_NOWARN_VARIADIC_MACROS_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc++98-compat-pedantic") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc++98-compat-pedantic") # define MHD_RESTORE_WARN_VARIADIC_MACROS_ MHD_WARN_POP_ # endif # ifdef MHD_USE_CPP_INIT_LIST # define MHD_NOWARN_CPP_INIT_LIST_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc++98-compat") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc++98-compat") # define MHD_RESTORE_WARN_CPP_INIT_LIST_ MHD_WARN_POP_ # endif # ifdef MHD_USE_COMPOUND_LITERALS_EXT # define MHD_NOWARN_COMPOUND_LITERALS_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc99-extensions") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc99-extensions") # define MHD_RESTORE_WARN_COMPOUND_LITERALS_ MHD_WARN_POP_ # endif # define MHD_NOWARN_UNUSED_FUNC_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wunused-function") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wunused-function") # define MHD_RESTORE_WARN_UNUSED_FUNC_ MHD_WARN_POP_ -# if MHD_CLANG_MINV (3,4) +# if MHD_CLANG_MINV (3, 4) # define MHD_NOWARN_AGGR_DYN_INIT_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc99-extensions") + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wc99-extensions") # define MHD_RESTORE_WARN_AGGR_DYN_INIT_ MHD_WARN_POP_ # endif # elif MHD_MSC_MINV (1500) @@ -386,18 +386,18 @@ # define MHD_WARN_POP_ __pragma(warning(pop)) # define MHD_WARN_IGNORE_(warn) __pragma(warning(disable:warn)) # define MHD_NOWARN_UNUSED_FUNC_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ (4505) MHD_WARN_IGNORE_ (4514) + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ (4505) MHD_WARN_IGNORE_ (4514) # define MHD_RESTORE_WARN_UNUSED_FUNC_ MHD_WARN_POP_ -# if (! MHD_C_MINV_99) && ! defined(__cplusplus) +# if (!MHD_C_MINV_99) && !defined(__cplusplus) # define MHD_NOWARN_AGGR_DYN_INIT_ \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ (4204) + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ (4204) # define MHD_RESTORE_WARN_AGGR_DYN_INIT_ MHD_WARN_POP_ # endif # endif #endif /*! MHD_NO__PRAGMA */ #ifndef MHD_NOWARN_EXPRESSION_ -# if MHD_GNUC_MINV (2,8) +# if MHD_GNUC_MINV (2, 8) # define MHD_NOWARN_EXPRESSION_ __extension__ /* Indicate that MHD_NOWARN_EXPRESSION macro is functional */ # define MHD_HAS_NOWARN_EXPRESSION_ 1 @@ -487,14 +487,14 @@ #endif /* MHD_NO_DEPRECATION */ #ifndef MHD_DEPR_MACRO_ -# if MHD_GNUC_MINV (4,8) && ! defined (__clang__) /* GCC >= 4.8 */ +# if MHD_GNUC_MINV (4, 8) && !defined(__clang__) /* GCC >= 4.8 */ /* Print warning when the macro is processed (if not excluded from processing). * To be used outside other macros */ # define MHD_DEPR_MACRO_(msg) _Pragma(MHD_MACRO_STR_(GCC warning msg)) /* Print warning message when another macro which includes this macro is used */ # define MHD_DEPR_IN_MACRO_(msg) MHD_DEPR_MACRO_ (msg) -# elif (MHD_CLANG_MINV (3,3) && ! defined(__apple_build_version__)) \ - || MHD_CLANG_MINV (5,0) +# elif (MHD_CLANG_MINV (3, 3) && !defined(__apple_build_version__)) \ + || MHD_CLANG_MINV (5, 0) /* clang >= 3.3 (or XCode's clang >= 5.0) */ /* Print warning when the macro is processed (if not excluded from processing). * To be used outside other macros */ @@ -505,15 +505,15 @@ /* Print warning when the macro is processed (if not excluded from processing). * To be used outside other macros */ # define MHD_DEPR_MACRO_(msg) \ - __pragma(message (__FILE__ "(" MHD_MACRO_STR_ ( __LINE__) ") : " \ - "warning MHDWARN01 : " msg)) + __pragma(message (__FILE__ "(" MHD_MACRO_STR_ ( __LINE__) ") : " \ + "warning MHDWARN01 : " msg)) /* Print warning message when another macro which includes this macro is used */ # define MHD_DEPR_IN_MACRO_(msg) MHD_DEPR_MACRO_ (msg) -# elif MHD_GNUC_MINV (3,0) /* 3.0 <= GCC < 4.8 */ +# elif MHD_GNUC_MINV (3, 0) /* 3.0 <= GCC < 4.8 */ /* Print warning when the macro is processed (if not excluded from processing). * To be used outside other macros */ # define MHD_DEPR_MACRO_(msg) _Pragma(MHD_MACRO_STR_(message msg)) -# elif MHD_CLANG_MINV (2,9) +# elif MHD_CLANG_MINV (2, 9) /* Print warning when the macro is processed (if not excluded from processing). * To be used outside other macros */ # define MHD_DEPR_MACRO_(msg) _Pragma(MHD_MACRO_STR_(message msg)) @@ -524,10 +524,10 @@ #endif /* !MHD_DEPR_MACRO_ */ #ifndef MHD_DEPR_FUNC_ -# if MHD_GNUC_MINV (5,0) || MHD_CLANG_MINV (2,9) +# if MHD_GNUC_MINV (5, 0) || MHD_CLANG_MINV (2, 9) /* GCC >= 5.0 or clang >= 2.9 */ # define MHD_DEPR_FUNC_(msg) __attribute__((deprecated (msg))) -# elif MHD_GNUC_MINV (3,1) || defined(__clang__) +# elif MHD_GNUC_MINV (3, 1) || defined(__clang__) /* 3.1 <= GCC < 5.0 or clang < 2.9 */ # define MHD_DEPR_FUNC_(msg) __attribute__((__deprecated__)) # elif MHD_MSC_MINV (1400) @@ -626,12 +626,12 @@ /* Define MHD_NO_FUNC_ATTRIBUTES to avoid having function attributes */ -#if ! defined(MHD_NO_FUNC_ATTRIBUTES) +#if !defined(MHD_NO_FUNC_ATTRIBUTES) # if defined(__has_attribute) /* Override detected value of MHD_FN_PURE_ by defining it before including * the header */ -# if __has_attribute (pure) && ! defined(MHD_FN_PURE_) +# if __has_attribute (pure) && !defined(MHD_FN_PURE_) /** * MHD_FN_PURE_ functions always return the same value for this same input * if volatile memory content is not changed. @@ -646,7 +646,7 @@ /* Override detected value of MHD_FN_CONST_ by defining it before including * the header */ -# if ! defined(MHD_FN_CONST_) +# if !defined(MHD_FN_CONST_) # if __has_attribute (const) /** * MHD_FN_CONST_ functions always return the same value for this same @@ -668,7 +668,7 @@ /* Override detected value of MHD_FN_RETURNS_NONNULL_ by defining it before * including the header */ # if __has_attribute (returns_nonnull) && \ - ! defined(MHD_FN_RETURNS_NONNULL_) + !defined(MHD_FN_RETURNS_NONNULL_) /** * MHD_FN_RETURNS_NONNULL_ indicates that function never returns NULL. */ @@ -678,7 +678,7 @@ /* Override detected value of MHD_FN_MUST_CHECK_RESULT_ by defining it before * including the header */ # if __has_attribute (warn_unused_result) && \ - ! defined(MHD_FN_MUST_CHECK_RESULT_) + !defined(MHD_FN_MUST_CHECK_RESULT_) /** * MHD_FN_MUST_CHECK_RESULT_ indicates that caller must check the value * returned by the function. @@ -689,19 +689,19 @@ /* Override detected value of MHD_FN_PAR_NONNULL_ by defining it before * including the header */ # if __has_attribute (nonnull) && \ - ! defined(MHD_FN_PAR_NONNULL_) + !defined(MHD_FN_PAR_NONNULL_) /** * MHD_FN_PAR_NONNULL_ indicates function parameter number @a param_num * must never be NULL. */ # define MHD_FN_PAR_NONNULL_(param_num) \ - __attribute__ ((nonnull (param_num))) + __attribute__ ((nonnull (param_num))) # endif /* nonnull && !MHD_FN_PAR_NONNULL_ */ /* Override detected value of MHD_FN_PAR_NONNULL_ALL_ by defining it before * including the header */ # if __has_attribute (nonnull) && \ - ! defined(MHD_FN_PAR_NONNULL_ALL_) + !defined(MHD_FN_PAR_NONNULL_ALL_) /** * MHD_FN_PAR_NONNULL_ALL_ indicates all function parameters must * never be NULL. @@ -713,71 +713,71 @@ /* Override detected value of MHD_FN_PAR_IN_ by defining it before * including the header */ -# if ! defined(MHD_FN_PAR_IN_) +# if !defined(MHD_FN_PAR_IN_) /** * MHD_FN_PAR_IN_ indicates function parameter points to data * that must not be modified by the function */ # define MHD_FN_PAR_IN_(param_num) \ - __attribute__ ((access (read_only,param_num))) + __attribute__ ((access (read_only,param_num))) # endif /* !MHD_FN_PAR_IN_ */ /* Override detected value of MHD_FN_PAR_IN_SIZE_ by defining it before * including the header */ -# if ! defined(MHD_FN_PAR_IN_SIZE_) +# if !defined(MHD_FN_PAR_IN_SIZE_) /** * MHD_FN_PAR_IN_SIZE_ indicates function parameter points to data * which size is specified by @a size_num parameter and that must not be * modified by the function */ -# define MHD_FN_PAR_IN_SIZE_(param_num,size_num) \ - __attribute__ ((access (read_only,param_num,size_num))) +# define MHD_FN_PAR_IN_SIZE_(param_num, size_num) \ + __attribute__ ((access (read_only,param_num,size_num))) # endif /* !MHD_FN_PAR_IN_SIZE_ */ /* Override detected value of MHD_FN_PAR_OUT_ by defining it before * including the header */ -# if ! defined(MHD_FN_PAR_OUT_) +# if !defined(MHD_FN_PAR_OUT_) /** * MHD_FN_PAR_OUT_ indicates function parameter points to data * that could be written by the function, but not read. */ # define MHD_FN_PAR_OUT_(param_num) \ - __attribute__ ((access (write_only,param_num))) + __attribute__ ((access (write_only,param_num))) # endif /* !MHD_FN_PAR_OUT_ */ /* Override detected value of MHD_FN_PAR_OUT_SIZE_ by defining it before * including the header */ -# if ! defined(MHD_FN_PAR_OUT_SIZE_) +# if !defined(MHD_FN_PAR_OUT_SIZE_) /** * MHD_FN_PAR_OUT_SIZE_ indicates function parameter points to data * which size is specified by @a size_num parameter and that could be * written by the function, but not read. */ -# define MHD_FN_PAR_OUT_SIZE_(param_num,size_num) \ - __attribute__ ((access (write_only,param_num,size_num))) +# define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) \ + __attribute__ ((access (write_only,param_num,size_num))) # endif /* !MHD_FN_PAR_OUT_SIZE_ */ /* Override detected value of MHD_FN_PAR_INOUT_ by defining it before * including the header */ -# if ! defined(MHD_FN_PAR_INOUT_) +# if !defined(MHD_FN_PAR_INOUT_) /** * MHD_FN_PAR_INOUT_ indicates function parameter points to data * that could be both read and written by the function. */ # define MHD_FN_PAR_INOUT_(param_num) \ - __attribute__ ((access (read_write,param_num))) + __attribute__ ((access (read_write,param_num))) # endif /* !MHD_FN_PAR_INOUT_ */ /* Override detected value of MHD_FN_PAR_INOUT_SIZE_ by defining it before * including the header */ -# if ! defined(MHD_FN_PAR_INOUT_SIZE_) +# if !defined(MHD_FN_PAR_INOUT_SIZE_) /** * MHD_FN_PAR_INOUT_SIZE_ indicates function parameter points to data * which size is specified by @a size_num parameter and that could be * both read and written by the function. */ -# define MHD_FN_PAR_INOUT_SIZE_(param_num,size_num) \ - __attribute__ ((access (read_write,param_num,size_num))) +# define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num) \ + __attribute__ ((access (read_write,param_num,size_num))) # endif /* !MHD_FN_PAR_INOUT_SIZE_ */ # endif /* access */ @@ -785,24 +785,24 @@ /* Override detected value of MHD_FN_PAR_FD_READ_ by defining it before * including the header */ # if __has_attribute (fd_arg_read) && \ - ! defined(MHD_FN_PAR_FD_READ_) + !defined(MHD_FN_PAR_FD_READ_) /** * MHD_FN_PAR_FD_READ_ indicates function parameter is file descriptor that * must be in open state and available for reading */ # define MHD_FN_PAR_FD_READ_(param_num) \ - __attribute__ ((fd_arg_read (param_num))) + __attribute__ ((fd_arg_read (param_num))) # endif /* fd_arg_read && !MHD_FN_PAR_FD_READ_ */ /* Override detected value of MHD_FN_PAR_CSTR_ by defining it before * including the header */ # if __has_attribute (null_terminated_string_arg) && \ - ! defined(MHD_FN_PAR_CSTR_) + !defined(MHD_FN_PAR_CSTR_) /** * MHD_FN_PAR_CSTR_ indicates function parameter is a NUL-terminated C string */ # define MHD_FN_PAR_CSTR_(param_num) \ - __attribute__ ((null_terminated_string_arg (param_num))) + __attribute__ ((null_terminated_string_arg (param_num))) # endif /* null_terminated_string_arg && !MHD_FN_PAR_CSTR_ */ # endif /* __has_attribute */ @@ -853,19 +853,19 @@ # define MHD_FN_PAR_IN_(param_num) /* empty */ #endif /* !MHD_FN_PAR_IN_ */ #ifndef MHD_FN_PAR_IN_SIZE_ -# define MHD_FN_PAR_IN_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_IN_SIZE_(param_num, size_num) /* empty */ #endif /* !MHD_FN_PAR_IN_SIZE_ */ #ifndef MHD_FN_PAR_OUT_ # define MHD_FN_PAR_OUT_(param_num) /* empty */ #endif /* !MHD_FN_PAR_OUT_ */ #ifndef MHD_FN_PAR_OUT_SIZE_ -# define MHD_FN_PAR_OUT_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_OUT_SIZE_(param_num, size_num) /* empty */ #endif /* !MHD_FN_PAR_OUT_SIZE_ */ #ifndef MHD_FN_PAR_INOUT_ # define MHD_FN_PAR_INOUT_(param_num) /* empty */ #endif /* !MHD_FN_PAR_INOUT_ */ #ifndef MHD_FN_PAR_INOUT_SIZE_ -# define MHD_FN_PAR_INOUT_SIZE_(param_num,size_num) /* empty */ +# define MHD_FN_PAR_INOUT_SIZE_(param_num, size_num) /* empty */ #endif /* !MHD_FN_PAR_INOUT_SIZE_ */ #ifndef MHD_FN_PAR_FD_READ_ # define MHD_FN_PAR_FD_READ_(param_num) /* empty */ diff --git a/src/include/microhttpd2_preamble.h.in b/src/include/microhttpd2_preamble.h.in @@ -186,11 +186,11 @@ MHD_C_DECLARATIONS_START_HERE_ # endif # ifndef MHD_SYS_SOCKET_TYPES_H /* Headers for 'struct sockaddr' */ -# if ! defined(_WIN32) || defined(__CYGWIN__) +# if !defined(_WIN32) || defined(__CYGWIN__) # include <sys/socket.h> # else /* Prevent conflict of <winsock.h> and <winsock2.h> */ -# if ! defined(_WINSOCK2API_) && ! defined(_WINSOCKAPI_) +# if !defined(_WINSOCK2API_) && !defined(_WINSOCKAPI_) # ifndef WIN32_LEAN_AND_MEAN /* Do not use unneeded parts of W32 headers. */ # define WIN32_LEAN_AND_MEAN 1 @@ -228,7 +228,7 @@ enum MHD_Bool }; -#define MHD_BOOL_DEFINED 1 +# define MHD_BOOL_DEFINED 1 #endif /* ! MHD_BOOL_DEFINED */ #ifndef MHD_STRINGS_DEFINED @@ -271,12 +271,12 @@ struct MHD_StringNullable const char *cstr; }; -#define MHD_STRINGS_DEFINED 1 +# define MHD_STRINGS_DEFINED 1 #endif /* ! MHD_STRINGS_DEFINED */ #ifndef MHD_INVALID_SOCKET -# if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET) +# if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) # define MHD_SOCKETS_KIND_POSIX 1 /** * MHD_Socket is a type for socket FDs @@ -302,7 +302,7 @@ typedef SOCKET MHD_Socket; # define MHD_SIZE_UNKNOWN UINT64_MAX #else # define MHD_SIZE_UNKNOWN \ - MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) + MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) #endif @@ -314,7 +314,7 @@ typedef SOCKET MHD_Socket; # define MHD_WAIT_INDEFINITELY UINT64_MAX #else # define MHD_WAIT_INDEFINITELY \ - MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) + MHD_STATIC_CAST_ (uint_fast64_t,0xffffffffffffffffU) #endif @@ -1916,7 +1916,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_Method MHD_HTTP_METHOD_ASTERISK = 9 }; -#define MHD_HTTP_METHOD_DEFINED 1 +# define MHD_HTTP_METHOD_DEFINED 1 #endif /* ! MHD_HTTP_METHOD_DEFINED */ /** @@ -2061,7 +2061,7 @@ enum MHD_FIXED_ENUM_MHD_APP_SET_ MHD_HTTP_PostEncoding /** @} */ /* end of group postenc */ -#define MHD_HTTP_POSTENCODING_DEFINED 1 +# define MHD_HTTP_POSTENCODING_DEFINED 1 #endif /* ! MHD_HTTP_POSTENCODING_DEFINED */ @@ -2799,7 +2799,7 @@ enum MHD_FIXED_ENUM_ MHD_FdState /** * Checks whether specific @a state is enabled/set in the @a var */ -#define MHD_FD_STATE_IS_SET(var,state) \ +#define MHD_FD_STATE_IS_SET(var, state) \ (MHD_FD_STATE_NONE != \ ((enum MHD_FdState) (((unsigned int) (var)) \ & ((unsigned int) (state))))) @@ -2824,8 +2824,8 @@ enum MHD_FIXED_ENUM_ MHD_FdState /** * Set/enable specific @a state in the @a var */ -#define MHD_FD_STATE_SET(var,state) \ - ((var) = \ +#define MHD_FD_STATE_SET(var, state) \ + ((var) = \ (enum MHD_FdState) (((unsigned int) var) | ((unsigned int) state))) /** * Set/enable RECV state in the @a var @@ -2844,10 +2844,10 @@ enum MHD_FIXED_ENUM_ MHD_FdState /** * Clear/disable specific @a state in the @a var */ -#define MHD_FD_STATE_CLEAR(var,state) \ - ( (var) = \ - (enum MHD_FdState) \ - (((unsigned int) var) \ +#define MHD_FD_STATE_CLEAR(var, state) \ + ( (var) = \ + (enum MHD_FdState) \ + (((unsigned int) var) \ & ((enum MHD_FdState) (~((unsigned int) state)))) \ ) /** @@ -3119,13 +3119,13 @@ struct MHD_WorkModeWithParam * This is the default mode. * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_PERIODIC() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_PERIODIC) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_PERIODIC() \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_PERIODIC) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3136,15 +3136,15 @@ struct MHD_WorkModeWithParam * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val,cb_cls_val) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL), \ - .params.v_external_event_loop_cb.reg_cb = (cb_val), \ - .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_LEVEL(cb_val, cb_cls_val) \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL), \ + .params.v_external_event_loop_cb.reg_cb = (cb_val), \ + .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3155,15 +3155,15 @@ struct MHD_WorkModeWithParam * @param cb_cls_val the closure for the @a cv_val callback * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val,cb_cls_val) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE), \ - .params.v_external_event_loop_cb.reg_cb = (cb_val), \ - .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_EVENT_LOOP_CB_EDGE(cb_val, cb_cls_val) \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE), \ + .params.v_external_event_loop_cb.reg_cb = (cb_val), \ + .params.v_external_event_loop_cb.reg_cb_cls = (cb_cls_val) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3177,13 +3177,13 @@ struct MHD_WorkModeWithParam * be called. * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_EXTERNAL_SINGLE_FD_WATCH) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_EXTERNAL_SINGLE_FD_WATCH() \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_EXTERNAL_SINGLE_FD_WATCH) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3195,14 +3195,14 @@ struct MHD_WorkModeWithParam * @param num_workers the number of worker threads, zero is treated as one * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_WORKER_THREADS(num_workers) \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_WORKER_THREADS), \ - .params.num_worker_threads = (num_workers) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_WORKER_THREADS(num_workers) \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_WORKER_THREADS), \ + .params.num_worker_threads = (num_workers) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ /** * Create parameter for #MHD_D_O_WORK_MODE() for work mode with @@ -3212,13 +3212,13 @@ struct MHD_WorkModeWithParam * connection). * @return the object of struct MHD_WorkModeWithParam with requested values */ -# define MHD_WM_OPTION_THREAD_PER_CONNECTION() \ - MHD_NOWARN_COMPOUND_LITERALS_ \ - (const struct MHD_WorkModeWithParam) \ - { \ - .mode = (MHD_WM_THREAD_PER_CONNECTION) \ - } \ - MHD_RESTORE_WARN_COMPOUND_LITERALS_ +# define MHD_WM_OPTION_THREAD_PER_CONNECTION() \ + MHD_NOWARN_COMPOUND_LITERALS_ \ + (const struct MHD_WorkModeWithParam) \ + { \ + .mode = (MHD_WM_THREAD_PER_CONNECTION) \ + } \ + MHD_RESTORE_WARN_COMPOUND_LITERALS_ #else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */ MHD_NOWARN_UNUSED_FUNC_ @@ -3611,7 +3611,7 @@ enum MHD_FIXED_ENUM_APP_SET_ MHD_ProtocolStrictLevel * Not recommended unless absolutely necessary to communicate with clients * that have severely broken HTTP implementations. */ - MHD_PSL_EXTRA_PERMISSIVE = -3, + MHD_PSL_EXTRA_PERMISSIVE = -3 }; /** @@ -4188,9 +4188,9 @@ struct MHD_RequestEndedData * @ingroup request */ typedef void -(*MHD_RequestEndedCallback) (void *cls, - const struct MHD_RequestEndedData *data, - void *request_app_context); +(*MHD_RequestEndedCallback)(void *cls, + const struct MHD_RequestEndedData *data, + void *request_app_context); #include "microhttpd2_generated_response_options.h" diff --git a/src/include/options-generator.c b/src/include/options-generator.c @@ -45,7 +45,7 @@ #include <stdarg.h> #include <string.h> #include <ctype.h> -#if ! defined(_WIN32) || defined(__CYGWIN__) +#if !defined(_WIN32) || defined(__CYGWIN__) # include <unistd.h> #endif #include <sys/stat.h> @@ -100,7 +100,7 @@ my_asprintf (char **buf, format, args); va_end (args); - *buf = (char *) malloc (ret + 1); + *buf = (char *)malloc (ret + 1); va_start (args, format); ret = vsprintf (*buf, @@ -203,7 +203,7 @@ indent (const char *pfx, my_asprintf (&tmp, "%.*s\n%s%s", - (int) (off - ret), + (int)(off - ret), ret, (off[1] == '\n') ? xfx @@ -263,7 +263,7 @@ dump_enum (const char *name, { printf (" /**\n * %s\n */\n MHD_%c_O_%s = %u\n ,\n\n", indent (" * ", comment), - (char) toupper (*category), + (char)toupper (*category), uppercase (name), value); } @@ -299,7 +299,7 @@ dump_union_members (const char *name, return; printf ("/**\n * Data for #MHD_%c_O_%s\n */\n%s\n{\n", - (char) toupper (*category), + (char)toupper (*category), uppercase (name), type); for (unsigned int i = 0; i < argc; i++) @@ -311,7 +311,7 @@ dump_union_members (const char *name, printf (" /**\n * %s\n */\n %.*sv_%s;\n\n", indent (" * ", desc), - (int) (vn - arg), + (int)(vn - arg), arg, vn); } @@ -337,7 +337,7 @@ dump_union (const char *name, " /**\n" " * Value for #MHD_%c_O_%s.%s%s\n" " */\n", - (char) toupper (*category), + (char)toupper (*category), uppercase (name), NULL != xcomment ? "\n * " @@ -359,7 +359,7 @@ dump_union (const char *name, fprintf (f, " %.*s%s;\n", - (int) (vn - arg), + (int)(vn - arg), arg, lowercase (name)); } @@ -432,7 +432,7 @@ dump_option_macros (const char *name, printf (" * @param value the value of the parameter"); printf (" * @return structure with the requested setting\n */\n"); printf ("# define MHD_%c_OPTION_%s(", - (char) toupper (*category), + (char)toupper (*category), uppercase (name)); if (0 == argc) printf ("value"); @@ -451,7 +451,7 @@ dump_option_macros (const char *name, " { \\\n" " .opt = MHD_%c_O_%s, \\\n", capitalize (category), - (char) toupper (*category), + (char)toupper (*category), uppercase (name)); if (0 == argc) printf (" .val.%s = (value) \\\n", @@ -517,7 +517,7 @@ dump_option_static_functions (const char *name, printf ("static MHD_INLINE struct MHD_%sOptionAndValue\n" "MHD_%c_OPTION_%s (\n", capitalize (category), - (char) toupper (*category), + (char)toupper (*category), uppercase (name)); if (0 == argc) printf (" %s value", @@ -534,7 +534,7 @@ dump_option_static_functions (const char *name, if (0 != i) printf (",\n"); printf (" %.*s%s", - (int) (vn - arg), + (int)(vn - arg), arg, vn); } @@ -545,7 +545,7 @@ dump_option_static_functions (const char *name, " struct MHD_%sOptionAndValue opt_val;\n\n" " opt_val.opt = MHD_%c_O_%s;\n", capitalize (category), - (char) toupper (*category), + (char)toupper (*category), uppercase (name)); if (0 == argc) printf (" opt_val.val.%s = (value); \\\n", @@ -602,7 +602,7 @@ dump_option_documentation_functions (const char *name, fprintf (f, "struct MHD_%sOptionAndValue\n" "MHD_%c_OPTION_%s (\n", capitalize (category), - (char) toupper (*category), + (char)toupper (*category), uppercase (name)); if (0 == argc) fprintf (f, @@ -620,7 +620,7 @@ dump_option_documentation_functions (const char *name, fprintf (f, ",\n"); fprintf (f, " %.*s%s", - (int) (vn - arg), + (int)(vn - arg), arg, vn); } @@ -667,7 +667,7 @@ dump_option_set_switch (const char *name, uppercase (conditional)); fprintf (f, " case MHD_%c_O_%s:\n", - (char) toupper (*category), + (char)toupper (*category), uppercase (name)); if (NULL != custom_setter) { @@ -678,14 +678,14 @@ dump_option_set_switch (const char *name, while (NULL != line) { const char *nl = strchr (line, '\n'); - size_t len = (NULL == nl) ? strlen (line) : (size_t) (nl - line); + size_t len = (NULL == nl) ? strlen (line) : (size_t)(nl - line); if (0 == len) fprintf (f, "\n"); else if ('#' == line[0]) - fprintf (f, "%.*s\n", (int) len, line); + fprintf (f, "%.*s\n", (int)len, line); else - fprintf (f, " %.*s\n", (int) len, line); + fprintf (f, " %.*s\n", (int)len, line); line = (NULL == nl) ? NULL : nl + 1; } } @@ -820,8 +820,8 @@ TOP: exit (2); } - *larg = (char *) realloc (*larg, - strlen (*larg) + r + 2); + *larg = (char *)realloc (*larg, + strlen (*larg) + r + 2); strcat (*larg, "\n"); if (0 != strcmp ("+", @@ -835,7 +835,7 @@ TOP: continue; if (NULL == larg) { - struct Option *o = (struct Option *) malloc (sizeof (struct Option)); + struct Option *o = (struct Option *)malloc (sizeof (struct Option)); memset (o, 0, sizeof (*o)); if (NULL == head) @@ -937,7 +937,7 @@ TOP: " */\n" " MHD_%c_O_END = 0\n" " ,\n\n", - (char) toupper (*category)); + (char)toupper (*category)); iterate (head, &dump_enum); printf (" /**\n" @@ -946,7 +946,7 @@ TOP: " * Do not use.\n" " */\n" " MHD_%c_O_SENTINEL = 65535\n\n", - (char) toupper (*category)); + (char)toupper (*category)); printf ("};\n\n"); iterate (head, &dump_union_members); @@ -999,9 +999,9 @@ TOP: " } \\\n" " MHD_RESTORE_WARN_COMPOUND_LITERALS_\n\n", capitalize (category), - (char) toupper (*category), + (char)toupper (*category), capitalize (category), - (char) toupper (*category)); + (char)toupper (*category)); printf ( "#else /* !MHD_USE_COMPOUND_LITERALS || !MHD_USE_DESIG_NEST_INIT */\n"); @@ -1021,9 +1021,9 @@ TOP: "}\n\n\n", capitalize (category), capitalize (category), - (char) toupper (*category), + (char)toupper (*category), capitalize (category), - (char) toupper (*category)); + (char)toupper (*category)); printf ("MHD_RESTORE_WARN_UNUSED_FUNC_\n"); printf ( @@ -1035,7 +1035,7 @@ TOP: my_asprintf (&doc_in, "microhttpd2_inline_%s_documentation.h.in", category); - (void) unlink (doc_in); + (void)unlink (doc_in); f = fopen (doc_in, "w"); if (NULL == f) { @@ -1066,7 +1066,7 @@ TOP: my_asprintf (&so_c, "../mhd2/%s_set_options.c", category); - (void) unlink (so_c); + (void)unlink (so_c); f = fopen (so_c, "w"); if (NULL == f) { @@ -1150,7 +1150,7 @@ TOP: " if (response->reuse.reusable)\n" " {\n" " need_unlock = true;\n" - " if (! mhd_mutex_lock (&response->reuse.settings_lock))\n" + " if (!mhd_mutex_lock (&response->reuse.settings_lock))\n" " return MHD_SC_RESP_MUTEX_LOCK_FAILED;\n" " mhd_assert (1 == mhd_atomic_counter_get (&response->reuse.counter));\n" " if (response->frozen) /* Firm re-check under the lock */\n" @@ -1181,7 +1181,7 @@ TOP: " case MHD_%c_O_END:\n" " i = options_max_num - 1;\n" " break;\n", - (char) toupper (*category)); + (char)toupper (*category)); iterate (head, &dump_option_set_switch); fprintf (f, @@ -1190,7 +1190,7 @@ TOP: " res = MHD_SC_OPTION_UNKNOWN;\n" " i = options_max_num - 1;\n" " break;\n", - (char) toupper (*category)); + (char)toupper (*category)); fprintf (f, " }\n" " }\n"); @@ -1216,7 +1216,7 @@ TOP: my_asprintf (&do_h, "../mhd2/%s_options.h", category); - (void) unlink (do_h); + (void)unlink (do_h); f = fopen (do_h, "w"); if (NULL == f) { diff --git a/src/include/r_options.rec b/src/include/r_options.rec @@ -34,7 +34,7 @@ CustomSetter: /* custom setter */ + } + } + else if ((MHD_NO != option->val.reusable) -+ && (! response_make_reusable (response))) ++ && (!response_make_reusable (response))) + { + res = MHD_SC_RESP_MUTEX_INIT_FAILED; + i = options_max_num - 1; diff --git a/src/mhd2/action.c b/src/mhd2/action.c @@ -73,7 +73,7 @@ MHD_action_suspend (struct MHD_Request *request) struct MHD_Action *const head_act = mhd_REQ_GET_ACT_HEAD (request); if (mhd_ACTION_NO_ACTION != head_act->act) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; head_act->act = mhd_ACTION_SUSPEND; return head_act; @@ -87,7 +87,7 @@ MHD_action_from_response (struct MHD_Request *MHD_RESTRICT request, { struct MHD_Action *const head_act = mhd_REQ_GET_ACT_HEAD (request); if (NULL == response) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; mhd_response_check_frozen_freeze (response); mhd_response_inc_use_count (response); @@ -95,12 +95,12 @@ MHD_action_from_response (struct MHD_Request *MHD_RESTRICT request, #ifdef MHD_SUPPORT_HTTP2 if (mhd_REQ_IS_HTTP2 (request)) { - if (! mhd_h2_act_is_resp_h2_compatible ((struct mhd_H2RequestData*) request, - response)) + if (!mhd_h2_act_is_resp_h2_compatible ((struct mhd_H2RequestData *)request, + response)) { /* Clean-up unused response */ mhd_response_dec_use_count (response); - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; } } #endif /* MHD_SUPPORT_HTTP2 */ @@ -109,22 +109,22 @@ MHD_action_from_response (struct MHD_Request *MHD_RESTRICT request, { /* Clean-up unused response */ mhd_response_dec_use_count (response); - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; } #ifdef MHD_SUPPORT_AUTH_DIGEST - if (mhd_RESP_HAS_AUTH_DIGEST (response) && - ! mhd_D_HAS_AUTH_DIGEST ( \ + if (mhd_RESP_HAS_AUTH_DIGEST (response) + && !mhd_D_HAS_AUTH_DIGEST ( \ mhd_CNTNR_CPTR (request, struct MHD_Connection, rq)->daemon)) { /* Clean-up unused response */ mhd_response_dec_use_count (response); // TODO: get connection pointer for HTTP/2 - mhd_assert (! mhd_REQ_IS_HTTP2 (request)); + mhd_assert (!mhd_REQ_IS_HTTP2 (request)); mhd_LOG_MSG (mhd_CNTNR_PTR (request, struct MHD_Connection, rq)->daemon, \ MHD_SC_AUTH_DIGEST_UNSUPPORTED, \ "Attempted to use a response with Digest Auth challenge on " \ "the daemon without enabled Digest Auth support"); - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; } #endif /* MHD_SUPPORT_AUTH_DIGEST */ @@ -147,19 +147,19 @@ MHD_action_process_upload (struct MHD_Request *request, struct MHD_Action *const head_act = mhd_REQ_GET_ACT_HEAD (request); if (mhd_ACTION_NO_ACTION != head_act->act) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; if (0 == large_buffer_size) { if (NULL != uc_full) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; if (NULL == uc_inc) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; } else { if (NULL == uc_full) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; } head_act->act = mhd_ACTION_UPLOAD; @@ -188,10 +188,10 @@ MHD_action_parse_post (struct MHD_Request *request, struct MHD_Action *const head_act = mhd_REQ_GET_ACT_HEAD (request); if (mhd_ACTION_NO_ACTION != head_act->act) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; if (NULL == done_cb) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; head_act->act = mhd_ACTION_POST_PARSE; head_act->data.post_parse.buffer_size = buffer_size; @@ -204,9 +204,14 @@ MHD_action_parse_post (struct MHD_Request *request, return head_act; #else /* ! MHD_SUPPORT_POST_PARSER */ - (void) request; (void) buffer_size; (void) max_nonstream_size; - (void) enc; (void) stream_reader; (void) reader_cls; - (void) done_cb; (void) done_cb_cls; + (void)request; + (void)buffer_size; + (void)max_nonstream_size; + (void)enc; + (void)stream_reader; + (void)reader_cls; + (void)done_cb; + (void)done_cb_cls; return NULL; #endif /* ! MHD_SUPPORT_POST_PARSER */ } @@ -217,7 +222,7 @@ MHD_action_parse_post (struct MHD_Request *request, MHD_EXTERN_ MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (6,5) const struct MHD_Action * +MHD_FN_PAR_IN_SIZE_ (6, 5) const struct MHD_Action * MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request, const char *MHD_RESTRICT upgrade_hdr_value, MHD_UpgradeHandler upgrade_handler, @@ -229,20 +234,20 @@ MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request, &(request->app_act.head_act); if (mhd_REQ_IS_HTTP2 (request)) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; if (mhd_ACTION_NO_ACTION != head_act->act) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; if (NULL == upgrade_handler) - return (const struct MHD_Action *) NULL; + return (const struct MHD_Action *)NULL; if (request->cntn.cntn_size != request->cntn.recv_size) - return (const struct MHD_Action *) NULL; /* Cannot start "Upgrade" if any content upload is pending */ + return (const struct MHD_Action *)NULL; /* Cannot start "Upgrade" if any content upload is pending */ - if (! mhd_upgrade_prep_for_action (request, - upgrade_hdr_value, - num_headers, - headers, - false)) - return (const struct MHD_Action *) NULL; + if (!mhd_upgrade_prep_for_action (request, + upgrade_hdr_value, + num_headers, + headers, + false)) + return (const struct MHD_Action *)NULL; head_act->act = mhd_ACTION_UPGRADE; head_act->data.upgrd.cb = upgrade_handler; @@ -255,7 +260,7 @@ MHD_action_upgrade (struct MHD_Request *MHD_RESTRICT request, MHD_EXTERN_ MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (6,5) const struct MHD_UploadAction * +MHD_FN_PAR_IN_SIZE_ (6, 5) const struct MHD_UploadAction * MHD_upload_action_upgrade ( struct MHD_Request *MHD_RESTRICT request, const char *MHD_RESTRICT upgrade_hdr_value, @@ -268,20 +273,20 @@ MHD_upload_action_upgrade ( &(request->app_act.upl_act); if (mhd_REQ_IS_HTTP2 (request)) - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; if (mhd_UPLOAD_ACTION_NO_ACTION != upl_act->act) - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; if (NULL == upgrade_handler) - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; if (request->cntn.cntn_size != request->cntn.recv_size) - return (const struct MHD_UploadAction *) NULL; /* Cannot start "Upgrade" if any content upload is pending */ + return (const struct MHD_UploadAction *)NULL; /* Cannot start "Upgrade" if any content upload is pending */ - if (! mhd_upgrade_prep_for_action (request, - upgrade_hdr_value, - num_headers, - headers, - true)) - return (const struct MHD_UploadAction *) NULL; + if (!mhd_upgrade_prep_for_action (request, + upgrade_hdr_value, + num_headers, + headers, + true)) + return (const struct MHD_UploadAction *)NULL; upl_act->act = mhd_UPLOAD_ACTION_UPGRADE; upl_act->data.upgrd.cb = upgrade_handler; @@ -300,7 +305,7 @@ MHD_upload_action_suspend (struct MHD_Request *request) { struct MHD_UploadAction *const upl_act = mhd_REQ_GET_ACT_UPLD (request); if (mhd_UPLOAD_ACTION_NO_ACTION != upl_act->act) - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; upl_act->act = mhd_UPLOAD_ACTION_SUSPEND; @@ -315,7 +320,7 @@ MHD_upload_action_from_response (struct MHD_Request *MHD_RESTRICT request, { struct MHD_UploadAction *const upl_act = mhd_REQ_GET_ACT_UPLD (request); if (NULL == response) - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; mhd_response_check_frozen_freeze (response); mhd_response_inc_use_count (response); @@ -323,12 +328,12 @@ MHD_upload_action_from_response (struct MHD_Request *MHD_RESTRICT request, #ifdef MHD_SUPPORT_HTTP2 if (mhd_REQ_IS_HTTP2 (request)) { - if (! mhd_h2_act_is_resp_h2_compatible ((struct mhd_H2RequestData*) request, - response)) + if (!mhd_h2_act_is_resp_h2_compatible ((struct mhd_H2RequestData *)request, + response)) { /* Clean-up unused response */ mhd_response_dec_use_count (response); - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; } } #endif /* MHD_SUPPORT_HTTP2 */ @@ -337,22 +342,22 @@ MHD_upload_action_from_response (struct MHD_Request *MHD_RESTRICT request, { /* Clean-up unused response */ mhd_response_dec_use_count (response); - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; } #ifdef MHD_SUPPORT_AUTH_DIGEST - if (mhd_RESP_HAS_AUTH_DIGEST (response) && - ! mhd_D_HAS_AUTH_DIGEST ( \ + if (mhd_RESP_HAS_AUTH_DIGEST (response) + && !mhd_D_HAS_AUTH_DIGEST ( \ mhd_CNTNR_CPTR (request, struct MHD_Connection, rq)->daemon)) { /* Clean-up unused response */ mhd_response_dec_use_count (response); // TODO: get connection pointer for HTTP/2 - mhd_assert (! mhd_REQ_IS_HTTP2 (request)); + mhd_assert (!mhd_REQ_IS_HTTP2 (request)); mhd_LOG_MSG (mhd_CNTNR_PTR (request, struct MHD_Connection, rq)->daemon, \ MHD_SC_AUTH_DIGEST_UNSUPPORTED, \ "Attempted to use a response with Digest Auth challenge on " \ "the daemon without enabled Digest Auth support"); - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; } #endif /* MHD_SUPPORT_AUTH_DIGEST */ @@ -369,7 +374,7 @@ MHD_upload_action_continue (struct MHD_Request *request) { struct MHD_UploadAction *const upl_act = mhd_REQ_GET_ACT_UPLD (request); if (mhd_UPLOAD_ACTION_NO_ACTION != upl_act->act) - return (const struct MHD_UploadAction *) NULL; + return (const struct MHD_UploadAction *)NULL; upl_act->act = mhd_UPLOAD_ACTION_CONTINUE; diff --git a/src/mhd2/auth_basic.c b/src/mhd2/auth_basic.c @@ -74,9 +74,9 @@ find_and_parse_auth_basic (struct MHD_Request *restrict req) mhd_assert (NULL == req->auth.basic.intr.username.cstr); - if (! mhd_request_get_auth_header_value (req, - mhd_AUTH_HDR_BASIC, - &token68)) + if (!mhd_request_get_auth_header_value (req, + mhd_AUTH_HDR_BASIC, + &token68)) return MHD_SC_AUTH_ABSENT; mhd_assert (NULL != token68.cstr); @@ -112,9 +112,9 @@ find_and_parse_auth_basic (struct MHD_Request *restrict req) dec_buf[dec_size] = 0; /* Zero-terminate the result */ req->auth.basic.intr.username.cstr = dec_buf; - colon_ptr = (char *) memchr (dec_buf, - ':', - dec_size); + colon_ptr = (char *)memchr (dec_buf, + ':', + dec_size); if (NULL == colon_ptr) { /* No password provided. Only username. */ @@ -124,7 +124,7 @@ find_and_parse_auth_basic (struct MHD_Request *restrict req) return MHD_SC_OK; } *colon_ptr = 0; /* Zero-terminate the username */ - req->auth.basic.intr.username.len = (size_t) (colon_ptr - dec_buf); + req->auth.basic.intr.username.len = (size_t)(colon_ptr - dec_buf); req->auth.basic.intr.password.cstr = colon_ptr + 1; mhd_assert ((req->auth.basic.intr.username.len + 1) <= dec_size); req->auth.basic.intr.password.len = diff --git a/src/mhd2/auth_basic.h b/src/mhd2/auth_basic.h @@ -47,8 +47,8 @@ #include "mhd_sys_options.h" -#if ! defined(MHD_SUPPORT_AUTH_BASIC) -#error Basic Authorization must be enabled +#if !defined(MHD_SUPPORT_AUTH_BASIC) +# error Basic Authorization must be enabled #endif #include "mhd_public_api.h" diff --git a/src/mhd2/auth_digest.c b/src/mhd2/auth_digest.c @@ -244,8 +244,8 @@ simple_hash (size_t data_size, else memcpy (&a, data, data_size); a ^= c[(i++) % mhd_ARR_NUM_ELEMS (c)]; - a = (uint_fast64_t) mhd_ROTR64 ((uint64_t) a, \ - (unsigned int) (res >> 58u)); + a = (uint_fast64_t)mhd_ROTR64 ((uint64_t)a, \ + (unsigned int)(res >> 58u)); res ^= a; if (8 >= data_size) break; @@ -279,7 +279,7 @@ nonce_to_index (const uint8_t nonce[mhd_AUTH_DIGEST_NONCE_BIN_SIZE], hash = (hash ^ (hash >> 8)) & 0xFFu; /* 'arr_size' <=8-bit, fold hash */ } } - return ((size_t) hash) % arr_size; + return ((size_t)hash) % arr_size; } @@ -306,15 +306,15 @@ gen_new_nonce (struct MHD_Daemon *restrict d, { uint_fast64_t expiration; - mhd_assert (! mhd_D_HAS_MASTER (d)); /* only master daemon should be used */ + mhd_assert (!mhd_D_HAS_MASTER (d)); /* only master daemon should be used */ mhd_assert (d == c->daemon); mhd_assert (0 != d->auth_dg.cfg.nonce_tmout); expiration = mhd_monotonic_msec_counter () - + d->auth_dg.cfg.nonce_tmout * (uint_fast64_t) 1000; + + d->auth_dg.cfg.nonce_tmout * (uint_fast64_t)1000; - if (! mhd_rng (mhd_AUTH_DIGEST_NONCE_BIN_SIZE, - out_buf)) + if (!mhd_rng (mhd_AUTH_DIGEST_NONCE_BIN_SIZE, + out_buf)) { /* Fallback to generating nonce from application-provided entropy. Note: this should fail if we do not have @@ -328,17 +328,17 @@ gen_new_nonce (struct MHD_Daemon *restrict d, mhd_SHA512_256_init_one_time (&(d_ctx.sha512_256_ctx)); mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), d->auth_dg.entropy.size, - (const uint8_t*) d->auth_dg.entropy.data); + (const uint8_t *)d->auth_dg.entropy.data); mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), sizeof(gen_num), - (const uint8_t*) &gen_num); + (const uint8_t *)&gen_num); if (0 != c->sk.addr.size) mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), c->sk.addr.size, - (const uint8_t*) c->sk.addr.data); + (const uint8_t *)c->sk.addr.data); mhd_SHA512_256_update (&(d_ctx.sha512_256_ctx), sizeof(expiration), - (const uint8_t*) &expiration); + (const uint8_t *)&expiration); mhd_SHA512_256_finish_deinit (&(d_ctx.sha512_256_ctx), \ out_buf); if (mhd_SHA512_256_has_err (&(d_ctx.sha512_256_ctx))) @@ -347,39 +347,39 @@ gen_new_nonce (struct MHD_Daemon *restrict d, mhd_SHA256_init_one_time (&(d_ctx.sha256_ctx)); mhd_SHA256_update (&(d_ctx.sha256_ctx), d->auth_dg.entropy.size, - (const void*) d->auth_dg.entropy.data); + (const void *)d->auth_dg.entropy.data); mhd_SHA256_update (&(d_ctx.sha256_ctx), sizeof(gen_num), - (const void*) &gen_num); + (const void *)&gen_num); if (0 != c->sk.addr.size) mhd_SHA256_update (&(d_ctx.sha256_ctx), c->sk.addr.size, - (const void*) c->sk.addr.data); + (const void *)c->sk.addr.data); mhd_SHA256_update (&(d_ctx.sha256_ctx), sizeof(expiration), - (const void*) &expiration); + (const void *)&expiration); mhd_SHA256_finish_deinit (&(d_ctx.sha256_ctx), \ out_buf); if (mhd_SHA256_has_err (&(d_ctx.sha256_ctx))) return false; #else /* MHD_SUPPORT_MD5 */ -#ifndef MHD_SUPPORT_MD5 -#error At least one hashing algorithm must be enabled -#endif +# ifndef MHD_SUPPORT_MD5 +# error At least one hashing algorithm must be enabled +# endif mhd_MD5_init_one_time (&(d_ctx.md5_ctx)); mhd_MD5_update (&(d_ctx.md5_ctx), d->auth_dg.entropy.size, - (const void*) d->auth_dg.entropy.data); + (const void *)d->auth_dg.entropy.data); mhd_MD5_update (&(d_ctx.md5_ctx), sizeof(gen_num), - (const void*) &gen_num); + (const void *)&gen_num); if (0 != c->sk.addr.size) mhd_MD5_update (&(d_ctx.md5_ctx), c->sk.addr.size, - (const void*) c->sk.addr.data); + (const void *)c->sk.addr.data); mhd_MD5_update (&(d_ctx.md5_ctx), sizeof(expiration), - (const void*) &expiration); + (const void *)&expiration); mhd_MD5_finish_deinit (&(d_ctx.md5_ctx), \ out_buf); if (mhd_MD5_has_err (&(d_ctx.md5_ctx))) @@ -391,17 +391,17 @@ gen_new_nonce (struct MHD_Daemon *restrict d, mhd_MD5_init_one_time (&(d_ctx.md5_ctx)); mhd_MD5_update (&(d_ctx.md5_ctx), d->auth_dg.entropy.size, - (const void*) d->auth_dg.entropy.data); + (const void *)d->auth_dg.entropy.data); mhd_MD5_update (&(d_ctx.md5_ctx), sizeof(gen_num), - (const void*) &gen_num); + (const void *)&gen_num); if (0 != c->sk.addr.size) mhd_MD5_update (&(d_ctx.md5_ctx), c->sk.addr.size, - (const void*) c->sk.addr.data); + (const void *)c->sk.addr.data); mhd_MD5_update (&(d_ctx.md5_ctx), sizeof(expiration), - (const void*) &expiration); + (const void *)&expiration); mhd_MD5_finish_deinit (&(d_ctx.md5_ctx), \ out_buf + mhd_MD5_DIGEST_SIZE); if (mhd_MD5_has_err (&(d_ctx.md5_ctx))) @@ -410,9 +410,9 @@ gen_new_nonce (struct MHD_Daemon *restrict d, } - *expir = (uint_fast32_t) (expiration / 1000u); + *expir = (uint_fast32_t)(expiration / 1000u); mhd_PUT_32BIT_LE_UNALIGN (out_buf + mhd_AUTH_DIGEST_NONCE_RAND_BIN_SIZE, \ - (uint32_t) (*expir & UINT32_C (0xFFFFFFFF))); + (uint32_t)(*expir & UINT32_C (0xFFFFFFFF))); return true; } @@ -438,17 +438,17 @@ mhd_auth_digest_get_new_nonce (struct MHD_Connection *restrict c, { bool good_nonce; struct mhd_DaemonAuthDigestNonceData *nonce_slot; - if (! gen_new_nonce (d, - c, - nonce_bin, - &expir)) + if (!gen_new_nonce (d, + c, + nonce_bin, + &expir)) continue; /* Failed, re-try */ nonce_generated = true; nonce_slot = d->auth_dg.nonces + nonce_to_index (nonce_bin, d->auth_dg.cfg.nonces_num); - if (! mhd_mutex_lock (&(d->auth_dg.nonces_lock))) + if (!mhd_mutex_lock (&(d->auth_dg.nonces_lock))) return false; /* Failure exit point */ /* Check whether the same nonce has been used before */ good_nonce = (0 != memcmp (nonce_slot->nonce, @@ -473,15 +473,15 @@ mhd_auth_digest_get_new_nonce (struct MHD_Connection *restrict c, if (good_nonce) break; } - if (! nonce_generated) + if (!nonce_generated) return false; /* Failure exit point */ /* Use the generated nonce even if it is duplicated. One of the clients will just get "nonce stale" response with the new nonce. */ - (void) mhd_bin_to_hex (nonce_bin, - sizeof(nonce_bin), - out_buf); + (void)mhd_bin_to_hex (nonce_bin, + sizeof(nonce_bin), + out_buf); return true; /* Success exit point */ } @@ -656,16 +656,16 @@ parse_dauth_params (const struct MHD_String *restrict val, The order of the elements matches the previous array. */ struct mhd_RqDAuthParam *params[sizeof(tk_names) / sizeof(tk_names[0])]; - params[0 ] = &(pdauth->nonce); /* 0 */ - params[1 ] = &(pdauth->opaque); /* 1 */ - params[2 ] = &algorithm; /* 2 */ - params[3 ] = &(pdauth->response); /* 3 */ - params[4 ] = &(pdauth->username); /* 4 */ - params[5 ] = &(pdauth->username_ext); /* 5 */ - params[6 ] = &(pdauth->realm); /* 6 */ - params[7 ] = &(pdauth->uri); /* 7 */ - params[8 ] = &(pdauth->qop_raw); /* 8 */ - params[9 ] = &(pdauth->cnonce); /* 9 */ + params[0] = &(pdauth->nonce); /* 0 */ + params[1] = &(pdauth->opaque); /* 1 */ + params[2] = &algorithm; /* 2 */ + params[3] = &(pdauth->response); /* 3 */ + params[4] = &(pdauth->username); /* 4 */ + params[5] = &(pdauth->username_ext); /* 5 */ + params[6] = &(pdauth->realm); /* 6 */ + params[7] = &(pdauth->uri); /* 7 */ + params[8] = &(pdauth->qop_raw); /* 8 */ + params[9] = &(pdauth->cnonce); /* 9 */ params[10] = &(pdauth->nc); /* 10 */ params[11] = &userhash; /* 11 */ @@ -689,15 +689,15 @@ parse_dauth_params (const struct MHD_String *restrict val, { const struct MHD_String *const tk_name = tk_names[p]; struct mhd_RqDAuthParam *const param = params[p]; - if ( (tk_name->len <= left) && - mhd_str_equal_caseless_bin_n (val->cstr + i, tk_name->cstr, - tk_name->len) && - ((tk_name->len == left) || - ('=' == val->cstr[i + tk_name->len]) || - (' ' == val->cstr[i + tk_name->len]) || - ('\t' == val->cstr[i + tk_name->len]) || - (',' == val->cstr[i + tk_name->len]) || - (';' == val->cstr[i + tk_name->len])) ) + if ((tk_name->len <= left) + && mhd_str_equal_caseless_bin_n (val->cstr + i, tk_name->cstr, + tk_name->len) + && ((tk_name->len == left) + || ('=' == val->cstr[i + tk_name->len]) + || (' ' == val->cstr[i + tk_name->len]) + || ('\t' == val->cstr[i + tk_name->len]) + || (',' == val->cstr[i + tk_name->len]) + || (';' == val->cstr[i + tk_name->len]))) { size_t value_start; size_t value_len; @@ -760,7 +760,7 @@ parse_dauth_params (const struct MHD_String *restrict val, return false; /* Garbage after parameter value */ /* Have valid parameter name and value */ - mhd_assert (! quoted || 0 != value_len); + mhd_assert (!quoted || 0 != value_len); param->value.cstr = val->cstr + value_start; param->value.len = value_len; param->quoted = quoted; @@ -852,9 +852,9 @@ get_rq_auth_digest_params (struct MHD_Request *restrict req) if (NULL != req->auth.digest.rqp) return MHD_SC_OK; - if (! mhd_request_get_auth_header_value (req, - mhd_AUTH_HDR_DIGEST, - &h_auth_value)) + if (!mhd_request_get_auth_header_value (req, + mhd_AUTH_HDR_DIGEST, + &h_auth_value)) return MHD_SC_AUTH_ABSENT; dauth = @@ -868,8 +868,8 @@ get_rq_auth_digest_params (struct MHD_Request *restrict req) return MHD_SC_CONNECTION_POOL_NO_MEM_AUTH_DATA; memset (dauth, 0, sizeof(struct mhd_AuthDigesReqParams)); - if (! parse_dauth_params (&h_auth_value, - dauth)) + if (!parse_dauth_params (&h_auth_value, + dauth)) return MHD_SC_REQ_AUTH_DATA_BROKEN; req->auth.digest.rqp = dauth; @@ -899,8 +899,8 @@ get_rq_uname_type (const struct mhd_AuthDigesReqParams *params) } else if (NULL != params->username_ext.value.cstr) { - if (! params->username_ext.quoted && ! params->userhash && - (mhd_DAUTH_EXT_PARAM_MIN_LEN <= params->username_ext.value.len) ) + if (!params->username_ext.quoted && !params->userhash + && (mhd_DAUTH_EXT_PARAM_MIN_LEN <= params->username_ext.value.len)) return MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED; else return MHD_DIGEST_AUTH_UNAME_TYPE_INVALID; @@ -925,8 +925,8 @@ get_rq_unames_size (const struct mhd_AuthDigesReqParams *params, mhd_assert (get_rq_uname_type (params) == uname_type); s = 0; - if ((MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD == uname_type) || - (MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH == uname_type) ) + if ((MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD == uname_type) + || (MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH == uname_type)) { s += params->username.value.len + 1; /* Add one byte for zero-termination */ if (MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH == uname_type) @@ -954,10 +954,10 @@ get_rq_param_unquoted_copy_z (const struct mhd_RqDAuthParam *restrict param, { size_t len; mhd_assert (NULL != param->value.cstr); - if (! param->quoted) + if (!param->quoted) { memcpy (buf, param->value.cstr, param->value.len); - buf [param->value.len] = 0; + buf[param->value.len] = 0; return param->value.len; } @@ -980,8 +980,8 @@ get_rq_param_unquoted_copy_z (const struct mhd_RqDAuthParam *restrict param, * -1 if wrong extended notation is used. */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) -MHD_FN_PAR_OUT_SIZE_ (3,4) ssize_t +MHD_FN_PAR_IN_SIZE_ (1, 2) +MHD_FN_PAR_OUT_SIZE_ (3, 4) ssize_t get_rq_extended_uname_copy_z (const char *restrict uname_ext, size_t uname_ext_len, char *restrict buf, @@ -989,13 +989,13 @@ get_rq_extended_uname_copy_z (const char *restrict uname_ext, { size_t r; size_t w; - if ((size_t) SSIZE_MAX < uname_ext_len) + if ((size_t)SSIZE_MAX < uname_ext_len) return -1; /* Too long input string */ if (mhd_DAUTH_EXT_PARAM_MIN_LEN > uname_ext_len) return -1; /* Required prefix is missing */ - if (! mhd_str_equal_caseless_bin_n ( + if (!mhd_str_equal_caseless_bin_n ( uname_ext, mhd_DAUTH_EXT_PARAM_PREFIX, mhd_SSTR_LEN (mhd_DAUTH_EXT_PARAM_PREFIX))) @@ -1006,8 +1006,8 @@ get_rq_extended_uname_copy_z (const char *restrict uname_ext, while (r < uname_ext_len && '\'' != uname_ext[r]) { const char chr = uname_ext[r]; - if ((' ' == chr) || ('\t' == chr) || ('\"' == chr) || (',' == chr) || - (';' == chr) ) + if ((' ' == chr) || ('\t' == chr) || ('\"' == chr) || (',' == chr) + || (';' == chr)) return -1; /* Wrong char in language tag */ r++; } @@ -1021,7 +1021,7 @@ get_rq_extended_uname_copy_z (const char *restrict uname_ext, return -1; /* Broken percent encoding */ buf[w] = 0; /* Zero terminate the result */ mhd_assert (SSIZE_MAX > w); - return (ssize_t) w; + return (ssize_t)w; } @@ -1057,10 +1057,10 @@ get_rq_uname (const struct mhd_AuthDigesReqParams *restrict params, if (MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD == uname_type) { // TODO: Avoid copying string if not quoted - uname_info->username.cstr = (char *) (buf + buf_used); + uname_info->username.cstr = (char *)(buf + buf_used); uname_info->username.len = get_rq_param_unquoted_copy_z (&params->username, - (char *) (buf + buf_used)); + (char *)(buf + buf_used)); buf_used += uname_info->username.len + 1; uname_info->uname_type = MHD_DIGEST_AUTH_UNAME_TYPE_STANDARD; } @@ -1068,15 +1068,15 @@ get_rq_uname (const struct mhd_AuthDigesReqParams *restrict params, { size_t res; - uname_info->userhash_hex.cstr = (char *) (buf + buf_used); + uname_info->userhash_hex.cstr = (char *)(buf + buf_used); uname_info->userhash_hex.len = get_rq_param_unquoted_copy_z (&params->username, - (char *) (buf + buf_used)); + (char *)(buf + buf_used)); buf_used += uname_info->userhash_hex.len + 1; - uname_info->userhash_bin = (uint8_t *) (buf + buf_used); + uname_info->userhash_bin = (uint8_t *)(buf + buf_used); res = mhd_hex_to_bin (uname_info->userhash_hex.cstr, uname_info->userhash_hex.len, - (uint8_t *) (buf + buf_used)); + (uint8_t *)(buf + buf_used)); if (res != uname_info->userhash_hex.len / 2) { uname_info->userhash_bin = NULL; @@ -1086,7 +1086,7 @@ get_rq_uname (const struct mhd_AuthDigesReqParams *restrict params, { /* Avoid pointers outside allocated region when the size is zero */ if (0 == res) - uname_info->userhash_bin = (const uint8_t *) uname_info->username.cstr; + uname_info->userhash_bin = (const uint8_t *)uname_info->username.cstr; uname_info->uname_type = MHD_DIGEST_AUTH_UNAME_TYPE_USERHASH; buf_used += res; } @@ -1096,14 +1096,14 @@ get_rq_uname (const struct mhd_AuthDigesReqParams *restrict params, ssize_t res; res = get_rq_extended_uname_copy_z (params->username_ext.value.cstr, params->username_ext.value.len, - (char *) (buf + buf_used), + (char *)(buf + buf_used), buf_size - buf_used); if (0 > res) uname_info->uname_type = MHD_DIGEST_AUTH_UNAME_TYPE_INVALID; else { - uname_info->username.cstr = (char *) (buf + buf_used); - uname_info->username.len = (size_t) res; + uname_info->username.cstr = (char *)(buf + buf_used); + uname_info->username.len = (size_t)res; uname_info->uname_type = MHD_DIGEST_AUTH_UNAME_TYPE_EXTENDED; buf_used += uname_info->username.len + 1; } @@ -1155,7 +1155,7 @@ get_rq_nc (const struct mhd_AuthDigesReqParams *params, if (0 == nc_param->value.len) return mhd_GET_RQ_NC_BROKEN; - if (! nc_param->quoted) + if (!nc_param->quoted) { val = nc_param->value.cstr; val_len = nc_param->value.len; @@ -1177,9 +1177,9 @@ get_rq_nc (const struct mhd_AuthDigesReqParams *params, if (0 == res) { const char f = val[0]; - if ( (('9' >= f) && ('0' <= f)) || - (('F' >= f) && ('A' <= f)) || - (('a' <= f) && ('f' >= f)) ) + if ((('9' >= f) && ('0' <= f)) + || (('F' >= f) && ('A' <= f)) + || (('a' <= f) && ('f' >= f))) return mhd_GET_RQ_NC_TOO_LARGE; else return mhd_GET_RQ_NC_BROKEN; @@ -1188,7 +1188,7 @@ get_rq_nc (const struct mhd_AuthDigesReqParams *params, return mhd_GET_RQ_NC_BROKEN; if (nc_val != (nc_val & UINT64_C (0xFFFFFFFF))) return mhd_GET_RQ_NC_TOO_LARGE; - *nc = (uint_fast32_t) nc_val; + *nc = (uint_fast32_t)nc_val; return mhd_GET_RQ_NC_VALID; } @@ -1241,13 +1241,13 @@ find_and_parse_auth_digest_info (struct MHD_Request *restrict req) info->realm.cstr = NULL; #endif - unif_buf_ptr = (uint8_t *) (info + 1); + unif_buf_ptr = (uint8_t *)(info + 1); unif_buf_used = 0; info->algo = req->auth.digest.rqp->algo; - if ( (MHD_DIGEST_AUTH_UNAME_TYPE_MISSING != uname_type) && - (MHD_DIGEST_AUTH_UNAME_TYPE_INVALID != uname_type) ) + if ((MHD_DIGEST_AUTH_UNAME_TYPE_MISSING != uname_type) + && (MHD_DIGEST_AUTH_UNAME_TYPE_INVALID != uname_type)) unif_buf_used += get_rq_uname (req->auth.digest.rqp, uname_type, info, unif_buf_ptr + unif_buf_used, @@ -1257,18 +1257,18 @@ find_and_parse_auth_digest_info (struct MHD_Request *restrict req) if (NULL != req->auth.digest.rqp->opaque.value.cstr) { - info->opaque.cstr = (char *) (unif_buf_ptr + unif_buf_used); + info->opaque.cstr = (char *)(unif_buf_ptr + unif_buf_used); info->opaque.len = get_rq_param_unquoted_copy_z (&(req->auth.digest.rqp->opaque), - (char *) (unif_buf_ptr + unif_buf_used)); + (char *)(unif_buf_ptr + unif_buf_used)); unif_buf_used += info->opaque.len + 1; } if (NULL != req->auth.digest.rqp->realm.value.cstr) { - info->realm.cstr = (char *) (unif_buf_ptr + unif_buf_used); + info->realm.cstr = (char *)(unif_buf_ptr + unif_buf_used); info->realm.len = get_rq_param_unquoted_copy_z (&(req->auth.digest.rqp->realm), - (char *) (unif_buf_ptr + unif_buf_used)); + (char *)(unif_buf_ptr + unif_buf_used)); unif_buf_used += info->realm.len + 1; } @@ -1295,16 +1295,16 @@ find_and_parse_auth_digest_info (struct MHD_Request *restrict req) if (mhd_GET_RQ_NC_BROKEN == nc_res) info->nc_type = MHD_DIGEST_AUTH_NC_NONE; else - info->nc_type = (enum MHD_DigestAuthNC) nc_res; + info->nc_type = (enum MHD_DigestAuthNC)nc_res; } req->auth.digest.info = info; mhd_assert (uname_type == info->uname_type); - if ((MHD_DIGEST_AUTH_UNAME_TYPE_MISSING == uname_type) || - (MHD_DIGEST_AUTH_UNAME_TYPE_INVALID == uname_type) || - ((mhd_GET_RQ_NC_BROKEN == nc_res))) + if ((MHD_DIGEST_AUTH_UNAME_TYPE_MISSING == uname_type) + || (MHD_DIGEST_AUTH_UNAME_TYPE_INVALID == uname_type) + || ((mhd_GET_RQ_NC_BROKEN == nc_res))) return MHD_SC_REQ_AUTH_DATA_BROKEN; return MHD_SC_OK; @@ -1349,11 +1349,11 @@ get_base_digest_algo (enum MHD_DigestAuthAlgo algo) unsigned int base_algo; base_algo = - ((unsigned int) algo) + ((unsigned int)algo) & ~((unsigned int) (MHD_DIGEST_AUTH_ALGO_NON_SESSION | MHD_DIGEST_AUTH_ALGO_SESSION)); - return (enum MHD_DigestBaseAlgo) base_algo; + return (enum MHD_DigestBaseAlgo)base_algo; } @@ -1376,42 +1376,42 @@ digest_get_hash_size (enum MHD_DigestAuthAlgo algo) #endif /* MHD_SUPPORT_SHA256 */ #ifdef MHD_SUPPORT_SHA512_256 mhd_assert (MHD_SHA512_256_DIGEST_SIZE == mhd_SHA512_256_DIGEST_SIZE); -#ifdef MHD_SUPPORT_SHA256 +# ifdef MHD_SUPPORT_SHA256 mhd_assert (mhd_SHA256_DIGEST_SIZE == mhd_SHA512_256_DIGEST_SIZE); -#endif /* MHD_SUPPORT_SHA256 */ +# endif /* MHD_SUPPORT_SHA256 */ #endif /* MHD_SUPPORT_SHA512_256 */ /* Only one algorithm must be specified */ mhd_assert (1 == \ - (((0 != (((unsigned int) algo) \ + (((0 != (((unsigned int)algo) \ & MHD_DIGEST_BASE_ALGO_MD5)) ? 1 : 0) \ - + ((0 != (((unsigned int) algo) \ + + ((0 != (((unsigned int)algo) \ & MHD_DIGEST_BASE_ALGO_SHA256)) ? 1 : 0) \ - + ((0 != (((unsigned int) algo) \ + + ((0 != (((unsigned int)algo) \ & MHD_DIGEST_BASE_ALGO_SHA512_256)) ? 1 : 0))); #ifdef MHD_SUPPORT_MD5 - if (0 != (((unsigned int) algo) - & ((unsigned int) MHD_DIGEST_BASE_ALGO_MD5))) + if (0 != (((unsigned int)algo) + & ((unsigned int)MHD_DIGEST_BASE_ALGO_MD5))) return MHD_MD5_DIGEST_SIZE; else #endif /* MHD_SUPPORT_MD5 */ #if defined(MHD_SUPPORT_SHA256) && defined(MHD_SUPPORT_SHA512_256) - if (0 != (((unsigned int) algo) - & ( ((unsigned int) MHD_DIGEST_BASE_ALGO_SHA256) - | ((unsigned int) MHD_DIGEST_BASE_ALGO_SHA512_256)))) + if (0 != (((unsigned int)algo) + & (((unsigned int)MHD_DIGEST_BASE_ALGO_SHA256) + | ((unsigned int)MHD_DIGEST_BASE_ALGO_SHA512_256)))) return MHD_SHA256_DIGEST_SIZE; /* The same as mhd_SHA512_256_DIGEST_SIZE */ else #elif defined(MHD_SUPPORT_SHA256) - if (0 != (((unsigned int) algo) - & ((unsigned int) MHD_DIGEST_BASE_ALGO_SHA256))) + if (0 != (((unsigned int)algo) + & ((unsigned int)MHD_DIGEST_BASE_ALGO_SHA256))) return MHD_SHA256_DIGEST_SIZE; else #elif defined(MHD_SUPPORT_SHA512_256) - if (0 != (((unsigned int) algo) - & ((unsigned int) MHD_DIGEST_BASE_ALGO_SHA512_256))) + if (0 != (((unsigned int)algo) + & ((unsigned int)MHD_DIGEST_BASE_ALGO_SHA512_256))) return MHD_SHA512_256_DIGEST_SIZE; else #endif /* MHD_SUPPORT_SHA512_256 */ - (void) 0; /* Unsupported algorithm */ + (void)0; /* Unsupported algorithm */ return 0; /* Wrong input or unsupported algorithm */ } @@ -1474,7 +1474,7 @@ struct DigestAlgorithm mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ unsigned int digest_get_size (struct DigestAlgorithm *da) { - mhd_assert (! da->uninitialised); + mhd_assert (!da->uninitialised); mhd_assert (da->algo_selected); #ifdef MHD_SUPPORT_MD5 if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) @@ -1499,7 +1499,7 @@ digest_get_size (struct DigestAlgorithm *da) /** * Indicates presence of digest_deinit() function */ -#define mhd_DIGEST_HAS_DEINIT 1 +# define mhd_DIGEST_HAS_DEINIT 1 #endif /* mhd_MD5_HAS_DEINIT || mhd_SHA256_HAS_DEINIT */ #ifdef mhd_DIGEST_HAS_DEINIT @@ -1513,12 +1513,12 @@ digest_get_size (struct DigestAlgorithm *da) mhd_static_inline void digest_setup_zero (struct DigestAlgorithm *da) { -#ifndef NDEBUG +# ifndef NDEBUG da->uninitialised = false; da->algo_selected = false; da->ready_for_hashing = false; da->hashing = false; -#endif /* _DEBUG */ +# endif /* _DEBUG */ da->algo = MHD_DIGEST_BASE_ALGO_INVALID; } @@ -1535,30 +1535,30 @@ digest_setup_zero (struct DigestAlgorithm *da) mhd_static_inline void digest_deinit (struct DigestAlgorithm *da) { - mhd_assert (! da->uninitialised); -#ifdef mhd_MD5_HAS_DEINIT + mhd_assert (!da->uninitialised); +# ifdef mhd_MD5_HAS_DEINIT if (MHD_DIGEST_BASE_ALGO_MD5 == da->algo) mhd_MD5_deinit (&(da->ctx.md5_ctx)); else -#endif /* mhd_MD5_HAS_DEINIT */ -#ifdef mhd_SHA256_HAS_DEINIT +# endif /* mhd_MD5_HAS_DEINIT */ +# ifdef mhd_SHA256_HAS_DEINIT if (MHD_DIGEST_BASE_ALGO_SHA256 == da->algo) mhd_SHA256_deinit (&(da->ctx.sha256_ctx)); else -#endif /* mhd_SHA256_HAS_DEINIT */ -#ifdef mhd_SHA512_256_HAS_DEINIT +# endif /* mhd_SHA256_HAS_DEINIT */ +# ifdef mhd_SHA512_256_HAS_DEINIT if (MHD_DIGEST_BASE_ALGO_SHA512_256 == da->algo) mhd_SHA512_256_deinit (&(da->ctx.sha512_256_ctx)); else -#endif /* mhd_SHA512_256_HAS_DEINIT */ - (void) 0; +# endif /* mhd_SHA512_256_HAS_DEINIT */ + (void)0; digest_setup_zero (da); } #else /* ! mhd_DIGEST_HAS_DEINIT */ -#define digest_setup_zero(da) ((void) 0) -#define digest_deinit(da) ((void) 0) +# define digest_setup_zero(da) ((void) 0) +# define digest_deinit(da) ((void) 0) #endif /* ! mhd_DIGEST_HAS_DEINIT */ @@ -1651,7 +1651,7 @@ digest_update (struct DigestAlgorithm *restrict da, size_t size, const void *restrict data) { - mhd_assert (! da->uninitialised); + mhd_assert (!da->uninitialised); mhd_assert (da->algo_selected); mhd_assert (da->ready_for_hashing); switch (da->algo) @@ -1660,7 +1660,7 @@ digest_update (struct DigestAlgorithm *restrict da, #ifdef MHD_SUPPORT_MD5 mhd_MD5_update (&da->ctx.md5_ctx, size, - (const uint8_t *) data); + (const uint8_t *)data); #else mhd_UNREACHABLE (); #endif @@ -1669,7 +1669,7 @@ digest_update (struct DigestAlgorithm *restrict da, #ifdef MHD_SUPPORT_SHA256 mhd_SHA256_update (&da->ctx.sha256_ctx, size, - (const uint8_t *) data); + (const uint8_t *)data); #else mhd_UNREACHABLE (); #endif @@ -1678,7 +1678,7 @@ digest_update (struct DigestAlgorithm *restrict da, #ifdef MHD_SUPPORT_SHA512_256 mhd_SHA512_256_update (&da->ctx.sha512_256_ctx, size, - (const uint8_t *) data); + (const uint8_t *)data); #else mhd_UNREACHABLE (); #endif @@ -1706,7 +1706,7 @@ digest_update_str (struct DigestAlgorithm *restrict da, { digest_update (da, strlen (str), - (const uint8_t *) str); + (const uint8_t *)str); } @@ -1722,7 +1722,7 @@ digest_update_cbuf (struct DigestAlgorithm *restrict da, { digest_update (da, buf->size, - (const uint8_t *) buf->data); + (const uint8_t *)buf->data); } @@ -1738,7 +1738,7 @@ digest_update_buf (struct DigestAlgorithm *restrict da, { digest_update (da, buf->size, - (const uint8_t *) buf->data); + (const uint8_t *)buf->data); } @@ -1749,7 +1749,7 @@ digest_update_buf (struct DigestAlgorithm *restrict da, mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ void digest_update_with_colon (struct DigestAlgorithm *da) { - static const uint8_t colon = (uint8_t) ':'; + static const uint8_t colon = (uint8_t)':'; digest_update (da, 1, &colon); @@ -1767,7 +1767,7 @@ MHD_FN_PAR_OUT_ (2) void digest_calc_hash (struct DigestAlgorithm *da, uint8_t *digest) { - mhd_assert (! da->uninitialised); + mhd_assert (!da->uninitialised); mhd_assert (da->algo_selected); mhd_assert (da->ready_for_hashing); switch (da->algo) @@ -1810,17 +1810,17 @@ digest_calc_hash (struct DigestAlgorithm *da, case MHD_DIGEST_BASE_ALGO_SHA512_256: #ifdef MHD_SUPPORT_SHA512_256 -#ifdef mhd_SHA512_256_HAS_FINISH +# ifdef mhd_SHA512_256_HAS_FINISH mhd_SHA512_256_finish (&da->ctx.sha512_256_ctx, digest); -#ifndef NDEBUG +# ifndef NDEBUG da->ready_for_hashing = false; -#endif /* _DEBUG */ -#else /* ! mhd_SHA512_256_HAS_FINISH */ +# endif /* _DEBUG */ +# else /* ! mhd_SHA512_256_HAS_FINISH */ mhd_SHA512_256_finish_reset (&da->ctx.sha512_256_ctx, digest); -#ifndef NDEBUG +# ifndef NDEBUG da->ready_for_hashing = true; -#endif /* _DEBUG */ -#endif /* ! mhd_SHA512_256_HAS_FINISH */ +# endif /* _DEBUG */ +# endif /* ! mhd_SHA512_256_HAS_FINISH */ #else /* ! MHD_SUPPORT_SHA512_256 */ mhd_UNREACHABLE (); #endif /* ! MHD_SUPPORT_SHA512_256 */ @@ -1845,15 +1845,15 @@ digest_calc_hash (struct DigestAlgorithm *da, mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ void digest_reset (struct DigestAlgorithm *da) { - mhd_assert (! da->uninitialised); + mhd_assert (!da->uninitialised); mhd_assert (da->algo_selected); - mhd_assert (! da->hashing); + mhd_assert (!da->hashing); switch (da->algo) { case MHD_DIGEST_BASE_ALGO_MD5: #ifdef MHD_SUPPORT_MD5 # ifdef mhd_MD5_HAS_FINISH - mhd_assert (! da->ready_for_hashing); + mhd_assert (!da->ready_for_hashing); # else /* ! mhd_MD5_HAS_FINISH */ mhd_assert (da->ready_for_hashing); # endif /* ! mhd_MD5_HAS_FINISH */ @@ -1868,15 +1868,15 @@ digest_reset (struct DigestAlgorithm *da) case MHD_DIGEST_BASE_ALGO_SHA256: #ifdef MHD_SUPPORT_SHA256 -#ifdef mhd_SHA256_HAS_FINISH - mhd_assert (! da->ready_for_hashing); -#else /* ! mhd_SHA256_HAS_FINISH */ +# ifdef mhd_SHA256_HAS_FINISH + mhd_assert (!da->ready_for_hashing); +# else /* ! mhd_SHA256_HAS_FINISH */ mhd_assert (da->ready_for_hashing); -#endif /* ! mhd_SHA256_HAS_FINISH */ +# endif /* ! mhd_SHA256_HAS_FINISH */ mhd_SHA256_reset (&(da->ctx.sha256_ctx)); -#ifndef NDEBUG +# ifndef NDEBUG da->ready_for_hashing = true; -#endif /* _DEBUG */ +# endif /* _DEBUG */ #else /* ! MHD_SUPPORT_SHA256 */ mhd_UNREACHABLE (); #endif /* ! MHD_SUPPORT_SHA256 */ @@ -1885,7 +1885,7 @@ digest_reset (struct DigestAlgorithm *da) case MHD_DIGEST_BASE_ALGO_SHA512_256: #ifdef MHD_SUPPORT_SHA512_256 # ifdef mhd_SHA512_256_HAS_FINISH - mhd_assert (! da->ready_for_hashing); + mhd_assert (!da->ready_for_hashing); # else /* ! mhd_SHA512_256_HAS_FINISH */ mhd_assert (da->ready_for_hashing); # endif /* ! mhd_SHA512_256_HAS_FINISH */ @@ -1915,7 +1915,7 @@ digest_reset (struct DigestAlgorithm *da) /** * Indicates that digest algorithm has external error status */ -#define mhd_DIGEST_HAS_EXT_ERROR 1 +# define mhd_DIGEST_HAS_EXT_ERROR 1 #endif /* mhd_MD5_HAS_EXT_ERROR || mhd_SHA256_HAS_EXT_ERROR || mhd_SHA512_256_HAS_EXT_ERROR*/ @@ -1933,32 +1933,32 @@ digest_reset (struct DigestAlgorithm *da) mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ bool digest_has_error (struct DigestAlgorithm *da) { - mhd_assert (! da->uninitialised); + mhd_assert (!da->uninitialised); mhd_assert (da->algo_selected); switch (da->algo) { case MHD_DIGEST_BASE_ALGO_MD5: -#ifdef MHD_SUPPORT_MD5 +# ifdef MHD_SUPPORT_MD5 return mhd_MD5_has_err (&(da->ctx.md5_ctx)); -#else /* ! MHD_SUPPORT_MD5 */ +# else /* ! MHD_SUPPORT_MD5 */ mhd_UNREACHABLE (); -#endif /* ! MHD_SUPPORT_MD5 */ +# endif /* ! MHD_SUPPORT_MD5 */ break; case MHD_DIGEST_BASE_ALGO_SHA256: -#ifdef MHD_SUPPORT_SHA256 +# ifdef MHD_SUPPORT_SHA256 return mhd_SHA256_has_err (&(da->ctx.sha256_ctx)); -#else /* ! MHD_SUPPORT_SHA256 */ +# else /* ! MHD_SUPPORT_SHA256 */ mhd_UNREACHABLE (); -#endif /* ! MHD_SUPPORT_SHA256 */ +# endif /* ! MHD_SUPPORT_SHA256 */ break; case MHD_DIGEST_BASE_ALGO_SHA512_256: -#ifdef MHD_SUPPORT_SHA512_256 +# ifdef MHD_SUPPORT_SHA512_256 return mhd_SHA512_256_has_err (&(da->ctx.sha512_256_ctx)); -#else /* ! MHD_SUPPORT_SHA512_256 */ +# else /* ! MHD_SUPPORT_SHA512_256 */ mhd_UNREACHABLE (); -#endif /* ! MHD_SUPPORT_SHA512_256 */ +# endif /* ! MHD_SUPPORT_SHA512_256 */ break; case MHD_DIGEST_BASE_ALGO_INVALID: @@ -1971,7 +1971,7 @@ digest_has_error (struct DigestAlgorithm *da) #else /* ! mhd_DIGEST_HAS_EXT_ERROR */ -#define digest_has_error(da) (((void) (da)), ! ! 0) +# define digest_has_error(da) (((void) (da)), ! ! 0) #endif /* ! mhd_DIGEST_HAS_EXT_ERROR */ @@ -2000,9 +2000,9 @@ calc_userdigest (struct DigestAlgorithm *restrict da, const char *restrict password, uint8_t *ha1_bin) { - mhd_assert (! da->uninitialised); + mhd_assert (!da->uninitialised); mhd_assert (da->algo_selected); - mhd_assert (! da->hashing); + mhd_assert (!da->hashing); digest_update (da, username_len, username); digest_update_with_colon (da); digest_update (da, realm_len, realm); @@ -2014,7 +2014,7 @@ calc_userdigest (struct DigestAlgorithm *restrict da, MHD_EXTERN_ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (4) -MHD_FN_PAR_OUT_SIZE_ (6,5) enum MHD_StatusCode +MHD_FN_PAR_OUT_SIZE_ (6, 5) enum MHD_StatusCode MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo algo, const char *MHD_RESTRICT username, const char *MHD_RESTRICT realm, @@ -2024,7 +2024,7 @@ MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo algo, { struct DigestAlgorithm da; enum MHD_StatusCode ret; - if (! digest_init_one_time (&da, get_base_digest_algo (algo))) + if (!digest_init_one_time (&da, get_base_digest_algo (algo))) return MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED; if (digest_get_size (&da) > bin_buf_size) @@ -2037,7 +2037,7 @@ MHD_digest_auth_calc_userdigest (enum MHD_DigestAuthAlgo algo, realm, strlen (realm), password, - (uint8_t *) userdigest_bin); + (uint8_t *)userdigest_bin); ret = digest_has_error (&da) ? MHD_SC_HASH_FAILED : MHD_SC_OK; } digest_deinit (&da); @@ -2068,9 +2068,9 @@ calc_userhash (struct DigestAlgorithm *da, const char *realm, uint8_t *digest_bin) { - mhd_assert (! da->uninitialised); + mhd_assert (!da->uninitialised); mhd_assert (da->algo_selected); - mhd_assert (! da->hashing); + mhd_assert (!da->hashing); digest_update (da, username_len, username); digest_update_with_colon (da); digest_update (da, realm_len, realm); @@ -2080,7 +2080,7 @@ calc_userhash (struct DigestAlgorithm *da, MHD_EXTERN_ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4) enum MHD_StatusCode +MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4) enum MHD_StatusCode MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, const char *MHD_RESTRICT username, const char *MHD_RESTRICT realm, @@ -2090,7 +2090,7 @@ MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, struct DigestAlgorithm da; enum MHD_StatusCode ret; - if (! digest_init_one_time (&da, get_base_digest_algo (algo))) + if (!digest_init_one_time (&da, get_base_digest_algo (algo))) return MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED; if (digest_get_size (&da) > bin_buf_size) ret = MHD_SC_OUT_BUFF_TOO_SMALL; @@ -2101,7 +2101,7 @@ MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, username, strlen (realm), realm, - (uint8_t *) userhash_bin); + (uint8_t *)userhash_bin); ret = digest_has_error (&da) ? MHD_SC_HASH_FAILED : MHD_SC_OK; } @@ -2113,7 +2113,7 @@ MHD_digest_auth_calc_userhash (enum MHD_DigestAuthAlgo algo, MHD_EXTERN_ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5,4) enum MHD_StatusCode +MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_OUT_SIZE_ (5, 4) enum MHD_StatusCode MHD_digest_auth_calc_userhash_hex ( enum MHD_DigestAuthAlgo algo, const char *MHD_RESTRICT username, @@ -2136,9 +2136,9 @@ MHD_digest_auth_calc_userhash_hex ( if (MHD_SC_OK != res) return res; - (void) mhd_bin_to_hex_z (userhash_bin, - digest_size, - userhash_hex); + (void)mhd_bin_to_hex_z (userhash_bin, + digest_size, + userhash_hex); return MHD_SC_OK; } @@ -2210,7 +2210,7 @@ check_nonce_nc (struct MHD_Daemon *restrict d, uint_fast32_t slot_valid_time; enum mhd_CheckNonceNC ret; - mhd_assert (! mhd_D_HAS_MASTER (d)); /* only master daemon should be used */ + mhd_assert (!mhd_D_HAS_MASTER (d)); /* only master daemon should be used */ mhd_assert (0 != noncelen); mhd_assert (0 != nc); if (mhd_AUTH_DIGEST_NONCE_LEN != noncelen) @@ -2249,7 +2249,7 @@ check_nonce_nc (struct MHD_Daemon *restrict d, { /* 'nc' is larger, shift bitmask and bump limit */ const uint_fast32_t jump_size = - (uint_fast32_t) nc - nonce_slot->max_recvd_nc; + (uint_fast32_t)nc - nonce_slot->max_recvd_nc; if (64 > jump_size) { /* small jump, less than mask width */ @@ -2344,7 +2344,7 @@ test_header (void *restrict cls, const struct MHD_String *restrict name, const struct MHD_StringNullable *restrict value) { - struct test_header_param *const param = (struct test_header_param *) cls; + struct test_header_param *const param = (struct test_header_param *)cls; struct MHD_Request *req = param->request; struct mhd_RequestField *pos; size_t i; @@ -2411,10 +2411,10 @@ check_argument_match (struct MHD_Request *restrict req, param.request = req; param.num_get_params = 0; - if (! mhd_parse_uri_args (args_len, - args, - &test_header, - &param)) + if (!mhd_parse_uri_args (args_len, + args, + &test_header, + &param)) return false; /* Check that the number of arguments matches */ @@ -2461,13 +2461,13 @@ check_uri_match (struct MHD_Request *restrict req, return false; uri[uri_len] = 0; - qmark = (char *) memchr (uri, - '?', - uri_len); + qmark = (char *)memchr (uri, + '?', + uri_len); if (NULL != qmark) { *qmark = 0; - url_len = (size_t) (qmark - uri); + url_len = (size_t)(qmark - uri); } else url_len = uri_len; @@ -2478,18 +2478,18 @@ check_uri_match (struct MHD_Request *restrict req, uri, url_len, NULL); - if ((url_len != req->url_len) || - (0 != memcmp (uri, - req->url, - url_len))) + if ((url_len != req->url_len) + || (0 != memcmp (uri, + req->url, + url_len))) return false; args = (NULL != qmark) ? (qmark + 1) : uri + uri_len; - args_len = (size_t) (uri + uri_len - args); + args_len = (size_t)(uri + uri_len - args); - if (! check_argument_match (req, - args_len, - args)) + if (!check_argument_match (req, + args_len, + args)) return false; return true; @@ -2520,8 +2520,8 @@ get_buffer_for_size (char tmp1[mhd_STATIC_UNQ_BUFFER_SIZE], { mhd_assert ((0 == *ptmp2_size) || (NULL != *ptmp2)); mhd_assert ((NULL != *ptmp2) || (0 == *ptmp2_size)); - mhd_assert ((0 == *ptmp2_size) || \ - (mhd_STATIC_UNQ_BUFFER_SIZE < *ptmp2_size)); + mhd_assert ((0 == *ptmp2_size) \ + || (mhd_STATIC_UNQ_BUFFER_SIZE < *ptmp2_size)); if (required_size <= mhd_STATIC_UNQ_BUFFER_SIZE) return tmp1; @@ -2533,7 +2533,7 @@ get_buffer_for_size (char tmp1[mhd_STATIC_UNQ_BUFFER_SIZE], return NULL; if (NULL != *ptmp2) free (*ptmp2); - *ptmp2 = (char *) malloc (required_size); + *ptmp2 = (char *)malloc (required_size); if (NULL == *ptmp2) *ptmp2_size = 0; else @@ -2575,7 +2575,7 @@ get_unquoted_param (const struct mhd_RqDAuthParam *param, mhd_assert (NULL != param->value.cstr); mhd_assert (0 != param->value.len); - if (! param->quoted) + if (!param->quoted) { unquoted->data = param->value.cstr; unquoted->size = param->value.len; @@ -2635,7 +2635,7 @@ get_unquoted_param_copy (const struct mhd_RqDAuthParam *param, return (param->value.len + 1 > mhd_AUTH_DIGEST_MAX_PARAM_SIZE) ? mhd_UNQ_TOO_LARGE : mhd_UNQ_OUT_OF_MEM; - if (! param->quoted) + if (!param->quoted) { memcpy (unquoted->data, param->value.cstr, @@ -2663,7 +2663,7 @@ get_unquoted_param_copy (const struct mhd_RqDAuthParam *param, * false otherwise */ mhd_static_inline MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) bool +MHD_FN_PAR_IN_SIZE_ (3, 2) bool is_param_equal (const struct mhd_RqDAuthParam *restrict param, const size_t str_len, const char *restrict str) @@ -2675,8 +2675,8 @@ is_param_equal (const struct mhd_RqDAuthParam *restrict param, param->value.len, str, str_len); - return (str_len == param->value.len) && - (0 == memcmp (str, param->value.cstr, str_len)); + return (str_len == param->value.len) + && (0 == memcmp (str, param->value.cstr, str_len)); } @@ -2689,7 +2689,7 @@ is_param_equal (const struct mhd_RqDAuthParam *restrict param, * false otherwise */ mhd_static_inline MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) bool +MHD_FN_PAR_IN_SIZE_ (3, 2) bool is_param_equal_caseless (const struct mhd_RqDAuthParam *restrict param, const size_t str_len, const char *restrict str) @@ -2701,8 +2701,8 @@ is_param_equal_caseless (const struct mhd_RqDAuthParam *restrict param, param->value.len, str, str_len); - return (str_len == param->value.len) && - (mhd_str_equal_caseless_bin_n (str, param->value.cstr, str_len)); + return (str_len == param->value.len) + && (mhd_str_equal_caseless_bin_n (str, param->value.cstr, str_len)); } @@ -2806,47 +2806,47 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, /* Get client's algorithm */ c_algo = params->algo; /* Check whether client's algorithm is allowed by function parameter */ - if (((unsigned int) c_algo) != - (((unsigned int) c_algo) & ((unsigned int) malgo))) + if (((unsigned int)c_algo) != + (((unsigned int)c_algo) & ((unsigned int)malgo))) return MHD_DAUTH_WRONG_ALGO; /* Check whether client's algorithm is supported */ - if (0 != (((unsigned int) c_algo) & MHD_DIGEST_AUTH_ALGO_SESSION)) + if (0 != (((unsigned int)c_algo) & MHD_DIGEST_AUTH_ALGO_SESSION)) return MHD_DAUTH_UNSUPPORTED_ALGO; #ifndef MHD_SUPPORT_MD5 - if (0 != (((unsigned int) c_algo) & MHD_DIGEST_BASE_ALGO_MD5)) + if (0 != (((unsigned int)c_algo) & MHD_DIGEST_BASE_ALGO_MD5)) return MHD_DAUTH_UNSUPPORTED_ALGO; #endif /* ! MHD_SUPPORT_MD5 */ #ifndef MHD_SUPPORT_SHA256 - if (0 != (((unsigned int) c_algo) & MHD_DIGEST_BASE_ALGO_SHA256)) + if (0 != (((unsigned int)c_algo) & MHD_DIGEST_BASE_ALGO_SHA256)) return MHD_DAUTH_UNSUPPORTED_ALGO; #endif /* ! MHD_SUPPORT_SHA256 */ #ifndef MHD_SUPPORT_SHA512_256 - if (0 != (((unsigned int) c_algo) & MHD_DIGEST_BASE_ALGO_SHA512_256)) + if (0 != (((unsigned int)c_algo) & MHD_DIGEST_BASE_ALGO_SHA512_256)) return MHD_DAUTH_UNSUPPORTED_ALGO; #endif /* ! MHD_SUPPORT_SHA512_256 */ - if (! digest_init_one_time (da, get_base_digest_algo (c_algo))) + if (!digest_init_one_time (da, get_base_digest_algo (c_algo))) mhd_UNREACHABLE (); /* Check 'mqop' value */ c_qop = params->qop; /* Check whether client's QOP is allowed by function parameter */ - if (((unsigned int) c_qop) != - (((unsigned int) c_qop) & ((unsigned int) mqop))) + if (((unsigned int)c_qop) != + (((unsigned int)c_qop) & ((unsigned int)mqop))) return MHD_DAUTH_WRONG_QOP; - if (0 != (((unsigned int) c_qop) & MHD_DIGEST_AUTH_QOP_AUTH_INT)) + if (0 != (((unsigned int)c_qop) & MHD_DIGEST_AUTH_QOP_AUTH_INT)) return MHD_DAUTH_UNSUPPORTED_QOP; digest_size = digest_get_size (da); /* ** A quick check for presence of all required parameters ** */ - if ((NULL == params->username.value.cstr) && - (NULL == params->username_ext.value.cstr)) + if ((NULL == params->username.value.cstr) + && (NULL == params->username_ext.value.cstr)) return MHD_DAUTH_HEADER_BROKEN; - else if ((NULL != params->username.value.cstr) && - (NULL != params->username_ext.value.cstr)) + else if ((NULL != params->username.value.cstr) + && (NULL != params->username_ext.value.cstr)) return MHD_DAUTH_HEADER_BROKEN; /* Parameters cannot be used together */ - else if ((NULL != params->username_ext.value.cstr) && - (mhd_DAUTH_EXT_PARAM_MIN_LEN > params->username_ext.value.len)) + else if ((NULL != params->username_ext.value.cstr) + && (mhd_DAUTH_EXT_PARAM_MIN_LEN > params->username_ext.value.len)) return MHD_DAUTH_HEADER_BROKEN; /* Broken extended notation */ else if (params->userhash && (NULL == params->username.value.cstr)) return MHD_DAUTH_HEADER_BROKEN; /* Userhash cannot be used with extended notation */ @@ -2857,8 +2857,8 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, if (NULL == params->realm.value.cstr) return MHD_DAUTH_HEADER_BROKEN; - else if (((NULL == userdigest) || params->userhash) && - (mhd_AUTH_DIGEST_MAX_PARAM_SIZE < params->realm.value.len)) + else if (((NULL == userdigest) || params->userhash) + && (mhd_AUTH_DIGEST_MAX_PARAM_SIZE < params->realm.value.len)) return MHD_DAUTH_TOO_LARGE; /* Realm is too large and should be used in hash calculations */ if (MHD_DIGEST_AUTH_QOP_NONE != c_qop) @@ -2913,19 +2913,19 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, /* Check 'realm' */ realm_len = strlen (realm); - if (! is_param_equal (&params->realm, - realm_len, - realm)) + if (!is_param_equal (&params->realm, + realm_len, + realm)) return MHD_DAUTH_WRONG_REALM; /* 'realm' valid */ /* Check 'username' */ username_len = strlen (username); - if (! params->userhash) + if (!params->userhash) { if (NULL != params->username.value.cstr) { /* Username in standard notation */ - if (! is_param_equal (&params->username, username_len, username)) + if (!is_param_equal (&params->username, username_len, username)) return MHD_DAUTH_WRONG_USERNAME; } else @@ -2947,8 +2947,8 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, r_uname, buf_size); if (0 > res) return MHD_DAUTH_HEADER_BROKEN; /* Broken extended notation */ - if ((username_len != (size_t) res) || - (0 != memcmp (username, r_uname, username_len))) + if ((username_len != (size_t)res) + || (0 != memcmp (username, r_uname, username_len))) return MHD_DAUTH_WRONG_USERNAME; } } @@ -2965,7 +2965,7 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, return MHD_DAUTH_ERROR; mhd_assert (sizeof (tmp1) >= (2 * digest_size)); mhd_bin_to_hex (hash1_bin, digest_size, tmp1); - if (! is_param_equal_caseless (&params->username, 2 * digest_size, tmp1)) + if (!is_param_equal_caseless (&params->username, 2 * digest_size, tmp1)) return MHD_DAUTH_WRONG_USERNAME; /* To simplify the logic, the digest is reset here instead of resetting before the next hash calculation. */ @@ -3041,7 +3041,7 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, /* ** Build H(A2) and check URI match in the header and in the request ** */ /* Get 'uri' */ - mhd_assert (! da->hashing); + mhd_assert (!da->hashing); digest_update (da, req->method.len, req->method.cstr); digest_update_with_colon (da); #if 0 @@ -3058,7 +3058,7 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, digest_update_buf (da, &unq_copy); /* The next check will modify copied URI string */ - if (! check_uri_match (req, unq_copy.size, unq_copy.data)) + if (!check_uri_match (req, unq_copy.size, unq_copy.data)) return MHD_DAUTH_WRONG_URI; digest_calc_hash (da, hash2_bin); #ifdef mhd_DIGEST_HAS_EXT_ERROR @@ -3069,7 +3069,7 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, /* ** Build H(A1) ** */ if (NULL == userdigest) { - mhd_assert (! da->hashing); + mhd_assert (!da->hashing); digest_reset (da); calc_userdigest (da, username, username_len, @@ -3086,7 +3086,7 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, /* ** Check 'response' ** */ - mhd_assert (! da->hashing); + mhd_assert (!da->hashing); digest_reset (da); /* Update digest with H(A1) */ mhd_assert (sizeof (tmp1) >= (digest_size * 2)); @@ -3094,7 +3094,7 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, mhd_bin_to_hex (hash1_bin, digest_size, tmp1); else mhd_bin_to_hex (userdigest, digest_size, tmp1); - digest_update (da, digest_size * 2, (const uint8_t *) tmp1); + digest_update (da, digest_size * 2, (const uint8_t *)tmp1); /* H(A1) is not needed anymore, reuse the buffer. * Use hash1_bin for the client's 'response' decoded to binary form. */ @@ -3154,7 +3154,7 @@ digest_auth_check_all_inner (struct MHD_Request *restrict req, } /* Update digest with H(A2) */ mhd_bin_to_hex (hash2_bin, digest_size, tmp1); - digest_update (da, digest_size * 2, (const uint8_t *) tmp1); + digest_update (da, digest_size * 2, (const uint8_t *)tmp1); /* H(A2) is not needed anymore, reuse the buffer. * Use hash2_bin for the calculated response in binary form */ @@ -3298,28 +3298,28 @@ MHD_digest_auth_check_digest (struct MHD_Request *MHD_RESTRICT request, enum MHD_DigestAuthMultiQOP mqop, enum MHD_DigestAuthMultiAlgo malgo) { - if (1 != (((0 != (((unsigned int) malgo) \ + if (1 != (((0 != (((unsigned int)malgo) \ & MHD_DIGEST_BASE_ALGO_MD5)) ? 1 : 0) - + ((0 != (((unsigned int) malgo) \ + + ((0 != (((unsigned int)malgo) \ & MHD_DIGEST_BASE_ALGO_SHA256)) ? 1 : 0) - + ((0 != (((unsigned int) malgo) \ + + ((0 != (((unsigned int)malgo) \ & MHD_DIGEST_BASE_ALGO_SHA512_256)) ? 1 : 0))) return MHD_DAUTH_UNSUPPORTED_ALGO; #ifndef MHD_SUPPORT_MD5 - if (0 != (((unsigned int) malgo) & MHD_DIGEST_BASE_ALGO_MD5)) + if (0 != (((unsigned int)malgo) & MHD_DIGEST_BASE_ALGO_MD5)) return MHD_DAUTH_UNSUPPORTED_ALGO; #endif /* ! MHD_SUPPORT_MD5 */ #ifndef MHD_SUPPORT_SHA256 - if (0 != (((unsigned int) malgo) & MHD_DIGEST_BASE_ALGO_SHA256)) + if (0 != (((unsigned int)malgo) & MHD_DIGEST_BASE_ALGO_SHA256)) return MHD_DAUTH_UNSUPPORTED_ALGO; #endif /* ! MHD_SUPPORT_SHA256 */ #ifndef MHD_SUPPORT_SHA512_256 - if (0 != (((unsigned int) malgo) & MHD_DIGEST_BASE_ALGO_SHA512_256)) + if (0 != (((unsigned int)malgo) & MHD_DIGEST_BASE_ALGO_SHA512_256)) return MHD_DAUTH_UNSUPPORTED_ALGO; #endif /* ! MHD_SUPPORT_SHA512_256 */ - if (digest_get_hash_size ((enum MHD_DigestAuthAlgo) malgo) != + if (digest_get_hash_size ((enum MHD_DigestAuthAlgo)malgo) != userdigest_size) return MHD_DAUTH_INVALID_USERDIGEST_SIZE; @@ -3327,7 +3327,7 @@ MHD_digest_auth_check_digest (struct MHD_Request *MHD_RESTRICT request, realm, username, NULL, - (const uint8_t *) userdigest, + (const uint8_t *)userdigest, max_nc, mqop, malgo); diff --git a/src/mhd2/auth_digest.h b/src/mhd2/auth_digest.h @@ -47,8 +47,8 @@ #include "mhd_sys_options.h" -#if ! defined(MHD_SUPPORT_AUTH_DIGEST) -#error Digest Authorization must be enabled +#if !defined(MHD_SUPPORT_AUTH_DIGEST) +# error Digest Authorization must be enabled #endif #include "sys_bool_type.h" diff --git a/src/mhd2/compat_calloc.c b/src/mhd2/compat_calloc.c @@ -46,31 +46,31 @@ #include "compat_calloc.h" #ifndef HAVE_CALLOC -#include <string.h> /* for memset() */ -#include "sys_malloc.h" +# include <string.h> /* for memset() */ +# include "sys_malloc.h" -#ifdef __has_builtin -# if __has_builtin (__builtin_mul_overflow) +# ifdef __has_builtin +# if __has_builtin (__builtin_mul_overflow) +# define MHD_HAVE_MUL_OVERFLOW 1 +# endif +# elif defined(__GNUC__) && __GNUC__ + 0 >= 5 # define MHD_HAVE_MUL_OVERFLOW 1 -# endif -#elif defined(__GNUC__) && __GNUC__ + 0 >= 5 -# define MHD_HAVE_MUL_OVERFLOW 1 -#endif /* __GNUC__ >= 5 */ +# endif /* __GNUC__ >= 5 */ MHD_INTERNAL void * mhd_calloc (size_t nelem, size_t elsize) { size_t alloc_size; void *ptr; -#ifdef MHD_HAVE_MUL_OVERFLOW +# ifdef MHD_HAVE_MUL_OVERFLOW if (__builtin_mul_overflow (nelem, elsize, &alloc_size) || (0 == alloc_size)) return NULL; -#else /* ! MHD_HAVE_MUL_OVERFLOW */ +# else /* ! MHD_HAVE_MUL_OVERFLOW */ alloc_size = nelem * elsize; if ((0 == alloc_size) || (elsize != alloc_size / nelem)) return NULL; -#endif /* ! MHD_HAVE_MUL_OVERFLOW */ +# endif /* ! MHD_HAVE_MUL_OVERFLOW */ ptr = malloc (alloc_size); if (NULL == ptr) return NULL; diff --git a/src/mhd2/conn_data_process.c b/src/mhd2/conn_data_process.c @@ -99,11 +99,11 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c) data_processed = false; - mhd_assert (! c->suspended); + mhd_assert (!c->suspended); if (c->resuming) { /* Fully resume the connection + call app callbacks for the data */ - if (! mhd_conn_process_data (c)) + if (!mhd_conn_process_data (c)) return false; data_processed = true; @@ -111,7 +111,7 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c) if (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err) { - if (! mhd_conn_process_data (c)) + if (!mhd_conn_process_data (c)) return false; } @@ -133,8 +133,8 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c) sending (therefore "send-ready" was explicitly checked by sockets polling call). */ send_ready_state_known = - ((mhd_D_HAS_EDGE_TRIGG (c->daemon)) || - (0 != (MHD_EVENT_LOOP_INFO_SEND & c->event_loop_info))); + ((mhd_D_HAS_EDGE_TRIGG (c->daemon)) + || (0 != (MHD_EVENT_LOOP_INFO_SEND & c->event_loop_info))); has_sock_err = (0 != (mhd_SOCKET_NET_STATE_ERROR_READY & c->sk.ready)); mhd_assert (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err); @@ -144,17 +144,17 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c) bool use_recv; use_recv = (0 != (mhd_SOCKET_NET_STATE_RECV_READY & (c->sk.ready | mhd_C_HAS_TLS_DATA_IN (c)))); - use_recv = use_recv || - (has_sock_err && c->sk.props.is_nonblck); + use_recv = use_recv + || (has_sock_err && c->sk.props.is_nonblck); if (use_recv) { mhd_conn_data_recv (c, has_sock_err); - mhd_assert (! has_sock_err || - (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err)); - if (! mhd_C_IS_HTTP2 (c)) + mhd_assert (!has_sock_err + || (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err)); + if (!mhd_C_IS_HTTP2 (c)) { - if (! mhd_conn_process_data (c)) + if (!mhd_conn_process_data (c)) return false; data_processed = true; mhd_ASSUME (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err); @@ -178,23 +178,23 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c) /* Do not try to send if connection is broken when receiving */ use_send = use_send && (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err); - if (! mhd_C_IS_HTTP2 (c)) + if (!mhd_C_IS_HTTP2 (c)) { - use_send = use_send || - (data_processed && (! send_ready_state_known) - && c->sk.props.is_nonblck); - use_send = use_send || - (has_sock_err && c->sk.props.is_nonblck); + use_send = use_send + || (data_processed && (!send_ready_state_known) + && c->sk.props.is_nonblck); + use_send = use_send + || (has_sock_err && c->sk.props.is_nonblck); } if (use_send) { mhd_conn_data_send (c); - mhd_assert (! has_sock_err || - (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err)); - if (! mhd_C_IS_HTTP2 (c)) + mhd_assert (!has_sock_err + || (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err)); + if (!mhd_C_IS_HTTP2 (c)) { - if (! mhd_conn_process_data (c)) + if (!mhd_conn_process_data (c)) return false; data_processed = true; mhd_ASSUME (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err); @@ -203,16 +203,16 @@ mhd_conn_process_recv_send_data (struct MHD_Connection *restrict c) } if (mhd_SCKT_NET_ST_HAS_FLAG (c->sk.ready, - mhd_SOCKET_NET_STATE_ERROR_READY) && - (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err)) + mhd_SOCKET_NET_STATE_ERROR_READY) + && (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err)) { c->sk.state.discnt_err = mhd_socket_error_get_from_socket (c->sk.fd); mhd_ASSUME (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err); } - if (! data_processed || - mhd_C_IS_HTTP2 (c) || - (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err)) + if (!data_processed + || mhd_C_IS_HTTP2 (c) + || (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err)) return mhd_conn_process_data (c); return true; diff --git a/src/mhd2/conn_data_recv.c b/src/mhd2/conn_data_recv.c @@ -72,10 +72,10 @@ mhd_conn_data_recv (struct MHD_Connection *c, mhd_assert (mhd_HTTP_STAGE_CLOSED != c->stage); mhd_assert (NULL != c->read_buffer); mhd_assert (c->read_buffer_size > c->read_buffer_offset); - mhd_assert (! has_err || \ - (0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY))); - mhd_assert ((0 == (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY)) || \ - has_err); + mhd_assert (!has_err \ + || (0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY))); + mhd_assert ((0 == (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY)) \ + || has_err); mhd_assert (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err); buf = c->read_buffer + c->read_buffer_offset; @@ -83,7 +83,7 @@ mhd_conn_data_recv (struct MHD_Connection *c, res = mhd_recv (c, buf_size, - (char *) buf, + (char *)buf, &received); if ((mhd_SOCKET_ERR_NO_ERROR != res) || has_err) @@ -98,13 +98,13 @@ mhd_conn_data_recv (struct MHD_Connection *c, if (has_err && (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err)) { /* Try to get the real error from the socket */ - if (! mhd_SOCKET_ERR_IS_HARD (res) && c->sk.props.is_nonblck) + if (!mhd_SOCKET_ERR_IS_HARD (res) && c->sk.props.is_nonblck) { /* Re-try the last time with direct socket recv() to detect the error */ uint_fast64_t dummy_buf; res = mhd_sckt_recv (&(c->sk), sizeof(dummy_buf), - (char *) &dummy_buf, + (char *)&dummy_buf, &received); } if (mhd_SOCKET_ERR_IS_HARD (res)) @@ -137,13 +137,13 @@ if ((bytes_read < 0) || socket_error) { if (MHD_ERR_CONNRESET_ == bytes_read) { - if ( (mhd_HTTP_STAGE_INIT < c->stage) && - (mhd_HTTP_STAGE_FULL_REQ_RECEIVED > c->stage) ) + if ((mhd_HTTP_STAGE_INIT < c->stage) + && (mhd_HTTP_STAGE_FULL_REQ_RECEIVED > c->stage)) { -#ifdef HAVE_MESSAGES +# ifdef HAVE_MESSAGES MHD_DLOG (c->daemon, _ ("Socket has been disconnected when reading request.\n")); -#endif +# endif c->discard_request = true; } MHD_connection_close_ (c, @@ -151,31 +151,31 @@ if ((bytes_read < 0) || socket_error) return; } -#ifdef HAVE_MESSAGES +# ifdef HAVE_MESSAGES if (mhd_HTTP_STAGE_INIT != c->stage) MHD_DLOG (c->daemon, _ ("Connection socket is closed when reading " \ "request due to the error: %s\n"), (bytes_read < 0) ? str_conn_error_ (bytes_read) : "detected c closure"); -#endif +# endif CONNECTION_CLOSE_ERROR (c, NULL); return; } -#if 0 // TODO: handle remote shut WR +# if 0 // TODO: handle remote shut WR if (0 == bytes_read) { /* Remote side closed c. */ // FIXME: Actually NOT! c->sk.state.rmt_shut_wr = true; - if ( (mhd_HTTP_STAGE_INIT < c->stage) && - (mhd_HTTP_STAGE_FULL_REQ_RECEIVED > c->stage) ) + if ((mhd_HTTP_STAGE_INIT < c->stage) + && (mhd_HTTP_STAGE_FULL_REQ_RECEIVED > c->stage)) { -#ifdef HAVE_MESSAGES +# ifdef HAVE_MESSAGES MHD_DLOG (c->daemon, _ ("Connection was closed by remote side with incomplete " "request.\n")); -#endif +# endif c->discard_request = true; MHD_connection_close_ (c, MHD_REQUEST_TERMINATED_CLIENT_ABORT); @@ -190,5 +190,5 @@ if (0 == bytes_read) MHD_REQUEST_TERMINATED_WITH_ERROR); return; } -#endif +# endif #endif diff --git a/src/mhd2/conn_data_send.c b/src/mhd2/conn_data_send.c @@ -82,10 +82,10 @@ check_write_done (struct MHD_Connection *restrict connection, enum mhd_HttpStage next_stage) { // TODO: integrate into states processing - if ( (connection->write_buffer_append_offset != - connection->write_buffer_send_offset) - /* || data_in_tls_buffers == true */ - ) + if ((connection->write_buffer_append_offset != + connection->write_buffer_send_offset) + /* || data_in_tls_buffers == true */ + ) return false; connection->write_buffer_append_offset = 0; connection->write_buffer_send_offset = 0; @@ -150,25 +150,25 @@ mhd_conn_data_send (struct MHD_Connection *c) mhd_assert (c->write_buffer_append_offset >= \ c->write_buffer_send_offset); mhd_assert (NULL != resp); - mhd_assert ((mhd_CONN_MUST_UPGRADE != c->conn_reuse) || \ - (! c->rp.props.send_reply_body)); + mhd_assert ((mhd_CONN_MUST_UPGRADE != c->conn_reuse) \ + || (!c->rp.props.send_reply_body)); // TODO: support body generating alongside with header sending - if ((c->rp.props.send_reply_body) && - (mhd_REPLY_CNTN_LOC_RESP_BUF == c->rp.cntn_loc)) + if ((c->rp.props.send_reply_body) + && (mhd_REPLY_CNTN_LOC_RESP_BUF == c->rp.cntn_loc)) { /* Send response headers alongside the response body, if the body * data is available. */ bool complete_response = true; - size_t body_size = (size_t) resp->cntn_size; + size_t body_size = (size_t)resp->cntn_size; mhd_assert (mhd_RESPONSE_CONTENT_DATA_BUFFER == resp->cntn_dtype); - mhd_assert (! c->rp.props.chunked); + mhd_assert (!c->rp.props.chunked); mhd_assert (MHD_SIZE_UNKNOWN != resp->cntn_size); if (resp->cntn_size != body_size) { - body_size = (size_t) ~((size_t) 0); + body_size = (size_t)~((size_t)0); complete_response = false; } @@ -178,7 +178,7 @@ mhd_conn_data_send (struct MHD_Connection *c) + c->write_buffer_send_offset, false, body_size, - (const char *) resp->cntn.buf, + (const char *)resp->cntn.buf, complete_response, &sent); } @@ -194,8 +194,8 @@ mhd_conn_data_send (struct MHD_Connection *c) false, 0, NULL, - ((0 == resp->cntn_size) || - (! c->rp.props.send_reply_body)), + ((0 == resp->cntn_size) + || (!c->rp.props.send_reply_body)), &sent); } if (mhd_SOCKET_ERR_NO_ERROR == res) @@ -207,7 +207,7 @@ mhd_conn_data_send (struct MHD_Connection *c) /* The complete header and some response data have been sent, * update both offsets. */ mhd_assert (0 == c->rp.rsp_cntn_read_pos); - mhd_assert (! c->rp.props.chunked); + mhd_assert (!c->rp.props.chunked); mhd_assert (c->rp.props.send_reply_body); mhd_assert (MHD_SIZE_UNKNOWN != resp->cntn_size); c->stage = mhd_HTTP_STAGE_UNCHUNKED_BODY_READY; @@ -233,14 +233,14 @@ mhd_conn_data_send (struct MHD_Connection *c) struct MHD_Response *const restrict resp = c->rp.response; mhd_assert (c->rp.props.send_reply_body); mhd_assert (c->rp.rsp_cntn_read_pos <= resp->cntn_size); - mhd_assert ((mhd_HTTP_STAGE_CHUNKED_BODY_READY != c->stage) || \ - (mhd_REPLY_CNTN_LOC_CONN_BUF == c->rp.cntn_loc)); + mhd_assert ((mhd_HTTP_STAGE_CHUNKED_BODY_READY != c->stage) \ + || (mhd_REPLY_CNTN_LOC_CONN_BUF == c->rp.cntn_loc)); if (mhd_REPLY_CNTN_LOC_RESP_BUF == c->rp.cntn_loc) { bool complete_response = true; const uint_fast64_t send_left = resp->cntn_size - c->rp.rsp_cntn_read_pos; - size_t send_size = (size_t) send_left; + size_t send_size = (size_t)send_left; mhd_assert (MHD_SIZE_UNKNOWN != resp->cntn_size); mhd_assert (mhd_HTTP_STAGE_UNCHUNKED_BODY_READY == c->stage); @@ -249,19 +249,19 @@ mhd_conn_data_send (struct MHD_Connection *c) if (send_left != send_size) { - send_size = (size_t) ~((size_t) 0); + send_size = (size_t)~((size_t)0); complete_response = false; mhd_assert (send_left >= send_size); } res = mhd_send_data (c, send_size, - (const char *) resp->cntn.buf + (const char *)resp->cntn.buf + c->rp.rsp_cntn_read_pos, complete_response, &sent); - mhd_assert ((mhd_SOCKET_ERR_NO_ERROR != res) || - sent <= send_size); + mhd_assert ((mhd_SOCKET_ERR_NO_ERROR != res) + || sent <= send_size); } else if (mhd_REPLY_CNTN_LOC_CONN_BUF == c->rp.cntn_loc) { @@ -274,9 +274,9 @@ mhd_conn_data_send (struct MHD_Connection *c) c->write_buffer + c->write_buffer_send_offset, true, &sent); - mhd_assert ((mhd_SOCKET_ERR_NO_ERROR != res) || \ - sent <= (c->write_buffer_append_offset \ - - c->write_buffer_send_offset)); + mhd_assert ((mhd_SOCKET_ERR_NO_ERROR != res) \ + || sent <= (c->write_buffer_append_offset \ + - c->write_buffer_send_offset)); } else if (mhd_REPLY_CNTN_LOC_IOV == c->rp.cntn_loc) { @@ -295,9 +295,9 @@ mhd_conn_data_send (struct MHD_Connection *c) res = mhd_send_sendfile (c, &sent); if (mhd_SOCKET_ERR_INTR == res) { - if (! c->rp.response->cntn.file.use_sf) + if (!c->rp.response->cntn.file.use_sf) { /* Switch to filereader */ - mhd_assert (! c->rp.props.chunked); + mhd_assert (!c->rp.props.chunked); c->rp.cntn_loc = mhd_REPLY_CNTN_LOC_CONN_BUF; c->stage = mhd_HTTP_STAGE_UNCHUNKED_BODY_UNREADY; } @@ -415,13 +415,13 @@ mhd_conn_data_send (struct MHD_Connection *c) if (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err) c->sk.state.discnt_err = res; c->sk.ready = - (enum mhd_SocketNetState) (((unsigned int) c->sk.ready) - | mhd_SOCKET_NET_STATE_ERROR_READY); + (enum mhd_SocketNetState)(((unsigned int)c->sk.ready) + | mhd_SOCKET_NET_STATE_ERROR_READY); } if (mhd_SCKT_NET_ST_HAS_FLAG (c->sk.ready, - mhd_SOCKET_NET_STATE_ERROR_READY) && - (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err)) + mhd_SOCKET_NET_STATE_ERROR_READY) + && (mhd_SOCKET_ERR_NO_ERROR == c->sk.state.discnt_err)) { c->sk.state.discnt_err = mhd_socket_error_get_from_socket (c->sk.fd); mhd_assert (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err); diff --git a/src/mhd2/conn_get_info.c b/src/mhd2/conn_get_info.c @@ -81,7 +81,7 @@ MHD_connection_get_info_fixed_sz ( return MHD_SC_INFO_GET_BUFF_TOO_SMALL; output_buf->v_client_address_sa_info.sa_size = connection->sk.addr.size; output_buf->v_client_address_sa_info.sa = - (const struct sockaddr*) connection->sk.addr.data; + (const struct sockaddr *)connection->sk.addr.data; return MHD_SC_OK; case MHD_CONNECTION_INFO_FIXED_CONNECTION_SOCKET: if (sizeof(output_buf->v_connection_socket) > output_buf_size) @@ -142,8 +142,8 @@ MHD_connection_get_info_dynamic_sz ( return MHD_SC_OK; case MHD_CONNECTION_INFO_DYNAMIC_TLS_VER: #ifdef MHD_SUPPORT_HTTPS - if ((mhd_CONN_STATE_TCP_CONNECTED != connection->conn_state) && - (mhd_CONN_STATE_TLS_CONNECTED != connection->conn_state)) + if ((mhd_CONN_STATE_TCP_CONNECTED != connection->conn_state) + && (mhd_CONN_STATE_TLS_CONNECTED != connection->conn_state)) { if (mhd_CONN_FLAG_CLOSING > connection->conn_state) return MHD_SC_TOO_EARLY; @@ -153,14 +153,14 @@ MHD_connection_get_info_dynamic_sz ( #endif if (sizeof(output_buf->v_tls_ver) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - if (! mhd_C_HAS_TLS (connection)) + if (!mhd_C_HAS_TLS (connection)) output_buf->v_tls_ver = MHD_TLS_VERSION_NO_TLS; else { #ifdef MHD_SUPPORT_HTTPS struct mhd_StctTlsVersion stct_tls_ver; - if (! mhd_tls_conn_get_tls_ver (connection->tls, \ - &stct_tls_ver)) + if (!mhd_tls_conn_get_tls_ver (connection->tls, \ + &stct_tls_ver)) return MHD_SC_INFO_GET_TYPE_UNOBTAINABLE; output_buf->v_tls_ver = stct_tls_ver.tls_ver; #else /* ! MHD_SUPPORT_HTTPS */ @@ -169,7 +169,7 @@ MHD_connection_get_info_dynamic_sz ( } return MHD_SC_OK; case MHD_CONNECTION_INFO_DYNAMIC_TLS_SESSION: - if (! mhd_C_HAS_TLS (connection)) + if (!mhd_C_HAS_TLS (connection)) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; if (sizeof(output_buf->v_tls_session) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; diff --git a/src/mhd2/conn_mark_ready.h b/src/mhd2/conn_mark_ready.h @@ -69,9 +69,9 @@ mhd_conn_mark_ready (struct MHD_Connection *restrict c, mhd_assert (d == c->daemon); if (c->in_proc_ready) { - mhd_assert ((NULL != mhd_DLINKEDL_GET_NEXT (c, proc_ready)) || \ - (NULL != mhd_DLINKEDL_GET_PREV (c, proc_ready)) || \ - (c == mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready))); + mhd_assert ((NULL != mhd_DLINKEDL_GET_NEXT (c, proc_ready)) \ + || (NULL != mhd_DLINKEDL_GET_PREV (c, proc_ready)) \ + || (c == mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready))); return; /* Already marked and in the list */ } mhd_assert (NULL == mhd_DLINKEDL_GET_NEXT (c, proc_ready)); @@ -95,7 +95,7 @@ mhd_conn_mark_unready (struct MHD_Connection *restrict c, struct MHD_Daemon *restrict d) { mhd_assert (d == c->daemon); - if (! c->in_proc_ready) + if (!c->in_proc_ready) { mhd_assert (NULL == mhd_DLINKEDL_GET_NEXT (c, proc_ready)); mhd_assert (NULL == mhd_DLINKEDL_GET_PREV (c, proc_ready)); @@ -103,9 +103,9 @@ mhd_conn_mark_unready (struct MHD_Connection *restrict c, mhd_assert (c != mhd_DLINKEDL_GET_LAST (&(d->events), proc_ready)); return; /* Already unmarked and not in the list */ } - mhd_assert ((NULL != mhd_DLINKEDL_GET_NEXT (c, proc_ready)) || \ - (NULL != mhd_DLINKEDL_GET_PREV (c, proc_ready)) || \ - (c == mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready))); + mhd_assert ((NULL != mhd_DLINKEDL_GET_NEXT (c, proc_ready)) \ + || (NULL != mhd_DLINKEDL_GET_PREV (c, proc_ready)) \ + || (c == mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready))); mhd_DLINKEDL_DEL (&(d->events), c, proc_ready); c->in_proc_ready = false; @@ -124,11 +124,11 @@ mhd_conn_mark_ready_update3 (struct MHD_Connection *restrict c, bool force_ready, struct MHD_Daemon *restrict d) { - if (force_ready || - (0 != - ((((unsigned int) c->sk.ready) | mhd_C_HAS_TLS_DATA_IN (c)) - & ((unsigned int) c->event_loop_info) - & (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND)))) + if (force_ready + || (0 != + ((((unsigned int)c->sk.ready) | mhd_C_HAS_TLS_DATA_IN (c)) + & ((unsigned int)c->event_loop_info) + & (MHD_EVENT_LOOP_INFO_RECV | MHD_EVENT_LOOP_INFO_SEND)))) mhd_conn_mark_ready (c, d); else mhd_conn_mark_unready (c, d); diff --git a/src/mhd2/conn_timeout.c b/src/mhd2/conn_timeout.c @@ -64,15 +64,15 @@ mhd_conn_get_timeout_left (const struct MHD_Connection *restrict c, uint_fast64_t cur_milsec) { mhd_constexpr uint_fast64_t uifast64_hibit = - (uint_fast64_t) (~(((uint_fast64_t) (~((uint_fast64_t) 0))) >> 1u)); + (uint_fast64_t)(~(((uint_fast64_t)(~((uint_fast64_t)0))) >> 1u)); const uint_fast64_t timeout = c->timeout.milsec; uint_fast64_t timedout_time; uint_fast64_t timeout_left; - mhd_assert (! c->suspended); + mhd_assert (!c->suspended); if (0u == timeout) - return (uint_fast64_t) 0xFFFFFFFFFFFFFFFFu; + return (uint_fast64_t)0xFFFFFFFFFFFFFFFFu; /* The logic used in these calculations allows values wrap over the maximum value (taking into account that maximum timeout time is limited) */ @@ -85,9 +85,9 @@ mhd_conn_get_timeout_left (const struct MHD_Connection *restrict c, { /* "Timeout left" must be always less or equal the timeout value (plus one) unless the system clock jumped back. */ - mhd_assert ((timeout_left <= (c->timeout.milsec + 1u)) || - ((cur_milsec - c->timeout.last_act) - > (c->timeout.last_act - cur_milsec))); + mhd_assert ((timeout_left <= (c->timeout.milsec + 1u)) + || ((cur_milsec - c->timeout.last_act) + > (c->timeout.last_act - cur_milsec))); return timeout_left; } @@ -113,11 +113,11 @@ mhd_conn_init_activity_timeout (struct MHD_Connection *restrict c, struct MHD_Daemon *const restrict d = c->daemon; #if defined(MHD_SUPPORT_THREADS) - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); #endif /* MHD_SUPPORT_THREADS */ - mhd_assert (! c->suspended); - mhd_assert (! c->timeout.in_cstm_tmout_list); + mhd_assert (!c->suspended); + mhd_assert (!c->timeout.in_cstm_tmout_list); c->timeout.milsec = timeout; @@ -152,22 +152,22 @@ mhd_conn_deinit_activity_timeout (struct MHD_Connection *restrict c) struct MHD_Daemon *const restrict d = c->daemon; #if defined(MHD_SUPPORT_THREADS) - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); #endif /* MHD_SUPPORT_THREADS */ if (0u == c->timeout.milsec) { - mhd_assert (! c->timeout.in_cstm_tmout_list); + mhd_assert (!c->timeout.in_cstm_tmout_list); return; } if (mhd_D_HAS_THR_PER_CONN (d)) { - mhd_assert (! c->timeout.in_cstm_tmout_list); + mhd_assert (!c->timeout.in_cstm_tmout_list); return; } - if (! c->timeout.in_cstm_tmout_list) + if (!c->timeout.in_cstm_tmout_list) mhd_DLINKEDL_DEL_D (&(d->conns.def_timeout), c, timeout.tmout_list); @@ -187,14 +187,14 @@ mhd_conn_update_activity_mark (struct MHD_Connection *restrict c) uint_fast64_t prev_mark; #if defined(MHD_SUPPORT_THREADS) - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); #endif /* MHD_SUPPORT_THREADS */ - mhd_assert (! c->suspended); + mhd_assert (!c->suspended); if (0u == c->timeout.milsec) { - mhd_assert (! c->timeout.in_cstm_tmout_list); + mhd_assert (!c->timeout.in_cstm_tmout_list); return; } @@ -206,7 +206,7 @@ mhd_conn_update_activity_mark (struct MHD_Connection *restrict c) if (mhd_D_HAS_THR_PER_CONN (d)) { - mhd_assert (! c->timeout.in_cstm_tmout_list); + mhd_assert (!c->timeout.in_cstm_tmout_list); return; /* each connection has personal timeout */ } diff --git a/src/mhd2/conn_tls_check.c b/src/mhd2/conn_tls_check.c @@ -67,9 +67,9 @@ mhd_conn_tls_check (struct MHD_Connection *restrict c) { mhd_assert (mhd_C_HAS_TLS (c)); mhd_assert (mhd_D_HAS_TLS (c->daemon)); - mhd_assert ((mhd_CONN_STATE_TLS_HANDSHAKE_RECV == c->conn_state) || \ - (mhd_CONN_STATE_TLS_HANDSHAKE_SEND == c->conn_state) || \ - (mhd_CONN_STATE_TLS_CONNECTED == c->conn_state)); + mhd_assert ((mhd_CONN_STATE_TLS_HANDSHAKE_RECV == c->conn_state) \ + || (mhd_CONN_STATE_TLS_HANDSHAKE_SEND == c->conn_state) \ + || (mhd_CONN_STATE_TLS_CONNECTED == c->conn_state)); if (mhd_CONN_STATE_TLS_CONNECTED == c->conn_state) return mhd_COMM_LAYER_OK; /* TLS is already connected */ @@ -84,20 +84,20 @@ mhd_conn_tls_check (struct MHD_Connection *restrict c) } /* Check whether the socket is ready for the required send/recv operation */ if (0 == (((mhd_CONN_FLAG_RECV | mhd_CONN_FLAG_SEND) - & ((unsigned int) c->conn_state) - & ((unsigned int) c->sk.ready)))) + & ((unsigned int)c->conn_state) + & ((unsigned int)c->sk.ready)))) return mhd_COMM_LAYER_PROCESSING; switch (mhd_tls_conn_handshake (c->tls)) { case mhd_TLS_PROCED_SUCCESS: c->conn_state = mhd_CONN_STATE_TLS_CONNECTED; - if (! c->sk.props.is_nonblck) + if (!c->sk.props.is_nonblck) { /* The socket is blocking (and polling is not edge-triggering), probably all available data has been processed already. */ c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' and 'send-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY) & (~(enum mhd_SocketNetState) @@ -113,7 +113,7 @@ mhd_conn_tls_check (struct MHD_Connection *restrict c) break; case mhd_TLS_PROCED_RECV_MORE_NEEDED: c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_RECV_READY)); mhd_FALLTHROUGH; @@ -124,7 +124,7 @@ mhd_conn_tls_check (struct MHD_Connection *restrict c) break; case mhd_TLS_PROCED_SEND_MORE_NEEDED: c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); mhd_FALLTHROUGH; diff --git a/src/mhd2/daemon_add_conn.c b/src/mhd2/daemon_add_conn.c @@ -151,9 +151,9 @@ connection_set_initial_state (struct MHD_Connection *restrict c) #ifndef HAVE_NULL_PTR_ALL_ZEROS // TODO: move request reset to special function mhd_DLINKEDL_INIT_LIST (&(c->rq), fields); -#ifdef MHD_SUPPORT_POST_PARSER +# ifdef MHD_SUPPORT_POST_PARSER mhd_DLINKEDL_INIT_LIST (&(c->rq), post_fields); -#endif /* MHD_SUPPORT_POST_PARSER */ +# endif /* MHD_SUPPORT_POST_PARSER */ c->rq.version = NULL; c->rq.url = NULL; c->rq.field_lines.start = NULL; @@ -177,9 +177,9 @@ connection_set_initial_state (struct MHD_Connection *restrict c) c->read_buffer_offset = 0; read_buf_size = c->daemon->conns.cfg.mem_pool_size / 2; c->read_buffer - = (char *) mhd_pool_allocate (c->pool, - read_buf_size, - false); + = (char *)mhd_pool_allocate (c->pool, + read_buf_size, + false); c->read_buffer_size = read_buf_size; } @@ -189,7 +189,7 @@ notify_app_conn (struct MHD_Daemon *restrict daemon, struct MHD_Connection *restrict connection, bool closed) { - (void) daemon, (void) connection, (void) closed; + (void)daemon, (void)connection, (void)closed; // TODO: implement } @@ -218,7 +218,7 @@ notify_app_conn (struct MHD_Daemon *restrict daemon, * error on failure (the @a client_socket is closed) */ static MHD_FN_MUST_CHECK_RESULT_ -MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_INOUT_SIZE_ (4,3) +MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_INOUT_SIZE_ (4, 3) MHD_FN_PAR_NONNULL_ (9) MHD_FN_PAR_OUT_ (9) enum MHD_StatusCode new_connection_prepare_ (struct MHD_Daemon *restrict daemon, MHD_Socket client_socket, @@ -270,7 +270,7 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, #endif /* ! HAVE_NULL_PTR_ALL_ZEROS */ #ifdef MHD_SUPPORT_HTTPS if (0 != tls_data_size) - c->tls = (struct mhd_TlsConnData *) (c + 1); + c->tls = (struct mhd_TlsConnData *)(c + 1); # ifndef HAVE_NULL_PTR_ALL_ZEROS else c->tls = NULL; @@ -281,7 +281,7 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, mhd_h2_blank_init (c); #endif /* MHD_SUPPORT_HTTP2 */ - if (! external_add) + if (!external_add) { c->sk.state.corked = mhd_T_NO; c->sk.state.nodelay = mhd_T_NO; @@ -294,9 +294,9 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, if ((0 < addrlen)) { - if (! external_add) + if (!external_add) { - c->sk.addr.data = (struct sockaddr_storage *) malloc (addrlen); + c->sk.addr.data = (struct sockaddr_storage *)malloc (addrlen); if (NULL == c->sk.addr.data) { mhd_LOG_MSG (daemon, \ @@ -320,7 +320,7 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, c->sk.addr.data = addr; c->sk.addr.size = addrlen; #ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN - c->sk.addr.data->ss_len = (uint8_t) addrlen; + c->sk.addr.data->ss_len = (uint8_t)addrlen; #endif /* HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ addr = NULL; } @@ -346,9 +346,9 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, #ifdef MHD_SUPPORT_HTTPS if (0 != tls_data_size) { - if (! mhd_tls_conn_init (daemon->tls, - &(c->sk), - c->tls)) + if (!mhd_tls_conn_init (daemon->tls, + &(c->sk), + c->tls)) { mhd_LOG_MSG (daemon, \ MHD_SC_TLS_CONNECTION_INIT_FAILED, \ @@ -359,9 +359,9 @@ new_connection_prepare_ (struct MHD_Daemon *restrict daemon, else { c->conn_state = mhd_CONN_STATE_TLS_HANDSHAKE_RECV; -#ifndef NDEBUG +# ifndef NDEBUG c->dbg.tls_inited = true; -#endif +# endif } } #endif /* MHD_SUPPORT_HTTPS */ @@ -425,7 +425,7 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon, { /* 'pool' creation succeed */ - mhd_assert (! daemon->conns.block_new); + mhd_assert (!daemon->conns.block_new); mhd_assert (daemon->conns.count < daemon->conns.cfg.count_limit); daemon->conns.count++; @@ -444,15 +444,15 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon, #ifdef MHD_SUPPORT_THREADS if (mhd_DAEMON_TYPE_LISTEN_ONLY == daemon->threading.d_type) { - mhd_assert ((mhd_POLL_TYPE_SELECT == daemon->events.poll_type) || \ - (mhd_POLL_TYPE_POLL == daemon->events.poll_type)); - if (! mhd_create_named_thread (&connection->tid, - "MHD-connection", - daemon->threading.cfg.stack_size, - &mhd_worker_connection, - connection)) + mhd_assert ((mhd_POLL_TYPE_SELECT == daemon->events.poll_type) \ + || (mhd_POLL_TYPE_POLL == daemon->events.poll_type)); + if (!mhd_create_named_thread (&connection->tid, + "MHD-connection", + daemon->threading.cfg.stack_size, + &mhd_worker_connection, + connection)) { -#ifdef EAGAIN +# ifdef EAGAIN if (EAGAIN == errno) { mhd_LOG_MSG (daemon, MHD_SC_CONNECTION_THREAD_SYS_LIMITS_REACHED, @@ -462,7 +462,7 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon, res = MHD_SC_CONNECTION_THREAD_SYS_LIMITS_REACHED; } else -#endif /* EAGAIN */ +# endif /* EAGAIN */ if (1) { mhd_LOG_MSG (daemon, MHD_SC_CONNECTION_THREAD_LAUNCH_FAILURE, @@ -507,8 +507,8 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon, if (0) // TODO: implement turbo { connection->sk.ready = - (enum mhd_SocketNetState) (mhd_SOCKET_NET_STATE_RECV_READY - | mhd_SOCKET_NET_STATE_SEND_READY); + (enum mhd_SocketNetState)(mhd_SOCKET_NET_STATE_RECV_READY + | mhd_SOCKET_NET_STATE_SEND_READY); mhd_conn_mark_ready (connection, daemon); } return MHD_SC_OK; /* *** Function success exit point *** */ @@ -542,7 +542,7 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon, if (NULL != connection->sk.addr.data) free (connection->sk.addr.data); - (void) mhd_socket_close (connection->sk.fd); + (void)mhd_socket_close (connection->sk.fd); free (connection); mhd_assert (MHD_SC_OK != res); return res; /* *** Function failure exit point *** */ @@ -572,12 +572,12 @@ new_connection_process_ (struct MHD_Daemon *restrict daemon, if (MHD_SC_OK == res) fprintf (stderr, "&&& Added new connection, FD: %2llu\n", - (unsigned long long) connection->sk.fd); + (unsigned long long)connection->sk.fd); else fprintf (stderr, "&&& Failed add connection, FD: %2llu -> %u\n", - (unsigned long long) connection->sk.fd, - (unsigned int) res); + (unsigned long long)connection->sk.fd, + (unsigned int)res); #endif /* MHD_USE_TRACE_CONN_ADD_CLOSE */ return res; @@ -604,7 +604,7 @@ new_connection_process_ (struct MHD_Daemon *restrict daemon, * @return #MHD_SC_OK on success, * error on failure (the @a client_socket is closed) */ -static MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_INOUT_SIZE_ (4,3) enum MHD_StatusCode +static MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_INOUT_SIZE_ (4, 3) enum MHD_StatusCode internal_add_connection (struct MHD_Daemon *daemon, MHD_Socket client_socket, size_t addrlen, @@ -618,14 +618,14 @@ internal_add_connection (struct MHD_Daemon *daemon, enum MHD_StatusCode res; /* Direct add to master daemon could never happen. */ - mhd_assert (! mhd_D_HAS_WORKERS (daemon)); + mhd_assert (!mhd_D_HAS_WORKERS (daemon)); mhd_assert (mhd_FD_FITS_DAEMON (daemon, client_socket)); res = MHD_SC_OK; - if ((! non_blck) && - (mhd_POLL_TYPE_INT_IS_EPOLL (daemon->events.poll_type) || - (mhd_WM_INT_EXTERNAL_EVENTS_EDGE == daemon->wmode_int))) + if ((!non_blck) + && (mhd_POLL_TYPE_INT_IS_EPOLL (daemon->events.poll_type) + || (mhd_WM_INT_EXTERNAL_EVENTS_EDGE == daemon->wmode_int))) { mhd_LOG_MSG (daemon, MHD_SC_NONBLOCKING_REQUIRED, \ "The daemon configuration requires non-blocking sockets, " @@ -691,11 +691,11 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, sk_nonbl = false; // TODO: global daemon lock for external events - (void) connection_cntx; // TODO: add support for connection's context + (void)connection_cntx; // TODO: add support for connection's context ret = MHD_SC_OK; - if (! mhd_D_TYPE_HAS_WORKERS (daemon->threading.d_type) + if (!mhd_D_TYPE_HAS_WORKERS (daemon->threading.d_type) && daemon->conns.block_new) ret = MHD_SC_LIMIT_CONNECTIONS_REACHED; @@ -723,8 +723,8 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, if (sizeof(struct sockaddr_in) > addr_size) log_bad_addlen = true; #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN - else if ((0 != addr->sa_len) && - (sizeof(struct sockaddr_in) > (size_t) addr->sa_len) ) + else if ((0 != addr->sa_len) + && (sizeof(struct sockaddr_in) > (size_t)addr->sa_len)) { mhd_LOG_MSG (daemon, MHD_SC_CONFIGURATION_WRONG_SA_SIZE, \ "MHD_add_connection() has been called with " \ @@ -739,9 +739,9 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, { if (sizeof(struct sockaddr_in6) != addr_size) log_bad_addlen = true; -#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN - else if ((0 != addr->sa_len) && - (sizeof(struct sockaddr_in6) > (size_t) addr->sa_len) ) +# ifdef HAVE_STRUCT_SOCKADDR_SA_LEN + else if ((0 != addr->sa_len) + && (sizeof(struct sockaddr_in6) > (size_t)addr->sa_len)) { mhd_LOG_MSG (daemon, MHD_SC_CONFIGURATION_WRONG_SA_SIZE, \ "MHD_add_connection() has been called with " \ @@ -749,11 +749,12 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, "'struct sockaddr' which does not match 'sa_family'."); ret = MHD_SC_CONFIGURATION_WRONG_SA_SIZE; } -#endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ +# endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ } #endif /* HAVE_INET6 */ - mhd_ASSUME ((log_bad_addlen && (MHD_SC_OK == ret)) || - ((MHD_SC_OK != ret) && ! log_bad_addlen) || (MHD_SC_OK == ret)); + mhd_ASSUME ((log_bad_addlen && (MHD_SC_OK == ret)) + || ((MHD_SC_OK != ret) && !log_bad_addlen) + || (MHD_SC_OK == ret)); if (log_bad_addlen) { mhd_LOG_MSG (daemon, MHD_SC_CONFIGURATION_WRONG_SA_SIZE, \ @@ -762,9 +763,9 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, ret = MHD_SC_CONFIGURATION_WRONG_SA_SIZE; } #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN - if ((0 != addr->sa_len) && - (addr_size > (size_t) addr->sa_len)) - addr_size = (size_t) addr->sa_len; /* Use safest value */ + if ((0 != addr->sa_len) + && (addr_size > (size_t)addr->sa_len)) + addr_size = (size_t)addr->sa_len; /* Use safest value */ #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ } else @@ -772,8 +773,8 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, if (MHD_SC_OK == ret) { - if (! mhd_FD_FITS_DAEMON (daemon, - new_socket)) + if (!mhd_FD_FITS_DAEMON (daemon, + new_socket)) { mhd_LOG_MSG (daemon, MHD_SC_NEW_CONN_FD_OUTSIDE_OF_SET_RANGE, \ "The new connection FD value is higher than allowed"); @@ -784,13 +785,13 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, if (MHD_SC_OK == ret) { sk_nonbl = mhd_socket_nonblocking (new_socket); - if (! sk_nonbl) + if (!sk_nonbl) mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED, \ "Failed to set nonblocking mode on the new client socket."); if (1) // TODO: implement turbo { - if (! mhd_socket_noninheritable (new_socket)) + if (!mhd_socket_noninheritable (new_socket)) mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED, \ "Failed to set noninheritable mode on new client socket."); } @@ -804,16 +805,16 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, #if defined(mhd_socket_nosignal) if (MHD_SC_OK == ret) { - if (! sk_spipe_supprs) + if (!sk_spipe_supprs) sk_spipe_supprs = mhd_socket_nosignal (new_socket); - if (! sk_spipe_supprs) + if (!sk_spipe_supprs) { mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED, \ "Failed to suppress SIGPIPE on the new client socket."); # ifndef HAVE_DCLR_MSG_NOSIGNAL /* Application expects that SIGPIPE will be suppressed, * but suppression failed and SIGPIPE cannot be suppressed with send(). */ - if (! daemon->sigpipe_blocked) + if (!daemon->sigpipe_blocked) ret = MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED; # endif /* HAVE_DCLR_MSG_NOSIGNAL */ } @@ -825,7 +826,7 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, struct mhd_DaemonExtAddedConn *new_conn; new_conn = - (struct mhd_DaemonExtAddedConn*) + (struct mhd_DaemonExtAddedConn *) malloc (sizeof(struct mhd_DaemonExtAddedConn)); if (NULL == new_conn) @@ -840,7 +841,7 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, if (0 != addr_size) { - new_conn->addr = (struct sockaddr_storage *) malloc (addr_size); + new_conn->addr = (struct sockaddr_storage *)malloc (addr_size); if (NULL == new_conn->addr) ret = MHD_SC_CONNECTION_MEM_ALLOC_FAILURE; else @@ -854,7 +855,7 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, if (MHD_SC_OK == ret) { struct MHD_Daemon *d_to_add; - if (! mhd_D_TYPE_HAS_WORKERS (daemon->threading.d_type)) + if (!mhd_D_TYPE_HAS_WORKERS (daemon->threading.d_type)) d_to_add = daemon; else { @@ -921,7 +922,7 @@ MHD_daemon_add_connection (struct MHD_Daemon *MHD_RESTRICT daemon, } } - (void) mhd_socket_close (new_socket); + (void)mhd_socket_close (new_socket); mhd_assert (MHD_SC_OK != ret); @@ -940,30 +941,31 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon) bool sk_spipe_supprs; bool sk_cloexec; enum mhd_Tristate sk_non_ip; -#if ! defined(NDEBUG) && defined (mhd_USE_ACCEPT4) - const bool use_accept4 = ! daemon->dbg.avoid_accept4; -#elif defined (mhd_USE_ACCEPT4) +#if !defined(NDEBUG) && defined(mhd_USE_ACCEPT4) + const bool use_accept4 = !daemon->dbg.avoid_accept4; +#elif defined(mhd_USE_ACCEPT4) static const bool use_accept4 = true; #else /* ! USE_ACCEPT4 && ! _DEBUG */ static const bool use_accept4 = false; #endif /* ! USE_ACCEPT4 && ! _DEBUG */ #ifdef MHD_SUPPORT_THREADS - mhd_assert ((! mhd_D_HAS_THREADS (daemon)) || \ - mhd_thread_handle_ID_is_current_thread (daemon->threading.tid)); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (daemon->threading.d_type)); + mhd_assert ((!mhd_D_HAS_THREADS (daemon)) \ + || mhd_thread_handle_ID_is_current_thread ( + daemon->threading.tid)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (daemon->threading.d_type)); #endif /* MHD_SUPPORT_THREADS */ fd = daemon->net.listen.fd; mhd_assert (MHD_INVALID_SOCKET != fd); - mhd_assert (! daemon->net.listen.is_broken); + mhd_assert (!daemon->net.listen.is_broken); - addrlen = (socklen_t) sizeof (addrstorage); + addrlen = (socklen_t)sizeof (addrstorage); memset (addrstorage, 0, - (size_t) addrlen); + (size_t)addrlen); #ifdef HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN - addrstorage->ss_len = (uint8_t) addrlen; + addrstorage->ss_len = (uint8_t)addrlen; #endif /* HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ /* Initialise with default values to avoid compiler warnings */ @@ -976,39 +978,39 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon) if (use_accept4) { s = accept4 (fd, - (struct sockaddr *) addrstorage, + (struct sockaddr *)addrstorage, &addrlen, mhd_SOCK_CLOEXEC | mhd_SOCK_NONBLOCK | mhd_SOCK_NOSIGPIPE); if (MHD_INVALID_SOCKET != s) { sk_nonbl = (mhd_SOCK_NONBLOCK != 0); -#ifndef MHD_SOCKETS_KIND_WINSOCK +# ifndef MHD_SOCKETS_KIND_WINSOCK sk_spipe_supprs = (mhd_SOCK_NOSIGPIPE != 0); -#else /* MHD_SOCKETS_KIND_WINSOCK */ +# else /* MHD_SOCKETS_KIND_WINSOCK */ sk_spipe_supprs = true; /* Nothing to suppress on W32 */ -#endif /* MHD_SOCKETS_KIND_WINSOCK */ +# endif /* MHD_SOCKETS_KIND_WINSOCK */ sk_cloexec = (mhd_SOCK_CLOEXEC != 0); } } #endif /* mhd_USE_ACCEPT4 */ -#if ! defined(mhd_USE_ACCEPT4) || ! defined(NDEBUG) - if (! use_accept4) +#if !defined(mhd_USE_ACCEPT4) || !defined(NDEBUG) + if (!use_accept4) { s = accept (fd, - (struct sockaddr *) addrstorage, + (struct sockaddr *)addrstorage, &addrlen); if (MHD_INVALID_SOCKET != s) { -#ifdef MHD_ACCEPTED_INHERITS_NONBLOCK +# ifdef MHD_ACCEPTED_INHERITS_NONBLOCK sk_nonbl = daemon->net.listen.non_block; -#else /* ! MHD_ACCEPTED_INHERITS_NONBLOCK */ +# else /* ! MHD_ACCEPTED_INHERITS_NONBLOCK */ sk_nonbl = false; -#endif /* ! MHD_ACCEPTED_INHERITS_NONBLOCK */ -#ifndef MHD_SOCKETS_KIND_WINSOCK +# endif /* ! MHD_ACCEPTED_INHERITS_NONBLOCK */ +# ifndef MHD_SOCKETS_KIND_WINSOCK sk_spipe_supprs = false; -#else /* MHD_SOCKETS_KIND_WINSOCK */ +# else /* MHD_SOCKETS_KIND_WINSOCK */ sk_spipe_supprs = true; /* Nothing to suppress on W32 */ -#endif /* MHD_SOCKETS_KIND_WINSOCK */ +# endif /* MHD_SOCKETS_KIND_WINSOCK */ sk_cloexec = false; } } @@ -1026,7 +1028,7 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon) return mhd_DAEMON_ACCEPT_SKIPPED; if (mhd_SCKT_ERR_IS_EAGAIN (err)) return mhd_DAEMON_ACCEPT_NO_MORE_PENDING; - if (mhd_SCKT_ERR_IS_LOW_RESOURCES (err) ) + if (mhd_SCKT_ERR_IS_LOW_RESOURCES (err)) { /* system/process out of resources */ if (0 == daemon->conns.count) @@ -1057,11 +1059,11 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon) return mhd_DAEMON_ACCEPT_FAILED; } - if (! mhd_FD_FITS_DAEMON (daemon, s)) + if (!mhd_FD_FITS_DAEMON (daemon, s)) { mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_OUTSIDE_OF_SET_RANGE, \ "The accepted socket has value outside of allowed range."); - (void) mhd_socket_close (s); + (void)mhd_socket_close (s); return mhd_DAEMON_ACCEPT_FAILED; } if (mhd_SOCKET_TYPE_IP == daemon->net.listen.type) @@ -1080,7 +1082,7 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon) addrlen = 0; sk_non_ip = mhd_T_MAYBE; } - else if (((socklen_t) sizeof (addrstorage)) < addrlen) + else if (((socklen_t)sizeof (addrstorage)) < addrlen) { /* Should not happen as 'sockaddr_storage' must be large enough to * store any address supported by the system. */ @@ -1093,54 +1095,54 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon) } else if (mhd_T_MAYBE == sk_non_ip) { - if (AF_INET == ((struct sockaddr *) addrstorage)->sa_family) + if (AF_INET == ((struct sockaddr *)addrstorage)->sa_family) sk_non_ip = mhd_T_NO; #ifdef HAVE_INET6 - else if (AF_INET6 == ((struct sockaddr *) addrstorage)->sa_family) + else if (AF_INET6 == ((struct sockaddr *)addrstorage)->sa_family) sk_non_ip = mhd_T_NO; #endif /* HAVE_INET6 */ } - if (! sk_nonbl) + if (!sk_nonbl) { /* Was not set automatically */ sk_nonbl = mhd_socket_nonblocking (s); - if (! sk_nonbl) + if (!sk_nonbl) mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NONBLOCKING_FAILED, \ "Failed to set nonblocking mode on " "new connection socket."); } - if (! sk_cloexec) + if (!sk_cloexec) { /* Was not set automatically */ sk_cloexec = mhd_socket_noninheritable (s); - if (! sk_cloexec) + if (!sk_cloexec) mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NOINHERIT_FAILED, \ "Failed to set non-inheritable mode on " "new connection socket."); } #if defined(mhd_socket_nosignal) - if (! sk_spipe_supprs && ! mhd_socket_nosignal (s)) + if (!sk_spipe_supprs && !mhd_socket_nosignal (s)) { mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED, "Failed to suppress SIGPIPE on incoming connection " \ "socket."); -#ifndef HAVE_DCLR_MSG_NOSIGNAL +# ifndef HAVE_DCLR_MSG_NOSIGNAL /* Application expects that SIGPIPE will be suppressed, * but suppression failed and SIGPIPE cannot be suppressed with send(). */ - if (! daemon->sigpipe_blocked) + if (!daemon->sigpipe_blocked) { - (void) MHD_socket_close_ (s); + (void)MHD_socket_close_ (s); return mhd_DAEMON_ACCEPT_FAILED; } -#endif /* HAVE_DCLR_MSG_NOSIGNAL */ +# endif /* HAVE_DCLR_MSG_NOSIGNAL */ } else sk_spipe_supprs = true; #endif /* mhd_socket_nosignal */ return (MHD_SC_OK == internal_add_connection (daemon, s, - (size_t) addrlen, + (size_t)addrlen, addrstorage, false, sk_nonbl, @@ -1155,10 +1157,10 @@ mhd_conn_remove_from_daemon (struct MHD_Connection *restrict c) { mhd_assert (c->dbg.closing_started); mhd_assert (c->dbg.pre_cleaned); - mhd_assert (! c->dbg.removed_from_daemon); + mhd_assert (!c->dbg.removed_from_daemon); mhd_assert (NULL == c->rp.response); - mhd_assert (! c->rq.app_aware); - mhd_assert (! c->in_proc_ready); + mhd_assert (!c->rq.app_aware); + mhd_assert (!c->in_proc_ready); mhd_assert (NULL == c->rq.cntn.lbuf.data); mhd_assert (NULL == mhd_DLINKEDL_GET_NEXT (c, proc_ready)); mhd_assert (NULL == mhd_DLINKEDL_GET_PREV (c, proc_ready)); @@ -1194,8 +1196,8 @@ mhd_conn_close_final (struct MHD_Connection *restrict c) mhd_assert (c->dbg.pre_cleaned); mhd_assert (c->dbg.removed_from_daemon); mhd_assert (NULL == c->rp.response); - mhd_assert (! c->rq.app_aware); - mhd_assert (! c->in_proc_ready); + mhd_assert (!c->rq.app_aware); + mhd_assert (!c->in_proc_ready); mhd_assert (NULL == mhd_DLINKEDL_GET_NEXT (c, proc_ready)); mhd_assert (NULL == mhd_DLINKEDL_GET_PREV (c, proc_ready)); mhd_assert (c != mhd_DLINKEDL_GET_FIRST (&(c->daemon->events), proc_ready)); @@ -1220,8 +1222,8 @@ mhd_conn_close_final (struct MHD_Connection *restrict c) # ifndef NDEBUG else { - mhd_assert (! mhd_D_HAS_TLS (c->daemon)); - mhd_assert (! c->dbg.tls_inited); + mhd_assert (!mhd_D_HAS_TLS (c->daemon)); + mhd_assert (!c->dbg.tls_inited); } # endif #endif @@ -1232,7 +1234,7 @@ mhd_conn_close_final (struct MHD_Connection *restrict c) #ifdef MHD_USE_TRACE_CONN_ADD_CLOSE fprintf (stderr, "&&& Closed connection, FD: %2llu\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_CONN_ADD_CLOSE */ free (c); @@ -1245,7 +1247,7 @@ mhd_daemon_process_ext_added_conns (struct MHD_Daemon *restrict d) struct mhd_DaemonExtAddedConn *ext_added; mhd_DLNKDL_LIST (mhd_DaemonExtAddedConn, detached_q); - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); if (NULL == mhd_DLINKEDL_GET_FIRST (&(d->events.act_req.ext_added.worker), @@ -1269,16 +1271,16 @@ mhd_daemon_process_ext_added_conns (struct MHD_Daemon *restrict d) mhd_DLINKEDL_DEL_D (&detached_q, ext_added, queue); - if (! d->conns.block_new) + if (!d->conns.block_new) { - (void) internal_add_connection (d, - ext_added->skt, - ext_added->addr_size, - ext_added->addr, - true, - ext_added->is_nonblock, - ext_added->has_spipe_suppr, - mhd_T_MAYBE); + (void)internal_add_connection (d, + ext_added->skt, + ext_added->addr_size, + ext_added->addr, + true, + ext_added->is_nonblock, + ext_added->has_spipe_suppr, + mhd_T_MAYBE); } else { diff --git a/src/mhd2/daemon_create.c b/src/mhd2/daemon_create.c @@ -72,7 +72,7 @@ MHD_daemon_create (MHD_RequestCallback req_cb, struct MHD_Daemon *d; struct DaemonOptions *s; - if (! mhd_lib_init_global_if_needed ()) + if (!mhd_lib_init_global_if_needed ()) { #ifndef NDEBUG fprintf (stderr, "Failed to initialise MHD library.\n"); @@ -84,11 +84,11 @@ MHD_daemon_create (MHD_RequestCallback req_cb, if (NULL == req_cb) return NULL; - d = (struct MHD_Daemon *) mhd_calloc (1, sizeof(struct MHD_Daemon)); + d = (struct MHD_Daemon *)mhd_calloc (1, sizeof(struct MHD_Daemon)); if (NULL == d) return NULL; - s = (struct DaemonOptions *) mhd_calloc (1, sizeof(struct DaemonOptions)); + s = (struct DaemonOptions *)mhd_calloc (1, sizeof(struct DaemonOptions)); if (NULL == s) { free (d); @@ -128,7 +128,7 @@ MHD_daemon_create (MHD_RequestCallback req_cb, s->listen_socket = MHD_INVALID_SOCKET; s->fd_number_limit = MHD_INVALID_SOCKET; - d->log_params.v_log_cb = (MHD_LoggingCallback) mhd_logger_default; + d->log_params.v_log_cb = (MHD_LoggingCallback)mhd_logger_default; d->req_cfg.cb = req_cb; d->req_cfg.cb_cls = req_cb_cls; d->settings = s; diff --git a/src/mhd2/daemon_event_update.c b/src/mhd2/daemon_event_update.c @@ -73,7 +73,7 @@ MHD_daemon_event_update ( if (mhd_DAEMON_STATE_STARTED > daemon->state) return; - if (! mhd_WM_INT_HAS_EXT_EVENTS (daemon->wmode_int)) + if (!mhd_WM_INT_HAS_EXT_EVENTS (daemon->wmode_int)) return; /* FIXME: log error? */ if (mhd_DAEMON_STATE_STARTED < daemon->state) return; @@ -86,7 +86,7 @@ MHD_daemon_event_update ( state_str[2] = MHD_FD_STATE_IS_SET_SEND (fd_current_state) ? 'W' : '-'; state_str[4] = MHD_FD_STATE_IS_SET_EXCEPT (fd_current_state) ? 'E' : '-'; - switch ((mhd_SockRelMarker) ecb_cntx) + switch ((mhd_SockRelMarker)ecb_cntx) { case mhd_SOCKET_REL_MARKER_EMPTY: fprintf (stderr, @@ -96,20 +96,20 @@ MHD_daemon_event_update ( case mhd_SOCKET_REL_MARKER_ITC: fprintf (stderr, "### MHD_daemon_event_update(daemon, [ITC: %2llu], %s)\n", - (unsigned long long) mhd_itc_r_fd (daemon->threading.itc), + (unsigned long long)mhd_itc_r_fd (daemon->threading.itc), state_str); break; case mhd_SOCKET_REL_MARKER_LISTEN: fprintf (stderr, "### MHD_daemon_event_update(daemon, [lstn: %2llu], %s)\n", - (unsigned long long) daemon->net.listen.fd, + (unsigned long long)daemon->net.listen.fd, state_str); break; default: fprintf (stderr, "### MHD_daemon_event_update(daemon, [conn: %2llu], %s)\n", (unsigned long long) - (((struct MHD_Connection *) ecb_cntx)->sk.fd), + (((struct MHD_Connection *)ecb_cntx)->sk.fd), state_str); break; } @@ -119,7 +119,7 @@ MHD_daemon_event_update ( broken_app_data = false; unneeded_event = false; - switch ((mhd_SockRelMarker) ecb_cntx) + switch ((mhd_SockRelMarker)ecb_cntx) { case mhd_SOCKET_REL_MARKER_EMPTY: broken_app_data = true; @@ -151,26 +151,26 @@ MHD_daemon_event_update ( } break; default: - if (((struct MHD_Connection *) ecb_cntx)->daemon != daemon) + if (((struct MHD_Connection *)ecb_cntx)->daemon != daemon) broken_app_data = true; else { - struct MHD_Connection *const c = ((struct MHD_Connection *) ecb_cntx); + struct MHD_Connection *const c = ((struct MHD_Connection *)ecb_cntx); unsigned int err_flag; mhd_assert (MHD_FD_STATE_NONE != c->events.extrn.reg_for); - unneeded_event = (0 != ((~((unsigned int) c->events.extrn.reg_for)) - & ((unsigned int) fd_current_state))); + unneeded_event = (0 != ((~((unsigned int)c->events.extrn.reg_for)) + & ((unsigned int)fd_current_state))); /* Preserve connection's "error flag" */ - err_flag = (((unsigned int) c->sk.ready) - & (unsigned int) mhd_SOCKET_NET_STATE_ERROR_READY); + err_flag = (((unsigned int)c->sk.ready) + & (unsigned int)mhd_SOCKET_NET_STATE_ERROR_READY); c->sk.ready = (enum mhd_SocketNetState) - (err_flag | (((unsigned int) fd_current_state) - & ((unsigned int) c->events.extrn.reg_for))); + (err_flag | (((unsigned int)fd_current_state) + & ((unsigned int)c->events.extrn.reg_for))); } break; } diff --git a/src/mhd2/daemon_funcs.c b/src/mhd2/daemon_funcs.c @@ -75,7 +75,7 @@ MHD_INTERNAL bool mhd_daemon_trigger_itc (struct MHD_Daemon *restrict d) { mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); - if (! mhd_itc_activate (d->threading.itc)) + if (!mhd_itc_activate (d->threading.itc)) { mhd_LOG_MSG (d, MHD_SC_ITC_USE_FAILED, \ "Failed to communicate by ITC with the daemon thread."); @@ -156,13 +156,13 @@ mhd_daemon_get_lbuf (struct MHD_Daemon *restrict d, size_t requested_size, struct mhd_Buffer *restrict buf) { - if (! mhd_daemon_claim_lbuf (d, requested_size)) + if (!mhd_daemon_claim_lbuf (d, requested_size)) { buf->size = 0; buf->data = NULL; return false; } - buf->data = (char *) malloc (requested_size); + buf->data = (char *)malloc (requested_size); if (NULL == buf->data) { buf->size = 0; @@ -184,7 +184,7 @@ mhd_daemon_grow_lbuf (struct MHD_Daemon *restrict d, mhd_assert (NULL != buf->data || 0 == buf->size); mhd_assert (0 != buf->size || NULL == buf->data); - if (! mhd_daemon_claim_lbuf (d, grow_size)) + if (!mhd_daemon_claim_lbuf (d, grow_size)) return false; if (NULL == buf->data) @@ -197,7 +197,7 @@ mhd_daemon_grow_lbuf (struct MHD_Daemon *restrict d, return false; } - buf->data = (char *) new_alloc; + buf->data = (char *)new_alloc; buf->size += grow_size; return true; @@ -221,8 +221,8 @@ mhd_daemon_extend_lbuf_up_to (struct MHD_Daemon *restrict d, new_alloc = NULL; if (NULL == buf->data) { - while ((0 != grow_size) && - (NULL == (new_alloc = malloc (grow_size)))) + while ((0 != grow_size) + && (NULL == (new_alloc = malloc (grow_size)))) { size_t reduce = grow_size / 2; if (sizeof(void *) >= (grow_size - reduce)) @@ -234,9 +234,9 @@ mhd_daemon_extend_lbuf_up_to (struct MHD_Daemon *restrict d, } else { - while ((0 != grow_size) && - (NULL == (new_alloc = realloc (buf->data, - buf->size + grow_size)))) + while ((0 != grow_size) + && (NULL == (new_alloc = realloc (buf->data, + buf->size + grow_size)))) { size_t reduce = grow_size / 2; if (sizeof(void *) >= (grow_size - reduce)) @@ -250,7 +250,7 @@ mhd_daemon_extend_lbuf_up_to (struct MHD_Daemon *restrict d, if (NULL != new_alloc) { mhd_assert (0 != grow_size); - buf->data = (char *) new_alloc; + buf->data = (char *)new_alloc; buf->size += grow_size; } @@ -278,7 +278,7 @@ mhd_daemon_free_lbuf (struct MHD_Daemon *restrict d, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ uint_fast64_t mhd_daemon_get_milsec_counter (struct MHD_Daemon *restrict d) { - if (! d->events.time.is_set) + if (!d->events.time.is_set) { d->events.time.cur = mhd_monotonic_msec_counter (); d->events.time.is_set = true; diff --git a/src/mhd2/daemon_funcs.h b/src/mhd2/daemon_funcs.h @@ -77,7 +77,7 @@ mhd_daemon_trigger_itc (struct MHD_Daemon *restrict d); #else /* ! MHD_SUPPORT_THREADS */ -#define mhd_daemon_trigger_itc(d) ((void) d, ! 0) +# define mhd_daemon_trigger_itc(d) ((void) d, ! 0) #endif /* ! MHD_SUPPORT_THREADS */ @@ -118,7 +118,7 @@ mhd_daemon_get_lbuf (struct MHD_Daemon *restrict d, size_t requested_size, struct mhd_Buffer *restrict buf) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_ - MHD_FN_PAR_OUT_ (3); +MHD_FN_PAR_OUT_ (3); /** * Grow the large buffer, which previously was allocated @@ -133,7 +133,7 @@ mhd_daemon_grow_lbuf (struct MHD_Daemon *restrict d, size_t grow_size, struct mhd_Buffer *restrict buf) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_ - MHD_FN_PAR_INOUT_ (3); +MHD_FN_PAR_INOUT_ (3); /** * Grow or allocate the large buffer up to specified grow size. @@ -149,7 +149,7 @@ mhd_daemon_extend_lbuf_up_to (struct MHD_Daemon *restrict d, size_t desired_grow_size, struct mhd_Buffer *restrict buf) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_MUST_CHECK_RESULT_ - MHD_FN_PAR_INOUT_ (3); +MHD_FN_PAR_INOUT_ (3); /** diff --git a/src/mhd2/daemon_get_info.c b/src/mhd2/daemon_get_info.c @@ -71,7 +71,7 @@ MHD_daemon_get_info_fixed_sz ( union MHD_DaemonInfoFixedData *MHD_RESTRICT output_buf, size_t output_buf_size) { - mhd_assert (! mhd_D_HAS_MASTER (daemon)); + mhd_assert (!mhd_D_HAS_MASTER (daemon)); if (mhd_DAEMON_STATE_STARTED > daemon->state) return MHD_SC_TOO_EARLY; if (mhd_DAEMON_STATE_STARTED < daemon->state) @@ -85,11 +85,11 @@ MHD_daemon_get_info_fixed_sz ( if (sizeof(output_buf->v_poll_syscall) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; output_buf->v_poll_syscall = - (enum MHD_SockPollSyscall) daemon->events.poll_type; + (enum MHD_SockPollSyscall)daemon->events.poll_type; return MHD_SC_OK; case MHD_DAEMON_INFO_FIXED_NUM_WORK_THREADS: #ifdef MHD_SUPPORT_THREADS - if (! mhd_WM_INT_HAS_THREADS (daemon->wmode_int)) + if (!mhd_WM_INT_HAS_THREADS (daemon->wmode_int)) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; if (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION == daemon->wmode_int) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; @@ -109,7 +109,7 @@ MHD_daemon_get_info_fixed_sz ( #endif /* ! MHD_SUPPORT_THREADS */ case MHD_DAEMON_INFO_FIXED_BIND_PORT: if ((MHD_INVALID_SOCKET == daemon->net.listen.fd) - && ! daemon->net.listen.is_broken) + && !daemon->net.listen.is_broken) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; if (mhd_SOCKET_TYPE_UNKNOWN > daemon->net.listen.type) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; @@ -138,7 +138,7 @@ MHD_daemon_get_info_fixed_sz ( return MHD_SC_OK; case MHD_DAEMON_INFO_FIXED_AGGREAGATE_FD: #ifdef MHD_SUPPORT_EPOLL - if (! mhd_D_IS_USING_EPOLL (daemon)) + if (!mhd_D_IS_USING_EPOLL (daemon)) return MHD_SC_INFO_GET_TYPE_NOT_APPLICABLE; if (sizeof(output_buf->v_aggreagate_fd) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; @@ -151,11 +151,11 @@ MHD_daemon_get_info_fixed_sz ( case MHD_DAEMON_INFO_FIXED_TLS_BACKEND: if (sizeof(output_buf->v_tls_backend) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - if (! mhd_D_HAS_TLS (daemon)) + if (!mhd_D_HAS_TLS (daemon)) output_buf->v_tls_backend = MHD_TLS_BACKEND_NONE; else { -#if ! defined(MHD_SUPPORT_HTTPS) +#if !defined(MHD_SUPPORT_HTTPS) mhd_UNREACHABLE (); #elif defined(MHD_USE_MULTITLS) switch (daemon->tls->choice) @@ -187,7 +187,7 @@ MHD_daemon_get_info_fixed_sz ( #elif defined(MHD_SUPPORT_MBEDTLS) output_buf->v_tls_backend = MHD_TLS_BACKEND_MBEDTLS; #else -#error No TLS backends enabled, while TLS support is enabled +# error No TLS backends enabled, while TLS support is enabled #endif } return MHD_SC_OK; @@ -246,7 +246,7 @@ MHD_daemon_get_info_dynamic_sz ( union MHD_DaemonInfoDynamicData *MHD_RESTRICT output_buf, size_t output_buf_size) { - mhd_assert (! mhd_D_HAS_MASTER (daemon)); + mhd_assert (!mhd_D_HAS_MASTER (daemon)); if (mhd_DAEMON_STATE_STARTED > daemon->state) return MHD_SC_TOO_EARLY; if (mhd_DAEMON_STATE_STARTED < daemon->state) @@ -271,7 +271,7 @@ MHD_daemon_get_info_dynamic_sz ( test against zero/non-zero value is valid even if reading is non-atomic. */ - if (! mhd_D_HAS_WORKERS (daemon)) + if (!mhd_D_HAS_WORKERS (daemon)) res = (0 != daemon->conns.count) ? MHD_YES : MHD_NO; else { diff --git a/src/mhd2/daemon_logger.c b/src/mhd2/daemon_logger.c @@ -45,10 +45,10 @@ #include "mhd_sys_options.h" #ifdef MHD_SUPPORT_LOG_FUNCTIONALITY -#include <stdarg.h> -#include "sys_null_macro.h" -#include "mhd_daemon.h" -#include "daemon_logger.h" +# include <stdarg.h> +# include "sys_null_macro.h" +# include "mhd_daemon.h" +# include "daemon_logger.h" MHD_INTERNAL void diff --git a/src/mhd2/daemon_logger.h b/src/mhd2/daemon_logger.h @@ -49,7 +49,7 @@ #ifdef MHD_SUPPORT_LOG_FUNCTIONALITY -#include "mhd_public_api.h" /* For enum MHD_StatusCode */ +# include "mhd_public_api.h" /* For enum MHD_StatusCode */ struct MHD_Daemon; /* Forward declaration */ @@ -77,7 +77,7 @@ mhd_logger (struct MHD_Daemon *daemon, * Note: no printf() parameters allowed (except the format string). To log * message with variable parameters, use #mhd_LOG_PRINT with #mhd_LOG_FMT. */ -#define mhd_LOG_MSG(daemon,sc,msg) mhd_logger (daemon,sc,msg) +# define mhd_LOG_MSG(daemon, sc, msg) mhd_logger (daemon,sc,msg) /** * Define a message that will be used for logging. @@ -85,7 +85,7 @@ mhd_logger (struct MHD_Daemon *daemon, * macro. For example, when defining a message that passed as a pointer * to the logging function. */ -#define mhd_MSG4LOG(msg) msg +# define mhd_MSG4LOG(msg) msg /** * Format message and log it. @@ -94,18 +94,18 @@ mhd_logger (struct MHD_Daemon *daemon, * * Example: mhd_LOG_PRINT(daemon, MHD_SC_VALUE, mhd_LOG_FMT("Number: %d"), i); */ -#define mhd_LOG_PRINT mhd_logger +# define mhd_LOG_PRINT mhd_logger /** * The wrapper macro for the format string to be used for format parameter for * the #mhd_LOG_FMT() macro */ -#define mhd_LOG_FMT(format_string) format_string +# define mhd_LOG_FMT(format_string) format_string #else /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ -#ifdef HAVE_MACRO_VARIADIC +# ifdef HAVE_MACRO_VARIADIC /** * Log a single fixed message. @@ -117,7 +117,7 @@ mhd_logger (struct MHD_Daemon *daemon, * Note: no printf() parameters allowed (except the format string). To log * message with variable parameters, use #mhd_LOG_PRINT with #mhd_LOG_FMT. */ -#define mhd_LOG_MSG(daemon,sc,msg) do { (void) daemon; } while (0) +# define mhd_LOG_MSG(daemon, sc, msg) do { (void) daemon; } while (0) /** * Format message and log it. @@ -126,11 +126,11 @@ mhd_logger (struct MHD_Daemon *daemon, * * Example: mhd_LOG_PRINT(daemon, MHD_SC_VALUE, mhd_LOG_FMT("Number: %d"), i); */ -#define mhd_LOG_PRINT(daemon,sc,fm,...) do { (void) daemon; } while (0) +# define mhd_LOG_PRINT(daemon, sc, fm, ...) do { (void) daemon; } while (0) -#else /* ! HAVE_MACRO_VARIADIC */ +# else /* ! HAVE_MACRO_VARIADIC */ -#include "sys_base_types.h" /* For NULL */ +# include "sys_base_types.h" /* For NULL */ /** * Format message and log it @@ -143,7 +143,9 @@ mhd_LOG_PRINT (struct MHD_Daemon *daemon, const char *fm, ...) { - (void) daemon; (void) sc; (void) fm; + (void)daemon; + (void)sc; + (void)fm; } @@ -154,9 +156,9 @@ mhd_LOG_PRINT (struct MHD_Daemon *daemon, * Any '%' symbols should be doubled ('%%') to avoid interpretation as a format * specifier symbol. */ -#define mhd_LOG_MSG(daemon,sc,msg) mhd_LOG_PRINT (daemon,sc,NULL) +# define mhd_LOG_MSG(daemon, sc, msg) mhd_LOG_PRINT (daemon,sc,NULL) -#endif /* ! HAVE_MACRO_VARIADIC */ +# endif /* ! HAVE_MACRO_VARIADIC */ /** * Define a message that will be used for logging. @@ -164,13 +166,13 @@ mhd_LOG_PRINT (struct MHD_Daemon *daemon, * macro. For example, when defining a message that passed as a pointer * to the logging function. */ -#define mhd_MSG4LOG(msg) NULL +# define mhd_MSG4LOG(msg) NULL /** * The wrapper macro for the format string to be used for format parameter for * the #mhd_LOG_FMT() macro */ -#define mhd_LOG_FMT(format_string) NULL +# define mhd_LOG_FMT(format_string) NULL #endif /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ diff --git a/src/mhd2/daemon_logger_default.c b/src/mhd2/daemon_logger_default.c @@ -46,10 +46,10 @@ #ifdef MHD_SUPPORT_LOG_FUNCTIONALITY -#include <stdio.h> +# include <stdio.h> -#include "daemon_logger_default.h" -#include "mhd_assert.h" /* For NDEBUG macro */ +# include "daemon_logger_default.h" +# include "mhd_assert.h" /* For NDEBUG macro */ MHD_INTERNAL void mhd_logger_default (void *cls, @@ -58,17 +58,17 @@ mhd_logger_default (void *cls, va_list ap) { int res; - (void) cls; /* Not used by default logger */ - (void) sc; /* Not used by default logger */ + (void)cls; /* Not used by default logger */ + (void)sc; /* Not used by default logger */ res = vfprintf (stderr, fm, ap); - (void) res; /* The result of vfprintf() call is ignored */ + (void)res; /* The result of vfprintf() call is ignored */ res = fprintf (stderr, "\n"); - (void) res; /* The result of vfprintf() call is ignored */ -#ifndef NDEBUG + (void)res; /* The result of vfprintf() call is ignored */ +# ifndef NDEBUG res = fflush (stderr); - (void) res; /* The result of fflush() call is ignored */ -#endif /* ! NDEBUG */ + (void)res; /* The result of fflush() call is ignored */ +# endif /* ! NDEBUG */ } diff --git a/src/mhd2/daemon_logger_default.h b/src/mhd2/daemon_logger_default.h @@ -49,9 +49,9 @@ #ifdef MHD_SUPPORT_LOG_FUNCTIONALITY -#include "mhd_public_api.h" /* For enum MHD_StatusCode */ +# include "mhd_public_api.h" /* For enum MHD_StatusCode */ -#include <stdarg.h> +# include <stdarg.h> /** * Default logger function. @@ -69,9 +69,9 @@ mhd_logger_default (void *cls, #else /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ -#include "sys_null_macro.h" +# include "sys_null_macro.h" -#define mhd_logger_default NULL +# define mhd_logger_default NULL #endif /* ! MHD_DAEMON_LOGGER_DEFAULT_H */ diff --git a/src/mhd2/daemon_set_options.c b/src/mhd2/daemon_set_options.c @@ -115,9 +115,9 @@ MHD_daemon_set_options ( ++pass_size; /* Space for zero-termination */ if (NULL != settings->tls_cert_key.v_mem_cert) free (settings->tls_cert_key.v_mem_cert); // TODO: Support multiple certificates!! - settings->tls_cert_key.v_mem_cert = (char *) malloc (cert_size - + key_size - + pass_size); + settings->tls_cert_key.v_mem_cert = (char *)malloc (cert_size + + key_size + + pass_size); if (NULL == settings->tls_cert_key.v_mem_cert) return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; memcpy (settings->tls_cert_key.v_mem_cert, @@ -164,7 +164,7 @@ MHD_daemon_set_options ( len = strlen (option->val.tls_app_name.v_app_name); if (128 <= len) return MHD_SC_CONFIGURATION_PARAM_TOO_LARGE; - settings->tls_app_name.v_app_name = (char *) malloc (len + 1u); + settings->tls_app_name.v_app_name = (char *)malloc (len + 1u); if (NULL == settings->tls_app_name.v_app_name) return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; memcpy (settings->tls_app_name.v_app_name, @@ -182,7 +182,7 @@ MHD_daemon_set_options ( { size_t len; len = strlen (option->val.tls_openssl_def_file.v_pathname); - settings->tls_openssl_def_file.v_pathname = (char *) malloc (len + 1u); + settings->tls_openssl_def_file.v_pathname = (char *)malloc (len + 1u); if (NULL == settings->tls_openssl_def_file.v_pathname) return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; memcpy (settings->tls_openssl_def_file.v_pathname, diff --git a/src/mhd2/daemon_start.c b/src/mhd2/daemon_start.c @@ -207,9 +207,9 @@ daemon_set_work_mode (struct MHD_Daemon *restrict d, d->wmode_int = mhd_WM_INT_EXTERNAL_EVENTS_EDGE; break; case MHD_WM_EXTERNAL_SINGLE_FD_WATCH: - if ((MHD_SPS_AUTO != s->poll_syscall) && - (MHD_SPS_EPOLL != s->poll_syscall) && - (MHD_SPS_KQUEUE != s->poll_syscall)) + if ((MHD_SPS_AUTO != s->poll_syscall) + && (MHD_SPS_EPOLL != s->poll_syscall) + && (MHD_SPS_KQUEUE != s->poll_syscall)) { mhd_LOG_MSG ( \ d, MHD_SC_SYSCALL_WORK_MODE_COMBINATION_INVALID, \ @@ -217,7 +217,7 @@ daemon_set_work_mode (struct MHD_Daemon *restrict d, "is not compatible with requested socket polling syscall."); return MHD_SC_SYSCALL_WORK_MODE_COMBINATION_INVALID; } -#if ! defined(MHD_SUPPORT_EPOLL) && ! defined(MHD_SUPPORT_KQUEUE) +#if !defined(MHD_SUPPORT_EPOLL) && !defined(MHD_SUPPORT_KQUEUE) mhd_LOG_MSG ( \ d, MHD_SC_FEATURE_DISABLED, \ "The epoll or kqueue is required for the requested work mode " \ @@ -268,9 +268,9 @@ daemon_set_work_mode (struct MHD_Daemon *restrict d, return MHD_SC_CONFIGURATION_UNEXPECTED_WM; } - if ((mhd_WM_INT_EXTERNAL_EVENTS_LEVEL != d->wmode_int) && - (mhd_WM_INT_EXTERNAL_EVENTS_EDGE != d->wmode_int) && - (MHD_NO != s->reregister_all)) + if ((mhd_WM_INT_EXTERNAL_EVENTS_LEVEL != d->wmode_int) + && (mhd_WM_INT_EXTERNAL_EVENTS_EDGE != d->wmode_int) + && (MHD_NO != s->reregister_all)) { mhd_LOG_MSG ( \ d, \ @@ -394,15 +394,15 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, sk_port = 0; #ifndef HAVE_INET6 - mhd_assert (! v6_tried); - mhd_assert (! force_v6_any_dual); + mhd_assert (!v6_tried); + mhd_assert (!force_v6_any_dual); #endif mhd_assert (mhd_SKT_NO_SOCKET == sk_type); /* Mute analyser warning */ if (MHD_INVALID_SOCKET != s->listen_socket) { - mhd_assert (! v6_tried); - mhd_assert (! force_v6_any_dual); + mhd_assert (!v6_tried); + mhd_assert (!force_v6_any_dual); /* Check for options conflicts */ if (0 != s->bind_sa.v_sa_len) { @@ -429,8 +429,8 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, { if (0 != s->bind_sa.v_sa_len) { - mhd_assert (! v6_tried); - mhd_assert (! force_v6_any_dual); + mhd_assert (!v6_tried); + mhd_assert (!force_v6_any_dual); /* Check for options conflicts */ if (MHD_AF_NONE != s->bind_port.v_af) @@ -454,13 +454,13 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, return MHD_SC_CONFIGURATION_WRONG_SA_SIZE; } memcpy (&(sa_all.sa_i4), s->bind_sa.v_sa, sizeof(sa_all.sa_i4)); - sk_port = (uint_least16_t) ntohs (sa_all.sa_i4.sin_port); + sk_port = (uint_least16_t)ntohs (sa_all.sa_i4.sin_port); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - mhd_assert (sizeof(sa_all.sa_i4) == (uint8_t) sizeof(sa_all.sa_i4)); - sa_all.sa_i4.sin_len = (uint8_t) sizeof(sa_all.sa_i4); + mhd_assert (sizeof(sa_all.sa_i4) == (uint8_t)sizeof(sa_all.sa_i4)); + sa_all.sa_i4.sin_len = (uint8_t)sizeof(sa_all.sa_i4); #endif - p_use_sa = (struct sockaddr *) &(sa_all.sa_i4); - use_sa_size = (socklen_t) sizeof(sa_all.sa_i4); + p_use_sa = (struct sockaddr *)&(sa_all.sa_i4); + use_sa_size = (socklen_t)sizeof(sa_all.sa_i4); break; #ifdef HAVE_INET6 case AF_INET6: @@ -473,13 +473,13 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, return MHD_SC_CONFIGURATION_WRONG_SA_SIZE; } memcpy (&(sa_all.sa_i6), s->bind_sa.v_sa, s->bind_sa.v_sa_len); - sk_port = (uint_least16_t) ntohs (sa_all.sa_i6.sin6_port); -#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN - mhd_assert (sizeof(sa_all.sa_i6) == (uint8_t) sizeof(sa_all.sa_i6)); - sa_all.sa_i6.sin6_len = (uint8_t) sizeof(sa_all.sa_i6); -#endif - p_use_sa = (struct sockaddr *) &(sa_all.sa_i6); - use_sa_size = (socklen_t) sizeof(sa_all.sa_i6); + sk_port = (uint_least16_t)ntohs (sa_all.sa_i6.sin6_port); +# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN + mhd_assert (sizeof(sa_all.sa_i6) == (uint8_t)sizeof(sa_all.sa_i6)); + sa_all.sa_i6.sin6_len = (uint8_t)sizeof(sa_all.sa_i6); +# endif + p_use_sa = (struct sockaddr *)&(sa_all.sa_i6); + use_sa_size = (socklen_t)sizeof(sa_all.sa_i6); break; #endif /* HAVE_INET6 */ #ifdef MHD_AF_UNIX @@ -504,14 +504,14 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, #ifdef HAVE_INET6 else { -#ifdef HAVE_DCLR_IPV6_V6ONLY +# ifdef HAVE_DCLR_IPV6_V6ONLY sk_type = mhd_SKT_IP_DUAL_REQUIRED; -#else /* ! IPV6_V6ONLY */ +# else /* ! IPV6_V6ONLY */ mhd_LOG_MSG (d, \ MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_NOT_SUPPORTED, \ "IP dual stack is not supported by this platform or " \ "by this MHD build"); -#endif /* ! IPV6_V6ONLY */ +# endif /* ! IPV6_V6ONLY */ } #endif /* HAVE_INET6 */ } @@ -520,19 +520,19 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, { #if defined(HAVE_STRUCT_SOCKADDR_SA_LEN) && \ defined(HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN) - if ((((size_t) s->bind_sa.v_sa->sa_len) != s->bind_sa.v_sa_len) && - (sizeof(sa_all) >= s->bind_sa.v_sa_len)) + if ((((size_t)s->bind_sa.v_sa->sa_len) != s->bind_sa.v_sa_len) + && (sizeof(sa_all) >= s->bind_sa.v_sa_len)) { /* Fix embedded 'sa_len' member if possible */ memcpy (&sa_all, s->bind_sa.v_sa, s->bind_sa.v_sa_len); - mhd_assert (s->bind_sa.v_sa_len == (uint8_t) s->bind_sa.v_sa_len); - sa_all.sa_stor.ss_len = (uint8_t) s->bind_sa.v_sa_len; - p_use_sa = (const struct sockaddr *) &(sa_all.sa_stor); + mhd_assert (s->bind_sa.v_sa_len == (uint8_t)s->bind_sa.v_sa_len); + sa_all.sa_stor.ss_len = (uint8_t)s->bind_sa.v_sa_len; + p_use_sa = (const struct sockaddr *)&(sa_all.sa_stor); } else #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN && HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN */ p_use_sa = s->bind_sa.v_sa; - use_sa_size = (socklen_t) s->bind_sa.v_sa_len; + use_sa_size = (socklen_t)s->bind_sa.v_sa_len; } } else /* if (MHD_AF_NONE != s->bind_port.v_af) */ @@ -546,32 +546,32 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, return MHD_SC_INTERNAL_ERROR; case MHD_AF_AUTO: #ifdef HAVE_INET6 -#ifdef HAVE_DCLR_IPV6_V6ONLY +# ifdef HAVE_DCLR_IPV6_V6ONLY if (force_v6_any_dual) sk_type = mhd_SKT_IP_V6_WITH_V4_OPT; else if (v6_tried) sk_type = mhd_SKT_IP_V4_WITH_FALLBACK; else sk_type = mhd_SKT_IP_V4_WITH_V6_OPT; -#else /* ! IPV6_V6ONLY */ - mhd_assert (! v6_tried); +# else /* ! IPV6_V6ONLY */ + mhd_assert (!v6_tried); if (force_v6_any_dual) sk_type = mhd_SKT_IP_V6_ONLY; else sk_type = mhd_SKT_IP_V4_WITH_FALLBACK; -#endif /* ! IPV6_V6ONLY */ +# endif /* ! IPV6_V6ONLY */ #else /* ! HAVE_INET6 */ sk_type = mhd_SKT_IP_V4_ONLY; #endif /* ! HAVE_INET6 */ break; case MHD_AF_INET4: - mhd_assert (! v6_tried); - mhd_assert (! force_v6_any_dual); + mhd_assert (!v6_tried); + mhd_assert (!force_v6_any_dual); sk_type = mhd_SKT_IP_V4_ONLY; break; case MHD_AF_INET6: - mhd_assert (! v6_tried); - mhd_assert (! force_v6_any_dual); + mhd_assert (!v6_tried); + mhd_assert (!force_v6_any_dual); #ifdef HAVE_INET6 sk_type = mhd_SKT_IP_V6_ONLY; #else /* ! HAVE_INET6 */ @@ -582,18 +582,18 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, #endif /* ! HAVE_INET6 */ break; case MHD_AF_DUAL: - mhd_assert (! v6_tried); - mhd_assert (! force_v6_any_dual); + mhd_assert (!v6_tried); + mhd_assert (!force_v6_any_dual); #ifdef HAVE_INET6 -#ifdef HAVE_DCLR_IPV6_V6ONLY +# ifdef HAVE_DCLR_IPV6_V6ONLY sk_type = mhd_SKT_IP_DUAL_REQUIRED; -#else /* ! IPV6_V6ONLY */ +# else /* ! IPV6_V6ONLY */ mhd_LOG_MSG (d, MHD_SC_LISTEN_DUAL_STACK_CONFIGURATION_NOT_SUPPORTED, \ "IP dual stack is not supported by this platform or " \ "by this MHD build"); sk_type = mhd_SKT_IP_V6_ONLY; -#endif /* ! IPV6_V6ONLY */ +# endif /* ! IPV6_V6ONLY */ #else /* ! HAVE_INET6 */ mhd_LOG_MSG (d, MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD, \ "IPv6 is not supported by this MHD build or " \ @@ -602,14 +602,14 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, #endif /* ! HAVE_INET6 */ break; case MHD_AF_DUAL_v4_OPTIONAL: - mhd_assert (! v6_tried); - mhd_assert (! force_v6_any_dual); + mhd_assert (!v6_tried); + mhd_assert (!force_v6_any_dual); #ifdef HAVE_INET6 -#ifdef HAVE_DCLR_IPV6_V6ONLY +# ifdef HAVE_DCLR_IPV6_V6ONLY sk_type = mhd_SKT_IP_V6_WITH_V4_OPT; -#else /* ! IPV6_V6ONLY */ +# else /* ! IPV6_V6ONLY */ sk_type = mhd_SKT_IP_V6_ONLY; -#endif /* ! IPV6_V6ONLY */ +# endif /* ! IPV6_V6ONLY */ #else /* ! HAVE_INET6 */ mhd_LOG_MSG (d, MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD, \ "IPv6 is not supported by this MHD build or " \ @@ -618,17 +618,17 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, #endif /* ! HAVE_INET6 */ break; case MHD_AF_DUAL_v6_OPTIONAL: - mhd_assert (! force_v6_any_dual); + mhd_assert (!force_v6_any_dual); #ifdef HAVE_INET6 -#ifdef HAVE_DCLR_IPV6_V6ONLY - sk_type = (! v6_tried) ? +# ifdef HAVE_DCLR_IPV6_V6ONLY + sk_type = (!v6_tried) ? mhd_SKT_IP_V4_WITH_V6_OPT : mhd_SKT_IP_V4_ONLY; -#else /* ! IPV6_V6ONLY */ - mhd_assert (! v6_tried); +# else /* ! IPV6_V6ONLY */ + mhd_assert (!v6_tried); sk_type = mhd_SKT_IP_V4_ONLY; -#endif /* ! IPV6_V6ONLY */ +# endif /* ! IPV6_V6ONLY */ #else /* ! HAVE_INET6 */ - mhd_assert (! v6_tried); + mhd_assert (!v6_tried); sk_type = mhd_SKT_IP_V4_ONLY; #endif /* ! HAVE_INET6 */ break; @@ -652,10 +652,10 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, if (0 != INADDR_ANY) /* Optimised at compile time */ sa_all.sa_i4.sin_addr.s_addr = htonl (INADDR_ANY); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN - sa_all.sa_i4.sin_len = (uint8_t) sizeof (sa_all.sa_i4); + sa_all.sa_i4.sin_len = (uint8_t)sizeof (sa_all.sa_i4); #endif - p_use_sa = (const struct sockaddr *) &(sa_all.sa_i4); - use_sa_size = (socklen_t) sizeof (sa_all.sa_i4); + p_use_sa = (const struct sockaddr *)&(sa_all.sa_i4); + use_sa_size = (socklen_t)sizeof (sa_all.sa_i4); break; case mhd_SKT_IP_V6_ONLY: case mhd_SKT_IP_DUAL_REQUIRED: @@ -664,21 +664,21 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, #ifdef HAVE_INET6 if (1) { -#ifdef IN6ADDR_ANY_INIT +# ifdef IN6ADDR_ANY_INIT static const struct in6_addr static_in6any = IN6ADDR_ANY_INIT; -#endif +# endif /* Zeroing is required by POSIX */ memset (&(sa_all.sa_i6), 0, sizeof(sa_all.sa_i6)); sa_all.sa_i6.sin6_family = AF_INET6; sa_all.sa_i6.sin6_port = htons (s->bind_port.v_port); -#ifdef IN6ADDR_ANY_INIT /* Optional assignment at the address is all zeros anyway */ +# ifdef IN6ADDR_ANY_INIT /* Optional assignment at the address is all zeros anyway */ sa_all.sa_i6.sin6_addr = static_in6any; -#endif -#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN - sa_all.sa_i6.sin6_len = (uint8_t) sizeof (sa_all.sa_i6); -#endif - p_use_sa = (const struct sockaddr *) &(sa_all.sa_i6); - use_sa_size = (socklen_t) sizeof (sa_all.sa_i6); +# endif +# ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN + sa_all.sa_i6.sin6_len = (uint8_t)sizeof (sa_all.sa_i6); +# endif + p_use_sa = (const struct sockaddr *)&(sa_all.sa_i6); + use_sa_size = (socklen_t)sizeof (sa_all.sa_i6); } break; #endif /* HAVE_INET6 */ @@ -773,7 +773,7 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, do { /* The scope for automatic socket close for error returns */ - if (! mhd_FD_FITS_DAEMON (d,sk)) + if (!mhd_FD_FITS_DAEMON (d, sk)) { mhd_LOG_MSG (d, MHD_SC_LISTEN_FD_OUTSIDE_OF_SET_RANGE, \ "The listen FD value is higher than allowed"); @@ -781,33 +781,33 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, break; } - if (! is_non_inhr) + if (!is_non_inhr) { - if (! mhd_socket_noninheritable (sk)) + if (!mhd_socket_noninheritable (sk)) mhd_LOG_MSG (d, MHD_SC_LISTEN_SOCKET_NOINHERIT_FAILED, \ "OS refused to make the listen socket non-inheritable"); } - if (! sk_already_listening) + if (!sk_already_listening) { #ifdef HAVE_INET6 -#ifdef HAVE_DCLR_IPV6_V6ONLY - if ((mhd_SKT_IP_V6_ONLY == sk_type) || - (mhd_SKT_IP_DUAL_REQUIRED == sk_type) || - (mhd_SKT_IP_V4_WITH_V6_OPT == sk_type) || - (mhd_SKT_IP_V6_WITH_V4_OPT == sk_type) || - (mhd_SKT_UNKNOWN == sk_type)) +# ifdef HAVE_DCLR_IPV6_V6ONLY + if ((mhd_SKT_IP_V6_ONLY == sk_type) + || (mhd_SKT_IP_DUAL_REQUIRED == sk_type) + || (mhd_SKT_IP_V4_WITH_V6_OPT == sk_type) + || (mhd_SKT_IP_V6_WITH_V4_OPT == sk_type) + || (mhd_SKT_UNKNOWN == sk_type)) { mhd_SCKT_OPT_BOOL no_dual_to_set; bool use_dual; - use_dual = ((mhd_SKT_IP_DUAL_REQUIRED == sk_type) || - (mhd_SKT_IP_V4_WITH_V6_OPT == sk_type) || - (mhd_SKT_IP_V6_WITH_V4_OPT == sk_type)); + use_dual = ((mhd_SKT_IP_DUAL_REQUIRED == sk_type) + || (mhd_SKT_IP_V4_WITH_V6_OPT == sk_type) + || (mhd_SKT_IP_V6_WITH_V4_OPT == sk_type)); no_dual_to_set = use_dual ? 0 : 1; if (0 != mhd_setsockopt (sk, IPPROTO_IPV6, IPV6_V6ONLY, - (void *) &no_dual_to_set, + (void *)&no_dual_to_set, sizeof (no_dual_to_set))) { mhd_SCKT_OPT_BOOL no_dual_current; @@ -821,8 +821,8 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, /* Some platforms forbid setting this options, but allow reading. */ if ((0 != mhd_getsockopt (sk, IPPROTO_IPV6, IPV6_V6ONLY, - (void*) &no_dual_current, &opt_size)) - || (((socklen_t) sizeof(no_dual_current)) < opt_size)) + (void *)&no_dual_current, &opt_size)) + || (((socklen_t)sizeof(no_dual_current)) < opt_size)) { state_unknown = true; state_match = false; @@ -830,21 +830,21 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, else { state_unknown = false; - state_match = ((! ! no_dual_current) == (! ! no_dual_to_set)); + state_match = ((!!no_dual_current) == (!!no_dual_to_set)); } - if (state_unknown || ! state_match) + if (state_unknown || !state_match) { if (mhd_SKT_IP_V4_WITH_V6_OPT == sk_type) { - (void) mhd_socket_close (sk); + (void)mhd_socket_close (sk); return create_bind_listen_stream_socket_inner (d, s, true, false, prev_bnd_lstn_err); } - if (! state_unknown) + if (!state_unknown) { /* The dual-stack state is definitely wrong */ if (mhd_SKT_IP_V6_ONLY == sk_type) @@ -885,27 +885,27 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, } } } -#else /* ! IPV6_V6ONLY */ +# else /* ! IPV6_V6ONLY */ mhd_assert (mhd_SKT_IP_DUAL_REQUIRED != sk_type); mhd_assert (mhd_SKT_IP_V4_WITH_V6_OPT != sk_type); mhd_assert (mhd_SKT_IP_V6_WITH_V4_OPT != sk_type); -#endif /* ! IPV6_V6ONLY */ +# endif /* ! IPV6_V6ONLY */ #endif /* HAVE_INET6 */ if (MHD_FOM_AUTO <= d->settings->tcp_fastopen.v_option) { #if defined(HAVE_DCLR_TCP_FASTOPEN) int fo_param; -#ifdef __linux__ +# ifdef __linux__ /* The parameter is the queue length */ - fo_param = (int) d->settings->tcp_fastopen.v_queue_length; + fo_param = (int)d->settings->tcp_fastopen.v_queue_length; if (0 == fo_param) fo_param = MHD_TCP_FASTOPEN_DEF_QUEUE_LEN; -#else /* ! __linux__ */ +# else /* ! __linux__ */ fo_param = 1; /* The parameter is on/off type of setting */ -#endif /* ! __linux__ */ +# endif /* ! __linux__ */ if (0 != mhd_setsockopt (sk, IPPROTO_TCP, TCP_FASTOPEN, - (const void *) &fo_param, + (const void *)&fo_param, sizeof (fo_param))) { mhd_LOG_MSG (d, MHD_SC_LISTEN_FAST_OPEN_FAILURE, \ @@ -931,34 +931,34 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, if (MHD_D_OPTION_BIND_TYPE_NOT_SHARED >= d->settings->listen_addr_reuse) { #ifndef MHD_SOCKETS_KIND_WINSOCK -#ifdef HAVE_DCLR_SO_REUSEADDR +# ifdef HAVE_DCLR_SO_REUSEADDR mhd_SCKT_OPT_BOOL on_val1 = 1; if (0 != mhd_setsockopt (sk, SOL_SOCKET, SO_REUSEADDR, - (const void *) &on_val1, sizeof (on_val1))) + (const void *)&on_val1, sizeof (on_val1))) { mhd_LOG_MSG (d, MHD_SC_LISTEN_PORT_REUSE_ENABLE_FAILED, \ "OS refused to enable address reuse on " \ "the listen socket"); } -#else /* ! SO_REUSEADDR */ +# else /* ! SO_REUSEADDR */ mhd_LOG_MSG (d, MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_NOT_SUPPORTED, \ "The OS does not support address reuse for sockets"); -#endif /* ! SO_REUSEADDR */ +# endif /* ! SO_REUSEADDR */ #endif /* ! MHD_SOCKETS_KIND_WINSOCK */ if (MHD_D_OPTION_BIND_TYPE_NOT_SHARED > d->settings->listen_addr_reuse) { #if defined(HAVE_DCLR_SO_REUSEPORT) || defined(MHD_SOCKETS_KIND_WINSOCK) int opt_name; mhd_SCKT_OPT_BOOL on_val2 = 1; -#ifndef MHD_SOCKETS_KIND_WINSOCK +# ifndef MHD_SOCKETS_KIND_WINSOCK opt_name = SO_REUSEPORT; -#else /* ! MHD_SOCKETS_KIND_WINSOCK */ +# else /* ! MHD_SOCKETS_KIND_WINSOCK */ opt_name = SO_REUSEADDR; /* On W32 it is the same as SO_REUSEPORT on other platforms */ -#endif /* ! MHD_SOCKETS_KIND_WINSOCK */ +# endif /* ! MHD_SOCKETS_KIND_WINSOCK */ if (0 != mhd_setsockopt (sk, \ SOL_SOCKET, \ opt_name, \ - (const void *) &on_val2, \ + (const void *)&on_val2, \ sizeof (on_val2))) { mhd_LOG_MSG (d, MHD_SC_LISTEN_ADDRESS_REUSE_ENABLE_FAILED, \ @@ -981,15 +981,15 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, { int opt_name; mhd_SCKT_OPT_BOOL on_val = 1; -#ifdef SO_EXCLUSIVEADDRUSE +# ifdef SO_EXCLUSIVEADDRUSE opt_name = SO_EXCLUSIVEADDRUSE; -#else +# else opt_name = SO_EXCLBIND; -#endif +# endif if (0 != mhd_setsockopt (sk, \ SOL_SOCKET, \ opt_name, \ - (const void *) &on_val, \ + (const void *)&on_val, \ sizeof (on_val))) { mhd_LOG_MSG (d, MHD_SC_LISTEN_ADDRESS_EXCLUSIVE_ENABLE_FAILED, \ @@ -1010,7 +1010,7 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, #ifdef HAVE_INET6 if (mhd_SKT_IP_V4_WITH_FALLBACK == sk_type) { - (void) mhd_socket_close (sk); + (void)mhd_socket_close (sk); return create_bind_listen_stream_socket_inner (d, s, v6_tried, @@ -1019,7 +1019,7 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, } if (mhd_SKT_IP_V4_WITH_V6_OPT == sk_type) { - (void) mhd_socket_close (sk); + (void)mhd_socket_close (sk); return create_bind_listen_stream_socket_inner (d, s, true, @@ -1033,7 +1033,7 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, if (1) { int accept_queue_len; - accept_queue_len = (int) s->listen_backlog; + accept_queue_len = (int)s->listen_backlog; if (0 > accept_queue_len) accept_queue_len = 0; if (0 == accept_queue_len) @@ -1050,7 +1050,7 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, #ifdef HAVE_INET6 if (mhd_SKT_IP_V4_WITH_FALLBACK == sk_type) { - (void) mhd_socket_close (sk); + (void)mhd_socket_close (sk); return create_bind_listen_stream_socket_inner (d, s, v6_tried, @@ -1059,7 +1059,7 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, } if (mhd_SKT_IP_V4_WITH_V6_OPT == sk_type) { - (void) mhd_socket_close (sk); + (void)mhd_socket_close (sk); return create_bind_listen_stream_socket_inner (d, s, true, @@ -1073,10 +1073,10 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, } /* A valid listening socket is ready here */ - if (! is_non_block) + if (!is_non_block) { is_non_block = mhd_socket_nonblocking (sk); - if (! is_non_block) + if (!is_non_block) mhd_LOG_MSG (d, MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE, \ "OS refused to make the listen socket non-blocking"); } @@ -1119,7 +1119,7 @@ create_bind_listen_stream_socket_inner (struct MHD_Daemon *restrict d, mhd_assert (MHD_SC_OK != ret); /* This should be only error returns here */ mhd_assert (MHD_INVALID_SOCKET != sk); - (void) mhd_socket_close (sk); + (void)mhd_socket_close (sk); return ret; } @@ -1174,7 +1174,7 @@ detect_listen_type_and_port (struct MHD_Daemon *restrict d) mhd_assert (MHD_INVALID_SOCKET != d->net.listen.fd); mhd_assert (0 == d->net.listen.port); memset (&sa_all, 0, sizeof(sa_all)); /* Actually not required */ - sa_size = (socklen_t) sizeof(sa_all); + sa_size = (socklen_t)sizeof(sa_all); if (0 != getsockname (d->net.listen.fd, &(sa_all.sa), &sa_size)) { @@ -1187,13 +1187,13 @@ detect_listen_type_and_port (struct MHD_Daemon *restrict d) declared_type = d->net.listen.type; if (0 == sa_size) { -#ifndef __linux__ +# ifndef __linux__ /* Used on some non-Linux platforms */ d->net.listen.type = mhd_SOCKET_TYPE_UNIX; d->net.listen.port = 0; -#else /* ! __linux__ */ - (void) 0; -#endif /* ! __linux__ */ +# else /* ! __linux__ */ + (void)0; +# endif /* ! __linux__ */ } else { @@ -1201,20 +1201,20 @@ detect_listen_type_and_port (struct MHD_Daemon *restrict d) { case AF_INET: d->net.listen.type = mhd_SOCKET_TYPE_IP; - d->net.listen.port = (uint_least16_t) ntohs (sa_all.sa_i4.sin_port); + d->net.listen.port = (uint_least16_t)ntohs (sa_all.sa_i4.sin_port); break; -#ifdef HAVE_INET6 +# ifdef HAVE_INET6 case AF_INET6: d->net.listen.type = mhd_SOCKET_TYPE_IP; - d->net.listen.port = (uint_least16_t) ntohs (sa_all.sa_i6.sin6_port); + d->net.listen.port = (uint_least16_t)ntohs (sa_all.sa_i6.sin6_port); break; -#endif /* HAVE_INET6 */ -#ifdef MHD_AF_UNIX +# endif /* HAVE_INET6 */ +# ifdef MHD_AF_UNIX case MHD_AF_UNIX: d->net.listen.type = mhd_SOCKET_TYPE_UNIX; d->net.listen.port = 0; break; -#endif /* MHD_AF_UNIX */ +# endif /* MHD_AF_UNIX */ default: d->net.listen.type = mhd_SOCKET_TYPE_UNKNOWN; d->net.listen.port = 0; @@ -1255,19 +1255,19 @@ init_epoll_fd (struct MHD_Daemon *restrict d, { int e_fd; mhd_ASSUME (early_probing || log_failures); - mhd_assert ((mhd_POLL_TYPE_EPOLL == d->events.poll_type) || - (mhd_POLL_TYPE_NOT_SET_YET == d->events.poll_type)); - mhd_assert (! mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); + mhd_assert ((mhd_POLL_TYPE_EPOLL == d->events.poll_type) + || (mhd_POLL_TYPE_NOT_SET_YET == d->events.poll_type)); + mhd_assert (!mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); mhd_assert (early_probing || d->dbg.net_inited); - mhd_assert (! early_probing || ! d->dbg.net_inited); - mhd_assert ((mhd_POLL_TYPE_EPOLL != d->events.poll_type) || \ - (NULL == d->events.data.epoll.events)); + mhd_assert (!early_probing || !d->dbg.net_inited); + mhd_assert ((mhd_POLL_TYPE_EPOLL != d->events.poll_type) \ + || (NULL == d->events.data.epoll.events)); - if (! early_probing) + if (!early_probing) { /* Full events initialisation */ mhd_ASSUME (mhd_POLL_TYPE_EPOLL == d->events.poll_type); - if (! mhd_D_HAS_MASTER (d)) + if (!mhd_D_HAS_MASTER (d)) { mhd_assert (0 < d->events.data.epoll.early_fd); /* Move early initialised epoll FD */ @@ -1275,7 +1275,7 @@ init_epoll_fd (struct MHD_Daemon *restrict d, d->events.data.epoll.early_fd = MHD_INVALID_SOCKET; return MHD_SC_OK; } -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS else { /* Worker daemon */ @@ -1293,22 +1293,22 @@ init_epoll_fd (struct MHD_Daemon *restrict d, } /* Process with new epoll FD creation */ } -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ } else mhd_ASSUME (mhd_POLL_TYPE_NOT_SET_YET == d->events.poll_type); -#ifdef HAVE_EPOLL_CREATE1 +# ifdef HAVE_EPOLL_CREATE1 e_fd = epoll_create1 (EPOLL_CLOEXEC); -#else /* ! HAVE_EPOLL_CREATE1 */ +# else /* ! HAVE_EPOLL_CREATE1 */ e_fd = epoll_create (128); /* The number is usually ignored */ if (0 <= e_fd) { - if (! mhd_socket_noninheritable (e_fd)) + if (!mhd_socket_noninheritable (e_fd)) mhd_LOG_MSG (d, MHD_SC_EPOLL_CTL_CONFIGURE_NOINHERIT_FAILED, \ "Failed to make epoll control FD non-inheritable"); } -#endif /* ! HAVE_EPOLL_CREATE1 */ +# endif /* ! HAVE_EPOLL_CREATE1 */ if (0 > e_fd) { if (log_failures) @@ -1317,18 +1317,18 @@ init_epoll_fd (struct MHD_Daemon *restrict d, return MHD_SC_EPOLL_CTL_CREATE_FAILED; /* Failure exit point */ } - if (! mhd_FD_FITS_DAEMON (d, e_fd)) + if (!mhd_FD_FITS_DAEMON (d, e_fd)) { if (log_failures) mhd_LOG_MSG (d, MHD_SC_EPOLL_CTL_OUTSIDE_OF_SET_RANGE, \ "The epoll control FD value is higher than allowed"); - (void) close (e_fd); + (void)close (e_fd); return MHD_SC_EPOLL_CTL_OUTSIDE_OF_SET_RANGE; /* Failure exit point */ } /* Needs to be set here as setting epoll data member 'early_fd' */ d->events.poll_type = mhd_POLL_TYPE_EPOLL; - if (! early_probing) + if (!early_probing) d->events.data.epoll.e_fd = e_fd; else d->events.data.epoll.early_fd = e_fd; @@ -1370,9 +1370,9 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, mhd_assert (mhd_POLL_TYPE_NOT_SET_YET == d->events.poll_type); - mhd_assert ((mhd_WM_INT_EXTERNAL_EVENTS_EDGE != d->wmode_int) || \ - (mhd_WM_INT_EXTERNAL_EVENTS_LEVEL != d->wmode_int) || \ - (MHD_SPS_AUTO == s->poll_syscall)); + mhd_assert ((mhd_WM_INT_EXTERNAL_EVENTS_EDGE != d->wmode_int) \ + || (mhd_WM_INT_EXTERNAL_EVENTS_LEVEL != d->wmode_int) \ + || (MHD_SPS_AUTO == s->poll_syscall)); /* Check whether the provided parameter is in the range of expected values. Reject unsupported or disabled values. */ @@ -1382,7 +1382,7 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, chosen_type = mhd_POLL_TYPE_NOT_SET_YET; break; case MHD_SPS_SELECT: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); #ifndef MHD_SUPPORT_SELECT mhd_LOG_MSG (d, MHD_SC_SELECT_SYSCALL_NOT_AVAILABLE, \ "'select()' is not supported by the platform or " \ @@ -1393,7 +1393,7 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, #endif /* MHD_SUPPORT_SELECT */ break; case MHD_SPS_POLL: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); #ifndef MHD_SUPPORT_POLL mhd_LOG_MSG (d, MHD_SC_POLL_SYSCALL_NOT_AVAILABLE, \ "'poll()' is not supported by the platform or " \ @@ -1404,8 +1404,8 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, #endif /* MHD_SUPPORT_POLL */ break; case MHD_SPS_EPOLL: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); - mhd_assert (! mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); #ifndef MHD_SUPPORT_EPOLL mhd_LOG_MSG (d, MHD_SC_EPOLL_SYSCALL_NOT_AVAILABLE, \ "'epoll' is not supported by the platform or " \ @@ -1416,8 +1416,8 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, #endif /* MHD_SUPPORT_EPOLL */ break; case MHD_SPS_KQUEUE: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); - mhd_assert (! mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); #ifndef MHD_SUPPORT_KQUEUE mhd_LOG_MSG (d, MHD_SC_KQUEUE_SYSCALL_NOT_AVAILABLE, \ "'kqueue' is not supported by the platform or " \ @@ -1434,14 +1434,14 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, } #ifdef MHD_SUPPORT_HTTPS - if ((mhd_WM_INT_EXTERNAL_EVENTS_EDGE == (d)->wmode_int) || - mhd_POLL_TYPE_INT_IS_EDGE_TRIG (chosen_type)) + if ((mhd_WM_INT_EXTERNAL_EVENTS_EDGE == (d)->wmode_int) + || mhd_POLL_TYPE_INT_IS_EDGE_TRIG (chosen_type)) { /* Edge-triggered polling chosen */ if (MHD_TLS_BACKEND_NONE != s->tls) { - if (! mhd_tls_is_edge_trigg_supported (s)) + if (!mhd_tls_is_edge_trigg_supported (s)) { -#ifdef MHD_SUPPORT_LOG_FUNCTIONALITY +# ifdef MHD_SUPPORT_LOG_FUNCTIONALITY if (MHD_TLS_BACKEND_ANY == s->tls) mhd_LOG_MSG (d, MHD_SC_TLS_BACKEND_DAEMON_INCOMPATIBLE_SETTINGS, \ "Edge-triggered sockets polling cannot be used " @@ -1450,7 +1450,7 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, mhd_LOG_MSG (d, MHD_SC_TLS_BACKEND_DAEMON_INCOMPATIBLE_SETTINGS, \ "Edge-triggered sockets polling cannot be used " "with selected TLS backend"); -#endif /* MHD_SUPPORT_LOG_FUNCTIONALITY */ +# endif /* MHD_SUPPORT_LOG_FUNCTIONALITY */ return MHD_SC_TLS_BACKEND_DAEMON_INCOMPATIBLE_SETTINGS; } } @@ -1458,8 +1458,8 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, #endif /* MHD_SUPPORT_HTTPS */ mhd_assert (mhd_POLL_TYPE_EXT != chosen_type); - mhd_ASSUME ((mhd_POLL_TYPE_NOT_SET_YET != chosen_type) || \ - (MHD_SPS_AUTO == s->poll_syscall)); + mhd_ASSUME ((mhd_POLL_TYPE_NOT_SET_YET != chosen_type) \ + || (MHD_SPS_AUTO == s->poll_syscall)); if (mhd_POLL_TYPE_NOT_SET_YET == chosen_type) { @@ -1478,8 +1478,8 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, et_allowed = true; if (mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)) { - mhd_assert (! mhd_POLL_TYPE_INT_IS_KQUEUE (chosen_type)); - mhd_assert (! mhd_POLL_TYPE_INT_IS_EPOLL (chosen_type)); + mhd_assert (!mhd_POLL_TYPE_INT_IS_KQUEUE (chosen_type)); + mhd_assert (!mhd_POLL_TYPE_INT_IS_EPOLL (chosen_type)); et_allowed = false; } # ifdef MHD_SUPPORT_HTTPS @@ -1522,8 +1522,8 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, mhd_assert (mhd_POLL_TYPE_NOT_SET_YET == chosen_type); } # ifdef MHD_SUPPORT_EPOLL - mhd_assert ((mhd_POLL_TYPE_EPOLL != d->events.poll_type) || \ - (0 < d->events.data.epoll.early_fd)); + mhd_assert ((mhd_POLL_TYPE_EPOLL != d->events.poll_type) \ + || (0 < d->events.data.epoll.early_fd)); mhd_assert ((mhd_POLL_TYPE_EPOLL == d->events.poll_type) == \ (mhd_POLL_TYPE_EPOLL == chosen_type)); # endif /* ! MHD_SUPPORT_EPOLL */ @@ -1546,8 +1546,8 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, switch (chosen_type) { case mhd_POLL_TYPE_EXT: - mhd_assert ((MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL == s->work_mode.mode) || \ - (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE == s->work_mode.mode)); + mhd_assert ((MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL == s->work_mode.mode) \ + || (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE == s->work_mode.mode)); mhd_assert (mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); d->events.poll_type = mhd_POLL_TYPE_EXT; d->events.data.extr.cb_data.cb = @@ -1562,7 +1562,7 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, break; #ifdef MHD_SUPPORT_SELECT case mhd_POLL_TYPE_SELECT: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); mhd_assert (MHD_WM_EXTERNAL_SINGLE_FD_WATCH != s->work_mode.mode); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL != s->work_mode.mode); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE != s->work_mode.mode); @@ -1575,7 +1575,7 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, #endif /* MHD_SUPPORT_SELECT */ #ifdef MHD_SUPPORT_POLL case mhd_POLL_TYPE_POLL: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); mhd_assert (MHD_WM_EXTERNAL_SINGLE_FD_WATCH != s->work_mode.mode); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL != s->work_mode.mode); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE != s->work_mode.mode); @@ -1587,7 +1587,7 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, #endif /* MHD_SUPPORT_POLL */ #ifdef MHD_SUPPORT_EPOLL case mhd_POLL_TYPE_EPOLL: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL != s->work_mode.mode); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE != s->work_mode.mode); mhd_assert (MHD_NO == s->reregister_all); @@ -1600,7 +1600,7 @@ daemon_choose_and_preinit_events (struct MHD_Daemon *restrict d, #endif /* MHD_SUPPORT_EPOLL */ #ifdef MHD_SUPPORT_KQUEUE case mhd_POLL_TYPE_KQUEUE: - mhd_assert (! mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_LEVEL != s->work_mode.mode); mhd_assert (MHD_WM_EXTERNAL_EVENT_LOOP_CB_EDGE != s->work_mode.mode); mhd_assert (MHD_NO == s->reregister_all); @@ -1640,8 +1640,8 @@ daemon_init_net (struct MHD_Daemon *restrict d, { enum MHD_StatusCode ret; - mhd_assert (! d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_inited); + mhd_assert (!d->dbg.net_deinited); #ifdef MHD_SOCKETS_KIND_POSIX d->net.cfg.max_fd_num = s->fd_number_limit; #endif /* MHD_SOCKETS_KIND_POSIX */ @@ -1658,8 +1658,8 @@ daemon_init_net (struct MHD_Daemon *restrict d, #if defined(MHD_SOCKETS_KIND_POSIX) && defined(MHD_SUPPORT_SELECT) if (mhd_POLL_TYPE_SELECT == d->events.poll_type) { - if ((MHD_INVALID_SOCKET == d->net.cfg.max_fd_num) || - (FD_SETSIZE < d->net.cfg.max_fd_num)) + if ((MHD_INVALID_SOCKET == d->net.cfg.max_fd_num) + || (FD_SETSIZE < d->net.cfg.max_fd_num)) d->net.cfg.max_fd_num = FD_SETSIZE; } #endif /* MHD_SOCKETS_KIND_POSIX && MHD_SUPPORT_SELECT */ @@ -1671,9 +1671,9 @@ daemon_init_net (struct MHD_Daemon *restrict d, if (MHD_SC_OK == ret) { if ((MHD_INVALID_SOCKET != d->net.listen.fd) - && ! d->net.listen.non_block - && (mhd_D_HAS_EDGE_TRIGG (d) || - mhd_WM_INT_IS_THREAD_POOL (d->wmode_int))) + && !d->net.listen.non_block + && (mhd_D_HAS_EDGE_TRIGG (d) + || mhd_WM_INT_IS_THREAD_POOL (d->wmode_int))) { mhd_LOG_MSG (d, MHD_SC_LISTEN_SOCKET_NONBLOCKING_FAILURE, \ "The selected daemon work mode requires listening socket " @@ -1683,9 +1683,9 @@ daemon_init_net (struct MHD_Daemon *restrict d, if (MHD_SC_OK == ret) { - if ((MHD_INVALID_SOCKET != d->net.listen.fd) && - ((0 == d->net.listen.port) || - (mhd_SOCKET_TYPE_UNKNOWN == d->net.listen.type))) + if ((MHD_INVALID_SOCKET != d->net.listen.fd) + && ((0 == d->net.listen.port) + || (mhd_SOCKET_TYPE_UNKNOWN == d->net.listen.type))) detect_listen_type_and_port (d); #ifndef NDEBUG @@ -1725,14 +1725,14 @@ MHD_FN_PAR_NONNULL_ (1) static void daemon_deinit_net (struct MHD_Daemon *restrict d) { mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (mhd_POLL_TYPE_NOT_SET_YET != d->events.poll_type); #ifdef MHD_SUPPORT_EPOLL /* Special case for epoll: epoll FD is probed early in events pre-initialisation and could be not moved yet to events epoll FD therefore it needs cleanup here */ - if ((mhd_POLL_TYPE_EPOLL == d->events.poll_type) && - (MHD_INVALID_SOCKET != d->events.data.epoll.early_fd)) + if ((mhd_POLL_TYPE_EPOLL == d->events.poll_type) + && (MHD_INVALID_SOCKET != d->events.data.epoll.early_fd)) { mhd_assert (0 < d->events.data.epoll.early_fd); close (d->events.data.epoll.early_fd); @@ -1752,10 +1752,10 @@ void dauth_init (struct MHD_Daemon *restrict d, struct DaemonOptions *restrict s) { - mhd_assert ((NULL == s->random_entropy.v_buf) || \ - (0 != s->random_entropy.v_buf_size)); - mhd_assert ((0 == s->random_entropy.v_buf_size) || \ - (NULL != s->random_entropy.v_buf)); + mhd_assert ((NULL == s->random_entropy.v_buf) \ + || (0 != s->random_entropy.v_buf_size)); + mhd_assert ((0 == s->random_entropy.v_buf_size) \ + || (NULL != s->random_entropy.v_buf)); } @@ -1780,10 +1780,10 @@ daemon_init_auth_digest (struct MHD_Daemon *restrict d, if (0 == s->random_entropy.v_buf_size) { /* No initialisation needed */ -#ifndef HAVE_NULL_PTR_ALL_ZEROS +# ifndef HAVE_NULL_PTR_ALL_ZEROS d->auth_dg.entropy.data = NULL; d->auth_dg.nonces = NULL; -#endif +# endif return MHD_SC_OK; } nonces_num = s->auth_digest_map_size; @@ -1801,7 +1801,7 @@ daemon_init_auth_digest (struct MHD_Daemon *restrict d, } d->auth_dg.cfg.nonces_num = nonces_num; - if (! mhd_mutex_init (&(d->auth_dg.nonces_lock))) + if (!mhd_mutex_init (&(d->auth_dg.nonces_lock))) { mhd_LOG_MSG (d, MHD_SC_MUTEX_INIT_FAILURE, \ "Failed to initialise mutex for the Digest Auth data"); @@ -1809,7 +1809,7 @@ daemon_init_auth_digest (struct MHD_Daemon *restrict d, } else { - if (! mhd_atomic_counter_init (&(d->auth_dg.num_gen_nonces), 0)) + if (!mhd_atomic_counter_init (&(d->auth_dg.num_gen_nonces), 0)) { mhd_LOG_MSG (d, MHD_SC_MUTEX_INIT_FAILURE, \ "Failed to initialise mutex for the Digest Auth data"); @@ -1818,7 +1818,7 @@ daemon_init_auth_digest (struct MHD_Daemon *restrict d, else { /* Move ownership of the entropy buffer */ - d->auth_dg.entropy.data = (char *) s->random_entropy.v_buf; + d->auth_dg.entropy.data = (char *)s->random_entropy.v_buf; d->auth_dg.entropy.size = s->random_entropy.v_buf_size; s->random_entropy.v_buf = NULL; s->random_entropy.v_buf_size = 0; @@ -1861,8 +1861,8 @@ daemon_deinit_auth_digest (struct MHD_Daemon *restrict d) #else /* MHD_SUPPORT_AUTH_DIGEST */ -#define daemon_init_auth_digest(d,s) (MHD_SC_OK) -#define daemon_deinit_auth_digest(d) ((void) 0) +# define daemon_init_auth_digest(d, s) (MHD_SC_OK) +# define daemon_deinit_auth_digest(d) ((void) 0) #endif /* MHD_SUPPORT_AUTH_DIGEST */ @@ -1882,7 +1882,7 @@ daemon_init_tls (struct MHD_Daemon *restrict d, mhd_StatusCodeInt ret; #endif /* MHD_SUPPORT_HTTPS */ - mhd_assert (! d->dbg.tls_inited); + mhd_assert (!d->dbg.tls_inited); #ifdef MHD_SUPPORT_HTTPS d->tls = NULL; #endif @@ -1927,10 +1927,10 @@ daemon_init_tls (struct MHD_Daemon *restrict d, &(d->tls)); mhd_assert ((MHD_SC_OK == ret) || (NULL == d->tls)); mhd_assert ((MHD_SC_OK != ret) || (NULL != d->tls)); -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.tls_inited = (MHD_SC_OK == ret); -#endif - return (enum MHD_StatusCode) ret; +# endif + return (enum MHD_StatusCode)ret; #endif /* MHD_SUPPORT_HTTPS */ } @@ -1950,7 +1950,7 @@ daemon_deinit_tls (struct MHD_Daemon *restrict d) mhd_tls_daemon_deinit (d->tls); } #elif defined(NDEBUG) - (void) d; /* Mute compiler warning */ + (void)d; /* Mute compiler warning */ #endif } @@ -1967,7 +1967,7 @@ static MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) \ daemon_init_large_buf (struct MHD_Daemon *restrict d, struct DaemonOptions *restrict s) { - mhd_assert (! mhd_D_HAS_MASTER (d)); + mhd_assert (!mhd_D_HAS_MASTER (d)); mhd_assert (0 != d->conns.cfg.count_limit); mhd_assert (0 != d->conns.cfg.mem_pool_size); @@ -1980,7 +1980,7 @@ daemon_init_large_buf (struct MHD_Daemon *restrict d, d->dbg.initial_lbuf_size = d->req_cfg.large_buf.space_left; #endif - if (! mhd_mutex_init_short (&(d->req_cfg.large_buf.lock))) + if (!mhd_mutex_init_short (&(d->req_cfg.large_buf.lock))) { mhd_LOG_MSG (d, MHD_SC_MUTEX_INIT_FAILURE, \ "Failed to initialise mutex for the global large buffer."); @@ -2016,7 +2016,7 @@ init_kqueue_fd (struct MHD_Daemon *restrict d) { int kq_fd; mhd_assert (mhd_POLL_TYPE_KQUEUE == d->events.poll_type); - mhd_assert (! mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); + mhd_assert (!mhd_WM_INT_IS_THREAD_PER_CONN (d->wmode_int)); mhd_assert (d->dbg.net_inited); mhd_assert (MHD_INVALID_SOCKET == d->events.data.kq.kq_fd); mhd_assert (NULL == d->events.data.kq.kes); @@ -2030,17 +2030,17 @@ init_kqueue_fd (struct MHD_Daemon *restrict d) return MHD_SC_KQUEUE_FD_CREATE_FAILED; /* Failure exit point */ } - if (! mhd_FD_FITS_DAEMON (d, kq_fd)) + if (!mhd_FD_FITS_DAEMON (d, kq_fd)) { mhd_LOG_MSG (d, MHD_SC_KQUEUE_FD_OUTSIDE_OF_SET_RANGE, \ "The kqueue FD value is higher than allowed"); - (void) close (kq_fd); + (void)close (kq_fd); return MHD_SC_KQUEUE_FD_OUTSIDE_OF_SET_RANGE; /* Failure exit point */ } - if (! mhd_KQUEUE_HAS_CLOEXEC_SET ()) + if (!mhd_KQUEUE_HAS_CLOEXEC_SET ()) { - if (! mhd_socket_noninheritable (kq_fd)) + if (!mhd_socket_noninheritable (kq_fd)) mhd_LOG_MSG (d, MHD_SC_KQUEUE_FD_SET_NOINHERIT_FAILED, \ "Failed to make kqueue FD non-inheritable"); } @@ -2185,20 +2185,20 @@ allocate_events (struct MHD_Daemon *restrict d) */ unsigned int num_fd_elems; num_fd_elems = 0; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS ++num_fd_elems; /* For the ITC */ -#endif +# endif if (MHD_INVALID_SOCKET != d->net.listen.fd) ++num_fd_elems; /* For the listening socket */ - if (! mhd_D_HAS_THR_PER_CONN (d)) + if (!mhd_D_HAS_THR_PER_CONN (d)) num_fd_elems += d->conns.cfg.count_limit; #endif /* MHD_SUPPORT_POLL || MHD_SUPPORT_EPOLL */ mhd_assert (0 != d->conns.cfg.count_limit); mhd_assert (mhd_D_TYPE_HAS_EVENTS_PROCESSING (d->threading.d_type)); - mhd_assert (! d->dbg.events_allocated); + mhd_assert (!d->dbg.events_allocated); - mhd_DLINKEDL_INIT_LIST (&(d->events),proc_ready); + mhd_DLINKEDL_INIT_LIST (&(d->events), proc_ready); switch (d->events.poll_type) { @@ -2216,19 +2216,19 @@ allocate_events (struct MHD_Daemon *restrict d) mhd_assert (NULL == d->events.data.select.rfds); mhd_assert (NULL == d->events.data.select.wfds); mhd_assert (NULL == d->events.data.select.efds); - d->events.data.select.rfds = (fd_set *) malloc (sizeof(fd_set)); + d->events.data.select.rfds = (fd_set *)malloc (sizeof(fd_set)); if (NULL != d->events.data.select.rfds) { - d->events.data.select.wfds = (fd_set *) malloc (sizeof(fd_set)); + d->events.data.select.wfds = (fd_set *)malloc (sizeof(fd_set)); if (NULL != d->events.data.select.wfds) { - d->events.data.select.efds = (fd_set *) malloc (sizeof(fd_set)); + d->events.data.select.efds = (fd_set *)malloc (sizeof(fd_set)); if (NULL != d->events.data.select.efds) { -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.num_events_elements = FD_SETSIZE; d->dbg.events_allocated = true; -#endif +# endif return MHD_SC_OK; /* Success exit point */ } @@ -2250,18 +2250,18 @@ allocate_events (struct MHD_Daemon *restrict d) || (mhd_D_HAS_THR_PER_CONN (d))) { d->events.data.poll.fds = - (struct pollfd *) malloc (sizeof(struct pollfd) * num_fd_elems); + (struct pollfd *)malloc (sizeof(struct pollfd) * num_fd_elems); if (NULL != d->events.data.poll.fds) { d->events.data.poll.rel = - (union mhd_SocketRelation *) malloc (sizeof(union mhd_SocketRelation) - * num_fd_elems); + (union mhd_SocketRelation *)malloc (sizeof(union mhd_SocketRelation) + * num_fd_elems); if (NULL != d->events.data.poll.rel) { -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.num_events_elements = num_fd_elems; d->dbg.events_allocated = true; -#endif +# endif return MHD_SC_OK; /* Success exit point */ } free (d->events.data.poll.fds); @@ -2274,7 +2274,7 @@ allocate_events (struct MHD_Daemon *restrict d) #endif /* MHD_SUPPORT_POLL */ #ifdef MHD_SUPPORT_EPOLL case mhd_POLL_TYPE_EPOLL: - mhd_ASSUME (! mhd_D_HAS_THR_PER_CONN (d)); + mhd_ASSUME (!mhd_D_HAS_THR_PER_CONN (d)); /* The event FD has been created by event FD initialisation */ mhd_assert (MHD_INVALID_SOCKET != d->events.data.epoll.e_fd); mhd_assert (MHD_INVALID_SOCKET == d->events.data.epoll.early_fd); @@ -2283,10 +2283,10 @@ allocate_events (struct MHD_Daemon *restrict d) mhd_assert (0 == d->events.data.epoll.num_elements); if (1) { - const unsigned int upper_limit = (sizeof(void*) >= 8) ? 4096u : 1024u; + const unsigned int upper_limit = (sizeof(void *) >= 8) ? 4096u : 1024u; - mhd_assert (0 < (int) upper_limit); - mhd_assert (upper_limit == (unsigned int) (size_t) upper_limit); + mhd_assert (0 < (int)upper_limit); + mhd_assert (upper_limit == (unsigned int)(size_t)upper_limit); if (num_fd_elems < d->conns.cfg.count_limit) /* Check for value overflow */ num_fd_elems = upper_limit; @@ -2296,15 +2296,15 @@ allocate_events (struct MHD_Daemon *restrict d) num_fd_elems = upper_limit; d->events.data.epoll.events = - (struct epoll_event *) malloc (sizeof(struct epoll_event) - * num_fd_elems); + (struct epoll_event *)malloc (sizeof(struct epoll_event) + * num_fd_elems); if (NULL != d->events.data.epoll.events) { d->events.data.epoll.num_elements = num_fd_elems; -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.num_events_elements = num_fd_elems; d->dbg.events_allocated = true; -#endif +# endif return MHD_SC_OK; /* Success exit point */ } } @@ -2315,7 +2315,7 @@ allocate_events (struct MHD_Daemon *restrict d) #endif /* MHD_SUPPORT_EPOLL */ #ifdef MHD_SUPPORT_KQUEUE case mhd_POLL_TYPE_KQUEUE: - mhd_ASSUME (! mhd_D_HAS_THR_PER_CONN (d)); + mhd_ASSUME (!mhd_D_HAS_THR_PER_CONN (d)); /* The event FD has been created by event FD initialisation */ mhd_assert (0 < d->events.data.kq.kq_fd); /* The pointer has been set to NULL during pre-initialisation of the events */ @@ -2323,15 +2323,15 @@ allocate_events (struct MHD_Daemon *restrict d) mhd_assert (0u == d->events.data.kq.num_elements); if (1) { - const unsigned int upper_limit = (sizeof(void*) >= 8) ? 4096u : 1024u; + const unsigned int upper_limit = (sizeof(void *) >= 8) ? 4096u : 1024u; unsigned int num_event_elems = 0; - mhd_assert (0 < (int) upper_limit); - mhd_assert (upper_limit == (unsigned int) (size_t) upper_limit); + mhd_assert (0 < (int)upper_limit); + mhd_assert (upper_limit == (unsigned int)(size_t)upper_limit); -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS ++num_event_elems; /* For the ITC */ -#endif +# endif if (MHD_INVALID_SOCKET != d->net.listen.fd) ++num_event_elems; /* For the listening socket */ @@ -2345,18 +2345,18 @@ allocate_events (struct MHD_Daemon *restrict d) num_event_elems = upper_limit; /* Make sure that run-time overflow check is easy */ - mhd_assert (((int) num_event_elems) > 0); - mhd_assert (((int) (num_event_elems + 1)) > 0); + mhd_assert (((int)num_event_elems) > 0); + mhd_assert (((int)(num_event_elems + 1)) > 0); d->events.data.kq.kes = - (struct kevent *) malloc (sizeof(struct kevent) * num_event_elems); + (struct kevent *)malloc (sizeof(struct kevent) * num_event_elems); if (NULL != d->events.data.kq.kes) { d->events.data.kq.num_elements = num_event_elems; -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.num_events_elements = num_event_elems; d->dbg.events_allocated = true; -#endif +# endif return MHD_SC_OK; /* Success exit point */ } } @@ -2458,39 +2458,39 @@ init_itc (struct MHD_Daemon *restrict d) mhd_assert (mhd_D_TYPE_HAS_EVENTS_PROCESSING (d->threading.d_type)); #ifdef MHD_SUPPORT_THREADS // TODO: add and process "thread unsafe" daemon's option - if (! mhd_itc_init (&(d->threading.itc))) + if (!mhd_itc_init (&(d->threading.itc))) { -#if defined(MHD_ITC_EVENTFD_) +# if defined(MHD_ITC_EVENTFD_) mhd_LOG_MSG ( \ d, MHD_SC_ITC_INITIALIZATION_FAILED, \ "Failed to initialise eventFD for inter-thread communication"); -#elif defined(MHD_ITC_PIPE_) +# elif defined(MHD_ITC_PIPE_) mhd_LOG_MSG ( \ d, MHD_SC_ITC_INITIALIZATION_FAILED, \ "Failed to create a pipe for inter-thread communication"); -#elif defined(MHD_ITC_SOCKETPAIR_) +# elif defined(MHD_ITC_SOCKETPAIR_) mhd_LOG_MSG ( \ d, MHD_SC_ITC_INITIALIZATION_FAILED, \ "Failed to create a socketpair for inter-thread communication"); -#else -#warning Missing expicit handling of the ITC type +# else +# warning Missing expicit handling of the ITC type mhd_LOG_MSG ( \ d, MHD_SC_ITC_INITIALIZATION_FAILED, \ "Failed to initialise inter-thread communication"); -#endif +# endif return MHD_SC_ITC_INITIALIZATION_FAILED; } - if (! mhd_FD_FITS_DAEMON (d,mhd_itc_r_fd (d->threading.itc))) + if (!mhd_FD_FITS_DAEMON (d, mhd_itc_r_fd (d->threading.itc))) { mhd_LOG_MSG (d, MHD_SC_ITC_FD_OUTSIDE_OF_SET_RANGE, \ "The inter-thread communication FD value is " \ "higher than allowed"); - (void) mhd_itc_destroy (d->threading.itc); + (void)mhd_itc_destroy (d->threading.itc); mhd_itc_set_invalid (&(d->threading.itc)); return MHD_SC_ITC_FD_OUTSIDE_OF_SET_RANGE; } #else /* ! MHD_SUPPORT_THREADS */ - (void) d; /* Unused */ + (void)d; /* Unused */ #endif /* ! MHD_SUPPORT_THREADS */ return MHD_SC_OK; } @@ -2507,10 +2507,10 @@ deinit_itc (struct MHD_Daemon *restrict d) mhd_assert (mhd_D_TYPE_HAS_EVENTS_PROCESSING (d->threading.d_type)); #ifdef MHD_SUPPORT_THREADS // TODO: add and process "thread unsafe" daemon's option - mhd_assert (! mhd_ITC_IS_INVALID (d->threading.itc)); - (void) mhd_itc_destroy (d->threading.itc); + mhd_assert (!mhd_ITC_IS_INVALID (d->threading.itc)); + (void)mhd_itc_destroy (d->threading.itc); #else /* ! MHD_SUPPORT_THREADS */ - (void) d; /* Unused */ + (void)d; /* Unused */ #endif /* ! MHD_SUPPORT_THREADS */ } @@ -2527,9 +2527,9 @@ MHD_FN_MUST_CHECK_RESULT_ enum MHD_StatusCode init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) { mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (d->dbg.events_allocated); - mhd_assert (! d->dbg.events_fully_inited); + mhd_assert (!d->dbg.events_fully_inited); mhd_assert (mhd_D_TYPE_HAS_EVENTS_PROCESSING (d->threading.d_type)); #ifdef MHD_SUPPORT_THREADS mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); @@ -2545,7 +2545,7 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) d->events.data.extr.itc_data.is_active = false; d->events.data.extr.itc_data.is_broken = false; #endif /* MHD_SUPPORT_THREADS */ - if (! d->events.data.extr.reg_all) + if (!d->events.data.extr.reg_all) { bool itc_reg_succeed; @@ -2584,12 +2584,12 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) /* Below is a clean-up path for 'case mhd_POLL_TYPE_EXT:' */ #ifdef MHD_SUPPORT_THREADS /* De-register ITC FD */ - (void) mhd_daemon_extr_event_reg (d, - mhd_itc_r_fd (d->threading.itc), - MHD_FD_STATE_NONE, - d->events.data.extr.itc_data.app_cntx, - (struct MHD_EventUpdateContext *) - mhd_SOCKET_REL_MARKER_ITC); + (void)mhd_daemon_extr_event_reg (d, + mhd_itc_r_fd (d->threading.itc), + MHD_FD_STATE_NONE, + d->events.data.extr.itc_data.app_cntx, + (struct MHD_EventUpdateContext *) + mhd_SOCKET_REL_MARKER_ITC); d->events.data.extr.itc_data.app_cntx = NULL; #endif /* MHD_SUPPORT_THREADS */ } @@ -2626,12 +2626,12 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) { unsigned int i; i = 0; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS d->events.data.poll.fds[i].fd = mhd_itc_r_fd (d->threading.itc); d->events.data.poll.fds[i].events = POLLIN; d->events.data.poll.rel[i].fd_id = mhd_SOCKET_REL_MARKER_ITC; ++i; -#endif +# endif if (MHD_INVALID_SOCKET != d->net.listen.fd) { d->events.data.poll.fds[i].fd = d->net.listen.fd; @@ -2651,9 +2651,9 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) if (1) { struct epoll_event reg_event; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS reg_event.events = EPOLLIN | EPOLLET; - reg_event.data.u64 = (uint64_t) mhd_SOCKET_REL_MARKER_ITC; /* uint64_t is used in the epoll header */ + reg_event.data.u64 = (uint64_t)mhd_SOCKET_REL_MARKER_ITC; /* uint64_t is used in the epoll header */ if (0 != epoll_ctl (d->events.data.epoll.e_fd, EPOLL_CTL_ADD, mhd_itc_r_fd (d->threading.itc), &reg_event)) { @@ -2666,11 +2666,11 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) true, \ false, \ false); -#endif +# endif if (MHD_INVALID_SOCKET != d->net.listen.fd) { reg_event.events = EPOLLIN; - reg_event.data.u64 = (uint64_t) mhd_SOCKET_REL_MARKER_LISTEN; /* uint64_t is used in the epoll header */ + reg_event.data.u64 = (uint64_t)mhd_SOCKET_REL_MARKER_LISTEN; /* uint64_t is used in the epoll header */ if (0 != epoll_ctl (d->events.data.epoll.e_fd, EPOLL_CTL_ADD, d->net.listen.fd, &reg_event)) { @@ -2698,7 +2698,7 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) int num_elemnts; num_elemnts = 0; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS mhd_KE_SET (d->events.data.kq.kes + num_elemnts, mhd_itc_r_fd (d->threading.itc), EVFILT_READ, @@ -2707,7 +2707,7 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) mhd_dbg_print_kevent_change ("ITC", d->events.data.kq.kes + num_elemnts); ++num_elemnts; -#endif +# endif if (MHD_INVALID_SOCKET != d->net.listen.fd) { mhd_KE_SET (d->events.data.kq.kes + num_elemnts, @@ -2726,27 +2726,27 @@ init_daemon_fds_monitoring (struct MHD_Daemon *restrict d) static const struct timespec zero_timeout = {0, 0}; int res; -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Starting) kevent(%d, changes, %d, [NULL], " "0, [0, 0])...\n", d->events.data.kq.kq_fd, num_elemnts); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ res = kevent (d->events.data.kq.kq_fd, d->events.data.kq.kes, num_elemnts, NULL, 0, &zero_timeout); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Finished) kevent(%d, changes, %d, [NULL], " "0, [0, 0]) -> %d\n", d->events.data.kq.kq_fd, num_elemnts, res); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ if (0 != res) { mhd_LOG_MSG (d, MHD_SC_EVENTS_REG_DAEMON_FDS_FAILURE, \ @@ -2789,20 +2789,20 @@ deinit_daemon_fds_monitoring (struct MHD_Daemon *restrict d) { case mhd_POLL_TYPE_EXT: if (NULL != d->events.data.extr.listen_data.app_cntx) - (void) mhd_daemon_extr_event_reg ( + (void)mhd_daemon_extr_event_reg ( d, d->net.listen.fd, MHD_FD_STATE_NONE, d->events.data.extr.listen_data.app_cntx, - (struct MHD_EventUpdateContext *) mhd_SOCKET_REL_MARKER_LISTEN); + (struct MHD_EventUpdateContext *)mhd_SOCKET_REL_MARKER_LISTEN); #ifdef MHD_SUPPORT_THREADS if (NULL != d->events.data.extr.itc_data.app_cntx) - (void) mhd_daemon_extr_event_reg (d, - mhd_itc_r_fd (d->threading.itc), - MHD_FD_STATE_NONE, - d->events.data.extr.itc_data.app_cntx, - (struct MHD_EventUpdateContext *) - mhd_SOCKET_REL_MARKER_ITC); + (void)mhd_daemon_extr_event_reg (d, + mhd_itc_r_fd (d->threading.itc), + MHD_FD_STATE_NONE, + d->events.data.extr.itc_data.app_cntx, + (struct MHD_EventUpdateContext *) + mhd_SOCKET_REL_MARKER_ITC); #endif /* MHD_SUPPORT_THREADS */ return; #ifdef MHD_SUPPORT_SELECT @@ -2858,12 +2858,12 @@ MHD_FN_MUST_CHECK_RESULT_ enum MHD_StatusCode init_individual_conns (struct MHD_Daemon *restrict d, struct DaemonOptions *restrict s) { - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); mhd_assert (0 != d->conns.cfg.count_limit); - mhd_DLINKEDL_INIT_LIST (&(d->conns),all_conn); - mhd_DLINKEDL_INIT_LIST (&(d->conns),def_timeout); - mhd_DLINKEDL_INIT_LIST (&(d->conns),cust_timeout); + mhd_DLINKEDL_INIT_LIST (&(d->conns), all_conn); + mhd_DLINKEDL_INIT_LIST (&(d->conns), def_timeout); + mhd_DLINKEDL_INIT_LIST (&(d->conns), cust_timeout); d->conns.count = 0; d->conns.block_new = false; @@ -2888,8 +2888,8 @@ init_individual_conns (struct MHD_Daemon *restrict d, } #ifdef MHD_SUPPORT_UPGRADE - mhd_DLINKEDL_INIT_LIST (&(d->conns.upgr),upgr_cleanup); - if (! mhd_mutex_init (&(d->conns.upgr.ucu_lock))) + mhd_DLINKEDL_INIT_LIST (&(d->conns.upgr), upgr_cleanup); + if (!mhd_mutex_init (&(d->conns.upgr.ucu_lock))) { mhd_LOG_MSG (d, MHD_SC_MUTEX_INIT_FAILURE, \ "Failed to initialise mutex for the upgraded " \ @@ -2913,20 +2913,20 @@ static MHD_FN_PAR_NONNULL_ (1) void deinit_individual_conns (struct MHD_Daemon *restrict d) { #ifdef MHD_SUPPORT_UPGRADE - mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns.upgr),upgr_cleanup)); - mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns.upgr),upgr_cleanup)); + mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns.upgr), upgr_cleanup)); + mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns.upgr), upgr_cleanup)); mhd_mutex_destroy_chk (&(d->conns.upgr.ucu_lock)); #endif /* MHD_SUPPORT_UPGRADE */ mhd_assert (0 != d->conns.cfg.mem_pool_size); mhd_assert (0 == d->conns.count); - mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns),cust_timeout)); - mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns),cust_timeout)); - mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns),def_timeout)); - mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns),def_timeout)); - mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn)); - mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns),all_conn)); + mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns), cust_timeout)); + mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns), cust_timeout)); + mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns), def_timeout)); + mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns), def_timeout)); + mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn)); + mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns), all_conn)); } @@ -2947,8 +2947,8 @@ init_individual_thread_data_events_conns (struct MHD_Daemon *restrict d, enum MHD_StatusCode res; mhd_assert (mhd_D_TYPE_IS_VALID (d->threading.d_type)); mhd_assert (mhd_D_TYPE_HAS_EVENTS_PROCESSING (d->threading.d_type)); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); - mhd_assert (! d->dbg.connections_inited); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!d->dbg.connections_inited); res = init_events_fd (d); if (MHD_SC_OK != res) @@ -3009,8 +3009,8 @@ deinit_individual_thread_data_events_conns (struct MHD_Daemon *restrict d) deinit_itc (d); deallocate_events (d); deinit_events_fd (d); - mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn)); - mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->events),proc_ready)); + mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn)); + mhd_assert (NULL == mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready)); #ifndef NDEBUG d->dbg.events_fully_inited = false; #endif @@ -3031,11 +3031,11 @@ init_worker_only_data (struct MHD_Daemon *restrict d) struct mhd_DaemonExtAddedConnectionsWorker *worker_only_data = &(d->events.act_req.ext_added.worker); - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.worker_only_inited); - mhd_assert (mhd_D_HAS_MASTER (d) || ! d->dbg.master_only_inited); - mhd_assert (! mhd_D_HAS_MASTER (d) || d->dbg.master_only_inited); /* Copied from master daemon */ + mhd_assert (!d->dbg.worker_only_inited); + mhd_assert (mhd_D_HAS_MASTER (d) || !d->dbg.master_only_inited); + mhd_assert (!mhd_D_HAS_MASTER (d) || d->dbg.master_only_inited); /* Copied from master daemon */ #ifndef NDEBUG /* "master"-only data will be overwritten here without de-initialising */ @@ -3044,7 +3044,7 @@ init_worker_only_data (struct MHD_Daemon *restrict d) mhd_DLINKEDL_INIT_LIST (worker_only_data, queue); - if (! mhd_mutex_init (&(worker_only_data->q_lock))) + if (!mhd_mutex_init (&(worker_only_data->q_lock))) { mhd_LOG_MSG (d, MHD_SC_MUTEX_INIT_FAILURE, \ "Failed to initialise mutex for externally added " @@ -3074,10 +3074,10 @@ deinit_worker_only_data (struct MHD_Daemon *restrict d) &(d->events.act_req.ext_added.worker); struct mhd_DaemonExtAddedConn *q_e; - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); mhd_assert (d->dbg.net_inited); mhd_assert (d->dbg.worker_only_inited); - mhd_assert (! d->dbg.master_only_inited); + mhd_assert (!d->dbg.master_only_inited); /* Clean-up all unprocessed entries */ @@ -3119,7 +3119,7 @@ init_worker (struct MHD_Daemon *restrict d, struct DaemonOptions *restrict s) { enum MHD_StatusCode res; - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); res = init_worker_only_data (d); @@ -3153,7 +3153,7 @@ init_worker (struct MHD_Daemon *restrict d, static MHD_FN_PAR_NONNULL_ (1) void deinit_worker (struct MHD_Daemon *restrict d) { - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); deinit_individual_thread_data_events_conns (d); @@ -3181,7 +3181,7 @@ set_connections_total_limits (struct MHD_Daemon *restrict d, bool error_by_fd_setsize; unsigned int num_worker_daemons; - mhd_assert (! mhd_D_HAS_MASTER (d)); + mhd_assert (!mhd_D_HAS_MASTER (d)); mhd_assert (mhd_D_TYPE_IS_VALID (d->threading.d_type)); num_worker_daemons = 1; @@ -3189,9 +3189,10 @@ set_connections_total_limits (struct MHD_Daemon *restrict d, if (mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL == d->wmode_int) { mhd_assert (MHD_WM_WORKER_THREADS == s->work_mode.mode); - if ((0 != s->global_connection_limit) && - (0 != s->work_mode.params.num_worker_threads) && - (s->global_connection_limit < s->work_mode.params.num_worker_threads)) + if ((0 != s->global_connection_limit) + && (0 != s->work_mode.params.num_worker_threads) + && (s->global_connection_limit < + s->work_mode.params.num_worker_threads)) { mhd_LOG_MSG ( \ d, MHD_SC_CONFIGURATION_CONN_LIMIT_TOO_SMALL, \ @@ -3213,20 +3214,21 @@ set_connections_total_limits (struct MHD_Daemon *restrict d, #ifdef MHD_SOCKETS_KIND_POSIX if (1) { - limit_by_num = (unsigned int) d->net.cfg.max_fd_num; + limit_by_num = (unsigned int)d->net.cfg.max_fd_num; if (0 != limit_by_num) { /* Find the upper limit. The real limit is lower, as any other process FDs will use the slots in the allowed numbers range */ limit_by_num -= 3; /* The numbers zero, one and two are used typically */ -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS limit_by_num -= mhd_ITC_NUM_FDS * num_worker_daemons; -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ if (MHD_INVALID_SOCKET != d->net.listen.fd) --limit_by_num; /* One FD is used for the listening socket */ - if ((num_worker_daemons > limit_by_num) || - (limit_by_num > (unsigned int) d->net.cfg.max_fd_num) /* Underflow */) + if ((num_worker_daemons > limit_by_num) + || (limit_by_num > + (unsigned int)d->net.cfg.max_fd_num) /* Underflow */) { if (d->net.cfg.max_fd_num == s->fd_number_limit) { @@ -3244,14 +3246,14 @@ set_connections_total_limits (struct MHD_Daemon *restrict d, } } else - limit_by_num = (unsigned int) INT_MAX; + limit_by_num = (unsigned int)INT_MAX; } #elif defined(MHD_SOCKETS_KIND_WINSOCK) if (1) { -#ifdef MHD_SUPPORT_SELECT - if ((mhd_DAEMON_TYPE_SINGLE == d->threading.d_type) && - (mhd_POLL_TYPE_SELECT == d->events.poll_type)) +# ifdef MHD_SUPPORT_SELECT + if ((mhd_DAEMON_TYPE_SINGLE == d->threading.d_type) + && (mhd_POLL_TYPE_SELECT == d->events.poll_type)) { /* W32 limits the total number (count) of sockets used for select() */ unsigned int limit_per_worker; @@ -3259,9 +3261,9 @@ set_connections_total_limits (struct MHD_Daemon *restrict d, limit_per_worker = FD_SETSIZE; if (MHD_INVALID_SOCKET != d->net.listen.fd) --limit_per_worker; /* The slot for the listening socket */ -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS --limit_per_worker; /* The slot for the ITC */ -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ if ((0 == limit_per_worker) || (limit_per_worker > FD_SETSIZE)) error_by_fd_setsize = true; else @@ -3271,8 +3273,8 @@ set_connections_total_limits (struct MHD_Daemon *restrict d, limit_by_select = UINT_MAX; } } -#endif /* MHD_SUPPORT_SELECT */ - (void) 0; /* Mute compiler warning */ +# endif /* MHD_SUPPORT_SELECT */ + (void)0; /* Mute compiler warning */ } #endif /* MHD_SOCKETS_KIND_POSIX */ if (error_by_fd_setsize) @@ -3294,22 +3296,22 @@ set_connections_total_limits (struct MHD_Daemon *restrict d, /* No user configuration provided */ unsigned int suggested_limit; #ifndef MHD_SOCKETS_KIND_WINSOCK -#define TYPICAL_NOFILES_LIMIT (1024) /* The usual limit for the number of open FDs */ +# define TYPICAL_NOFILES_LIMIT (1024) /* The usual limit for the number of open FDs */ suggested_limit = TYPICAL_NOFILES_LIMIT; suggested_limit -= 3; /* The numbers zero, one and two are used typically */ -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS suggested_limit -= mhd_ITC_NUM_FDS * num_worker_daemons; -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ if (MHD_INVALID_SOCKET != d->net.listen.fd) --suggested_limit; /* One FD is used for the listening socket */ if (suggested_limit > TYPICAL_NOFILES_LIMIT) suggested_limit = 0; /* Overflow */ #else /* MHD_SOCKETS_KIND_WINSOCK */ -#ifdef _WIN64 +# ifdef _WIN64 suggested_limit = 2048; -#else +# else suggested_limit = 1024; -#endif +# endif #endif /* MHD_SOCKETS_KIND_WINSOCK */ if (suggested_limit < num_worker_daemons) { @@ -3350,7 +3352,7 @@ set_d_threading_type (struct MHD_Daemon *restrict d) { case mhd_WM_INT_EXTERNAL_EVENTS_EDGE: case mhd_WM_INT_EXTERNAL_EVENTS_LEVEL: - mhd_assert (! mhd_WM_INT_HAS_THREADS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_THREADS (d->wmode_int)); mhd_assert (mhd_POLL_TYPE_EXT == d->events.poll_type); mhd_assert (NULL != d->events.data.extr.cb_data.cb); #ifdef MHD_SUPPORT_THREADS @@ -3358,7 +3360,7 @@ set_d_threading_type (struct MHD_Daemon *restrict d) #endif /* MHD_SUPPORT_THREADS */ return MHD_SC_OK; case mhd_WM_INT_INTERNAL_EVENTS_NO_THREADS: - mhd_assert (! mhd_WM_INT_HAS_THREADS (d->wmode_int)); + mhd_assert (!mhd_WM_INT_HAS_THREADS (d->wmode_int)); mhd_assert (mhd_POLL_TYPE_EXT != d->events.poll_type); #ifdef MHD_SUPPORT_THREADS d->threading.d_type = mhd_DAEMON_TYPE_SINGLE; @@ -3373,8 +3375,8 @@ set_d_threading_type (struct MHD_Daemon *restrict d) case mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION: mhd_assert (mhd_WM_INT_HAS_THREADS (d->wmode_int)); mhd_assert (mhd_POLL_TYPE_EXT != d->events.poll_type); - mhd_assert (! mhd_POLL_TYPE_INT_IS_EPOLL (d->events.poll_type)); - mhd_assert (! mhd_POLL_TYPE_INT_IS_KQUEUE (d->events.poll_type)); + mhd_assert (!mhd_POLL_TYPE_INT_IS_EPOLL (d->events.poll_type)); + mhd_assert (!mhd_POLL_TYPE_INT_IS_KQUEUE (d->events.poll_type)); d->threading.d_type = mhd_DAEMON_TYPE_LISTEN_ONLY; return MHD_SC_OK; case mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL: @@ -3406,12 +3408,12 @@ deinit_workers_pool (struct MHD_Daemon *restrict d, unsigned int i; mhd_assert (mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); mhd_assert (NULL != d->threading.hier.pool.workers); - mhd_assert ((2 <= d->threading.hier.pool.num) || \ - (mhd_DAEMON_STATE_STARTING == d->state)); - mhd_assert ((num_workers == d->threading.hier.pool.num) || \ - (mhd_DAEMON_STATE_STARTING == d->state)); - mhd_assert ((mhd_DAEMON_STATE_STOPPING == d->state) || \ - (mhd_DAEMON_STATE_STARTING == d->state)); + mhd_assert ((2 <= d->threading.hier.pool.num) \ + || (mhd_DAEMON_STATE_STARTING == d->state)); + mhd_assert ((num_workers == d->threading.hier.pool.num) \ + || (mhd_DAEMON_STATE_STARTING == d->state)); + mhd_assert ((mhd_DAEMON_STATE_STOPPING == d->state) \ + || (mhd_DAEMON_STATE_STARTING == d->state)); /* Deinitialise in reverse order */ for (i = num_workers - 1; num_workers > i; --i) @@ -3420,9 +3422,9 @@ deinit_workers_pool (struct MHD_Daemon *restrict d, deinit_worker (worker); } free (d->threading.hier.pool.workers); -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.thread_pool_inited = false; -#endif +# endif } @@ -3434,21 +3436,21 @@ deinit_workers_pool (struct MHD_Daemon *restrict d, static MHD_FN_PAR_NONNULL_ (1) void reset_master_only_areas (struct MHD_Daemon *restrict d) { -#ifdef MHD_SUPPORT_EPOLL +# ifdef MHD_SUPPORT_EPOLL /* In release builds this is done mostly for safety as @a early_fd is used in workers only for asserts */ if (mhd_POLL_TYPE_EPOLL == d->events.poll_type) d->events.data.epoll.early_fd = MHD_INVALID_SOCKET; -#endif /* MHD_SUPPORT_EPOLL */ +# endif /* MHD_SUPPORT_EPOLL */ -#ifdef MHD_SUPPORT_AUTH_DIGEST +# ifdef MHD_SUPPORT_AUTH_DIGEST memset (&(d->auth_dg.nonces_lock), 0x7F, sizeof(d->auth_dg.nonces_lock)); -#endif +# endif /* Not needed. It is initialised later */ /* memset (&(d->req_cfg.large_buf), 0, sizeof(d->req_cfg.large_buf)); */ - (void) d; + (void)d; } @@ -3473,7 +3475,7 @@ init_workers_pool (struct MHD_Daemon *restrict d, unsigned int i; mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL == d->wmode_int); mhd_assert (mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); mhd_assert (mhd_POLL_TYPE_NOT_SET_YET < d->events.poll_type); @@ -3481,7 +3483,7 @@ init_workers_pool (struct MHD_Daemon *restrict d, mhd_assert (0 != d->conns.cfg.count_limit); mhd_assert (s->work_mode.params.num_worker_threads <= \ d->conns.cfg.count_limit); - mhd_assert (! d->dbg.thread_pool_inited); + mhd_assert (!d->dbg.thread_pool_inited); num_workers = s->work_mode.params.num_worker_threads; workers_pool_size = @@ -3494,10 +3496,10 @@ init_workers_pool (struct MHD_Daemon *restrict d, return MHD_SC_THREAD_POOL_MEM_ALLOC_FAILURE; } -#ifndef NDEBUG +# ifndef NDEBUG mhd_itc_set_invalid (&(d->threading.itc)); mhd_thread_handle_ID_set_invalid (&(d->threading.tid)); -#endif +# endif d->threading.hier.pool.workers = (struct MHD_Daemon *) malloc (workers_pool_size); @@ -3524,14 +3526,14 @@ init_workers_pool (struct MHD_Daemon *restrict d, worker->conns.cfg.count_limit = conn_per_daemon; if (conn_remainder > i) worker->conns.cfg.count_limit++; /* Distribute the reminder */ -#ifdef MHD_SUPPORT_EPOLL - mhd_assert ((mhd_POLL_TYPE_EPOLL != worker->events.poll_type) || - (0 != i) || - (0 < d->events.data.epoll.early_fd)); - mhd_assert ((mhd_POLL_TYPE_EPOLL != worker->events.poll_type) || - (0 == i) || - (MHD_INVALID_SOCKET == d->events.data.epoll.early_fd)); -#endif /* MHD_SUPPORT_EPOLL */ +# ifdef MHD_SUPPORT_EPOLL + mhd_assert ((mhd_POLL_TYPE_EPOLL != worker->events.poll_type) + || (0 != i) + || (0 < d->events.data.epoll.early_fd)); + mhd_assert ((mhd_POLL_TYPE_EPOLL != worker->events.poll_type) + || (0 == i) + || (MHD_INVALID_SOCKET == d->events.data.epoll.early_fd)); +# endif /* MHD_SUPPORT_EPOLL */ res = init_worker (worker, s); if (MHD_SC_OK != res) @@ -3540,10 +3542,10 @@ init_workers_pool (struct MHD_Daemon *restrict d, if (num_workers == i) { mhd_assert (MHD_SC_OK == res); -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.thread_pool_inited = true; d->dbg.threading_inited = true; -#endif +# endif d->threading.hier.pool.num = num_workers; return MHD_SC_OK; } @@ -3570,10 +3572,10 @@ init_master_only_data (struct MHD_Daemon *restrict d) mhd_assert (mhd_D_HAS_WORKERS (d)); mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.master_only_inited); - mhd_assert (! d->dbg.worker_only_inited); + mhd_assert (!d->dbg.master_only_inited); + mhd_assert (!d->dbg.worker_only_inited); - if (! mhd_atomic_counter_init ( \ + if (!mhd_atomic_counter_init ( \ &(d->events.act_req.ext_added.master.next_d_idx), 0)) { @@ -3585,10 +3587,10 @@ init_master_only_data (struct MHD_Daemon *restrict d) else res = MHD_SC_OK; -#ifndef NDEBUG +# ifndef NDEBUG if (MHD_SC_OK == res) d->dbg.master_only_inited = true; -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ return res; } @@ -3603,13 +3605,13 @@ deinit_master_only_data (struct MHD_Daemon *restrict d) { mhd_assert (mhd_D_HAS_WORKERS (d)); mhd_assert (d->dbg.master_only_inited); - mhd_assert (! d->dbg.worker_only_inited); + mhd_assert (!d->dbg.worker_only_inited); mhd_atomic_counter_deinit (&(d->events.act_req.ext_added.master.next_d_idx)); -#ifndef NDEBUG +# ifndef NDEBUG d->dbg.master_only_inited = false; -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ } @@ -3692,7 +3694,7 @@ daemon_init_threading_and_conn (struct MHD_Daemon *restrict d, enum MHD_StatusCode res; mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (mhd_POLL_TYPE_NOT_SET_YET != d->events.poll_type); res = set_d_threading_type (d); @@ -3707,7 +3709,7 @@ daemon_init_threading_and_conn (struct MHD_Daemon *restrict d, d->threading.cfg.stack_size = s->stack_size; #endif /* MHD_SUPPORT_THREADS */ - if (! mhd_D_HAS_WORKERS (d)) + if (!mhd_D_HAS_WORKERS (d)) res = init_worker (d, s); #ifdef MHD_SUPPORT_THREADS @@ -3718,17 +3720,17 @@ daemon_init_threading_and_conn (struct MHD_Daemon *restrict d, if (MHD_SC_OK == res) { - mhd_assert (d->dbg.events_allocated || \ - mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type) || \ - ! d->dbg.events_allocated); - mhd_assert (! d->dbg.thread_pool_inited || \ - mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type) || \ - d->dbg.thread_pool_inited); - mhd_assert (! mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); - mhd_assert (! d->dbg.events_allocated || d->dbg.connections_inited); - mhd_assert (! d->dbg.connections_inited || d->dbg.events_allocated); + mhd_assert (d->dbg.events_allocated \ + || mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type) \ + || !d->dbg.events_allocated); + mhd_assert (!d->dbg.thread_pool_inited \ + || mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type) \ + || d->dbg.thread_pool_inited); + mhd_assert (!mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); + mhd_assert (!d->dbg.events_allocated || d->dbg.connections_inited); + mhd_assert (!d->dbg.connections_inited || d->dbg.events_allocated); } return res; } @@ -3744,29 +3746,29 @@ static MHD_FN_PAR_NONNULL_ (1) void daemon_deinit_threading_and_conn (struct MHD_Daemon *restrict d) { mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (d->dbg.threading_inited); - mhd_assert (! mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); - if (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)) + mhd_assert (!mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); + if (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)) { - mhd_assert (! mhd_WM_INT_IS_THREAD_POOL (d->wmode_int)); + mhd_assert (!mhd_WM_INT_IS_THREAD_POOL (d->wmode_int)); mhd_assert (d->dbg.connections_inited); mhd_assert (d->dbg.events_allocated); - mhd_assert (! d->dbg.thread_pool_inited); + mhd_assert (!d->dbg.thread_pool_inited); deinit_worker (d); } else { #ifdef MHD_SUPPORT_THREADS mhd_assert (mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL == d->wmode_int); - mhd_assert (! d->dbg.connections_inited); - mhd_assert (! d->dbg.events_allocated); + mhd_assert (!d->dbg.connections_inited); + mhd_assert (!d->dbg.events_allocated); mhd_assert (d->dbg.thread_pool_inited); deinit_master (d); #else /* ! MHD_SUPPORT_THREADS */ mhd_assert (0 && "Impossible value"); mhd_UNREACHABLE (); - (void) 0; + (void)0; #endif /* ! MHD_SUPPORT_THREADS */ } } @@ -3790,16 +3792,16 @@ start_individual_daemon_thread (struct MHD_Daemon *restrict d) mhd_assert (d->dbg.threading_inited); mhd_assert (mhd_WM_INT_HAS_THREADS (d->wmode_int)); mhd_assert (mhd_D_TYPE_IS_VALID (d->threading.d_type)); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); - mhd_assert (! mhd_thread_handle_ID_is_valid_handle (d->threading.tid)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_thread_handle_ID_is_valid_handle (d->threading.tid)); if (mhd_DAEMON_TYPE_SINGLE == d->threading.d_type) { - if (! mhd_create_named_thread ( \ + if (!mhd_create_named_thread ( \ &(d->threading.tid), "MHD-single", \ d->threading.cfg.stack_size, \ &mhd_worker_all_events, \ - (void*) d)) + (void *)d)) { mhd_LOG_MSG (d, MHD_SC_THREAD_MAIN_LAUNCH_FAILURE, \ "Failed to start daemon main thread."); @@ -3808,11 +3810,11 @@ start_individual_daemon_thread (struct MHD_Daemon *restrict d) } else if (mhd_DAEMON_TYPE_WORKER == d->threading.d_type) { - if (! mhd_create_named_thread ( \ + if (!mhd_create_named_thread ( \ &(d->threading.tid), "MHD-worker", \ d->threading.cfg.stack_size, \ &mhd_worker_all_events, \ - (void*) d)) + (void *)d)) { mhd_LOG_MSG (d, MHD_SC_THREAD_WORKER_LAUNCH_FAILURE, \ "Failed to start daemon worker thread."); @@ -3821,11 +3823,11 @@ start_individual_daemon_thread (struct MHD_Daemon *restrict d) } else if (mhd_DAEMON_TYPE_LISTEN_ONLY == d->threading.d_type) { - if (! mhd_create_named_thread ( \ + if (!mhd_create_named_thread ( \ &(d->threading.tid), "MHD-listen", \ d->threading.cfg.stack_size, \ &mhd_worker_listening_only, \ - (void*) d)) + (void *)d)) { mhd_LOG_MSG (d, MHD_SC_THREAD_LISTENING_LAUNCH_FAILURE, \ "Failed to start daemon listening thread."); @@ -3856,15 +3858,15 @@ stop_individual_daemon_thread (struct MHD_Daemon *restrict d) mhd_assert (d->dbg.threading_inited); mhd_assert (mhd_WM_INT_HAS_THREADS (d->wmode_int)); mhd_assert (mhd_D_TYPE_IS_VALID (d->threading.d_type)); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); - mhd_assert ((mhd_DAEMON_STATE_STOPPING == d->state) || \ - (mhd_DAEMON_STATE_STARTING == d->state)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert ((mhd_DAEMON_STATE_STOPPING == d->state) \ + || (mhd_DAEMON_STATE_STARTING == d->state)); mhd_assert (mhd_thread_handle_ID_is_valid_handle (d->threading.tid)); d->threading.stop_requested = true; mhd_daemon_trigger_itc (d); - if (! mhd_thread_handle_ID_join_thread (d->threading.tid)) + if (!mhd_thread_handle_ID_join_thread (d->threading.tid)) { mhd_LOG_MSG (d, MHD_SC_DAEMON_THREAD_STOP_ERROR, \ "Failed to stop daemon main thread."); @@ -3888,10 +3890,10 @@ stop_worker_pool_threads (struct MHD_Daemon *restrict d, mhd_assert (0 != d->threading.hier.pool.num); mhd_assert (d->dbg.thread_pool_inited); mhd_assert (2 <= d->threading.hier.pool.num); - mhd_assert ((num_workers == d->threading.hier.pool.num) || \ - (mhd_DAEMON_STATE_STARTING == d->state)); - mhd_assert ((mhd_DAEMON_STATE_STOPPING == d->state) || \ - (mhd_DAEMON_STATE_STARTING == d->state)); + mhd_assert ((num_workers == d->threading.hier.pool.num) \ + || (mhd_DAEMON_STATE_STARTING == d->state)); + mhd_assert ((mhd_DAEMON_STATE_STOPPING == d->state) \ + || (mhd_DAEMON_STATE_STARTING == d->state)); /* Process all the threads in the reverse order */ @@ -3910,7 +3912,7 @@ stop_worker_pool_threads (struct MHD_Daemon *restrict d, struct MHD_Daemon *const restrict worker = d->threading.hier.pool.workers + i; mhd_assert (mhd_thread_handle_ID_is_valid_handle (worker->threading.tid)); - if (! mhd_thread_handle_ID_join_thread (worker->threading.tid)) + if (!mhd_thread_handle_ID_join_thread (worker->threading.tid)) { mhd_LOG_MSG (d, MHD_SC_DAEMON_THREAD_STOP_ERROR, \ "Failed to stop a worker thread."); @@ -3973,9 +3975,9 @@ MHD_FN_MUST_CHECK_RESULT_ enum MHD_StatusCode daemon_start_threads (struct MHD_Daemon *restrict d) { mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (d->dbg.threading_inited); - mhd_assert (! mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); if (mhd_WM_INT_HAS_THREADS (d->wmode_int)) { #ifdef MHD_SUPPORT_THREADS @@ -4009,7 +4011,7 @@ static MHD_FN_PAR_NONNULL_ (1) void daemon_stop_threads (struct MHD_Daemon *restrict d) { mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (d->dbg.threading_inited); if (mhd_WM_INT_HAS_THREADS (d->wmode_int)) { @@ -4017,7 +4019,7 @@ daemon_stop_threads (struct MHD_Daemon *restrict d) if (mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL != d->wmode_int) { mhd_assert (d->dbg.threading_inited); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); stop_individual_daemon_thread (d); return; } @@ -4046,7 +4048,7 @@ daemon_close_connections (struct MHD_Daemon *restrict d) if (mhd_WM_INT_HAS_THREADS (d->wmode_int)) { /* In these modes connections must be closed in the daemon thread */ - mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns),all_conn)); + mhd_assert (NULL == mhd_DLINKEDL_GET_LAST (&(d->conns), all_conn)); return; } @@ -4095,7 +4097,7 @@ daemon_start_internal (struct MHD_Daemon *restrict d, if (MHD_SC_OK == res) { mhd_assert (d->dbg.threading_inited); - mhd_assert (! mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_IS_INTERNAL_ONLY (d->threading.d_type)); res = daemon_init_large_buf (d, s); if (MHD_SC_OK == res) @@ -4161,7 +4163,7 @@ MHD_daemon_destroy (struct MHD_Daemon *daemon) mhd_assert (NULL != daemon->settings); dsettings_release (daemon->settings); } - else if (! has_failed) + else if (!has_failed) { mhd_assert (NULL == daemon->settings); mhd_assert (daemon->dbg.threading_inited); diff --git a/src/mhd2/dcc_action.c b/src/mhd2/dcc_action.c @@ -83,7 +83,7 @@ MHD_DCC_action_continue_zc ( if (NULL == iov_data) break; mhd_assert (0 && "Not implemented yet"); - (void) iov_data->iov_count; + (void)iov_data->iov_count; // TODO: add check for iov data total size break; } diff --git a/src/mhd2/events_process.c b/src/mhd2/events_process.c @@ -128,7 +128,7 @@ mhd_dbg_print_fd_mon_req (const char *fd_name, fprintf (stderr, "### Set FD watching: %4s [%2llu] for %s\n", fd_name, - (unsigned long long) fd, + (unsigned long long)fd, state_str); } @@ -156,7 +156,7 @@ dbg_print_fd_state_update (const char *fd_name, fprintf (stderr, "### FD state update: %4s [%2llu] -> %s\n", fd_name, - (unsigned long long) fd, + (unsigned long long)fd, state_str); } @@ -179,7 +179,7 @@ mhd_dbg_kefilter_to_name (const struct kevent *ke) } -#define mhd_DBG_KEFLAGS_BUF_SIZE 512 +# define mhd_DBG_KEFLAGS_BUF_SIZE 512 static void mdd_dbg_keflags_to_text (const struct kevent *ke, @@ -211,25 +211,25 @@ mdd_dbg_keflags_to_text (const struct kevent *ke, strcat (buf, "EOF|"); if (0 != (EV_ERROR & keflags)) strcat (buf, "ERROR|"); -#ifdef EV_KEEPUDATA +# ifdef EV_KEEPUDATA if (0 != (EV_KEEPUDATA & keflags)) strcat (buf, "KEEPUDATA|"); -#endif /* EV_KEEPUDATA */ +# endif /* EV_KEEPUDATA */ len = strlen (buf); mhd_assert (buf_size > len); extra_flags = - (~((unsigned int) (EV_ADD | EV_ENABLE | EV_DISABLE | EV_DISPATCH | EV_DELETE - | EV_RECEIPT | EV_ONESHOT | EV_CLEAR | EV_EOF | EV_ERROR - | mhd_EV_KEEPUDATA_OR_ZERO))) & keflags; + (~((unsigned int)(EV_ADD | EV_ENABLE | EV_DISABLE | EV_DISPATCH | EV_DELETE + | EV_RECEIPT | EV_ONESHOT | EV_CLEAR | EV_EOF | EV_ERROR + | mhd_EV_KEEPUDATA_OR_ZERO))) & keflags; if (0u != extra_flags) { - (void) snprintf (buf + len, - buf_size - len, - "0x%02X|", - extra_flags); + (void)snprintf (buf + len, + buf_size - len, + "0x%02X|", + extra_flags); len = strlen (buf); mhd_assert (buf_size > len); } @@ -258,21 +258,21 @@ mhd_dbg_print_kevent (const char *fd_name, "fflags: %u;\tdata %lld\n", action_name, fd_name, - (unsigned long long) ke->ident, + (unsigned long long)ke->ident, mhd_dbg_kefilter_to_name (ke), flags_txt, - (unsigned int) ke->fflags, - (long long) ke->data); + (unsigned int)ke->fflags, + (long long)ke->data); } # endif /* MHD_SUPPORT_KQUEUE */ #else /* ! MHD_USE_TRACE_POLLING_FDS */ -# define dbg_print_fd_state_update(fd_n,fd,r_ready,w_ready,e_ready) \ - ((void) 0) +# define dbg_print_fd_state_update(fd_n, fd, r_ready, w_ready, e_ready) \ + ((void) 0) # ifdef MHD_SUPPORT_KQUEUE -# define mhd_dbg_print_kq_fd_mon_req(fd_name,ke) +# define mhd_dbg_print_kq_fd_mon_req(fd_name, ke) # endif /* MHD_SUPPORT_KQUEUE */ #endif /* ! MHD_USE_TRACE_POLLING_FDS */ @@ -349,9 +349,9 @@ mhd_daemon_get_wait_max (const struct MHD_Daemon *restrict d) { uint_fast64_t ret; - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); - if (d->events.accept_pending && ! d->conns.block_new) + if (d->events.accept_pending && !d->conns.block_new) { #ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, @@ -391,14 +391,14 @@ mhd_daemon_get_wait_max (const struct MHD_Daemon *restrict d) #ifdef MHD_SUPPORT_KQUEUE if (mhd_D_IS_USING_KQUEUE (d)) { - if ((NULL != mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn)) && - ! mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn)->events.kq.monitored) + if ((NULL != mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn)) + && !mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn)->events.kq.monitored) { -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### mhd_daemon_get_wait_max(daemon) -> zero " "(kqueue unmonitored connection(s) pending)\n"); -#endif +# endif return 0; } } @@ -413,7 +413,7 @@ mhd_daemon_get_wait_max (const struct MHD_Daemon *restrict d) else fprintf (stderr, "### mhd_daemon_get_wait_max(daemon) -> %lu\n", - (unsigned long) ret); + (unsigned long)ret); #endif return ret; @@ -428,7 +428,7 @@ start_resuming_connection (struct MHD_Connection *restrict c, #ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Resuming connection, FD: %2llu\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_SUSPEND_RESUME */ c->suspended = false; mhd_conn_init_activity_timeout (c, @@ -446,14 +446,14 @@ daemon_resume_conns_if_needed (struct MHD_Daemon *restrict d) { struct MHD_Connection *c; - if (! d->events.act_req.resume) + if (!d->events.act_req.resume) return; d->events.act_req.resume = false; /* Reset flag before processing data */ - for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn); + for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn); NULL != c; - c = mhd_DLINKEDL_GET_NEXT (c,all_conn)) + c = mhd_DLINKEDL_GET_NEXT (c, all_conn)) { if (c->resuming) start_resuming_connection (c, d); @@ -461,7 +461,7 @@ daemon_resume_conns_if_needed (struct MHD_Daemon *restrict d) } -#if defined (MHD_SUPPORT_POLL) || defined(MHD_SUPPORT_EPOLL) +#if defined(MHD_SUPPORT_POLL) || defined(MHD_SUPPORT_EPOLL) mhd_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE @@ -469,13 +469,13 @@ static MHD_FN_PAR_NONNULL_ALL_ int get_max_wait (const struct MHD_Daemon *restrict d) { const uint_fast64_t ui64_wait = mhd_daemon_get_wait_max (d); - int i_wait = (int) ui64_wait; + int i_wait = (int)ui64_wait; if (MHD_WAIT_INDEFINITELY <= ui64_wait) return -1; - if (mhd_COND_ALMOST_NEVER ((0 > i_wait) || - (ui64_wait != (uint_fast64_t) i_wait))) + if (mhd_COND_ALMOST_NEVER ((0 > i_wait) + || (ui64_wait != (uint_fast64_t)i_wait))) return INT_MAX; return i_wait; @@ -500,7 +500,7 @@ update_conn_net_status (struct MHD_Daemon *restrict d, mhd_assert (d == c->daemon); /* "resuming" must be not processed yet */ - mhd_assert (! c->resuming || c->suspended); + mhd_assert (!c->resuming || c->suspended); dbg_print_fd_state_update ("conn", \ c->sk.fd, \ @@ -511,19 +511,19 @@ update_conn_net_status (struct MHD_Daemon *restrict d, sk_state = mhd_SOCKET_NET_STATE_NOTHING; if (recv_ready) sk_state = (enum mhd_SocketNetState) - (sk_state | (unsigned int) mhd_SOCKET_NET_STATE_RECV_READY); + (sk_state | (unsigned int)mhd_SOCKET_NET_STATE_RECV_READY); if (send_ready) sk_state = (enum mhd_SocketNetState) - (sk_state | (unsigned int) mhd_SOCKET_NET_STATE_SEND_READY); + (sk_state | (unsigned int)mhd_SOCKET_NET_STATE_SEND_READY); if (err_state) sk_state = (enum mhd_SocketNetState) - (sk_state | (unsigned int) mhd_SOCKET_NET_STATE_ERROR_READY); + (sk_state | (unsigned int)mhd_SOCKET_NET_STATE_ERROR_READY); c->sk.ready = sk_state; - if (! c->suspended) + if (!c->suspended) mhd_conn_mark_ready_update3 (c, err_state, d); else - mhd_assert (! c->in_proc_ready); + mhd_assert (!c->in_proc_ready); } @@ -538,17 +538,17 @@ daemon_accept_new_conns (struct MHD_Daemon *restrict d) { unsigned int num_to_accept; mhd_assert (MHD_INVALID_SOCKET != d->net.listen.fd); - mhd_assert (! d->net.listen.is_broken); - mhd_assert (! d->conns.block_new); + mhd_assert (!d->net.listen.is_broken); + mhd_assert (!d->conns.block_new); mhd_assert (d->conns.count < d->conns.cfg.count_limit); - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); - if (! d->net.listen.non_block) + if (!d->net.listen.non_block) num_to_accept = 1; /* listen socket is blocking, only one connection can be processed */ else { const unsigned int slots_left = d->conns.cfg.count_limit - d->conns.count; - if (! mhd_D_HAS_MASTER (d)) + if (!mhd_D_HAS_MASTER (d)) { /* Fill up to one quarter of allowed limit in one turn */ num_to_accept = d->conns.cfg.count_limit / 4; @@ -669,8 +669,8 @@ is_conn_excluded_from_http_comm (struct MHD_Connection *restrict c) #ifdef MHD_SUPPORT_UPGRADE if (NULL != c->upgr.c) { - mhd_assert ((mhd_HTTP_STAGE_UPGRADED == c->stage) || \ - (mhd_HTTP_STAGE_UPGRADED_CLEANING == c->stage)); + mhd_assert ((mhd_HTTP_STAGE_UPGRADED == c->stage) \ + || (mhd_HTTP_STAGE_UPGRADED_CLEANING == c->stage)); return true; } #endif /* MHD_SUPPORT_UPGRADE */ @@ -683,16 +683,16 @@ static bool daemon_process_all_active_conns (struct MHD_Daemon *restrict d) { struct MHD_Connection *c; - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); - c = mhd_DLINKEDL_GET_FIRST (&(d->events),proc_ready); + c = mhd_DLINKEDL_GET_FIRST (&(d->events), proc_ready); while (NULL != c) { struct MHD_Connection *next; /* The current connection can be closed or removed from "ready" list */ next = mhd_DLINKEDL_GET_NEXT (c, proc_ready); - if (! mhd_conn_process_recv_send_data (c)) + if (!mhd_conn_process_recv_send_data (c)) { mhd_conn_pre_clean (c); mhd_conn_remove_from_daemon (c); @@ -700,7 +700,7 @@ daemon_process_all_active_conns (struct MHD_Daemon *restrict d) } else { - mhd_assert (! c->resuming || c->suspended); + mhd_assert (!c->resuming || c->suspended); } c = next; @@ -718,7 +718,7 @@ static MHD_FN_PAR_NONNULL_ALL_ void daemon_cleanup_upgraded_conns (struct MHD_Daemon *d) { volatile struct MHD_Daemon *voltl_d = d; - mhd_assert (! mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); if (NULL == mhd_DLINKEDL_GET_FIRST (&(voltl_d->conns.upgr), upgr_cleanup)) return; @@ -746,7 +746,7 @@ daemon_cleanup_upgraded_conns (struct MHD_Daemon *d) #else /* ! MHD_SUPPORT_UPGRADE */ -#define daemon_cleanup_upgraded_conns(d) ((void) d) +# define daemon_cleanup_upgraded_conns(d) ((void) d) #endif /* ! MHD_SUPPORT_UPGRADE */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void @@ -756,11 +756,11 @@ mhd_daemon_close_all_conns (struct MHD_Daemon *d) bool has_upgraded_unclosed; has_upgraded_unclosed = false; - if (! mhd_D_HAS_THR_PER_CONN (d)) + if (!mhd_D_HAS_THR_PER_CONN (d)) { - for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn); + for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn); NULL != c; - c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn)) + c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn)) { #ifdef MHD_SUPPORT_UPGRADE mhd_assert (mhd_HTTP_STAGE_UPGRADING != c->stage); @@ -828,9 +828,9 @@ ext_events_process_net_updates_and_resume_conn (struct MHD_Daemon *restrict d) } #endif /* MHD_SUPPORT_THREADS */ - for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn); + for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn); NULL != c; - c = mhd_DLINKEDL_GET_NEXT (c,all_conn)) + c = mhd_DLINKEDL_GET_NEXT (c, all_conn)) { bool has_err_state; @@ -840,11 +840,11 @@ ext_events_process_net_updates_and_resume_conn (struct MHD_Daemon *restrict d) { if (is_conn_excluded_from_http_comm (c)) { - mhd_assert (! c->in_proc_ready); + mhd_assert (!c->in_proc_ready); continue; } - has_err_state = (0 != (((unsigned int) c->sk.ready) + has_err_state = (0 != (((unsigned int)c->sk.ready) & mhd_SOCKET_NET_STATE_ERROR_READY)); mhd_conn_mark_ready_update3 (c, @@ -877,8 +877,8 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) /* (Re-)register daemon's FDs */ #ifdef MHD_SUPPORT_THREADS - if (rereg_all || - (NULL == d->events.data.extr.itc_data.app_cntx)) + if (rereg_all + || (NULL == d->events.data.extr.itc_data.app_cntx)) { /* (Re-)register ITC FD */ d->events.data.extr.itc_data.app_cntx = @@ -896,8 +896,8 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) if (daemon_fds_succeed) { - if ((MHD_INVALID_SOCKET == d->net.listen.fd) && - (NULL != d->events.data.extr.listen_data.app_cntx)) + if ((MHD_INVALID_SOCKET == d->net.listen.fd) + && (NULL != d->events.data.extr.listen_data.app_cntx)) { /* De-register the listen FD */ d->events.data.extr.listen_data.app_cntx = @@ -910,8 +910,9 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) if (NULL != d->events.data.extr.listen_data.app_cntx) mhd_log_extr_event_dereg_failed (d); } - else if ((MHD_INVALID_SOCKET != d->net.listen.fd) && - (rereg_all || (NULL == d->events.data.extr.listen_data.app_cntx))) + else if ((MHD_INVALID_SOCKET != d->net.listen.fd) + && (rereg_all + || (NULL == d->events.data.extr.listen_data.app_cntx))) { /* (Re-)register listen FD */ d->events.data.extr.listen_data.app_cntx = @@ -926,7 +927,7 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) } } - if (! daemon_fds_succeed) + if (!daemon_fds_succeed) { mhd_LOG_MSG (d, MHD_SC_EXT_EVENT_REG_DAEMON_FDS_FAILURE, \ "Failed to register daemon FDs in the application " @@ -934,7 +935,7 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) return MHD_SC_EXT_EVENT_REG_DAEMON_FDS_FAILURE; } - for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn); + for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn); NULL != c; c = c_next) { @@ -942,9 +943,9 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) /* Get the next connection now, as the current connection could be removed from the daemon. */ - c_next = mhd_DLINKEDL_GET_NEXT (c,all_conn); + c_next = mhd_DLINKEDL_GET_NEXT (c, all_conn); - mhd_assert (! c->resuming || c->suspended); + mhd_assert (!c->resuming || c->suspended); if (is_conn_excluded_from_http_comm (c)) { @@ -956,7 +957,7 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) c->sk.fd, MHD_FD_STATE_NONE, c->events.extrn.app_cntx, - (struct MHD_EventUpdateContext *) c); + (struct MHD_EventUpdateContext *)c); if (NULL != c->events.extrn.app_cntx) mhd_log_extr_event_dereg_failed (d); } @@ -966,18 +967,18 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) watch_for = edge_trigg ? MHD_FD_STATE_RECV_SEND_EXCEPT : - (enum MHD_FdState) (MHD_FD_STATE_EXCEPT - | (((unsigned int) c->event_loop_info) - & (MHD_EVENT_LOOP_INFO_RECV - | MHD_EVENT_LOOP_INFO_SEND))); - - mhd_assert ((! edge_trigg) || \ - (MHD_FD_STATE_RECV_SEND_EXCEPT == c->events.extrn.reg_for) || \ - (NULL == c->events.extrn.app_cntx)); - - if ((NULL == c->events.extrn.app_cntx) || - rereg_all || - (! edge_trigg && (watch_for != c->events.extrn.reg_for))) + (enum MHD_FdState)(MHD_FD_STATE_EXCEPT + | (((unsigned int)c->event_loop_info) + & (MHD_EVENT_LOOP_INFO_RECV + | MHD_EVENT_LOOP_INFO_SEND))); + + mhd_assert ((!edge_trigg) \ + || (MHD_FD_STATE_RECV_SEND_EXCEPT == c->events.extrn.reg_for) \ + || (NULL == c->events.extrn.app_cntx)); + + if ((NULL == c->events.extrn.app_cntx) + || rereg_all + || (!edge_trigg && (watch_for != c->events.extrn.reg_for))) { /* (Re-)register the connection socket FD */ c->events.extrn.app_cntx = @@ -985,7 +986,7 @@ ext_events_update_registrations (struct MHD_Daemon *restrict d) c->sk.fd, watch_for, c->events.extrn.app_cntx, - (struct MHD_EventUpdateContext *) c); + (struct MHD_EventUpdateContext *)c); if (NULL == c->events.extrn.app_cntx) { mhd_conn_start_closing_ext_event_failed (c); @@ -1022,22 +1023,22 @@ fd_set_wrap (MHD_Socket fd, mhd_assert (mhd_FD_FITS_DAEMON (d, fd)); /* Must be checked for every FD before it is added */ mhd_assert (mhd_POLL_TYPE_SELECT == d->events.poll_type); - (void) d; /* Unused with non-debug builds */ -#if defined(MHD_SOCKETS_KIND_POSIX) + (void)d; /* Unused with non-debug builds */ +# if defined(MHD_SOCKETS_KIND_POSIX) FD_SET (fd, fs); if (*max < fd) *max = fd; -#elif defined(MHD_SOCKETS_KIND_WINSOCK) +# elif defined(MHD_SOCKETS_KIND_WINSOCK) /* Use custom set function to take advantage of know uniqueness of * used sockets (to skip useless (for this function) check for duplicated * sockets implemented in system's macro). */ mhd_assert (fs->fd_count < FD_SETSIZE - 1); /* Daemon limits set to always fit FD_SETSIZE */ - mhd_assert (! FD_ISSET (fd, fs)); /* All sockets must be unique */ + mhd_assert (!FD_ISSET (fd, fs)); /* All sockets must be unique */ fs->fd_array[fs->fd_count++] = fd; *max = 1; -#else -#error Unknown sockets type -#endif +# else +# error Unknown sockets type +# endif } @@ -1071,7 +1072,7 @@ select_update_fdsets (struct MHD_Daemon *restrict d, FD_ZERO (efds); ret = 0; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); fd_set_wrap (mhd_itc_r_fd (d->threading.itc), rfds, @@ -1086,11 +1087,11 @@ select_update_fdsets (struct MHD_Daemon *restrict d, true, \ false, \ true); -#endif +# endif if ((MHD_INVALID_SOCKET != d->net.listen.fd) - && ! d->conns.block_new) + && !d->conns.block_new) { - mhd_assert (! d->net.listen.is_broken); + mhd_assert (!d->net.listen.is_broken); fd_set_wrap (d->net.listen.fd, rfds, @@ -1109,8 +1110,8 @@ select_update_fdsets (struct MHD_Daemon *restrict d, if (listen_only) return ret; - for (c = mhd_DLINKEDL_GET_LAST (&(d->conns),all_conn); NULL != c; - c = mhd_DLINKEDL_GET_PREV (c,all_conn)) + for (c = mhd_DLINKEDL_GET_LAST (&(d->conns), all_conn); NULL != c; + c = mhd_DLINKEDL_GET_PREV (c, all_conn)) { mhd_assert (mhd_HTTP_STAGE_CLOSED != c->stage); if (is_conn_excluded_from_http_comm (c)) @@ -1153,23 +1154,23 @@ select_update_statuses_from_fdsets_and_resume_conn (struct MHD_Daemon *d, mhd_assert (mhd_POLL_TYPE_SELECT == d->events.poll_type); mhd_assert (0 <= num_events); - mhd_assert (((unsigned int) num_events) <= d->dbg.num_events_elements); + mhd_assert (((unsigned int)num_events) <= d->dbg.num_events_elements); resuming_conn = d->events.act_req.resume; if (resuming_conn) { - mhd_assert (! mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type)); - mhd_assert (! mhd_D_HAS_THR_PER_CONN (d)); - num_events = (int) -1; /* Force process all connections */ + mhd_assert (!mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type)); + mhd_assert (!mhd_D_HAS_THR_PER_CONN (d)); + num_events = (int)-1; /* Force process all connections */ d->events.act_req.resume = false; } -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE if (0 == num_events) return true; -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); dbg_print_fd_state_update ("ITC", \ mhd_itc_r_fd (d->threading.itc), \ @@ -1193,15 +1194,15 @@ select_update_statuses_from_fdsets_and_resume_conn (struct MHD_Daemon *d, mhd_itc_clear (d->threading.itc); } -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE if (0 == num_events) return true; -#endif /* MHD_FAVOR_SMALL_CODE */ -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_SUPPORT_THREADS */ if (MHD_INVALID_SOCKET != d->net.listen.fd) { - mhd_assert (! d->net.listen.is_broken); + mhd_assert (!d->net.listen.is_broken); dbg_print_fd_state_update ("lstn", \ d->net.listen.fd, \ FD_ISSET (d->net.listen.fd, rfds), \ @@ -1212,17 +1213,17 @@ select_update_statuses_from_fdsets_and_resume_conn (struct MHD_Daemon *d, --num_events; log_listen_broken (d); /* Close the listening socket unless the master daemon should close it */ - if (! mhd_D_HAS_MASTER (d)) + if (!mhd_D_HAS_MASTER (d)) mhd_socket_close (d->net.listen.fd); d->events.accept_pending = false; d->net.listen.is_broken = true; /* Stop monitoring socket to avoid spinning with busy-waiting */ d->net.listen.fd = MHD_INVALID_SOCKET; -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE if (FD_ISSET (d->net.listen.fd, rfds)) --num_events; -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ } else { @@ -1232,13 +1233,13 @@ select_update_statuses_from_fdsets_and_resume_conn (struct MHD_Daemon *d, } } - mhd_assert ((0 == num_events) || \ - (! mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type))); + mhd_assert ((0 == num_events) \ + || (!mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type))); -#ifdef MHD_FAVOR_SMALL_CODE - (void) num_events; +# ifdef MHD_FAVOR_SMALL_CODE + (void)num_events; num_events = 1; /* Use static value to minimise the binary size of the next loop */ -#endif /* ! MHD_FAVOR_SMALL_CODE */ +# endif /* ! MHD_FAVOR_SMALL_CODE */ for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn); (NULL != c) && (0 != num_events); @@ -1266,16 +1267,16 @@ select_update_statuses_from_fdsets_and_resume_conn (struct MHD_Daemon *d, recv_ready, send_ready, err_state); -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE num_events -= (recv_ready ? 1 : 0) + (send_ready ? 1 : 0) + (err_state ? 1 : 0); -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ } } -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE mhd_assert ((0 == num_events) || resuming_conn); -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ return true; } @@ -1293,16 +1294,16 @@ get_timeval_for_select (const struct MHD_Daemon *restrict d, struct timeval *tmvl) { const uint_fast64_t max_wait = mhd_daemon_get_wait_max (d); -#ifdef HAVE_TIME_T - time_t max_wait_secs = (time_t) (max_wait / 1000u); -#else /* ! HAVE_TIME_T */ - long max_wait_secs = (long) (max_wait / 1000u); -#endif /* ! HAVE_TIME_T */ -#ifdef HAVE_SUSECONDS_T - suseconds_t max_wait_usecs = (suseconds_t) ((max_wait % 1000u) * 1000u); -#else /* ! HAVE_SUSECONDS_T */ - long max_wait_usecs = (long) ((max_wait % 1000u) * 1000u); -#endif /* ! HAVE_SUSECONDS_T */ +# ifdef HAVE_TIME_T + time_t max_wait_secs = (time_t)(max_wait / 1000u); +# else /* ! HAVE_TIME_T */ + long max_wait_secs = (long)(max_wait / 1000u); +# endif /* ! HAVE_TIME_T */ +# ifdef HAVE_SUSECONDS_T + suseconds_t max_wait_usecs = (suseconds_t)((max_wait % 1000u) * 1000u); +# else /* ! HAVE_SUSECONDS_T */ + long max_wait_usecs = (long)((max_wait % 1000u) * 1000u); +# endif /* ! HAVE_SUSECONDS_T */ if (MHD_WAIT_INDEFINITELY <= max_wait) return NULL; @@ -1316,8 +1317,8 @@ get_timeval_for_select (const struct MHD_Daemon *restrict d, } if (mhd_COND_ALMOST_NEVER ((max_wait / 1000u != - (uint_fast64_t) max_wait_secs) || - (max_wait_secs <= 0))) + (uint_fast64_t)max_wait_secs) + || (max_wait_secs <= 0))) { /* Do not bother figuring out the real maximum 'time_t' value. '0x7FFFFFFF' is large enough to be already unrealistic and should @@ -1360,39 +1361,39 @@ get_all_net_updates_by_select_and_resume_conn (struct MHD_Daemon *restrict d, tmvl_ptr = get_timeval_for_select (d, &tmvl_value); -#ifdef MHD_SOCKETS_KIND_WINSOCK +# ifdef MHD_SOCKETS_KIND_WINSOCK if (0 == max_socket) { Sleep (tmvl_ptr ? tmvl_ptr->tv_sec : 600); return true; } -#endif /* MHD_SOCKETS_KIND_WINSOCK */ +# endif /* MHD_SOCKETS_KIND_WINSOCK */ -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS if (NULL != tmvl_ptr) fprintf (stderr, "### (Starting) select(%d, rfds, wfds, efds, [%llu, %llu])...\n", max_socket + 1, - (unsigned long long) tmvl_ptr->tv_sec, - (unsigned long long) tmvl_ptr->tv_usec); + (unsigned long long)tmvl_ptr->tv_sec, + (unsigned long long)tmvl_ptr->tv_usec); else fprintf (stderr, "### (Starting) select(%d, rfds, wfds, efds, [NULL])...\n", max_socket + 1); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ num_events = select (max_socket + 1, d->events.data.select.rfds, d->events.data.select.wfds, d->events.data.select.efds, tmvl_ptr); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS if (NULL != tmvl_ptr) fprintf (stderr, "### (Finished) select(%d, rfds, wfds, efds, ->[%llu, %llu]) -> " "%d\n", max_socket + 1, - (unsigned long long) tmvl_ptr->tv_sec, - (unsigned long long) tmvl_ptr->tv_usec, + (unsigned long long)tmvl_ptr->tv_sec, + (unsigned long long)tmvl_ptr->tv_usec, num_events); else fprintf (stderr, @@ -1400,7 +1401,7 @@ get_all_net_updates_by_select_and_resume_conn (struct MHD_Daemon *restrict d, "%d\n", max_socket + 1, num_events); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ if (0 > num_events) { @@ -1409,7 +1410,7 @@ get_all_net_updates_by_select_and_resume_conn (struct MHD_Daemon *restrict d, bool is_ignored_error; is_hard_error = false; is_ignored_error = false; -#if defined(MHD_SOCKETS_KIND_POSIX) +# if defined(MHD_SOCKETS_KIND_POSIX) err = errno; if (0 != err) { @@ -1417,13 +1418,13 @@ get_all_net_updates_by_select_and_resume_conn (struct MHD_Daemon *restrict d, ((mhd_EBADF_OR_ZERO == err) || (mhd_EINVAL_OR_ZERO == err)); is_ignored_error = (mhd_EINTR_OR_ZERO == err); } -#elif defined(MHD_SOCKETS_KIND_WINSOCK) +# elif defined(MHD_SOCKETS_KIND_WINSOCK) err = WSAGetLastError (); is_hard_error = - ((WSAENETDOWN == err) || (WSAEFAULT == err) || (WSAEINVAL == err) || - (WSANOTINITIALISED == err)); -#endif - if (! is_ignored_error) + ((WSAENETDOWN == err) || (WSAEFAULT == err) || (WSAEINVAL == err) + || (WSANOTINITIALISED == err)); +# endif + if (!is_ignored_error) { if (is_hard_error) { @@ -1453,41 +1454,41 @@ poll_update_fds (struct MHD_Daemon *restrict d, unsigned int i_s; unsigned int i_c; struct MHD_Connection *restrict c; -#ifndef NDEBUG +# ifndef NDEBUG unsigned int num_skipped = 0; -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ mhd_assert (mhd_POLL_TYPE_POLL == d->events.poll_type); i_s = 0; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); mhd_assert (d->events.data.poll.fds[i_s].fd == \ mhd_itc_r_fd (d->threading.itc)); mhd_assert (mhd_SOCKET_REL_MARKER_ITC == \ d->events.data.poll.rel[i_s].fd_id); -#ifndef HAVE_POLL_CLOBBERS_EVENTS +# ifndef HAVE_POLL_CLOBBERS_EVENTS mhd_assert (POLLIN == d->events.data.poll.fds[i_s].events); -#else /* HAVE_POLL_CLOBBERS_EVENTS */ +# else /* HAVE_POLL_CLOBBERS_EVENTS */ d->events.data.poll.fds[i_s].events = POLLIN; -#endif /* HAVE_POLL_CLOBBERS_EVENTS */ +# endif /* HAVE_POLL_CLOBBERS_EVENTS */ mhd_dbg_print_fd_mon_req ("ITC", \ mhd_itc_r_fd (d->threading.itc), \ true, \ false, \ false); ++i_s; -#endif +# endif if (MHD_INVALID_SOCKET != d->net.listen.fd) { - mhd_assert (! d->net.listen.is_broken); + mhd_assert (!d->net.listen.is_broken); mhd_assert (d->events.data.poll.fds[i_s].fd == d->net.listen.fd); mhd_assert (mhd_SOCKET_REL_MARKER_LISTEN == \ d->events.data.poll.rel[i_s].fd_id); -#ifndef HAVE_POLL_CLOBBERS_EVENTS - mhd_assert ((POLLIN == d->events.data.poll.fds[i_s].events) || - (0 == d->events.data.poll.fds[i_s].events)); -#endif /* ! HAVE_POLL_CLOBBERS_EVENTS */ +# ifndef HAVE_POLL_CLOBBERS_EVENTS + mhd_assert ((POLLIN == d->events.data.poll.fds[i_s].events) + || (0 == d->events.data.poll.fds[i_s].events)); +# endif /* ! HAVE_POLL_CLOBBERS_EVENTS */ d->events.data.poll.fds[i_s].events = d->conns.block_new ? 0 : POLLIN; mhd_dbg_print_fd_mon_req ("lstn", \ d->net.listen.fd, \ @@ -1500,16 +1501,16 @@ poll_update_fds (struct MHD_Daemon *restrict d, return i_s; i_c = i_s; - for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn); NULL != c; - c = mhd_DLINKEDL_GET_NEXT (c,all_conn)) + for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn); NULL != c; + c = mhd_DLINKEDL_GET_NEXT (c, all_conn)) { unsigned short events; /* 'unsigned' for correct bits manipulations */ if (is_conn_excluded_from_http_comm (c)) { -#ifndef NDEBUG +# ifndef NDEBUG ++num_skipped; -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ continue; } @@ -1525,7 +1526,7 @@ poll_update_fds (struct MHD_Daemon *restrict d, if (0 != (c->event_loop_info & MHD_EVENT_LOOP_INFO_SEND)) events |= MHD_POLL_OUT; - d->events.data.poll.fds[i_c].events = (short) events; + d->events.data.poll.fds[i_c].events = (short)events; mhd_dbg_print_fd_mon_req ("conn", \ c->sk.fd, \ MHD_POLL_IN == (MHD_POLL_IN & events), \ @@ -1547,21 +1548,21 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d, unsigned int i_c; mhd_assert (mhd_POLL_TYPE_POLL == d->events.poll_type); mhd_assert (0 <= num_events); - mhd_assert (((unsigned int) num_events) <= d->dbg.num_events_elements); + mhd_assert (((unsigned int)num_events) <= d->dbg.num_events_elements); if (0 == num_events) return true; i_s = 0; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); mhd_assert (d->events.data.poll.fds[i_s].fd == \ mhd_itc_r_fd (d->threading.itc)); mhd_assert (mhd_SOCKET_REL_MARKER_ITC == \ d->events.data.poll.rel[i_s].fd_id); -#ifndef HAVE_POLL_CLOBBERS_EVENTS +# ifndef HAVE_POLL_CLOBBERS_EVENTS mhd_assert (POLLIN == d->events.data.poll.fds[i_s].events); -#endif /* ! HAVE_POLL_CLOBBERS_EVENTS */ +# endif /* ! HAVE_POLL_CLOBBERS_EVENTS */ dbg_print_fd_state_update ( \ "ITC", \ d->events.data.poll.fds[i_s].fd, \ @@ -1589,20 +1590,20 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d, if (0 == num_events) return true; -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ if (MHD_INVALID_SOCKET != d->net.listen.fd) { const short revents = d->events.data.poll.fds[i_s].revents; - mhd_assert (! d->net.listen.is_broken); + mhd_assert (!d->net.listen.is_broken); mhd_assert (d->events.data.poll.fds[i_s].fd == d->net.listen.fd); mhd_assert (mhd_SOCKET_REL_MARKER_LISTEN == \ d->events.data.poll.rel[i_s].fd_id); -#ifndef HAVE_POLL_CLOBBERS_EVENTS - mhd_assert ((POLLIN == d->events.data.poll.fds[i_s].events) || - (0 == d->events.data.poll.fds[i_s].events)); -#endif /* ! HAVE_POLL_CLOBBERS_EVENTS */ +# ifndef HAVE_POLL_CLOBBERS_EVENTS + mhd_assert ((POLLIN == d->events.data.poll.fds[i_s].events) + || (0 == d->events.data.poll.fds[i_s].events)); +# endif /* ! HAVE_POLL_CLOBBERS_EVENTS */ dbg_print_fd_state_update ("lstn", \ d->events.data.poll.fds[i_s].fd, \ 0 != (revents & (MHD_POLL_IN | POLLIN)), \ @@ -1613,7 +1614,7 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d, --num_events; log_listen_broken (d); /* Close the listening socket unless the master daemon should close it */ - if (! mhd_D_HAS_MASTER (d)) + if (!mhd_D_HAS_MASTER (d)) mhd_socket_close (d->net.listen.fd); d->events.accept_pending = false; @@ -1640,8 +1641,8 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d, ++i_s; } - mhd_assert ((0 == num_events) || \ - (! mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type))); + mhd_assert ((0 == num_events) \ + || (!mhd_D_TYPE_IS_LISTEN_ONLY (d->threading.d_type))); for (i_c = i_s; (i_c < i_s + d->conns.count) && (0 < num_events); ++i_c) { @@ -1659,14 +1660,14 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d, d->events.data.poll.rel[i_c].fd_id); c = d->events.data.poll.rel[i_c].connection; - mhd_assert (! is_conn_excluded_from_http_comm (c)); + mhd_assert (!is_conn_excluded_from_http_comm (c)); mhd_assert (c->sk.fd == d->events.data.poll.fds[i_c].fd); revents = d->events.data.poll.fds[i_c].revents; recv_ready = (0 != (revents & (MHD_POLL_IN | POLLIN))); send_ready = (0 != (revents & (MHD_POLL_OUT | POLLOUT))); -#ifndef MHD_POLLHUP_ON_REM_SHUT_WR +# ifndef MHD_POLLHUP_ON_REM_SHUT_WR err_state = (0 != (revents & (POLLHUP | POLLERR | POLLNVAL))); -#else +# else err_state = (0 != (revents & (POLLERR | POLLNVAL))); if (0 != (revents & POLLHUP)) { /* This can be a disconnect OR remote side set SHUT_WR */ @@ -1674,17 +1675,17 @@ poll_update_statuses_from_fds (struct MHD_Daemon *restrict d, if (0 == (c->event_loop_info & MHD_EVENT_LOOP_INFO_RECV)) err_state = true; /* The socket will not be checked by reading, the only way to avoid spinning */ } -#endif +# endif if (0 != (revents & (MHD_POLLPRI | MHD_POLLRDBAND))) { /* Statuses were not requested, but returned */ - if (! recv_ready || - (0 == (c->event_loop_info & MHD_EVENT_LOOP_INFO_RECV))) + if (!recv_ready + || (0 == (c->event_loop_info & MHD_EVENT_LOOP_INFO_RECV))) err_state = true; /* The socket will not be read, the only way to avoid spinning */ } if (0 != (revents & MHD_POLLWRBAND)) { /* Status was not requested, but returned */ - if (! send_ready || - (0 == (c->event_loop_info & MHD_EVENT_LOOP_INFO_SEND))) + if (!send_ready + || (0 == (c->event_loop_info & MHD_EVENT_LOOP_INFO_SEND))) err_state = true; /* The socket will not be written, the only way to avoid spinning */ } @@ -1700,13 +1701,13 @@ static MHD_FN_PAR_NONNULL_ (1) bool get_all_net_updates_by_poll (struct MHD_Daemon *restrict d, bool listen_only) { -#ifdef MHD_USE_TRACE_POLLING_FDS -# ifdef MHD_SOCKETS_KIND_POSIX +# ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_SOCKETS_KIND_POSIX static const char poll_fn_name[] = "poll"; -# else /* MHD_SOCKETS_KIND_WINSOCK */ +# else /* MHD_SOCKETS_KIND_WINSOCK */ static const char poll_fn_name[] = "WSAPoll"; -# endif /* MHD_SOCKETS_KIND_WINSOCK */ -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_SOCKETS_KIND_WINSOCK */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ unsigned int num_fds; int max_wait; int num_events; @@ -1718,24 +1719,24 @@ get_all_net_updates_by_poll (struct MHD_Daemon *restrict d, // TODO: handle empty list situation max_wait = get_max_wait (d); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Starting) %s(fds, %u, %d)...\n", poll_fn_name, num_fds, max_wait); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ num_events = mhd_poll (d->events.data.poll.fds, num_fds, max_wait); // TODO: use correct timeout value -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Finished) %s(fds, %u, %d) -> %d\n", poll_fn_name, num_fds, max_wait, num_events); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ if (0 > num_events) { int err; @@ -1743,7 +1744,7 @@ get_all_net_updates_by_poll (struct MHD_Daemon *restrict d, bool is_ignored_error; is_hard_error = false; is_ignored_error = false; -#if defined(MHD_SOCKETS_KIND_POSIX) +# if defined(MHD_SOCKETS_KIND_POSIX) err = errno; if (0 != err) { @@ -1751,12 +1752,12 @@ get_all_net_updates_by_poll (struct MHD_Daemon *restrict d, ((mhd_EFAULT_OR_ZERO == err) || (mhd_EINVAL_OR_ZERO == err)); is_ignored_error = (mhd_EINTR_OR_ZERO == err); } -#elif defined(MHD_SOCKETS_KIND_WINSOCK) +# elif defined(MHD_SOCKETS_KIND_WINSOCK) err = WSAGetLastError (); is_hard_error = ((WSAENETDOWN == err) || (WSAEFAULT == err) || (WSAEINVAL == err)); -#endif - if (! is_ignored_error) +# endif + if (!is_ignored_error) { if (is_hard_error) { @@ -1792,8 +1793,8 @@ update_statuses_from_eevents (struct MHD_Daemon *restrict d, for (i = 0; num_events > i; ++i) { struct epoll_event *const e = events + i; -#ifdef MHD_SUPPORT_THREADS - if (((uint64_t) mhd_SOCKET_REL_MARKER_ITC) == e->data.u64) /* uint64_t is in the system header */ +# ifdef MHD_SUPPORT_THREADS + if (((uint64_t)mhd_SOCKET_REL_MARKER_ITC) == e->data.u64) /* uint64_t is in the system header */ { mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); dbg_print_fd_state_update ( \ @@ -1820,8 +1821,8 @@ update_statuses_from_eevents (struct MHD_Daemon *restrict d, } } else -#endif /* MHD_SUPPORT_THREADS */ - if (((uint64_t) mhd_SOCKET_REL_MARKER_LISTEN) == e->data.u64) /* uint64_t is in the system header */ +# endif /* MHD_SUPPORT_THREADS */ + if (((uint64_t)mhd_SOCKET_REL_MARKER_LISTEN) == e->data.u64) /* uint64_t is in the system header */ { mhd_assert (MHD_INVALID_SOCKET != d->net.listen.fd); dbg_print_fd_state_update ( \ @@ -1835,16 +1836,16 @@ update_statuses_from_eevents (struct MHD_Daemon *restrict d, log_listen_broken (d); /* Close the listening socket unless the master daemon should close it */ - if (! mhd_D_HAS_MASTER (d)) + if (!mhd_D_HAS_MASTER (d)) mhd_socket_close (d->net.listen.fd); else { /* Ignore possible error as the socket could be already removed from the epoll monitoring by closing the socket */ - (void) epoll_ctl (d->events.data.epoll.e_fd, - EPOLL_CTL_DEL, - d->net.listen.fd, - NULL); + (void)epoll_ctl (d->events.data.epoll.e_fd, + EPOLL_CTL_DEL, + d->net.listen.fd, + NULL); } d->events.accept_pending = false; @@ -1860,8 +1861,8 @@ update_statuses_from_eevents (struct MHD_Daemon *restrict d, bool send_ready; bool err_state; struct MHD_Connection *const restrict c = - (struct MHD_Connection *) e->data.ptr; - mhd_assert (! is_conn_excluded_from_http_comm (c)); + (struct MHD_Connection *)e->data.ptr; + mhd_assert (!is_conn_excluded_from_http_comm (c)); recv_ready = (0 != (e->events & (EPOLLIN | EPOLLERR | EPOLLHUP))); send_ready = (0 != (e->events & (EPOLLOUT | EPOLLERR | EPOLLHUP))); err_state = (0 != (e->events & (EPOLLERR | EPOLLHUP))); @@ -1885,10 +1886,10 @@ get_all_net_updates_by_epoll (struct MHD_Daemon *restrict d) unsigned int events_processed; int max_wait; mhd_assert (mhd_POLL_TYPE_EPOLL == d->events.poll_type); - mhd_assert (0 < ((int) d->events.data.epoll.num_elements)); - mhd_assert (0 <= ((int) d->conns.count)); + mhd_assert (0 < ((int)d->events.data.epoll.num_elements)); + mhd_assert (0 <= ((int)d->conns.count)); mhd_assert (d->events.data.epoll.num_elements == \ - (size_t) ((int) d->events.data.epoll.num_elements)); + (size_t)((int)d->events.data.epoll.num_elements)); mhd_assert (0 != d->events.data.epoll.num_elements); mhd_assert (0 != d->conns.cfg.count_limit); mhd_assert (d->events.data.epoll.num_elements == d->dbg.num_events_elements); @@ -1896,42 +1897,42 @@ get_all_net_updates_by_epoll (struct MHD_Daemon *restrict d) // TODO: add listen socket enable/disable /* Minimise amount of data passed from userspace to kernel and back */ - max_events = (int) d->conns.count; -#ifdef MHD_SUPPORT_THREADS + max_events = (int)d->conns.count; +# ifdef MHD_SUPPORT_THREADS ++max_events; -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ if (MHD_INVALID_SOCKET != d->net.listen.fd) ++max_events; /* Make sure that one extra slot used to clearly detect that all events * were gotten. */ ++max_events; - if ((0 > max_events) || - (max_events > (int) d->events.data.epoll.num_elements)) - max_events = (int) d->events.data.epoll.num_elements; + if ((0 > max_events) + || (max_events > (int)d->events.data.epoll.num_elements)) + max_events = (int)d->events.data.epoll.num_elements; events_processed = 0; max_wait = get_max_wait (d); do { -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Starting) epoll_wait(%d, events, %d, %d)...\n", d->events.data.epoll.e_fd, - (int) d->events.data.epoll.num_elements, + (int)d->events.data.epoll.num_elements, max_wait); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ num_events = epoll_wait (d->events.data.epoll.e_fd, d->events.data.epoll.events, max_events, max_wait); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Finished) epoll_wait(%d, events, %d, %d) -> %d\n", d->events.data.epoll.e_fd, max_events, max_wait, num_events); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ max_wait = 0; if (0 > num_events) { @@ -1944,18 +1945,18 @@ get_all_net_updates_by_epoll (struct MHD_Daemon *restrict d) } return true; /* EINTR, try next time */ } - if (! update_statuses_from_eevents (d, (unsigned int) num_events)) + if (!update_statuses_from_eevents (d, (unsigned int)num_events)) return false; if (max_events > num_events) return true; /* All events have been read */ /* Use all buffer for the next getting events round(s) */ - max_events = (int) d->events.data.epoll.num_elements; + max_events = (int)d->events.data.epoll.num_elements; mhd_assert (0 < max_events); - mhd_assert (d->events.data.epoll.num_elements == (size_t) max_events); + mhd_assert (d->events.data.epoll.num_elements == (size_t)max_events); max_wait = 0; /* Do not block on the next getting events rounds */ - events_processed += (unsigned int) num_events; /* Avoid reading too many events */ + events_processed += (unsigned int)num_events; /* Avoid reading too many events */ } while ((events_processed < d->conns.cfg.count_limit) || (events_processed < d->conns.cfg.count_limit + 2)); @@ -1983,7 +1984,7 @@ kqueue_handle_missed_change (struct MHD_Daemon *restrict d, else { struct MHD_Connection *const restrict c = - (struct MHD_Connection *) mhd_KE_GET_UDATA (upd_event); + (struct MHD_Connection *)mhd_KE_GET_UDATA (upd_event); mhd_ASSUME (d == c->daemon); @@ -1996,7 +1997,7 @@ kqueue_handle_missed_change (struct MHD_Daemon *restrict d, static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,3) void +MHD_FN_PAR_IN_SIZE_ (2, 3) void kqueue_handle_missed_changes (struct MHD_Daemon *restrict d, struct kevent *restrict kes, int num_elements) @@ -2017,7 +2018,7 @@ update_kqueue_monitoring (struct MHD_Daemon *restrict d) struct MHD_Connection *c; struct kevent *restrict kes = d->events.data.kq.kes; int num_updates; - const int max_changes = (int) d->events.data.kq.num_elements; + const int max_changes = (int)d->events.data.kq.num_elements; mhd_assert (mhd_D_IS_USING_KQUEUE (d)); mhd_assert (NULL != kes); @@ -2027,7 +2028,7 @@ update_kqueue_monitoring (struct MHD_Daemon *restrict d) if (MHD_INVALID_SOCKET != d->net.listen.fd) { - mhd_assert (! d->net.listen.is_broken); + mhd_assert (!d->net.listen.is_broken); mhd_KE_SET (kes + num_updates, d->net.listen.fd, @@ -2044,14 +2045,14 @@ update_kqueue_monitoring (struct MHD_Daemon *restrict d) /* Process unmonitored connections starting from the earliest added unmonitored connection */ - c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn); + c = mhd_DLINKEDL_GET_FIRST (&(d->conns), all_conn); if ((NULL == c) || (c->events.kq.monitored)) return num_updates; while (1) { - struct MHD_Connection *const next_c = mhd_DLINKEDL_GET_NEXT (c,all_conn); + struct MHD_Connection *const next_c = mhd_DLINKEDL_GET_NEXT (c, all_conn); if (NULL == next_c) break; /* Found the end of the list */ if (next_c->events.kq.monitored) @@ -2060,13 +2061,13 @@ update_kqueue_monitoring (struct MHD_Daemon *restrict d) } mhd_ASSUME (NULL != c); - mhd_ASSUME (! c->events.kq.monitored); + mhd_ASSUME (!c->events.kq.monitored); - for ((void) c; NULL != c; c = mhd_DLINKEDL_GET_PREV (c,all_conn)) + for ((void)c; NULL != c; c = mhd_DLINKEDL_GET_PREV (c, all_conn)) { - mhd_ASSUME (! c->events.kq.monitored); + mhd_ASSUME (!c->events.kq.monitored); - mhd_assert (! is_conn_excluded_from_http_comm (c)); + mhd_assert (!is_conn_excluded_from_http_comm (c)); mhd_assert (mhd_HTTP_STAGE_CLOSED != c->stage); /* Check for the space for two filters */ @@ -2076,27 +2077,27 @@ update_kqueue_monitoring (struct MHD_Daemon *restrict d) static const struct timespec zero_timeout = {0, 0}; int res; -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Starting) kevent(%d, changes, %d, [NULL], " "0, [0, 0])...\n", d->events.data.kq.kq_fd, num_updates); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ res = mhd_kevent (d->events.data.kq.kq_fd, kes, num_updates, NULL, 0, &zero_timeout); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Finished) kevent(%d, changes, %d, [NULL], " "0, [0, 0]) -> %d\n", d->events.data.kq.kq_fd, num_updates, res); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ if (0 > res) { if (EINTR != errno) @@ -2136,7 +2137,7 @@ update_kqueue_monitoring (struct MHD_Daemon *restrict d) } mhd_assert (0 <= num_updates); - mhd_assert (num_updates <= (int) d->events.data.kq.num_elements); + mhd_assert (num_updates <= (int)d->events.data.kq.num_elements); return num_updates; } @@ -2159,11 +2160,11 @@ update_statuses_from_kevents (struct MHD_Daemon *restrict d, { struct kevent *const e = kes + i; bool eof_ready; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS if (mhd_SOCKET_REL_PTRMARKER_ITC == mhd_KE_GET_UDATA (e)) { mhd_assert (mhd_ITC_IS_VALID (d->threading.itc)); - mhd_assert (mhd_itc_r_fd (d->threading.itc) == (int) e->ident); + mhd_assert (mhd_itc_r_fd (d->threading.itc) == (int)e->ident); mhd_assert (EVFILT_READ == e->filter); mhd_assert (0 == (e->flags & EV_ERROR)); @@ -2186,12 +2187,12 @@ update_statuses_from_kevents (struct MHD_Daemon *restrict d, mhd_itc_clear (d->threading.itc); } else -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ if (mhd_SOCKET_REL_PTRMARKER_LISTEN == mhd_KE_GET_UDATA (e)) { bool listen_broken; mhd_assert (MHD_INVALID_SOCKET != d->net.listen.fd); - mhd_assert (d->net.listen.fd == (int) e->ident); + mhd_assert (d->net.listen.fd == (int)e->ident); mhd_assert (EVFILT_READ == e->filter); eof_ready = (0 != (e->flags & EV_EOF)); @@ -2210,7 +2211,7 @@ update_statuses_from_kevents (struct MHD_Daemon *restrict d, log_listen_broken (d); /* Close the listening socket unless the master daemon should close it */ - if (! mhd_D_HAS_MASTER (d)) + if (!mhd_D_HAS_MASTER (d)) mhd_socket_close (d->net.listen.fd); else { @@ -2224,28 +2225,28 @@ update_statuses_from_kevents (struct MHD_Daemon *restrict d, EV_DELETE, mhd_SOCKET_REL_PTRMARKER_LISTEN); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Starting) kevent(%d, changes, 1, [NULL], " "0, [0, 0])...\n", d->events.data.kq.kq_fd); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ res = mhd_kevent (d->events.data.kq.kq_fd, &remove_listen, 1, NULL, 0, &zero_timeout); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS fprintf (stderr, "### (Finished) kevent(%d, changes, 1, [NULL], " "0, [0, 0]) -> %d\n", d->events.data.kq.kq_fd, res); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ /* Ignore possible error as the socket could be already removed from the kqueue monitoring by closing the socket */ - (void) res; + (void)res; } d->events.accept_pending = false; @@ -2261,7 +2262,7 @@ update_statuses_from_kevents (struct MHD_Daemon *restrict d, bool recv_ready; bool send_ready; struct MHD_Connection *const restrict c = - (struct MHD_Connection *) mhd_KE_GET_UDATA (e); + (struct MHD_Connection *)mhd_KE_GET_UDATA (e); mhd_ASSUME (d == c->daemon); mhd_assert (c->events.kq.monitored); @@ -2285,7 +2286,7 @@ update_statuses_from_kevents (struct MHD_Daemon *restrict d, if (err_ready) { c->sk.state.discnt_err = - mhd_socket_error_get_from_sys_err ((int) e->fflags); + mhd_socket_error_get_from_sys_err ((int)e->fflags); mhd_assert (mhd_SOCKET_ERR_IS_HARD (c->sk.state.discnt_err)); } /* This is a tricky processing as each "filter" updates only its own @@ -2332,7 +2333,7 @@ get_all_net_updates_by_kqueue (struct MHD_Daemon *restrict d) mhd_assert (mhd_D_IS_USING_KQUEUE (d)); mhd_assert (0 < d->events.data.kq.kq_fd); - mhd_assert (0 < (int) (d->events.data.kq.num_elements)); + mhd_assert (0 < (int)(d->events.data.kq.num_elements)); mhd_assert (0 != d->events.data.kq.num_elements); mhd_assert (0 != d->conns.cfg.count_limit); mhd_assert (d->events.data.kq.num_elements == d->dbg.num_events_elements); @@ -2341,27 +2342,27 @@ get_all_net_updates_by_kqueue (struct MHD_Daemon *restrict d) mhd_ASSUME (0 <= num_updates); /* Minimise amount of data passed from userspace to kernel and back */ - max_events = (int) (d->conns.count * 2); -#ifdef MHD_SUPPORT_THREADS + max_events = (int)(d->conns.count * 2); +# ifdef MHD_SUPPORT_THREADS ++max_events; -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ if (MHD_INVALID_SOCKET != d->net.listen.fd) ++max_events; /* Make sure that one extra slot used to clearly detect that all events were gotten (if all provided slots are used then extra event could be pending still). */ ++max_events; - if ((0 >= max_events) || - (max_events > (int) d->events.data.kq.num_elements)) - max_events = (int) d->events.data.kq.num_elements; + if ((0 >= max_events) + || (max_events > (int)d->events.data.kq.num_elements)) + max_events = (int)d->events.data.kq.num_elements; max_wait = mhd_daemon_get_wait_max (d); - ke_timeout.tv_sec = (time_t) (max_wait / 1000); - ke_timeout.tv_nsec = (long) ((max_wait % 1000) * 1000000L); + ke_timeout.tv_sec = (time_t)(max_wait / 1000); + ke_timeout.tv_nsec = (long)((max_wait % 1000) * 1000000L); events_processed = 0; do { -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS if (max_wait == MHD_WAIT_INDEFINITELY) fprintf (stderr, "### (Starting) kevent(%d, changes, %d, events, " @@ -2376,9 +2377,9 @@ get_all_net_updates_by_kqueue (struct MHD_Daemon *restrict d) d->events.data.kq.kq_fd, num_updates, max_events, - (unsigned long long) ke_timeout.tv_sec, - (unsigned long long) ke_timeout.tv_nsec); -#endif /* MHD_USE_TRACE_POLLING_FDS */ + (unsigned long long)ke_timeout.tv_sec, + (unsigned long long)ke_timeout.tv_nsec); +# endif /* MHD_USE_TRACE_POLLING_FDS */ num_events = kevent (d->events.data.kq.kq_fd, d->events.data.kq.kes, @@ -2386,7 +2387,7 @@ get_all_net_updates_by_kqueue (struct MHD_Daemon *restrict d) d->events.data.kq.kes, max_events, (max_wait == MHD_WAIT_INDEFINITELY) ? NULL : &ke_timeout); -#ifdef MHD_USE_TRACE_POLLING_FDS +# ifdef MHD_USE_TRACE_POLLING_FDS if (max_wait == MHD_WAIT_INDEFINITELY) fprintf (stderr, "### (Finished) kevent(%d, changes, %d, events, " @@ -2402,10 +2403,10 @@ get_all_net_updates_by_kqueue (struct MHD_Daemon *restrict d) d->events.data.kq.kq_fd, num_updates, max_events, - (unsigned long long) ke_timeout.tv_sec, - (unsigned long long) ke_timeout.tv_nsec, + (unsigned long long)ke_timeout.tv_sec, + (unsigned long long)ke_timeout.tv_nsec, num_events); -#endif /* MHD_USE_TRACE_POLLING_FDS */ +# endif /* MHD_USE_TRACE_POLLING_FDS */ if (0 > num_events) { @@ -2417,14 +2418,14 @@ get_all_net_updates_by_kqueue (struct MHD_Daemon *restrict d) "The kevent() encountered unrecoverable error."); return false; } - if (! update_statuses_from_kevents (d, - (unsigned int) num_events)) + if (!update_statuses_from_kevents (d, + (unsigned int)num_events)) return false; if (max_events > num_events) return true; /* All events have been read */ /* Use all slots for the next round(s) of getting events */ - max_events = (int) d->events.data.kq.num_elements; + max_events = (int)d->events.data.kq.num_elements; max_wait = 0; /* Do not block on the next getting events rounds */ ke_timeout.tv_sec = 0; ke_timeout.tv_nsec = 0; @@ -2432,7 +2433,7 @@ get_all_net_updates_by_kqueue (struct MHD_Daemon *restrict d) mhd_assert (0 < max_events); /* If too many events are coming - process events that have been read already */ - events_processed += (size_t) num_events; + events_processed += (size_t)num_events; } while ((events_processed < (d->conns.cfg.count_limit * 2)) || (events_processed < (d->conns.cfg.count_limit * 2) + 2)); @@ -2454,8 +2455,8 @@ daemon_close_timedout_conns (struct MHD_Daemon *restrict d) struct MHD_Connection *prev_c; #if defined(MHD_SUPPORT_THREADS) - mhd_assert (! mhd_D_HAS_WORKERS (d)); - mhd_assert (! mhd_D_HAS_THR_PER_CONN (d)); + mhd_assert (!mhd_D_HAS_WORKERS (d)); + mhd_assert (!mhd_D_HAS_THR_PER_CONN (d)); #endif /* MHD_SUPPORT_THREADS */ /* Check "normal" timeouts list */ @@ -2463,7 +2464,7 @@ daemon_close_timedout_conns (struct MHD_Daemon *restrict d) while (NULL != c) { - mhd_assert (! c->timeout.in_cstm_tmout_list); + mhd_assert (!c->timeout.in_cstm_tmout_list); mhd_assert (0u != d->conns.cfg.timeout_milsec); if (mhd_conn_is_timeout_expired (c)) @@ -2542,32 +2543,32 @@ process_all_events_and_data (struct MHD_Daemon *restrict d) { case mhd_POLL_TYPE_EXT: mhd_assert (mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); - if (! ext_events_process_net_updates_and_resume_conn (d)) + if (!ext_events_process_net_updates_and_resume_conn (d)) return false; break; #ifdef MHD_SUPPORT_SELECT case mhd_POLL_TYPE_SELECT: - if (! get_all_net_updates_by_select_and_resume_conn (d, false)) + if (!get_all_net_updates_by_select_and_resume_conn (d, false)) return false; break; #endif /* MHD_SUPPORT_SELECT */ #ifdef MHD_SUPPORT_POLL case mhd_POLL_TYPE_POLL: - if (! get_all_net_updates_by_poll (d, false)) + if (!get_all_net_updates_by_poll (d, false)) return false; daemon_resume_conns_if_needed (d); break; #endif /* MHD_SUPPORT_POLL */ #ifdef MHD_SUPPORT_EPOLL case mhd_POLL_TYPE_EPOLL: - if (! get_all_net_updates_by_epoll (d)) + if (!get_all_net_updates_by_epoll (d)) return false; daemon_resume_conns_if_needed (d); break; #endif /* MHD_SUPPORT_EPOLL */ #ifdef MHD_SUPPORT_KQUEUE case mhd_POLL_TYPE_KQUEUE: - if (! get_all_net_updates_by_kqueue (d)) + if (!get_all_net_updates_by_kqueue (d)) return false; daemon_resume_conns_if_needed (d); break; @@ -2587,13 +2588,13 @@ process_all_events_and_data (struct MHD_Daemon *restrict d) mhd_daemon_process_ext_added_conns (d); - if (d->events.accept_pending && ! d->conns.block_new) - d->events.accept_pending = ! daemon_accept_new_conns (d); + if (d->events.accept_pending && !d->conns.block_new) + d->events.accept_pending = !daemon_accept_new_conns (d); daemon_process_all_active_conns (d); daemon_close_timedout_conns (d); daemon_cleanup_upgraded_conns (d); - return ! mhd_D_HAS_STOP_REQ (d); + return !mhd_D_HAS_STOP_REQ (d); } @@ -2606,7 +2607,7 @@ process_reg_events_int (struct MHD_Daemon *MHD_RESTRICT daemon, if (mhd_DAEMON_STATE_STARTED > daemon->state) return MHD_SC_TOO_EARLY; - if (! mhd_WM_INT_HAS_EXT_EVENTS (daemon->wmode_int)) + if (!mhd_WM_INT_HAS_EXT_EVENTS (daemon->wmode_int)) return MHD_SC_EXTERNAL_EVENT_ONLY; if (mhd_DAEMON_STATE_STARTED < daemon->state) return MHD_SC_TOO_LATE; @@ -2620,7 +2621,7 @@ process_reg_events_int (struct MHD_Daemon *MHD_RESTRICT daemon, return MHD_SC_DAEMON_SYS_DATA_BROKEN; /* Ignore returned value */ - (void) process_all_events_and_data (daemon); + (void)process_all_events_and_data (daemon); if (NULL != next_max_wait) *next_max_wait = MHD_WAIT_INDEFINITELY; @@ -2668,18 +2669,18 @@ MHD_daemon_process_reg_events (struct MHD_Daemon *MHD_RESTRICT daemon, fprintf (stderr, "### (Finished) MHD_daemon_process_reg_events(daemon, [NULL]) ->" "%u\n", - (unsigned int) res); + (unsigned int)res); else if (MHD_WAIT_INDEFINITELY == *next_max_wait) fprintf (stderr, "### (Finished) MHD_daemon_process_reg_events(daemon, " "->MHD_WAIT_INDEFINITELY) ->%u\n", - (unsigned int) res); + (unsigned int)res); else fprintf (stderr, "### (Finished) MHD_daemon_process_reg_events(daemon, ->%llu) " "->%u\n", - (unsigned long long) *next_max_wait, - (unsigned int) res); + (unsigned long long)*next_max_wait, + (unsigned int)res); #endif return res; } @@ -2694,29 +2695,29 @@ MHD_daemon_process_reg_events (struct MHD_Daemon *MHD_RESTRICT daemon, mhd_THRD_RTRN_TYPE mhd_THRD_CALL_SPEC mhd_worker_all_events (void *cls) { - struct MHD_Daemon *const restrict d = (struct MHD_Daemon *) cls; + struct MHD_Daemon *const restrict d = (struct MHD_Daemon *)cls; mhd_thread_handle_ID_set_current_thread_ID (&(d->threading.tid)); mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (mhd_D_TYPE_IS_VALID (d->threading.d_type)); mhd_assert (mhd_D_TYPE_HAS_EVENTS_PROCESSING (d->threading.d_type)); mhd_assert (mhd_DAEMON_TYPE_LISTEN_ONLY != d->threading.d_type); - mhd_assert (! mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); + mhd_assert (!mhd_D_TYPE_HAS_WORKERS (d->threading.d_type)); mhd_assert (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION != d->wmode_int); mhd_assert (d->dbg.events_fully_inited); mhd_assert (d->dbg.connections_inited); -#ifdef mhd_HAVE_MHD_THREAD_BLOCK_SIGPIPE +# ifdef mhd_HAVE_MHD_THREAD_BLOCK_SIGPIPE // TODO: store and use the result - (void) mhd_thread_block_sigpipe (); -#endif + (void)mhd_thread_block_sigpipe (); +# endif - while (! d->threading.stop_requested) + while (!d->threading.stop_requested) { - if (! process_all_events_and_data (d)) + if (!process_all_events_and_data (d)) break; } - if (! d->threading.stop_requested) + if (!d->threading.stop_requested) { mhd_LOG_MSG (d, MHD_SC_DAEMON_THREAD_STOP_UNEXPECTED, \ "The daemon thread is stopping, but termination has not " \ @@ -2724,12 +2725,12 @@ mhd_worker_all_events (void *cls) } mhd_daemon_close_all_conns (d); -#ifdef MHD_SUPPORT_HTTPS +# ifdef MHD_SUPPORT_HTTPS if (mhd_D_HAS_TLS (d)) mhd_tls_thread_cleanup (d->tls); -#endif /* MHD_SUPPORT_HTTPS */ +# endif /* MHD_SUPPORT_HTTPS */ - return (mhd_THRD_RTRN_TYPE) 0; + return (mhd_THRD_RTRN_TYPE)0; } @@ -2737,23 +2738,23 @@ static MHD_FN_PAR_NONNULL_ (1) bool process_listening_and_itc_only (struct MHD_Daemon *restrict d) { if (false) - (void) 0; -#ifdef MHD_SUPPORT_SELECT + (void)0; +# ifdef MHD_SUPPORT_SELECT else if (mhd_POLL_TYPE_SELECT == d->events.poll_type) { return false; // TODO: implement } -#endif /* MHD_SUPPORT_SELECT */ -#ifdef MHD_SUPPORT_POLL +# endif /* MHD_SUPPORT_SELECT */ +# ifdef MHD_SUPPORT_POLL else if (mhd_POLL_TYPE_POLL == d->events.poll_type) { - if (! get_all_net_updates_by_poll (d, true)) + if (!get_all_net_updates_by_poll (d, true)) return false; } -#endif /* MHD_SUPPORT_POLL */ +# endif /* MHD_SUPPORT_POLL */ else { - (void) d; /* Mute compiler warning */ + (void)d; /* Mute compiler warning */ mhd_assert (0 && "Impossible value"); mhd_UNREACHABLE (); MHD_PANIC ("Daemon data integrity broken"); @@ -2770,39 +2771,39 @@ process_listening_and_itc_only (struct MHD_Daemon *restrict d) mhd_THRD_RTRN_TYPE mhd_THRD_CALL_SPEC mhd_worker_listening_only (void *cls) { - struct MHD_Daemon *const restrict d = (struct MHD_Daemon *) cls; + struct MHD_Daemon *const restrict d = (struct MHD_Daemon *)cls; mhd_thread_handle_ID_set_current_thread_ID (&(d->threading.tid)); mhd_assert (d->dbg.net_inited); - mhd_assert (! d->dbg.net_deinited); + mhd_assert (!d->dbg.net_deinited); mhd_assert (mhd_DAEMON_TYPE_LISTEN_ONLY == d->threading.d_type); mhd_assert (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION == d->wmode_int); mhd_assert (d->dbg.events_fully_inited); mhd_assert (d->dbg.connections_inited); -#ifdef mhd_HAVE_MHD_THREAD_BLOCK_SIGPIPE +# ifdef mhd_HAVE_MHD_THREAD_BLOCK_SIGPIPE // TODO: store and use the result - (void) mhd_thread_block_sigpipe (); -#endif + (void)mhd_thread_block_sigpipe (); +# endif - while (! d->threading.stop_requested) + while (!d->threading.stop_requested) { - if (! process_listening_and_itc_only (d)) + if (!process_listening_and_itc_only (d)) break; } - if (! d->threading.stop_requested) + if (!d->threading.stop_requested) { mhd_LOG_MSG (d, MHD_SC_DAEMON_THREAD_STOP_UNEXPECTED, \ "The daemon thread is stopping, but termination has " \ "not been requested by the daemon."); } -#ifdef MHD_SUPPORT_HTTPS +# ifdef MHD_SUPPORT_HTTPS if (mhd_D_HAS_TLS (d)) mhd_tls_thread_cleanup (d->tls); -#endif /* MHD_SUPPORT_HTTPS */ +# endif /* MHD_SUPPORT_HTTPS */ - return (mhd_THRD_RTRN_TYPE) 0; + return (mhd_THRD_RTRN_TYPE)0; } @@ -2812,12 +2813,12 @@ mhd_worker_connection (void *cls) if (cls) // TODO: Implement MHD_PANIC ("Not yet implemented"); -#if 0 // def MHD_SUPPORT_HTTPS +# if 0 // def MHD_SUPPORT_HTTPS if (mhd_D_HAS_TLS (d)) mhd_tls_thread_cleanup (d->tls); -#endif /* MHD_SUPPORT_HTTPS */ +# endif /* MHD_SUPPORT_HTTPS */ - return (mhd_THRD_RTRN_TYPE) 0; + return (mhd_THRD_RTRN_TYPE)0; } diff --git a/src/mhd2/extr_events_funcs.c b/src/mhd2/extr_events_funcs.c @@ -47,7 +47,7 @@ #ifdef MHD_SUPPORT_LOG_FUNCTIONALITY -#include "daemon_logger.h" +# include "daemon_logger.h" MHD_INTERNAL void mhd_log_extr_event_dereg_failed (struct MHD_Daemon *restrict d) diff --git a/src/mhd2/extr_events_funcs.h b/src/mhd2/extr_events_funcs.h @@ -69,7 +69,7 @@ mhd_log_extr_event_dereg_failed (struct MHD_Daemon *restrict d); /** * Log message about failed de-registration of FDs (no-op implementation) */ -#define mhd_log_extr_event_dereg_failed(d) ((void) 0) +# define mhd_log_extr_event_dereg_failed(d) ((void) 0) #endif /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ @@ -97,7 +97,7 @@ mhd_daemon_extr_event_reg (struct MHD_Daemon *d, mhd_assert (mhd_WM_INT_HAS_EXT_EVENTS (d->wmode_int)); mhd_assert (mhd_POLL_TYPE_EXT == d->events.poll_type); - mhd_assert (mhd_SOCKET_REL_MARKER_EMPTY != (mhd_SockRelMarker) ecb_cntx); + mhd_assert (mhd_SOCKET_REL_MARKER_EMPTY != (mhd_SockRelMarker)ecb_cntx); res = d->events.data.extr.cb_data.cb (d->events.data.extr.cb_data.cls, @@ -117,7 +117,7 @@ mhd_daemon_extr_event_reg (struct MHD_Daemon *d, state_str[2] = MHD_FD_STATE_IS_SET_SEND (watch_for) ? 'W' : '-'; state_str[4] = MHD_FD_STATE_IS_SET_EXCEPT (watch_for) ? 'E' : '-'; - switch ((mhd_SockRelMarker) ecb_cntx) + switch ((mhd_SockRelMarker)ecb_cntx) { case mhd_SOCKET_REL_MARKER_ITC: fd_rel = "ITC: "; @@ -134,17 +134,17 @@ mhd_daemon_extr_event_reg (struct MHD_Daemon *d, "-> 0x%08llX\n", reg_type, fd_rel, - (unsigned long long) fd, + (unsigned long long)fd, state_str, - (unsigned long long) app_cntx_old, - (unsigned long long) res); + (unsigned long long)app_cntx_old, + (unsigned long long)res); return res; } #else /* ! MHD_USE_TRACE_POLLING_FDS */ -# define mhd_daemon_extr_event_reg(d,fd,w_for,app_cntx_old,ecb_cntx) \ - d->events.data.extr.cb_data.cb (d->events.data.extr.cb_data.cls, \ - fd, w_for, app_cntx_old, ecb_cntx) +# define mhd_daemon_extr_event_reg(d, fd, w_for, app_cntx_old, ecb_cntx) \ + d->events.data.extr.cb_data.cb (d->events.data.extr.cb_data.cls, \ + fd, w_for, app_cntx_old, ecb_cntx) #endif /* ! MHD_USE_TRACE_POLLING_FDS */ diff --git a/src/mhd2/h2/h2_action.c b/src/mhd2/h2/h2_action.c @@ -61,15 +61,15 @@ mhd_h2_act_is_resp_h2_compatible (const struct mhd_H2RequestData *restrict req, mhd_assert (req->is_http2); // TODO: move new two checks to the unified (HTTP/1.x and HTTP/2) code - if ((mhd_HTTP_METHOD_CONNECT == req->method) && - (200 <= response->sc) && (299 >= response->sc)) + if ((mhd_HTTP_METHOD_CONNECT == req->method) + && (200 <= response->sc) && (299 >= response->sc)) return false; - if ((MHD_NO != response->cfg.head_only) && - (200 <= response->sc) && - (MHD_HTTP_STATUS_NOT_MODIFIED != response->sc) && - (MHD_HTTP_STATUS_NO_CONTENT != response->sc) && - (mhd_HTTP_METHOD_HEAD != req->method)) + if ((MHD_NO != response->cfg.head_only) + && (200 <= response->sc) + && (MHD_HTTP_STATUS_NOT_MODIFIED != response->sc) + && (MHD_HTTP_STATUS_NO_CONTENT != response->sc) + && (mhd_HTTP_METHOD_HEAD != req->method)) return false; // TODO: support digest auth with HTTP/2 @@ -85,8 +85,8 @@ mhd_h2_act_is_resp_h2_compatible (const struct mhd_H2RequestData *restrict req, && (mhd_RESPONSE_CONTENT_DATA_FILE != response->cntn_dtype) && (mhd_RESPONSE_CONTENT_DATA_IOVEC != response->cntn_dtype)) return false; - if ((mhd_RESPONSE_CONTENT_DATA_FILE == response->cntn_dtype) && - response->cntn.file.is_pipe) + if ((mhd_RESPONSE_CONTENT_DATA_FILE == response->cntn_dtype) + && response->cntn.file.is_pipe) return false; return true; diff --git a/src/mhd2/h2/h2_app_cb.c b/src/mhd2/h2/h2_app_cb.c @@ -83,12 +83,12 @@ mhd_h2_stream_cb_early_uri (struct mhd_H2Stream *restrict s) struct MHD_EarlyUriCbData req_data; bool res; - req_data.request = (struct MHD_Request *) (void*) &(s->req); + req_data.request = (struct MHD_Request *)(void *)&(s->req); res = mhd_h2_items_get_item_value (s->c->h2.mem.req_ib, s->req.pos_path, &(req_data.full_uri)); mhd_assert (res); - (void) res; + (void)res; if (s->c->h2.state.top_proc_stream_id < s->stream_id) s->c->h2.state.top_proc_stream_id = s->stream_id; @@ -130,7 +130,7 @@ mhd_h2_stream_cb_request (struct mhd_H2Stream *restrict s) s->req.pos_path, &(path)); mhd_assert (res); - (void) res; + (void)res; } if (s->c->h2.state.top_proc_stream_id < s->stream_id) @@ -138,14 +138,14 @@ mhd_h2_stream_cb_request (struct mhd_H2Stream *restrict s) s->req.app_seen = true; a = d->req_cfg.cb (d->req_cfg.cb_cls, - (struct MHD_Request *) (void*) &(s->req), + (struct MHD_Request *)(void *)&(s->req), &path, - (enum MHD_HTTP_Method) s->req.method, + (enum MHD_HTTP_Method)s->req.method, s->req.cntn_size); if ((NULL != a) && (((&(s->req.app_act.head_act) != a)) - || ! mhd_ACTION_IS_VALID (s->req.app_act.head_act.act))) + || !mhd_ACTION_IS_VALID (s->req.app_act.head_act.act))) { mhd_LOG_MSG (d, MHD_SC_ACTION_INVALID, \ "Provided action is not a correct action generated " \ @@ -192,14 +192,14 @@ mhd_h2_stream_cb_request (struct mhd_H2Stream *restrict s) case mhd_ACTION_UPLOAD: if (0 != s->req.cntn_size) { - if (! check_and_alloc_buf_for_upload_processing (c)) + if (!check_and_alloc_buf_for_upload_processing (c)) return true; c->stage = mhd_HTTP_STAGE_BODY_RECEIVING; return (0 != c->read_buffer_offset); } c->stage = mhd_HTTP_STAGE_FULL_REQ_RECEIVED; return true; -#ifdef MHD_SUPPORT_POST_PARSER +# ifdef MHD_SUPPORT_POST_PARSER case mhd_ACTION_POST_PARSE: if (0 == s->req.cntn.cntn_size) { @@ -207,7 +207,7 @@ mhd_h2_stream_cb_request (struct mhd_H2Stream *restrict s) c->stage = mhd_HTTP_STAGE_FULL_REQ_RECEIVED; return true; } - if (! mhd_stream_prepare_for_post_parse (c)) + if (!mhd_stream_prepare_for_post_parse (c)) { mhd_assert (mhd_HTTP_STAGE_FOOTERS_RECEIVED < c->stage); return true; @@ -219,22 +219,22 @@ mhd_h2_stream_cb_request (struct mhd_H2Stream *restrict s) } c->stage = mhd_HTTP_STAGE_BODY_RECEIVING; return true; -#endif /* MHD_SUPPORT_POST_PARSER */ +# endif /* MHD_SUPPORT_POST_PARSER */ case mhd_ACTION_SUSPEND: c->suspended = true; -#ifdef MHD_USE_TRACE_SUSPEND_RESUME +# ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Suspending connection, FD: %2llu\n", - (unsigned long long) c->sk.fd); -#endif /* MHD_USE_TRACE_SUSPEND_RESUME */ + (unsigned long long)c->sk.fd); +# endif /* MHD_USE_TRACE_SUSPEND_RESUME */ s->req.app_act.head_act.act = mhd_ACTION_NO_ACTION; return false; -#ifdef MHD_SUPPORT_UPGRADE +# ifdef MHD_SUPPORT_UPGRADE case mhd_ACTION_UPGRADE: mhd_assert (0 == s->req.cntn.cntn_size); c->stage = mhd_HTTP_STAGE_UPGRADE_HEADERS_SENDING; return false; -#endif /* MHD_SUPPORT_UPGRADE */ +# endif /* MHD_SUPPORT_UPGRADE */ case mhd_ACTION_ABORT: mhd_conn_start_closing_app_abort (c); return true; diff --git a/src/mhd2/h2/h2_comm.c b/src/mhd2/h2/h2_comm.c @@ -199,8 +199,8 @@ h2_switch_to_h2 (struct MHD_Connection *restrict c) c->h2.peer.stream_init_win_sz = mhd_H2_STNG_DEF_INIT_WIN_SIZE; c->h2.peer.max_frame_size = mhd_H2_STNG_DEF_MAX_FRAME_SIZE; - c->h2.peer.max_header_list = (uint_least32_t) (~((uint_least32_t) 0u)); - c->h2.peer.max_concur_streams = (uint_least32_t) (~((uint_least32_t) 0u)); + c->h2.peer.max_header_list = (uint_least32_t)(~((uint_least32_t)0u)); + c->h2.peer.max_concur_streams = (uint_least32_t)(~((uint_least32_t)0u)); buff_size = mhd_pool_get_size (c->pool); c->read_buffer = @@ -275,10 +275,10 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void mhd_h2_conn_h2_deinit_start_closing (struct MHD_Connection *restrict c) { mhd_assert (mhd_C_IS_HTTP2 (c)); - mhd_assert ((mhd_HTTP_LAYER_CONNECTED == c->h_layer.state) || - (mhd_HTTP_LAYER_CLOSING == c->h_layer.state) || - (mhd_HTTP_LAYER_BROKEN == c->h_layer.state)); - mhd_assert (! c->h2.dbg.h2_deinited); + mhd_assert ((mhd_HTTP_LAYER_CONNECTED == c->h_layer.state) + || (mhd_HTTP_LAYER_CLOSING == c->h_layer.state) + || (mhd_HTTP_LAYER_BROKEN == c->h_layer.state)); + mhd_assert (!c->h2.dbg.h2_deinited); mhd_h2_conn_close_streams_all (c); @@ -300,9 +300,9 @@ mhd_h2_conn_h2_deinit_start_closing (struct MHD_Connection *restrict c) c->h2.dbg.h2_deinited = true; #endif /* ! NDEBUG */ - if ((mhd_HTTP_LAYER_BROKEN == c->h_layer.state) || - (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err) || - (0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY))) + if ((mhd_HTTP_LAYER_BROKEN == c->h_layer.state) + || (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err) + || (0 != (c->sk.ready & mhd_SOCKET_NET_STATE_ERROR_READY))) mhd_conn_start_closing_h2_hard (c); else mhd_conn_start_closing_h2_soft (c); @@ -331,7 +331,7 @@ h2_handle_preface_found (struct MHD_Connection *restrict c) mhd_assert (mhd_HTTP_LAYER_PREFACE == c->h_layer.state); mhd_assert (mhd_H2_PREFACE_LEN <= c->read_buffer_offset); - if (! mhd_D_IS_HTTP2_ENABLED (c->daemon)) + if (!mhd_D_IS_HTTP2_ENABLED (c->daemon)) { c->h_layer.state = mhd_HTTP_LAYER_CONNECTED; c->h_layer.fam = mhd_HTTP_VER_FAM_NOT_2; @@ -348,7 +348,7 @@ h2_handle_preface_found (struct MHD_Connection *restrict c) { case mhd_TLS_ALPN_PROT_HTTP1_0: case mhd_TLS_ALPN_PROT_HTTP1_1: - if (! allow_on_alpn_mismatch) + if (!allow_on_alpn_mismatch) { c->h_layer.state = mhd_HTTP_LAYER_CONNECTED; c->h_layer.fam = mhd_HTTP_VER_FAM_NOT_2; @@ -362,7 +362,7 @@ h2_handle_preface_found (struct MHD_Connection *restrict c) break; case mhd_TLS_ALPN_PROT_NOT_SELECTED: case mhd_TLS_ALPN_PROT_ERROR: - if (! allow_without_alpn) + if (!allow_without_alpn) { c->h_layer.state = mhd_HTTP_LAYER_CONNECTED; c->h_layer.fam = mhd_HTTP_VER_FAM_NOT_2; @@ -419,7 +419,7 @@ h2_handle_preface_not_found (struct MHD_Connection *restrict c) case mhd_TLS_ALPN_PROT_ERROR: break; case mhd_TLS_ALPN_PROT_HTTP2: - if (! allow_on_alpn_mismatch) + if (!allow_on_alpn_mismatch) { c->h_layer.state = mhd_HTTP_LAYER_BROKEN; c->h_layer.fam = mhd_HTTP_VER_FAM_INVALID; @@ -441,7 +441,7 @@ h2_handle_preface_not_found (struct MHD_Connection *restrict c) } #endif /* MHD_SUPPORT_HTTPS */ - if (! mhd_D_IS_HTTP1_ENABLED (c->daemon)) + if (!mhd_D_IS_HTTP1_ENABLED (c->daemon)) { c->h_layer.state = mhd_HTTP_LAYER_CONNECTED; c->h_layer.fam = mhd_HTTP_VER_FAM_NOT_2; @@ -497,12 +497,12 @@ mhd_h2_conn_state_update (struct MHD_Connection *restrict c) new_state = 0u; if (c->read_buffer_offset < c->read_buffer_size) - new_state |= (unsigned int) MHD_EVENT_LOOP_INFO_RECV; + new_state |= (unsigned int)MHD_EVENT_LOOP_INFO_RECV; if (c->write_buffer_send_offset < c->write_buffer_append_offset) - new_state |= (unsigned int) MHD_EVENT_LOOP_INFO_SEND; + new_state |= (unsigned int)MHD_EVENT_LOOP_INFO_SEND; - c->event_loop_info = (enum MHD_ConnectionEventLoopInfo) new_state; + c->event_loop_info = (enum MHD_ConnectionEventLoopInfo)new_state; } @@ -515,8 +515,8 @@ h2_conn_manage_buff_out (struct MHD_Connection *restrict c) c->write_buffer_send_offset = 0u; c->write_buffer_append_offset = 0u; } - else if ((0u != c->write_buffer_append_offset) && - (c->write_buffer_send_offset > c->write_buffer_size / 128)) + else if ((0u != c->write_buffer_append_offset) + && (c->write_buffer_send_offset > c->write_buffer_size / 128)) { const size_t left_unsent = c->write_buffer_append_offset - c->write_buffer_send_offset; @@ -534,16 +534,16 @@ h2_conn_process_data_inner (struct MHD_Connection *restrict c) { /* Check whether first SETTINGS frame was send (queued). It is a part of connection initialisation. */ - if (! c->h2.state.init.sent_setns) + if (!c->h2.state.init.sent_setns) { - if (! mhd_h2_q_settings_first_fr (c)) + if (!mhd_h2_q_settings_first_fr (c)) return; } /* Check whether first peer SETTINGS frame was received. It is a part of connection initialisation. */ - if (! c->h2.state.init.got_setns) + if (!c->h2.state.init.got_setns) { - if (! mhd_h2_conn_process_first_fr (c)) + if (!mhd_h2_conn_process_first_fr (c)) return; /* HTTP/2 cannot be processed */ } @@ -555,7 +555,7 @@ h2_conn_process_data_inner (struct MHD_Connection *restrict c) If connection is broken or output buffer has no space to add required frame, this connection processing is stopped here until the output buffer got more space. */ - if (! mhd_h2_conn_process_in_data (c)) + if (!mhd_h2_conn_process_in_data (c)) return; /* Close broken streams, update receive windows. @@ -564,7 +564,7 @@ h2_conn_process_data_inner (struct MHD_Connection *restrict c) If connection is broken or output buffer has no space to add required frame, this connection processing is stopped here until the output buffer got more space. */ - if (! mhd_h2_conn_process_changes (c)) + if (!mhd_h2_conn_process_changes (c)) return; /* Finally send the replies (if output buffer still have any space). */ @@ -596,8 +596,8 @@ mhd_h2_conn_process_data (struct MHD_Connection *restrict c) h2_conn_process_data_inner (c); mhd_assert (mhd_HTTP_LAYER_CLOSED != c->h_layer.state); - if ((mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err) || - (mhd_HTTP_LAYER_CLOSING == c->h_layer.state)) + if ((mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err) + || (mhd_HTTP_LAYER_CLOSING == c->h_layer.state)) { mhd_h2_conn_h2_deinit_start_closing (c); return false; diff --git a/src/mhd2/h2/h2_comm.h b/src/mhd2/h2/h2_comm.h @@ -63,7 +63,7 @@ mhd_h2_blank_init (struct MHD_Connection *restrict c); MHD_FN_PAR_NONNULL_ALL_; #else /* ! HAVE_NULL_PTR_ALL_ZEROS */ -#define mhd_h2_blank_init(c) ((void) 0) +# define mhd_h2_blank_init(c) ((void) 0) #endif /* ! HAVE_NULL_PTR_ALL_ZEROS */ /** diff --git a/src/mhd2/h2/h2_conn_data.h b/src/mhd2/h2/h2_conn_data.h @@ -234,9 +234,9 @@ struct mhd_H2ConnData #ifndef NDEBUG # define mhd_H2_W_BUFF_UPDATING_SET(h2data) \ - do {(h2data)->dbg.w_buff_updating = true;} while (0) + do {(h2data)->dbg.w_buff_updating = true;} while (0) # define mhd_H2_W_BUFF_UPDATING_CLEAR(h2data) \ - do {(h2data)->dbg.w_buff_updating = false;} while (0) + do {(h2data)->dbg.w_buff_updating = false;} while (0) #else /* NDEBUG */ # define mhd_H2_W_BUFF_UPDATING_SET(h2data) ((void) 0) # define mhd_H2_W_BUFF_UPDATING_CLEAR(h2data) ((void) 0) diff --git a/src/mhd2/h2/h2_conn_streams.c b/src/mhd2/h2/h2_conn_streams.c @@ -90,8 +90,8 @@ conn_add_new_stream (struct MHD_Connection *restrict c, mhd_assert ((stream_id & mhd_H2_STREAM_ID_MASK) == stream_id); mhd_assert (c->h2.rcv_cfg.max_concur_streams > c->h2.streams.num_streams); - s = (struct mhd_H2Stream *) mhd_calloc (1u, - sizeof(struct mhd_H2Stream)); + s = (struct mhd_H2Stream *)mhd_calloc (1u, + sizeof(struct mhd_H2Stream)); if (NULL == s) return NULL; @@ -112,9 +112,9 @@ conn_add_new_stream (struct MHD_Connection *restrict c, s->req.pos_path = mhd_H2_REQ_ITEM_POS_INVALID; s->req.pos_authority = mhd_H2_REQ_ITEM_POS_INVALID; - s->state.recv_window = (int_least32_t) c->h2.rcv_cfg.stream_init_win_sz; + s->state.recv_window = (int_least32_t)c->h2.rcv_cfg.stream_init_win_sz; mhd_assert (0 < s->state.recv_window); - s->state.send_window = (int_least32_t) c->h2.peer.stream_init_win_sz; + s->state.send_window = (int_least32_t)c->h2.peer.stream_init_win_sz; mhd_assert (0 < s->state.send_window); mhd_DLINKEDL_INS_LAST_D (&(c->h2.streams.active), s, streams); @@ -169,7 +169,7 @@ mhd_h2_stream_req_problem (struct mhd_H2Stream *restrict s, enum mhd_H2RequestProblemType problem_type) { // TODO: send error reply - (void) problem_type; + (void)problem_type; return mhd_h2_stream_abort (s, mhd_H2_ERR_PROTOCOL_ERROR); // TODO: use correct error code } @@ -179,12 +179,12 @@ static MHD_FN_PAR_NONNULL_ALL_ bool stream_send_rst_stream (struct mhd_H2Stream *restrict s, enum mhd_H2ErrorCode err) { - mhd_assert ((! s->state.sent_rst_stream) && - "RST_STREAM must not be sent more than once for active stream"); + mhd_assert ((!s->state.sent_rst_stream) + && "RST_STREAM must not be sent more than once for active stream"); - if (! mhd_h2_q_rst_stream (s->c, - s->stream_id, - err)) + if (!mhd_h2_q_rst_stream (s->c, + s->stream_id, + err)) return false; s->state.sent_rst_stream = true; @@ -218,21 +218,21 @@ stream_proc_complete_headers (struct mhd_H2Stream *restrict s) s->req.stage = mhd_H2_REQ_STAGE_HEADERS_DECODING; s->req.cntn_size = (s->req.got_end_stream ? 0u : MHD_SIZE_UNKNOWN); - if (! mhd_h2_req_headers_preprocess (s)) + if (!mhd_h2_req_headers_preprocess (s)) return false; - if (! mhd_h2_stream_cb_early_uri (s)) + if (!mhd_h2_stream_cb_early_uri (s)) return false; - if (! mhd_h2_req_uri_parse (s)) + if (!mhd_h2_req_uri_parse (s)) return false; - if (! mhd_h2_req_cookie_parse (s)) + if (!mhd_h2_req_cookie_parse (s)) return false; s->req.stage = mhd_H2_REQ_STAGE_HEADERS_PROCESSING; - if (! mhd_h2_stream_cb_request (s)) + if (!mhd_h2_stream_cb_request (s)) return false; mhd_assert (mhd_H2_REQ_STAGE_BROKEN != s->req.stage); @@ -295,15 +295,15 @@ stream_proc_in_headers (struct mhd_H2Stream *restrict s, } if (end_headers && (0u != unprocessed)) - return ! mhd_h2_conn_finish (c, - mhd_H2_ERR_COMPRESSION_ERROR, - true); + return !mhd_h2_conn_finish (c, + mhd_H2_ERR_COMPRESSION_ERROR, + true); - if (! end_headers) + if (!end_headers) { if (0u != unprocessed) { - const size_t payload_offset = (size_t) (payload->data - c->read_buffer); + const size_t payload_offset = (size_t)(payload->data - c->read_buffer); /* Unprocessed part may contain only a single field line. Stop stream if it is larger than 3/4 of the max headers size. */ @@ -454,8 +454,8 @@ static MHD_FN_PAR_NONNULL_ALL_ void stream_set_reply_props (struct mhd_H2Stream *restrict s) { mhd_assert (mhd_H2_RPL_STAGE_HEADERS_INCOMPLETE == s->rpl.stage); - mhd_assert ((mhd_H2_REQ_STAGE_END_STREAM == s->req.stage) || - (mhd_H2_REQ_STAGE_HEADERS_COMPLETE == s->req.stage)); + mhd_assert ((mhd_H2_REQ_STAGE_END_STREAM == s->req.stage) + || (mhd_H2_REQ_STAGE_HEADERS_COMPLETE == s->req.stage)); mhd_assert (NULL != s->rpl.response); #if 0 // TODO: implement chained replies if (199 >= s->rpl.response->sc) @@ -471,8 +471,8 @@ stream_set_reply_props (struct mhd_H2Stream *restrict s) s->rpl.fields.auto_cntn_len = false; s->rpl.send_content = false; } - else if ((mhd_HTTP_METHOD_HEAD == s->req.method) || - (MHD_HTTP_STATUS_NOT_MODIFIED == s->rpl.response->sc)) + else if ((mhd_HTTP_METHOD_HEAD == s->req.method) + || (MHD_HTTP_STATUS_NOT_MODIFIED == s->rpl.response->sc)) { s->rpl.fields.auto_cntn_len = (MHD_NO == s->rpl.response->cfg.head_only) @@ -524,8 +524,8 @@ mhd_h2_conn_streamid_window_incr (struct MHD_Connection *restrict c, stream_id); if (NULL == s) { - if ((0u == (stream_id & 1u)) || - (c->h2.state.top_rst_stream_id < stream_id)) + if ((0u == (stream_id & 1u)) + || (c->h2.state.top_rst_stream_id < stream_id)) return mhd_h2_conn_finish (c, mhd_H2_ERR_PROTOCOL_ERROR, false); @@ -533,10 +533,10 @@ mhd_h2_conn_streamid_window_incr (struct MHD_Connection *restrict c, return true; /* Just ignore the frame */ } if ((0 < s->state.send_window) - && (0 > s->state.send_window + (int_least32_t) stream_id)) + && (0 > s->state.send_window + (int_least32_t)stream_id)) return mhd_h2_stream_req_problem (s, mhd_H2_REQ_PRBLM_FLOW_CONTROL); - s->state.send_window += (int_least32_t) stream_id; + s->state.send_window += (int_least32_t)stream_id; return true; } @@ -560,19 +560,19 @@ stream_maintain_rcv_window (struct mhd_H2Stream *restrict s) * window size, then bump to the full size. */ if ((c->h2.rcv_cfg.stream_init_win_sz - c->h2.rcv_cfg.stream_init_win_sz / 4) - <= (uint_least32_t) s->state.recv_window) + <= (uint_least32_t)s->state.recv_window) { uint_least32_t incr = (uint_least32_t) (c->h2.rcv_cfg.stream_init_win_sz - - (uint_least32_t) s->state.recv_window); + - (uint_least32_t)s->state.recv_window); mhd_assert (0x7FFFFFFFu >= incr); - if (! mhd_h2_q_window_update (c, - s->stream_id, - incr)) + if (!mhd_h2_q_window_update (c, + s->stream_id, + incr)) return false; - s->state.recv_window = (int_least32_t) c->h2.rcv_cfg.stream_init_win_sz; + s->state.recv_window = (int_least32_t)c->h2.rcv_cfg.stream_init_win_sz; } return true; @@ -599,8 +599,8 @@ mhd_h2_conn_maintain_streams_all (struct MHD_Connection *c) { struct mhd_H2Stream *next; struct mhd_H2Stream *s; - mhd_assert ((! c->h2.state.sent_goaway.occurred) || - (mhd_H2_ERR_NO_ERROR == c->h2.state.sent_goaway.code)); + mhd_assert ((!c->h2.state.sent_goaway.occurred) + || (mhd_H2_ERR_NO_ERROR == c->h2.state.sent_goaway.code)); next = mhd_DLINKEDL_GET_FIRST_D (&(c->h2.streams.active)); while (NULL != (s = next)) @@ -608,18 +608,18 @@ mhd_h2_conn_maintain_streams_all (struct MHD_Connection *c) next = mhd_DLINKEDL_GET_NEXT (s, streams); /* Send RST_STREAM is needed */ - if ((! s->state.rcvd_rst_stream) - && (! s->state.sent_rst_stream)) + if ((!s->state.rcvd_rst_stream) + && (!s->state.sent_rst_stream)) { - if ((mhd_H2_REQ_STAGE_BROKEN == s->req.stage) || - (mhd_H2_RPL_STAGE_BROKEN == s->rpl.stage)) + if ((mhd_H2_REQ_STAGE_BROKEN == s->req.stage) + || (mhd_H2_RPL_STAGE_BROKEN == s->rpl.stage)) { enum mhd_H2ErrorCode err; err = s->state.mhd_err; if (mhd_H2_ERR_NO_ERROR == err) err = mhd_H2_ERR_INTERNAL_ERROR; - if (! stream_send_rst_stream (s, - err)) + if (!stream_send_rst_stream (s, + err)) return false; } } @@ -634,7 +634,7 @@ mhd_h2_conn_maintain_streams_all (struct MHD_Connection *c) if (mhd_H2_REQ_STAGE_END_STREAM > s->req.stage) { - if (! stream_maintain_rcv_window (s)) + if (!stream_maintain_rcv_window (s)) return false; } } @@ -649,11 +649,11 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool mhd_h2_conn_process_streams_sending_queue (struct MHD_Connection *c) { struct mhd_H2Stream *already_processed; - mhd_assert ((! c->h2.state.sent_goaway.occurred) || - (mhd_H2_ERR_NO_ERROR == c->h2.state.sent_goaway.code)); + mhd_assert ((!c->h2.state.sent_goaway.occurred) + || (mhd_H2_ERR_NO_ERROR == c->h2.state.sent_goaway.code)); already_processed = NULL; - while (! 0) + while (!0) { struct mhd_H2Stream *const s = mhd_DLINKEDL_GET_FIRST_D (&(c->h2.streams.send_q)); @@ -664,7 +664,7 @@ mhd_h2_conn_process_streams_sending_queue (struct MHD_Connection *c) if (already_processed == s) break; - mhd_assert (! stream_is_closed (s)); + mhd_assert (!stream_is_closed (s)); mhd_h2_stream_reply_send (s); if (mhd_H2_ERR_NO_ERROR != c->h2.state.sent_goaway.code) @@ -690,9 +690,9 @@ mhd_h2_conn_process_streams_sending_queue (struct MHD_Connection *c) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void -mhd_h2_conn_close_streams_all (struct MHD_Connection *restrict c) +mhd_h2_conn_close_streams_all (struct MHD_Connection *restrict c) { - while (! 0) + while (!0) { struct mhd_H2Stream *const s = mhd_DLINKEDL_GET_FIRST_D (&(c->h2.streams.send_q)); @@ -700,7 +700,7 @@ mhd_h2_conn_close_streams_all (struct MHD_Connection *restrict c) if (NULL == s) break; - mhd_assert (! stream_is_closed (s)); + mhd_assert (!stream_is_closed (s)); mhd_DLINKEDL_DEL_D (&(c->h2.streams.send_q), s, send_q); conn_remove_stream (c, diff --git a/src/mhd2/h2/h2_conn_streams.h b/src/mhd2/h2/h2_conn_streams.h @@ -159,7 +159,7 @@ MHD_FN_PAR_NONNULL_ALL_; * if connection is broken */ MHD_INTERNAL bool -mhd_h2_conn_maintain_streams_all (struct MHD_Connection *restrict c) +mhd_h2_conn_maintain_streams_all (struct MHD_Connection *restrict c) MHD_FN_PAR_NONNULL_ALL_; /** @@ -178,7 +178,7 @@ MHD_FN_PAR_NONNULL_ALL_; * @param c the connection to use */ MHD_INTERNAL void -mhd_h2_conn_close_streams_all (struct MHD_Connection *restrict c) +mhd_h2_conn_close_streams_all (struct MHD_Connection *restrict c) MHD_FN_PAR_NONNULL_ALL_; #endif /* ! MHD_H2_CONN_STREAMS_H */ diff --git a/src/mhd2/h2/h2_frame_codec.c b/src/mhd2/h2/h2_frame_codec.c @@ -106,7 +106,7 @@ * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (4) MHD_FN_PAR_OUT_ (5) enum mhd_H2FrameDecodeResult frame_decode_data (size_t payload_buff_size, @@ -135,7 +135,7 @@ frame_decode_data (size_t payload_buff_size, if (real_payload_pos >= payload_buff_size) return mhd_H2_F_DEC_F_HEADER_INCOMPLETE; - data->pad_length = (uint_least8_t) payload_buff[real_payload_pos++]; + data->pad_length = (uint_least8_t)payload_buff[real_payload_pos++]; } else data->pad_length = 0u; @@ -145,9 +145,9 @@ frame_decode_data (size_t payload_buff_size, if (payload_buff_size < data->length) return mhd_H2_F_DEC_F_PAYLOAD_INCOMPLETE; - frame_payload->data = (char *) payload_buff + real_payload_pos; + frame_payload->data = (char *)payload_buff + real_payload_pos; frame_payload->size = - (size_t) (data->length - real_payload_pos - data->pad_length); + (size_t)(data->length - real_payload_pos - data->pad_length); return mhd_H2_F_DEC_OK; } @@ -170,7 +170,7 @@ frame_decode_data (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (4) MHD_FN_PAR_OUT_ (5) enum mhd_H2FrameDecodeResult frame_decode_headers (size_t payload_buff_size, @@ -200,7 +200,7 @@ frame_decode_headers (size_t payload_buff_size, return mhd_H2_F_DEC_CONN_ERR_PROT; if (real_payload_pos >= payload_buff_size) return mhd_H2_F_DEC_F_HEADER_INCOMPLETE; - headers->pad_length = (uint_least8_t) payload_buff[real_payload_pos++]; + headers->pad_length = (uint_least8_t)payload_buff[real_payload_pos++]; } else headers->pad_length = 0u; @@ -235,9 +235,9 @@ frame_decode_headers (size_t payload_buff_size, if (payload_buff_size < headers->length) return mhd_H2_F_DEC_F_PAYLOAD_INCOMPLETE; - frame_payload->data = (char *) payload_buff + real_payload_pos; + frame_payload->data = (char *)payload_buff + real_payload_pos; frame_payload->size = - (size_t) (headers->length - real_payload_pos - headers->pad_length); + (size_t)(headers->length - real_payload_pos - headers->pad_length); return mhd_H2_F_DEC_OK; } @@ -256,7 +256,7 @@ frame_decode_headers (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (3) enum mhd_H2FrameDecodeResult frame_decode_priority (size_t payload_buff_size, @@ -304,7 +304,7 @@ frame_decode_priority (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (3) enum mhd_H2FrameDecodeResult frame_decode_rst_stream (size_t payload_buff_size, @@ -325,7 +325,7 @@ frame_decode_rst_stream (size_t payload_buff_size, return mhd_H2_F_DEC_F_HEADER_INCOMPLETE; load_buff32b = mhd_GET_32BIT_BE_UNALIGN (payload_buff + 0u); - rst_stream->error_code = (enum mhd_H2ErrorCode) load_buff32b; + rst_stream->error_code = (enum mhd_H2ErrorCode)load_buff32b; return mhd_H2_F_DEC_OK; } @@ -347,7 +347,7 @@ frame_decode_rst_stream (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (4) MHD_FN_PAR_OUT_ (5) enum mhd_H2FrameDecodeResult frame_decode_settings (size_t payload_buff_size, @@ -375,7 +375,7 @@ frame_decode_settings (size_t payload_buff_size, if (payload_buff_size < settings->length) return mhd_H2_F_DEC_F_PAYLOAD_INCOMPLETE; - frame_payload->data = (char *) payload_buff; + frame_payload->data = (char *)payload_buff; frame_payload->size = settings->length; return mhd_H2_F_DEC_OK; @@ -398,7 +398,7 @@ frame_decode_settings (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (4) MHD_FN_PAR_OUT_ (5) enum mhd_H2FrameDecodeResult frame_decode_push_promise (size_t payload_buff_size, @@ -424,7 +424,7 @@ frame_decode_push_promise (size_t payload_buff_size, if (real_payload_pos >= payload_buff_size) return mhd_H2_F_DEC_F_HEADER_INCOMPLETE; push_promise->pad_length = - (uint_least8_t) payload_buff[real_payload_pos++]; + (uint_least8_t)payload_buff[real_payload_pos++]; } else push_promise->pad_length = 0u; @@ -449,7 +449,7 @@ frame_decode_push_promise (size_t payload_buff_size, if (payload_buff_size < push_promise->length) return mhd_H2_F_DEC_F_PAYLOAD_INCOMPLETE; - frame_payload->data = (char *) payload_buff + real_payload_pos; + frame_payload->data = (char *)payload_buff + real_payload_pos; frame_payload->size = (size_t) (push_promise->length - real_payload_pos - push_promise->pad_length); @@ -472,7 +472,7 @@ frame_decode_push_promise (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (4) enum mhd_H2FrameDecodeResult frame_decode_ping (size_t payload_buff_size, @@ -516,7 +516,7 @@ frame_decode_ping (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (3) MHD_FN_PAR_OUT_ (4) enum mhd_H2FrameDecodeResult frame_decode_goaway (size_t payload_buff_size, @@ -545,11 +545,11 @@ frame_decode_goaway (size_t payload_buff_size, & mhd_MASK_31BITS); real_payload_pos += 4u; load_buff32b = mhd_GET_32BIT_BE_UNALIGN (payload_buff + real_payload_pos); - goaway->error_code = (enum mhd_H2ErrorCode) load_buff32b; + goaway->error_code = (enum mhd_H2ErrorCode)load_buff32b; real_payload_pos += 4u; - frame_payload->data = (char *) payload_buff + real_payload_pos; - frame_payload->size = (size_t) (goaway->length - real_payload_pos); + frame_payload->data = (char *)payload_buff + real_payload_pos; + frame_payload->size = (size_t)(goaway->length - real_payload_pos); return mhd_H2_F_DEC_OK; } @@ -568,7 +568,7 @@ frame_decode_goaway (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (3) enum mhd_H2FrameDecodeResult frame_decode_window_update (size_t payload_buff_size, @@ -610,7 +610,7 @@ frame_decode_window_update (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (4) MHD_FN_PAR_OUT_ (5) enum mhd_H2FrameDecodeResult frame_decode_continuation (size_t payload_buff_size, @@ -632,7 +632,7 @@ frame_decode_continuation (size_t payload_buff_size, if (payload_buff_size < continuation->length) return mhd_H2_F_DEC_F_PAYLOAD_INCOMPLETE; - frame_payload->data = (char *) payload_buff; + frame_payload->data = (char *)payload_buff; frame_payload->size = continuation->length; return mhd_H2_F_DEC_OK; @@ -653,7 +653,7 @@ frame_decode_continuation (size_t payload_buff_size, * or a relevant decode error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_INOUT_ (3) MHD_FN_PAR_OUT_ (4) enum mhd_H2FrameDecodeResult frame_decode_unknown_type (size_t payload_buff_size, @@ -664,7 +664,7 @@ frame_decode_unknown_type (size_t payload_buff_size, if (payload_buff_size < frame_info->selector.length) return mhd_H2_F_DEC_F_PAYLOAD_INCOMPLETE; - frame_payload->data = (char *) payload_buff; + frame_payload->data = (char *)payload_buff; frame_payload->size = frame_info->selector.length; return mhd_H2_F_DEC_OK; @@ -672,7 +672,7 @@ frame_decode_unknown_type (size_t payload_buff_size, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_OUT_ (5) enum mhd_H2FrameDecodeResult mhd_h2_frame_decode (size_t buff_size, uint8_t *restrict buff, @@ -691,21 +691,21 @@ mhd_h2_frame_decode (size_t buff_size, len_and_type = mhd_GET_32BIT_BE_UNALIGN (buff + 0u); - length = (uint_least32_t) (len_and_type >> 8u); - type = (uint_least8_t) (len_and_type & 0xFFu); + length = (uint_least32_t)(len_and_type >> 8u); + type = (uint_least8_t)(len_and_type & 0xFFu); flags = buff[4]; stream_id = (mhd_GET_32BIT_BE_UNALIGN (buff + 5u) & mhd_H2_STREAM_ID_MASK); frame_info->selector.length = length; - frame_info->selector.type = (enum mhd_H2FrameIDs) type; + frame_info->selector.type = (enum mhd_H2FrameIDs)type; frame_info->selector.stream_id = stream_id; if (max_frame_size < length) return mhd_H2_F_DEC_CONN_ERR_F_SIZE; - switch ((enum mhd_H2FrameIDs) type) + switch ((enum mhd_H2FrameIDs)type) { case mhd_H2_FRAME_IDS_DATA_ID: return frame_decode_data (buff_size - mhd_H2_FR_SIZE_MIN, @@ -837,16 +837,16 @@ mhd_h2_frame_get_padding_size ( switch (frame_info->selector.type) { case mhd_H2_FRAME_IDS_DATA_ID: - mhd_assert ((0u == frame_info->data.pad_length) || \ - frame_info->data.padded); + mhd_assert ((0u == frame_info->data.pad_length) \ + || frame_info->data.padded); return frame_info->data.pad_length; case mhd_H2_FRAME_IDS_HEADERS_ID: - mhd_assert ((0u == frame_info->headers.pad_length) || \ - frame_info->headers.padded); + mhd_assert ((0u == frame_info->headers.pad_length) \ + || frame_info->headers.padded); return frame_info->headers.pad_length; case mhd_H2_FRAME_IDS_PUSH_PROMISE_ID: - mhd_assert ((0u == frame_info->push_promise.pad_length) || \ - frame_info->push_promise.padded); + mhd_assert ((0u == frame_info->push_promise.pad_length) \ + || frame_info->push_promise.padded); return frame_info->push_promise.pad_length; case mhd_H2_FRAME_IDS_PRIORITY_ID: case mhd_H2_FRAME_IDS_RST_STREAM_ID: @@ -872,7 +872,7 @@ mhd_h2_frame_set_payload_size (union mhd_H2FrameUnion *restrict frame_info, mhd_assert (frame_info->selector.length == \ (frame_info->selector.length & mhd_H2_FR_LENGTH_MASK)); mhd_assert (frame_info->selector.type == \ - (((uint_least64_t) frame_info->selector.type) & 0xFFu)); + (((uint_least64_t)frame_info->selector.type) & 0xFFu)); #ifndef NDEBUG switch (frame_info->selector.type) { @@ -904,7 +904,7 @@ mhd_h2_frame_set_payload_size (union mhd_H2FrameUnion *restrict frame_info, frame_info->selector.length = fr_length; - return (size_t) (mhd_H2_FR_HDR_BASE_SIZE + (size_t) fr_length); + return (size_t)(mhd_H2_FR_HDR_BASE_SIZE + (size_t)fr_length); } @@ -923,7 +923,7 @@ mhd_h2_frame_set_payload_size (union mhd_H2FrameUnion *restrict frame_info, */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4,3) size_t +MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4, 3) size_t frame_hdr_encode_data (const union mhd_H2FrameUnion *restrict frame_info, uint8_t *restrict flags, const size_t out_extra_hdr_size, @@ -936,18 +936,18 @@ frame_hdr_encode_data (const union mhd_H2FrameUnion *restrict frame_info, mhd_assert (mhd_H2_FRAME_DATA_ID == data->type); mhd_assert (0u != data->stream_id); - mhd_assert ((0u == data->pad_length) || - (data->padded)); + mhd_assert ((0u == data->pad_length) + || (data->padded)); - *flags = (uint8_t) (data->padded ? mhd_FFLAG_PADDED : 0u); - *flags |= (uint8_t) (data->end_stream ? mhd_FFLAG_END_STREAM : 0u); + *flags = (uint8_t)(data->padded ? mhd_FFLAG_PADDED : 0u); + *flags |= (uint8_t)(data->end_stream ? mhd_FFLAG_END_STREAM : 0u); extra_hdr_pos = 0u; if (data->padded) { if (out_extra_hdr_size <= extra_hdr_pos) return 0u; - out_extra_hdr[extra_hdr_pos++] = (uint8_t) data->pad_length; + out_extra_hdr[extra_hdr_pos++] = (uint8_t)data->pad_length; } mhd_assert (data->length >= (extra_hdr_pos + data->pad_length)); @@ -969,7 +969,7 @@ frame_hdr_encode_data (const union mhd_H2FrameUnion *restrict frame_info, */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4,3) size_t +MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4, 3) size_t frame_hdr_encode_headers (const union mhd_H2FrameUnion *restrict frame_info, uint8_t *restrict flags, const size_t out_extra_hdr_size, @@ -982,20 +982,20 @@ frame_hdr_encode_headers (const union mhd_H2FrameUnion *restrict frame_info, mhd_assert (mhd_H2_FRAME_HEADERS_ID == headers->type); mhd_assert (0u != headers->stream_id); - mhd_assert ((0u == headers->pad_length) || - (headers->padded)); + mhd_assert ((0u == headers->pad_length) + || (headers->padded)); - *flags = (uint8_t) (headers->priority ? mhd_FFLAG_PRIORITY : 0u); - *flags |= (uint8_t) (headers->padded ? mhd_FFLAG_PADDED : 0u); - *flags |= (uint8_t) (headers->end_headers ? mhd_FFLAG_END_HEADERS : 0u); - *flags |= (uint8_t) (headers->end_stream ? mhd_FFLAG_END_STREAM : 0u); + *flags = (uint8_t)(headers->priority ? mhd_FFLAG_PRIORITY : 0u); + *flags |= (uint8_t)(headers->padded ? mhd_FFLAG_PADDED : 0u); + *flags |= (uint8_t)(headers->end_headers ? mhd_FFLAG_END_HEADERS : 0u); + *flags |= (uint8_t)(headers->end_stream ? mhd_FFLAG_END_STREAM : 0u); extra_hdr_pos = 0u; if (headers->padded) { if (out_extra_hdr_size <= extra_hdr_pos) return 0u; - out_extra_hdr[extra_hdr_pos++] = (uint8_t) headers->pad_length; + out_extra_hdr[extra_hdr_pos++] = (uint8_t)headers->pad_length; } if (headers->priority) @@ -1013,7 +1013,7 @@ frame_hdr_encode_headers (const union mhd_H2FrameUnion *restrict frame_info, extra_hdr_pos += 4u; /* Use "on-wire" 'weight' format. */ - out_extra_hdr[extra_hdr_pos++] = (uint8_t) headers->weight; + out_extra_hdr[extra_hdr_pos++] = (uint8_t)headers->weight; } mhd_assert (headers->length >= (extra_hdr_pos + headers->pad_length)); @@ -1034,7 +1034,7 @@ frame_hdr_encode_headers (const union mhd_H2FrameUnion *restrict frame_info, */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_SIZE_ (3,2) size_t +MHD_FN_PAR_OUT_SIZE_ (3, 2) size_t frame_hdr_encode_priority (const union mhd_H2FrameUnion *restrict frame_info, const size_t out_extra_hdr_size, uint8_t *restrict out_extra_hdr) @@ -1063,7 +1063,7 @@ frame_hdr_encode_priority (const union mhd_H2FrameUnion *restrict frame_info, extra_hdr_pos += 4u; /* Use "on-wire" 'weight' format. */ - out_extra_hdr[extra_hdr_pos++] = (uint8_t) priority->weight; + out_extra_hdr[extra_hdr_pos++] = (uint8_t)priority->weight; mhd_assert (priority->length == extra_hdr_pos); mhd_assert (mhd_H2_FR_FIXED_LEN_PRIORITY == extra_hdr_pos); @@ -1084,7 +1084,7 @@ frame_hdr_encode_priority (const union mhd_H2FrameUnion *restrict frame_info, */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_SIZE_ (3,2) size_t +MHD_FN_PAR_OUT_SIZE_ (3, 2) size_t frame_hdr_encode_rst_stream (const union mhd_H2FrameUnion *restrict frame_info, const size_t out_extra_hdr_size, uint8_t *restrict out_extra_hdr) @@ -1103,7 +1103,7 @@ frame_hdr_encode_rst_stream (const union mhd_H2FrameUnion *restrict frame_info, return 0u; mhd_PUT_32BIT_BE_UNALIGN (out_extra_hdr + extra_hdr_pos, - (uint32_t) rst_stream->error_code); + (uint32_t)rst_stream->error_code); extra_hdr_pos += 4u; mhd_assert (rst_stream->length == extra_hdr_pos); @@ -1136,10 +1136,10 @@ frame_hdr_encode_settings (const union mhd_H2FrameUnion *restrict frame_info, mhd_assert (mhd_H2_FRAME_SETTINGS_ID == settings->type); mhd_assert (0u == settings->stream_id); - mhd_assert ((! settings->ack) || (0u == settings->length)); + mhd_assert ((!settings->ack) || (0u == settings->length)); mhd_assert (0u == (settings->length % 6)); - *flags = (uint8_t) (settings->ack ? mhd_FFLAG_ACK : 0u); + *flags = (uint8_t)(settings->ack ? mhd_FFLAG_ACK : 0u); return mhd_H2_FR_HDR_BASE_SIZE; } @@ -1161,7 +1161,7 @@ frame_hdr_encode_settings (const union mhd_H2FrameUnion *restrict frame_info, */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4,3) size_t +MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4, 3) size_t frame_hdr_encode_push_promise ( const union mhd_H2FrameUnion *restrict frame_info, uint8_t *restrict flags, @@ -1175,29 +1175,29 @@ frame_hdr_encode_push_promise ( mhd_assert (mhd_H2_FRAME_PUSH_PROMISE_ID == push_promise->type); mhd_assert (0u != push_promise->stream_id); - mhd_assert ((0u == push_promise->pad_length) || - (push_promise->padded)); + mhd_assert ((0u == push_promise->pad_length) + || (push_promise->padded)); mhd_assert (0u != push_promise->promised_stream_id); mhd_assert (push_promise->promised_stream_id == (push_promise->promised_stream_id & mhd_H2_STREAM_ID_MASK)); - *flags = (uint8_t) (push_promise->padded ? mhd_FFLAG_PADDED : 0u); - *flags |= (uint8_t) (push_promise->end_headers ? mhd_FFLAG_END_HEADERS : 0u); + *flags = (uint8_t)(push_promise->padded ? mhd_FFLAG_PADDED : 0u); + *flags |= (uint8_t)(push_promise->end_headers ? mhd_FFLAG_END_HEADERS : 0u); extra_hdr_pos = 0u; if (push_promise->padded) { if (out_extra_hdr_size <= extra_hdr_pos) return 0u; - out_extra_hdr[extra_hdr_pos++] = (uint8_t) push_promise->pad_length; + out_extra_hdr[extra_hdr_pos++] = (uint8_t)push_promise->pad_length; } if (out_extra_hdr_size < (extra_hdr_pos + 4u)) return 0u; mhd_PUT_32BIT_BE_UNALIGN (out_extra_hdr + extra_hdr_pos, - (uint32_t) (push_promise->promised_stream_id - & mhd_H2_STREAM_ID_MASK)); + (uint32_t)(push_promise->promised_stream_id + & mhd_H2_STREAM_ID_MASK)); extra_hdr_pos += 4u; mhd_assert (push_promise->length >= @@ -1220,7 +1220,7 @@ frame_hdr_encode_push_promise ( */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4,3) size_t +MHD_FN_PAR_OUT_ (2) MHD_FN_PAR_OUT_SIZE_ (4, 3) size_t frame_hdr_encode_ping (const union mhd_H2FrameUnion *restrict frame_info, uint8_t *restrict flags, const size_t out_extra_hdr_size, @@ -1234,7 +1234,7 @@ frame_hdr_encode_ping (const union mhd_H2FrameUnion *restrict frame_info, mhd_assert (0u == ping->stream_id); - *flags = (uint8_t) (ping->ack ? mhd_FFLAG_ACK : 0u); + *flags = (uint8_t)(ping->ack ? mhd_FFLAG_ACK : 0u); extra_hdr_pos = 0u; @@ -1268,7 +1268,7 @@ frame_hdr_encode_ping (const union mhd_H2FrameUnion *restrict frame_info, */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_SIZE_ (3,2) size_t +MHD_FN_PAR_OUT_SIZE_ (3, 2) size_t frame_hdr_encode_goaway (const union mhd_H2FrameUnion *restrict frame_info, const size_t out_extra_hdr_size, uint8_t *restrict out_extra_hdr) @@ -1287,12 +1287,12 @@ frame_hdr_encode_goaway (const union mhd_H2FrameUnion *restrict frame_info, return 0u; mhd_PUT_32BIT_BE_UNALIGN (out_extra_hdr + extra_hdr_pos, - (uint32_t) (goaway->last_stream_id - & mhd_H2_STREAM_ID_MASK)); + (uint32_t)(goaway->last_stream_id + & mhd_H2_STREAM_ID_MASK)); extra_hdr_pos += 4u; mhd_PUT_32BIT_BE_UNALIGN (out_extra_hdr + extra_hdr_pos, - (uint32_t) goaway->error_code); + (uint32_t)goaway->error_code); extra_hdr_pos += 4u; mhd_assert (goaway->length >= extra_hdr_pos); @@ -1313,7 +1313,7 @@ frame_hdr_encode_goaway (const union mhd_H2FrameUnion *restrict frame_info, */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_SIZE_ (3,2) size_t +MHD_FN_PAR_OUT_SIZE_ (3, 2) size_t frame_hdr_encode_window_update ( const union mhd_H2FrameUnion *restrict frame_info, const size_t out_extra_hdr_size, @@ -1334,8 +1334,8 @@ frame_hdr_encode_window_update ( return 0u; mhd_PUT_32BIT_BE_UNALIGN (out_extra_hdr + extra_hdr_pos, - (uint32_t) (window_update->window_size_increment - & mhd_MASK_31BITS)); + (uint32_t)(window_update->window_size_increment + & mhd_MASK_31BITS)); extra_hdr_pos += 4u; mhd_assert (window_update->length >= extra_hdr_pos); @@ -1369,7 +1369,7 @@ frame_hdr_encode_continuation ( mhd_assert (0u != continuation->stream_id); - *flags = (uint8_t) (continuation->end_headers ? mhd_FFLAG_END_HEADERS : 0u); + *flags = (uint8_t)(continuation->end_headers ? mhd_FFLAG_END_HEADERS : 0u); return mhd_H2_FR_HDR_BASE_SIZE; } @@ -1377,7 +1377,7 @@ frame_hdr_encode_continuation ( MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_SIZE_ (3,2) size_t +MHD_FN_PAR_OUT_SIZE_ (3, 2) size_t mhd_h2_frame_hdr_encode (const union mhd_H2FrameUnion *restrict frame_info, size_t out_buff_size, uint8_t *restrict out_buff) @@ -1387,17 +1387,17 @@ mhd_h2_frame_hdr_encode (const union mhd_H2FrameUnion *restrict frame_info, mhd_assert (frame_info->selector.length == \ (frame_info->selector.length & mhd_H2_FR_LENGTH_MASK)); mhd_assert (frame_info->selector.type == \ - (((uint_least64_t) frame_info->selector.type) & 0xFFu)); + (((uint_least64_t)frame_info->selector.type) & 0xFFu)); mhd_assert (frame_info->selector.stream_id == \ (frame_info->selector.stream_id & mhd_H2_STREAM_ID_MASK)); if (mhd_H2_FR_SIZE_MIN > out_buff_size) return 0u; - len_and_type = (uint_least8_t) (frame_info->selector.type & 0xFFu); + len_and_type = (uint_least8_t)(frame_info->selector.type & 0xFFu); len_and_type |= (uint32_t) - ((((uint_least32_t) frame_info->selector.length) << 8u) + ((((uint_least32_t)frame_info->selector.length) << 8u) & mhd_H2_FR_LENGTH_MASK); mhd_PUT_32BIT_BE_UNALIGN (out_buff + 0u, diff --git a/src/mhd2/h2/h2_frame_codec.h b/src/mhd2/h2/h2_frame_codec.h @@ -53,9 +53,9 @@ #include "h2_frame_types.h" #if defined(_MSC_FULL_VER) -#pragma warning(push) +# pragma warning(push) /* Disable C4505 "unreferenced local function has been removed" */ -#pragma warning(disable:4505) +# pragma warning(disable:4505) #endif /* _MSC_FULL_VER */ /** @@ -142,8 +142,8 @@ mhd_h2_frame_decode (size_t buff_size, uint_least32_t max_frame_size, union mhd_H2FrameUnion *restrict frame_info, struct mhd_Buffer *restrict frame_payload) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_(2,1) -MHD_FN_PAR_OUT_(4) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2, 1) +MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_OUT_ (5); /** @@ -196,7 +196,7 @@ mhd_h2_frame_get_total_size (const union mhd_H2FrameUnion *restrict frame_info) mhd_assert ((mhd_h2_frame_get_extra_hdr_size (frame_info) + mhd_h2_frame_get_padding_size (frame_info)) <= frame_info->selector.length); - return (size_t) (mhd_H2_FR_HDR_BASE_SIZE + frame_info->selector.length); + return (size_t)(mhd_H2_FR_HDR_BASE_SIZE + frame_info->selector.length); } @@ -241,11 +241,11 @@ mhd_h2_frame_hdr_encode (const union mhd_H2FrameUnion *restrict frame_info, size_t out_buff_size, uint8_t *restrict out_buff) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_SIZE_ (3,2); +MHD_FN_PAR_OUT_SIZE_ (3, 2); #if defined(_MSC_FULL_VER) /* Restore warnings */ -#pragma warning(pop) +# pragma warning(pop) #endif /* _MSC_FULL_VER */ #endif /* ! MHD_H2_FRAME_CODEC_H */ diff --git a/src/mhd2/h2/h2_frame_init.h b/src/mhd2/h2/h2_frame_init.h @@ -56,12 +56,12 @@ #include "h2_frame_length.h" #if defined(_MSC_FULL_VER) -#pragma warning(push) +# pragma warning(push) /* Disable C4505 "unreferenced local function has been removed" */ -#pragma warning(disable:4505) +# pragma warning(disable:4505) #endif /* _MSC_FULL_VER */ -mhd_static_inline struct mhd_H2FrameDataInfo* +mhd_static_inline struct mhd_H2FrameDataInfo * mhd_h2_frame_init_data (union mhd_H2FrameUnion *restrict frame_info, uint_least32_t stream_id, bool end_stream) @@ -80,7 +80,7 @@ mhd_h2_frame_init_data (union mhd_H2FrameUnion *restrict frame_info, } -mhd_static_inline struct mhd_H2FrameHeadersInfo* +mhd_static_inline struct mhd_H2FrameHeadersInfo * mhd_h2_frame_init_headers (union mhd_H2FrameUnion *restrict frame_info, uint_least32_t stream_id, bool end_headers, @@ -105,7 +105,7 @@ mhd_h2_frame_init_headers (union mhd_H2FrameUnion *restrict frame_info, } -mhd_static_inline struct mhd_H2FrameRstStreamInfo* +mhd_static_inline struct mhd_H2FrameRstStreamInfo * mhd_h2_frame_init_rst_stream (union mhd_H2FrameUnion *restrict frame_info, uint_least32_t stream_id, enum mhd_H2ErrorCode error_code) @@ -121,7 +121,7 @@ mhd_h2_frame_init_rst_stream (union mhd_H2FrameUnion *restrict frame_info, } -mhd_static_inline struct mhd_H2FrameSettingsInfo* +mhd_static_inline struct mhd_H2FrameSettingsInfo * mhd_h2_frame_init_settings (union mhd_H2FrameUnion *restrict frame_info, bool ack) { @@ -136,7 +136,7 @@ mhd_h2_frame_init_settings (union mhd_H2FrameUnion *restrict frame_info, } -mhd_static_inline struct mhd_H2FramePingInfo* +mhd_static_inline struct mhd_H2FramePingInfo * mhd_h2_frame_init_ping (union mhd_H2FrameUnion *restrict frame_info, bool ack, const uint8_t opaque_data[MHD_FN_PAR_FIX_ARR_SIZE_ (8)]) @@ -156,7 +156,7 @@ mhd_h2_frame_init_ping (union mhd_H2FrameUnion *restrict frame_info, } -mhd_static_inline struct mhd_H2FrameGoawayInfo* +mhd_static_inline struct mhd_H2FrameGoawayInfo * mhd_h2_frame_init_goaway (union mhd_H2FrameUnion *restrict frame_info, uint_least32_t last_stream_id, enum mhd_H2ErrorCode error_code) @@ -173,7 +173,7 @@ mhd_h2_frame_init_goaway (union mhd_H2FrameUnion *restrict frame_info, } -mhd_static_inline struct mhd_H2FrameWindowUpdateInfo* +mhd_static_inline struct mhd_H2FrameWindowUpdateInfo * mhd_h2_frame_init_window_update (union mhd_H2FrameUnion *restrict frame_info, uint_least32_t stream_id, uint_least32_t window_size_increment) @@ -190,7 +190,7 @@ mhd_h2_frame_init_window_update (union mhd_H2FrameUnion *restrict frame_info, } -mhd_static_inline struct mhd_H2FrameContinuationInfo* +mhd_static_inline struct mhd_H2FrameContinuationInfo * mhd_h2_frame_init_continuation (union mhd_H2FrameUnion *restrict frame_info, uint_least32_t stream_id, bool end_headers) @@ -209,7 +209,7 @@ mhd_h2_frame_init_continuation (union mhd_H2FrameUnion *restrict frame_info, #if defined(_MSC_FULL_VER) /* Restore warnings */ -#pragma warning(pop) +# pragma warning(pop) #endif /* _MSC_FULL_VER */ #endif /* ! MHD_H2_FRAME_INIT_H */ diff --git a/src/mhd2/h2/h2_proc_conn.c b/src/mhd2/h2/h2_proc_conn.c @@ -73,10 +73,10 @@ mhd_h2_conn_process_first_fr (struct MHD_Connection *restrict c) bool ret; mhd_assert (mhd_C_IS_HTTP2 (c)); - mhd_assert (! c->h2.state.init.got_setns); + mhd_assert (!c->h2.state.init.got_setns); dec_res = mhd_h2_frame_decode (c->read_buffer_offset - c->h2.buff.r_cur_frame, - (uint8_t *) c->read_buffer + (uint8_t *)c->read_buffer + c->h2.buff.r_cur_frame, mhd_H2_STNG_DEF_MAX_FRAME_SIZE, /* Settings are not yet ACKed */ &first_fr, @@ -93,8 +93,8 @@ mhd_h2_conn_process_first_fr (struct MHD_Connection *restrict c) if (mhd_H2_F_DEC_OK != dec_res) return false; /* Not yet complete */ - if ((mhd_H2_FRAME_IDS_SETTINGS_ID != first_fr.selector.type) || - (first_fr.settings.ack)) + if ((mhd_H2_FRAME_IDS_SETTINGS_ID != first_fr.selector.type) + || (first_fr.settings.ack)) { mhd_h2_conn_finish (c, mhd_H2_ERR_PROTOCOL_ERROR, @@ -131,7 +131,7 @@ mhd_h2_conn_update_stream_init_window (struct MHD_Connection *restrict c, uint_least32_t init_wind_size) { mhd_assert (0x7FFFFFFFu >= init_wind_size); - (void) c; // TODO: change window in all streams + (void)c; // TODO: change window in all streams c->h2.peer.stream_init_win_sz = init_wind_size; return true; @@ -145,18 +145,18 @@ conn_win_update (struct MHD_Connection *restrict c) /* Dumb algorithm: if receive windows is less than three quarters of the full * window size, then bump to the full size. */ if ((c->h2.rcv_cfg.conn_full_win_sz - c->h2.rcv_cfg.conn_full_win_sz / 4) >= - (uint_least32_t) c->h2.state.recv_window) + (uint_least32_t)c->h2.state.recv_window) { const uint_least32_t incr = (uint_least32_t) (c->h2.rcv_cfg.conn_full_win_sz - - (uint_least32_t) c->h2.state.recv_window); + - (uint_least32_t)c->h2.state.recv_window); mhd_assert (0x7FFFFFFFu >= incr); - if (! mhd_h2_q_window_update (c, - 0u, - incr)) + if (!mhd_h2_q_window_update (c, + 0u, + incr)) return false; - c->h2.state.recv_window = (int_least32_t) c->h2.rcv_cfg.conn_full_win_sz; + c->h2.state.recv_window = (int_least32_t)c->h2.rcv_cfg.conn_full_win_sz; } return true; } @@ -165,10 +165,10 @@ conn_win_update (struct MHD_Connection *restrict c) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool mhd_h2_conn_process_changes (struct MHD_Connection *restrict c) { - if (! conn_win_update (c)) + if (!conn_win_update (c)) return false; - if (! mhd_h2_conn_maintain_streams_all (c)) + if (!mhd_h2_conn_maintain_streams_all (c)) return false; return true; @@ -180,21 +180,21 @@ mhd_h2_conn_finish (struct MHD_Connection *restrict c, enum mhd_H2ErrorCode err, bool forced) { - if (! mhd_h2_q_goaway (c, - err)) + if (!mhd_h2_q_goaway (c, + err)) { - if (! forced) + if (!forced) return false; c->h2.state.sent_goaway.occurred = true; - c->h2.state.sent_goaway.code = (uint_least32_t) err; + c->h2.state.sent_goaway.code = (uint_least32_t)err; c->h_layer.state = mhd_HTTP_LAYER_BROKEN; return true; } c->h2.state.sent_goaway.occurred = true; - c->h2.state.sent_goaway.code = (uint_least32_t) err; + c->h2.state.sent_goaway.code = (uint_least32_t)err; c->h_layer.state = mhd_HTTP_LAYER_CLOSING; return true; diff --git a/src/mhd2/h2/h2_proc_in.c b/src/mhd2/h2/h2_proc_in.c @@ -93,9 +93,9 @@ process_inc_frame (struct MHD_Connection *restrict c, if ((mhd_H2_FRAME_IDS_CONTINUATION_ID != h2frame->selector.type) || (c->h2.state.continuation_stream_id != h2frame->continuation.stream_id)) - return ! mhd_h2_conn_finish (c, - mhd_H2_ERR_PROTOCOL_ERROR, - false); + return !mhd_h2_conn_finish (c, + mhd_H2_ERR_PROTOCOL_ERROR, + false); } else mhd_assert (0u == c->h2.buff.unproc_hdrs_size); @@ -122,9 +122,9 @@ process_inc_frame (struct MHD_Connection *restrict c, return (mhd_H2_STNGS_PROC_OK == mhd_h2_proc_new_settings (c, payload)); case mhd_H2_FRAME_IDS_PUSH_PROMISE_ID: - return ! mhd_h2_conn_finish (c, - mhd_H2_ERR_PROTOCOL_ERROR, - false); + return !mhd_h2_conn_finish (c, + mhd_H2_ERR_PROTOCOL_ERROR, + false); case mhd_H2_FRAME_IDS_PING_ID: return mhd_h2_q_ping (c, true, @@ -143,12 +143,12 @@ process_inc_frame (struct MHD_Connection *restrict c, h2frame->window_update.window_size_increment); } if ((h2frame->window_update.window_size_increment - + (uint_least32_t) c->h2.state.send_window) > 0x7FFFFFFFu) - return ! mhd_h2_conn_finish (c, - mhd_H2_ERR_FLOW_CONTROL_ERROR, - false); + + (uint_least32_t)c->h2.state.send_window) > 0x7FFFFFFFu) + return !mhd_h2_conn_finish (c, + mhd_H2_ERR_FLOW_CONTROL_ERROR, + false); c->h2.state.send_window += - (int_least32_t) h2frame->window_update.window_size_increment; + (int_least32_t)h2frame->window_update.window_size_increment; return true; case mhd_H2_FRAME_IDS_CONTINUATION_ID: return @@ -183,7 +183,7 @@ mhd_h2_conn_process_in_data (struct MHD_Connection *restrict c) struct mhd_Buffer payload; bool proc_next; uint8_t *const frame_buff = - (uint8_t *) c->read_buffer + c->h2.buff.r_cur_frame; + (uint8_t *)c->read_buffer + c->h2.buff.r_cur_frame; const size_t buff_left = c->read_buffer_offset - c->h2.buff.r_cur_frame; proc_next = true; @@ -238,7 +238,7 @@ mhd_h2_conn_process_in_data (struct MHD_Connection *restrict c) break; /* ignore unknown types */ } - if (! proc_next) + if (!proc_next) break; mhd_assert (mhd_HTTP_LAYER_CONNECTED == c->h_layer.state); diff --git a/src/mhd2/h2/h2_proc_out.c b/src/mhd2/h2/h2_proc_out.c @@ -68,7 +68,7 @@ mhd_h2_out_buff_has_space_sz (struct MHD_Connection *restrict c, size_t have_buff_space; mhd_assert (c->write_buffer_size >= c->write_buffer_append_offset); - mhd_assert (! c->h2.dbg.w_buff_updating); + mhd_assert (!c->h2.dbg.w_buff_updating); mhd_H2_W_BUFF_UPDATING_SET (&(c->h2)); have_buff_space = c->write_buffer_size - c->write_buffer_append_offset; @@ -100,17 +100,17 @@ mhd_h2_out_buff_acquire_fr_w_payload_l ( const size_t padding_size = mhd_h2_frame_get_padding_size (h2frame); size_t w_buff_space; - mhd_assert (! c->h2.dbg.w_buff_updating); + mhd_assert (!c->h2.dbg.w_buff_updating); mhd_H2_W_BUFF_UPDATING_SET (&(c->h2)); mhd_assert (c->write_buffer_size >= c->write_buffer_append_offset); if (full_payload_limit > c->h2.peer.max_frame_size) - full_payload_limit = (uint_least32_t) c->h2.peer.max_frame_size; + full_payload_limit = (uint_least32_t)c->h2.peer.max_frame_size; w_buff_space = c->write_buffer_size - c->write_buffer_append_offset; if (((mhd_H2_FR_HDR_BASE_SIZE + extra_hdr_size + padding_size) - >= w_buff_space) || - ((extra_hdr_size + padding_size) >= full_payload_limit)) + >= w_buff_space) + || ((extra_hdr_size + padding_size) >= full_payload_limit)) { mhd_H2_W_BUFF_UPDATING_CLEAR (&(c->h2)); return false; @@ -173,7 +173,7 @@ mhd_h2_q_frame_no_payload (struct MHD_Connection *restrict c, fr_hdr_size = mhd_H2_FR_HDR_BASE_SIZE + mhd_h2_frame_get_extra_hdr_size (h2frame); - mhd_assert (! c->h2.dbg.w_buff_updating); + mhd_assert (!c->h2.dbg.w_buff_updating); mhd_H2_W_BUFF_UPDATING_SET (&(c->h2)); succeed = false; @@ -182,7 +182,7 @@ mhd_h2_q_frame_no_payload (struct MHD_Connection *restrict c, { uint8_t *w_buff; size_t written; - w_buff = (uint8_t *) c->write_buffer + c->write_buffer_append_offset; + w_buff = (uint8_t *)c->write_buffer + c->write_buffer_append_offset; written = mhd_h2_frame_hdr_encode (h2frame, w_buff_space, diff --git a/src/mhd2/h2/h2_proc_settings.c b/src/mhd2/h2/h2_proc_settings.c @@ -114,7 +114,7 @@ mhd_h2_proc_first_settings (struct MHD_Connection *restrict c, for (pos = 0u; pos < (stngs_payload->size - 5u); pos += 6u) { struct mhd_H2Setting stng; - mhd_h2_setting_decode ((uint8_t *) stngs_payload->data + pos, + mhd_h2_setting_decode ((uint8_t *)stngs_payload->data + pos, &stng); switch (stng.identifier) @@ -124,7 +124,7 @@ mhd_h2_proc_first_settings (struct MHD_Connection *restrict c, { if (4096u >= stng.value) // TODO: take the limit from the daemon mhd_hpack_enc_set_dyn_size (&(c->h2.hk_enc), - (size_t) stng.value); + (size_t)stng.value); } break; case mhd_H2_STNGS_ENABLE_PUSH: @@ -147,8 +147,8 @@ mhd_h2_proc_first_settings (struct MHD_Connection *restrict c, c->h2.peer.stream_init_win_sz = stng.value; break; case mhd_H2_STNGS_MAX_FRAME_SIZE: - if ((mhd_H2_STNG_MIN_MAX_FRAME_SIZE > stng.value) || - (mhd_H2_STNG_MAX_MAX_FRAME_SIZE < stng.value)) + if ((mhd_H2_STNG_MIN_MAX_FRAME_SIZE > stng.value) + || (mhd_H2_STNG_MAX_MAX_FRAME_SIZE < stng.value)) { mhd_h2_conn_finish (c, mhd_H2_ERR_PROTOCOL_ERROR, @@ -180,7 +180,7 @@ mhd_h2_proc_first_settings (struct MHD_Connection *restrict c, ack_succeed = h2_q_settings_ack (c); mhd_assert (ack_succeed); - (void) ack_succeed; + (void)ack_succeed; return true; /* Success exit point */ } @@ -190,7 +190,8 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ enum mhd_H2SettingsProcessResult mhd_h2_proc_new_settings (struct MHD_Connection *restrict c, const struct mhd_Buffer *restrict stngs_payload) { - (void) c; (void) stngs_payload; // TODO: implement + (void)c; + (void)stngs_payload; // TODO: implement return mhd_H2_STNGS_PROC_STNGS_ERR; } @@ -213,10 +214,10 @@ mhd_h2_q_settings_first_fr (struct MHD_Connection *restrict c) /* This is the first data sent by the server */ mhd_assert (0u == c->write_buffer_append_offset); - if (! mhd_h2_out_buff_acquire_fr_w_payload (c, - &h2frame, - &buff, - &fr_hdr_size)) + if (!mhd_h2_out_buff_acquire_fr_w_payload (c, + &h2frame, + &buff, + &fr_hdr_size)) { mhd_H2_W_BUFF_UPDATING_CLEAR (&(c->h2)); mhd_h2_conn_finish (c, @@ -225,7 +226,7 @@ mhd_h2_q_settings_first_fr (struct MHD_Connection *restrict c) return false; } - payload = (uint8_t *) buff.data + fr_hdr_size; + payload = (uint8_t *)buff.data + fr_hdr_size; payload_space = buff.size - fr_hdr_size; if (payload_space != (payload_space & 0xFFFFFFFFu)) @@ -237,7 +238,7 @@ mhd_h2_q_settings_first_fr (struct MHD_Connection *restrict c) if (payload_space >= payload_pos + mhd_H2_SETTING_SIZE) { mhd_h2_setting_encode3 (mhd_H2_STNGS_HEADER_TABLE_SIZE, - (uint_least32_t) c->h2.hk_dec.max_allowed_dyn_size, + (uint_least32_t)c->h2.hk_dec.max_allowed_dyn_size, payload + payload_pos); payload_pos += mhd_H2_SETTING_SIZE; } @@ -295,7 +296,7 @@ mhd_h2_q_settings_first_fr (struct MHD_Connection *restrict c) else set_all_settings = false; - if (! set_all_settings) + if (!set_all_settings) { mhd_H2_W_BUFF_UPDATING_CLEAR (&(c->h2)); mhd_h2_conn_finish (c, @@ -311,7 +312,7 @@ mhd_h2_q_settings_first_fr (struct MHD_Connection *restrict c) final_fr_hdr_size = mhd_h2_frame_hdr_encode (&h2frame, buff.size, - (uint8_t *) buff.data); + (uint8_t *)buff.data); mhd_assert (fr_hdr_size == final_fr_hdr_size); mhd_h2_out_buff_unlock (c, final_fr_hdr_size + payload_pos); diff --git a/src/mhd2/h2/h2_reply_funcs.c b/src/mhd2/h2/h2_reply_funcs.c @@ -83,7 +83,7 @@ struct mhd_H2Stream; /* Forward declaration */ /* local wrapper */ mhd_static_inline MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_IN_ (2) MHD_FN_PAR_IN_ (3) -MHD_FN_PAR_OUT_SIZE_ (6,5) MHD_FN_PAR_OUT_ (7) bool +MHD_FN_PAR_OUT_SIZE_ (6, 5) MHD_FN_PAR_OUT_ (7) bool enc_field (struct mhd_HpackEncContext *restrict hk_enc, const struct mhd_BufferConst *restrict name, const struct mhd_BufferConst *restrict value, @@ -115,7 +115,7 @@ stream_headers_encode (struct mhd_H2Stream *restrict s, { struct mhd_HpackEncContext *const hk_enc = &(s->c->h2.hk_enc); struct MHD_Response *const r = s->rpl.response; - uint8_t *restrict buff = (uint8_t *) pl->data; + uint8_t *restrict buff = (uint8_t *)pl->data; size_t pos; size_t pos_incr; size_t fld_num; @@ -130,7 +130,7 @@ stream_headers_encode (struct mhd_H2Stream *restrict s, if (fld_num >= s->rpl.fields.num_sent) { enc_res = mhd_hpack_enc_ph_status (hk_enc, - (uint_fast16_t) s->rpl.response->sc, + (uint_fast16_t)s->rpl.response->sc, mhd_HPACK_ENC_PFS_POL_NORMAL, pl->size - pos, buff + pos, @@ -146,8 +146,8 @@ stream_headers_encode (struct mhd_H2Stream *restrict s, /* "date" header */ - if ( (! r->cfg.has_hdr_date) && - (! s->c->daemon->req_cfg.suppress_date) ) + if ((!r->cfg.has_hdr_date) + && (!s->c->daemon->req_cfg.suppress_date)) { if (fld_num >= s->rpl.fields.num_sent) { @@ -161,14 +161,14 @@ stream_headers_encode (struct mhd_H2Stream *restrict s, hdr_val.data = val_buff; hdr_val.size = 29u; - if (! enc_field (hk_enc, - &hdr_name, - &hdr_val, - 1 >= s->c->h2.streams.num_streams ? - mhd_HPACK_ENC_POL_LOW_PRIO : mhd_HPACK_ENC_POL_NEUTRAL, - pl->size - pos, - buff + pos, - &pos_incr)) + if (!enc_field (hk_enc, + &hdr_name, + &hdr_val, + (1 >= s->c->h2.streams.num_streams) ? + mhd_HPACK_ENC_POL_LOW_PRIO : mhd_HPACK_ENC_POL_NEUTRAL, + pl->size - pos, + buff + pos, + &pos_incr)) return pos; pos += pos_incr; @@ -195,14 +195,14 @@ stream_headers_encode (struct mhd_H2Stream *restrict s, sizeof(val_buff)); mhd_assert (0u != hdr_val.size); - if (! enc_field (hk_enc, - &hdr_name, - &hdr_val, - r->reuse.reusable ? - mhd_HPACK_ENC_POL_NEUTRAL : mhd_HPACK_ENC_POL_LOW_PRIO, - pl->size - pos, - buff + pos, - &pos_incr)) + if (!enc_field (hk_enc, + &hdr_name, + &hdr_val, + r->reuse.reusable ? + mhd_HPACK_ENC_POL_NEUTRAL : mhd_HPACK_ENC_POL_LOW_PRIO, + pl->size - pos, + buff + pos, + &pos_incr)) return pos; pos += pos_incr; @@ -222,13 +222,13 @@ stream_headers_encode (struct mhd_H2Stream *restrict s, if (fld_num >= s->rpl.fields.num_sent) { - if (! enc_field (hk_enc, - &(hdr->h2.name), - &(hdr->h2.value), - mhd_HPACK_ENC_POL_NEUTRAL, - pl->size - pos, - buff + pos, - &pos_incr)) + if (!enc_field (hk_enc, + &(hdr->h2.name), + &(hdr->h2.value), + mhd_HPACK_ENC_POL_NEUTRAL, + pl->size - pos, + buff + pos, + &pos_incr)) return pos; pos += pos_incr; ++(s->rpl.fields.num_sent); @@ -260,7 +260,7 @@ stream_headers_send (struct mhd_H2Stream *s) hdrs = mhd_h2_frame_init_headers (&h2frame, s->stream_id, false, /* could be updated below */ - ! s->rpl.send_content); + !s->rpl.send_content); cont = NULL; complete_header = &(hdrs->end_headers); } @@ -273,10 +273,10 @@ stream_headers_send (struct mhd_H2Stream *s) complete_header = &(cont->end_headers); } - if (! mhd_h2_out_buff_acquire_fr_w_payload (s->c, - &h2frame, - &buff, - &payload_offset)) + if (!mhd_h2_out_buff_acquire_fr_w_payload (s->c, + &h2frame, + &buff, + &payload_offset)) return false; payload.data = buff.data + payload_offset; @@ -293,9 +293,9 @@ stream_headers_send (struct mhd_H2Stream *s) const size_t final_fr_hdr_size = mhd_h2_frame_hdr_encode (&h2frame, payload_offset, - (uint8_t*) buff.data); + (uint8_t *)buff.data); mhd_assert (payload_offset == final_fr_hdr_size); - (void) final_fr_hdr_size; + (void)final_fr_hdr_size; mhd_h2_out_buff_unlock (s->c, full_fr_size); @@ -312,8 +312,8 @@ stream_headers_send (struct mhd_H2Stream *s) 0u); if (((s->c->write_buffer_size - s->c->write_buffer_append_offset) >= - mhd_H2_FR_HDR_BASE_SIZE + s->c->h2.peer.max_frame_size) || - (0u == s->c->write_buffer_append_offset)) + mhd_H2_FR_HDR_BASE_SIZE + s->c->h2.peer.max_frame_size) + || (0u == s->c->write_buffer_append_offset)) { /* The output buffer may contain the maximum size frame, but no single header has been added. It makes no sense to wait more as the @@ -328,7 +328,7 @@ stream_headers_send (struct mhd_H2Stream *s) static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (4,3) +MHD_FN_PAR_OUT_SIZE_ (4, 3) MHD_FN_PAR_OUT_ (5) bool content_read_iovec (struct MHD_Response *restrict r, uint_fast64_t offset, @@ -358,19 +358,19 @@ content_read_iovec (struct MHD_Response *restrict r, if (1) { size_t elmnt_copy; - const size_t elmnt_off = (size_t) (offset - skipped); + const size_t elmnt_off = (size_t)(offset - skipped); if (elmnt_off != (offset - skipped)) return false; mhd_assert (0u != iov[i].iov_len); - elmnt_copy = (size_t) (iov[i].iov_len - elmnt_off); + elmnt_copy = (size_t)(iov[i].iov_len - elmnt_off); if (buff_size < elmnt_copy) elmnt_copy = buff_size; memcpy (buff, - ((const uint8_t *) iov[i].iov_base) + elmnt_off, + ((const uint8_t *)iov[i].iov_base) + elmnt_off, elmnt_copy); *written = elmnt_copy; @@ -380,7 +380,7 @@ content_read_iovec (struct MHD_Response *restrict r, ++i; } - for ((void) i; r->cntn.iovec.cnt > i; ++i) + for ((void)i; r->cntn.iovec.cnt > i; ++i) { mhd_assert (0u != iov[i].iov_len); if ((buff_size - *written) <= iov[i].iov_len) @@ -393,8 +393,8 @@ content_read_iovec (struct MHD_Response *restrict r, } memcpy (buff + *written, iov[i].iov_base, - (size_t) iov[i].iov_len); - *written += (size_t) iov[i].iov_len; + (size_t)iov[i].iov_len); + *written += (size_t)iov[i].iov_len; mhd_assert (*written > iov[i].iov_len); } return true; @@ -402,7 +402,7 @@ content_read_iovec (struct MHD_Response *restrict r, static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (4,3) +MHD_FN_PAR_OUT_SIZE_ (4, 3) MHD_FN_PAR_OUT_ (5) bool content_read_file (struct MHD_Response *restrict r, uint_fast64_t offset, @@ -414,7 +414,7 @@ content_read_file (struct MHD_Response *restrict r, mhd_assert (mhd_RESPONSE_CONTENT_DATA_FILE == r->cntn_dtype); // TODO: support pipe reading without position - mhd_assert (! r->cntn.file.is_pipe); + mhd_assert (!r->cntn.file.is_pipe); file_off = offset + r->cntn.file.offset; if (file_off < offset) @@ -424,7 +424,7 @@ content_read_file (struct MHD_Response *restrict r, mhd_read_file (r->cntn.file.fd, file_off, buff_size, - (char*) buff, + (char *)buff, written)); } @@ -449,7 +449,7 @@ stream_content_send (struct mhd_H2Stream *s) mhd_assert (mhd_H2_RPL_STAGE_HEADERS_COMPLETE == s->rpl.stage); mhd_assert (s->rpl.send_content); mhd_assert (0u != r->cntn_size); - mhd_assert (! r->cfg.head_only); + mhd_assert (!r->cfg.head_only); if (s->c->h2.state.send_window < s->state.send_window) wndw_limit = s->c->h2.state.send_window; @@ -459,12 +459,12 @@ stream_content_send (struct mhd_H2Stream *s) if (0 >= wndw_limit) return false; /* The peer should increment window(s) first */ - full_payload_limit = (uint_least32_t) wndw_limit; + full_payload_limit = (uint_least32_t)wndw_limit; if (MHD_SIZE_UNKNOWN != r->cntn_size) { cntnt_left = r->cntn_size - s->rpl.cntn_read_pos; if (cntnt_left < full_payload_limit) - full_payload_limit = (uint_least32_t) cntnt_left; + full_payload_limit = (uint_least32_t)cntnt_left; } else cntnt_left = MHD_SIZE_UNKNOWN; @@ -477,14 +477,14 @@ stream_content_send (struct mhd_H2Stream *s) s->stream_id, false); /* could be updated below */ - if (! mhd_h2_out_buff_acquire_fr_w_payload_l (s->c, - &h2frame, - full_payload_limit, - &buff, - &payload_offset)) + if (!mhd_h2_out_buff_acquire_fr_w_payload_l (s->c, + &h2frame, + full_payload_limit, + &buff, + &payload_offset)) return false; - pld_buff = (uint8_t*) buff.data + payload_offset; + pld_buff = (uint8_t *)buff.data + payload_offset; pld_buff_size = buff.size - payload_offset; mhd_assert (mhd_H2_FR_HDR_BASE_SIZE < pld_buff_size); @@ -494,27 +494,27 @@ stream_content_send (struct mhd_H2Stream *s) switch (r->cntn_dtype) { case mhd_RESPONSE_CONTENT_DATA_BUFFER: - payload_used = (size_t) full_payload_limit; + payload_used = (size_t)full_payload_limit; memcpy (pld_buff, r->cntn.buf + s->rpl.cntn_read_pos, payload_used); break; case mhd_RESPONSE_CONTENT_DATA_IOVEC: - if (! content_read_iovec (r, - s->rpl.cntn_read_pos, - pld_buff_size, - pld_buff, - &payload_used)) - payload_used = 0u; - break; - case mhd_RESPONSE_CONTENT_DATA_FILE: - if (! content_read_file (r, + if (!content_read_iovec (r, s->rpl.cntn_read_pos, pld_buff_size, pld_buff, &payload_used)) payload_used = 0u; break; + case mhd_RESPONSE_CONTENT_DATA_FILE: + if (!content_read_file (r, + s->rpl.cntn_read_pos, + pld_buff_size, + pld_buff, + &payload_used)) + payload_used = 0u; + break; case mhd_RESPONSE_CONTENT_DATA_CALLBACK: s->rpl.stage = mhd_H2_RPL_STAGE_BROKEN; break; @@ -534,17 +534,17 @@ stream_content_send (struct mhd_H2Stream *s) const size_t final_fr_hdr_size = mhd_h2_frame_hdr_encode (&h2frame, payload_offset, - (uint8_t*) buff.data); + (uint8_t *)buff.data); mhd_assert (payload_offset == final_fr_hdr_size); - (void) final_fr_hdr_size; + (void)final_fr_hdr_size; mhd_h2_out_buff_unlock (s->c, full_fr_size); s->c->h2.state.send_window -= - (int_least32_t) (full_fr_size - mhd_H2_FR_HDR_BASE_SIZE); + (int_least32_t)(full_fr_size - mhd_H2_FR_HDR_BASE_SIZE); mhd_assert (0 <= s->c->h2.state.send_window); s->state.send_window -= - (int_least32_t) (full_fr_size - mhd_H2_FR_HDR_BASE_SIZE); + (int_least32_t)(full_fr_size - mhd_H2_FR_HDR_BASE_SIZE); mhd_assert (0 <= s->state.send_window); return true; /* Success exit point */ @@ -570,7 +570,7 @@ mhd_h2_stream_reply_send (struct mhd_H2Stream *s) if (mhd_H2_RPL_STAGE_HEADERS_INCOMPLETE == s->rpl.stage) { - if (! mhd_hpack_enc_dyn_resize (&(s->c->h2.hk_enc))) + if (!mhd_hpack_enc_dyn_resize (&(s->c->h2.hk_enc))) { /* Ignore failure of the next function as the connection and stream will be retried next round if connection is not aborted. */ @@ -580,17 +580,17 @@ mhd_h2_stream_reply_send (struct mhd_H2Stream *s) return false; } - if (! stream_headers_send (s)) + if (!stream_headers_send (s)) return false; - if ((mhd_H2_RPL_STAGE_HEADERS_COMPLETE == s->rpl.stage) && - (mhd_RESPONSE_CONTENT_DATA_FILE <= s->rpl.response->cntn_dtype)) + if ((mhd_H2_RPL_STAGE_HEADERS_COMPLETE == s->rpl.stage) + && (mhd_RESPONSE_CONTENT_DATA_FILE <= s->rpl.response->cntn_dtype)) return true; /* Do not combine with content sending as the data is not ready yet */ } if (mhd_H2_RPL_STAGE_HEADERS_COMPLETE == s->rpl.stage) { - if (! stream_content_send (s)) + if (!stream_content_send (s)) return false; } diff --git a/src/mhd2/h2/h2_req_fields.c b/src/mhd2/h2/h2_req_fields.c @@ -108,20 +108,20 @@ mhd_h2_req_fields_decode (struct mhd_HpackDecContext *restrict hk_dec, mhd_assert (mhd_H2_DEC_FIELDS_OK == ret); - if (! mhd_h2_items_get_buff_new_item (ib, - &buff)) + if (!mhd_h2_items_get_buff_new_item (ib, + &buff)) return mhd_H2_DEC_FIELDS_NO_SPACE; res = mhd_hpack_dec_data (hk_dec, enc_data->size - pos, - (const uint8_t *) enc_data->data + pos, + (const uint8_t *)enc_data->data + pos, buff.size, buff.data, &name_len, &val_len, &pos_incr); - if (! mhd_HPACK_DEC_RES_IS_ERR (res)) + if (!mhd_HPACK_DEC_RES_IS_ERR (res)) { mhd_assert (0u != pos_incr); pos += pos_incr; @@ -189,7 +189,7 @@ MHD_FN_PAR_INOUT_ (1) bool req_validate_fields_chars (struct mhd_H2Stream *restrict s) { // TODO: implement checking all field chars for validity, RFC 9113 Section 8.2.1 - (void) s; + (void)s; return true; } @@ -222,10 +222,10 @@ req_pseudoheaders_preprocess (struct mhd_H2Stream *restrict s, break; else if (mhd_H2_RIK_PSEUDOHEADER != item->kind) break; - else if ((item->name_len == ph_method.len) && - (0 == memcmp (buff + item->offset, - ph_method.cstr, - ph_method.len))) + else if ((item->name_len == ph_method.len) + && (0 == memcmp (buff + item->offset, + ph_method.cstr, + ph_method.len))) { if (have_method) return mhd_h2_stream_req_problem (s, @@ -236,10 +236,10 @@ req_pseudoheaders_preprocess (struct mhd_H2Stream *restrict s, mhd_parse_http_method (item->val_len, buff + item->offset + ph_method.len + 1u); } - else if ((item->name_len == ph_path.len) && - (0 == memcmp (buff + item->offset, - ph_path.cstr, - ph_path.len))) + else if ((item->name_len == ph_path.len) + && (0 == memcmp (buff + item->offset, + ph_path.cstr, + ph_path.len))) { if (have_path) return mhd_h2_stream_req_problem (s, @@ -247,10 +247,10 @@ req_pseudoheaders_preprocess (struct mhd_H2Stream *restrict s, have_path = true; s->req.pos_path = *pos; } - else if ((item->name_len == ph_authority.len) && - (0 == memcmp (buff + item->offset, - ph_authority.cstr, - ph_authority.len))) + else if ((item->name_len == ph_authority.len) + && (0 == memcmp (buff + item->offset, + ph_authority.cstr, + ph_authority.len))) { if (have_authority) return mhd_h2_stream_req_problem (s, @@ -258,10 +258,10 @@ req_pseudoheaders_preprocess (struct mhd_H2Stream *restrict s, have_authority = true; s->req.pos_authority = *pos; } - else if ((item->name_len == ph_scheme.len) && - (0 == memcmp (buff + item->offset, - ph_scheme.cstr, - ph_scheme.len))) + else if ((item->name_len == ph_scheme.len) + && (0 == memcmp (buff + item->offset, + ph_scheme.cstr, + ph_scheme.len))) { if (have_scheme) return mhd_h2_stream_req_problem (s, @@ -272,13 +272,13 @@ req_pseudoheaders_preprocess (struct mhd_H2Stream *restrict s, ++(*pos); } - if (! have_method) + if (!have_method) return mhd_h2_stream_req_problem (s, mhd_H2_REQ_PRBLM_PSEUDOHDR_MISSING); if (mhd_HTTP_METHOD_CONNECT != s->req.method) { - if (! have_path || ! have_scheme) + if (!have_path || !have_scheme) return mhd_h2_stream_req_problem (s, mhd_H2_REQ_PRBLM_PSEUDOHDR_EXTRA); } @@ -316,32 +316,32 @@ req_headers_preprocess (struct mhd_H2Stream *restrict s, return mhd_h2_stream_req_problem (s, mhd_H2_REQ_PRBLM_PSEUDOHDR_AFTER_HDR); else if (mhd_H2_RIK_HEADER != item->kind) - (void) 0; /* skip */ - else if ((item->name_len == h_cntn_len.len) && - (0 == memcmp (buff + item->offset, - h_cntn_len.cstr, - h_cntn_len.len))) + (void)0; /* skip */ + else if ((item->name_len == h_cntn_len.len) + && (0 == memcmp (buff + item->offset, + h_cntn_len.cstr, + h_cntn_len.len))) { uint_fast64_t cntnt_len; - if ((0u == item->val_len) || - (item->val_len != - mhd_str_to_uint64 (buff + item->offset + h_cntn_len.len + 1u, - &cntnt_len))) + if ((0u == item->val_len) + || (item->val_len != + mhd_str_to_uint64 (buff + item->offset + h_cntn_len.len + 1u, + &cntnt_len))) return mhd_h2_stream_req_problem (s, mhd_H2_REQ_PRBLM_CNTNT_LEN_WRONG); - if ((MHD_SIZE_UNKNOWN != s->req.cntn_size) && - (s->req.cntn_size != cntnt_len)) + if ((MHD_SIZE_UNKNOWN != s->req.cntn_size) + && (s->req.cntn_size != cntnt_len)) return mhd_h2_stream_req_problem (s, mhd_H2_REQ_PRBLM_CNTNT_LEN_WRONG); else s->req.cntn_size = cntnt_len; } - else if ((item->name_len == h_host.len) && - (0 == memcmp (buff + item->offset, - h_host.cstr, - h_host.len))) + else if ((item->name_len == h_host.len) + && (0 == memcmp (buff + item->offset, + h_host.cstr, + h_host.len))) { if (mhd_H2_REQ_ITEM_POS_INVALID == s->req.pos_authority) s->req.pos_authority = *pos; @@ -351,12 +351,12 @@ req_headers_preprocess (struct mhd_H2Stream *restrict s, mhd_h2_items_get_item_nc (ib, s->req.pos_authority); mhd_assert (NULL != item_auth); - if ((item_auth->val_len != item->val_len) || - (! mhd_str_equal_caseless_bin_n (buff + item->offset - + item->name_len + 1u, - buff + item_auth->offset - + item_auth->name_len + 1u, - item->val_len))) + if ((item_auth->val_len != item->val_len) + || (!mhd_str_equal_caseless_bin_n (buff + item->offset + + item->name_len + 1u, + buff + item_auth->offset + + item_auth->name_len + 1u, + item->val_len))) return mhd_h2_stream_req_problem (s, mhd_H2_REQ_PRBLM_HOST_HDR_WRONG_EXTRA); @@ -364,8 +364,8 @@ req_headers_preprocess (struct mhd_H2Stream *restrict s, } ++(*pos); - mhd_assert ((mhd_H2_RIK_HEADER != item->kind) || - (':' != buff[item->offset])); + mhd_assert ((mhd_H2_RIK_HEADER != item->kind) + || (':' != buff[item->offset])); } return true; @@ -381,18 +381,18 @@ mhd_h2_req_headers_preprocess (struct mhd_H2Stream *restrict s) mhd_assert (mhd_h2_items_debug_get_streamid (s->c->h2.mem.req_ib) == s->stream_id); - if (! req_validate_fields_chars (s)) + if (!req_validate_fields_chars (s)) return false; - if (! req_pseudoheaders_preprocess (s, - &pos)) + if (!req_pseudoheaders_preprocess (s, + &pos)) return false; mhd_assert (0u != pos); mhd_assert (mhd_HTTP_METHOD_NO_METHOD != s->req.method); - if (! req_headers_preprocess (s, - &pos)) + if (!req_headers_preprocess (s, + &pos)) return false; return true; @@ -408,23 +408,23 @@ mhd_h2_req_uri_parse (struct mhd_H2Stream *restrict s) struct mhd_H2ReqItem *restrict item = mhd_h2_items_get_item_n (ib, s->req.pos_path); - const size_t path_start = (size_t) (item->offset + item->name_len + 1u); + const size_t path_start = (size_t)(item->offset + item->name_len + 1u); char *questn_mark; - questn_mark = (char*) memchr (buff + path_start, + questn_mark = (char *)memchr (buff + path_start, '?', - (size_t) item->val_len); + (size_t)item->val_len); if (NULL == questn_mark) { item->val_len = (uint_least32_t) - mhd_str_dec_norm_uri_path ((size_t) item->val_len, + mhd_str_dec_norm_uri_path ((size_t)item->val_len, buff + path_start); } else { - const size_t path_len = (size_t) (questn_mark - (buff + path_start)); - const size_t uri_end = (size_t) (path_start + item->val_len); + const size_t path_len = (size_t)(questn_mark - (buff + path_start)); + const size_t uri_end = (size_t)(path_start + item->val_len); size_t i = path_start + path_len + 1u; mhd_assert (path_len < item->val_len); @@ -494,7 +494,7 @@ mhd_h2_req_uri_parse (struct mhd_H2Stream *restrict s) buff[value_start + value_len] = 0; } - if (! mhd_h2_items_reserve_new_item (ib)) + if (!mhd_h2_items_reserve_new_item (ib)) break; // TODO: support reporting no space errors mhd_h2_items_add_new_item_reserved (ib, diff --git a/src/mhd2/h2/h2_req_fields.h b/src/mhd2/h2/h2_req_fields.h @@ -92,8 +92,8 @@ mhd_h2_req_fields_decode (struct mhd_HpackDecContext *restrict hk_dec, bool are_trailers, struct mhd_H2ReqItemsBlock *restrict ib, size_t *restrict left_unprocessed) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_(1) MHD_FN_PAR_IN_(2) -MHD_FN_PAR_INOUT_(4) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_IN_ (2) +MHD_FN_PAR_INOUT_ (4) MHD_FN_PAR_OUT_ (5); MHD_INTERNAL bool mhd_h2_req_headers_preprocess (struct mhd_H2Stream *restrict s) diff --git a/src/mhd2/h2/h2_req_get_items.c b/src/mhd2/h2/h2_req_get_items.c @@ -69,17 +69,17 @@ req_items_kind_mask (enum MHD_ValueKind kind) { unsigned int m; m = 0u; - if (0u != (MHD_VK_HEADER & (unsigned int) kind)) - m |= (unsigned int) mhd_H2_RIK_HEADER; - if (0u != (MHD_VK_COOKIE & (unsigned int) kind)) - m |= (unsigned int) mhd_H2_RIK_COOKIE; - if (0u != (MHD_VK_URI_QUERY_PARAM & (unsigned int) kind)) + if (0u != (MHD_VK_HEADER & (unsigned int)kind)) + m |= (unsigned int)mhd_H2_RIK_HEADER; + if (0u != (MHD_VK_COOKIE & (unsigned int)kind)) + m |= (unsigned int)mhd_H2_RIK_COOKIE; + if (0u != (MHD_VK_URI_QUERY_PARAM & (unsigned int)kind)) { - m |= (unsigned int) mhd_H2_RIK_URI_PARAM; - m |= (unsigned int) mhd_H2_RIK_URI_PARAM_NV; + m |= (unsigned int)mhd_H2_RIK_URI_PARAM; + m |= (unsigned int)mhd_H2_RIK_URI_PARAM_NV; } - if (0u != (MHD_VK_TRAILER & (unsigned int) kind)) - m |= (unsigned int) mhd_H2_RIK_TRAILER; + if (0u != (MHD_VK_TRAILER & (unsigned int)kind)) + m |= (unsigned int)mhd_H2_RIK_TRAILER; return m; } @@ -87,7 +87,7 @@ req_items_kind_mask (enum MHD_ValueKind kind) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (4,3) +MHD_FN_PAR_IN_SIZE_ (4, 3) MHD_FN_PAR_CSTR_ (4) MHD_FN_PAR_OUT_ (5) bool mhd_h2_request_get_value_n (struct MHD_Request *restrict r, enum MHD_ValueKind kind, @@ -96,7 +96,7 @@ mhd_h2_request_get_value_n (struct MHD_Request *restrict r, struct MHD_StringNullable *restrict value_out) { struct mhd_H2Stream *const s = - mhd_CNTNR_PTR ((struct mhd_H2RequestData *) (void*) r, + mhd_CNTNR_PTR ((struct mhd_H2RequestData *)(void *)r, struct mhd_H2Stream, req); struct MHD_Connection *const c = s->c; size_t pos; @@ -132,18 +132,18 @@ mhd_h2_request_get_value_n (struct MHD_Request *restrict r, if (key_len != itm->name_len) continue; - if (0u == (type_mask & (unsigned int) itm->kind)) + if (0u == (type_mask & (unsigned int)itm->kind)) continue; - if (! mhd_str_equal_lowercase_bin_n (key, - buff + itm->offset, - key_len)) + if (!mhd_str_equal_lowercase_bin_n (key, + buff + itm->offset, + key_len)) continue; if (mhd_H2_RIK_URI_PARAM_NV != itm->kind) { value_out->cstr = buff + itm->offset + itm->name_len + 1u; - value_out->len = (size_t) itm->val_len; + value_out->len = (size_t)itm->val_len; } else { @@ -190,7 +190,7 @@ mhd_h2_request_get_values_cb (struct MHD_Request *r, void *iterator_cls) { struct mhd_H2Stream *const s = - mhd_CNTNR_PTR ((struct mhd_H2RequestData *) (void*) r, + mhd_CNTNR_PTR ((struct mhd_H2RequestData *)(void *)r, struct mhd_H2Stream, req); struct MHD_Connection *const c = s->c; size_t pos; @@ -226,7 +226,7 @@ mhd_h2_request_get_values_cb (struct MHD_Request *r, if (NULL == itm) break; - if (((unsigned int) itm->kind) != (type_mask & (unsigned int) itm->kind)) + if (((unsigned int)itm->kind) != (type_mask & (unsigned int)itm->kind)) continue; ++count; @@ -235,11 +235,11 @@ mhd_h2_request_get_values_cb (struct MHD_Request *r, struct MHD_NameAndValue nv; nv.name.cstr = buff + itm->offset; - nv.name.len = (size_t) itm->val_len; + nv.name.len = (size_t)itm->val_len; if (mhd_H2_RIK_URI_PARAM_NV != itm->kind) { nv.value.cstr = buff + itm->offset + itm->name_len + 1u; - nv.value.len = (size_t) itm->val_len; + nv.value.len = (size_t)itm->val_len; } else { diff --git a/src/mhd2/h2/h2_req_get_items.h b/src/mhd2/h2/h2_req_get_items.h @@ -60,7 +60,7 @@ mhd_h2_request_get_value_n (struct MHD_Request *restrict r, size_t key_len, const char *restrict key, struct MHD_StringNullable *restrict value_out) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (4,3) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (4, 3) MHD_FN_PAR_CSTR_ (4) MHD_FN_PAR_OUT_ (5); MHD_INTERNAL size_t diff --git a/src/mhd2/h2/h2_req_items_funcs.c b/src/mhd2/h2/h2_req_items_funcs.c @@ -91,7 +91,7 @@ mhd_static_inline char * h2_ib_get_buff (struct mhd_H2ReqItemsBlock *ib) { mhd_assert (ib->start_free <= ib->buf_size); - return (char *) (ib + 1u); + return (char *)(ib + 1u); } @@ -99,7 +99,7 @@ mhd_static_inline const char * h2_ib_get_buffc (const struct mhd_H2ReqItemsBlock *ib) { mhd_assert (ib->start_free <= ib->buf_size); - return (const char *) (ib + 1u); + return (const char *)(ib + 1u); } @@ -107,7 +107,7 @@ mhd_static_inline struct mhd_H2ReqItem * h2_ib_get_zero_item (struct mhd_H2ReqItemsBlock *ib) { return ((struct mhd_H2ReqItem *) - (void *) (h2_ib_get_buff (ib) + ib->buf_size)) + (void *)(h2_ib_get_buff (ib) + ib->buf_size)) - 1u; } @@ -116,7 +116,7 @@ mhd_static_inline const struct mhd_H2ReqItem * h2_ib_get_zero_itemc (const struct mhd_H2ReqItemsBlock *ib) { return ((const struct mhd_H2ReqItem *) - (const void *) (h2_ib_get_buffc (ib) + ib->buf_size)) + (const void *)(h2_ib_get_buffc (ib) + ib->buf_size)) - 1u; } @@ -174,7 +174,7 @@ mhd_h2_items_block_create (size_t buffer_size) - 2u * mhd_ALIGNOF (struct mhd_H2ReqItem)) > buffer_size)) buf_alloc_size = - (uint_fast32_t) (0xFFFFFFFFu - 2 * mhd_ALIGNOF (struct mhd_H2ReqItem)); + (uint_fast32_t)(0xFFFFFFFFu - 2 * mhd_ALIGNOF (struct mhd_H2ReqItem)); /* Round up to alignment */ buf_alloc_size += @@ -191,16 +191,16 @@ mhd_h2_items_block_create (size_t buffer_size) - (sizeof(*ret) % mhd_ALIGNOF (struct mhd_H2ReqItem))) % mhd_ALIGNOF (struct mhd_H2ReqItem)); - mhd_assert ((buffer_size <= buf_alloc_size) || \ - (0xFFFFFFFFu - 2 * mhd_ALIGNOF (struct mhd_H2ReqItem) \ - <= buf_alloc_size)); + mhd_assert ((buffer_size <= buf_alloc_size) \ + || (0xFFFFFFFFu - 2 * mhd_ALIGNOF (struct mhd_H2ReqItem) \ + <= buf_alloc_size)); - ret = (struct mhd_H2ReqItemsBlock *) malloc (sizeof (*ret) + buf_alloc_size); + ret = (struct mhd_H2ReqItemsBlock *)malloc (sizeof (*ret) + buf_alloc_size); if (NULL == ret) return NULL; /* Failure exit point */ - ret->buf_size = (size_t) buf_alloc_size; + ret->buf_size = (size_t)buf_alloc_size; #ifndef NDEBUG ret->buff_locked = false; #endif /* ! NDEBUG */ @@ -222,7 +222,7 @@ MHD_FN_PAR_INOUT_ (1) void mhd_h2_items_block_reset (struct mhd_H2ReqItemsBlock *restrict ib) { mhd_assert (ib->start_free <= ib->buf_size); - mhd_assert (! ib->buff_locked); + mhd_assert (!ib->buff_locked); ib->num_items = 0u; ib->start_free = 0u; @@ -241,7 +241,7 @@ mhd_h2_items_get_buff_new_item (struct mhd_H2ReqItemsBlock *restrict ib, { const size_t free_space = h2_ib_get_buff_free_size (ib); - mhd_assert (! ib->buff_locked); + mhd_assert (!ib->buff_locked); if (mhd_rii_size + 2u > free_space) /* 2 for two zero-terminations */ return false; @@ -263,7 +263,7 @@ mhd_h2_items_reserve_new_item (struct mhd_H2ReqItemsBlock *restrict ib) { const size_t free_space = h2_ib_get_buff_free_size (ib); - mhd_assert (! ib->buff_locked); + mhd_assert (!ib->buff_locked); if (mhd_rii_size + 2u > free_space) /* 2 for two zero-terminations */ return false; @@ -293,10 +293,10 @@ mhd_h2_items_add_new_item_buff (struct mhd_H2ReqItemsBlock *restrict ib, itm->kind = kind; itm->offset = ib->start_free; - itm->name_len = (uint_least32_t) name_len; - itm->val_len = (uint_least32_t) val_len; + itm->name_len = (uint_least32_t)name_len; + itm->val_len = (uint_least32_t)val_len; - ib->start_free += (uint_least32_t) (name_len + val_len + 2u); + ib->start_free += (uint_least32_t)(name_len + val_len + 2u); ++ib->num_items; #ifndef NDEBUG @@ -321,15 +321,16 @@ mhd_h2_items_add_new_item_reserved (struct mhd_H2ReqItemsBlock *restrict ib, mhd_assert (ib->buff_locked); mhd_assert (h2_ib_get_buff_free_size (ib) >= mhd_rii_size); mhd_assert (0 == h2_ib_get_buffc (ib)[name_start + name_len]); - mhd_assert ((mhd_H2_RIK_URI_PARAM_NV == kind) || - (0 == h2_ib_get_buffc (ib)[name_start + name_len + 1 + val_len])); + mhd_assert ((mhd_H2_RIK_URI_PARAM_NV == kind) + || (0 == + h2_ib_get_buffc (ib)[name_start + name_len + 1 + val_len])); mhd_assert (name_start < ib->start_free); mhd_assert (name_len + val_len + 2u <= ib->start_free); itm->kind = kind; - itm->offset = (uint_least32_t) name_start; - itm->name_len = (uint_least32_t) name_len; - itm->val_len = (uint_least32_t) val_len; + itm->offset = (uint_least32_t)name_start; + itm->name_len = (uint_least32_t)name_len; + itm->val_len = (uint_least32_t)val_len; ++ib->num_items; @@ -443,7 +444,7 @@ mhd_h2_items_get_item_kind (struct mhd_H2ReqItemsBlock *restrict ib, return false; *kind = itm->kind; - mhd_assert (0u != (unsigned int) *kind); + mhd_assert (0u != (unsigned int)*kind); return true; @@ -473,7 +474,7 @@ mhd_h2_items_get_item_full (struct mhd_H2ReqItemsBlock *restrict ib, mhd_assert (0 == name->cstr[name->len]); mhd_assert (0 == value->cstr[value->len]); - mhd_assert (0u != (unsigned int) *kind); + mhd_assert (0u != (unsigned int)*kind); return true; } diff --git a/src/mhd2/h2/h2_req_items_funcs.h b/src/mhd2/h2/h2_req_items_funcs.h @@ -201,7 +201,7 @@ mhd_h2_items_get_item_full (struct mhd_H2ReqItemsBlock *restrict ib, struct MHD_String *restrict value, enum mhd_H2RequestItemKind *restrict kind) MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ - MHD_FN_PAR_OUT_ (3) MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_OUT_ (3) MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_OUT_ (5); #ifndef NDEBUG MHD_INTERNAL void @@ -214,7 +214,7 @@ mhd_h2_items_debug_get_streamid (struct mhd_H2ReqItemsBlock *restrict ib) MHD_FN_PAR_NONNULL_ALL_; #else /* NDEBUG */ -# define mhd_h2_items_debug_set_streamid(ib,stream_id) ((void) 0) +# define mhd_h2_items_debug_set_streamid(ib, stream_id) ((void) 0) # define mhd_h2_items_debug_get_streamid(ib) ((void) 0) #endif diff --git a/src/mhd2/h2/h2_settings.h b/src/mhd2/h2/h2_settings.h @@ -57,9 +57,9 @@ #include "mhd_bithelpers.h" #if defined(_MSC_FULL_VER) -#pragma warning(push) +# pragma warning(push) /* Disable C4505 "unreferenced local function has been removed" */ -#pragma warning(disable:4505) +# pragma warning(disable:4505) #endif /* _MSC_FULL_VER */ /** @@ -151,7 +151,7 @@ mhd_h2_setting_decode (const uint8_t encoded[MHD_FN_PAR_FIX_ARR_SIZE_ (6)], mhd_h2_setting_decode3 (encoded, &identifier, &(setting->value)); - setting->identifier = (enum mhd_H2SettingsID) identifier; + setting->identifier = (enum mhd_H2SettingsID)identifier; } @@ -189,7 +189,7 @@ MHD_FN_PAR_OUT_ (2) void mhd_h2_setting_encode (const struct mhd_H2Setting *restrict setting, uint8_t encoded[MHD_FN_PAR_FIX_ARR_SIZE_ (6)]) { - mhd_h2_setting_encode3 ((uint_least16_t) setting->identifier, + mhd_h2_setting_encode3 ((uint_least16_t)setting->identifier, setting->value, encoded); } @@ -197,7 +197,7 @@ mhd_h2_setting_encode (const struct mhd_H2Setting *restrict setting, #if defined(_MSC_FULL_VER) /* Restore warnings */ -#pragma warning(pop) +# pragma warning(pop) #endif /* _MSC_FULL_VER */ #endif /* ! MHD_H2_SETTINGS_H */ diff --git a/src/mhd2/h2/hpack/h2_huffman_codec.c b/src/mhd2/h2/hpack/h2_huffman_codec.c @@ -66,7 +66,7 @@ * Automatically enabled when unit-testing. */ #if defined(MHD_UNIT_TESTING) -# if ! defined(MHD_USE_CODE_HARDENING) +# if !defined(MHD_USE_CODE_HARDENING) # define MHD_USE_CODE_HARDENING 1 # endif #endif @@ -626,18 +626,18 @@ mhd_constexpr uint8_t mhd_h2huff_bitlen_by_sym[256] = { MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (4,3) size_t +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_SIZE_ (4, 3) size_t mhd_h2_huffman_encode (size_t str_len, const char *restrict str, size_t out_buf_size, void *restrict out_buf) { mhd_constexpr uint_fast32_t uif32_all_ones = - (uint_fast32_t) (~((uint_fast32_t) 0u)); + (uint_fast32_t)(~((uint_fast32_t)0u)); /** The width of the @a acc_out. */ mhd_constexpr uint_fast8_t acc_out_bits_width = - (uint_fast8_t) (sizeof(uint_fast32_t) * 8u); - uint8_t *const out_b = (uint8_t *) out_buf; + (uint_fast8_t)(sizeof(uint_fast32_t) * 8u); + uint8_t *const out_b = (uint8_t *)out_buf; /** 32-bit (or wider) output accumulator. Filled completely with encoded data and then the data is pushed to the output buffer. */ @@ -655,16 +655,16 @@ mhd_h2_huffman_encode (size_t str_len, #ifdef BUILDING_MHD_LIB mhd_assert (out_buf_size <= str_len); #endif /* ! BUILDING_MHD_LIB */ - mhd_assert (out_buf_size <= ((~((size_t) (0))) - sizeof(acc_out))); + mhd_assert (out_buf_size <= ((~((size_t)(0))) - sizeof(acc_out))); for (str_idx = 0u, out_idx = 0u, acc_out = 0u, acc_out_used_bits = 0u; str_idx < str_len; ++str_idx) { - const uint_fast8_t sym = (uint_fast8_t) (unsigned char) str[str_idx]; + const uint_fast8_t sym = (uint_fast8_t)(unsigned char)str[str_idx]; const uint_fast32_t sym_code = mhd_GET_H2HUFF_CODE_AS_UINTFAST32_ALG (sym); const uint_fast8_t sym_code_bits = - (uint_fast8_t) mhd_h2huff_bitlen_by_sym[sym]; + (uint_fast8_t)mhd_h2huff_bitlen_by_sym[sym]; mhd_assert (acc_out_bits_width > acc_out_used_bits); mhd_assert (0 == (acc_out & (uif32_all_ones >> acc_out_used_bits))); @@ -675,7 +675,7 @@ mhd_h2_huffman_encode (size_t str_len, acc_out |= (sym_code >> acc_out_used_bits); acc_out_used_bits += sym_code_bits; - if (mhd_COND_PRED_FALSE_P (acc_out_used_bits >= acc_out_bits_width, 0.81)) + if (mhd_COND_PRED_FALSE_P ((acc_out_used_bits >= acc_out_bits_width), 0.81)) { /* The accumulator 'acc_out' must be written to the output buffer. */ uint_fast32_t data_out; size_t next_out_idx; @@ -710,12 +710,12 @@ mhd_h2_huffman_encode (size_t str_len, mhd_assert (acc_out_bits_width > acc_out_used_bits); mhd_assert (0 == (acc_out & (uif32_all_ones >> acc_out_used_bits))); - if (mhd_COND_PRED_TRUE_P (0 != acc_out_used_bits, \ + if (mhd_COND_PRED_TRUE_P ((0 != acc_out_used_bits), \ (sizeof(uint_fast32_t) - 1.0) \ - / ((double) sizeof(uint_fast32_t)))) + / ((double)sizeof(uint_fast32_t)))) { /* The accumulator 'acc_out' must be flushed to the output buffer. */ const uint_fast8_t tail_bytes = - (uint_fast8_t) (acc_out_used_bits + 7u) >> 3u; + (uint_fast8_t)(acc_out_used_bits + 7u) >> 3u; size_t next_out_idx; uint_fast32_t data_out; @@ -758,7 +758,7 @@ static bool h2huff_decode_inited = false; * If not defined then enabled for code hardening and for debug builds. */ #ifndef MHD_USE_HUFFMAN_DECODE_TABLES_TAIL_GAP -# if defined(MHD_USE_CODE_HARDENING) || ! defined(NDEBUG) +# if defined(MHD_USE_CODE_HARDENING) || !defined(NDEBUG) # define MHD_USE_HUFFMAN_DECODE_TABLES_TAIL_GAP 1 # else # define MHD_USE_HUFFMAN_DECODE_TABLES_TAIL_GAP 0 @@ -781,7 +781,7 @@ static bool h2huff_decode_inited = false; * This corresponds to the addressable range of codes for that table, * excluding the part that belongs to the next table deeper in the chain. */ -#define HUFF_DTBL_ENTRIES(pwidth,twidth,next_pwidth) \ +#define HUFF_DTBL_ENTRIES(pwidth, twidth, next_pwidth) \ (HUFF_DTBL_SIZE_ROUNDED (twidth) \ - (1u << ((pwidth) + (twidth) - (next_pwidth))) ) @@ -790,11 +790,11 @@ static bool h2huff_decode_inited = false; * Actual allocation size for the decode table (may include extra space). */ #if MHD_USE_HUFFMAN_DECODE_TABLES_TAIL_GAP -# define HUFF_DTBL_SIZE(pwidth,twidth,next_pwidth) \ - HUFF_DTBL_ENTRIES (pwidth,twidth,next_pwidth) +# define HUFF_DTBL_SIZE(pwidth, twidth, next_pwidth) \ + HUFF_DTBL_ENTRIES (pwidth,twidth,next_pwidth) #else -# define HUFF_DTBL_SIZE(pwidth,twidth,next_pwidth) \ - HUFF_DTBL_SIZE_ROUNDED (twidth) +# define HUFF_DTBL_SIZE(pwidth, twidth, next_pwidth) \ + HUFF_DTBL_SIZE_ROUNDED (twidth) #endif @@ -835,7 +835,7 @@ uint_least16_t mhd_h2huff_SL_by_code_7p6c[HUFF_DTBL_SIZE (7, 6, 12)]; '{' (123) 111111111111 110 [15] */ mhd_ALIGNED_8 static -uint_least16_t mhd_h2huff_SL_by_code_12p3c[HUFF_DTBL_SIZE (12,3,15)]; +uint_least16_t mhd_h2huff_SL_by_code_12p3c[HUFF_DTBL_SIZE (12, 3, 15)]; /* Decode table for prefix 15 bits, table width 7 bits. Codes: @@ -849,7 +849,7 @@ uint_least16_t mhd_h2huff_SL_by_code_12p3c[HUFF_DTBL_SIZE (12,3,15)]; (173) 111111111111111 1011111 [22] */ mhd_ALIGNED_16 static -uint_least16_t mhd_h2huff_SL_by_code_15p7c[HUFF_DTBL_SIZE (15,7,17)]; +uint_least16_t mhd_h2huff_SL_by_code_15p7c[HUFF_DTBL_SIZE (15, 7, 17)]; /* Decode table for prefix 17 bits, table width 6 bits. Codes: @@ -863,7 +863,7 @@ uint_least16_t mhd_h2huff_SL_by_code_15p7c[HUFF_DTBL_SIZE (15,7,17)]; (235) 1111111111111111111 101111 [25] */ mhd_ALIGNED_16 static -uint_least16_t mhd_h2huff_SL_by_code_17p6c[HUFF_DTBL_SIZE (17,6,19)]; +uint_least16_t mhd_h2huff_SL_by_code_17p6c[HUFF_DTBL_SIZE (17, 6, 19)]; /* Decode table for prefix 19 bits, table width 6 bits. Codes: @@ -877,7 +877,7 @@ uint_least16_t mhd_h2huff_SL_by_code_17p6c[HUFF_DTBL_SIZE (17,6,19)]; (253) 111111111111111111111 101111 [27] */ mhd_ALIGNED_16 static -uint_least16_t mhd_h2huff_SL_by_code_19p6c[HUFF_DTBL_SIZE (19,6,21)]; +uint_least16_t mhd_h2huff_SL_by_code_19p6c[HUFF_DTBL_SIZE (19, 6, 21)]; /* Decode table for prefix 21 bits, table width 6 bits. Codes: @@ -891,7 +891,7 @@ uint_least16_t mhd_h2huff_SL_by_code_19p6c[HUFF_DTBL_SIZE (19,6,21)]; (253) 111111111111111111111 101111 [27] */ mhd_ALIGNED_16 static -uint_least16_t mhd_h2huff_SL_by_code_21p6c[HUFF_DTBL_SIZE (21,6,23)]; +uint_least16_t mhd_h2huff_SL_by_code_21p6c[HUFF_DTBL_SIZE (21, 6, 23)]; /* Decode table for prefix 23 bits, table width 5 bits. Codes: @@ -905,7 +905,7 @@ uint_least16_t mhd_h2huff_SL_by_code_21p6c[HUFF_DTBL_SIZE (21,6,23)]; (249) 11111111111111111111111 11110 [28] */ mhd_ALIGNED_16 static -uint_least16_t mhd_h2huff_SL_by_code_23p5c[HUFF_DTBL_SIZE (23,5,28)]; +uint_least16_t mhd_h2huff_SL_by_code_23p5c[HUFF_DTBL_SIZE (23, 5, 28)]; /* Decode table for prefix 28 bits, table width 2 bits. Codes: @@ -914,7 +914,7 @@ uint_least16_t mhd_h2huff_SL_by_code_23p5c[HUFF_DTBL_SIZE (23,5,28)]; ( 22) 1111111111111111111111111111 10 [30] */ mhd_ALIGNED_8 static -uint_least16_t mhd_h2huff_SL_by_code_28p2c[HUFF_DTBL_SIZE (28,2,30)]; +uint_least16_t mhd_h2huff_SL_by_code_28p2c[HUFF_DTBL_SIZE (28, 2, 30)]; /** @@ -942,33 +942,33 @@ init_decode_table_entries_per_sym ( const uint_fast8_t tbits, const uint_fast8_t next_pbits, uint_least16_t table_to_fill[ - MHD_FN_PAR_DYN_ARR_SIZE_ (HUFF_DTBL_SIZE (pbits,tbits,next_pbits))]) + MHD_FN_PAR_DYN_ARR_SIZE_ (HUFF_DTBL_SIZE (pbits, tbits, next_pbits))]) { mhd_constexpr uint_least32_t b32ones = 0xFFFFFFFFu; /**< 32 all-ones bits */ const uint_least16_t sym_and_blen = - (uint_least16_t) (((uint_least16_t) codebits) << 8u | sym); + (uint_least16_t)(((uint_least16_t)codebits) << 8u | sym); uint_least32_t i_tbl; uint_least32_t i_tbl_end; #ifdef NDEBUG - (void) next_pbits; /* Mute compiler warning */ + (void)next_pbits; /* Mute compiler warning */ #endif /* NDEBUG */ mhd_assert ((codebits <= 30u) && "The longest code is 30 bits"); - mhd_assert ((pbits < codebits) && \ - "The prefix must not be wider than the code"); + mhd_assert ((pbits < codebits) \ + && "The prefix must not be wider than the code"); mhd_assert ((pbits + tbits) >= codebits && "The width of the code cannot " \ "be larger than the total width of the prefix plus the " \ "width of the table"); - mhd_assert (code == (code & b32ones) && \ - "The code cannot have bits higher than 32 bits"); - mhd_assert (0u == (code & (b32ones >> codebits)) && \ - "The unused part of the code must be zero"); - mhd_assert ((0u == pbits) || \ - ((b32ones >> (32u - pbits)) == (code >> (32u - pbits)) && \ - "The prefix bits in the code must be all set")); - mhd_assert ((b32ones >> (32u - codebits)) != (code >> (32u - codebits)) && \ - "The bits in the code after the prefix cannot be all set"); + mhd_assert (code == (code & b32ones) \ + && "The code cannot have bits higher than 32 bits"); + mhd_assert (0u == (code & (b32ones >> codebits)) \ + && "The unused part of the code must be zero"); + mhd_assert ((0u == pbits) \ + || ((b32ones >> (32u - pbits)) == (code >> (32u - pbits)) \ + && "The prefix bits in the code must be all set")); + mhd_assert ((b32ones >> (32u - codebits)) != (code >> (32u - codebits)) \ + && "The bits in the code after the prefix cannot be all set"); i_tbl = ((code & (b32ones >> pbits)) >> (32u - (pbits + tbits))); mhd_assert (HUFF_DTBL_ENTRIES (pbits, tbits, next_pbits) > i_tbl); @@ -979,8 +979,8 @@ init_decode_table_entries_per_sym ( do { mhd_assert (HUFF_DTBL_ENTRIES (pbits, tbits, next_pbits) > i_tbl); - mhd_assert (0 == table_to_fill[i_tbl] && \ - "No entry must be written twice"); + mhd_assert (0 == table_to_fill[i_tbl] \ + && "No entry must be written twice"); table_to_fill[i_tbl] = sym_and_blen; } while (i_tbl++ < i_tbl_end); } @@ -1002,7 +1002,7 @@ init_decode_table ( const uint_fast8_t tbits, const uint_fast8_t next_pbits, uint_least16_t table_to_fill[ - MHD_FN_PAR_DYN_ARR_SIZE_ (HUFF_DTBL_SIZE (pbits,tbits,next_pbits))]) + MHD_FN_PAR_DYN_ARR_SIZE_ (HUFF_DTBL_SIZE (pbits, tbits, next_pbits))]) { mhd_constexpr uint_least32_t b32ones = 0xFFFFFFFFu; /**< 32 all-ones bits */ uint_fast8_t sym; @@ -1014,7 +1014,7 @@ init_decode_table ( memset (table_to_fill, 0, - HUFF_DTBL_SIZE (pbits,tbits,next_pbits) * sizeof(*table_to_fill)); /* Zero the table completely, including unused entries */ + HUFF_DTBL_SIZE (pbits, tbits, next_pbits) * sizeof(*table_to_fill)); /* Zero the table completely, including unused entries */ sym = 0; do @@ -1026,11 +1026,11 @@ init_decode_table ( && "Huffman code must be less than or equal to the largest " \ "Huffman code in the table."); mhd_assert (codebits <= 30); - mhd_assert (0 == (code & (b32ones >> codebits)) && \ - "The unused part of the code must be zero"); + mhd_assert (0 == (code & (b32ones >> codebits)) \ + && "The unused part of the code must be zero"); - if ((0 != pbits) && - (((b32ones << (32u - pbits)) & b32ones) > code)) + if ((0 != pbits) + && (((b32ones << (32u - pbits)) & b32ones) > code)) continue; if (((b32ones << (32u - next_pbits)) & b32ones) <= code) @@ -1052,16 +1052,16 @@ init_decode_table ( { /* Check the table */ uint_least32_t i; for (i = 0; - i < HUFF_DTBL_ENTRIES (pbits,tbits,next_pbits); + i < HUFF_DTBL_ENTRIES (pbits, tbits, next_pbits); ++i) - mhd_assert ((0u != table_to_fill[i]) && \ - "All valid entries must be used"); + mhd_assert ((0u != table_to_fill[i]) \ + && "All valid entries must be used"); # if MHD_USE_HUFFMAN_DECODE_TABLES_TAIL_GAP - for (i = HUFF_DTBL_ENTRIES (pbits,tbits,next_pbits); - i < HUFF_DTBL_SIZE (pbits,tbits,next_pbits); + for (i = HUFF_DTBL_ENTRIES (pbits, tbits, next_pbits); + i < HUFF_DTBL_SIZE (pbits, tbits, next_pbits); ++i) - mhd_assert ((0u == table_to_fill[i]) && \ - "All unused entries must be zero"); + mhd_assert ((0u == table_to_fill[i]) \ + && "All unused entries must be zero"); # endif /* MHD_USE_HUFFMAN_DECODE_TABLES_TAIL_GAP */ } #endif /* ! NDEBUG */ @@ -1107,7 +1107,7 @@ mhd_h2_huffman_init (void) #endif MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (4,3) size_t +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_SIZE_ (4, 3) size_t mhd_h2_huffman_decode (size_t encoded_size, const void *restrict encoded, size_t out_buf_size, @@ -1137,7 +1137,7 @@ mhd_h2_huffman_decode (size_t encoded_size, #endif /* ! mhd_HF_DEC64 */ /** The total number of valid bits in @a enc_chunk and @a enc_chunk_next */ uint_fast8_t enc_chunk_bits; - const uint8_t *const enc_b = (const uint8_t *) encoded; + const uint8_t *const enc_b = (const uint8_t *)encoded; size_t enc_idx; size_t out_idx; @@ -1147,7 +1147,7 @@ mhd_h2_huffman_decode (size_t encoded_size, mhd_assert (0 != encoded_size); mhd_assert (0 != out_buf_size); #endif /* ! MHD_UNIT_TESTING */ - mhd_assert (out_buf_size <= ((~((size_t) (0))) - sizeof(uint_least32_t))); + mhd_assert (out_buf_size <= ((~((size_t)(0))) - sizeof(uint_least32_t))); /* Pre-load data */ if (1) @@ -1162,10 +1162,10 @@ mhd_h2_huffman_decode (size_t encoded_size, #ifdef mhd_HF_DEC64 enc_chunk = enc_chunk64; #else /* ! mhd_HF_DEC64 */ - enc_chunk = ((uint_least32_t) (enc_chunk64 >> 32u)) & b32ones; - enc_chunk_next = ((uint_least32_t) enc_chunk64) & b32ones; + enc_chunk = ((uint_least32_t)(enc_chunk64 >> 32u)) & b32ones; + enc_chunk_next = ((uint_least32_t)enc_chunk64) & b32ones; #endif /* ! mhd_HF_DEC64 */ - enc_chunk_bits = (uint_fast8_t) (load_bytes << 3u); + enc_chunk_bits = (uint_fast8_t)(load_bytes << 3u); enc_idx = load_bytes; #ifdef mhd_HF_DEC64 if (enc_idx < encoded_size) @@ -1176,7 +1176,7 @@ mhd_h2_huffman_decode (size_t encoded_size, load_bytes = 8u; memcpy (&data_in, enc_b + enc_idx, load_bytes); enc_shadow = mhd_GET_64BIT_BE (&data_in); - enc_shadow_bits = (uint_fast8_t) (load_bytes << 3u); + enc_shadow_bits = (uint_fast8_t)(load_bytes << 3u); enc_idx += load_bytes; } else @@ -1193,7 +1193,7 @@ mhd_h2_huffman_decode (size_t encoded_size, /* 32 bit MSB-aligned current decoding code */ const uint_least32_t cur_code = #ifdef mhd_HF_DEC64 - (uint_least32_t) (((uint_least32_t) (enc_chunk >> 32u)) & b32ones) + (uint_least32_t)(((uint_least32_t)(enc_chunk >> 32u)) & b32ones) #else /* ! mhd_HF_DEC64 */ enc_chunk #endif /* ! mhd_HF_DEC64 */ @@ -1211,14 +1211,15 @@ mhd_h2_huffman_decode (size_t encoded_size, mhd_assert (64u >= enc_chunk_bits); #ifdef mhd_HF_DEC64 - mhd_assert ((64u == enc_chunk_bits) || \ - (0 == ((enc_chunk << enc_chunk_bits) & b64ones))); + mhd_assert ((64u == enc_chunk_bits) \ + || (0 == ((enc_chunk << enc_chunk_bits) & b64ones))); mhd_assert (enc_chunk == (enc_chunk & b64ones)); #else /* ! mhd_HF_DEC64 */ - mhd_assert ((32u <= enc_chunk_bits) || \ - (0 == ((enc_chunk << enc_chunk_bits) & b32ones))); - mhd_assert ((32u > enc_chunk_bits) || (64u == enc_chunk_bits) || \ - (0 == ((enc_chunk_next << (enc_chunk_bits - 32u)) & b32ones))); + mhd_assert ((32u <= enc_chunk_bits) \ + || (0 == ((enc_chunk << enc_chunk_bits) & b32ones))); + mhd_assert ((32u > enc_chunk_bits) || (64u == enc_chunk_bits) \ + || (0 == + ((enc_chunk_next << (enc_chunk_bits - 32u)) & b32ones))); mhd_assert (enc_chunk == (enc_chunk & b32ones)); #endif /* ! mhd_HF_DEC64 */ @@ -1232,7 +1233,7 @@ mhd_h2_huffman_decode (size_t encoded_size, tbits = 8u; dec_table = mhd_h2huff_SL_by_code_0p8c; next_pbits = 7u; - if (mhd_COND_PRED_FALSE_P (HUFF_DTBL_START (next_pbits) <= cur_code, 0.8)) + if (mhd_COND_PRED_FALSE_P ((HUFF_DTBL_START (next_pbits) <= cur_code), 0.8)) { pbits = next_pbits; tbits = 6u; @@ -1300,7 +1301,7 @@ mhd_h2_huffman_decode (size_t encoded_size, else { tbl_pos = cur_code >> (32u - tbits); - (void) pbits; + (void)pbits; } #endif /* ! MHD_FAVOR_SMALL_CODE */ @@ -1318,8 +1319,8 @@ mhd_h2_huffman_decode (size_t encoded_size, mhd_assert (0u != sym_and_blen); - sym = (uint8_t) (sym_and_blen & 0xFFu); - sym_bits = (uint_fast8_t) (sym_and_blen >> 8u); + sym = (uint8_t)(sym_and_blen & 0xFFu); + sym_bits = (uint_fast8_t)(sym_and_blen >> 8u); mhd_assert (0u != sym_bits); mhd_assert (5u <= sym_bits); @@ -1347,19 +1348,19 @@ mhd_h2_huffman_decode (size_t encoded_size, *decode_result = MHD_H2_HUFF_DEC_RES_NO_SPACE; return 0; } - out_buf[out_idx++] = (char) sym; + out_buf[out_idx++] = (char)sym; - if (mhd_COND_PRED_FALSE_P (32u > enc_chunk_bits, 0.84)) + if (mhd_COND_PRED_FALSE_P ((32u > enc_chunk_bits), 0.84)) { /* Load new chunk of encoded data */ #ifdef mhd_HF_DEC64 if (enc_shadow_bits != 0) { - const uint_fast8_t free_bits = (uint_fast8_t) (64u - enc_chunk_bits); + const uint_fast8_t free_bits = (uint_fast8_t)(64u - enc_chunk_bits); const uint_fast8_t move_bits = (enc_shadow_bits > free_bits) ? free_bits : enc_shadow_bits; - mhd_assert (0u != enc_chunk_bits && \ - "A single symbol cannot be more than 30 bits. If on " \ + mhd_assert (0u != enc_chunk_bits \ + && "A single symbol cannot be more than 30 bits. If on " \ "the previous step 'enc_chunk' has not been filled to " \ "more than 32 bits it means that 'enc_shadow' is " \ "already empty."); @@ -1369,8 +1370,8 @@ mhd_h2_huffman_decode (size_t encoded_size, enc_chunk_bits += move_bits; enc_shadow <<= move_bits; enc_shadow_bits -= move_bits; - mhd_assert ((64u == enc_chunk_bits) || \ - (0 == ((enc_chunk << enc_chunk_bits) & b64ones))); + mhd_assert ((64u == enc_chunk_bits) \ + || (0 == ((enc_chunk << enc_chunk_bits) & b64ones))); } if ((0u == enc_shadow_bits) \ && (encoded_size > enc_idx)) @@ -1385,11 +1386,11 @@ mhd_h2_huffman_decode (size_t encoded_size, memcpy (&data_in, enc_b + enc_idx, load_bytes); enc_idx += load_bytes; enc_shadow = mhd_GET_64BIT_BE (&data_in); - enc_shadow_bits = (uint_fast8_t) (load_bytes << 3u); + enc_shadow_bits = (uint_fast8_t)(load_bytes << 3u); if (mhd_COND_RARELY (32u > enc_chunk_bits)) { - const uint_fast8_t free_bits = (uint_fast8_t) (64u - enc_chunk_bits); + const uint_fast8_t free_bits = (uint_fast8_t)(64u - enc_chunk_bits); const uint_fast8_t use_bits = (enc_shadow_bits > free_bits) ? free_bits : enc_shadow_bits; @@ -1407,8 +1408,8 @@ mhd_h2_huffman_decode (size_t encoded_size, size_t load_bytes; uint_least32_t enc_data_load; - mhd_assert (0u != enc_chunk_bits && \ - "A single symbol cannot be more than 30 bits. If more " \ + mhd_assert (0u != enc_chunk_bits \ + && "A single symbol cannot be more than 30 bits. If more " \ "data to decode is present, then buffer would be filled " \ "on the previous step."); mhd_assert (0 == (enc_chunk & (b32ones >> enc_chunk_bits))); @@ -1424,7 +1425,7 @@ mhd_h2_huffman_decode (size_t encoded_size, enc_chunk |= ((enc_data_load >> enc_chunk_bits) & b32ones); enc_chunk_next = ((enc_data_load << (32u - enc_chunk_bits)) & b32ones); - enc_chunk_bits += (uint_fast8_t) (load_bytes << 3u); + enc_chunk_bits += (uint_fast8_t)(load_bytes << 3u); } #endif /* mhd_HF_DEC64 */ } @@ -1435,8 +1436,8 @@ mhd_h2_huffman_decode (size_t encoded_size, /** The last portion of the data one-padded on the right */ const uint_least8_t last_byte = - (uint_least8_t) ((enc_chunk >> (enc_chunk_width - 8u)) - | (0xFFu >> enc_chunk_bits)); + (uint_least8_t)((enc_chunk >> (enc_chunk_width - 8u)) + | (0xFFu >> enc_chunk_bits)); mhd_assert (7 >= enc_chunk_bits); if (0xFFu != last_byte) @@ -1449,8 +1450,8 @@ mhd_h2_huffman_decode (size_t encoded_size, mhd_assert (0u != sym_and_blen); - sym = (uint8_t) (sym_and_blen & 0xFFu); - sym_bits = (uint_fast8_t) (sym_and_blen >> 8u); + sym = (uint8_t)(sym_and_blen & 0xFFu); + sym_bits = (uint_fast8_t)(sym_and_blen >> 8u); mhd_assert (sym_bits <= 8u); if (mhd_COND_VERY_RARELY (enc_chunk_bits < sym_bits)) @@ -1461,9 +1462,9 @@ mhd_h2_huffman_decode (size_t encoded_size, if (sym_bits != enc_chunk_bits) { /* Check whether the tail is EOS */ - if (mhd_COND_VERY_RARELY (((uint_least8_t) (0xFFu >> sym_bits)) != + if (mhd_COND_VERY_RARELY (((uint_least8_t)(0xFFu >> sym_bits)) != (last_byte - & (uint_least8_t) (0xFFu >> sym_bits)))) + & (uint_least8_t)(0xFFu >> sym_bits)))) { *decode_result = MHD_H2_HUFF_DEC_RES_BROKEN_DATA; return 0; @@ -1475,7 +1476,7 @@ mhd_h2_huffman_decode (size_t encoded_size, *decode_result = MHD_H2_HUFF_DEC_RES_NO_SPACE; return 0; } - out_buf[out_idx++] = (char) sym; + out_buf[out_idx++] = (char)sym; } } *decode_result = MHD_H2_HUFF_DEC_RES_OK; diff --git a/src/mhd2/h2/hpack/h2_huffman_codec.h b/src/mhd2/h2/hpack/h2_huffman_codec.h @@ -76,7 +76,7 @@ mhd_h2_huffman_encode (size_t str_len, const char *restrict str, size_t out_buf_size, void *restrict out_buf) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (4,3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_SIZE_ (4, 3); /** @@ -122,7 +122,7 @@ mhd_h2_huffman_decode (size_t encoded_size, size_t out_buf_size, char *restrict out_buf, enum mhd_H2HuffDecodeRes *restrict decode_result) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (4,3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_SIZE_ (4, 3); #endif /* ! MHD_H2_HUFFMAN_CODEC_H */ diff --git a/src/mhd2/h2/hpack/h2_huffman_est.h b/src/mhd2/h2/hpack/h2_huffman_est.h @@ -59,10 +59,10 @@ mhd_static_inline uint_least32_t mhd_h2_huffman_est_min_size (uint_fast32_t str_len) { - const uint_fast64_t min_bits = ((uint_fast64_t) str_len) * 5u; + const uint_fast64_t min_bits = ((uint_fast64_t)str_len) * 5u; mhd_assert (str_len == (str_len & 0xFFFFFFFFu)); - return (uint_least32_t) ((min_bits + 7u) / 8u); + return (uint_least32_t)((min_bits + 7u) / 8u); } @@ -80,9 +80,9 @@ mhd_h2_huffman_est_avg_size (uint_fast32_t str_len) mhd_assert (str_len == (str_len & 0xFFFFFFFFu)); /* Assume 6.5 bits per symbol in average */ - est_bits = ((uint_fast64_t) str_len) * 6u; + est_bits = ((uint_fast64_t)str_len) * 6u; est_bits += str_len / 2; - return (uint_least32_t) ((est_bits + 7u) / 8u); + return (uint_least32_t)((est_bits + 7u) / 8u); } diff --git a/src/mhd2/h2/hpack/mhd_hpack_codec.c b/src/mhd2/h2/hpack/mhd_hpack_codec.c @@ -71,7 +71,7 @@ #include "mhd_hpack_enc_types.h" #include "mhd_hpack_codec.h" -#if ! defined(mhd_HPACK_TESTING_TABLES_ONLY) || ! defined(MHD_UNIT_TESTING) +#if !defined(mhd_HPACK_TESTING_TABLES_ONLY) || !defined(MHD_UNIT_TESTING) # include "h2_huffman_codec.h" # include "h2_huffman_est.h" #endif @@ -187,7 +187,7 @@ typedef uint_fast16_t dtbl_idx_ft; */ # define mhd_DTBL_VALUE_FITS(val) (0xFFFFu == ((val) | 0xFFFFu)) #else -#error Unsupported mhd_HPACK_DTBL_BITS value +# error Unsupported mhd_HPACK_DTBL_BITS value #endif @@ -277,7 +277,7 @@ dtbl_new_entry_strs_size_formal (dtbl_size_ft strings_len) mhd_assert (strings_len < formal_size); mhd_assert (mhd_DTBL_VALUE_FITS (strings_len)); mhd_assert (mhd_DTBL_VALUE_FITS (formal_size)); - return (dtbl_size_t) formal_size; + return (dtbl_size_t)formal_size; } @@ -516,7 +516,7 @@ dtbl_is_empty (const struct mhd_HpackDTblContext *dyn) MHD_FN_CONST_ mhd_static_inline char * dtbl_get_strs_buff (struct mhd_HpackDTblContext *dyn) { - return (char*) + return (char *) (dyn + 1u); } @@ -529,7 +529,7 @@ dtbl_get_strs_buff (struct mhd_HpackDTblContext *dyn) MHD_FN_CONST_ mhd_static_inline const char * dtbl_get_strs_buffc (const struct mhd_HpackDTblContext *dyn) { - return (const char*) + return (const char *) (dyn + 1u); } @@ -583,10 +583,10 @@ dtbl_get_infosc (const struct mhd_HpackDTblContext *dyn) MHD_FN_PURE_ mhd_static_inline dtbl_idx_t dtbl_get_pos_edge (const struct mhd_HpackDTblContext *dyn) { - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (dyn->buf_alloc_size >= mhd_DTBL_ENTRY_INFO_SIZE * dyn->num_entries); - return (dtbl_idx_t) (dyn->num_entries - 1u); + return (dtbl_idx_t)(dyn->num_entries - 1u); } @@ -607,14 +607,14 @@ MHD_FN_PURE_ mhd_static_inline dtbl_idx_t dtbl_get_pos_prev (const struct mhd_HpackDTblContext *dyn, dtbl_idx_ft loc_pos) { - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (loc_pos <= dtbl_get_pos_edge (dyn)); #ifdef MHD_USE_CODE_HARDENING if (0u == loc_pos) return dtbl_get_pos_edge (dyn); - return (dtbl_idx_t) (loc_pos - 1u); + return (dtbl_idx_t)(loc_pos - 1u); #else /* ! MHD_USE_CODE_HARDENING */ - return (dtbl_idx_t) ((dyn->num_entries + loc_pos - 1u) % dyn->num_entries); + return (dtbl_idx_t)((dyn->num_entries + loc_pos - 1u) % dyn->num_entries); #endif /* ! MHD_USE_CODE_HARDENING */ } @@ -636,14 +636,14 @@ MHD_FN_PURE_ mhd_static_inline dtbl_idx_t dtbl_get_pos_next (const struct mhd_HpackDTblContext *dyn, dtbl_idx_ft loc_pos) { - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (loc_pos <= dtbl_get_pos_edge (dyn)); #ifdef MHD_USE_CODE_HARDENING if (dtbl_get_pos_edge (dyn) == loc_pos) return 0u; - return (dtbl_idx_t) (loc_pos + 1u); + return (dtbl_idx_t)(loc_pos + 1u); #else /* ! MHD_USE_CODE_HARDENING */ - return (dtbl_idx_t) ((dyn->num_entries + loc_pos + 1u) % dyn->num_entries); + return (dtbl_idx_t)((dyn->num_entries + loc_pos + 1u) % dyn->num_entries); #endif /* ! MHD_USE_CODE_HARDENING */ } @@ -661,7 +661,7 @@ dtbl_get_pos_next (const struct mhd_HpackDTblContext *dyn, MHD_FN_PURE_ mhd_static_inline dtbl_idx_t dtbl_get_pos_newest (const struct mhd_HpackDTblContext *dyn) { - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); return dyn->newest_pos; } @@ -702,7 +702,7 @@ dtbl_get_pos_from_hpack_idx (const struct mhd_HpackDTblContext *dyn, dtbl_idx_ft hpack_idx) { dtbl_idx_ft pos_back_from_newest = - (dtbl_idx_ft) (hpack_idx - mhd_dtbl_hpack_idx_offset); + (dtbl_idx_ft)(hpack_idx - mhd_dtbl_hpack_idx_offset); mhd_assert (mhd_DTBL_VALUE_FITS (hpack_idx)); mhd_assert (mhd_HPACK_STBL_LAST_IDX < hpack_idx); mhd_assert (dtbl_get_num_entries (dyn) + mhd_dtbl_hpack_idx_offset > \ @@ -710,9 +710,9 @@ dtbl_get_pos_from_hpack_idx (const struct mhd_HpackDTblContext *dyn, #ifdef MHD_USE_CODE_HARDENING if (dtbl_get_pos_newest (dyn) >= pos_back_from_newest) - return (dtbl_idx_t) (dtbl_get_pos_newest (dyn) - pos_back_from_newest); - return (dtbl_idx_t) (dtbl_get_num_entries (dyn) + dtbl_get_pos_newest (dyn) - - pos_back_from_newest); + return (dtbl_idx_t)(dtbl_get_pos_newest (dyn) - pos_back_from_newest); + return (dtbl_idx_t)(dtbl_get_num_entries (dyn) + dtbl_get_pos_newest (dyn) + - pos_back_from_newest); #else /* ! MHD_USE_CODE_HARDENING */ return (dtbl_idx_t) @@ -745,10 +745,10 @@ dtbl_get_hpack_idx_from_pos (const struct mhd_HpackDTblContext *dyn, #ifdef MHD_USE_CODE_HARDENING if (dtbl_get_pos_newest (dyn) >= loc_pos) - return (dtbl_idx_t) (dtbl_get_pos_newest (dyn) - loc_pos - + mhd_dtbl_hpack_idx_offset); - return (dtbl_idx_t) (dtbl_get_num_entries (dyn) + dtbl_get_pos_newest (dyn) - - loc_pos + mhd_dtbl_hpack_idx_offset); + return (dtbl_idx_t)(dtbl_get_pos_newest (dyn) - loc_pos + + mhd_dtbl_hpack_idx_offset); + return (dtbl_idx_t)(dtbl_get_num_entries (dyn) + dtbl_get_pos_newest (dyn) + - loc_pos + mhd_dtbl_hpack_idx_offset); #else /* ! MHD_USE_CODE_HARDENING */ return (dtbl_idx_t) @@ -773,13 +773,13 @@ dtbl_get_strs_ceiling (const struct mhd_HpackDTblContext *dyn) { dtbl_size_ft ceiling = dyn->buf_alloc_size - - (dtbl_size_ft) mhd_DTBL_ENTRY_INFO_SIZE * dyn->num_entries; + - (dtbl_size_ft)mhd_DTBL_ENTRY_INFO_SIZE * dyn->num_entries; mhd_assert (dyn->buf_alloc_size >= mhd_DTBL_ENTRY_INFO_SIZE * dyn->num_entries); mhd_assert (mhd_DTBL_VALUE_FITS (ceiling)); - return (dtbl_size_t) ceiling; + return (dtbl_size_t)ceiling; } @@ -838,7 +838,7 @@ dtbl_pos_entry_info (struct mhd_HpackDTblContext *dyn, dtbl_idx_ft loc_pos) { mhd_assert (mhd_DTBL_VALUE_FITS (loc_pos)); - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (dyn->num_entries > loc_pos); mhd_assert (dyn->buf_alloc_size >= mhd_DTBL_ENTRY_INFO_SIZE * dyn->num_entries); @@ -860,7 +860,7 @@ dtbl_pos_entry_infoc (const struct mhd_HpackDTblContext *dyn, dtbl_idx_ft loc_pos) { mhd_assert (mhd_DTBL_VALUE_FITS (loc_pos)); - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (dyn->num_entries > loc_pos); mhd_assert (dyn->buf_alloc_size >= mhd_DTBL_ENTRY_INFO_SIZE * dyn->num_entries); @@ -914,9 +914,9 @@ dtbl_edge_entry_info (struct mhd_HpackDTblContext *dyn) struct mhd_HpackDTblEntryInfo *const ptr = dtbl_pos_entry_info (dyn, dtbl_get_pos_edge (dyn)); - mhd_assert (((const void *) ptr) == \ - ((const void *) (dtbl_get_strs_buffc (dyn) - + dtbl_get_strs_ceiling (dyn)))); + mhd_assert (((const void *)ptr) == \ + ((const void *)(dtbl_get_strs_buffc (dyn) + + dtbl_get_strs_ceiling (dyn)))); return ptr; } @@ -935,9 +935,9 @@ dtbl_edge_entry_infoc (const struct mhd_HpackDTblContext *dyn) const struct mhd_HpackDTblEntryInfo *const ptr = dtbl_pos_entry_infoc (dyn, dtbl_get_pos_edge (dyn)); - mhd_assert (((const void *) ptr) == \ - ((const void *) (dtbl_get_strs_buffc (dyn) - + dtbl_get_strs_ceiling (dyn)))); + mhd_assert (((const void *)ptr) == \ + ((const void *)(dtbl_get_strs_buffc (dyn) + + dtbl_get_strs_ceiling (dyn)))); return ptr; } @@ -1272,9 +1272,9 @@ MHD_FN_PURE_ mhd_static_inline dtbl_size_t dtbl_entr_as_edge_get_gap (const struct mhd_HpackDTblContext *dyn, const struct mhd_HpackDTblEntryInfo *entr_inf) { - const char *upper_ptr = (const char *) entr_inf; + const char *upper_ptr = (const char *)entr_inf; const char *lower_ptr = dtbl_entr_strs_ptr_endc (dyn, entr_inf); - const dtbl_size_ft gap = (dtbl_size_ft) (upper_ptr - lower_ptr); + const dtbl_size_ft gap = (dtbl_size_ft)(upper_ptr - lower_ptr); mhd_assert (dtbl_zero_entry_infoc (dyn) >= entr_inf); mhd_assert (dtbl_edge_entry_infoc (dyn) <= entr_inf); @@ -1282,7 +1282,7 @@ dtbl_entr_as_edge_get_gap (const struct mhd_HpackDTblContext *dyn, mhd_assert (mhd_DTBL_VALUE_FITS (gap)); mhd_assert (gap < dyn->buf_alloc_size); - return (dtbl_size_t) gap; + return (dtbl_size_t)gap; } @@ -1535,9 +1535,9 @@ dtbl_choose_strs_offset_for_size (dtbl_size_ft space_start, mhd_assert (mhd_DTBL_VALUE_FITS (entry_strs_size)); if (mhd_dtbl_entry_slack <= extra_space) - return (dtbl_size_t) (space_start + mhd_dtbl_entry_slack); + return (dtbl_size_t)(space_start + mhd_dtbl_entry_slack); - return (dtbl_size_t) (space_start + extra_space); + return (dtbl_size_t)(space_start + extra_space); } @@ -1583,11 +1583,11 @@ dtbl_move_strs_down (struct mhd_HpackDTblContext *dyn, mhd_assert (0u != shift_down_size); mhd_assert (dtbl_get_pos_edge (dyn) >= from_pos); mhd_assert (shift_down_size <= dtbl_pos_strs_start (dyn, from_pos)); - mhd_assert ((0u == from_pos) || \ - (dtbl_pos_strs_end_min (dyn, from_pos - 1u) <= \ - dtbl_pos_strs_start (dyn, from_pos) - shift_down_size)); - mhd_assert ((0u != from_pos) || \ - (dtbl_bottom_gap (dyn) >= shift_down_size)); + mhd_assert ((0u == from_pos) \ + || (dtbl_pos_strs_end_min (dyn, from_pos - 1u) <= \ + dtbl_pos_strs_start (dyn, from_pos) - shift_down_size)); + mhd_assert ((0u != from_pos) \ + || (dtbl_bottom_gap (dyn) >= shift_down_size)); mhd_assert (dtbl_edge_gap (dyn) < dyn->buf_alloc_size); mhd_assert (dyn->buf_alloc_size > move_area_size); @@ -1615,7 +1615,7 @@ dtbl_move_strs_down (struct mhd_HpackDTblContext *dyn, for (i = from_pos; dtbl_get_pos_edge (dyn) >= i; ++i) dtbl_pos_entry_info (dyn, - i)->offset -= (dtbl_size_t) shift_down_size; + i)->offset -= (dtbl_size_t)shift_down_size; } @@ -1678,7 +1678,7 @@ dtbl_move_strs_up (struct mhd_HpackDTblContext *dyn, for (i = from_pos; dtbl_get_pos_edge (dyn) >= i; ++i) dtbl_pos_entry_info (dyn, - i)->offset += (dtbl_size_t) shift_up_size; + i)->offset += (dtbl_size_t)shift_up_size; } @@ -1765,9 +1765,9 @@ dtbl_choose_strs_offset (dtbl_size_ft space_start, mhd_assert (mhd_DTBL_VALUE_FITS (space_size)); mhd_assert (space_end >= space_size); - return (dtbl_size_t) dtbl_choose_strs_offset_for_size (space_start, - space_size, - entry_strs_size); + return (dtbl_size_t)dtbl_choose_strs_offset_for_size (space_start, + space_size, + entry_strs_size); } @@ -1910,32 +1910,36 @@ dtbl_zeroout_strs_slack_pos (struct mhd_HpackDTblContext *dyn, /** * No-op macro in non-debug builds. */ -#define dtbl_zeroout_strs_slack_ptr_space(ptr,space) ((void) 0) +# define dtbl_zeroout_strs_slack_ptr_space(ptr, space) ((void) 0) /** * No-op macro in non-debug builds. */ -#define dtbl_zeroout_strs_slack_offset_space(dyn,offset,space) ((void) 0) +# define dtbl_zeroout_strs_slack_offset_space(dyn, offset, space) \ + ((void) 0) /** * No-op macro in non-debug builds. */ -#define dtbl_zeroout_strs_slack_offset_next(dyn,offset,next_offset) ((void) 0) +# define dtbl_zeroout_strs_slack_offset_next(dyn, offset, next_offset) \ + ((void) 0) /** * No-op macro in non-debug builds. */ -#define dtbl_zeroout_strs_slack_entry_space(dyn,entry,space) ((void) 0) +# define dtbl_zeroout_strs_slack_entry_space(dyn, entry, space) \ + ((void) 0) /** * No-op macro in non-debug builds. */ -#define dtbl_zeroout_strs_slack_entry_next(dyn,entry,next_offset) ((void) 0) +# define dtbl_zeroout_strs_slack_entry_next(dyn, entry, next_offset) \ + ((void) 0) /** * No-op macro in non-debug builds. */ -#define dtbl_zeroout_strs_slack_pos(dyn,loc_pos) ((void) 0) +# define dtbl_zeroout_strs_slack_pos(dyn, loc_pos) ((void) 0) #endif /* NDEBUG */ @@ -1974,11 +1978,11 @@ dtbl_new_entry_copy_entr_strs ( #ifndef MHD_ASAN_ACTIVE # ifdef HAVE_UINTPTR_T /* The new entry must not be in the table */ - mhd_assert (dtbl_is_empty (dyn) || - (((uintptr_t) (const void*) dtbl_zero_entry_infoc (dyn)) < \ - (uintptr_t) (const void*) new_entry) || \ - (((uintptr_t) (const void*) dtbl_zero_entry_infoc (dyn)) > \ - (uintptr_t) (const void*) new_entry)); + mhd_assert (dtbl_is_empty (dyn) + || (((uintptr_t)(const void *)dtbl_zero_entry_infoc (dyn)) < \ + (uintptr_t)(const void *)new_entry) \ + || (((uintptr_t)(const void *)dtbl_zero_entry_infoc (dyn)) > \ + (uintptr_t)(const void *)new_entry)); # endif /* HAVE_UINTPTR_T */ #endif /* ! MHD_ASAN_ACTIVE*/ @@ -1993,11 +1997,11 @@ dtbl_new_entry_copy_entr_strs ( { /* Check whether the buffer area referenced in the new entry is not used by other entries */ - mhd_assert ((0u == dtbl_pos_strs_size_min (dyn, i)) || \ - (dtbl_pos_strs_end_min (dyn, i) <= \ - dtbl_entr_strs_start (new_entry)) || \ - (dtbl_entr_strs_end_min (new_entry) <= \ - dtbl_pos_strs_start (dyn, i))); + mhd_assert ((0u == dtbl_pos_strs_size_min (dyn, i)) \ + || (dtbl_pos_strs_end_min (dyn, i) <= \ + dtbl_entr_strs_start (new_entry)) \ + || (dtbl_entr_strs_end_min (new_entry) <= \ + dtbl_pos_strs_start (dyn, i))); if (dtbl_entr_strs_end_min (new_entry) <= \ dtbl_pos_strs_start (dyn, i)) @@ -2163,7 +2167,7 @@ dtbl_move_infos_pos (struct mhd_HpackDTblContext *dyn, memmove (dst, src, - (size_t) (num_elements * mhd_DTBL_ENTRY_INFO_SIZE)); + (size_t)(num_elements * mhd_DTBL_ENTRY_INFO_SIZE)); } @@ -2196,8 +2200,8 @@ dtbl_check_internals (const struct mhd_HpackDTblContext *dyn) dtbl_idx_ft i; mhd_assert (dyn->newest_pos < dyn->num_entries); - mhd_assert ((0u != dyn->cur_size) && \ - "Each entry has minimal size, even with zero-length strings"); + mhd_assert ((0u != dyn->cur_size) \ + && "Each entry has minimal size, even with zero-length strings"); mhd_assert (dyn->cur_size >= \ (dyn->num_entries * mhd_dtbl_entry_overhead)); mhd_assert (dtbl_edge_gap (dyn) <= dyn->buf_alloc_size); @@ -2207,8 +2211,8 @@ dtbl_check_internals (const struct mhd_HpackDTblContext *dyn) at the start of the buffer. */ if (0u != dtbl_get_pos_oldest (dyn)) { - mhd_assert ((0u == zero_entry->offset) && \ - "The extra gap between entries' strings is allowed only " \ + mhd_assert ((0u == zero_entry->offset) \ + && "The extra gap between entries' strings is allowed only " \ "between the newest and the oldest entries"); } mhd_assert (zero_entry->offset < dyn->buf_alloc_size); @@ -2216,7 +2220,7 @@ dtbl_check_internals (const struct mhd_HpackDTblContext *dyn) mhd_assert (zero_entry->val_len < dyn->buf_alloc_size); mhd_assert (dtbl_entr_strs_end_min (zero_entry) < dyn->buf_alloc_size); mhd_assert (dtbl_entr_strs_ptr_endc (dyn, zero_entry) <= \ - (const char*) dtbl_edge_entry_infoc (dyn)); + (const char *)dtbl_edge_entry_infoc (dyn)); counted_size += dtbl_entr_size_formal (zero_entry); mhd_assert (counted_size <= dyn->cur_size); @@ -2227,13 +2231,13 @@ dtbl_check_internals (const struct mhd_HpackDTblContext *dyn) i); mhd_assert ((dtbl_pos_strs_end_min (dyn, i - 1u) <= \ - dtbl_pos_strs_start (dyn, i)) && \ - "Strings data cannot overlap between entries"); + dtbl_pos_strs_start (dyn, i)) \ + && "Strings data cannot overlap between entries"); if (dtbl_get_pos_oldest (dyn) != i) mhd_assert ((dtbl_pos_strs_end_optm (dyn, i - 1u) >= \ - dtbl_pos_strs_start (dyn, i)) && \ - "The extra gap between entries' strings is allowed only " \ + dtbl_pos_strs_start (dyn, i)) \ + && "The extra gap between entries' strings is allowed only " \ "between the newest and the oldest entries"); mhd_assert (dtbl_pos_strs_start (dyn, i) < dyn->buf_alloc_size); @@ -2241,7 +2245,7 @@ dtbl_check_internals (const struct mhd_HpackDTblContext *dyn) mhd_assert (check_entry->val_len < dyn->buf_alloc_size); mhd_assert (dtbl_entr_strs_end_min (check_entry) < dyn->buf_alloc_size); mhd_assert (dtbl_entr_strs_ptr_endc (dyn, check_entry) <= \ - (const char*) dtbl_edge_entry_infoc (dyn)); + (const char *)dtbl_edge_entry_infoc (dyn)); if (dtbl_get_pos_edge (dyn) != i) mhd_assert (0u != dtbl_pos_as_edge_get_gap (dyn, i)); @@ -2256,7 +2260,7 @@ dtbl_check_internals (const struct mhd_HpackDTblContext *dyn) #else /* NDEBUG */ /* No-op in non-debug builds */ -#define dtbl_check_internals(dyn) ((void) 0) +# define dtbl_check_internals(dyn) ((void) 0) #endif /* NDEBUG */ /** @@ -2271,7 +2275,7 @@ dtbl_check_internals (const struct mhd_HpackDTblContext *dyn) * @param val_len the length of the @a val * @param val the value of the header, does NOT need to be zero terminated */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) void +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) void dtbl_add_first_entry (struct mhd_HpackDTblContext *restrict dyn, const dtbl_size_ft name_len, const char *restrict name, @@ -2293,8 +2297,8 @@ dtbl_add_first_entry (struct mhd_HpackDTblContext *restrict dyn, dtbl_check_internals (dyn); - new_entry.name_len = (dtbl_size_t) name_len; - new_entry.val_len = (dtbl_size_t) val_len; + new_entry.name_len = (dtbl_size_t)name_len; + new_entry.val_len = (dtbl_size_t)val_len; new_entry.offset = 0u; mhd_assert (dtbl_get_free_formal (dyn) >= \ @@ -2335,7 +2339,7 @@ dtbl_add_first_entry (struct mhd_HpackDTblContext *restrict dyn, * @param val_len the length of the @a val * @param val the value of the header, does NOT need to be zero terminated */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) void +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) void dtbl_add_new_entry_at_new_edge (struct mhd_HpackDTblContext *restrict dyn, const dtbl_size_ft name_len, const char *restrict name, @@ -2356,7 +2360,7 @@ dtbl_add_new_entry_at_new_edge (struct mhd_HpackDTblContext *restrict dyn, dtbl_new_entry_size_formal (name_len, val_len)); /* Check conditions */ - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (dtbl_get_pos_edge (dyn) == dtbl_get_pos_newest (dyn)); mhd_assert (dtbl_edge_gap (dyn) >= \ entry_strs_size + mhd_DTBL_ENTRY_INFO_SIZE); @@ -2369,8 +2373,8 @@ dtbl_add_new_entry_at_new_edge (struct mhd_HpackDTblContext *restrict dyn, /* Both strings and the entry info data must be stored in this memory area (edge gap). */ - new_entry.name_len = (dtbl_size_t) name_len; - new_entry.val_len = (dtbl_size_t) val_len; + new_entry.name_len = (dtbl_size_t)name_len; + new_entry.val_len = (dtbl_size_t)val_len; new_entry.offset = dtbl_choose_strs_offset (dtbl_pos_strs_end_min (dyn, dtbl_get_pos_edge (dyn)), @@ -2392,7 +2396,7 @@ dtbl_add_new_entry_at_new_edge (struct mhd_HpackDTblContext *restrict dyn, dyn->cur_size += dtbl_entr_size_formal (&new_entry); mhd_assert (dyn->cur_size > dtbl_entr_size_formal (&new_entry)); - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (0u != dyn->newest_pos); mhd_assert (dyn->size_limit >= dyn->cur_size); /* The next assert evaluates dtbl_edge_gap(), which also checks the @@ -2462,7 +2466,7 @@ dtbl_insert_next_new_entry (struct mhd_HpackDTblContext *restrict dyn, (dtbl_get_pos_newest (dyn) == dtbl_get_pos_edge (dyn))); /* Check conditions */ - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); dtbl_check_internals (dyn); @@ -2471,8 +2475,8 @@ dtbl_insert_next_new_entry (struct mhd_HpackDTblContext *restrict dyn, another entry). */ mhd_assert (avail_space_end >= avail_space_start); - new_entry.name_len = (dtbl_size_t) name_len; - new_entry.val_len = (dtbl_size_t) val_len; + new_entry.name_len = (dtbl_size_t)name_len; + new_entry.val_len = (dtbl_size_t)val_len; new_entry.offset = insert_at_zero ? 0u : dtbl_choose_strs_offset (avail_space_start, avail_space_end, @@ -2496,12 +2500,12 @@ dtbl_insert_next_new_entry (struct mhd_HpackDTblContext *restrict dyn, *insert_entry_ptr = new_entry; ++(dyn->num_entries); - dyn->newest_pos = (dtbl_idx_t) loc_pos; + dyn->newest_pos = (dtbl_idx_t)loc_pos; dyn->cur_size += dtbl_entr_size_formal (&new_entry); mhd_assert (dyn->cur_size > dtbl_entr_size_formal (&new_entry)); mhd_assert (dtbl_get_pos_edge (dyn) > dtbl_get_pos_newest (dyn)); - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (dyn->size_limit >= dyn->cur_size); /* The next assert calls dtbl_edge_gap() which force checking non-overlap of entries and strings. */ @@ -2564,7 +2568,7 @@ dtbl_extend_with_entry (struct mhd_HpackDTblContext *restrict dyn, const dtbl_size_ft bottom_gap = dtbl_bottom_gap (dyn); /* 'true' to insert at the edge, 'false' to insert at the bottom */ bool insert_at_the_edge; - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (0u != dyn->cur_size); if (mhd_DTBL_ENTRY_INFO_SIZE > top_gap) @@ -2617,8 +2621,8 @@ dtbl_extend_with_entry (struct mhd_HpackDTblContext *restrict dyn, mhd_assert ((top_gap + bottom_gap >= \ mhd_dtbl_entry_slack \ + entry_strs_size \ - + mhd_dtbl_entry_slack + mhd_DTBL_ENTRY_INFO_SIZE) && \ - "The total allocation size of the buffer is larger than " \ + + mhd_dtbl_entry_slack + mhd_DTBL_ENTRY_INFO_SIZE) \ + && "The total allocation size of the buffer is larger than " \ "required for strict HPACK. All extra size should be now " \ "on the top and on the bottom, as all other strings " \ "should now be place optimally or denser. The total free " \ @@ -2634,8 +2638,8 @@ dtbl_extend_with_entry (struct mhd_HpackDTblContext *restrict dyn, mhd_assert ((dtbl_edge_gap (dyn) >= \ mhd_dtbl_entry_slack \ + entry_strs_size \ - + mhd_dtbl_entry_slack + mhd_DTBL_ENTRY_INFO_SIZE) && \ - "Strings have been compacted up to optimal space or " + + mhd_dtbl_entry_slack + mhd_DTBL_ENTRY_INFO_SIZE) \ + && "Strings have been compacted up to optimal space or " "denser. The free space should be enough for optimal " "placement."); insert_at_the_edge = true; @@ -2684,8 +2688,8 @@ dtbl_extend_with_entry (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (top_gap + inbetween_gap >= \ entry_strs_size + mhd_DTBL_ENTRY_INFO_SIZE); mhd_assert ((top_gap + inbetween_gap >= \ - optimal_inbetween_size + mhd_DTBL_ENTRY_INFO_SIZE) && \ - "This is not required for the insertion of the entry " \ + optimal_inbetween_size + mhd_DTBL_ENTRY_INFO_SIZE) \ + && "This is not required for the insertion of the entry " \ "but this is guaranteed by the checking the overall size " \ "of the buffer before the insertion, so this is a check " \ "for the overall handling logic."); @@ -2746,7 +2750,7 @@ dtbl_extend_with_entry (struct mhd_HpackDTblContext *restrict dyn, * @param val_len the length of the @a val * @param val the value of the header, does NOT need to be zero terminated */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) void +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) void dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, const dtbl_size_ft name_len, const char *restrict name, @@ -2769,7 +2773,7 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (mhd_DTBL_VALUE_FITS (name_len)); mhd_assert (mhd_DTBL_VALUE_FITS (val_len)); mhd_assert (0u != dyn->cur_size); - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (mhd_DTBL_VALUE_FITS (entry_strs_size)); mhd_assert (entry_strs_size >= name_len); mhd_assert (entry_strs_size >= val_len); @@ -2834,14 +2838,14 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, + add the new entry at the edge. No need to move the data in the table's buffer. */ mhd_assert (eviction_end >= eviction_start); - mhd_assert ((0u == dtbl_pos_strs_start (dyn, 0u)) && \ - "An extra gap is allowed only between the newest and the " \ + mhd_assert ((0u == dtbl_pos_strs_start (dyn, 0u)) \ + && "An extra gap is allowed only between the newest and the " \ "oldest entries. The newest entry was not the edge entry " \ "before the eviction."); mhd_assert (dtbl_get_pos_newest (dyn) == (eviction_start - 1u)); - dyn->cur_size -= (dtbl_size_t) evicted_size; - dyn->num_entries = (dtbl_idx_t) eviction_start; + dyn->cur_size -= (dtbl_size_t)evicted_size; + dyn->num_entries = (dtbl_idx_t)eviction_start; dtbl_add_new_entry_at_new_edge (dyn, name_len, @@ -2850,8 +2854,8 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, val); return; } - else if ((0u != eviction_start) && - (eviction_end >= eviction_start)) + else if ((0u != eviction_start) + && (eviction_end >= eviction_start)) { /* Entries are evicted in between other entries, at least two entries are not evicted (at the start and at the edge). */ @@ -2900,8 +2904,8 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, dtbl_get_pos_edge (dyn), eviction_start + 1u); /* Keep the standard overhead of the entry being replaced */ - dyn->cur_size -= (dtbl_size_t) (evicted_size - mhd_dtbl_entry_overhead); - dyn->num_entries -= (dtbl_idx_t) (num_to_evict - 1u); + dyn->cur_size -= (dtbl_size_t)(evicted_size - mhd_dtbl_entry_overhead); + dyn->num_entries -= (dtbl_idx_t)(num_to_evict - 1u); if (space_size < entry_strs_size) { @@ -2920,8 +2924,8 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (space_size >= entry_strs_size); - new_entry.name_len = (dtbl_size_t) name_len; - new_entry.val_len = (dtbl_size_t) val_len; + new_entry.name_len = (dtbl_size_t)name_len; + new_entry.val_len = (dtbl_size_t)val_len; new_entry.offset = dtbl_choose_strs_offset_for_size (space_start, space_size, entry_strs_size); @@ -2936,9 +2940,9 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, &new_entry); *replace_entry_ptr = new_entry; /* Keep the standard overhead of the entry being replaced */ - dyn->cur_size += (dtbl_size_t) entry_strs_size; + dyn->cur_size += (dtbl_size_t)entry_strs_size; mhd_assert ((dyn->newest_pos + 1u) == eviction_start); - dyn->newest_pos = (dtbl_idx_t) eviction_start; + dyn->newest_pos = (dtbl_idx_t)eviction_start; return; } @@ -2963,7 +2967,7 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, dtbl_idx_ft last_entry_keep = dtbl_get_pos_prev (dyn, eviction_start); dtbl_idx_ft num_to_keep = - ((dtbl_idx_ft) (last_entry_keep - first_entry_keep) + 1u); + ((dtbl_idx_ft)(last_entry_keep - first_entry_keep) + 1u); /** The available space at the bottom of the strings buffer after eviction of the entries */ dtbl_size_ft new_bottom_gap = dtbl_pos_strs_start (dyn, @@ -2995,11 +2999,11 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, last_entry_keep, 1u); /* Keep the standard overhead of the entry being replaced */ - dyn->cur_size -= (dtbl_size_t) (evicted_size - mhd_dtbl_entry_overhead); - dyn->num_entries = (dtbl_idx_t) num_to_keep + 1u; /* Plus replaced zero position */ + dyn->cur_size -= (dtbl_size_t)(evicted_size - mhd_dtbl_entry_overhead); + dyn->num_entries = (dtbl_idx_t)num_to_keep + 1u; /* Plus replaced zero position */ - new_entry.name_len = (dtbl_size_t) name_len; - new_entry.val_len = (dtbl_size_t) val_len; + new_entry.name_len = (dtbl_size_t)name_len; + new_entry.val_len = (dtbl_size_t)val_len; new_entry.offset = 0u; mhd_assert (dtbl_entr_strs_end_min (&new_entry) <= \ @@ -3011,7 +3015,7 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, &new_entry); *replace_entry_ptr = new_entry; /* Keep the standard overhead of the entry being replaced */ - dyn->cur_size += (dtbl_size_t) entry_strs_size; + dyn->cur_size += (dtbl_size_t)entry_strs_size; dyn->newest_pos = 0u; dtbl_zeroout_strs_slack_pos (dyn, @@ -3036,8 +3040,8 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, entry_strs_size + mhd_DTBL_ENTRY_INFO_SIZE); mhd_assert ((new_top_gap + new_bottom_gap >= \ mhd_dtbl_entry_slack + entry_strs_size - + mhd_dtbl_entry_slack + mhd_DTBL_ENTRY_INFO_SIZE) && \ - "This is not required for the insertion of the entry " \ + + mhd_dtbl_entry_slack + mhd_DTBL_ENTRY_INFO_SIZE) \ + && "This is not required for the insertion of the entry " \ "but this is guaranteed by the checking the overall size " \ "of the buffer before the insertion, so this is a check " \ "for the overall handling logic."); @@ -3050,9 +3054,9 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, last_entry_keep, 0u); /* Keep the table internal data correct */ - dyn->num_entries = (dtbl_idx_t) num_to_keep; - dyn->newest_pos = (dtbl_idx_t) (num_to_keep - 1u); - dyn->cur_size -= (dtbl_size_t) evicted_size; + dyn->num_entries = (dtbl_idx_t)num_to_keep; + dyn->newest_pos = (dtbl_idx_t)(num_to_keep - 1u); + dyn->cur_size -= (dtbl_size_t)evicted_size; mhd_assert (new_top_gap == dtbl_edge_gap (dyn)); @@ -3073,8 +3077,8 @@ dtbl_evict_add_entry (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (new_top_gap + shift_size == dtbl_edge_gap (dyn)); mhd_assert (dtbl_edge_gap (dyn) >= \ mhd_dtbl_entry_slack \ - + dtbl_new_entry_strs_size_formal (entry_strs_size) && \ - "All strings have been compacted, the free space must " \ + + dtbl_new_entry_strs_size_formal (entry_strs_size) \ + && "All strings have been compacted, the free space must " \ "be enough for the previous entry slack and for " \ "a complete new entry, including slack and info data."); } @@ -3124,7 +3128,7 @@ dtbl_evict_to_size (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (dtbl_get_used_formal (dyn) > max_used_final); mhd_assert (0u != dyn->cur_size); - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (0u != needed_evict_min); mhd_assert (needed_evict_min <= dyn->cur_size); @@ -3162,13 +3166,13 @@ dtbl_evict_to_size (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (eviction_end >= eviction_start); mhd_assert (dtbl_get_pos_newest (dyn) == (eviction_start - 1u)); - dyn->cur_size -= (dtbl_size_t) evicted_size; - dyn->num_entries = (dtbl_idx_t) eviction_start; + dyn->cur_size -= (dtbl_size_t)evicted_size; + dyn->num_entries = (dtbl_idx_t)eviction_start; return; } - else if ((0u != eviction_start) && - (eviction_end >= eviction_start)) + else if ((0u != eviction_start) + && (eviction_end >= eviction_start)) { /* Entries are evicted in-between of other entries, at least two entries are not evicted (at the start and at the edge). */ @@ -3188,8 +3192,8 @@ dtbl_evict_to_size (struct mhd_HpackDTblContext *restrict dyn, first_entry_keep, dtbl_get_pos_edge (dyn), eviction_start); - dyn->cur_size -= (dtbl_size_t) evicted_size; - dyn->num_entries -= (dtbl_idx_t) num_to_evict; + dyn->cur_size -= (dtbl_size_t)evicted_size; + dyn->num_entries -= (dtbl_idx_t)num_to_evict; mhd_assert (dtbl_get_pos_edge (dyn) >= dtbl_get_pos_newest (dyn)); return; @@ -3205,7 +3209,7 @@ dtbl_evict_to_size (struct mhd_HpackDTblContext *restrict dyn, dtbl_idx_ft last_entry_keep = dtbl_get_pos_prev (dyn, eviction_start); dtbl_idx_ft num_to_keep = - ((dtbl_idx_ft) (last_entry_keep - first_entry_keep) + 1u); + ((dtbl_idx_ft)(last_entry_keep - first_entry_keep) + 1u); mhd_assert (dtbl_get_pos_edge (dyn) != eviction_end); mhd_assert (0u != num_to_keep); @@ -3216,8 +3220,8 @@ dtbl_evict_to_size (struct mhd_HpackDTblContext *restrict dyn, first_entry_keep, last_entry_keep, 0u); - dyn->cur_size -= (dtbl_size_t) evicted_size; - dyn->num_entries = (dtbl_idx_t) num_to_keep; + dyn->cur_size -= (dtbl_size_t)evicted_size; + dyn->num_entries = (dtbl_idx_t)num_to_keep; dyn->newest_pos = dtbl_get_pos_edge (dyn); return; @@ -3250,7 +3254,7 @@ dtbl_perform_resize (struct mhd_HpackDTblContext *restrict dyn, const dtbl_size_ft entries_total_size = dtbl_get_num_entries (dyn) * mhd_DTBL_ENTRY_INFO_SIZE; - mhd_assert (! dtbl_is_empty (dyn)); + mhd_assert (!dtbl_is_empty (dyn)); mhd_assert (mhd_DTBL_VALUE_FITS (new_alloc_size)); mhd_assert (mhd_DTBL_VALUE_FITS (new_formal_size)); mhd_assert (new_formal_size <= mhd_DTBL_MAX_SIZE); @@ -3272,7 +3276,7 @@ dtbl_perform_resize (struct mhd_HpackDTblContext *restrict dyn, } else if (mhd_COND_ALMOST_NEVER (new_alloc_size == dyn->buf_alloc_size)) { - dyn->size_limit = (dtbl_size_t) new_formal_size; + dyn->size_limit = (dtbl_size_t)new_formal_size; return; /* Just update the formal size */ } else @@ -3284,14 +3288,14 @@ dtbl_perform_resize (struct mhd_HpackDTblContext *restrict dyn, } /* Set the new table size */ - dyn->size_limit = (dtbl_size_t) new_formal_size; - dyn->buf_alloc_size = (dtbl_size_t) new_alloc_size; + dyn->size_limit = (dtbl_size_t)new_formal_size; + dyn->buf_alloc_size = (dtbl_size_t)new_alloc_size; /* Get the data location based on the new table size */ infos_new_ptr = dtbl_edge_entry_info (dyn); memmove (infos_new_ptr, infos_old_ptr, - (size_t) entries_total_size); + (size_t)entries_total_size); } @@ -3317,7 +3321,7 @@ dtbl_adapt_to_new_size (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (new_formal_size <= mhd_DTBL_MAX_SIZE); mhd_assert (new_formal_size < new_alloc_size); - if (! dtbl_is_empty (dyn)) + if (!dtbl_is_empty (dyn)) { dtbl_perform_resize (dyn, new_alloc_size, @@ -3326,8 +3330,8 @@ dtbl_adapt_to_new_size (struct mhd_HpackDTblContext *restrict dyn, } /* Just set the new table size */ - dyn->size_limit = (dtbl_size_t) new_formal_size; - dyn->buf_alloc_size = (dtbl_size_t) new_alloc_size; + dyn->size_limit = (dtbl_size_t)new_formal_size; + dyn->buf_alloc_size = (dtbl_size_t)new_alloc_size; } @@ -3372,7 +3376,7 @@ dtbl_calc_alloc_size (dtbl_size_ft formal_size) mhd_assert (mhd_DTBL_VALUE_FITS (dyn_table_alloc_size)); - return (dtbl_size_t) dyn_table_alloc_size; + return (dtbl_size_t)dyn_table_alloc_size; } @@ -3393,7 +3397,7 @@ dtbl_calc_alloc_size (dtbl_size_ft formal_size) * @return the HPACK index (> #mhd_HPACK_STBL_LAST_IDX) of the matching entry, * or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) dtbl_idx_t dtbl_find_entry (const struct mhd_HpackDTblContext *restrict dyn, dtbl_size_ft name_len, const char *restrict name, @@ -3412,17 +3416,17 @@ dtbl_find_entry (const struct mhd_HpackDTblContext *restrict dyn, continue; if (val_len != entry->val_len) continue; - if (((0u == name_len) || - (0 == memcmp (name, - dtbl_entr_strs_ptr_namec (dyn, - entry), - name_len))) + if (((0u == name_len) + || (0 == memcmp (name, + dtbl_entr_strs_ptr_namec (dyn, + entry), + name_len))) && - ((0u == val_len) || - (0 == memcmp (val, - dtbl_entr_strs_ptr_valuec (dyn, - entry), - val_len)))) + ((0u == val_len) + || (0 == memcmp (val, + dtbl_entr_strs_ptr_valuec (dyn, + entry), + val_len)))) { /* Found the entry */ return dtbl_get_hpack_idx_from_pos (dyn, dtbl_get_pos_edge (dyn) - i); @@ -3444,7 +3448,7 @@ dtbl_find_entry (const struct mhd_HpackDTblContext *restrict dyn, * @return the HPACK index (> #mhd_HPACK_STBL_LAST_IDX) of the matching entry, * or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (3,2) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (3, 2) dtbl_idx_t dtbl_find_name (const struct mhd_HpackDTblContext *restrict dyn, dtbl_size_ft name_len, const char *restrict name) @@ -3459,11 +3463,11 @@ dtbl_find_name (const struct mhd_HpackDTblContext *restrict dyn, if (name_len != entry->name_len) continue; - if ((0u == name_len) || - (0 == memcmp (name, - dtbl_entr_strs_ptr_namec (dyn, - entry), - name_len))) + if ((0u == name_len) + || (0 == memcmp (name, + dtbl_entr_strs_ptr_namec (dyn, + entry), + name_len))) { /* Found the entry */ return dtbl_get_hpack_idx_from_pos (dyn, dtbl_get_pos_edge (dyn) - i); @@ -3499,20 +3503,20 @@ static mhd_FN_RET_UNALIASED struct mhd_HpackDTblContext * mhd_dtbl_create (size_t dyn_table_size) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; dtbl_size_ft alloc_size; mhd_assert (mhd_DTBL_MAX_SIZE >= dyn_table_size); mhd_assert (mhd_DTBL_VALUE_FITS (dyn_table_size)); - alloc_size = dtbl_calc_alloc_size ((dtbl_size_ft) dyn_table_size); + alloc_size = dtbl_calc_alloc_size ((dtbl_size_ft)dyn_table_size); - dyn = (struct mhd_HpackDTblContext*) malloc (sizeof(*dyn) - + (size_t) alloc_size); + dyn = (struct mhd_HpackDTblContext *)malloc (sizeof(*dyn) + + (size_t)alloc_size); if (NULL == dyn) return NULL; /* Failure exit point */ - dyn->buf_alloc_size = (dtbl_size_t) alloc_size; - dyn->size_limit = (dtbl_size_t) dyn_table_size; + dyn->buf_alloc_size = (dtbl_size_t)alloc_size; + dyn->size_limit = (dtbl_size_t)dyn_table_size; dtbl_reset (dyn); dtbl_check_internals (dyn); @@ -3543,7 +3547,7 @@ mhd_dtbl_destroy (struct mhd_HpackDTblContext *dyn) static MHD_FN_PURE_ size_t mhd_dtbl_get_table_max_size (const struct mhd_HpackDTblContext *dyn) { - return (size_t) dtbl_get_size_max_formal (dyn); + return (size_t)dtbl_get_size_max_formal (dyn); } @@ -3555,7 +3559,7 @@ mhd_dtbl_get_table_max_size (const struct mhd_HpackDTblContext *dyn) static MHD_FN_PURE_ size_t mhd_dtbl_get_table_used (const struct mhd_HpackDTblContext *dyn) { - return (size_t) dtbl_get_used_formal (dyn); + return (size_t)dtbl_get_used_formal (dyn); } @@ -3567,7 +3571,7 @@ mhd_dtbl_get_table_used (const struct mhd_HpackDTblContext *dyn) static MHD_FN_PURE_ size_t mhd_dtbl_get_num_entries (const struct mhd_HpackDTblContext *dyn) { - return (size_t) dtbl_get_num_entries (dyn); + return (size_t)dtbl_get_num_entries (dyn); } @@ -3596,7 +3600,7 @@ mhd_dtbl_evict_to_size (struct mhd_HpackDTblContext *dyn, return; else dtbl_evict_to_size (dyn, - (dtbl_size_t) max_used_formal); + (dtbl_size_t)max_used_formal); dtbl_check_internals (dyn); } @@ -3617,7 +3621,7 @@ mhd_dtbl_evict_to_size (struct mhd_HpackDTblContext *dyn, * not resized) */ static bool -mhd_dtbl_resize (struct mhd_HpackDTblContext** const dyn_pp, +mhd_dtbl_resize (struct mhd_HpackDTblContext **const dyn_pp, size_t dyn_table_size) { const dtbl_size_ft old_official_size = dtbl_get_size_max_formal (*dyn_pp); @@ -3629,15 +3633,15 @@ mhd_dtbl_resize (struct mhd_HpackDTblContext** const dyn_pp, if (old_official_size == dyn_table_size) return true; /* Do nothing */ - new_alloc_size = dtbl_calc_alloc_size ((dtbl_size_ft) dyn_table_size); + new_alloc_size = dtbl_calc_alloc_size ((dtbl_size_ft)dyn_table_size); if (old_official_size < dyn_table_size) { /* Growing table size */ /* No need to evict */ - new_dyn = (struct mhd_HpackDTblContext*) + new_dyn = (struct mhd_HpackDTblContext *) realloc (*dyn_pp, - sizeof(**dyn_pp) + (size_t) new_alloc_size); + sizeof(**dyn_pp) + (size_t)new_alloc_size); if (NULL == new_dyn) return false; /* No table resize */ *dyn_pp = new_dyn; @@ -3645,23 +3649,23 @@ mhd_dtbl_resize (struct mhd_HpackDTblContext** const dyn_pp, /* Adapt the table data to the larger size */ dtbl_adapt_to_new_size (new_dyn, new_alloc_size, - (dtbl_size_ft) dyn_table_size); + (dtbl_size_ft)dyn_table_size); } else { /* Shrinking table size */ mhd_dtbl_evict_to_size (*dyn_pp, - (dtbl_size_ft) dyn_table_size); + (dtbl_size_ft)dyn_table_size); /* Adapt table data before resizing */ dtbl_adapt_to_new_size (*dyn_pp, new_alloc_size, - (dtbl_size_ft) dyn_table_size); + (dtbl_size_ft)dyn_table_size); /* Try to reduce the allocated memory */ - new_dyn = (struct mhd_HpackDTblContext*) + new_dyn = (struct mhd_HpackDTblContext *) realloc (*dyn_pp, - sizeof(**dyn_pp) + (size_t) new_alloc_size); + sizeof(**dyn_pp) + (size_t)new_alloc_size); /* If realloc() failed, just use the previous allocation. The table will use the new (reduced) size anyway, while the allocation @@ -3718,16 +3722,16 @@ mhd_dtbl_check_entry_fit (struct mhd_HpackDTblContext *restrict dyn, * @param val_len the length of the @a val, must fit #mhd_HPACK_DTBL_BITS bits * @param val the value of the header, does NOT need to be zero terminated */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) void +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) void mhd_dtbl_new_entry (struct mhd_HpackDTblContext *restrict dyn, size_t name_len, const char *restrict name, size_t val_len, const char *restrict val) { - if (mhd_COND_ALMOST_NEVER (! mhd_dtbl_check_entry_fit (dyn, - name_len, - val_len))) + if (mhd_COND_ALMOST_NEVER (!mhd_dtbl_check_entry_fit (dyn, + name_len, + val_len))) { /* The entry cannot fit the table. * Reset table to empty state (need to evict all entries). */ @@ -3735,16 +3739,16 @@ mhd_dtbl_new_entry (struct mhd_HpackDTblContext *restrict dyn, } else if (dtbl_get_free_formal (dyn) - >= dtbl_new_entry_size_formal ((dtbl_size_ft) name_len, - (dtbl_size_ft) val_len)) + >= dtbl_new_entry_size_formal ((dtbl_size_ft)name_len, + (dtbl_size_ft)val_len)) { /* Enough space. Insert new entry. */ mhd_assert (mhd_DTBL_VALUE_FITS (name_len)); mhd_assert (mhd_DTBL_VALUE_FITS (val_len)); dtbl_extend_with_entry (dyn, - (dtbl_size_ft) name_len, + (dtbl_size_ft)name_len, name, - (dtbl_size_ft) val_len, + (dtbl_size_ft)val_len, val); } else @@ -3754,9 +3758,9 @@ mhd_dtbl_new_entry (struct mhd_HpackDTblContext *restrict dyn, mhd_assert (mhd_DTBL_VALUE_FITS (name_len)); mhd_assert (mhd_DTBL_VALUE_FITS (val_len)); dtbl_evict_add_entry (dyn, - (dtbl_size_ft) name_len, + (dtbl_size_ft)name_len, name, - (dtbl_size_ft) val_len, + (dtbl_size_ft)val_len, val); } @@ -3805,10 +3809,10 @@ mhd_dtbl_get_entry (const struct mhd_HpackDTblContext *restrict dyn, entry = dtbl_pos_entry_infoc (dyn, dtbl_get_pos_from_hpack_idx (dyn, idx)); - name_out->size = (size_t) entry->name_len; + name_out->size = (size_t)entry->name_len; name_out->data = dtbl_entr_strs_ptr_startc (dyn, entry); - value_out->size = (size_t) entry->val_len; + value_out->size = (size_t)entry->val_len; value_out->data = name_out->data + name_out->size; return true; @@ -3831,7 +3835,7 @@ mhd_dtbl_get_entry (const struct mhd_HpackDTblContext *restrict dyn, * @return the HPACK index (> #mhd_HPACK_STBL_LAST_IDX) of the matching entry, * or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) dtbl_idx_t mhd_dtbl_find_entry (const struct mhd_HpackDTblContext *restrict dyn, size_t name_len, const char *restrict name, @@ -3841,15 +3845,15 @@ mhd_dtbl_find_entry (const struct mhd_HpackDTblContext *restrict dyn, if (dtbl_is_empty (dyn)) return 0u; - if (mhd_COND_HARDLY_EVER (! mhd_DTBL_VALUE_FITS (name_len))) + if (mhd_COND_HARDLY_EVER (!mhd_DTBL_VALUE_FITS (name_len))) return 0u; - if (mhd_COND_HARDLY_EVER (! mhd_DTBL_VALUE_FITS (val_len))) + if (mhd_COND_HARDLY_EVER (!mhd_DTBL_VALUE_FITS (val_len))) return 0u; return dtbl_find_entry (dyn, - (dtbl_size_ft) name_len, + (dtbl_size_ft)name_len, name, - (dtbl_size_ft) val_len, + (dtbl_size_ft)val_len, val); } @@ -3867,7 +3871,7 @@ mhd_dtbl_find_entry (const struct mhd_HpackDTblContext *restrict dyn, * @return the HPACK index (> #mhd_HPACK_STBL_LAST_IDX) of the matching entry, * or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (3,2) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (3, 2) dtbl_idx_t mhd_dtbl_find_name (const struct mhd_HpackDTblContext *restrict dyn, size_t name_len, const char *restrict name) @@ -3875,11 +3879,11 @@ mhd_dtbl_find_name (const struct mhd_HpackDTblContext *restrict dyn, if (dtbl_is_empty (dyn)) return 0u; - if (mhd_COND_HARDLY_EVER (! mhd_DTBL_VALUE_FITS (name_len))) + if (mhd_COND_HARDLY_EVER (!mhd_DTBL_VALUE_FITS (name_len))) return 0u; return dtbl_find_name (dyn, - (dtbl_size_ft) name_len, + (dtbl_size_ft)name_len, name); } @@ -4007,7 +4011,7 @@ stbl_get_pos_from_hpack_idx (dtbl_idx_ft hpack_idx) { mhd_assert (0u != hpack_idx); mhd_assert (mhd_HPACK_STBL_LAST_IDX >= hpack_idx); - return (dtbl_idx_t) (hpack_idx - 1u); + return (dtbl_idx_t)(hpack_idx - 1u); } @@ -4025,7 +4029,7 @@ MHD_FN_CONST_ mhd_static_inline dtbl_idx_t stbl_get_hpack_idx_from_pos (dtbl_idx_ft loc_pos) { mhd_assert (mhd_HPACK_STBL_LAST_IDX > loc_pos); - return (dtbl_idx_t) (loc_pos + 1u); + return (dtbl_idx_t)(loc_pos + 1u); } @@ -4122,7 +4126,7 @@ mhd_stbl_get_entry (dtbl_idx_ft idx, * @return the HPACK index (<= #mhd_HPACK_STBL_LAST_IDX) of the matching * static entry, or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_IN_SIZE_ (4,3) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_IN_SIZE_ (4, 3) dtbl_idx_t mhd_stbl_find_entry_real (size_t name_len, const char *restrict name, size_t val_len, @@ -4203,10 +4207,10 @@ mhd_stbl_find_entry_real (size_t name_len, entry->name.cstr, name_len)) { /* 'name' matches */ - if ((0u == val_len) || - (0 == memcmp (val, - entry->value.cstr, - val_len))) + if ((0u == val_len) + || (0 == memcmp (val, + entry->value.cstr, + val_len))) { /* 'value' matches (empty or identical) */ /* Full match found, return the HPACK index */ return stbl_get_hpack_idx_from_pos (i); @@ -4234,7 +4238,7 @@ mhd_stbl_find_entry_real (size_t name_len, * @return the HPACK index (<= #mhd_HPACK_STBL_LAST_IDX) of the matching * static entry, or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (2,1) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (2, 1) dtbl_idx_t mhd_stbl_find_name_real (size_t name_len, const char *restrict name) { @@ -4326,7 +4330,7 @@ mhd_htbl_get_entry (const struct mhd_HpackDTblContext *restrict dyn, * @return the HPACK index of the matching entry (either static or dynamic), * or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) dtbl_idx_t mhd_htbl_find_entry_real (const struct mhd_HpackDTblContext *restrict dyn, size_t name_len, const char *restrict name, @@ -4353,7 +4357,7 @@ mhd_htbl_find_entry_real (const struct mhd_HpackDTblContext *restrict dyn, val_len, val); - return (dtbl_idx_t) idx; + return (dtbl_idx_t)idx; } @@ -4371,7 +4375,7 @@ mhd_htbl_find_entry_real (const struct mhd_HpackDTblContext *restrict dyn, * @return the HPACK index of the matching entry (either static or dynamic), * or 0 if not found */ -static MHD_FN_PAR_IN_SIZE_ (3,2) dtbl_idx_t +static MHD_FN_PAR_IN_SIZE_ (3, 2) dtbl_idx_t mhd_htbl_find_name_real (const struct mhd_HpackDTblContext *restrict dyn, size_t name_len, const char *restrict name) @@ -4392,7 +4396,7 @@ mhd_htbl_find_name_real (const struct mhd_HpackDTblContext *restrict dyn, name_len, name); - return (dtbl_idx_t) idx; + return (dtbl_idx_t)idx; } @@ -4403,7 +4407,7 @@ mhd_htbl_find_name_real (const struct mhd_HpackDTblContext *restrict dyn, */ mhd_constexpr size_t mhd_hpack_def_dyn_table_size = 4096u; -#if ! defined(mhd_HPACK_TESTING_TABLES_ONLY) || ! defined(MHD_UNIT_TESTING) +#if !defined(mhd_HPACK_TESTING_TABLES_ONLY) || !defined(MHD_UNIT_TESTING) /** * Exactly eight bits all set (to one). @@ -4447,7 +4451,7 @@ enum MHD_FIXED_ENUM_ mhd_HpackGetNumResult * error code otherwise */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_OUT_ (5) enum mhd_HpackGetNumResult hpack_dec_number (uint_fast8_t first_byte_prefix_bits, const size_t buf_size, @@ -4457,7 +4461,7 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { /** The maximum value of the first byte. Also the mask for the first byte. */ const uint_fast8_t first_byte_val_max = - (uint_fast8_t) (b8ones >> first_byte_prefix_bits); + (uint_fast8_t)(b8ones >> first_byte_prefix_bits); uint_fast8_t first_byte; uint_fast32_t dec_num; uint_fast8_t i; @@ -4468,13 +4472,13 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, first_byte = (buf[0] & first_byte_val_max); if (first_byte_val_max != first_byte) { - *num_out = (uint_fast32_t) first_byte; + *num_out = (uint_fast32_t)first_byte; *bytes_decoded = 1u; return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } dec_num = first_byte; -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE /* Unrolled loop */ i = 1u; if (buf_size == i) @@ -4483,12 +4487,12 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { const uint_fast8_t cur_byte = buf[i]; const bool is_final = (0u == (cur_byte & 0x80u)); - const uint_fast8_t byte_val = (uint_fast8_t) (cur_byte & 0x7Fu); - dec_num += (uint_fast32_t) (((uint_fast32_t) byte_val) << (7u * (i - 1u))); + const uint_fast8_t byte_val = (uint_fast8_t)(cur_byte & 0x7Fu); + dec_num += (uint_fast32_t)(((uint_fast32_t)byte_val) << (7u * (i - 1u))); if (is_final) { *num_out = dec_num; - *bytes_decoded = (size_t) (i + 1u); + *bytes_decoded = (size_t)(i + 1u); return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } } @@ -4500,12 +4504,12 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { const uint_fast8_t cur_byte = buf[i]; const bool is_final = (0u == (cur_byte & 0x80u)); - const uint_fast8_t byte_val = (uint_fast8_t) (cur_byte & 0x7Fu); - dec_num += (uint_fast32_t) (((uint_fast32_t) byte_val) << (7u * (i - 1u))); + const uint_fast8_t byte_val = (uint_fast8_t)(cur_byte & 0x7Fu); + dec_num += (uint_fast32_t)(((uint_fast32_t)byte_val) << (7u * (i - 1u))); if (is_final) { *num_out = dec_num; - *bytes_decoded = (size_t) (i + 1u); + *bytes_decoded = (size_t)(i + 1u); return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } } @@ -4517,12 +4521,12 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { const uint_fast8_t cur_byte = buf[i]; const bool is_final = (0u == (cur_byte & 0x80u)); - const uint_fast8_t byte_val = (uint_fast8_t) (cur_byte & 0x7Fu); - dec_num += (uint_fast32_t) (((uint_fast32_t) byte_val) << (7u * (i - 1u))); + const uint_fast8_t byte_val = (uint_fast8_t)(cur_byte & 0x7Fu); + dec_num += (uint_fast32_t)(((uint_fast32_t)byte_val) << (7u * (i - 1u))); if (is_final) { *num_out = dec_num; - *bytes_decoded = (size_t) (i + 1u); + *bytes_decoded = (size_t)(i + 1u); return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } } @@ -4534,18 +4538,18 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { const uint_fast8_t cur_byte = buf[i]; const bool is_final = (0u == (cur_byte & 0x80u)); - const uint_fast8_t byte_val = (uint_fast8_t) (cur_byte & 0x7Fu); - dec_num += (uint_fast32_t) (((uint_fast32_t) byte_val) << (7u * (i - 1u))); + const uint_fast8_t byte_val = (uint_fast8_t)(cur_byte & 0x7Fu); + dec_num += (uint_fast32_t)(((uint_fast32_t)byte_val) << (7u * (i - 1u))); if (is_final) { *num_out = dec_num; - *bytes_decoded = (size_t) (i + 1u); + *bytes_decoded = (size_t)(i + 1u); return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } } i = 5u; -#else /* MHD_FAVOR_SMALL_CODE */ +# else /* MHD_FAVOR_SMALL_CODE */ /* First four bytes cannot overflow the output */ for (i = 1u; 4u >= i; ++i) { @@ -4555,18 +4559,18 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { const uint_fast8_t cur_byte = buf[i]; const bool is_final = (0u == (cur_byte & 0x80u)); - const uint_fast8_t byte_val = (uint_fast8_t) (cur_byte & 0x7Fu); - dec_num += (uint_fast32_t) (((uint_fast32_t) byte_val) << (7u * (i - 1u))) + const uint_fast8_t byte_val = (uint_fast8_t)(cur_byte & 0x7Fu); + dec_num += (uint_fast32_t)(((uint_fast32_t)byte_val) << (7u * (i - 1u))) ; if (is_final) { *num_out = dec_num; - *bytes_decoded = (size_t) (i + 1u); + *bytes_decoded = (size_t)(i + 1u); return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } } } -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ mhd_assert (0u == (dec_num >> 29u)); mhd_assert (5u == i); @@ -4576,9 +4580,9 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { /* Handle the fifth byte with overflow checks */ const uint_fast8_t cur_byte = buf[i]; const bool is_final = (0u == (cur_byte & 0x80u)); - const uint_fast8_t byte_val = (uint_fast8_t) (cur_byte & 0x7Fu); + const uint_fast8_t byte_val = (uint_fast8_t)(cur_byte & 0x7Fu); const uint_fast32_t add_val = - (uint_fast32_t) (((uint_fast32_t) byte_val) << (7u * (i - 1u))); + (uint_fast32_t)(((uint_fast32_t)byte_val) << (7u * (i - 1u))); if (byte_val != ((add_val & 0xFFFFFFFFu) >> (7u * (i - 1u)))) return mhd_HPACK_GET_NUM_RES_TOO_LARGE; /* Failure exit point */ dec_num += add_val; @@ -4587,7 +4591,7 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, else if (is_final) { *num_out = dec_num; - *bytes_decoded = (size_t) (i + 1u); + *bytes_decoded = (size_t)(i + 1u); return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } } @@ -4601,13 +4605,13 @@ hpack_dec_number (uint_fast8_t first_byte_prefix_bits, { const uint_fast8_t cur_byte = buf[i]; const bool is_final = (0u == (cur_byte & 0x80u)); - const uint_fast8_t byte_val = (uint_fast8_t) (cur_byte & 0x7Fu); + const uint_fast8_t byte_val = (uint_fast8_t)(cur_byte & 0x7Fu); if (0u != byte_val) return mhd_HPACK_GET_NUM_RES_TOO_LARGE; /* Failure exit point */ else if (is_final) { *num_out = dec_num; - *bytes_decoded = (size_t) (i + 1u); + *bytes_decoded = (size_t)(i + 1u); return mhd_HPACK_GET_NUM_RES_NO_ERROR; /* Success exit point */ } } @@ -4677,8 +4681,8 @@ dec_check_resize_pending (struct mhd_HpackDecContext *restrict hk_dec) if (mhd_dtbl_get_table_max_size (hk_dec->dyn) != hk_dec->last_remote_dyn_size) { /* Resize must be performed before processing any headers data */ - if (! mhd_dtbl_resize (&(hk_dec->dyn), - hk_dec->last_remote_dyn_size)) + if (!mhd_dtbl_resize (&(hk_dec->dyn), + hk_dec->last_remote_dyn_size)) return mhd_HPACK_DEC_RES_ALLOC_ERR; /* Failure exit point */ } @@ -4703,7 +4707,7 @@ dec_check_resize_pending (struct mhd_HpackDecContext *restrict hk_dec) * @return #mhd_HPACK_DEC_RES_NEW_FIELD on success or an error code */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_SIZE_ (5,4) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_SIZE_ (5, 4) MHD_FN_PAR_OUT_ (6) MHD_FN_PAR_OUT_ (7) MHD_FN_PAR_OUT_ (8) enum mhd_HpackDecResult hpack_dec_field_indexed (struct mhd_HpackDecContext *restrict hk_dec, @@ -4756,10 +4760,10 @@ hpack_dec_field_indexed (struct mhd_HpackDecContext *restrict hk_dec, if (mhd_COND_HARDLY_EVER (mhd_HPACK_MAX_POSSIBLE_IDX < field_idx)) return mhd_HPACK_DEC_RES_HPACK_BAD_IDX; /* Failure exit point */ - if (! mhd_htbl_get_entry (hk_dec->dyn, - (dtbl_idx_ft) field_idx, - &idx_name, - &idx_value)) + if (!mhd_htbl_get_entry (hk_dec->dyn, + (dtbl_idx_ft)field_idx, + &idx_name, + &idx_value)) return mhd_HPACK_DEC_RES_HPACK_BAD_IDX; /* Failure exit point */ /* No math overflow check is needed here as both strings are already stored @@ -4800,7 +4804,7 @@ hpack_dec_field_indexed (struct mhd_HpackDecContext *restrict hk_dec, * error code otherwise */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (4,3) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_SIZE_ (4, 3) MHD_FN_PAR_OUT_ (5) MHD_FN_PAR_OUT_ (6) enum mhd_HpackDecResult hpack_dec_string_literal (size_t enc_data_size, const uint8_t *restrict enc_data, @@ -4852,7 +4856,7 @@ hpack_dec_string_literal (size_t enc_data_size, /* mhd_h2_huffman_decode() will check whether the output buffer is large enough. */ - dec_str_len = mhd_h2_huffman_decode ((size_t) enc_str_len, + dec_str_len = mhd_h2_huffman_decode ((size_t)enc_str_len, enc_data + enc_num_len, out_buff_size - 1u, /* leave one byte for zero-termination */ out_buff, @@ -4879,7 +4883,7 @@ hpack_dec_string_literal (size_t enc_data_size, if (out_buff_size <= enc_str_len) /* leave one byte for zero-termination */ return mhd_HPACK_DEC_RES_BUFFER_TOO_SMALL; /* Failure exit point */ - dec_str_len = (size_t) enc_str_len; + dec_str_len = (size_t)enc_str_len; memcpy (out_buff, enc_data + enc_num_len, dec_str_len); @@ -4889,7 +4893,7 @@ hpack_dec_string_literal (size_t enc_data_size, out_buff[dec_str_len] = '\0'; /* Zero-terminate the result */ *out_len = dec_str_len; - *bytes_decoded = enc_num_len + (size_t) enc_str_len; + *bytes_decoded = enc_num_len + (size_t)enc_str_len; return mhd_HPACK_DEC_RES_NEW_FIELD; /* Return any non-error code */ } @@ -4914,7 +4918,7 @@ hpack_dec_string_literal (size_t enc_data_size, * error code otherwise */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_SIZE_ (6,5) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_SIZE_ (6, 5) MHD_FN_PAR_OUT_ (7) MHD_FN_PAR_OUT_ (8) MHD_FN_PAR_OUT_ (9) enum mhd_HpackDecResult hpack_dec_field_literal (struct mhd_HpackDecContext *restrict hk_dec, @@ -4933,10 +4937,10 @@ hpack_dec_field_literal (struct mhd_HpackDecContext *restrict hk_dec, size_t pos_incr; uint_fast32_t name_idx; - mhd_assert (with_indexing || \ - (1u == (enc_data[0] >> 4u)) || (0u == (enc_data[0] >> 4u))); - mhd_assert (! with_indexing || \ - (1u == (enc_data[0] >> 6u))); + mhd_assert (with_indexing \ + || (1u == (enc_data[0] >> 4u)) || (0u == (enc_data[0] >> 4u))); + mhd_assert (!with_indexing \ + || (1u == (enc_data[0] >> 6u))); mhd_assert (0u != enc_data_size); mhd_assert (2u <= out_buff_size); @@ -4947,14 +4951,14 @@ hpack_dec_field_literal (struct mhd_HpackDecContext *restrict hk_dec, return res; pos = 0u; -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE if (0u == (enc_data[0] & (b8ones >> prfx_bits))) { name_idx = 0u; /* Shortcut for frequent case */ pos_incr = 1u; } else -#endif /* ! MHD_FAVOR_SMALL_CODE */ +# endif /* ! MHD_FAVOR_SMALL_CODE */ if (1) { enum mhd_HpackGetNumResult dec_res; @@ -4979,9 +4983,9 @@ hpack_dec_field_literal (struct mhd_HpackDecContext *restrict hk_dec, } mhd_assert (0u != pos_incr); -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE mhd_assert (0u != name_idx); -#endif /* ! MHD_FAVOR_SMALL_CODE */ +# endif /* ! MHD_FAVOR_SMALL_CODE */ } pos += pos_incr; @@ -5012,10 +5016,10 @@ hpack_dec_field_literal (struct mhd_HpackDecContext *restrict hk_dec, if (mhd_COND_HARDLY_EVER (mhd_HPACK_MAX_POSSIBLE_IDX < name_idx)) return mhd_HPACK_DEC_RES_HPACK_BAD_IDX; /* Failure exit point */ - if (! mhd_htbl_get_entry (hk_dec->dyn, - (dtbl_idx_ft) name_idx, - &idx_name, - &idx_value)) + if (!mhd_htbl_get_entry (hk_dec->dyn, + (dtbl_idx_ft)name_idx, + &idx_name, + &idx_value)) return mhd_HPACK_DEC_RES_HPACK_BAD_IDX; /* Failure exit point */ if (idx_name.size >= (out_buff_size - 1u)) @@ -5069,7 +5073,7 @@ hpack_dec_field_literal (struct mhd_HpackDecContext *restrict hk_dec, * @return #mhd_HPACK_DEC_RES_NO_NEW_FIELD on success, * error code otherwise */ -static MHD_FN_PAR_IN_SIZE_ (3,2) +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_HpackDecResult dec_update_dyn_size (struct mhd_HpackDecContext *restrict hk_dec, const size_t enc_data_size, @@ -5080,8 +5084,8 @@ dec_update_dyn_size (struct mhd_HpackDecContext *restrict hk_dec, size_t used_bytes; enum mhd_HpackGetNumResult dec_res; - mhd_assert ((1u == (enc_data[0] >> 5u)) && \ - "the first byte must be the dynamic table update signal"); + mhd_assert ((1u == (enc_data[0] >> 5u)) \ + && "the first byte must be the dynamic table update signal"); dec_res = hpack_dec_number (3u, enc_data_size, enc_data, @@ -5111,9 +5115,9 @@ dec_update_dyn_size (struct mhd_HpackDecContext *restrict hk_dec, /* Only evict here, no resize yet to avoid repetitive realloc() calls if remote sends multiple table size updates in a row. */ mhd_dtbl_evict_to_size (hk_dec->dyn, - (size_t) new_dyn_size); + (size_t)new_dyn_size); - hk_dec->last_remote_dyn_size = (size_t) new_dyn_size; + hk_dec->last_remote_dyn_size = (size_t)new_dyn_size; *bytes_decoded = used_bytes; return mhd_HPACK_DEC_RES_NO_NEW_FIELD; /* Success exit point */ @@ -5235,7 +5239,7 @@ hpack_number_len (uint_fast8_t prefix_bits, uint_fast32_t number) { const uint_fast8_t first_byte_val_max = - (uint_fast8_t) (b8ones >> prefix_bits); + (uint_fast8_t)(b8ones >> prefix_bits); uint_least32_t val_for_next_bytes; mhd_assert (0u != prefix_bits); @@ -5244,7 +5248,7 @@ hpack_number_len (uint_fast8_t prefix_bits, if (first_byte_val_max > number) /* the number must be strictly less than */ return 1u; - val_for_next_bytes = (uint_least32_t) (number - first_byte_val_max); + val_for_next_bytes = (uint_least32_t)(number - first_byte_val_max); if (0 == val_for_next_bytes) return 2u; return (uint_fast8_t) \ @@ -5271,7 +5275,7 @@ hpack_number_len (uint_fast8_t prefix_bits, * @return the number of bytes written on success; * zero if output buffer is too small to fit the number encoded */ -static MHD_FN_PAR_OUT_SIZE_ (5,4) size_t +static MHD_FN_PAR_OUT_SIZE_ (5, 4) size_t hpack_put_number_to_buf (uint_fast8_t first_byte_prefix, uint_fast8_t first_byte_prefix_bits, uint_fast32_t number, @@ -5279,7 +5283,7 @@ hpack_put_number_to_buf (uint_fast8_t first_byte_prefix, uint8_t buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)]) { const uint_fast8_t first_byte_val_max = - (uint_fast8_t) (b8ones >> first_byte_prefix_bits); + (uint_fast8_t)(b8ones >> first_byte_prefix_bits); uint_fast32_t number_left; uint_fast8_t i; @@ -5292,14 +5296,14 @@ hpack_put_number_to_buf (uint_fast8_t first_byte_prefix, if (first_byte_val_max > number) /* the number must be strictly less than */ { - buf[0] = (uint8_t) (first_byte_prefix | (uint8_t) number); + buf[0] = (uint8_t)(first_byte_prefix | (uint8_t)number); return 1u; } - buf[0] = (uint8_t) (first_byte_prefix | first_byte_val_max); + buf[0] = (uint8_t)(first_byte_prefix | first_byte_val_max); number_left = number - first_byte_val_max; for (i = 1u; mhd_COND_PREDOMINANTLY (i < buf_size); ++i) { - const uint8_t cur_byte = (uint8_t) (number_left & 0x7Fu); + const uint8_t cur_byte = (uint8_t)(number_left & 0x7Fu); number_left >>= 7u; if (0 == number_left) { @@ -5307,7 +5311,7 @@ hpack_put_number_to_buf (uint_fast8_t first_byte_prefix, buf[i] = cur_byte; return i + 1u; /* Success exit point */ } - buf[i] = (uint8_t) (cur_byte | 0x80u); + buf[i] = (uint8_t)(cur_byte | 0x80u); mhd_assert (6u > i); } return 0u; /* Not enough space */ @@ -5370,14 +5374,14 @@ mhd_hpack_enc_dyn_resize (struct mhd_HpackEncContext *hk_enc) if (mhd_dtbl_get_table_max_size (hk_enc->dyn) != hk_enc->dyn_size_new) { -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE /* This is just an optimisation to simplify eviction later */ mhd_dtbl_evict_to_size (hk_enc->dyn, hk_enc->dyn_size_smallest); -#endif /* ! MHD_FAVOR_SMALL_CODE */ +# endif /* ! MHD_FAVOR_SMALL_CODE */ - if (mhd_COND_HARDLY_EVER (! mhd_dtbl_resize (&(hk_enc->dyn), \ - hk_enc->dyn_size_new))) + if (mhd_COND_HARDLY_EVER (!mhd_dtbl_resize (&(hk_enc->dyn), \ + hk_enc->dyn_size_new))) return false; mhd_assert (mhd_dtbl_get_table_max_size (hk_enc->dyn) == \ @@ -5401,13 +5405,13 @@ mhd_hpack_enc_dyn_resize (struct mhd_HpackEncContext *hk_enc) * 'false' if the output buffer is too small */ static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4) bool +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) bool hpack_enc_field_indexed (dtbl_idx_ft idx, const size_t out_buff_size, uint8_t *restrict out_buff, size_t *restrict bytes_encoded) { - mhd_constexpr uint_fast8_t field_indexed_prfx = (uint_fast8_t) (1u << 7u); + mhd_constexpr uint_fast8_t field_indexed_prfx = (uint_fast8_t)(1u << 7u); mhd_constexpr uint_fast8_t field_indexed_prfx_bits = 1u; size_t pos; @@ -5469,7 +5473,7 @@ enum MHD_FIXED_ENUM_ mhd_HpackEncLitIndexingType */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) -MHD_FN_PAR_OUT_SIZE_ (4,3) MHD_FN_PAR_OUT_ (5) bool +MHD_FN_PAR_OUT_SIZE_ (4, 3) MHD_FN_PAR_OUT_ (5) bool hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, bool huffman_allowed, const size_t out_buff_size, @@ -5477,9 +5481,9 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, size_t *restrict bytes_encoded) { /** The prefix for Huffman-encoded string */ - mhd_constexpr uint8_t huff_on_prfx = (uint8_t) (1u << 7u); + mhd_constexpr uint8_t huff_on_prfx = (uint8_t)(1u << 7u); /** The prefix for literal string without Huffman encoding */ - mhd_constexpr uint8_t huff_off_prfx = (uint8_t) (0u << 7u); + mhd_constexpr uint8_t huff_off_prfx = (uint8_t)(0u << 7u); mhd_constexpr uint8_t huff_prfx_bits = 1u; size_t enc_size; size_t enc_size_enc_len; @@ -5504,16 +5508,16 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, bool is_limited_by_buff_size; est_enc_size = - mhd_h2_huffman_est_avg_size ((uint_fast32_t) str_data->size); + mhd_h2_huffman_est_avg_size ((uint_fast32_t)str_data->size); est_enc_size_enc_len = hpack_number_len (huff_prfx_bits, est_enc_size); - if ((out_buff_size <= est_enc_size_enc_len) || - ((out_buff_size - est_enc_size_enc_len) < est_enc_size)) + if ((out_buff_size <= est_enc_size_enc_len) + || ((out_buff_size - est_enc_size_enc_len) < est_enc_size)) { /* Probably the buffer is not large enough to encode the string */ /* Try as if the string were compressible to a minimal size */ est_enc_size = - mhd_h2_huffman_est_min_size ((uint_fast32_t) str_data->size); + mhd_h2_huffman_est_min_size ((uint_fast32_t)str_data->size); est_enc_size_enc_len = hpack_number_len (huff_prfx_bits, est_enc_size); if (out_buff_size < (est_enc_size_enc_len + est_enc_size)) @@ -5527,8 +5531,8 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, mhd_assert (out_buff_size > est_enc_size_enc_len); mhd_assert ((out_buff_size - est_enc_size_enc_len) \ >= est_enc_size); - mhd_assert (is_limited_by_buff_size || \ - ((out_buff_size - est_enc_size_enc_len) >= str_data->size)); + mhd_assert (is_limited_by_buff_size \ + || ((out_buff_size - est_enc_size_enc_len) >= str_data->size)); /* Limit the size of the buffer for the encoded string to the size of the original (not encoded) string or the size of the buffer (whatever @@ -5552,7 +5556,7 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, enc_size_enc_len = hpack_put_number_to_buf (huff_on_prfx, huff_prfx_bits, - (uint_fast32_t) enc_size, + (uint_fast32_t)enc_size, est_enc_size_enc_len, out_buff); if (mhd_COND_ALMOST_NEVER (0u == enc_size_enc_len)) @@ -5563,7 +5567,7 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, mhd_assert (est_enc_size < enc_size); calc_enc_size_enc_len = hpack_number_len (huff_prfx_bits, - (uint_fast32_t) enc_size); + (uint_fast32_t)enc_size); if ((out_buff_size - enc_size) < calc_enc_size_enc_len) return false; /* The output buffer is not large enough */ @@ -5574,7 +5578,7 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, enc_size_enc_len = hpack_put_number_to_buf (huff_on_prfx, huff_prfx_bits, - (uint_fast32_t) enc_size, + (uint_fast32_t)enc_size, calc_enc_size_enc_len, out_buff); mhd_assert (calc_enc_size_enc_len == enc_size_enc_len); @@ -5610,7 +5614,7 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, enc_size_enc_len = hpack_put_number_to_buf (huff_off_prfx, huff_prfx_bits, - (uint_fast32_t) enc_size, + (uint_fast32_t)enc_size, out_buff_size - enc_size, out_buff); @@ -5663,7 +5667,7 @@ hpack_enc_string_literal (const struct mhd_BufferConst *restrict str_data, static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_IN_ (2) MHD_FN_PAR_IN_ (4) -MHD_FN_PAR_OUT_SIZE_ (10,9) MHD_FN_PAR_OUT_ (11) bool +MHD_FN_PAR_OUT_SIZE_ (10, 9) MHD_FN_PAR_OUT_ (11) bool hpack_enc_field_literal (struct mhd_HpackEncContext *restrict hk_enc, const struct mhd_BufferConst *restrict name, dtbl_idx_ft name_idx, @@ -5676,11 +5680,11 @@ hpack_enc_field_literal (struct mhd_HpackEncContext *restrict hk_enc, uint8_t *restrict out_buff, size_t *restrict bytes_encoded) { - mhd_constexpr uint_fast8_t field_indexing_prfx = (uint_fast8_t) (1u << 6u); + mhd_constexpr uint_fast8_t field_indexing_prfx = (uint_fast8_t)(1u << 6u); mhd_constexpr uint_fast8_t field_indexing_prfx_bits = 2u; - mhd_constexpr uint_fast8_t field_not_idxng_prfx = (uint_fast8_t) (0u << 4u); + mhd_constexpr uint_fast8_t field_not_idxng_prfx = (uint_fast8_t)(0u << 4u); mhd_constexpr uint_fast8_t field_not_idxng_prfx_bits = 4u; - mhd_constexpr uint_fast8_t field_never_idxng_prfx = (uint_fast8_t) (1u << 4u); + mhd_constexpr uint_fast8_t field_never_idxng_prfx = (uint_fast8_t)(1u << 4u); mhd_constexpr uint_fast8_t field_never_idxng_prfx_bits = 4u; struct mhd_HpackDTblContext const *restrict dyn = hk_enc->dyn; uint_fast8_t first_byte_prefix; @@ -5728,10 +5732,10 @@ hpack_enc_field_literal (struct mhd_HpackEncContext *restrict hk_enc, } else { - mhd_assert (name_idx_stat_allowed || \ - (mhd_HPACK_STBL_LAST_IDX < name_idx)); - mhd_assert (name_idx_dyn_allowed || \ - (mhd_HPACK_STBL_LAST_IDX >= name_idx)); + mhd_assert (name_idx_stat_allowed \ + || (mhd_HPACK_STBL_LAST_IDX < name_idx)); + mhd_assert (name_idx_dyn_allowed \ + || (mhd_HPACK_STBL_LAST_IDX >= name_idx)); } pos = 0u; @@ -5754,15 +5758,15 @@ hpack_enc_field_literal (struct mhd_HpackEncContext *restrict hk_enc, /* Add name literally */ /* Use 'zero' index to indicate literal name */ - out_buff[pos++] = (uint8_t) first_byte_prefix; + out_buff[pos++] = (uint8_t)first_byte_prefix; /* The buffer has at least one byte (or more) available; the next call will fail if only one byte is available. */ - if (! hpack_enc_string_literal (name, - huffman_allowed, - out_buff_size - pos - 1u, /* Reserve one byte for the field value */ - out_buff + pos, - &pos_incr)) + if (!hpack_enc_string_literal (name, + huffman_allowed, + out_buff_size - pos - 1u, /* Reserve one byte for the field value */ + out_buff + pos, + &pos_incr)) return false; /* Not enough space */ pos += pos_incr; @@ -5773,11 +5777,11 @@ hpack_enc_field_literal (struct mhd_HpackEncContext *restrict hk_enc, /* Add value literally */ - if (! hpack_enc_string_literal (value, - huffman_allowed, - out_buff_size - pos, - out_buff + pos, - &pos_incr)) + if (!hpack_enc_string_literal (value, + huffman_allowed, + out_buff_size - pos, + out_buff + pos, + &pos_incr)) return false; /* Not enough space */ pos += pos_incr; @@ -5832,7 +5836,7 @@ enum MHD_FIXED_ENUM_ mhd_HpackEncResultInternal static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_IN_ (2) MHD_FN_PAR_IN_ (3) -MHD_FN_PAR_OUT_SIZE_ (6,5) MHD_FN_PAR_OUT_ (7) enum mhd_HpackEncResultInternal +MHD_FN_PAR_OUT_SIZE_ (6, 5) MHD_FN_PAR_OUT_ (7) enum mhd_HpackEncResultInternal hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, const struct mhd_BufferConst *restrict name, const struct mhd_BufferConst *restrict value, @@ -5870,10 +5874,10 @@ hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, if (0u != field_idx) { - if (! hpack_enc_field_indexed (field_idx, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_indexed (field_idx, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -5894,17 +5898,17 @@ hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, (mhd_HPACK_ENC_POL_NEVER_W_NAME_IDX_STATIC > enc_pol); const bool huffman_allowed = (mhd_HPACK_ENC_POL_NEVER_W_NAME_LIT_NO_HUFFMAN > enc_pol); - if (! hpack_enc_field_literal (hk_enc, - name, - 0u, - value, - mhd_HPACK_ENC_LIT_IDX_TYPE_NEVER_INDEXING, - name_idx_stat_allowed, - name_idx_dyn_allowed, - huffman_allowed, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_literal (hk_enc, + name, + 0u, + value, + mhd_HPACK_ENC_LIT_IDX_TYPE_NEVER_INDEXING, + name_idx_stat_allowed, + name_idx_dyn_allowed, + huffman_allowed, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -5915,17 +5919,17 @@ hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, /* Adding to the tables is not allowed */ mhd_assert (mhd_HPACK_ENC_POL_NOT_INDEXED >= enc_pol); - if (! hpack_enc_field_literal (hk_enc, - name, - 0u, - value, - mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, - true, - true, - true, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_literal (hk_enc, + name, + 0u, + value, + mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, + true, + true, + true, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -5934,27 +5938,27 @@ hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, if (mhd_HPACK_ENC_POL_ALWAYS_IF_FIT >= enc_pol) { bool add_to_idx; - if ((mhd_HPACK_ENC_POL_FORCED == enc_pol) || - (mhd_HPACK_ENC_POL_FORCED_NEW_IDX == enc_pol)) + if ((mhd_HPACK_ENC_POL_FORCED == enc_pol) + || (mhd_HPACK_ENC_POL_FORCED_NEW_IDX == enc_pol)) add_to_idx = true; else add_to_idx = mhd_dtbl_check_entry_fit (hk_enc->dyn, name->size, value->size); - if (! hpack_enc_field_literal (hk_enc, - name, - 0u, - value, - add_to_idx ? - mhd_HPACK_ENC_LIT_IDX_TYPE_INDEXING : - mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, - true, - true, - true, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_literal (hk_enc, + name, + 0u, + value, + add_to_idx ? + mhd_HPACK_ENC_LIT_IDX_TYPE_INDEXING : + mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, + true, + true, + true, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return add_to_idx ? @@ -6051,34 +6055,34 @@ hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, if (mhd_T_IS_YES (add_to_idx)) { - if (! hpack_enc_field_literal (hk_enc, - name, - 0u, - value, - mhd_HPACK_ENC_LIT_IDX_TYPE_INDEXING, - true, - true, - true, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_literal (hk_enc, + name, + 0u, + value, + mhd_HPACK_ENC_LIT_IDX_TYPE_INDEXING, + true, + true, + true, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_ADD_TO_DYN; } } - if (! hpack_enc_field_literal (hk_enc, - name, - 0u, - value, - mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, - true, - true, - true, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_literal (hk_enc, + name, + 0u, + value, + mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, + true, + true, + true, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -6102,7 +6106,7 @@ hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, * @return 'true' on success; * 'false' if the output buffer is too small */ -static MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4) bool +static MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) bool hpack_enc_check_dyn_size_update ( struct mhd_HpackEncContext *restrict hk_enc, size_t out_buff_size, @@ -6110,7 +6114,7 @@ hpack_enc_check_dyn_size_update ( size_t *restrict bytes_encoded) { /** The prefix for Dynamic Table Size Update message */ - mhd_constexpr uint_fast8_t dyn_size_upd_msg_prfx = (uint_fast8_t) (1u << 5u); + mhd_constexpr uint_fast8_t dyn_size_upd_msg_prfx = (uint_fast8_t)(1u << 5u); mhd_constexpr uint_fast8_t dyn_size_upd_msg_prfx_bits = 3u; size_t pos; size_t pos_incr; @@ -6127,8 +6131,8 @@ hpack_enc_check_dyn_size_update ( mhd_dtbl_evict_to_size (dyn, hk_enc->dyn_size_smallest); - if ((hk_enc->dyn_size_smallest == hk_enc->dyn_size_peer) && - (hk_enc->dyn_size_new == hk_enc->dyn_size_peer)) + if ((hk_enc->dyn_size_smallest == hk_enc->dyn_size_peer) + && (hk_enc->dyn_size_new == hk_enc->dyn_size_peer)) { *bytes_encoded = 0u; return true; /* No resize signal needed */ @@ -6146,7 +6150,7 @@ hpack_enc_check_dyn_size_update ( pos_incr = hpack_put_number_to_buf (dyn_size_upd_msg_prfx, dyn_size_upd_msg_prfx_bits, - (uint_fast32_t) hk_enc->dyn_size_smallest, + (uint_fast32_t)hk_enc->dyn_size_smallest, out_buff_size, out_buff); @@ -6165,7 +6169,7 @@ hpack_enc_check_dyn_size_update ( pos_incr = hpack_put_number_to_buf (dyn_size_upd_msg_prfx, dyn_size_upd_msg_prfx_bits, - (uint_fast32_t) hk_enc->dyn_size_new, + (uint_fast32_t)hk_enc->dyn_size_new, out_buff_size - pos, out_buff + pos); @@ -6198,8 +6202,8 @@ hpack_enc_perform_dyn_size_update (struct mhd_HpackEncContext *restrict hk_enc) <= hk_enc->dyn_size_smallest); if (mhd_dtbl_get_table_max_size (hk_enc->dyn) != hk_enc->dyn_size_new) { - if (mhd_COND_HARDLY_EVER (! mhd_dtbl_resize (&(hk_enc->dyn), \ - hk_enc->dyn_size_new))) + if (mhd_COND_HARDLY_EVER (!mhd_dtbl_resize (&(hk_enc->dyn), \ + hk_enc->dyn_size_new))) return false; mhd_assert (mhd_dtbl_get_table_max_size (hk_enc->dyn) == \ @@ -6216,7 +6220,7 @@ hpack_enc_perform_dyn_size_update (struct mhd_HpackEncContext *restrict hk_enc) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_IN_ (2) MHD_FN_PAR_IN_ (3) -MHD_FN_PAR_OUT_SIZE_ (6,5) MHD_FN_PAR_OUT_ (7) enum mhd_HpackEncResult +MHD_FN_PAR_OUT_SIZE_ (6, 5) MHD_FN_PAR_OUT_ (7) enum mhd_HpackEncResult mhd_hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, const struct mhd_BufferConst *restrict name, const struct mhd_BufferConst *restrict value, @@ -6239,10 +6243,10 @@ mhd_hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, pos = 0u; /* Add Dynamic Table Size Update message if needed */ - if (! hpack_enc_check_dyn_size_update (hk_enc, - out_buff_size - 1u, /* Reserve one byte for minimal field size */ - out_buff, - &pos_incr)) + if (!hpack_enc_check_dyn_size_update (hk_enc, + out_buff_size - 1u, /* Reserve one byte for minimal field size */ + out_buff, + &pos_incr)) return mhd_HPACK_ENC_BUFFER_TOO_SMALL; pos += pos_incr; @@ -6263,7 +6267,7 @@ mhd_hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, pos += pos_incr; /* Finally resize the dynamic table (if resize is pending) */ - if (! hpack_enc_perform_dyn_size_update (hk_enc)) + if (!hpack_enc_perform_dyn_size_update (hk_enc)) return mhd_HPACK_ENC_RES_ALLOC_ERR; /* Add the field (if needed) only after dynamic table resizing (if any) */ @@ -6296,9 +6300,9 @@ status_to_str (uint_fast16_t code, mhd_assert (100u <= code); mhd_assert (699u >= code); - code_str[0] = (char) ('0' + (char) (uint8_t) ((code / 100u) % 10)); - code_str[1] = (char) ('0' + (char) (uint8_t) ((code / 10u) % 10)); - code_str[2] = (char) ('0' + (char) (uint8_t) ((code / 1u) % 10)); + code_str[0] = (char)('0' + (char)(uint8_t)((code / 100u) % 10)); + code_str[1] = (char)('0' + (char)(uint8_t)((code / 10u) % 10)); + code_str[2] = (char)('0' + (char)(uint8_t)((code / 1u) % 10)); } @@ -6333,7 +6337,7 @@ static const struct mhd_BufferConst pf_status_str = mhd_MSTR_INIT (":status"); static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_OUT_ (4) -MHD_FN_PAR_OUT_SIZE_ (6,5) MHD_FN_PAR_OUT_ (7) enum mhd_HpackEncResultInternal +MHD_FN_PAR_OUT_SIZE_ (6, 5) MHD_FN_PAR_OUT_ (7) enum mhd_HpackEncResultInternal hpack_enc_pf_status (struct mhd_HpackEncContext *restrict hk_enc, uint_fast16_t code, enum mhd_HpackEncPFieldStatusPolicy enc_pol, @@ -6409,10 +6413,10 @@ hpack_enc_pf_status (struct mhd_HpackEncContext *restrict hk_enc, if (0u != field_idx) { - if (! hpack_enc_field_indexed (field_idx, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_indexed (field_idx, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -6439,10 +6443,10 @@ hpack_enc_pf_status (struct mhd_HpackEncContext *restrict hk_enc, if (0u != field_idx) { - if (! hpack_enc_field_indexed (field_idx, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_indexed (field_idx, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -6461,18 +6465,18 @@ hpack_enc_pf_status (struct mhd_HpackEncContext *restrict hk_enc, (mhd_HPACK_ENC_PFS_POL_NEVER_W_NAME_IDX == enc_pol); const bool huffman_allowed = (mhd_HPACK_ENC_PFS_POL_NEVER_W_NAME_LIT_NO_HUFFMAN > enc_pol); - if (! hpack_enc_field_literal (hk_enc, - &pf_status_str, - name_idx_stat_allowed ? - pf_status_first_idx : 0u, - &code_val, - mhd_HPACK_ENC_LIT_IDX_TYPE_NEVER_INDEXING, - name_idx_stat_allowed, - false, - huffman_allowed, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_literal (hk_enc, + &pf_status_str, + name_idx_stat_allowed ? + pf_status_first_idx : 0u, + &code_val, + mhd_HPACK_ENC_LIT_IDX_TYPE_NEVER_INDEXING, + name_idx_stat_allowed, + false, + huffman_allowed, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -6483,17 +6487,17 @@ hpack_enc_pf_status (struct mhd_HpackEncContext *restrict hk_enc, /* Adding to the tables is not allowed */ mhd_assert (mhd_HPACK_ENC_PFS_POL_NOT_INDEXED >= enc_pol); - if (! hpack_enc_field_literal (hk_enc, - &pf_status_str, - pf_status_first_idx, - &code_val, - mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, - true, - false, - true, - out_buff_size, - out_buff, - bytes_encoded)) + if (!hpack_enc_field_literal (hk_enc, + &pf_status_str, + pf_status_first_idx, + &code_val, + mhd_HPACK_ENC_LIT_IDX_TYPE_NOT_INDEXING, + true, + false, + true, + out_buff_size, + out_buff, + bytes_encoded)) return mhd_ENC_RESULT_INT_NO_SPACE; return mhd_ENC_RESULT_INT_OK_NO_ADD_TO_DYN; @@ -6534,7 +6538,7 @@ hpack_enc_pf_status (struct mhd_HpackEncContext *restrict hk_enc, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) -MHD_FN_PAR_OUT_SIZE_ (5,4) MHD_FN_PAR_OUT_ (6) enum mhd_HpackEncResult +MHD_FN_PAR_OUT_SIZE_ (5, 4) MHD_FN_PAR_OUT_ (6) enum mhd_HpackEncResult mhd_hpack_enc_ph_status (struct mhd_HpackEncContext *restrict hk_enc, uint_fast16_t code, enum mhd_HpackEncPFieldStatusPolicy enc_pol, @@ -6556,10 +6560,10 @@ mhd_hpack_enc_ph_status (struct mhd_HpackEncContext *restrict hk_enc, pos = 0u; /* Add Dynamic Table Size Update message if needed */ - if (! hpack_enc_check_dyn_size_update (hk_enc, - out_buff_size - 1u, /* Reserve one byte for minimal field size */ - out_buff, - &pos_incr)) + if (!hpack_enc_check_dyn_size_update (hk_enc, + out_buff_size - 1u, /* Reserve one byte for minimal field size */ + out_buff, + &pos_incr)) return mhd_HPACK_ENC_BUFFER_TOO_SMALL; pos += pos_incr; @@ -6580,7 +6584,7 @@ mhd_hpack_enc_ph_status (struct mhd_HpackEncContext *restrict hk_enc, pos += pos_incr; /* Finally resize the dynamic table (if resize is pending) */ - if (! hpack_enc_perform_dyn_size_update (hk_enc)) + if (!hpack_enc_perform_dyn_size_update (hk_enc)) return mhd_HPACK_ENC_RES_ALLOC_ERR; /* Add the field (if needed) only after dynamic table resizing (if any) */ diff --git a/src/mhd2/h2/hpack/mhd_hpack_codec.h b/src/mhd2/h2/hpack/mhd_hpack_codec.h @@ -62,7 +62,7 @@ # endif #else /* mhd_HPACK_DTBL_BITS */ # if (mhd_HPACK_DTBL_BITS != 16) && (mhd_HPACK_DTBL_BITS != 32) -#error Unsupported mhd_HPACK_DTBL_BITS value +# error Unsupported mhd_HPACK_DTBL_BITS value # endif #endif /* mhd_HPACK_DTBL_BITS */ @@ -226,10 +226,10 @@ mhd_hpack_dec_data (struct mhd_HpackDecContext *restrict hk_dec, size_t *restrict name_len, size_t *restrict val_len, size_t *restrict bytes_decoded) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_(1) -MHD_FN_PAR_IN_SIZE_(3, 2) -MHD_FN_PAR_OUT_SIZE_(5, 4) -MHD_FN_PAR_OUT_(6) MHD_FN_PAR_OUT_(7) MHD_FN_PAR_OUT_ (8); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) +MHD_FN_PAR_IN_SIZE_ (3, 2) +MHD_FN_PAR_OUT_SIZE_ (5, 4) +MHD_FN_PAR_OUT_ (6) MHD_FN_PAR_OUT_ (7) MHD_FN_PAR_OUT_ (8); struct mhd_HpackEncContext; /* forward declaration */ @@ -480,9 +480,9 @@ mhd_hpack_enc_field (struct mhd_HpackEncContext *restrict hk_enc, const size_t out_buff_size, uint8_t *restrict out_buff, size_t *restrict bytes_encoded) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_(1) -MHD_FN_PAR_IN_(2) MHD_FN_PAR_IN_(3) -MHD_FN_PAR_OUT_SIZE_(6,5) MHD_FN_PAR_OUT_ (7); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) +MHD_FN_PAR_IN_ (2) MHD_FN_PAR_IN_ (3) +MHD_FN_PAR_OUT_SIZE_ (6, 5) MHD_FN_PAR_OUT_ (7); /** @@ -588,7 +588,7 @@ mhd_hpack_enc_ph_status (struct mhd_HpackEncContext *restrict hk_enc, const size_t out_buff_size, uint8_t *restrict out_buff, size_t *restrict bytes_encoded) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_(1) -MHD_FN_PAR_OUT_SIZE_(5,4) MHD_FN_PAR_OUT_ (6); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) +MHD_FN_PAR_OUT_SIZE_ (5, 4) MHD_FN_PAR_OUT_ (6); #endif /* ! MHD_HPACK_CODEC_H */ diff --git a/src/mhd2/http_method.h b/src/mhd2/http_method.h @@ -115,7 +115,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_Method }; -#define MHD_HTTP_METHOD_DEFINED 1 +# define MHD_HTTP_METHOD_DEFINED 1 #endif /* ! MHD_HTTP_METHOD_DEFINED */ /** diff --git a/src/mhd2/http_prot_ver.h b/src/mhd2/http_prot_ver.h @@ -72,7 +72,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_HTTP_ProtocolVersion }; -#define MHD_HTTP_PROTOCOL_VER_DEFINED 1 +# define MHD_HTTP_PROTOCOL_VER_DEFINED 1 #endif /* ! MHD_HTTP_PROTOCOL_VER_DEFINED */ /** diff --git a/src/mhd2/http_status_str.c b/src/mhd2/http_status_str.c @@ -199,7 +199,7 @@ MHD_EXTERN_ MHD_FN_CONST_ const struct MHD_String * MHD_HTTP_status_code_to_string (enum MHD_HTTP_StatusCode code) { const struct MHD_String *res; - const unsigned int code_i = (unsigned int) code; + const unsigned int code_i = (unsigned int)code; if (100 > code_i) return NULL; if (600 < code) @@ -220,7 +220,7 @@ mhd_HTTP_status_code_to_string_int (uint_fast16_t code) mhd_MSTR_INIT ("Nonstandard Status"); const struct MHD_String *res; - res = MHD_HTTP_status_code_to_string ((enum MHD_HTTP_StatusCode) code); + res = MHD_HTTP_status_code_to_string ((enum MHD_HTTP_StatusCode)code); if (NULL != res) return res; diff --git a/src/mhd2/lib_get_info.c b/src/mhd2/lib_get_info.c @@ -117,10 +117,10 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, case MHD_LIB_INFO_FIXED_VERSION_NUM: if (sizeof(output_buf->v_version_num_uint32) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! MHD_VERSION -#error MHD_VERSION is not defined +#if !MHD_VERSION +# error MHD_VERSION is not defined #endif - output_buf->v_version_num_uint32 = (uint_fast32_t) MHD_VERSION; + output_buf->v_version_num_uint32 = (uint_fast32_t)MHD_VERSION; return MHD_SC_OK; case MHD_LIB_INFO_FIXED_VERSION_STRING: if (sizeof(output_buf->v_version_string) <= output_buf_size) @@ -134,8 +134,8 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, static char str_buf[10] = /* Larger than needed */ {0, 1, 1, 1, 1, 1, 1, 1, 1, 1}; static size_t str_len = 0; - if ((0 == str_len) || - (0 != str_buf[str_len])) + if ((0 == str_len) + || (0 != str_buf[str_len])) { const uint_fast32_t ver_num = MHD_VERSION; size_t pos = 0; @@ -269,13 +269,13 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, case MHD_LIB_INFO_FIXED_TYPE_DIGEST_AUTH_MD5: if (sizeof(output_buf->v_type_digest_auth_md5_algo_type) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined(MHD_SUPPORT_MD5) +#if !defined(MHD_SUPPORT_MD5) output_buf->v_type_digest_auth_md5_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_NOT_AVAILABLE; -#elif ! defined(MHD_MD5_EXTR) +#elif !defined(MHD_MD5_EXTR) output_buf->v_type_digest_auth_md5_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_BUILT_IN; -#elif ! defined(mhd_MD5_HAS_EXT_ERROR) +#elif !defined(mhd_MD5_HAS_EXT_ERROR) output_buf->v_type_digest_auth_md5_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_NEVER_FAIL; #else @@ -287,13 +287,13 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, if (sizeof(output_buf->v_type_digest_auth_sha256_algo_type) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined(MHD_SUPPORT_SHA256) +#if !defined(MHD_SUPPORT_SHA256) output_buf->v_type_digest_auth_sha256_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_NOT_AVAILABLE; -#elif ! defined(MHD_SHA256_EXTR) +#elif !defined(MHD_SHA256_EXTR) output_buf->v_type_digest_auth_sha256_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_BUILT_IN; -#elif ! defined(mhd_SHA256_HAS_EXT_ERROR) +#elif !defined(mhd_SHA256_HAS_EXT_ERROR) output_buf->v_type_digest_auth_sha256_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_NEVER_FAIL; #else @@ -305,13 +305,13 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, if (sizeof(output_buf->v_type_digest_auth_sha512_256_algo_type) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined(MHD_SUPPORT_SHA512_256) +#if !defined(MHD_SUPPORT_SHA512_256) output_buf->v_type_digest_auth_sha512_256_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_NOT_AVAILABLE; -#elif ! defined(MHD_SHA512_256_EXTR) +#elif !defined(MHD_SHA512_256_EXTR) output_buf->v_type_digest_auth_sha512_256_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_BUILT_IN; -#elif ! defined(mhd_SHA512_256_HAS_EXT_ERROR) +#elif !defined(mhd_SHA512_256_HAS_EXT_ERROR) output_buf->v_type_digest_auth_sha512_256_algo_type = MHD_LIB_INFO_FIXED_DIGEST_ALGO_TYPE_EXTERNAL_NEVER_FAIL; #else @@ -369,9 +369,9 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, case MHD_LIB_INFO_FIXED_TYPE_IPV6: if (sizeof(output_buf->v_ipv6) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined(HAVE_INET6) +#if !defined(HAVE_INET6) output_buf->v_ipv6 = MHD_LIB_INFO_FIXED_IPV6_TYPE_NONE; -#elif ! defined(HAVE_DCLR_IPV6_V6ONLY) +#elif !defined(HAVE_DCLR_IPV6_V6ONLY) output_buf->v_ipv6 = MHD_LIB_INFO_FIXED_IPV6_TYPE_DUAL_ONLY; #else output_buf->v_ipv6 = MHD_LIB_INFO_FIXED_IPV6_TYPE_IPV6_PURE; @@ -408,9 +408,9 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, if (sizeof(output_buf->v_has_autosuppress_sigpipe_int_bool) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined (mhd_SEND_SPIPE_SUPPRESS_NEEDED) +#if !defined(mhd_SEND_SPIPE_SUPPRESS_NEEDED) output_buf->v_has_autosuppress_sigpipe_int_bool = MHD_YES; -#elif defined (mhd_SEND_SPIPE_SUPPRESS_POSSIBLE) \ +#elif defined(mhd_SEND_SPIPE_SUPPRESS_POSSIBLE) \ || defined(mhd_HAVE_MHD_THREAD_BLOCK_SIGPIPE) output_buf->v_has_autosuppress_sigpipe_int_bool = MHD_YES; #else @@ -421,9 +421,9 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, if (sizeof(output_buf->v_has_autosuppress_sigpipe_ext_bool) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined (mhd_SEND_SPIPE_SUPPRESS_NEEDED) +#if !defined(mhd_SEND_SPIPE_SUPPRESS_NEEDED) output_buf->v_has_autosuppress_sigpipe_ext_bool = MHD_YES; -#elif defined (mhd_SEND_SPIPE_SUPPRESS_POSSIBLE) +#elif defined(mhd_SEND_SPIPE_SUPPRESS_POSSIBLE) output_buf->v_has_autosuppress_sigpipe_ext_bool = MHD_YES; #else output_buf->v_has_autosuppress_sigpipe_ext_bool = MHD_NO; @@ -441,7 +441,7 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, case MHD_LIB_INFO_FIXED_TYPE_ITC: if (sizeof(output_buf->v_type_itc) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined(MHD_SUPPORT_THREADS) +#if !defined(MHD_SUPPORT_THREADS) output_buf->v_type_itc = MHD_LIB_INFO_FIXED_ITC_TYPE_NONE; #elif defined(MHD_ITC_SOCKETPAIR_) output_buf->v_type_itc = MHD_LIB_INFO_FIXED_ITC_TYPE_SOCKETPAIR; @@ -450,13 +450,13 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, #elif defined(MHD_ITC_EVENTFD_) output_buf->v_type_itc = MHD_LIB_INFO_FIXED_ITC_TYPE_EVENTFD; #else -#error The type of ITC is not defined +# error The type of ITC is not defined #endif return MHD_SC_OK; case MHD_LIB_INFO_FIXED_SUPPORT_LARGE_FILE: if (sizeof(output_buf->v_support_large_file_bool) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; -#if ! defined(HAVE_PREAD) && defined(lseek64) +#if !defined(HAVE_PREAD) && defined(lseek64) output_buf->v_support_large_file_bool = MHD_YES; #elif defined(HAVE_PREAD64) output_buf->v_support_large_file_bool = MHD_YES; @@ -464,7 +464,7 @@ MHD_lib_get_info_fixed_sz (enum MHD_LibInfoFixed info_type, output_buf->v_support_large_file_bool = MHD_YES; #else output_buf->v_support_large_file_bool = - (0x7FFFFFFFFFFFFFFF == ((off_t) 0x7FFFFFFFFFFFFFFF)) ? MHD_YES : MHD_NO; + (0x7FFFFFFFFFFFFFFF == ((off_t)0x7FFFFFFFFFFFFFFF)) ? MHD_YES : MHD_NO; #endif return MHD_SC_OK; case MHD_LIB_INFO_FIXED_TLS_BACKENDS: @@ -542,7 +542,7 @@ MHD_lib_get_info_dynamic_sz ( bool openssl_avail; bool mdedtls_avail; - if (! mhd_lib_init_global_if_needed ()) + if (!mhd_lib_init_global_if_needed ()) return MHD_SC_INFO_GET_TYPE_UNOBTAINABLE; gnutls_avail = mhd_tls_gnu_is_inited_fine (); diff --git a/src/mhd2/md5_ext.h b/src/mhd2/md5_ext.h @@ -54,7 +54,7 @@ #define mhd_MD5_DIGEST_SIZE (16) #ifndef MHD_MD5_Context -#define MHD_MD5_Context void +# define MHD_MD5_Context void #endif /** diff --git a/src/mhd2/md5_ext_mbedtls.c b/src/mhd2/md5_ext_mbedtls.c @@ -59,7 +59,7 @@ void mhd_MD5_init_one_time (struct mhd_Md5CtxExt *ctx) { ctx->ext_error = 0; - ctx->handle = (mbedtls_md5_context *) malloc ( + ctx->handle = (mbedtls_md5_context *)malloc ( sizeof (mbedtls_md5_context)); if (NULL == ctx->handle) { diff --git a/src/mhd2/md5_int.c b/src/mhd2/md5_int.c @@ -93,78 +93,78 @@ md5_transform (uint32_t H[mhd_MD5_HASH_SIZE_WORDS], uint32_t X[16]; #ifndef mhd_GET_32BIT_LE_UNALIGNED - if (0 != (((uintptr_t) M) % mhd_UINT32_ALIGN)) + if (0 != (((uintptr_t)M) % mhd_UINT32_ALIGN)) { /* The input data is unaligned. */ /* Copy the unaligned input data to the aligned buffer. */ memcpy (X, M, sizeof(X)); /* The X[] buffer itself will be used as the source of the data, * but the data will be reloaded in correct bytes order on * the next steps. */ - M = (const void *) X; + M = (const void *)X; } #endif /* mhd_GET_32BIT_LE_UNALIGNED */ /* Four auxiliary functions, see RFC 1321, Clause 3.4 (step 4). */ /* Some optimisations used. */ /* #define F_FUNC(x,y,z) (((x)&(y)) | ((~(x))&(z))) */ /* Original version */ -#define F_FUNC(x,y,z) ((((y) ^ (z)) & (x)) ^ (z)) +#define F_FUNC(x, y, z) ((((y) ^ (z)) & (x)) ^ (z)) /* #define G_FUNC_1(x,y,z) (((x)&(z)) | ((y)&(~(z)))) */ /* Original version */ /* #define G_FUNC_2(x,y,z) UINT32_C(0) */ /* Original version */ #ifndef MHD_FAVOR_SMALL_CODE -# define G_FUNC_1(x,y,z) ((~(z)) & (y)) -# define G_FUNC_2(x,y,z) ((z) & (x)) +# define G_FUNC_1(x, y, z) ((~(z)) & (y)) +# define G_FUNC_2(x, y, z) ((z) & (x)) #else /* MHD_FAVOR_SMALL_CODE */ -# define G_FUNC_1(x,y,z) ((((x) ^ (y)) & (z)) ^ (y)) -# define G_FUNC_2(x,y,z) UINT32_C (0) +# define G_FUNC_1(x, y, z) ((((x) ^ (y)) & (z)) ^ (y)) +# define G_FUNC_2(x, y, z) UINT32_C (0) #endif /* MHD_FAVOR_SMALL_CODE */ -#define H_FUNC(x,y,z) ((x) ^ (y) ^ (z)) /* Original version */ +#define H_FUNC(x, y, z) ((x) ^ (y) ^ (z)) /* Original version */ /* #define I_FUNC(x,y,z) ((y) ^ ((x) | (~(z)))) */ /* Original version */ -#define I_FUNC(x,y,z) (((~(z)) | (x)) ^ (y)) +#define I_FUNC(x, y, z) (((~(z)) | (x)) ^ (y)) /* One step of round 1 of MD5 computation, see RFC 1321, Clause 3.4 (step 4). The original function was modified to use X[k] and T[i] as direct inputs. */ -#define MD5STEP_R1(va,vb,vc,vd,vX,vs,vT) do { \ - (va) += (vX) + (vT); \ - (va) += F_FUNC ((vb),(vc),(vd)); \ - (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) +#define MD5STEP_R1(va, vb, vc, vd, vX, vs, vT) do { \ + (va) += (vX) + (vT); \ + (va) += F_FUNC ((vb),(vc),(vd)); \ + (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) /* Get value of X(k) from input data buffer. See RFC 1321 Clause 3.4 (step 4). */ -#define GET_X_FROM_DATA(buf,t) \ +#define GET_X_FROM_DATA(buf, t) \ mhd_GET_32BIT_LE (((const uint32_t*) (buf)) + (t)) /* One step of round 2 of MD5 computation, see RFC 1321, Clause 3.4 (step 4). The original function was modified to use X[k] and T[i] as direct inputs. */ -#define MD5STEP_R2(va,vb,vc,vd,vX,vs,vT) do { \ - (va) += (vX) + (vT); \ - (va) += G_FUNC_1 ((vb),(vc),(vd)); \ - (va) += G_FUNC_2 ((vb),(vc),(vd)); \ - (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) +#define MD5STEP_R2(va, vb, vc, vd, vX, vs, vT) do { \ + (va) += (vX) + (vT); \ + (va) += G_FUNC_1 ((vb),(vc),(vd)); \ + (va) += G_FUNC_2 ((vb),(vc),(vd)); \ + (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) /* One step of round 3 of MD5 computation, see RFC 1321, Clause 3.4 (step 4). The original function was modified to use X[k] and T[i] as direct inputs. */ -#define MD5STEP_R3(va,vb,vc,vd,vX,vs,vT) do { \ - (va) += (vX) + (vT); \ - (va) += H_FUNC ((vb),(vc),(vd)); \ - (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) +#define MD5STEP_R3(va, vb, vc, vd, vX, vs, vT) do { \ + (va) += (vX) + (vT); \ + (va) += H_FUNC ((vb),(vc),(vd)); \ + (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) /* One step of round 4 of MD5 computation, see RFC 1321, Clause 3.4 (step 4). The original function was modified to use X[k] and T[i] as direct inputs. */ -#define MD5STEP_R4(va,vb,vc,vd,vX,vs,vT) do { \ - (va) += (vX) + (vT); \ - (va) += I_FUNC ((vb),(vc),(vd)); \ - (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) +#define MD5STEP_R4(va, vb, vc, vd, vX, vs, vT) do { \ + (va) += (vX) + (vT); \ + (va) += I_FUNC ((vb),(vc),(vd)); \ + (va) = mhd_ROTL32 ((va),(vs)) + (vb); } while (0) -#if ! defined(MHD_FAVOR_SMALL_CODE) +#if !defined(MHD_FAVOR_SMALL_CODE) /* Round 1. */ -#if mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN - if ((const void *) X == M) +# if mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN + if ((const void *)X == M) { /* The input data is already in the data buffer X[] in correct bytes order. */ @@ -189,7 +189,7 @@ md5_transform (uint32_t H[mhd_MD5_HASH_SIZE_WORDS], MD5STEP_R1 (B, C, D, A, X[15], 22, UINT32_C (0x49b40821)); } else /* Combined with the next 'if' */ -#endif /* mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN */ +# endif /* mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN */ if (1) { /* The input data is loaded in correct (little-endian) format before @@ -410,7 +410,7 @@ mhd_MD5_update (struct mhd_Md5CtxInt *restrict ctx, /* Note: (count & (mhd_MD5_BLOCK_SIZE-1)) equals (count % mhd_MD5_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned int) (ctx->count & (mhd_MD5_BLOCK_SIZE - 1)); + bytes_have = (unsigned int)(ctx->count & (mhd_MD5_BLOCK_SIZE - 1)); ctx->count += size; if (0 != bytes_have) @@ -419,7 +419,7 @@ mhd_MD5_update (struct mhd_Md5CtxInt *restrict ctx, if (size >= bytes_left) { /* Combine new data with data in the buffer and process the full block. */ - memcpy (((uint8_t *) ctx->buffer) + bytes_have, + memcpy (((uint8_t *)ctx->buffer) + bytes_have, data, bytes_left); data += bytes_left; @@ -440,7 +440,7 @@ mhd_MD5_update (struct mhd_Md5CtxInt *restrict ctx, if (0 != size) { /* Copy incomplete block of new data (if any) to the buffer. */ - memcpy (((uint8_t *) ctx->buffer) + bytes_have, data, size); + memcpy (((uint8_t *)ctx->buffer) + bytes_have, data, size); } } @@ -471,7 +471,7 @@ mhd_MD5_finish (struct mhd_Md5CtxInt *restrict ctx, /* Note: (count & (mhd_MD5_BLOCK_SIZE-1)) equals (count % mhd_MD5_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned int) (ctx->count & (mhd_MD5_BLOCK_SIZE - 1)); + bytes_have = (unsigned int)(ctx->count & (mhd_MD5_BLOCK_SIZE - 1)); /* Input data must be padded with a single bit "1", then with zeros and the finally the length of data in bits must be added as the final bytes @@ -482,13 +482,13 @@ mhd_MD5_finish (struct mhd_Md5CtxInt *restrict ctx, predefined (0x80). */ /* Buffer always have space for one byte at least (as full buffers are processed immediately). */ - ((uint8_t *) ctx->buffer)[bytes_have++] = 0x80; + ((uint8_t *)ctx->buffer)[bytes_have++] = 0x80; if (mhd_MD5_BLOCK_SIZE - bytes_have < MD5_SIZE_OF_LEN_ADD) { /* No space in the current block to put the total length of message. Pad the current block with zeros and process it. */ if (bytes_have < mhd_MD5_BLOCK_SIZE) - memset (((uint8_t *) ctx->buffer) + bytes_have, 0, + memset (((uint8_t *)ctx->buffer) + bytes_have, 0, mhd_MD5_BLOCK_SIZE - bytes_have); /* Process the full block. */ md5_transform (ctx->H, ctx->buffer); @@ -497,7 +497,7 @@ mhd_MD5_finish (struct mhd_Md5CtxInt *restrict ctx, } /* Pad the rest of the buffer with zeros. */ - memset (((uint8_t *) ctx->buffer) + bytes_have, 0, + memset (((uint8_t *)ctx->buffer) + bytes_have, 0, mhd_MD5_BLOCK_SIZE - MD5_SIZE_OF_LEN_ADD - bytes_have); /* Put the number of bits in processed data as little-endian value. See RFC 1321, clauses 2 and 3.2 (step 2). */ @@ -514,11 +514,11 @@ mhd_MD5_finish (struct mhd_Md5CtxInt *restrict ctx, #if defined(mhd_PUT_32BIT_LE_UNALIGNED) use_tmp_buf_to_align_result = false; -#elif defined (MHD_FAVOR_SMALL_CODE) +#elif defined(MHD_FAVOR_SMALL_CODE) use_tmp_buf_to_align_result = true; /* smaller code: eliminated branch below */ #else use_tmp_buf_to_align_result = - (0 != ((uintptr_t) digest) % mhd_UINT32_ALIGN); + (0 != ((uintptr_t)digest) % mhd_UINT32_ALIGN); #endif if (use_tmp_buf_to_align_result) { @@ -538,13 +538,13 @@ mhd_MD5_finish (struct mhd_Md5CtxInt *restrict ctx, { /* Use cast to (void*) here to mute compiler alignment warnings. * Compilers are not smart enough to see that alignment has been checked. */ - mhd_PUT_32BIT_LE ((void *) (digest + 0 * mhd_MD5_BYTES_IN_WORD), \ + mhd_PUT_32BIT_LE ((void *)(digest + 0 * mhd_MD5_BYTES_IN_WORD), \ ctx->H[0]); - mhd_PUT_32BIT_LE ((void *) (digest + 1 * mhd_MD5_BYTES_IN_WORD), \ + mhd_PUT_32BIT_LE ((void *)(digest + 1 * mhd_MD5_BYTES_IN_WORD), \ ctx->H[1]); - mhd_PUT_32BIT_LE ((void *) (digest + 2 * mhd_MD5_BYTES_IN_WORD), \ + mhd_PUT_32BIT_LE ((void *)(digest + 2 * mhd_MD5_BYTES_IN_WORD), \ ctx->H[2]); - mhd_PUT_32BIT_LE ((void *) (digest + 3 * mhd_MD5_BYTES_IN_WORD), \ + mhd_PUT_32BIT_LE ((void *)(digest + 3 * mhd_MD5_BYTES_IN_WORD), \ ctx->H[3]); } } diff --git a/src/mhd2/mempool_funcs.c b/src/mhd2/mempool_funcs.c @@ -101,14 +101,14 @@ #ifdef MHD_ASAN_POISON_ACTIVE -#include <sanitizer/asan_interface.h> +# include <sanitizer/asan_interface.h> #endif /* MHD_ASAN_POISON_ACTIVE */ #if defined(MAP_ANONYMOUS) # define mhd_MAP_ANONYMOUS MAP_ANONYMOUS #endif -#if ! defined(mhd_MAP_ANONYMOUS) && defined(MAP_ANON) +#if !defined(mhd_MAP_ANONYMOUS) && defined(MAP_ANON) # define mhd_MAP_ANONYMOUS MAP_ANON #endif @@ -143,37 +143,37 @@ /** * Boolean 'true' if the first pointer is less or equal the second pointer */ -# define mp_ptr_le_(p1,p2) \ - (((const uint8_t*) (p1)) <= ((const uint8_t*) (p2))) +# define mp_ptr_le_(p1, p2) \ + (((const uint8_t*) (p1)) <= ((const uint8_t*) (p2))) /** * The difference in bytes between positions of the first and * the second pointers */ -# define mp_ptr_diff_(p1,p2) \ - ((size_t) (((const uint8_t*) (p1)) - ((const uint8_t*) (p2)))) +# define mp_ptr_diff_(p1, p2) \ + ((size_t) (((const uint8_t*) (p1)) - ((const uint8_t*) (p2)))) #else /* MHD_ASAN_POISON_ACTIVE */ # define mhd_RED_ZONE_SIZE (mhd_MEMPOOL_ALIGN_SIZE) # define mhd_ROUND_TO_ALIGN_PLUS_RED_ZONE(n) \ - (mhd_ROUND_TO_ALIGN (n) + mhd_RED_ZONE_SIZE) + (mhd_ROUND_TO_ALIGN (n) + mhd_RED_ZONE_SIZE) # define mhd_POISON_MEMORY(pointer, size) \ - ASAN_POISON_MEMORY_REGION ((pointer), (size)) + ASAN_POISON_MEMORY_REGION ((pointer), (size)) # define mhd_UNPOISON_MEMORY(pointer, size) \ - ASAN_UNPOISON_MEMORY_REGION ((pointer), (size)) + ASAN_UNPOISON_MEMORY_REGION ((pointer), (size)) # if defined(FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS) /** * Boolean 'true' if the first pointer is less or equal the second pointer */ -# define mp_ptr_le_(p1,p2) \ - (((uintptr_t) ((const void*) (p1))) <= \ - ((uintptr_t) ((const void*) (p2)))) +# define mp_ptr_le_(p1, p2) \ + (((uintptr_t) ((const void*) (p1))) <= \ + ((uintptr_t) ((const void*) (p2)))) /** * The difference in bytes between positions of the first and * the second pointers */ -# define mp_ptr_diff_(p1,p2) \ - ((size_t) (((uintptr_t) ((const uint8_t*) (p1))) - \ - ((uintptr_t) ((const uint8_t*) (p2))))) -#elif defined(FUNC_ATTR_PTRCOMPARE_WORKS) && \ +# define mp_ptr_diff_(p1, p2) \ + ((size_t) (((uintptr_t) ((const uint8_t*) (p1))) - \ + ((uintptr_t) ((const uint8_t*) (p2))))) +# elif defined(FUNC_ATTR_PTRCOMPARE_WORKS) && \ defined(FUNC_ATTR_PTRSUBTRACT_WORKS) # ifndef NDEBUG /** @@ -182,7 +182,7 @@ __attribute__((no_sanitize ("pointer-compare"))) static bool mp_ptr_le_ (const void *p1, const void *p2) { - return (((const uint8_t *) p1) <= ((const uint8_t *) p2)); + return (((const uint8_t *)p1) <= ((const uint8_t *)p2)); } @@ -196,7 +196,7 @@ mp_ptr_le_ (const void *p1, const void *p2) __attribute__((no_sanitize ("pointer-subtract"))) static size_t mp_ptr_diff_ (const void *p1, const void *p2) { - return (size_t) (((const uint8_t *) p1) - ((const uint8_t *) p2)); + return (size_t)(((const uint8_t *)p1) - ((const uint8_t *)p2)); } @@ -208,11 +208,11 @@ mp_ptr_diff_ (const void *p1, const void *p2) __attribute__((no_sanitize ("address"))) static bool mp_ptr_le_ (const void *p1, const void *p2) { - return (((const uint8_t *) p1) <= ((const uint8_t *) p2)); + return (((const uint8_t *)p1) <= ((const uint8_t *)p2)); } - #endif /* _DEBUG */ +# endif /* _DEBUG */ /** * The difference in bytes between positions of the first and @@ -221,12 +221,12 @@ mp_ptr_le_ (const void *p1, const void *p2) __attribute__((no_sanitize ("address"))) static size_t mp_ptr_diff_ (const void *p1, const void *p2) { - return (size_t) (((const uint8_t *) p1) - ((const uint8_t *) p2)); + return (size_t)(((const uint8_t *)p1) - ((const uint8_t *)p2)); } # else /* ! FUNC_ATTR_NOSANITIZE_WORKS */ -#error User-poisoning cannot be used +# error User-poisoning cannot be used # endif /* ! FUNC_ATTR_NOSANITIZE_WORKS */ #endif /* MHD_ASAN_POISON_ACTIVE */ @@ -248,23 +248,23 @@ void mhd_init_mem_pools (void) { #ifdef mhd_USE_LARGE_ALLOCS -#ifdef MHD_SC_PAGESIZE +# ifdef MHD_SC_PAGESIZE long result; result = sysconf (MHD_SC_PAGESIZE); if (-1 != result) - MHD_sys_page_size_ = (size_t) result; + MHD_sys_page_size_ = (size_t)result; else - MHD_sys_page_size_ = (size_t) mhd_DEF_PAGE_SIZE; -#elif defined(_WIN32) + MHD_sys_page_size_ = (size_t)mhd_DEF_PAGE_SIZE; +# elif defined(_WIN32) SYSTEM_INFO si; GetSystemInfo (&si); - MHD_sys_page_size_ = (size_t) si.dwPageSize; -#else - MHD_sys_page_size_ = (size_t) mhd_DEF_PAGE_SIZE; -#endif /* _WIN32 */ + MHD_sys_page_size_ = (size_t)si.dwPageSize; +# else + MHD_sys_page_size_ = (size_t)mhd_DEF_PAGE_SIZE; +# endif /* _WIN32 */ mhd_assert (0 == (MHD_sys_page_size_ % mhd_MEMPOOL_ALIGN_SIZE)); #endif /* mhd_USE_LARGE_ALLOCS */ - (void) 0; + (void)0; } @@ -322,16 +322,16 @@ mhd_pool_create (size_t max, mhd_assert (mhd_RED_ZONE_SIZE < (max + mhd_RED_ZONE_SIZE)); max += mhd_RED_ZONE_SIZE; alloc_size = 0; - pool = (struct mhd_MemoryPool *) malloc (sizeof (struct mhd_MemoryPool)); + pool = (struct mhd_MemoryPool *)malloc (sizeof (struct mhd_MemoryPool)); if (NULL == pool) return NULL; pool->zeroing = zeroing; #ifdef mhd_USE_LARGE_ALLOCS pool->is_large_alloc = false; - if ( (max <= 32 * 1024) || - (max < MHD_sys_page_size_ * 4 / 3) ) + if ((max <= 32 * 1024) + || (max < MHD_sys_page_size_ * 4 / 3)) { - pool->memory = (uint8_t *) mhd_MAP_FAILED; + pool->memory = (uint8_t *)mhd_MAP_FAILED; } else { @@ -339,37 +339,37 @@ mhd_pool_create (size_t max, alloc_size = max + MHD_sys_page_size_ - 1; alloc_size -= alloc_size % MHD_sys_page_size_; # if defined(mhd_MAP_ANONYMOUS) - pool->memory = (uint8_t *) mmap (NULL, - alloc_size, - PROT_READ | PROT_WRITE, - MAP_PRIVATE | mhd_MAP_ANONYMOUS, - -1, - 0); + pool->memory = (uint8_t *)mmap (NULL, + alloc_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | mhd_MAP_ANONYMOUS, + -1, + 0); # else /* ! mhd_MAP_ANONYMOUS */ - pool->memory = (uint8_t *) VirtualAlloc (NULL, - alloc_size, - MEM_COMMIT | MEM_RESERVE, - PAGE_READWRITE); + pool->memory = (uint8_t *)VirtualAlloc (NULL, + alloc_size, + MEM_COMMIT | MEM_RESERVE, + PAGE_READWRITE); # endif /* ! mhd_MAP_ANONYMOUS */ } if (mhd_MAP_FAILED != pool->memory) pool->is_large_alloc = true; else #endif /* mhd_USE_LARGE_ALLOCS */ - if (! 0) + if (!0) { alloc_size = mhd_ROUND_TO_ALIGN (max); if (MHD_MEMPOOL_ZEROING_NEVER == zeroing) - pool->memory = (uint8_t *) malloc (alloc_size); + pool->memory = (uint8_t *)malloc (alloc_size); else - pool->memory = (uint8_t *) mhd_calloc (1, alloc_size); - if (((uint8_t *) NULL) == pool->memory) + pool->memory = (uint8_t *)mhd_calloc (1, alloc_size); + if (((uint8_t *)NULL) == pool->memory) { free (pool); return NULL; } } - mhd_assert (0 == (((uintptr_t) pool->memory) % mhd_MEMPOOL_ALIGN_SIZE)); + mhd_assert (0 == (((uintptr_t)pool->memory) % mhd_MEMPOOL_ALIGN_SIZE)); pool->pos = 0; pool->end = alloc_size; pool->size = alloc_size; @@ -403,7 +403,7 @@ mhd_pool_destroy (struct mhd_MemoryPool *restrict pool) } else #endif /* mhd_USE_LARGE_ALLOCS*/ - if (! 0) + if (!0) free (pool->memory); free (pool); @@ -433,7 +433,7 @@ mhd_pool_get_free (struct mhd_MemoryPool *restrict pool) MHD_INTERNAL mhd_FN_RET_UNALIASED mhd_FN_RET_SIZED (2) -mhd_FN_RET_ALIGNED (mhd_MEMPOOL_ALIGN_SIZE) void * +mhd_FN_RET_ALIGNED (mhd_MEMPOOL_ALIGN_SIZE)void * mhd_pool_allocate (struct mhd_MemoryPool *restrict pool, size_t size, bool from_end) @@ -445,7 +445,7 @@ mhd_pool_allocate (struct mhd_MemoryPool *restrict pool, mhd_assert (pool->size >= pool->end - pool->pos); mhd_assert (pool->pos == mhd_ROUND_TO_ALIGN (pool->pos)); asize = mhd_ROUND_TO_ALIGN_PLUS_RED_ZONE (size); - if ( (0 == asize) && (0 != size) ) + if ((0 == asize) && (0 != size)) return NULL; /* size too close to SIZE_MAX */ if (asize > pool->end - pool->pos) return NULL; @@ -488,7 +488,7 @@ mhd_pool_is_resizable_inplace (struct mhd_MemoryPool *restrict pool, MHD_INTERNAL mhd_FN_RET_UNALIASED mhd_FN_RET_SIZED (2) -mhd_FN_RET_ALIGNED (mhd_MEMPOOL_ALIGN_SIZE) void * +mhd_FN_RET_ALIGNED (mhd_MEMPOOL_ALIGN_SIZE)void * mhd_pool_try_alloc (struct mhd_MemoryPool *restrict pool, size_t size, size_t *restrict required_bytes) @@ -500,7 +500,7 @@ mhd_pool_try_alloc (struct mhd_MemoryPool *restrict pool, mhd_assert (pool->size >= pool->end - pool->pos); mhd_assert (pool->pos == mhd_ROUND_TO_ALIGN (pool->pos)); asize = mhd_ROUND_TO_ALIGN_PLUS_RED_ZONE (size); - if ( (0 == asize) && (0 != size) ) + if ((0 == asize) && (0 != size)) { /* size is too close to SIZE_MAX, very unlikely */ *required_bytes = SIZE_MAX; return NULL; @@ -553,26 +553,27 @@ mhd_pool_reallocate (struct mhd_MemoryPool *restrict pool, mhd_assert ((pool->size - mhd_RED_ZONE_SIZE) >= (old_offset + old_size)); /* Blocks "from the end" must not be reallocated */ /* (old_size == 0 || pool->memory + pool->pos > (uint8_t*) old) */ - mhd_assert ((old_size == 0) || \ - (pool->pos > old_offset)); - mhd_assert ((old_size == 0) || \ - ((pool->end - mhd_RED_ZONE_SIZE) >= (old_offset + old_size))); + mhd_assert ((old_size == 0) \ + || (pool->pos > old_offset)); + mhd_assert ((old_size == 0) \ + || ((pool->end - mhd_RED_ZONE_SIZE) >= + (old_offset + old_size))); /* Try resizing in-place */ if (shrinking) { /* Shrinking in-place, zero-out freed part */ if (MHD_MEMPOOL_ZEROING_ON_RESET < pool->zeroing) - memset ((uint8_t *) old + new_size, 0, old_size - new_size); - mhd_POISON_MEMORY ((uint8_t *) old + new_size, old_size - new_size); + memset ((uint8_t *)old + new_size, 0, old_size - new_size); + mhd_POISON_MEMORY ((uint8_t *)old + new_size, old_size - new_size); } if (pool->pos == mhd_ROUND_TO_ALIGN_PLUS_RED_ZONE (old_offset + old_size)) { /* "old" block is the last allocated block */ const size_t new_apos = mhd_ROUND_TO_ALIGN_PLUS_RED_ZONE (old_offset + new_size); - if (! shrinking) + if (!shrinking) { /* Grow in-place, check for enough space. */ - if ( (new_apos > pool->end) || - (new_apos < pool->pos) ) /* Value wrap */ + if ((new_apos > pool->end) + || (new_apos < pool->pos)) /* Value wrap */ return NULL; /* No space */ } /* Resized in-place */ @@ -585,9 +586,9 @@ mhd_pool_reallocate (struct mhd_MemoryPool *restrict pool, } /* Need to allocate new block */ asize = mhd_ROUND_TO_ALIGN_PLUS_RED_ZONE (new_size); - if ( ( (0 == asize) && - (0 != new_size) ) || /* Value wrap, too large new_size. */ - (asize > pool->end - pool->pos) ) /* Not enough space */ + if (((0 == asize) + && (0 != new_size)) /* Value wrap, too large new_size. */ + || (asize > pool->end - pool->pos)) /* Not enough space */ return NULL; new_blc = pool->memory + pool->pos; @@ -631,7 +632,7 @@ mhd_pool_deallocate (struct mhd_MemoryPool *restrict pool, memset (block, 0, block_size); mhd_POISON_MEMORY (block, block_size); } -#if ! defined(MHD_FAVOR_SMALL_CODE) && ! defined(MHD_ASAN_POISON_ACTIVE) +#if !defined(MHD_FAVOR_SMALL_CODE) && !defined(MHD_ASAN_POISON_ACTIVE) else return; /* Zero size, no need to do anything */ #endif /* ! MHD_FAVOR_SMALL_CODE && ! MHD_ASAN_POISON_ACTIVE */ @@ -656,18 +657,18 @@ mhd_pool_deallocate (struct mhd_MemoryPool *restrict pool, { bool need_red_zone_before; mhd_assert (mhd_RED_ZONE_SIZE <= alg_start); -#if defined(HAVE___ASAN_REGION_IS_POISONED) +# if defined(HAVE___ASAN_REGION_IS_POISONED) need_red_zone_before = (NULL == __asan_region_is_poisoned (pool->memory + alg_start - mhd_RED_ZONE_SIZE, mhd_RED_ZONE_SIZE)); -#elif defined(HAVE___ASAN_ADDRESS_IS_POISONED) +# elif defined(HAVE___ASAN_ADDRESS_IS_POISONED) need_red_zone_before = (0 == __asan_address_is_poisoned (pool->memory + alg_start - 1)); -#else /* ! HAVE___ASAN_ADDRESS_IS_POISONED */ +# else /* ! HAVE___ASAN_ADDRESS_IS_POISONED */ need_red_zone_before = true; /* Unknown, assume new red zone needed */ -#endif /* ! HAVE___ASAN_ADDRESS_IS_POISONED */ +# endif /* ! HAVE___ASAN_ADDRESS_IS_POISONED */ if (need_red_zone_before) { mhd_POISON_MEMORY (pool->memory + alg_start, mhd_RED_ZONE_SIZE); @@ -714,22 +715,23 @@ mhd_pool_reset (struct mhd_MemoryPool *restrict pool, mhd_assert (keep != NULL || copy_bytes == 0); mhd_assert (keep == NULL || mp_ptr_le_ (pool->memory, keep)); /* (keep == NULL || pool->memory + pool->size >= (uint8_t*) keep + copy_bytes) */ - mhd_assert ((keep == NULL) || \ - (pool->size >= mp_ptr_diff_ (keep, pool->memory) + copy_bytes)); + mhd_assert ((keep == NULL) \ + || (pool->size >= mp_ptr_diff_ (keep, + pool->memory) + copy_bytes)); #if defined(MHD_ASAN_POISON_ACTIVE) && defined(HAVE___ASAN_REGION_IS_POISONED) mhd_assert (NULL == __asan_region_is_poisoned (keep, copy_bytes)); #endif /* MHD_ASAN_POISON_ACTIVE && HAVE___ASAN_REGION_IS_POISONED */ mhd_UNPOISON_MEMORY (pool->memory, new_size); - if ( (NULL != keep) && - (keep != pool->memory) ) + if ((NULL != keep) + && (keep != pool->memory)) { if (0 != copy_bytes) memmove (pool->memory, keep, copy_bytes); } - if ((MHD_MEMPOOL_ZEROING_NEVER != pool->zeroing) && - (pool->size > copy_bytes)) + if ((MHD_MEMPOOL_ZEROING_NEVER != pool->zeroing) + && (pool->size > copy_bytes)) { size_t to_zero; /** Size of area to zero-out */ @@ -766,7 +768,7 @@ mhd_pool_reset (struct mhd_MemoryPool *restrict pool, } pool->pos = mhd_ROUND_TO_ALIGN_PLUS_RED_ZONE (new_size); pool->end = pool->size; - mhd_POISON_MEMORY (((uint8_t *) pool->memory) + new_size, \ + mhd_POISON_MEMORY (((uint8_t *)pool->memory) + new_size, \ pool->size - new_size); return pool->memory; } diff --git a/src/mhd2/mhd_action.h b/src/mhd2/mhd_action.h @@ -115,13 +115,13 @@ enum mhd_ActionType #ifndef MHD_UPLOADCALLBACK_DEFINED typedef const struct MHD_UploadAction * -(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (4,3) +(MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (4, 3) *MHD_UploadCallback)(void *upload_cls, struct MHD_Request *request, size_t content_data_size, void *content_data); -#define MHD_UPLOADCALLBACK_DEFINED 1 +# define MHD_UPLOADCALLBACK_DEFINED 1 #endif /* ! MHD_UPLOADCALLBACK_DEFINED */ /** @@ -162,7 +162,7 @@ struct mhd_UploadCallbacks }; #ifdef MHD_SUPPORT_POST_PARSER -#ifndef MHD_POST_DATA_READER_DEFINED +# ifndef MHD_POST_DATA_READER_DEFINED typedef const struct MHD_UploadAction * (MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_NONNULL_ (4) @@ -184,8 +184,8 @@ typedef const struct MHD_UploadAction * void *cls, enum MHD_PostParseResult parsing_result); -#define MHD_POST_DATA_READER_DEFINED 1 -#endif /* ! MHD_POST_DATA_READER_DEFINED */ +# define MHD_POST_DATA_READER_DEFINED 1 +# endif /* ! MHD_POST_DATA_READER_DEFINED */ /** @@ -233,15 +233,15 @@ struct mhd_PostParseActionData struct MHD_UpgradedHandle; /* forward declaration */ -#ifndef MHD_UPGRADEHANDLER_DEFINED +# ifndef MHD_UPGRADEHANDLER_DEFINED typedef void (*MHD_UpgradeHandler)(void *cls, struct MHD_Request *MHD_RESTRICT request, struct MHD_UpgradedHandle *MHD_RESTRICT urh); -#define MHD_UPGRADEHANDLER_DEFINED 1 -#endif /* ! MHD_UPGRADEHANDLER_DEFINED */ +# define MHD_UPGRADEHANDLER_DEFINED 1 +# endif /* ! MHD_UPGRADEHANDLER_DEFINED */ /** diff --git a/src/mhd2/mhd_align.h b/src/mhd2/mhd_align.h @@ -50,14 +50,14 @@ #include "sys_base_types.h" #if (defined(__GNUC__) && __GNUC__ < 4 && __GNUC_MINOR__ < 9 && \ - ! defined(__clang__)) || \ + !defined(__clang__)) || \ (defined(__clang__) && __clang_major__ < 8) || \ (defined(__clang__) && __clang_major__ < 11 && \ defined(__apple_build_version__)) /* GCC before 4.9 and clang before 8.0 have incorrect implementation of 'alignof()' which returns preferred alignment instead of minimal required alignment */ # define mhd_SYS_ALIGNOF_UNRELIABLE 1 -#elif defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1900 +#elif defined(_MSC_VER) && !defined(__clang__) && _MSC_VER < 1900 /* MSVC has the same problem as old GCC versions: '__alignof()' may return "preferred" alignment instead of "required". */ # define mhd_SYS_ALIGNOF_UNRELIABLE 1 @@ -66,7 +66,7 @@ #ifndef mhd_ALIGNOF # ifndef mhd_SYS_ALIGNOF_UNRELIABLE # ifdef HAVE_C_ALIGNOF -# if ! defined(__STDC_VERSION__) || (__STDC_VERSION__ + 0) < 202311 +# if !defined(__STDC_VERSION__) || (__STDC_VERSION__ + 0) < 202311 # ifdef HAVE_STDALIGN_H # include <stdalign.h> # endif /* HAVE_STDALIGN_H */ @@ -78,7 +78,7 @@ # endif /* HAVE_C_ALIGNOF */ # ifndef mhd_ALIGNOF -# if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER >= 1700 +# if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER >= 1700 # define mhd_ALIGNOF(TYPE) __alignof (TYPE) # endif /* _MSC_VER >= 1700 */ # endif /* !mhd_ALIGNOF */ @@ -88,7 +88,7 @@ #ifndef mhd_ALIGNOF # include "sys_offsetof.h" # define mhd_ALIGNOF(TYPE) \ - offsetof (struct { char mhd__s; TYPE mhd__m; }, mhd__m) + offsetof (struct { char mhd__s; TYPE mhd__m; }, mhd__m) #endif /* Provide a limited set of alignment macros */ @@ -105,7 +105,7 @@ #endif #ifdef HAVE_C_ALIGNAS -# if ! defined(__STDC_VERSION__) || (__STDC_VERSION__ + 0) < 202311 +# if !defined(__STDC_VERSION__) || (__STDC_VERSION__ + 0) < 202311 # ifdef HAVE_STDALIGN_H # include <stdalign.h> # endif /* HAVE_STDALIGN_H */ diff --git a/src/mhd2/mhd_assert.h b/src/mhd2/mhd_assert.h @@ -50,7 +50,7 @@ #include "mhd_sys_options.h" -#if ! defined(_DEBUG) && ! defined(NDEBUG) +#if !defined(_DEBUG) && !defined(NDEBUG) # ifndef DEBUG /* Used by some toolchains */ # define NDEBUG 1 /* Use NDEBUG by default */ # else /* DEBUG */ @@ -59,7 +59,7 @@ #endif /* !_DEBUG && !NDEBUG */ #if defined(_DEBUG) && defined(NDEBUG) -#error Both _DEBUG and NDEBUG are defined +# error Both _DEBUG and NDEBUG are defined #endif /* _DEBUG && NDEBUG */ #ifdef NDEBUG @@ -77,21 +77,21 @@ # endif # ifdef MHD_HAVE_MHD_FUNC_ # define mhd_assert(CHK) \ - do { \ - if (! (CHK)) { \ - fprintf (stderr, \ - "%s:%s:%u Assertion failed: %s\nProgram aborted.\n", \ - __FILE__, MHD_FUNC_, (unsigned) __LINE__, #CHK); \ - fflush (stderr); abort (); } \ - } while (0) + do { \ + if (! (CHK)) { \ + fprintf (stderr, \ + "%s:%s:%u Assertion failed: %s\nProgram aborted.\n", \ + __FILE__, MHD_FUNC_, (unsigned) __LINE__, #CHK); \ + fflush (stderr); abort (); } \ + } while (0) # else # define mhd_assert(CHK) \ - do { \ - if (! (CHK)) { \ - fprintf (stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \ - __FILE__, (unsigned) __LINE__, #CHK); \ - fflush (stderr); abort (); } \ - } while (0) + do { \ + if (! (CHK)) { \ + fprintf (stderr, "%s:%u Assertion failed: %s\nProgram aborted.\n", \ + __FILE__, (unsigned) __LINE__, #CHK); \ + fflush (stderr); abort (); } \ + } while (0) # endif # endif /* ! HAVE_ASSERT */ #endif /* NDEBUG */ diff --git a/src/mhd2/mhd_assume.h b/src/mhd2/mhd_assume.h @@ -47,9 +47,9 @@ #include "mhd_sys_options.h" -#if ! defined(NDEBUG) +#if !defined(NDEBUG) # include "mhd_assert.h" -#elif ! defined(MHD_ASSUME_KEYWORD) && defined(MHD_UNREACHABLE_KEYWORD) +#elif !defined(MHD_ASSUME_KEYWORD) && defined(MHD_UNREACHABLE_KEYWORD) # include "mhd_unreachable.h" #endif @@ -66,13 +66,13 @@ # define mhd_ASSUME(statement) MHD_ASSUME_KEYWORD ((statement)) # elif defined(MHD_UNREACHABLE_KEYWORD) # define mhd_ASSUME(statement) \ - do { if (! (statement)) mhd_UNREACHABLE (); } while (0) + do { if (! (statement)) mhd_UNREACHABLE (); } while (0) # else # define mhd_ASSUME(statement) ((void) 0) # endif #else # define mhd_ASSUME(statement) \ - mhd_assert ((statement) && "This statement must be always 'true'") + mhd_assert ((statement) && "This statement must be always 'true'") #endif #endif /* ! MHD_ASSUME_H */ diff --git a/src/mhd2/mhd_atomic_counter.c b/src/mhd2/mhd_atomic_counter.c @@ -48,7 +48,7 @@ #if defined(mhd_ATOMIC_BY_LOCKS) -#include "mhd_assert.h" +# include "mhd_assert.h" MHD_INTERNAL mhd_ATOMIC_COUNTER_TYPE mhd_atomic_counter_get_inc_wrap (struct mhd_AtomicCounter *pcnt) @@ -63,7 +63,7 @@ mhd_atomic_counter_get_inc_wrap (struct mhd_AtomicCounter *pcnt) } -#ifndef NDEBUG +# ifndef NDEBUG MHD_INTERNAL mhd_ATOMIC_COUNTER_TYPE mhd_atomic_counter_get_inc (struct mhd_AtomicCounter *pcnt) @@ -76,7 +76,7 @@ mhd_atomic_counter_get_inc (struct mhd_AtomicCounter *pcnt) } -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ MHD_INTERNAL mhd_ATOMIC_COUNTER_TYPE diff --git a/src/mhd2/mhd_atomic_counter.h b/src/mhd2/mhd_atomic_counter.h @@ -68,7 +68,7 @@ #ifdef MHD_SUPPORT_THREADS -# if defined(MHD_SUPPORT_ATOMIC_COUNTERS) && ! defined(__STDC_NO_ATOMICS__) +# if defined(MHD_SUPPORT_ATOMIC_COUNTERS) && !defined(__STDC_NO_ATOMICS__) /** * Atomic operations are based native compiler support for atomics @@ -149,8 +149,8 @@ struct mhd_AtomicCounter * @warning Must not be called for the counters that has been initialised * already. */ -# define mhd_atomic_counter_init(pcnt,initial_value) \ - (atomic_init (&((pcnt)->count), (initial_value)), (! 0)) +# define mhd_atomic_counter_init(pcnt, initial_value) \ + (atomic_init (&((pcnt)->count), (initial_value)), (! 0)) /** * Deinitialise the counter. @@ -165,9 +165,9 @@ struct mhd_AtomicCounter * @param pcnt the pointer to the counter to increment * @return the counter value before the increment */ -# define mhd_atomic_counter_get_inc_wrap(pcnt) \ - atomic_fetch_add_explicit (&((pcnt)->count), \ - 1, memory_order_relaxed) +# define mhd_atomic_counter_get_inc_wrap(pcnt) \ + atomic_fetch_add_explicit (&((pcnt)->count), \ + 1, memory_order_relaxed) # ifdef NDEBUG /** @@ -176,9 +176,9 @@ struct mhd_AtomicCounter * @param pcnt the pointer to the counter to increment */ # define mhd_atomic_counter_inc(pcnt) \ - do { (void) \ - atomic_fetch_add_explicit (&((pcnt)->count), 1, \ - memory_order_relaxed); } while (0) + do { (void) \ + atomic_fetch_add_explicit (&((pcnt)->count), 1, \ + memory_order_relaxed); } while (0) /** * Get the value of the counter and atomically increment the counter. @@ -187,7 +187,7 @@ struct mhd_AtomicCounter * @return the counter value before the increment */ # define mhd_atomic_counter_get_inc(pcnt) \ - mhd_atomic_counter_get_inc_wrap ((pcnt)) + mhd_atomic_counter_get_inc_wrap ((pcnt)) /** * Get the value of the counter and atomically decrement the counter. @@ -196,8 +196,8 @@ struct mhd_AtomicCounter * @return the counter value before the decrement */ # define mhd_atomic_counter_get_dec(pcnt) \ - atomic_fetch_sub_explicit (&((pcnt)->count), \ - 1, memory_order_release) + atomic_fetch_sub_explicit (&((pcnt)->count), \ + 1, memory_order_release) # else /* _DEBUG */ /** * Atomically increment the value of the counter. @@ -205,10 +205,10 @@ struct mhd_AtomicCounter * @param pcnt the pointer to the counter to increment */ # define mhd_atomic_counter_inc(pcnt) \ - do { mhd_ATOMIC_COUNTER_TYPE old_val = \ - atomic_fetch_add_explicit (&((pcnt)->count), 1, \ - memory_order_relaxed); \ - mhd_assert (mhd_ATOMIC_COUNTER_MAX != old_val); } while (0) + do { mhd_ATOMIC_COUNTER_TYPE old_val = \ + atomic_fetch_add_explicit (&((pcnt)->count), 1, \ + memory_order_relaxed); \ + mhd_assert (mhd_ATOMIC_COUNTER_MAX != old_val); } while (0) /** * Get the value of the counter and atomically increment the counter. @@ -240,7 +240,7 @@ mhd_atomic_counter_get_dec (struct mhd_AtomicCounter *pcnt) { mhd_ATOMIC_COUNTER_TYPE ret; - ret = atomic_fetch_sub_explicit (&((pcnt)->count),1, memory_order_relaxed); + ret = atomic_fetch_sub_explicit (&((pcnt)->count), 1, memory_order_relaxed); mhd_assert (0 != ret); @@ -256,7 +256,7 @@ mhd_atomic_counter_get_dec (struct mhd_AtomicCounter *pcnt) * @return the counter value */ # define mhd_atomic_counter_get(pcnt) \ - (atomic_load_explicit (&((pcnt)->count), memory_order_relaxed)) + (atomic_load_explicit (&((pcnt)->count), memory_order_relaxed)) #elif defined(mhd_ATOMIC_BY_LOCKS) @@ -268,9 +268,9 @@ mhd_atomic_counter_get_dec (struct mhd_AtomicCounter *pcnt) * @warning Must not be called for the counters that has been initialised * already. */ -# define mhd_atomic_counter_init(pcnt,initial_value) \ - ((pcnt)->count = (initial_value), \ - mhd_mutex_init_short (&((pcnt)->lock))) +# define mhd_atomic_counter_init(pcnt, initial_value) \ + ((pcnt)->count = (initial_value), \ + mhd_mutex_init_short (&((pcnt)->lock))) /** * Deinitialise the counter. @@ -278,7 +278,7 @@ mhd_atomic_counter_get_dec (struct mhd_AtomicCounter *pcnt) * @warning Must be called only for the counters that has been initialised. */ # define mhd_atomic_counter_deinit(pcnt) \ - mhd_mutex_destroy_chk (&((pcnt)->lock)) + mhd_mutex_destroy_chk (&((pcnt)->lock)) /** * Get the value of the counter and atomically increment the counter. * The value may overflow and wrap back to zero. @@ -288,17 +288,17 @@ mhd_atomic_counter_get_dec (struct mhd_AtomicCounter *pcnt) MHD_INTERNAL mhd_ATOMIC_COUNTER_TYPE mhd_atomic_counter_get_inc_wrap (struct mhd_AtomicCounter *pcnt); -#ifdef NDEBUG +# ifdef NDEBUG /** * Atomically increment the value of the counter. * Counter overflow is detected in debug builds. * @param pcnt the pointer to the counter to increment */ -# define mhd_atomic_counter_inc(pcnt) do { \ - mhd_mutex_lock_chk (&((pcnt)->lock)); \ - ++((pcnt)->count); \ - mhd_mutex_unlock_chk (&((pcnt)->lock)); } while (0) +# define mhd_atomic_counter_inc(pcnt) do { \ + mhd_mutex_lock_chk (&((pcnt)->lock)); \ + ++((pcnt)->count); \ + mhd_mutex_unlock_chk (&((pcnt)->lock)); } while (0) /** * Get the value of the counter and atomically increment the counter. @@ -306,21 +306,22 @@ mhd_atomic_counter_get_inc_wrap (struct mhd_AtomicCounter *pcnt); * @param pcnt the pointer to the counter to increment * @return the counter value before the increment */ -#define mhd_atomic_counter_get_inc(pcnt) mhd_atomic_counter_get_inc_wrap (pcnt) +# define mhd_atomic_counter_get_inc(pcnt) \ + mhd_atomic_counter_get_inc_wrap (pcnt) -#else +# else /** * Atomically increment the value of the counter. * Counter overflow is detected in debug builds. * @param pcnt the pointer to the counter to increment */ -# define mhd_atomic_counter_inc(pcnt) do { \ - mhd_ATOMIC_COUNTER_TYPE old_val; \ - mhd_mutex_lock_chk (&((pcnt)->lock)); \ - old_val = (pcnt)->count++; \ - mhd_mutex_unlock_chk (&((pcnt)->lock)); \ - mhd_assert (mhd_ATOMIC_COUNTER_MAX != old_val); } while (0) +# define mhd_atomic_counter_inc(pcnt) do {\ + mhd_ATOMIC_COUNTER_TYPE old_val; \ + mhd_mutex_lock_chk (&((pcnt)->lock)); \ + old_val = (pcnt)->count++; \ + mhd_mutex_unlock_chk (&((pcnt)->lock)); \ + mhd_assert (mhd_ATOMIC_COUNTER_MAX != old_val); } while (0) /** * Get the value of the counter and atomically increment the counter. @@ -331,7 +332,7 @@ mhd_atomic_counter_get_inc_wrap (struct mhd_AtomicCounter *pcnt); MHD_INTERNAL mhd_ATOMIC_COUNTER_TYPE mhd_atomic_counter_get_inc (struct mhd_AtomicCounter *pcnt); -#endif +# endif /** * Get the value of the counter and atomically decrement the counter. @@ -360,8 +361,8 @@ mhd_atomic_counter_get (struct mhd_AtomicCounter *pcnt); * @warning Must not be called for the counters that has been initialised * already. */ -# define mhd_atomic_counter_init(pcnt,initial_value) \ - ((pcnt)->count = (initial_value), (! 0)) +# define mhd_atomic_counter_init(pcnt, initial_value) \ + ((pcnt)->count = (initial_value), (! 0)) /** * Deinitialise the counter. @@ -384,8 +385,8 @@ mhd_atomic_counter_get (struct mhd_AtomicCounter *pcnt); * @param pcnt the pointer to the counter to increment */ # define mhd_atomic_counter_inc(pcnt) \ - do { mhd_assert (mhd_ATOMIC_COUNTER_MAX != ((pcnt)->count)); \ - ++((pcnt)->count); } while (0) + do { mhd_assert (mhd_ATOMIC_COUNTER_MAX != ((pcnt)->count)); \ + ++((pcnt)->count); } while (0) # ifdef NDEBUG /** @@ -395,7 +396,7 @@ mhd_atomic_counter_get (struct mhd_AtomicCounter *pcnt); * @return the counter value before the increment */ # define mhd_atomic_counter_get_inc(pcnt) \ - mhd_atomic_counter_get_inc_wrap ((pcnt)) + mhd_atomic_counter_get_inc_wrap ((pcnt)) /** * Get the value of the counter and atomically decrement the counter. @@ -403,7 +404,7 @@ mhd_atomic_counter_get (struct mhd_AtomicCounter *pcnt); * @param pcnt the pointer to the counter to decrement * @return the counter value before the decrement */ -# define mhd_atomic_counter_get_dec(pcnt) ((pcnt)->count--) +# define mhd_atomic_counter_get_dec(pcnt) ((pcnt)->count--) # else /* _DEBUG */ /** diff --git a/src/mhd2/mhd_auth_digest_hdr.h b/src/mhd2/mhd_auth_digest_hdr.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_AUTH_DIGEST -#error This header should be used only if Digest Auth is build +# error This header should be used only if Digest Auth is build #endif #include "mhd_str_types.h" diff --git a/src/mhd2/mhd_bithelpers.h b/src/mhd2/mhd_bithelpers.h @@ -55,7 +55,7 @@ #if defined(_MSC_FULL_VER) /* Clang-cl produces a function call instead of intrinsics if optimisations are turned off. */ -# if (! defined(__clang__)) || defined(__OPTIMIZE__) +# if (!defined(__clang__)) || defined(__OPTIMIZE__) /* Declarations for VC & Clang-cl built-ins */ # include <intrin.h> # define mhd_HAS_VC_INTRINSICS 1 @@ -65,7 +65,7 @@ #ifdef CHAR_BIT # if CHAR_BIT != 8 -#error CHAR_BIT different from 8 is not supported +# error CHAR_BIT different from 8 is not supported # endif #endif @@ -76,9 +76,9 @@ #endif #if defined(_MSC_FULL_VER) -#pragma warning(push) +# pragma warning(push) /* Disable C4505 "unreferenced local function has been removed" */ -#pragma warning(disable:4505) +# pragma warning(disable:4505) #endif /* _MSC_FULL_VER */ mhd_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE @@ -86,18 +86,18 @@ mhd_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE #if defined(MHD_HAVE___BUILTIN_BSWAP16) || \ mhd_HAS_BUILTIN (__builtin_bswap16) # define mhd_BYTES_SWAP16(value16) \ - ((uint16_t)__builtin_bswap16 ((uint16_t) value16)) + ((uint16_t)__builtin_bswap16 ((uint16_t) value16)) #elif defined(mhd_HAS_VC_INTRINSICS) # ifndef __clang__ # pragma intrinsic(_byteswap_ushort) # endif /* ! __clang__ */ # define mhd_BYTES_SWAP16(value16) \ - ((uint16_t)_byteswap_ushort ((uint16_t) value16)) + ((uint16_t)_byteswap_ushort ((uint16_t) value16)) #else /* ! mhd_HAS_BUILTIN(__builtin_bswap32) */ mhd_static_inline uint16_t mhd_BYTES_SWAP16 (uint16_t value16) { - return (uint16_t) ((value16 << 8u) | (value16 >> 8u)); + return (uint16_t)((value16 << 8u) | (value16 >> 8u)); } @@ -106,26 +106,26 @@ mhd_BYTES_SWAP16 (uint16_t value16) #ifdef MHD_HAVE___BUILTIN_BSWAP32 # define mhd_BYTES_SWAP32(value32) \ - ((uint32_t) __builtin_bswap32 ((uint32_t) value32)) + ((uint32_t) __builtin_bswap32 ((uint32_t) value32)) #elif defined(mhd_HAS_VC_INTRINSICS) # ifndef __clang__ # pragma intrinsic(_byteswap_ulong) # endif /* ! __clang__ */ # define mhd_BYTES_SWAP32(value32) \ - ((uint32_t) _byteswap_ulong ((uint32_t) value32)) + ((uint32_t) _byteswap_ulong ((uint32_t) value32)) #elif \ mhd_HAS_BUILTIN (__builtin_bswap32) # define mhd_BYTES_SWAP32(value32) \ - ((uint32_t) __builtin_bswap32 ((uint32_t) value32)) + ((uint32_t) __builtin_bswap32 ((uint32_t) value32)) #else /* ! mhd_HAS_BUILTIN(__builtin_bswap32) */ mhd_static_inline uint32_t mhd_BYTES_SWAP32 (uint32_t value32) { uint32_t ret; - ret = (uint32_t) (value32 << 24u); - ret |= (uint32_t) ((value32 << 8u) & (0x00FF0000u)); - ret |= (uint32_t) ((value32 >> 8u) & (0x0000FF00u)); - ret |= (uint32_t) (value32 >> 24u); + ret = (uint32_t)(value32 << 24u); + ret |= (uint32_t)((value32 << 8u) & (0x00FF0000u)); + ret |= (uint32_t)((value32 >> 8u) & (0x0000FF00u)); + ret |= (uint32_t)(value32 >> 24u); return ret; } @@ -135,30 +135,30 @@ mhd_BYTES_SWAP32 (uint32_t value32) #ifdef MHD_HAVE___BUILTIN_BSWAP64 # define mhd_BYTES_SWAP64(value64) \ - ((uint64_t) __builtin_bswap64 ((uint64_t) value64)) + ((uint64_t) __builtin_bswap64 ((uint64_t) value64)) #elif defined(mhd_HAS_VC_INTRINSICS) # ifndef __clang__ # pragma intrinsic(_byteswap_uint64) # endif /* ! __clang__ */ # define mhd_BYTES_SWAP64(value64) \ - ((uint64_t) _byteswap_uint64 ((uint64_t) value64)) + ((uint64_t) _byteswap_uint64 ((uint64_t) value64)) #elif \ mhd_HAS_BUILTIN (__builtin_bswap64) # define mhd_BYTES_SWAP64(value64) \ - ((uint64_t) __builtin_bswap64 ((uint64_t) value64)) + ((uint64_t) __builtin_bswap64 ((uint64_t) value64)) #else /* ! mhd_HAS_BUILTIN(__builtin_bswap64) */ mhd_static_inline uint64_t mhd_BYTES_SWAP64(uint64_t value64) { uint64_t ret; - ret = (uint64_t) (value64 << 56u); - ret |= (uint64_t) ((value64 << 40u) & (0x00FF000000000000u)); - ret |= (uint64_t) ((value64 << 24u) & (0x0000FF0000000000u)); - ret |= (uint64_t) ((value64 << 8u) & (0x000000FF00000000u)); - ret |= (uint64_t) ((value64 >> 8u) & (0x00000000FF000000u)); - ret |= (uint64_t) ((value64 >> 24u) & (0x0000000000FF0000u)); - ret |= (uint64_t) ((value64 >> 40u) & (0x000000000000FF00u)); - ret |= (uint64_t) (value64 >> 56u); + ret = (uint64_t)(value64 << 56u); + ret |= (uint64_t)((value64 << 40u) & (0x00FF000000000000u)); + ret |= (uint64_t)((value64 << 24u) & (0x0000FF0000000000u)); + ret |= (uint64_t)((value64 << 8u) & (0x000000FF00000000u)); + ret |= (uint64_t)((value64 >> 8u) & (0x00000000FF000000u)); + ret |= (uint64_t)((value64 >> 24u) & (0x0000000000FF0000u)); + ret |= (uint64_t)((value64 >> 40u) & (0x000000000000FF00u)); + ret |= (uint64_t)(value64 >> 56u); return ret; } #endif /* ! mhd_HAS_BUILTIN(__builtin_bswap64) */ @@ -171,22 +171,22 @@ mhd_BYTES_SWAP64(uint64_t value64) * Warning: evaluate arguments multiple times! */ # define mhd_BYTES_SWAP128(value128) \ - (((((value128) >> 0u) & 0xFFu) << 120u) | \ - ((((value128) >> 8u) & 0xFFu) << 112u) | \ - ((((value128) >> 16u) & 0xFFu) << 104u) | \ - ((((value128) >> 24u) & 0xFFu) << 96u) | \ - ((((value128) >> 32u) & 0xFFu) << 88u) | \ - ((((value128) >> 40u) & 0xFFu) << 80u) | \ - ((((value128) >> 48u) & 0xFFu) << 72u) | \ - ((((value128) >> 56u) & 0xFFu) << 64u) | \ - ((((value128) >> 64u) & 0xFFu) << 56u) | \ - ((((value128) >> 72u) & 0xFFu) << 48u) | \ - ((((value128) >> 80u) & 0xFFu) << 40u) | \ - ((((value128) >> 88u) & 0xFFu) << 32u) | \ - ((((value128) >> 96u) & 0xFFu) << 24u) | \ - ((((value128) >> 104u) & 0xFFu) << 16u) | \ - ((((value128) >> 112u) & 0xFFu) << 8u) | \ - ((((value128) >> 120u) & 0xFFu) << 0u)) + (((((value128) >> 0u) & 0xFFu) << 120u) | \ + ((((value128) >> 8u) & 0xFFu) << 112u) | \ + ((((value128) >> 16u) & 0xFFu) << 104u) | \ + ((((value128) >> 24u) & 0xFFu) << 96u) | \ + ((((value128) >> 32u) & 0xFFu) << 88u) | \ + ((((value128) >> 40u) & 0xFFu) << 80u) | \ + ((((value128) >> 48u) & 0xFFu) << 72u) | \ + ((((value128) >> 56u) & 0xFFu) << 64u) | \ + ((((value128) >> 64u) & 0xFFu) << 56u) | \ + ((((value128) >> 72u) & 0xFFu) << 48u) | \ + ((((value128) >> 80u) & 0xFFu) << 40u) | \ + ((((value128) >> 88u) & 0xFFu) << 32u) | \ + ((((value128) >> 96u) & 0xFFu) << 24u) | \ + ((((value128) >> 104u) & 0xFFu) << 16u) | \ + ((((value128) >> 112u) & 0xFFu) << 8u) | \ + ((((value128) >> 120u) & 0xFFu) << 0u)) #endif /* mhd_PUT_64BIT_LE (addr, value64) @@ -196,26 +196,26 @@ mhd_BYTES_SWAP64(uint64_t value64) mhd_static_inline void mhd_PUT_64BIT_LE_SLOW(void *addr, uint64_t value64) { - uint8_t *const dst = (uint8_t *) addr; - dst[0] = (uint8_t) value64; - dst[1] = (uint8_t) (value64 >> 8u); - dst[2] = (uint8_t) (value64 >> 16u); - dst[3] = (uint8_t) (value64 >> 24u); - dst[4] = (uint8_t) (value64 >> 32u); - dst[5] = (uint8_t) (value64 >> 40u); - dst[6] = (uint8_t) (value64 >> 48u); - dst[7] = (uint8_t) (value64 >> 56u); + uint8_t *const dst = (uint8_t *)addr; + dst[0] = (uint8_t)value64; + dst[1] = (uint8_t)(value64 >> 8u); + dst[2] = (uint8_t)(value64 >> 16u); + dst[3] = (uint8_t)(value64 >> 24u); + dst[4] = (uint8_t)(value64 >> 32u); + dst[5] = (uint8_t)(value64 >> 40u); + dst[6] = (uint8_t)(value64 >> 48u); + dst[7] = (uint8_t)(value64 >> 56u); } #if mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_PUT_64BIT_LE(addr, value64) \ - ((*(uint64_t*) (addr)) = (uint64_t) (value64)) + ((*(uint64_t*) (addr)) = (uint64_t) (value64)) #elif mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_PUT_64BIT_LE(addr, value64) \ - ((*(uint64_t*) (addr)) = mhd_BYTES_SWAP64 (value64)) + ((*(uint64_t*) (addr)) = mhd_BYTES_SWAP64 (value64)) #else /* mhd_BYTE_ORDER != mhd_BIG_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ # define mhd_PUT_64BIT_LE(addr, value64) \ - mhd_PUT_64BIT_LE_SLOW ((addr),(value64)) + mhd_PUT_64BIT_LE_SLOW ((addr),(value64)) /* Indicate that mhd_PUT_64BIT_LE does not need aligned pointer */ # define mhd_PUT_64BIT_LE_ALLOW_UNALIGNED 1 #endif /* mhd_BYTE_ORDER != mhd_BIG_ENDIAN */ @@ -223,13 +223,13 @@ mhd_PUT_64BIT_LE_SLOW(void *addr, uint64_t value64) /* Put result safely to unaligned address */ #ifdef mhd_PUT_64BIT_LE_ALLOW_UNALIGNED # define mhd_PUT_64BIT_LE_UNALIGN(addr, value64) \ - mhd_PUT_64BIT_LE ((addr),(value64)) + mhd_PUT_64BIT_LE ((addr),(value64)) #else /* ! mhd_PUT_64BIT_LE_ALLOW_UNALIGNED */ # define mhd_PUT_64BIT_LE_UNALIGN(addr, value64) \ - do { uint64_t mhd__aligned_dst; \ - mhd_PUT_64BIT_LE (&mhd__aligned_dst, (value64)); \ - memcpy ((addr), &mhd__aligned_dst, \ - sizeof(mhd__aligned_dst)); } while (0) + do { uint64_t mhd__aligned_dst; \ + mhd_PUT_64BIT_LE (&mhd__aligned_dst, (value64)); \ + memcpy ((addr), &mhd__aligned_dst, \ + sizeof(mhd__aligned_dst)); } while (0) #endif /* ! mhd_PUT_64BIT_LE_ALLOW_UNALIGNED */ @@ -240,22 +240,22 @@ mhd_PUT_64BIT_LE_SLOW(void *addr, uint64_t value64) mhd_static_inline void mhd_PUT_32BIT_LE_SLOW(void *addr, uint32_t value32) { - uint8_t *const dst = (uint8_t *) addr; - dst[0] = (uint8_t) value32; - dst[1] = (uint8_t) (value32 >> 8u); - dst[2] = (uint8_t) (value32 >> 16u); - dst[3] = (uint8_t) (value32 >> 24u); + uint8_t *const dst = (uint8_t *)addr; + dst[0] = (uint8_t)value32; + dst[1] = (uint8_t)(value32 >> 8u); + dst[2] = (uint8_t)(value32 >> 16u); + dst[3] = (uint8_t)(value32 >> 24u); } #if mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN -# define mhd_PUT_32BIT_LE(addr,value32) \ - ((*(uint32_t*) (addr)) = (uint32_t) (value32)) +# define mhd_PUT_32BIT_LE(addr, value32) \ + ((*(uint32_t*) (addr)) = (uint32_t) (value32)) #elif mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_PUT_32BIT_LE(addr, value32) \ - ((*(uint32_t*) (addr)) = mhd_BYTES_SWAP32 (value32)) + ((*(uint32_t*) (addr)) = mhd_BYTES_SWAP32 (value32)) #else /* mhd_BYTE_ORDER != mhd_BIG_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ # define mhd_PUT_32BIT_LE(addr, value32) \ - mhd_PUT_32BIT_LE_SLOW ((addr),(value32)) + mhd_PUT_32BIT_LE_SLOW ((addr),(value32)) /* Indicate that mhd_PUT_32BIT_LE does not need aligned pointer */ # define mhd_PUT_32BIT_LE_ALLOW_UNALIGNED 1 #endif /* mhd_BYTE_ORDER != mhd_BIG_ENDIAN */ @@ -263,13 +263,13 @@ mhd_PUT_32BIT_LE_SLOW(void *addr, uint32_t value32) /* Put result safely to unaligned address */ #ifdef mhd_PUT_32BIT_LE_ALLOW_UNALIGNED # define mhd_PUT_32BIT_LE_UNALIGN(addr, value32) \ - mhd_PUT_32BIT_LE ((addr),(value32)) + mhd_PUT_32BIT_LE ((addr),(value32)) #else /* ! mhd_PUT_32BIT_LE_ALLOW_UNALIGNED */ # define mhd_PUT_32BIT_LE_UNALIGN(addr, value32) \ - do { uint32_t mhd__aligned_dst; \ - mhd_PUT_32BIT_LE (&mhd__aligned_dst, (value32)); \ - memcpy ((addr), &mhd__aligned_dst, \ - sizeof(mhd__aligned_dst)); } while (0) + do { uint32_t mhd__aligned_dst; \ + mhd_PUT_32BIT_LE (&mhd__aligned_dst, (value32)); \ + memcpy ((addr), &mhd__aligned_dst, \ + sizeof(mhd__aligned_dst)); } while (0) #endif /* ! mhd_PUT_32BIT_LE_ALLOW_UNALIGNED */ @@ -281,20 +281,20 @@ mhd_PUT_32BIT_LE_SLOW(void *addr, uint32_t value32) mhd_static_inline uint32_t mhd_GET_32BIT_LE_SLOW(const void *addr) { - const uint8_t *const src = (const uint8_t *) addr; + const uint8_t *const src = (const uint8_t *)addr; uint32_t ret; - ret = (uint32_t) src[0]; - ret |= (uint32_t) (((uint32_t) src[1]) << 8u); - ret |= (uint32_t) (((uint32_t) src[2]) << 16u); - ret |= (uint32_t) (((uint32_t) src[3]) << 24u); + ret = (uint32_t)src[0]; + ret |= (uint32_t)(((uint32_t)src[1]) << 8u); + ret |= (uint32_t)(((uint32_t)src[2]) << 16u); + ret |= (uint32_t)(((uint32_t)src[3]) << 24u); return ret; } #if mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_GET_32BIT_LE(addr) \ - (*(const uint32_t*) (addr)) + (*(const uint32_t*) (addr)) #elif mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_GET_32BIT_LE(addr) \ - mhd_BYTES_SWAP32 (*(const uint32_t*) (addr)) + mhd_BYTES_SWAP32 (*(const uint32_t*) (addr)) #else /* mhd_BYTE_ORDER != mhd_BIG_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ # define mhd_GET_32BIT_LE(addr) mhd_GET_32BIT_LE_SLOW ((addr)) @@ -325,24 +325,24 @@ mhd_GET_32BIT_LE_UNALIGN (const void *addr) mhd_static_inline uint64_t mhd_GET_64BIT_LE_SLOW (const void *addr) { - const uint8_t *const src = (const uint8_t *) addr; + const uint8_t *const src = (const uint8_t *)addr; uint64_t ret; - ret = (uint64_t) src[0]; - ret |= (uint64_t) src[1] << 8u; - ret |= (uint64_t) src[2] << 16u; - ret |= (uint64_t) src[3] << 24u; - ret |= (uint64_t) src[4] << 32u; - ret |= (uint64_t) src[5] << 40u; - ret |= (uint64_t) src[6] << 48u; - ret |= (uint64_t) src[7] << 56u; + ret = (uint64_t)src[0]; + ret |= (uint64_t)src[1] << 8u; + ret |= (uint64_t)src[2] << 16u; + ret |= (uint64_t)src[3] << 24u; + ret |= (uint64_t)src[4] << 32u; + ret |= (uint64_t)src[5] << 40u; + ret |= (uint64_t)src[6] << 48u; + ret |= (uint64_t)src[7] << 56u; return ret; } #if mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_GET_64BIT_LE(addr) \ - (*(const uint64_t*) (addr)) + (*(const uint64_t*) (addr)) #elif mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_GET_64BIT_LE(addr) \ - mhd_BYTES_SWAP64 (*(const uint64_t*) (addr)) + mhd_BYTES_SWAP64 (*(const uint64_t*) (addr)) #else /* mhd_BYTE_ORDER != mhd_BIG_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ # define mhd_GET_64BIT_LE(addr) mhd_GET_64BIT_LE_SLOW ((addr)) @@ -367,19 +367,19 @@ mhd_GET_64BIT_LE_UNALIGN (const void *addr) */ #if SIZEOF_UINT_FAST32_T == 4 # define mhd_GET_UINTFAST32_LE(addr) \ - mhd_GET_32BIT_LE ((addr)) + mhd_GET_32BIT_LE ((addr)) #elif SIZEOF_UINT_FAST32_T == 8 # define mhd_GET_UINTFAST32_LE(addr) \ - mhd_GET_64BIT_LE ((addr)) + mhd_GET_64BIT_LE ((addr)) #else /* future-proof */ mhd_static_inline uint_fast32_t mhd_GET_UINTFAST32_LE(const void *addr) { - const uint8_t *const src = (const uint8_t *) addr; + const uint8_t *const src = (const uint8_t *)addr; size_t i; uint_fast32_t ret = 0; for (i = 0; i < sizeof(ret); ++i) - ret |= (uint_fast32_t) (((uint_fast32_t) src[i]) << (8u * i)); + ret |= (uint_fast32_t)(((uint_fast32_t)src[i]) << (8u * i)); return ret; } #endif @@ -393,22 +393,22 @@ mhd_GET_UINTFAST32_LE(const void *addr) mhd_static_inline void mhd_PUT_64BIT_BE_SLOW(void *addr, uint64_t value64) { - uint8_t *const dst = (uint8_t *) addr; - dst[0] = (uint8_t) (value64 >> 56u); - dst[1] = (uint8_t) (value64 >> 48u); - dst[2] = (uint8_t) (value64 >> 40u); - dst[3] = (uint8_t) (value64 >> 32u); - dst[4] = (uint8_t) (value64 >> 24u); - dst[5] = (uint8_t) (value64 >> 16u); - dst[6] = (uint8_t) (value64 >> 8u); - dst[7] = (uint8_t) value64; + uint8_t *const dst = (uint8_t *)addr; + dst[0] = (uint8_t)(value64 >> 56u); + dst[1] = (uint8_t)(value64 >> 48u); + dst[2] = (uint8_t)(value64 >> 40u); + dst[3] = (uint8_t)(value64 >> 32u); + dst[4] = (uint8_t)(value64 >> 24u); + dst[5] = (uint8_t)(value64 >> 16u); + dst[6] = (uint8_t)(value64 >> 8u); + dst[7] = (uint8_t)value64; } #if mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_PUT_64BIT_BE(addr, value64) \ - ((*(uint64_t*) (addr)) = (uint64_t) (value64)) + ((*(uint64_t*) (addr)) = (uint64_t) (value64)) #elif mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_PUT_64BIT_BE(addr, value64) \ - ((*(uint64_t*) (addr)) = mhd_BYTES_SWAP64 (value64)) + ((*(uint64_t*) (addr)) = mhd_BYTES_SWAP64 (value64)) #else /* mhd_BYTE_ORDER != mhd_LITTLE_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ # define mhd_PUT_64BIT_BE(addr, value64) mhd_PUT_64BIT_BE_SLOW (addr, value64) @@ -419,13 +419,13 @@ mhd_PUT_64BIT_BE_SLOW(void *addr, uint64_t value64) /* Put result safely to unaligned address */ #ifdef mhd_PUT_64BIT_BE_ALLOW_UNALIGNED # define mhd_PUT_64BIT_BE_UNALIGN(addr, value64) \ - mhd_PUT_64BIT_BE ((addr),(value64)) + mhd_PUT_64BIT_BE ((addr),(value64)) #else /* ! mhd_PUT_64BIT_BE_ALLOW_UNALIGNED */ # define mhd_PUT_64BIT_BE_UNALIGN(addr, value64) \ - do { uint64_t mhd__aligned_dst; \ - mhd_PUT_64BIT_BE (&mhd__aligned_dst, (value64)); \ - memcpy ((addr), &mhd__aligned_dst, \ - sizeof(mhd__aligned_dst)); } while (0) + do { uint64_t mhd__aligned_dst; \ + mhd_PUT_64BIT_BE (&mhd__aligned_dst, (value64)); \ + memcpy ((addr), &mhd__aligned_dst, \ + sizeof(mhd__aligned_dst)); } while (0) #endif /* ! mhd_PUT_64BIT_BE_ALLOW_UNALIGNED */ @@ -434,25 +434,25 @@ mhd_PUT_64BIT_BE_SLOW(void *addr, uint64_t value64) */ #if mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_GET_64BIT_BE(addr) \ - (*(const uint64_t*) (addr)) + (*(const uint64_t*) (addr)) #elif mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_GET_64BIT_BE(addr) \ - mhd_BYTES_SWAP64 (*(const uint64_t*) (addr)) + mhd_BYTES_SWAP64 (*(const uint64_t*) (addr)) #else /* mhd_BYTE_ORDER != mhd_LITTLE_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ mhd_static_inline uint64_t mhd_GET_64BIT_BE(const void *addr) { - const uint8_t *const src = (const uint8_t *) addr; + const uint8_t *const src = (const uint8_t *)addr; uint64_t ret; - ret = (uint64_t) (((uint64_t) src[0]) << 56u); - ret |= (uint64_t) (((uint64_t) src[1]) << 48u); - ret |= (uint64_t) (((uint64_t) src[2]) << 40u); - ret |= (uint64_t) (((uint64_t) src[3]) << 32u); - ret |= (uint64_t) (((uint64_t) src[4]) << 24u); - ret |= (uint64_t) (((uint64_t) src[5]) << 16u); - ret |= (uint64_t) (((uint64_t) src[6]) << 8u); - ret |= (uint64_t) src[7]; + ret = (uint64_t)(((uint64_t)src[0]) << 56u); + ret |= (uint64_t)(((uint64_t)src[1]) << 48u); + ret |= (uint64_t)(((uint64_t)src[2]) << 40u); + ret |= (uint64_t)(((uint64_t)src[3]) << 32u); + ret |= (uint64_t)(((uint64_t)src[4]) << 24u); + ret |= (uint64_t)(((uint64_t)src[5]) << 16u); + ret |= (uint64_t)(((uint64_t)src[6]) << 8u); + ret |= (uint64_t)src[7]; return ret; } /* Indicate that mhd_GET_64BIT_BE does not need aligned pointer */ @@ -466,20 +466,20 @@ mhd_GET_64BIT_BE(const void *addr) */ #if mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_PUT_32BIT_BE(addr, value32) \ - ((*(uint32_t*) (addr)) = (uint32_t) (value32)) + ((*(uint32_t*) (addr)) = (uint32_t) (value32)) #elif mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_PUT_32BIT_BE(addr, value32) \ - ((*(uint32_t*) (addr)) = mhd_BYTES_SWAP32 (value32)) + ((*(uint32_t*) (addr)) = mhd_BYTES_SWAP32 (value32)) #else /* mhd_BYTE_ORDER != mhd_LITTLE_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ mhd_static_inline void mhd_PUT_32BIT_BE(void *addr, uint32_t value32) { - uint8_t *const dst = (uint8_t *) addr; - dst[0] = (uint8_t) (value32 >> 24u); - dst[1] = (uint8_t) (value32 >> 16u); - dst[2] = (uint8_t) (value32 >> 8u); - dst[3] = (uint8_t) value32; + uint8_t *const dst = (uint8_t *)addr; + dst[0] = (uint8_t)(value32 >> 24u); + dst[1] = (uint8_t)(value32 >> 16u); + dst[2] = (uint8_t)(value32 >> 8u); + dst[3] = (uint8_t)value32; } /* Indicate that mhd_PUT_32BIT_BE does not need aligned pointer */ # define mhd_PUT_32BIT_BE_ALLOW_UNALIGNED 1 @@ -488,13 +488,13 @@ mhd_PUT_32BIT_BE(void *addr, uint32_t value32) /* Put result safely to unaligned address */ #ifdef mhd_PUT_32BIT_BE_ALLOW_UNALIGNED # define mhd_PUT_32BIT_BE_UNALIGN(addr, value32) \ - mhd_PUT_32BIT_BE ((addr),(value32)) + mhd_PUT_32BIT_BE ((addr),(value32)) #else /* ! mhd_PUT_32BIT_BE_ALLOW_UNALIGNED */ # define mhd_PUT_32BIT_BE_UNALIGN(addr, value32) \ - do { uint32_t mhd__aligned_dst; \ - mhd_PUT_32BIT_BE (&mhd__aligned_dst, (value32)); \ - memcpy ((addr), &mhd__aligned_dst, \ - sizeof(mhd__aligned_dst)); } while (0) + do { uint32_t mhd__aligned_dst; \ + mhd_PUT_32BIT_BE (&mhd__aligned_dst, (value32)); \ + memcpy ((addr), &mhd__aligned_dst, \ + sizeof(mhd__aligned_dst)); } while (0) #endif /* ! mhd_PUT_32BIT_BE_ALLOW_UNALIGNED */ @@ -504,21 +504,21 @@ mhd_PUT_32BIT_BE(void *addr, uint32_t value32) */ #if mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_GET_32BIT_BE(addr) \ - (*(const uint32_t*) (addr)) + (*(const uint32_t*) (addr)) #elif mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_GET_32BIT_BE(addr) \ - mhd_BYTES_SWAP32 (*(const uint32_t*) (addr)) + mhd_BYTES_SWAP32 (*(const uint32_t*) (addr)) #else /* mhd_BYTE_ORDER != mhd_LITTLE_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ mhd_static_inline uint32_t mhd_GET_32BIT_BE(const void *addr) { - const uint8_t *const src = (const uint8_t *) addr; + const uint8_t *const src = (const uint8_t *)addr; uint32_t ret; - ret = (uint32_t) (((uint32_t) src[0]) << 24u); - ret |= (uint32_t) (((uint32_t) src[1]) << 16u); - ret |= (uint32_t) (((uint32_t) src[2]) << 8u); - ret |= (uint32_t) src[3]; + ret = (uint32_t)(((uint32_t)src[0]) << 24u); + ret |= (uint32_t)(((uint32_t)src[1]) << 16u); + ret |= (uint32_t)(((uint32_t)src[2]) << 8u); + ret |= (uint32_t)src[3]; return ret; } /* Indicate that mhd_GET_32BIT_BE does not need aligned pointer */ @@ -548,18 +548,18 @@ mhd_GET_32BIT_BE_UNALIGN (const void *addr) */ #if SIZEOF_UINT_FAST32_T == 4 # define mhd_PUT_UINTFAST32_BE(addr, uif32) \ - mhd_PUT_32BIT_BE ((addr),(uif32)) + mhd_PUT_32BIT_BE ((addr),(uif32)) #elif SIZEOF_UINT_FAST32_T == 8 # define mhd_PUT_UINTFAST32_BE(addr, uif32) \ - mhd_PUT_64BIT_BE ((addr),(uif32)) + mhd_PUT_64BIT_BE ((addr),(uif32)) #else /* future-proof */ mhd_static_inline void mhd_PUT_UINTFAST32_BE(void *addr, uint_fast32_t uif32) { - uint8_t *const dst = (uint8_t *) addr; + uint8_t *const dst = (uint8_t *)addr; size_t i; for (i = 0; i < sizeof(uif32); ++i) - dst[i] = (uint8_t) (uif32 >> ((sizeof(uif32) - 1 - i) * 8)); + dst[i] = (uint8_t)(uif32 >> ((sizeof(uif32) - 1 - i) * 8)); } #endif @@ -568,10 +568,10 @@ mhd_PUT_UINTFAST32_BE(void *addr, uint_fast32_t uif32) */ #if SIZEOF_UINT_FAST32_T == 4 # define mhd_GET_UINTFAST32_BE(addr) \ - mhd_GET_32BIT_BE ((addr)) + mhd_GET_32BIT_BE ((addr)) #elif SIZEOF_UINT_FAST32_T == 8 # define mhd_GET_UINTFAST32_BE(addr) \ - mhd_GET_64BIT_BE ((addr)) + mhd_GET_64BIT_BE ((addr)) #else /* future-proof */ mhd_static_inline uint_fast32_t mhd_GET_UINTFAST32_BE(const void *addr) @@ -582,7 +582,7 @@ mhd_GET_UINTFAST32_BE(const void *addr) for (i = 0; i < sizeof(ret); ++i) { ret <<= 8u; - ret |= (uint_fast32_t) (((const uint8_t*) addr)[i]); + ret |= (uint_fast32_t)(((const uint8_t *)addr)[i]); } return ret; } @@ -595,18 +595,18 @@ mhd_GET_UINTFAST32_BE(const void *addr) */ #if mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_PUT_16BIT_BE(addr, value16) \ - ((*(uint16_t*) (addr)) = (uint16_t) (value16)) + ((*(uint16_t*) (addr)) = (uint16_t) (value16)) #elif mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_PUT_16BIT_BE(addr, value16) \ - ((*(uint16_t*) (addr)) = mhd_BYTES_SWAP16 (value16)) + ((*(uint16_t*) (addr)) = mhd_BYTES_SWAP16 (value16)) #else /* mhd_BYTE_ORDER != mhd_LITTLE_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ mhd_static_inline void mhd_PUT_16BIT_BE(void *addr, uint16_t value16) { - uint8_t *const dst = (uint8_t *) addr; - dst[0] = (uint8_t) (value16 >> 8u); - dst[1] = (uint8_t) (value16 >> 0u); + uint8_t *const dst = (uint8_t *)addr; + dst[0] = (uint8_t)(value16 >> 8u); + dst[1] = (uint8_t)(value16 >> 0u); } /* Indicate that mhd_PUT_16BIT_BE does not need aligned pointer */ # define mhd_PUT_16BIT_BE_ALLOW_UNALIGNED 1 @@ -615,13 +615,13 @@ mhd_PUT_16BIT_BE(void *addr, uint16_t value16) /* Put result safely to unaligned address */ #ifdef mhd_PUT_16BIT_BE_ALLOW_UNALIGNED # define mhd_PUT_16BIT_BE_UNALIGN(addr, value16) \ - mhd_PUT_16BIT_BE ((addr),(value16)) + mhd_PUT_16BIT_BE ((addr),(value16)) #else /* ! mhd_PUT_16BIT_BE_ALLOW_UNALIGNED */ # define mhd_PUT_16BIT_BE_UNALIGN(addr, value16) \ - do { uint16_t mhd__aligned_dst; \ - mhd_PUT_16BIT_BE (&mhd__aligned_dst, (value16)); \ - memcpy ((addr), &mhd__aligned_dst, \ - sizeof(mhd__aligned_dst)); } while (0) + do { uint16_t mhd__aligned_dst; \ + mhd_PUT_16BIT_BE (&mhd__aligned_dst, (value16)); \ + memcpy ((addr), &mhd__aligned_dst, \ + sizeof(mhd__aligned_dst)); } while (0) #endif /* ! mhd_PUT_16BIT_BE_ALLOW_UNALIGNED */ @@ -630,17 +630,17 @@ mhd_PUT_16BIT_BE(void *addr, uint16_t value16) */ #if mhd_BYTE_ORDER == mhd_BIG_ENDIAN # define mhd_GET_16BIT_BE(addr) \ - (*(const uint16_t*) (addr)) + (*(const uint16_t*) (addr)) #elif mhd_BYTE_ORDER == mhd_LITTLE_ENDIAN # define mhd_GET_16BIT_BE(addr) \ - mhd_BYTES_SWAP16 (*(const uint16_t*) (addr)) + mhd_BYTES_SWAP16 (*(const uint16_t*) (addr)) #else /* mhd_BYTE_ORDER != mhd_LITTLE_ENDIAN */ /* Endianness was not detected or non-standard like PDP-endian */ mhd_static_inline uint16_t mhd_GET_16BIT_BE(const void *addr) { - const uint8_t *const src = (const uint8_t *) addr; - return (uint16_t) ((((uint16_t) src[0]) << 8u) | ((uint16_t) src[1])); + const uint8_t *const src = (const uint8_t *)addr; + return (uint16_t)((((uint16_t)src[0]) << 8u) | ((uint16_t)src[1])); } /* Indicate that mhd_GET_16BIT_BE does not need aligned pointer */ # define mhd_GET_16BIT_BE_ALLOW_UNALIGNED 1 @@ -669,13 +669,13 @@ mhd_GET_16BIT_BE_UNALIGN (const void *addr) # pragma intrinsic(_rotr) # endif /* ! __clang__ */ # define mhd_ROTR32(value32, bits) \ - ((uint32_t) _rotr ((uint32_t) (value32), (int) (bits))) + ((uint32_t) _rotr ((uint32_t) (value32), (int) (bits))) #elif mhd_HAS_BUILTIN (__builtin_stdc_rotate_right) # define mhd_ROTR32(value32, bits) \ - (__builtin_stdc_rotate_right ((uint32_t) (value32), (bits))) + (__builtin_stdc_rotate_right ((uint32_t) (value32), (bits))) #elif mhd_HAS_BUILTIN (__builtin_rotateright32) # define mhd_ROTR32(value32, bits) \ - ((uint32_t) __builtin_rotateright32 ((value32), (bits))) + ((uint32_t) __builtin_rotateright32 ((value32), (bits))) #else /* ! __builtin_rotateright32 */ mhd_static_inline uint32_t mhd_ROTR32 (uint32_t value32, unsigned int bits) @@ -696,13 +696,13 @@ mhd_ROTR32 (uint32_t value32, unsigned int bits) # pragma intrinsic(_rotl) # endif /* ! __clang__ */ # define mhd_ROTL32(value32, bits) \ - ((uint32_t) _rotl ((uint32_t) (value32), (int) (bits))) + ((uint32_t) _rotl ((uint32_t) (value32), (int) (bits))) #elif mhd_HAS_BUILTIN (__builtin_stdc_rotate_left) # define mhd_ROTL32(value32, bits) \ - (__builtin_stdc_rotate_left ((uint32_t) (value32), (bits))) + (__builtin_stdc_rotate_left ((uint32_t) (value32), (bits))) #elif mhd_HAS_BUILTIN (__builtin_rotateleft32) # define mhd_ROTL32(value32, bits) \ - ((uint32_t) __builtin_rotateleft32 ((value32), (bits))) + ((uint32_t) __builtin_rotateleft32 ((value32), (bits))) #else /* ! __builtin_rotateleft32 */ mhd_static_inline uint32_t mhd_ROTL32 (uint32_t value32, unsigned int bits) @@ -723,13 +723,13 @@ mhd_ROTL32 (uint32_t value32, unsigned int bits) # pragma intrinsic(_rotr64) # endif /* ! __clang__ */ # define mhd_ROTR64(value64, bits) \ - ((uint64_t) _rotr64 ((uint64_t) (value64), (int) (bits))) + ((uint64_t) _rotr64 ((uint64_t) (value64), (int) (bits))) #elif mhd_HAS_BUILTIN (__builtin_stdc_rotate_right) # define mhd_ROTR64(value64, bits) \ - (__builtin_stdc_rotate_right ((uint64_t) (value64), (bits))) + (__builtin_stdc_rotate_right ((uint64_t) (value64), (bits))) #elif mhd_HAS_BUILTIN (__builtin_rotateright64) # define mhd_ROTR64(value64, bits) \ - ((uint64_t) __builtin_rotateright64 ((value64), (bits))) + ((uint64_t) __builtin_rotateright64 ((value64), (bits))) #else /* ! __builtin_rotateright64 */ mhd_static_inline uint64_t mhd_ROTR64 (uint64_t value64, unsigned int bits) @@ -749,18 +749,18 @@ mhd_ROTR64 (uint64_t value64, unsigned int bits) */ #if defined(MHD_HAVE___BUILTIN_CLZ) && 4 == SIZEOF_UNSIGNED_INT # define mhd_LEADING_ZEROS32NZ(val32) \ - ((uint_least8_t) __builtin_clz ((unsigned int) (val32))) + ((uint_least8_t) __builtin_clz ((unsigned int) (val32))) #elif defined(MHD_HAVE___BUILTIN_CLZL) && 4 == SIZEOF_UNSIGNED_LONG # define mhd_LEADING_ZEROS32NZ(val32) \ - ((uint_least8_t) __builtin_clzl ((unsigned long) (val32))) + ((uint_least8_t) __builtin_clzl ((unsigned long) (val32))) #elif defined(MHD_HAVE___BUILTIN_CLZG1) && 4 <= SIZEOF_UINT_LEAST32_T # if 4 == SIZEOF_UINT_LEAST32_T # define mhd_LEADING_ZEROS32NZ(val32) \ - ((uint_least8_t) __builtin_clzg ((uint_least32_t) (val32))) + ((uint_least8_t) __builtin_clzg ((uint_least32_t) (val32))) # else /* 4 < SIZEOF_UINT_LEAST32_T */ # define mhd_LEADING_ZEROS32NZ(val32) \ - ((uint_least8_t) (__builtin_clzg ((uint_least32_t) (val32)) \ - - ((sizeof(uint_least32_t) - 4u) * 8u))) + ((uint_least8_t) (__builtin_clzg ((uint_least32_t) (val32)) \ + - ((sizeof(uint_least32_t) - 4u) * 8u))) # endif /* 4 < SIZEOF_UINT_LEAST32_T */ #endif /* MHD_HAVE___BUILTIN_CLZG1 && 4 <= SIZEOF_UINT_LEAST32_T */ @@ -782,8 +782,8 @@ mhd_static_inline uint_least8_t mhd_bh_func_bit_width32nz(uint_least32_t val32) { unsigned long idx; - (void) _BitScanReverse(&idx, (unsigned long) val32); - return (uint_least8_t) (idx + 1u); + (void)_BitScanReverse(&idx, (unsigned long)val32); + return (uint_least8_t)(idx + 1u); } # define mhd_BIT_WIDTH32NZ(val32) mhd_bh_func_bit_width32nz ((val32)) #endif /* mhd_HAS_VC_INTRINSICS && 4 == SIZEOF_UNSIGNED_LONG && (x86 || ARM) */ @@ -799,34 +799,34 @@ mhd_bh_func_bit_width32nz(uint_least32_t val32) #if defined(MHD_HAVE___BUILTIN_CLZG2) && 4 <= SIZEOF_UINT_LEAST32_T # if 4 == SIZEOF_UINT_LEAST32_T # define mhd_LEADING_ZEROS32(val32) \ - ((uint_least8_t) __builtin_clzg ((uint_least32_t) (val32),32u)) + ((uint_least8_t) __builtin_clzg ((uint_least32_t) (val32),32u)) # else /* 4 < SIZEOF_UINT_LEAST32_T */ # define mhd_LEADING_ZEROS32(val32) \ - ((uint_least8_t) (__builtin_clzg ((uint_least32_t) (val32), \ - sizeof(uint_least32_t) * 8u) \ - - ((sizeof(uint_least32_t) - 4u) * 8u))) + ((uint_least8_t) (__builtin_clzg ((uint_least32_t) (val32), \ + sizeof(uint_least32_t) * 8u) \ + - ((sizeof(uint_least32_t) - 4u) * 8u))) # endif /* 4 < SIZEOF_UINT_LEAST32_T */ #elif defined(mhd_HAS_VC_INTRINSICS) && 4 == SIZEOF_UNSIGNED_LONG && \ (defined(_M_ARM) || defined(_M_ARM64) \ || defined(__arm__) || defined(__aarch64__)) && \ - ( (! defined(__clang__)) \ - || (((__clang_major__ + 0) >= 18) && defined(__aarch64__)) ) + ((!defined(__clang__)) \ + || (((__clang_major__ + 0) >= 18) && defined(__aarch64__))) /* Support for _CountLeadingZeros() was added only in clang 18 */ # ifndef __clang__ # pragma intrinsic(_CountLeadingZeros) # endif /* ! __clang__ */ # define mhd_LEADING_ZEROS32(val32) \ - ((uint_least8_t) _CountLeadingZeros ((unsigned long) (val32))) + ((uint_least8_t) _CountLeadingZeros ((unsigned long) (val32))) #elif mhd_HAS_BUILTIN (__builtin_stdc_leading_zeros) # if 4 == SIZEOF_UINT_LEAST32_T # define mhd_LEADING_ZEROS32(val32) \ - ((uint_least8_t) \ - __builtin_stdc_leading_zeros ((uint_least32_t) (val32))) + ((uint_least8_t) \ + __builtin_stdc_leading_zeros ((uint_least32_t) (val32))) # else /* 4 < SIZEOF_UINT_LEAST32_T */ # define mhd_LEADING_ZEROS32(val32) \ - ((uint_least8_t) \ - (__builtin_stdc_leading_zeros ((uint_least32_t) (val32)) \ - - ((sizeof(uint_least32_t) - 4u) * 8u))) + ((uint_least8_t) \ + (__builtin_stdc_leading_zeros ((uint_least32_t) (val32)) \ + - ((sizeof(uint_least32_t) - 4u) * 8u))) # endif /* 4 < SIZEOF_UINT_LEAST32_T */ #endif /* __builtin_stdc_leading_zeros */ @@ -849,14 +849,14 @@ mhd_static_inline uint_least8_t mhd_bh_func_bit_width32(uint_least32_t val32) { unsigned long idx; - if (0 == _BitScanReverse(&idx, (unsigned long) val32)) + if (0 == _BitScanReverse(&idx, (unsigned long)val32)) return 0u; - return (uint_least8_t) (idx + 1u); + return (uint_least8_t)(idx + 1u); } # define mhd_BIT_WIDTH32(val32) mhd_bh_func_bit_width32 ((val32)) #elif mhd_HAS_BUILTIN (__builtin_stdc_bit_width) # define mhd_BIT_WIDTH32(val32) \ - ((uint_least8_t) __builtin_stdc_bit_width ((uint_least32_t) (val32))) + ((uint_least8_t) __builtin_stdc_bit_width ((uint_least32_t) (val32))) #endif /* __builtin_stdc_bit_width */ @@ -864,38 +864,38 @@ mhd_bh_func_bit_width32(uint_least32_t val32) #ifndef mhd_LEADING_ZEROS32NZ # ifdef mhd_BIT_WIDTH32NZ # define mhd_LEADING_ZEROS32NZ(val32) \ - ((uint_least8_t) (32u - mhd_BIT_WIDTH32NZ ((val32)))) + ((uint_least8_t) (32u - mhd_BIT_WIDTH32NZ ((val32)))) # endif /* mhd_BIT_WIDTH32NZ */ #endif /* ! mhd_LEADING_ZEROS32NZ */ #ifndef mhd_BIT_WIDTH32NZ # ifdef mhd_LEADING_ZEROS32NZ # define mhd_BIT_WIDTH32NZ(val32) \ - ((uint_least8_t) (32u - mhd_LEADING_ZEROS32NZ ((val32)))) + ((uint_least8_t) (32u - mhd_LEADING_ZEROS32NZ ((val32)))) # endif /* mhd_LEADING_ZEROS32NZ */ #endif /* ! mhd_BIT_WIDTH32NZ */ #ifndef mhd_LEADING_ZEROS32 # ifdef mhd_BIT_WIDTH32 # define mhd_LEADING_ZEROS32(val32) \ - ((uint_least8_t) (32u - mhd_BIT_WIDTH32 ((val32)))) + ((uint_least8_t) (32u - mhd_BIT_WIDTH32 ((val32)))) # endif /* mhd_BIT_WIDTH32 */ #endif /* ! mhd_LEADING_ZEROS32 */ #ifndef mhd_BIT_WIDTH32 # ifdef mhd_LEADING_ZEROS32 # define mhd_BIT_WIDTH32(val32) \ - ((uint_least8_t) (32u - mhd_LEADING_ZEROS32 ((val32)))) + ((uint_least8_t) (32u - mhd_LEADING_ZEROS32 ((val32)))) # endif /* mhd_LEADING_ZEROS32 */ #endif /* ! mhd_BIT_WIDTH32 */ -#if ! defined(mhd_LEADING_ZEROS32NZ) +#if !defined(mhd_LEADING_ZEROS32NZ) # ifdef mhd_LEADING_ZEROS32 # define mhd_LEADING_ZEROS32NZ(val32) mhd_LEADING_ZEROS32 ((val32)) # define mhd_BIT_WIDTH32NZ(val32) mhd_BIT_WIDTH32 ((val32)) # endif /* mhd_LEADING_ZEROS32 */ #else /* mhd_LEADING_ZEROS32NZ */ -# if ! defined(mhd_LEADING_ZEROS32) +# if !defined(mhd_LEADING_ZEROS32) mhd_static_inline uint_least8_t mhd_bh_func_leading_zeros32(uint_least32_t val32) @@ -922,17 +922,17 @@ mhd_bh_func_bit_width32(uint_least32_t val32) || defined(mhd_LEADING_ZEROS32) || defined(mhd_BIT_WIDTH32) /* If at least one compiler-optimised function is detected, all macros must be defined as all of them can be based on a single base function. */ -# if ! defined(mhd_LEADING_ZEROS32NZ) -#error mhd_LEADING_ZEROS32NZ() must be defined +# if !defined(mhd_LEADING_ZEROS32NZ) +# error mhd_LEADING_ZEROS32NZ() must be defined # endif -# if ! defined(mhd_BIT_WIDTH32NZ) -#error mhd_BIT_WIDTH32NZ() must be defined +# if !defined(mhd_BIT_WIDTH32NZ) +# error mhd_BIT_WIDTH32NZ() must be defined # endif -# if ! defined(mhd_LEADING_ZEROS32) -#error mhd_LEADING_ZEROS32() must be defined +# if !defined(mhd_LEADING_ZEROS32) +# error mhd_LEADING_ZEROS32() must be defined # endif -# if ! defined(mhd_BIT_WIDTH32) -#error mhd_BIT_WIDTH32() must be defined +# if !defined(mhd_BIT_WIDTH32) +# error mhd_BIT_WIDTH32() must be defined # endif #else /* No compiler-optimised base version. Use fallback implementation. */ @@ -943,41 +943,41 @@ mhd_bh_func_bit_width32(uint_least32_t val32) { uint_fast8_t cal_width = 0u; uint_fast8_t check_bits; - uint_fast32_t val_left = (uint_fast32_t) (val32 & 0xFFFFFFFFu); + uint_fast32_t val_left = (uint_fast32_t)(val32 & 0xFFFFFFFFu); mhd_assert (val32 == val_left); /* Branchless code without any tables. Should have a good performance even with a cold cache. */ - check_bits = (uint_fast8_t) ((0 != (val_left >> 16u)) * 16u); + check_bits = (uint_fast8_t)((0 != (val_left >> 16u)) * 16u); cal_width += check_bits; val_left >>= check_bits; - check_bits = (uint_fast8_t) ((0 != (val_left >> 8u)) * 8u); + check_bits = (uint_fast8_t)((0 != (val_left >> 8u)) * 8u); cal_width += check_bits; val_left >>= check_bits; - check_bits = (uint_fast8_t) ((0 != (val_left >> 4u)) * 4u); + check_bits = (uint_fast8_t)((0 != (val_left >> 4u)) * 4u); cal_width += check_bits; val_left >>= check_bits; - check_bits = (uint_fast8_t) ((0 != (val_left >> 2u)) * 2u); + check_bits = (uint_fast8_t)((0 != (val_left >> 2u)) * 2u); cal_width += check_bits; val_left >>= check_bits; - check_bits = (uint_fast8_t) ((0 != (val_left >> 1u)) * 1u); + check_bits = (uint_fast8_t)((0 != (val_left >> 1u)) * 1u); cal_width += check_bits; val_left >>= check_bits; - return (uint_least8_t) (cal_width + val_left); + return (uint_least8_t)(cal_width + val_left); } # define mhd_LEADING_ZEROS32NZ(val32) \ - ((uint_least8_t) \ - (32u - mhd_bh_func_bit_width32 ((uint_least32_t) (val32)))) + ((uint_least8_t) \ + (32u - mhd_bh_func_bit_width32 ((uint_least32_t) (val32)))) # define mhd_BIT_WIDTH32NZ(val32) mhd_bh_func_bit_width32 ((val32)) # define mhd_LEADING_ZEROS32(val32) \ - ((uint_least8_t) \ - (32u - mhd_bh_func_bit_width32 ((uint_least32_t) (val32)))) + ((uint_least8_t) \ + (32u - mhd_bh_func_bit_width32 ((uint_least32_t) (val32)))) # define mhd_BIT_WIDTH32(val32) mhd_bh_func_bit_width32 ((val32)) #endif @@ -993,11 +993,11 @@ mhd_bh_func_bit_width32(uint_least32_t val32) #if mhd_HAS_BUILTIN (__builtin_stdc_leading_ones) && \ 4 == SIZEOF_UINT_LEAST32_T # define mhd_LEADING_ONES32(val32) \ - ((uint_least8_t) __builtin_stdc_leading_ones ((uint_least32_t) (val32))) + ((uint_least8_t) __builtin_stdc_leading_ones ((uint_least32_t) (val32))) #else /* ! __builtin_stdc_leading_ones || 4 != SIZEOF_UINT_LEAST32_T */ # define mhd_LEADING_ONES32(val32) \ - mhd_LEADING_ZEROS32 ((uint_least32_t) \ - (0xFFFFFFFFu & ~((uint_least32_t) (val32)))) + mhd_LEADING_ZEROS32 ((uint_least32_t) \ + (0xFFFFFFFFu & ~((uint_least32_t) (val32)))) #endif /* ! __builtin_stdc_leading_ones || 4 != SIZEOF_UINT_LEAST32_T */ @@ -1005,7 +1005,7 @@ mhd_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE #if defined(_MSC_FULL_VER) /* Restore warnings */ -#pragma warning(pop) +# pragma warning(pop) #endif /* _MSC_FULL_VER */ #endif /* ! MHD_BITHELPERS_H */ diff --git a/src/mhd2/mhd_bool.h b/src/mhd2/mhd_bool.h @@ -66,7 +66,7 @@ enum MHD_Bool }; -#define MHD_BOOL_DEFINED 1 +# define MHD_BOOL_DEFINED 1 #endif /* ! MHD_BOOL_DEFINED */ #endif /* ! MHD_BOOL_H */ diff --git a/src/mhd2/mhd_byteorder.h b/src/mhd2/mhd_byteorder.h @@ -130,12 +130,12 @@ /* Byte order specification didn't detected in system headers */ /* Try some guessing */ -# if (defined(__BIG_ENDIAN__) && ! defined(__LITTLE_ENDIAN__)) || \ - (defined(_BIG_ENDIAN) && ! defined(_LITTLE_ENDIAN)) +# if (defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)) || \ + (defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)) /* Seems that this is a big endian platform */ # define mhd_BYTE_ORDER mhd_BIG_ENDIAN -# elif (defined(__LITTLE_ENDIAN__) && ! defined(__BIG_ENDIAN__)) || \ - (defined(_LITTLE_ENDIAN) && ! defined(_BIG_ENDIAN)) +# elif (defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \ + (defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)) /* Seems that this is a little endian platform */ # define mhd_BYTE_ORDER mhd_LITTLE_ENDIAN # elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || \ @@ -165,10 +165,10 @@ defined(_M_IA64) || defined(__itanium__) || defined(__bfin__) || \ defined(__BFIN__) || defined(bfin) || defined(BFIN) /* Looks like this is a little endian platform */ -# define mhd_BYTE_ORDER mhd_LITTLE_ENDIAN +# define mhd_BYTE_ORDER mhd_LITTLE_ENDIAN # elif defined(_WIN32) /* W32 is always little endian on all platforms, except XBOX 360 */ -# if ! defined(_M_PPC) && ! defined(XBOX360) +# if !defined(_M_PPC) && !defined(XBOX360) # define mhd_BYTE_ORDER mhd_LITTLE_ENDIAN # endif # elif defined(WORDS_BIGENDIAN) @@ -180,9 +180,9 @@ #ifdef mhd_BYTE_ORDER /* Some sanity checks */ # if defined(WORDS_BIGENDIAN) && mhd_BYTE_ORDER != mhd_BIG_ENDIAN -#error Configure found big endian but headers specify different order -# elif ! defined(WORDS_BIGENDIAN) && mhd_BYTE_ORDER == mhd_BIG_ENDIAN -#error Headers specify big endian but configure did not detect it +# error Configure found big endian but headers specify different order +# elif !defined(WORDS_BIGENDIAN) && mhd_BYTE_ORDER == mhd_BIG_ENDIAN +# error Headers specify big endian but configure did not detect it # endif /* !WORDS_BIGENDIAN && mhd_BYTE_ORDER == mhd_BIG_ENDIAN */ #endif /* mhd_BYTE_ORDER */ diff --git a/src/mhd2/mhd_cntnr_ptr.h b/src/mhd2/mhd_cntnr_ptr.h @@ -63,9 +63,9 @@ * @param membr_name the name of the member pointed by @a membr_ptr * @return the pointer to the outer structure */ -#define mhd_CNTNR_PTR(membr_ptr,cntnr_type,membr_name) \ - ((cntnr_type*) (void*) \ - (((char*) (0 ? \ +#define mhd_CNTNR_PTR(membr_ptr, cntnr_type, membr_name) \ + ((cntnr_type*) (void*) \ + (((char*) (0 ? \ (&(((cntnr_type*) NULL)->membr_name)) : \ (membr_ptr))) - offsetof (cntnr_type,membr_name))) @@ -81,9 +81,9 @@ * @param membr_name the name of the member pointed by @a membr_ptr * @return the pointer to the outer structure */ -#define mhd_CNTNR_CPTR(membr_ptr,cntnr_type,membr_name) \ - ((const cntnr_type*) (const void*) \ - (((const char*) (0 ? \ +#define mhd_CNTNR_CPTR(membr_ptr, cntnr_type, membr_name) \ + ((const cntnr_type*) (const void*) \ + (((const char*) (0 ? \ (&(((cntnr_type*) NULL)->membr_name)) : \ (membr_ptr))) - offsetof (cntnr_type,membr_name))) diff --git a/src/mhd2/mhd_conn_socket.h b/src/mhd2/mhd_conn_socket.h @@ -84,20 +84,20 @@ enum MHD_FIXED_FLAGS_ENUM_ mhd_SocketNetState }; -#define mhd_SCKT_NET_ST_CLEAR_FLAG(p_scktns,flag) \ +#define mhd_SCKT_NET_ST_CLEAR_FLAG(p_scktns, flag) \ ((*p_scktns) = \ (enum mhd_SocketNetState) \ ((~((unsigned int) ((enum mhd_SocketNetState) (flag)))) \ & ((unsigned int) (*p_scktns))) ) -#define mhd_SCKT_NET_ST_SET_FLAG(p_scktns,flag) \ +#define mhd_SCKT_NET_ST_SET_FLAG(p_scktns, flag) \ ((*p_scktns) = \ - (enum mhd_SocketNetState) \ + (enum mhd_SocketNetState) \ (((unsigned int) (flag)) | ((unsigned int) (*p_scktns))) ) -#define mhd_SCKT_NET_ST_HAS_FLAG(scktns,flag) \ +#define mhd_SCKT_NET_ST_HAS_FLAG(scktns, flag) \ (0 != (((unsigned int) (flag)) & ((unsigned int) (scktns))) ) diff --git a/src/mhd2/mhd_connection.h b/src/mhd2/mhd_connection.h @@ -596,7 +596,7 @@ struct mhd_ConnTimeoutData /** * The list of connections sorted by timeout */ - mhd_DLNKDL_LINKS (MHD_Connection,tmout_list); + mhd_DLNKDL_LINKS (MHD_Connection, tmout_list); /** * Set to 'true' if this connection is in daemon's 'custom timeout list'. @@ -645,7 +645,7 @@ struct MHD_Connection /** * The list with all daemon's connections */ - mhd_DLNKDL_LINKS (MHD_Connection,all_conn); + mhd_DLNKDL_LINKS (MHD_Connection, all_conn); /** * The connection socket data @@ -700,7 +700,7 @@ struct MHD_Connection /** * The list with all daemon's connections that ready to processing */ - mhd_DLNKDL_LINKS (MHD_Connection,proc_ready); + mhd_DLNKDL_LINKS (MHD_Connection, proc_ready); /** * Connection's activity timeout data @@ -716,7 +716,7 @@ struct MHD_Connection /** * Double-linked list of HTTP-Upgraded connections waiting for clean-up */ - mhd_DLNKDL_LINKS (MHD_Connection,upgr_cleanup); + mhd_DLNKDL_LINKS (MHD_Connection, upgr_cleanup); #endif /* MHD_SUPPORT_UPGRADE */ /** @@ -899,7 +899,7 @@ struct MHD_Connection * pending in TLS buffers */ # define mhd_C_HAS_TLS_DATA_IN(c) \ - (((c)->tls) ? ((unsigned int) ((c)->tls_has_data_in)) : (0u)) + (((c)->tls) ? ((unsigned int) ((c)->tls_has_data_in)) : (0u)) #else /* ! MHD_SUPPORT_HTTPS */ /** * Returns #mhd_SOCKET_NET_STATE_RECV_READY if connection has incoming data @@ -910,7 +910,7 @@ struct MHD_Connection #ifdef MHD_SUPPORT_HTTP2 # define mhd_C_IS_HTTP2(c) \ - (mhd_HTTP_VER_FAM_2 == c->h_layer.fam) + (mhd_HTTP_VER_FAM_2 == c->h_layer.fam) #else /* ! MHD_SUPPORT_HTTP2 */ # define mhd_C_IS_HTTP2(c) (! ! 0) #endif /* ! MHD_SUPPORT_HTTP2 */ diff --git a/src/mhd2/mhd_daemon.h b/src/mhd2/mhd_daemon.h @@ -190,17 +190,17 @@ enum MHD_FIXED_ENUM_ mhd_WorkModeIntType * either directly controlled or indirectly, via additional workers daemons. */ # define mhd_WM_INT_HAS_THREADS(wm_i) \ - (mhd_WM_INT_INTERNAL_EVENTS_ONE_THREAD <= wm_i) + (mhd_WM_INT_INTERNAL_EVENTS_ONE_THREAD <= wm_i) /** * Check whether given mhd_WorkModeIntType value equals "thread-per-connection" */ # define mhd_WM_INT_IS_THREAD_PER_CONN(wm_i) \ - (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION == wm_i) + (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION == wm_i) /** * Check whether given mhd_WorkModeIntType value equals "thread pool" */ # define mhd_WM_INT_IS_THREAD_POOL(wm_i) \ - (mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL == wm_i) + (mhd_WM_INT_INTERNAL_EVENTS_THREAD_POOL == wm_i) #else /* ! MHD_SUPPORT_THREADS */ # define mhd_WM_INT_HAS_THREADS(wm_i) (0) # define mhd_WM_INT_IS_THREAD_PER_CONN(wm_i) (0) @@ -264,7 +264,7 @@ enum MHD_FIXED_ENUM_ mhd_IntPollType * Check whether provided mhd_IntPollType value is "epoll" */ # define mhd_POLL_TYPE_INT_IS_EPOLL(poll_type) \ - (mhd_POLL_TYPE_EPOLL == (poll_type)) + (mhd_POLL_TYPE_EPOLL == (poll_type)) #else # define mhd_POLL_TYPE_INT_IS_EPOLL(poll_type) (0) #endif @@ -274,7 +274,7 @@ enum MHD_FIXED_ENUM_ mhd_IntPollType * Check whether provided mhd_IntPollType value is "kqueue" */ # define mhd_POLL_TYPE_INT_IS_KQUEUE(poll_type) \ - (mhd_POLL_TYPE_KQUEUE == (poll_type)) + (mhd_POLL_TYPE_KQUEUE == (poll_type)) #else # define mhd_POLL_TYPE_INT_IS_KQUEUE(poll_type) (0) #endif @@ -717,7 +717,7 @@ struct mhd_DaemonEventMonitoringData /** * The list of the daemon's connections that need processing */ - mhd_DLNKDL_LIST (MHD_Connection,proc_ready); + mhd_DLNKDL_LIST (MHD_Connection, proc_ready); /** * The daemon's time data @@ -895,12 +895,12 @@ struct mhd_DaemonAuthDigestData */ struct mhd_AtomicCounter num_gen_nonces; -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS /** * The mutex to change or access the @a nonces data */ mhd_mutex nonces_lock; -#endif +# endif /** * Digest Auth daemon configuration data @@ -923,10 +923,10 @@ enum MHD_FIXED_ENUM_ mhd_DaemonType * This daemon may have a optional single thread, managed by MHD. */ mhd_DAEMON_TYPE_SINGLE -#ifndef NDEBUG +# ifndef NDEBUG = 1 -#endif -#ifdef MHD_SUPPORT_THREADS +# endif +# ifdef MHD_SUPPORT_THREADS , /** * A master daemon, only controlling worker daemons. @@ -949,45 +949,45 @@ enum MHD_FIXED_ENUM_ mhd_DaemonType * to application directly. */ mhd_DAEMON_TYPE_WORKER -#endif /* MHD_SUPPORT_THREADS */ +# endif /* MHD_SUPPORT_THREADS */ }; /** * Check whether the daemon type is allowed to have internal thread with * direct control */ -#define mhd_D_TYPE_IS_VALID(t) \ - ((mhd_DAEMON_TYPE_SINGLE <= (t)) && (mhd_DAEMON_TYPE_WORKER >= (t))) +# define mhd_D_TYPE_IS_VALID(t) \ + ((mhd_DAEMON_TYPE_SINGLE <= (t)) && (mhd_DAEMON_TYPE_WORKER >= (t))) /** * Check whether the daemon type must not be exposed to the application */ -#define mhd_D_TYPE_IS_INTERNAL_ONLY(t) \ - (mhd_DAEMON_TYPE_WORKER == (t)) +# define mhd_D_TYPE_IS_INTERNAL_ONLY(t) \ + (mhd_DAEMON_TYPE_WORKER == (t)) /** * Check whether the daemon type is allowed to process the network data */ -#define mhd_D_TYPE_HAS_EVENTS_PROCESSING(t) \ - (mhd_DAEMON_TYPE_MASTER_CONTROL_ONLY != (t)) +# define mhd_D_TYPE_HAS_EVENTS_PROCESSING(t) \ + (mhd_DAEMON_TYPE_MASTER_CONTROL_ONLY != (t)) /** * Check whether the daemon type must not be exposed to the application */ -#define mhd_D_TYPE_HAS_WORKERS(t) \ - (mhd_DAEMON_TYPE_MASTER_CONTROL_ONLY == (t)) +# define mhd_D_TYPE_HAS_WORKERS(t) \ + (mhd_DAEMON_TYPE_MASTER_CONTROL_ONLY == (t)) /** * Check whether the daemon type has master (controlling) daemon */ -#define mhd_D_TYPE_HAS_MASTER_DAEMON(t) \ - (mhd_DAEMON_TYPE_WORKER == (t)) +# define mhd_D_TYPE_HAS_MASTER_DAEMON(t) \ + (mhd_DAEMON_TYPE_WORKER == (t)) /** * Check whether the daemon is listening only (with connection data * processed in separate threads) */ -#define mhd_D_TYPE_IS_LISTEN_ONLY(t) \ - (mhd_DAEMON_TYPE_LISTEN_ONLY == (t)) +# define mhd_D_TYPE_IS_LISTEN_ONLY(t) \ + (mhd_DAEMON_TYPE_LISTEN_ONLY == (t)) #else /* ! MHD_SUPPORT_THREADS */ @@ -995,33 +995,33 @@ enum MHD_FIXED_ENUM_ mhd_DaemonType * Check whether the daemon type is allowed to have internal thread with * direct control */ -#define mhd_D_TYPE_IS_VALID(t) (! 0) +# define mhd_D_TYPE_IS_VALID(t) (! 0) /** * Check whether the daemon type must not be exposed to the application */ -#define mhd_D_TYPE_IS_INTERNAL_ONLY(t) (0) +# define mhd_D_TYPE_IS_INTERNAL_ONLY(t) (0) /** * Check whether the daemon type is allowed to process the network data */ -#define mhd_D_TYPE_HAS_EVENTS_PROCESSING(t) (! 0) +# define mhd_D_TYPE_HAS_EVENTS_PROCESSING(t) (! 0) /** * Check whether the daemon type must not be exposed to the application */ -#define mhd_D_TYPE_HAS_WORKERS(t) (0) +# define mhd_D_TYPE_HAS_WORKERS(t) (0) /** * Check whether the daemon type has master (controlling) daemon */ -#define mhd_D_TYPE_HAS_MASTER_DAEMON(t) (0) +# define mhd_D_TYPE_HAS_MASTER_DAEMON(t) (0) /** * Check whether the daemon is listening only (with connection data * processed in separate threads) */ -#define mhd_D_TYPE_IS_LISTEN_ONLY(t) (0) +# define mhd_D_TYPE_IS_LISTEN_ONLY(t) (0) #endif /* ! MHD_SUPPORT_THREADS */ @@ -1158,14 +1158,14 @@ struct mhd_DaemonConnectionsUpgraded * The list of HTTP-Upgraded connection closed by application and * queued for cleanup */ - mhd_DLNKDL_LIST (MHD_Connection,upgr_cleanup); + mhd_DLNKDL_LIST (MHD_Connection, upgr_cleanup); -#ifdef MHD_SUPPORT_THREADS +# ifdef MHD_SUPPORT_THREADS /** * The mutex to change or check the @a upgr_cleanup list values */ mhd_mutex ucu_lock; -#endif +# endif }; #endif /* MHD_SUPPORT_UPGRADE */ @@ -1180,17 +1180,17 @@ struct mhd_DaemonConnections * The list of all daemon's connections. * All connection are listed here, expect connection in @a to_clean list. */ - mhd_DLNKDL_LIST (MHD_Connection,all_conn); + mhd_DLNKDL_LIST (MHD_Connection, all_conn); /** * The list of connections sorted by last activity */ - mhd_DLNKDL_LIST (MHD_Connection,def_timeout); + mhd_DLNKDL_LIST (MHD_Connection, def_timeout); /** * The list of connections with custom timeouts */ - mhd_DLNKDL_LIST (MHD_Connection,cust_timeout); + mhd_DLNKDL_LIST (MHD_Connection, cust_timeout); /** * The current number of connections handled by the daemon @@ -1463,11 +1463,11 @@ struct MHD_Daemon /** * Checks whether @a fd socket number fits limitations for the @a d_ptr daemon */ -# define mhd_FD_FITS_DAEMON(d_ptr,fd) \ - ((MHD_INVALID_SOCKET == d_ptr->net.cfg.max_fd_num) || \ - (d_ptr->net.cfg.max_fd_num > fd)) +# define mhd_FD_FITS_DAEMON(d_ptr, fd) \ + ((MHD_INVALID_SOCKET == d_ptr->net.cfg.max_fd_num) || \ + (d_ptr->net.cfg.max_fd_num > fd)) #else -# define mhd_FD_FITS_DAEMON(d_ptr,fd) (! 0) +# define mhd_FD_FITS_DAEMON(d_ptr, fd) (! 0) #endif #define mhd_D_IS_USING_EPOLL(d) \ @@ -1494,8 +1494,8 @@ struct MHD_Daemon #ifdef MHD_SUPPORT_THREADS # define mhd_D_HAS_THR_PER_CONN(d) \ - (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION == \ - ((d)->wmode_int)) + (mhd_WM_INT_INTERNAL_EVENTS_THREAD_PER_CONNECTION == \ + ((d)->wmode_int)) #else # define mhd_D_HAS_THR_PER_CONN(d) (0) #endif diff --git a/src/mhd2/mhd_dbg_print.h b/src/mhd2/mhd_dbg_print.h @@ -89,9 +89,10 @@ MHD_FN_PAR_NONNULL_ALL_; # endif /* MHD_SUPPORT_KQUEUE */ #else /* ! MHD_USE_TRACE_POLLING_FDS */ -# define mhd_dbg_print_fd_mon_req(fd_n,fd,r_ready,w_ready,e_ready) ((void) 0) +# define mhd_dbg_print_fd_mon_req(fd_n, fd, r_ready, w_ready, e_ready) \ + ((void) 0) # ifdef MHD_SUPPORT_KQUEUE -# define mhd_dbg_print_kevent(fd_name,ke,update_req) ((void) 0) +# define mhd_dbg_print_kevent(fd_name, ke, update_req) ((void) 0) # endif /* MHD_SUPPORT_KQUEUE */ #endif /* ! MHD_USE_TRACE_POLLING_FDS */ @@ -101,16 +102,16 @@ MHD_FN_PAR_NONNULL_ALL_; * @param fd_name the name of FD ("ITC", "lstn" or "conn") * @param ke the pointer to kevent */ -# define mhd_dbg_print_kevent_change(fd_name,ke) \ - mhd_dbg_print_kevent ((fd_name),(ke),true) +# define mhd_dbg_print_kevent_change(fd_name, ke) \ + mhd_dbg_print_kevent ((fd_name),(ke),true) /** * Debug print kqueue event report * @param fd_name the name of FD ("ITC", "lstn" or "conn") * @param ke the pointer to kevent */ -# define mhd_dbg_print_kevent_report(fd_name,ke) \ - mhd_dbg_print_kevent ((fd_name),(ke),false) +# define mhd_dbg_print_kevent_report(fd_name, ke) \ + mhd_dbg_print_kevent ((fd_name),(ke),false) #endif /* MHD_SUPPORT_KQUEUE */ #endif /* ! MHD_DBG_PRINT_H */ diff --git a/src/mhd2/mhd_dcc_action.h b/src/mhd2/mhd_dcc_action.h @@ -108,9 +108,9 @@ enum mhd_DccActionType * @ingroup response */ typedef void -(*MHD_FreeCallback) (void *free_cls); +(*MHD_FreeCallback)(void *free_cls); -#define MHD_FREECALLBACK_DEFINED 1 +# define MHD_FREECALLBACK_DEFINED 1 #endif /* ! MHD_FREECALLBACK_DEFINED */ #ifndef MHD_DYNCONTENTZCIOVEC_DEFINED @@ -141,7 +141,7 @@ struct MHD_DynContentZCIoVec void *iov_fcb_cls; }; -#define MHD_DYNCONTENTZCIOVEC_DEFINED 1 +# define MHD_DYNCONTENTZCIOVEC_DEFINED 1 #endif /* ! MHD_DYNCONTENTZCIOVEC_DEFINED */ /** diff --git a/src/mhd2/mhd_dlinked_list.h b/src/mhd2/mhd_dlinked_list.h @@ -104,21 +104,20 @@ * @param l_type the struct tag name of elements that the list holds */ #define mhd_DLINKEDL_LIST_DEF(l_type) \ - mhd_DLNKDL_LIST_TYPE (l_type) { /* Holds the list in the owner */ \ - struct l_type *first; /* The pointer to the first element in the list */ \ - struct l_type *last; /* The pointer to the last element in the list */ \ - } + mhd_DLNKDL_LIST_TYPE (l_type) { /* Holds the list in the owner */ \ + struct l_type *first; /* The pointer to the first element in the list */ \ + struct l_type *last; /* The pointer to the last element in the list */ \ + } /** * Template for declaration of the inter-links helper struct * @param l_type the struct tag name of elements linked by the inter-links */ #define mhd_DLINKEDL_LINKS_DEF(l_type) \ - /* Holds the inter-links in the list element */ \ - mhd_DLNKDL_LINKS_TYPE (l_type) { \ - struct l_type *prev; /* The pointer to the previous element in the list */ \ - struct l_type *next; /* The pointer to the next element in the list */ \ - } + mhd_DLNKDL_LINKS_TYPE (l_type) { /* The inter-links in the list element */ \ + struct l_type *prev; /* The previous element in the list */ \ + struct l_type *next; /* The next element in the list */ \ + } /** * Template for declaration of the list helper structs @@ -133,13 +132,13 @@ /** * Declare the list field in the owner struct */ -#define mhd_DLNKDL_LIST(l_type,list_name) \ +#define mhd_DLNKDL_LIST(l_type, list_name) \ mhd_DLNKDL_LIST_TYPE (l_type) list_name /** * Declare the inter-links field in the list element */ -#define mhd_DLNKDL_LINKS(l_type,links_name) \ +#define mhd_DLNKDL_LINKS(l_type, links_name) \ mhd_DLNKDL_LINKS_TYPE (l_type) links_name /* Direct work with the list */ @@ -165,21 +164,21 @@ * using @a links_name inter-links * @param links_name the name of the inter-links field in the @a p_obj */ -#define mhd_DLINKEDL_INS_FIRST_D(p_list,p_obj,links_name) do { \ - mhd_ASSUME (NULL == (p_obj)->links_name.prev); \ - mhd_ASSUME (NULL == (p_obj)->links_name.next); \ - mhd_ASSUME ((p_obj) != (p_list)->first); \ - mhd_ASSUME ((p_obj) != (p_list)->last); \ - if (NULL != (p_list)->first) \ - { mhd_ASSUME (NULL == (p_list)->first->links_name.prev); \ - mhd_ASSUME (NULL == (p_list)->last->links_name.next); \ - mhd_ASSUME ((p_obj) != (p_list)->first->links_name.next); \ - mhd_ASSUME (NULL != (p_list)->last); \ - ((p_obj)->links_name.next = (p_list)->first) \ - ->links_name.prev = (p_obj); } else \ - { mhd_ASSUME (NULL == (p_list)->last); \ - (p_list)->last = (p_obj); } \ - (p_list)->first = (p_obj); } while (0) +#define mhd_DLINKEDL_INS_FIRST_D(p_list, p_obj, links_name) do { \ + mhd_ASSUME (NULL == (p_obj)->links_name.prev); \ + mhd_ASSUME (NULL == (p_obj)->links_name.next); \ + mhd_ASSUME ((p_obj) != (p_list)->first); \ + mhd_ASSUME ((p_obj) != (p_list)->last); \ + if (NULL != (p_list)->first) \ + { mhd_ASSUME (NULL == (p_list)->first->links_name.prev); \ + mhd_ASSUME (NULL == (p_list)->last->links_name.next); \ + mhd_ASSUME ((p_obj) != (p_list)->first->links_name.next); \ + mhd_ASSUME (NULL != (p_list)->last); \ + ((p_obj)->links_name.next = (p_list)->first) \ + ->links_name.prev = (p_obj); } else \ + { mhd_ASSUME (NULL == (p_list)->last); \ + (p_list)->last = (p_obj); } \ + (p_list)->first = (p_obj); } while (0) /** * Insert new list element into the last position in the list using direct @@ -190,21 +189,21 @@ * using @a links_name inter-links * @param links_name the name of the inter-links field in the @a p_obj */ -#define mhd_DLINKEDL_INS_LAST_D(p_list,p_obj,links_name) do { \ - mhd_ASSUME (NULL == (p_obj)->links_name.prev); \ - mhd_ASSUME (NULL == (p_obj)->links_name.next); \ - mhd_ASSUME ((p_obj) != (p_list)->first); \ - mhd_ASSUME ((p_obj) != (p_list)->last); \ - if (NULL != (p_list)->last) \ - { mhd_ASSUME (NULL == (p_list)->last->links_name.next); \ - mhd_ASSUME (NULL == (p_list)->first->links_name.prev); \ - mhd_ASSUME ((p_obj) != (p_list)->last->links_name.prev); \ - mhd_ASSUME (NULL != (p_list)->first); \ - ((p_obj)->links_name.prev = (p_list)->last) \ - ->links_name.next = (p_obj); } else \ - { mhd_ASSUME (NULL == (p_list)->first); \ - (p_list)->first = (p_obj); } \ - (p_list)->last = (p_obj); } while (0) +#define mhd_DLINKEDL_INS_LAST_D(p_list, p_obj, links_name) do { \ + mhd_ASSUME (NULL == (p_obj)->links_name.prev); \ + mhd_ASSUME (NULL == (p_obj)->links_name.next); \ + mhd_ASSUME ((p_obj) != (p_list)->first); \ + mhd_ASSUME ((p_obj) != (p_list)->last); \ + if (NULL != (p_list)->last) \ + { mhd_ASSUME (NULL == (p_list)->last->links_name.next); \ + mhd_ASSUME (NULL == (p_list)->first->links_name.prev); \ + mhd_ASSUME ((p_obj) != (p_list)->last->links_name.prev); \ + mhd_ASSUME (NULL != (p_list)->first); \ + ((p_obj)->links_name.prev = (p_list)->last) \ + ->links_name.next = (p_obj); } else \ + { mhd_ASSUME (NULL == (p_list)->first); \ + (p_list)->first = (p_obj); } \ + (p_list)->last = (p_obj); } while (0) /** * Remove list element from the list using direct pointer to the list @@ -213,35 +212,35 @@ * @param p_obj the pointer to the existing list element to remove from the list * @param links_name the name of the inter-links field in the @a p_obj */ -#define mhd_DLINKEDL_DEL_D(p_list,p_obj,links_name) do { \ - mhd_ASSUME (NULL != (p_list)->first); \ - mhd_ASSUME (NULL != (p_list)->last); \ - mhd_ASSUME (NULL == (p_list)->first->links_name.prev); \ - mhd_ASSUME (NULL == (p_list)->last->links_name.next); \ - mhd_ASSUME ((p_obj) != (p_obj)->links_name.prev); \ - mhd_ASSUME ((p_list)->last != (p_obj)->links_name.prev); \ - mhd_ASSUME ((p_obj) != (p_obj)->links_name.next); \ - mhd_ASSUME ((p_list)->first != (p_obj)->links_name.next); \ - if (NULL != (p_obj)->links_name.next) \ - { mhd_ASSUME ((p_obj) == (p_obj)->links_name.next->links_name.prev); \ - mhd_ASSUME ((p_obj) != (p_list)->last); \ - mhd_ASSUME ((p_obj)->links_name.next != \ - (p_obj)->links_name.prev); \ - (p_obj)->links_name.next->links_name.prev = \ - (p_obj)->links_name.prev; } else \ - { mhd_ASSUME ((p_obj) == (p_list)->last); \ - (p_list)->last = (p_obj)->links_name.prev; } \ - if (NULL != (p_obj)->links_name.prev) \ - { mhd_ASSUME ((p_obj) == (p_obj)->links_name.prev->links_name.next); \ - mhd_ASSUME ((p_obj) != (p_list)->first); \ - mhd_ASSUME ((p_obj)->links_name.next != \ - (p_obj)->links_name.prev); \ - (p_obj)->links_name.prev->links_name.next = \ - (p_obj)->links_name.next; } else \ - { mhd_ASSUME ((p_obj) == (p_list)->first); \ - (p_list)->first = (p_obj)->links_name.next; } \ - (p_obj)->links_name.prev = NULL; \ - (p_obj)->links_name.next = NULL; } while (0) +#define mhd_DLINKEDL_DEL_D(p_list, p_obj, links_name) do { \ + mhd_ASSUME (NULL != (p_list)->first); \ + mhd_ASSUME (NULL != (p_list)->last); \ + mhd_ASSUME (NULL == (p_list)->first->links_name.prev); \ + mhd_ASSUME (NULL == (p_list)->last->links_name.next); \ + mhd_ASSUME ((p_obj) != (p_obj)->links_name.prev); \ + mhd_ASSUME ((p_list)->last != (p_obj)->links_name.prev); \ + mhd_ASSUME ((p_obj) != (p_obj)->links_name.next); \ + mhd_ASSUME ((p_list)->first != (p_obj)->links_name.next); \ + if (NULL != (p_obj)->links_name.next) \ + { mhd_ASSUME ((p_obj) == (p_obj)->links_name.next->links_name.prev); \ + mhd_ASSUME ((p_obj) != (p_list)->last); \ + mhd_ASSUME ((p_obj)->links_name.next != \ + (p_obj)->links_name.prev); \ + (p_obj)->links_name.next->links_name.prev = \ + (p_obj)->links_name.prev; } else \ + { mhd_ASSUME ((p_obj) == (p_list)->last); \ + (p_list)->last = (p_obj)->links_name.prev; } \ + if (NULL != (p_obj)->links_name.prev) \ + { mhd_ASSUME ((p_obj) == (p_obj)->links_name.prev->links_name.next); \ + mhd_ASSUME ((p_obj) != (p_list)->first); \ + mhd_ASSUME ((p_obj)->links_name.next != \ + (p_obj)->links_name.prev); \ + (p_obj)->links_name.prev->links_name.next = \ + (p_obj)->links_name.next; } else \ + { mhd_ASSUME ((p_obj) == (p_list)->first); \ + (p_list)->first = (p_obj)->links_name.next; } \ + (p_obj)->links_name.prev = NULL; \ + (p_obj)->links_name.next = NULL; } while (0) /** * Get the first element in the list using direct pointer to the list @@ -262,30 +261,30 @@ * first position * @param links_name the name of the inter-links field in the @a p_obj */ -#define mhd_DLINKEDL_MOVE_TO_FIRST_D(p_list,p_obj,links_name) do { \ - mhd_ASSUME (NULL != (p_list)->first); \ - mhd_ASSUME (NULL != (p_list)->last); \ - mhd_ASSUME ((p_obj) != (p_obj)->links_name.next); \ - mhd_ASSUME ((p_obj) != (p_obj)->links_name.prev); \ - if (NULL == (p_obj)->links_name.prev) \ - { mhd_ASSUME ((p_obj) == (p_list)->first); } else \ - { mhd_ASSUME ((p_obj) != (p_list)->first); \ - mhd_ASSUME ((p_obj) == \ - (p_obj)->links_name.prev->links_name.next); \ - (p_obj)->links_name.prev->links_name.next = \ - (p_obj)->links_name.next; \ - if (NULL == (p_obj)->links_name.next) \ - { mhd_ASSUME ((p_obj) == (p_list)->last); \ - (p_list)->last = (p_obj)->links_name.prev; } else \ - { mhd_ASSUME ((p_obj) != (p_list)->last); \ - mhd_ASSUME ((p_obj) == \ - (p_obj)->links_name.next->links_name.prev); \ - (p_obj)->links_name.next->links_name.prev = \ - (p_obj)->links_name.prev; } \ - (p_obj)->links_name.next = (p_list)->first; \ - (p_obj)->links_name.prev = NULL; \ - (p_list)->first->links_name.prev = (p_obj); \ - (p_list)->first = (p_obj); } } while (0) +#define mhd_DLINKEDL_MOVE_TO_FIRST_D(p_list, p_obj, links_name) do { \ + mhd_ASSUME (NULL != (p_list)->first); \ + mhd_ASSUME (NULL != (p_list)->last); \ + mhd_ASSUME ((p_obj) != (p_obj)->links_name.next); \ + mhd_ASSUME ((p_obj) != (p_obj)->links_name.prev); \ + if (NULL == (p_obj)->links_name.prev) \ + { mhd_ASSUME ((p_obj) == (p_list)->first); } else \ + { mhd_ASSUME ((p_obj) != (p_list)->first); \ + mhd_ASSUME ((p_obj) == \ + (p_obj)->links_name.prev->links_name.next); \ + (p_obj)->links_name.prev->links_name.next = \ + (p_obj)->links_name.next; \ + if (NULL == (p_obj)->links_name.next) \ + { mhd_ASSUME ((p_obj) == (p_list)->last); \ + (p_list)->last = (p_obj)->links_name.prev; } else \ + { mhd_ASSUME ((p_obj) != (p_list)->last); \ + mhd_ASSUME ((p_obj) == \ + (p_obj)->links_name.next->links_name.prev); \ + (p_obj)->links_name.next->links_name.prev = \ + (p_obj)->links_name.prev; } \ + (p_obj)->links_name.next = (p_list)->first; \ + (p_obj)->links_name.prev = NULL; \ + (p_list)->first->links_name.prev = (p_obj); \ + (p_list)->first = (p_obj); } } while (0) /* ** The main interface ** */ @@ -300,7 +299,7 @@ * @param p_own the pointer to the owner object with the @a list_name list * @param list_name the name of the list */ -#define mhd_DLINKEDL_INIT_LIST(p_own,list_name) \ +#define mhd_DLINKEDL_INIT_LIST(p_own, list_name) \ mhd_DLINKEDL_INIT_LIST_D (&((p_own)->list_name)) /** @@ -310,8 +309,8 @@ * the @a links_name list * @param links_name the name of the inter-links field in the @a p_obj */ -#define mhd_DLINKEDL_INIT_LINKS(p_obj,links_name) \ - do {(p_obj)->links_name.prev = NULL; \ +#define mhd_DLINKEDL_INIT_LINKS(p_obj, links_name) \ + do {(p_obj)->links_name.prev = NULL; \ (p_obj)->links_name.next = NULL;} while (0) /* List manipulations */ @@ -325,7 +324,7 @@ * @param l_name the same name for the list field in the owner and * the inter-links field in the list element */ -#define mhd_DLINKEDL_INS_FIRST(p_own,p_obj,l_name) \ +#define mhd_DLINKEDL_INS_FIRST(p_own, p_obj, l_name) \ mhd_DLINKEDL_INS_FIRST_D (&((p_own)->l_name),(p_obj),l_name) /** @@ -337,7 +336,7 @@ * @param l_name the same name for the list field in the owner and * the inter-links field in the list element */ -#define mhd_DLINKEDL_INS_LAST(p_own,p_obj,l_name) \ +#define mhd_DLINKEDL_INS_LAST(p_own, p_obj, l_name) \ mhd_DLINKEDL_INS_LAST_D (&((p_own)->l_name),(p_obj),l_name) /** @@ -349,7 +348,7 @@ * @param l_name the same name for the list field in the owner and * the inter-links field in the list element */ -#define mhd_DLINKEDL_DEL(p_own,p_obj,l_name) \ +#define mhd_DLINKEDL_DEL(p_own, p_obj, l_name) \ mhd_DLINKEDL_DEL_D (&((p_own)->l_name),(p_obj),l_name) /* List iterations */ @@ -359,7 +358,7 @@ * @param p_own the pointer to the owner object with the @a list_name list * @param list_name the name of the list */ -#define mhd_DLINKEDL_GET_FIRST(p_own,list_name) \ +#define mhd_DLINKEDL_GET_FIRST(p_own, list_name) \ mhd_DLINKEDL_GET_FIRST_D (&((p_own)->list_name)) /** @@ -367,7 +366,7 @@ * @param p_own the pointer to the owner object with the @a list_name list * @param list_name the name of the list */ -#define mhd_DLINKEDL_GET_LAST(p_own,list_name) \ +#define mhd_DLINKEDL_GET_LAST(p_own, list_name) \ mhd_DLINKEDL_GET_LAST_D (&((p_own)->list_name)) /** @@ -375,14 +374,14 @@ * @param p_obj the pointer to the existing @a links_name list element * @param links_name the name of the inter-links field in the @a p_obj */ -#define mhd_DLINKEDL_GET_NEXT(p_obj,links_name) ((p_obj)->links_name.next) +#define mhd_DLINKEDL_GET_NEXT(p_obj, links_name) ((p_obj)->links_name.next) /** * Get the previous element in the list * @param p_obj the pointer to the existing @a links_name list element * @param links_name the name of the inter-links field in the @a p_obj */ -#define mhd_DLINKEDL_GET_PREV(p_obj,links_name) ((p_obj)->links_name.prev) +#define mhd_DLINKEDL_GET_PREV(p_obj, links_name) ((p_obj)->links_name.prev) #endif /* ! MHD_DLINKED_LIST_H */ diff --git a/src/mhd2/mhd_iovec.h b/src/mhd2/mhd_iovec.h @@ -79,10 +79,10 @@ struct mhd_w32_iovec char *iov_base; }; typedef struct mhd_w32_iovec mhd_iovec; -#define mhd_IOV_ELMN_MAX_SIZE ULONG_MAX -#define mhd_IOV_ELMN_PTR_TYPE char * +# define mhd_IOV_ELMN_MAX_SIZE ULONG_MAX +# define mhd_IOV_ELMN_PTR_TYPE char * typedef unsigned long mhd_iov_elmn_size; -#define mhd_IOV_RET_MAX_SIZE LONG_MAX +# define mhd_IOV_RET_MAX_SIZE LONG_MAX typedef long mhd_iov_ret_type; #elif defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) /** @@ -90,10 +90,10 @@ typedef long mhd_iov_ret_type; * is available. Matches system "struct iovec". */ typedef struct iovec mhd_iovec; -#define mhd_IOV_ELMN_MAX_SIZE SIZE_MAX -#define mhd_IOV_ELMN_PTR_TYPE void * +# define mhd_IOV_ELMN_MAX_SIZE SIZE_MAX +# define mhd_IOV_ELMN_PTR_TYPE void * typedef size_t mhd_iov_elmn_size; -#define mhd_IOV_RET_MAX_SIZE SSIZE_MAX +# define mhd_IOV_RET_MAX_SIZE SSIZE_MAX typedef ssize_t mhd_iov_ret_type; #else /** @@ -101,10 +101,10 @@ typedef ssize_t mhd_iov_ret_type; * is not available. */ typedef struct MHD_IoVec mhd_iovec; -#define mhd_IOV_ELMN_MAX_SIZE SIZE_MAX -#define mhd_IOV_ELMN_PTR_TYPE void * +# define mhd_IOV_ELMN_MAX_SIZE SIZE_MAX +# define mhd_IOV_ELMN_PTR_TYPE void * typedef size_t mhd_iov_elmn_size; -#define mhd_IOV_RET_MAX_SIZE SSIZE_MAX +# define mhd_IOV_RET_MAX_SIZE SSIZE_MAX typedef ssize_t mhd_iov_ret_type; #endif diff --git a/src/mhd2/mhd_itc.c b/src/mhd2/mhd_itc.c @@ -49,14 +49,14 @@ # ifdef MHD_HAVE_MHD_ITC_NONBLOCKING # include "mhd_sockets_funcs.h" # ifndef MHD_SOCKETS_KIND_POSIX -#error Pipe-based ITC can be used only with POSIX sockets +# error Pipe-based ITC can be used only with POSIX sockets # endif MHD_INTERNAL bool mhd_itc_nonblocking (struct mhd_itc *pitc) { - return mhd_socket_nonblocking ((MHD_Socket) pitc->fd[0]) && - mhd_socket_nonblocking ((MHD_Socket) pitc->fd[1]); + return mhd_socket_nonblocking ((MHD_Socket)pitc->fd[0]) + && mhd_socket_nonblocking ((MHD_Socket)pitc->fd[1]); } diff --git a/src/mhd2/mhd_itc.h b/src/mhd2/mhd_itc.h @@ -77,7 +77,7 @@ * Set @a itc to the invalid value. * @param pitc the pointer to the itc to set */ -#define mhd_itc_set_invalid(pitc) ((pitc)->fd = -1) +# define mhd_itc_set_invalid(pitc) ((pitc)->fd = -1) /** * Check whether ITC has valid value. @@ -88,7 +88,7 @@ * @return boolean true if @a itc has valid value, * boolean false otherwise. */ -#define mhd_ITC_IS_VALID(itc) (0 <= ((itc).fd)) +# define mhd_ITC_IS_VALID(itc) (0 <= ((itc).fd)) /** * Initialise ITC by generating eventFD @@ -96,7 +96,7 @@ * @return non-zero if succeeded, zero otherwise */ # define mhd_itc_init(pitc) \ - (-1 != ((pitc)->fd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) + (-1 != ((pitc)->fd = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK))) /** * Helper for mhd_itc_activate() @@ -115,25 +115,25 @@ static const uint_fast64_t mhd_ITC_WR_DATA = 1; * @param itc the itc to use * @return non-zero if succeeded, zero otherwise */ -#define mhd_itc_activate(itc) \ - ((write ((itc).fd, (const void*) &mhd_ITC_WR_DATA, 8) > 0) \ - || (EAGAIN == errno)) +# define mhd_itc_activate(itc) \ + ((write ((itc).fd, (const void*) &mhd_ITC_WR_DATA, 8) > 0) \ + || (EAGAIN == errno)) /** * Return read FD of @a itc which can be used for poll(), select() etc. * @param itc the itc to get FD * @return FD of read side */ -#define mhd_itc_r_fd(itc) ((itc).fd) +# define mhd_itc_r_fd(itc) ((itc).fd) /** * Clear signalled state on @a itc * @param itc the itc to clear */ -#define mhd_itc_clear(itc) \ - do { uint_fast64_t mhd__b; \ - (void) (0 > read ((itc).fd, (void*) &mhd__b, 8)); \ - } while (0) +# define mhd_itc_clear(itc) \ + do { uint_fast64_t mhd__b; \ + (void) (0 > read ((itc).fd, (void*) &mhd__b, 8)); \ + } while (0) /** * Destroy previously initialised ITC. Note that close() @@ -142,8 +142,8 @@ static const uint_fast64_t mhd_ITC_WR_DATA = 1; * @param itc the itc to destroy * @return non-zero if succeeded, zero otherwise */ -#define mhd_itc_destroy(itc) \ - ((0 == close ((itc).fd)) || (EBADF != errno)) +# define mhd_itc_destroy(itc) \ + ((0 == close ((itc).fd)) || (EBADF != errno)) #elif defined(MHD_ITC_PIPE_) @@ -196,11 +196,11 @@ static const uint_fast64_t mhd_ITC_WR_DATA = 1; # define mhd_itc_init(pitc) (! pipe2 ((pitc)->fd, O_CLOEXEC | O_NONBLOCK)) # else /* ! MHD_USE_PIPE2 */ # define mhd_itc_init(pitc) \ - ( (! pipe ((pitc)->fd)) ? \ - (mhd_itc_nonblocking ((pitc)) ? \ - (! 0) : \ - ((void) mhd_itc_destroy (*(pitc)), 0) ) \ - : (0) ) + ( (! pipe ((pitc)->fd)) ? \ + (mhd_itc_nonblocking ((pitc)) ? \ + (! 0) : \ + ((void) mhd_itc_destroy (*(pitc)), 0) ) \ + : (0) ) # define MHD_HAVE_MHD_ITC_NONBLOCKING 1 /** @@ -220,7 +220,7 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @return non-zero if succeeded, zero otherwise */ # define mhd_itc_activate(itc) \ - ((write ((itc).fd[1], (const void*) "", 1) > 0) || (EAGAIN == errno)) + ((write ((itc).fd[1], (const void*) "", 1) > 0) || (EAGAIN == errno)) /** * Return read FD of @a itc which can be used for poll(), select() etc. @@ -234,9 +234,9 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @param itc the itc to clear */ # define mhd_itc_clear(itc) do \ - { long mhd__b; \ - while (0 < read ((itc).fd[0], (void*) &mhd__b, sizeof(mhd__b))) \ - {(void) 0;} } while (0) + { long mhd__b; \ + while (0 < read ((itc).fd[0], (void*) &mhd__b, sizeof(mhd__b))) \ + {(void) 0;} } while (0) /** * Destroy previously initialised ITC @@ -244,7 +244,7 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @return non-zero if succeeded, zero otherwise */ # define mhd_itc_destroy(itc) \ - (0 == (close ((itc).fd[0]) + close ((itc).fd[1]))) + (0 == (close ((itc).fd[0]) + close ((itc).fd[1]))) #elif defined(MHD_ITC_SOCKETPAIR_) @@ -252,7 +252,7 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); # include "sys_sockets_headers.h" # include "mhd_sockets_macros.h" -# if ! defined(mhd_socket_pair_nblk) +# if !defined(mhd_socket_pair_nblk) # include "mhd_sockets_funcs.h" # endif @@ -266,7 +266,7 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @param pitc the pointer to the itc to set */ # define mhd_itc_set_invalid(pitc) \ - ((pitc)->sk[0] = (pitc)->sk[1] = MHD_INVALID_SOCKET) + ((pitc)->sk[0] = (pitc)->sk[1] = MHD_INVALID_SOCKET) /** * Check whether ITC has valid value. @@ -288,9 +288,9 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); # define mhd_itc_init(pitc) mhd_socket_pair_nblk ((pitc)->sk) # else /* ! mhd_socket_pair_nblk */ # define mhd_itc_init(pitc) \ - ( (! mhd_socket_pair ((pitc)->sk)) ? \ - (0) : ( (! mhd_itc_nonblocking ((pitc))) ? \ - (mhd_itc_destroy (*(pitc)), 0) : (! 0) ) ) + ( (! mhd_socket_pair ((pitc)->sk)) ? \ + (0) : ( (! mhd_itc_nonblocking ((pitc))) ? \ + (mhd_itc_destroy (*(pitc)), 0) : (! 0) ) ) /** * Change itc FD options to be non-blocking. @@ -299,8 +299,8 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @return true if succeeded, false otherwise */ # define mhd_itc_nonblocking(pitc) \ - (mhd_socket_nonblocking ((pitc)->sk[0]) && \ - mhd_socket_nonblocking ((pitc)->sk[1])) + (mhd_socket_nonblocking ((pitc)->sk[0]) && \ + mhd_socket_nonblocking ((pitc)->sk[1])) # endif /* ! mhd_socket_pair_nblk */ @@ -310,7 +310,7 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @return non-zero if succeeded, zero otherwise */ # define mhd_itc_activate(itc) \ - ((0 < mhd_sys_send ((itc).sk[1], "", 1)) || mhd_SCKT_LERR_IS_EAGAIN ()) + ((0 < mhd_sys_send ((itc).sk[1], "", 1)) || mhd_SCKT_LERR_IS_EAGAIN ()) /** * Return read FD of @a itc which can be used for poll(), select() etc. @@ -324,9 +324,9 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @param itc the itc to clear */ # define mhd_itc_clear(itc) do \ - { long mhd__b; \ - while (0 < mhd_sys_recv ((itc).sk[0], &mhd__b, sizeof(mhd__b))) \ - {(void) 0;} } while (0) + { long mhd__b; \ + while (0 < mhd_sys_recv ((itc).sk[0], &mhd__b, sizeof(mhd__b))) \ + {(void) 0;} } while (0) /** * Destroy previously initialised ITC @@ -334,9 +334,9 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * @return non-zero if succeeded, zero otherwise */ # define mhd_itc_destroy(itc) \ - (mhd_socket_close ((itc).sk[1]) ? \ - mhd_socket_close ((itc).sk[0]) : \ - ((void) mhd_socket_close ((itc).sk[0]), ! ! 0) ) + (mhd_socket_close ((itc).sk[1]) ? \ + mhd_socket_close ((itc).sk[0]) : \ + ((void) mhd_socket_close ((itc).sk[0]), ! ! 0) ) #endif /* MHD_ITC_SOCKETPAIR_ */ @@ -345,10 +345,10 @@ mhd_itc_nonblocking (struct mhd_itc *pitc); * if error is detected. * @param itc the itc to destroy */ -#define mhd_itc_destroy_chk(itc) do { \ - if (! mhd_itc_destroy (itc)) \ - MHD_PANIC ("Failed to destroy ITC.\n"); \ -} while (0) +#define mhd_itc_destroy_chk(itc) do { \ + if (!mhd_itc_destroy (itc)) \ + MHD_PANIC ("Failed to destroy ITC.\n"); \ + } while (0) /** * Check whether ITC has invalid value. diff --git a/src/mhd2/mhd_itc_types.h b/src/mhd2/mhd_itc_types.h @@ -50,8 +50,8 @@ #include "mhd_sys_options.h" /* Force socketpair on native W32 */ -#if defined(_WIN32) && ! defined(__CYGWIN__) && ! defined(MHD_ITC_SOCKETPAIR_) -#error MHD_ITC_SOCKETPAIR_ is not defined on native W32 platform +#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(MHD_ITC_SOCKETPAIR_) +# error MHD_ITC_SOCKETPAIR_ is not defined on native W32 platform #endif /* _WIN32 && !__CYGWIN__ && !MHD_ITC_SOCKETPAIR_ */ #if defined(MHD_ITC_EVENTFD_) @@ -105,7 +105,7 @@ struct mhd_itc * Static initialiser for struct mhd_itc */ # define mhd_ITC_STATIC_INIT_INVALID \ - { { MHD_INVALID_SOCKET, MHD_INVALID_SOCKET } } + { { MHD_INVALID_SOCKET, MHD_INVALID_SOCKET } } #endif /* MHD_ITC_SOCKETPAIR_ */ diff --git a/src/mhd2/mhd_lib_init.c b/src/mhd2/mhd_lib_init.c @@ -166,13 +166,13 @@ static mhd_mutex mhd_init_mutex; * Have #mhd_LIB_INIT_MARKER_VALUE value when initialised. */ static volatile uint_fast32_t mhd_lib_global_init_marker = - (uint_fast32_t) mhd_LIB_INIT_MARKER_VALUE; + (uint_fast32_t)mhd_LIB_INIT_MARKER_VALUE; /** * The indicator of performed global lazy initialisation. * Have (~ #mhd_LIB_INIT_MARKER_VALUE) value when initialised. */ static volatile uint_fast32_t mhd_lib_global_init_Nmarker = - (uint_fast32_t) ~((uint_fast32_t) mhd_LIB_INIT_MARKER_VALUE); + (uint_fast32_t) ~((uint_fast32_t)mhd_LIB_INIT_MARKER_VALUE); /* Variables used for full initialisation */ /** * The number of user of library global resources. @@ -214,11 +214,11 @@ static bool mhd_lib_global_lazy_init (void) { mhd_panic_init_default (); /* Just set a few variables to NULL */ - if (! mhd_mutex_init (&mhd_init_mutex)) + if (!mhd_mutex_init (&mhd_init_mutex)) return false; mhd_lib_fully_inited_once = false; mhd_lib_use_counter = 0; - mhd_lib_global_init_marker = (uint_fast32_t) mhd_LIB_INIT_MARKER_VALUE; + mhd_lib_global_init_marker = (uint_fast32_t)mhd_LIB_INIT_MARKER_VALUE; mhd_lib_global_init_Nmarker = (uint_fast32_t) ~mhd_lib_global_init_marker; return true; } @@ -237,7 +237,7 @@ mhd_lib_global_lazy_deinit (void) { mhd_lib_global_init_Nmarker = 0u; mhd_lib_global_init_marker = 0u; - (void) mhd_mutex_destroy (&mhd_init_mutex); + (void)mhd_mutex_destroy (&mhd_init_mutex); } @@ -253,13 +253,13 @@ mhd_lib_global_lazy_deinit (void) void mhd_lib_global_init_auto (void) { - if (! mhd_lib_global_lazy_init ()) + if (!mhd_lib_global_lazy_init ()) { - (void) 0; + (void)0; /* Do not abort in non-debug builds, weak workarounds will be used */ -#ifndef NDEBUG +# ifndef NDEBUG MHD_PANIC ("Failed to initialise the MHD library"); -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ } } @@ -267,8 +267,8 @@ mhd_lib_global_init_auto (void) void mhd_lib_global_deinit_auto (void) { -#ifndef NDEBUG - if (! mhd_LIB_INIT_LAZY_IS_PERFORMED ()) +# ifndef NDEBUG + if (!mhd_LIB_INIT_LAZY_IS_PERFORMED ()) { fprintf (stderr, "Automatic MHD library initialisation has not been " "performed, but the library de-initialisation is called.\n"); @@ -281,7 +281,7 @@ mhd_lib_global_deinit_auto (void) "some MHD resources are still in use by the application.\n"); fflush (stderr); } -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ mhd_lib_global_lazy_deinit (); } @@ -304,11 +304,11 @@ AUTOINIT_FUNCS_USR_DLLMAIN_NAME (HINSTANCE hinst, DWORD reason, LPVOID pReserved) { - (void) pReserved; /* Not used */ + (void)pReserved; /* Not used */ /* Disable calls with DLL_THREAD_ATTACH and DLL_THREAD_DETACH messages */ if (AIF_W32_DLL_PROCESS_ATTACH == reason) - (void) DisableThreadLibraryCalls ((HMODULE) hinst); + (void)DisableThreadLibraryCalls ((HMODULE)hinst); return TRUE; } @@ -350,7 +350,7 @@ mhd_lib_sockets_init_w32 (void) mhd_static_inline void mhd_lib_sockets_deinit_w32 (void) { - (void) WSACleanup (); + (void)WSACleanup (); } @@ -370,10 +370,10 @@ static bool mhd_lib_global_full_init_once (void) { mhd_assert (mhd_LIB_INIT_LAZY_IS_PERFORMED ()); - mhd_assert (! mhd_lib_fully_inited_once); + mhd_assert (!mhd_lib_fully_inited_once); mhd_assert (0 == mhd_lib_use_counter); - if (! mhd_lib_sockets_init_w32 ()) + if (!mhd_lib_sockets_init_w32 ()) return false; mhd_mclock_init_once (); mhd_send_init_once (); @@ -416,7 +416,7 @@ static bool mhd_lib_global_full_re_init (void) { mhd_assert (mhd_lib_fully_inited_once); - if (! mhd_lib_sockets_init_w32 ()) + if (!mhd_lib_sockets_init_w32 ()) return false; mhd_mclock_re_init (); #ifdef MHD_SUPPORT_HTTPS @@ -435,23 +435,23 @@ MHD_INTERNAL bool mhd_lib_init_global_if_needed (void) { bool ret; - if (! mhd_LIB_INIT_LAZY_IS_PERFORMED ()) + if (!mhd_LIB_INIT_LAZY_IS_PERFORMED ()) { -#if defined (mhd_INIT_LAZY_AUTOMATIC) && ! defined(NDEBUG) +#if defined(mhd_INIT_LAZY_AUTOMATIC) && !defined(NDEBUG) /* Problem detected: the library must be already initialised automatically, but it is not. */ abort (); /* abort if this is a debug build */ #else /* !mhd_INIT_LAZY_AUTOMATIC || NDEBUG */ - if (! mhd_lib_global_lazy_init ()) /* Not thread safe, but no choice here */ + if (!mhd_lib_global_lazy_init ()) /* Not thread safe, but no choice here */ return false; #endif /* !mhd_INIT_LAZY_AUTOMATIC || NDEBUG */ } - if (! mhd_mutex_lock (&mhd_init_mutex)) + if (!mhd_mutex_lock (&mhd_init_mutex)) return false; if (0 == mhd_lib_use_counter) { - if (! mhd_lib_fully_inited_once) + if (!mhd_lib_fully_inited_once) ret = mhd_lib_global_full_init_once (); else ret = mhd_lib_global_full_re_init (); diff --git a/src/mhd2/mhd_lib_init_impl.h b/src/mhd2/mhd_lib_init_impl.h @@ -46,7 +46,7 @@ */ #ifdef MHD_LIB_INIT_IMPL_H -#error This file must not be included more the one time only +# error This file must not be included more the one time only #endif #define MHD_LIB_INIT_IMPL_H 1 @@ -56,26 +56,26 @@ * object/module/c-file. */ #ifndef MHD_LIB_INIT_IMPL_H_IN_DAEMON_CREATE_C -#error This file must in included only in 'daemon_create.c' file +# error This file must in included only in 'daemon_create.c' file #else /* MHD_LIB_INIT_IMPL_H_IN_DAEMON_CREATE_C */ -#include "mhd_sys_options.h" -#include "mhd_lib_init_auto.h" +# include "mhd_sys_options.h" +# include "mhd_lib_init_auto.h" -#ifdef mhd_AUTOINIT_FUNCS_USE +# ifdef mhd_AUTOINIT_FUNCS_USE -# ifndef mhd_AUTOINIT_FUNCS_PRAGMA +# ifndef mhd_AUTOINIT_FUNCS_PRAGMA /* Call automatically initialiser and deinitialiser functions */ AIF_SET_INIT_AND_DEINIT_FUNCS (mhd_lib_global_init_auto, \ mhd_lib_global_deinit_auto); -# else +# else /* Call automatically initialiser function */ -#pragma init(mhd_lib_global_init_auto) +# pragma init(mhd_lib_global_init_auto) /* Call automatically deinitialiser function */ -#pragma fini(mhd_lib_global_deinit_auto) -# endif +# pragma fini(mhd_lib_global_deinit_auto) +# endif -#endif /* AIF_AUTOINIT_FUNCS_ARE_SUPPORTED */ +# endif /* AIF_AUTOINIT_FUNCS_ARE_SUPPORTED */ #endif /* MHD_LIB_INIT_IMPL_H_IN_DAEMON_CREATE_C */ diff --git a/src/mhd2/mhd_limits.h b/src/mhd2/mhd_limits.h @@ -66,7 +66,7 @@ /* The maximum value for signed type, based on knowledge of unsigned counterpart type */ -#define mhd_SIGNED_TYPE_MAX2(type,utype) \ +#define mhd_SIGNED_TYPE_MAX2(type, utype) \ ((type) (((utype) (~((utype) 0))) >> 1)) #define mhd_IS_TYPE_SIGNED(type) (((type) 0) > ((type) - 1)) @@ -175,15 +175,15 @@ # endif #endif /* !OFF_T_MAX */ -#if defined(_LARGEFILE64_SOURCE) && ! defined(OFF64_T_MAX) +#if defined(_LARGEFILE64_SOURCE) && !defined(OFF64_T_MAX) # define OFF64_T_MAX mhd_SIGNED_TYPE_MAX (off64_t) #endif /* _LARGEFILE64_SOURCE && !OFF64_T_MAX */ #ifndef TIME_T_MAX -# define TIME_T_MAX ((time_t) \ - (mhd_IS_TYPE_SIGNED (time_t) ? \ - mhd_SIGNED_TYPE_MAX (time_t) : \ - mhd_UNSIGNED_TYPE_MAX (time_t))) +# define TIME_T_MAX ((time_t) \ + (mhd_IS_TYPE_SIGNED (time_t) ? \ + mhd_SIGNED_TYPE_MAX (time_t) : \ + mhd_UNSIGNED_TYPE_MAX (time_t))) #endif /* !TIME_T_MAX */ #ifndef TIMEVAL_TV_SEC_MAX diff --git a/src/mhd2/mhd_locks.h b/src/mhd2/mhd_locks.h @@ -59,86 +59,86 @@ #ifdef MHD_SUPPORT_THREADS -#if defined(HAVE_PTHREAD_H) && defined(mhd_THREADS_KIND_POSIX) +# if defined(HAVE_PTHREAD_H) && defined(mhd_THREADS_KIND_POSIX) /** * The mutex is POSIX Threads' mutex */ -# define mhd_MUTEX_KIND_PTHREAD 1 -# include <pthread.h> -# include "sys_null_macro.h" -#elif defined(mhd_THREADS_KIND_W32) -# include "sys_w32_ver.h" -# if _WIN32_WINNT >= 0x0600 /* Vista or later */ && \ - ! defined (MHD_NO_W32_SRWLOCKS) +# define mhd_MUTEX_KIND_PTHREAD 1 +# include <pthread.h> +# include "sys_null_macro.h" +# elif defined(mhd_THREADS_KIND_W32) +# include "sys_w32_ver.h" +# if _WIN32_WINNT >= 0x0600 /* Vista or later */ && \ + !defined(MHD_NO_W32_SRWLOCKS) /** * The mutex is W32 SRW lock */ -# define mhd_MUTEX_KIND_W32_SRW 1 -# else +# define mhd_MUTEX_KIND_W32_SRW 1 +# else /** * The mutex is W32 Critical Section */ -# define mhd_MUTEX_KIND_W32_CS 1 -# endif -# if 0 /* _WIN32_WINNT >= 0x0602 */ /* Win8 or later */ +# define mhd_MUTEX_KIND_W32_CS 1 +# endif +# if 0 /* _WIN32_WINNT >= 0x0602 */ /* Win8 or later */ /* This include does not work as _ARM_ or _AMD64_ macros are missing */ -# include <synchapi.h> +# include <synchapi.h> +# else +# include <windows.h> +# endif # else -# include <windows.h> +# error No base mutex API is available. # endif -#else -#error No base mutex API is available. -#endif -#include "mhd_panic.h" +# include "mhd_panic.h" -#if defined(mhd_MUTEX_KIND_PTHREAD) +# if defined(mhd_MUTEX_KIND_PTHREAD) typedef pthread_mutex_t mhd_mutex; -#elif defined(mhd_MUTEX_KIND_W32_SRW) +# elif defined(mhd_MUTEX_KIND_W32_SRW) typedef SRWLOCK mhd_mutex; -#elif defined(mhd_MUTEX_KIND_W32_CS) +# elif defined(mhd_MUTEX_KIND_W32_CS) typedef CRITICAL_SECTION mhd_mutex; -#endif +# endif -#if defined(mhd_MUTEX_KIND_PTHREAD) +# if defined(mhd_MUTEX_KIND_PTHREAD) /** * Initialise a new mutex. * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_init(pmutex) (0 == pthread_mutex_init ((pmutex), NULL)) -#elif defined(mhd_MUTEX_KIND_W32_SRW) +# define mhd_mutex_init(pmutex) (0 == pthread_mutex_init ((pmutex), NULL)) +# elif defined(mhd_MUTEX_KIND_W32_SRW) /** * Initialise a new mutex. * @param pmutex the pointer to the mutex * @return always nonzero (success) */ -# define mhd_mutex_init(pmutex) (InitializeSRWLock ((pmutex)), ! 0) -#elif defined(mhd_MUTEX_KIND_W32_CS) -# if _WIN32_WINNT < 0x0600 +# define mhd_mutex_init(pmutex) (InitializeSRWLock ((pmutex)), ! 0) +# elif defined(mhd_MUTEX_KIND_W32_CS) +# if _WIN32_WINNT < 0x0600 /* Before Vista */ /** * Initialise a new mutex. * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_init(pmutex) \ - (InitializeCriticalSectionAndSpinCount ((pmutex), 0)) -# else +# define mhd_mutex_init(pmutex) \ + (InitializeCriticalSectionAndSpinCount ((pmutex), 0)) +# else /* The function always succeed starting from Vista */ /** * Initialise a new mutex. * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_init(pmutex) \ - (((void) InitializeCriticalSection (pmutex)), ! 0) +# define mhd_mutex_init(pmutex) \ + (((void) InitializeCriticalSection (pmutex)), ! 0) +# endif # endif -#endif -#ifdef mhd_MUTEX_KIND_W32_CS -# if _WIN32_WINNT < 0x0600 +# ifdef mhd_MUTEX_KIND_W32_CS +# if _WIN32_WINNT < 0x0600 /* Before Vista */ /** * Initialise a new mutex for short locks. @@ -150,9 +150,9 @@ typedef CRITICAL_SECTION mhd_mutex; * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_init_short(pmutex) \ - (InitializeCriticalSectionAndSpinCount ((pmutex), 128)) -# else +# define mhd_mutex_init_short(pmutex) \ + (InitializeCriticalSectionAndSpinCount ((pmutex), 128)) +# else /* The function always succeed starting from Vista */ /** * Initialise a new mutex for short locks. @@ -164,64 +164,64 @@ typedef CRITICAL_SECTION mhd_mutex; * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_init_short(pmutex) \ - ((void) InitializeCriticalSectionAndSpinCount ((pmutex), 128), ! 0) +# define mhd_mutex_init_short(pmutex) \ + ((void) InitializeCriticalSectionAndSpinCount ((pmutex), 128), ! 0) +# endif # endif -#endif -#ifndef mhd_mutex_init_short -# define mhd_mutex_init_short(pmutex) mhd_mutex_init ((pmutex)) -#endif +# ifndef mhd_mutex_init_short +# define mhd_mutex_init_short(pmutex) mhd_mutex_init ((pmutex)) +# endif -#if defined(mhd_MUTEX_KIND_PTHREAD) -# if defined(PTHREAD_MUTEX_INITIALIZER) +# if defined(mhd_MUTEX_KIND_PTHREAD) +# if defined(PTHREAD_MUTEX_INITIALIZER) /** * The value to statically initialise mutex */ -# define mhd_MUTEX_INITIALISER_STAT PTHREAD_MUTEX_INITIALIZER -# endif /* PTHREAD_MUTEX_INITIALIZER */ -#elif defined(mhd_MUTEX_KIND_W32_SRW) -# if defined(SRWLOCK_INIT) +# define mhd_MUTEX_INITIALISER_STAT PTHREAD_MUTEX_INITIALIZER +# endif /* PTHREAD_MUTEX_INITIALIZER */ +# elif defined(mhd_MUTEX_KIND_W32_SRW) +# if defined(SRWLOCK_INIT) /** * The value to statically initialise mutex */ -# define mhd_MUTEX_INITIALISER_STAT SRWLOCK_INIT +# define mhd_MUTEX_INITIALISER_STAT SRWLOCK_INIT +# endif # endif -#endif -#ifdef mhd_MUTEX_INITIALISER_STAT +# ifdef mhd_MUTEX_INITIALISER_STAT /** * Define static mutex and statically initialise it. */ -# define mhd_MUTEX_STATIC_DEFN_INIT(m) \ - static mhd_mutex m = mhd_MUTEX_INITIALISER_STAT -#endif +# define mhd_MUTEX_STATIC_DEFN_INIT(m) \ + static mhd_mutex m = mhd_MUTEX_INITIALISER_STAT +# endif -#if defined(mhd_MUTEX_KIND_PTHREAD) +# if defined(mhd_MUTEX_KIND_PTHREAD) /** * Destroy previously initialised mutex. * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_destroy(pmutex) (0 == pthread_mutex_destroy ((pmutex))) -#elif defined(mhd_MUTEX_KIND_W32_SRW) +# define mhd_mutex_destroy(pmutex) (0 == pthread_mutex_destroy ((pmutex))) +# elif defined(mhd_MUTEX_KIND_W32_SRW) /** * Destroy (no-op) previously initialised mutex. * @param pmutex the pointer to the mutex * @return always nonzero (success) */ -# define mhd_mutex_destroy(pmutex) ((void) (pmutex), ! 0) -#elif defined(mhd_MUTEX_KIND_W32_CS) +# define mhd_mutex_destroy(pmutex) ((void) (pmutex), ! 0) +# elif defined(mhd_MUTEX_KIND_W32_CS) /** * Destroy previously initialised mutex. * @param pmutex the pointer to the mutex * @return always nonzero (success) */ -# define mhd_mutex_destroy(pmutex) (DeleteCriticalSection ((pmutex)), ! 0) -#endif +# define mhd_mutex_destroy(pmutex) (DeleteCriticalSection ((pmutex)), ! 0) +# endif -#if defined(mhd_MUTEX_KIND_PTHREAD) +# if defined(mhd_MUTEX_KIND_PTHREAD) /** * Acquire a lock on previously initialised mutex. * If the mutex was already locked by other thread, function blocks until @@ -229,8 +229,8 @@ typedef CRITICAL_SECTION mhd_mutex; * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_lock(pmutex) (0 == pthread_mutex_lock ((pmutex))) -#elif defined(mhd_MUTEX_KIND_W32_SRW) +# define mhd_mutex_lock(pmutex) (0 == pthread_mutex_lock ((pmutex))) +# elif defined(mhd_MUTEX_KIND_W32_SRW) /** * Acquire a lock on previously initialised mutex. * If the mutex was already locked by other thread, function blocks until @@ -238,8 +238,8 @@ typedef CRITICAL_SECTION mhd_mutex; * @param pmutex the pointer to the mutex * @return always nonzero (success) */ -# define mhd_mutex_lock(pmutex) (AcquireSRWLockExclusive ((pmutex)), ! 0) -#elif defined(mhd_MUTEX_KIND_W32_CS) +# define mhd_mutex_lock(pmutex) (AcquireSRWLockExclusive ((pmutex)), ! 0) +# elif defined(mhd_MUTEX_KIND_W32_CS) /** * Acquire a lock on previously initialised mutex. * If the mutex was already locked by other thread, function blocks until @@ -247,17 +247,17 @@ typedef CRITICAL_SECTION mhd_mutex; * @param pmutex the pointer to the mutex * @return always nonzero (success) */ -# define mhd_mutex_lock(pmutex) (EnterCriticalSection ((pmutex)), ! 0) -#endif +# define mhd_mutex_lock(pmutex) (EnterCriticalSection ((pmutex)), ! 0) +# endif -#if defined(mhd_MUTEX_KIND_PTHREAD) +# if defined(mhd_MUTEX_KIND_PTHREAD) /** * Unlock previously locked mutex. * @param pmutex the pointer to the mutex * @return nonzero on success, zero otherwise */ -# define mhd_mutex_unlock(pmutex) (0 == pthread_mutex_unlock ((pmutex))) -#elif defined(mhd_MUTEX_KIND_W32_SRW) +# define mhd_mutex_unlock(pmutex) (0 == pthread_mutex_unlock ((pmutex))) +# elif defined(mhd_MUTEX_KIND_W32_SRW) /** * Acquire a lock on previously initialised mutex. * If the mutex was already locked by other thread, function blocks until @@ -265,25 +265,25 @@ typedef CRITICAL_SECTION mhd_mutex; * @param pmutex the pointer to the mutex * @return always nonzero (success) */ -# define mhd_mutex_unlock(pmutex) (ReleaseSRWLockExclusive ((pmutex)), ! 0) -#elif defined(mhd_MUTEX_KIND_W32_CS) +# define mhd_mutex_unlock(pmutex) (ReleaseSRWLockExclusive ((pmutex)), ! 0) +# elif defined(mhd_MUTEX_KIND_W32_CS) /** * Unlock previously initialised and locked mutex. * @param pmutex pointer to mutex * @return always nonzero (success) */ -# define mhd_mutex_unlock(pmutex) (LeaveCriticalSection ((pmutex)), ! 0) -#endif +# define mhd_mutex_unlock(pmutex) (LeaveCriticalSection ((pmutex)), ! 0) +# endif /** * Destroy previously initialised mutex and abort execution if error is * detected. * @param pmutex the pointer to the mutex */ -#define mhd_mutex_destroy_chk(pmutex) do { \ - if (! mhd_mutex_destroy (pmutex)) \ - MHD_PANIC ("Failed to destroy mutex.\n"); \ -} while (0) +# define mhd_mutex_destroy_chk(pmutex) do { \ + if (! mhd_mutex_destroy (pmutex)) \ + MHD_PANIC ("Failed to destroy mutex.\n"); \ + } while (0) /** * Acquire a lock on previously initialised mutex. @@ -292,20 +292,20 @@ typedef CRITICAL_SECTION mhd_mutex; * If error is detected, execution is aborted. * @param pmutex the pointer to the mutex */ -#define mhd_mutex_lock_chk(pmutex) do { \ - if (! mhd_mutex_lock (pmutex)) \ - MHD_PANIC ("Failed to lock mutex.\n"); \ -} while (0) +# define mhd_mutex_lock_chk(pmutex) do { \ + if (! mhd_mutex_lock (pmutex)) \ + MHD_PANIC ("Failed to lock mutex.\n"); \ + } while (0) /** * Unlock previously locked mutex. * If error is detected, execution is aborted. * @param pmutex the pointer to the mutex */ -#define mhd_mutex_unlock_chk(pmutex) do { \ - if (! mhd_mutex_unlock (pmutex)) \ - MHD_PANIC ("Failed to unlock mutex.\n"); \ -} while (0) +# define mhd_mutex_unlock_chk(pmutex) do { \ + if (! mhd_mutex_unlock (pmutex)) \ + MHD_PANIC ("Failed to unlock mutex.\n"); \ + } while (0) #else /* ! MHD_SUPPORT_THREADS */ diff --git a/src/mhd2/mhd_md5.h b/src/mhd2/mhd_md5.h @@ -48,13 +48,13 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_MD5 -#error This file must be used only when MD5 is enabled +# error This file must be used only when MD5 is enabled #endif #ifndef MHD_MD5_EXTR -#include "md5_int.h" +# include "md5_int.h" #else /* MHD_MD5_EXTR */ -#include "md5_ext.h" +# include "md5_ext.h" #endif /* MHD_MD5_EXTR */ #ifndef mhd_MD5_DIGEST_SIZE @@ -92,20 +92,20 @@ /** * Finalise MD5 calculation, return digest, reset hash calculation. */ -# define mhd_MD5_finish_reset(ctx,digest) \ - (mhd_MD5_finish (ctx,digest), mhd_MD5_reset (ctx)) +# define mhd_MD5_finish_reset(ctx, digest) \ + (mhd_MD5_finish (ctx,digest), mhd_MD5_reset (ctx)) /** * Finalise hash calculation, return digest, de-initialise hash calculation. */ -# define mhd_MD5_finish_deinit(ctx,digest) \ - (mhd_MD5_finish (ctx,digest), mhd_MD5_deinit (ctx)) +# define mhd_MD5_finish_deinit(ctx, digest) \ + (mhd_MD5_finish (ctx,digest), mhd_MD5_deinit (ctx)) #else /* mhd_MD5_HAS_FINISH_RESET */ # define mhd_MD5_reset(ctx) ((void) 0) /** * Finalise hash calculation, return digest, de-initialise hash calculation. */ -# define mhd_MD5_finish_deinit(ctx,digest) \ - (mhd_MD5_finish_reset (ctx,digest), mhd_MD5_deinit (ctx)) +# define mhd_MD5_finish_deinit(ctx, digest) \ + (mhd_MD5_finish_reset (ctx,digest), mhd_MD5_deinit (ctx)) #endif /* mhd_MD5_HAS_FINISH_RESET */ #ifndef mhd_MD5_HAS_DEINIT @@ -114,15 +114,15 @@ #ifdef mhd_MD5_HAS_EXT_ERROR -#define mhd_MD5_has_err(ctx) (0 != ((ctx)->ext_error)) +# define mhd_MD5_has_err(ctx) (0 != ((ctx)->ext_error)) #else /* ! mhd_MD5_HAS_EXT_ERROR */ -#define mhd_MD5_has_err(ctx) (((void) (ctx)), ! ! 0) +# define mhd_MD5_has_err(ctx) (((void) (ctx)), ! ! 0) #endif /* ! mhd_SHA512_256_HAS_EXT_ERROR */ /* Sanity checks */ -#if ! defined(mhd_MD5_HAS_FINISH_RESET) && ! defined(mhd_MD5_HAS_FINISH) -#error Required at least one of mhd_MD5_finish_reset(), mhd_MD5_finish() +#if !defined(mhd_MD5_HAS_FINISH_RESET) && !defined(mhd_MD5_HAS_FINISH) +# error Required at least one of mhd_MD5_finish_reset(), mhd_MD5_finish() #endif /* ! mhd_MD5_HAS_FINISH_RESET && ! mhd_MD5_HAS_FINISH */ #endif /* MHD_MD5_H */ diff --git a/src/mhd2/mhd_mono_clock.c b/src/mhd2/mhd_mono_clock.c @@ -46,7 +46,7 @@ #include "mhd_mono_clock.h" -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) /* Prefer native clock source over wrappers */ # ifdef HAVE_CLOCK_GETTIME # undef HAVE_CLOCK_GETTIME @@ -110,7 +110,7 @@ static time_t mono_clock_start; #endif /* HAVE_CLOCK_GETTIME || HAVE_CLOCK_GET_TIME || HAVE_GETHRTIME */ #ifdef HAVE_CLOCK_GET_TIME -# if ! defined(SYSTEM_CLOCK) && defined(REALTIME_CLOCK) +# if !defined(SYSTEM_CLOCK) && defined(REALTIME_CLOCK) # define SYSTEM_CLOCK REALTIME_CLOCK # endif # define mhd_CLOCK_SERV_INVALID ((clock_serv_t) -2) @@ -145,7 +145,7 @@ static uint64_t perf_start; /* 'uint64_t' is available on W32 always */ #if defined(HAVE_TIMESPEC_GET) || defined(HAVE_GETTIMEOFDAY) /* The start value shared for timespec_get() and gettimeofday () */ static time_t gettime_start; -#define mhd_HAVE_GETTIME_START_VAR 1 +# define mhd_HAVE_GETTIME_START_VAR 1 #endif /* HAVE_TIMESPEC_GET || HAVE_GETTIMEOFDAY */ static time_t sys_clock_start; @@ -173,8 +173,8 @@ mclock_init_clock_get_time (mach_timespec_t *cur_time) if (KERN_SUCCESS != clock_get_time (mono_clock_service, cur_time)) { - (void) mach_port_deallocate (mach_task_self (), - mono_clock_service); + (void)mach_port_deallocate (mach_task_self (), + mono_clock_service); mono_clock_service = mhd_CLOCK_SERV_INVALID; return false; } @@ -191,8 +191,8 @@ static void mclock_deinit_clock_get_time (void) { mhd_assert (mhd_CLOCK_SERV_INVALID != mono_clock_service); - (void) mach_port_deallocate (mach_task_self (), - mono_clock_service); + (void)mach_port_deallocate (mach_task_self (), + mono_clock_service); mono_clock_service = mhd_CLOCK_SERV_INVALID; } @@ -257,7 +257,7 @@ mclock_init_mach_time (void) comm_div = mclock_gcd (mach_tb_info.numer, nanosec_in_milisec); mach_time_mls_numer = mach_tb_info.numer / comm_div; mach_time_mls_denom = - ((uint_fast64_t) mach_tb_info.denom) * (nanosec_in_milisec / comm_div); + ((uint_fast64_t)mach_tb_info.denom) * (nanosec_in_milisec / comm_div); return true; } @@ -315,14 +315,14 @@ enum mhd_mono_clock_source #endif /* HAVE_GETHRTIME */ #ifdef _WIN32 -#if _WIN32_WINNT >= 0x0600 +# if _WIN32_WINNT >= 0x0600 , /** * GetTickCount64() * W32 tick counter source. */ mhd_MCLOCK_SOUCE_GETTICKCOUNT64 -#else /* _WIN32_WINNT < 0x0600 */ +# else /* _WIN32_WINNT < 0x0600 */ , /** @@ -330,7 +330,7 @@ enum mhd_mono_clock_source * Older W32 monotonic time source. */ mhd_MCLOCK_SOUCE_PERFCOUNTER -#endif /* _WIN32_WINNT < 0x0600 */ +# endif /* _WIN32_WINNT < 0x0600 */ #endif /* _WIN32 */ }; @@ -362,7 +362,7 @@ mhd_mclock_init_once (void) /* Try specialised fast sources */ #ifdef _WIN32 -#if _WIN32_WINNT >= 0x0600 +# if _WIN32_WINNT >= 0x0600 /* W32 Vista or later specific monotonic clock */ /* Available since Vista, ~15ms accuracy */ if (1) @@ -371,7 +371,7 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTICKCOUNT64; } else -#else /* _WIN32_WINNT < 0x0600 */ +# else /* _WIN32_WINNT < 0x0600 */ /* W32 specific monotonic clock */ /* Available on Windows 2000 and later */ if (1) @@ -379,14 +379,14 @@ mhd_mclock_init_once (void) LARGE_INTEGER freq; LARGE_INTEGER perf_counter; - (void) QueryPerformanceFrequency (&freq); /* never fail on XP and later */ - (void) QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ - perf_freq = (uint64_t) freq.QuadPart; - perf_start = (uint64_t) perf_counter.QuadPart; + (void)QueryPerformanceFrequency (&freq); /* never fail on XP and later */ + (void)QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ + perf_freq = (uint64_t)freq.QuadPart; + perf_start = (uint64_t)perf_counter.QuadPart; mono_clock_source = mhd_MCLOCK_SOUCE_PERFCOUNTER; } else -#endif /* _WIN32_WINNT < 0x0600 */ +# endif /* _WIN32_WINNT < 0x0600 */ #endif /* _WIN32 */ #if defined(mhd_USE_MACH_TIME) /* Mach (Darwin) specific monotonic clock */ @@ -408,7 +408,7 @@ mhd_mclock_init_once (void) /* Try universally available sources */ #ifdef HAVE_CLOCK_GETTIME -#ifdef CLOCK_MONOTONIC_COARSE +# ifdef CLOCK_MONOTONIC_COARSE /* Linux-specific fast value-getting clock */ /* Can be affected by frequency adjustment and doesn't count time * in suspend, but preferred since it's fast */ @@ -420,8 +420,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_MONOTONIC_COARSE */ -#ifdef CLOCK_MONOTONIC_FAST +# endif /* CLOCK_MONOTONIC_COARSE */ +# ifdef CLOCK_MONOTONIC_FAST /* FreeBSD/DragonFly fast value-getting clock */ /* Can be affected by frequency adjustment, but preferred since it's fast */ if (0 == clock_gettime (CLOCK_MONOTONIC_FAST, @@ -432,8 +432,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_MONOTONIC_COARSE */ -#ifdef CLOCK_UPTIME_FAST +# endif /* CLOCK_MONOTONIC_COARSE */ +# ifdef CLOCK_UPTIME_FAST /* FreeBSD/DragonFly fast value-getting clock */ /* Can be affected by frequency adjustment and doesn't count time * in suspend, but preferred since it's fast */ @@ -445,8 +445,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_UPTIME_FAST */ -#ifdef CLOCK_MONOTONIC_RAW_APPROX +# endif /* CLOCK_UPTIME_FAST */ +# ifdef CLOCK_MONOTONIC_RAW_APPROX /* Darwin-specific clock */ /* Not affected by frequency adjustment, returns clock value cached at * context switch. Can be "milliseconds old", but it's fast. */ @@ -458,8 +458,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_MONOTONIC_RAW */ -#ifdef CLOCK_UPTIME_RAW_APPROX +# endif /* CLOCK_MONOTONIC_RAW */ +# ifdef CLOCK_UPTIME_RAW_APPROX /* Darwin-specific clock */ /* Not affected by frequency adjustment, but doesn't count time in suspend. * Returns clock value cached at context switch. @@ -472,8 +472,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_UPTIME_RAW_APPROX */ -#ifdef CLOCK_MONOTONIC_RAW +# endif /* CLOCK_UPTIME_RAW_APPROX */ +# ifdef CLOCK_MONOTONIC_RAW /* Linux and Darwin clock */ /* Not affected by frequency adjustment, * on Linux doesn't count time in suspend */ @@ -485,8 +485,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_MONOTONIC_RAW */ -#ifdef CLOCK_BOOTTIME +# endif /* CLOCK_MONOTONIC_RAW */ +# ifdef CLOCK_BOOTTIME /* Counts time in suspend on Linux so it's real monotonic, */ /* but can be slower value-getting than other clocks */ if (0 == clock_gettime (CLOCK_BOOTTIME, @@ -497,8 +497,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_BOOTTIME */ -#ifdef CLOCK_MONOTONIC +# endif /* CLOCK_BOOTTIME */ +# ifdef CLOCK_MONOTONIC /* Monotonic clock */ /* Widely supported, may be affected by frequency adjustment */ /* On Linux it's not truly monotonic as it doesn't count time in suspend */ @@ -510,8 +510,8 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_MONOTONIC */ -#ifdef CLOCK_UPTIME +# endif /* CLOCK_MONOTONIC */ +# ifdef CLOCK_UPTIME /* non-Linux clock */ /* Doesn't count time in suspend */ if (0 == clock_gettime (CLOCK_UPTIME, @@ -522,7 +522,7 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_BOOTTIME */ +# endif /* CLOCK_BOOTTIME */ #endif /* HAVE_CLOCK_GETTIME */ #ifdef HAVE_CLOCK_GET_TIME /* Darwin-specific monotonic clock source */ @@ -536,7 +536,7 @@ mhd_mclock_init_once (void) else #endif /* HAVE_CLOCK_GET_TIME */ #ifdef HAVE_CLOCK_GETTIME -#ifdef CLOCK_HIGHRES +# ifdef CLOCK_HIGHRES /* Solaris-specific monotonic high-resolution clock */ /* Not preferred due to be potentially resource-hungry */ if (0 == clock_gettime (CLOCK_HIGHRES, @@ -547,7 +547,7 @@ mhd_mclock_init_once (void) mono_clock_source = mhd_MCLOCK_SOUCE_GETTIME; } else -#endif /* CLOCK_HIGHRES */ +# endif /* CLOCK_HIGHRES */ #endif /* HAVE_CLOCK_GETTIME */ #ifdef HAVE_GETHRTIME /* HP-UX and Solaris monotonic clock */ @@ -559,7 +559,7 @@ mhd_mclock_init_once (void) } else #endif /* HAVE_GETHRTIME */ - (void) 0; /* The end of if-else chain */ + (void)0; /* The end of if-else chain */ /* Initialise start values for fallbacks */ #ifdef HAVE_TIMESPEC_GET @@ -584,7 +584,7 @@ mhd_mclock_init_once (void) sys_clock_start = time (NULL); #ifdef mhd_HAVE_GETTIME_START_VAR - if (((time_t) -1) == sys_clock_start) + if (((time_t)-1) == sys_clock_start) sys_clock_start = gettime_start; #endif /* mhd_HAVE_GETTIME_START_VAR */ } @@ -606,7 +606,7 @@ mhd_mclock_re_init (void) { if (mhd_MCLOCK_SOUCE_GET_TIME == mono_clock_source) { - if (! mclock_init_clock_get_time (NULL)) + if (!mclock_init_clock_get_time (NULL)) /* Fallback to full initialisation */ mhd_mclock_init_once (); } @@ -650,8 +650,8 @@ mhd_monotonic_msec_counter (void) if (0 == clock_gettime (mono_clock_id, &ts)) return (uint_fast64_t) - (((uint_fast64_t) (ts.tv_sec - mono_clock_start)) * 1000 - + (uint_fast64_t) (ts.tv_nsec / 1000000)); + (((uint_fast64_t)(ts.tv_sec - mono_clock_start)) * 1000 + + (uint_fast64_t)(ts.tv_nsec / 1000000)); } break; #endif /* HAVE_CLOCK_GETTIME */ @@ -670,14 +670,14 @@ mhd_monotonic_msec_counter (void) # endif # ifndef MHD_FAVOR_SMALL_CODE if (1 == mach_time_mls_numer) /* Shortcut for the most common situation */ - return (uint_fast64_t) t / mach_time_mls_denom; + return (uint_fast64_t)t / mach_time_mls_denom; # endif /* MHD_FAVOR_SMALL_CODE */ /* Avoid float point arithmetic as it lower precision on higher values. Two stages calculations to avoid overflow of integer values and keep precision high enough. */ - return (((uint_fast64_t) t) / mach_time_mls_denom) * mach_time_mls_numer - + ((((uint_fast64_t) t) % mach_time_mls_denom) + return (((uint_fast64_t)t) / mach_time_mls_denom) * mach_time_mls_numer + + ((((uint_fast64_t)t) % mach_time_mls_denom) * mach_time_mls_numer) / mach_time_mls_denom; } break; @@ -693,22 +693,22 @@ mhd_monotonic_msec_counter (void) if (KERN_SUCCESS == clock_get_time (mono_clock_service, &cur_time)) return (uint_fast64_t) - (((uint_fast64_t) (cur_time.tv_sec - mono_clock_start)) * 1000 - + (uint_fast64_t) (cur_time.tv_nsec / 1000000)); + (((uint_fast64_t)(cur_time.tv_sec - mono_clock_start)) * 1000 + + (uint_fast64_t)(cur_time.tv_nsec / 1000000)); } break; #endif /* HAVE_CLOCK_GET_TIME */ #ifdef HAVE_GETHRTIME case mhd_MCLOCK_SOUCE_GETHRTIME: - return ((uint_fast64_t) (gethrtime () - hrtime_start)) / 1000000; + return ((uint_fast64_t)(gethrtime () - hrtime_start)) / 1000000; #endif /* HAVE_GETHRTIME */ #ifdef _WIN32 -#if _WIN32_WINNT >= 0x0600 +# if _WIN32_WINNT >= 0x0600 case mhd_MCLOCK_SOUCE_GETTICKCOUNT64: - return (uint_fast64_t) (GetTickCount64 () - tick_start); -#else /* _WIN32_WINNT < 0x0600 */ + return (uint_fast64_t)(GetTickCount64 () - tick_start); +# else /* _WIN32_WINNT < 0x0600 */ case mhd_MCLOCK_SOUCE_PERFCOUNTER: mhd_assert (0 != perf_freq); if (1) @@ -716,13 +716,13 @@ mhd_monotonic_msec_counter (void) LARGE_INTEGER perf_counter; uint_fast64_t num_ticks; - (void) QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ - num_ticks = (uint_fast64_t) (perf_counter.QuadPart - perf_start); + (void)QueryPerformanceCounter (&perf_counter); /* never fail on XP and later */ + num_ticks = (uint_fast64_t)(perf_counter.QuadPart - perf_start); return ((num_ticks / perf_freq) * 1000) + (((num_ticks % perf_freq) * 1000) / perf_freq); } break; -#endif /* _WIN32_WINNT < 0x0600 */ +# endif /* _WIN32_WINNT < 0x0600 */ #endif /* _WIN32 */ default: mhd_UNREACHABLE (); @@ -736,8 +736,8 @@ mhd_monotonic_msec_counter (void) struct timespec ts; if (TIME_UTC == timespec_get (&ts, TIME_UTC)) return (uint_fast64_t) - (((uint_fast64_t) (ts.tv_sec - gettime_start)) * 1000 - + (uint_fast64_t) (ts.tv_nsec / 1000000)); + (((uint_fast64_t)(ts.tv_sec - gettime_start)) * 1000 + + (uint_fast64_t)(ts.tv_nsec / 1000000)); } #elif defined(HAVE_GETTIMEOFDAY) if (1) @@ -745,8 +745,8 @@ mhd_monotonic_msec_counter (void) struct timeval tv; if (0 == gettimeofday (&tv, NULL)) return (uint_fast64_t) - (((uint_fast64_t) (tv.tv_sec - gettime_start)) * 1000 - + (uint_fast64_t) (tv.tv_usec / 1000)); + (((uint_fast64_t)(tv.tv_sec - gettime_start)) * 1000 + + (uint_fast64_t)(tv.tv_usec / 1000)); } #endif /* HAVE_GETTIMEOFDAY */ @@ -756,11 +756,11 @@ mhd_monotonic_msec_counter (void) { time_t time_now; time_now = time (NULL); - if (((time_t) -1) != time_now) - return ((uint_fast64_t) (time_now - sys_clock_start)) * 1000; + if (((time_t)-1) != time_now) + return ((uint_fast64_t)(time_now - sys_clock_start)) * 1000; } return 0; /* No time source, should not really happen */ #else /* ! mhd_HAVE_GETTIME_START_VAR */ - return ((uint_fast64_t) (time (NULL) - sys_clock_start)) * 1000; + return ((uint_fast64_t)(time (NULL) - sys_clock_start)) * 1000; #endif } diff --git a/src/mhd2/mhd_panic.c b/src/mhd2/mhd_panic.c @@ -57,7 +57,7 @@ /** * The user handler for panic */ -static MHD_PanicCallback user_panic_handler = (MHD_PanicCallback) NULL; +static MHD_PanicCallback user_panic_handler = (MHD_PanicCallback)NULL; /** * The closure argument for the #user_panic_handler @@ -67,7 +67,7 @@ static void *user_panic_handler_cls = NULL; MHD_INTERNAL void mhd_panic_init_default (void) { - user_panic_handler = (MHD_PanicCallback) NULL; + user_panic_handler = (MHD_PanicCallback)NULL; } diff --git a/src/mhd2/mhd_panic.h b/src/mhd2/mhd_panic.h @@ -50,16 +50,16 @@ #ifndef BUILDING_MHD_LIB /* Simplified implementation, utilised by unit tests that use some parts of the library code directly. */ -#include <stdio.h> -#ifdef HAVE_STDLIB_H -# include <stdlib.h> -#elif defined(HAVE_UNISTD_H) -# include <unistd.h> -#endif +# include <stdio.h> +# ifdef HAVE_STDLIB_H +# include <stdlib.h> +# elif defined(HAVE_UNISTD_H) +# include <unistd.h> +# endif -#define MHD_PANIC(msg) \ - do { fprintf (stderr,"Unrecoverable error: %s\n", msg); abort (); } \ - while (0) +# define MHD_PANIC(msg) \ + do { fprintf (stderr,"Unrecoverable error: %s\n", msg); abort (); } \ + while (0) #else /* BUILDING_MHD_LIB */ /* Fully functional implementation for the library */ @@ -78,39 +78,39 @@ mhd_panic (const char *file, const char *message); -#ifdef MHD_PANIC -#error MHD_PANIC macro is already defined. Check other headers. -#endif /* MHD_PANIC */ +# ifdef MHD_PANIC +# error MHD_PANIC macro is already defined. Check other headers. +# endif /* MHD_PANIC */ -#ifdef MHD_SUPPORT_LOG_FUNCTIONALITY -# ifdef MHD_HAVE_MHD_FUNC_ +# ifdef MHD_SUPPORT_LOG_FUNCTIONALITY +# ifdef MHD_HAVE_MHD_FUNC_ /** * Panic processing for unrecoverable errors. * * @param msg the error message string */ -# define MHD_PANIC(msg) \ - mhd_panic (__FILE__, MHD_FUNC_, __LINE__, msg) -# else -# include "sys_null_macro.h" +# define MHD_PANIC(msg) \ + mhd_panic (__FILE__, MHD_FUNC_, __LINE__, msg) +# else +# include "sys_null_macro.h" /** * Panic processing for unrecoverable errors. * * @param msg the error message string */ -# define MHD_PANIC(msg) \ - mhd_panic (__FILE__, NULL, __LINE__, msg) -# endif -#else -# include "sys_null_macro.h" +# define MHD_PANIC(msg) \ + mhd_panic (__FILE__, NULL, __LINE__, msg) +# endif +# else +# include "sys_null_macro.h" /** * Panic processing for unrecoverable errors. * * @param msg the error message string */ # define MHD_PANIC(msg) \ - mhd_panic (NULL, NULL, __LINE__, NULL) -#endif + mhd_panic (NULL, NULL, __LINE__, NULL) +# endif /** * Initialise panic handler to default value diff --git a/src/mhd2/mhd_post_result.h b/src/mhd2/mhd_post_result.h @@ -129,7 +129,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ MHD_PostParseResult }; -#define MHD_POST_PARSE_RESULT_DEFINED 1 +# define MHD_POST_PARSE_RESULT_DEFINED 1 #endif /* ! MHD_POST_PARSE_RESULT_DEFINED */ diff --git a/src/mhd2/mhd_predict.h b/src/mhd2/mhd_predict.h @@ -81,11 +81,11 @@ # endif #else # ifdef __has_builtin -# if ! defined(MHD_HAVE___BUILTIN_EXPECT_WITH_PROBABILITY) && \ +# if !defined(MHD_HAVE___BUILTIN_EXPECT_WITH_PROBABILITY) && \ __has_builtin (__builtin_expect_with_probability) # define MHD_HAVE___BUILTIN_EXPECT_WITH_PROBABILITY 1 # endif -# if ! defined(MHD_HAVE___BUILTIN_EXPECT) && __has_builtin (__builtin_expect) +# if !defined(MHD_HAVE___BUILTIN_EXPECT) && __has_builtin (__builtin_expect) # define MHD_HAVE___BUILTIN_EXPECT 1 # endif # endif @@ -132,18 +132,18 @@ #if defined(MHD_HAVE___BUILTIN_EXPECT_WITH_PROBABILITY) -# define mhd_COND_PRED_TRUE_P(cond,prob) \ - __builtin_expect_with_probability (! ! (cond), ! 0, (prob)) -# define mhd_COND_PRED_FALSE_P(cond,prob) \ - __builtin_expect_with_probability (! ! (cond), 0, (prob)) +# define mhd_COND_PRED_TRUE_P(cond, prob) \ + __builtin_expect_with_probability (! ! (cond), ! 0, (prob)) +# define mhd_COND_PRED_FALSE_P(cond, prob) \ + __builtin_expect_with_probability (! ! (cond), 0, (prob)) #elif defined(MHD_HAVE___BUILTIN_EXPECT) -# define mhd_COND_PRED_TRUE_P(cond,prob) \ - (((prob) < 0.85) ? (! ! (cond)) : (__builtin_expect (! ! (cond), ! 0))) -# define mhd_COND_PRED_FALSE_P(cond,prob) \ - (((prob) < 0.85) ? (! ! (cond)) : (__builtin_expect (! ! (cond), 0))) +# define mhd_COND_PRED_TRUE_P(cond, prob) \ + (((prob) < 0.85) ? (! ! (cond)) : (__builtin_expect (! ! (cond), ! 0))) +# define mhd_COND_PRED_FALSE_P(cond, prob) \ + (((prob) < 0.85) ? (! ! (cond)) : (__builtin_expect (! ! (cond), 0))) #else -# define mhd_COND_PRED_TRUE_P(cond,prob) (! ! (cond)) -# define mhd_COND_PRED_FALSE_P(cond,prob) (! ! (cond)) +# define mhd_COND_PRED_TRUE_P(cond, prob) (! ! (cond)) +# define mhd_COND_PRED_FALSE_P(cond, prob) (! ! (cond)) #endif /* diff --git a/src/mhd2/mhd_read_file.c b/src/mhd2/mhd_read_file.c @@ -51,7 +51,7 @@ # include <unistd.h> #endif -#if ! defined(mhd_W32_NATIVE) +#if !defined(mhd_W32_NATIVE) # include "mhd_limits.h" #else /* Native W32 */ @@ -68,21 +68,21 @@ mhd_read_file (int file_fd, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict size_filled) { -#if (defined(HAVE_PREAD64) || defined(HAVE_PREAD)) && ! defined(mhd_W32_NATIVE) +#if (defined(HAVE_PREAD64) || defined(HAVE_PREAD)) && !defined(mhd_W32_NATIVE) # ifdef HAVE_PREAD64 - const off64_t pos_off = (off64_t) offset; + const off64_t pos_off = (off64_t)offset; # else /* HAVE_PREAD */ - const off_t pos_off = (off_t) offset; + const off_t pos_off = (off_t)offset; # endif /* HAVE_PREAD */ ssize_t res; *size_filled = 0; - if ((0 > pos_off) || - (offset != (uint_fast64_t) pos_off)) + if ((0 > pos_off) + || (offset != (uint_fast64_t)pos_off)) return mhd_FILE_READ_OFFSET_TOO_LARGE; - if (0 > (ssize_t) buf_size) + if (0 > (ssize_t)buf_size) buf_size = SSIZE_MAX; /* Larger sizes may result in undefined behaviour */ # ifdef HAVE_PREAD64 @@ -103,24 +103,24 @@ mhd_read_file (int file_fd, if (0 == res) return mhd_FILE_READ_EOF; - *size_filled = (size_t) res; + *size_filled = (size_t)res; return mhd_FILE_READ_OK; -#elif ! defined(mhd_W32_NATIVE) +#elif !defined(mhd_W32_NATIVE) /* Multithread-unsafe emulation */ # ifdef HAVE_LSEEK64 - const off64_t pos_off = (off64_t) offset; + const off64_t pos_off = (off64_t)offset; # else - const off_t pos_off = (off_t) offset; + const off_t pos_off = (off_t)offset; # endif ssize_t res; *size_filled = 0; - if ((0 > pos_off) || - (offset != (uint_fast64_t) pos_off)) + if ((0 > pos_off) + || (offset != (uint_fast64_t)pos_off)) return mhd_FILE_READ_OFFSET_TOO_LARGE; - if (0 > (ssize_t) buf_size) + if (0 > (ssize_t)buf_size) buf_size = SSIZE_MAX; /* Larger sizes may result in undefined behaviour */ # ifdef HAVE_LSEEK64 @@ -145,36 +145,36 @@ mhd_read_file (int file_fd, if (0 == res) return mhd_FILE_READ_EOF; - *size_filled = (size_t) res; + *size_filled = (size_t)res; return mhd_FILE_READ_OK; #else /* Native W32 */ const intptr_t sys_fd = _get_osfhandle (file_fd); - const HANDLE w_hndl = (HANDLE) sys_fd; + const HANDLE w_hndl = (HANDLE)sys_fd; OVERLAPPED ovrlp; DWORD reqReadSize; DWORD resReadSize; *size_filled = 0; - if ((((intptr_t) -2) == sys_fd) || - (INVALID_HANDLE_VALUE == w_hndl)) + if ((((intptr_t)-2) == sys_fd) + || (INVALID_HANDLE_VALUE == w_hndl)) return mhd_FILE_READ_ERROR; memset (&ovrlp, 0, sizeof(ovrlp)); - reqReadSize = (DWORD) buf_size; + reqReadSize = (DWORD)buf_size; if (reqReadSize != buf_size) - reqReadSize = (DWORD) (~((DWORD) 0)); - ovrlp.Offset = (DWORD) offset; + reqReadSize = (DWORD)(~((DWORD)0)); + ovrlp.Offset = (DWORD)offset; offset >>= 32; - ovrlp.OffsetHigh = (DWORD) offset; + ovrlp.OffsetHigh = (DWORD)offset; if (0 != (offset >> 32)) return mhd_FILE_READ_OFFSET_TOO_LARGE; - if (! ReadFile (w_hndl, - buf, - reqReadSize, - &resReadSize, - &ovrlp)) + if (!ReadFile (w_hndl, + buf, + reqReadSize, + &resReadSize, + &ovrlp)) return mhd_FILE_READ_ERROR; if (0 == resReadSize) diff --git a/src/mhd2/mhd_read_file.h b/src/mhd2/mhd_read_file.h @@ -100,7 +100,7 @@ mhd_read_file (int file_fd, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict size_filled) MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_(4, 3) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_OUT_SIZE_ (4, 3) MHD_FN_PAR_OUT_ (5); #endif /* ! MHD_READ_FILE_H */ diff --git a/src/mhd2/mhd_recv.c b/src/mhd2/mhd_recv.c @@ -60,7 +60,7 @@ #ifdef MHD_SUPPORT_HTTPS static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_recv_tls (struct MHD_Connection *restrict c, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], @@ -80,14 +80,14 @@ mhd_recv_tls (struct MHD_Connection *restrict c, if (mhd_SOCKET_ERR_AGAIN == res) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_RECV_READY)); else if (mhd_SOCKET_ERR_NO_ERROR == res) { - if (! c->sk.props.is_nonblck) + if (!c->sk.props.is_nonblck) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'recv-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_RECV_READY)); if (*received == buf_size) @@ -95,10 +95,10 @@ mhd_recv_tls (struct MHD_Connection *restrict c, if (mhd_tls_conn_has_data_in (c->tls)) c->tls_has_data_in = mhd_TLS_BUF_HAS_DATA_IN; } -#ifndef NDEBUG +# ifndef NDEBUG else - mhd_assert (! mhd_tls_conn_has_data_in (c->tls)); -#endif + mhd_assert (!mhd_tls_conn_has_data_in (c->tls)); +# endif } return res; @@ -108,7 +108,7 @@ mhd_recv_tls (struct MHD_Connection *restrict c, #endif /* MHD_SUPPORT_HTTPS */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_recv (struct MHD_Connection *restrict c, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], diff --git a/src/mhd2/mhd_recv.h b/src/mhd2/mhd_recv.h @@ -69,7 +69,7 @@ mhd_recv (struct MHD_Connection *restrict c, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict received) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); #endif /* ! MHD_RECV_H */ diff --git a/src/mhd2/mhd_request.h b/src/mhd2/mhd_request.h @@ -206,7 +206,7 @@ struct mhd_RequestField /** * Headers are kept in a double-linked list. */ - mhd_DLNKDL_LINKS (mhd_RequestField,fields); + mhd_DLNKDL_LINKS (mhd_RequestField, fields); }; mhd_DLINKEDL_LIST_DEF (mhd_RequestField); @@ -230,7 +230,7 @@ struct mhd_RequestPostField /** * Headers are kept in a double-linked list. */ - mhd_DLNKDL_LINKS (mhd_RequestPostField,post_fields); + mhd_DLNKDL_LINKS (mhd_RequestPostField, post_fields); }; mhd_DLINKEDL_LIST_DEF (mhd_RequestPostField); @@ -363,18 +363,18 @@ struct mhd_ReqAuthDigestData */ struct mhd_ReqAuthData { -#ifdef MHD_SUPPORT_AUTH_BASIC +# ifdef MHD_SUPPORT_AUTH_BASIC /** * Request Basic Auth data */ union mhd_ReqAuthBasicData basic; -#endif /* MHD_SUPPORT_AUTH_BASIC */ -#ifdef MHD_SUPPORT_AUTH_DIGEST +# endif /* MHD_SUPPORT_AUTH_BASIC */ +# ifdef MHD_SUPPORT_AUTH_DIGEST /** * Request Digest Auth data */ struct mhd_ReqAuthDigestData digest; -#endif /* MHD_SUPPORT_AUTH_DIGEST */ +# endif /* MHD_SUPPORT_AUTH_DIGEST */ }; #endif /* mhd_SUPPORT_AUTH */ @@ -395,13 +395,13 @@ struct MHD_Request /** * Linked list of parsed headers. */ - mhd_DLNKDL_LIST (mhd_RequestField,fields); + mhd_DLNKDL_LIST (mhd_RequestField, fields); #ifdef MHD_SUPPORT_POST_PARSER /** * Linked list of parsed POST fields. */ - mhd_DLNKDL_LIST (mhd_RequestPostField,post_fields); + mhd_DLNKDL_LIST (mhd_RequestPostField, post_fields); #endif /* MHD_SUPPORT_POST_PARSER */ /** @@ -558,9 +558,9 @@ struct MHD_Request #ifdef MHD_SUPPORT_HTTP2 # define mhd_REQ_GET_ACT_UNION(req) \ - (mhd_REQ_IS_HTTP2 ((req)) ? \ - &(((struct mhd_H2RequestData*) (req))->app_act) : \ - &((req)->app_act)) + (mhd_REQ_IS_HTTP2 ((req)) ? \ + &(((struct mhd_H2RequestData*) (req))->app_act) : \ + &((req)->app_act)) #else /* ! MHD_SUPPORT_HTTP2 */ # define mhd_REQ_GET_ACT_UNION(req) (&((req)->app_act)) #endif /* ! MHD_SUPPORT_HTTP2 */ diff --git a/src/mhd2/mhd_response.h b/src/mhd2/mhd_response.h @@ -102,7 +102,7 @@ struct mhd_ResponseHeader /** * The links to other headers */ - mhd_DLNKDL_LINKS (mhd_ResponseHeader,headers); + mhd_DLNKDL_LINKS (mhd_ResponseHeader, headers); }; /** @@ -386,13 +386,13 @@ struct MHD_Response /** * The double linked list of the response headers */ - mhd_DLNKDL_LIST (mhd_ResponseHeader,headers); + mhd_DLNKDL_LIST (mhd_ResponseHeader, headers); #ifdef MHD_SUPPORT_AUTH_DIGEST /** * The double linked list of the Digest Auth response headers */ - mhd_DLNKDL_LIST (mhd_RespAuthDigestHeader,auth_d_hdrs); + mhd_DLNKDL_LIST (mhd_RespAuthDigestHeader, auth_d_hdrs); #endif /** @@ -414,10 +414,10 @@ struct MHD_Response * Check whether the response has Digest Auth headers */ #ifdef MHD_SUPPORT_AUTH_DIGEST -#define mhd_RESP_HAS_AUTH_DIGEST(resp) \ - (NULL != mhd_DLINKEDL_GET_FIRST (resp, auth_d_hdrs)) +# define mhd_RESP_HAS_AUTH_DIGEST(resp) \ + (NULL != mhd_DLINKEDL_GET_FIRST (resp, auth_d_hdrs)) #else -#define mhd_RESP_HAS_AUTH_DIGEST(resp) (((void) (resp)), ! ! 0) +# define mhd_RESP_HAS_AUTH_DIGEST(resp) (((void) (resp)), ! ! 0) #endif #endif /* ! MHD_RESPONSE_H */ diff --git a/src/mhd2/mhd_rng.c b/src/mhd2/mhd_rng.c @@ -53,27 +53,27 @@ #include "sys_errno.h" #if defined(MHD_SUPPORT_OPENSSL) -#include <openssl/rand.h> +# include <openssl/rand.h> #endif #if defined(MHD_SUPPORT_GNUTLS) -#include <gnutls/crypto.h> +# include <gnutls/crypto.h> #endif #if defined(MHD_SUPPORT_MBEDTLS) -#include <mbedtls/entropy.h> -#include <mbedtls/ctr_drbg.h> +# include <mbedtls/entropy.h> +# include <mbedtls/ctr_drbg.h> #endif #if defined(__linux__) -#include <sys/random.h> -#include <unistd.h> +# include <sys/random.h> +# include <unistd.h> #elif defined(_WIN32) || defined(_WIN64) -#include <windows.h> -#include <bcrypt.h> -#pragma comment(lib, "bcrypt.lib") +# include <windows.h> +# include <bcrypt.h> +# pragma comment(lib, "bcrypt.lib") #elif defined(__FreeBSD__) -#include <sys/random.h> +# include <sys/random.h> #else -#include <stdio.h> -#include <unistd.h> +# include <stdio.h> +# include <unistd.h> #endif #ifdef MHD_SUPPORT_SHA512_256 @@ -96,11 +96,11 @@ MHD_INTERNAL bool mhd_rng (size_t buf_size, uint8_t buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)]) { - #if defined(MHD_SUPPORT_OPENSSL) +#if defined(MHD_SUPPORT_OPENSSL) /* OpenSSL - RAND_bytes() */ mhd_assert (buf_size < INT_MAX); - if (1 == RAND_bytes ((unsigned char *) buf, - (int) buf_size)) + if (1 == RAND_bytes ((unsigned char *)buf, + (int)buf_size)) return true; #endif #if defined(MHD_SUPPORT_GNUTLS) @@ -137,11 +137,11 @@ mhd_rng (size_t buf_size, } } - if ( (1 == initialized) && - (0 == - mbedtls_ctr_drbg_random (&ctr_drbg, - (unsigned char *) buf, - buf_size)) ) + if ((1 == initialized) + && (0 == + mbedtls_ctr_drbg_random (&ctr_drbg, + (unsigned char *)buf, + buf_size))) return true; } #endif @@ -150,7 +150,7 @@ mhd_rng (size_t buf_size, { /* Modern Linux with glibc >= 2.25 - getrandom() syscall */ size_t offset = 0; - unsigned char *ptr = (unsigned char *) buf; + unsigned char *ptr = (unsigned char *)buf; while (1) { @@ -167,7 +167,7 @@ mhd_rng (size_t buf_size, } break; /* failure */ } - offset += (size_t) ret; + offset += (size_t)ret; if (offset == buf_size) return true; } @@ -176,8 +176,8 @@ mhd_rng (size_t buf_size, /* Windows - BCryptGenRandom() */ if (STATUS_SUCCESS == BCryptGenRandom (NULL, - (PUCHAR) buf, - (ULONG) buf_size, + (PUCHAR)buf, + (ULONG)buf_size, BCRYPT_USE_SYSTEM_PREFERRED_RNG)) return true; #elif defined(__FreeBSD__) @@ -191,8 +191,8 @@ mhd_rng (size_t buf_size, static int tried = 0; static FILE *fp = NULL; - if ( (0 == tried) && - (NULL == fp) ) + if ((0 == tried) + && (NULL == fp)) { tried = 1; fp = fopen ("/dev/urandom", diff --git a/src/mhd2/mhd_rng.h b/src/mhd2/mhd_rng.h @@ -62,6 +62,6 @@ MHD_INTERNAL bool mhd_rng (size_t buf_size, uint8_t buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)]) -MHD_FN_PAR_OUT_SIZE_ (2,1); +MHD_FN_PAR_OUT_SIZE_ (2, 1); #endif /* ! MHD_RNG_H */ diff --git a/src/mhd2/mhd_send.c b/src/mhd2/mhd_send.c @@ -102,7 +102,7 @@ #ifdef mhd_USE_VECT_SEND -# if (! defined(HAVE_SENDMSG) || ! defined(HAVE_DCLR_MSG_NOSIGNAL)) && \ +# if (!defined(HAVE_SENDMSG) || !defined(HAVE_DCLR_MSG_NOSIGNAL)) && \ defined(mhd_SEND_SPIPE_SUPPRESS_POSSIBLE) && \ defined(mhd_SEND_SPIPE_SUPPRESS_NEEDED) # define mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED 1 @@ -174,7 +174,7 @@ iov_max_init_ (void) { long res = sysconf (_SC_IOV_MAX); if (res >= 0) - mhd_iov_max_ = (unsigned long) res; + mhd_iov_max_ = (unsigned long)res; else { # if defined(IOV_MAX) @@ -192,12 +192,12 @@ iov_max_init_ (void) # define mhd_IOV_MAX mhd_iov_max_ #else /* ! HAVE_SYSCONF || ! _SC_IOV_MAX */ # define iov_max_init_() ((void) 0) -# if defined(IOV_MAX) +# if defined(IOV_MAX) /** * IOV_MAX (static) value */ -# define mhd_IOV_MAX IOV_MAX +# define mhd_IOV_MAX IOV_MAX # endif /* IOV_MAX */ #endif /* ! HAVE_SYSCONF || ! _SC_IOV_MAX */ @@ -235,15 +235,15 @@ mhd_connection_set_nodelay_state (struct mhd_ConnSocket *restrict sk, if (mhd_T_IS_YES (sk->props.is_nonip)) return false; -#ifndef mhd_NODELAY_SET_PUSH_DATA_ALWAYS - mhd_assert ((! nodelay_state) || (mhd_T_IS_NOT_YES (sk->state.nodelay))); -#endif /* mhd_NODELAY_SET_PUSH_DATA_ALWAYS */ +# ifndef mhd_NODELAY_SET_PUSH_DATA_ALWAYS + mhd_assert ((!nodelay_state) || (mhd_T_IS_NOT_YES (sk->state.nodelay))); +# endif /* mhd_NODELAY_SET_PUSH_DATA_ALWAYS */ mhd_assert ((nodelay_state) || (mhd_T_IS_NOT_NO (sk->state.nodelay))); if (0 == mhd_setsockopt (sk->fd, IPPROTO_TCP, TCP_NODELAY, - (const void *) (nodelay_state ? &on_val : &off_val), + (const void *)(nodelay_state ? &on_val : &off_val), sizeof (off_val))) { sk->state.nodelay = nodelay_state ? mhd_T_YES : mhd_T_NO; @@ -251,22 +251,22 @@ mhd_connection_set_nodelay_state (struct mhd_ConnSocket *restrict sk, } err_code = mhd_SCKT_GET_LERR (); - if ((mhd_T_IS_NOT_YES (sk->props.is_nonip)) && - (mhd_SCKT_ERR_IS_EINVAL (err_code) || - mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) || - mhd_SCKT_ERR_IS_NOTSOCK (err_code))) + if ((mhd_T_IS_NOT_YES (sk->props.is_nonip)) + && (mhd_SCKT_ERR_IS_EINVAL (err_code) + || mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) + || mhd_SCKT_ERR_IS_NOTSOCK (err_code))) { sk->props.is_nonip = mhd_T_YES; } -#if 0 /* No messages, avoid potential message flood in the log */ +# if 0 /* No messages, avoid potential message flood in the log */ else { mhd_LOG_MSG (connection->daemon, MHD_SC_SOCKET_TCP_NODELAY_FAILED, \ "Failed to set required TCP_NODELAY option for the socket."); } -#endif /* No messages */ +# endif /* No messages */ #else /* ! TCP_NODELAY */ - (void) nodelay_state; /* Mute compiler warnings */ + (void)nodelay_state; /* Mute compiler warnings */ sk->state.nodelay = mhd_T_NO; #endif /* ! TCP_NODELAY */ return false; @@ -295,15 +295,15 @@ mhd_connection_set_cork_state (struct mhd_ConnSocket *restrict sk, if (mhd_T_IS_YES (sk->props.is_nonip)) return false; - mhd_assert ((! cork_state) || (mhd_T_IS_NOT_YES (sk->state.corked))); -#ifndef mhd_CORK_RESET_PUSH_DATA_ALWAYS + mhd_assert ((!cork_state) || (mhd_T_IS_NOT_YES (sk->state.corked))); +# ifndef mhd_CORK_RESET_PUSH_DATA_ALWAYS mhd_assert ((cork_state) || (mhd_T_IS_NOT_NO (sk->state.corked))); -#endif /* mhd_CORK_RESET_PUSH_DATA_ALWAYS */ +# endif /* mhd_CORK_RESET_PUSH_DATA_ALWAYS */ if (0 == mhd_setsockopt (sk->fd, IPPROTO_TCP, mhd_TCP_CORK_NOPUSH, - (const void *) (cork_state ? &on_val : &off_val), + (const void *)(cork_state ? &on_val : &off_val), sizeof (off_val))) { sk->state.corked = cork_state ? mhd_T_YES : mhd_T_NO; @@ -311,28 +311,28 @@ mhd_connection_set_cork_state (struct mhd_ConnSocket *restrict sk, } err_code = mhd_SCKT_GET_LERR (); - if ((mhd_T_IS_NOT_YES (sk->props.is_nonip)) && - (mhd_SCKT_ERR_IS_EINVAL (err_code) || - mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) || - mhd_SCKT_ERR_IS_NOTSOCK (err_code))) + if ((mhd_T_IS_NOT_YES (sk->props.is_nonip)) + && (mhd_SCKT_ERR_IS_EINVAL (err_code) + || mhd_SCKT_ERR_IS_NOPROTOOPT (err_code) + || mhd_SCKT_ERR_IS_NOTSOCK (err_code))) { sk->props.is_nonip = mhd_T_YES; } -#if 0 /* No messages, avoid potential message flood in the log */ +# if 0 /* No messages, avoid potential message flood in the log */ else { -# ifdef TCP_CORK +# ifdef TCP_CORK mhd_LOG_MSG (connection->daemon, MHD_SC_SOCKET_TCP_CORK_NOPUSH_FAILED, \ "Failed to set required TCP_CORK option for the socket."); -# else +# else mhd_LOG_MSG (connection->daemon, MHD_SC_SOCKET_TCP_CORK_NOPUSH_FAILED, \ "Failed to set required TCP_NOPUSH option for the socket."); -# endif +# endif } -#endif /* No messages */ +# endif /* No messages */ #else /* ! mhd_TCP_CORK_NOPUSH */ - (void) cork_state; /* Mute compiler warnings. */ + (void)cork_state; /* Mute compiler warnings. */ sk->state.corked = mhd_T_NO; #endif /* ! mhd_TCP_CORK_NOPUSH */ return false; @@ -356,7 +356,7 @@ pre_send_setopt (struct mhd_ConnSocket *restrict sk, { /* Try to buffer data if not sending the final piece. * Final piece is indicated by push_data == true. */ - const bool buffer_data = (! push_data); + const bool buffer_data = (!push_data); if (mhd_T_IS_YES (sk->props.is_nonip)) return; @@ -376,7 +376,7 @@ pre_send_setopt (struct mhd_ConnSocket *restrict sk, return; /* Data is buffered by send() with MSG_MORE flag. * No need to check or change anything. */ #else /* ! mhd_USE_MSG_MORE */ - (void) plain_send; /* Mute compiler warning. */ + (void)plain_send; /* Mute compiler warning. */ #endif /* ! mhd_USE_MSG_MORE */ #ifdef mhd_TCP_CORK_NOPUSH @@ -612,10 +612,10 @@ zero_send (struct mhd_ConnSocket *restrict sk) mhd_assert (mhd_T_IS_YES (sk->state.nodelay)); if (0 == mhd_sys_send (sk->fd, &dummy, 0)) return true; -#if 0 /* No messages, avoid potential message flood in the log */ +# if 0 /* No messages, avoid potential message flood in the log */ mhd_LOG_MSG (connection->daemon, MHD_SC_SOCKET_ZERO_SEND_FAILED, \ "Failed to push the data by zero-sized send."); -#endif /* No messages */ +# endif /* No messages */ return false; } @@ -639,7 +639,7 @@ post_send_setopt (struct mhd_ConnSocket *restrict sk, { /* Try to buffer data if not sending the final piece. * Final piece is indicated by push_data == true. */ - const bool buffer_data = (! push_data); + const bool buffer_data = (!push_data); if (mhd_T_IS_YES (sk->props.is_nonip)) return; @@ -647,13 +647,13 @@ post_send_setopt (struct mhd_ConnSocket *restrict sk, return; /* Nothing to do after the send(). */ #ifndef mhd_USE_MSG_MORE - (void) plain_send_next; /* Mute compiler warning */ + (void)plain_send_next; /* Mute compiler warning */ #endif /* ! mhd_USE_MSG_MORE */ /* Need to push data. */ #ifdef mhd_TCP_CORK_NOPUSH - if (mhd_T_IS_YES (sk->state.nodelay) && \ - mhd_T_IS_NO (sk->state.corked)) + if (mhd_T_IS_YES (sk->state.nodelay) \ + && mhd_T_IS_NO (sk->state.corked)) return; /* Data has been already pushed by last send(). */ # ifdef mhd_CORK_RESET_PUSH_DATA_ALWAYS @@ -680,8 +680,8 @@ post_send_setopt (struct mhd_ConnSocket *restrict sk, * resetting of TCP_CORK so next final send without MSG_MORE will push * data to the network (without additional sys-call to push data). */ - if (mhd_T_IS_NOT_YES (sk->state.nodelay) || - (! plain_send_next)) + if (mhd_T_IS_NOT_YES (sk->state.nodelay) + || (!plain_send_next)) { if (mhd_connection_set_nodelay_state (sk, true)) return; /* Data has been pushed by TCP_NODELAY. */ @@ -751,24 +751,24 @@ post_send_setopt (struct mhd_ConnSocket *restrict sk, } else { -#ifdef mhd_CORK_RESET_PUSH_DATA +# ifdef mhd_CORK_RESET_PUSH_DATA enum mhd_Tristate old_cork_state = sk->state.corked; -#endif /* mhd_CORK_RESET_PUSH_DATA */ +# endif /* mhd_CORK_RESET_PUSH_DATA */ /* The socket is corked or cork state is unknown. */ if (mhd_connection_set_cork_state (sk, false)) { -#ifdef mhd_CORK_RESET_PUSH_DATA +# ifdef mhd_CORK_RESET_PUSH_DATA /* Modern FreeBSD or OpenBSD kernel */ if (mhd_T_IS_YES (old_cork_state)) return; /* Data has been pushed by uncorking the socket. */ -#endif /* mhd_CORK_RESET_PUSH_DATA */ +# endif /* mhd_CORK_RESET_PUSH_DATA */ /* Unlikely to reach this code. * The data should be pushed by uncorking (FreeBSD) or * the socket should be uncorked before send(). */ - if (mhd_T_IS_YES (sk->state.nodelay) || - (mhd_connection_set_nodelay_state (sk, true))) + if (mhd_T_IS_YES (sk->state.nodelay) + || (mhd_connection_set_nodelay_state (sk, true))) { /* TCP_NODELAY is turned ON on uncorked socket. * Use zero-send to push the data. */ @@ -778,7 +778,7 @@ post_send_setopt (struct mhd_ConnSocket *restrict sk, } /* Data cannot be pushed. */ } -#endif /* ! mhd_CORK_RESET_PUSH_DATA_ALWAYS */ +# endif /* ! mhd_CORK_RESET_PUSH_DATA_ALWAYS */ #else /* ! mhd_TCP_CORK_NOPUSH */ /* Corking is not supported. Buffering is controlled * by TCP_NODELAY only. */ @@ -811,7 +811,7 @@ post_send_setopt (struct mhd_ConnSocket *restrict sk, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5) enum mhd_SocketError mhd_sckt_send (struct mhd_ConnSocket *restrict sk, size_t buf_size, @@ -854,11 +854,11 @@ mhd_sckt_send (struct mhd_ConnSocket *restrict sk, return err; } - *sent = (size_t) res; + *sent = (size_t)res; - full_buf_sent = (buf_size == (size_t) res); + full_buf_sent = (buf_size == (size_t)res); - if (! full_buf_sent || ! sk->props.is_nonblck) + if (!full_buf_sent || !sk->props.is_nonblck) mhd_SCKT_NET_ST_CLEAR_FLAG (&(sk->ready), mhd_SOCKET_NET_STATE_SEND_READY); @@ -877,7 +877,7 @@ mhd_sckt_send (struct mhd_ConnSocket *restrict sk, #ifdef MHD_SUPPORT_HTTPS static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5) enum mhd_SocketError mhd_send_tls (struct MHD_Connection *restrict c, size_t buf_size, @@ -893,7 +893,7 @@ mhd_send_tls (struct MHD_Connection *restrict c, mhd_assert (mhd_D_HAS_TLS (c->daemon)); mhd_assert (0 != buf_size); - if (! custm_trnsp) + if (!custm_trnsp) pre_send_setopt (&(c->sk), false, push_data); res = mhd_tls_conn_send (c->tls, @@ -906,21 +906,21 @@ mhd_send_tls (struct MHD_Connection *restrict c, { if (mhd_SOCKET_ERR_AGAIN == res) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); return res; } - if (! c->sk.props.is_nonblck) + if (!c->sk.props.is_nonblck) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); /* If there is a need to push the data from network buffers * call post_send_setopt(). */ - if ((! custm_trnsp) && push_data && (buf_size == *sent)) + if ((!custm_trnsp) && push_data && (buf_size == *sent)) post_send_setopt (&(c->sk), false, true); return mhd_SOCKET_ERR_NO_ERROR; @@ -930,7 +930,7 @@ mhd_send_tls (struct MHD_Connection *restrict c, #endif /* MHD_SUPPORT_HTTPS */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5) enum mhd_SocketError mhd_send_data (struct MHD_Connection *restrict connection, size_t buf_size, @@ -960,7 +960,7 @@ mhd_send_data (struct MHD_Connection *restrict connection, MHD_INTERNAL MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) -MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (6,5) enum mhd_SocketError +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (6, 5) enum mhd_SocketError mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, size_t header_size, const char *restrict header, @@ -976,40 +976,40 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, bool push_body; MHD_Socket s = connection->sk.fd; #ifdef mhd_USE_VECT_SEND -#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) +# if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) struct iovec vector[2]; -#ifdef HAVE_SENDMSG +# ifdef HAVE_SENDMSG struct msghdr msg; -#endif /* HAVE_SENDMSG */ -#endif /* HAVE_SENDMSG || HAVE_WRITEV */ -#ifdef _WIN32 +# endif /* HAVE_SENDMSG */ +# endif /* HAVE_SENDMSG || HAVE_WRITEV */ +# ifdef _WIN32 WSABUF vector[2]; DWORD vec_sent; -#endif /* _WIN32 */ +# endif /* _WIN32 */ bool no_vec; /* Is vector-send() disallowed? */ no_vec = false; no_vec = no_vec || (mhd_C_HAS_TLS (connection)); -#if (! defined(HAVE_SENDMSG) || ! defined(HAVE_DCLR_MSG_NOSIGNAL) ) && \ +# if (!defined(HAVE_SENDMSG) || !defined(HAVE_DCLR_MSG_NOSIGNAL)) && \ defined(mhd_SEND_SPIPE_SUPPRESS_POSSIBLE) && \ defined(mhd_SEND_SPIPE_SUPPRESS_NEEDED) - no_vec = no_vec || (! connection->daemon->sigpipe_blocked && - ! connection->sk.props.has_spipe_supp); -#endif /* (!HAVE_SENDMSG || ! HAVE_DCLR_MSG_NOSIGNAL) && + no_vec = no_vec || (!connection->daemon->sigpipe_blocked + && !connection->sk.props.has_spipe_supp); +# endif /* (!HAVE_SENDMSG || ! HAVE_DCLR_MSG_NOSIGNAL) && mhd_SEND_SPIPE_SUPPRESS_POSSIBLE && mhd_SEND_SPIPE_SUPPRESS_NEEDED */ #endif /* mhd_USE_VECT_SEND */ - mhd_assert ( (NULL != body) || (0 == body_size) ); + mhd_assert ((NULL != body) || (0 == body_size)); mhd_assert (MHD_INVALID_SOCKET != s); mhd_assert (mhd_HTTP_STAGE_CLOSED != connection->stage); push_body = complete_response; - if (! never_push_hdr) + if (!never_push_hdr) { - if (! complete_response) + if (!complete_response) push_hdr = true; /* Push the header as the client may react * on header alone while the body data is * being prepared. */ @@ -1035,8 +1035,8 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, no_vec = (no_vec || true); #else /* mhd_USE_VECT_SEND */ no_vec = (no_vec || (0 == body_size)); - no_vec = (no_vec || ((sizeof(mhd_iov_elmn_size) <= sizeof(size_t)) && - (((size_t) mhd_IOV_ELMN_MAX_SIZE) < header_size))); + no_vec = (no_vec || ((sizeof(mhd_iov_elmn_size) <= sizeof(size_t)) + && (((size_t)mhd_IOV_ELMN_MAX_SIZE) < header_size))); #endif /* mhd_USE_VECT_SEND */ @@ -1049,11 +1049,11 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, push_hdr, sent); - if ((mhd_SOCKET_ERR_NO_ERROR == ret) && - (header_size == *sent) && - (0 != body_size) && - (header_size < header_size + body_size) && - (connection->sk.props.is_nonblck)) + if ((mhd_SOCKET_ERR_NO_ERROR == ret) + && (header_size == *sent) + && (0 != body_size) + && (header_size < header_size + body_size) + && (connection->sk.props.is_nonblck)) { size_t sent_b; /* The header has been sent completely. @@ -1077,7 +1077,7 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, } #ifdef mhd_USE_VECT_SEND - mhd_assert (! mhd_C_HAS_TLS (connection)); + mhd_assert (!mhd_C_HAS_TLS (connection)); if (header_size > (header_size + body_size)) { @@ -1086,9 +1086,9 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, complete_response = false; push_body = complete_response; } - if (((mhd_iov_ret_type) (header_size + body_size)) < 0 || - ((size_t) (mhd_iov_ret_type) (header_size + body_size)) != - (header_size + body_size)) + if ((((mhd_iov_ret_type)(header_size + body_size)) < 0) + || (((size_t)(mhd_iov_ret_type)(header_size + body_size)) != + (header_size + body_size))) { /* Send sys-call total amount limit */ body_size = mhd_IOV_RET_MAX_SIZE - header_size; @@ -1097,20 +1097,20 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, } pre_send_setopt (&(connection->sk), -#ifdef HAVE_SENDMSG +# ifdef HAVE_SENDMSG true, -#else /* ! HAVE_SENDMSG */ +# else /* ! HAVE_SENDMSG */ false, -#endif /* ! HAVE_SENDMSG */ +# endif /* ! HAVE_SENDMSG */ push_hdr || push_body); send_error = false; -#if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) +# if defined(HAVE_SENDMSG) || defined(HAVE_WRITEV) vector[0].iov_base = mhd_DROP_CONST (header); vector[0].iov_len = header_size; vector[1].iov_base = mhd_DROP_CONST (body); vector[1].iov_len = body_size; -#if defined(HAVE_SENDMSG) +# if defined(HAVE_SENDMSG) memset (&msg, 0, sizeof(msg)); msg.msg_name = NULL; msg.msg_namelen = 0; @@ -1121,37 +1121,37 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, msg.msg_flags = 0; res = sendmsg (s, &msg, mhd_MSG_NOSIGNAL -# ifdef mhd_USE_MSG_MORE +# ifdef mhd_USE_MSG_MORE | ((push_hdr || push_body) ? 0 : mhd_MSG_MORE) -# endif +# endif ); -#elif defined(HAVE_WRITEV) +# elif defined(HAVE_WRITEV) res = writev (s, vector, 2); -#endif /* HAVE_WRITEV */ +# endif /* HAVE_WRITEV */ if (0 < res) - *sent = (size_t) res; + *sent = (size_t)res; else send_error = true; -#endif /* HAVE_SENDMSG || HAVE_WRITEV */ -#ifdef _WIN32 - if (((mhd_iov_elmn_size) body_size) != body_size) +# endif /* HAVE_SENDMSG || HAVE_WRITEV */ +# ifdef _WIN32 + if (((mhd_iov_elmn_size)body_size) != body_size) { /* Send item size limit */ body_size = mhd_IOV_ELMN_MAX_SIZE; complete_response = false; push_body = complete_response; } - vector[0].buf = (char *) mhd_DROP_CONST (header); - vector[0].len = (unsigned long) header_size; - vector[1].buf = (char *) mhd_DROP_CONST (body); - vector[1].len = (unsigned long) body_size; + vector[0].buf = (char *)mhd_DROP_CONST (header); + vector[0].len = (unsigned long)header_size; + vector[1].buf = (char *)mhd_DROP_CONST (body); + vector[1].len = (unsigned long)body_size; res = WSASend (s, vector, 2, &vec_sent, 0, NULL, NULL); if (0 == res) - *sent = (size_t) vec_sent; + *sent = (size_t)vec_sent; else send_error = true; -#endif /* _WIN32 */ +# endif /* _WIN32 */ if (send_error) { @@ -1161,23 +1161,23 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, if (mhd_SOCKET_ERR_AGAIN == err) connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) connection->sk.ready) + (((unsigned int)connection->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); return err; } if (((header_size + body_size) > *sent) - || ! connection->sk.props.is_nonblck) + || !connection->sk.props.is_nonblck) connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) connection->sk.ready) + (((unsigned int)connection->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); /* If there is a need to push the data from network buffers * call post_send_setopt(). */ - if ( (push_body) && - ((header_size + body_size) == *sent) ) + if ((push_body) + && ((header_size + body_size) == *sent)) { /* Complete reply has been sent. */ /* If TLS connection is used then next final send() will be @@ -1186,15 +1186,15 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, * sendfile() will be used so assume that next final send() will be * the same, like for this response. */ post_send_setopt (&(connection->sk), -#ifdef HAVE_SENDMSG +# ifdef HAVE_SENDMSG true, /* Assume the same type of the send function */ -#else /* ! HAVE_SENDMSG */ +# else /* ! HAVE_SENDMSG */ false, /* Assume the same type of the send function */ -#endif /* ! HAVE_SENDMSG */ +# endif /* ! HAVE_SENDMSG */ true); } - else if ( (push_hdr) && - (header_size <= *sent)) + else if ((push_hdr) + && (header_size <= *sent)) { /* The header has been sent completely and there is a * need to push the header data. */ @@ -1214,11 +1214,11 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, #if defined(mhd_USE_SENDFILE) -#if defined(HAVE_LINUX_SENDFILE) && defined(HAVE_SENDFILE64) -# define mhd_off_t off64_t -#else -# define mhd_off_t off_t -#endif +# if defined(HAVE_LINUX_SENDFILE) && defined(HAVE_SENDFILE64) +# define mhd_off_t off64_t +# else +# define mhd_off_t off_t +# endif MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (2) enum mhd_SocketError @@ -1239,8 +1239,8 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, bool fallback_to_filereader; mhd_assert (mhd_REPLY_CNTN_LOC_FILE == c->rp.cntn_loc); mhd_assert (MHD_SIZE_UNKNOWN != c->rp.response->cntn_size); - mhd_assert (chunk_size <= (size_t) SSIZE_MAX); - mhd_assert (! mhd_C_HAS_TLS (c)); + mhd_assert (chunk_size <= (size_t)SSIZE_MAX); + mhd_assert (!mhd_C_HAS_TLS (c)); mhd_assert (0 == send_size); /* Mute analyser warning */ push_data = true; @@ -1251,10 +1251,11 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, offset = (mhd_off_t) (c->rp.rsp_cntn_read_pos + c->rp.response->cntn.file.offset); - too_large = (((uint_fast64_t) offset) < c->rp.rsp_cntn_read_pos); - too_large = too_large || - (((uint_fast64_t) offset) != - (c->rp.rsp_cntn_read_pos + c->rp.response->cntn.file.offset)); + too_large = (((uint_fast64_t)offset) < c->rp.rsp_cntn_read_pos); + too_large = too_large + || (((uint_fast64_t)offset) != + (c->rp.rsp_cntn_read_pos + + c->rp.response->cntn.file.offset)); too_large = too_large || (0 > offset); if (too_large) { /* Retry to send with file reader and standard 'send()'. */ @@ -1272,7 +1273,7 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, push_data = false; /* No need to push data, there is more to send. */ } else - send_size = (size_t) left; + send_size = (size_t)left; } mhd_assert (0 != send_size); @@ -1281,51 +1282,51 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, sent_bytes = 0; ret = mhd_SOCKET_ERR_NO_ERROR; fallback_to_filereader = false; -#if defined(HAVE_LINUX_SENDFILE) +# if defined(HAVE_LINUX_SENDFILE) if (1) { ssize_t res; -#ifndef HAVE_SENDFILE64 +# ifndef HAVE_SENDFILE64 ret = sendfile (c->sk.fd, file_fd, &offset, send_size); -#else /* HAVE_SENDFILE64 */ +# else /* HAVE_SENDFILE64 */ res = sendfile64 (c->sk.fd, file_fd, &offset, send_size); -#endif /* HAVE_SENDFILE64 */ +# endif /* HAVE_SENDFILE64 */ if (0 > res) { const int sk_err = mhd_SCKT_GET_LERR (); - if ((EINVAL == sk_err) || - (EOVERFLOW == sk_err) || -#ifdef EIO + if ((EINVAL == sk_err) + || (EOVERFLOW == sk_err) || +# ifdef EIO (EIO == sk_err) || -#endif -#ifdef EAFNOSUPPORT +# endif +# ifdef EAFNOSUPPORT (EAFNOSUPPORT == sk_err) || -#endif +# endif (EOPNOTSUPP == sk_err)) fallback_to_filereader = true; else ret = mhd_socket_error_get_from_sys_err (sk_err); } else - sent_bytes = (size_t) res; + sent_bytes = (size_t)res; } -#elif defined(HAVE_FREEBSD_SENDFILE) +# elif defined(HAVE_FREEBSD_SENDFILE) if (1) { off_t sent_bytes_offt = 0; int flags = 0; bool sent_something = false; -#ifdef SF_FLAGS +# ifdef SF_FLAGS flags = used_thr_p_c ? freebsd_sendfile_flags_thd_p_c_ : freebsd_sendfile_flags_; -#endif /* SF_FLAGS */ +# endif /* SF_FLAGS */ if (0 != sendfile (file_fd, c->sk.fd, offset, @@ -1337,15 +1338,15 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, const int sk_err = mhd_SCKT_GET_LERR (); sent_something = - (((EAGAIN == sk_err) || (EBUSY == sk_err) || (EINTR == sk_err)) && - (0 != sent_bytes_offt)); + (((EAGAIN == sk_err) || (EBUSY == sk_err) || (EINTR == sk_err)) + && (0 != sent_bytes_offt)); - if (! sent_something) + if (!sent_something) { enum mhd_SocketError err; - if ((EINVAL == sk_err) || - (EIO == sk_err) || - (EOPNOTSUPP == sk_err)) + if ((EINVAL == sk_err) + || (EIO == sk_err) + || (EOPNOTSUPP == sk_err)) fallback_to_filereader = true; else ret = mhd_socket_error_get_from_sys_err (sk_err); @@ -1358,17 +1359,17 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, { mhd_assert (0 <= sent_bytes_offt); mhd_assert (SIZE_MAX >= sent_bytes_offt); - sent_bytes = (size_t) sent_bytes_offt; + sent_bytes = (size_t)sent_bytes_offt; } } -#elif defined(HAVE_DARWIN_SENDFILE) +# elif defined(HAVE_DARWIN_SENDFILE) if (1) { off_t len; bool sent_something; sent_something = false; - len = (off_t) send_size; /* chunk always fit */ + len = (off_t)send_size; /* chunk always fit */ if (0 != sendfile (file_fd, c->sk.fd, @@ -1380,13 +1381,13 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, const int sk_err = mhd_SCKT_GET_LERR (); sent_something = - ((EAGAIN == sk_err) || (EINTR == sk_err)) && - (0 != len); + ((EAGAIN == sk_err) || (EINTR == sk_err)) + && (0 != len); - if (! sent_something) + if (!sent_something) { - if ((ENOTSUP == sk_err) || - (EOPNOTSUPP == sk_err)) + if ((ENOTSUP == sk_err) + || (EOPNOTSUPP == sk_err)) fallback_to_filereader = true; else ret = mhd_socket_error_get_from_sys_err (sk_err); @@ -1399,28 +1400,28 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, { mhd_assert (0 <= len); mhd_assert (SIZE_MAX >= len); - sent_bytes = (size_t) len; + sent_bytes = (size_t)len; } } -#else -#error No sendfile() function -#endif +# else +# error No sendfile() function +# endif mhd_assert (send_size >= sent_bytes); /* Some platforms indicate "beyond of the end of the file" by returning * success with zero bytes. Let filereader to re-detect this kind of error. */ - if ((fallback_to_filereader) || - ((mhd_SOCKET_ERR_NO_ERROR == ret) && (0 == sent_bytes))) + if ((fallback_to_filereader) + || ((mhd_SOCKET_ERR_NO_ERROR == ret) && (0 == sent_bytes))) { /* Retry to send with file reader and standard 'send()'. */ c->rp.response->cntn.file.use_sf = false; return mhd_SOCKET_ERR_INTR; } - if ((mhd_SOCKET_ERR_AGAIN == ret) || ! c->sk.props.is_nonblck || - ((mhd_SOCKET_ERR_NO_ERROR == ret) && (send_size > sent_bytes))) + if ((mhd_SOCKET_ERR_AGAIN == ret) || !c->sk.props.is_nonblck + || ((mhd_SOCKET_ERR_NO_ERROR == ret) && (send_size > sent_bytes))) c->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) c->sk.ready) + (((unsigned int)c->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); @@ -1431,8 +1432,8 @@ mhd_send_sendfile (struct MHD_Connection *restrict c, * call post_send_setopt(). */ /* It's unknown whether sendfile() will be used in the next * response so assume that next response will be the same. */ - if ((push_data) && - (send_size == sent_bytes)) + if ((push_data) + && (send_size == sent_bytes)) post_send_setopt (&(c->sk), true, push_data); *sent = sent_bytes; @@ -1469,25 +1470,25 @@ send_iov_nontls (struct MHD_Connection *restrict connection, { bool send_error; size_t items_to_send; -#ifndef MHD_SOCKETS_KIND_WINSOCK +# ifndef MHD_SOCKETS_KIND_WINSOCK ssize_t res; -#endif -#ifdef HAVE_SENDMSG +# endif +# ifdef HAVE_SENDMSG struct msghdr msg; -#elif defined(MHD_SOCKETS_KIND_WINSOCK) +# elif defined(MHD_SOCKETS_KIND_WINSOCK) DWORD bytes_sent; DWORD cnt_w; -#endif /* MHD_SOCKETS_KIND_WINSOCK */ +# endif /* MHD_SOCKETS_KIND_WINSOCK */ - mhd_assert (! mhd_C_HAS_TLS (connection)); - mhd_assert (! mhd_D_HAS_TLS (connection->daemon)); + mhd_assert (!mhd_C_HAS_TLS (connection)); + mhd_assert (!mhd_D_HAS_TLS (connection->daemon)); mhd_assert (MHD_INVALID_SOCKET != connection->sk.fd); mhd_assert (mhd_HTTP_STAGE_CLOSED != connection->stage); send_error = false; items_to_send = r_iov->cnt - r_iov->sent; -#ifdef mhd_IOV_MAX +# ifdef mhd_IOV_MAX if (mhd_IOV_MAX < items_to_send) { mhd_assert (0 < mhd_IOV_MAX); @@ -1496,8 +1497,8 @@ send_iov_nontls (struct MHD_Connection *restrict connection, items_to_send = mhd_IOV_MAX; push_data = false; /* Incomplete response */ } -#endif /* mhd_IOV_MAX */ -#ifdef HAVE_SENDMSG +# endif /* mhd_IOV_MAX */ +# ifdef HAVE_SENDMSG memset (&msg, 0, sizeof(struct msghdr)); msg.msg_name = NULL; msg.msg_namelen = 0; @@ -1510,45 +1511,45 @@ send_iov_nontls (struct MHD_Connection *restrict connection, pre_send_setopt (&(connection->sk), true, push_data); res = sendmsg (connection->sk.fd, &msg, mhd_MSG_NOSIGNAL -# ifdef mhd_USE_MSG_MORE +# ifdef mhd_USE_MSG_MORE | (push_data ? 0 : MSG_MORE) -# endif +# endif ); if (0 < res) - *sent = (size_t) res; + *sent = (size_t)res; else send_error = true; -#elif defined(HAVE_WRITEV) +# elif defined(HAVE_WRITEV) pre_send_setopt (&(connection->sk), false, push_data); res = writev (connection->sk.fd, r_iov->iov + r_iov->sent, items_to_send); if (0 < res) - *sent = (size_t) res; + *sent = (size_t)res; else send_error = true; -#elif defined(MHD_SOCKETS_KIND_WINSOCK) -#ifdef _WIN64 +# elif defined(MHD_SOCKETS_KIND_WINSOCK) +# ifdef _WIN64 if (items_to_send > ULONG_MAX) { cnt_w = ULONG_MAX; push_data = false; /* Incomplete response */ } else - cnt_w = (DWORD) items_to_send; -#else /* ! _WIN64 */ - cnt_w = (DWORD) items_to_send; -#endif /* ! _WIN64 */ + cnt_w = (DWORD)items_to_send; +# else /* ! _WIN64 */ + cnt_w = (DWORD)items_to_send; +# endif /* ! _WIN64 */ pre_send_setopt (&(connection->sk), true, push_data); if (0 == WSASend (connection->sk.fd, - (LPWSABUF) (r_iov->iov + r_iov->sent), + (LPWSABUF)(r_iov->iov + r_iov->sent), cnt_w, &bytes_sent, 0, NULL, NULL)) - *sent = (size_t) bytes_sent; + *sent = (size_t)bytes_sent; else send_error = true; -#else /* !HAVE_SENDMSG && !HAVE_WRITEV && !MHD_SOCKETS_KIND_WINSOCK */ -#error No vector-send function available -#endif +# else /* !HAVE_SENDMSG && !HAVE_WRITEV && !MHD_SOCKETS_KIND_WINSOCK */ +# error No vector-send function available +# endif if (send_error) { @@ -1558,7 +1559,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection, if (mhd_SOCKET_ERR_AGAIN == err) connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) connection->sk.ready) + (((unsigned int)connection->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); @@ -1568,11 +1569,11 @@ send_iov_nontls (struct MHD_Connection *restrict connection, /* Some data has been sent */ if (1) { - size_t track_sent = (size_t) *sent; + size_t track_sent = (size_t)*sent; - if (! connection->sk.props.is_nonblck) + if (!connection->sk.props.is_nonblck) connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) connection->sk.ready) + (((unsigned int)connection->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); @@ -1590,7 +1591,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection, else { connection->sk.ready = (enum mhd_SocketNetState) /* Clear 'send-ready' */ - (((unsigned int) connection->sk.ready) + (((unsigned int)connection->sk.ready) & (~(enum mhd_SocketNetState) mhd_SOCKET_NET_STATE_SEND_READY)); if (0 != track_sent) @@ -1599,9 +1600,9 @@ send_iov_nontls (struct MHD_Connection *restrict connection, /* The last iov element has been partially sent */ r_iov->iov[r_iov->sent].iov_base = (mhd_IOV_ELMN_PTR_TYPE) - (((uint8_t *) r_iov->iov[r_iov->sent].iov_base) + (((uint8_t *)r_iov->iov[r_iov->sent].iov_base) + track_sent); - r_iov->iov[r_iov->sent].iov_len -= (mhd_iov_elmn_size) track_sent; + r_iov->iov[r_iov->sent].iov_len -= (mhd_iov_elmn_size)track_sent; } } } @@ -1612,7 +1613,7 @@ send_iov_nontls (struct MHD_Connection *restrict connection, #endif /* mhd_USE_VECT_SEND */ -#if ! defined(mhd_USE_VECT_SEND) || defined(MHD_SUPPORT_HTTPS) || \ +#if !defined(mhd_USE_VECT_SEND) || defined(MHD_SUPPORT_HTTPS) || \ defined(mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED) @@ -1651,12 +1652,12 @@ send_iov_emu (struct MHD_Connection *restrict connection, enum mhd_SocketError res; size_t sent_el_size; - if (total_sent > (size_t) (r_iov->iov[r_iov->sent].iov_len + total_sent)) + if (total_sent > (size_t)(r_iov->iov[r_iov->sent].iov_len + total_sent)) break; /* return value would overflow */ res = mhd_send_data (connection, r_iov->iov[r_iov->sent].iov_len, - (const char *) r_iov->iov[r_iov->sent].iov_base, + (const char *)r_iov->iov[r_iov->sent].iov_base, push_data && (r_iov->cnt == r_iov->sent + 1), &sent_el_size); if (mhd_SOCKET_ERR_NO_ERROR == res) @@ -1679,15 +1680,15 @@ send_iov_emu (struct MHD_Connection *restrict connection, * Adjust buffer of the last element. */ r_iov->iov[r_iov->sent].iov_base = (mhd_IOV_ELMN_PTR_TYPE) - (((uint8_t *) r_iov->iov[r_iov->sent].iov_base) + sent_el_size); - r_iov->iov[r_iov->sent].iov_len -= (mhd_iov_elmn_size) sent_el_size; + (((uint8_t *)r_iov->iov[r_iov->sent].iov_base) + sent_el_size); + r_iov->iov[r_iov->sent].iov_len -= (mhd_iov_elmn_size)sent_el_size; break; /* Return the amount of the sent data */ } /* The iov element has been completely sent */ r_iov->sent++; - } while ((r_iov->cnt > r_iov->sent) && 0 != (--max_elelements_to_sent) && - (non_blk)); + } while ((r_iov->cnt > r_iov->sent) && 0 != (--max_elelements_to_sent) + && (non_blk)); mhd_assert (0 != total_sent); *sent = total_sent; @@ -1706,10 +1707,10 @@ mhd_send_iovec (struct MHD_Connection *restrict connection, size_t *restrict sent) { #ifdef mhd_USE_VECT_SEND -#if defined(MHD_SUPPORT_HTTPS) || \ +# if defined(MHD_SUPPORT_HTTPS) || \ defined(mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED) bool use_iov_send = true; -#endif /* MHD_SUPPORT_HTTPS || mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */ +# endif /* MHD_SUPPORT_HTTPS || mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */ #endif /* mhd_USE_VECT_SEND */ mhd_assert (NULL != connection->rp.resp_iov.iov); @@ -1717,20 +1718,20 @@ mhd_send_iovec (struct MHD_Connection *restrict connection, connection->rp.response->cntn_dtype); mhd_assert (connection->rp.resp_iov.cnt > connection->rp.resp_iov.sent); #ifdef mhd_USE_VECT_SEND -#if defined(MHD_SUPPORT_HTTPS) || \ +# if defined(MHD_SUPPORT_HTTPS) || \ defined(mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED) - use_iov_send = use_iov_send && - (! mhd_C_HAS_TLS (connection)); -#ifdef mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED - use_iov_send = use_iov_send && (connection->daemon->sigpipe_blocked || - connection->sk.props.has_spipe_supp); -#endif /* mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */ + use_iov_send = use_iov_send + && (!mhd_C_HAS_TLS (connection)); +# ifdef mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED + use_iov_send = use_iov_send && (connection->daemon->sigpipe_blocked + || connection->sk.props.has_spipe_supp); +# endif /* mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */ if (use_iov_send) -#endif /* MHD_SUPPORT_HTTPS || mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */ +# endif /* MHD_SUPPORT_HTTPS || mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED */ return send_iov_nontls (connection, r_iov, push_data, sent); #endif /* mhd_USE_VECT_SEND */ -#if ! defined(mhd_USE_VECT_SEND) || defined(MHD_SUPPORT_HTTPS) || \ +#if !defined(mhd_USE_VECT_SEND) || defined(MHD_SUPPORT_HTTPS) || \ defined(mhd_VECT_SEND_NEEDS_SPIPE_SUPPRESSED) return send_iov_emu (connection, r_iov, push_data, sent); #endif /* !mhd_USE_VECT_SEND || MHD_SUPPORT_HTTPS diff --git a/src/mhd2/mhd_send.h b/src/mhd2/mhd_send.h @@ -85,7 +85,7 @@ mhd_send_data (struct MHD_Connection *restrict connection, const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], bool push_data, size_t *restrict sent) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5); /** @@ -117,8 +117,8 @@ mhd_send_hdr_and_body (struct MHD_Connection *restrict connection, const char *restrict body, bool complete_response, size_t *restrict sent) -MHD_FN_PAR_NONNULL_(1) MHD_FN_PAR_NONNULL_(3) -MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (6,5) MHD_FN_PAR_OUT_ (8); +MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (6, 5) MHD_FN_PAR_OUT_ (8); #if defined(mhd_USE_SENDFILE) /** diff --git a/src/mhd2/mhd_sha256.h b/src/mhd2/mhd_sha256.h @@ -49,7 +49,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_SHA256 -#error This file must be used only when SHA-256 is enabled +# error This file must be used only when SHA-256 is enabled #endif #ifndef MHD_SHA256_EXTR # include "sha256_int.h" @@ -92,20 +92,20 @@ /** * Finalise SHA-512/256 calculation, return digest, reset hash calculation. */ -# define mhd_SHA256_finish_reset(ctx,digest) \ - (mhd_SHA256_finish (ctx,digest), mhd_SHA256_reset (ctx)) +# define mhd_SHA256_finish_reset(ctx, digest) \ + (mhd_SHA256_finish (ctx,digest), mhd_SHA256_reset (ctx)) /** * Finalise hash calculation, return digest, de-initialise hash calculation. */ -# define mhd_SHA256_finish_deinit(ctx,digest) \ - (mhd_SHA256_finish (ctx,digest), mhd_SHA256_deinit (ctx)) +# define mhd_SHA256_finish_deinit(ctx, digest) \ + (mhd_SHA256_finish (ctx,digest), mhd_SHA256_deinit (ctx)) #else /* mhd_SHA256_HAS_FINISH_RESET */ # define mhd_SHA256_reset(ctx) ((void) 0) /** * Finalise hash calculation, return digest, de-initialise hash calculation. */ -# define mhd_SHA256_finish_deinit(ctx,digest) \ - (mhd_SHA256_finish_reset (ctx,digest), mhd_SHA256_deinit (ctx)) +# define mhd_SHA256_finish_deinit(ctx, digest) \ + (mhd_SHA256_finish_reset (ctx,digest), mhd_SHA256_deinit (ctx)) #endif /* mhd_SHA256_HAS_FINISH_RESET */ #ifndef mhd_SHA256_HAS_DEINIT @@ -113,15 +113,15 @@ #endif /* HAVE_SHA256_DEINIT */ #ifdef mhd_SHA256_HAS_EXT_ERROR -#define mhd_SHA256_has_err(ctx) (0 != ((ctx)->ext_error)) +# define mhd_SHA256_has_err(ctx) (0 != ((ctx)->ext_error)) #else /* ! mhd_SHA256_HAS_EXT_ERROR */ -#define mhd_SHA256_has_err(ctx) (((void) (ctx)), ! ! 0) +# define mhd_SHA256_has_err(ctx) (((void) (ctx)), ! ! 0) #endif /* ! mhd_SHA512_256_HAS_EXT_ERROR */ /* Sanity checks */ -#if ! defined(mhd_SHA256_HAS_FINISH_RESET) && ! defined(mhd_SHA256_HAS_FINISH) -#error Required mhd_SHA256_finish_reset() or mhd_SHA256_finish() +#if !defined(mhd_SHA256_HAS_FINISH_RESET) && !defined(mhd_SHA256_HAS_FINISH) +# error Required mhd_SHA256_finish_reset() or mhd_SHA256_finish() #endif /* ! mhd_SHA256_HAS_FINISH_RESET && ! mhd_SHA256_HAS_FINISH */ #endif /* MHD_SHA256_H */ diff --git a/src/mhd2/mhd_sha512_256.h b/src/mhd2/mhd_sha512_256.h @@ -49,7 +49,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_SHA512_256 -#error This file must be used only when SHA-512/256 is enabled +# error This file must be used only when SHA-512/256 is enabled #endif #ifndef MHD_SHA512_256_EXTR # include "sha512_256_int.h" @@ -96,33 +96,33 @@ /** * Finalise hash calculation, return digest, reset hash calculation. */ -# define mhd_SHA512_256_finish_reset(ctx,digest) \ - (mhd_SHA512_256_finish (ctx,digest), mhd_SHA512_256_reset (ctx)) +# define mhd_SHA512_256_finish_reset(ctx, digest) \ + (mhd_SHA512_256_finish (ctx,digest), mhd_SHA512_256_reset (ctx)) /** * Finalise hash calculation, return digest, de-initialise hash calculation. */ -# define mhd_SHA512_256_finish_deinit(ctx,digest) \ - (mhd_SHA512_256_finish (ctx,digest), mhd_SHA512_256_deinit (ctx)) +# define mhd_SHA512_256_finish_deinit(ctx, digest) \ + (mhd_SHA512_256_finish (ctx,digest), mhd_SHA512_256_deinit (ctx)) #else /* mhd_SHA512_256_HAS_FINISH_RESET */ # define mhd_SHA512_256_reset(ctx) ((void) 0) /** * Finalise hash calculation, return digest, de-initialise hash calculation. */ -# define mhd_SHA512_256_finish_deinit(ctx,digest) \ - (mhd_SHA512_256_finish_reset (ctx,digest), mhd_SHA512_256_deinit (ctx)) +# define mhd_SHA512_256_finish_deinit(ctx, digest) \ + (mhd_SHA512_256_finish_reset (ctx,digest), mhd_SHA512_256_deinit (ctx)) #endif /* mhd_SHA512_256_HAS_FINISH_RESET */ /* Sanity checks */ -#if ! defined(mhd_SHA512_256_HAS_FINISH_RESET) && \ - ! defined(mhd_SHA512_256_HAS_FINISH) -#error Required mhd_SHA512_256_finish_reset() or mhd_SHA512_256_finish() +#if !defined(mhd_SHA512_256_HAS_FINISH_RESET) && \ + !defined(mhd_SHA512_256_HAS_FINISH) +# error Required mhd_SHA512_256_finish_reset() or mhd_SHA512_256_finish() #endif /* ! mhd_SHA512_256_HAS_FINISH_RESET && ! mhd_SHA512_256_HAS_FINISH */ #ifdef mhd_SHA512_256_HAS_EXT_ERROR -#define mhd_SHA512_256_has_err(ctx) (0 != ((ctx)->ext_error)) +# define mhd_SHA512_256_has_err(ctx) (0 != ((ctx)->ext_error)) #else /* ! mhd_SHA512_256_HAS_EXT_ERROR */ -#define mhd_SHA512_256_has_err(ctx) (((void) (ctx)), ! ! 0) +# define mhd_SHA512_256_has_err(ctx) (((void) (ctx)), ! ! 0) #endif /* ! mhd_SHA512_256_HAS_EXT_ERROR */ #endif /* MHD_SHA512_256_H */ diff --git a/src/mhd2/mhd_socket_error_funcs.c b/src/mhd2/mhd_socket_error_funcs.c @@ -90,14 +90,14 @@ mhd_socket_error_get_from_socket (MHD_Socket fd) if ((0 == mhd_getsockopt (fd, SOL_SOCKET, SO_ERROR, - (void *) &sock_err, + (void *)&sock_err, &optlen)) && (sizeof(sock_err) == optlen)) return mhd_socket_error_get_from_sys_err (sock_err); err = mhd_socket_error_get_from_sys_err (mhd_SCKT_GET_LERR ()); - if ((mhd_SOCKET_ERR_NOTSOCK == err) || - (mhd_SOCKET_ERR_BADF == err)) + if ((mhd_SOCKET_ERR_NOTSOCK == err) + || (mhd_SOCKET_ERR_BADF == err)) return err; #endif /* SOL_SOCKET && SO_ERROR */ return mhd_SOCKET_ERR_NOT_CHECKED; diff --git a/src/mhd2/mhd_socket_type.h b/src/mhd2/mhd_socket_type.h @@ -50,7 +50,7 @@ #include "mhd_sys_options.h" #ifndef MHD_INVALID_SOCKET -# if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET) +# if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) # define MHD_SOCKETS_KIND_POSIX 1 /* The POSIX-style sockets are used */ /** * MHD_Socket is type for socket FDs diff --git a/src/mhd2/mhd_sockets_funcs.c b/src/mhd2/mhd_sockets_funcs.c @@ -71,7 +71,7 @@ mhd_socket_nonblocking (MHD_Socket sckt) { #if defined(MHD_SOCKETS_KIND_POSIX) // TODO: detect constants in configure -#if defined(F_GETFL) && defined(O_NONBLOCK) && defined(F_SETFL) +# if defined(F_GETFL) && defined(O_NONBLOCK) && defined(F_SETFL) int get_flags; int set_flags; @@ -85,11 +85,11 @@ mhd_socket_nonblocking (MHD_Socket sckt) if (-1 != fcntl (sckt, F_SETFL, set_flags)) return true; -#endif /* F_GETFL && O_NONBLOCK && F_SETFL */ +# endif /* F_GETFL && O_NONBLOCK && F_SETFL */ #elif defined(MHD_SOCKETS_KIND_WINSOCK) unsigned long set_flag = 1; - if (0 == ioctlsocket (sckt, (long) FIONBIO, &set_flag)) + if (0 == ioctlsocket (sckt, (long)FIONBIO, &set_flag)) return true; #endif /* MHD_SOCKETS_KIND_WINSOCK */ @@ -102,7 +102,7 @@ mhd_socket_noninheritable (MHD_Socket sckt) { #if defined(MHD_SOCKETS_KIND_POSIX) // TODO: detect constants in configure -#if defined(F_GETFD) && defined(FD_CLOEXEC) && defined(F_SETFD) +# if defined(F_GETFD) && defined(FD_CLOEXEC) && defined(F_SETFD) int get_flags; int set_flags; @@ -116,9 +116,9 @@ mhd_socket_noninheritable (MHD_Socket sckt) if (-1 != fcntl (sckt, F_SETFD, set_flags)) return true; -#endif /* F_GETFD && FD_CLOEXEC && F_SETFD */ +# endif /* F_GETFD && FD_CLOEXEC && F_SETFD */ #elif defined(MHD_SOCKETS_KIND_WINSOCK) - if (SetHandleInformation ((HANDLE) sckt, HANDLE_FLAG_INHERIT, 0)) + if (SetHandleInformation ((HANDLE)sckt, HANDLE_FLAG_INHERIT, 0)) return true; #endif /* MHD_SOCKETS_KIND_WINSOCK */ return false; @@ -135,9 +135,10 @@ mhd_socket_set_nodelay (MHD_Socket sckt, value = on ? 1 : 0; return 0 == mhd_setsockopt (sckt, IPPROTO_TCP, TCP_NODELAY, - (const void *) &value, sizeof (value)); + (const void *)&value, sizeof (value)); #else /* ! TCP_NODELAY */ - (void) sckt; (void) on; + (void)sckt; + (void)on; return false; #endif /* ! TCP_NODELAY */ } @@ -153,9 +154,9 @@ mhd_socket_set_hard_close (MHD_Socket sckt) par.l_linger = 0; return 0 == mhd_setsockopt (sckt, SOL_SOCKET, SO_LINGER, - (const void *) &par, sizeof (par)); + (const void *)&par, sizeof (par)); #else /* ! SOL_SOCKET || ! SO_LINGER */ - (void) sckt; + (void)sckt; return false; #endif /* ! SOL_SOCKET || ! SO_LINGER */ } @@ -179,9 +180,9 @@ mhd_socket_shut_wr (MHD_Socket sckt) static bool mhd_socket_blocking (MHD_Socket sckt) { -#if defined(MHD_SOCKETS_KIND_POSIX) +# if defined(MHD_SOCKETS_KIND_POSIX) // TODO: detect constants in configure -#if defined(F_GETFL) && defined(O_NONBLOCK) && defined(F_SETFL) +# if defined(F_GETFL) && defined(O_NONBLOCK) && defined(F_SETFL) int get_flags; int set_flags; @@ -195,13 +196,13 @@ mhd_socket_blocking (MHD_Socket sckt) if (-1 != fcntl (sckt, F_SETFL, set_flags)) return true; -#endif /* F_GETFL && O_NONBLOCK && F_SETFL */ -#elif defined(MHD_SOCKETS_KIND_WINSOCK) +# endif /* F_GETFL && O_NONBLOCK && F_SETFL */ +# elif defined(MHD_SOCKETS_KIND_WINSOCK) unsigned long set_flag = 0; - if (0 == ioctlsocket (sckt, (long) FIONBIO, &set_flag)) + if (0 == ioctlsocket (sckt, (long)FIONBIO, &set_flag)) return true; -#endif /* MHD_SOCKETS_KIND_WINSOCK */ +# endif /* MHD_SOCKETS_KIND_WINSOCK */ return false; } @@ -212,7 +213,7 @@ mhd_socket_pair_func (MHD_Socket sckt[2], bool non_blk) { int i; -#define PAIR_MAX_TRIES 511 +# define PAIR_MAX_TRIES 511 for (i = 0; i < PAIR_MAX_TRIES; i++) { struct sockaddr_in listen_addr; @@ -228,23 +229,23 @@ mhd_socket_pair_func (MHD_Socket sckt[2], bool non_blk) listen_addr.sin_family = AF_INET; listen_addr.sin_port = 0; /* same as htons(0) */ -#ifdef INADDR_LOOPBACK +# ifdef INADDR_LOOPBACK listen_addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); -#else +# else memcpy (&(listen_addr.sin_addr.s_addr), "\x7F\x00\x00\x01", 4); -#endif -#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN +# endif +# ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN listen_addr.sin_len = sizeof(listen_addr); -#endif +# endif - if ( ((0 == bind (listen_s, - (struct sockaddr *) &listen_addr, - c_addinlen)) && - (0 == listen (listen_s, - 1) ) && - (0 == getsockname (listen_s, - (struct sockaddr *) &listen_addr, - &addr_len))) ) + if (((0 == bind (listen_s, + (struct sockaddr *)&listen_addr, + c_addinlen)) + && (0 == listen (listen_s, + 1)) + && (0 == getsockname (listen_s, + (struct sockaddr *)&listen_addr, + &addr_len)))) { MHD_Socket client_s = socket (AF_INET, SOCK_STREAM, 0); struct sockaddr_in accepted_from_addr; @@ -252,30 +253,30 @@ mhd_socket_pair_func (MHD_Socket sckt[2], bool non_blk) if (MHD_INVALID_SOCKET != client_s) { - if (mhd_socket_nonblocking (client_s) && - ( (0 == connect (client_s, - (struct sockaddr *) &listen_addr, - c_addinlen)) || - mhd_SCKT_LERR_IS_EAGAIN () )) + if (mhd_socket_nonblocking (client_s) + && ((0 == connect (client_s, + (struct sockaddr *)&listen_addr, + c_addinlen)) + || mhd_SCKT_LERR_IS_EAGAIN ())) { MHD_Socket server_s; addr_len = c_addinlen; server_s = accept (listen_s, - (struct sockaddr *) &accepted_from_addr, + (struct sockaddr *)&accepted_from_addr, &addr_len); if (MHD_INVALID_SOCKET != server_s) { addr_len = c_addinlen; - if ( (0 == getsockname (client_s, - (struct sockaddr *) &client_addr, - &addr_len)) && - (accepted_from_addr.sin_port == client_addr.sin_port) && - (accepted_from_addr.sin_addr.s_addr == - client_addr.sin_addr.s_addr) ) + if ((0 == getsockname (client_s, + (struct sockaddr *)&client_addr, + &addr_len)) + && (accepted_from_addr.sin_port == client_addr.sin_port) + && (accepted_from_addr.sin_addr.s_addr == + client_addr.sin_addr.s_addr)) { - (void) mhd_socket_set_nodelay (server_s, true); - (void) mhd_socket_set_nodelay (client_s, true); + (void)mhd_socket_set_nodelay (server_s, true); + (void)mhd_socket_set_nodelay (client_s, true); if (non_blk ? mhd_socket_nonblocking (server_s) : mhd_socket_blocking (client_s)) diff --git a/src/mhd2/mhd_sockets_macros.h b/src/mhd2/mhd_sockets_macros.h @@ -82,13 +82,13 @@ * @return ssize_t type value */ #ifdef MHD_SOCKETS_KIND_POSIX -# define mhd_sys_send4(s,b,l,f) \ - ((ssize_t) send ((s),(const void*) (b),(mhd_SCKT_SEND_SIZE) (l), \ - ((mhd_MSG_NOSIGNAL) | (f)))) +# define mhd_sys_send4(s, b, l, f) \ + ((ssize_t) send ((s),(const void*) (b),(mhd_SCKT_SEND_SIZE) (l), \ + ((mhd_MSG_NOSIGNAL) | (f)))) #else -# define mhd_sys_send4(s,b,l,f) \ - ((ssize_t) send ((s),(const char*) (b),(mhd_SCKT_SEND_SIZE) (l), \ - ((mhd_MSG_NOSIGNAL) | (f)))) +# define mhd_sys_send4(s, b, l, f) \ + ((ssize_t) send ((s),(const char*) (b),(mhd_SCKT_SEND_SIZE) (l), \ + ((mhd_MSG_NOSIGNAL) | (f)))) #endif /** @@ -98,7 +98,7 @@ * @param l the length of data in @a b * @return ssize_t type value */ -#define mhd_sys_send(s,b,l) mhd_sys_send4 ((s),(b),(l), 0) +#define mhd_sys_send(s, b, l) mhd_sys_send4 ((s),(b),(l), 0) /** @@ -109,11 +109,11 @@ * @return ssize_t type value */ #ifdef MHD_SOCKETS_KIND_POSIX -# define mhd_sys_recv(s,b,l) \ - ((ssize_t) recv ((s),(void*) (b),(mhd_SCKT_SEND_SIZE) (l), 0)) +# define mhd_sys_recv(s, b, l) \ + ((ssize_t) recv ((s),(void*) (b),(mhd_SCKT_SEND_SIZE) (l), 0)) #else -# define mhd_sys_recv(s,b,l) \ - ((ssize_t) recv ((s),(char*) (b),(mhd_SCKT_SEND_SIZE) (l), 0)) +# define mhd_sys_recv(s, b, l) \ + ((ssize_t) recv ((s),(char*) (b),(mhd_SCKT_SEND_SIZE) (l), 0)) #endif /** @@ -138,7 +138,7 @@ # if defined(EAGAIN) && defined(EWOULDBLOCK) && \ ((EWOULDBLOCK + 0) != (EAGAIN + 0)) # define mhd_SCKT_ERR_IS_EAGAIN(err) \ - ((EAGAIN == (err)) || (EWOULDBLOCK == (err))) + ((EAGAIN == (err)) || (EWOULDBLOCK == (err))) # elif defined(EAGAIN) # define mhd_SCKT_ERR_IS_EAGAIN(err) (EAGAIN == (err)) # elif defined(EWOULDBLOCK) @@ -290,15 +290,15 @@ /* + EHOSTUNREACH: probably reported by intermediate + ETIMEDOUT: probably keep-alive ping failure + ENETUNREACH: probably cable physically disconnected or similar */ -# define mhd_SCKT_ERR_IS_CONN_BROKEN(err) \ - ((0 != (err)) && \ - ((mhd_EHOSTUNREACH_OR_ZERO == (err)) || \ - (mhd_ETIMEDOUT_OR_ZERO == (err)) || \ - (mhd_ENETUNREACH_OR_ZERO == (err)))) +# define mhd_SCKT_ERR_IS_CONN_BROKEN(err) \ + ((0 != (err)) && \ + ((mhd_EHOSTUNREACH_OR_ZERO == (err)) || \ + (mhd_ETIMEDOUT_OR_ZERO == (err)) || \ + (mhd_ENETUNREACH_OR_ZERO == (err)))) #elif defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_SCKT_ERR_IS_CONN_BROKEN(err) \ - ( (WSAENETRESET == (err)) || (WSAECONNABORTED == (err)) || \ - (WSAETIMEDOUT == (err)) ) + ( (WSAENETRESET == (err)) || (WSAECONNABORTED == (err)) || \ + (WSAETIMEDOUT == (err)) ) #endif /** @@ -307,13 +307,13 @@ * boolean false otherwise. */ #if defined(MHD_SOCKETS_KIND_POSIX) -# define mhd_SCKT_ERR_IS_LOW_RESOURCES(err) \ - ((0 != (err)) && \ - ((mhd_EMFILE_OR_ZERO == (err)) || (mhd_ENFILE_OR_ZERO == (err)) || \ - (mhd_ENOMEM_OR_ZERO == (err)) || (mhd_ENOBUFS_OR_ZERO == (err)))) +# define mhd_SCKT_ERR_IS_LOW_RESOURCES(err) \ + ((0 != (err)) && \ + ((mhd_EMFILE_OR_ZERO == (err)) || (mhd_ENFILE_OR_ZERO == (err)) || \ + (mhd_ENOMEM_OR_ZERO == (err)) || (mhd_ENOBUFS_OR_ZERO == (err)))) #elif defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_SCKT_ERR_IS_LOW_RESOURCES(err) \ - ( (WSAEMFILE == (err)) || (WSAENOBUFS == (err)) ) + ( (WSAEMFILE == (err)) || (WSAENOBUFS == (err)) ) #endif /** @@ -323,9 +323,9 @@ * boolean false otherwise. */ #if defined(MHD_SOCKETS_KIND_POSIX) -# define mhd_SCKT_ERR_IS_LOW_MEM(err) \ - ((0 != (err)) && \ - ((mhd_ENOMEM_OR_ZERO == (err)) || (mhd_ENOBUFS_OR_ZERO == (err)))) +# define mhd_SCKT_ERR_IS_LOW_MEM(err) \ + ((0 != (err)) && \ + ((mhd_ENOMEM_OR_ZERO == (err)) || (mhd_ENOBUFS_OR_ZERO == (err)))) #elif defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_SCKT_ERR_IS_LOW_MEM(err) (WSAENOBUFS == (err)) #endif @@ -335,19 +335,22 @@ # ifdef HAVE_SOCKETPAIR # ifdef MHD_AF_UNIX # define mhd_socket_pair(fdarr_ptr) \ - (0 != socketpair (MHD_AF_UNIX, SOCK_STREAM, 0, (fdarr_ptr))) + (0 != socketpair (MHD_AF_UNIX, SOCK_STREAM, 0, (fdarr_ptr))) # else +/* Fallback, could be broken on many platforms */ # define mhd_socket_pair(fdarr_ptr) \ - (0 != socketpair (AF_INET, SOCK_STREAM, 0, (fdarr_ptr))) /* Fallback, could be broken on many platforms */ + (0 != socketpair (AF_INET, SOCK_STREAM, 0, (fdarr_ptr))) # endif # if defined(HAVE_DCLR_SOCK_NONBLOCK) # ifdef MHD_AF_UNIX # define mhd_socket_pair_nblk(fdarr_ptr) \ - (0 != socketpair (MHD_AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, \ - (fdarr_ptr))) + (0 != socketpair (MHD_AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, \ + (fdarr_ptr))) # else +/* Fallback, could be broken on many platforms */ # define mhd_socket_pair_nblk(fdarr_ptr) \ - (0 != socketpair (AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0, (fdarr_ptr))) /* Fallback, could be broken on many platforms */ + (0 != socketpair (AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0, \ + (fdarr_ptr))) # endif # endif /* HAVE_DCLR_SOCK_NONBLOCK*/ # endif /* HAVE_SOCKETPAIR */ diff --git a/src/mhd2/mhd_str.c b/src/mhd2/mhd_str.c @@ -74,7 +74,7 @@ #ifdef HAVE_INLINE_FUNCS -#ifdef mhd_HAVE_STR_TO_UPPER +# ifdef mhd_HAVE_STR_TO_UPPER /** * Check whether character is lower case letter in US-ASCII * @@ -84,13 +84,13 @@ mhd_static_inline MHD_FN_CONST_ bool isasciilower (char c) { - const unsigned int uc = (unsigned int) (unsigned char) c; - const unsigned int t = uc - (unsigned int) (unsigned char) 'a'; - return (((unsigned int) ('z' - 'a')) >= t); + const unsigned int uc = (unsigned int)(unsigned char)c; + const unsigned int t = uc - (unsigned int)(unsigned char)'a'; + return (((unsigned int)('z' - 'a')) >= t); } -#endif /* mhd_HAVE_STR_TO_UPPER */ +# endif /* mhd_HAVE_STR_TO_UPPER */ /** @@ -102,13 +102,13 @@ isasciilower (char c) mhd_static_inline MHD_FN_CONST_ bool isasciiupper (char c) { - const unsigned int uc = (unsigned int) (unsigned char) c; - const unsigned int t = uc - (unsigned int) (unsigned char) 'A'; - return (((unsigned int) ('Z' - 'A')) >= t); + const unsigned int uc = (unsigned int)(unsigned char)c; + const unsigned int t = uc - (unsigned int)(unsigned char)'A'; + return (((unsigned int)('Z' - 'A')) >= t); } -#if 0 /* Disable unused functions. */ +# if 0 /* Disable unused functions. */ /** * Check whether character is letter in US-ASCII * @@ -122,7 +122,7 @@ isasciialpha (char c) } -#endif /* Disable unused functions. */ +# endif /* Disable unused functions. */ /** @@ -138,7 +138,7 @@ isasciidigit (char c) } -#if 0 /* Disable unused functions. */ +# if 0 /* Disable unused functions. */ /** * Check whether character is hexadecimal digit in US-ASCII * @@ -148,9 +148,9 @@ isasciidigit (char c) mhd_static_inline MHD_FN_CONST_ bool isasciixdigit (char c) { - return isasciidigit (c) || - ( (c <= 'F') && (c >= 'A') ) || - ( (c <= 'f') && (c >= 'a') ); + return isasciidigit (c) + || ((c <= 'F') && (c >= 'A')) + || ((c <= 'f') && (c >= 'a')); } @@ -167,7 +167,7 @@ isasciialnum (char c) } -#endif /* Disable unused functions. */ +# endif /* Disable unused functions. */ /** * Convert US-ASCII character to lower case. @@ -181,11 +181,11 @@ isasciialnum (char c) mhd_static_inline MHD_FN_CONST_ char toasciilower (char c) { - return (char) (((unsigned char) c) | ((isasciiupper (c) ? 1u : 0u) << 5u)); + return (char)(((unsigned char)c) | ((isasciiupper (c) ? 1u : 0u) << 5u)); } -#ifdef mhd_HAVE_STR_TO_UPPER +# ifdef mhd_HAVE_STR_TO_UPPER /** * Convert US-ASCII character to upper case. @@ -199,15 +199,15 @@ toasciilower (char c) mhd_static_inline MHD_FN_CONST_ char toasciiupper (char c) { - return (char) (unsigned char) - (((unsigned char) c) & ~((isasciilower (c) ? 1u : 0u) << 5u)); + return (char)(unsigned char) + (((unsigned char)c) & ~((isasciilower (c) ? 1u : 0u) << 5u)); } -#endif /* mhd_HAVE_STR_TO_UPPER */ +# endif /* mhd_HAVE_STR_TO_UPPER */ -#if defined(MHD_FAVOR_SMALL_CODE) /* Used only in mhd_str_to_uvalue_n() */ +# if defined(MHD_FAVOR_SMALL_CODE) /* Used only in mhd_str_to_uvalue_n() */ /** * Convert US-ASCII decimal digit to its value. * @@ -218,13 +218,13 @@ mhd_static_inline MHD_FN_CONST_ int todigitvalue (char c) { if (isasciidigit (c)) - return (unsigned char) (c - '0'); + return (unsigned char)(c - '0'); return -1; } -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ /** @@ -236,8 +236,8 @@ todigitvalue (char c) mhd_static_inline MHD_FN_CONST_ int xdigittovalue (char c) { - const unsigned char uc = (unsigned char) c; /* Force unsigned value */ -#if ! defined(MHD_FAVOR_SMALL_CODE) + const unsigned char uc = (unsigned char)c; /* Force unsigned value */ +# if !defined(MHD_FAVOR_SMALL_CODE) static const signed char map_xdigit_to_value[256] = { -1 /* 0x00 (NUL) */, -1 /* 0x01 (SOH) */, @@ -497,18 +497,18 @@ xdigittovalue (char c) -1 /* 0xFF (EXT) */ }; return map_xdigit_to_value[uc]; -#else /* MHD_FAVOR_SMALL_CODE */ +# else /* MHD_FAVOR_SMALL_CODE */ unsigned int try_val; - try_val = uc - (unsigned char) '0'; + try_val = uc - (unsigned char)'0'; if (9 >= try_val) - return (int) (unsigned int) try_val; - try_val = (uc | 0x20u /* fold case */) - (unsigned char) 'a'; + return (int)(unsigned int)try_val; + try_val = (uc | 0x20u /* fold case */) - (unsigned char)'a'; if (5 >= try_val) - return (int) (unsigned int) (try_val + 10u); + return (int)(unsigned int)(try_val + 10u); return -1; -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ } @@ -521,7 +521,7 @@ xdigittovalue (char c) mhd_static_inline MHD_FN_CONST_ char valuetoxdigit (unsigned int v) { -#if ! defined(MHD_FAVOR_SMALL_CODE) +# if !defined(MHD_FAVOR_SMALL_CODE) static const char map_value_to_xdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; @@ -529,25 +529,25 @@ valuetoxdigit (unsigned int v) mhd_assert (16 > v); return map_value_to_xdigit[v]; -#else /* MHD_FAVOR_SMALL_CODE */ +# else /* MHD_FAVOR_SMALL_CODE */ mhd_assert (16 > v); if (v <= 9) - return '0' + (char) (v); - return 'a' + (char) (v - 10); -#endif /* MHD_FAVOR_SMALL_CODE */ + return '0' + (char)(v); + return 'a' + (char)(v - 10); +# endif /* MHD_FAVOR_SMALL_CODE */ } -#if ! defined(MHD_FAVOR_SMALL_CODE) +# if !defined(MHD_FAVOR_SMALL_CODE) /** * Convert 8 bit value to two US-ASCII hexadecimal digits. * * @param v the value to convert * @return pointer to char[2] with two hexadecimal digits */ -mhd_static_inline MHD_FN_CONST_ MHD_FN_RETURNS_NONNULL_ const char* +mhd_static_inline MHD_FN_CONST_ MHD_FN_RETURNS_NONNULL_ const char * uint8totwoxdigits (uint8_t v) { static const char map_uint8_to_two_xdigits[][2] = @@ -807,10 +807,10 @@ uint8totwoxdigits (uint8_t v) { 'f', 'd' }, { 'f', 'e' }, { 'f', 'f' } -#ifndef NDEBUG +# ifndef NDEBUG , { 0, 0 } -#endif /* ! NDEBUG */ +# endif /* ! NDEBUG */ }; mhd_assert (257u == \ @@ -821,11 +821,11 @@ uint8totwoxdigits (uint8_t v) /** * Indicates that function uint8totwoxdigits() is available */ -#define mhd_HAVE_UINT8TOTWOXDIGITS 1 +# define mhd_HAVE_UINT8TOTWOXDIGITS 1 } -#endif /* ! MHD_FAVOR_SMALL_CODE */ +# endif /* ! MHD_FAVOR_SMALL_CODE */ /** @@ -841,8 +841,8 @@ charsequalcaseless (char c1, char c2) if (c1 == c2) return true; /* Fold case on both sides */ - c1 = ((char) (~0x20u & (unsigned char) c1)); - c2 = ((char) (~0x20u & (unsigned char) c2)); + c1 = ((char)(~0x20u & (unsigned char)c1)); + c2 = ((char)(~0x20u & (unsigned char)c2)); return (c1 == c2) && isasciiupper (c1); } @@ -860,7 +860,7 @@ charsequallowercase (char mc, char lc) char uc; if (mc == lc) return true; - uc = ((char) (~0x20u & (unsigned char) lc)); + uc = ((char)(~0x20u & (unsigned char)lc)); return (mc == uc) && isasciiupper (mc); } @@ -916,8 +916,8 @@ charsequallowercase (char mc, char lc) * boolean false otherwise */ # define isasciixdigit(c) (isasciidigit ((c)) || \ - (((char) (c)) <= 'F' && ((char) (c)) >= 'A') || \ - (((char) (c)) <= 'f' && ((char) (c)) >= 'a')) + (((char) (c)) <= 'F' && ((char) (c)) >= 'A') || \ + (((char) (c)) <= 'f' && ((char) (c)) >= 'a')) /** @@ -940,7 +940,7 @@ charsequallowercase (char mc, char lc) * @return converted to lower case character */ # define toasciilower(c) \ - ((isasciiupper (c)) ? (((char) (c)) - 'A' + 'a') : ((char) (c))) + ((isasciiupper (c)) ? (((char) (c)) - 'A' + 'a') : ((char) (c))) /** @@ -953,7 +953,7 @@ charsequallowercase (char mc, char lc) * @return converted to upper case character */ # define toasciiupper(c) ((isasciilower (c)) ? (((char) (c)) - 'a' + 'A') : \ - ((char) (c))) + ((char) (c))) /** @@ -963,7 +963,7 @@ charsequallowercase (char mc, char lc) * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit */ # define todigitvalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \ - (int) (-1)) + (int) (-1)) /** @@ -972,14 +972,14 @@ charsequallowercase (char mc, char lc) * @return value of hexadecimal digit or -1 if @ c is not hexadecimal digit */ # define xdigittovalue(c) (isasciidigit (c) ? (int) (((char) (c)) - '0') : \ - ( (((char) (c)) >= 'A' && ((char) (c)) <= 'F') ? \ - (int) (((unsigned char) (c)) - 'A' + 10) : \ - ( (((char) (c)) >= 'a' && ((char) (c)) <= 'f') ? \ - (int) (((unsigned char) (c)) - 'a' + 10) : \ - (int) (-1) ))) + ( (((char) (c)) >= 'A' && ((char) (c)) <= 'F') ? \ + (int) (((unsigned char) (c)) - 'A' + 10) : \ + ( (((char) (c)) >= 'a' && ((char) (c)) <= 'f') ? \ + (int) (((unsigned char) (c)) - 'a' + 10) : \ + (int) (-1) ))) -#if ! defined(MHD_FAVOR_SMALL_CODE) +# if !defined(MHD_FAVOR_SMALL_CODE) static const char map_value_to_xdigit[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; @@ -991,16 +991,16 @@ static const char map_value_to_xdigit[16] = * @return hexadecimal digit */ # define valuetoxdigit(v) map_value_to_xdigit[v] -#else /* MHD_FAVOR_SMALL_CODE */ +# else /* MHD_FAVOR_SMALL_CODE */ /** * Convert 4 bit value to US-ASCII hexadecimal digit. * * @param v the value to convert, must be less then 16 * @return hexadecimal digit */ - # define valuetoxdigit(v) \ - (char) ((v <= 9) ? ('0' + (char) v) : ('a' + (char) v - 10)) -#endif /* MHD_FAVOR_SMALL_CODE */ +# define valuetoxdigit(v) \ + (char) ((v <= 9) ? ('0' + (char) v) : ('a' + (char) v - 10)) +# endif /* MHD_FAVOR_SMALL_CODE */ /** * Caseless compare two characters. @@ -1009,10 +1009,10 @@ static const char map_value_to_xdigit[16] = * @param c2 the second char to compare * @return boolean 'true' if chars are caseless equal, false otherwise */ -#define charsequalcaseless(c1, c2) \ - (((c1) == (c2)) || \ - (((0x20u | (unsigned char) (c1)) == (0x20u | (unsigned char) (c2))) \ - && isasciilower (((char) (0x20u | (unsigned char) (c2))))) ) +# define charsequalcaseless(c1, c2) \ + (((c1) == (c2)) || \ + (((0x20u | (unsigned char) (c1)) == (0x20u | (unsigned char) (c2))) \ + && isasciilower (((char) (0x20u | (unsigned char) (c2))))) ) /** * Compare mixed case and lower case characters. @@ -1021,10 +1021,10 @@ static const char map_value_to_xdigit[16] = * @param lc the lower case char to compare * @return boolean 'true' if chars are caseless equal, false otherwise */ -#define charsequallowercase(mc,lc) \ - ( ((mc) == (lc)) || \ - (((0x20u | (unsigned char) (mc)) == ((unsigned char) (lc))) && \ - isasciilower (lc)) ) +# define charsequallowercase(mc, lc) \ + ( ((mc) == (lc)) || \ + (((0x20u | (unsigned char) (mc)) == ((unsigned char) (lc))) && \ + isasciilower (lc)) ) #endif /* !HAVE_INLINE_FUNCS */ @@ -1093,7 +1093,7 @@ mhd_str_equal_caseless_bin_n (const char *const str1, else return 0; } - return ! 0; + return !0; } @@ -1110,8 +1110,8 @@ mhd_str_equal_lowercase_bin_n (const char *const mixstr, { const char mc = mixstr[i]; const char lc = lowstr[i]; - mhd_assert (! isasciiupper (lc)); - if (! charsequallowercase (mc, lc)) + mhd_assert (!isasciiupper (lc)); + if (!charsequallowercase (mc, lc)) return false; } return true; @@ -1119,8 +1119,8 @@ mhd_str_equal_lowercase_bin_n (const char *const mixstr, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) -MHD_FN_PAR_OUT_SIZE_ (3,1) void +MHD_FN_PAR_IN_SIZE_ (2, 1) +MHD_FN_PAR_OUT_SIZE_ (3, 1) void mhd_str_to_lowercase_bin_n (size_t size, const char *restrict inbuff, char *restrict outbuff) @@ -1133,7 +1133,7 @@ mhd_str_to_lowercase_bin_n (size_t size, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) bool +MHD_FN_PAR_IN_SIZE_ (2, 1) bool mhd_str_is_lowercase_bin_n (size_t len, const char *restrict str) { @@ -1149,8 +1149,8 @@ mhd_str_is_lowercase_bin_n (size_t len, #ifdef mhd_HAVE_STR_TO_UPPER MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) -MHD_FN_PAR_OUT_SIZE_ (3,1) void +MHD_FN_PAR_IN_SIZE_ (2, 1) +MHD_FN_PAR_OUT_SIZE_ (3, 1) void mhd_str_to_uppercase_bin_n (size_t size, const char *restrict inbuff, char *restrict outbuff) @@ -1191,7 +1191,7 @@ mhd_str_has_token_caseless (const char *restrict str, if (0 == sc) return false; - if (! charsequalcaseless (sc, tc)) + if (!charsequalcaseless (sc, tc)) break; if (i >= token_len) { @@ -1200,7 +1200,7 @@ mhd_str_has_token_caseless (const char *restrict str, while (' ' == *str || '\t' == *str) str++; /* End of (sub)string? */ - if ((0 == *str) || (',' == *str) ) + if ((0 == *str) || (',' == *str)) return true; /* Unmatched chars at end of substring. */ break; @@ -1215,7 +1215,7 @@ mhd_str_has_token_caseless (const char *restrict str, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_IN_SIZE_ (3,4) +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_IN_SIZE_ (3, 4) MHD_FN_PAR_OUT_ (5) MHD_FN_PAR_INOUT_ (6) bool mhd_str_remove_token_caseless (const char *restrict str, size_t str_len, @@ -1238,27 +1238,27 @@ mhd_str_remove_token_caseless (const char *restrict str, if (SSIZE_MAX <= ((str_len / 2) * 3 + 3)) { /* The return value may overflow, refuse */ - *buf_size = (ssize_t) -1; + *buf_size = (ssize_t)-1; return false; } s1 = str; s2 = buf; token_removed = false; - while ((size_t) (s1 - str) < str_len) + while ((size_t)(s1 - str) < str_len) { const char *cur_token; /**< the first char of current token */ size_t copy_size; /* Skip any initial whitespaces and empty tokens */ - while ( ((size_t) (s1 - str) < str_len) && - ((' ' == *s1) || ('\t' == *s1) || (',' == *s1)) ) + while (((size_t)(s1 - str) < str_len) + && ((' ' == *s1) || ('\t' == *s1) || (',' == *s1))) s1++; /* 's1' points to the first char of token in the input string or * points just beyond the end of the input string */ - if ((size_t) (s1 - str) >= str_len) + if ((size_t)(s1 - str) >= str_len) break; /* Nothing to copy, end of the input string */ /* 's1' points to the first char of token in the input string */ @@ -1267,24 +1267,24 @@ mhd_str_remove_token_caseless (const char *restrict str, /* Check the token with case-insensetive match */ t_pos = 0; - while ( ((size_t) (s1 - str) < str_len) && (token_len > t_pos) && - (charsequalcaseless (*s1, token[t_pos])) ) + while (((size_t)(s1 - str) < str_len) && (token_len > t_pos) + && (charsequalcaseless (*s1, token[t_pos]))) { s1++; t_pos++; } /* s1 may point just beyond the end of the input string */ - if ( (token_len == t_pos) && (0 != token_len) ) + if ((token_len == t_pos) && (0 != token_len)) { /* 'token' matched, check that current input token does not have * any suffixes */ - while ( ((size_t) (s1 - str) < str_len) && - ((' ' == *s1) || ('\t' == *s1)) ) + while (((size_t)(s1 - str) < str_len) + && ((' ' == *s1) || ('\t' == *s1))) s1++; /* 's1' points to the first non-whitespace char after the token matched * requested token or points just beyond the end of the input string after * the requested token */ - if (((size_t) (s1 - str) == str_len) || (',' == *s1)) + if (((size_t)(s1 - str) == str_len) || (',' == *s1)) {/* full token match, do not copy current token to the output */ token_removed = true; continue; @@ -1297,21 +1297,21 @@ mhd_str_remove_token_caseless (const char *restrict str, /* The current token in the input string does not match the token * to exclude, it must be copied to the output string */ /* the current token size excluding leading whitespaces and current char */ - copy_size = (size_t) (s1 - cur_token); + copy_size = (size_t)(s1 - cur_token); if (buf == s2) { /* The first token to copy to the output */ - if ((size_t) *buf_size < copy_size) + if ((size_t)*buf_size < copy_size) { /* Not enough space in the output buffer */ - *buf_size = (ssize_t) -1; + *buf_size = (ssize_t)-1; return false; } } else { /* Some token was already copied to the output buffer */ mhd_assert (s2 > buf); - if ((size_t) *buf_size < ((size_t) (s2 - buf)) + copy_size + 2) + if ((size_t)*buf_size < ((size_t)(s2 - buf)) + copy_size + 2) { /* Not enough space in the output buffer */ - *buf_size = (ssize_t) -1; + *buf_size = (ssize_t)-1; return false; } *(s2++) = ','; @@ -1324,19 +1324,19 @@ mhd_str_remove_token_caseless (const char *restrict str, s2 += copy_size; } - while ( ((size_t) (s1 - str) < str_len) && (',' != *s1)) + while (((size_t)(s1 - str) < str_len) && (',' != *s1)) { /* 's1' points to first non-whitespace char, to some char after * first non-whitespace char in the token in the input string */ /* Copy all non-whitespace chars from the current token in * the input string */ - while ( ((size_t) (s1 - str) < str_len) && - (',' != *s1) && (' ' != *s1) && ('\t' != *s1) ) + while (((size_t)(s1 - str) < str_len) + && (',' != *s1) && (' ' != *s1) && ('\t' != *s1)) { mhd_assert (s2 >= buf); - if ((size_t) *buf_size <= (size_t) (s2 - buf)) /* '<= s2' equals '< s2 + 1' */ + if ((size_t)*buf_size <= (size_t)(s2 - buf)) /* '<= s2' equals '< s2 + 1' */ { /* Not enough space in the output buffer */ - *buf_size = (ssize_t) -1; + *buf_size = (ssize_t)-1; return false; } *(s2++) = *(s1++); @@ -1344,34 +1344,34 @@ mhd_str_remove_token_caseless (const char *restrict str, /* 's1' points to some whitespace char in the token in the input * string, to the ',', or just beyond the end of the input string */ /* Skip all whitespaces */ - while ( ((size_t) (s1 - str) < str_len) && - ((' ' == *s1) || ('\t' == *s1)) ) + while (((size_t)(s1 - str) < str_len) + && ((' ' == *s1) || ('\t' == *s1))) s1++; /* 's1' points to the first non-whitespace char in the input string * after whitespace chars, to the ',', or just beyond the end of * the input string */ - if (((size_t) (s1 - str) < str_len) && (',' != *s1)) + if (((size_t)(s1 - str) < str_len) && (',' != *s1)) { /* Not the end of the current token */ mhd_assert (s2 >= buf); - if ((size_t) *buf_size <= (size_t) (s2 - buf)) /* '<= s2' equals '< s2 + 1' */ + if ((size_t)*buf_size <= (size_t)(s2 - buf)) /* '<= s2' equals '< s2 + 1' */ { /* Not enough space in the output buffer */ - *buf_size = (ssize_t) -1; + *buf_size = (ssize_t)-1; return false; } *(s2++) = ' '; } } } - mhd_assert (((ssize_t) (s2 - buf)) <= *buf_size); - *buf_size = (ssize_t) (s2 - buf); + mhd_assert (((ssize_t)(s2 - buf)) <= *buf_size); + *buf_size = (ssize_t)(s2 - buf); return token_removed; } MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_INOUT_ (2) -MHD_FN_PAR_IN_SIZE_ (3,4) bool +MHD_FN_PAR_IN_SIZE_ (3, 4) bool mhd_str_remove_tokens_caseless (char *restrict str, size_t *restrict str_len, const char *const restrict tkns, @@ -1391,8 +1391,8 @@ mhd_str_remove_tokens_caseless (char *restrict str, size_t tkn_len; /* Skip any initial whitespaces and empty tokens in 'tokens' */ - while ( (pt < tkns_len) && - ((' ' == tkns[pt]) || ('\t' == tkns[pt]) || (',' == tkns[pt])) ) + while ((pt < tkns_len) + && ((' ' == tkns[pt]) || ('\t' == tkns[pt]) || (',' == tkns[pt]))) pt++; if (pt >= tkns_len) @@ -1405,10 +1405,10 @@ mhd_str_remove_tokens_caseless (char *restrict str, do { pt++; - } while (pt < tkns_len && - (' ' != tkns[pt] && '\t' != tkns[pt] && ',' != tkns[pt])); + } while (pt < tkns_len + && (' ' != tkns[pt] && '\t' != tkns[pt] && ',' != tkns[pt])); /* Found end of the token string, space, tab, or comma */ - tkn_len = pt - (size_t) (tkn - tkns); + tkn_len = pt - (size_t)(tkn - tkns); /* Skip all spaces and tabs */ while (pt < tkns_len && (' ' == tkns[pt] || '\t' == tkns[pt])) @@ -1447,12 +1447,12 @@ mhd_str_remove_tokens_caseless (char *restrict str, { mhd_assert (pr >= pw); mhd_assert ((*str_len) >= (pr + tkn_len)); - if ( ( ((*str_len) == (pr + tkn_len)) || (',' == str[pr + tkn_len]) ) && - mhd_str_equal_caseless_bin_n (str + pr, tkn, tkn_len) ) + if ((((*str_len) == (pr + tkn_len)) || (',' == str[pr + tkn_len])) + && mhd_str_equal_caseless_bin_n (str + pr, tkn, tkn_len)) { /* current token in the input string matches the 'tkn', skip it */ - mhd_assert ((*str_len == pr + tkn_len) || \ - (' ' == str[pr + tkn_len + 1])); /* 'str' must be normalized */ + mhd_assert ((*str_len == pr + tkn_len) \ + || (' ' == str[pr + tkn_len + 1])); /* 'str' must be normalized */ token_removed = true; /* Advance to the next token in the input string or beyond * the end of the input string. */ @@ -1532,32 +1532,32 @@ mhd_str_to_uint64 (const char *restrict str, const char *const start = str; uint_fast64_t res; - if (! isasciidigit (str[0])) + if (!isasciidigit (str[0])) return 0; res = 0; do { - const int digit = (unsigned char) (*str) - '0'; + const int digit = (unsigned char)(*str) - '0'; uint_fast64_t prev_res = res; res *= 10; if (res / 10 != prev_res) return 0; - res += (unsigned int) digit; - if (res < (unsigned int) digit) + res += (unsigned int)digit; + if (res < (unsigned int)digit) return 0; str++; } while (isasciidigit (*str)); *out_val = res; - return (size_t) (str - start); + return (size_t)(str - start); } MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3) size_t mhd_str_to_uint64_n (const char *restrict str, size_t maxlen, @@ -1566,25 +1566,25 @@ mhd_str_to_uint64_n (const char *restrict str, uint_fast64_t res; size_t i; - if (! maxlen || ! isasciidigit (str[0])) + if (!maxlen || !isasciidigit (str[0])) return 0; res = 0; i = 0; do { - const int digit = (unsigned char) str[i] - '0'; + const int digit = (unsigned char)str[i] - '0'; uint_fast64_t prev_res = res; res *= 10; if (res / 10 != prev_res) return 0; - res += (unsigned int) digit; - if (res < (unsigned int) digit) + res += (unsigned int)digit; + if (res < (unsigned int)digit) return 0; i++; - } while ( (i < maxlen) && - isasciidigit (str[i]) ); + } while ((i < maxlen) + && isasciidigit (str[i])); *out_val = res; return i; @@ -1610,8 +1610,8 @@ mhd_strx_to_uint32 (const char *restrict str, res *= 16; if (res / 16 != prev_res) return 0; - res += (unsigned int) digit; - if (res < (unsigned int) digit) + res += (unsigned int)digit; + if (res < (unsigned int)digit) return 0; str++; @@ -1620,12 +1620,12 @@ mhd_strx_to_uint32 (const char *restrict str, if (str - start > 0) *out_val = res; - return (size_t) (str - start); + return (size_t)(str - start); } MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3) size_t mhd_strx_to_uint32_n (const char *restrict str, size_t maxlen, @@ -1647,8 +1647,8 @@ mhd_strx_to_uint32_n (const char *restrict str, res *= 16; if (res / 16 != prev_res) return 0; - res += (uint_fast32_t) digit; - if (res < (uint_fast32_t) digit) + res += (uint_fast32_t)digit; + if (res < (uint_fast32_t)digit) return 0; i++; @@ -1679,8 +1679,8 @@ mhd_strx_to_uint64 (const char *restrict str, res *= 16; if (res / 16 != prev_res) return 0; - res += (unsigned int) digit; - if (res < (unsigned int) digit) + res += (unsigned int)digit; + if (res < (unsigned int)digit) return 0; str++; @@ -1689,12 +1689,12 @@ mhd_strx_to_uint64 (const char *restrict str, if (str - start > 0) *out_val = res; - return (size_t) (str - start); + return (size_t)(str - start); } MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3) size_t mhd_strx_to_uint64_n (const char *restrict str, size_t maxlen, @@ -1716,8 +1716,8 @@ mhd_strx_to_uint64_n (const char *restrict str, res *= 16; if (res / 16 != prev_res) return 0; - res += (unsigned int) digit; - if (res < (unsigned int) digit) + res += (unsigned int)digit; + if (res < (unsigned int)digit) return 0; i++; } @@ -1731,7 +1731,7 @@ mhd_strx_to_uint64_n (const char *restrict str, #else /* MHD_FAVOR_SMALL_CODE */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4) size_t +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4) size_t mhd_str_to_uvalue_n (const char *restrict str, size_t maxlen, void *restrict out_val, @@ -1756,22 +1756,22 @@ mhd_str_to_uvalue_n (const char *restrict str, if (0 > digit) break; - if ( ((max_v_div_b) < res) || - (( (max_v_div_b) == res) && - ( (max_v_mod_b) < (uint_fast64_t) digit) ) ) + if (((max_v_div_b) < res) + || (((max_v_div_b) == res) + && ((max_v_mod_b) < (uint_fast64_t)digit))) return 0; res *= base; - res += (unsigned int) digit; + res += (unsigned int)digit; i++; } if (i) { if (8 == val_size) - *(uint_fast64_t *) out_val = res; + *(uint_fast64_t *)out_val = res; else if (4 == val_size) - *(uint_fast32_t *) out_val = (uint_fast32_t) res; + *(uint_fast32_t *)out_val = (uint_fast32_t)res; else return 0; } @@ -1783,21 +1783,21 @@ mhd_str_to_uvalue_n (const char *restrict str, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (2,3) size_t +MHD_FN_PAR_OUT_SIZE_ (2, 3) size_t mhd_uint32_to_strx (uint_fast32_t val, char *buf, size_t buf_size) { size_t o_pos = 0; /**< position of the output character */ int digit_pos = 8; /** zero-based, digit position in @a 'val' */ - uint_least32_t val32 = ((uint_least32_t) val) & 0xFFFFFFFFu; + uint_least32_t val32 = ((uint_least32_t)val) & 0xFFFFFFFFu; unsigned int xdigit; /* Skip leading zeros */ do { digit_pos--; - xdigit = (unsigned int) (val32 >> 28); + xdigit = (unsigned int)(val32 >> 28); val32 <<= 4; val32 &= 0xFFFFFFFFu; } while ((0 == xdigit) && (0 != digit_pos)); @@ -1808,7 +1808,7 @@ mhd_uint32_to_strx (uint_fast32_t val, if (0 == digit_pos) return o_pos; digit_pos--; - xdigit = (unsigned int) (val32 >> 28); + xdigit = (unsigned int)(val32 >> 28); val32 <<= 4; val32 &= 0xFFFFFFFFu; } @@ -1818,7 +1818,7 @@ mhd_uint32_to_strx (uint_fast32_t val, #ifndef MHD_FAVOR_SMALL_CODE MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (2,3) size_t +MHD_FN_PAR_OUT_SIZE_ (2, 3) size_t mhd_uint16_to_str (uint_least16_t val, char *buf, size_t buf_size) @@ -1830,27 +1830,27 @@ mhd_uint16_to_str (uint_least16_t val, val &= 0xFFFFu; chr = buf; - digit = (int) (val / divisor); + digit = (int)(val / divisor); mhd_assert (digit < 10); /* Do not print leading zeros */ while ((0 == digit) && (1 < divisor)) { divisor /= 10; - digit = (int) (val / divisor); + digit = (int)(val / divisor); mhd_assert (digit < 10); } while (0 != buf_size) { - *chr = (char) ((char) digit + '0'); + *chr = (char)((char)digit + '0'); chr++; buf_size--; if (1 == divisor) - return (size_t) (chr - buf); - val = (uint_least16_t) (val % divisor); + return (size_t)(chr - buf); + val = (uint_least16_t)(val % divisor); divisor /= 10; - digit = (int) (val / divisor); + digit = (int)(val / divisor); mhd_assert (digit < 10); } return 0; /* The buffer is too small */ @@ -1861,39 +1861,39 @@ mhd_uint16_to_str (uint_least16_t val, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (2,3) size_t +MHD_FN_PAR_OUT_SIZE_ (2, 3) size_t mhd_uint64_to_str (uint_fast64_t val, char *buf, size_t buf_size) { char *chr; /**< pointer to the current printed digit */ /* The biggest printable number is 18446744073709551615 */ - uint_fast64_t divisor = (uint_fast64_t) 10000000000000000000U; + uint_fast64_t divisor = (uint_fast64_t)10000000000000000000U; int digit; val &= 0xFFFFFFFFFFFFFFFFu; chr = buf; - digit = (int) (val / divisor); + digit = (int)(val / divisor); mhd_assert (digit < 10); /* Do not print leading zeros */ while ((0 == digit) && (1 < divisor)) { divisor /= 10; - digit = (int) (val / divisor); + digit = (int)(val / divisor); mhd_assert (digit < 10); } while (0 != buf_size) { - *chr = (char) ((char) digit + '0'); + *chr = (char)((char)digit + '0'); chr++; buf_size--; if (1 == divisor) - return (size_t) (chr - buf); + return (size_t)(chr - buf); val %= divisor; divisor /= 10; - digit = (int) (val / divisor); + digit = (int)(val / divisor); mhd_assert (digit < 10); } return 0; /* The buffer is too small */ @@ -1901,7 +1901,7 @@ mhd_uint64_to_str (uint_fast64_t val, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,4) size_t +MHD_FN_PAR_OUT_SIZE_ (3, 4) size_t mhd_uint8_to_str_pad (uint8_t val, uint8_t min_digits, char *buf, @@ -1923,7 +1923,7 @@ mhd_uint8_to_str_pad (uint8_t val, } else { - buf[pos++] = (char) ('0' + (char) digit); + buf[pos++] = (char)('0' + (char)digit); val %= 100; min_digits = 2; } @@ -1938,13 +1938,13 @@ mhd_uint8_to_str_pad (uint8_t val, } else { - buf[pos++] = (char) ('0' + (char) digit); + buf[pos++] = (char)('0' + (char)digit); val %= 10; } if (buf_size <= pos) return 0; - buf[pos++] = (char) ('0' + (char) val); + buf[pos++] = (char)('0' + (char)val); return pos; } @@ -1959,7 +1959,7 @@ mhd_bin_to_hex (const void *restrict bin, for (i = 0; i < size; ++i) { - const uint8_t b = ((const uint8_t *) bin)[i]; + const uint8_t b = ((const uint8_t *)bin)[i]; #ifdef mhd_HAVE_UINT8TOTWOXDIGITS const char *two_xdigits = uint8totwoxdigits (b); hex[i * 2] = two_xdigits[0]; @@ -1989,7 +1989,7 @@ mhd_bin_to_hex_z (const void *restrict bin, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_ (3) size_t +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3) size_t mhd_hex_to_bin (const char *restrict hex, size_t len, void *restrict bin) @@ -2006,7 +2006,7 @@ mhd_hex_to_bin (const char *restrict hex, const int l = xdigittovalue (c2); if (0 > l) return 0; - ((uint8_t *) bin)[w++] = (uint8_t) ((unsigned int) l); + ((uint8_t *)bin)[w++] = (uint8_t)((unsigned int)l); } while (r < len) { @@ -2016,9 +2016,9 @@ mhd_hex_to_bin (const char *restrict hex, const int l = xdigittovalue (c2); if ((0 > h) || (0 > l)) return 0; - ((uint8_t *) bin)[w++] = - (uint8_t) ( ((uint8_t) (((uint8_t) ((unsigned int) h)) << 4)) - | ((uint8_t) ((unsigned int) l)) ); + ((uint8_t *)bin)[w++] = + (uint8_t)(((uint8_t)(((uint8_t)((unsigned int)h)) << 4)) + | ((uint8_t)((unsigned int)l))); } mhd_assert (len == r); mhd_assert ((len + 1) / 2 == w); @@ -2027,7 +2027,7 @@ mhd_hex_to_bin (const char *restrict hex, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4) size_t +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4) size_t mhd_str_pct_decode_strict_n (const char *pct_encoded, size_t pct_encoded_len, char *decoded, @@ -2067,9 +2067,9 @@ mhd_str_pct_decode_strict_n (const char *pct_encoded, if ((0 > h) || (0 > l)) return 0; out = - (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4)) - | ((uint8_t) ((unsigned int) l))); - decoded[w] = (char) out; + (unsigned char)(((uint8_t)(((uint8_t)((unsigned int)h)) << 4)) + | ((uint8_t)((unsigned int)l))); + decoded[w] = (char)out; } } else @@ -2099,9 +2099,9 @@ mhd_str_pct_decode_strict_n (const char *pct_encoded, if ((0 > h) || (0 > l)) return 0; out = - (unsigned char) (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4)) - | ((uint8_t) ((unsigned int) l))); - decoded[w] = (char) out; + (unsigned char)(((uint8_t)(((uint8_t)((unsigned int)h)) << 4)) + | ((uint8_t)((unsigned int)l))); + decoded[w] = (char)out; } } else @@ -2116,7 +2116,7 @@ mhd_str_pct_decode_strict_n (const char *pct_encoded, MHD_INTERNAL MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4) size_t +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4) size_t mhd_str_pct_decode_lenient_n (const char *pct_encoded, size_t pct_encoded_len, char *decoded, @@ -2161,9 +2161,9 @@ mhd_str_pct_decode_lenient_n (const char *pct_encoded, { out = (unsigned char) - (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4)) - | ((uint8_t) ((unsigned int) l))); - decoded[w] = (char) out; + (((uint8_t)(((uint8_t)((unsigned int)h)) << 4)) + | ((uint8_t)((unsigned int)l))); + decoded[w] = (char)out; } } } @@ -2206,9 +2206,9 @@ mhd_str_pct_decode_lenient_n (const char *pct_encoded, unsigned char out; out = (unsigned char) - (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4)) - | ((uint8_t) ((unsigned int) l))); - decoded[w] = (char) out; + (((uint8_t)(((uint8_t)((unsigned int)h)) << 4)) + | ((uint8_t)((unsigned int)l))); + decoded[w] = (char)out; } } } @@ -2264,9 +2264,9 @@ mhd_str_pct_decode_in_place_strict (char *str) return 0; out = (unsigned char) - (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4)) - | ((uint8_t) ((unsigned int) l))); - str[w++] = (char) out; + (((uint8_t)(((uint8_t)((unsigned int)h)) << 4)) + | ((uint8_t)((unsigned int)l))); + str[w++] = (char)out; } } } @@ -2342,9 +2342,9 @@ mhd_str_pct_decode_in_place_lenient (char *restrict str, } out = (unsigned char) - (((uint8_t) (((uint8_t) ((unsigned int) h)) << 4)) - | ((uint8_t) ((unsigned int) l))); - str[w++] = (char) out; + (((uint8_t)(((uint8_t)((unsigned int)h)) << 4)) + | ((uint8_t)((unsigned int)l))); + str[w++] = (char)out; continue; } } @@ -2382,7 +2382,7 @@ pct_decode_no_slash (const size_t str_len, char dec; mhd_ASSUME (15 >= h); mhd_ASSUME (15 >= l); - dec = (char) ((((unsigned char) h) << 4u) | ((unsigned char) l)); + dec = (char)((((unsigned char)h) << 4u) | ((unsigned char)l)); if ('/' != dec) { *chr = dec; @@ -2396,7 +2396,7 @@ pct_decode_no_slash (const size_t str_len, MHD_INTERNAL -MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (2,1) size_t +MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (2, 1) size_t mhd_str_dec_norm_uri_path (size_t str_len, char *restrict str) { @@ -2413,11 +2413,11 @@ mhd_str_dec_norm_uri_path (size_t str_len, c = str[r]; if ('/' == c) break; /* Processed after this loop */ - if (('%' == c) && - pct_decode_no_slash (str_len, - str, - r, - &c)) + if (('%' == c) + && pct_decode_no_slash (str_len, + str, + r, + &c)) r += 2u; if ('.' == c) { @@ -2436,11 +2436,11 @@ mhd_str_dec_norm_uri_path (size_t str_len, r += 2u; /* Skip "./" */ continue; } - if (('%' == c2) && - pct_decode_no_slash (str_len, - str, - r + 1u, - &c2)) + if (('%' == c2) + && pct_decode_no_slash (str_len, + str, + r + 1u, + &c2)) r += 2u; if ('.' == c2) { @@ -2475,16 +2475,16 @@ mhd_str_dec_norm_uri_path (size_t str_len, mhd_ASSUME (w <= r); /* Found first segment which is not "../" and is not "./" OR the end of the string */ - for ((void) r; str_len > r && '/' != str[r]; ++r) + for ((void)r; str_len > r && '/' != str[r]; ++r) { char c; mhd_ASSUME (w <= r); c = str[r]; - if (('%' == c) && - pct_decode_no_slash (str_len, - str, - r, - &c)) + if (('%' == c) + && pct_decode_no_slash (str_len, + str, + r, + &c)) r += 2u; mhd_ASSUME (w <= r); str[w++] = c; @@ -2506,11 +2506,11 @@ mhd_str_dec_norm_uri_path (size_t str_len, c = str[r]; if ('/' == c) continue; - if (('%' == c) && - pct_decode_no_slash (str_len, - str, - r, - &c)) + if (('%' == c) + && pct_decode_no_slash (str_len, + str, + r, + &c)) r += 2u; if ('.' == c) { @@ -2530,11 +2530,11 @@ mhd_str_dec_norm_uri_path (size_t str_len, ++r; /* Skip "." */ continue; /* Go to the next "/", which will be written again */ } - if (('%' == c2) && - pct_decode_no_slash (str_len, - str, - r + 1u, - &c2)) + if (('%' == c2) + && pct_decode_no_slash (str_len, + str, + r + 1u, + &c2)) r += 2u; if ('.' == c2) { @@ -2580,17 +2580,17 @@ mhd_str_dec_norm_uri_path (size_t str_len, } mhd_assert (seg_start < w); } - for ((void) r; str_len > r && '/' != str[r]; ++r) + for ((void)r; str_len > r && '/' != str[r]; ++r) { /* Process the end of the segment */ char c; mhd_ASSUME (w <= r); c = str[r]; - if (('%' == c) && - pct_decode_no_slash (str_len, - str, - r, - &c)) + if (('%' == c) + && pct_decode_no_slash (str_len, + str, + r, + &c)) r += 2u; mhd_ASSUME (w <= r); str[w++] = c; @@ -2609,7 +2609,7 @@ mhd_str_dec_norm_uri_path (size_t str_len, #ifdef MHD_SUPPORT_AUTH_DIGEST MHD_INTERNAL MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_IN_SIZE_ (3,4) bool +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_IN_SIZE_ (3, 4) bool mhd_str_equal_quoted_bin_n (const char *quoted, size_t quoted_len, const char *unquoted, @@ -2640,7 +2640,7 @@ mhd_str_equal_quoted_bin_n (const char *quoted, MHD_INTERNAL MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_IN_SIZE_ (3,4) bool +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_IN_SIZE_ (3, 4) bool mhd_str_equal_caseless_quoted_bin_n (const char *quoted, size_t quoted_len, const char *unquoted, @@ -2660,7 +2660,7 @@ mhd_str_equal_caseless_quoted_bin_n (const char *quoted, if (quoted_len == i) return false; /* No character after escaping backslash */ } - if (! charsequalcaseless (quoted[i], unquoted[j])) + if (!charsequalcaseless (quoted[i], unquoted[j])) return false; /* Different characters */ } if ((quoted_len != i) || (unquoted_len != j)) @@ -2675,7 +2675,7 @@ mhd_str_equal_caseless_quoted_bin_n (const char *quoted, #if defined(MHD_SUPPORT_AUTH_DIGEST) || defined(MHD_SUPPORT_POST_PARSER) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,2) size_t +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 2) size_t mhd_str_unquote (const char *quoted, size_t quoted_len, char *result) @@ -2705,8 +2705,8 @@ mhd_str_unquote (const char *quoted, #if defined(MHD_SUPPORT_AUTH_DIGEST) || defined(MHD_SUPPORT_AUTH_BASIC) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) -MHD_FN_PAR_OUT_SIZE_ (3,4) size_t +MHD_FN_PAR_IN_SIZE_ (1, 2) +MHD_FN_PAR_OUT_SIZE_ (3, 4) size_t mhd_str_quote (const char *unquoted, size_t unquoted_len, char *result, @@ -2718,7 +2718,7 @@ mhd_str_quote (const char *unquoted, r = 0; w = 0; -#ifndef MHD_FAVOR_SMALL_CODE +# ifndef MHD_FAVOR_SMALL_CODE if (unquoted_len * 2 <= buf_size) { /* Fast loop: the output will fit the buffer with any input string content */ @@ -2734,10 +2734,10 @@ mhd_str_quote (const char *unquoted, { if (unquoted_len > buf_size) return 0; /* Quick fail: the output buffer is too small */ -#else /* MHD_FAVOR_SMALL_CODE */ +# else /* MHD_FAVOR_SMALL_CODE */ if (1) { -#endif /* MHD_FAVOR_SMALL_CODE */ +# endif /* MHD_FAVOR_SMALL_CODE */ while (unquoted_len > r) { @@ -2773,36 +2773,36 @@ mhd_str_quote (const char *unquoted, * 2 = medium, * 3 = fastest */ -#ifndef MHD_BASE64_FUNC_VERSION -#ifdef MHD_FAVOR_SMALL_CODE -#define MHD_BASE64_FUNC_VERSION 1 -#else /* ! MHD_FAVOR_SMALL_CODE */ -#define MHD_BASE64_FUNC_VERSION 3 -#endif /* ! MHD_FAVOR_SMALL_CODE */ -#endif /* ! MHD_BASE64_FUNC_VERSION */ - -#if MHD_BASE64_FUNC_VERSION < 1 || MHD_BASE64_FUNC_VERSION > 3 -#error Wrong MHD_BASE64_FUNC_VERSION value -#endif /* MHD_BASE64_FUNC_VERSION < 1 || MHD_BASE64_FUNC_VERSION > 3 */ - -#if MHD_BASE64_FUNC_VERSION == 3 -#define mhd_base64_map_type int -#else /* MHD_BASE64_FUNC_VERSION < 3 */ -#define mhd_base64_map_type int8_t -#endif /* MHD_BASE64_FUNC_VERSION < 3 */ - -#if MHD_BASE64_FUNC_VERSION == 1 +# ifndef MHD_BASE64_FUNC_VERSION +# ifdef MHD_FAVOR_SMALL_CODE +# define MHD_BASE64_FUNC_VERSION 1 +# else /* ! MHD_FAVOR_SMALL_CODE */ +# define MHD_BASE64_FUNC_VERSION 3 +# endif /* ! MHD_FAVOR_SMALL_CODE */ +# endif /* ! MHD_BASE64_FUNC_VERSION */ + +# if MHD_BASE64_FUNC_VERSION < 1 || MHD_BASE64_FUNC_VERSION > 3 +# error Wrong MHD_BASE64_FUNC_VERSION value +# endif /* MHD_BASE64_FUNC_VERSION < 1 || MHD_BASE64_FUNC_VERSION > 3 */ + +# if MHD_BASE64_FUNC_VERSION == 3 +# define mhd_base64_map_type int +# else /* MHD_BASE64_FUNC_VERSION < 3 */ +# define mhd_base64_map_type int8_t +# endif /* MHD_BASE64_FUNC_VERSION < 3 */ + +# if MHD_BASE64_FUNC_VERSION == 1 static mhd_base64_map_type base64_char_to_value_ (uint8_t c) { if ('Z' >= c) { if ('A' <= c) - return (mhd_base64_map_type) ((c - 'A') + 0); + return (mhd_base64_map_type)((c - 'A') + 0); else if ('0' <= c) { if ('9' >= c) - return (mhd_base64_map_type) ((c - '0') + 52); + return (mhd_base64_map_type)((c - '0') + 52); else if ('=' == c) return -2; else @@ -2816,25 +2816,25 @@ base64_char_to_value_ (uint8_t c) return -1; } else if (('z' >= c) && ('a' <= c)) - return (mhd_base64_map_type) ((c - 'a') + 26); + return (mhd_base64_map_type)((c - 'a') + 26); return -1; } -#endif /* MHD_BASE64_FUNC_VERSION == 1 */ +# endif /* MHD_BASE64_FUNC_VERSION == 1 */ mhd_DATA_TRUNCATION_RUNTIME_CHECK_DISABLE MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4) size_t +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4) size_t mhd_base64_to_bin_n (const char *base64, size_t base64_len, void *bin, size_t bin_size) { -#if MHD_BASE64_FUNC_VERSION >= 2 +# if MHD_BASE64_FUNC_VERSION >= 2 static const mhd_base64_map_type map[] = { /* -1 = invalid char, -2 = padding 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, @@ -2901,7 +2901,7 @@ mhd_base64_to_bin_n (const char *base64, 'x', 'y', 'z', '{', '|', '}', '~', DEL, */ 49, 50, 51, -1, -1, -1, -1, -1 -#if MHD_BASE64_FUNC_VERSION == 3 +# if MHD_BASE64_FUNC_VERSION == 3 , -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80..8F */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 90..9F */ @@ -2911,12 +2911,12 @@ mhd_base64_to_bin_n (const char *base64, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* D0..DF */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* E0..EF */ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* F0..FF */ -#endif /* ! MHD_BASE64_FUNC_VERSION == 3 */ +# endif /* ! MHD_BASE64_FUNC_VERSION == 3 */ }; -#define base64_char_to_value_(c) map[(c)] -#endif /* MHD_BASE64_FUNC_VERSION >= 2 */ - const uint8_t *const in = (const uint8_t *) base64; - uint8_t *const out = (uint8_t *) bin; +# define base64_char_to_value_(c) map[(c)] +# endif /* MHD_BASE64_FUNC_VERSION >= 2 */ + const uint8_t *const in = (const uint8_t *)base64; + uint8_t *const out = (uint8_t *)bin; size_t i; size_t j; if (0 == base64_len) @@ -2929,10 +2929,10 @@ mhd_base64_to_bin_n (const char *base64, j = 0; for (i = 0; i < (base64_len - 4); i += 4) { -#if MHD_BASE64_FUNC_VERSION == 2 +# if MHD_BASE64_FUNC_VERSION == 2 if (0 != (0x80 & (in[i] | in[i + 1] | in[i + 2] | in[i + 3]))) return 0; -#endif /* MHD_BASE64_FUNC_VERSION == 2 */ +# endif /* MHD_BASE64_FUNC_VERSION == 2 */ if (1) { const mhd_base64_map_type v1 = base64_char_to_value_ (in[i + 0]); @@ -2941,19 +2941,19 @@ mhd_base64_to_bin_n (const char *base64, const mhd_base64_map_type v4 = base64_char_to_value_ (in[i + 3]); if ((0 > v1) || (0 > v2) || (0 > v3) || (0 > v4)) return 0; - out[j + 0] = (uint8_t) (((uint8_t) (((uint8_t) v1) << 2)) - | ((uint8_t) (((uint8_t) v2) >> 4))); - out[j + 1] = (uint8_t) (((uint8_t) (((uint8_t) v2) << 4)) - | ((uint8_t) (((uint8_t) v3) >> 2))); - out[j + 2] = (uint8_t) (((uint8_t) (((uint8_t) v3) << 6)) - | ((uint8_t) v4)); + out[j + 0] = (uint8_t)(((uint8_t)(((uint8_t)v1) << 2)) + | ((uint8_t)(((uint8_t)v2) >> 4))); + out[j + 1] = (uint8_t)(((uint8_t)(((uint8_t)v2) << 4)) + | ((uint8_t)(((uint8_t)v3) >> 2))); + out[j + 2] = (uint8_t)(((uint8_t)(((uint8_t)v3) << 6)) + | ((uint8_t)v4)); } j += 3; } -#if MHD_BASE64_FUNC_VERSION == 2 +# if MHD_BASE64_FUNC_VERSION == 2 if (0 != (0x80 & (in[i] | in[i + 1] | in[i + 2] | in[i + 3]))) return 0; -#endif /* MHD_BASE64_FUNC_VERSION == 2 */ +# endif /* MHD_BASE64_FUNC_VERSION == 2 */ if (1) { /* The last four chars block */ const mhd_base64_map_type v1 = base64_char_to_value_ (in[i + 0]); @@ -2963,44 +2963,44 @@ mhd_base64_to_bin_n (const char *base64, if ((0 > v1) || (0 > v2)) return 0; /* Invalid char or padding at first two positions */ mhd_assert (j < bin_size); - out[j++] = (uint8_t) (((uint8_t) (((uint8_t) v1) << 2)) - | ((uint8_t) (((uint8_t) v2) >> 4))); + out[j++] = (uint8_t)(((uint8_t)(((uint8_t)v1) << 2)) + | ((uint8_t)(((uint8_t)v2) >> 4))); if (0 > v3) { /* Third char is either padding or invalid */ if ((-2 != v3) || (-2 != v4)) return 0; /* Both two last chars must be padding */ - if (0 != (uint8_t) (((uint8_t) v2) << 4)) + if (0 != (uint8_t)(((uint8_t)v2) << 4)) return 0; /* Wrong last char */ return j; } if (j >= bin_size) return 0; /* Not enough space */ - out[j++] = (uint8_t) (((uint8_t) (((uint8_t) v2) << 4)) - | ((uint8_t) (((uint8_t) v3) >> 2))); + out[j++] = (uint8_t)(((uint8_t)(((uint8_t)v2) << 4)) + | ((uint8_t)(((uint8_t)v3) >> 2))); if (0 > v4) { /* Fourth char is either padding or invalid */ if (-2 != v4) return 0; /* The char must be padding */ - if (0 != (uint8_t) (((uint8_t) v3) << 6)) + if (0 != (uint8_t)(((uint8_t)v3) << 6)) return 0; /* Wrong last char */ return j; } if (j >= bin_size) return 0; /* Not enough space */ - out[j++] = (uint8_t) (((uint8_t) (((uint8_t) v3) << 6)) - | ((uint8_t) v4)); + out[j++] = (uint8_t)(((uint8_t)(((uint8_t)v3) << 6)) + | ((uint8_t)v4)); } return j; -#if MHD_BASE64_FUNC_VERSION >= 2 -#undef base64_char_to_value_ -#endif /* MHD_BASE64_FUNC_VERSION >= 2 */ +# if MHD_BASE64_FUNC_VERSION >= 2 +# undef base64_char_to_value_ +# endif /* MHD_BASE64_FUNC_VERSION >= 2 */ } mhd_DATA_TRUNCATION_RUNTIME_CHECK_RESTORE -#undef mhd_base64_map_type +# undef mhd_base64_map_type #endif /* MHD_SUPPORT_AUTH_BASIC */ @@ -3019,9 +3019,9 @@ mhd_str_starts_with_token_opt_param (const struct MHD_String *restrict str, if (str->len < token->len) return false; /* The string is too short to match */ - if (! mhd_str_equal_caseless_bin_n (str->cstr, - token->cstr, - token->len)) + if (!mhd_str_equal_caseless_bin_n (str->cstr, + token->cstr, + token->len)) return false; /* The string does not start with the token */ for (i = token->len; i < str->len; ++i) @@ -3067,9 +3067,9 @@ mhd_str_starts_with_token_req_param ( if (str->len < token->len) return mhd_STR_STARTS_W_TOKEN_NO_TOKEN; /* The string is too short to match */ - if (! mhd_str_equal_caseless_bin_n (cstr, - token->cstr, - token->len)) + if (!mhd_str_equal_caseless_bin_n (cstr, + token->cstr, + token->len)) return mhd_STR_STARTS_W_TOKEN_NO_TOKEN; /* The string does not start with the token */ token_found = false; param_found = false; @@ -3078,7 +3078,7 @@ mhd_str_starts_with_token_req_param ( do { /* Find start of the next parameter */ - for ((void) 0; i < str->len; ++i) + for ((void)0; i < str->len; ++i) { const char c = cstr[i]; if ((' ' == c) || ('\t' == c)) @@ -3094,7 +3094,7 @@ mhd_str_starts_with_token_req_param ( if (',' == c) return mhd_STR_STARTS_W_TOKEN_HAS_TOKEN; /* Found the start of the next token */ - if (! token_found) + if (!token_found) { if (i == token->len) { @@ -3132,13 +3132,13 @@ mhd_str_starts_with_token_req_param ( const char *const prm_str = cstr + i; for (j = 0; j < par->len; ++j) - if (! charsequalcaseless (prm_str[j], - par->cstr[j])) + if (!charsequalcaseless (prm_str[j], + par->cstr[j])) break; i += j; mhd_assert (str->len > i); - if ((j == par->len) && - ('=' == cstr[i])) + if ((j == par->len) + && ('=' == cstr[i])) { /* The parameter name matches required parameter */ param_found = true; @@ -3191,7 +3191,7 @@ mhd_str_starts_with_token_req_param ( } while ('"' != cstr[i]); if (param_found) { - par_value->size = (size_t) ((cstr + i) - par_value->data); + par_value->size = (size_t)((cstr + i) - par_value->data); *par_value_needs_unquote = val_needs_unquote; } /* Complete value found */ @@ -3201,8 +3201,8 @@ mhd_str_starts_with_token_req_param ( else { /* The value is not quoted */ - while ((' ' != cstr[i]) && - ('\t' != cstr[i])) + while ((' ' != cstr[i]) + && ('\t' != cstr[i])) { if ((';' == cstr[i]) /* end of the parameter */ || (',' == cstr[i]) /* end of the token */ @@ -3212,7 +3212,7 @@ mhd_str_starts_with_token_req_param ( /* The end parameter value */ if (param_found) { - par_value->size = (size_t) ((cstr + i) - par_value->data); + par_value->size = (size_t)((cstr + i) - par_value->data); *par_value_needs_unquote = false; } /* Check for the garbage data at the end */ diff --git a/src/mhd2/mhd_str.h b/src/mhd2/mhd_str.h @@ -85,8 +85,8 @@ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (1) MHD_FN_PAR_CSTR_ (2); #else /* MHD_FAVOR_SMALL_CODE */ /* Reuse mhd_str_equal_caseless_n() to reduce size */ -#define mhd_str_equal_caseless(s1,s2) \ - mhd_str_equal_caseless_n ((s1),(s2), SIZE_MAX) +# define mhd_str_equal_caseless(s1, s2) \ + mhd_str_equal_caseless_n ((s1),(s2), SIZE_MAX) #endif /* MHD_FAVOR_SMALL_CODE */ @@ -138,7 +138,7 @@ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_ (1) MHD_FN_PAR_IN_ (2); * @param l the number of characters in the @a str string * @return 'true' if two strings are equal, 'false' otherwise. */ -#define mhd_str_equal_caseless_n_st(arr,str,l) \ +#define mhd_str_equal_caseless_n_st(arr, str, l) \ ((mhd_SSTR_LEN (arr) == (l)) \ && mhd_str_equal_caseless_bin_n (arr,str,l)) @@ -172,7 +172,7 @@ MHD_INTERNAL void mhd_str_to_lowercase_bin_n (size_t size, const char *restrict inbuff, char *restrict outbuff) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (3,1); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_SIZE_ (3, 1); /** * Check whether the string does not contain US-ASCII upper case letters. @@ -184,7 +184,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (3,1); MHD_INTERNAL bool mhd_str_is_lowercase_bin_n (size_t len, const char *restrict str) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2, 1); #ifdef mhd_HAVE_STR_TO_UPPER @@ -201,7 +201,7 @@ MHD_INTERNAL void mhd_str_to_uppercase_bin_n (size_t size, const char *restrict inbuff, char *restrict outbuff) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_OUT_SIZE_ (3,1); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_OUT_SIZE_ (3, 1); #endif /* mhd_HAVE_STR_TO_UPPER */ @@ -235,7 +235,7 @@ MHD_FN_PAR_IN_ (1) MHD_FN_PAR_IN_ (2); * @param tkn the static string of token to find * @return non-zero if two strings are equal, zero otherwise. */ -#define mhd_str_has_s_token_caseless(str,tkn) \ +#define mhd_str_has_s_token_caseless(str, tkn) \ mhd_str_has_token_caseless ((str),(tkn),mhd_SSTR_LEN (tkn)) @@ -274,7 +274,7 @@ mhd_str_remove_token_caseless (const char *restrict str, const size_t token_len, char *restrict buf, ssize_t *restrict buf_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_IN_SIZE_ (3,4) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_IN_SIZE_ (3, 4) MHD_FN_PAR_OUT_ (5) MHD_FN_PAR_INOUT_ (6); @@ -307,7 +307,7 @@ mhd_str_remove_tokens_caseless (char *restrict str, const char *const restrict tkns, const size_t tkns_len) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1) MHD_FN_PAR_INOUT_ (2) -MHD_FN_PAR_IN_SIZE_ (3,4); +MHD_FN_PAR_IN_SIZE_ (3, 4); #ifndef MHD_FAVOR_SMALL_CODE @@ -346,7 +346,7 @@ MHD_INTERNAL size_t mhd_str_to_uint64_n (const char *restrict str, size_t maxlen, uint_fast64_t *restrict out_val) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_ (3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3); /** @@ -383,7 +383,7 @@ MHD_INTERNAL size_t mhd_strx_to_uint32_n (const char *restrict str, size_t maxlen, uint_fast32_t *restrict out_val) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_ (3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3); /** @@ -420,7 +420,7 @@ MHD_INTERNAL size_t mhd_strx_to_uint64_n (const char *restrict str, size_t maxlen, uint_fast64_t *restrict out_val) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_ (3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3); #else /* MHD_FAVOR_SMALL_CODE */ /* Use one universal function and macros to reduce size */ @@ -450,47 +450,47 @@ mhd_str_to_uvalue_n (const char *restrict str, size_t val_size, uint_fast64_t max_val, unsigned int base) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4); - -#define mhd_str_to_uint64(s,ov) \ - mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ - sizeof(uint_fast64_t), \ - UINT64_MAX,10) - -#define mhd_str_to_uint64_n(s,ml,ov) \ - mhd_str_to_uvalue_n ((s),(ml),(ov), \ - sizeof(uint_fast64_t), \ - UINT64_MAX,10) - -#define mhd_strx_to_sizet(s,ov) \ - mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ - sizeof(size_t),SIZE_MAX, \ - 16) - -#define mhd_strx_to_sizet_n(s,ml,ov) \ - mhd_str_to_uvalue_n ((s),(ml),(ov), \ - sizeof(size_t), \ - SIZE_MAX,16) - -#define mhd_strx_to_uint32(s,ov) \ - mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ - sizeof(uint_fast32_t), \ - UINT32_MAX,16) - -#define mhd_strx_to_uint32_n(s,ml,ov) \ - mhd_str_to_uvalue_n ((s),(ml),(ov), \ - sizeof(uint_fast32_t), \ - UINT32_MAX,16) - -#define mhd_strx_to_uint64(s,ov) \ - mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ - sizeof(uint_fast64_t), \ - UINT64_MAX,16) - -#define mhd_strx_to_uint64_n(s,ml,ov) \ - mhd_str_to_uvalue_n ((s),(ml),(ov), \ - sizeof(uint_fast64_t), \ - UINT64_MAX,16) +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4); + +# define mhd_str_to_uint64(s, ov) \ + mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ + sizeof(uint_fast64_t), \ + UINT64_MAX,10) + +# define mhd_str_to_uint64_n(s, ml, ov) \ + mhd_str_to_uvalue_n ((s),(ml),(ov), \ + sizeof(uint_fast64_t), \ + UINT64_MAX,10) + +# define mhd_strx_to_sizet(s, ov) \ + mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ + sizeof(size_t),SIZE_MAX, \ + 16) + +# define mhd_strx_to_sizet_n(s, ml, ov) \ + mhd_str_to_uvalue_n ((s),(ml),(ov), \ + sizeof(size_t), \ + SIZE_MAX,16) + +# define mhd_strx_to_uint32(s, ov) \ + mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ + sizeof(uint_fast32_t), \ + UINT32_MAX,16) + +# define mhd_strx_to_uint32_n(s, ml, ov) \ + mhd_str_to_uvalue_n ((s),(ml),(ov), \ + sizeof(uint_fast32_t), \ + UINT32_MAX,16) + +# define mhd_strx_to_uint64(s, ov) \ + mhd_str_to_uvalue_n ((s),SIZE_MAX,(ov), \ + sizeof(uint_fast64_t), \ + UINT64_MAX,16) + +# define mhd_strx_to_uint64_n(s, ml, ov) \ + mhd_str_to_uvalue_n ((s),(ml),(ov), \ + sizeof(uint_fast64_t), \ + UINT64_MAX,16) #endif /* MHD_FAVOR_SMALL_CODE */ @@ -509,7 +509,7 @@ MHD_INTERNAL size_t mhd_uint32_to_strx (uint_fast32_t val, char *buf, size_t buf_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (2,3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (2, 3); #ifndef MHD_FAVOR_SMALL_CODE @@ -527,10 +527,10 @@ MHD_INTERNAL size_t mhd_uint16_to_str (uint_least16_t val, char *buf, size_t buf_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (2,3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (2, 3); #else /* MHD_FAVOR_SMALL_CODE */ -#define mhd_uint16_to_str(v,b,s) mhd_uint64_to_str (v,b,s) +# define mhd_uint16_to_str(v, b, s) mhd_uint64_to_str (v,b,s) #endif /* MHD_FAVOR_SMALL_CODE */ @@ -548,7 +548,7 @@ MHD_INTERNAL size_t mhd_uint64_to_str (uint_fast64_t val, char *buf, size_t buf_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (2,3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (2, 3); /** @@ -571,7 +571,7 @@ mhd_uint8_to_str_pad (uint8_t val, uint8_t min_digits, char *buf, size_t buf_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 4); /** @@ -621,7 +621,7 @@ MHD_INTERNAL size_t mhd_hex_to_bin (const char *restrict hex, size_t len, void *restrict bin) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_ (3); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_ (3); /** * Decode string with percent-encoded characters as defined by @@ -646,7 +646,7 @@ mhd_str_pct_decode_strict_n (const char *pct_encoded, size_t pct_encoded_len, char *decoded, size_t buf_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4); /** * Decode string with percent-encoded characters as defined by @@ -677,7 +677,7 @@ mhd_str_pct_decode_lenient_n (const char *pct_encoded, size_t buf_size, bool *restrict broken_encoding) MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) -MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4); +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4); /** @@ -724,7 +724,7 @@ MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_CSTR_ (1); MHD_INTERNAL size_t mhd_str_dec_norm_uri_path (size_t str_len, char *restrict str) -MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (2,1); +MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_INOUT_SIZE_ (2, 1); #ifdef MHD_SUPPORT_AUTH_DIGEST @@ -753,7 +753,7 @@ mhd_str_equal_quoted_bin_n (const char *quoted, const char *unquoted, size_t unquoted_len) MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ - MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_IN_SIZE_ (3,4); +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_IN_SIZE_ (3, 4); /** * Check whether the string after "unquoting" equals static string. @@ -771,8 +771,8 @@ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ * non-zero if two strings are equal after unquoting of the * first string. */ -#define mhd_str_equal_quoted_s_bin_n(q,l,u) \ - mhd_str_equal_quoted_bin_n (q,l,u,mhd_SSTR_LEN (u)) +# define mhd_str_equal_quoted_s_bin_n(q, l, u) \ + mhd_str_equal_quoted_bin_n (q,l,u,mhd_SSTR_LEN (u)) /** * Check two strings for equality, "unquoting" the first string from quoted @@ -800,7 +800,7 @@ mhd_str_equal_caseless_quoted_bin_n (const char *quoted, const char *unquoted, size_t unquoted_len) MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ - MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_IN_SIZE_ (3,4); +MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_IN_SIZE_ (3, 4); /** * Check whether the string after "unquoting" equals static string, ignoring @@ -819,8 +819,8 @@ MHD_FN_PURE_ MHD_FN_PAR_NONNULL_ALL_ * non-zero if two strings are caseless equal after unquoting of the * first string. */ -#define mhd_str_equal_caseless_quoted_s_bin_n(q,l,u) \ - mhd_str_equal_caseless_quoted_bin_n (q,l,u,mhd_SSTR_LEN (u)) +# define mhd_str_equal_caseless_quoted_s_bin_n(q, l, u) \ + mhd_str_equal_caseless_quoted_bin_n (q,l,u,mhd_SSTR_LEN (u)) #endif /* MHD_SUPPORT_AUTH_DIGEST */ @@ -845,7 +845,7 @@ MHD_INTERNAL size_t mhd_str_unquote (const char *quoted, size_t quoted_len, char *result) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,2); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 2); #endif /* MHD_SUPPORT_AUTH_DIGEST || MHD_SUPPORT_POST_PARSER */ @@ -871,7 +871,7 @@ mhd_str_quote (const char *unquoted, size_t unquoted_len, char *result, size_t buf_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4); #endif /* MHD_SUPPORT_AUTH_DIGEST || MHD_SUPPORT_AUTH_BASIC */ @@ -885,7 +885,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4); * @a enc_size is valid (properly padded), * undefined value smaller then @a enc_size if @a enc_size is not valid */ -#define mhd_base64_max_dec_size(enc_size) (((enc_size) / 4) * 3) +# define mhd_base64_max_dec_size(enc_size) (((enc_size) / 4) * 3) /** * Convert Base64 encoded string to binary data. @@ -909,7 +909,7 @@ mhd_base64_to_bin_n (const char *base64, size_t base64_len, void *bin, size_t bin_size) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1,2) MHD_FN_PAR_OUT_SIZE_ (3,4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (1, 2) MHD_FN_PAR_OUT_SIZE_ (3, 4); #endif /* MHD_SUPPORT_AUTH_BASIC */ diff --git a/src/mhd2/mhd_str_types.h b/src/mhd2/mhd_str_types.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_STRINGS_DEFINED -#include "sys_sizet_type.h" +# include "sys_sizet_type.h" /** @@ -88,7 +88,7 @@ struct MHD_StringNullable const char *cstr; }; -#define MHD_STRINGS_DEFINED 1 +# define MHD_STRINGS_DEFINED 1 #endif /* ! MHD_STRINGS_DEFINED */ #endif /* ! MHD_STR_TYPES_H */ diff --git a/src/mhd2/mhd_threads.c b/src/mhd2/mhd_threads.c @@ -50,7 +50,7 @@ # include <process.h> #endif #if defined(mhd_USE_THREAD_NAME) -# if ! defined(MHD_USE_THREAD_ATTR_SETNAME) +# if !defined(MHD_USE_THREAD_ATTR_SETNAME) # include "sys_malloc.h" # endif # ifdef HAVE_PTHREAD_NP_H @@ -121,7 +121,7 @@ mhd_set_thread_name (const mhd_thread_ID_native thread_id, * @return non-zero on success, zero otherwise */ # define mhd_set_cur_thread_name(n) \ - mhd_set_thread_name (pthread_self (),(n)) + mhd_set_thread_name (pthread_self (),(n)) # else /* __QNXNTO__ */ /* Special case for QNX Neutrino - using zero for thread ID sets name faster. */ # define mhd_set_cur_thread_name(n) mhd_set_thread_name (0,(n)) @@ -138,7 +138,7 @@ mhd_set_thread_name (const mhd_thread_ID_native thread_id, # elif defined(mhd_THREADS_KIND_W32) # ifndef _MSC_FULL_VER -#error Thread name available only for VC-compiler +# error Thread name available only for VC-compiler # else /* _MSC_FULL_VER */ /** * Set thread name @@ -152,7 +152,7 @@ mhd_set_thread_name (const mhd_thread_ID_native thread_id, const char *thread_name) { static const DWORD VC_SETNAME_EXC = 0x406D1388; -#pragma pack(push,8) +# pragma pack(push,8) struct thread_info_struct { DWORD type; /* Must be 0x1000. */ @@ -160,7 +160,7 @@ mhd_set_thread_name (const mhd_thread_ID_native thread_id, DWORD ID; /* Thread ID (-1 = caller thread). */ DWORD flags; /* Reserved for future use, must be zero. */ } thread_info; -#pragma pack(pop) +# pragma pack(pop) if (NULL == thread_name) return false; @@ -175,7 +175,7 @@ mhd_set_thread_name (const mhd_thread_ID_native thread_id, RaiseException (VC_SETNAME_EXC, 0, sizeof (thread_info) / sizeof(ULONG_PTR), - (ULONG_PTR *) &thread_info); + (ULONG_PTR *)&thread_info); } __except (EXCEPTION_EXECUTE_HANDLER) {} @@ -190,7 +190,7 @@ mhd_set_thread_name (const mhd_thread_ID_native thread_id, * @return true on success, false otherwise */ # define mhd_set_cur_thread_name(n) \ - mhd_set_thread_name ((mhd_thread_ID_native) (-1),(n)) + mhd_set_thread_name ((mhd_thread_ID_native) (-1),(n)) # endif /* _MSC_FULL_VER */ # endif /* mhd_THREADS_KIND_W32 */ @@ -224,7 +224,7 @@ mhd_create_thread (mhd_thread_handle_ID *handle_id, pthread_t *const new_tid_ptr = &new_tid; # endif /* ! mhd_thread_handle_ID_get_native_handle_ptr */ - mhd_assert (! mhd_thread_handle_ID_is_valid_handle (*handle_id)); + mhd_assert (!mhd_thread_handle_ID_is_valid_handle (*handle_id)); if (0 != stack_size) { @@ -253,7 +253,7 @@ mhd_create_thread (mhd_thread_handle_ID *handle_id, errno = res; mhd_thread_handle_ID_set_invalid (handle_id); } -# if ! defined(mhd_thread_handle_ID_get_native_handle_ptr) +# if !defined(mhd_thread_handle_ID_get_native_handle_ptr) else mhd_thread_handle_ID_set_native_handle (handle_id, new_tid); # endif /* ! mhd_thread_handle_ID_set_current_thread_ID */ @@ -263,9 +263,9 @@ mhd_create_thread (mhd_thread_handle_ID *handle_id, uintptr_t thr_handle; unsigned int stack_size_w32; - mhd_assert (! mhd_thread_handle_ID_is_valid_handle (*handle_id)); + mhd_assert (!mhd_thread_handle_ID_is_valid_handle (*handle_id)); - stack_size_w32 = (unsigned int) stack_size; + stack_size_w32 = (unsigned int)stack_size; # if SIZEOF_SIZE_T != SIZEOF_UNSIGNED_INT if (stack_size != stack_size_w32) { @@ -279,7 +279,7 @@ mhd_create_thread (mhd_thread_handle_ID *handle_id, arg, 0, NULL); - if ((mhd_thread_handle_native) 0 == (mhd_thread_handle_native) thr_handle) + if ((mhd_thread_handle_native)0 == (mhd_thread_handle_native)thr_handle) return false; mhd_thread_handle_ID_set_native_handle (handle_id, \ @@ -317,12 +317,12 @@ static mhd_THRD_RTRN_TYPE mhd_THRD_CALL_SPEC named_thread_starter (void *data) { struct mhd_named_helper_param *const param = - (struct mhd_named_helper_param *) data; + (struct mhd_named_helper_param *)data; void *arg; mhd_THREAD_START_ROUTINE thr_func; if (NULL == data) - return (mhd_THRD_RTRN_TYPE) 0; + return (mhd_THRD_RTRN_TYPE)0; mhd_set_cur_thread_name (param->name); @@ -381,9 +381,9 @@ mhd_create_named_thread (mhd_thread_handle_ID *handle_id, res = pthread_attr_setname_np (&attr, thread_name); # else -#error No pthread_attr_setname_np() function. +# error No pthread_attr_setname_np() function. # endif - if ((res == 0) && (0 != stack_size) ) + if ((res == 0) && (0 != stack_size)) res = pthread_attr_setstacksize (&attr, stack_size); if (0 == res) @@ -398,7 +398,7 @@ mhd_create_named_thread (mhd_thread_handle_ID *handle_id, errno = res; mhd_thread_handle_ID_set_invalid (handle_id); } -# if ! defined(mhd_thread_handle_ID_get_native_handle_ptr) +# if !defined(mhd_thread_handle_ID_get_native_handle_ptr) else mhd_thread_handle_ID_set_native_handle (handle_id, new_tid); # endif /* ! mhd_thread_handle_ID_set_current_thread_ID */ @@ -425,10 +425,10 @@ mhd_create_named_thread (mhd_thread_handle_ID *handle_id, /* Set the thread name in the thread itself to avoid problems with * threads which terminated before the name is set in other thread. */ - if (! mhd_create_thread (handle_id, - stack_size, - &named_thread_starter, - (void *) param)) + if (!mhd_create_thread (handle_id, + stack_size, + &named_thread_starter, + (void *)param)) { int err_num; @@ -451,9 +451,9 @@ mhd_thread_block_sigpipe (void) { sigset_t s_mask; - return ((0 == sigemptyset (&s_mask)) && - (0 == sigaddset (&s_mask, SIGPIPE)) && - (0 == pthread_sigmask (SIG_BLOCK, &s_mask, NULL))); + return ((0 == sigemptyset (&s_mask)) + && (0 == sigaddset (&s_mask, SIGPIPE)) + && (0 == pthread_sigmask (SIG_BLOCK, &s_mask, NULL))); } diff --git a/src/mhd2/mhd_threads.h b/src/mhd2/mhd_threads.h @@ -121,13 +121,13 @@ typedef HANDLE mhd_thread_handle_native; behaviour (while the thread ID cannot be zero with GNU C Library, it is not specified anywhere officially). It could be enabled for neglectable performance and size improvements. */ -# if 0 /* Disabled code */ +# if 0 /* Disabled code */ /** * The native invalid value for native thread handle */ -# define mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID \ - ((mhd_thread_handle_native) 0) -# endif /* Disabled code */ +# define mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID\ + ((mhd_thread_handle_native) 0) +# endif /* Disabled code */ # endif /* __gnu_linux__ || (__linux__ && __GLIBC__) */ #elif defined(mhd_THREADS_KIND_W32) /* On W32 the invalid value for thread handle is described directly in @@ -136,7 +136,7 @@ typedef HANDLE mhd_thread_handle_native; * The native invalid value for native thread handle */ # define mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID \ - ((mhd_thread_handle_native) NULL) + ((mhd_thread_handle_native) NULL) #endif /* mhd_THREADS_KIND_W32 */ #if defined(mhd_THREADS_KIND_POSIX) @@ -146,7 +146,7 @@ typedef HANDLE mhd_thread_handle_native; * @return nonzero on success, zero otherwise */ # define mhd_join_thread(native_handle) \ - (! pthread_join ((native_handle), NULL)) + (! pthread_join ((native_handle), NULL)) #elif defined(mhd_THREADS_KIND_W32) /** * Wait until specified thread is ended and the free thread handle on success. @@ -154,11 +154,11 @@ typedef HANDLE mhd_thread_handle_native; * @return nonzero on success, zero otherwise */ # define mhd_join_thread(native_handle) \ - ( (WAIT_OBJECT_0 == WaitForSingleObject ( (native_handle), INFINITE)) ? \ - (CloseHandle ( (native_handle)), ! 0) : 0) + ( (WAIT_OBJECT_0 == WaitForSingleObject ( (native_handle), INFINITE)) ? \ + (CloseHandle ( (native_handle)), ! 0) : 0) #endif -#if ! defined(mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID) +#if !defined(mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID) /** * Structure with thread handle and validity flag */ @@ -176,23 +176,23 @@ typedef struct mhd_thread_handle_struct mhd_thread_handle; * Set variable pointed by @a handle_ptr to invalid (unset) value */ # define mhd_thread_handle_set_invalid(handle_ptr) \ - ((handle_ptr)->valid = false) + ((handle_ptr)->valid = false) /** * Set the native handle in the variable pointed by the @a handle_ptr * to the @a native_val value */ -# define mhd_thread_handle_set_native(handle_ptr,native_val) \ - ((handle_ptr)->valid = true, (handle_ptr)->native = native_val) +# define mhd_thread_handle_set_native(handle_ptr, native_val) \ + ((handle_ptr)->valid = true, (handle_ptr)->native = native_val) /** * Check whether the native handle value is set in the @a handle_var variable */ # define mhd_thread_handle_is_valid(handle_var) \ - ((handle_var).valid) + ((handle_var).valid) /** * Get the native handle value from the @a handle_var variable */ # define mhd_thread_handle_get_native(handle_var) \ - ((handle_var).native) + ((handle_var).native) #else /* MHD_THREAD_HANDLE_NATIVE_INVALID_ */ /** * Type with thread handle that can be set to invalid value @@ -203,23 +203,23 @@ typedef mhd_thread_handle_native mhd_thread_handle; * Set the variable pointed by the @a handle_ptr to the invalid (unset) value */ # define mhd_thread_handle_set_invalid(handle_ptr) \ - ((*(handle_ptr)) = mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID) + ((*(handle_ptr)) = mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID) /** * Set the native handle in the variable pointed by the @a handle_ptr * to the @a native_val value */ -# define mhd_thread_handle_set_native(handle_ptr,native_val) \ - ((*(handle_ptr)) = (native_val)) +# define mhd_thread_handle_set_native(handle_ptr, native_val) \ + ((*(handle_ptr)) = (native_val)) /** * Check whether the native handle value is set in the @a handle_var variable */ # define mhd_thread_handle_is_valid(handle_var) \ - (mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID != (handle_var)) + (mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID != (handle_var)) /** * Get the native handle value from the @a handle_var variable */ # define mhd_thread_handle_get_native(handle_var) \ - (handle_var) + (handle_var) /** * Get the pointer to the native handle stored the variable pointed by * the @a handle_ptr pointer @@ -227,7 +227,7 @@ typedef mhd_thread_handle_native mhd_thread_handle; * the native handle is not possible */ # define mhd_thread_handle_get_native_ptr(handle_ptr) \ - (handle_ptr) + (handle_ptr) #endif /* MHD_THREAD_HANDLE_NATIVE_INVALID_ */ @@ -249,8 +249,8 @@ typedef pthread_t mhd_thread_ID_native; * Check whether two native thread IDs are equal. * @return non-zero if equal, zero if not equal */ -# define mhd_thread_ID_native_equal(id1,id2) \ - (pthread_equal ((id1),(id2))) +# define mhd_thread_ID_native_equal(id1, id2) \ + (pthread_equal ((id1),(id2))) #elif defined(mhd_THREADS_KIND_W32) /** * The native type used to check whether the current thread matches @@ -267,8 +267,8 @@ typedef DWORD mhd_thread_ID_native; * Check whether two native thread IDs are equal. * @return non-zero if equal, zero if not equal */ -# define mhd_thread_ID_native_equal(id1,id2) \ - ((id1) == (id2)) +# define mhd_thread_ID_native_equal(id1, id2) \ + ((id1) == (id2)) #endif /** @@ -286,17 +286,17 @@ typedef DWORD mhd_thread_ID_native; * The native invalid value for native thread ID */ # define MHD_THREAD_ID_NATIVE_VALUE_INVALID_ \ - mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID + mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID # endif /* mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID */ #elif defined(mhd_THREADS_KIND_W32) /** * The native invalid value for native thread ID */ - # define MHD_THREAD_ID_NATIVE_VALUE_INVALID_ \ - ((mhd_thread_ID_native) 0) +# define MHD_THREAD_ID_NATIVE_VALUE_INVALID_ \ + ((mhd_thread_ID_native) 0) #endif /* mhd_THREADS_KIND_W32 */ -#if ! defined(MHD_THREAD_ID_NATIVE_VALUE_INVALID_) +#if !defined(MHD_THREAD_ID_NATIVE_VALUE_INVALID_) /** * Structure with thread id and validity flag */ @@ -314,29 +314,29 @@ typedef struct mhd_thread_ID_struct mhd_thread_ID; * Set variable pointed by the @a ID_ptr to the invalid (unset) value */ # define mhd_thread_ID_set_invalid(ID_ptr) \ - ((ID_ptr)->valid = false) + ((ID_ptr)->valid = false) /** * Set the native ID in the variable pointed by the @a ID_ptr * to the @a native_val value */ -# define mhd_thread_ID_set_native(ID_ptr,native_val) \ - ((ID_ptr)->valid = true, (ID_ptr)->native = (native_val)) +# define mhd_thread_ID_set_native(ID_ptr, native_val) \ + ((ID_ptr)->valid = true, (ID_ptr)->native = (native_val)) /** * Check whether the native ID value is set in the @a ID_var variable */ # define mhd_thread_ID_is_valid(ID_var) \ - ((ID_var).valid) + ((ID_var).valid) /** * Get the native ID value from the @a ID_var variable */ # define mhd_thread_ID_get_native(ID_var) \ - ((ID_var).native) + ((ID_var).native) /** * Check whether the @a ID_var variable is equal current thread */ # define mhd_thread_ID_is_current_thread(ID_var) \ - (mhd_thread_ID_is_valid (ID_var) && \ - mhd_thread_ID_native_is_current_thread ((ID_var).native)) + (mhd_thread_ID_is_valid (ID_var) && \ + mhd_thread_ID_native_is_current_thread ((ID_var).native)) #else /* MHD_THREAD_ID_NATIVE_INVALID_ */ /** * Type with thread ID that can be set to the invalid value @@ -347,43 +347,43 @@ typedef mhd_thread_ID_native mhd_thread_ID; * Set variable pointed by the @a ID_ptr to the invalid (unset) value */ # define mhd_thread_ID_set_invalid(ID_ptr) \ - ((*(ID_ptr)) = MHD_THREAD_ID_NATIVE_VALUE_INVALID_) + ((*(ID_ptr)) = MHD_THREAD_ID_NATIVE_VALUE_INVALID_) /** * Set the native ID in the variable pointed by the @a ID_ptr * to the @a native_val value */ -# define mhd_thread_ID_set_native(ID_ptr,native_val) \ - ((*(ID_ptr)) = (native_val)) +# define mhd_thread_ID_set_native(ID_ptr, native_val) \ + ((*(ID_ptr)) = (native_val)) /** * Check whether the native ID value is set in the @a ID_var variable */ # define mhd_thread_ID_is_valid(ID_var) \ - (MHD_THREAD_ID_NATIVE_VALUE_INVALID_ != (ID_var)) + (MHD_THREAD_ID_NATIVE_VALUE_INVALID_ != (ID_var)) /** * Get the native ID value from the @a ID_var variable */ # define mhd_thread_ID_get_native(ID_var) \ - (ID_var) + (ID_var) /** * Check whether the @a ID_var variable is equal current thread */ # define mhd_thread_ID_is_current_thread(ID_var) \ - mhd_thread_ID_native_is_current_thread (ID_var) + mhd_thread_ID_native_is_current_thread (ID_var) #endif /* MHD_THREAD_ID_NATIVE_INVALID_ */ /** * Set current thread ID in the variable pointed by the @a ID_ptr */ -# define mhd_thread_ID_set_current_thread(ID_ptr) \ +#define mhd_thread_ID_set_current_thread(ID_ptr) \ mhd_thread_ID_set_native ((ID_ptr),mhd_thread_ID_native_current ()) #if defined(mhd_THREADS_KIND_POSIX) # if defined(mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID) && \ - ! defined(MHD_THREAD_ID_NATIVE_VALUE_INVALID_) + !defined(MHD_THREAD_ID_NATIVE_VALUE_INVALID_) # error mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID is defined, \ but MHD_THREAD_ID_NATIVE_VALUE_INVALID_ is not defined -# elif ! defined(mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID) && \ +# elif !defined(mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID) && \ defined(MHD_THREAD_ID_NATIVE_VALUE_INVALID_) # error mhd_THREAD_HANDLE_NATIVE_VALUE_INVALID is not defined, \ but MHD_THREAD_ID_NATIVE_VALUE_INVALID_ is defined @@ -465,7 +465,7 @@ typedef struct mhd_thread_handle_ID_ mhd_thread_handle_ID; * Set the native handle in the variable pointed by the @a hndl_id_ptr * to the @a native_val value */ -#define mhd_thread_handle_ID_set_native_handle(hndl_id_ptr,native_val) \ +#define mhd_thread_handle_ID_set_native_handle(hndl_id_ptr, native_val) \ mhd_thread_handle_set_native (&((hndl_id_ptr)->handle),native_val) #if defined(mhd_thread_handle_get_native_ptr) @@ -476,7 +476,7 @@ typedef struct mhd_thread_handle_ID_ mhd_thread_handle_ID; * the native handle is not possible */ # define mhd_thread_handle_ID_get_native_handle_ptr(hndl_id_ptr) \ - mhd_thread_handle_get_native_ptr (&((hndl_id_ptr)->handle)) + mhd_thread_handle_get_native_ptr (&((hndl_id_ptr)->handle)) #endif /* mhd_thread_handle_get_native_ptr */ /** @@ -505,7 +505,7 @@ typedef struct mhd_thread_handle_ID_ mhd_thread_handle_ID; * Set current thread ID in the variable pointed by the @a hndl_id_ptr */ # define mhd_thread_handle_ID_set_current_thread_ID(hndl_id_ptr) \ - mhd_thread_ID_set_current_thread (&((hndl_id_ptr)->ID)) + mhd_thread_ID_set_current_thread (&((hndl_id_ptr)->ID)) #endif /* ! MHD_THREAD_HANDLE_ID_IS_UNION */ /** @@ -543,7 +543,8 @@ mhd_create_thread (mhd_thread_handle_ID *handle_id, void *arg); #ifndef mhd_USE_THREAD_NAME -#define mhd_create_named_thread(t,n,s,r,a) mhd_create_thread ((t),(s),(r),(a)) +# define mhd_create_named_thread(t, n, s, r, a) \ + mhd_create_thread ((t),(s),(r),(a)) #else /* mhd_USE_THREAD_NAME */ /** * Create a named thread and set the attributes according to our options. @@ -564,7 +565,7 @@ mhd_create_named_thread (mhd_thread_handle_ID *handle_id, #endif /* mhd_USE_THREAD_NAME */ -#if ! defined(mhd_SEND_SPIPE_SUPPRESS_NEEDED) +#if !defined(mhd_SEND_SPIPE_SUPPRESS_NEEDED) # define mhd_thread_block_sigpipe() ((void) 0) #else # ifdef HAVE_PTHREAD_SIGMASK diff --git a/src/mhd2/mhd_tls_choice.h b/src/mhd2/mhd_tls_choice.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_HTTPS -#error This header should be used only if HTTPS is enabled +# error This header should be used only if HTTPS is enabled #endif /* ** Helper macros ** */ @@ -56,11 +56,11 @@ /** * Concatenate three arguments literally */ -#define mhd_MACRO_CONCAT3_(a,b,c) a ## b ## c +#define mhd_MACRO_CONCAT3_(a, b, c) a ## b ## c /** * Concatenate three arguments after expansion */ -#define mhd_MACRO_CONCAT3(a,b,c) mhd_MACRO_CONCAT3_ (a,b,c) +#define mhd_MACRO_CONCAT3(a, b, c) mhd_MACRO_CONCAT3_ (a,b,c) /* ** Enumerate TLS backends ** */ @@ -129,7 +129,7 @@ (mhd_TLS_GNU_ENABLED + mhd_TLS_OPEN_ENABLED + mhd_TLS_MBED_ENABLED) #if mhd_TLS_NUM_BACKENDS == 0 -#error At least one TLS backend must be enabled if this header is included +# error At least one TLS backend must be enabled if this header is included #endif #if mhd_TLS_NUM_BACKENDS > 1 @@ -140,11 +140,11 @@ #endif /* Sanity check */ -#if defined(MHD_USE_MULTITLS) && ! defined(mhd_HAVE_SEVERAL_TLS_BACKENDS) -#error several TLS backends set by configure, but only one available for code +#if defined(MHD_USE_MULTITLS) && !defined(mhd_HAVE_SEVERAL_TLS_BACKENDS) +# error several TLS backends set by configure, but only one available for code #endif -#if ! defined(MHD_USE_MULTITLS) && defined(mhd_HAVE_SEVERAL_TLS_BACKENDS) -#error several TLS backends available for code, but ony one set by configure +#if !defined(MHD_USE_MULTITLS) && defined(mhd_HAVE_SEVERAL_TLS_BACKENDS) +# error several TLS backends available for code, but ony one set by configure #endif #ifdef MHD_USE_MULTITLS diff --git a/src/mhd2/mhd_tls_common.h b/src/mhd2/mhd_tls_common.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_HTTPS -#error This header should be used only if HTTPS is enabled +# error This header should be used only if HTTPS is enabled #endif struct DaemonOptions; /* Forward declaration */ diff --git a/src/mhd2/mhd_tls_enums.h b/src/mhd2/mhd_tls_enums.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_HTTPS -#error This header should be used only if HTTPS is enabled +# error This header should be used only if HTTPS is enabled #endif /** diff --git a/src/mhd2/mhd_tls_funcs.h b/src/mhd2/mhd_tls_funcs.h @@ -52,7 +52,7 @@ #include "mhd_tls_choice.h" #ifndef MHD_SUPPORT_HTTPS -#error This header should be used only if HTTPS is enabled +# error This header should be used only if HTTPS is enabled #endif #if defined(MHD_USE_MULTITLS) @@ -103,7 +103,7 @@ * @return #MHD_SC_OK on success (p_d_tls set to the allocated settings), * error code otherwise */ -#define mhd_tls_daemon_init(d,et,s,p_d_tls) \ +#define mhd_tls_daemon_init(d, et, s, p_d_tls) \ mhd_TLS_FUNC (_daemon_init)((d),(et),(s),(p_d_tls)) /** @@ -142,7 +142,7 @@ * @return 'true' on success, * 'false' otherwise */ -#define mhd_tls_conn_init(d_tls,sk,c_tls) \ +#define mhd_tls_conn_init(d_tls, sk, c_tls) \ mhd_TLS_FUNC (_conn_init)((d_tls),(sk),(c_tls)) /** @@ -187,7 +187,7 @@ * @return mhd_SOCKET_ERR_NO_ERROR if receive succeed (the @a received gets * the received size) or socket error */ -#define mhd_tls_conn_recv(c_tls,buf_size,buf,received) \ +#define mhd_tls_conn_recv(c_tls, buf_size, buf, received) \ mhd_TLS_FUNC (_conn_recv)((c_tls),(buf_size),(buf),(received)) /** @@ -214,7 +214,7 @@ * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets * the sent size) or socket error */ -#define mhd_tls_conn_send(c_tls,buf_size,buf,push_data,sent) \ +#define mhd_tls_conn_send(c_tls, buf_size, buf, push_data, sent) \ mhd_TLS_FUNC (_conn_send)((c_tls),(buf_size),(buf),(push_data),(sent)) @@ -242,7 +242,7 @@ * @param c_tls the connection TLS handle * @param tls_ver_out the pointer to variable to be set to the TLS version */ -#define mhd_tls_conn_get_tls_sess(c_tls,tls_sess_out) \ +#define mhd_tls_conn_get_tls_sess(c_tls, tls_sess_out) \ mhd_TLS_FUNC (_conn_get_tls_sess)((c_tls),(tls_sess_out)) /** @@ -252,7 +252,7 @@ * @return 'true' is TLS version information set successfully, * 'false' if TLS version information cannot be obtained or mapped */ -#define mhd_tls_conn_get_tls_ver(c_tls,tls_ver_out) \ +#define mhd_tls_conn_get_tls_ver(c_tls, tls_ver_out) \ mhd_TLS_FUNC (_conn_get_tls_ver)((c_tls),(tls_ver_out)) /** diff --git a/src/mhd2/mhd_tls_internal.c b/src/mhd2/mhd_tls_internal.c @@ -65,23 +65,23 @@ mhd_tls_alpn_decode_n (size_t alnp_id_size, return mhd_TLS_ALPN_PROT_NOT_SELECTED; #ifdef MHD_SUPPORT_HTTP2 - if ((alnp_id_size == mhd_ALPN_H2_LEN) && - (0 == memcmp (alnp_id, - mhd_ALPN_H2, - mhd_ALPN_H2_LEN))) + if ((alnp_id_size == mhd_ALPN_H2_LEN) + && (0 == memcmp (alnp_id, + mhd_ALPN_H2, + mhd_ALPN_H2_LEN))) return mhd_TLS_ALPN_PROT_HTTP2; #endif /* MHD_SUPPORT_HTTP2 */ - if ((alnp_id_size == mhd_ALPN_H1_1_LEN) && - (0 == memcmp (alnp_id, - mhd_ALPN_H1_1, - mhd_ALPN_H1_1_LEN))) + if ((alnp_id_size == mhd_ALPN_H1_1_LEN) + && (0 == memcmp (alnp_id, + mhd_ALPN_H1_1, + mhd_ALPN_H1_1_LEN))) return mhd_TLS_ALPN_PROT_HTTP1_1; - if ((alnp_id_size == mhd_ALPN_H1_0_LEN) && - (0 == memcmp (alnp_id, - mhd_ALPN_H1_0, - mhd_ALPN_H1_0_LEN))) + if ((alnp_id_size == mhd_ALPN_H1_0_LEN) + && (0 == memcmp (alnp_id, + mhd_ALPN_H1_0, + mhd_ALPN_H1_0_LEN))) return mhd_TLS_ALPN_PROT_HTTP1_0; mhd_UNREACHABLE_D ("ALPN can negotiate only one of the provided values"); diff --git a/src/mhd2/mhd_tls_internal.h b/src/mhd2/mhd_tls_internal.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_HTTPS -#error This header should be used only if HTTPS is enabled +# error This header should be used only if HTTPS is enabled #endif #include "sys_sizet_type.h" diff --git a/src/mhd2/mhd_unreachable.h b/src/mhd2/mhd_unreachable.h @@ -47,9 +47,9 @@ #include "mhd_sys_options.h" -#if ! defined(NDEBUG) +#if !defined(NDEBUG) # include "mhd_assert.h" -#elif defined (MHD_UNREACHABLE_NEEDS_STDDEF_H) +#elif defined(MHD_UNREACHABLE_NEEDS_STDDEF_H) # include <stddef.h> #endif @@ -69,9 +69,9 @@ # endif #else # define mhd_UNREACHABLE() \ - mhd_assert (0 && "This code should be unreachable") + mhd_assert (0 && "This code should be unreachable") # define mhd_UNREACHABLE_D(descr) \ - mhd_assert (0 && descr) + mhd_assert (0 && descr) #endif #endif /* ! MHD_UNREACHABLE_H */ diff --git a/src/mhd2/post_parser_funcs.c b/src/mhd2/post_parser_funcs.c @@ -136,7 +136,7 @@ process_mpart_header (struct MHD_Connection *restrict c, "because 'Content-Type: " \ "multipart/form-data' header is " \ "misformed: %.*s%s"), \ - (int) ((h_cnt_tp->len <= 127) ? h_cnt_tp->len : 127), + (int)((h_cnt_tp->len <= 127) ? h_cnt_tp->len : 127), h_cnt_tp->cstr, (h_cnt_tp->len <= 127) ? "" : "..."); c->rq.u_proc.post.parse_result = @@ -183,7 +183,7 @@ process_mpart_header (struct MHD_Connection *restrict c, buf[2] = '-'; buf[3] = '-'; - if (! mpart_bound_quoted) + if (!mpart_bound_quoted) { memcpy (buf + 4, mpart_bound.data, @@ -220,10 +220,10 @@ detect_post_enc (struct MHD_Connection *restrict c) mhd_assert (mhd_HTTP_STAGE_BODY_RECEIVING > c->stage); - if (! mhd_request_get_value_st (&(c->rq), - MHD_VK_HEADER, - MHD_HTTP_HEADER_CONTENT_TYPE, - &hdr_cnt_tp)) + if (!mhd_request_get_value_st (&(c->rq), + MHD_VK_HEADER, + MHD_HTTP_HEADER_CONTENT_TYPE, + &hdr_cnt_tp)) { mhd_LOG_MSG (c->daemon, MHD_SC_REQ_POST_PARSE_FAILED_NO_CNTN_TYPE, \ "The request POST data cannot be parsed because " \ @@ -248,7 +248,7 @@ detect_post_enc (struct MHD_Connection *restrict c) enum mhd_MPartDetectResult res; res = process_mpart_header (c, - (const struct MHD_String *) (const void *) + (const struct MHD_String *)(const void *) &hdr_cnt_tp); if (mhd_MPART_DET_OK == res) @@ -300,10 +300,10 @@ detect_mpart_boundary_from_the_header (struct MHD_Connection *restrict c) mhd_assert (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == \ c->rq.app_act.head_act.data.post_parse.enc); - if (! mhd_request_get_value_st (&(c->rq), - MHD_VK_HEADER, - MHD_HTTP_HEADER_CONTENT_TYPE, - &hdr_cnt_tp)) + if (!mhd_request_get_value_st (&(c->rq), + MHD_VK_HEADER, + MHD_HTTP_HEADER_CONTENT_TYPE, + &hdr_cnt_tp)) { mhd_LOG_MSG (c->daemon, MHD_SC_REQ_POST_PARSE_FAILED_NO_CNTN_TYPE, \ "The request POST data cannot be parsed because " \ @@ -316,7 +316,7 @@ detect_mpart_boundary_from_the_header (struct MHD_Connection *restrict c) mhd_assert (NULL != hdr_cnt_tp.cstr); res = process_mpart_header (c, - (const struct MHD_String *) (const void *) + (const struct MHD_String *)(const void *) &hdr_cnt_tp); if (mhd_MPART_DET_OK == res) @@ -450,7 +450,7 @@ mhd_stream_prepare_for_post_parse (struct MHD_Connection *restrict c) if (MHD_HTTP_POST_ENCODING_OTHER == c->rq.app_act.head_act.data.post_parse.enc) { - if (! detect_post_enc (c)) + if (!detect_post_enc (c)) { mhd_assert (MHD_POST_PARSE_RES_OK != c->rq.u_proc.post.parse_result); c->discard_request = true; @@ -461,7 +461,7 @@ mhd_stream_prepare_for_post_parse (struct MHD_Connection *restrict c) else if (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == c->rq.app_act.head_act.data.post_parse.enc) { - if (! detect_mpart_boundary_from_the_header (c)) + if (!detect_mpart_boundary_from_the_header (c)) { mhd_assert (MHD_POST_PARSE_RES_OK != c->rq.u_proc.post.parse_result); c->discard_request = true; @@ -475,8 +475,8 @@ mhd_stream_prepare_for_post_parse (struct MHD_Connection *restrict c) mhd_assert (MHD_HTTP_POST_ENCODING_OTHER != \ c->rq.u_proc.post.enc); mhd_assert ((MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA != \ - c->rq.u_proc.post.enc) || \ - (4 < c->rq.u_proc.post.e_d.m_form.delim.size)); + c->rq.u_proc.post.enc) \ + || (4 < c->rq.u_proc.post.e_d.m_form.delim.size)); init_post_parse_data (c); @@ -633,7 +633,7 @@ is_value_streaming_needed (struct MHD_Connection *restrict c, if (NULL == p_par->stream_reader) { mhd_assert (0 == p_data->value_off); - mhd_assert (! p_data->force_streamed); + mhd_assert (!p_data->force_streamed); return false; /* No value streaming possible */ } @@ -671,8 +671,8 @@ add_parsed_post_field (struct MHD_Connection *restrict c, mhd_assert ((0 != filename->pos) || (0 == filename->len)); mhd_assert ((0 != content_type->pos) || (0 == content_type->len)); - mhd_assert ((0 != transfer_encoding->pos) || \ - (0 == transfer_encoding->len)); + mhd_assert ((0 != transfer_encoding->pos) \ + || (0 == transfer_encoding->len)); mhd_assert ((0 != value->pos) || (0 == value->len)); pfield = (struct mhd_RequestPostField *) @@ -802,31 +802,31 @@ process_complete_field_all (struct MHD_Connection *restrict c, mhd_assert (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act); - mhd_assert ((0 == filename_start) || \ - (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc)); - mhd_assert ((0 == cntn_type_start) || \ - (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc)); - mhd_assert ((0 == enc_start) || \ - (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc)); + mhd_assert ((0 == filename_start) \ + || (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc)); + mhd_assert ((0 == cntn_type_start) \ + || (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc)); + mhd_assert ((0 == enc_start) \ + || (MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc)); mhd_assert (mhd_HTTP_STAGE_REQ_RECV_FINISHED >= c->stage); mhd_assert (value_start + value_len <= *pfield_next_pos); - mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) || \ - (value_start + value_len < *pfield_next_pos)); + mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) \ + || (value_start + value_len < *pfield_next_pos)); mhd_assert (*pfield_next_pos <= *pdata_size); - mhd_assert ((name_start + name_len < value_start) || \ - (0 == value_start)); + mhd_assert ((name_start + name_len < value_start) \ + || (0 == value_start)); mhd_assert (value_start + value_len <= *pfield_next_pos); - mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) || \ - (name_start + name_len < *pfield_next_pos)); - mhd_assert ((filename_start + filename_len < value_start) || \ - (0 == value_start)); + mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) \ + || (name_start + name_len < *pfield_next_pos)); + mhd_assert ((filename_start + filename_len < value_start) \ + || (0 == value_start)); mhd_assert (filename_start + filename_len <= *pfield_next_pos); - mhd_assert ((cntn_type_start + cntn_type_len < value_start) || \ - (0 == value_start)); + mhd_assert ((cntn_type_start + cntn_type_len < value_start) \ + || (0 == value_start)); mhd_assert (cntn_type_start + cntn_type_len <= *pfield_next_pos); - mhd_assert ((enc_start + enc_len < value_start) || \ - (0 == value_start)); + mhd_assert ((enc_start + enc_len < value_start) \ + || (0 == value_start)); mhd_assert (enc_start + enc_len <= *pfield_next_pos); mhd_assert (field_start <= name_start); mhd_assert ((field_start <= filename_start) || (0 == filename_start)); @@ -837,7 +837,7 @@ process_complete_field_all (struct MHD_Connection *restrict c, mhd_assert ((0 != cntn_type_start) || (0 == cntn_type_len)); mhd_assert ((0 != enc_start) || (0 == enc_len)); mhd_assert ((0 != value_start) || (0 == value_len)); - mhd_assert (0 == buf [name_start + name_len]); + mhd_assert (0 == buf[name_start + name_len]); p_data->some_data_provided = true; @@ -905,9 +905,9 @@ process_complete_field_all (struct MHD_Connection *restrict c, struct mhd_PositionAndLength encoding_i; struct mhd_PositionAndLength value_i; - mhd_assert (! p_data->force_streamed); + mhd_assert (!p_data->force_streamed); mhd_assert (0 == p_data->value_off); - mhd_assert ((0 == value_start) || (0 == buf [value_start + value_len])); + mhd_assert ((0 == value_start) || (0 == buf[value_start + value_len])); name_i.pos = name_start; name_i.len = name_len; @@ -920,12 +920,12 @@ process_complete_field_all (struct MHD_Connection *restrict c, value_i.pos = value_start; value_i.len = value_len; - if (! add_parsed_post_field (c, - &name_i, - &filename_i, - &content_type_i, - &encoding_i, - &value_i)) + if (!add_parsed_post_field (c, + &name_i, + &filename_i, + &content_type_i, + &encoding_i, + &value_i)) { c->stage = mhd_HTTP_STAGE_FULL_REQ_RECEIVED; mhd_LOG_MSG (c->daemon, MHD_SC_REQ_POST_PARSE_FAILED_NO_POOL_MEM, \ @@ -973,13 +973,13 @@ process_complete_field (struct MHD_Connection *restrict c, { mhd_assert (mhd_HTTP_STAGE_REQ_RECV_FINISHED >= c->stage); mhd_assert (value_start + value_len <= *pfield_next_pos); - mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) || \ - (value_start + value_len < *pfield_next_pos)); - mhd_assert ((name_start + name_len < value_start) || \ - (0 == value_start)); + mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) \ + || (value_start + value_len < *pfield_next_pos)); + mhd_assert ((name_start + name_len < value_start) \ + || (0 == value_start)); mhd_assert (name_start + name_len <= *pfield_next_pos); - mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) || \ - (name_start + name_len < *pfield_next_pos)); + mhd_assert ((mhd_HTTP_STAGE_FULL_REQ_RECEIVED <= c->stage) \ + || (name_start + name_len < *pfield_next_pos)); mhd_assert (field_start <= name_start); mhd_assert ((field_start <= value_start) || (0 == value_start)); @@ -1201,11 +1201,11 @@ parse_post_urlenc (struct MHD_Connection *restrict c, mhd_assert (MHD_HTTP_POST_ENCODING_FORM_URLENCODED == c->rq.u_proc.post.enc); mhd_assert (MHD_POST_PARSE_RES_OK == p_data->parse_result); - mhd_assert (! c->discard_request); + mhd_assert (!c->discard_request); mhd_assert (p_data->next_parse_pos < *pdata_size); - if ((mhd_POST_UENC_ST_VALUE == uf->st) && - (0 != uf->value_len)) + if ((mhd_POST_UENC_ST_VALUE == uf->st) + && (0 != uf->value_len)) { /* The 'value' was partially decoded, but not processed because application * asked for 'suspend' action */ @@ -1254,17 +1254,17 @@ parse_post_urlenc (struct MHD_Connection *restrict c, break; } } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_UENC_ST_AT_EQ == uf->st) || \ - (mhd_POST_UENC_ST_AT_AMPRSND == uf->st) ); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_UENC_ST_AT_EQ == uf->st) \ + || (mhd_POST_UENC_ST_AT_AMPRSND == uf->st)); continue; case mhd_POST_UENC_ST_AT_EQ: mhd_assert (i > uf->name_idx); mhd_assert (0 == uf->name_len); mhd_assert (uf->last_pct_idx >= p_data->field_start); mhd_assert (uf->last_pct_idx >= uf->name_idx); - mhd_assert ((uf->last_pct_idx == mhd_POST_INVALID_POS) || \ - (uf->last_pct_idx < i)); + mhd_assert ((uf->last_pct_idx == mhd_POST_INVALID_POS) \ + || (uf->last_pct_idx < i)); mhd_assert (0 == uf->value_len); if (uf->last_pct_idx != mhd_POST_INVALID_POS) uf->name_len = mhd_str_pct_decode_lenient_n (buf + uf->name_idx, @@ -1302,15 +1302,15 @@ parse_post_urlenc (struct MHD_Connection *restrict c, break; } } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_UENC_ST_AT_AMPRSND == uf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_UENC_ST_AT_AMPRSND == uf->st)); continue; case mhd_POST_UENC_ST_AT_AMPRSND: mhd_assert (0 == uf->value_len); - mhd_assert ((uf->last_pct_idx == mhd_POST_INVALID_POS) || \ - (uf->last_pct_idx < i)); - mhd_assert ((uf->last_pct_idx == mhd_POST_INVALID_POS) || \ - ((uf->name_idx + uf->name_len) < i)); + mhd_assert ((uf->last_pct_idx == mhd_POST_INVALID_POS) \ + || (uf->last_pct_idx < i)); + mhd_assert ((uf->last_pct_idx == mhd_POST_INVALID_POS) \ + || ((uf->name_idx + uf->name_len) < i)); if (0 != uf->value_idx) { /* Have 'name' and 'value' */ @@ -1377,14 +1377,14 @@ parse_post_urlenc (struct MHD_Connection *restrict c, mhd_assert (mhd_POST_UENC_ST_AT_EQ != uf->st); mhd_assert (mhd_POST_UENC_ST_AT_AMPRSND != uf->st); mhd_assert (mhd_POST_UENC_ST_FULL_FIELD_FOUND != uf->st); - mhd_assert ((mhd_POST_UENC_ST_VALUE != uf->st) || \ - (0 == uf->value_len)); + mhd_assert ((mhd_POST_UENC_ST_VALUE != uf->st) \ + || (0 == uf->value_len)); mhd_assert (*pdata_size == i); - if ((mhd_POST_UENC_ST_VALUE == uf->st) && - (i != uf->value_idx) && /* Encoded value position must be larger then zero */ - is_value_streaming_needed (c, i - p_data->field_start)) + if ((mhd_POST_UENC_ST_VALUE == uf->st) + && (i != uf->value_idx) /* Encoded value position must be larger then zero */ + && is_value_streaming_needed (c, i - p_data->field_start)) { size_t len_of_value_part; if (uf->last_pct_idx != mhd_POST_INVALID_POS) @@ -1470,7 +1470,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, c->rq.u_proc.post.enc); mhd_assert (MHD_POST_PARSE_RES_OK == p_data->parse_result); mhd_assert (mhd_POST_MPART_ST_FORMAT_ERROR != mf->st); - mhd_assert (! c->discard_request); + mhd_assert (!c->discard_request); mhd_assert (p_data->next_parse_pos < *pdata_size); i = p_data->next_parse_pos; @@ -1492,16 +1492,16 @@ parse_post_mpart (struct MHD_Connection *restrict c, if (mf->delim.size <= *pdata_size - i) { const char *delim_ptr; - if (! bare_lf_as_crlf) - delim_ptr = (const char *) memmem (buf + i, - *pdata_size - i, - mf->delim.data, - mf->delim.size); + if (!bare_lf_as_crlf) + delim_ptr = (const char *)memmem (buf + i, + *pdata_size - i, + mf->delim.data, + mf->delim.size); else - delim_ptr = (const char *) memmem (buf + i, - *pdata_size - i, - mf->delim.data + 1, - mf->delim.size - 1); + delim_ptr = (const char *)memmem (buf + i, + *pdata_size - i, + mf->delim.data + 1, + mf->delim.size - 1); if (NULL != delim_ptr) { size_t delim_pos; @@ -1509,11 +1509,11 @@ parse_post_mpart (struct MHD_Connection *restrict c, mhd_assert (delim_ptr >= buf + i); mhd_assert (delim_ptr + mf->delim.size - 1 <= buf + *pdata_size); - delim_pos = (size_t) (delim_ptr - buf); + delim_pos = (size_t)(delim_ptr - buf); mhd_assert (i <= delim_pos); - if (! bare_lf_as_crlf) + if (!bare_lf_as_crlf) { mf->line_start = delim_pos + 2u; /* '2' for CRLF */ i = delim_pos + mf->delim.size; @@ -1527,7 +1527,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, continue; } i = *pdata_size - mf->delim.size + 1u; /* '+ 1u' to move to then next position */ - if (! bare_lf_as_crlf) + if (!bare_lf_as_crlf) i += 1u; } #endif /* HAVE_MEMMEM */ @@ -1537,7 +1537,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, const char *lf_ptr; size_t lf_pos; - lf_ptr = (const char *) memchr (buf + i, '\n', *pdata_size - i); + lf_ptr = (const char *)memchr (buf + i, '\n', *pdata_size - i); if (NULL == lf_ptr) { if ('\r' == buf[*pdata_size - 1]) @@ -1545,7 +1545,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, i = *pdata_size; break; } - lf_pos = (size_t) (lf_ptr - buf); + lf_pos = (size_t)(lf_ptr - buf); mhd_assert (i <= lf_pos); mhd_assert (*pdata_size > i); if (bare_lf_as_crlf) @@ -1554,8 +1554,8 @@ parse_post_mpart (struct MHD_Connection *restrict c, mf->st = mhd_POST_MPART_ST_PREAMBL_LINE_START; break; } - else if ((i < lf_pos) && - ('\r' == buf[lf_pos - 1])) + else if ((i < lf_pos) + && ('\r' == buf[lf_pos - 1])) { i = lf_pos + 1; mf->st = mhd_POST_MPART_ST_PREAMBL_LINE_START; @@ -1569,7 +1569,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, ++i; /* Go to the next char */ break; } - else if ('\n' == buf[i] && bare_lf_as_crlf) + else if (('\n' == buf[i]) && bare_lf_as_crlf) { mf->st = mhd_POST_MPART_ST_PREAMBL_LINE_START; ++i; /* Go to the next char */ @@ -1577,9 +1577,9 @@ parse_post_mpart (struct MHD_Connection *restrict c, } #endif /* MHD_FAVOR_SMALL_CODE */ } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_MPART_ST_PREAMBL_CR_FOUND == mf->st) || \ - (mhd_POST_MPART_ST_PREAMBL_LINE_START == mf->st) ); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_MPART_ST_PREAMBL_CR_FOUND == mf->st) \ + || (mhd_POST_MPART_ST_PREAMBL_LINE_START == mf->st)); continue; case mhd_POST_MPART_ST_PREAMBL_CR_FOUND: mhd_assert (mhd_POST_INVALID_POS != mf->delim_check_start); @@ -1647,9 +1647,9 @@ parse_post_mpart (struct MHD_Connection *restrict c, else mf->st = mhd_POST_MPART_ST_BACK_TO_PREAMBL; } - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_MPART_ST_FIRST_DELIM_FOUND == mf->st) || \ - (mhd_POST_MPART_ST_BACK_TO_PREAMBL == mf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_MPART_ST_FIRST_DELIM_FOUND == mf->st) \ + || (mhd_POST_MPART_ST_BACK_TO_PREAMBL == mf->st)); continue; case mhd_POST_MPART_ST_FIRST_DELIM_FOUND: mhd_assert (mhd_POST_INVALID_POS == mf->delim_check_start); /* Ignored for first delimiter */ @@ -1659,8 +1659,8 @@ parse_post_mpart (struct MHD_Connection *restrict c, { if ('\n' == buf[i]) { - if (bare_lf_as_crlf || - ('\r' == buf [i - 1])) + if (bare_lf_as_crlf + || ('\r' == buf[i - 1])) { mf->st = mhd_POST_MPART_ST_FIRST_PART_START; ++i; @@ -1670,31 +1670,31 @@ parse_post_mpart (struct MHD_Connection *restrict c, break; } - else if ('\r' == buf [i - 1]) + else if ('\r' == buf[i - 1]) { mf->st = mhd_POST_MPART_ST_FORMAT_ERROR; break; } - else if ((i == mf->line_start + (mf->delim.size - 2) + 1) && - ('-' == buf [i - 1]) && - ('-' == buf [i])) + else if ((i == mf->line_start + (mf->delim.size - 2) + 1) + && ('-' == buf[i - 1]) + && ('-' == buf[i])) { mf->st = mhd_POST_MPART_ST_EPILOGUE; break; } } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_MPART_ST_FIRST_PART_START == mf->st) || \ - (mhd_POST_MPART_ST_FORMAT_ERROR == mf->st) || \ - (mhd_POST_MPART_ST_EPILOGUE == mf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_MPART_ST_FIRST_PART_START == mf->st) \ + || (mhd_POST_MPART_ST_FORMAT_ERROR == mf->st) \ + || (mhd_POST_MPART_ST_EPILOGUE == mf->st)); continue; case mhd_POST_MPART_ST_FIRST_PART_START: mhd_assert (mhd_POST_INVALID_POS == mf->delim_check_start); /* Ignored for first delimiter */ mhd_assert (i > p_data->field_start); mhd_assert (*pdata_size > i); if ((c->rq.app_act.head_act.data.post_parse.max_nonstream_size < - i - p_data->field_start) || - (*pdata_size - i < i - p_data->field_start)) + i - p_data->field_start) + || (*pdata_size - i < i - p_data->field_start)) { /* Discard unused data */ memmove (buf + p_data->field_start, @@ -1748,7 +1748,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, /* The delimiter before the end of the header */ if (2 > mf->line_start) mf->delim_check_start = mf->line_start; - else if (! bare_lf_as_crlf) + else if (!bare_lf_as_crlf) mf->delim_check_start = mf->line_start - 2; else mf->delim_check_start = mf->line_start - 1; /* Actually can be one char earlier */ @@ -1757,11 +1757,11 @@ parse_post_mpart (struct MHD_Connection *restrict c, } } } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_MPART_ST_HEADER_LINE_CR_FOUND == mf->st) || \ - (mhd_POST_MPART_ST_HEADER_LINE_END == mf->st) || \ - (mhd_POST_MPART_ST_DELIM_FOUND == mf->st) || \ - (mhd_POST_MPART_ST_FORMAT_ERROR == mf->st) ); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_MPART_ST_HEADER_LINE_CR_FOUND == mf->st) \ + || (mhd_POST_MPART_ST_HEADER_LINE_END == mf->st) \ + || (mhd_POST_MPART_ST_DELIM_FOUND == mf->st) \ + || (mhd_POST_MPART_ST_FORMAT_ERROR == mf->st)); continue; case mhd_POST_MPART_ST_HEADER_LINE_CR_FOUND: if ('\n' != buf[i]) @@ -1799,10 +1799,10 @@ parse_post_mpart (struct MHD_Connection *restrict c, static const struct MHD_String tkn = mhd_MSTR_INIT ("form-data"); static const struct MHD_String n_par = mhd_MSTR_INIT ("name"); - if ((hdr.len + tkn.len + n_par.len + 2 <= line_len) && - mhd_str_equal_caseless_bin_n (hdr.cstr, - buf + mf->line_start, - hdr.len)) + if ((hdr.len + tkn.len + n_par.len + 2 <= line_len) + && mhd_str_equal_caseless_bin_n (hdr.cstr, + buf + mf->line_start, + hdr.len)) { size_t hdr_val_start; struct MHD_String hdr_val; @@ -1811,7 +1811,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, bool hdr_has_name; bool name_needs_unq; - buf [mf->line_start + line_len] = 0; /* Zero-terminate the header line */ + buf[mf->line_start + line_len] = 0; /* Zero-terminate the header line */ hdr_val_start = mf->line_start + hdr.len; /* Skip all whitespace chars */ while ((' ' == buf[hdr_val_start]) || ('\t' == buf[hdr_val_start])) @@ -1849,7 +1849,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, mf->st = mhd_POST_MPART_ST_FORMAT_ERROR; continue; } - mf->f.name_idx = (size_t) (name_buf.data - buf); + mf->f.name_idx = (size_t)(name_buf.data - buf); mf->f.name_len = name_buf.size; hdr_has_name = true; @@ -1880,8 +1880,8 @@ parse_post_mpart (struct MHD_Connection *restrict c, mf->st = mhd_POST_MPART_ST_FORMAT_ERROR; continue; } - mf->f.filename_idx = (size_t) (fname_buf.data - buf); - if (! fname_needs_unq) + mf->f.filename_idx = (size_t)(fname_buf.data - buf); + if (!fname_needs_unq) mf->f.filename_len = fname_buf.size; else { @@ -1996,16 +1996,16 @@ parse_post_mpart (struct MHD_Connection *restrict c, if (mf->delim.size <= *pdata_size - i) { const char *delim_ptr; - if (! bare_lf_as_crlf) - delim_ptr = (const char *) memmem (buf + i, - *pdata_size - i, - mf->delim.data, - mf->delim.size); + if (!bare_lf_as_crlf) + delim_ptr = (const char *)memmem (buf + i, + *pdata_size - i, + mf->delim.data, + mf->delim.size); else - delim_ptr = (const char *) memmem (buf + i, - *pdata_size - i, - mf->delim.data + 1, - mf->delim.size - 1); + delim_ptr = (const char *)memmem (buf + i, + *pdata_size - i, + mf->delim.data + 1, + mf->delim.size - 1); if (NULL != delim_ptr) { size_t delim_pos; @@ -2013,11 +2013,11 @@ parse_post_mpart (struct MHD_Connection *restrict c, mhd_assert (delim_ptr >= buf + i); mhd_assert (delim_ptr + mf->delim.size - 1 <= buf + *pdata_size); - delim_pos = (size_t) (delim_ptr - buf); + delim_pos = (size_t)(delim_ptr - buf); mhd_assert (i <= delim_pos); - if (! bare_lf_as_crlf) + if (!bare_lf_as_crlf) { mf->line_start = delim_pos + 2; i = delim_pos + mf->delim.size; @@ -2026,8 +2026,8 @@ parse_post_mpart (struct MHD_Connection *restrict c, { mf->line_start = delim_pos + 1; i = delim_pos + mf->delim.size - 1; - if ((delim_pos > 0) && - ('\r' == buf[delim_pos - 1])) + if ((delim_pos > 0) + && ('\r' == buf[delim_pos - 1])) --delim_pos; } mf->delim_check_start = delim_pos; @@ -2035,7 +2035,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, continue; } i = *pdata_size - mf->delim.size + 1u; /* '+ 1u' to move to then next position */ - if (! bare_lf_as_crlf) + if (!bare_lf_as_crlf) i += 1u; } #endif /* HAVE_MEMMEM */ @@ -2045,7 +2045,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, const char *lf_ptr; size_t lf_pos; - lf_ptr = (const char *) memchr (buf + i, '\n', *pdata_size - i); + lf_ptr = (const char *)memchr (buf + i, '\n', *pdata_size - i); if (NULL == lf_ptr) { if ('\r' == buf[*pdata_size - 1]) @@ -2053,11 +2053,11 @@ parse_post_mpart (struct MHD_Connection *restrict c, i = *pdata_size; break; } - lf_pos = (size_t) (lf_ptr - buf); + lf_pos = (size_t)(lf_ptr - buf); mhd_assert (i <= lf_pos); mhd_assert (*pdata_size > i); - if ((i < lf_pos) && - ('\r' == buf[lf_pos - 1])) + if ((i < lf_pos) + && ('\r' == buf[lf_pos - 1])) { mf->delim_check_start = lf_pos - 1; mf->st = mhd_POST_MPART_ST_VALUE_LINE_START; @@ -2080,7 +2080,7 @@ parse_post_mpart (struct MHD_Connection *restrict c, ++i; break; } - else if (bare_lf_as_crlf && '\n' == buf[i]) + else if (bare_lf_as_crlf && ('\n' == buf[i])) { mf->delim_check_start = i; mf->st = mhd_POST_MPART_ST_VALUE_LINE_START; @@ -2089,9 +2089,9 @@ parse_post_mpart (struct MHD_Connection *restrict c, } #endif /* MHD_FAVOR_SMALL_CODE */ } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_MPART_ST_VALUE_CR_FOUND == mf->st) || \ - (mhd_POST_MPART_ST_VALUE_LINE_START == mf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_MPART_ST_VALUE_CR_FOUND == mf->st) \ + || (mhd_POST_MPART_ST_VALUE_LINE_START == mf->st)); continue; case mhd_POST_MPART_ST_VALUE_CR_FOUND: if ('\n' != buf[i]) @@ -2150,9 +2150,9 @@ parse_post_mpart (struct MHD_Connection *restrict c, else mf->st = mhd_POST_MPART_ST_BACK_TO_VALUE; } - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_MPART_ST_DELIM_FOUND == mf->st) || \ - (mhd_POST_MPART_ST_BACK_TO_VALUE == mf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_MPART_ST_DELIM_FOUND == mf->st) \ + || (mhd_POST_MPART_ST_BACK_TO_VALUE == mf->st)); continue; case mhd_POST_MPART_ST_DELIM_FOUND: mhd_assert (mhd_POST_INVALID_POS != mf->delim_check_start); @@ -2163,31 +2163,31 @@ parse_post_mpart (struct MHD_Connection *restrict c, { if ('\n' == buf[i]) { - if (bare_lf_as_crlf || - ('\r' == buf [i - 1])) + if (bare_lf_as_crlf + || ('\r' == buf[i - 1])) mf->st = mhd_POST_MPART_ST_VALUE_END_FOUND; else mf->st = mhd_POST_MPART_ST_FORMAT_ERROR; break; } - else if ('\r' == buf [i - 1]) + else if ('\r' == buf[i - 1]) { mf->st = mhd_POST_MPART_ST_FORMAT_ERROR; break; } - else if ((i == mf->line_start + (mf->delim.size - 2) + 1) && - ('-' == buf [i - 1]) && - ('-' == buf [i])) + else if ((i == mf->line_start + (mf->delim.size - 2) + 1) + && ('-' == buf[i - 1]) + && ('-' == buf[i])) { mf->st = mhd_POST_MPART_ST_VALUE_END_FOUND_FINAL; break; } } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_MPART_ST_VALUE_END_FOUND == mf->st) || \ - (mhd_POST_MPART_ST_VALUE_END_FOUND_FINAL == mf->st) || \ - (mhd_POST_MPART_ST_FORMAT_ERROR == mf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_MPART_ST_VALUE_END_FOUND == mf->st) \ + || (mhd_POST_MPART_ST_VALUE_END_FOUND_FINAL == mf->st) \ + || (mhd_POST_MPART_ST_FORMAT_ERROR == mf->st)); continue; case mhd_POST_MPART_ST_VALUE_END_FOUND: case mhd_POST_MPART_ST_VALUE_END_FOUND_FINAL: @@ -2312,27 +2312,27 @@ parse_post_mpart (struct MHD_Connection *restrict c, mhd_assert (mhd_POST_MPART_ST_BACK_TO_VALUE != mf->st); mhd_assert (mhd_POST_MPART_ST_VALUE_END_FOUND != mf->st); mhd_assert (mhd_POST_MPART_ST_VALUE_END_FOUND_FINAL != mf->st); - mhd_assert ((mhd_POST_MPART_ST_VALUE != mf->st) || \ - (0 == mf->f.value_len)); + mhd_assert ((mhd_POST_MPART_ST_VALUE != mf->st) \ + || (0 == mf->f.value_len)); mhd_assert (*pdata_size == i); - if ((0 != mf->f.value_idx) && - (((mhd_POST_MPART_ST_VALUE == mf->st) && - (i != mf->f.value_idx) && - is_value_streaming_needed (c, i - p_data->field_start)) || - (((mhd_POST_MPART_ST_VALUE_CR_FOUND == mf->st) || - (mhd_POST_MPART_ST_VALUE_LINE_START == mf->st) || - (mhd_POST_MPART_ST_VALUE_CHECKING_FOR_DELIM == mf->st)) && - (i != mf->delim_check_start) && - is_value_streaming_needed (c, i - mf->delim_check_start)))) + if ((0 != mf->f.value_idx) + && (((mhd_POST_MPART_ST_VALUE == mf->st) + && (i != mf->f.value_idx) + && is_value_streaming_needed (c, i - p_data->field_start)) + || (((mhd_POST_MPART_ST_VALUE_CR_FOUND == mf->st) + || (mhd_POST_MPART_ST_VALUE_LINE_START == mf->st) + || (mhd_POST_MPART_ST_VALUE_CHECKING_FOR_DELIM == mf->st)) + && (i != mf->delim_check_start) + && is_value_streaming_needed (c, i - mf->delim_check_start)))) { bool proc_res; - mhd_assert ((mhd_POST_MPART_ST_VALUE == mf->st) || \ - (i >= mf->delim_check_start)); - mhd_assert ((mhd_POST_MPART_ST_VALUE == mf->st) || \ - (mhd_POST_INVALID_POS != mf->delim_check_start)); + mhd_assert ((mhd_POST_MPART_ST_VALUE == mf->st) \ + || (i >= mf->delim_check_start)); + mhd_assert ((mhd_POST_MPART_ST_VALUE == mf->st) \ + || (mhd_POST_INVALID_POS != mf->delim_check_start)); if (mhd_POST_MPART_ST_VALUE != mf->st) { i = mf->delim_check_start; /* Reset position */ @@ -2384,7 +2384,7 @@ parse_post_text (struct MHD_Connection *restrict c, mhd_assert (MHD_HTTP_POST_ENCODING_TEXT_PLAIN == c->rq.u_proc.post.enc); mhd_assert (MHD_POST_PARSE_RES_OK == p_data->parse_result); - mhd_assert (! c->discard_request); + mhd_assert (!c->discard_request); mhd_assert (p_data->next_parse_pos < *pdata_size); enc_broken = false; @@ -2420,8 +2420,8 @@ parse_post_text (struct MHD_Connection *restrict c, break; } } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_TEXT_ST_NAME != tf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_TEXT_ST_NAME != tf->st)); continue; case mhd_POST_TEXT_ST_AT_EQ: mhd_assert (i > tf->name_idx); @@ -2455,12 +2455,12 @@ parse_post_text (struct MHD_Connection *restrict c, break; } } while (*pdata_size > ++i); - mhd_assert ((*pdata_size == i) || \ - (mhd_POST_TEXT_ST_AT_CR == tf->st) || \ - (mhd_POST_TEXT_ST_AT_LF_BARE == tf->st)); + mhd_assert ((*pdata_size == i) \ + || (mhd_POST_TEXT_ST_AT_CR == tf->st) \ + || (mhd_POST_TEXT_ST_AT_LF_BARE == tf->st)); continue; case mhd_POST_TEXT_ST_AT_LF_BARE: - if (! bare_lf_as_crlf) + if (!bare_lf_as_crlf) { enc_broken = true; break; @@ -2562,9 +2562,9 @@ parse_post_text (struct MHD_Connection *restrict c, mhd_assert (*pdata_size == i); - if ((mhd_POST_TEXT_ST_VALUE == tf->st) && - (i != tf->value_idx) && - is_value_streaming_needed (c, i - p_data->field_start)) + if ((mhd_POST_TEXT_ST_VALUE == tf->st) + && (i != tf->value_idx) + && is_value_streaming_needed (c, i - p_data->field_start)) { if (process_partial_value (c, buf, @@ -2597,8 +2597,8 @@ mhd_stream_post_parse (struct MHD_Connection *restrict c, mhd_assert (MHD_HTTP_POST_ENCODING_OTHER != p_data->enc); mhd_assert (c->rq.cntn.lbuf.size <= p_data->lbuf_limit); - if ((MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc) && - (mhd_POST_MPART_ST_EPILOGUE == p_data->e_d.m_form.st)) + if ((MHD_HTTP_POST_ENCODING_MULTIPART_FORMDATA == p_data->enc) + && (mhd_POST_MPART_ST_EPILOGUE == p_data->e_d.m_form.st)) { /* No need to process the data */ *pdata_size = 0; /* All data has been "processed" */ @@ -2611,12 +2611,12 @@ mhd_stream_post_parse (struct MHD_Connection *restrict c, lbuf_left = c->rq.cntn.lbuf.size - p_data->lbuf_used; if (*pdata_size + 1 > lbuf_left) - (void) extend_lbuf_up_to (c, - *pdata_size + 1 - lbuf_left, - &(c->rq.cntn.lbuf)); + (void)extend_lbuf_up_to (c, + *pdata_size + 1 - lbuf_left, + &(c->rq.cntn.lbuf)); - while ((0 != *pdata_size) && - (c->rq.cntn.lbuf.size > p_data->lbuf_used)) + while ((0 != *pdata_size) + && (c->rq.cntn.lbuf.size > p_data->lbuf_used)) { size_t data_size_before_parse; size_t copy_size = *pdata_size; @@ -2718,8 +2718,8 @@ check_post_leftovers_urlenc (struct MHD_Connection *restrict c, else name_len = pos - uf->name_idx; mhd_assert (name_start + name_len <= pos); - if (! have_extra_space && - (name_start + name_len == pos)) + if (!have_extra_space + && (name_start + name_len == pos)) return report_low_lbuf_mem (c); buf[name_start + name_len] = 0; /* Zero-terminate the result, an extra byte is available */ value_start = 0; @@ -2731,7 +2731,7 @@ check_post_leftovers_urlenc (struct MHD_Connection *restrict c, name_len = uf->name_len; value_start = pos; value_len = 0; - if (! have_extra_space) + if (!have_extra_space) need_value_stream = true; else buf[value_start] = 0; /* Zero-terminate the result, an extra byte is available */ @@ -2768,8 +2768,8 @@ check_post_leftovers_urlenc (struct MHD_Connection *restrict c, else value_len = pos - uf->value_idx; } - if (! have_extra_space && - (value_start + value_len == pos)) + if (!have_extra_space + && (value_start + value_len == pos)) need_value_stream = true; else buf[value_start + value_len] = 0; /* Zero-terminate the result, an extra byte is available in the buffer */ @@ -2939,7 +2939,7 @@ check_post_leftovers_mpart (struct MHD_Connection *restrict c, if (add_field) { if (c->rq.cntn.lbuf.size > (value_pos + value_len)) - buf [value_pos + value_len] = 0; /* Zero-terminate the value */ + buf[value_pos + value_len] = 0; /* Zero-terminate the value */ else if (NULL != c->rq.app_act.head_act.data.post_parse.stream_reader) p_data->force_streamed = true; else @@ -2966,7 +2966,7 @@ check_post_leftovers_mpart (struct MHD_Connection *restrict c, } reset_parse_field_data_mpart_cont (p_data, - ! not_terminated); + !not_terminated); return false; /* Continue normal processing */ } @@ -3049,8 +3049,8 @@ check_post_leftovers_text (struct MHD_Connection *restrict c, name_len = tf->name_len; value_start = tf->value_idx; value_len = tf->value_len; - mhd_assert ((value_start + value_len + 1 == pos) || \ - (value_start + value_len + 2 == pos)); + mhd_assert ((value_start + value_len + 1 == pos) \ + || (value_start + value_len + 2 == pos)); mhd_assert (0 == buf[value_start + value_len]); ++pos; mhd_assert (pos == *pdata_size); @@ -3070,7 +3070,7 @@ check_post_leftovers_text (struct MHD_Connection *restrict c, if (0 != value_start) { if (c->rq.cntn.lbuf.size > (value_start + value_len)) - buf [value_start + value_len] = 0; /* Zero-terminate the value */ + buf[value_start + value_len] = 0; /* Zero-terminate the value */ else if (NULL != c->rq.app_act.head_act.data.post_parse.stream_reader) p_data->force_streamed = true; else @@ -3106,9 +3106,9 @@ check_post_leftovers (struct MHD_Connection *restrict c) struct mhd_PostParserData *const p_data = &(c->rq.u_proc.post); // TODO: implement processing in the connection buffer if (p_data->lbuf_used == c->rq.cntn.lbuf.size) - (void) extend_lbuf_up_to (c, - 1, - &(c->rq.cntn.lbuf)); + (void)extend_lbuf_up_to (c, + 1, + &(c->rq.cntn.lbuf)); switch (p_data->enc) { @@ -3143,8 +3143,8 @@ mhd_stream_process_post_finish (struct MHD_Connection *restrict c) const struct MHD_UploadAction *act; bool state_changed; - if ((MHD_POST_PARSE_RES_OK == p_data->parse_result) && - ! c->discard_request) + if ((MHD_POST_PARSE_RES_OK == p_data->parse_result) + && !c->discard_request) { // TODO: implement processing in the connection buffer if (check_post_leftovers (c)) @@ -3157,7 +3157,7 @@ mhd_stream_process_post_finish (struct MHD_Connection *restrict c) p_data->parse_result); state_changed = mhd_stream_process_upload_action (c, act, true); - if (! c->suspended) + if (!c->suspended) mhd_daemon_free_lbuf (c->daemon, &(c->rq.cntn.lbuf)); return state_changed; } diff --git a/src/mhd2/request_auth_get.c b/src/mhd2/request_auth_get.c @@ -117,13 +117,13 @@ mhd_request_get_auth_header_value (struct MHD_Request *restrict request, continue; if (prefix_len > f->field.nv.value.len) continue; - if (! mhd_str_equal_caseless_bin_n (hdr_name.cstr, - f->field.nv.name.cstr, - hdr_name.len)) + if (!mhd_str_equal_caseless_bin_n (hdr_name.cstr, + f->field.nv.name.cstr, + hdr_name.len)) continue; - if (! mhd_str_equal_caseless_bin_n (prefix_str, - f->field.nv.value.cstr, - prefix_len)) + if (!mhd_str_equal_caseless_bin_n (prefix_str, + f->field.nv.value.cstr, + prefix_len)) continue; /* Match only if the search token string is the full header value or the search token is followed by space */ @@ -139,8 +139,8 @@ mhd_request_get_auth_header_value (struct MHD_Request *restrict request, However, as a slight violation of the specifications, a tab character is also recognised here for additional flexibility and uniformity (tabs are supported as separators between parameters). */ - if (allow_tab_as_sep && - ('\t' == f->field.nv.value.cstr[prefix_len])) + if (allow_tab_as_sep + && ('\t' == f->field.nv.value.cstr[prefix_len])) break; } if (NULL == f) @@ -150,16 +150,16 @@ mhd_request_get_auth_header_value (struct MHD_Request *restrict request, /* Skip leading whitespaces */ for (p_start = prefix_len + 1; p_start < f->field.nv.name.len; ++p_start) { - if ((' ' != f->field.nv.value.cstr[p_start]) && - ('\t' != f->field.nv.value.cstr[p_start])) + if ((' ' != f->field.nv.value.cstr[p_start]) + && ('\t' != f->field.nv.value.cstr[p_start])) break; } header_value->cstr = f->field.nv.value.cstr + p_start; header_value->len = f->field.nv.value.len - p_start; mhd_assert (0 == header_value->cstr[header_value->len]); - mhd_assert ((0 != header_value->len) && \ - "Trailing header whitespaces must be already stripped"); + mhd_assert ((0 != header_value->len) \ + && "Trailing header whitespaces must be already stripped"); return true; /* Success exit point */ } diff --git a/src/mhd2/request_auth_get.h b/src/mhd2/request_auth_get.h @@ -47,8 +47,8 @@ #include "mhd_sys_options.h" -#if ! defined(MHD_SUPPORT_AUTH_BASIC) && ! defined(MHD_SUPPORT_AUTH_DIGEST) -#error Authorization header parsing must be enabled +#if !defined(MHD_SUPPORT_AUTH_BASIC) && !defined(MHD_SUPPORT_AUTH_DIGEST) +# error Authorization header parsing must be enabled #endif #include "sys_bool_type.h" diff --git a/src/mhd2/request_funcs.c b/src/mhd2/request_funcs.c @@ -75,7 +75,7 @@ mhd_stream_add_field_nullable (struct MHD_Stream *restrict s, f->field.kind = kind; mhd_DLINKEDL_INIT_LINKS (f, fields); - mhd_DLINKEDL_INS_LAST (&(c->rq),f,fields); + mhd_DLINKEDL_INS_LAST (&(c->rq), f, fields); return true; } diff --git a/src/mhd2/request_get_info.c b/src/mhd2/request_get_info.c @@ -93,7 +93,7 @@ MHD_request_get_info_fixed_sz ( return MHD_SC_TOO_EARLY; if (sizeof(output_buf->v_http_method) > output_buf_size) return MHD_SC_INFO_GET_BUFF_TOO_SMALL; - output_buf->v_http_method = (enum MHD_HTTP_Method) request->http_mthd; + output_buf->v_http_method = (enum MHD_HTTP_Method)request->http_mthd; return MHD_SC_OK; case MHD_REQUEST_INFO_FIXED_DAEMON: if (sizeof(output_buf->v_daemon) > output_buf_size) @@ -189,7 +189,7 @@ MHD_request_get_info_dynamic_sz ( output_buf->v_number_uri_params_sizet = MHD_request_get_values_cb (request, MHD_VK_URI_QUERY_PARAM, - (MHD_NameValueIterator) NULL, + (MHD_NameValueIterator)NULL, NULL); return MHD_SC_OK; case MHD_REQUEST_INFO_DYNAMIC_NUMBER_COOKIES: @@ -213,7 +213,7 @@ MHD_request_get_info_dynamic_sz ( output_buf->v_number_cookies_sizet = MHD_request_get_values_cb (request, MHD_VK_COOKIE, - (MHD_NameValueIterator) NULL, + (MHD_NameValueIterator)NULL, NULL); return MHD_SC_OK; #else @@ -252,7 +252,7 @@ MHD_request_get_info_dynamic_sz ( output_buf->v_number_post_params_sizet = MHD_request_get_values_cb (request, MHD_VK_POSTDATA, - (MHD_NameValueIterator) NULL, + (MHD_NameValueIterator)NULL, NULL); return MHD_SC_OK; #else diff --git a/src/mhd2/request_get_value.c b/src/mhd2/request_get_value.c @@ -64,7 +64,7 @@ MHD_INTERNAL -MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4,3) +MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4, 3) MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_CSTR_ (4) MHD_FN_PAR_OUT_ (5) bool mhd_request_get_value_n (struct MHD_Request *restrict request, @@ -95,11 +95,11 @@ mhd_request_get_value_n (struct MHD_Request *restrict request, for (f = mhd_DLINKEDL_GET_FIRST (request, fields); NULL != f; f = mhd_DLINKEDL_GET_NEXT (f, fields)) { - if ((key_len == f->field.nv.name.len) && - (0 != (kind & f->field.kind)) && - mhd_str_equal_caseless_bin_n (key, - f->field.nv.name.cstr, - key_len)) + if ((key_len == f->field.nv.name.len) + && (0 != (kind & f->field.kind)) + && mhd_str_equal_caseless_bin_n (key, + f->field.nv.name.cstr, + key_len)) { *value_out = f->field.nv.value; return true; @@ -115,18 +115,18 @@ mhd_request_get_value_n (struct MHD_Request *restrict request, for (f = mhd_DLINKEDL_GET_FIRST (request, post_fields); NULL != f; f = mhd_DLINKEDL_GET_NEXT (f, post_fields)) { - if ((key_len == f->field.name.len) && - mhd_str_equal_caseless_bin_n (key, - buf + f->field.name.pos, - key_len)) + if ((key_len == f->field.name.len) + && mhd_str_equal_caseless_bin_n (key, + buf + f->field.name.pos, + key_len)) { value_out->cstr = (0 == f->field.value.pos) ? NULL : (buf + f->field.value.pos); value_out->len = f->field.value.len; - mhd_assert ((NULL != value_out->cstr) || \ - (0 == value_out->len)); + mhd_assert ((NULL != value_out->cstr) \ + || (0 == value_out->len)); return true; } @@ -174,14 +174,14 @@ mhd_stream_has_header_token (const struct MHD_Connection *restrict c, NULL != f; f = mhd_DLINKEDL_GET_NEXT (f, fields)) { - if ((MHD_VK_HEADER == f->field.kind) && - (header_len == f->field.nv.name.len) && - (mhd_str_equal_caseless_bin_n (header, - f->field.nv.name.cstr, - header_len)) && - (mhd_str_has_token_caseless (f->field.nv.value.cstr, - token, - token_len))) + if ((MHD_VK_HEADER == f->field.kind) + && (header_len == f->field.nv.name.len) + && (mhd_str_equal_caseless_bin_n (header, + f->field.nv.name.cstr, + header_len)) + && (mhd_str_has_token_caseless (f->field.nv.value.cstr, + token, + token_len))) return true; } @@ -198,7 +198,7 @@ MHD_request_get_values_cb (struct MHD_Request *request, { size_t count; - #ifdef MHD_SUPPORT_HTTP2 +#ifdef MHD_SUPPORT_HTTP2 if (mhd_REQ_IS_HTTP2 (request)) return mhd_h2_request_get_values_cb (request, kind, @@ -311,10 +311,10 @@ MHD_request_get_post_data_cb (struct MHD_Request *request, mhd_assert ((NULL != field.value.cstr) || (0 == field.value.len)); mhd_assert ((NULL != field.filename.cstr) || (0 == field.filename.len)); - mhd_assert ((NULL != field.content_type.cstr) || \ - (0 == field.content_type.len)); - mhd_assert ((NULL != field.transfer_encoding.cstr) || \ - (0 == field.transfer_encoding.len)); + mhd_assert ((NULL != field.content_type.cstr) \ + || (0 == field.content_type.len)); + mhd_assert ((NULL != field.transfer_encoding.cstr) \ + || (0 == field.transfer_encoding.len)); if (MHD_NO == iterator (iterator_cls, diff --git a/src/mhd2/request_get_value.h b/src/mhd2/request_get_value.h @@ -43,14 +43,14 @@ */ #ifndef MHD_REQUEST_GET_VALUE_H -#define MHD_REQUEST_GET_VALUE_H 1 +# define MHD_REQUEST_GET_VALUE_H 1 -#include "mhd_sys_options.h" -#include "sys_base_types.h" -#include "sys_bool_type.h" -#include "mhd_str_macros.h" +# include "mhd_sys_options.h" +# include "sys_base_types.h" +# include "sys_bool_type.h" +# include "mhd_str_macros.h" -#include "mhd_public_api.h" +# include "mhd_public_api.h" /** * Get specified field value from request @@ -79,7 +79,7 @@ mhd_request_get_value_n (struct MHD_Request *restrict request, size_t key_len, const char *restrict key, struct MHD_StringNullable *restrict value_out) -MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4,3) +MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4, 3) MHD_FN_PAR_NONNULL_ (4) MHD_FN_PAR_CSTR_ (4) MHD_FN_PAR_OUT_ (5); @@ -97,8 +97,8 @@ MHD_FN_PAR_OUT_ (5); * @return NULL if no such item was found * @ingroup request */ -#define mhd_request_get_value_st(r,k,str,v_out) \ - mhd_request_get_value_n ((r),(k),mhd_SSTR_LEN (str),(str),(v_out)) +# define mhd_request_get_value_st(r, k, str, v_out) \ + mhd_request_get_value_n ((r),(k),mhd_SSTR_LEN (str),(str),(v_out)) #endif /* ! MHD_REQUEST_GET_VALUE_H */ @@ -137,6 +137,6 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (5); * @return true if the token is found in the specified header, * false otherwise */ -#define mhd_stream_has_header_token_st(c,hdr,tkn) \ +#define mhd_stream_has_header_token_st(c, hdr, tkn) \ mhd_stream_has_header_token ((c), mhd_SSTR_LEN (hdr), (hdr), \ mhd_SSTR_LEN (tkn), (tkn)) diff --git a/src/mhd2/request_resume.c b/src/mhd2/request_resume.c @@ -65,13 +65,13 @@ MHD_request_resume (struct MHD_Request *request) rq); struct MHD_Daemon *d = c->daemon; - if (! c->suspended) + if (!c->suspended) { #ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Requested conn resume, FD: %2llu -> " "failed as not suspended\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_SUSPEND_RESUME */ return; } @@ -79,8 +79,8 @@ MHD_request_resume (struct MHD_Request *request) #ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Requested conn resume, FD: %2llu\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_SUSPEND_RESUME */ d->events.act_req.resume = true; - (void) mhd_daemon_trigger_itc (d); + (void)mhd_daemon_trigger_itc (d); } diff --git a/src/mhd2/respond_with_error.c b/src/mhd2/respond_with_error.c @@ -77,7 +77,7 @@ respond_with_error_len (struct MHD_Connection *c, { struct MHD_Response *err_res; - mhd_assert (! c->stop_with_error); /* Do not send error twice */ + mhd_assert (!c->stop_with_error); /* Do not send error twice */ mhd_assert (mhd_HTTP_STAGE_REQ_RECV_FINISHED >= c->stage); /* Discard most of the request data */ @@ -109,16 +109,16 @@ respond_with_error_len (struct MHD_Connection *c, c->stop_with_error = true; c->discard_request = true; - if ((MHD_HTTP_STATUS_CONTENT_TOO_LARGE == http_code) || - (MHD_HTTP_STATUS_URI_TOO_LONG == http_code) || - (MHD_HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE == http_code)) + if ((MHD_HTTP_STATUS_CONTENT_TOO_LARGE == http_code) + || (MHD_HTTP_STATUS_URI_TOO_LONG == http_code) + || (MHD_HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE == http_code)) c->rq.too_large = true; mhd_LOG_PRINT (c->daemon, MHD_SC_REQ_PROCCESSING_ERR_REPLY, mhd_LOG_FMT ("Error processing request. Sending %u " \ "error reply: %s"), - (unsigned int) http_code, + (unsigned int)http_code, (NULL != msg) ? msg : "[EMPTY BODY]"); if (NULL != c->rp.response) diff --git a/src/mhd2/respond_with_error.h b/src/mhd2/respond_with_error.h @@ -80,34 +80,34 @@ MHD_FN_PAR_CSTR_ (4) MHD_FN_PAR_CSTR_ (6); * Transmit static string as error response */ # define mhd_RESPOND_WITH_ERROR_STATIC(c, code, msg) \ - respond_with_error_len ((c), (code), \ - mhd_SSTR_LEN (msg), (msg), \ - 0, NULL) + respond_with_error_len ((c), (code), \ + mhd_SSTR_LEN (msg), (msg), \ + 0, NULL) /** * Transmit static string as error response and add specified header */ -# define mhd_RESPOND_WITH_ERROR_HEADER(c,code,m,hdrl_l,hdrl) \ - respond_with_error_len ((c), (code), \ - mhd_SSTR_LEN (m), (m), \ - (hdrl_l), (hdrl)) +# define mhd_RESPOND_WITH_ERROR_HEADER(c, code, m, hdrl_l, hdrl) \ + respond_with_error_len ((c), (code), \ + mhd_SSTR_LEN (m), (m), \ + (hdrl_l), (hdrl)) #else /** * Transmit static string as error response */ # define mhd_RESPOND_WITH_ERROR_STATIC(c, code, msg) \ - respond_with_error_len ((c), (code), \ - 0, NULL, \ - 0, NULL) + respond_with_error_len ((c), (code), \ + 0, NULL, \ + 0, NULL) /** * Transmit static string as error response and add specified header */ -# define mhd_RESPOND_WITH_ERROR_HEADER(c,code,m,hdrl_l,hdrl) \ - respond_with_error_len ((c), (code), \ - 0, NULL, \ - (hdrl_l), (hdrl)) +# define mhd_RESPOND_WITH_ERROR_HEADER(c, code, m, hdrl_l, hdrl) \ + respond_with_error_len ((c), (code), \ + 0, NULL, \ + (hdrl_l), (hdrl)) #endif #endif /* ! MHD_RESPOND_WITH_ERROR_H */ diff --git a/src/mhd2/response_add_header.c b/src/mhd2/response_add_header.c @@ -61,7 +61,7 @@ #ifdef MHD_SUPPORT_HTTP2 static MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_IN_SIZE_ (2,1) bool +MHD_FN_PAR_CSTR_ (2) MHD_FN_PAR_IN_SIZE_ (2, 1) bool is_name_h2_allowed (size_t name_len, const char name[MHD_FN_PAR_DYN_ARR_SIZE_ (name_len)]) { @@ -152,7 +152,7 @@ response_add_header_no_check ( if (NULL == new_hdr) return false; - buf = ((char *) new_hdr) + sizeof(struct mhd_ResponseHeader); + buf = ((char *)new_hdr) + sizeof(struct mhd_ResponseHeader); pos = 0u; memcpy (buf + pos, name, name_len + 1u); new_hdr->name.cstr = buf + pos; @@ -166,7 +166,7 @@ response_add_header_no_check ( #ifdef MHD_SUPPORT_HTTP2 if (h2_allowed) { - if (! name_is_lower) + if (!name_is_lower) { mhd_str_to_lowercase_bin_n (name_len + 1u, name, @@ -209,14 +209,14 @@ response_add_header_no_check ( || (0u == new_hdr->h2.name.size)); mhd_assert ((NULL != new_hdr->h2.value.data) || (0u == new_hdr->h2.value.size)); - mhd_assert ((NULL != new_hdr->h2.name.data) || \ - (NULL == new_hdr->h2.value.data)); - mhd_assert ((NULL != new_hdr->h2.value.data) || \ - (NULL == new_hdr->h2.name.data)); + mhd_assert ((NULL != new_hdr->h2.name.data) \ + || (NULL == new_hdr->h2.value.data)); + mhd_assert ((NULL != new_hdr->h2.value.data) \ + || (NULL == new_hdr->h2.name.data)); #endif /* MHD_SUPPORT_HTTP2 */ mhd_assert (strings_size == pos); - (void) pos; /* Mute compiler warning in non-debug builds */ + (void)pos; /* Mute compiler warning in non-debug builds */ mhd_DLINKEDL_INIT_LINKS (new_hdr, headers); mhd_DLINKEDL_INS_LAST (response, new_hdr, headers); @@ -250,14 +250,14 @@ response_add_header_int (struct MHD_Response *restrict response, if (response->frozen) /* Re-check with the lock held */ return MHD_SC_TOO_LATE; - if ((NULL != memchr (name, ' ', name_len)) || - (NULL != memchr (name, '\t', name_len)) || - (NULL != memchr (name, ':', name_len)) || - (NULL != memchr (name, '\n', name_len)) || - (NULL != memchr (name, '\r', name_len))) + if ((NULL != memchr (name, ' ', name_len)) + || (NULL != memchr (name, '\t', name_len)) + || (NULL != memchr (name, ':', name_len)) + || (NULL != memchr (name, '\n', name_len)) + || (NULL != memchr (name, '\r', name_len))) return MHD_SC_RESP_HEADER_NAME_INVALID; - if ((NULL != memchr (value, '\n', value_len)) || - (NULL != memchr (value, '\r', value_len))) + if ((NULL != memchr (value, '\n', value_len)) + || (NULL != memchr (value, '\r', value_len))) return MHD_SC_RESP_HEADER_VALUE_INVALID; if (mhd_str_equal_caseless_n_st (MHD_HTTP_HEADER_DATE, @@ -267,8 +267,8 @@ response_add_header_int (struct MHD_Response *restrict response, if (response->cfg.has_hdr_date) return MHD_SC_RESP_HEADER_DATE_DUPLICATE; - if (! response_add_header_no_check (response, name_len, name, - value_len, value)) + if (!response_add_header_no_check (response, name_len, name, + value_len, value)) return MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED; response->cfg.has_hdr_date = true; @@ -283,8 +283,8 @@ response_add_header_int (struct MHD_Response *restrict response, if (response->cfg.has_hdr_conn) return MHD_SC_RESP_HEADER_CONNECTION_DUPLICATE; - if (! response_add_header_no_check (response, name_len, name, - value_len, value)) + if (!response_add_header_no_check (response, name_len, name, + value_len, value)) return MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED; response->cfg.has_hdr_conn = true; @@ -294,8 +294,8 @@ response_add_header_int (struct MHD_Response *restrict response, // TODO: add special processing for "Content-Length", "Transfer-Encoding" - if (! response_add_header_no_check (response, name_len, name, - value_len, value)) + if (!response_add_header_no_check (response, name_len, name, + value_len, value)) return MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED; return MHD_SC_OK; @@ -320,7 +320,7 @@ MHD_response_add_header (struct MHD_Response *MHD_RESTRICT response, if (response->reuse.reusable) { need_unlock = true; - if (! mhd_mutex_lock (&(response->reuse.settings_lock))) + if (!mhd_mutex_lock (&(response->reuse.settings_lock))) return MHD_SC_RESP_MUTEX_LOCK_FAILED; mhd_assert (1 == mhd_atomic_counter_get (&(response->reuse.counter))); } @@ -343,6 +343,8 @@ MHD_response_add_predef_header (struct MHD_Response *MHD_RESTRICT response, enum MHD_PredefinedHeader stk, const char *MHD_RESTRICT content) { - (void) response; (void) stk; (void) content; + (void)response; + (void)stk; + (void)content; return MHD_SC_FEATURE_DISABLED; } diff --git a/src/mhd2/response_auth_basic.c b/src/mhd2/response_auth_basic.c @@ -77,8 +77,8 @@ response_add_auth_basic_challenge_int (struct MHD_Response *restrict response, size_t pos; struct mhd_ResponseHeader *new_hdr; - if ((NULL != memchr (realm, '\n', realm_len)) || - (NULL != memchr (realm, '\r', realm_len))) + if ((NULL != memchr (realm, '\n', realm_len)) + || (NULL != memchr (realm, '\r', realm_len))) return MHD_SC_RESP_HEADER_VALUE_INVALID; if (0 == realm_len) return MHD_SC_RESP_HEADER_VALUE_INVALID; @@ -96,12 +96,12 @@ response_add_auth_basic_challenge_int (struct MHD_Response *restrict response, return MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED; /* Set the name of the header */ - memcpy ((char *) (new_hdr + 1), + memcpy ((char *)(new_hdr + 1), hdr_name.cstr, hdr_name.len + 1); /* Set the value of the header */ - val_str = ((char *) (new_hdr + 1)) + hdr_name.len + 1; + val_str = ((char *)(new_hdr + 1)) + hdr_name.len + 1; memcpy (val_str, prefix.cstr, prefix.len); pos = prefix.len; realm_quoted_len = mhd_str_quote (realm, @@ -130,16 +130,16 @@ response_add_auth_basic_challenge_int (struct MHD_Response *restrict response, + hdr_name.len + 1 + pos + 1); /* Just use the old pointer if realloc() failed */ if (NULL != new_ptr) - new_hdr = (struct mhd_ResponseHeader *) new_ptr; + new_hdr = (struct mhd_ResponseHeader *)new_ptr; } - new_hdr->name.cstr = (char *) (new_hdr + 1); + new_hdr->name.cstr = (char *)(new_hdr + 1); new_hdr->name.len = hdr_name.len; mhd_assert (0 == memcmp (hdr_name.cstr, \ new_hdr->name.cstr, \ new_hdr->name.len + 1)); - new_hdr->value.cstr = ((char *) (new_hdr + 1)) + hdr_name.len + 1; + new_hdr->value.cstr = ((char *)(new_hdr + 1)) + hdr_name.len + 1; new_hdr->value.len = pos; mhd_assert (0 == memcmp (prefix.cstr, \ new_hdr->value.cstr, \ @@ -176,7 +176,7 @@ MHD_response_add_auth_basic_challenge ( if (response->reuse.reusable) { need_unlock = true; - if (! mhd_mutex_lock (&(response->reuse.settings_lock))) + if (!mhd_mutex_lock (&(response->reuse.settings_lock))) return MHD_SC_RESP_MUTEX_LOCK_FAILED; mhd_assert (1 == mhd_atomic_counter_get (&(response->reuse.counter))); } diff --git a/src/mhd2/response_auth_digest.c b/src/mhd2/response_auth_digest.c @@ -68,7 +68,7 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ (1) void -mhd_response_remove_auth_digest_headers (struct MHD_Response*response) +mhd_response_remove_auth_digest_headers (struct MHD_Response *response) { struct mhd_RespAuthDigestHeader *hdr_d; @@ -233,7 +233,7 @@ response_add_auth_digest_challenge_alg ( + hdr_maxlen + 1); if (NULL == new_hdr) return MHD_SC_RESP_HEADER_MEM_ALLOC_FAILED; - hdr_str = (char *) (new_hdr + 1); + hdr_str = (char *)(new_hdr + 1); /* ** Build the header ** */ pos = 0; @@ -252,7 +252,7 @@ response_add_auth_digest_challenge_alg ( hdr_str[pos++] = '"'; /* qop */ - if (! qop_none) + if (!qop_none) { memcpy (hdr_str + pos, qop_str.cstr, @@ -316,8 +316,8 @@ response_add_auth_digest_challenge_alg ( } /* charset */ - if ((! qop_none) && - (MHD_NO != prefer_utf8)) + if ((!qop_none) + && (MHD_NO != prefer_utf8)) { memcpy (hdr_str + pos, charset_str.cstr, @@ -326,8 +326,8 @@ response_add_auth_digest_challenge_alg ( } /* userhash */ - if ((! qop_none) && - (MHD_NO != userhash_support)) + if ((!qop_none) + && (MHD_NO != userhash_support)) { memcpy (hdr_str + pos, userhash_str.cstr, @@ -350,10 +350,10 @@ response_add_auth_digest_challenge_alg ( + pos + 1); /* Just use the old pointer if realloc() failed */ if (NULL != new_ptr) - new_hdr = (struct mhd_RespAuthDigestHeader *) new_ptr; + new_hdr = (struct mhd_RespAuthDigestHeader *)new_ptr; } - new_hdr->hdr.cstr = (char *) (new_hdr + 1); + new_hdr->hdr.cstr = (char *)(new_hdr + 1); new_hdr->hdr.len = pos; mhd_assert (0 == \ memcmp (new_hdr->hdr.cstr, \ @@ -401,7 +401,7 @@ response_add_auth_digest_challenge_int (struct MHD_Response *restrict response, struct MHD_StringNullable opq = {0, NULL }; struct MHD_StringNullable dmn = {0, NULL}; const bool qop_none = - (0 != (MHD_DIGEST_AUTH_QOP_NONE & ((unsigned int) mqop))); + (0 != (MHD_DIGEST_AUTH_QOP_NONE & ((unsigned int)mqop))); enum MHD_StatusCode res; rlm.len = strlen (realm); @@ -421,33 +421,33 @@ response_add_auth_digest_challenge_int (struct MHD_Response *restrict response, if (0 == rlm.len) return MHD_SC_RESP_HEADER_VALUE_INVALID; /* Failure exit point */ - if ((NULL != memchr (rlm.cstr, '\n', rlm.len)) || - (NULL != memchr (rlm.cstr, '\r', rlm.len))) + if ((NULL != memchr (rlm.cstr, '\n', rlm.len)) + || (NULL != memchr (rlm.cstr, '\r', rlm.len))) return MHD_SC_RESP_HEADER_VALUE_INVALID; /* Failure exit point */ - if ((0 != opq.len) && - ((NULL != memchr (opq.cstr, '\n', opq.len)) || - (NULL != memchr (opq.cstr, '\r', opq.len)))) + if ((0 != opq.len) + && ((NULL != memchr (opq.cstr, '\n', opq.len)) + || (NULL != memchr (opq.cstr, '\r', opq.len)))) return MHD_SC_RESP_HEADER_VALUE_INVALID; /* Failure exit point */ - if ((0 != dmn.len) && - ((NULL != memchr (dmn.cstr, '\n', dmn.len)) || - (NULL != memchr (dmn.cstr, '\r', dmn.len)) || - (NULL != memchr (dmn.cstr, '"', dmn.len)))) + if ((0 != dmn.len) + && ((NULL != memchr (dmn.cstr, '\n', dmn.len)) + || (NULL != memchr (dmn.cstr, '\r', dmn.len)) + || (NULL != memchr (dmn.cstr, '"', dmn.len)))) return MHD_SC_RESP_HEADER_VALUE_INVALID; /* Failure exit point */ - if (0 == (MHD_DIGEST_AUTH_ALGO_NON_SESSION & ((unsigned int) malgo))) + if (0 == (MHD_DIGEST_AUTH_ALGO_NON_SESSION & ((unsigned int)malgo))) return MHD_SC_AUTH_DIGEST_ALGO_NOT_SUPPORTED; /* Failure exit point */ if (0 == ((MHD_DIGEST_AUTH_QOP_NONE | MHD_DIGEST_AUTH_QOP_AUTH) - & ((unsigned int) mqop))) + & ((unsigned int)mqop))) return MHD_SC_AUTH_DIGEST_QOP_NOT_SUPPORTED; /* Failure exit point */ res = MHD_SC_OK; #ifdef MHD_SUPPORT_MD5 - if ((MHD_SC_OK == res) && - (0 != (MHD_DIGEST_BASE_ALGO_MD5 & ((unsigned int) malgo)))) + if ((MHD_SC_OK == res) + && (0 != (MHD_DIGEST_BASE_ALGO_MD5 & ((unsigned int)malgo)))) res = response_add_auth_digest_challenge_alg (response, &rlm, &opq, @@ -459,8 +459,8 @@ response_add_auth_digest_challenge_int (struct MHD_Response *restrict response, prefer_utf8); #endif #ifdef MHD_SUPPORT_SHA256 - if ((MHD_SC_OK == res) && - (0 != (MHD_DIGEST_BASE_ALGO_SHA256 & ((unsigned int) malgo)))) + if ((MHD_SC_OK == res) + && (0 != (MHD_DIGEST_BASE_ALGO_SHA256 & ((unsigned int)malgo)))) res = response_add_auth_digest_challenge_alg (response, &rlm, &opq, @@ -472,8 +472,8 @@ response_add_auth_digest_challenge_int (struct MHD_Response *restrict response, prefer_utf8); #endif #ifdef MHD_SUPPORT_SHA512_256 - if ((MHD_SC_OK == res) && - (0 != (MHD_DIGEST_BASE_ALGO_SHA512_256 & ((unsigned int) malgo)))) + if ((MHD_SC_OK == res) + && (0 != (MHD_DIGEST_BASE_ALGO_SHA512_256 & ((unsigned int)malgo)))) res = response_add_auth_digest_challenge_alg ( response, &rlm, @@ -526,7 +526,7 @@ MHD_response_add_auth_digest_challenge ( if (response->reuse.reusable) { need_unlock = true; - if (! mhd_mutex_lock (&(response->reuse.settings_lock))) + if (!mhd_mutex_lock (&(response->reuse.settings_lock))) return MHD_SC_RESP_MUTEX_LOCK_FAILED; mhd_assert (1 == mhd_atomic_counter_get (&(response->reuse.counter))); } diff --git a/src/mhd2/response_auth_digest.h b/src/mhd2/response_auth_digest.h @@ -54,7 +54,7 @@ struct MHD_Response; /* forward declaration */ * @param response the response to clean */ MHD_INTERNAL void -mhd_response_remove_auth_digest_headers (struct MHD_Response*response) +mhd_response_remove_auth_digest_headers (struct MHD_Response *response) MHD_FN_PAR_NONNULL_ (1); #endif /* ! MHD_RESPONSE_AUTH_DIGEST_H */ diff --git a/src/mhd2/response_destroy.c b/src/mhd2/response_destroy.c @@ -113,7 +113,7 @@ mhd_response_inc_use_count (struct MHD_Response *restrict r) if (r->was_destroyed) MHD_PANIC (mhd_RESPONSE_DESTOYED); - if (! r->reuse.reusable) + if (!r->reuse.reusable) return; mhd_atomic_counter_inc (&(r->reuse.counter)); @@ -127,7 +127,7 @@ MHD_response_destroy (struct MHD_Response *response) if (response->was_destroyed) MHD_PANIC (mhd_RESPONSE_DESTOYED); - if (! response->frozen) + if (!response->frozen) { /* This response has been never used for actions */ mhd_assert (NULL != response->settings); diff --git a/src/mhd2/response_from.c b/src/mhd2/response_from.c @@ -90,9 +90,9 @@ response_create_basic (enum MHD_HTTP_StatusCode sc, { #ifndef HAVE_NULL_PTR_ALL_ZEROS mhd_DLINKEDL_INIT_LIST (r, headers); -#ifdef MHD_SUPPORT_AUTH_DIGEST +# ifdef MHD_SUPPORT_AUTH_DIGEST mhd_DLINKEDL_INIT_LIST (r, auth_d_hdrs); -#endif +# endif r->free.cb = NULL; r->free.cls = NULL; r->special_resp.spec_hdr = NULL; @@ -153,7 +153,7 @@ MHD_response_from_callback (enum MHD_HTTP_StatusCode sc, static const unsigned char empty_buf[1] = { 0 }; MHD_EXTERN_ -MHD_FN_PAR_IN_SIZE_ (3,2) struct MHD_Response * +MHD_FN_PAR_IN_SIZE_ (3, 2) struct MHD_Response * MHD_response_from_buffer ( enum MHD_HTTP_StatusCode sc, size_t buffer_size, @@ -173,7 +173,7 @@ MHD_response_from_buffer ( { res->cntn_dtype = mhd_RESPONSE_CONTENT_DATA_BUFFER; res->cntn.buf = (0 != buffer_size) ? - (const unsigned char *) buffer : empty_buf; + (const unsigned char *)buffer : empty_buf; } return res; } @@ -187,7 +187,7 @@ response_cntn_free_buf (void *ptr) MHD_EXTERN_ -MHD_FN_PAR_IN_SIZE_ (3,2) struct MHD_Response * +MHD_FN_PAR_IN_SIZE_ (3, 2) struct MHD_Response * MHD_response_from_buffer_copy ( enum MHD_HTTP_StatusCode sc, size_t buffer_size, @@ -204,7 +204,7 @@ MHD_response_from_buffer_copy ( if (0 != buffer_size) { - new_buf = (unsigned char *) malloc (buffer_size); + new_buf = (unsigned char *)malloc (buffer_size); if (NULL == new_buf) return NULL; memcpy (new_buf, buffer, buffer_size); @@ -216,7 +216,7 @@ MHD_response_from_buffer_copy ( { new_buf = NULL; buf_copy = empty_buf; - res = response_create_basic (sc, 0, (MHD_FreeCallback) NULL, NULL); + res = response_create_basic (sc, 0, (MHD_FreeCallback)NULL, NULL); } if (NULL != res) @@ -254,17 +254,17 @@ MHD_response_from_iovec ( return NULL; /* NULL pointer with non-zero size */ total_size += iov[i].iov_len; - if ((total_size < iov[i].iov_len) || (0 > (ssize_t) total_size) - || (((size_t) total_size) != total_size)) + if ((total_size < iov[i].iov_len) || (0 > (ssize_t)total_size) + || (((size_t)total_size) != total_size)) return NULL; /* Larger than send function may report as success */ -#if defined(MHD_SOCKETS_KIND_POSIX) || ! defined(_WIN64) +#if defined(MHD_SOCKETS_KIND_POSIX) || !defined(_WIN64) i_cp++; #else /* ! MHD_SOCKETS_KIND_POSIX && _WIN64 */ if (1) { size_t i_add; - i_add = (size_t) (iov[i].iov_len / mhd_IOV_ELMN_MAX_SIZE); + i_add = (size_t)(iov[i].iov_len / mhd_IOV_ELMN_MAX_SIZE); if (0 != iov[i].iov_len % mhd_IOV_ELMN_MAX_SIZE) i_add++; i_cp += i_add; @@ -305,7 +305,7 @@ MHD_response_from_iovec ( for (i = 0; i < iov_count; ++i) { size_t element_size = iov[i].iov_len; - const unsigned char *buf = (const unsigned char *) iov[i].iov_base; + const unsigned char *buf = (const unsigned char *)iov[i].iov_base; if (0 == element_size) continue; /* skip zero-sized elements */ @@ -313,15 +313,15 @@ MHD_response_from_iovec ( while (mhd_IOV_ELMN_MAX_SIZE < element_size) { iov_copy[i_cp].iov_base = - (mhd_IOV_ELMN_PTR_TYPE) mhd_DROP_CONST (buf); + (mhd_IOV_ELMN_PTR_TYPE)mhd_DROP_CONST (buf); iov_copy[i_cp].iov_len = mhd_IOV_ELMN_MAX_SIZE; buf += mhd_IOV_ELMN_MAX_SIZE; element_size -= mhd_IOV_ELMN_MAX_SIZE; i_cp++; } #endif /* MHD_SOCKETS_KIND_WINSOCK && _WIN64 */ - iov_copy[i_cp].iov_base = (mhd_IOV_ELMN_PTR_TYPE) mhd_DROP_CONST (buf); - iov_copy[i_cp].iov_len = (mhd_iov_elmn_size) element_size; + iov_copy[i_cp].iov_base = (mhd_IOV_ELMN_PTR_TYPE)mhd_DROP_CONST (buf); + iov_copy[i_cp].iov_len = (mhd_iov_elmn_size)element_size; i_cp++; } mhd_assert (num_copy_elements == i_cp); @@ -358,7 +358,7 @@ MHD_response_from_fd (enum MHD_HTTP_StatusCode sc, if (size > ((size + offset) & 0xFFFFFFFFFFFFFFFFU)) return NULL; } - res = response_create_basic (sc, size, (MHD_FreeCallback) NULL, NULL); + res = response_create_basic (sc, size, (MHD_FreeCallback)NULL, NULL); if (NULL != res) { res->cntn_dtype = mhd_RESPONSE_CONTENT_DATA_FILE; @@ -381,7 +381,7 @@ MHD_response_from_pipe (enum MHD_HTTP_StatusCode sc, struct MHD_Response *restrict res; res = response_create_basic (sc, MHD_SIZE_UNKNOWN, - (MHD_FreeCallback) NULL, + (MHD_FreeCallback)NULL, NULL); if (NULL != res) { @@ -436,10 +436,10 @@ mhd_response_special_for_error (unsigned int sc, res->free.cls = NULL; res->special_resp.spec_hdr = NULL; #endif /* ! HAVE_NULL_PTR_ALL_ZEROS */ - res->sc = (enum MHD_HTTP_StatusCode) sc; + res->sc = (enum MHD_HTTP_StatusCode)sc; res->cntn_size = cntn_len; res->cntn_dtype = mhd_RESPONSE_CONTENT_DATA_BUFFER; - res->cntn.buf = (const unsigned char *) ((0 != cntn_len) ? cntn : ""); + res->cntn.buf = (const unsigned char *)((0 != cntn_len) ? cntn : ""); res->cfg.close_forced = true; res->cfg.int_err_resp = true; res->special_resp.spec_hdr_len = spec_hdr_len; diff --git a/src/mhd2/response_from.h b/src/mhd2/response_from.h @@ -75,7 +75,7 @@ mhd_response_special_for_error (unsigned int sc, const char *cntn, size_t spec_hdr_len, char *spec_hdr) -MHD_FN_PAR_CSTR_(3) MHD_FN_PAR_CSTR_(5); +MHD_FN_PAR_CSTR_ (3) MHD_FN_PAR_CSTR_ (5); #endif /* ! MHD_RESPONSE_FROM_H */ diff --git a/src/mhd2/response_funcs.c b/src/mhd2/response_funcs.c @@ -60,8 +60,8 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool response_make_reusable (struct MHD_Response *restrict r) { - mhd_assert (! r->reuse.reusable); - mhd_assert (! r->frozen); + mhd_assert (!r->reuse.reusable); + mhd_assert (!r->frozen); mhd_assert (NULL != r->settings); if (mhd_mutex_init (&(r->reuse.settings_lock))) @@ -71,7 +71,7 @@ response_make_reusable (struct MHD_Response *restrict r) r->reuse.reusable = true; return true; } - (void) mhd_mutex_destroy (&(r->reuse.settings_lock)); + (void)mhd_mutex_destroy (&(r->reuse.settings_lock)); } return false; } @@ -141,10 +141,10 @@ mhd_response_check_frozen_freeze (struct MHD_Response *restrict response) else need_unlock = false; - if (! response->frozen)/* Re-check under the lock */ + if (!response->frozen) /* Re-check under the lock */ { - mhd_assert ((! response->reuse.reusable) || \ - (1 == mhd_atomic_counter_get (&(response->reuse.counter)))); + mhd_assert ((!response->reuse.reusable) \ + || (1 == mhd_atomic_counter_get (&(response->reuse.counter)))); response_set_properties (response); } diff --git a/src/mhd2/response_set_options.c b/src/mhd2/response_set_options.c @@ -34,7 +34,7 @@ MHD_response_set_options ( if (response->reuse.reusable) { need_unlock = true; - if (! mhd_mutex_lock (&response->reuse.settings_lock)) + if (!mhd_mutex_lock (&response->reuse.settings_lock)) return MHD_SC_RESP_MUTEX_LOCK_FAILED; mhd_assert (1 == mhd_atomic_counter_get (&response->reuse.counter)); if (response->frozen) /* Firm re-check under the lock */ @@ -65,7 +65,7 @@ MHD_response_set_options ( } } else if ((MHD_NO != option->val.reusable) - && (! response_make_reusable (response))) + && (!response_make_reusable (response))) { res = MHD_SC_RESP_MUTEX_INIT_FAILED; i = options_max_num - 1; diff --git a/src/mhd2/sckt_recv.c b/src/mhd2/sckt_recv.c @@ -64,7 +64,7 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_sckt_recv (struct mhd_ConnSocket *restrict sk, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], @@ -85,12 +85,12 @@ mhd_sckt_recv (struct mhd_ConnSocket *restrict sk, after successful read as complete data could be already retrieved and no more data is pending. Note: blocking sockets are never used with edge-triggering. */ - if ((buf_size > (size_t) res) - || ! sk->props.is_nonblck) + if ((buf_size > (size_t)res) + || !sk->props.is_nonblck) mhd_SCKT_NET_ST_CLEAR_FLAG (&(sk->ready), mhd_SOCKET_NET_STATE_RECV_READY); - *received = (size_t) res; + *received = (size_t)res; return mhd_SOCKET_ERR_NO_ERROR; /* Success exit point */ } diff --git a/src/mhd2/sckt_recv.h b/src/mhd2/sckt_recv.h @@ -71,7 +71,7 @@ mhd_sckt_recv (struct mhd_ConnSocket *restrict sk, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict received) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); #endif /* ! MHD_SCKT_RECV_H */ diff --git a/src/mhd2/sckt_send.h b/src/mhd2/sckt_send.h @@ -77,7 +77,7 @@ mhd_sckt_send (struct mhd_ConnSocket *restrict sk, const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], bool push_data, size_t *restrict sent) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5); #endif /* ! MHD_SCKT_RECV_H */ diff --git a/src/mhd2/sha256_ext.h b/src/mhd2/sha256_ext.h @@ -43,30 +43,30 @@ */ #ifndef MHD_SHA256_EXT_H -#define MHD_SHA256_EXT_H 1 +# define MHD_SHA256_EXT_H 1 -#include "mhd_sys_options.h" -#include <stdint.h> -#include "sys_sizet_type.h" +# include "mhd_sys_options.h" +# include <stdint.h> +# include "sys_sizet_type.h" /** * Size of SHA-256 resulting digest in bytes * This is the final digest size, not intermediate hash. */ -#define mhd_SHA256_DIGEST_SIZE (32) +# define mhd_SHA256_DIGEST_SIZE (32) -#ifndef MHD_SHA256_Context -#define MHD_SHA256_Context void -#endif +# ifndef MHD_SHA256_Context +# define MHD_SHA256_Context void +# endif /** * Indicates that struct mhd_Sha256CtxExt has 'ext_error' */ -#define mhd_SHA256_HAS_EXT_ERROR 1 +# define mhd_SHA256_HAS_EXT_ERROR 1 -#ifndef MHD_SHA256_Context -#define MHD_SHA256_Context void -#endif +# ifndef MHD_SHA256_Context +# define MHD_SHA256_Context void +# endif /** * SHA-256 calculation context @@ -80,7 +80,7 @@ struct mhd_Sha256CtxExt /** * Indicates that mhd_SHA256_init_one_time() function is present. */ -#define mhd_SHA256_HAS_INIT_ONE_TIME 1 +# define mhd_SHA256_HAS_INIT_ONE_TIME 1 /** * Initialise structure for SHA-256 calculation, allocate resources. @@ -109,7 +109,7 @@ mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, /** * Indicates that mhd_SHA256_finish_reset() function is available */ -#define mhd_SHA256_HAS_FINISH_RESET 1 +# define mhd_SHA256_HAS_FINISH_RESET 1 /** * Finalise SHA-256 calculation, return digest, reset hash calculation. @@ -124,7 +124,7 @@ mhd_SHA256_finish_reset (struct mhd_Sha256CtxExt *ctx, /** * Indicates that mhd_SHA256_deinit() function is present */ -#define mhd_SHA256_HAS_DEINIT 1 +# define mhd_SHA256_HAS_DEINIT 1 /** * Free allocated resources. @@ -180,26 +180,26 @@ mhd_SHA256_deinit (struct mhd_Sha256CtxExt *ctx); */ #ifndef MHD_SHA256_EXT_H -#define MHD_SHA256_EXT_H 1 +# define MHD_SHA256_EXT_H 1 -#include "mhd_sys_options.h" -#include <stdint.h> -#include "sys_sizet_type.h" +# include "mhd_sys_options.h" +# include <stdint.h> +# include "sys_sizet_type.h" /** * Size of SHA-256 resulting digest in bytes * This is the final digest size, not intermediate hash. */ -#define mhd_SHA256_DIGEST_SIZE (32) +# define mhd_SHA256_DIGEST_SIZE (32) -#ifndef MHD_SHA256_Context -#define MHD_SHA256_Context void -#endif +# ifndef MHD_SHA256_Context +# define MHD_SHA256_Context void +# endif /** * Indicates that struct mhd_Sha256CtxExt has 'ext_error' */ -#define mhd_SHA256_HAS_EXT_ERROR 1 +# define mhd_SHA256_HAS_EXT_ERROR 1 /** * SHA-256 calculation context @@ -213,7 +213,7 @@ struct mhd_Sha256CtxExt /** * Indicates that mhd_SHA256_init_one_time() function is present. */ -#define mhd_SHA256_HAS_INIT_ONE_TIME 1 +# define mhd_SHA256_HAS_INIT_ONE_TIME 1 /** * Initialise structure for SHA-256 calculation, allocate resources. @@ -242,7 +242,7 @@ mhd_SHA256_update (struct mhd_Sha256CtxExt *ctx, /** * Indicates that mhd_SHA256_finish_reset() function is available */ -#define mhd_SHA256_HAS_FINISH_RESET 1 +# define mhd_SHA256_HAS_FINISH_RESET 1 /** * Finalise SHA-256 calculation, return digest, reset hash calculation. @@ -257,7 +257,7 @@ mhd_SHA256_finish_reset (struct mhd_Sha256CtxExt *ctx, /** * Indicates that mhd_SHA256_deinit() function is present */ -#define mhd_SHA256_HAS_DEINIT 1 +# define mhd_SHA256_HAS_DEINIT 1 /** * Free allocated resources. diff --git a/src/mhd2/sha256_ext_gnutls.c b/src/mhd2/sha256_ext_gnutls.c @@ -60,8 +60,8 @@ mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx) ctx->handle = NULL; ctx->ext_error = gnutls_hash_init (&ctx->handle, GNUTLS_DIG_SHA256); - if ( (0 != ctx->ext_error) && - (NULL != ctx->handle) ) + if ((0 != ctx->ext_error) + && (NULL != ctx->handle)) { /* GnuTLS may return initialisation error and set the handle at the same time. Such handle cannot be used for calculations. diff --git a/src/mhd2/sha256_ext_mbedtls.c b/src/mhd2/sha256_ext_mbedtls.c @@ -59,7 +59,7 @@ void mhd_SHA256_init_one_time (struct mhd_Sha256CtxExt *ctx) { ctx->ext_error = 0; - ctx->handle = (mbedtls_sha256_context *) malloc ( + ctx->handle = (mbedtls_sha256_context *)malloc ( sizeof (mbedtls_sha256_context)); if (NULL == ctx->handle) { diff --git a/src/mhd2/sha256_int.c b/src/mhd2/sha256_int.c @@ -96,22 +96,22 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], uint32_t W[16]; #ifndef mhd_GET_32BIT_BE_UNALIGNED - if (0 != (((uintptr_t) data) % mhd_UINT32_ALIGN)) + if (0 != (((uintptr_t)data) % mhd_UINT32_ALIGN)) { /* Copy the unaligned input data to the aligned buffer */ memcpy (W, data, mhd_SHA256_BLOCK_SIZE); /* The W[] buffer itself will be used as the source of the data, * but data will be reloaded in correct bytes order during * the next steps */ - data = (const void *) W; + data = (const void *)W; } #endif /* mhd_GET_32BIT_BE_UNALIGNED */ /* 'Ch' and 'Maj' macro functions are defined with widely-used optimization. See FIPS PUB 180-4 formulae 4.2, 4.3. */ -#define Ch(x,y,z) ( (z) ^ ((x) & ((y) ^ (z))) ) -#define Maj(x,y,z) ( ((x) & (y)) ^ ((z) & ((x) ^ (y))) ) +#define Ch(x, y, z) ( (z) ^ ((x) & ((y) ^ (z))) ) +#define Maj(x, y, z) ( ((x) & (y)) ^ ((z) & ((x) ^ (y))) ) /* Unoptimized (original) versions: */ /* #define Ch(x,y,z) ( ( (x) & (y) ) ^ ( ~(x) & (z) ) ) */ /* #define Maj(x,y,z) ( ((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)) ) */ @@ -119,13 +119,13 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], /* Four 'Sigma' macro functions. See FIPS PUB 180-4 formulae 4.4, 4.5, 4.6, 4.7. */ #define SIG0(x) (mhd_ROTR32 ((x), 2) ^ mhd_ROTR32 ((x), 13) ^ \ - mhd_ROTR32 ((x), 22) ) + mhd_ROTR32 ((x), 22) ) #define SIG1(x) (mhd_ROTR32 ((x), 6) ^ mhd_ROTR32 ((x), 11) ^ \ - mhd_ROTR32 ((x), 25) ) + mhd_ROTR32 ((x), 25) ) #define sig0(x) (mhd_ROTR32 ((x), 7) ^ mhd_ROTR32 ((x), 18) ^ \ - ((x) >> 3) ) + ((x) >> 3) ) #define sig1(x) (mhd_ROTR32 ((x), 17) ^ mhd_ROTR32 ((x),19) ^ \ - ((x) >> 10) ) + ((x) >> 10) ) /* One step of SHA-256 computation, see FIPS PUB 180-4 paragraph 6.2.2 step 3. @@ -134,9 +134,9 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], second (vH += SIG0(vA) + Maj(vE,vF,vC) equals T1 + T2 in FIPS PUB 180-4 paragraph 6.2.2 step 3. * Note: 'wt' must be used exactly one time in this macro as it change other data as well every time when used. */ -#define SHA2STEP32(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \ - (vD) += ((vH) += SIG1 ((vE)) + Ch ((vE),(vF),(vG)) + (kt) + (wt)); \ - (vH) += SIG0 ((vA)) + Maj ((vA),(vB),(vC)); } while (0) +#define SHA2STEP32(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) do { \ + (vD) += ((vH) += SIG1 ((vE)) + Ch ((vE),(vF),(vG)) + (kt) + (wt)); \ + (vH) += SIG0 ((vA)) + Maj ((vA),(vB),(vC)); } while (0) /* Get value of W(t) from input data buffer, See FIPS PUB 180-4 paragraph 6.2. @@ -144,7 +144,7 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], see FIPS PUB 180-4 paragraph 3.1.2. */ /* Use cast to (const void*) to mute compiler alignment warning, * data was already aligned in previous step */ -#define GET_W_FROM_DATA(buf,t) \ +#define GET_W_FROM_DATA(buf, t) \ mhd_GET_32BIT_BE ((const void*) (((const uint8_t*) (buf)) + \ (t) * mhd_SHA256_BYTES_IN_WORD)) @@ -153,8 +153,8 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], As only last 16 'W' are used in calculations, it is possible to use 16 elements array of W as cyclic buffer. * Note: ((t-16)&0xf) have same value as (t&0xf) */ -#define Wgen(w,t) ( (w)[(t - 16) & 0xf] + sig1 ((w)[((t) - 2) & 0xf]) \ - + (w)[((t) - 7) & 0xf] + sig0 ((w)[((t) - 15) & 0xf]) ) +#define Wgen(w, t) ( (w)[(t - 16) & 0xf] + sig1 ((w)[((t) - 2) & 0xf]) \ + + (w)[((t) - 7) & 0xf] + sig0 ((w)[((t) - 15) & 0xf]) ) #ifndef MHD_FAVOR_SMALL_CODE @@ -167,8 +167,8 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], SHA2STEP32(h, a, b, c, d, e, f, g, K[1], data[1]); so current 'vD' will be used as 'vE' on next step, current 'vH' will be used as 'vA' on next step. */ -#if mhd_BYTE_ORDER == mhd_BIG_ENDIAN - if ((const void *) W == data) +# if mhd_BYTE_ORDER == mhd_BIG_ENDIAN + if ((const void *)W == data) { /* The input data is already in the cyclic data buffer W[] in correct bytes order. */ @@ -190,7 +190,7 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xc19bf174), W[15]); } else /* Combined with the next 'if' */ -#endif /* mhd_BYTE_ORDER == mhd_BIG_ENDIAN */ +# endif /* mhd_BYTE_ORDER == mhd_BIG_ENDIAN */ if (1) { /* During first 16 steps, before making any calculations on each step, @@ -236,101 +236,101 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], /* Note: instead of using K constants as array, all K values are specified individually for each step, see FIPS PUB 180-4 paragraph 4.2.2 for K values. */ SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0xe49b69c1), W[16 & 0xf] = \ - Wgen (W,16)); + Wgen (W, 16)); SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0xefbe4786), W[17 & 0xf] = \ - Wgen (W,17)); + Wgen (W, 17)); SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0x0fc19dc6), W[18 & 0xf] = \ - Wgen (W,18)); + Wgen (W, 18)); SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0x240ca1cc), W[19 & 0xf] = \ - Wgen (W,19)); + Wgen (W, 19)); SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x2de92c6f), W[20 & 0xf] = \ - Wgen (W,20)); + Wgen (W, 20)); SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x4a7484aa), W[21 & 0xf] = \ - Wgen (W,21)); + Wgen (W, 21)); SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x5cb0a9dc), W[22 & 0xf] = \ - Wgen (W,22)); + Wgen (W, 22)); SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0x76f988da), W[23 & 0xf] = \ - Wgen (W,23)); + Wgen (W, 23)); SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0x983e5152), W[24 & 0xf] = \ - Wgen (W,24)); + Wgen (W, 24)); SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0xa831c66d), W[25 & 0xf] = \ - Wgen (W,25)); + Wgen (W, 25)); SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0xb00327c8), W[26 & 0xf] = \ - Wgen (W,26)); + Wgen (W, 26)); SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0xbf597fc7), W[27 & 0xf] = \ - Wgen (W,27)); + Wgen (W, 27)); SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0xc6e00bf3), W[28 & 0xf] = \ - Wgen (W,28)); + Wgen (W, 28)); SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0xd5a79147), W[29 & 0xf] = \ - Wgen (W,29)); + Wgen (W, 29)); SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x06ca6351), W[30 & 0xf] = \ - Wgen (W,30)); + Wgen (W, 30)); SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0x14292967), W[31 & 0xf] = \ - Wgen (W,31)); + Wgen (W, 31)); SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0x27b70a85), W[32 & 0xf] = \ - Wgen (W,32)); + Wgen (W, 32)); SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x2e1b2138), W[33 & 0xf] = \ - Wgen (W,33)); + Wgen (W, 33)); SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0x4d2c6dfc), W[34 & 0xf] = \ - Wgen (W,34)); + Wgen (W, 34)); SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0x53380d13), W[35 & 0xf] = \ - Wgen (W,35)); + Wgen (W, 35)); SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x650a7354), W[36 & 0xf] = \ - Wgen (W,36)); + Wgen (W, 36)); SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x766a0abb), W[37 & 0xf] = \ - Wgen (W,37)); + Wgen (W, 37)); SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x81c2c92e), W[38 & 0xf] = \ - Wgen (W,38)); + Wgen (W, 38)); SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0x92722c85), W[39 & 0xf] = \ - Wgen (W,39)); + Wgen (W, 39)); SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0xa2bfe8a1), W[40 & 0xf] = \ - Wgen (W,40)); + Wgen (W, 40)); SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0xa81a664b), W[41 & 0xf] = \ - Wgen (W,41)); + Wgen (W, 41)); SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0xc24b8b70), W[42 & 0xf] = \ - Wgen (W,42)); + Wgen (W, 42)); SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0xc76c51a3), W[43 & 0xf] = \ - Wgen (W,43)); + Wgen (W, 43)); SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0xd192e819), W[44 & 0xf] = \ - Wgen (W,44)); + Wgen (W, 44)); SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0xd6990624), W[45 & 0xf] = \ - Wgen (W,45)); + Wgen (W, 45)); SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0xf40e3585), W[46 & 0xf] = \ - Wgen (W,46)); + Wgen (W, 46)); SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0x106aa070), W[47 & 0xf] = \ - Wgen (W,47)); + Wgen (W, 47)); SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0x19a4c116), W[48 & 0xf] = \ - Wgen (W,48)); + Wgen (W, 48)); SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x1e376c08), W[49 & 0xf] = \ - Wgen (W,49)); + Wgen (W, 49)); SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0x2748774c), W[50 & 0xf] = \ - Wgen (W,50)); + Wgen (W, 50)); SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0x34b0bcb5), W[51 & 0xf] = \ - Wgen (W,51)); + Wgen (W, 51)); SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x391c0cb3), W[52 & 0xf] = \ - Wgen (W,52)); + Wgen (W, 52)); SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0x4ed8aa4a), W[53 & 0xf] = \ - Wgen (W,53)); + Wgen (W, 53)); SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0x5b9cca4f), W[54 & 0xf] = \ - Wgen (W,54)); + Wgen (W, 54)); SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0x682e6ff3), W[55 & 0xf] = \ - Wgen (W,55)); + Wgen (W, 55)); SHA2STEP32 (a, b, c, d, e, f, g, h, UINT32_C (0x748f82ee), W[56 & 0xf] = \ - Wgen (W,56)); + Wgen (W, 56)); SHA2STEP32 (h, a, b, c, d, e, f, g, UINT32_C (0x78a5636f), W[57 & 0xf] = \ - Wgen (W,57)); + Wgen (W, 57)); SHA2STEP32 (g, h, a, b, c, d, e, f, UINT32_C (0x84c87814), W[58 & 0xf] = \ - Wgen (W,58)); + Wgen (W, 58)); SHA2STEP32 (f, g, h, a, b, c, d, e, UINT32_C (0x8cc70208), W[59 & 0xf] = \ - Wgen (W,59)); + Wgen (W, 59)); SHA2STEP32 (e, f, g, h, a, b, c, d, UINT32_C (0x90befffa), W[60 & 0xf] = \ - Wgen (W,60)); + Wgen (W, 60)); SHA2STEP32 (d, e, f, g, h, a, b, c, UINT32_C (0xa4506ceb), W[61 & 0xf] = \ - Wgen (W,61)); + Wgen (W, 61)); SHA2STEP32 (c, d, e, f, g, h, a, b, UINT32_C (0xbef9a3f7), W[62 & 0xf] = \ - Wgen (W,62)); + Wgen (W, 62)); SHA2STEP32 (b, c, d, e, f, g, h, a, UINT32_C (0xc67178f2), W[63 & 0xf] = \ - Wgen (W,63)); + Wgen (W, 63)); #else /* ! MHD_FAVOR_SMALL_CODE */ if (1) { @@ -364,19 +364,18 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], see FIPS PUB 180-4 paragraph 6.2.2 step 3. * Note: this version of macro reassign all working variable on each step. */ -#define SHA2STEP32RV(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \ - uint32_t tmp_h_ = (vH); \ - SHA2STEP32 ((vA),(vB),(vC),(vD),(vE),(vF),(vG),tmp_h_,(kt),(wt)); \ - (vH) = (vG); \ - (vG) = (vF); \ - (vF) = (vE); \ - (vE) = (vD); \ - (vD) = (vC); \ - (vC) = (vB); \ - (vB) = (vA); \ - (vA) = tmp_h_; \ -} \ - while (0) +# define SHA2STEP32RV(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) do { \ + uint32_t tmp_h_ = (vH); \ + SHA2STEP32 ((vA),(vB),(vC),(vD),(vE),(vF),(vG),tmp_h_,(kt),(wt)); \ + (vH) = (vG); \ + (vG) = (vF); \ + (vF) = (vE); \ + (vE) = (vD); \ + (vD) = (vC); \ + (vC) = (vB); \ + (vB) = (vA); \ + (vA) = tmp_h_; \ + } while (0) /* During first 16 steps, before making any calculations on each step, the W element is read from input data buffer as big-endian value and @@ -392,7 +391,7 @@ sha256_transform (uint32_t H[mhd_SHA256_DIGEST_SIZE_WORDS], and the generated value is stored back in the cyclic buffer. */ for (t = 16; t < 64; ++t) { - SHA2STEP32RV (a, b, c, d, e, f, g, h, K[t], W[t & 15] = Wgen (W,t)); + SHA2STEP32RV (a, b, c, d, e, f, g, h, K[t], W[t & 15] = Wgen (W, t)); } } #endif /* ! MHD_FAVOR_SMALL_CODE */ @@ -422,7 +421,7 @@ mhd_SHA256_update (struct mhd_Sha256CtxInt *restrict ctx, /* Note: (count & (mhd_SHA256_BLOCK_SIZE-1)) equals (count % mhd_SHA256_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned) (ctx->count & (mhd_SHA256_BLOCK_SIZE - 1)); + bytes_have = (unsigned)(ctx->count & (mhd_SHA256_BLOCK_SIZE - 1)); ctx->count += size; if (0 != bytes_have) @@ -431,7 +430,7 @@ mhd_SHA256_update (struct mhd_Sha256CtxInt *restrict ctx, if (size >= bytes_left) { /* Combine new data with data in the buffer and process full block. */ - memcpy (((uint8_t *) ctx->buffer) + bytes_have, + memcpy (((uint8_t *)ctx->buffer) + bytes_have, data, bytes_left); data += bytes_left; @@ -452,7 +451,7 @@ mhd_SHA256_update (struct mhd_Sha256CtxInt *restrict ctx, if (0 != size) { /* Copy incomplete block of new data (if any) to the buffer. */ - memcpy (((uint8_t *) ctx->buffer) + bytes_have, data, size); + memcpy (((uint8_t *)ctx->buffer) + bytes_have, data, size); } } @@ -473,7 +472,7 @@ mhd_SHA256_finish (struct mhd_Sha256CtxInt *restrict ctx, num_bits = ctx->count << 3; /* Note: (count & (mhd_SHA256_BLOCK_SIZE-1)) equal (count % mhd_SHA256_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned) (ctx->count & (mhd_SHA256_BLOCK_SIZE - 1)); + bytes_have = (unsigned)(ctx->count & (mhd_SHA256_BLOCK_SIZE - 1)); /* Input data must be padded with a single bit "1", then with zeros and the finally the length of data in bits must be added as the final bytes @@ -485,13 +484,13 @@ mhd_SHA256_finish (struct mhd_Sha256CtxInt *restrict ctx, predefined (0x80). */ /* Buffer always have space at least for one byte (as full buffers are processed immediately). */ - ((uint8_t *) ctx->buffer)[bytes_have++] = 0x80; + ((uint8_t *)ctx->buffer)[bytes_have++] = 0x80; if (mhd_SHA256_BLOCK_SIZE - bytes_have < SHA256_SIZE_OF_LEN_ADD) { /* No space in current block to put total length of message. Pad current block with zeros and process it. */ if (bytes_have < mhd_SHA256_BLOCK_SIZE) - memset (((uint8_t *) ctx->buffer) + bytes_have, 0, + memset (((uint8_t *)ctx->buffer) + bytes_have, 0, mhd_SHA256_BLOCK_SIZE - bytes_have); /* Process full block. */ sha256_transform (ctx->H, ctx->buffer); @@ -500,7 +499,7 @@ mhd_SHA256_finish (struct mhd_Sha256CtxInt *restrict ctx, } /* Pad the rest of the buffer with zeros. */ - memset (((uint8_t *) ctx->buffer) + bytes_have, 0, + memset (((uint8_t *)ctx->buffer) + bytes_have, 0, mhd_SHA256_BLOCK_SIZE - SHA256_SIZE_OF_LEN_ADD - bytes_have); /* Put the number of bits in processed message as big-endian value. */ mhd_PUT_64BIT_BE_UNALIGN (ctx->buffer + mhd_SHA256_BLOCK_SIZE_WORDS - 2, @@ -515,11 +514,11 @@ mhd_SHA256_finish (struct mhd_Sha256CtxInt *restrict ctx, #if defined(mhd_PUT_32BIT_BE_UNALIGNED) use_tmp_buf_to_align_result = false; -#elif defined (MHD_FAVOR_SMALL_CODE) +#elif defined(MHD_FAVOR_SMALL_CODE) use_tmp_buf_to_align_result = true; /* smaller code: eliminated branch below */ #else use_tmp_buf_to_align_result = - (0 != ((uintptr_t) digest) % mhd_UINT32_ALIGN); + (0 != ((uintptr_t)digest) % mhd_UINT32_ALIGN); #endif if (use_tmp_buf_to_align_result) { @@ -543,21 +542,21 @@ mhd_SHA256_finish (struct mhd_Sha256CtxInt *restrict ctx, { /* Use cast to (void*) here to mute compiler alignment warnings. * Compilers are not smart enough to see that alignment has been checked. */ - mhd_PUT_32BIT_BE ((void *) (digest + 0 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 0 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[0]); - mhd_PUT_32BIT_BE ((void *) (digest + 1 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 1 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[1]); - mhd_PUT_32BIT_BE ((void *) (digest + 2 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 2 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[2]); - mhd_PUT_32BIT_BE ((void *) (digest + 3 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 3 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[3]); - mhd_PUT_32BIT_BE ((void *) (digest + 4 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 4 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[4]); - mhd_PUT_32BIT_BE ((void *) (digest + 5 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 5 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[5]); - mhd_PUT_32BIT_BE ((void *) (digest + 6 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 6 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[6]); - mhd_PUT_32BIT_BE ((void *) (digest + 7 * mhd_SHA256_BYTES_IN_WORD), \ + mhd_PUT_32BIT_BE ((void *)(digest + 7 * mhd_SHA256_BYTES_IN_WORD), \ ctx->H[7]); } } diff --git a/src/mhd2/sha512_256_ext.h b/src/mhd2/sha512_256_ext.h @@ -43,26 +43,26 @@ */ #ifndef MHD_SHA512_256_EXT_H -#define MHD_SHA512_256_EXT_H 1 +# define MHD_SHA512_256_EXT_H 1 -#include "mhd_sys_options.h" -#include <stdint.h> -#include "sys_sizet_type.h" +# include "mhd_sys_options.h" +# include <stdint.h> +# include "sys_sizet_type.h" /** * Size of SHA-512_256 resulting digest in bytes * This is the final digest size, not intermediate hash. */ -#define mhd_SHA512_256_DIGEST_SIZE (32) +# define mhd_SHA512_256_DIGEST_SIZE (32) -#ifndef MHD_SHA512_256_Context -#define MHD_SHA512_256_Context void -#endif +# ifndef MHD_SHA512_256_Context +# define MHD_SHA512_256_Context void +# endif /** * Indicates that struct mhd_Sha512_256CtxExt has 'ext_error' */ -#define mhd_SHA512_256_HAS_EXT_ERROR 1 +# define mhd_SHA512_256_HAS_EXT_ERROR 1 /** * SHA-512_256 calculation context @@ -76,7 +76,7 @@ struct mhd_Sha512_256CtxExt /** * Indicates that mhd_SHA512_256_init_one_time() function is present. */ -#define mhd_SHA512_256_HAS_INIT_ONE_TIME 1 +# define mhd_SHA512_256_HAS_INIT_ONE_TIME 1 /** * Initialise structure for SHA-512_256 calculation, allocate resources. @@ -105,7 +105,7 @@ mhd_SHA512_256_update (struct mhd_Sha512_256CtxExt *ctx, /** * Indicates that mhd_SHA512_256_finish_reset() function is available */ -#define mhd_SHA512_256_HAS_FINISH_RESET 1 +# define mhd_SHA512_256_HAS_FINISH_RESET 1 /** * Finalise SHA-512_256 calculation, return digest, reset hash calculation. @@ -120,7 +120,7 @@ mhd_SHA512_256_finish_reset (struct mhd_Sha512_256CtxExt *ctx, /** * Indicates that mhd_SHA512_256_deinit() function is present */ -#define mhd_SHA512_256_HAS_DEINIT 1 +# define mhd_SHA512_256_HAS_DEINIT 1 /** * Free allocated resources. @@ -176,26 +176,26 @@ mhd_SHA512_256_deinit (struct mhd_Sha512_256CtxExt *ctx); */ #ifndef MHD_SHA512_256_EXT_H -#define MHD_SHA512_256_EXT_H 1 +# define MHD_SHA512_256_EXT_H 1 -#include "mhd_sys_options.h" -#include <stdint.h> -#include "sys_sizet_type.h" +# include "mhd_sys_options.h" +# include <stdint.h> +# include "sys_sizet_type.h" /** * Size of SHA-512/256 resulting digest in bytes * This is the final digest size, not intermediate hash. */ -#define mhd_SHA512_256_DIGEST_SIZE (32) +# define mhd_SHA512_256_DIGEST_SIZE (32) -#ifndef MHD_SHA512_256_Context -#define MHD_SHA512_256_Context void -#endif +# ifndef MHD_SHA512_256_Context +# define MHD_SHA512_256_Context void +# endif /** * Indicates that struct mhd_Sha512_256CtxExt has 'ext_error' */ -#define mhd_SHA512_256_HAS_EXT_ERROR 1 +# define mhd_SHA512_256_HAS_EXT_ERROR 1 /** * SHA-512_256 calculation context @@ -209,7 +209,7 @@ struct mhd_Sha512_256CtxExt /** * Indicates that mhd_SHA512_256_init_one_time() function is present. */ -#define mhd_SHA512_256_HAS_INIT_ONE_TIME 1 +# define mhd_SHA512_256_HAS_INIT_ONE_TIME 1 /** * Initialise structure for SHA-512_256 calculation, allocate resources. @@ -238,7 +238,7 @@ mhd_SHA512_256_update (struct mhd_Sha512_256CtxExt *ctx, /** * Indicates that mhd_SHA512_256_finish_reset() function is available */ -#define mhd_SHA512_256_HAS_FINISH_RESET 1 +# define mhd_SHA512_256_HAS_FINISH_RESET 1 /** * Finalise SHA-512_256 calculation, return digest, reset hash calculation. @@ -253,7 +253,7 @@ mhd_SHA512_256_finish_reset (struct mhd_Sha512_256CtxExt *ctx, /** * Indicates that mhd_SHA512_256_deinit() function is present */ -#define mhd_SHA512_256_HAS_DEINIT 1 +# define mhd_SHA512_256_HAS_DEINIT 1 /** * Free allocated resources. diff --git a/src/mhd2/sha512_256_ext_mbedtls.c b/src/mhd2/sha512_256_ext_mbedtls.c @@ -109,7 +109,7 @@ void mhd_SHA512_256_init_one_time (struct mhd_Sha512_256CtxExt *ctx) { ctx->ext_error = 0; - ctx->handle = (mbedtls_sha512_context *) malloc ( + ctx->handle = (mbedtls_sha512_context *)malloc ( sizeof (mbedtls_sha512_context)); if (NULL == ctx->handle) { diff --git a/src/mhd2/sha512_256_int.c b/src/mhd2/sha512_256_int.c @@ -102,22 +102,22 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], uint64_t W[16]; #ifndef mhd_GET_64BIT_BE_ALLOW_UNALIGNED - if (0 != (((uintptr_t) data) % mhd_UINT64_ALIGN)) + if (0 != (((uintptr_t)data) % mhd_UINT64_ALIGN)) { /* The input data is unaligned */ /* Copy the unaligned input data to the aligned buffer */ memcpy (W, data, sizeof(W)); /* The W[] buffer itself will be used as the source of the data, * but the data will be reloaded in correct bytes order on * the next steps */ - data = (const void *) W; + data = (const void *)W; } #endif /* mhd_GET_64BIT_BE_ALLOW_UNALIGNED */ /* 'Ch' and 'Maj' macro functions are defined with widely-used optimisation. See FIPS PUB 180-4 formulae 4.8, 4.9. */ -#define Ch(x,y,z) ( (z) ^ ((x) & ((y) ^ (z))) ) -#define Maj(x,y,z) ( ((x) & (y)) ^ ((z) & ((x) ^ (y))) ) +#define Ch(x, y, z) ( (z) ^ ((x) & ((y) ^ (z))) ) +#define Maj(x, y, z) ( ((x) & (y)) ^ ((z) & ((x) ^ (y))) ) /* Unoptimized (original) versions: */ /* #define Ch(x,y,z) ( ( (x) & (y) ) ^ ( ~(x) & (z) ) ) */ /* #define Maj(x,y,z) ( ((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)) ) */ @@ -142,15 +142,15 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], FIPS PUB 180-4 clause 6.4.2 step 3. * Note: 'wt' must be used exactly one time in this macro as it change other data as well every time when used. */ -#define SHA2STEP64(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) do { \ - (vD) += ((vH) += SIG1 ((vE)) + Ch ((vE),(vF),(vG)) + (kt) + (wt)); \ - (vH) += SIG0 ((vA)) + Maj ((vA),(vB),(vC)); } while (0) +#define SHA2STEP64(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) do { \ + (vD) += ((vH) += SIG1 ((vE)) + Ch ((vE),(vF),(vG)) + (kt) + (wt)); \ + (vH) += SIG0 ((vA)) + Maj ((vA),(vB),(vC)); } while (0) /* Get value of W(t) from input data buffer for 0 <= t <= 15, See FIPS PUB 180-4 clause 6.2. Input data must be read in big-endian bytes order, see FIPS PUB 180-4 clause 3.1.2. */ -#define GET_W_FROM_DATA(buf,t) \ +#define GET_W_FROM_DATA(buf, t) \ mhd_GET_64BIT_BE (((const uint64_t*) (buf)) + (t)) /* 'W' generation and assignment for 16 <= t <= 79. @@ -158,8 +158,8 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], As only last 16 'W' are used in calculations, it is possible to use 16 elements array of W as a cyclic buffer. * Note: ((t-16) & 15) have same value as (t & 15) */ -#define Wgen(w,t) ( (w)[(t - 16) & 15] + sig1 ((w)[((t) - 2) & 15]) \ - + (w)[((t) - 7) & 15] + sig0 ((w)[((t) - 15) & 15]) ) +#define Wgen(w, t) ( (w)[(t - 16) & 15] + sig1 ((w)[((t) - 2) & 15]) \ + + (w)[((t) - 7) & 15] + sig0 ((w)[((t) - 15) & 15]) ) #ifndef MHD_FAVOR_SMALL_CODE @@ -172,8 +172,8 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], SHA2STEP64(h, a, b, c, d, e, f, g, K[1], data[1]); so current 'vD' will be used as 'vE' on next step, current 'vH' will be used as 'vA' on next step. */ -#if mhd_BYTE_ORDER == mhd_BIG_ENDIAN - if ((const void *) W == data) +# if mhd_BYTE_ORDER == mhd_BIG_ENDIAN + if ((const void *)W == data) { /* The input data is already in the cyclic data buffer W[] in correct bytes order. */ @@ -195,7 +195,7 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0xc19bf174cf692694), W[15]); } else /* Combined with the next 'if' */ -#endif /* mhd_BYTE_ORDER == mhd_BIG_ENDIAN */ +# endif /* mhd_BYTE_ORDER == mhd_BIG_ENDIAN */ if (1) { /* During first 16 steps, before making any calculations on each step, @@ -242,133 +242,133 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], individually for each step, see FIPS PUB 180-4 clause 4.2.3 for K values. */ SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0xe49b69c19ef14ad2), \ - W[16 & 15] = Wgen (W,16)); + W[16 & 15] = Wgen (W, 16)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0xefbe4786384f25e3), \ - W[17 & 15] = Wgen (W,17)); + W[17 & 15] = Wgen (W, 17)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0x0fc19dc68b8cd5b5), \ - W[18 & 15] = Wgen (W,18)); + W[18 & 15] = Wgen (W, 18)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0x240ca1cc77ac9c65), \ - W[19 & 15] = Wgen (W,19)); + W[19 & 15] = Wgen (W, 19)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0x2de92c6f592b0275), \ - W[20 & 15] = Wgen (W,20)); + W[20 & 15] = Wgen (W, 20)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0x4a7484aa6ea6e483), \ - W[21 & 15] = Wgen (W,21)); + W[21 & 15] = Wgen (W, 21)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0x5cb0a9dcbd41fbd4), \ - W[22 & 15] = Wgen (W,22)); + W[22 & 15] = Wgen (W, 22)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0x76f988da831153b5), \ - W[23 & 15] = Wgen (W,23)); + W[23 & 15] = Wgen (W, 23)); SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0x983e5152ee66dfab), \ - W[24 & 15] = Wgen (W,24)); + W[24 & 15] = Wgen (W, 24)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0xa831c66d2db43210), \ - W[25 & 15] = Wgen (W,25)); + W[25 & 15] = Wgen (W, 25)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0xb00327c898fb213f), \ - W[26 & 15] = Wgen (W,26)); + W[26 & 15] = Wgen (W, 26)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0xbf597fc7beef0ee4), \ - W[27 & 15] = Wgen (W,27)); + W[27 & 15] = Wgen (W, 27)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0xc6e00bf33da88fc2), \ - W[28 & 15] = Wgen (W,28)); + W[28 & 15] = Wgen (W, 28)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0xd5a79147930aa725), \ - W[29 & 15] = Wgen (W,29)); + W[29 & 15] = Wgen (W, 29)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0x06ca6351e003826f), \ - W[30 & 15] = Wgen (W,30)); + W[30 & 15] = Wgen (W, 30)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0x142929670a0e6e70), \ - W[31 & 15] = Wgen (W,31)); + W[31 & 15] = Wgen (W, 31)); SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0x27b70a8546d22ffc), \ - W[32 & 15] = Wgen (W,32)); + W[32 & 15] = Wgen (W, 32)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0x2e1b21385c26c926), \ - W[33 & 15] = Wgen (W,33)); + W[33 & 15] = Wgen (W, 33)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0x4d2c6dfc5ac42aed), \ - W[34 & 15] = Wgen (W,34)); + W[34 & 15] = Wgen (W, 34)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0x53380d139d95b3df), \ - W[35 & 15] = Wgen (W,35)); + W[35 & 15] = Wgen (W, 35)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0x650a73548baf63de), \ - W[36 & 15] = Wgen (W,36)); + W[36 & 15] = Wgen (W, 36)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0x766a0abb3c77b2a8), \ - W[37 & 15] = Wgen (W,37)); + W[37 & 15] = Wgen (W, 37)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0x81c2c92e47edaee6), \ - W[38 & 15] = Wgen (W,38)); + W[38 & 15] = Wgen (W, 38)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0x92722c851482353b), \ - W[39 & 15] = Wgen (W,39)); + W[39 & 15] = Wgen (W, 39)); SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0xa2bfe8a14cf10364), \ - W[40 & 15] = Wgen (W,40)); + W[40 & 15] = Wgen (W, 40)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0xa81a664bbc423001), \ - W[41 & 15] = Wgen (W,41)); + W[41 & 15] = Wgen (W, 41)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0xc24b8b70d0f89791), \ - W[42 & 15] = Wgen (W,42)); + W[42 & 15] = Wgen (W, 42)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0xc76c51a30654be30), \ - W[43 & 15] = Wgen (W,43)); + W[43 & 15] = Wgen (W, 43)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0xd192e819d6ef5218), \ - W[44 & 15] = Wgen (W,44)); + W[44 & 15] = Wgen (W, 44)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0xd69906245565a910), \ - W[45 & 15] = Wgen (W,45)); + W[45 & 15] = Wgen (W, 45)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0xf40e35855771202a), \ - W[46 & 15] = Wgen (W,46)); + W[46 & 15] = Wgen (W, 46)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0x106aa07032bbd1b8), \ - W[47 & 15] = Wgen (W,47)); + W[47 & 15] = Wgen (W, 47)); SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0x19a4c116b8d2d0c8), \ - W[48 & 15] = Wgen (W,48)); + W[48 & 15] = Wgen (W, 48)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0x1e376c085141ab53), \ - W[49 & 15] = Wgen (W,49)); + W[49 & 15] = Wgen (W, 49)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0x2748774cdf8eeb99), \ - W[50 & 15] = Wgen (W,50)); + W[50 & 15] = Wgen (W, 50)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0x34b0bcb5e19b48a8), \ - W[51 & 15] = Wgen (W,51)); + W[51 & 15] = Wgen (W, 51)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0x391c0cb3c5c95a63), \ - W[52 & 15] = Wgen (W,52)); + W[52 & 15] = Wgen (W, 52)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0x4ed8aa4ae3418acb), \ - W[53 & 15] = Wgen (W,53)); + W[53 & 15] = Wgen (W, 53)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0x5b9cca4f7763e373), \ - W[54 & 15] = Wgen (W,54)); + W[54 & 15] = Wgen (W, 54)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0x682e6ff3d6b2b8a3), \ - W[55 & 15] = Wgen (W,55)); + W[55 & 15] = Wgen (W, 55)); SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0x748f82ee5defb2fc), \ - W[56 & 15] = Wgen (W,56)); + W[56 & 15] = Wgen (W, 56)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0x78a5636f43172f60), \ - W[57 & 15] = Wgen (W,57)); + W[57 & 15] = Wgen (W, 57)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0x84c87814a1f0ab72), \ - W[58 & 15] = Wgen (W,58)); + W[58 & 15] = Wgen (W, 58)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0x8cc702081a6439ec), \ - W[59 & 15] = Wgen (W,59)); + W[59 & 15] = Wgen (W, 59)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0x90befffa23631e28), \ - W[60 & 15] = Wgen (W,60)); + W[60 & 15] = Wgen (W, 60)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0xa4506cebde82bde9), \ - W[61 & 15] = Wgen (W,61)); + W[61 & 15] = Wgen (W, 61)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0xbef9a3f7b2c67915), \ - W[62 & 15] = Wgen (W,62)); + W[62 & 15] = Wgen (W, 62)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0xc67178f2e372532b), \ - W[63 & 15] = Wgen (W,63)); + W[63 & 15] = Wgen (W, 63)); SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0xca273eceea26619c), \ - W[64 & 15] = Wgen (W,64)); + W[64 & 15] = Wgen (W, 64)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0xd186b8c721c0c207), \ - W[65 & 15] = Wgen (W,65)); + W[65 & 15] = Wgen (W, 65)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0xeada7dd6cde0eb1e), \ - W[66 & 15] = Wgen (W,66)); + W[66 & 15] = Wgen (W, 66)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0xf57d4f7fee6ed178), \ - W[67 & 15] = Wgen (W,67)); + W[67 & 15] = Wgen (W, 67)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0x06f067aa72176fba), \ - W[68 & 15] = Wgen (W,68)); + W[68 & 15] = Wgen (W, 68)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0x0a637dc5a2c898a6), \ - W[69 & 15] = Wgen (W,69)); + W[69 & 15] = Wgen (W, 69)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0x113f9804bef90dae), \ - W[70 & 15] = Wgen (W,70)); + W[70 & 15] = Wgen (W, 70)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0x1b710b35131c471b), \ - W[71 & 15] = Wgen (W,71)); + W[71 & 15] = Wgen (W, 71)); SHA2STEP64 (a, b, c, d, e, f, g, h, UINT64_C (0x28db77f523047d84), \ - W[72 & 15] = Wgen (W,72)); + W[72 & 15] = Wgen (W, 72)); SHA2STEP64 (h, a, b, c, d, e, f, g, UINT64_C (0x32caab7b40c72493), \ - W[73 & 15] = Wgen (W,73)); + W[73 & 15] = Wgen (W, 73)); SHA2STEP64 (g, h, a, b, c, d, e, f, UINT64_C (0x3c9ebe0a15c9bebc), \ - W[74 & 15] = Wgen (W,74)); + W[74 & 15] = Wgen (W, 74)); SHA2STEP64 (f, g, h, a, b, c, d, e, UINT64_C (0x431d67c49c100d4c), \ - W[75 & 15] = Wgen (W,75)); + W[75 & 15] = Wgen (W, 75)); SHA2STEP64 (e, f, g, h, a, b, c, d, UINT64_C (0x4cc5d4becb3e42b6), \ - W[76 & 15] = Wgen (W,76)); + W[76 & 15] = Wgen (W, 76)); SHA2STEP64 (d, e, f, g, h, a, b, c, UINT64_C (0x597f299cfc657e2a), \ - W[77 & 15] = Wgen (W,77)); + W[77 & 15] = Wgen (W, 77)); SHA2STEP64 (c, d, e, f, g, h, a, b, UINT64_C (0x5fcb6fab3ad6faec), \ - W[78 & 15] = Wgen (W,78)); + W[78 & 15] = Wgen (W, 78)); SHA2STEP64 (b, c, d, e, f, g, h, a, UINT64_C (0x6c44198c4a475817), \ - W[79 & 15] = Wgen (W,79)); + W[79 & 15] = Wgen (W, 79)); #else /* MHD_FAVOR_SMALL_CODE */ if (1) { @@ -421,20 +421,19 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], see FIPS PUB 180-4 clause 6.4.2 step 3. * Note: this version of macro reassign all working variable on each step. */ -#define SHA2STEP64RV(vA,vB,vC,vD,vE,vF,vG,vH,kt,wt) \ - do { \ - uint64_t tmp_h_ = (vH); \ - SHA2STEP64 ((vA),(vB),(vC),(vD),(vE),(vF),(vG),tmp_h_,(kt),(wt)); \ - (vH) = (vG); \ - (vG) = (vF); \ - (vF) = (vE); \ - (vE) = (vD); \ - (vD) = (vC); \ - (vC) = (vB); \ - (vB) = (vA); \ - (vA) = tmp_h_; \ - } \ - while (0) +# define SHA2STEP64RV(vA, vB, vC, vD, vE, vF, vG, vH, kt, wt) \ + do { \ + uint64_t tmp_h_ = (vH); \ + SHA2STEP64 ((vA),(vB),(vC),(vD),(vE),(vF),(vG),tmp_h_,(kt),(wt)); \ + (vH) = (vG); \ + (vG) = (vF); \ + (vF) = (vE); \ + (vE) = (vD); \ + (vD) = (vC); \ + (vC) = (vB); \ + (vB) = (vA); \ + (vA) = tmp_h_; \ + } while (0) /* During first 16 steps, before making any calculations on each step, the W element is read from the input data buffer as big-endian value and @@ -450,7 +449,7 @@ sha512_256_transform (uint64_t H[mhd_SHA512_256_HASH_SIZE_WORDS], for (t = 16; t < 80; ++t) { SHA2STEP64RV (a, b, c, d, e, f, g, h, K[t], \ - W[t & 15] = Wgen (W,t)); + W[t & 15] = Wgen (W, t)); } } #endif /* MHD_FAVOR_SMALL_CODE */ @@ -481,7 +480,7 @@ mhd_SHA512_256_update (struct mhd_Sha512_256CtxInt *restrict ctx, /* Note: (count & (mhd_SHA512_256_BLOCK_SIZE-1)) equals (count % mhd_SHA512_256_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned int) (ctx->count & (mhd_SHA512_256_BLOCK_SIZE - 1)); + bytes_have = (unsigned int)(ctx->count & (mhd_SHA512_256_BLOCK_SIZE - 1)); ctx->count += size; #if SIZEOF_SIZE_T > 7 if (size > ctx->count) @@ -500,7 +499,7 @@ mhd_SHA512_256_update (struct mhd_Sha512_256CtxInt *restrict ctx, if (size >= bytes_left) { /* Combine new data with data in the buffer and process the full block. */ - memcpy (((uint8_t *) ctx->buffer) + bytes_have, + memcpy (((uint8_t *)ctx->buffer) + bytes_have, data, bytes_left); data += bytes_left; @@ -521,7 +520,7 @@ mhd_SHA512_256_update (struct mhd_Sha512_256CtxInt *restrict ctx, if (0 != size) { /* Copy incomplete block of new data (if any) to the buffer. */ - memcpy (((uint8_t *) ctx->buffer) + bytes_have, data, size); + memcpy (((uint8_t *)ctx->buffer) + bytes_have, data, size); } } @@ -551,7 +550,7 @@ mhd_SHA512_256_finish (struct mhd_Sha512_256CtxInt *restrict ctx, /* Note: (count & (mhd_SHA512_256_BLOCK_SIZE-1)) equals (count % mhd_SHA512_256_BLOCK_SIZE) for this block size. */ - bytes_have = (unsigned int) (ctx->count & (mhd_SHA512_256_BLOCK_SIZE - 1)); + bytes_have = (unsigned int)(ctx->count & (mhd_SHA512_256_BLOCK_SIZE - 1)); /* Input data must be padded with a single bit "1", then with zeros and the finally the length of data in bits must be added as the final bytes @@ -563,13 +562,13 @@ mhd_SHA512_256_finish (struct mhd_Sha512_256CtxInt *restrict ctx, predefined (0x80). */ /* Buffer always have space for one byte at least (as full buffers are processed immediately). */ - ((uint8_t *) ctx->buffer)[bytes_have++] = 0x80; + ((uint8_t *)ctx->buffer)[bytes_have++] = 0x80; if (mhd_SHA512_256_BLOCK_SIZE - bytes_have < SHA512_256_SIZE_OF_LEN_ADD) { /* No space in the current block to put the total length of message. Pad the current block with zeros and process it. */ if (bytes_have < mhd_SHA512_256_BLOCK_SIZE) - memset (((uint8_t *) ctx->buffer) + bytes_have, 0, + memset (((uint8_t *)ctx->buffer) + bytes_have, 0, mhd_SHA512_256_BLOCK_SIZE - bytes_have); /* Process the full block. */ sha512_256_transform (ctx->H, ctx->buffer); @@ -578,7 +577,7 @@ mhd_SHA512_256_finish (struct mhd_Sha512_256CtxInt *restrict ctx, } /* Pad the rest of the buffer with zeros. */ - memset (((uint8_t *) ctx->buffer) + bytes_have, 0, + memset (((uint8_t *)ctx->buffer) + bytes_have, 0, mhd_SHA512_256_BLOCK_SIZE - SHA512_256_SIZE_OF_LEN_ADD - bytes_have); /* Put high part of number of bits in processed message and then lower part of number of bits as big-endian values. @@ -599,11 +598,11 @@ mhd_SHA512_256_finish (struct mhd_Sha512_256CtxInt *restrict ctx, #if defined(mhd_PUT_64BIT_BE_UNALIGNED) use_tmp_buf_to_align_result = false; -#elif defined (MHD_FAVOR_SMALL_CODE) +#elif defined(MHD_FAVOR_SMALL_CODE) use_tmp_buf_to_align_result = true; /* smaller code: eliminated branch below */ #else use_tmp_buf_to_align_result = - (0 != ((uintptr_t) digest) % mhd_UINT64_ALIGN); + (0 != ((uintptr_t)digest) % mhd_UINT64_ALIGN); #endif if (use_tmp_buf_to_align_result) { @@ -623,13 +622,13 @@ mhd_SHA512_256_finish (struct mhd_Sha512_256CtxInt *restrict ctx, { /* Use cast to (void*) here to mute compiler alignment warnings. * Compilers are not smart enough to see that alignment has been checked. */ - mhd_PUT_64BIT_BE ((void *) (digest + 0 * mhd_SHA512_256_BYTES_IN_WORD), \ + mhd_PUT_64BIT_BE ((void *)(digest + 0 * mhd_SHA512_256_BYTES_IN_WORD), \ ctx->H[0]); - mhd_PUT_64BIT_BE ((void *) (digest + 1 * mhd_SHA512_256_BYTES_IN_WORD), \ + mhd_PUT_64BIT_BE ((void *)(digest + 1 * mhd_SHA512_256_BYTES_IN_WORD), \ ctx->H[1]); - mhd_PUT_64BIT_BE ((void *) (digest + 2 * mhd_SHA512_256_BYTES_IN_WORD), \ + mhd_PUT_64BIT_BE ((void *)(digest + 2 * mhd_SHA512_256_BYTES_IN_WORD), \ ctx->H[2]); - mhd_PUT_64BIT_BE ((void *) (digest + 3 * mhd_SHA512_256_BYTES_IN_WORD), \ + mhd_PUT_64BIT_BE ((void *)(digest + 3 * mhd_SHA512_256_BYTES_IN_WORD), \ ctx->H[3]); } } diff --git a/src/mhd2/stream_funcs.c b/src/mhd2/stream_funcs.c @@ -110,10 +110,10 @@ mhd_stream_alloc_memory (struct MHD_Connection *restrict c, { char *buf; const size_t new_buf_size = c->write_buffer_size - need_to_be_freed; - buf = (char *) mhd_pool_reallocate (pool, - c->write_buffer, - c->write_buffer_size, - new_buf_size); + buf = (char *)mhd_pool_reallocate (pool, + c->write_buffer, + c->write_buffer_size, + new_buf_size); mhd_assert (c->write_buffer == buf); mhd_assert (c->write_buffer_append_offset <= new_buf_size); mhd_assert (c->write_buffer_send_offset <= new_buf_size); @@ -131,10 +131,10 @@ mhd_stream_alloc_memory (struct MHD_Connection *restrict c, { char *buf; const size_t new_buf_size = c->read_buffer_size - need_to_be_freed; - buf = (char *) mhd_pool_reallocate (pool, - c->read_buffer, - c->read_buffer_size, - new_buf_size); + buf = (char *)mhd_pool_reallocate (pool, + c->read_buffer, + c->read_buffer_size, + new_buf_size); mhd_assert (c->read_buffer == buf); mhd_assert (c->read_buffer_offset <= new_buf_size); c->read_buffer_size = new_buf_size; @@ -181,7 +181,7 @@ mhd_stream_shrink_read_buffer (struct MHD_Connection *restrict c) new_buf = mhd_pool_reallocate (c->pool, c->read_buffer, c->read_buffer_size, c->read_buffer_offset); mhd_assert (c->read_buffer == new_buf); - c->read_buffer = (char *) new_buf; + c->read_buffer = (char *)new_buf; c->read_buffer_size = c->read_buffer_offset; } } @@ -207,15 +207,15 @@ mhd_stream_maximize_write_buffer (struct MHD_Connection *restrict c) * mhd_pool_reallocate () may return the new position only if buffer was * allocated 'from_end' or is not the last allocation, * which should not happen. */ - mhd_assert ((NULL == c->write_buffer) || \ - mhd_pool_is_resizable_inplace (pool, c->write_buffer, \ - c->write_buffer_size)); + mhd_assert ((NULL == c->write_buffer) \ + || mhd_pool_is_resizable_inplace (pool, c->write_buffer, \ + c->write_buffer_size)); new_buf = mhd_pool_reallocate (pool, c->write_buffer, c->write_buffer_size, new_size); mhd_assert ((c->write_buffer == new_buf) || (NULL == c->write_buffer)); - c->write_buffer = (char *) new_buf; + c->write_buffer = (char *)new_buf; c->write_buffer_size = new_size; if (c->write_buffer_send_offset == c->write_buffer_append_offset) { @@ -318,7 +318,7 @@ mhd_stream_release_write_buffer (struct MHD_Connection *restrict c) MHD_INTERNAL -MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4,3) unsigned int +MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4, 3) unsigned int mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, enum MHD_ProcRecvDataStage stage, size_t add_element_size, @@ -339,8 +339,8 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, { mhd_assert (NULL != c->rq.field_lines.start); opt_headers_size = - (size_t) ((c->read_buffer + c->read_buffer_offset) - - c->rq.field_lines.start); + (size_t)((c->read_buffer + c->read_buffer_offset) + - c->rq.field_lines.start); } else opt_headers_size = c->rq.field_lines.size; @@ -353,8 +353,8 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, The return status code works as a suggestion for the client to reduce one of the request elements. */ - if ((MHD_PROC_RECV_BODY_CHUNKED == stage) && - (MHD_MIN_REASONABLE_REQ_CHUNK_LINE_LENGTH_ < add_element_size)) + if ((MHD_PROC_RECV_BODY_CHUNKED == stage) + && (MHD_MIN_REASONABLE_REQ_CHUNK_LINE_LENGTH_ < add_element_size)) { /* Request could be re-tried easily with smaller chunk sizes */ return MHD_HTTP_STATUS_CONTENT_TOO_LARGE; @@ -371,20 +371,20 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, mhd_SSTR_LEN (MHD_HTTP_HEADER_HOST); const bool is_host_header = (header_host_key_len + 1 <= add_element_size) - && ( (0 == add_element[header_host_key_len]) - || (':' == add_element[header_host_key_len]) ) + && ((0 == add_element[header_host_key_len]) + || (':' == add_element[header_host_key_len])) && mhd_str_equal_caseless_bin_n (MHD_HTTP_HEADER_HOST, add_element, header_host_key_len); if (is_host_header) { - const bool is_parsed = ! ( - (mhd_HTTP_STAGE_HEADERS_RECEIVED > c->stage) && - (add_element_size == c->read_buffer_offset) && - (c->read_buffer == add_element) ); + const bool is_parsed = !( + (mhd_HTTP_STAGE_HEADERS_RECEIVED > c->stage) + && (add_element_size == c->read_buffer_offset) + && (c->read_buffer == add_element)); size_t actual_element_size; - mhd_assert (! is_parsed || (0 == add_element[header_host_key_len])); + mhd_assert (!is_parsed || (0 == add_element[header_host_key_len])); /* The actual size should be larger due to CRLF or LF chars, however the exact termination sequence is not known here and as perfect precision is not required, to simplify the code @@ -439,7 +439,7 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, mhd_assert (method_size == strlen (c->rq.method.cstr)); } - if ((size_t) MHD_MAX_REASONABLE_HEADERS_SIZE_ < opt_headers_size) + if ((size_t)MHD_MAX_REASONABLE_HEADERS_SIZE_ < opt_headers_size) { /* Typically the easiest way to reduce request header size is a removal of some optional headers. */ @@ -458,7 +458,7 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, return MHD_HTTP_STATUS_NOT_IMPLEMENTED; /* The length of the HTTP request method is unreasonably large */ } } - if ((size_t) MHD_MAX_REASONABLE_REQ_TARGET_SIZE_ < uri_size) + if ((size_t)MHD_MAX_REASONABLE_REQ_TARGET_SIZE_ < uri_size) { /* If request target size if larger than maximum reasonable size recommend client to reduce the request target size (length). */ @@ -470,7 +470,7 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, /* The read buffer is too small to handle reasonably large requests */ - if ((size_t) MHD_MIN_REASONABLE_HEADERS_SIZE_ < opt_headers_size) + if ((size_t)MHD_MIN_REASONABLE_HEADERS_SIZE_ < opt_headers_size) { /* Recommend application to retry with minimal headers */ if ((opt_headers_size * 4) > uri_size) @@ -488,7 +488,7 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, return MHD_HTTP_STATUS_NOT_IMPLEMENTED; /* The length of the HTTP request method is unreasonably large */ } } - if ((size_t) MHD_MIN_REASONABLE_REQ_TARGET_SIZE_ < uri_size) + if ((size_t)MHD_MIN_REASONABLE_REQ_TARGET_SIZE_ < uri_size) { /* Recommend application to retry with a shorter request target */ if (uri_size > method_size * 4) @@ -497,7 +497,7 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, return MHD_HTTP_STATUS_NOT_IMPLEMENTED; /* The length of the HTTP request method is unreasonably large */ } - if ((size_t) MHD_MIN_REASONABLE_REQ_METHOD_SIZE_ < method_size) + if ((size_t)MHD_MIN_REASONABLE_REQ_METHOD_SIZE_ < method_size) { /* The request target (URI) and headers are (reasonably) very small. Some non-standard long request method is used. */ @@ -547,10 +547,10 @@ mhd_stream_finish_req_serving (struct MHD_Connection *restrict c, { struct MHD_Daemon *const restrict d = c->daemon; - if (! reuse) + if (!reuse) { - mhd_assert (! c->stop_with_error || (NULL == c->rp.response) || \ - (c->rp.response->cfg.int_err_resp)); + mhd_assert (!c->stop_with_error || (NULL == c->rp.response) \ + || (c->rp.response->cfg.int_err_resp)); /* Next function will notify client and set connection * state to "PRE-CLOSING" */ @@ -565,13 +565,13 @@ mhd_stream_finish_req_serving (struct MHD_Connection *restrict c, { /* Reset connection to process the next request */ size_t new_read_buf_size; - mhd_assert (! c->stop_with_error); - mhd_assert (! c->discard_request); + mhd_assert (!c->stop_with_error); + mhd_assert (!c->discard_request); mhd_assert (NULL == c->rq.cntn.lbuf.data); #if 0 // TODO: notification callback - if ( (NULL != d->notify_completed) && - (c->rq.app_aware) ) + if ((NULL != d->notify_completed) + && (c->rq.app_aware)) d->notify_completed (d->notify_completed_cls, c, &c->rq.app_context, @@ -604,9 +604,9 @@ mhd_stream_finish_req_serving (struct MHD_Connection *restrict c, #ifndef HAVE_NULL_PTR_ALL_ZEROS // TODO: move request reset to special function mhd_DLINKEDL_INIT_LIST (&(c->rq), fields); -#ifdef MHD_SUPPORT_POST_PARSER +# ifdef MHD_SUPPORT_POST_PARSER mhd_DLINKEDL_INIT_LIST (&(c->rq), post_fields); -#endif /* MHD_SUPPORT_POST_PARSER */ +# endif /* MHD_SUPPORT_POST_PARSER */ c->rq.version = NULL; c->rq.url = NULL; c->rq.field_lines.start = NULL; @@ -633,10 +633,10 @@ mhd_stream_finish_req_serving (struct MHD_Connection *restrict c, new_read_buf_size = c->read_buffer_offset; c->read_buffer - = (char *) mhd_pool_reset (c->pool, - c->read_buffer, - c->read_buffer_offset, - new_read_buf_size); + = (char *)mhd_pool_reset (c->pool, + c->read_buffer, + c->read_buffer_offset, + new_read_buf_size); c->read_buffer_size = new_read_buf_size; } c->rq.app_context = NULL; @@ -654,23 +654,23 @@ conn_start_socket_closing (struct MHD_Connection *restrict c, if (close_hard) { /* Use abortive closing, send RST to remote to indicate a problem */ - (void) mhd_socket_set_hard_close (c->sk.fd); + (void)mhd_socket_set_hard_close (c->sk.fd); c->stage = mhd_HTTP_STAGE_PRE_CLOSING; c->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; return false; } - mhd_assert (c->sk.state.rmt_shut_wr || \ - ! mhd_SOCKET_ERR_IS_HARD (c->sk.state.discnt_err)); + mhd_assert (c->sk.state.rmt_shut_wr \ + || !mhd_SOCKET_ERR_IS_HARD (c->sk.state.discnt_err)); - need_lingering = ! c->sk.state.rmt_shut_wr; + need_lingering = !c->sk.state.rmt_shut_wr; if (need_lingering) { #ifdef MHD_SUPPORT_HTTPS if (mhd_C_HAS_TLS (c)) { - if ((0 != (((unsigned int) c->sk.ready) + if ((0 != (((unsigned int)c->sk.ready) & mhd_SOCKET_NET_STATE_SEND_READY)) || c->sk.props.is_nonblck) need_lingering = @@ -682,7 +682,7 @@ conn_start_socket_closing (struct MHD_Connection *restrict c, { need_lingering = mhd_socket_shut_wr (c->sk.fd); if (need_lingering) - need_lingering = (! c->sk.state.rmt_shut_wr); /* Skip as already closed */ + need_lingering = (!c->sk.state.rmt_shut_wr); /* Skip as already closed */ } } @@ -698,16 +698,16 @@ conn_h2_start_closing (struct MHD_Connection *restrict c, { mhd_assert (mhd_C_IS_HTTP2 (c)); mhd_assert (c->h2.dbg.h2_deinited); - mhd_assert (! c->rq.app_aware); + mhd_assert (!c->rq.app_aware); conn_start_socket_closing (c, close_hard); mhd_conn_deinit_activity_timeout (c); -#ifndef NDEBUG +# ifndef NDEBUG c->dbg.closing_started = true; -#endif +# endif } @@ -728,8 +728,8 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c, #ifdef MHD_USE_TRACE_CONN_ADD_CLOSE fprintf (stderr, "&&& mhd_conn_start_closing([FD: %2llu], %u, %s%s%s)...\n", - (unsigned long long) c->sk.fd, - (unsigned int) reason, + (unsigned long long)c->sk.fd, + (unsigned int)reason, log_msg ? "\"" : "", log_msg ? log_msg : "[NULL]", log_msg ? "\"" : ""); @@ -738,10 +738,10 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c, #ifdef MHD_SUPPORT_HTTP2 if (mhd_C_IS_HTTP2 (c)) { - mhd_assert ((mhd_CONN_CLOSE_TIMEDOUT == reason) || - (mhd_CONN_CLOSE_DAEMON_SHUTDOWN == reason) || - (mhd_CONN_CLOSE_H2_CLOSE_SOFT == reason) || - (mhd_CONN_CLOSE_H2_CLOSE_HARD == reason)); + mhd_assert ((mhd_CONN_CLOSE_TIMEDOUT == reason) + || (mhd_CONN_CLOSE_DAEMON_SHUTDOWN == reason) + || (mhd_CONN_CLOSE_H2_CLOSE_SOFT == reason) + || (mhd_CONN_CLOSE_H2_CLOSE_HARD == reason)); mhd_assert (NULL == log_msg); conn_h2_start_closing (c, reason != mhd_CONN_CLOSE_H2_CLOSE_SOFT); @@ -759,18 +759,18 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c, close_hard = true; end_code = MHD_REQUEST_ENDED_HTTP_PROTOCOL_ERROR; sc = MHD_SC_REQ_MALFORMED; - mhd_assert (! reply_sending_aborted); + mhd_assert (!reply_sending_aborted); break; case mhd_CONN_CLOSE_NO_POOL_MEM_FOR_REQUEST: close_hard = true; end_code = MHD_REQUEST_ENDED_NO_RESOURCES; - mhd_assert (! reply_sending_aborted); + mhd_assert (!reply_sending_aborted); break; case mhd_CONN_CLOSE_CLIENT_SHUTDOWN_EARLY: close_hard = true; end_code = MHD_REQUEST_ENDED_CLIENT_ABORT; sc = MHD_SC_CLIENT_SHUTDOWN_EARLY; - mhd_assert (! reply_sending_aborted); + mhd_assert (!reply_sending_aborted); break; case mhd_CONN_CLOSE_H2_PREFACE_MISSING: close_hard = true; @@ -779,7 +779,7 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c, break; case mhd_CONN_CLOSE_NO_POOL_MEM_FOR_REPLY: close_hard = true; - end_code = (! c->stop_with_error || c->rq.too_large) ? + end_code = (!c->stop_with_error || c->rq.too_large) ? MHD_REQUEST_ENDED_NO_RESOURCES : MHD_REQUEST_ENDED_HTTP_PROTOCOL_ERROR; sc = MHD_SC_REPLY_POOL_ALLOCATION_FAILURE; @@ -838,7 +838,7 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c, close_hard = true; end_code = MHD_REQUEST_ENDED_NONCE_ERROR; sc = MHD_SC_REPLY_NONCE_ERROR; - mhd_assert (! reply_sending_aborted); + mhd_assert (!reply_sending_aborted); break; #endif /* MHD_SUPPORT_AUTH_DIGEST */ @@ -981,7 +981,7 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c, if (conn_start_socket_closing (c, close_hard)) { - (void) 0; // TODO: start local lingering phase + (void)0; // TODO: start local lingering phase c->stage = mhd_HTTP_STAGE_PRE_CLOSING; // TODO: start local lingering phase c->event_loop_info = MHD_EVENT_LOOP_INFO_CLEANUP; // TODO: start local lingering phase } @@ -998,26 +998,26 @@ mhd_conn_start_closing (struct MHD_Connection *restrict c, mhd_LOG_MSG (c->daemon, sc, log_msg); } #else /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ - (void) log_msg; /* Mute compiler warning */ - (void) sc; /* Mute compiler warning */ + (void)log_msg; /* Mute compiler warning */ + (void)sc; /* Mute compiler warning */ #endif /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ #if 0 // TODO: notification callback - mhd_assert ((mhd_HTTP_STAGE_INIT != c->stage) || (! c->rq.app_aware)); - if ( (NULL != d->notify_completed) && - (c->rq.app_aware) ) + mhd_assert ((mhd_HTTP_STAGE_INIT != c->stage) || (!c->rq.app_aware)); + if ((NULL != d->notify_completed) + && (c->rq.app_aware)) d->notify_completed (d->notify_completed_cls, c, &c->rq.app_context, MHD_REQUEST_ENDED_COMPLETED_OK); #else - (void) end_code; + (void)end_code; #endif c->rq.app_aware = false; - if (! c->suspended) + if (!c->suspended) { - mhd_assert (! c->resuming); + mhd_assert (!c->resuming); mhd_conn_deinit_activity_timeout (c); } @@ -1048,7 +1048,7 @@ mhd_conn_pre_clean_part1 (struct MHD_Connection *restrict c) c->sk.fd, MHD_FD_STATE_NONE, c->events.extrn.app_cntx, - (struct MHD_EventUpdateContext *) c); + (struct MHD_EventUpdateContext *)c); if (NULL != c->events.extrn.app_cntx) mhd_log_extr_event_dereg_failed (d); } @@ -1123,7 +1123,7 @@ mhd_conn_pre_clean_part1 (struct MHD_Connection *restrict c) } } # endif /* MHD_SUPPORT_UPGRADE */ - (void) 0; + (void)0; } #endif /* MHD_SUPPORT_KQUEUE */ } @@ -1136,11 +1136,11 @@ mhd_conn_pre_clean (struct MHD_Connection *restrict c) #ifdef MHD_USE_TRACE_CONN_ADD_CLOSE fprintf (stderr, "&&& Closing connection, FD: %2llu\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_CONN_ADD_CLOSE */ mhd_assert (c->dbg.closing_started); - mhd_assert (! c->dbg.pre_cleaned); + mhd_assert (!c->dbg.pre_cleaned); #ifdef MHD_SUPPORT_UPGRADE if (NULL == c->upgr.c) diff --git a/src/mhd2/stream_funcs.h b/src/mhd2/stream_funcs.h @@ -128,7 +128,7 @@ mhd_stream_get_no_space_err_status_code (struct MHD_Connection *restrict c, enum MHD_ProcRecvDataStage stage, size_t add_element_size, const char *restrict add_element) -MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4,3); +MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_IN_SIZE_ (4, 3); /** * Switch connection from recv mode to send mode. @@ -330,9 +330,9 @@ MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_CSTR_ (3); * Abort the stream and log message */ #ifdef MHD_SUPPORT_LOG_FUNCTIONALITY -# define mhd_STREAM_ABORT(c,r,m) (mhd_conn_start_closing ((c),(r),(m))) +# define mhd_STREAM_ABORT(c, r, m) (mhd_conn_start_closing ((c),(r),(m))) #else /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ -# define mhd_STREAM_ABORT(c,r,m) (mhd_conn_start_closing ((c),(r),NULL)) +# define mhd_STREAM_ABORT(c, r, m) (mhd_conn_start_closing ((c),(r),NULL)) #endif /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ /** @@ -350,20 +350,20 @@ MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_CSTR_ (3); * Set the reason to "socket error" * @param c the connection for pre-closing */ -#define mhd_conn_start_closing_ext_event_failed(c) \ - mhd_conn_start_closing ((c), \ - mhd_CONN_CLOSE_EXTR_EVENT_REG_FAILED, \ - "The application failed to register FD for " \ - "the external events monitoring.") +# define mhd_conn_start_closing_ext_event_failed(c) \ + mhd_conn_start_closing ((c), \ + mhd_CONN_CLOSE_EXTR_EVENT_REG_FAILED, \ + "The application failed to register FD for " \ + "the external events monitoring.") #else /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ /** * Perform initial clean-up and mark for closing. * Set the reason to "socket error" * @param c the connection for pre-closing */ -#define mhd_conn_start_closing_ext_event_failed(c) \ - mhd_conn_start_closing ((c), \ - mhd_CONN_CLOSE_EXTR_EVENT_REG_FAILED, NULL) +# define mhd_conn_start_closing_ext_event_failed(c) \ + mhd_conn_start_closing ((c), \ + mhd_CONN_CLOSE_EXTR_EVENT_REG_FAILED, NULL) #endif /* ! MHD_SUPPORT_LOG_FUNCTIONALITY */ /** @@ -413,14 +413,14 @@ MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_CSTR_ (3); * @param c the connection for preparing */ # define mhd_conn_pre_upgrade(c) \ - mhd_conn_start_closing ((c), mhd_CONN_CLOSE_UPGRADE, NULL) + mhd_conn_start_closing ((c), mhd_CONN_CLOSE_UPGRADE, NULL) #endif /* MHD_SUPPORT_UPGRADE */ #ifdef MHD_SUPPORT_HTTP2 # define mhd_conn_start_closing_h2_soft(c) \ - mhd_conn_start_closing ((c), mhd_CONN_CLOSE_H2_CLOSE_SOFT, NULL) + mhd_conn_start_closing ((c), mhd_CONN_CLOSE_H2_CLOSE_SOFT, NULL) # define mhd_conn_start_closing_h2_hard(c) \ - mhd_conn_start_closing ((c), mhd_CONN_CLOSE_H2_CLOSE_HARD, NULL) + mhd_conn_start_closing ((c), mhd_CONN_CLOSE_H2_CLOSE_HARD, NULL) #endif /* MHD_SUPPORT_HTTP2 */ diff --git a/src/mhd2/stream_process_reply.c b/src/mhd2/stream_process_reply.c @@ -162,23 +162,23 @@ get_conn_reuse (struct MHD_Connection *c) if (mhd_CONN_MUST_CLOSE == c->conn_reuse) return mhd_CONN_MUST_CLOSE; - mhd_assert ( (! c->stop_with_error) || (c->discard_request)); + mhd_assert ((!c->stop_with_error) || (c->discard_request)); if ((c->sk.state.rmt_shut_wr) || (c->discard_request)) return mhd_CONN_MUST_CLOSE; if (rp->cfg.close_forced) return mhd_CONN_MUST_CLOSE; - mhd_assert ((MHD_SIZE_UNKNOWN != rp->cntn_size) || \ - (! rp->cfg.mode_1_0)); + mhd_assert ((MHD_SIZE_UNKNOWN != rp->cntn_size) \ + || (!rp->cfg.mode_1_0)); - if (! MHD_HTTP_VERSION_IS_1X (c->rq.http_ver)) + if (!MHD_HTTP_VERSION_IS_1X (c->rq.http_ver)) return mhd_CONN_MUST_CLOSE; - if (rp->cfg.mode_1_0 && - ! mhd_stream_has_header_token_st (c, - MHD_HTTP_HEADER_CONNECTION, - "keep-alive")) + if (rp->cfg.mode_1_0 + && !mhd_stream_has_header_token_st (c, + MHD_HTTP_HEADER_CONNECTION, + "keep-alive")) return mhd_CONN_MUST_CLOSE; #if 0 // def MHD_SUPPORT_UPGRADE // TODO: Implement upgrade support @@ -190,7 +190,7 @@ get_conn_reuse (struct MHD_Connection *c) mhd_assert (0 == (r->flags_auto & MHD_RAF_HAS_CONNECTION_CLOSE)); /* Valid HTTP version is enforced by 'MHD_queue_response()' */ mhd_assert (MHD_IS_HTTP_VER_SUPPORTED (c->rq.http_ver)); - mhd_assert (! c->stop_with_error); + mhd_assert (!c->stop_with_error); return mhd_CONN_MUST_UPGRADE; } #endif /* MHD_SUPPORT_UPGRADE */ @@ -225,18 +225,18 @@ is_reply_body_needed (struct MHD_Connection *restrict c, #if 0 /* This check is not needed as upgrade handler is used only with code 101 */ -#ifdef MHD_SUPPORT_UPGRADE +# ifdef MHD_SUPPORT_UPGRADE if (NULL != rp.response->upgrade_handler) return RP_BODY_NONE; -#endif /* MHD_SUPPORT_UPGRADE */ +# endif /* MHD_SUPPORT_UPGRADE */ #endif #if 0 /* CONNECT is not supported by MHD */ /* Successful responses for connect requests are filtered by * MHD_queue_response() */ - if ( (mhd_HTTP_METHOD_CONNECT == c->rq.http_mthd) && - (2 == rcode / 100) ) + if ((mhd_HTTP_METHOD_CONNECT == c->rq.http_mthd) + && (2 == rcode / 100)) return false; /* Actually pass-through CONNECT is not supported by MHD */ #endif @@ -282,8 +282,8 @@ setup_reply_properties (struct MHD_Connection *restrict c) c->rp.props.use_reply_body_headers = (use_rp_body >= RP_BODY_HEADERS_ONLY); #if 0 // def MHD_SUPPORT_UPGRADE // TODO: upgrade support - mhd_assert ( (NULL == r->upgrade_handler) || - (RP_BODY_NONE == use_rp_body) ); + mhd_assert ((NULL == r->upgrade_handler) + || (RP_BODY_NONE == use_rp_body)); #endif /* MHD_SUPPORT_UPGRADE */ use_chunked = false; @@ -292,12 +292,12 @@ setup_reply_properties (struct MHD_Connection *restrict c) { if (r->cfg.chunked) { - mhd_assert (! r->cfg.mode_1_0); + mhd_assert (!r->cfg.mode_1_0); use_chunked = MHD_HTTP_VERSION_IS_LIKE_11 (c->rq.http_ver); } - if ((MHD_SIZE_UNKNOWN == r->cntn_size) && - (! use_chunked) && - (c->rp.props.send_reply_body)) + if ((MHD_SIZE_UNKNOWN == r->cntn_size) + && (!use_chunked) + && (c->rp.props.send_reply_body)) { /* End of the stream is indicated by closure */ end_by_closing = true; @@ -314,7 +314,7 @@ setup_reply_properties (struct MHD_Connection *restrict c) c->rp.props.chunked = use_chunked; c->rp.props.end_by_closing = end_by_closing; - if ((! c->rp.props.send_reply_body) || (0 == r->cntn_size)) + if ((!c->rp.props.send_reply_body) || (0 == r->cntn_size)) c->rp.cntn_loc = mhd_REPLY_CNTN_LOC_NOWHERE; else if (c->rp.props.chunked) c->rp.cntn_loc = mhd_REPLY_CNTN_LOC_CONN_BUF; @@ -371,24 +371,24 @@ check_connection_reply (struct MHD_Connection *restrict c) mhd_assert (c->rp.props.set); - if ( (! c->rp.props.use_reply_body_headers) && - (0 != r->cntn_size) ) + if ((!c->rp.props.use_reply_body_headers) + && (0 != r->cntn_size)) { mhd_LOG_PRINT (c->daemon, MHD_SC_REPLY_NOT_EMPTY_RESPONSE, mhd_LOG_FMT ("This reply with response code %u " \ "cannot use reply content. Non-empty " \ "response content is ignored and not used."), - (unsigned) (c->rp.response->sc)); + (unsigned)(c->rp.response->sc)); } - if ( (! c->rp.props.use_reply_body_headers) && - (r->cfg.cnt_len_by_app) ) + if ((!c->rp.props.use_reply_body_headers) + && (r->cfg.cnt_len_by_app)) { mhd_LOG_PRINT (c->daemon, MHD_SC_REPLY_CONTENT_LENGTH_NOT_ALLOWED, mhd_LOG_FMT ("This reply with response code %u " \ "cannot use reply content. Application " \ "defined \"Content-Length\" header " \ "violates HTTP specification."), - (unsigned) (c->rp.response->sc)); + (unsigned)(c->rp.response->sc)); } } @@ -408,12 +408,12 @@ mhd_build_date_str (char date[MHD_FN_PAR_FIX_ARR_SIZE_ (29)]) struct tm now; time_t t; const char *src; -#if ! defined(HAVE_C11_GMTIME_S) && ! defined(HAVE_W32_GMTIME_S) && \ - ! defined(HAVE_GMTIME_R) +#if !defined(HAVE_C11_GMTIME_S) && !defined(HAVE_W32_GMTIME_S) && \ + !defined(HAVE_GMTIME_R) struct tm *pNow; #endif - if ((time_t) -1 == time (&t)) + if ((time_t)-1 == time (&t)) return false; #if defined(HAVE_GMTIME_R) if (NULL == gmtime_r (&t, @@ -442,7 +442,7 @@ mhd_build_date_str (char date[MHD_FN_PAR_FIX_ARR_SIZE_ (29)]) date[3] = ','; date[4] = ' '; /* Day of the month */ - if (2 != mhd_uint8_to_str_pad ((uint8_t) now.tm_mday, 2, + if (2 != mhd_uint8_to_str_pad ((uint8_t)now.tm_mday, 2, date + 5, buf_len - 5)) return false; date[7] = ' '; @@ -453,16 +453,16 @@ mhd_build_date_str (char date[MHD_FN_PAR_FIX_ARR_SIZE_ (29)]) date[10] = src[2]; date[11] = ' '; /* Year */ - if (4 != mhd_uint16_to_str ((uint_least16_t) (1900 + now.tm_year), date + 12, + if (4 != mhd_uint16_to_str ((uint_least16_t)(1900 + now.tm_year), date + 12, buf_len - 12)) return false; date[16] = ' '; /* Time */ - mhd_uint8_to_str_pad ((uint8_t) now.tm_hour, 2, date + 17, buf_len - 17); + mhd_uint8_to_str_pad ((uint8_t)now.tm_hour, 2, date + 17, buf_len - 17); date[19] = ':'; - mhd_uint8_to_str_pad ((uint8_t) now.tm_min, 2, date + 20, buf_len - 20); + mhd_uint8_to_str_pad ((uint8_t)now.tm_min, 2, date + 20, buf_len - 20); date[22] = ':'; - mhd_uint8_to_str_pad ((uint8_t) now.tm_sec, 2, date + 23, buf_len - 23); + mhd_uint8_to_str_pad ((uint8_t)now.tm_sec, 2, date + 23, buf_len - 23); date[25] = ' '; date[26] = 'G'; date[27] = 'M'; @@ -489,7 +489,7 @@ get_date_header (char *header) header[3] = 'e'; header[4] = ':'; header[5] = ' '; - if (! mhd_build_date_str (header + 6)) + if (!mhd_build_date_str (header + 6)) { header[0] = 0; return false; @@ -586,8 +586,8 @@ add_user_headers (char *restrict buf, struct mhd_ResponseHeader *hdr; /**< Iterates through User-specified headers */ size_t el_size; /**< the size of current element to be added to the @a buf */ - mhd_assert (! add_close || ! add_keep_alive); - mhd_assert (! add_keep_alive || ! add_close); + mhd_assert (!add_close || !add_keep_alive); + mhd_assert (!add_keep_alive || !add_close); if (r->cfg.has_hdr_conn) { @@ -690,7 +690,7 @@ add_user_headers (char *restrict buf, * @return true if data has been added and position has been updated, * false if not enough space is available */ -#define buffer_append_s(buf,buf_size,ppos,str) \ +#define buffer_append_s(buf, buf_size, ppos, str) \ buffer_append ((buf),(buf_size),(ppos),(str),mhd_SSTR_LEN (str)) @@ -704,7 +704,7 @@ add_user_headers (char *restrict buf, * @return true if data has been added and position has been updated, * false if not enough space is available */ -#define buffer_append_mstr(buf,buf_size,ppos,pmhdstr) \ +#define buffer_append_mstr(buf, buf_size, ppos, pmhdstr) \ buffer_append ((buf),(buf_size),(ppos), \ (pmhdstr)->cstr, (pmhdstr)->len) @@ -735,28 +735,28 @@ build_header_response_inn (struct MHD_Connection *restrict c) setup_reply_properties (c); mhd_assert (c->rp.props.set); - mhd_assert ((mhd_CONN_MUST_CLOSE == c->conn_reuse) || \ - (mhd_CONN_KEEPALIVE_POSSIBLE == c->conn_reuse) || \ - (mhd_CONN_MUST_UPGRADE == c->conn_reuse)); + mhd_assert ((mhd_CONN_MUST_CLOSE == c->conn_reuse) \ + || (mhd_CONN_KEEPALIVE_POSSIBLE == c->conn_reuse) \ + || (mhd_CONN_MUST_UPGRADE == c->conn_reuse)); #if 0 // def MHD_SUPPORT_UPGRADE // TODO: upgrade support - mhd_assert ((NULL == r->upgrade_handler) || \ - (mhd_CONN_MUST_UPGRADE == c->keepalive)); + mhd_assert ((NULL == r->upgrade_handler) \ + || (mhd_CONN_MUST_UPGRADE == c->keepalive)); #else /* ! MHD_SUPPORT_UPGRADE */ mhd_assert (mhd_CONN_MUST_UPGRADE != c->conn_reuse); #endif /* ! MHD_SUPPORT_UPGRADE */ - mhd_assert ((! c->rp.props.chunked) || c->rp.props.use_reply_body_headers); - mhd_assert ((! c->rp.props.send_reply_body) || \ - c->rp.props.use_reply_body_headers); - mhd_assert ((! c->rp.props.end_by_closing) || \ - (mhd_CONN_MUST_CLOSE == c->conn_reuse)); + mhd_assert ((!c->rp.props.chunked) || c->rp.props.use_reply_body_headers); + mhd_assert ((!c->rp.props.send_reply_body) \ + || c->rp.props.use_reply_body_headers); + mhd_assert ((!c->rp.props.end_by_closing) \ + || (mhd_CONN_MUST_CLOSE == c->conn_reuse)); #if 0 // def MHD_SUPPORT_UPGRADE // TODO: upgrade support - mhd_assert (NULL == r->upgrade_handler || \ - ! c->rp.props.use_reply_body_headers); + mhd_assert (NULL == r->upgrade_handler \ + || !c->rp.props.use_reply_body_headers); #endif /* MHD_SUPPORT_UPGRADE */ check_connection_reply (c); - rcode = (uint_fast16_t) c->rp.response->sc; + rcode = (uint_fast16_t)c->rp.response->sc; if (mhd_CONN_MUST_CLOSE == c->conn_reuse) { /* The closure of connection must be always indicated by header @@ -766,14 +766,14 @@ build_header_response_inn (struct MHD_Connection *restrict c) } else if (mhd_CONN_KEEPALIVE_POSSIBLE == c->conn_reuse) { - mhd_assert (! r->cfg.mode_1_0); + mhd_assert (!r->cfg.mode_1_0); use_conn_close = false; /* Add "Connection: keep-alive" if request is HTTP/1.0 or * if reply is HTTP/1.0 * For HTTP/1.1 add header only if explicitly requested by app * (by response flag), as "Keep-Alive" is default for HTTP/1.1. */ - if (r->cfg.mode_1_0 || - (MHD_HTTP_VERSION_1_0 == c->rq.http_ver)) + if (r->cfg.mode_1_0 + || (MHD_HTTP_VERSION_1_0 == c->rq.http_ver)) use_conn_k_alive = true; else use_conn_k_alive = false; @@ -799,24 +799,24 @@ build_header_response_inn (struct MHD_Connection *restrict c) /* * The status line * */ /* The HTTP version */ - if (! c->rp.responseIcy) + if (!c->rp.responseIcy) { /* HTTP reply */ - if (! r->cfg.mode_1_0) + if (!r->cfg.mode_1_0) { /* HTTP/1.1 reply */ /* Use HTTP/1.1 responses for HTTP/1.0 clients. * See https://datatracker.ietf.org/doc/html/rfc7230#section-2.6 */ - if (! buffer_append_s (buf, buf_size, &pos, MHD_HTTP_VERSION_1_1_STR)) + if (!buffer_append_s (buf, buf_size, &pos, MHD_HTTP_VERSION_1_1_STR)) return false; } else { /* HTTP/1.0 reply */ - if (! buffer_append_s (buf, buf_size, &pos, MHD_HTTP_VERSION_1_0_STR)) + if (!buffer_append_s (buf, buf_size, &pos, MHD_HTTP_VERSION_1_0_STR)) return false; } } else { /* ICY reply */ - if (! buffer_append_s (buf, buf_size, &pos, "ICY")) + if (!buffer_append_s (buf, buf_size, &pos, "ICY")) return false; } @@ -826,7 +826,7 @@ build_header_response_inn (struct MHD_Connection *restrict c) if (buf_size < pos + 5) /* space + code + space */ return false; buf[pos++] = ' '; - pos += mhd_uint16_to_str ((uint16_t) rcode, buf + pos, + pos += mhd_uint16_to_str ((uint16_t)rcode, buf + pos, buf_size - pos); buf[pos++] = ' '; @@ -836,15 +836,15 @@ build_header_response_inn (struct MHD_Connection *restrict c) const struct MHD_String *stat_str; stat_str = mhd_HTTP_status_code_to_string_int (rcode); mhd_assert (0 != stat_str->len); - if (! buffer_append (buf, buf_size, &pos, - stat_str->cstr, - stat_str->len)) + if (!buffer_append (buf, buf_size, &pos, + stat_str->cstr, + stat_str->len)) return false; } /* The linefeed */ - if (! buffer_append_crlf (buf, - buf_size, - &pos)) + if (!buffer_append_crlf (buf, + buf_size, + &pos)) return false; /* * The headers * */ @@ -853,21 +853,21 @@ build_header_response_inn (struct MHD_Connection *restrict c) if (0 != r->special_resp.spec_hdr_len) { mhd_assert (r->cfg.int_err_resp); - if (! buffer_append (buf, buf_size, &pos, - r->special_resp.spec_hdr, - r->special_resp.spec_hdr_len)) + if (!buffer_append (buf, buf_size, &pos, + r->special_resp.spec_hdr, + r->special_resp.spec_hdr_len)) return false; - if (! buffer_append_crlf (buf, - buf_size, - &pos)) + if (!buffer_append_crlf (buf, + buf_size, + &pos)) return false; } /* Main automatic headers */ /* The "Date:" header */ - if ( (! r->cfg.has_hdr_date) && - (! c->daemon->req_cfg.suppress_date) ) + if ((!r->cfg.has_hdr_date) + && (!c->daemon->req_cfg.suppress_date)) { /* Additional byte for unused zero-termination */ if (mhd_COND_HARDLY_EVER (pos + 38 < 38)) /* Check for overflow */ @@ -878,20 +878,20 @@ build_header_response_inn (struct MHD_Connection *restrict c) pos += 37; } /* The "Connection:" header */ - mhd_assert (! use_conn_close || ! use_conn_k_alive); - mhd_assert (! use_conn_k_alive || ! use_conn_close); - if (! r->cfg.has_hdr_conn) + mhd_assert (!use_conn_close || !use_conn_k_alive); + mhd_assert (!use_conn_k_alive || !use_conn_close); + if (!r->cfg.has_hdr_conn) { if (use_conn_close) { - if (! buffer_append_s (buf, buf_size, &pos, - MHD_HTTP_HEADER_CONNECTION ": close\r\n")) + if (!buffer_append_s (buf, buf_size, &pos, + MHD_HTTP_HEADER_CONNECTION ": close\r\n")) return false; } else if (use_conn_k_alive) { - if (! buffer_append_s (buf, buf_size, &pos, - MHD_HTTP_HEADER_CONNECTION ": Keep-Alive\r\n")) + if (!buffer_append_s (buf, buf_size, &pos, + MHD_HTTP_HEADER_CONNECTION ": Keep-Alive\r\n")) return false; } use_conn_close = false; @@ -904,8 +904,8 @@ build_header_response_inn (struct MHD_Connection *restrict c) { char noncestr[mhd_AUTH_DIGEST_NONCE_LEN]; const struct mhd_RespAuthDigestHeader *dg_hdr; - if (! mhd_auth_digest_get_new_nonce (c, - noncestr)) + if (!mhd_auth_digest_get_new_nonce (c, + noncestr)) { mhd_STREAM_ABORT (c, mhd_CONN_CLOSE_NONCE_ERROR, @@ -918,8 +918,8 @@ build_header_response_inn (struct MHD_Connection *restrict c) { size_t nonce_pos; nonce_pos = pos + dg_hdr->nonce_pos; - if (! buffer_append_mstr (buf, buf_size, &pos, \ - &(dg_hdr->hdr))) + if (!buffer_append_mstr (buf, buf_size, &pos, \ + &(dg_hdr->hdr))) return false; memcpy (buf + nonce_pos, noncestr, @@ -930,10 +930,10 @@ build_header_response_inn (struct MHD_Connection *restrict c) /* User-defined headers */ - if (! add_user_headers (buf, &pos, buf_size, r, - ! c->rp.props.use_reply_body_headers, - use_conn_close, - use_conn_k_alive)) + if (!add_user_headers (buf, &pos, buf_size, r, + !c->rp.props.use_reply_body_headers, + use_conn_close, + use_conn_k_alive)) return false; /* Other automatic headers */ @@ -944,23 +944,23 @@ build_header_response_inn (struct MHD_Connection *restrict c) if (c->rp.props.chunked) { /* Chunked encoding is used */ - mhd_assert (! c->rp.props.end_by_closing); - if (! buffer_append_s (buf, buf_size, &pos, - MHD_HTTP_HEADER_TRANSFER_ENCODING ": " \ - "chunked\r\n")) + mhd_assert (!c->rp.props.end_by_closing); + if (!buffer_append_s (buf, buf_size, &pos, + MHD_HTTP_HEADER_TRANSFER_ENCODING ": " \ + "chunked\r\n")) return false; } else /* Chunked encoding is not used */ { - if ((MHD_SIZE_UNKNOWN != r->cntn_size) && - (! c->rp.props.end_by_closing) && - (! r->cfg.chunked) && - (! r->cfg.head_only)) + if ((MHD_SIZE_UNKNOWN != r->cntn_size) + && (!c->rp.props.end_by_closing) + && (!r->cfg.chunked) + && (!r->cfg.head_only)) { /* The size is known and can be indicated by the header */ - if (! r->cfg.cnt_len_by_app) + if (!r->cfg.cnt_len_by_app) { /* The response does not have app-defined "Content-Length" header */ - if (! buffer_append_s (buf, buf_size, &pos, - MHD_HTTP_HEADER_CONTENT_LENGTH ": ")) + if (!buffer_append_s (buf, buf_size, &pos, + MHD_HTTP_HEADER_CONTENT_LENGTH ": ")) return false; el_size = mhd_uint64_to_str (r->cntn_size, buf + pos, @@ -969,25 +969,25 @@ build_header_response_inn (struct MHD_Connection *restrict c) return false; pos += el_size; - if (! buffer_append_crlf (buf, - buf_size, - &pos)) + if (!buffer_append_crlf (buf, + buf_size, + &pos)) return false; } } else { - mhd_assert ((! c->rp.props.send_reply_body) || \ - (mhd_CONN_MUST_CLOSE == c->conn_reuse)); - (void) 0; + mhd_assert ((!c->rp.props.send_reply_body) \ + || (mhd_CONN_MUST_CLOSE == c->conn_reuse)); + (void)0; } } } /* * Header termination * */ - if (! buffer_append_crlf (buf, - buf_size, - &pos)) + if (!buffer_append_crlf (buf, + buf_size, + &pos)) return false; c->write_buffer_append_offset = pos; @@ -998,7 +998,7 @@ build_header_response_inn (struct MHD_Connection *restrict c) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool mhd_stream_build_header_response (struct MHD_Connection *restrict c) { - if (! build_header_response_inn (c)) + if (!build_header_response_inn (c)) { #ifdef MHD_SUPPORT_AUTH_DIGEST if (mhd_HTTP_STAGE_PRE_CLOSING <= c->stage) @@ -1038,10 +1038,10 @@ preprocess_dcc_action (struct MHD_Connection *restrict c, if (NULL != act) { - if ((a != act) || - ! mhd_DCC_ACTION_IS_VALID (c->rp.app_act.act) || - ((MHD_SIZE_UNKNOWN != c->rp.response->cntn_size) && - (mhd_DCC_ACTION_FINISH == c->rp.app_act.act))) + if ((a != act) + || !mhd_DCC_ACTION_IS_VALID (c->rp.app_act.act) + || ((MHD_SIZE_UNKNOWN != c->rp.response->cntn_size) + && (mhd_DCC_ACTION_FINISH == c->rp.app_act.act))) { mhd_LOG_MSG (c->daemon, MHD_SC_ACTION_INVALID, \ "Provided Dynamic Content Creator action is not " \ @@ -1172,7 +1172,7 @@ mhd_stream_prep_unchunked_body (struct MHD_Connection *restrict c) if (mhd_REPLY_CNTN_LOC_RESP_BUF == c->rp.cntn_loc) { - (void) 0; /* Nothing to do, buffers are ready */ + (void)0; /* Nothing to do, buffers are ready */ } else if (mhd_REPLY_CNTN_LOC_CONN_BUF == c->rp.cntn_loc) { @@ -1184,7 +1184,7 @@ mhd_stream_prep_unchunked_body (struct MHD_Connection *restrict c) size_t filled; if (size_to_fill > left_to_send) - size_to_fill = (size_t) left_to_send; + size_to_fill = (size_t)left_to_send; mhd_assert (c->write_buffer_append_offset < c->write_buffer_size); mhd_assert (NULL == c->rp.app_act_ctx.connection); @@ -1200,7 +1200,7 @@ mhd_stream_prep_unchunked_body (struct MHD_Connection *restrict c) (c->write_buffer + c->write_buffer_append_offset), size_to_fill); c->rp.app_act_ctx.connection = NULL; /* Block any attempt to create a new action */ - if (! preprocess_dcc_action (c, act)) + if (!preprocess_dcc_action (c, act)) return true; if (mhd_DCC_ACTION_FINISH == c->rp.app_act.act) { @@ -1233,13 +1233,13 @@ mhd_stream_prep_unchunked_body (struct MHD_Connection *restrict c) size_t filled; if (size_to_fill > left_to_send) - size_to_fill = (size_t) left_to_send; + size_to_fill = (size_t)left_to_send; - if (! read_response_file (c, - r, - size_to_fill, - c->write_buffer + c->write_buffer_append_offset, - &filled)) + if (!read_response_file (c, + r, + size_to_fill, + c->write_buffer + c->write_buffer_append_offset, + &filled)) return true; /* Error, the stream is closed */ c->rp.rsp_cntn_read_pos += filled; @@ -1281,7 +1281,7 @@ mhd_stream_prep_unchunked_body (struct MHD_Connection *restrict c) #if defined(mhd_USE_SENDFILE) else if (mhd_REPLY_CNTN_LOC_FILE == c->rp.cntn_loc) { - (void) 0; /* Nothing to do, file should be read directly */ + (void)0; /* Nothing to do, file should be read directly */ } #endif /* mhd_USE_SENDFILE */ else @@ -1342,13 +1342,13 @@ mhd_stream_prep_chunked_body (struct MHD_Connection *restrict c) if (max_chunk < size_to_fill) size_to_fill = max_chunk; if (left_to_send < size_to_fill) - size_to_fill = (size_t) left_to_send; + size_to_fill = (size_t)left_to_send; } else size_to_fill = 0; - if ((0 == left_to_send) && - (mhd_RESPONSE_CONTENT_DATA_CALLBACK != r->cntn_dtype)) + if ((0 == left_to_send) + && (mhd_RESPONSE_CONTENT_DATA_CALLBACK != r->cntn_dtype)) { c->stage = mhd_HTTP_STAGE_CHUNKED_BODY_SENT; return true; @@ -1356,9 +1356,9 @@ mhd_stream_prep_chunked_body (struct MHD_Connection *restrict c) else if (mhd_RESPONSE_CONTENT_DATA_BUFFER == r->cntn_dtype) { mhd_assert (size_to_fill <= \ - r->cntn_size - (size_t) c->rp.rsp_cntn_read_pos); + r->cntn_size - (size_t)c->rp.rsp_cntn_read_pos); memcpy (c->write_buffer + max_chunk_hdr_len, - r->cntn.buf + (size_t) c->rp.rsp_cntn_read_pos, + r->cntn.buf + (size_t)c->rp.rsp_cntn_read_pos, size_to_fill); filled = size_to_fill; } @@ -1379,7 +1379,7 @@ mhd_stream_prep_chunked_body (struct MHD_Connection *restrict c) (c->write_buffer + max_chunk_hdr_len), size_to_fill); c->rp.app_act_ctx.connection = NULL; /* Block any attempt to create a new action */ - if (! preprocess_dcc_action (c, act)) + if (!preprocess_dcc_action (c, act)) return true; if (mhd_DCC_ACTION_FINISH == c->rp.app_act.act) { @@ -1403,11 +1403,11 @@ mhd_stream_prep_chunked_body (struct MHD_Connection *restrict c) } else if (mhd_RESPONSE_CONTENT_DATA_FILE == r->cntn_dtype) { - if (! read_response_file (c, - r, - size_to_fill, - c->write_buffer + max_chunk_hdr_len, - &filled)) + if (!read_response_file (c, + r, + size_to_fill, + c->write_buffer + max_chunk_hdr_len, + &filled)) return true; /* Error, the stream is closed */ } else @@ -1416,7 +1416,7 @@ mhd_stream_prep_chunked_body (struct MHD_Connection *restrict c) filled = 0; } - chunk_hdr_len = mhd_uint32_to_strx ((uint_fast32_t) filled, + chunk_hdr_len = mhd_uint32_to_strx ((uint_fast32_t)filled, chunk_hdr, sizeof(chunk_hdr)); mhd_assert (chunk_hdr_len != 0); @@ -1512,7 +1512,7 @@ prep_chunked_footer_inn (struct MHD_Connection *restrict c) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool mhd_stream_prep_chunked_footer (struct MHD_Connection *restrict c) { - if (! prep_chunked_footer_inn (c)) + if (!prep_chunked_footer_inn (c)) { mhd_STREAM_ABORT (c, mhd_CONN_CLOSE_NO_POOL_MEM_FOR_REPLY, diff --git a/src/mhd2/stream_process_reply.h b/src/mhd2/stream_process_reply.h @@ -75,6 +75,7 @@ MHD_FN_PAR_NONNULL_ALL_; MHD_INTERNAL bool mhd_build_date_str (char date[MHD_FN_PAR_FIX_ARR_SIZE_ (29)]) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (1); + /** * Allocate the connection's write buffer and fill it with all of the * headers from the response. diff --git a/src/mhd2/stream_process_request.c b/src/mhd2/stream_process_request.c @@ -295,14 +295,14 @@ * Response text used when the request header is too big to be processed. */ #define ERR_RSP_REQUEST_HEADER_TOO_BIG \ - "<html>" \ - "<head><title>Request too big</title></head>" \ - "<body><p>The total size of the request headers, which includes the " \ - "request target and the request field lines, exceeds the memory " \ - "constraints of this web server.</p>" \ - "<p>The request could be re-tried with shorter field lines, a shorter " \ - "request target or a shorter request method token.</p></body>" \ - "</html>" + "<html>" \ + "<head><title>Request too big</title></head>" \ + "<body><p>The total size of the request headers, which includes the " \ + "request target and the request field lines, exceeds the memory " \ + "constraints of this web server.</p>" \ + "<p>The request could be re-tried with shorter field lines, a shorter " \ + "request target or a shorter request method token.</p></body>" \ + "</html>" /** * Response text used when the request header is too big to be processed. @@ -333,30 +333,30 @@ * cannot fit the buffer. */ #define ERR_RSP_REQUEST_CHUNK_LINE_EXT_TOO_BIG \ - "<html>" \ - "<head><title>Request too big</title></head>" \ - "<body><p>The total size of the request target, the request field lines " \ - "and the chunk size line exceeds the memory constraints of this web " \ - "server.</p>" \ - "<p>The request could be re-tried without chunk extensions, with a smaller " \ - "chunk size, shorter field lines, a shorter request target or a shorter " \ - "request method token.</p></body>" \ - "</html>" + "<html>" \ + "<head><title>Request too big</title></head>" \ + "<body><p>The total size of the request target, the request field lines " \ + "and the chunk size line exceeds the memory constraints of this web " \ + "server.</p>" \ + "<p>The request could be re-tried without chunk extensions, with a smaller " \ + "chunk size, shorter field lines, a shorter request target or a shorter " \ + "request method token.</p></body>" \ + "</html>" /** * Response text used when the request chunk size line without chunk extension * cannot fit the buffer. */ #define ERR_RSP_REQUEST_CHUNK_LINE_TOO_BIG \ - "<html>" \ - "<head><title>Request too big</title></head>" \ - "<body><p>The total size of the request target, the request field lines " \ - "and the chunk size line exceeds the memory constraints of this web " \ - "server.</p>" \ - "<p>The request could be re-tried with a smaller " \ - "chunk size, shorter field lines, a shorter request target or a shorter " \ - "request method token.</p></body>" \ - "</html>" + "<html>" \ + "<head><title>Request too big</title></head>" \ + "<body><p>The total size of the request target, the request field lines " \ + "and the chunk size line exceeds the memory constraints of this web " \ + "server.</p>" \ + "<p>The request could be re-tried with a smaller " \ + "chunk size, shorter field lines, a shorter request target or a shorter " \ + "request method token.</p></body>" \ + "</html>" /** * Response text used when the request (http header) does not @@ -414,11 +414,11 @@ * "Transfer-Encoding:" and "Content-Length:" */ #define ERR_RSP_REQUEST_CNTNLENGTH_WITH_TR_ENCODING \ - "<html>" \ - "<head><title>Malformed request</title></head>" \ - "<body>Wrong combination of the request headers: both Transfer-Encoding " \ - "and Content-Length headers are used at the same time.</body>" \ - "</html>" + "<html>" \ + "<head><title>Malformed request</title></head>" \ + "<body>Wrong combination of the request headers: both Transfer-Encoding " \ + "and Content-Length headers are used at the same time.</body>" \ + "</html>" /** * Response text used when the request HTTP content is too large. @@ -486,7 +486,7 @@ * @return enum mhd_HTTP_Method value */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (2,1) +MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PURE_ enum mhd_HTTP_Method mhd_parse_http_method (size_t len, const char mtd[MHD_FN_PAR_DYN_ARR_SIZE_ (len)]) @@ -605,7 +605,7 @@ enum MHD_FIXED_ENUM_MHD_SET_ mhd_HTTP_ProtVerParse * @param len the length of @a http_string in bytes * @param http_string the pointer to HTTP version string */ -static MHD_FN_PAR_IN_SIZE_ (2,1) MHD_FN_PAR_NONNULL_ALL_ +static MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PAR_NONNULL_ALL_ enum mhd_HTTP_ProtVerParse parse_http_version (size_t len, const char *restrict http_string) @@ -619,8 +619,8 @@ parse_http_version (size_t len, && (0 == memcmp ("HTTP/", h, 5u)) && ('.' == h[6])) { - const unsigned char mj = (unsigned char) (h[5] - '0'); /**< Major number */ - const unsigned char mn = (unsigned char) (h[7] - '0'); /**< Minor number */ + const unsigned char mj = (unsigned char)(h[5] - '0'); /**< Major number */ + const unsigned char mn = (unsigned char)(h[7] - '0'); /**< Minor number */ if (1u == mj) { @@ -655,7 +655,7 @@ parse_http_version (size_t len, * @return true if HTTP version is correct and supported, * false if HTTP version is not correct or unsupported. */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_NONNULL_ALL_ bool +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_NONNULL_ALL_ bool process_http_version (struct MHD_Connection *restrict connection, size_t len, const char *restrict http_string) @@ -673,7 +673,7 @@ process_http_version (struct MHD_Connection *restrict connection, return false; } - connection->rq.http_ver = (enum MHD_HTTP_ProtocolVersion) h_ver; + connection->rq.http_ver = (enum MHD_HTTP_ProtocolVersion)h_ver; switch (connection->rq.http_ver) { @@ -760,16 +760,16 @@ get_request_line_inner (struct MHD_Connection *restrict c) const bool bare_cr_keep = (wsp_in_uri_keep && (-3 >= discp_lvl)); /* Treat bare CR as space; replace it with space before processing. RFC 9112, section 2.2 */ - const bool bare_cr_as_sp = ((! bare_cr_keep) && (-1 >= discp_lvl)); + const bool bare_cr_as_sp = ((!bare_cr_keep) && (-1 >= discp_lvl)); - mhd_assert (mhd_HTTP_STAGE_INIT == c->stage || \ - mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage); - mhd_assert (NULL == c->rq.method.cstr || \ - mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage); - mhd_assert (mhd_HTTP_METHOD_NO_METHOD == c->rq.http_mthd || \ - mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage); - mhd_assert (mhd_HTTP_METHOD_NO_METHOD == c->rq.http_mthd || \ - 0 != c->rq.hdrs.rq_line.proc_pos); + mhd_assert (mhd_HTTP_STAGE_INIT == c->stage \ + || mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage); + mhd_assert (NULL == c->rq.method.cstr \ + || mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage); + mhd_assert (mhd_HTTP_METHOD_NO_METHOD == c->rq.http_mthd \ + || mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage); + mhd_assert (mhd_HTTP_METHOD_NO_METHOD == c->rq.http_mthd \ + || 0 != c->rq.hdrs.rq_line.proc_pos); if (0 == c->read_buffer_offset) { @@ -811,8 +811,8 @@ get_request_line_inner (struct MHD_Connection *restrict c) c->rq.hdrs.rq_line.skipped_empty_lines++; } } - else if (('\n' == c->read_buffer[0]) && - (bare_lf_as_crlf)) + else if (('\n' == c->read_buffer[0]) + && (bare_lf_as_crlf)) { is_empty_line = true; c->read_buffer += 1; @@ -822,10 +822,10 @@ get_request_line_inner (struct MHD_Connection *restrict c) } if (is_empty_line) { - if ((! skip_unlimited_empty_lines) && - (((unsigned int) ((skip_several_empty_lines) ? - MHD_MAX_EMPTY_LINES_SKIP : 1)) < - c->rq.hdrs.rq_line.skipped_empty_lines)) + if ((!skip_unlimited_empty_lines) + && (((unsigned int)((skip_several_empty_lines) ? + MHD_MAX_EMPTY_LINES_SKIP : 1)) < + c->rq.hdrs.rq_line.skipped_empty_lines)) { mhd_STREAM_ABORT (c, mhd_CONN_CLOSE_CLIENT_HTTP_ERR_ABORT_CONN, "Too many meaningless extra empty lines " \ @@ -865,11 +865,11 @@ get_request_line_inner (struct MHD_Connection *restrict c) end_of_line = false; - mhd_assert ((0 == c->rq.hdrs.rq_line.last_ws_end) || \ - (c->rq.hdrs.rq_line.last_ws_end > \ - c->rq.hdrs.rq_line.last_ws_start)); - mhd_assert ((0 == c->rq.hdrs.rq_line.last_ws_start) || \ - (0 != c->rq.hdrs.rq_line.last_ws_end)); + mhd_assert ((0 == c->rq.hdrs.rq_line.last_ws_end) \ + || (c->rq.hdrs.rq_line.last_ws_end > \ + c->rq.hdrs.rq_line.last_ws_start)); + mhd_assert ((0 == c->rq.hdrs.rq_line.last_ws_start) \ + || (0 != c->rq.hdrs.rq_line.last_ws_end)); /* Check for the end of the line */ if ('\r' == chr) @@ -892,11 +892,11 @@ get_request_line_inner (struct MHD_Connection *restrict c) c->rq.num_cr_sp_replaced++; continue; /* Re-start processing of the current character */ } - else if (! bare_cr_keep) + else if (!bare_cr_keep) { /* A quick simple check whether this line looks like an HTTP request */ - if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) && - (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) + if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) + && (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) { mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, @@ -923,8 +923,8 @@ get_request_line_inner (struct MHD_Connection *restrict c) if this char is not treated as a line delimiter, it should be rejected to avoid any security weakness due to request smuggling. */ /* A quick simple check whether this line looks like an HTTP request */ - if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) && - (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) + if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) + && (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) { mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, @@ -955,14 +955,14 @@ get_request_line_inner (struct MHD_Connection *restrict c) /* Determine the end and the length of the URI */ if (NULL != c->rq.hdrs.rq_line.rq_tgt) { - read_buffer [c->rq.hdrs.rq_line.last_ws_start] = 0; /* Zero terminate the URI */ + read_buffer[c->rq.hdrs.rq_line.last_ws_start] = 0; /* Zero terminate the URI */ c->rq.req_target_len = c->rq.hdrs.rq_line.last_ws_start - - (size_t) (c->rq.hdrs.rq_line.rq_tgt - read_buffer); + - (size_t)(c->rq.hdrs.rq_line.rq_tgt - read_buffer); } else if ((c->rq.hdrs.rq_line.last_ws_start + 1 < - c->rq.hdrs.rq_line.last_ws_end) && - (HTTP_VER_LEN == (p - c->rq.hdrs.rq_line.last_ws_end))) + c->rq.hdrs.rq_line.last_ws_end) + && (HTTP_VER_LEN == (p - c->rq.hdrs.rq_line.last_ws_end))) { /* Found only HTTP method and HTTP version and more than one whitespace between them. Assume zero-length URI. */ @@ -988,8 +988,8 @@ get_request_line_inner (struct MHD_Connection *restrict c) should be already known. */ if ((NULL == c->rq.version) && (NULL != c->rq.hdrs.rq_line.rq_tgt) - && (HTTP_VER_LEN == p - (size_t) (c->rq.hdrs.rq_line.rq_tgt - - read_buffer)) + && (HTTP_VER_LEN == p - (size_t)(c->rq.hdrs.rq_line.rq_tgt + - read_buffer)) && (0 != read_buffer[(size_t) (c->rq.hdrs.rq_line.rq_tgt - read_buffer) - 1])) @@ -999,7 +999,7 @@ get_request_line_inner (struct MHD_Connection *restrict c) size_t uri_pos; mhd_assert (wsp_blocks); mhd_assert (0 == c->rq.req_target_len); - uri_pos = (size_t) (c->rq.hdrs.rq_line.rq_tgt - read_buffer) - 1; + uri_pos = (size_t)(c->rq.hdrs.rq_line.rq_tgt - read_buffer) - 1; mhd_assert (uri_pos < p); c->rq.version = c->rq.hdrs.rq_line.rq_tgt; read_buffer[uri_pos] = 0; /* Zero terminate the URI */ @@ -1013,10 +1013,10 @@ get_request_line_inner (struct MHD_Connection *restrict c) if (NULL != c->rq.version) { mhd_assert (NULL != c->rq.hdrs.rq_line.rq_tgt); - if (! process_http_version (c, - p - (size_t) (c->rq.version - - read_buffer), - c->rq.version)) + if (!process_http_version (c, + p - (size_t)(c->rq.version + - read_buffer), + c->rq.version)) { mhd_assert (mhd_HTTP_STAGE_REQ_LINE_RECEIVING < c->stage); return true; /* Unsupported / broken HTTP version */ @@ -1033,23 +1033,23 @@ get_request_line_inner (struct MHD_Connection *restrict c) c->read_buffer_offset -= p; mhd_assert (c->rq.hdrs.rq_line.num_ws_in_uri <= \ c->rq.req_target_len); - mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) || \ - (0 != c->rq.req_target_len)); - mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) || \ - ((size_t) (c->rq.hdrs.rq_line.rq_tgt_qmark \ - - c->rq.hdrs.rq_line.rq_tgt) < \ - c->rq.req_target_len)); - mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) || \ - (c->rq.hdrs.rq_line.rq_tgt_qmark >= \ - c->rq.hdrs.rq_line.rq_tgt)); + mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) \ + || (0 != c->rq.req_target_len)); + mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) \ + || ((size_t)(c->rq.hdrs.rq_line.rq_tgt_qmark \ + - c->rq.hdrs.rq_line.rq_tgt) < \ + c->rq.req_target_len)); + mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) \ + || (c->rq.hdrs.rq_line.rq_tgt_qmark >= \ + c->rq.hdrs.rq_line.rq_tgt)); return true; /* The request line is successfully parsed */ } } /* Error in the request line */ /* A quick simple check whether this line looks like an HTTP request */ - if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) && - (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) + if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) + && (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) { mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, @@ -1063,9 +1063,9 @@ get_request_line_inner (struct MHD_Connection *restrict c) } /* Process possible end of the previously found whitespace delimiter */ - if ((! wsp_blocks) && - (p == c->rq.hdrs.rq_line.last_ws_end) && - (0 != c->rq.hdrs.rq_line.last_ws_end)) + if ((!wsp_blocks) + && (p == c->rq.hdrs.rq_line.last_ws_end) + && (0 != c->rq.hdrs.rq_line.last_ws_end)) { /* Previous character was a whitespace char and whitespace blocks are not allowed. */ @@ -1084,10 +1084,10 @@ get_request_line_inner (struct MHD_Connection *restrict c) else { /* It was a whitespace after the start of the URI */ - if (! wsp_in_uri) + if (!wsp_in_uri) { - mhd_assert ((0 != c->rq.req_target_len) || \ - (c->rq.hdrs.rq_line.rq_tgt + 1 == read_buffer + p)); + mhd_assert ((0 != c->rq.req_target_len) \ + || (c->rq.hdrs.rq_line.rq_tgt + 1 == read_buffer + p)); mhd_assert (NULL == c->rq.version); /* Too many whitespaces? This error is handled at whitespace start */ c->rq.version = read_buffer + p; /* Reset the whitespace marker */ @@ -1104,9 +1104,9 @@ get_request_line_inner (struct MHD_Connection *restrict c) || ((other_wsp_as_wsp) && ((0xb == chr) || (0xc == chr)))) { /* A whitespace character */ - if ((0 == c->rq.hdrs.rq_line.last_ws_end) || - (p != c->rq.hdrs.rq_line.last_ws_end) || - (! wsp_blocks)) + if ((0 == c->rq.hdrs.rq_line.last_ws_end) + || (p != c->rq.hdrs.rq_line.last_ws_end) + || (!wsp_blocks)) { /* Found first whitespace char of the new whitespace block */ if (NULL == c->rq.method.cstr) @@ -1131,7 +1131,7 @@ get_request_line_inner (struct MHD_Connection *restrict c) else { /* A whitespace after the start of the URI */ - if (! wsp_in_uri) + if (!wsp_in_uri) { /* Whitespace in URI is not allowed to be parsed */ if (NULL == c->rq.version) @@ -1139,18 +1139,18 @@ get_request_line_inner (struct MHD_Connection *restrict c) mhd_assert (NULL != c->rq.hdrs.rq_line.rq_tgt); /* This is a delimiter between URI and HTTP version string */ read_buffer[p] = 0; /* Zero-terminate request URI string */ - mhd_assert (((size_t) (c->rq.hdrs.rq_line.rq_tgt \ - - read_buffer)) <= p); + mhd_assert (((size_t)(c->rq.hdrs.rq_line.rq_tgt \ + - read_buffer)) <= p); c->rq.req_target_len = - p - (size_t) (c->rq.hdrs.rq_line.rq_tgt - read_buffer); + p - (size_t)(c->rq.hdrs.rq_line.rq_tgt - read_buffer); } else { /* This is a delimiter AFTER version string */ /* A quick simple check whether this line looks like an HTTP request */ - if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) && - (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) + if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) + && (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) { mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, @@ -1189,13 +1189,13 @@ get_request_line_inner (struct MHD_Connection *restrict c) else { /* Non-whitespace char, not the end of the line */ - mhd_assert ((0 == c->rq.hdrs.rq_line.last_ws_end) || \ - (c->rq.hdrs.rq_line.last_ws_end == p) || \ - wsp_in_uri); + mhd_assert ((0 == c->rq.hdrs.rq_line.last_ws_end) \ + || (c->rq.hdrs.rq_line.last_ws_end == p) \ + || wsp_in_uri); - if ((p == c->rq.hdrs.rq_line.last_ws_end) && - (0 != c->rq.hdrs.rq_line.last_ws_end) && - (wsp_blocks)) + if ((p == c->rq.hdrs.rq_line.last_ws_end) + && (0 != c->rq.hdrs.rq_line.last_ws_end) + && (wsp_blocks)) { /* The end of the whitespace block */ if (NULL == c->rq.hdrs.rq_line.rq_tgt) @@ -1210,12 +1210,12 @@ get_request_line_inner (struct MHD_Connection *restrict c) } else { - if (! wsp_in_uri) + if (!wsp_in_uri) { /* This is the first character of the HTTP version */ mhd_assert (NULL != c->rq.hdrs.rq_line.rq_tgt); - mhd_assert ((0 != c->rq.req_target_len) || \ - (c->rq.hdrs.rq_line.rq_tgt + 1 == read_buffer + p)); + mhd_assert ((0 != c->rq.req_target_len) \ + || (c->rq.hdrs.rq_line.rq_tgt + 1 == read_buffer + p)); mhd_assert (NULL == c->rq.version); /* Handled at whitespace start */ c->rq.version = read_buffer + p; /* Reset the whitespace marker */ @@ -1228,8 +1228,8 @@ get_request_line_inner (struct MHD_Connection *restrict c) /* Handle other special characters */ if ('?' == chr) { - if ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) && - (NULL != c->rq.hdrs.rq_line.rq_tgt)) + if ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) + && (NULL != c->rq.hdrs.rq_line.rq_tgt)) { c->rq.hdrs.rq_line.rq_tgt_qmark = read_buffer + p; } @@ -1237,10 +1237,10 @@ get_request_line_inner (struct MHD_Connection *restrict c) else if ((0xb == chr) || (0xc == chr)) { /* VT or LF characters */ - mhd_assert (! other_wsp_as_wsp); - if ((NULL != c->rq.hdrs.rq_line.rq_tgt) && - (NULL == c->rq.version) && - (wsp_in_uri)) + mhd_assert (!other_wsp_as_wsp); + if ((NULL != c->rq.hdrs.rq_line.rq_tgt) + && (NULL == c->rq.version) + && (wsp_in_uri)) { c->rq.hdrs.rq_line.num_ws_in_uri++; } @@ -1281,7 +1281,7 @@ request_add_get_arg (void *restrict cls, const struct MHD_String *restrict name, const struct MHD_StringNullable *restrict value) { - struct MHD_Stream *s = (struct MHD_Stream *) cls; + struct MHD_Stream *s = (struct MHD_Stream *)cls; return mhd_stream_add_field_nullable (s, MHD_VK_URI_QUERY_PARAM, name, value); } @@ -1298,7 +1298,7 @@ mhd_parse_uri_args (size_t args_len, { size_t i; - mhd_assert (args_len < (size_t) (args_len + 1)); /* Does not work when args_len == SIZE_MAX */ + mhd_assert (args_len < (size_t)(args_len + 1)); /* Does not work when args_len == SIZE_MAX */ for (i = 0; i < args_len; ++i) /* Looking for names of the parameters */ { @@ -1362,7 +1362,7 @@ mhd_parse_uri_args (size_t args_len, args[name_start + name_len] = 0; name.cstr = args + name_start; name.len = name_len; - if (! cb (cls, &name, &value)) + if (!cb (cls, &name, &value)) return false; } return true; @@ -1384,12 +1384,13 @@ process_request_target (struct MHD_Connection *c) mhd_assert (NULL == c->rq.url); mhd_assert (0 == c->rq.url_len); mhd_assert (NULL != c->rq.hdrs.rq_line.rq_tgt); - mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) || \ - (c->rq.hdrs.rq_line.rq_tgt <= c->rq.hdrs.rq_line.rq_tgt_qmark)); - mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) || \ - (c->rq.req_target_len > \ - (size_t) (c->rq.hdrs.rq_line.rq_tgt_qmark \ - - c->rq.hdrs.rq_line.rq_tgt))); + mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) \ + || (c->rq.hdrs.rq_line.rq_tgt <= + c->rq.hdrs.rq_line.rq_tgt_qmark)); + mhd_assert ((NULL == c->rq.hdrs.rq_line.rq_tgt_qmark) \ + || (c->rq.req_target_len > \ + (size_t)(c->rq.hdrs.rq_line.rq_tgt_qmark \ + - c->rq.hdrs.rq_line.rq_tgt))); /* Log callback before the request-target is modified/decoded */ if (NULL != c->daemon->req_cfg.uri_cb.cb) @@ -1408,17 +1409,17 @@ process_request_target (struct MHD_Connection *c) { params_len = c->rq.req_target_len - - (size_t) (c->rq.hdrs.rq_line.rq_tgt_qmark - c->rq.hdrs.rq_line.rq_tgt); + - (size_t)(c->rq.hdrs.rq_line.rq_tgt_qmark - c->rq.hdrs.rq_line.rq_tgt); mhd_assert (1 <= params_len); c->rq.hdrs.rq_line.rq_tgt_qmark[0] = 0; /* Replace '?' with zero termination */ // TODO: support detection of decoding errors - if (! mhd_parse_uri_args (params_len - 1, - c->rq.hdrs.rq_line.rq_tgt_qmark + 1, - &request_add_get_arg, - &(c->h1_stream))) + if (!mhd_parse_uri_args (params_len - 1, + c->rq.hdrs.rq_line.rq_tgt_qmark + 1, + &request_add_get_arg, + &(c->h1_stream))) { mhd_LOG_MSG (c->daemon, MHD_SC_CONNECTION_POOL_NO_MEM_GET_PARAM, "Not enough memory in the pool to store GET parameter"); @@ -1459,7 +1460,7 @@ process_request_target (struct MHD_Connection *c) /** * The maximum size of the fixed URI for automatic redirection */ -#define MHD_MAX_FIXED_URI_LEN (64 * 1024) +# define MHD_MAX_FIXED_URI_LEN (64 * 1024) #endif /* ! MHD_MAX_FIXED_URI_LEN */ /** @@ -1487,10 +1488,10 @@ send_redirect_fixed_rq_target (struct MHD_Connection *restrict c) c->rq.req_target_len); fixed_uri_len = c->rq.req_target_len + 2 * c->rq.hdrs.rq_line.num_ws_in_uri; - if ( (fixed_uri_len + 200 > c->daemon->conns.cfg.mem_pool_size) || - (fixed_uri_len > MHD_MAX_FIXED_URI_LEN) || - (NULL == - (hdr_line = (char *) malloc (fixed_uri_len + 1 + hdr_prefix_len))) ) + if ((fixed_uri_len + 200 > c->daemon->conns.cfg.mem_pool_size) + || (fixed_uri_len > MHD_MAX_FIXED_URI_LEN) + || (NULL == + (hdr_line = (char *)malloc (fixed_uri_len + 1 + hdr_prefix_len)))) { mhd_STREAM_ABORT (c, mhd_CONN_CLOSE_CLIENT_HTTP_ERR_ABORT_CONN, \ "The request has whitespace character is " \ @@ -1560,14 +1561,14 @@ mhd_stream_get_request_line (struct MHD_Connection *restrict c) automatic redirect to fixed URI */ const bool wsp_in_uri_keep = (-2 >= discp_lvl); - if (! get_request_line_inner (c)) + if (!get_request_line_inner (c)) { /* End of the request line has not been found yet */ - mhd_assert ((! wsp_in_uri) || NULL == c->rq.version); - if ((NULL != c->rq.version) && - (HTTP_VER_LEN < - (c->rq.hdrs.rq_line.proc_pos - - (size_t) (c->rq.version - c->read_buffer)))) + mhd_assert ((!wsp_in_uri) || NULL == c->rq.version); + if ((NULL != c->rq.version) + && (HTTP_VER_LEN < + (c->rq.hdrs.rq_line.proc_pos + - (size_t)(c->rq.version - c->read_buffer)))) { c->rq.http_ver = MHD_HTTP_VERSION_INVALID; mhd_RESPOND_WITH_ERROR_STATIC (c, @@ -1586,20 +1587,20 @@ mhd_stream_get_request_line (struct MHD_Connection *restrict c) mhd_assert (NULL != c->rq.hdrs.rq_line.rq_tgt); if (0 != c->rq.hdrs.rq_line.num_ws_in_uri) { - if (! wsp_in_uri) + if (!wsp_in_uri) { mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_RQ_TARGET_INVALID_CHAR); return true; /* Error in the request */ } - if (! wsp_in_uri_keep) + if (!wsp_in_uri_keep) { send_redirect_fixed_rq_target (c); return true; /* Error in the request */ } } - if (! process_request_target (c)) + if (!process_request_target (c)) return true; /* Error in processing */ c->stage = mhd_HTTP_STAGE_REQ_LINE_RECEIVED; @@ -1660,7 +1661,8 @@ handle_req_footers_no_space (struct MHD_Connection *restrict c, const char *restrict add_footer, size_t add_footer_size) { - (void) add_footer; (void) add_footer_size; /* Unused */ + (void)add_footer; + (void)add_footer_size; /* Unused */ mhd_assert (c->rq.have_chunked_upload); /* Footers should be optional */ @@ -1722,7 +1724,7 @@ get_req_header (struct MHD_Connection *restrict c, const bool bare_cr_keep = (-3 >= discp_lvl); /* Treat bare CR as space; replace it with space before processing. RFC 9112, section 2.2-4 */ - const bool bare_cr_as_sp = ((! bare_cr_keep) && (-1 >= discp_lvl)); + const bool bare_cr_as_sp = ((!bare_cr_keep) && (-1 >= discp_lvl)); /* Treat NUL as space; replace it with space before processing. RFC 9110, section 5.5-5 */ const bool nul_as_sp = (-1 >= discp_lvl); @@ -1751,7 +1753,7 @@ get_req_header (struct MHD_Connection *restrict c, size_t p; /**< The position of the currently processed character */ - (void) process_footers; /* Unused parameter in non-debug and no messages */ + (void)process_footers; /* Unused parameter in non-debug and no messages */ mhd_assert ((process_footers ? mhd_HTTP_STAGE_FOOTERS_RECEIVING : \ mhd_HTTP_STAGE_REQ_HEADERS_RECEIVING) == \ @@ -1766,21 +1768,21 @@ get_req_header (struct MHD_Connection *restrict c, const char chr = read_buffer[p]; bool end_of_line; - mhd_assert ((0 == c->rq.hdrs.hdr.name_len) || \ - (c->rq.hdrs.hdr.name_len < p)); + mhd_assert ((0 == c->rq.hdrs.hdr.name_len) \ + || (c->rq.hdrs.hdr.name_len < p)); mhd_assert ((0 == c->rq.hdrs.hdr.name_len) || (0 != p)); - mhd_assert ((0 == c->rq.hdrs.hdr.name_len) || \ - (c->rq.hdrs.hdr.name_end_found)); - mhd_assert ((0 == c->rq.hdrs.hdr.value_start) || \ - (c->rq.hdrs.hdr.name_len < c->rq.hdrs.hdr.value_start)); - mhd_assert ((0 == c->rq.hdrs.hdr.value_start) || \ - (0 != c->rq.hdrs.hdr.name_len)); - mhd_assert ((0 == c->rq.hdrs.hdr.ws_start) || \ - (0 == c->rq.hdrs.hdr.name_len) || \ - (c->rq.hdrs.hdr.ws_start > c->rq.hdrs.hdr.name_len)); - mhd_assert ((0 == c->rq.hdrs.hdr.ws_start) || \ - (0 == c->rq.hdrs.hdr.value_start) || \ - (c->rq.hdrs.hdr.ws_start > c->rq.hdrs.hdr.value_start)); + mhd_assert ((0 == c->rq.hdrs.hdr.name_len) \ + || (c->rq.hdrs.hdr.name_end_found)); + mhd_assert ((0 == c->rq.hdrs.hdr.value_start) \ + || (c->rq.hdrs.hdr.name_len < c->rq.hdrs.hdr.value_start)); + mhd_assert ((0 == c->rq.hdrs.hdr.value_start) \ + || (0 != c->rq.hdrs.hdr.name_len)); + mhd_assert ((0 == c->rq.hdrs.hdr.ws_start) \ + || (0 == c->rq.hdrs.hdr.name_len) \ + || (c->rq.hdrs.hdr.ws_start > c->rq.hdrs.hdr.name_len)); + mhd_assert ((0 == c->rq.hdrs.hdr.ws_start) \ + || (0 == c->rq.hdrs.hdr.value_start) \ + || (c->rq.hdrs.hdr.ws_start > c->rq.hdrs.hdr.value_start)); /* Check for the end of the line */ if ('\r' == chr) @@ -1810,9 +1812,9 @@ get_req_header (struct MHD_Connection *restrict c, c->rq.num_cr_sp_replaced++; continue; /* Re-start processing of the current character */ } - else if (! bare_cr_keep) + else if (!bare_cr_keep) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_BARE_CR_IN_HEADER); @@ -1841,7 +1843,7 @@ get_req_header (struct MHD_Connection *restrict c, } else { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_BARE_LF_IN_HEADER); @@ -1870,8 +1872,8 @@ get_req_header (struct MHD_Connection *restrict c, /* Zero-length header line. This is the end of the request header section. RFC 9112, Section 2.1-1 */ - mhd_assert (! c->rq.hdrs.hdr.starts_with_ws); - mhd_assert (! c->rq.hdrs.hdr.name_end_found); + mhd_assert (!c->rq.hdrs.hdr.starts_with_ws); + mhd_assert (!c->rq.hdrs.hdr.name_end_found); mhd_assert (0 == c->rq.hdrs.hdr.name_len); mhd_assert (0 == c->rq.hdrs.hdr.ws_start); mhd_assert (0 == c->rq.hdrs.hdr.value_start); @@ -1886,13 +1888,13 @@ get_req_header (struct MHD_Connection *restrict c, mhd_assert (0 != line_len); mhd_assert ('\n' == read_buffer[line_len - 1]); next_line_char = read_buffer[line_len]; - if ((' ' == next_line_char) || - ('\t' == next_line_char)) + if ((' ' == next_line_char) + || ('\t' == next_line_char)) { /* Folded line */ - if (! allow_folded) + if (!allow_folded) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_OBS_FOLD); @@ -1927,11 +1929,11 @@ get_req_header (struct MHD_Connection *restrict c, "has been skipped."); skip_line = true; } - else if (! c->rq.hdrs.hdr.name_end_found) + else if (!c->rq.hdrs.hdr.name_end_found) { - if (! allow_line_without_colon) + if (!allow_line_without_colon) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_HEADER_WITHOUT_COLON); @@ -2002,9 +2004,9 @@ get_req_header (struct MHD_Connection *restrict c, { if (0 == p) { - if (! allow_wsp_at_start) + if (!allow_wsp_at_start) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_WSP_BEFORE_HEADER); @@ -2016,8 +2018,8 @@ get_req_header (struct MHD_Connection *restrict c, } c->rq.hdrs.hdr.starts_with_ws = true; } - else if ((! c->rq.hdrs.hdr.name_end_found) && - (! c->rq.hdrs.hdr.starts_with_ws)) + else if ((!c->rq.hdrs.hdr.name_end_found) + && (!c->rq.hdrs.hdr.starts_with_ws)) { /* Whitespace in header name / between header name and colon */ if (allow_wsp_in_name || allow_wsp_before_colon) @@ -2027,7 +2029,7 @@ get_req_header (struct MHD_Connection *restrict c, } else { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_WSP_IN_HEADER_NAME); @@ -2048,9 +2050,9 @@ get_req_header (struct MHD_Connection *restrict c, } else if (0 == chr) { - if (! nul_as_sp) + if (!nul_as_sp) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_INVALID_CHR_IN_HEADER); @@ -2070,8 +2072,8 @@ get_req_header (struct MHD_Connection *restrict c, mhd_assert ('\r' != chr); mhd_assert ('\n' != chr); mhd_assert ('\0' != chr); - if ((! c->rq.hdrs.hdr.name_end_found) && - (! c->rq.hdrs.hdr.starts_with_ws)) + if ((!c->rq.hdrs.hdr.name_end_found) + && (!c->rq.hdrs.hdr.starts_with_ws)) { /* Processing the header (field) name */ if (':' == chr) @@ -2081,9 +2083,9 @@ get_req_header (struct MHD_Connection *restrict c, else { mhd_assert (allow_wsp_in_name || allow_wsp_before_colon); - if (! allow_wsp_before_colon) + if (!allow_wsp_before_colon) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_WSP_IN_HEADER_NAME); @@ -2098,9 +2100,9 @@ get_req_header (struct MHD_Connection *restrict c, c->rq.hdrs.hdr.ws_start = 0; /* Not on whitespace anymore */ #endif /* ! MHD_FAVOR_SMALL_CODE */ } - if ((0 == c->rq.hdrs.hdr.name_len) && ! allow_empty_name) + if ((0 == c->rq.hdrs.hdr.name_len) && !allow_empty_name) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_EMPTY_HEADER_NAME); @@ -2119,9 +2121,9 @@ get_req_header (struct MHD_Connection *restrict c, { /* End of the whitespace in header (field) name */ mhd_assert (allow_wsp_in_name || allow_wsp_before_colon); - if (! allow_wsp_in_name) + if (!allow_wsp_in_name) { - if (! process_footers) + if (!process_footers) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_WSP_IN_HEADER_NAME); @@ -2204,28 +2206,28 @@ mhd_stream_get_request_headers (struct MHD_Connection *restrict c, /* Values must not have whitespaces at the start or at the end */ mhd_assert ((hdr_name.len == 0) || (hdr_name.cstr[0] != ' ')); mhd_assert ((hdr_name.len == 0) || (hdr_name.cstr[0] != '\t')); - mhd_assert ((hdr_name.len == 0) || \ - (hdr_name.cstr[hdr_name.len - 1] != ' ')); - mhd_assert ((hdr_name.len == 0) || \ - (hdr_name.cstr[hdr_name.len - 1] != '\t')); + mhd_assert ((hdr_name.len == 0) \ + || (hdr_name.cstr[hdr_name.len - 1] != ' ')); + mhd_assert ((hdr_name.len == 0) \ + || (hdr_name.cstr[hdr_name.len - 1] != '\t')); mhd_assert ((hdr_value.len == 0) || (hdr_value.cstr[0] != ' ')); mhd_assert ((hdr_value.len == 0) || (hdr_value.cstr[0] != '\t')); - mhd_assert ((hdr_value.len == 0) || \ - (hdr_value.cstr[hdr_value.len - 1] != ' ')); - mhd_assert ((hdr_value.len == 0) || \ - (hdr_value.cstr[hdr_value.len - 1] != '\t')); - - if (! mhd_stream_add_field (&(c->h1_stream), - process_footers ? - MHD_VK_TRAILER : MHD_VK_HEADER, - &hdr_name, - &hdr_value)) + mhd_assert ((hdr_value.len == 0) \ + || (hdr_value.cstr[hdr_value.len - 1] != ' ')); + mhd_assert ((hdr_value.len == 0) \ + || (hdr_value.cstr[hdr_value.len - 1] != '\t')); + + if (!mhd_stream_add_field (&(c->h1_stream), + process_footers ? + MHD_VK_TRAILER : MHD_VK_HEADER, + &hdr_name, + &hdr_value)) { size_t add_element_size; mhd_assert (hdr_name.cstr < hdr_value.cstr); - if (! process_footers) + if (!process_footers) mhd_LOG_MSG (c->daemon, MHD_SC_CONNECTION_POOL_NO_MEM_REQ, \ "Failed to allocate memory in the connection memory " \ "pool to store header."); @@ -2235,9 +2237,9 @@ mhd_stream_get_request_headers (struct MHD_Connection *restrict c, "pool to store footer."); add_element_size = hdr_value.len - + (size_t) (hdr_value.cstr - hdr_name.cstr); + + (size_t)(hdr_value.cstr - hdr_name.cstr); - if (! process_footers) + if (!process_footers) handle_req_headers_no_space (c, hdr_name.cstr, add_element_size); else handle_req_footers_no_space (c, hdr_name.cstr, add_element_size); @@ -2275,7 +2277,7 @@ mhd_stream_get_request_headers (struct MHD_Connection *restrict c, if (1 == c->rq.num_cr_sp_replaced) { - if (! process_footers) + if (!process_footers) mhd_LOG_MSG (c->daemon, MHD_SC_REQ_HEADER_CR_REPLACED, \ "One bare CR character has been replaced with space " \ "in the request line or in the request headers."); @@ -2286,24 +2288,24 @@ mhd_stream_get_request_headers (struct MHD_Connection *restrict c, } else if (0 != c->rq.num_cr_sp_replaced) { - if (! process_footers) + if (!process_footers) mhd_LOG_PRINT (c->daemon, MHD_SC_REQ_HEADER_CR_REPLACED, \ mhd_LOG_FMT ("%" PRIuFAST64 " bare CR characters have " \ "been replaced with spaces in the request " \ "line and/or in the request headers."), \ - (uint_fast64_t) c->rq.num_cr_sp_replaced); + (uint_fast64_t)c->rq.num_cr_sp_replaced); else mhd_LOG_PRINT (c->daemon, MHD_SC_REQ_HEADER_CR_REPLACED, \ mhd_LOG_FMT ("%" PRIuFAST64 " bare CR characters have " \ "been replaced with spaces in the request " \ "footers."), \ - (uint_fast64_t) c->rq.num_cr_sp_replaced); + (uint_fast64_t)c->rq.num_cr_sp_replaced); } if (1 == c->rq.skipped_broken_lines) { - if (! process_footers) + if (!process_footers) mhd_LOG_MSG (c->daemon, MHD_SC_REQ_HEADER_LINE_NO_COLON, \ "One header line without colon has been skipped."); else @@ -2312,25 +2314,25 @@ mhd_stream_get_request_headers (struct MHD_Connection *restrict c, } else if (0 != c->rq.skipped_broken_lines) { - if (! process_footers) + if (!process_footers) mhd_LOG_PRINT (c->daemon, MHD_SC_REQ_HEADER_CR_REPLACED, \ mhd_LOG_FMT ("%" PRIu64 " header lines without colons " "have been skipped."), - (uint_fast64_t) c->rq.skipped_broken_lines); + (uint_fast64_t)c->rq.skipped_broken_lines); else mhd_LOG_PRINT (c->daemon, MHD_SC_REQ_HEADER_CR_REPLACED, \ mhd_LOG_FMT ("%" PRIu64 " footer lines without colons " "have been skipped."), - (uint_fast64_t) c->rq.skipped_broken_lines); + (uint_fast64_t)c->rq.skipped_broken_lines); } mhd_assert (c->rq.method.cstr < c->read_buffer); - if (! process_footers) + if (!process_footers) { - c->rq.header_size = (size_t) (c->read_buffer - c->rq.method.cstr); + c->rq.header_size = (size_t)(c->read_buffer - c->rq.method.cstr); mhd_assert (NULL != c->rq.field_lines.start); c->rq.field_lines.size = - (size_t) ((c->read_buffer - c->rq.field_lines.start) - 1); + (size_t)((c->read_buffer - c->rq.field_lines.start) - 1); if ('\r' == *(c->read_buffer - 2)) c->rq.field_lines.size--; c->stage = mhd_HTTP_STAGE_HEADERS_RECEIVED; @@ -2354,7 +2356,7 @@ mhd_stream_get_request_headers (struct MHD_Connection *restrict c, else last_elmnt_end = c->rq.version + HTTP_VER_LEN; mhd_assert ((last_elmnt_end + 1) < c->read_buffer); - shift_back_size = (size_t) (c->read_buffer - (last_elmnt_end + 1)); + shift_back_size = (size_t)(c->read_buffer - (last_elmnt_end + 1)); if (0 != c->read_buffer_offset) memmove (c->read_buffer - shift_back_size, c->read_buffer, @@ -2402,7 +2404,7 @@ enum mhd_ParseCookie */ static MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_INOUT_SIZE_ (2,1) enum mhd_ParseCookie +MHD_FN_PAR_INOUT_SIZE_ (2, 1) enum mhd_ParseCookie parse_cookies_string (const size_t str_len, char *restrict str, enum MHD_ProtocolStrictLevel strictness, @@ -2433,12 +2435,12 @@ parse_cookies_string (const size_t str_len, /* Skip any whitespaces and empty cookies */ while (' ' == str[i] || '\t' == str[i] || ';' == str[i]) { - if (! allow_wsp_empty) + if (!allow_wsp_empty) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; i++; if (i == str_len) - return non_strict? MHD_PARSE_COOKIE_OK_LAX : MHD_PARSE_COOKIE_OK; + return non_strict ? MHD_PARSE_COOKIE_OK_LAX : MHD_PARSE_COOKIE_OK; } /* 'i' must point to the first char of cookie-name */ name_start = i; @@ -2446,15 +2448,15 @@ parse_cookies_string (const size_t str_len, do { const char l = str[i]; - if (('=' == l) || (' ' == l) || ('\t' == l) || ('"' == l) || (',' == l) || - (';' == l) || (0 == l)) + if (('=' == l) || (' ' == l) || ('\t' == l) || ('"' == l) || (',' == l) + || (';' == l) || (0 == l)) break; } while (str_len > ++i); name_len = i - name_start; /* Skip any whitespaces */ while (str_len > i && (' ' == str[i] || '\t' == str[i])) { - if (! wsp_around_eq) + if (!wsp_around_eq) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; i++; @@ -2467,7 +2469,7 @@ parse_cookies_string (const size_t str_len, /* Skip any whitespaces */ while (str_len > i && (' ' == str[i] || '\t' == str[i])) { - if (! wsp_around_eq) + if (!wsp_around_eq) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; i++; @@ -2477,9 +2479,9 @@ parse_cookies_string (const size_t str_len, { value_start = 0; value_len = 0; -#ifndef NDEBUG +# ifndef NDEBUG val_quoted = false; /* This assignment used in assert */ -#endif +# endif } else { @@ -2496,9 +2498,9 @@ parse_cookies_string (const size_t str_len, break; if ((' ' == l) || ('\t' == l)) { - if (! val_quoted) + if (!val_quoted) break; - if (! wsp_in_quoted) + if (!wsp_in_quoted) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; } @@ -2521,7 +2523,7 @@ parse_cookies_string (const size_t str_len, /* Whitespace at the end? */ if (str_len > i) { - if (! allow_wsp_empty) + if (!allow_wsp_empty) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; } @@ -2533,7 +2535,7 @@ parse_cookies_string (const size_t str_len, else valid_cookie = false; - if (! valid_cookie) + if (!valid_cookie) return MHD_PARSE_COOKIE_MALFORMED; /* Garbage at the end of the cookie value */ } @@ -2552,10 +2554,10 @@ parse_cookies_string (const size_t str_len, str[value_start + value_len] = '\0'; /* Zero-terminate the value */ value.cstr = str + value_start; value.len = value_len; - if (! mhd_stream_add_field (s, - MHD_VK_COOKIE, - &name, - &value)) + if (!mhd_stream_add_field (s, + MHD_VK_COOKIE, + &name, + &value)) return MHD_PARSE_COOKIE_NO_MEMORY; } else @@ -2566,21 +2568,21 @@ parse_cookies_string (const size_t str_len, name.len = name_len; value.cstr = ""; value.len = 0; - if (! mhd_stream_add_field (s, - MHD_VK_COOKIE, - &name, - &value)) + if (!mhd_stream_add_field (s, + MHD_VK_COOKIE, + &name, + &value)) return MHD_PARSE_COOKIE_NO_MEMORY; } if (str_len > i) { mhd_assert (0 == str[i] || ';' == str[i]); - mhd_assert (! val_quoted || ';' == str[i]); + mhd_assert (!val_quoted || ';' == str[i]); mhd_assert (';' != str[i] || val_quoted || non_strict || 0 == value_len); i++; if (str_len == i) { /* No next cookie after semicolon */ - if (! allow_wsp_empty) + if (!allow_wsp_empty) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; } @@ -2588,7 +2590,7 @@ parse_cookies_string (const size_t str_len, {/* No space after semicolon */ if (('\t' == str[i]) && tab_as_sp) i++; - else if (! allow_no_space) + else if (!allow_no_space) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; } @@ -2597,14 +2599,14 @@ parse_cookies_string (const size_t str_len, i++; if (str_len == i) { - if (! allow_wsp_empty) + if (!allow_wsp_empty) return MHD_PARSE_COOKIE_MALFORMED; non_strict = true; } } } } - return non_strict? MHD_PARSE_COOKIE_OK_LAX : MHD_PARSE_COOKIE_OK; + return non_strict ? MHD_PARSE_COOKIE_OK_LAX : MHD_PARSE_COOKIE_OK; } @@ -2632,8 +2634,8 @@ parse_cookie_header (struct MHD_Connection *restrict connection, if (0 == cookie_val->len) return MHD_PARSE_COOKIE_OK; - cpy = (char *) mhd_stream_alloc_memory (connection, - cookie_val->len + 1); + cpy = (char *)mhd_stream_alloc_memory (connection, + cookie_val->len + 1); if (NULL == cpy) parse_res = MHD_PARSE_COOKIE_NO_MEMORY; else @@ -2667,7 +2669,7 @@ parse_cookie_header (struct MHD_Connection *restrict connection, case MHD_PARSE_COOKIE_MALFORMED: if (saved_tail != connection->rq.fields.last) // FIXME: a better way? { - if (! allow_partially_correct_cookie) + if (!allow_partially_correct_cookie) { /* Remove extracted values from partially broken cookie */ /* Memory remains allocated until the end of the request processing */ @@ -2791,9 +2793,9 @@ mhd_stream_parse_request_headers (struct MHD_Connection *restrict c) num_digits = mhd_str_to_uint64_n (f->field.nv.value.cstr, f->field.nv.value.len, &cntn_size); - if (((0 == num_digits) && - (0 != f->field.nv.value.len) && - ('9' >= f->field.nv.value.cstr[0]) + if (((0 == num_digits) + && (0 != f->field.nv.value.len) + && ('9' >= f->field.nv.value.cstr[0]) && ('0' <= f->field.nv.value.cstr[0])) || (MHD_SIZE_UNKNOWN == c->rq.cntn.cntn_size)) { @@ -2805,8 +2807,8 @@ mhd_stream_parse_request_headers (struct MHD_Connection *restrict c) ERR_RSP_REQUEST_CONTENTLENGTH_TOOLARGE); return; } - else if ((f->field.nv.value.len != num_digits) || - (0 == num_digits)) + else if ((f->field.nv.value.len != num_digits) + || (0 == num_digits)) { mhd_LOG_MSG (c->daemon, MHD_SC_CONTENT_LENGTH_MALFORMED, \ "Failed to parse 'Content-Length' header. " \ @@ -2848,8 +2850,8 @@ mhd_stream_parse_request_headers (struct MHD_Connection *restrict c) return; } } - mhd_assert ((0 == c->rq.cntn.cntn_size) || \ - (c->rq.cntn.cntn_size == cntn_size)); + mhd_assert ((0 == c->rq.cntn.cntn_size) \ + || (c->rq.cntn.cntn_size == cntn_size)); c->rq.cntn.cntn_size = cntn_size; has_cntnlen = true; continue; @@ -2907,10 +2909,10 @@ mhd_stream_parse_request_headers (struct MHD_Connection *restrict c) #ifdef MHD_SUPPORT_COOKIES /* "Cookie:" */ - if ((! c->daemon->req_cfg.disable_cookies) && - mhd_str_equal_caseless_n_st (MHD_HTTP_HEADER_COOKIE, - f->field.nv.name.cstr, - f->field.nv.name.len)) + if ((!c->daemon->req_cfg.disable_cookies) + && mhd_str_equal_caseless_n_st (MHD_HTTP_HEADER_COOKIE, + f->field.nv.name.cstr, + f->field.nv.name.len)) { if (MHD_PARSE_COOKIE_NO_MEMORY == parse_cookie_header (c, @@ -2972,8 +2974,8 @@ mhd_stream_parse_request_headers (struct MHD_Connection *restrict c) if (MHD_HTTP_VERSION_IS_LIKE_11 (c->rq.http_ver)) { - if ((! has_host) && - (-3 < c->daemon->req_cfg.strictness)) + if ((!has_host) + && (-3 < c->daemon->req_cfg.strictness)) { mhd_LOG_MSG (c->daemon, MHD_SC_HOST_HEADER_MISSING, \ "Received HTTP/1.1 request without 'Host' header."); @@ -2985,7 +2987,7 @@ mhd_stream_parse_request_headers (struct MHD_Connection *restrict c) } else { - if (! has_keepalive) + if (!has_keepalive) c->conn_reuse = mhd_CONN_MUST_CLOSE; /* Do not re-use HTTP/1.0 connection by default */ if (has_trenc) c->conn_reuse = mhd_CONN_MUST_CLOSE; /* Framing could be incorrect */ @@ -3010,7 +3012,7 @@ need_100_continue (struct MHD_Connection *restrict c) mhd_assert (mhd_HTTP_STAGE_HEADERS_PROCESSED <= c->stage); mhd_assert (mhd_HTTP_STAGE_BODY_RECEIVING > c->stage); - if (! c->rq.have_expect_100) + if (!c->rq.have_expect_100) return false; /* "100 Continue" has not been requested by the client */ if (0 != c->read_buffer_offset) @@ -3037,8 +3039,8 @@ need_100_continue (struct MHD_Connection *restrict c) static MHD_FN_PAR_NONNULL_ALL_ bool check_and_alloc_buf_for_upload_processing (struct MHD_Connection *restrict c) { - mhd_assert ((mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act) || \ - (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act)); + mhd_assert ((mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act) \ + || (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act)); if (c->rq.have_chunked_upload) return true; /* The size is unknown, buffers will be dynamically allocated @@ -3050,8 +3052,8 @@ check_and_alloc_buf_for_upload_processing (struct MHD_Connection *restrict c) return true; /* No additional buffer needed */ #endif - if ((mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act) && - (NULL == c->rq.app_act.head_act.data.upload.full.cb)) + if ((mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act) + && (NULL == c->rq.app_act.head_act.data.upload.full.cb)) return true; /* data will be processed only incrementally */ if (mhd_ACTION_UPLOAD != c->rq.app_act.head_act.act) @@ -3062,10 +3064,10 @@ check_and_alloc_buf_for_upload_processing (struct MHD_Connection *restrict c) } if ((c->rq.cntn.cntn_size > - c->rq.app_act.head_act.data.upload.large_buffer_size) || - ! mhd_daemon_get_lbuf (c->daemon, - (size_t) c->rq.cntn.cntn_size, - &(c->rq.cntn.lbuf))) + c->rq.app_act.head_act.data.upload.large_buffer_size) + || !mhd_daemon_get_lbuf (c->daemon, + (size_t)c->rq.cntn.cntn_size, + &(c->rq.cntn.lbuf))) { if (NULL != c->rq.app_act.head_act.data.upload.inc.cb) { @@ -3103,12 +3105,12 @@ mhd_stream_call_app_request_cb (struct MHD_Connection *restrict c) a = d->req_cfg.cb (d->req_cfg.cb_cls, &(c->rq), &path, - (enum MHD_HTTP_Method) c->rq.http_mthd, + (enum MHD_HTTP_Method)c->rq.http_mthd, c->rq.cntn.cntn_size); if ((NULL != a) && (((&(c->rq.app_act.head_act) != a)) - || ! mhd_ACTION_IS_VALID (c->rq.app_act.head_act.act))) + || !mhd_ACTION_IS_VALID (c->rq.app_act.head_act.act))) { mhd_LOG_MSG (d, MHD_SC_ACTION_INVALID, \ "Provided action is not a correct action generated " \ @@ -3155,7 +3157,7 @@ mhd_stream_call_app_request_cb (struct MHD_Connection *restrict c) case mhd_ACTION_UPLOAD: if (0 != c->rq.cntn.cntn_size) { - if (! check_and_alloc_buf_for_upload_processing (c)) + if (!check_and_alloc_buf_for_upload_processing (c)) return true; if (need_100_continue (c)) { @@ -3175,7 +3177,7 @@ mhd_stream_call_app_request_cb (struct MHD_Connection *restrict c) c->stage = mhd_HTTP_STAGE_FULL_REQ_RECEIVED; return true; } - if (! mhd_stream_prepare_for_post_parse (c)) + if (!mhd_stream_prepare_for_post_parse (c)) { mhd_assert (mhd_HTTP_STAGE_FOOTERS_RECEIVED < c->stage); return true; @@ -3193,7 +3195,7 @@ mhd_stream_call_app_request_cb (struct MHD_Connection *restrict c) #ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Suspending connection, FD: %2llu\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_SUSPEND_RESUME */ c->rq.app_act.head_act.act = mhd_ACTION_NO_ACTION; return false; @@ -3232,10 +3234,10 @@ mhd_stream_process_upload_action (struct MHD_Connection *restrict c, { if (NULL != act) { - if ((&(c->rq.app_act.upl_act) != act) || - ! mhd_UPLOAD_ACTION_IS_VALID (c->rq.app_act.upl_act.act) || - (final && - (mhd_UPLOAD_ACTION_CONTINUE == c->rq.app_act.upl_act.act))) + if ((&(c->rq.app_act.upl_act) != act) + || !mhd_UPLOAD_ACTION_IS_VALID (c->rq.app_act.upl_act.act) + || (final + && (mhd_UPLOAD_ACTION_CONTINUE == c->rq.app_act.upl_act.act))) { /* Perform cleanup of the created but now unused action */ switch (c->rq.app_act.upl_act.act) @@ -3248,11 +3250,11 @@ mhd_stream_process_upload_action (struct MHD_Connection *restrict c, case mhd_UPLOAD_ACTION_SUSPEND: /* No cleanup needed */ break; - #ifdef MHD_SUPPORT_UPGRADE +#ifdef MHD_SUPPORT_UPGRADE case mhd_UPLOAD_ACTION_UPGRADE: /* No cleanup needed */ break; - #endif /* MHD_SUPPORT_UPGRADE */ +#endif /* MHD_SUPPORT_UPGRADE */ case mhd_UPLOAD_ACTION_ABORT: mhd_UNREACHABLE (); break; @@ -3283,15 +3285,15 @@ mhd_stream_process_upload_action (struct MHD_Connection *restrict c, #ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Suspending connection, FD: %2llu\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_SUSPEND_RESUME */ memset (&(c->rq.app_act.upl_act), 0, sizeof(c->rq.app_act.upl_act)); return false; #ifdef MHD_SUPPORT_UPGRADE case mhd_UPLOAD_ACTION_UPGRADE: mhd_assert (c->rq.cntn.recv_size == c->rq.cntn.cntn_size); - mhd_assert (! c->rq.have_chunked_upload || \ - mhd_HTTP_STAGE_FULL_REQ_RECEIVED == c->stage); + mhd_assert (!c->rq.have_chunked_upload \ + || mhd_HTTP_STAGE_FULL_REQ_RECEIVED == c->stage); c->stage = mhd_HTTP_STAGE_UPGRADE_HEADERS_SENDING; return false; #endif /* MHD_SUPPORT_UPGRADE */ @@ -3340,17 +3342,17 @@ process_request_chunked_body (struct MHD_Connection *restrict c) has_more_data = false; - if ( (c->rq.current_chunk_offset == - c->rq.current_chunk_size) && - (0 != c->rq.current_chunk_size) ) + if ((c->rq.current_chunk_offset == + c->rq.current_chunk_size) + && (0 != c->rq.current_chunk_size)) { size_t i; mhd_assert (0 != available); /* skip new line at the *end* of a chunk */ i = 0; - if ( (2 <= available) && - ('\r' == buffer_head[0]) && - ('\n' == buffer_head[1]) ) + if ((2 <= available) + && ('\r' == buffer_head[0]) + && ('\n' == buffer_head[1])) i += 2; /* skip CRLF */ else if (bare_lf_as_crlf && ('\n' == buffer_head[0])) i++; /* skip bare LF */ @@ -3386,7 +3388,7 @@ process_request_chunked_body (struct MHD_Connection *restrict c) cntn_data_ready = available; else { /* cur_chunk_left <= (size_t)available */ - cntn_data_ready = (size_t) cur_chunk_left; + cntn_data_ready = (size_t)cur_chunk_left; if (available > cntn_data_ready) has_more_data = true; } @@ -3415,9 +3417,9 @@ process_request_chunked_body (struct MHD_Connection *restrict c) broken = (0 == num_dig); if (broken) /* Check whether result is invalid due to uint64_t overflow */ - overflow = ((('0' <= buffer_head[0]) && ('9' >= buffer_head[0])) || - (('A' <= buffer_head[0]) && ('F' >= buffer_head[0])) || - (('a' <= buffer_head[0]) && ('f' >= buffer_head[0]))); + overflow = ((('0' <= buffer_head[0]) && ('9' >= buffer_head[0])) + || (('A' <= buffer_head[0]) && ('F' >= buffer_head[0])) + || (('a' <= buffer_head[0]) && ('f' >= buffer_head[0]))); else { /** @@ -3427,10 +3429,10 @@ process_request_chunked_body (struct MHD_Connection *restrict c) size_t chunk_size_line_len; chunk_size_line_len = 0; - if ((';' == buffer_head[num_dig]) || - (allow_bws && - ((' ' == buffer_head[num_dig]) || - ('\t' == buffer_head[num_dig])))) + if ((';' == buffer_head[num_dig]) + || (allow_bws + && ((' ' == buffer_head[num_dig]) + || ('\t' == buffer_head[num_dig])))) { /* Chunk extension */ size_t i; @@ -3469,12 +3471,12 @@ process_request_chunked_body (struct MHD_Connection *restrict c) else { mhd_assert (available >= num_dig); - if ((2 <= (available - num_dig)) && - ('\r' == buffer_head[num_dig]) && - ('\n' == buffer_head[num_dig + 1])) + if ((2 <= (available - num_dig)) + && ('\r' == buffer_head[num_dig]) + && ('\n' == buffer_head[num_dig + 1])) chunk_size_line_len = num_dig + 2; - else if (bare_lf_as_crlf && - ('\n' == buffer_head[num_dig])) + else if (bare_lf_as_crlf + && ('\n' == buffer_head[num_dig])) chunk_size_line_len = num_dig + 1; else if (2 > (available - num_dig)) break; /* need more data */ @@ -3504,7 +3506,7 @@ process_request_chunked_body (struct MHD_Connection *restrict c) /* Invalid chunk size line */ } - if (! overflow) + if (!overflow) mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_BAD_REQUEST, ERR_RSP_REQUEST_CHUNKED_MALFORMED); @@ -3528,9 +3530,9 @@ process_request_chunked_body (struct MHD_Connection *restrict c) &size_provided, buffer_head); // TODO: support one chunk in-place processing? - mhd_assert ((0 == size_provided) || \ - (MHD_POST_PARSE_RES_OK != c->rq.u_proc.post.parse_result) || \ - (mhd_HTTP_STAGE_BODY_RECEIVING != c->stage)); + mhd_assert ((0 == size_provided) \ + || (MHD_POST_PARSE_RES_OK != c->rq.u_proc.post.parse_result) \ + || (mhd_HTTP_STAGE_BODY_RECEIVING != c->stage)); if (mhd_HTTP_STAGE_BODY_RECEIVING != c->stage) c->discard_request = true; } @@ -3544,18 +3546,18 @@ process_request_chunked_body (struct MHD_Connection *restrict c) need_inc_proc = false; mhd_assert (0 == c->rq.cntn.proc_size); - if ((uint_fast64_t) c->rq.cntn.lbuf.size < + if ((uint_fast64_t)c->rq.cntn.lbuf.size < c->rq.cntn.recv_size + cntn_data_ready) { size_t grow_size; - grow_size = (size_t) (c->rq.cntn.recv_size + cntn_data_ready - - c->rq.cntn.lbuf.size); - if (((size_t) (c->rq.cntn.recv_size + cntn_data_ready) < - cntn_data_ready) || - (! mhd_daemon_grow_lbuf (d, - grow_size, - &(c->rq.cntn.lbuf)))) + grow_size = (size_t)(c->rq.cntn.recv_size + cntn_data_ready + - c->rq.cntn.lbuf.size); + if (((size_t)(c->rq.cntn.recv_size + cntn_data_ready) < + cntn_data_ready) + || (!mhd_daemon_grow_lbuf (d, + grow_size, + &(c->rq.cntn.lbuf)))) { /* Failed to grow the buffer, no space to put the new data */ const struct MHD_UploadAction *act; @@ -3573,7 +3575,7 @@ process_request_chunked_body (struct MHD_Connection *restrict c) act = c->rq.app_act.head_act.data.upload.inc.cb ( c->rq.app_act.head_act.data.upload.inc.cls, &(c->rq), - (size_t) c->rq.cntn.recv_size, + (size_t)c->rq.cntn.recv_size, c->rq.cntn.lbuf.data); c->rq.cntn.proc_size = c->rq.cntn.recv_size; mhd_daemon_free_lbuf (d, &(c->rq.cntn.lbuf)); @@ -3582,7 +3584,7 @@ process_request_chunked_body (struct MHD_Connection *restrict c) need_inc_proc = true; } } - if (! need_inc_proc) + if (!need_inc_proc) { memcpy (c->rq.cntn.lbuf.data + c->rq.cntn.recv_size, buffer_head, cntn_data_ready); @@ -3615,16 +3617,16 @@ process_request_chunked_body (struct MHD_Connection *restrict c) mhd_ASSUME (c->rq.current_chunk_offset + cntn_data_ready >= c->rq.current_chunk_offset); c->rq.current_chunk_offset += cntn_data_ready; - } while (has_more_data && ! state_updated); + } while (has_more_data && !state_updated); /* TODO: optionally? zero out reused memory region */ - if ( (available > 0) && - (buffer_head != c->read_buffer) ) + if ((available > 0) + && (buffer_head != c->read_buffer)) memmove (c->read_buffer, buffer_head, available); else - mhd_assert ((0 == available) || \ - (c->read_buffer_offset == available)); + mhd_assert ((0 == available) \ + || (c->read_buffer_offset == available)); c->read_buffer_offset = available; return state_updated; @@ -3639,19 +3641,19 @@ process_request_nonchunked_body (struct MHD_Connection *restrict c) bool state_updated; mhd_assert (NULL == c->rp.response); - mhd_assert (! c->rq.have_chunked_upload); + mhd_assert (!c->rq.have_chunked_upload); mhd_assert (MHD_SIZE_UNKNOWN != c->rq.cntn.cntn_size); mhd_assert (c->rq.cntn.recv_size < c->rq.cntn.cntn_size); mhd_assert (c->rq.app_aware); if ((c->rq.cntn.cntn_size - c->rq.cntn.recv_size) < c->read_buffer_offset) - cntn_data_ready = (size_t) (c->rq.cntn.cntn_size - c->rq.cntn.recv_size); + cntn_data_ready = (size_t)(c->rq.cntn.cntn_size - c->rq.cntn.recv_size); else cntn_data_ready = c->read_buffer_offset; read_buf_reuse = false; state_updated = false; - mhd_assert (! read_buf_reuse); /* Mute analyser warning */ + mhd_assert (!read_buf_reuse); /* Mute analyser warning */ #ifdef MHD_SUPPORT_POST_PARSER if (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act) @@ -3665,9 +3667,9 @@ process_request_nonchunked_body (struct MHD_Connection *restrict c) state_updated = mhd_stream_post_parse (c, &size_provided, c->read_buffer); - mhd_assert ((0 == size_provided) || \ - (MHD_POST_PARSE_RES_OK != c->rq.u_proc.post.parse_result) || \ - (mhd_HTTP_STAGE_BODY_RECEIVING != c->stage)); + mhd_assert ((0 == size_provided) \ + || (MHD_POST_PARSE_RES_OK != c->rq.u_proc.post.parse_result) \ + || (mhd_HTTP_STAGE_BODY_RECEIVING != c->stage)); if (mhd_HTTP_STAGE_BODY_RECEIVING != c->stage) c->discard_request = true; @@ -3688,7 +3690,7 @@ process_request_nonchunked_body (struct MHD_Connection *restrict c) { // TODO: implement processing in pool memory if buffer is large enough mhd_assert ((c->rq.cntn.recv_size + cntn_data_ready) <= - (uint_fast64_t) c->rq.cntn.lbuf.size); + (uint_fast64_t)c->rq.cntn.lbuf.size); memcpy (c->rq.cntn.lbuf.data + c->rq.cntn.recv_size, c->read_buffer, cntn_data_ready); c->rq.cntn.recv_size += cntn_data_ready; @@ -3747,8 +3749,8 @@ mhd_stream_call_app_final_upload_cb (struct MHD_Connection *restrict c) { const struct MHD_UploadAction *act; bool state_changed; - mhd_assert (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act || \ - mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act); + mhd_assert (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act \ + || mhd_ACTION_UPLOAD == c->rq.app_act.head_act.act); #ifdef MHD_SUPPORT_POST_PARSER if (mhd_ACTION_POST_PARSE == c->rq.app_act.head_act.act) @@ -3767,7 +3769,7 @@ mhd_stream_call_app_final_upload_cb (struct MHD_Connection *restrict c) act = c->rq.app_act.head_act.data.upload.full.cb ( c->rq.app_act.head_act.data.upload.full.cls, &(c->rq), - (size_t) c->rq.cntn.recv_size, + (size_t)c->rq.cntn.recv_size, c->rq.cntn.lbuf.data); c->rq.cntn.proc_size = c->rq.cntn.recv_size; } @@ -3783,7 +3785,7 @@ mhd_stream_call_app_final_upload_cb (struct MHD_Connection *restrict c) } state_changed = mhd_stream_process_upload_action (c, act, true); - if (! c->suspended) + if (!c->suspended) mhd_daemon_free_lbuf (c->daemon, &(c->rq.cntn.lbuf)); return state_changed; @@ -3868,27 +3870,27 @@ handle_recv_no_space (struct MHD_Connection *c, mhd_assert (MHD_PROC_RECV_INIT <= stage); mhd_assert (MHD_PROC_RECV_FOOTERS >= stage); mhd_assert (mhd_HTTP_STAGE_FULL_REQ_RECEIVED > c->stage); - mhd_assert ((MHD_PROC_RECV_INIT != stage) || \ - (mhd_HTTP_STAGE_INIT == c->stage)); - mhd_assert ((MHD_PROC_RECV_METHOD != stage) || \ - (mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage)); - mhd_assert ((MHD_PROC_RECV_URI != stage) || \ - (mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage)); - mhd_assert ((MHD_PROC_RECV_HTTPVER != stage) || \ - (mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage)); - mhd_assert ((MHD_PROC_RECV_HEADERS != stage) || \ - (mhd_HTTP_STAGE_REQ_HEADERS_RECEIVING == c->stage)); + mhd_assert ((MHD_PROC_RECV_INIT != stage) \ + || (mhd_HTTP_STAGE_INIT == c->stage)); + mhd_assert ((MHD_PROC_RECV_METHOD != stage) \ + || (mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage)); + mhd_assert ((MHD_PROC_RECV_URI != stage) \ + || (mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage)); + mhd_assert ((MHD_PROC_RECV_HTTPVER != stage) \ + || (mhd_HTTP_STAGE_REQ_LINE_RECEIVING == c->stage)); + mhd_assert ((MHD_PROC_RECV_HEADERS != stage) \ + || (mhd_HTTP_STAGE_REQ_HEADERS_RECEIVING == c->stage)); mhd_assert (MHD_PROC_RECV_COOKIE != stage); /* handle_req_cookie_no_space() must be called directly */ - mhd_assert ((MHD_PROC_RECV_BODY_NORMAL != stage) || \ - (mhd_HTTP_STAGE_BODY_RECEIVING == c->stage)); - mhd_assert ((MHD_PROC_RECV_BODY_CHUNKED != stage) || \ - (mhd_HTTP_STAGE_BODY_RECEIVING == c->stage)); - mhd_assert ((MHD_PROC_RECV_FOOTERS != stage) || \ - (mhd_HTTP_STAGE_FOOTERS_RECEIVING == c->stage)); - mhd_assert ((MHD_PROC_RECV_BODY_NORMAL != stage) || \ - (! c->rq.have_chunked_upload)); - mhd_assert ((MHD_PROC_RECV_BODY_CHUNKED != stage) || \ - (c->rq.have_chunked_upload)); + mhd_assert ((MHD_PROC_RECV_BODY_NORMAL != stage) \ + || (mhd_HTTP_STAGE_BODY_RECEIVING == c->stage)); + mhd_assert ((MHD_PROC_RECV_BODY_CHUNKED != stage) \ + || (mhd_HTTP_STAGE_BODY_RECEIVING == c->stage)); + mhd_assert ((MHD_PROC_RECV_FOOTERS != stage) \ + || (mhd_HTTP_STAGE_FOOTERS_RECEIVING == c->stage)); + mhd_assert ((MHD_PROC_RECV_BODY_NORMAL != stage) \ + || (!c->rq.have_chunked_upload)); + mhd_assert ((MHD_PROC_RECV_BODY_CHUNKED != stage) \ + || (c->rq.have_chunked_upload)); switch (stage) { case MHD_PROC_RECV_INIT: @@ -3907,8 +3909,8 @@ handle_recv_no_space (struct MHD_Connection *c, mhd_assert (MHD_HTTP_VERSION_INVALID == c->rq.http_ver); /* A quick simple check whether the incomplete line looks * like an HTTP request */ - if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) && - (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) + if ((mhd_HTTP_METHOD_GET <= c->rq.http_mthd) + && (mhd_HTTP_METHOD_DELETE >= c->rq.http_mthd)) { mhd_RESPOND_WITH_ERROR_STATIC (c, MHD_HTTP_STATUS_URI_TOO_LONG, @@ -3929,7 +3931,7 @@ handle_recv_no_space (struct MHD_Connection *c, /* A header probably has been added to a suspended connection and it took precisely all the space in the buffer. Very low probability. */ - mhd_assert (! c->rq.have_chunked_upload); + mhd_assert (!c->rq.have_chunked_upload); handle_req_headers_no_space (c, NULL, 0); // FIXME: check return true; case MHD_PROC_RECV_BODY_CHUNKED: @@ -4010,7 +4012,7 @@ try_grow_read_buffer (struct MHD_Connection *restrict connection, if ((def_grow_size <= grow_size + left_free) && (left_free < def_grow_size)) grow_size = def_grow_size - left_free; /* Use precise 'def_grow_size' for new free space */ - else if (! required) + else if (!required) return false; /* Grow is not mandatory, leave some space in pool */ else { @@ -4027,19 +4029,19 @@ try_grow_read_buffer (struct MHD_Connection *restrict connection, new_size = connection->read_buffer_size + grow_size; } /* Make sure that read buffer will not be moved */ - if ((NULL != connection->read_buffer) && - ! mhd_pool_is_resizable_inplace (connection->pool, - connection->read_buffer, - connection->read_buffer_size)) + if ((NULL != connection->read_buffer) + && !mhd_pool_is_resizable_inplace (connection->pool, + connection->read_buffer, + connection->read_buffer_size)) { mhd_assert (0); return false; } /* we can actually grow the buffer, do it! */ - rb = (char *) mhd_pool_reallocate (connection->pool, - connection->read_buffer, - connection->read_buffer_size, - new_size); + rb = (char *)mhd_pool_reallocate (connection->pool, + connection->read_buffer, + connection->read_buffer_size, + new_size); if (NULL == rb) { /* This should NOT be possible: we just computed 'new_size' so that @@ -4074,7 +4076,7 @@ mhd_stream_check_and_grow_read_buffer_space (struct MHD_Connection *restrict c) bool rbuff_grow_required; mhd_assert (0 != (MHD_EVENT_LOOP_INFO_RECV & c->event_loop_info)); - mhd_assert (! c->discard_request); + mhd_assert (!c->discard_request); rbuff_grow_required = (c->read_buffer_offset == c->read_buffer_size); if (rbuff_grow_required) @@ -4084,10 +4086,10 @@ mhd_stream_check_and_grow_read_buffer_space (struct MHD_Connection *restrict c) rbuff_grow_desired = (c->read_buffer_offset + 1536 > // TODO: remove handcoded buffer grow size c->read_buffer_size); - if ((rbuff_grow_desired) && - (mhd_HTTP_STAGE_BODY_RECEIVING == c->stage)) + if ((rbuff_grow_desired) + && (mhd_HTTP_STAGE_BODY_RECEIVING == c->stage)) { - if (! c->rq.have_chunked_upload) + if (!c->rq.have_chunked_upload) { mhd_assert (MHD_SIZE_UNKNOWN != c->rq.cntn.cntn_size); /* Do not grow read buffer more than necessary to process the current @@ -4110,19 +4112,19 @@ mhd_stream_check_and_grow_read_buffer_space (struct MHD_Connection *restrict c) chunk with terminating CRLF. */ mhd_assert (c->rq.current_chunk_offset <= c->rq.current_chunk_size); rbuff_grow_desired = - ((cur_chunk_left + 2) > (uint_fast64_t) (c->read_buffer_size)); + ((cur_chunk_left + 2) > (uint_fast64_t)(c->read_buffer_size)); } } } } - if (! rbuff_grow_desired) + if (!rbuff_grow_desired) return mhd_CONN_BUFF_GROW_OK; /* No need to increase the buffer */ if (try_grow_read_buffer (c, rbuff_grow_required)) return mhd_CONN_BUFF_GROW_OK; /* Buffer increase succeed */ - if (! rbuff_grow_required) + if (!rbuff_grow_required) return mhd_CONN_BUFF_GROW_OK; /* Can continue without buffer increase */ /* Failed to increase the read buffer size, but need to read the data @@ -4186,7 +4188,7 @@ mhd_stream_check_and_grow_read_buffer_space (struct MHD_Connection *restrict c) res = handle_recv_no_space (c, stage); - mhd_assert (! res || ! c->dbg.closing_started); + mhd_assert (!res || !c->dbg.closing_started); mhd_assert (res || c->dbg.closing_started); return diff --git a/src/mhd2/stream_process_request.h b/src/mhd2/stream_process_request.h @@ -84,7 +84,7 @@ typedef bool MHD_INTERNAL enum mhd_HTTP_Method mhd_parse_http_method (size_t len, const char mtd[MHD_FN_PAR_DYN_ARR_SIZE_ (len)]) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_(2,1) MHD_FN_PURE_; +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (2, 1) MHD_FN_PURE_; /** * Parse and unescape the arguments given by the client diff --git a/src/mhd2/stream_process_states.c b/src/mhd2/stream_process_states.c @@ -87,10 +87,10 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ void mhd_conn_event_loop_state_update (struct MHD_Connection *restrict c) { #ifdef MHD_SUPPORT_HTTPS - mhd_assert (! mhd_C_HAS_TLS (c) || \ - (mhd_CONN_STATE_TLS_CONNECTED == c->conn_state)); - mhd_assert (mhd_C_HAS_TLS (c) || \ - (mhd_CONN_STATE_TCP_CONNECTED == c->conn_state)); + mhd_assert (!mhd_C_HAS_TLS (c) \ + || (mhd_CONN_STATE_TLS_CONNECTED == c->conn_state)); + mhd_assert (mhd_C_HAS_TLS (c) \ + || (mhd_CONN_STATE_TCP_CONNECTED == c->conn_state)); #endif /* MHD_SUPPORT_HTTPS */ #ifdef MHD_SUPPORT_HTTP2 @@ -250,7 +250,7 @@ process_http_comm_layer (struct MHD_Connection *restrict c) return mhd_COMM_LAYER_BROKEN; #else /* ! MHD_SUPPORT_HTTP2 */ - (void) c; /* Unused in HTTP/1.x-only modes */ + (void)c; /* Unused in HTTP/1.x-only modes */ return mhd_COMM_LAYER_OK; #endif /* ! MHD_SUPPORT_HTTP2 */ } @@ -269,9 +269,9 @@ finish_resume (struct MHD_Connection *restrict c) #ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Resumed connection, FD: %2llu\n", - (unsigned long long) c->sk.fd); + (unsigned long long)c->sk.fd); #endif /* MHD_USE_TRACE_SUSPEND_RESUME */ - mhd_assert (! c->suspended); + mhd_assert (!c->suspended); mhd_assert (MHD_EVENT_LOOP_INFO_PROCESS == c->event_loop_info); } @@ -284,7 +284,7 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) if (c->suspended) { - mhd_assert (! mhd_C_IS_HTTP2 (c)); + mhd_assert (!mhd_C_IS_HTTP2 (c)); return true; } @@ -293,7 +293,7 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) case mhd_COMM_LAYER_OK: break; /* Process HTTP data */ case mhd_COMM_LAYER_PROCESSING: - mhd_assert (! c->resuming); + mhd_assert (!c->resuming); return true; /* Too early for HTTP */ case mhd_COMM_LAYER_BROKEN: mhd_assert (c->dbg.closing_started); @@ -305,14 +305,14 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) if (c->resuming) { - mhd_assert (! mhd_C_IS_HTTP2 (c)); + mhd_assert (!mhd_C_IS_HTTP2 (c)); finish_resume (c); } #ifdef MHD_SUPPORT_HTTP2 if (mhd_C_IS_HTTP2 (c)) { - if (! mhd_h2_conn_process_data (c)) + if (!mhd_h2_conn_process_data (c)) return false; mhd_conn_event_loop_state_update (c); mhd_conn_mark_ready_update (c); @@ -320,8 +320,8 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) } #endif /* MHD_SUPPORT_HTTP2 */ - mhd_assert (mhd_D_IS_HTTP1_ENABLED (d) || (! mhd_C_IS_HTTP2 (c)) || \ - c->stop_with_error); + mhd_assert (mhd_D_IS_HTTP1_ENABLED (d) || (!mhd_C_IS_HTTP2 (c)) \ + || c->stop_with_error); if ((c->sk.state.rmt_shut_wr) && (mhd_HTTP_STAGE_START_REPLY > c->stage)) { @@ -336,8 +336,8 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) } } - mhd_assert ((! mhd_SCKT_NET_ST_HAS_FLAG (c->sk.ready, - mhd_SOCKET_NET_STATE_ERROR_READY)) + mhd_assert ((!mhd_SCKT_NET_ST_HAS_FLAG (c->sk.ready, + mhd_SOCKET_NET_STATE_ERROR_READY)) || (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err)); if (mhd_SOCKET_ERR_NO_ERROR != c->sk.state.discnt_err) @@ -357,15 +357,15 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) return false; } - mhd_assert (! c->suspended); + mhd_assert (!c->suspended); - while (! 0) + while (!0) { #ifdef MHD_SUPPORT_HTTPS - mhd_assert (! mhd_C_HAS_TLS (c) || \ - (mhd_CONN_STATE_TLS_CONNECTED == c->conn_state)); - mhd_assert (mhd_C_HAS_TLS (c) || \ - (mhd_CONN_STATE_TCP_CONNECTED == c->conn_state)); + mhd_assert (!mhd_C_HAS_TLS (c) \ + || (mhd_CONN_STATE_TLS_CONNECTED == c->conn_state)); + mhd_assert (mhd_C_HAS_TLS (c) \ + || (mhd_CONN_STATE_TCP_CONNECTED == c->conn_state)); #endif /* MHD_SUPPORT_HTTPS */ switch (c->stage) { @@ -389,8 +389,8 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) if (mhd_stream_get_request_headers (c, false)) { mhd_assert (mhd_HTTP_STAGE_REQ_HEADERS_RECEIVING < c->stage); - mhd_assert ((mhd_HTTP_STAGE_HEADERS_RECEIVED == c->stage) || \ - (c->discard_request)); + mhd_assert ((mhd_HTTP_STAGE_HEADERS_RECEIVED == c->stage) \ + || (c->discard_request)); continue; } mhd_assert (mhd_HTTP_STAGE_REQ_HEADERS_RECEIVING == c->stage); @@ -420,18 +420,18 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) break; case mhd_HTTP_STAGE_BODY_RECEIVING: mhd_assert (c->rq.cntn.recv_size < c->rq.cntn.cntn_size); - mhd_assert (! c->discard_request); + mhd_assert (!c->discard_request); mhd_assert (NULL == c->rp.response); if (0 == c->read_buffer_offset) break; /* Need more data to process */ if (mhd_stream_process_request_body (c)) continue; - mhd_assert (! c->discard_request); + mhd_assert (!c->discard_request); mhd_assert (NULL == c->rp.response); break; case mhd_HTTP_STAGE_BODY_RECEIVED: - mhd_assert (! c->discard_request); + mhd_assert (!c->discard_request); mhd_assert (NULL == c->rp.response); mhd_assert (c->rq.have_chunked_upload); /* Reset counter variables reused for footers */ @@ -445,8 +445,8 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) if (mhd_stream_get_request_headers (c, true)) { mhd_assert (mhd_HTTP_STAGE_FOOTERS_RECEIVING < c->stage); - mhd_assert ((mhd_HTTP_STAGE_FOOTERS_RECEIVED == c->stage) || \ - (c->discard_request)); + mhd_assert ((mhd_HTTP_STAGE_FOOTERS_RECEIVED == c->stage) \ + || (c->discard_request)); continue; } mhd_assert (mhd_HTTP_STAGE_FOOTERS_RECEIVING == c->stage); @@ -470,7 +470,7 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) case mhd_HTTP_STAGE_START_REPLY: mhd_assert (NULL != c->rp.response); mhd_stream_switch_from_recv_to_send (c); - if (! mhd_stream_build_header_response (c)) + if (!mhd_stream_build_header_response (c)) continue; mhd_assert (mhd_HTTP_STAGE_START_REPLY != c->stage); break; @@ -490,18 +490,18 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) continue; #ifdef MHD_SUPPORT_UPGRADE case mhd_HTTP_STAGE_UPGRADE_HEADERS_SENDING: - if (! mhd_upgrade_try_start_upgrading (c)) + if (!mhd_upgrade_try_start_upgrading (c)) break; continue; #endif /* MHD_SUPPORT_UPGRADE */ case mhd_HTTP_STAGE_UNCHUNKED_BODY_READY: mhd_assert (c->rp.props.send_reply_body); - mhd_assert (! c->rp.props.chunked); + mhd_assert (!c->rp.props.chunked); /* nothing to do here, send the data */ break; case mhd_HTTP_STAGE_UNCHUNKED_BODY_UNREADY: mhd_assert (c->rp.props.send_reply_body); - mhd_assert (! c->rp.props.chunked); + mhd_assert (!c->rp.props.chunked); if (0 == c->rp.response->cntn_size) { /* a shortcut */ c->stage = mhd_HTTP_STAGE_FULL_REPLY_SENT; @@ -518,9 +518,9 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) case mhd_HTTP_STAGE_CHUNKED_BODY_UNREADY: mhd_assert (c->rp.props.send_reply_body); mhd_assert (c->rp.props.chunked); - if ( (0 == c->rp.response->cntn_size) || - (c->rp.rsp_cntn_read_pos == - c->rp.response->cntn_size) ) + if ((0 == c->rp.response->cntn_size) + || (c->rp.rsp_cntn_read_pos == + c->rp.response->cntn_size)) { c->stage = mhd_HTTP_STAGE_CHUNKED_BODY_SENT; continue; @@ -548,8 +548,8 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) mhd_stream_finish_req_serving ( \ c, mhd_CONN_KEEPALIVE_POSSIBLE == c->conn_reuse - && ! c->discard_request - && ! c->sk.state.rmt_shut_wr); + && !c->discard_request + && !c->sk.state.rmt_shut_wr); continue; #ifdef MHD_SUPPORT_UPGRADE case mhd_HTTP_STAGE_UPGRADING: @@ -594,11 +594,11 @@ mhd_conn_process_data (struct MHD_Connection *restrict c) mhd_conn_mark_unready (c, d); mhd_conn_deinit_activity_timeout (c); - #ifdef MHD_USE_TRACE_SUSPEND_RESUME +#ifdef MHD_USE_TRACE_SUSPEND_RESUME fprintf (stderr, "%%%%%% Connection suspended, FD: %2llu\n", - (unsigned long long) c->sk.fd); - #endif /* MHD_USE_TRACE_SUSPEND_RESUME */ + (unsigned long long)c->sk.fd); +#endif /* MHD_USE_TRACE_SUSPEND_RESUME */ return true; } diff --git a/src/mhd2/sys_file_fd.h b/src/mhd2/sys_file_fd.h @@ -47,7 +47,7 @@ #include "mhd_sys_options.h" -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) # include <io.h> #endif #ifdef HAVE_UNISTD_H diff --git a/src/mhd2/sys_ip_headers.h b/src/mhd2/sys_ip_headers.h @@ -60,7 +60,7 @@ # ifdef HAVE_ARPA_INET_H # include <arpa/inet.h> # endif -# if ! defined(HAVE_NETINET_IN_H) && ! defined(HAVE_ARPA_INET_H) \ +# if !defined(HAVE_NETINET_IN_H) && !defined(HAVE_ARPA_INET_H) \ && defined(HAVE_NETDB_H) # include <netdb.h> # endif @@ -71,17 +71,17 @@ # include <ws2tcpip.h> #endif -#if ! defined(HAVE_DCLR_IPV6_V6ONLY) && defined(IPV6_V6ONLY) +#if !defined(HAVE_DCLR_IPV6_V6ONLY) && defined(IPV6_V6ONLY) /* Mis-deteted by configure */ # define HAVE_DCLR_IPV6_V6ONLY 1 #endif -#if ! defined(HAVE_DCLR_TCP_NODELAY) && defined(TCP_NODELAY) +#if !defined(HAVE_DCLR_TCP_NODELAY) && defined(TCP_NODELAY) /* Mis-deteted by configure */ # define HAVE_DCLR_TCP_NODELAY 1 #endif -#if ! defined(HAVE_DCLR_TCP_FASTOPEN) && defined(TCP_FASTOPEN) +#if !defined(HAVE_DCLR_TCP_FASTOPEN) && defined(TCP_FASTOPEN) /* Mis-deteted by configure */ # define HAVE_DCLR_TCP_FASTOPEN 1 #endif @@ -111,8 +111,8 @@ * even if TCP_CORK/TCP_NOPUSH was in switched off state. */ # define mhd_CORK_RESET_PUSH_DATA_ALWAYS 1 -#endif /* __linux__ */ -#if (defined(__FreeBSD__) && \ +# endif /* __linux__ */ +# if (defined(__FreeBSD__) && \ ((__FreeBSD__ + 0) >= 5 || (__FreeBSD_version + 0) >= 450000)) || \ (defined(__FreeBSD_kernel_version) && \ (__FreeBSD_kernel_version + 0) >= 450000) @@ -121,15 +121,15 @@ /** * Indicate that reset of TCP_CORK / TCP_NOPUSH push data to the network */ -#define mhd_CORK_RESET_PUSH_DATA 1 -#endif /* __FreeBSD_version >= 450000 */ -#ifdef __OpenBSD__ +# define mhd_CORK_RESET_PUSH_DATA 1 +# endif /* __FreeBSD_version >= 450000 */ +# ifdef __OpenBSD__ /* OpenBSD took implementation from FreeBSD */ /** * Indicate that reset of TCP_CORK / TCP_NOPUSH push data to the network */ -#define mhd_CORK_RESET_PUSH_DATA 1 -#endif /* __OpenBSD__ */ +# define mhd_CORK_RESET_PUSH_DATA 1 +# endif /* __OpenBSD__ */ #endif /* MHD_TCP_CORK_NOPUSH */ #ifdef __linux__ diff --git a/src/mhd2/sys_kqueue.h b/src/mhd2/sys_kqueue.h @@ -53,7 +53,7 @@ #ifdef MHD_SUPPORT_KQUEUE # include "mhd_socket_type.h" # ifndef MHD_SOCKETS_KIND_POSIX -#error Only POSIX type sockets are supported +# error Only POSIX type sockets are supported # endif # ifdef HAVE_SYS_TYPES_H # include <sys/types.h> @@ -112,12 +112,12 @@ typedef intptr_t mhd_KE_UDATA_TYPE; # define mhd_KE_GET_UDATA(ev_ptr) mhd_KE_UDATA_TO_PTR ((ev_ptr)->udata) -# define mhd_KE_SET(ev_ptr,fd,evfltr,evflags,evudata_ptr) do { \ - struct kevent mhd__ke_tmp = {0u}; \ - mhd__ke_tmp.ident = (unsigned int) (fd); \ - mhd__ke_tmp.filter = (evfltr); \ - mhd__ke_tmp.flags = (evflags); \ - mhd__ke_tmp.udata = mhd_PTR_TO_KE_UDATA ((evudata_ptr)); \ +# define mhd_KE_SET(ev_ptr, fd, evfltr, evflags, evudata_ptr) do { \ + struct kevent mhd__ke_tmp = {0u}; \ + mhd__ke_tmp.ident = (unsigned int) (fd); \ + mhd__ke_tmp.filter = (evfltr); \ + mhd__ke_tmp.flags = (evflags); \ + mhd__ke_tmp.udata = mhd_PTR_TO_KE_UDATA ((evudata_ptr)); \ (*(ev_ptr)) = mhd__ke_tmp; } while (0) # ifdef EV_KEEPUDATA @@ -127,12 +127,12 @@ typedef intptr_t mhd_KE_UDATA_TYPE; # endif # ifndef __NetBSD__ -# define mhd_kevent(kqfd,chlist,nchs,evlist,nevs,tmout) \ - kevent ((kqfd),(chlist),(nchs),(evlist),(nevs),(tmout)) +# define mhd_kevent(kqfd, chlist, nchs, evlist, nevs, tmout) \ + kevent ((kqfd),(chlist),(nchs),(evlist),(nevs),(tmout)) # else /* ! __NetBSD__ */ -# define mhd_kevent(kqfd,chlist,nchs,evlist,nevs,tmout) \ - kevent ((kqfd),(chlist),(size_t) (nchs),(evlist),(size_t) (nevs), \ - (tmout)) +# define mhd_kevent(kqfd, chlist, nchs, evlist, nevs, tmout) \ + kevent ((kqfd),(chlist),(size_t) (nchs),(evlist),(size_t) (nevs), \ + (tmout)) # endif #endif /* MHD_SUPPORT_KQUEUE */ diff --git a/src/mhd2/sys_offsetof.h b/src/mhd2/sys_offsetof.h @@ -54,7 +54,7 @@ #ifndef offsetof # include "sys_sizet_type.h" # define offsetof(strct, membr) \ - ((size_t) (((char*) &(((strct*) 0)->membr)) - ((char*) ((strct*) 0)))) + ((size_t) (((char*) &(((strct*) 0)->membr)) - ((char*) ((strct*) 0)))) #endif /* ! offsetof */ #endif /* ! MHD_SYS_OFFSETOF_H */ diff --git a/src/mhd2/sys_poll.h b/src/mhd2/sys_poll.h @@ -59,7 +59,7 @@ # include <winsock2.h> # define mhd_poll WSAPoll # else -#error Uknown sockets type +# error Uknown sockets type # endif # if defined(HAVE_DCLR_POLLRDNORM) || defined(POLLRDNORM) diff --git a/src/mhd2/sys_select.h b/src/mhd2/sys_select.h @@ -71,7 +71,7 @@ # elif defined(MHD_SOCKETS_KIND_WINSOCK) # include <winsock2.h> # else -#error Uknown sockets type +# error Uknown sockets type # endif #endif /* MHD_SUPPORT_SELECT */ diff --git a/src/mhd2/sys_sendfile.h b/src/mhd2/sys_sendfile.h @@ -61,7 +61,7 @@ # endif # include <sys/uio.h> #elif defined(mhd_USE_SENDFILE) -#error mhd_USE_SENDFILE is defined, while no HAVE_xxx_SENDFILE defined +# error mhd_USE_SENDFILE is defined, while no HAVE_xxx_SENDFILE defined #endif #endif /* ! MHD_SYS_SENDFILE_H */ diff --git a/src/mhd2/sys_sockets_headers.h b/src/mhd2/sys_sockets_headers.h @@ -66,75 +66,75 @@ # include <sys/un.h> #endif -#if defined(SOCK_NONBLOCK) && ! defined(HAVE_DCLR_SOCK_NONBLOCK) +#if defined(SOCK_NONBLOCK) && !defined(HAVE_DCLR_SOCK_NONBLOCK) /* Mis-detected by configure */ # define HAVE_DCLR_SOCK_NONBLOCK 1 #endif -#if defined(SOCK_CLOEXEC) && ! defined(HAVE_DCLR_SOCK_CLOEXEC) +#if defined(SOCK_CLOEXEC) && !defined(HAVE_DCLR_SOCK_CLOEXEC) /* Mis-detected by configure */ # define HAVE_DCLR_SOCK_CLOEXEC 1 #endif -#if defined(SOCK_NOSIGPIPE) && ! defined(HAVE_DCLR_SOCK_NOSIGPIPE) +#if defined(SOCK_NOSIGPIPE) && !defined(HAVE_DCLR_SOCK_NOSIGPIPE) /* Mis-detected by configure */ # define HAVE_DCLR_SOCK_NOSIGPIPE 1 #endif -#if defined(MSG_NOSIGNAL) && ! defined(HAVE_DCLR_MSG_NOSIGNAL) +#if defined(MSG_NOSIGNAL) && !defined(HAVE_DCLR_MSG_NOSIGNAL) /* Mis-detected by configure */ # define HAVE_DCLR_MSG_NOSIGNAL 1 #endif -#if defined(MSG_MORE) && ! defined(HAVE_DCLR_MSG_MORE) +#if defined(MSG_MORE) && !defined(HAVE_DCLR_MSG_MORE) /* Mis-detected by configure */ # define HAVE_DCLR_MSG_MORE 1 #endif -#if defined(SOL_SOCKET) && ! defined(HAVE_DCLR_SOL_SOCKET) +#if defined(SOL_SOCKET) && !defined(HAVE_DCLR_SOL_SOCKET) /* Mis-detected by configure */ # define HAVE_DCLR_SOL_SOCKET 1 #endif -#if defined(SO_REUSEADDR) && ! defined(HAVE_DCLR_SO_REUSEADDR) +#if defined(SO_REUSEADDR) && !defined(HAVE_DCLR_SO_REUSEADDR) /* Mis-detected by configure */ # define HAVE_DCLR_SO_REUSEADDR 1 #endif -#if defined(SO_REUSEPORT) && ! defined(HAVE_DCLR_SO_REUSEPORT) +#if defined(SO_REUSEPORT) && !defined(HAVE_DCLR_SO_REUSEPORT) /* Mis-detected by configure */ # define HAVE_DCLR_SO_REUSEPORT 1 #endif -#if defined(SO_LINGER) && ! defined(HAVE_DCLR_SO_LINGER) +#if defined(SO_LINGER) && !defined(HAVE_DCLR_SO_LINGER) /* Mis-detected by configure */ # define HAVE_DCLR_SO_LINGER 1 #endif -#if defined(SO_NOSIGPIPE) && ! defined(HAVE_DCLR_SO_NOSIGPIPE) +#if defined(SO_NOSIGPIPE) && !defined(HAVE_DCLR_SO_NOSIGPIPE) /* Mis-detected by configure */ # define HAVE_DCLR_SO_NOSIGPIPE 1 #endif -#if defined(HAVE_DCLR_SOCK_NONBLOCK) && ! defined(MHD_SOCKETS_KIND_WINSOCK) +#if defined(HAVE_DCLR_SOCK_NONBLOCK) && !defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_SOCK_NONBLOCK SOCK_NONBLOCK #else # define mhd_SOCK_NONBLOCK (0) #endif -#if defined(HAVE_DCLR_SOCK_CLOEXEC) && ! defined(MHD_SOCKETS_KIND_WINSOCK) +#if defined(HAVE_DCLR_SOCK_CLOEXEC) && !defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_SOCK_CLOEXEC SOCK_CLOEXEC #else # define mhd_SOCK_CLOEXEC (0) #endif -#if defined(HAVE_DCLR_SOCK_NOSIGPIPE) && ! defined(MHD_SOCKETS_KIND_WINSOCK) +#if defined(HAVE_DCLR_SOCK_NOSIGPIPE) && !defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_SOCK_NOSIGPIPE SOCK_NOSIGPIPE #else # define mhd_SOCK_NOSIGPIPE (0) #endif -#if defined(HAVE_DCLR_MSG_NOSIGNAL) && ! defined(MHD_SOCKETS_KIND_WINSOCK) +#if defined(HAVE_DCLR_MSG_NOSIGNAL) && !defined(MHD_SOCKETS_KIND_WINSOCK) # define mhd_MSG_NOSIGNAL MSG_NOSIGNAL #else # define mhd_MSG_NOSIGNAL (0) @@ -179,22 +179,22 @@ * mhd_setsockopt() is a wrapper for system setsockopt() */ #ifdef MHD_SOCKETS_KIND_POSIX -# define mhd_setsockopt(sk,l,o_name,po_value,o_len) \ - setsockopt ((sk),(l),(o_name),(po_value),(o_len)) +# define mhd_setsockopt(sk, l, o_name, po_value, o_len) \ + setsockopt ((sk),(l),(o_name),(po_value),(o_len)) #else -# define mhd_setsockopt(sk,l,o_name,po_value,o_len) \ - setsockopt ((sk),(l),(o_name),(const char *) (po_value),(o_len)) +# define mhd_setsockopt(sk, l, o_name, po_value, o_len) \ + setsockopt ((sk),(l),(o_name),(const char *) (po_value),(o_len)) #endif /** * mhd_getsockopt() is a wrapper for system getsockopt() */ #ifdef MHD_SOCKETS_KIND_POSIX -# define mhd_getsockopt(sk,l,o_name,po_value,po_len) \ - getsockopt ((sk),(l),(o_name),(po_value),(po_len)) +# define mhd_getsockopt(sk, l, o_name, po_value, po_len) \ + getsockopt ((sk),(l),(o_name),(po_value),(po_len)) #else -# define mhd_getsockopt(sk,l,o_name,po_value,po_len) \ - getsockopt ((sk),(l),(o_name),(char *) (po_value),(po_len)) +# define mhd_getsockopt(sk, l, o_name, po_value, po_len) \ + getsockopt ((sk),(l),(o_name),(char *) (po_value),(po_len)) #endif /** @@ -254,9 +254,9 @@ static const mhd_SCKT_OPT_BOOL mhd_socket_nosig_helper_int_one = 1; * @return non-zero if succeeded, zero otherwise */ # define mhd_socket_nosignal(sock) \ - (! mhd_setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE, \ - &mhd_socket_nosig_helper_int_one, \ - sizeof(mhd_SCKT_OPT_BOOL))) + (! mhd_setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE, \ + &mhd_socket_nosig_helper_int_one, \ + sizeof(mhd_SCKT_OPT_BOOL))) #endif /* SOL_SOCKET && SO_NOSIGPIPE */ diff --git a/src/mhd2/sys_w32_ver.h b/src/mhd2/sys_w32_ver.h @@ -49,7 +49,7 @@ #include "mhd_sys_options.h" #ifndef _WIN32 -#error This file must not be used on non-W32 systems +# error This file must not be used on non-W32 systems #endif #ifndef _WIN32_WINNT diff --git a/src/mhd2/tls_gnu_conn_data.h b/src/mhd2/tls_gnu_conn_data.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_GNUTLS -#error This header can be used only if GnuTLS is enabled +# error This header can be used only if GnuTLS is enabled #endif #include "tls_gnu_tls_lib.h" diff --git a/src/mhd2/tls_gnu_daemon_data.h b/src/mhd2/tls_gnu_daemon_data.h @@ -50,7 +50,7 @@ #include "sys_bool_type.h" #ifndef MHD_SUPPORT_GNUTLS -#error This header can be used only if GnuTLS is enabled +# error This header can be used only if GnuTLS is enabled #endif #include "tls_gnu_tls_lib.h" diff --git a/src/mhd2/tls_gnu_funcs.c b/src/mhd2/tls_gnu_funcs.c @@ -90,23 +90,23 @@ static void mhd_tls_gnu_debug_print (int level, const char *msg) { - (void) fprintf (stderr, "## GnuTLS %02i: %s", - level, - msg); - (void) fflush (stderr); + (void)fprintf (stderr, "## GnuTLS %02i: %s", + level, + msg); + (void)fflush (stderr); } # define mhd_DBG_PRINT_TLS_INFO_MSG(message) \ - do { (void) fprintf (stderr, "## GnuTLS info: %s\n", (message)); \ - (void) fflush (stderr);} while (0) -# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message,param) \ - do { (void) fprintf (stderr, "## GnuTLS info: " message "\n", (param)); \ - (void) fflush (stderr);} while (0) + do { (void) fprintf (stderr, "## GnuTLS info: %s\n", (message)); \ + (void) fflush (stderr);} while (0) +# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message, param) \ + do { (void) fprintf (stderr, "## GnuTLS info: " message "\n", (param)); \ + (void) fflush (stderr);} while (0) #else /* ! mhd_USE_TLS_DEBUG_MESSAGES */ # define mhd_DBG_PRINT_TLS_ERRS() ERR_clear_error () # define mhd_DBG_PRINT_TLS_INFO_MSG(message) ((void) 0) -# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message,param) ((void) 0) +# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message, param) ((void) 0) #endif /* ! mhd_USE_TLS_DEBUG_MESSAGES */ #ifdef mhd_TLS_GNU_HAS_ALPN @@ -119,16 +119,16 @@ static const char mhd_alpn_str_http2[] = mhd_ALPN_H2; static const char alpn_http_3[] = mhd_ALPN_H3; # endif static const gnutls_datum_t mhd_alpn_dat_http1_0 = { - (unsigned char *) mhd_DROP_CONST (mhd_alpn_str_http1_0), + (unsigned char *)mhd_DROP_CONST (mhd_alpn_str_http1_0), mhd_SSTR_LEN (mhd_alpn_str_http1_0) }; static const gnutls_datum_t mhd_alpn_dat_http1_1 = { - (unsigned char *) mhd_DROP_CONST (mhd_alpn_str_http1_1), + (unsigned char *)mhd_DROP_CONST (mhd_alpn_str_http1_1), mhd_SSTR_LEN (mhd_alpn_str_http1_1) }; # ifdef MHD_SUPPORT_HTTP2 static const gnutls_datum_t mhd_alpn_dat_http2 = { - (unsigned char *) mhd_DROP_CONST (mhd_alpn_str_http2), + (unsigned char *)mhd_DROP_CONST (mhd_alpn_str_http2), mhd_SSTR_LEN (mhd_alpn_str_http2) }; # endif @@ -190,8 +190,8 @@ check_app_tls_settings (struct MHD_Daemon *restrict d, struct DaemonOptions *restrict s) { mhd_assert (MHD_TLS_BACKEND_NONE != s->tls); - mhd_assert ((MHD_TLS_BACKEND_GNUTLS == s->tls) || \ - (MHD_TLS_BACKEND_ANY == s->tls)); + mhd_assert ((MHD_TLS_BACKEND_GNUTLS == s->tls) \ + || (MHD_TLS_BACKEND_ANY == s->tls)); if (NULL == s->tls_cert_key.v_mem_cert) { mhd_LOG_MSG (d, MHD_SC_TLS_CONF_BAD_CERT, \ @@ -249,7 +249,7 @@ daemon_init_dh_data (struct mhd_TlsGnuDaemonData *restrict d_tls) gnutls_dh_params_deinit (d_tls->dh_params); return false; #else - (void) d_tls; /* Mute compiler warning */ + (void)d_tls; /* Mute compiler warning */ return true; #endif } @@ -266,7 +266,7 @@ daemon_deinit_dh_data (struct mhd_TlsGnuDaemonData *restrict d_tls) mhd_assert (NULL != d_tls->dh_params); gnutls_dh_params_deinit (d_tls->dh_params); #else - (void) d_tls; /* Mute compiler warning */ + (void)d_tls; /* Mute compiler warning */ #endif } @@ -304,8 +304,8 @@ daemon_init_credentials (struct MHD_Daemon *restrict d, mhd_assert (0 != cert_len); mhd_assert (0 != key_len); - if ((cert_len != (unsigned int) cert_len) - || (key_len != (unsigned int) key_len)) + if ((cert_len != (unsigned int)cert_len) + || (key_len != (unsigned int)key_len)) ret = MHD_SC_TLS_CONF_BAD_CERT; /* Very unlikely, do not waste space on special message */ else { @@ -314,11 +314,11 @@ daemon_init_credentials (struct MHD_Daemon *restrict d, int res; cert_data.data = - (unsigned char *) mhd_DROP_CONST (s->tls_cert_key.v_mem_cert); - cert_data.size = (unsigned int) cert_len; + (unsigned char *)mhd_DROP_CONST (s->tls_cert_key.v_mem_cert); + cert_data.size = (unsigned int)cert_len; key_data.data = - (unsigned char *) mhd_DROP_CONST (s->tls_cert_key.v_mem_key); - key_data.size = (unsigned int) key_len; + (unsigned char *)mhd_DROP_CONST (s->tls_cert_key.v_mem_key); + key_data.size = (unsigned int)key_len; res = gnutls_certificate_set_x509_key_mem2 (d_tls->cred, &cert_data, &key_data, @@ -336,7 +336,7 @@ daemon_init_credentials (struct MHD_Daemon *restrict d, } else { - if (! daemon_init_dh_data (d_tls)) + if (!daemon_init_dh_data (d_tls)) { mhd_LOG_MSG (d, MHD_SC_TLS_DAEMON_INIT_FAILED, \ "Failed to initialise Diffie-Hellman parameters " \ @@ -466,7 +466,7 @@ daemon_init_priorities_cache (struct MHD_Daemon *restrict d, for (i = 0; i < mhd_ARR_NUM_ELEMS (tlsgnulib_base_priorities); ++i) { int res; -#if ! defined(mhd_TLS_GNU_TREATS_NULL_AS_DEF_PRIORITY) +#if !defined(mhd_TLS_GNU_TREATS_NULL_AS_DEF_PRIORITY) if (NULL == tlsgnulib_base_priorities[i].cstr) { /* GnuTLS default priorities */ @@ -502,7 +502,7 @@ daemon_init_priorities_cache (struct MHD_Daemon *restrict d, static MHD_FN_PAR_NONNULL_ALL_ void daemon_deinit_priorities_cache (struct mhd_TlsGnuDaemonData *restrict d_tls) { -#if ! defined(mhd_TLS_GNU_NULL_PRIO_CACHE_MEANS_DEF_PRIORITY) +#if !defined(mhd_TLS_GNU_NULL_PRIO_CACHE_MEANS_DEF_PRIORITY) mhd_assert (NULL != d_tls->pri_cache); #else if (NULL != d_tls->pri_cache) @@ -538,10 +538,10 @@ mhd_tls_gnu_daemon_init3 (struct MHD_Daemon *restrict d, // TODO: use daemon option to select protocols for ALPN d_tls->num_alpn_prots = 0; -#ifdef MHD_SUPPORT_HTTP2 +# ifdef MHD_SUPPORT_HTTP2 if (1 /* enabled HTTP/2 ? */) d_tls->alpn_prots[d_tls->num_alpn_prots++] = mhd_alpn_dat_http2; -#endif /* MHD_SUPPORT_HTTP2 */ +# endif /* MHD_SUPPORT_HTTP2 */ if (1 /* enabled HTTP/1.x ? */) { @@ -622,11 +622,11 @@ mhd_tls_gnu_conn_init (const struct mhd_TlsGnuDaemonData *restrict d_tls, return false; #if GNUTLS_VERSION_NUMBER >= 0x030100 - if (! sk->props.is_nonblck) + if (!sk->props.is_nonblck) gnutls_handshake_set_timeout (c_tls->sess, GNUTLS_DEFAULT_HANDSHAKE_TIMEOUT); #endif -#if ! defined(mhd_TLS_GNU_NULL_PRIO_CACHE_MEANS_DEF_PRIORITY) +#if !defined(mhd_TLS_GNU_NULL_PRIO_CACHE_MEANS_DEF_PRIORITY) mhd_assert (NULL != d_tls->pri_cache); #else if (NULL == d_tls->pri_cache) @@ -672,7 +672,7 @@ mhd_tls_gnu_conn_init (const struct mhd_TlsGnuDaemonData *restrict d_tls, d_tls->alpn_prots, d_tls->num_alpn_prots, alpn_flags); - (void) alpn_res; /* Ignore any possible ALPN set errors */ + (void)alpn_res; /* Ignore any possible ALPN set errors */ } #endif /* mhd_TLS_GNU_HAS_ALPN */ #ifndef NDEBUG @@ -712,9 +712,9 @@ mhd_tls_gnu_conn_handshake (struct mhd_TlsGnuConnData *restrict c_tls) int res; mhd_assert (c_tls->dbg.is_inited); - mhd_assert (! c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->dbg.is_finished); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_tls_handshake_completed); + mhd_assert (!c_tls->dbg.is_finished); + mhd_assert (!c_tls->dbg.is_failed); res = gnutls_handshake (c_tls->sess); switch (res) @@ -759,8 +759,8 @@ mhd_tls_gnu_conn_shutdown (struct mhd_TlsGnuConnData *restrict c_tls) mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->dbg.is_finished); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_finished); + mhd_assert (!c_tls->dbg.is_failed); res = gnutls_bye (c_tls->sess, c_tls->rmt_shut_tls_wr ? GNUTLS_SHUT_WR : GNUTLS_SHUT_RDWR); @@ -801,7 +801,7 @@ mhd_tls_gnu_conn_shutdown (struct mhd_TlsGnuConnData *restrict c_tls) /* ** Data receiving and sending ** */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_tls_gnu_conn_recv (struct mhd_TlsGnuConnData *restrict c_tls, size_t buf_size, @@ -812,12 +812,12 @@ mhd_tls_gnu_conn_recv (struct mhd_TlsGnuConnData *restrict c_tls, mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->dbg.is_finished); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_finished); + mhd_assert (!c_tls->dbg.is_failed); /* Check for GnuTLS return value limitation */ - if (0 > (ssize_t) buf_size) - buf_size = (ssize_t) ((~((size_t) 0u)) >> 1); /* SSIZE_MAX */ + if (0 > (ssize_t)buf_size) + buf_size = (ssize_t)((~((size_t)0u)) >> 1); /* SSIZE_MAX */ res = gnutls_record_recv (c_tls->sess, buf, @@ -846,7 +846,7 @@ mhd_tls_gnu_conn_recv (struct mhd_TlsGnuConnData *restrict c_tls, return mhd_SOCKET_ERR_TLS; } - *received = (size_t) res; + *received = (size_t)res; return mhd_SOCKET_ERR_NO_ERROR; } @@ -859,7 +859,7 @@ mhd_tls_gnu_conn_has_data_in (struct mhd_TlsGnuConnData *restrict c_tls) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_tls_gnu_conn_send4 (struct mhd_TlsGnuConnData *restrict c_tls, size_t buf_size, @@ -870,12 +870,12 @@ mhd_tls_gnu_conn_send4 (struct mhd_TlsGnuConnData *restrict c_tls, mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->dbg.is_finished); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_finished); + mhd_assert (!c_tls->dbg.is_failed); /* Check for GnuTLS return value limitation */ - if (0 > (ssize_t) buf_size) - buf_size = (ssize_t) ((~((size_t) 0u)) >> 1); /* SSIZE_MAX */ + if (0 > (ssize_t)buf_size) + buf_size = (ssize_t)((~((size_t)0u)) >> 1); /* SSIZE_MAX */ res = gnutls_record_send (c_tls->sess, buf, @@ -904,7 +904,7 @@ mhd_tls_gnu_conn_send4 (struct mhd_TlsGnuConnData *restrict c_tls, return mhd_SOCKET_ERR_TLS; } - *sent = (size_t) res; + *sent = (size_t)res; return mhd_SOCKET_ERR_NO_ERROR; } diff --git a/src/mhd2/tls_gnu_funcs.h b/src/mhd2/tls_gnu_funcs.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_GNUTLS -#error This header can be used only if GnuTLS is enabled +# error This header can be used only if GnuTLS is enabled #endif #include "sys_bool_type.h" @@ -143,7 +143,7 @@ MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (3); * @return #MHD_SC_OK on success (p_d_tls set to the allocated settings), * error code otherwise */ -#define mhd_tls_gnu_daemon_init(d,et,s,p_d_tls) \ +#define mhd_tls_gnu_daemon_init(d, et, s, p_d_tls) \ mhd_tls_gnu_daemon_init3 ((d),(s),(p_d_tls)) /** @@ -246,7 +246,7 @@ mhd_tls_gnu_conn_recv (struct mhd_TlsGnuConnData *restrict c_tls, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict received) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); /** * Check whether any incoming data is pending in the TLS buffers @@ -275,7 +275,7 @@ mhd_tls_gnu_conn_send4 (struct mhd_TlsGnuConnData *restrict c_tls, size_t buf_size, const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict sent) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); /** * Send data to the remote side over TLS connection @@ -290,7 +290,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets * the sent size) or socket error */ -#define mhd_tls_gnu_conn_send(c_tls,buf_size,buf,push_data,sent) \ +#define mhd_tls_gnu_conn_send(c_tls, buf_size, buf, push_data, sent) \ mhd_tls_gnu_conn_send4 (c_tls,buf_size,buf,sent) /* ** TLS connection information ** */ diff --git a/src/mhd2/tls_gnu_tls_lib.h b/src/mhd2/tls_gnu_tls_lib.h @@ -48,13 +48,13 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_GNUTLS -#error This header can be used only if GnuTLS is enabled +# error This header can be used only if GnuTLS is enabled #endif #include <gnutls/gnutls.h> #ifndef GNUTLS_VERSION_NUMBER -#error GNUTLS_VERSION_NUMBER is not defined +# error GNUTLS_VERSION_NUMBER is not defined #endif #if GNUTLS_VERSION_NUMBER >= 0x030600 @@ -93,7 +93,7 @@ # define mhd_TLS_GNU_TREATS_NULL_AS_DEF_PRIORITY 1 #endif -#if ! defined(mhd_TLS_GNU_TREATS_NULL_AS_DEF_PRIORITY) \ +#if !defined(mhd_TLS_GNU_TREATS_NULL_AS_DEF_PRIORITY) \ && defined(mhd_TLS_GNU_HAS_SET_DEF_PRIORITY) /** * Defined if NULL in priorities cache is treated as indication that default diff --git a/src/mhd2/tls_mbed_conn_data.h b/src/mhd2/tls_mbed_conn_data.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_MBEDTLS -#error This header can be used only if MbedTLS is enabled +# error This header can be used only if MbedTLS is enabled #endif #include "sys_bool_type.h" diff --git a/src/mhd2/tls_mbed_daemon_data.h b/src/mhd2/tls_mbed_daemon_data.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_MBEDTLS -#error This header can be used only if MbedTLS is enabled +# error This header can be used only if MbedTLS is enabled #endif #include "tls_mbed_tls_lib.h" diff --git a/src/mhd2/tls_mbed_funcs.c b/src/mhd2/tls_mbed_funcs.c @@ -102,11 +102,11 @@ /* MHD_TLS_MBED_DBG_PRINT_LEVEL can be defined to number in range 0..5, where 5 is the most detailed log */ -#ifdef MHD_TLS_MBED_DBG_PRINT_LEVEL -# define mhd_DBG_PRINT_LEVEL (MHD_TLS_MBED_DBG_PRINT_LEVEL + 0) -#else -# define mhd_DBG_PRINT_LEVEL (2) -#endif +# ifdef MHD_TLS_MBED_DBG_PRINT_LEVEL +# define mhd_DBG_PRINT_LEVEL (MHD_TLS_MBED_DBG_PRINT_LEVEL + 0) +# else +# define mhd_DBG_PRINT_LEVEL (2) +# endif static void mhd_tls_mbed_debug_print (void *ctx, @@ -115,17 +115,17 @@ mhd_tls_mbed_debug_print (void *ctx, int line_num, const char *msg) { - (void) ctx; /* Unused */ + (void)ctx; /* Unused */ /* The level should be pre-filtred by MbedTLS, but it is filtered again here in case if something else changed it. */ if (mhd_DBG_PRINT_LEVEL < level) return; - (void) fprintf (stderr, "## MbedTLS %02i [%s:%d]: %s", - level, - filename, - line_num, - msg); - (void) fflush (stderr); + (void)fprintf (stderr, "## MbedTLS %02i [%s:%d]: %s", + level, + filename, + line_num, + msg); + (void)fflush (stderr); } @@ -139,27 +139,27 @@ static const mbedtls_md_info_t * mbed_get_md_for_drbg (void) { mhd_constexpr mbedtls_md_type_t mds[] = { -#ifdef mhd_TLS_MBED_HAS_SHA3_IDS +# ifdef mhd_TLS_MBED_HAS_SHA3_IDS MBEDTLS_MD_SHA3_256 , -#endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ +# endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ MBEDTLS_MD_SHA256 -#ifdef mhd_TLS_MBED_HAS_SHA3_IDS +# ifdef mhd_TLS_MBED_HAS_SHA3_IDS , MBEDTLS_MD_SHA3_512 -#endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ +# endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ , MBEDTLS_MD_SHA512 -#ifdef mhd_TLS_MBED_HAS_SHA3_IDS +# ifdef mhd_TLS_MBED_HAS_SHA3_IDS , MBEDTLS_MD_SHA3_384 -#endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ +# endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ , MBEDTLS_MD_SHA384 -#ifdef mhd_TLS_MBED_HAS_SHA3_IDS +# ifdef mhd_TLS_MBED_HAS_SHA3_IDS , MBEDTLS_MD_SHA3_224 -#endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ +# endif /* mhd_TLS_MBED_HAS_SHA3_IDS */ , MBEDTLS_MD_SHA224 }; @@ -173,7 +173,7 @@ mbed_get_md_for_drbg (void) return ret; } - return (const mbedtls_md_info_t *) NULL; + return (const mbedtls_md_info_t *)NULL; } @@ -211,11 +211,11 @@ mbed_rng_init (void) entropy_cb_ctx = &mhd_mbed_entr_ctx; # else /* ! mhd_TLS_MBED_USE_LIB_ENTROPY */ /* Seeding with system's entropy sources could be implemented here */ -#error MbedTLS random generator needs entropy sources +# error MbedTLS random generator needs entropy sources # endif /* ! mhd_TLS_MBED_USE_LIB_ENTROPY */ #endif /* mhd_TLS_MBED_RNG_PREF_NEEDS_ENTROPY */ - mhd_assert (! mbedtls_rng_inited_now); + mhd_assert (!mbedtls_rng_inited_now); if (1) /* For local scope only */ { @@ -252,7 +252,7 @@ mbed_rng_init (void) entropy_cb_ctx, pers, sizeof(pers))); - if (! mbedtls_rng_inited_now) + if (!mbedtls_rng_inited_now) mbedtls_ctr_drbg_free (&mhd_mbed_ctr_drbg_ctx); #elif defined(MHD_TLS_MBED_PREF_RNG_HMAC) mbedtls_hmac_drbg_init (&mhd_mbed_hmac_drbg_ctx); @@ -263,14 +263,14 @@ mbed_rng_init (void) entropy_cb_ctx, pers, sizeof(pers))); - if (! mbedtls_rng_inited_now) + if (!mbedtls_rng_inited_now) mbedtls_hmac_drbg_free (&mhd_mbed_hmac_drbg_ctx); #elif defined(MHD_TLS_MBED_PREF_RNG_PSA) mbedtls_rng_inited_now = true; /* No additional initialisation needed */ -#elif ! defined(mhd_TLS_MBED_INIT_TLS_REQ_RNG) +#elif !defined(mhd_TLS_MBED_INIT_TLS_REQ_RNG) mbedtls_rng_inited_now = false; #else /* mhd_TLS_MBED_INIT_TLS_REQ_RNG */ -#error MbedTLS backend requires random generator +# error MbedTLS backend requires random generator /* Support for external strong random generator could be added */ mbedtls_rng_inited_now = false; #endif @@ -289,7 +289,7 @@ mbed_rng_init (void) static void mbed_rng_deinit (void) { - if (! mbedtls_rng_inited_now) + if (!mbedtls_rng_inited_now) return; #if defined(MHD_TLS_MBED_PREF_RNG_CTR) @@ -324,7 +324,7 @@ mhd_tls_mbed_global_init (void) # ifdef mhd_TLS_MBED_USE_PLATFORM_TEARDOWN /* 'setup' platform repeatedly only only if 'teardown' is called */ if (mbedtls_lib_inited_once) - (void) 0; /* Do not repeat 'setup' */ + (void)0; /* Do not repeat 'setup' */ else /* combined with tne next 'if()' */ # endif /* mhd_TLS_MBED_USE_PLATFORM_TEARDOWN */ if (0 != mbedtls_platform_setup (&mhd_mbed_plat_ctx)) @@ -335,9 +335,9 @@ mhd_tls_mbed_global_init (void) /* It is safe to call psa_crypto_init() several times */ if (PSA_SUCCESS != psa_crypto_init ()) { -#ifdef mhd_TLS_MBED_USE_PLATFORM_TEARDOWN +# ifdef mhd_TLS_MBED_USE_PLATFORM_TEARDOWN mbedtls_platform_teardown (&mhd_mbed_plat_ctx); -#endif /* mhd_TLS_MBED_USE_PLATFORM_TEARDOWN */ +# endif /* mhd_TLS_MBED_USE_PLATFORM_TEARDOWN */ return; } #endif /* mhd_TLS_MBED_USE_PSA */ @@ -346,11 +346,11 @@ mhd_tls_mbed_global_init (void) #if mhd_TLS_MBED_INIT_TLS_REQ_RNG mbedtls_lib_inited_now = mbed_rng_init (); #else /* ! mhd_TLS_MBED_INIT_TLS_REQ_RNG */ - (void) mbed_rng_init (); + (void)mbed_rng_init (); mbedtls_lib_inited_now = true; /* MbedTLS could be used even without random generator */ #endif /* ! mhd_TLS_MBED_INIT_TLS_REQ_RNG */ - if (! mbedtls_lib_inited_now) + if (!mbedtls_lib_inited_now) { #ifdef mhd_TLS_MBED_USE_PLATFORM_TEARDOWN mbedtls_platform_teardown (&mhd_mbed_plat_ctx); @@ -359,7 +359,7 @@ mhd_tls_mbed_global_init (void) #ifdef mhd_TLS_MBED_USE_PSA_FREE mbedtls_psa_crypto_free (); #endif /* mhd_TLS_MBED_USE_PLATFORM_TEARDOWN */ - (void) 0; + (void)0; } } @@ -367,7 +367,7 @@ mhd_tls_mbed_global_init (void) MHD_INTERNAL void mhd_tls_mbed_global_deinit (void) { - if (! mbedtls_lib_inited_now) + if (!mbedtls_lib_inited_now) return; mbed_rng_deinit (); @@ -391,7 +391,7 @@ mhd_tls_mbed_global_deinit (void) MHD_INTERNAL MHD_FN_PURE_ bool mhd_tls_mbed_is_inited_fine (void) { - mhd_assert (! mbedtls_lib_inited_now || mbedtls_lib_inited_once); + mhd_assert (!mbedtls_lib_inited_now || mbedtls_lib_inited_once); return mbedtls_lib_inited_now; } @@ -410,8 +410,8 @@ check_app_tls_settings (struct MHD_Daemon *restrict d, struct DaemonOptions *restrict s) { mhd_assert (MHD_TLS_BACKEND_NONE != s->tls); - mhd_assert ((MHD_TLS_BACKEND_MBEDTLS == s->tls) || \ - (MHD_TLS_BACKEND_ANY == s->tls)); + mhd_assert ((MHD_TLS_BACKEND_MBEDTLS == s->tls) \ + || (MHD_TLS_BACKEND_ANY == s->tls)); if (NULL == s->tls_cert_key.v_mem_cert) { @@ -421,12 +421,12 @@ check_app_tls_settings (struct MHD_Daemon *restrict d, } mhd_assert (NULL != s->tls_cert_key.v_mem_key); - if ((MHD_WM_THREAD_PER_CONNECTION == s->work_mode.mode) || - ((MHD_WM_WORKER_THREADS == s->work_mode.mode) - && (1u < s->work_mode.params.num_worker_threads))) + if ((MHD_WM_THREAD_PER_CONNECTION == s->work_mode.mode) + || ((MHD_WM_WORKER_THREADS == s->work_mode.mode) + && (1u < s->work_mode.params.num_worker_threads))) { bool threads_supported; -#if ! defined(MBEDTLS_THREADING_C) +#if !defined(MBEDTLS_THREADING_C) threads_supported = false; #else /* MBEDTLS_THREADING_C */ # if defined(MBEDTLS_VERSION_FEATURES) @@ -436,7 +436,7 @@ check_app_tls_settings (struct MHD_Daemon *restrict d, threads_supported = true; # endif /* ! MBEDTLS_VERSION_FEATURES */ #endif /* MBEDTLS_THREADING_C */ - if (! threads_supported) + if (!threads_supported) { mhd_LOG_MSG (d, MHD_SC_TLS_BACKEND_DAEMON_INCOMPATIBLE_SETTINGS, \ "MbedTLS built without threading support and cannot " @@ -549,8 +549,8 @@ daemon_init_credentials ( res = mbedtls_pk_check_pair (&(d_tls->cert_chain.pk), &(d_tls->prv_key)); # endif /* ! mhd_TLS_MBED_INIT_TLS_REQ_RNG */ - if ((0 == res) || - (MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE == res)) + if ((0 == res) + || (MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE == res)) return MHD_SC_OK; /* Success exit point */ mhd_LOG_MSG (d, MHD_SC_TLS_CONF_BAD_CERT, \ @@ -618,14 +618,14 @@ daemon_set_alpn (struct MHD_Daemon *restrict d, # endif size_t i; - (void) s; /* Unused currently. Implement reading allowed HTTP versions */ + (void)s; /* Unused currently. Implement reading allowed HTTP versions */ i = 0u; // TODO: implement reading protocol versions from settings */ -#ifdef MHD_SUPPORT_HTTP2 +# ifdef MHD_SUPPORT_HTTP2 if (1 /* enabled HTTP/2 ? */) d_tls->alpn_prots[i++] = alpn_str_http2; -#endif /* MHD_SUPPORT_HTTP2 */ +# endif /* MHD_SUPPORT_HTTP2 */ if (1 /* enabled HTTP/1.x ? */) { @@ -648,7 +648,7 @@ daemon_set_alpn (struct MHD_Daemon *restrict d, #else /* ! MBEDTLS_SSL_ALPN */ -# define daemon_set_alpn(d,d_tls,s) (MHD_SC_OK) +# define daemon_set_alpn(d, d_tls, s) (MHD_SC_OK) #endif /* ! MBEDTLS_SSL_ALPN */ /** @@ -681,7 +681,7 @@ daemon_init_config (struct MHD_Daemon *restrict d, rng_ctx = MBEDTLS_PSA_RANDOM_STATE; # else /* MHD_TLS_MBED_PREF_RNG_PSA */ /* Support for external strong random generator could be added here */ -#error No random generator is enabled in MbedTLS +# error No random generator is enabled in MbedTLS return MHD_SC_INTERNAL_ERROR; # endif /* MHD_TLS_MBED_PREF_RNG_PSA */ @@ -899,7 +899,7 @@ mhd_tls_mbed_sckt_comm_prep_send (struct mhd_TlsMbedConnData *restrict c_tls, if (push_data) c_tls->tr.state.send_unenc_size = unencr_size; else - c_tls->tr.state.send_unenc_size = (size_t) (~((size_t) 0)); + c_tls->tr.state.send_unenc_size = (size_t)(~((size_t)0)); } @@ -920,7 +920,7 @@ mhd_mbed_cb_recv (void *ctx, unsigned char *buf, size_t size) { - struct mhd_TlsMbedConnData *const c_tls = (struct mhd_TlsMbedConnData *) ctx; + struct mhd_TlsMbedConnData *const c_tls = (struct mhd_TlsMbedConnData *)ctx; struct mhd_TlsMbedConnCstmTrtState *const state = &(c_tls->tr.state); size_t received; @@ -937,38 +937,38 @@ mhd_mbed_cb_recv (void *ctx, checked by MHD for 'send-ready' as receiving operation was expected. Do not use recv() if 'recv-ready' is not known and the socket is blocking. */ - if (state->send_called && ! c_tls->tr.sk->props.is_nonblck) + if (state->send_called && !c_tls->tr.sk->props.is_nonblck) return MBEDTLS_ERR_SSL_WANT_READ; if (1) { - const int size_i = (int) size; + const int size_i = (int)size; - if ((0 > size_i) || - (size != (size_t) size_i)) + if ((0 > size_i) + || (size != (size_t)size_i)) { /* Return value limitation */ - size = (size_t) (((unsigned int) ~((unsigned int) 0)) >> 1u); + size = (size_t)(((unsigned int)~((unsigned int)0)) >> 1u); } } state->recv_res = mhd_sckt_recv (c_tls->tr.sk, size, - (char *) buf, + (char *)buf, &received); state->recv_called = true; if (mhd_SOCKET_ERR_NO_ERROR == state->recv_res) { mhd_ASSUME (size >= received); - mhd_assert (0 <= (int) received); - return (int) received; + mhd_assert (0 <= (int)received); + return (int)received; } if (mhd_SOCKET_ERR_INTR >= state->recv_res) { - mhd_assert ((mhd_SOCKET_ERR_INTR == state->recv_res) || - (mhd_SOCKET_ERR_AGAIN == state->recv_res)); + mhd_assert ((mhd_SOCKET_ERR_INTR == state->recv_res) + || (mhd_SOCKET_ERR_AGAIN == state->recv_res)); return MBEDTLS_ERR_SSL_WANT_READ; } @@ -998,7 +998,7 @@ mhd_mbed_cb_send (void *ctx, const unsigned char *buf, size_t size) { - struct mhd_TlsMbedConnData *const c_tls = (struct mhd_TlsMbedConnData *) ctx; + struct mhd_TlsMbedConnData *const c_tls = (struct mhd_TlsMbedConnData *)ctx; struct mhd_TlsMbedConnCstmTrtState *const state = &(c_tls->tr.state); /* Check whether the complete data is sending. The compression is not used so the data after the encryption must not @@ -1021,25 +1021,25 @@ mhd_mbed_cb_send (void *ctx, checked by MHD for 'recv-ready' as receiving operation was expected. Do not use send() if 'send-ready' is not known and the socket is blocking. */ - if (state->recv_called && ! c_tls->tr.sk->props.is_nonblck) + if (state->recv_called && !c_tls->tr.sk->props.is_nonblck) return MBEDTLS_ERR_SSL_WANT_WRITE; if (1) { - const int size_i = (int) size; + const int size_i = (int)size; - if ((0 > size_i) || - (size != (size_t) size_i)) + if ((0 > size_i) + || (size != (size_t)size_i)) { /* Return value limitation */ - size = (size_t) (((unsigned int) ~((unsigned int) 0)) >> 1u); + size = (size_t)(((unsigned int)~((unsigned int)0)) >> 1u); push_data = false; } } state->send_res = mhd_sckt_send (c_tls->tr.sk, size, - (const char *) buf, + (const char *)buf, push_data, &sent); state->send_called = true; @@ -1047,14 +1047,14 @@ mhd_mbed_cb_send (void *ctx, if (mhd_SOCKET_ERR_NO_ERROR == state->send_res) { mhd_ASSUME (size >= sent); - mhd_assert (0 < (int) sent); - return (int) sent; + mhd_assert (0 < (int)sent); + return (int)sent; } if (mhd_SOCKET_ERR_INTR >= state->send_res) { - mhd_assert ((mhd_SOCKET_ERR_INTR == state->send_res) || - (mhd_SOCKET_ERR_AGAIN == state->send_res)); + mhd_assert ((mhd_SOCKET_ERR_INTR == state->send_res) + || (mhd_SOCKET_ERR_AGAIN == state->send_res)); return MBEDTLS_ERR_SSL_WANT_WRITE; } @@ -1077,19 +1077,19 @@ mhd_tls_mbed_conn_handshake (struct mhd_TlsMbedConnData *c_tls) int res; mhd_assert (c_tls->dbg.is_inited); - mhd_assert (! c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->shut_tls_wr_sent); - mhd_assert (! c_tls->shut_tls_wr_received); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_tls_handshake_completed); + mhd_assert (!c_tls->shut_tls_wr_sent); + mhd_assert (!c_tls->shut_tls_wr_received); + mhd_assert (!c_tls->dbg.is_failed); mhd_tls_mbed_sckt_comm_prep (c_tls); res = mbedtls_ssl_handshake (&(c_tls->sess)); - mhd_assert ((c_tls->tr.state.recv_called) || - (mhd_SOCKET_ERR_NO_ERROR == c_tls->tr.state.recv_res)); - mhd_assert ((c_tls->tr.state.send_called) || - (mhd_SOCKET_ERR_NO_ERROR == c_tls->tr.state.send_res)); + mhd_assert ((c_tls->tr.state.recv_called) + || (mhd_SOCKET_ERR_NO_ERROR == c_tls->tr.state.recv_res)); + mhd_assert ((c_tls->tr.state.send_called) + || (mhd_SOCKET_ERR_NO_ERROR == c_tls->tr.state.send_res)); switch (res) { @@ -1100,10 +1100,10 @@ mhd_tls_mbed_conn_handshake (struct mhd_TlsMbedConnData *c_tls) return mhd_TLS_PROCED_SUCCESS; /* Success exit point */ case MBEDTLS_ERR_SSL_WANT_READ: - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); - if (! c_tls->tr.state.recv_called) + if (!c_tls->tr.state.recv_called) return mhd_TLS_PROCED_RECV_INTERRUPTED; /* Do not clear 'recv-ready' flag */ if (mhd_SOCKET_ERR_AGAIN == c_tls->tr.state.recv_res) @@ -1112,10 +1112,10 @@ mhd_tls_mbed_conn_handshake (struct mhd_TlsMbedConnData *c_tls) return mhd_TLS_PROCED_RECV_INTERRUPTED; /* Do not clear 'recv-ready' flag */ case MBEDTLS_ERR_SSL_WANT_WRITE: - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); - if (! c_tls->tr.state.send_called) + if (!c_tls->tr.state.send_called) return mhd_TLS_PROCED_SEND_INTERRUPTED; /* Do not clear 'send-ready' flag */ if (mhd_SOCKET_ERR_AGAIN == c_tls->tr.state.send_res) @@ -1134,16 +1134,16 @@ mhd_tls_mbed_conn_handshake (struct mhd_TlsMbedConnData *c_tls) so map it to "waiting for send-ready" as the socket should be already 'send-ready'. */ - return (c_tls->tr.state.send_called && - (mhd_SOCKET_ERR_AGAIN == c_tls->tr.state.send_res)) ? + return (c_tls->tr.state.send_called + && (mhd_SOCKET_ERR_AGAIN == c_tls->tr.state.send_res)) ? mhd_TLS_PROCED_SEND_MORE_NEEDED : mhd_TLS_PROCED_SEND_INTERRUPTED; case MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA: #ifdef MBEDTLS_SSL_EARLY_DATA /* Could be replaced with early data support is implemented */ #endif /* MBEDTLS_SSL_EARLY_DATA */ - mhd_assert (0 && - "MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA must not be returned"); + mhd_assert (0 + && "MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA must not be returned"); break; default: @@ -1167,7 +1167,7 @@ mhd_tls_mbed_conn_shutdown (struct mhd_TlsMbedConnData *c_tls) mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_failed); mhd_tls_mbed_sckt_comm_prep (c_tls); @@ -1181,10 +1181,10 @@ mhd_tls_mbed_conn_shutdown (struct mhd_TlsMbedConnData *c_tls) return mhd_TLS_PROCED_SUCCESS; /* Success exit point */ case MBEDTLS_ERR_SSL_WANT_READ: - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); - if (! c_tls->tr.state.recv_called) + if (!c_tls->tr.state.recv_called) return mhd_TLS_PROCED_RECV_INTERRUPTED; /* Do not clear 'recv-ready' flag */ if (mhd_SOCKET_ERR_AGAIN == c_tls->tr.state.recv_res) @@ -1193,10 +1193,10 @@ mhd_tls_mbed_conn_shutdown (struct mhd_TlsMbedConnData *c_tls) return mhd_TLS_PROCED_RECV_INTERRUPTED; /* Do not clear 'recv-ready' flag */ case MBEDTLS_ERR_SSL_WANT_WRITE: - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); - if (! c_tls->tr.state.send_called) + if (!c_tls->tr.state.send_called) return mhd_TLS_PROCED_SEND_INTERRUPTED; /* Do not clear 'send-ready' flag */ if (mhd_SOCKET_ERR_AGAIN == c_tls->tr.state.send_res) @@ -1220,7 +1220,7 @@ mhd_tls_mbed_conn_shutdown (struct mhd_TlsMbedConnData *c_tls) /* ** Data receiving and sending ** */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, size_t buf_size, @@ -1233,17 +1233,17 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->shut_tls_wr_sent); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->shut_tls_wr_sent); + mhd_assert (!c_tls->dbg.is_failed); if (1) { - const int buf_size_i = (int) buf_size; - if ((0 > buf_size_i) || - (buf_size != (size_t) buf_size_i)) + const int buf_size_i = (int)buf_size; + if ((0 > buf_size_i) + || (buf_size != (size_t)buf_size_i)) { /* Called function return value limitation */ - buf_size = (size_t) (((unsigned int) ~((unsigned int) 0)) >> 1u); + buf_size = (size_t)(((unsigned int)~((unsigned int)0)) >> 1u); } } @@ -1251,13 +1251,13 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, mhd_tls_mbed_sckt_comm_prep (c_tls); res = mbedtls_ssl_read (&(c_tls->sess), - (unsigned char *) buf, + (unsigned char *)buf, buf_size); if (0 <= res) { - mhd_ASSUME (buf_size >= (size_t) res); - *received = (size_t) res; + mhd_ASSUME (buf_size >= (size_t)res); + *received = (size_t)res; return mhd_SOCKET_ERR_NO_ERROR; /* Success exit point */ } @@ -1271,10 +1271,10 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, return mhd_SOCKET_ERR_NO_ERROR; /* Success exit point */ case MBEDTLS_ERR_SSL_WANT_READ: - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); - if (! c_tls->tr.state.recv_called) + if (!c_tls->tr.state.recv_called) return mhd_SOCKET_ERR_INTR; /* Do not clear 'recv-ready' flag */ if (mhd_SOCKET_ERR_NO_ERROR == c_tls->tr.state.recv_res) @@ -1287,8 +1287,8 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, return c_tls->tr.state.recv_res; case MBEDTLS_ERR_SSL_WANT_WRITE: - mhd_assert (0 && - "The handshake must be fully completed earlier"); + mhd_assert (0 + && "The handshake must be fully completed earlier"); break; case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS: @@ -1303,14 +1303,14 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, return mhd_SOCKET_ERR_INTR; /* Do not clear 'recv-ready' flag */ case MBEDTLS_ERR_SSL_CLIENT_RECONNECT: - mhd_assert (0 && - "MBEDTLS_ERR_SSL_CLIENT_RECONNECT must not be " + mhd_assert (0 + && "MBEDTLS_ERR_SSL_CLIENT_RECONNECT must not be " "returned for non-DTLS"); break; case MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET: - mhd_assert (0 && - "MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET must not be " + mhd_assert (0 + && "MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET must not be " "returned on the server side"); break; @@ -1318,8 +1318,8 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, #ifdef MBEDTLS_SSL_EARLY_DATA /* Could be replaced with early data support is implemented */ #endif /* MBEDTLS_SSL_EARLY_DATA */ - mhd_assert (0 && - "MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA must not be returned"); + mhd_assert (0 + && "MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA must not be returned"); break; default: @@ -1337,13 +1337,13 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ bool mhd_tls_mbed_conn_has_data_in (struct mhd_TlsMbedConnData *restrict c_tls) { - return c_tls->recv_data_in_buff || - (0 != mbedtls_ssl_check_pending (&(c_tls->sess))); + return c_tls->recv_data_in_buff + || (0 != mbedtls_ssl_check_pending (&(c_tls->sess))); } MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5) enum mhd_SocketError mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, size_t buf_size, @@ -1357,17 +1357,17 @@ mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->shut_tls_wr_sent); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->shut_tls_wr_sent); + mhd_assert (!c_tls->dbg.is_failed); if (1) { - const int buf_size_i = (int) buf_size; - if ((0 > buf_size_i) || - (buf_size != (size_t) buf_size_i)) + const int buf_size_i = (int)buf_size; + if ((0 > buf_size_i) + || (buf_size != (size_t)buf_size_i)) { /* Called function return value limitation */ - buf_size = (size_t) (((unsigned int) ~((unsigned int) 0)) >> 1u); + buf_size = (size_t)(((unsigned int)~((unsigned int)0)) >> 1u); push_data = false; } } @@ -1377,13 +1377,13 @@ mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, push_data); res = mbedtls_ssl_write (&(c_tls->sess), - (const unsigned char *) buf, + (const unsigned char *)buf, buf_size); if (0 < res) { - mhd_ASSUME (buf_size >= (size_t) res); - *sent = (size_t) res; + mhd_ASSUME (buf_size >= (size_t)res); + *sent = (size_t)res; return mhd_SOCKET_ERR_NO_ERROR; /* Success exit point */ } @@ -1391,15 +1391,15 @@ mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, switch (res) { case 0: - mhd_assert (0 && - "Zero must not be returned when sending non-zero size"); + mhd_assert (0 + && "Zero must not be returned when sending non-zero size"); break; case MBEDTLS_ERR_SSL_WANT_WRITE: - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); - mhd_assert (! mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.send_res)); + mhd_assert (!mhd_SOCKET_ERR_IS_HARD (c_tls->tr.state.recv_res)); - if (! c_tls->tr.state.send_called) + if (!c_tls->tr.state.send_called) return mhd_SOCKET_ERR_INTR; /* Do not clear 'recv-ready' flag */ if (mhd_SOCKET_ERR_NO_ERROR == c_tls->tr.state.send_res) @@ -1412,8 +1412,8 @@ mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, return c_tls->tr.state.send_res; case MBEDTLS_ERR_SSL_WANT_READ: - mhd_assert (0 && - "The handshake must be fully completed earlier"); + mhd_assert (0 + && "The handshake must be fully completed earlier"); break; case MBEDTLS_ERR_SSL_ASYNC_IN_PROGRESS: @@ -1427,14 +1427,14 @@ mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, return mhd_SOCKET_ERR_INTR; /* Do not clear 'recv-ready' flag */ case MBEDTLS_ERR_SSL_CLIENT_RECONNECT: - mhd_assert (0 && - "MBEDTLS_ERR_SSL_CLIENT_RECONNECT must not be " + mhd_assert (0 + && "MBEDTLS_ERR_SSL_CLIENT_RECONNECT must not be " "returned for non-DTLS"); break; case MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET: - mhd_assert (0 && - "MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET must not be " + mhd_assert (0 + && "MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET must not be " "returned on the server side"); break; @@ -1442,8 +1442,8 @@ mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, #ifdef MBEDTLS_SSL_EARLY_DATA /* Could be replaced with early data support is implemented */ #endif /* MBEDTLS_SSL_EARLY_DATA */ - mhd_assert (0 && - "MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA must not be returned"); + mhd_assert (0 + && "MBEDTLS_ERR_SSL_RECEIVED_EARLY_DATA must not be returned"); break; default: @@ -1484,17 +1484,17 @@ mhd_tls_mbed_conn_get_tls_ver (struct mhd_TlsMbedConnData *restrict c_tls, if (1) { uint_fast16_t tls_ver_num; -#if ((MBEDTLS_VERSION_NUMBER + 0) >= 0x03020000) +# if ((MBEDTLS_VERSION_NUMBER + 0) >= 0x03020000) mbedtls_ssl_protocol_version mbedtls_tls_ver; mbedtls_tls_ver = mbedtls_ssl_get_version_number (&(c_tls->sess)); - tls_ver_num = (uint_fast16_t) mbedtls_tls_ver; -#else /* MBEDTLS_VERSION_NUMBER < 0x03020000 */ - tls_ver_num = (uint_fast16_t) c_tls->sess.MBEDTLS_PRIVATE (major_ver); + tls_ver_num = (uint_fast16_t)mbedtls_tls_ver; +# else /* MBEDTLS_VERSION_NUMBER < 0x03020000 */ + tls_ver_num = (uint_fast16_t)c_tls->sess.MBEDTLS_PRIVATE (major_ver); tls_ver_num <<= 8u; - tls_ver_num |= (uint_fast16_t) c_tls->sess.MBEDTLS_PRIVATE (minor_ver); -#endif /* MBEDTLS_VERSION_NUMBER < 0x03020000 */ + tls_ver_num |= (uint_fast16_t)c_tls->sess.MBEDTLS_PRIVATE (minor_ver); +# endif /* MBEDTLS_VERSION_NUMBER < 0x03020000 */ /* Avoid MbedTLS helper macros and enum values in switch() as they are unstable in MbedTLS. */ switch (tls_ver_num) @@ -1540,7 +1540,7 @@ mhd_tls_mbed_conn_get_alpn_prot (struct mhd_TlsMbedConnData *restrict c_tls) return mhd_TLS_ALPN_PROT_NOT_SELECTED; return mhd_tls_alpn_decode_n (strlen (alpn_str), - (const unsigned char *) alpn_str); + (const unsigned char *)alpn_str); #else /* ! MBEDTLS_SSL_ALPN */ return mhd_TLS_ALPN_PROT_NOT_SELECTED; #endif /* ! MBEDTLS_SSL_ALPN */ diff --git a/src/mhd2/tls_mbed_funcs.h b/src/mhd2/tls_mbed_funcs.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_MBEDTLS -#error This header can be used only if MbedTLS is enabled +# error This header can be used only if MbedTLS is enabled #endif #include "sys_bool_type.h" @@ -142,7 +142,7 @@ MHD_FN_MUST_CHECK_RESULT_ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_ (3); * @return #MHD_SC_OK on success (p_d_tls set to the allocated settings), * error code otherwise */ -#define mhd_tls_mbed_daemon_init(d,et,s,p_d_tls) \ +#define mhd_tls_mbed_daemon_init(d, et, s, p_d_tls) \ mhd_tls_mbed_daemon_init3 ((d),(s),(p_d_tls)) /** @@ -245,7 +245,7 @@ mhd_tls_mbed_conn_recv (struct mhd_TlsMbedConnData *c_tls, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict received) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); /** * Check whether any incoming data is pending in the TLS buffers @@ -278,7 +278,7 @@ mhd_tls_mbed_conn_send (struct mhd_TlsMbedConnData *c_tls, const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], bool push_data, size_t *restrict sent) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5); /* ** TLS connection information ** */ diff --git a/src/mhd2/tls_mbed_tls_lib.h b/src/mhd2/tls_mbed_tls_lib.h @@ -48,17 +48,15 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_MBEDTLS -#error This header can be used only if MbedTLS is enabled +# error This header can be used only if MbedTLS is enabled #endif #ifndef __cplusplus # define mhd_MBETLS_C_HDR_START /* Empty */ # define mhd_MBETLS_C_HDR_FINISH /* Empty */ #else /* __cplusplus */ -/* *INDENT-OFF* */ # define mhd_MBETLS_C_HDR_START extern "C" { # define mhd_MBETLS_C_HDR_FINISH } -/* *INDENT-ON* */ #endif /* __cplusplus */ #include "microhttpd2_portability.h" @@ -95,10 +93,10 @@ MHD_WARN_IGNORE_ ("-Wdocumentation-pedantic") #endif /* MBEDTLS_VERSION_C */ #if ((MBEDTLS_VERSION_MAJOR + 0) < 3) -#error MbedTLS version 3.0 or later is required +# error MbedTLS version 3.0 or later is required #endif #if ((MBEDTLS_VERSION_NUMBER + 0) < 0x03000000) -#error MbedTLS version 3.0 or later is required +# error MbedTLS version 3.0 or later is required #endif /* #mhd_TLS_MBED_USE_PSA_FREE is MHD build-time user-definable macro */ @@ -150,9 +148,9 @@ mhd_MBETLS_C_HDR_FINISH # undef MHD_TLS_MBED_PREF_RNG_CTR #endif /* MBEDTLS_CTR_DRBG_C */ -#if ! defined(MHD_TLS_MBED_PREF_RNG_PSA) && \ - ! defined(MHD_TLS_MBED_PREF_RNG_HMAC) && \ - ! defined(MHD_TLS_MBED_PREF_RNG_CTR) +#if !defined(MHD_TLS_MBED_PREF_RNG_PSA) && \ + !defined(MHD_TLS_MBED_PREF_RNG_HMAC) && \ + !defined(MHD_TLS_MBED_PREF_RNG_CTR) # if defined(mhd_TLS_MBED_HAS_RNG_PSA) # define MHD_TLS_MBED_PREF_RNG_PSA 1 # elif defined(mhd_TLS_MBED_HAS_RNG_HMAC) && \ @@ -179,18 +177,18 @@ mhd_MBETLS_C_HDR_FINISH #include <mbedtls/x509_crt.h> -#if ! defined(MBEDTLS_X509_CRT_PARSE_C) -#error X.509 certificate parsing functions are required +#if !defined(MBEDTLS_X509_CRT_PARSE_C) +# error X.509 certificate parsing functions are required #endif /* ! MBEDTLS_X509_CRT_PARSE_C */ #include <mbedtls/pk.h> -#if ! defined(MBEDTLS_PK_PARSE_C) -#error Public key parser is required +#if !defined(MBEDTLS_PK_PARSE_C) +# error Public key parser is required #endif /* ! MBEDTLS_PK_PARSE_C */ -#if ! defined(MBEDTLS_PEM_PARSE_C) -#error PEM parser is required +#if !defined(MBEDTLS_PEM_PARSE_C) +# error PEM parser is required #endif /* ! MBEDTLS_PEM_PARSE_C */ /* Required header, checked in 'configure' */ @@ -202,7 +200,7 @@ mhd_MBETLS_C_HDR_FINISH #MHD_TLS_MBED_USE_PLATFORM_TEARDOWN when building MHD to control automatic platform setup / teardown */ #if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT) && \ - ! defined(MHD_TLS_MBED_SKIP_PLATFORM_SETUP) + !defined(MHD_TLS_MBED_SKIP_PLATFORM_SETUP) # define mhd_TLS_MBED_HAS_PLATFORM_SETUP 1 # ifdef MHD_TLS_MBED_USE_PLATFORM_TEARDOWN /* The application must not use MbedTLS directly */ diff --git a/src/mhd2/tls_multi_conn_data.h b/src/mhd2/tls_multi_conn_data.h @@ -50,7 +50,7 @@ #include "tls_multi_tls_lib.h" #ifndef MHD_USE_MULTITLS -#error This header can be used only if MultiTLS is enabled +# error This header can be used only if MultiTLS is enabled #endif #ifdef MHD_SUPPORT_GNUTLS diff --git a/src/mhd2/tls_multi_daemon_data.h b/src/mhd2/tls_multi_daemon_data.h @@ -50,7 +50,7 @@ #include "tls_multi_tls_lib.h" #ifndef MHD_USE_MULTITLS -#error This header can be used only if MultiTLS is enabled +# error This header can be used only if MultiTLS is enabled #endif #ifdef MHD_SUPPORT_GNUTLS diff --git a/src/mhd2/tls_multi_funcs.c b/src/mhd2/tls_multi_funcs.c @@ -82,14 +82,14 @@ #ifdef mhd_USE_TLS_DEBUG_MESSAGES # define mhd_M_DEBUG_PRINT(msg) \ - do { fprintf (stderr, "## MultiTLS: " msg "\n"); \ - fflush (stderr); } while (0) -# define mhd_M_DEBUG_PRINT1(msg,arg1) \ - do { fprintf (stderr, "## MultiTLS: " msg "\n", arg1); \ - fflush (stderr); } while (0) + do { fprintf (stderr, "## MultiTLS: " msg "\n"); \ + fflush (stderr); } while (0) +# define mhd_M_DEBUG_PRINT1(msg, arg1) \ + do { fprintf (stderr, "## MultiTLS: " msg "\n", arg1); \ + fflush (stderr); } while (0) #else # define mhd_M_DEBUG_PRINT(msg) ((void) 0) -# define mhd_M_DEBUG_PRINT1(msg,arg1) ((void) 0) +# define mhd_M_DEBUG_PRINT1(msg, arg1) ((void) 0) #endif @@ -218,14 +218,14 @@ tls_daemon_init_try (enum mhd_TlsMultiRoute route, mhd_StatusCodeInt res; #ifndef MHD_SUPPORT_OPENSSL - (void) sk_edge_trigg; /* Unused, mute compiler warning */ + (void)sk_edge_trigg; /* Unused, mute compiler warning */ #endif /* ! MHD_SUPPORT_OPENSSL */ switch (route) { #ifdef MHD_SUPPORT_GNUTLS case mhd_TLS_MULTI_ROUTE_GNU: - if (! mhd_tls_gnu_is_inited_fine ()) + if (!mhd_tls_gnu_is_inited_fine ()) return MHD_SC_TLS_BACKEND_UNAVAILABLE; res = mhd_tls_gnu_daemon_init (d, sk_edge_trigg, @@ -239,12 +239,12 @@ tls_daemon_init_try (enum mhd_TlsMultiRoute route, return MHD_SC_OK; } mhd_M_DEBUG_PRINT1 ("Failed to initialise GnuTLS backend for " \ - "the daemon, error code: %u", (unsigned) res); + "the daemon, error code: %u", (unsigned)res); return res; #endif #ifdef MHD_SUPPORT_OPENSSL case mhd_TLS_MULTI_ROUTE_OPEN: - if (! mhd_tls_open_is_inited_fine ()) + if (!mhd_tls_open_is_inited_fine ()) return MHD_SC_TLS_BACKEND_UNAVAILABLE; res = mhd_tls_open_daemon_init (d, sk_edge_trigg, @@ -258,12 +258,12 @@ tls_daemon_init_try (enum mhd_TlsMultiRoute route, return MHD_SC_OK; } mhd_M_DEBUG_PRINT1 ("Failed to initialise OpenSSL backend for " \ - "the daemon, error code: %u", (unsigned) res); + "the daemon, error code: %u", (unsigned)res); return res; #endif #ifdef MHD_SUPPORT_MBEDTLS case mhd_TLS_MULTI_ROUTE_MBED: - if (! mhd_tls_mbed_is_inited_fine ()) + if (!mhd_tls_mbed_is_inited_fine ()) return MHD_SC_TLS_BACKEND_UNAVAILABLE; res = mhd_tls_mbed_daemon_init (d, sk_edge_trigg, @@ -277,7 +277,7 @@ tls_daemon_init_try (enum mhd_TlsMultiRoute route, return MHD_SC_OK; } mhd_M_DEBUG_PRINT1 ("Failed to initialise MbedTLS backend for " \ - "the daemon, error code: %u", (unsigned) res); + "the daemon, error code: %u", (unsigned)res); return res; #endif case mhd_TLS_MULTI_ROUTE_NONE: @@ -437,21 +437,21 @@ mhd_tls_multi_thread_cleanup (struct mhd_TlsMultiDaemonData *restrict d_tls) { switch (d_tls->choice) { -#ifdef MHD_SUPPORT_GNUTLS +# ifdef MHD_SUPPORT_GNUTLS case mhd_TLS_MULTI_ROUTE_GNU: mhd_tls_gnu_thread_cleanup (d_tls->data.gnutls); break; -#endif -#ifdef MHD_SUPPORT_OPENSSL +# endif +# ifdef MHD_SUPPORT_OPENSSL case mhd_TLS_MULTI_ROUTE_OPEN: mhd_tls_open_thread_cleanup (d_tls->data.openssl); break; -#endif -#ifdef MHD_SUPPORT_MBEDTLS +# endif +# ifdef MHD_SUPPORT_MBEDTLS case mhd_TLS_MULTI_ROUTE_MBED: mhd_tls_mbed_thread_cleanup (d_tls->data.mbedtls); break; -#endif +# endif case mhd_TLS_MULTI_ROUTE_NONE: default: mhd_UNREACHABLE (); @@ -508,7 +508,7 @@ mhd_tls_multi_conn_init (const struct mhd_TlsMultiDaemonData *restrict d_tls, #ifdef MHD_SUPPORT_GNUTLS case mhd_TLS_MULTI_ROUTE_GNU: /* Assume the same alignment requirements for both structures */ - c_tls->data.gnutls = (struct mhd_TlsGnuConnData *) (c_tls + 1); + c_tls->data.gnutls = (struct mhd_TlsGnuConnData *)(c_tls + 1); return mhd_tls_gnu_conn_init (d_tls->data.gnutls, sk, c_tls->data.gnutls); @@ -516,7 +516,7 @@ mhd_tls_multi_conn_init (const struct mhd_TlsMultiDaemonData *restrict d_tls, #ifdef MHD_SUPPORT_OPENSSL case mhd_TLS_MULTI_ROUTE_OPEN: /* Assume the same alignment requirements for both structures */ - c_tls->data.openssl = (struct mhd_TlsOpenConnData *) (c_tls + 1); + c_tls->data.openssl = (struct mhd_TlsOpenConnData *)(c_tls + 1); return mhd_tls_open_conn_init (d_tls->data.openssl, sk, c_tls->data.openssl); @@ -524,7 +524,7 @@ mhd_tls_multi_conn_init (const struct mhd_TlsMultiDaemonData *restrict d_tls, #ifdef MHD_SUPPORT_MBEDTLS case mhd_TLS_MULTI_ROUTE_MBED: /* Assume the same alignment requirements for both structures */ - c_tls->data.mbedtls = (struct mhd_TlsMbedConnData *) (c_tls + 1); + c_tls->data.mbedtls = (struct mhd_TlsMbedConnData *)(c_tls + 1); return mhd_tls_mbed_conn_init (d_tls->data.mbedtls, sk, c_tls->data.mbedtls); @@ -630,7 +630,7 @@ mhd_tls_multi_conn_shutdown (struct mhd_TlsMultiConnData *restrict c_tls) /* ** Data receiving and sending ** */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_tls_multi_conn_recv (struct mhd_TlsMultiConnData *restrict c_tls, size_t buf_size, @@ -672,7 +672,7 @@ mhd_tls_multi_conn_recv (struct mhd_TlsMultiConnData *restrict c_tls, MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PURE_ bool mhd_tls_multi_conn_has_cstm_tr (struct mhd_TlsMultiConnData *restrict c_tls) { - (void) c_tls; /* Could be unused if all underling functions are actually macros */ + (void)c_tls; /* Could be unused if all underling functions are actually macros */ switch (c_tls->choice) { #ifdef MHD_SUPPORT_GNUTLS @@ -723,7 +723,7 @@ mhd_tls_multi_conn_has_data_in (struct mhd_TlsMultiConnData *restrict c_tls) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5) enum mhd_SocketError mhd_tls_multi_conn_send (struct mhd_TlsMultiConnData *restrict c_tls, size_t buf_size, @@ -731,7 +731,7 @@ mhd_tls_multi_conn_send (struct mhd_TlsMultiConnData *restrict c_tls, bool push_data, size_t *restrict sent) { - (void) push_data; /* Could be unused if not supported by all backends */ + (void)push_data; /* Could be unused if not supported by all backends */ switch (c_tls->choice) { #ifdef MHD_SUPPORT_GNUTLS diff --git a/src/mhd2/tls_multi_funcs.h b/src/mhd2/tls_multi_funcs.h @@ -50,7 +50,7 @@ #include "mhd_tls_choice.h" #ifndef MHD_USE_MULTITLS -#error This header can be used only when MultiTLS is enabled +# error This header can be used only when MultiTLS is enabled #endif #include "sys_bool_type.h" @@ -151,6 +151,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1); MHD_INTERNAL void mhd_tls_multi_thread_cleanup (struct mhd_TlsMultiDaemonData *restrict d_tls) MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_INOUT_ (1); + #else /* ! mhd_HAVE_TLS_THREAD_CLEANUP */ # define mhd_tls_multi_thread_cleanup(d_tls) ((void) 0) #endif /* ! mhd_HAVE_TLS_THREAD_CLEANUP */ @@ -232,7 +233,7 @@ mhd_tls_multi_conn_recv (struct mhd_TlsMultiConnData *restrict c_tls, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict received) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); /** * Check whether any incoming data is pending in the TLS buffers @@ -265,7 +266,7 @@ mhd_tls_multi_conn_send (struct mhd_TlsMultiConnData *restrict c_tls, const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], bool push_data, size_t *restrict sent) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (5); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (5); /* ** TLS connection information ** */ diff --git a/src/mhd2/tls_multi_tls_lib.h b/src/mhd2/tls_multi_tls_lib.h @@ -50,7 +50,7 @@ #include "mhd_tls_choice.h" #ifndef MHD_USE_MULTITLS -#error This header can be used only when MultiTLS is enabled +# error This header can be used only when MultiTLS is enabled #endif /** diff --git a/src/mhd2/tls_open_conn_data.h b/src/mhd2/tls_open_conn_data.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_OPENSSL -#error This header can be used only if OpenSSL is enabled +# error This header can be used only if OpenSSL is enabled #endif #include "tls_open_tls_lib.h" diff --git a/src/mhd2/tls_open_daemon_data.h b/src/mhd2/tls_open_daemon_data.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_OPENSSL -#error This header can be used only if OpenSSL is enabled +# error This header can be used only if OpenSSL is enabled #endif #include "tls_open_tls_lib.h" diff --git a/src/mhd2/tls_open_funcs.c b/src/mhd2/tls_open_funcs.c @@ -80,12 +80,12 @@ #include "mhd_public_api.h" #if defined(HAVE_WUSED_BUT_MARKED_UNUSED) && defined(MHD_WARN_IGNORE_STYLE_GCC) -# define mhd_NOWARN_USED_UNUSED \ - MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wused-but-marked-unused") -# define mhd_RESTORE_WARN_USED_UNUSED MHD_WARN_POP_ +# define mhd_NOWARN_USED_UNUSED \ + MHD_WARN_PUSH_ MHD_WARN_IGNORE_ ("-Wused-but-marked-unused") +# define mhd_RESTORE_WARN_USED_UNUSED MHD_WARN_POP_ #else -# define mhd_NOWARN_USED_UNUSED /* empty */ -# define mhd_RESTORE_WARN_USED_UNUSED /* empty */ +# define mhd_NOWARN_USED_UNUSED /* empty */ +# define mhd_RESTORE_WARN_USED_UNUSED /* empty */ #endif #ifdef mhd_USE_TLS_DEBUG_MESSAGES @@ -96,35 +96,35 @@ mhd_tls_open_dbg_print_errs (const char *msg, void *cls) { int ret; - int print_size = (int) msg_len; + int print_size = (int)msg_len; - (void) cls; /* Not used */ + (void)cls; /* Not used */ - if ((print_size < 0) || - (msg_len != (unsigned int) print_size)) - print_size = (int) ((~((unsigned int) 0u)) >> 1); + if ((print_size < 0) + || (msg_len != (unsigned int)print_size)) + print_size = (int)((~((unsigned int)0u)) >> 1); ret = fprintf (stderr, "## OpenSSL error: %.*s\n", print_size, msg); - (void) fflush (stderr); + (void)fflush (stderr); return ret; } # define mhd_DBG_PRINT_TLS_ERRS() \ - ERR_print_errors_cb (&mhd_tls_open_dbg_print_errs, NULL) + ERR_print_errors_cb (&mhd_tls_open_dbg_print_errs, NULL) # define mhd_DBG_PRINT_TLS_INFO_MSG(message) \ - do { (void) fprintf (stderr, "## OpenSSL info: %s\n", (message)); \ - (void) fflush (stderr);} while (0) -# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message,param) \ - do { (void) fprintf (stderr, "## OpenSSL info: " message "\n", (param)); \ - (void) fflush (stderr);} while (0) + do { (void) fprintf (stderr, "## OpenSSL info: %s\n", (message)); \ + (void) fflush (stderr);} while (0) +# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message, param) \ + do { (void) fprintf (stderr, "## OpenSSL info: " message "\n", (param)); \ + (void) fflush (stderr);} while (0) #else # define mhd_DBG_PRINT_TLS_ERRS() ERR_clear_error () # define mhd_DBG_PRINT_TLS_INFO_MSG(message) ((void) 0) -# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message,param) ((void) 0) +# define mhd_DBG_PRINT_TLS_INFO_PARAM1(message, param) ((void) 0) #endif /* ** Global initialisation / de-initialisation ** */ @@ -172,8 +172,8 @@ check_app_tls_settings (struct MHD_Daemon *restrict d, struct DaemonOptions *restrict s) { mhd_assert (MHD_TLS_BACKEND_NONE != s->tls); - mhd_assert ((MHD_TLS_BACKEND_OPENSSL == s->tls) || \ - (MHD_TLS_BACKEND_ANY == s->tls)); + mhd_assert ((MHD_TLS_BACKEND_OPENSSL == s->tls) \ + || (MHD_TLS_BACKEND_ANY == s->tls)); if (NULL == s->tls_cert_key.v_mem_cert) { mhd_LOG_MSG (d, MHD_SC_TLS_CONF_BAD_CERT, \ @@ -201,7 +201,10 @@ null_passwd_cb (char *buf, int rwflag, void *cls) { - (void) buf; (void) size; (void) rwflag; (void) cls; /* Unused */ + (void)buf; + (void)size; + (void)rwflag; + (void)cls; /* Unused */ mhd_DBG_PRINT_TLS_INFO_MSG ("The NULL passphrase callback is called\n"); return 0; } @@ -219,7 +222,7 @@ create_lib_ctx (struct MHD_Daemon *restrict d, struct mhd_TlsOpenDaemonData *restrict d_tls) { #ifndef MHD_SUPPORT_LOG_FUNCTIONALITY - (void) d; /* Used for logging only */ + (void)d; /* Used for logging only */ #endif /* MHD_SUPPORT_LOG_FUNCTIONALITY */ mhd_assert (NULL == d_tls->libctx); @@ -277,7 +280,7 @@ daemon_get_conf_file (struct DaemonOptions *restrict s, mhd_assert (NULL != s->tls_openssl_def_file.v_pathname); #ifndef MHD_SUPPORT_LOG_FUNCTIONALITY - (void) d; /* Used only for logging */ + (void)d; /* Used only for logging */ #endif /* Handle custom pathname */ @@ -292,7 +295,7 @@ daemon_get_conf_file (struct DaemonOptions *restrict s, name_len)); #endif /* _WIN32 */ - if ((! has_path) && (0u != name_len)) + if ((!has_path) && (0u != name_len)) { const char *def_path; size_t def_path_len; @@ -308,7 +311,7 @@ daemon_get_conf_file (struct DaemonOptions *restrict s, def_path_len = strlen (def_path); *conf_pathname = - (char *) OPENSSL_malloc (def_path_len + 1u + name_len + 1u); + (char *)OPENSSL_malloc (def_path_len + 1u + name_len + 1u); if (NULL == *conf_pathname) return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; @@ -323,7 +326,7 @@ daemon_get_conf_file (struct DaemonOptions *restrict s, return MHD_SC_OK; } - *conf_pathname = (char *) OPENSSL_malloc (name_len + 1u); + *conf_pathname = (char *)OPENSSL_malloc (name_len + 1u); if (NULL == *conf_pathname) return MHD_SC_DAEMON_MEM_ALLOC_FAILURE; @@ -337,7 +340,7 @@ daemon_get_conf_file (struct DaemonOptions *restrict s, #ifdef mhd_TLS_OPEN_HAS_CONF_DIAG # define mhd_LIBCTX_FORBIDS_FALLBACKS(d_tls) \ - (0 != OSSL_LIB_CTX_get_conf_diagnostics (d_tls->libctx)) + (0 != OSSL_LIB_CTX_get_conf_diagnostics (d_tls->libctx)) #else # define mhd_LIBCTX_FORBIDS_FALLBACKS(d_tls) ((void) (d_tls), ! ! 0) #endif /* ! mhd_TLS_OPEN_HAS_CONF_DIAG */ @@ -353,9 +356,9 @@ daemon_load_conf_from_cfg (struct MHD_Daemon *restrict d, bool log_missing_app_name) { #ifndef MHD_SUPPORT_LOG_FUNCTIONALITY - (void) d; /* Used for logging only */ + (void)d; /* Used for logging only */ # ifndef mhd_USE_TLS_DEBUG_MESSAGES - (void) filename; /* Used for logs only */ + (void)filename; /* Used for logs only */ # endif /* mhd_USE_TLS_DEBUG_MESSAGES */ #endif /* MHD_SUPPORT_LOG_FUNCTIONALITY */ @@ -419,7 +422,7 @@ cfg_reset_and_reload (struct MHD_Daemon *restrict d, CONF **restrict cfg_ptr) { #ifndef MHD_SUPPORT_LOG_FUNCTIONALITY - (void) d; /* Used for logging only */ + (void)d; /* Used for logging only */ #endif /* MHD_SUPPORT_LOG_FUNCTIONALITY */ mhd_assert (NULL != *cfg_ptr); @@ -431,8 +434,8 @@ cfg_reset_and_reload (struct MHD_Daemon *restrict d, *cfg_ptr = NULL; /* Reset OpenSSL library CTX, which may have partially applied configuration */ - if (! reset_lib_ctx (d, - d_tls)) + if (!reset_lib_ctx (d, + d_tls)) return false; /* Create a new cfg connected to the new CTX */ @@ -468,7 +471,7 @@ is_conf_file_fallback_allowed ( { mhd_assert (NULL != d_tls->libctx); - if (! s->tls_openssl_def_file.v_disable_fallback) + if (!s->tls_openssl_def_file.v_disable_fallback) return false; if (mhd_LIBCTX_FORBIDS_FALLBACKS (d_tls)) return false; @@ -480,7 +483,7 @@ static inline MHD_FN_PAR_NONNULL_ALL_ bool is_conf_fallback_allowed (const struct mhd_TlsOpenDaemonData *restrict d_tls, const struct DaemonOptions *restrict s) { - if (! s->tls_app_name.v_disable_fallback) + if (!s->tls_app_name.v_disable_fallback) return false; return is_conf_file_fallback_allowed (d_tls, @@ -511,7 +514,7 @@ daemon_load_lib_conf (struct MHD_Daemon *restrict d, CONF *conf; enum MHD_StatusCode ret; - if (! use_custom_conf_pathname) + if (!use_custom_conf_pathname) { /* Use default pathname */ conf_pathname = CONF_get1_default_config_file (); @@ -551,12 +554,12 @@ daemon_load_lib_conf (struct MHD_Daemon *restrict d, if (NULL == s->tls_app_name.v_app_name) return MHD_SC_OK; /* No special "application name" profile is needed */ - if (! s->tls_app_name.v_disable_fallback) + if (!s->tls_app_name.v_disable_fallback) return MHD_SC_OK; /* Initialisation allowed with default values */ /* Load of special "application name" profile is required */ - if (! use_custom_conf_pathname) + if (!use_custom_conf_pathname) return MHD_SC_TLS_DAEMON_INIT_FAILED; /* No fallback pathname */ mhd_assert (NULL != s->tls_openssl_def_file.v_pathname); @@ -616,7 +619,7 @@ daemon_load_lib_conf (struct MHD_Daemon *restrict d, unsigned long flags; flags = 0u; - if (! s->tls_app_name.v_disable_fallback) + if (!s->tls_app_name.v_disable_fallback) flags |= CONF_MFLAGS_IGNORE_ERRORS; conf_loaded = false; @@ -641,28 +644,28 @@ daemon_load_lib_conf (struct MHD_Daemon *restrict d, app_name_lc, conf, flags, - s->tls_app_name.v_disable_fallback || - mhd_LIBCTX_FORBIDS_FALLBACKS (d_tls)); + s->tls_app_name.v_disable_fallback + || mhd_LIBCTX_FORBIDS_FALLBACKS (d_tls)); - if (! conf_loaded) + if (!conf_loaded) { - if (s->tls_app_name.v_disable_fallback || - mhd_LIBCTX_FORBIDS_FALLBACKS (d_tls)) + if (s->tls_app_name.v_disable_fallback + || mhd_LIBCTX_FORBIDS_FALLBACKS (d_tls)) ret = MHD_SC_TLS_DAEMON_INIT_FAILED; - else if (! cfg_reset_and_reload (d, - d_tls, - conf_pathname, - &conf)) + else if (!cfg_reset_and_reload (d, + d_tls, + conf_pathname, + &conf)) ret = MHD_SC_TLS_DAEMON_INIT_FAILED; } } - if (! conf_loaded && - (MHD_SC_OK == ret)) + if (!conf_loaded + && (MHD_SC_OK == ret)) { - mhd_assert ((NULL == s->tls_app_name.v_app_name) || - ! s->tls_app_name.v_disable_fallback); + mhd_assert ((NULL == s->tls_app_name.v_app_name) + || !s->tls_app_name.v_disable_fallback); conf_loaded = daemon_load_conf_from_cfg (d, @@ -671,20 +674,20 @@ daemon_load_lib_conf (struct MHD_Daemon *restrict d, conf, flags, false); - if ((! conf_loaded) && - (! cfg_reset_and_reload (d, - d_tls, - conf_pathname, - &conf))) + if ((!conf_loaded) + && (!cfg_reset_and_reload (d, + d_tls, + conf_pathname, + &conf))) ret = MHD_SC_TLS_DAEMON_INIT_FAILED; } - if (! conf_loaded && - (MHD_SC_OK == ret)) + if (!conf_loaded + && (MHD_SC_OK == ret)) { - mhd_assert ((NULL == s->tls_app_name.v_app_name) || - ! s->tls_app_name.v_disable_fallback); + mhd_assert ((NULL == s->tls_app_name.v_app_name) + || !s->tls_app_name.v_disable_fallback); conf_loaded = daemon_load_conf_from_cfg (d, @@ -695,7 +698,7 @@ daemon_load_lib_conf (struct MHD_Daemon *restrict d, true); } - if (! conf_loaded) + if (!conf_loaded) ret = MHD_SC_TLS_LIB_CONF_WARNING; } @@ -727,7 +730,7 @@ daemon_init_lib_ctx (struct MHD_Daemon *restrict d, d_tls->libctx = NULL; #endif /* HAVE_NULL_PTR_ALL_ZEROS */ - if (! create_lib_ctx (d, d_tls)) + if (!create_lib_ctx (d, d_tls)) return MHD_SC_TLS_DAEMON_INIT_FAILED; if (NULL != s->tls_openssl_def_file.v_pathname) @@ -751,8 +754,8 @@ daemon_init_lib_ctx (struct MHD_Daemon *restrict d, if (MHD_SC_OK == ret) { - mhd_assert ((NULL == s->tls_openssl_def_file.v_pathname) || - ! s->tls_openssl_def_file.v_disable_fallback); + mhd_assert ((NULL == s->tls_openssl_def_file.v_pathname) + || !s->tls_openssl_def_file.v_disable_fallback); ret = daemon_load_lib_conf (d, d_tls, @@ -764,8 +767,8 @@ daemon_init_lib_ctx (struct MHD_Daemon *restrict d, if (MHD_SC_TLS_LIB_CONF_WARNING == ret) { - if ((! s->tls_app_name.v_disable_fallback) && - (! s->tls_openssl_def_file.v_disable_fallback)) + if ((!s->tls_app_name.v_disable_fallback) + && (!s->tls_openssl_def_file.v_disable_fallback)) return MHD_SC_OK; /* Load without configuration file */ ret = MHD_SC_TLS_DAEMON_INIT_FAILED; @@ -794,16 +797,16 @@ daemon_deinit_lib_ctx (struct mhd_TlsOpenDaemonData *restrict d_tls) #define mhd_ALPN_CODE_HTTP1_0 \ - 'h', 't', 't', 'p', '/', '1', '.', '0' /* Registered value for HTTP/1.0 */ + 'h', 't', 't', 'p', '/', '1', '.', '0' /* Registered value for HTTP/1.0 */ #define mhd_ALPN_CODE_HTTP1_1 \ - 'h', 't', 't', 'p', '/', '1', '.', '1' /* Registered value for HTTP/1.1 */ + 'h', 't', 't', 'p', '/', '1', '.', '1' /* Registered value for HTTP/1.1 */ #ifdef MHD_SUPPORT_HTTP2 -#define mhd_ALPN_CODE_HTTP2 \ - 'h', '2' /* Registered value for HTTP/2 over TLS */ +# define mhd_ALPN_CODE_HTTP2\ + 'h', '2' /* Registered value for HTTP/2 over TLS */ #endif /* MHD_SUPPORT_HTTP2 */ #if 0 /* Disabled code */ -#define mhd_ALPN_CODE_HTTP3 \ - 'h', '3' /* Registered value for HTTP/3 */ +# define mhd_ALPN_CODE_HTTP3\ + 'h', '3' /* Registered value for HTTP/3 */ #endif /* Disabled code */ @@ -841,8 +844,8 @@ get_npn_list (SSL *sess, void *cls) { struct mhd_TlsOpenDaemonData *const d_tls = - (struct mhd_TlsOpenDaemonData *) cls; - (void) sess; /* Unused */ + (struct mhd_TlsOpenDaemonData *)cls; + (void)sess; /* Unused */ *out = d_tls->alpn_prots; *outlen = d_tls->alpn_prots_size; return SSL_TLSEXT_ERR_OK; @@ -871,10 +874,10 @@ select_alpn_prot (SSL *sess, void *cls) { struct mhd_TlsOpenDaemonData *const d_tls = - (struct mhd_TlsOpenDaemonData *) cls; - (void) sess; /* Unused */ + (struct mhd_TlsOpenDaemonData *)cls; + (void)sess; /* Unused */ if (OPENSSL_NPN_NEGOTIATED == - SSL_select_next_proto ((unsigned char **) mhd_DROP_CONST (out), + SSL_select_next_proto ((unsigned char **)mhd_DROP_CONST (out), outlen, in, inlen, @@ -902,9 +905,9 @@ daemon_init_ctx (struct MHD_Daemon *restrict d, uint64_t ctx_opts; #ifndef MHD_SUPPORT_LOG_FUNCTIONALITY - (void) d; /* Mute compiler warning */ + (void)d; /* Mute compiler warning */ #endif - (void) s; // TODO: support configuration options + (void)s; // TODO: support configuration options mhd_assert (NULL != d_tls->libctx); @@ -945,8 +948,8 @@ daemon_init_ctx (struct MHD_Daemon *restrict d, /* Do not use session resumption for now */ ctx_opts |= SSL_OP_NO_TICKET; - (void) SSL_CTX_set_options (d_tls->ctx, - ctx_opts); + (void)SSL_CTX_set_options (d_tls->ctx, + ctx_opts); /* Prevent interactive password prompts */ SSL_CTX_set_default_passwd_cb (d_tls->ctx, @@ -956,15 +959,15 @@ daemon_init_ctx (struct MHD_Daemon *restrict d, /* SSL_CTX_set_security_level (d_tls->ctx, 0); */ /* recv()- and send()-related options */ - (void) SSL_CTX_set_mode (d_tls->ctx, - SSL_MODE_ENABLE_PARTIAL_WRITE - | SSL_MODE_AUTO_RETRY); - (void) SSL_CTX_clear_mode (d_tls->ctx, - SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER - | SSL_MODE_ASYNC); + (void)SSL_CTX_set_mode (d_tls->ctx, + SSL_MODE_ENABLE_PARTIAL_WRITE + | SSL_MODE_AUTO_RETRY); + (void)SSL_CTX_clear_mode (d_tls->ctx, + SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER + | SSL_MODE_ASYNC); SSL_CTX_set_read_ahead (d_tls->ctx, - ! 0); + !0); /* ALPN and NPN */ // TODO: use daemon option to disable ALPN @@ -1099,8 +1102,8 @@ daemon_load_certs_chain_obio (struct MHD_Daemon *restrict d, mhd_NOWARN_USED_UNUSED - if ((ERR_LIB_PEM == ERR_GET_LIB (err)) && - (PEM_R_NO_START_LINE == ERR_GET_REASON (err))) + if ((ERR_LIB_PEM == ERR_GET_LIB (err)) + && (PEM_R_NO_START_LINE == ERR_GET_REASON (err))) { /* End of data */ ERR_clear_error (); @@ -1111,7 +1114,6 @@ daemon_load_certs_chain_obio (struct MHD_Daemon *restrict d, } mhd_RESTORE_WARN_USED_UNUSED - mhd_DBG_PRINT_TLS_ERRS (); mhd_LOG_MSG (d, MHD_SC_TLS_DAEMON_INIT_FAILED, \ @@ -1370,8 +1372,8 @@ mhd_tls_open_conn_init (const struct mhd_TlsOpenDaemonData *restrict d_tls, ERR_clear_error (); - fd = (int) sk->fd; - if (sk->fd != (MHD_Socket) fd) + fd = (int)sk->fd; + if (sk->fd != (MHD_Socket)fd) return false; /* OpenSSL docs clam that it should not be possible */ c_tls->sess = SSL_new (d_tls->ctx); @@ -1416,10 +1418,10 @@ mhd_tls_open_conn_handshake (struct mhd_TlsOpenConnData *restrict c_tls) int res; mhd_assert (c_tls->dbg.is_inited); - mhd_assert (! c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->shut_tls_wr_sent); - mhd_assert (! c_tls->shut_tls_wr_received); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_tls_handshake_completed); + mhd_assert (!c_tls->shut_tls_wr_sent); + mhd_assert (!c_tls->shut_tls_wr_received); + mhd_assert (!c_tls->dbg.is_failed); ERR_clear_error (); @@ -1486,7 +1488,7 @@ mhd_tls_open_conn_shutdown (struct mhd_TlsOpenConnData *restrict c_tls) mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->dbg.is_failed); ERR_clear_error (); @@ -1558,7 +1560,7 @@ mhd_tls_open_conn_shutdown (struct mhd_TlsOpenConnData *restrict c_tls) /* ** Data receiving and sending ** */ MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_tls_open_conn_recv (struct mhd_TlsOpenConnData *restrict c_tls, size_t buf_size, @@ -1569,8 +1571,8 @@ mhd_tls_open_conn_recv (struct mhd_TlsOpenConnData *restrict c_tls, mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->shut_tls_wr_sent); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->shut_tls_wr_sent); + mhd_assert (!c_tls->dbg.is_failed); ERR_clear_error (); @@ -1638,7 +1640,7 @@ mhd_tls_open_conn_has_data_in (struct mhd_TlsOpenConnData *restrict c_tls) MHD_INTERNAL MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum mhd_SocketError mhd_tls_open_conn_send4 (struct mhd_TlsOpenConnData *restrict c_tls, size_t buf_size, @@ -1649,8 +1651,8 @@ mhd_tls_open_conn_send4 (struct mhd_TlsOpenConnData *restrict c_tls, mhd_assert (c_tls->dbg.is_inited); mhd_assert (c_tls->dbg.is_tls_handshake_completed); - mhd_assert (! c_tls->shut_tls_wr_sent); - mhd_assert (! c_tls->dbg.is_failed); + mhd_assert (!c_tls->shut_tls_wr_sent); + mhd_assert (!c_tls->dbg.is_failed); ERR_clear_error (); @@ -1767,8 +1769,8 @@ mhd_tls_open_conn_get_alpn_prot (struct mhd_TlsOpenConnData *restrict c_tls) &sel_prot_len); #ifndef OPENSSL_NO_NEXTPROTONEG - if ((NULL == sel_prot) || - (0 == sel_prot_len)) + if ((NULL == sel_prot) + || (0 == sel_prot_len)) { SSL_get0_next_proto_negotiated (c_tls->sess, &sel_prot, @@ -1776,8 +1778,8 @@ mhd_tls_open_conn_get_alpn_prot (struct mhd_TlsOpenConnData *restrict c_tls) } #endif /* ! OPENSSL_NO_NEXTPROTONEG */ - mhd_assert (sel_prot_len == (size_t) sel_prot_len); + mhd_assert (sel_prot_len == (size_t)sel_prot_len); - return mhd_tls_alpn_decode_n ((size_t) sel_prot_len, + return mhd_tls_alpn_decode_n ((size_t)sel_prot_len, sel_prot); } diff --git a/src/mhd2/tls_open_funcs.h b/src/mhd2/tls_open_funcs.h @@ -48,12 +48,12 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_OPENSSL -#error This header can be used only if OpenSSL is enabled +# error This header can be used only if OpenSSL is enabled #endif /* Sanity check */ #ifndef mhd_HAVE_TLS_THREAD_CLEANUP -#error mhd_HAVE_TLS_THREAD_CLEANUP macro must be defined when OpenSSL is used +# error mhd_HAVE_TLS_THREAD_CLEANUP macro must be defined when OpenSSL is used #endif #include "sys_bool_type.h" @@ -237,7 +237,7 @@ mhd_tls_open_conn_recv (struct mhd_TlsOpenConnData *restrict c_tls, size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict received) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); /** * Check whether any incoming data is pending in the TLS buffers @@ -266,7 +266,7 @@ mhd_tls_open_conn_send4 (struct mhd_TlsOpenConnData *restrict c_tls, size_t buf_size, const char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict sent) -MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); +MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4); /** * Send data to the remote side over TLS connection @@ -281,7 +281,7 @@ MHD_FN_PAR_NONNULL_ALL_ MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4); * @return mhd_SOCKET_ERR_NO_ERROR if send succeed (the @a sent gets * the sent size) or socket error */ -#define mhd_tls_open_conn_send(c_tls,buf_size,buf,push_data,sent) \ +#define mhd_tls_open_conn_send(c_tls, buf_size, buf, push_data, sent) \ mhd_tls_open_conn_send4 (c_tls,buf_size,buf,sent) diff --git a/src/mhd2/tls_open_tls_lib.h b/src/mhd2/tls_open_tls_lib.h @@ -48,7 +48,7 @@ #include "mhd_sys_options.h" #ifndef MHD_SUPPORT_OPENSSL -#error This header can be used only if OpenSSL is enabled +# error This header can be used only if OpenSSL is enabled #endif /* Declare compatibility with OpenSSL versions >= 3.0 */ @@ -66,14 +66,14 @@ #include <openssl/pem.h> #ifndef OPENSSL_VERSION_NUMBER -#error OPENSSL_VERSION_NUMBER is not defined +# error OPENSSL_VERSION_NUMBER is not defined #endif #ifndef OPENSSL_VERSION_PREREQ -#error OPENSSL_VERSION_PREREQ is not defined +# error OPENSSL_VERSION_PREREQ is not defined #endif -#if OPENSSL_VERSION_PREREQ (3,4) +#if OPENSSL_VERSION_PREREQ (3, 4) /** * Defined if functions OSSL_LIB_CTX_get_conf_diagnostics() and * OSSL_LIB_CTX_set_conf_diagnostics are available; diff --git a/src/mhd2/upgrade_prep.c b/src/mhd2/upgrade_prep.c @@ -83,17 +83,17 @@ * 'false' if @a buf buffer has not enough space */ mhd_static_inline -MHD_FN_PAR_OUT_SIZE_ (2,1) +MHD_FN_PAR_OUT_SIZE_ (2, 1) MHD_FN_PAR_NONNULL_ (3) MHD_FN_PAR_INOUT_ (3) -MHD_FN_PAR_IN_SIZE_ (5,4) bool +MHD_FN_PAR_IN_SIZE_ (5, 4) bool buf_append (size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], size_t *restrict pbuf_used, size_t copy_size, const char copy_data[MHD_FN_PAR_DYN_ARR_SIZE_ (copy_size)]) { - if ((*pbuf_used + copy_size > buf_size) || - (((size_t) (*pbuf_used + copy_size)) < copy_size)) + if ((*pbuf_used + copy_size > buf_size) + || (((size_t)(*pbuf_used + copy_size)) < copy_size)) return false; memcpy (buf + *pbuf_used, copy_data, copy_size); @@ -146,8 +146,8 @@ enum mhd_UpgradeHeaderBuildRes * has been logged) */ static MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (3) -MHD_FN_PAR_OUT_SIZE_ (3,2) MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_CSTR_ (5) -MHD_FN_PAR_IN_SIZE_ (7,6) enum mhd_UpgradeHeaderBuildRes +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) MHD_FN_PAR_CSTR_ (5) +MHD_FN_PAR_IN_SIZE_ (7, 6) enum mhd_UpgradeHeaderBuildRes build_reply_header (struct MHD_Connection *restrict c, const size_t buf_size, char buf[MHD_FN_PAR_DYN_ARR_SIZE_ (buf_size)], @@ -169,42 +169,42 @@ build_reply_header (struct MHD_Connection *restrict c, bool hdr_name_invalid; mhd_assert (MHD_HTTP_VERSION_IS_LIKE_11 (c->rq.http_ver)); - mhd_assert ((0 == c->rq.cntn.cntn_size) || \ - (mhd_HTTP_STAGE_FULL_REQ_RECEIVED == c->stage)); + mhd_assert ((0 == c->rq.cntn.cntn_size) \ + || (mhd_HTTP_STAGE_FULL_REQ_RECEIVED == c->stage)); buf_used = 0; - if (c->rq.have_expect_100 && ! c->rp.sent_100_cntn) + if (c->rq.have_expect_100 && !c->rp.sent_100_cntn) { /* Must send "100 Continue" before switching to data pumping */ - if (! buf_append (buf_size, - buf, - &buf_used, - rp_100_cntn_msg.len, - rp_100_cntn_msg.cstr)) + if (!buf_append (buf_size, + buf, + &buf_used, + rp_100_cntn_msg.len, + rp_100_cntn_msg.cstr)) return MHD_UPGRADE_HDR_BUILD_NO_MEM; } /* Status line */ - if (! buf_append (buf_size, - buf, - &buf_used, - status_line.len, - status_line.cstr)) + if (!buf_append (buf_size, + buf, + &buf_used, + status_line.len, + status_line.cstr)) return MHD_UPGRADE_HDR_BUILD_NO_MEM; /* "Upgrade:" header */ - if (! buf_append (buf_size, - buf, - &buf_used, - upgrade_hdr_start.len, - upgrade_hdr_start.cstr)) + if (!buf_append (buf_size, + buf, + &buf_used, + upgrade_hdr_start.len, + upgrade_hdr_start.cstr)) return MHD_UPGRADE_HDR_BUILD_NO_MEM; upgrade_hdr_value_len = strcspn (upgrade_hdr_value, "\n\r"); - if ((0 == upgrade_hdr_value_len) || - (0 != upgrade_hdr_value[upgrade_hdr_value_len])) + if ((0 == upgrade_hdr_value_len) + || (0 != upgrade_hdr_value[upgrade_hdr_value_len])) { mhd_LOG_MSG (c->daemon, \ MHD_SC_RESP_HEADER_VALUE_INVALID, \ @@ -212,8 +212,8 @@ build_reply_header (struct MHD_Connection *restrict c, "is invalid."); return MHD_UPGRADE_HDR_BUILD_OTHER_ERR; } - if ((buf_used + upgrade_hdr_value_len + 2 > buf_size) || - (((size_t) (buf_used + upgrade_hdr_value_len + 2)) < buf_used)) + if ((buf_used + upgrade_hdr_value_len + 2 > buf_size) + || (((size_t)(buf_used + upgrade_hdr_value_len + 2)) < buf_used)) return MHD_UPGRADE_HDR_BUILD_NO_MEM; memcpy (buf + buf_used, upgrade_hdr_value, @@ -243,8 +243,8 @@ build_reply_header (struct MHD_Connection *restrict c, hdr_name_len = strcspn (headers[i].name, "\n\r \t:,;\""); - if ((0 == hdr_name_len) || - (0 != headers[i].name[hdr_name_len])) + if ((0 == hdr_name_len) + || (0 != headers[i].name[hdr_name_len])) { hdr_name_invalid = true; break; @@ -288,9 +288,9 @@ build_reply_header (struct MHD_Connection *restrict c, return MHD_UPGRADE_HDR_BUILD_NO_MEM; } - if ((buf_used + line_len > buf_size) || - (((size_t) (buf_used + line_len)) < line_len) || - (line_len < hdr_value_len)) + if ((buf_used + line_len > buf_size) + || (((size_t)(buf_used + line_len)) < line_len) + || (line_len < hdr_value_len)) return MHD_UPGRADE_HDR_BUILD_NO_MEM; memcpy (buf + buf_used, @@ -316,7 +316,7 @@ build_reply_header (struct MHD_Connection *restrict c, buf[buf_used++] = '\n'; } mhd_assert (buf_size >= buf_used); - mhd_assert (! hdr_name_invalid || (i < num_headers)); + mhd_assert (!hdr_name_invalid || (i < num_headers)); if (i < num_headers) { @@ -327,7 +327,7 @@ build_reply_header (struct MHD_Connection *restrict c, "number %lu is invalid. " \ "Header name: '%s'. " \ "Header Value: '%s'."), - (unsigned long) i, + (unsigned long)i, headers[i].name ? headers[i].name : "(NULL)", headers[i].value ? headers[i].value : "(NULL)"); else @@ -337,7 +337,7 @@ build_reply_header (struct MHD_Connection *restrict c, "number %lu is invalid. " \ "Header name: '%s'. " \ "Header Value: '%s'."), - (unsigned long) i, + (unsigned long)i, headers[i].name ? headers[i].name : "(NULL)", headers[i].value ? headers[i].value : "(NULL)"); @@ -345,22 +345,22 @@ build_reply_header (struct MHD_Connection *restrict c, } /* "Connection:" header (if has not been added already) */ - if (! has_conn_hdr) + if (!has_conn_hdr) { static const struct MHD_String conn_hdr_line = mhd_MSTR_INIT (MHD_HTTP_HEADER_CONNECTION ": upgrade\r\n"); - if (! buf_append (buf_size, - buf, - &buf_used, - conn_hdr_line.len, - conn_hdr_line.cstr)) + if (!buf_append (buf_size, + buf, + &buf_used, + conn_hdr_line.len, + conn_hdr_line.cstr)) return MHD_UPGRADE_HDR_BUILD_NO_MEM; } /* End of reply header */ - if ((buf_used + 2 > buf_size) || - (((size_t) (buf_used + 2)) < 2)) + if ((buf_used + 2 > buf_size) + || (((size_t)(buf_used + 2)) < 2)) return MHD_UPGRADE_HDR_BUILD_NO_MEM; buf[buf_used++] = '\r'; @@ -389,7 +389,7 @@ build_reply_header (struct MHD_Connection *restrict c, */ static MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (4,3) bool +MHD_FN_PAR_IN_SIZE_ (4, 3) bool connection_prepare_for_upgrade ( struct MHD_Connection *restrict c, const char *restrict upgrade_hdr_value, @@ -431,7 +431,7 @@ connection_prepare_for_upgrade ( MHD_INTERNAL MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (4,3) bool +MHD_FN_PAR_IN_SIZE_ (4, 3) bool mhd_upgrade_prep_for_action (struct MHD_Request *restrict req, const char *restrict upgrade_hdr_value, size_t num_headers, @@ -444,11 +444,11 @@ mhd_upgrade_prep_for_action (struct MHD_Request *restrict req, mhd_assert (mhd_HTTP_STAGE_HEADERS_PROCESSED <= c->stage); mhd_assert (mhd_HTTP_STAGE_FULL_REQ_RECEIVED >= c->stage); - if (req->have_chunked_upload && - (mhd_HTTP_STAGE_FOOTERS_RECEIVED >= c->stage)) + if (req->have_chunked_upload + && (mhd_HTTP_STAGE_FOOTERS_RECEIVED >= c->stage)) return false; /* The request has not been fully received */ - if (! is_upload_act) + if (!is_upload_act) { if (mhd_HTTP_STAGE_HEADERS_PROCESSED != c->stage) return false; diff --git a/src/mhd2/upgrade_prep.h b/src/mhd2/upgrade_prep.h @@ -81,6 +81,6 @@ mhd_upgrade_prep_for_action (struct MHD_Request *restrict req, const struct MHD_NameValueCStr *restrict headers, bool is_upload_act) MHD_FN_PAR_NONNULL_ (1) MHD_FN_PAR_NONNULL_ (2) MHD_FN_PAR_CSTR_ (2) -MHD_FN_PAR_IN_SIZE_ (4,3); +MHD_FN_PAR_IN_SIZE_ (4, 3); #endif /* ! MHD_UPGRADE_PREP_H */ diff --git a/src/mhd2/upgrade_proc.c b/src/mhd2/upgrade_proc.c @@ -70,8 +70,8 @@ MHD_FN_PAR_NONNULL_ (1) bool mhd_upgrade_try_start_upgrading (struct MHD_Connection *restrict c) { mhd_assert (mhd_HTTP_STAGE_UPGRADE_HEADERS_SENDING == c->stage); - mhd_assert ((mhd_ACTION_UPGRADE == c->rq.app_act.head_act.act) || - (mhd_UPLOAD_ACTION_UPGRADE == c->rq.app_act.upl_act.act)); + mhd_assert ((mhd_ACTION_UPGRADE == c->rq.app_act.head_act.act) + || (mhd_UPLOAD_ACTION_UPGRADE == c->rq.app_act.upl_act.act)); mhd_assert (NULL != c->write_buffer); mhd_assert ((0 != c->read_buffer_offset) || (NULL == c->read_buffer)); mhd_assert (NULL == c->upgr.c); @@ -102,7 +102,7 @@ mhd_upgrade_finish_switch_to_upgraded (struct MHD_Connection *restrict c) // TODO: Support thread-per-connection c->upgr.c = c; - if (! mhd_mutex_init (&(c->upgr.lock))) + if (!mhd_mutex_init (&(c->upgr.lock))) { c->upgr.c = NULL; mhd_LOG_MSG (c->daemon, @@ -119,7 +119,7 @@ mhd_upgrade_finish_switch_to_upgraded (struct MHD_Connection *restrict c) c->stage = mhd_HTTP_STAGE_UPGRADED; - mhd_assert (! c->in_proc_ready); + mhd_assert (!c->in_proc_ready); mhd_assert (NULL == mhd_DLINKEDL_GET_PREV (c, timeout.tmout_list)); mhd_assert (NULL == mhd_DLINKEDL_GET_NEXT (c, timeout.tmout_list)); mhd_assert (c != mhd_DLINKEDL_GET_FIRST (&(c->daemon->conns), def_timeout)); @@ -148,7 +148,7 @@ MHD_upgraded_close (struct MHD_UpgradedHandle *urh) mhd_mutex_lock_chk (&(d->conns.upgr.ucu_lock)); mhd_DLINKEDL_INS_LAST (&(d->conns.upgr), c, upgr_cleanup); mhd_mutex_unlock_chk (&(d->conns.upgr.ucu_lock)); - (void) mhd_daemon_trigger_itc (d); /* Ignore result, the connection has been placed in cleanup list already */ + (void)mhd_daemon_trigger_itc (d); /* Ignore result, the connection has been placed in cleanup list already */ return MHD_SC_OK; } @@ -158,8 +158,8 @@ MHD_INTERNAL MHD_FN_PAR_NONNULL_ (1) void mhd_upgraded_deinit (struct MHD_Connection *restrict c) { - mhd_assert ((mhd_HTTP_STAGE_UPGRADED_CLEANING == c->stage) || \ - (mhd_HTTP_STAGE_UPGRADED == c->stage)); + mhd_assert ((mhd_HTTP_STAGE_UPGRADED_CLEANING == c->stage) \ + || (mhd_HTTP_STAGE_UPGRADED == c->stage)); mhd_assert (c == c->upgr.c); mhd_mutex_destroy_chk (&(c->upgr.lock)); diff --git a/src/mhd2/upgraded_net.c b/src/mhd2/upgraded_net.c @@ -72,8 +72,8 @@ #include "mhd_public_api.h" -#if ! defined (MHD_SUPPORT_POLL) && \ - (defined(MHD_SOCKETS_KIND_POSIX) || ! defined(MHD_SUPPORT_SELECT)) +#if !defined(MHD_SUPPORT_POLL) && \ + (defined(MHD_SOCKETS_KIND_POSIX) || !defined(MHD_SUPPORT_SELECT)) # if defined(_WIN32) || defined(HAVE_NANOSLEEP) || defined(HAVE_USLEEP) # define mhd_HAVE_MHD_SLEEP 1 @@ -85,11 +85,11 @@ static void mhd_sleep (uint_fast32_t millisec) { -#if defined(_WIN32) +# if defined(_WIN32) Sleep (millisec); -#elif defined(HAVE_NANOSLEEP) - struct timespec slp = { (time_t) (millisec / 1000), - (long) ((millisec % 1000) * 1000000l)}; +# elif defined(HAVE_NANOSLEEP) + struct timespec slp = { (time_t)(millisec / 1000), + (long)((millisec % 1000) * 1000000l)}; struct timespec rmn; int num_retries = 0; while (0 != nanosleep (&slp, &rmn)) @@ -100,7 +100,7 @@ mhd_sleep (uint_fast32_t millisec) break; slp = rmn; } -#elif defined(HAVE_USLEEP) +# elif defined(HAVE_USLEEP) uint64_t us = millisec * 1000; do { @@ -113,18 +113,18 @@ mhd_sleep (uint_fast32_t millisec) usleep (this_sleep); us -= this_sleep; } while (us > 0); -#endif +# endif } -#endif /* _WIN32 || HAVE_NANOSLEEP || HAVE_USLEEP */ +# endif /* _WIN32 || HAVE_NANOSLEEP || HAVE_USLEEP */ #endif /* ! MHD_SUPPORT_POLL && (MHD_SOCKETS_KIND_POSIX || ! MHD_SUPPORT_SELECT) */ MHD_EXTERN_ MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_OUT_SIZE_ (3,2) +MHD_FN_PAR_OUT_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum MHD_StatusCode MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, size_t recv_buf_size, @@ -136,7 +136,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, #if defined(MHD_SUPPORT_POLL) || defined(MHD_SUPPORT_SELECT) const MHD_Socket socket_fd = c->sk.fd; #endif /* MHD_SUPPORT_POLL || MHD_SUPPORT_SELECT */ - char *restrict buf_char = (char *) recv_buf; + char *restrict buf_char = (char *)recv_buf; size_t last_block_size; enum mhd_SocketError res; @@ -198,7 +198,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, else if (0 != *received_size) return MHD_SC_OK; - if (! mhd_SOCKET_ERR_IS_HARD (res)) + if (!mhd_SOCKET_ERR_IS_HARD (res)) { while (0 != max_wait_millisec) { @@ -214,9 +214,9 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, poll_wait = -1; else { - poll_wait = (int) max_wait_millisec; - if ((max_wait_millisec != (uint_fast64_t) poll_wait) || - (0 > poll_wait)) + poll_wait = (int)max_wait_millisec; + if ((max_wait_millisec != (uint_fast64_t)poll_wait) + || (0 > poll_wait)) poll_wait = INT_MAX; } fds[0].fd = socket_fd; @@ -225,17 +225,17 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, poll_res = mhd_poll (fds, 1, poll_wait); - if ((0 >= poll_res) && - (0 != *received_size)) + if ((0 >= poll_res) + && (0 != *received_size)) return MHD_SC_OK; else if (0 == poll_res) return MHD_SC_UPGRADED_NET_TIMEOUT; else if (0 > poll_res) { wait_err = mhd_SCKT_GET_LERR (); - if (! mhd_SCKT_ERR_IS_EAGAIN (wait_err) && - ! mhd_SCKT_ERR_IS_EINTR (wait_err) && - ! mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) + if (!mhd_SCKT_ERR_IS_EAGAIN (wait_err) + && !mhd_SCKT_ERR_IS_EINTR (wait_err) + && !mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) return MHD_SC_UPGRADED_NET_HARD_ERROR; } max_wait_millisec = 0; /* Re-try only one time */ @@ -256,12 +256,12 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, struct timeval tmvl; # ifdef HAVE_TIME_T - tmvl.tv_sec = (time_t) (max_wait_millisec / 1000); + tmvl.tv_sec = (time_t)(max_wait_millisec / 1000); # else /* ! HAVE_TIME_T */ - tmvl.tv_sec = (long) (max_wait_millisec / 1000); + tmvl.tv_sec = (long)(max_wait_millisec / 1000); # endif /* ! HAVE_TIME_T */ - if ((max_wait_millisec / 1000 != (uint_fast64_t) tmvl.tv_sec) || - ((0 >= tmvl.tv_sec) && (0 != tmvl.tv_sec))) /* Avoid signed/unsigned warnings */ + if ((max_wait_millisec / 1000 != (uint_fast64_t)tmvl.tv_sec) + || ((0 >= tmvl.tv_sec) && (0 != tmvl.tv_sec))) /* Avoid signed/unsigned warnings */ { /* Do not bother figuring out the real maximum 'time_t' value. '0x7FFFFFFF' is large enough to be already unrealistic and should @@ -272,32 +272,32 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, else { # ifdef HAVE_SUSECONDS_T - tmvl.tv_usec = (suseconds_t) ((max_wait_millisec % 1000) * 1000); + tmvl.tv_usec = (suseconds_t)((max_wait_millisec % 1000) * 1000); # else /* ! HAVE_SUSECONDS_T */ - tmvl.tv_usec = (long) ((max_wait_millisec % 1000) * 1000); + tmvl.tv_usec = (long)((max_wait_millisec % 1000) * 1000); # endif /* ! HAVE_SUSECONDS_T */ } FD_ZERO (&rfds); FD_SET (socket_fd, &rfds); - sel_res = select ((int) (c->sk.fd + 1), + sel_res = select ((int)(c->sk.fd + 1), &rfds, NULL, NULL, (MHD_WAIT_INDEFINITELY <= max_wait_millisec) ? NULL : &tmvl); - if ((0 >= sel_res) && - (0 != *received_size)) + if ((0 >= sel_res) + && (0 != *received_size)) return MHD_SC_OK; else if (0 == sel_res) return MHD_SC_UPGRADED_NET_TIMEOUT; else if (0 > sel_res) { wait_err = mhd_SCKT_GET_LERR (); - if (! mhd_SCKT_ERR_IS_EAGAIN (wait_err) && - ! mhd_SCKT_ERR_IS_EINTR (wait_err) && - ! mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) + if (!mhd_SCKT_ERR_IS_EAGAIN (wait_err) + && !mhd_SCKT_ERR_IS_EINTR (wait_err) + && !mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) return MHD_SC_UPGRADED_NET_HARD_ERROR; } max_wait_millisec = 0; /* Re-try only one time */ @@ -309,10 +309,10 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, # ifndef mhd_HAVE_MHD_SLEEP return MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED; # else /* mhd_HAVE_MHD_SLEEP */ - uint_fast32_t wait_millisec = (uint_fast32_t) max_wait_millisec; + uint_fast32_t wait_millisec = (uint_fast32_t)max_wait_millisec; - if ((wait_millisec != max_wait_millisec) || - (wait_millisec > 100)) + if ((wait_millisec != max_wait_millisec) + || (wait_millisec > 100)) wait_millisec = 100; mhd_sleep (wait_millisec); if (MHD_WAIT_INDEFINITELY > max_wait_millisec) @@ -334,13 +334,13 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, } } } - if (! mhd_SOCKET_ERR_IS_HARD (res)) + if (!mhd_SOCKET_ERR_IS_HARD (res)) return MHD_SC_UPGRADED_NET_TIMEOUT; if (mhd_SOCKET_ERR_REMT_DISCONN == res) return MHD_SC_UPGRADED_NET_CONN_CLOSED; if (mhd_SOCKET_ERR_TLS == res) return MHD_SC_UPGRADED_TLS_ERROR; - if (! mhd_SOCKET_ERR_IS_BAD (res)) + if (!mhd_SOCKET_ERR_IS_BAD (res)) return MHD_SC_UPGRADED_NET_CONN_BROKEN; return MHD_SC_UPGRADED_NET_HARD_ERROR; @@ -349,7 +349,7 @@ MHD_upgraded_recv (struct MHD_UpgradedHandle *MHD_RESTRICT urh, MHD_EXTERN_ MHD_FN_PAR_NONNULL_ALL_ -MHD_FN_PAR_IN_SIZE_ (3,2) +MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_OUT_ (4) enum MHD_StatusCode MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, size_t send_buf_size, @@ -362,7 +362,7 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, #if defined(MHD_SUPPORT_POLL) || defined(MHD_SUPPORT_SELECT) const MHD_Socket socket_fd = c->sk.fd; #endif /* MHD_SUPPORT_POLL || MHD_SUPPORT_SELECT */ - const char *restrict buf_char = (const char *) send_buf; + const char *restrict buf_char = (const char *)send_buf; const bool push_data = (MHD_NO == more_data_to_come); bool finish_time_set; bool wait_indefinitely; @@ -383,7 +383,7 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, enum mhd_SocketError res; size_t last_block_size; uint_fast64_t wait_left; -#if ! defined(MHD_SUPPORT_POLL) && defined(MHD_SUPPORT_SELECT) +#if !defined(MHD_SUPPORT_POLL) && defined(MHD_SUPPORT_SELECT) bool use_select; #endif /* ! MHD_SUPPORT_POLL */ @@ -408,7 +408,7 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, return MHD_SC_UPGRADED_NET_CONN_CLOSED; if (mhd_SOCKET_ERR_TLS == res) return MHD_SC_UPGRADED_TLS_ERROR; - if (! mhd_SOCKET_ERR_IS_BAD (res)) + if (!mhd_SOCKET_ERR_IS_BAD (res)) return MHD_SC_UPGRADED_NET_CONN_BROKEN; return MHD_SC_UPGRADED_NET_HARD_ERROR; @@ -421,12 +421,12 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, return MHD_SC_UPGRADED_NET_TIMEOUT; } - if (! wait_indefinitely) + if (!wait_indefinitely) { uint_fast64_t cur_time; cur_time = mhd_monotonic_msec_counter (); - if (! finish_time_set) + if (!finish_time_set) { finish_time = cur_time + max_wait_millisec; wait_left = max_wait_millisec; @@ -434,8 +434,8 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, else { wait_left = finish_time - cur_time; - if ((wait_left > cur_time - finish_time) || - (0 == wait_left)) + if ((wait_left > cur_time - finish_time) + || (0 == wait_left)) return MHD_SC_UPGRADED_NET_TIMEOUT; } } @@ -454,9 +454,9 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, poll_wait = -1; else { - poll_wait = (int) wait_left; - if ((wait_left != (uint_fast64_t) poll_wait) || - (0 > poll_wait)) + poll_wait = (int)wait_left; + if ((wait_left != (uint_fast64_t)poll_wait) + || (0 > poll_wait)) poll_wait = INT_MAX; } fds[0].fd = socket_fd; @@ -469,8 +469,8 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, continue; if (0 == poll_res) { - if (wait_indefinitely || - (INT_MAX == poll_wait)) + if (wait_indefinitely + || (INT_MAX == poll_wait)) continue; if (0 != *sent_size) return MHD_SC_OK; @@ -479,9 +479,9 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, mhd_assert (0 > poll_res); wait_err = mhd_SCKT_GET_LERR (); - if (! mhd_SCKT_ERR_IS_EAGAIN (wait_err) && - ! mhd_SCKT_ERR_IS_EINTR (wait_err) && - ! mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) + if (!mhd_SCKT_ERR_IS_EAGAIN (wait_err) + && !mhd_SCKT_ERR_IS_EINTR (wait_err) + && !mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) return MHD_SC_UPGRADED_NET_HARD_ERROR; } #else /* ! MHD_SUPPORT_POLL */ @@ -508,12 +508,12 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, else { # ifdef HAVE_TIME_T - tmvl.tv_sec = (time_t) (max_wait_millisec / 1000); + tmvl.tv_sec = (time_t)(max_wait_millisec / 1000); # else /* ! HAVE_TIME_T */ - tmvl.tv_sec = (long) (max_wait_millisec / 1000); + tmvl.tv_sec = (long)(max_wait_millisec / 1000); # endif /* ! HAVE_TIME_T */ - if ((max_wait_millisec / 1000 != (uint_fast64_t) tmvl.tv_sec) || - ((0 >= tmvl.tv_sec) && (0 != tmvl.tv_sec))) /* Avoid signed/unsigned warnings */ + if ((max_wait_millisec / 1000 != (uint_fast64_t)tmvl.tv_sec) + || ((0 >= tmvl.tv_sec) && (0 != tmvl.tv_sec))) /* Avoid signed/unsigned warnings */ { /* Do not bother figuring out the real maximum 'time_t' value. '0x7FFFFFFF' is large enough to be already unrealistic and should @@ -525,16 +525,16 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, else { # ifdef HAVE_SUSECONDS_T - tmvl.tv_usec = (suseconds_t) ((max_wait_millisec % 1000) * 1000); + tmvl.tv_usec = (suseconds_t)((max_wait_millisec % 1000) * 1000); # else /* ! HAVE_SUSECONDS_T */ - tmvl.tv_usec = (long) ((max_wait_millisec % 1000) * 1000); + tmvl.tv_usec = (long)((max_wait_millisec % 1000) * 1000); # endif /* ! HAVE_SUSECONDS_T */ } } FD_ZERO (&wfds); FD_SET (socket_fd, &wfds); - sel_res = select ((int) (c->sk.fd + 1), + sel_res = select ((int)(c->sk.fd + 1), NULL, &wfds, NULL, @@ -544,8 +544,8 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, continue; if (0 == sel_res) { - if (wait_indefinitely || - max_wait) + if (wait_indefinitely + || max_wait) continue; if (0 != *sent_size) return MHD_SC_OK; @@ -554,9 +554,9 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, mhd_assert (0 > sel_res); wait_err = mhd_SCKT_GET_LERR (); - if (! mhd_SCKT_ERR_IS_EAGAIN (wait_err) && - ! mhd_SCKT_ERR_IS_EINTR (wait_err) && - ! mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) + if (!mhd_SCKT_ERR_IS_EAGAIN (wait_err) + && !mhd_SCKT_ERR_IS_EINTR (wait_err) + && !mhd_SCKT_ERR_IS_LOW_RESOURCES (wait_err)) return MHD_SC_UPGRADED_NET_HARD_ERROR; } else /* combined with the next 'if()' */ @@ -566,10 +566,10 @@ MHD_upgraded_send (struct MHD_UpgradedHandle *MHD_RESTRICT urh, # ifndef mhd_HAVE_MHD_SLEEP return MHD_SC_UPGRADED_WAITING_NOT_SUPPORTED; # else /* mhd_HAVE_MHD_SLEEP */ - uint_fast32_t wait_millisec = (uint_fast32_t) wait_left; + uint_fast32_t wait_millisec = (uint_fast32_t)wait_left; - if ((wait_millisec != wait_left) || - (wait_millisec > 100)) + if ((wait_millisec != wait_left) + || (wait_millisec > 100)) wait_millisec = 100; mhd_sleep (wait_millisec); # endif /* mhd_HAVE_MHD_SLEEP */ diff --git a/src/tests/basic/test_basic_checks.c b/src/tests/basic/test_basic_checks.c @@ -64,12 +64,12 @@ ((void) fprintf (stderr, "MHD function failed, returned: %u\n", \ (unsigned int) (sc))), (0)) ) #if 0 -#define tst_EXPECT_OK(sc) \ - ( (MHD_SC_OK == (sc)) ? (! 0) : \ - (ERR_PRINT_LINE (), \ - ((void) fprintf (stderr, \ - "MHD function failed, returned: %s\n", \ - MHD_status_code_to_string_lazy (sc))), (0)) ) +# define tst_EXPECT_OK(sc) \ + ( (MHD_SC_OK == (sc)) ? (! 0) : \ + (ERR_PRINT_LINE (), \ + ((void) fprintf (stderr, \ + "MHD function failed, returned: %s\n", \ + MHD_status_code_to_string_lazy (sc))), (0)) ) #endif /** @@ -89,7 +89,7 @@ * @param sc the status code to check * @param expect_ok non-zero if SC should be OK, zero is SC should NOT be OK */ -#define tst_EXPECT_CHECK(sc,expect_ok) \ +#define tst_EXPECT_CHECK(sc, expect_ok) \ ((expect_ok) ? tst_EXPECT_OK ((sc)) : tst_EXPECT_FAIL ((sc))) @@ -126,9 +126,13 @@ my_req_process (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - (void) cls; (void) request; (void) path; (void) method; (void) upload_size; + (void)cls; + (void)request; + (void)path; + (void)method; + (void)upload_size; fprintf (stderr, "Unexpected call of the request callback.\n"); - err_flag = ! 0; + err_flag = !0; return NULL; } @@ -141,7 +145,7 @@ test_daemon_create (void) d = MHD_daemon_create (my_req_process, NULL); if (NULL == d) { - err_flag = ! 0; + err_flag = !0; ERR_PRINT_LINE (); fprintf (stderr, "MHD_daemon_create() failed, NULL returned.\n"); return NULL; @@ -155,13 +159,13 @@ test_daemon_setup (struct MHD_Daemon *d, int should_succeed) { enum MHD_StatusCode sc; - int ret = ! 0; + int ret = !0; if (use_ipv6) { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_BIND_PORT (MHD_AF_DUAL_v4_OPTIONAL, 0)); - if (! tst_EXPECT_CHECK (sc,should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -169,7 +173,7 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_BIND_PORT (MHD_AF_DUAL_v6_OPTIONAL, 0)); - if (! tst_EXPECT_CHECK (sc,should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -177,7 +181,7 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_BIND_PORT (MHD_AF_AUTO, 0)); - if (! tst_EXPECT_CHECK (sc,should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -185,7 +189,7 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_POLL_SYSCALL (MHD_SPS_SELECT)); - if (! tst_EXPECT_CHECK (sc,should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -193,7 +197,7 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_POLL_SYSCALL (MHD_SPS_POLL)); - if (! tst_EXPECT_CHECK (sc, should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -201,7 +205,7 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_POLL_SYSCALL (MHD_SPS_EPOLL)); - if (! tst_EXPECT_CHECK (sc,should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -209,7 +213,7 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_WORKER_THREADS (1))); - if (! tst_EXPECT_CHECK (sc, should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -217,7 +221,7 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_THREAD_PER_CONNECTION ())); - if (! tst_EXPECT_CHECK (sc, should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } @@ -225,12 +229,12 @@ test_daemon_setup (struct MHD_Daemon *d, { sc = MHD_DAEMON_SET_OPTIONS ( \ d, MHD_D_OPTION_WORK_MODE (MHD_WM_OPTION_WORKER_THREADS (4))); - if (! tst_EXPECT_CHECK (sc, should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) ret = 0; } - if (! ret) - err_flag = ! 0; + if (!ret) + err_flag = !0; return ret; } @@ -243,13 +247,13 @@ test_daemon_start (struct MHD_Daemon *d, enum MHD_StatusCode sc; sc = MHD_daemon_start (d); - if (! tst_EXPECT_CHECK (sc,should_succeed)) + if (!tst_EXPECT_CHECK (sc, should_succeed)) { - err_flag = ! 0; + err_flag = !0; return 0; } - return ! 0; + return !0; } @@ -257,26 +261,26 @@ static int test_simple (void) { struct MHD_Daemon *d; - int ret = ! 0; + int ret = !0; err_flag = 0; d = test_daemon_create (); if (NULL == d) - return (ret && ! err_flag); + return (ret && !err_flag); - test_daemon_setup (d, ! 0); + test_daemon_setup (d, !0); if (use_start) - test_daemon_start (d, ! 0); + test_daemon_start (d, !0); - test_daemon_setup (d, ! use_start); + test_daemon_setup (d, !use_start); if (use_start) test_daemon_start (d, 0); /* Second "start" should fail */ MHD_daemon_destroy (d); - return (ret && ! err_flag); + return (ret && !err_flag); } @@ -290,16 +294,16 @@ static int init_test (const char *prog_name) { if (mhdt_has_in_name (prog_name, "_start")) - use_start = ! 0; + use_start = !0; if (mhdt_has_in_name (prog_name, "_ipv4")) - use_ipv4 = ! 0; + use_ipv4 = !0; if (mhdt_has_in_name (prog_name, "_ipv6")) - use_ipv6 = ! 0; + use_ipv6 = !0; if (mhdt_has_in_name (prog_name, "_ipbest")) - use_ip_best = ! 0; + use_ip_best = !0; use_select = mhdt_has_in_name (prog_name, "_select"); @@ -313,7 +317,7 @@ init_test (const char *prog_name) use_thread_pool = mhdt_has_in_name (prog_name, "_thread_pool"); - return ! 0; + return !0; } @@ -321,15 +325,15 @@ int main (int argc, char *argv[]) { unsigned int num_err = 0; - (void) argc; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ - if (! init_test (argv[0])) + if (!init_test (argv[0])) { fprintf (stderr, "Failed to initialise the test!\n"); return 77; } - if (! test_simple ()) + if (!test_simple ()) ++num_err; if (0 != num_err) diff --git a/src/tests/basic/test_lib_info_version.c b/src/tests/basic/test_lib_info_version.c @@ -72,13 +72,13 @@ tst_EXPECT_OK_helper (enum MHD_StatusCode code, return 1; fflush (stdout); - (void) fprintf (stderr, - "At the line number %lu: " - "MHD function failed: \n" - "\"%s\"\n returned %lu.\n", - line_num, - expression, - (unsigned long) code); + (void)fprintf (stderr, + "At the line number %lu: " + "MHD function failed: \n" + "\"%s\"\n returned %lu.\n", + line_num, + expression, + (unsigned long)code); flush_std_all (); return 0; } @@ -102,21 +102,21 @@ tst_EXPECT_OK_helper (enum MHD_StatusCode code, static const char str_macro_pkg_ver[] = PACKAGE_VERSION; #else /* ! PACKAGE_VERSION */ static const char str_macro_pkg_ver[] = "error!"; -#error No PACKAGE_VERSION defined +# error No PACKAGE_VERSION defined #endif /* ! PACKAGE_VERSION */ #ifdef VERSION static const char str_macro_ver[] = VERSION; #else /* ! VERSION */ static const char str_macro_ver[] = "error!"; -#error No PACKAGE_VERSION defined +# error No PACKAGE_VERSION defined #endif /* ! VERSION */ #ifdef MHD_VERSION -static const uint_fast32_t bin_macro = (uint_fast32_t) (MHD_VERSION); +static const uint_fast32_t bin_macro = (uint_fast32_t)(MHD_VERSION); #else /* ! MHD_VERSION */ static const uint_fast32_t bin_macro = 0; -#error MHD_VERSION is not defined +# error MHD_VERSION is not defined #endif /* ! MHD_VERSION */ /* 0 = success, 1 = error */ @@ -143,9 +143,9 @@ test_macro2_vs_func_str (void) { union MHD_LibInfoFixedData info_data; - if (! tst_EXPECT_OK (MHD_lib_get_info_fixed ( \ - MHD_LIB_INFO_FIXED_VERSION_STRING, \ - &info_data))) + if (!tst_EXPECT_OK (MHD_lib_get_info_fixed ( \ + MHD_LIB_INFO_FIXED_VERSION_STRING, \ + &info_data))) return 1; printf ("Checking VERSION macro vs " @@ -178,23 +178,23 @@ test_func_str_vs_macro_bin (void) int res; union MHD_LibInfoFixedData info_data; - if (! tst_EXPECT_OK (MHD_lib_get_info_fixed ( \ - MHD_LIB_INFO_FIXED_VERSION_STRING, \ - &info_data))) + if (!tst_EXPECT_OK (MHD_lib_get_info_fixed ( \ + MHD_LIB_INFO_FIXED_VERSION_STRING, \ + &info_data))) return 1; printf ("Checking MHD_lib_get_info_fixed(MHD_LIB_INFO_FIXED_VERSION_STR) " \ "function vs MHD_VERSION macro.\n"); #ifdef HAVE_SNPRINTF res = snprintf (bin_print, sizeof(bin_print), "%X.%X.%X", - (unsigned int) ((bin_macro >> 24) & 0xFF), - (unsigned int) ((bin_macro >> 16) & 0xFF), - (unsigned int) ((bin_macro >> 8) & 0xFF)); + (unsigned int)((bin_macro >> 24) & 0xFF), + (unsigned int)((bin_macro >> 16) & 0xFF), + (unsigned int)((bin_macro >> 8) & 0xFF)); #else /* ! HAVE_SNPRINTF */ res = sprintf (bin_print, "%X.%X.%X", - (unsigned int) ((bin_macro >> 24) & 0xFF), - (unsigned int) ((bin_macro >> 16) & 0xFF), - (unsigned int) ((bin_macro >> 8) & 0xFF)); + (unsigned int)((bin_macro >> 24) & 0xFF), + (unsigned int)((bin_macro >> 16) & 0xFF), + (unsigned int)((bin_macro >> 8) & 0xFF)); #endif /* ! HAVE_SNPRINTF */ if ((9 < res) || (0 >= res)) { @@ -208,13 +208,13 @@ test_func_str_vs_macro_bin (void) fflush (stdout); fprintf (stderr, "'%s' vs '0x%08lX' ('%s') - FAILED.\n", info_data.v_version_string.cstr, - (unsigned long) bin_macro, + (unsigned long)bin_macro, bin_print); return 1; } printf ("'%s' vs '0x%08lX' ('%s') - success.\n", info_data.v_version_string.cstr, - (unsigned long) bin_macro, + (unsigned long)bin_macro, bin_print); return 0; } @@ -232,11 +232,11 @@ test_macro_vs_func_bin (void) { fflush (stdout); fprintf (stderr, "'0x%08lX' vs '0x%08lX' - FAILED.\n", - (unsigned long) bin_macro, (unsigned long) bin_func); + (unsigned long)bin_macro, (unsigned long)bin_func); return 1; } printf ("'0x%08lX' vs '0x%08lX' - success.\n", - (unsigned long) bin_macro, (unsigned long) bin_func); + (unsigned long)bin_macro, (unsigned long)bin_func); return 0; } @@ -250,7 +250,7 @@ test_func_bin_format (void) int ret = 0; printf ("Checking format of MHD_lib_get_info_ver_num() " "function return value.\n"); - test_byte = (unsigned int) ((bin_func >> 24) & 0xFF); + test_byte = (unsigned int)((bin_func >> 24) & 0xFF); if ((0xA <= (test_byte & 0xF)) || (0xA <= (test_byte >> 4))) { @@ -260,7 +260,7 @@ test_func_bin_format (void) test_byte); ret = 1; } - test_byte = (unsigned int) ((bin_func >> 16) & 0xFF); + test_byte = (unsigned int)((bin_func >> 16) & 0xFF); if ((0xA <= (test_byte & 0xF)) || (0xA <= (test_byte >> 4))) { @@ -270,7 +270,7 @@ test_func_bin_format (void) test_byte); ret = 1; } - test_byte = (unsigned int) ((bin_func >> 8) & 0xFF); + test_byte = (unsigned int)((bin_func >> 8) & 0xFF); if ((0xA <= (test_byte & 0xF)) || (0xA <= (test_byte >> 4))) { @@ -288,10 +288,10 @@ test_func_bin_format (void) "function is invalid as it cannot be used as packed BCD form " "(its hexadecimal representation has at least one digit in " "A-F range).\n", - (unsigned long) bin_func); + (unsigned long)bin_func); return 1; } - printf ("'0x%08lX' - success.\n", (unsigned long) bin_func); + printf ("'0x%08lX' - success.\n", (unsigned long)bin_func); return 0; } @@ -303,9 +303,9 @@ test_func_str_format (void) size_t ver_len; union MHD_LibInfoFixedData info_data; - if (! tst_EXPECT_OK (MHD_lib_get_info_fixed ( \ - MHD_LIB_INFO_FIXED_VERSION_STRING, \ - &info_data))) + if (!tst_EXPECT_OK (MHD_lib_get_info_fixed ( \ + MHD_LIB_INFO_FIXED_VERSION_STRING, \ + &info_data))) return 1; printf ("Checking MHD_lib_get_info_fixed(MHD_LIB_INFO_FIXED_VERSION_STR) " \ @@ -318,14 +318,14 @@ test_func_str_format (void) fprintf (stderr, "strlen(info_data.v_string.cstr) ('%lu') != " "info_data.v_string.len ('%lu') - FAILED.\n", - (unsigned long) ver_len, - (unsigned long) info_data.v_version_string.len); + (unsigned long)ver_len, + (unsigned long)info_data.v_version_string.len); return 1; } printf ("strlen(info_data.v_string.cstr) ('%lu') == " "info_data.v_string.len ('%lu') - success.\n", - (unsigned long) ver_len, - (unsigned long) info_data.v_version_string.len); + (unsigned long)ver_len, + (unsigned long)info_data.v_version_string.len); return 0; } @@ -335,7 +335,8 @@ main (int argc, char *argv[]) { int num_err; - (void) argc; (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silence compiler warning. */ num_err = test_macro1_vs_macro2_str (); flush_std_all (); diff --git a/src/tests/client_server/libtest.c b/src/tests/client_server/libtest.c @@ -84,7 +84,7 @@ test_check_ (bool cond, const char *filename, unsigned int line) { - if (! cond) + if (!cond) { fprintf (stderr, "Assertion failed at %s:%u\n", @@ -250,7 +250,7 @@ server_req_cb (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - struct ServerContext *sc = (struct ServerContext *) cls; + struct ServerContext *sc = (struct ServerContext *)cls; if (NULL == sc->phase->label) return NULL; @@ -299,7 +299,7 @@ struct ClientContext static void * run_single_client (void *cls) { - struct ClientContext *cc = (struct ClientContext *) cls; + struct ClientContext *cc = (struct ClientContext *)cls; const char *err; fprintf (stderr, @@ -384,7 +384,7 @@ run_client_phase (const struct MHDT_Phase *phase, fprintf (stderr, "Starting phase '%s'\n", phase->label); - for (i = 0; i<num_clients; i++) + for (i = 0; i < num_clients; i++) { cctxs[i].phase = phase; cctxs[i].pc = *pc; @@ -402,7 +402,7 @@ run_client_phase (const struct MHDT_Phase *phase, /* 0 for timeout_ms means no timeout, we deliberately underflow to MAX_UINT in this case... */ - for (te = phase->timeout_ms - 1; te>0; te--) + for (te = phase->timeout_ms - 1; te > 0; te--) { struct timespec ms = { .tv_nsec = 1000 * 1000 @@ -430,20 +430,20 @@ run_client_phase (const struct MHDT_Phase *phase, { fprintf (stderr, "Timeout (%lu ms) in phase '%s': %u clients still running\n", - (unsigned long) phase->timeout_ms, + (unsigned long)phase->timeout_ms, phase->label, clients_left); exit (1); } cleanup: - for (i = 0; i<num_clients; i++) + for (i = 0; i < num_clients; i++) { void *res; test_check (0 == pthread_join (clients[i], &res)); - if (! cctxs[i].status) + if (!cctxs[i].status) ret = false; curl_slist_free_all (cctxs[i].pc.hosts); } @@ -467,7 +467,7 @@ cleanup: static void * server_phase_logic (void *cls) { - struct ServerContext *ctx = (struct ServerContext *) cls; + struct ServerContext *ctx = (struct ServerContext *)cls; const struct MHDT_Phase *phases = ctx->phase; unsigned int j; @@ -500,7 +500,7 @@ server_phase_logic (void *cls) static void * server_run_logic (void *cls) { - struct ServerContext *ctx = (struct ServerContext *) cls; + struct ServerContext *ctx = (struct ServerContext *)cls; ctx->run_cb (ctx->run_cb_cls, ctx->finsig, @@ -582,7 +582,7 @@ MHDT_test (MHDT_ServerSetup ss_cb, #else fprintf (stderr, "Failed to start server: %u\n", - (unsigned int) sc); + (unsigned int)sc); #endif MHD_daemon_destroy (d); return 1; @@ -607,28 +607,28 @@ MHDT_test (MHDT_ServerSetup ss_cb, unsigned int pn; char dummy; - if ( (1 != sscanf (portenv, - "%u%c", - &pn, - &dummy)) || - (pn > 65535) ) + if ((1 != sscanf (portenv, + "%u%c", + &pn, + &dummy)) + || (pn > 65535)) { fprintf (stderr, "Invalid port number specified in MHD_TEST_FORCE_CLIENT_PORT"); MHD_daemon_destroy (d); return 1; } - port = (uint16_t) pn; + port = (uint16_t)pn; } snprintf (base_http_url, sizeof (base_http_url), "http://localhost:%u/", - (unsigned int) port); + (unsigned int)port); snprintf (base_https_url, sizeof (base_https_url), "https://localhost:%u/", - (unsigned int) port); + (unsigned int)port); pc_http.base_url = base_http_url; pc_https.base_url = base_https_url; } @@ -675,9 +675,9 @@ MHDT_test (MHDT_ServerSetup ss_cb, fprintf (stderr, "Running test phase '%s'\n", pi->label); - if ( (! run_client_phase (pi, - pc)) && - (! fuzzing) ) + if ((!run_client_phase (pi, + pc)) + && (!fuzzing)) { res = 1; goto cleanup; @@ -754,42 +754,42 @@ MHDT_load_pem (const char *name) "Failed to fstat %s: %s\n", path, strerror (errno)); - (void) close (fd); + (void)close (fd); return NULL; } - if (((unsigned long long) s.st_size) >= (unsigned long long) SIZE_MAX) + if (((unsigned long long)s.st_size) >= (unsigned long long)SIZE_MAX) { fprintf (stderr, "File %s too large (%llu >= %llu bytes) to malloc()\n", path, - (unsigned long long) s.st_size, - (unsigned long long) SIZE_MAX); - (void) close (fd); + (unsigned long long)s.st_size, + (unsigned long long)SIZE_MAX); + (void)close (fd); return NULL; } - buf = (char *) malloc (((size_t) s.st_size + 1)); + buf = (char *)malloc (((size_t)s.st_size + 1)); if (NULL == buf) { fprintf (stderr, "Failed to malloc(): %s\n", strerror (errno)); - (void) close (fd); + (void)close (fd); return NULL; } if (-1 == read (fd, // FIXME: read() should be called in loop to handle partial reads buf, - (size_t) s.st_size)) + (size_t)s.st_size)) { fprintf (stderr, "Failed to read %s: %s\n", path, strerror (errno)); free (buf); - (void) close (fd); + (void)close (fd); return NULL; } - (void) close (fd); - buf[(size_t) s.st_size] = 0; + (void)close (fd); + buf[(size_t)s.st_size] = 0; return buf; } diff --git a/src/tests/client_server/libtest_convenience.c b/src/tests/client_server/libtest_convenience.c @@ -68,17 +68,17 @@ get_port (void) unsigned int i; char dummy; - if ( (1 != sscanf (portenv, - "%u%c", - &i, - &dummy)) || - (i > 65535) ) + if ((1 != sscanf (portenv, + "%u%c", + &i, + &dummy)) + || (i > 65535)) { fprintf (stderr, "Invalid port number specified in MHD_TEST_FORCE_PORT, using 0"); return 0; } - return (uint16_t) i; + return (uint16_t)i; } return 0; } @@ -89,7 +89,7 @@ MHDT_server_setup_minimal (const void *cls, struct MHD_Daemon *d) { const struct MHD_DaemonOptionAndValue *options - = (const struct MHD_DaemonOptionAndValue *) cls; + = (const struct MHD_DaemonOptionAndValue *)cls; if (MHD_SC_OK != MHD_daemon_set_options ( @@ -193,7 +193,7 @@ MHDT_server_setup_tls (const void *cls, struct MHD_Daemon *d) { const struct MHD_DaemonOptionAndValue *options - = (const struct MHD_DaemonOptionAndValue *) cls; + = (const struct MHD_DaemonOptionAndValue *)cls; const char *err; err = MHDT_server_setup_minimal (options, @@ -213,7 +213,7 @@ MHDT_server_setup_gnutls (const void *cls, struct MHD_Daemon *d) { const struct MHD_DaemonOptionAndValue *options - = (const struct MHD_DaemonOptionAndValue *) cls; + = (const struct MHD_DaemonOptionAndValue *)cls; const char *err; err = MHDT_server_setup_minimal (options, @@ -233,7 +233,7 @@ MHDT_server_setup_openssl (const void *cls, struct MHD_Daemon *d) { const struct MHD_DaemonOptionAndValue *options - = (const struct MHD_DaemonOptionAndValue *) cls; + = (const struct MHD_DaemonOptionAndValue *)cls; const char *err; err = MHDT_server_setup_minimal (options, @@ -256,20 +256,20 @@ MHDT_server_run_minimal (void *cls, fd_set r; char c; - (void) cls; /* Unused */ - (void) d; /* Unused */ + (void)cls; /* Unused */ + (void)d; /* Unused */ FD_ZERO (&r); FD_SET (finsig, &r); while (1) { - if ( (-1 == - select (finsig + 1, - &r, - NULL, - NULL, - NULL)) && - (EAGAIN != errno) ) + if ((-1 == + select (finsig + 1, + &r, + NULL, + NULL, + NULL)) + && (EAGAIN != errno)) { fprintf (stderr, "Failure waiting on termination signal: %s\n", @@ -280,11 +280,11 @@ MHDT_server_run_minimal (void *cls, &r)) break; } - if ( (FD_ISSET (finsig, - &r)) && - (1 != read (finsig, - &c, - 1)) ) + if ((FD_ISSET (finsig, + &r)) + && (1 != read (finsig, + &c, + 1))) { fprintf (stderr, "Failed to drain termination signal\n"); @@ -300,8 +300,8 @@ MHDT_server_run_blocking (void *cls, fd_set r; char c; - (void) cls; /* Unused */ - (void) d; /* Unused */ + (void)cls; /* Unused */ + (void)d; /* Unused */ FD_ZERO (&r); FD_SET (finsig, &r); @@ -311,13 +311,13 @@ MHDT_server_run_blocking (void *cls, .tv_usec = 1000 /* 1000 microseconds */ }; - if ( (-1 == - select (finsig + 1, - &r, - NULL, - NULL, - &timeout)) && - (EAGAIN != errno) ) + if ((-1 == + select (finsig + 1, + &r, + NULL, + NULL, + &timeout)) + && (EAGAIN != errno)) { fprintf (stderr, "Failure waiting on termination signal: %s\n", @@ -337,11 +337,11 @@ MHDT_server_run_blocking (void *cls, abort (); #endif } - if ( (FD_ISSET (finsig, - &r)) && - (1 != read (finsig, - &c, - 1)) ) + if ((FD_ISSET (finsig, + &r)) + && (1 != read (finsig, + &c, + 1))) { fprintf (stderr, "Failed to drain termination signal\n"); @@ -381,7 +381,7 @@ update_fd ( { struct epoll_event ev; - (void) cls; + (void)cls; if (watch_for == MHD_FD_STATE_NONE) { epoll_ctl (my_epoll_fd, @@ -400,8 +400,8 @@ update_fd ( ev.events |= EPOLLHUP; if (0 != epoll_ctl (my_epoll_fd, - NULL == app_cntx_old - ? EPOLL_CTL_ADD + (NULL == app_cntx_old) + ? EPOLL_CTL_ADD : EPOLL_CTL_MOD, fd, &ev)) @@ -419,7 +419,7 @@ const char * MHDT_server_setup_external (const void *cls, struct MHD_Daemon *d) { - (void) cls; + (void)cls; if (MHD_SC_OK != MHD_DAEMON_SET_OPTIONS ( d, @@ -446,7 +446,7 @@ MHDT_server_run_external (void *cls, { fd_set r; - (void) cls; /* Unused */ + (void)cls; /* Unused */ if (-1 == my_epoll_fd) abort (); while (1) @@ -462,29 +462,29 @@ MHDT_server_run_external (void *cls, "MHD_daemon_process_reg_events() failed\n"); break; } -#ifdef HAVE_TIME_H - timeout.tv_sec = (time_t) (next_wait / 1000u); -#else - timeout.tv_sec = (long) (next_wait / 1000u); -#endif -#ifdef HAVE_SUSECONDS_T - timeout.tv_usec = (suseconds_t) ((next_wait % 1000u) * 1000u); -#else - timeout.tv_usec = (long) ((next_wait % 1000u) * 1000u); -#endif +# ifdef HAVE_TIME_H + timeout.tv_sec = (time_t)(next_wait / 1000u); +# else + timeout.tv_sec = (long)(next_wait / 1000u); +# endif +# ifdef HAVE_SUSECONDS_T + timeout.tv_usec = (suseconds_t)((next_wait % 1000u) * 1000u); +# else + timeout.tv_usec = (long)((next_wait % 1000u) * 1000u); +# endif FD_ZERO (&r); FD_SET (finsig, &r); FD_SET (my_epoll_fd, &r); - if ( (-1 == - select ((my_epoll_fd > finsig ? my_epoll_fd : finsig) + 1, - &r, - NULL, - NULL, - &timeout)) && - (EAGAIN != errno) ) + if ((-1 == + select (((my_epoll_fd > finsig) ? my_epoll_fd : finsig) + 1, + &r, + NULL, + NULL, + &timeout)) + && (EAGAIN != errno)) { fprintf (stderr, "Failure in select(): %s\n", @@ -521,11 +521,11 @@ MHDT_server_run_external (void *cls, MHD_FD_STATE_SET_RECV (state); if (0 != (events[i].events & EPOLLOUT)) MHD_FD_STATE_SET_SEND (state); - if (0 != (events[i].events & (EPOLLERR | EPOLLHUP)) ) + if (0 != (events[i].events & (EPOLLERR | EPOLLHUP))) MHD_FD_STATE_SET_EXCEPT (state); MHD_daemon_event_update ( d, - (struct MHD_EventUpdateContext *) events[i].data.ptr, + (struct MHD_EventUpdateContext *)events[i].data.ptr, state); } } @@ -534,11 +534,11 @@ MHDT_server_run_external (void *cls, { char c; - if ( (FD_ISSET (finsig, - &r)) && - (1 != read (finsig, - &c, - 1)) ) + if ((FD_ISSET (finsig, + &r)) + && (1 != read (finsig, + &c, + 1))) { fprintf (stderr, "Failed to drain termination signal\n"); diff --git a/src/tests/client_server/libtest_convenience_client_request.c b/src/tests/client_server/libtest_convenience_client_request.c @@ -51,14 +51,14 @@ #ifndef CURL_VERSION_BITS -# define CURL_VERSION_BITS(x,y,z) ((x) << 16 | (y) << 8 | (z)) +# define CURL_VERSION_BITS(x, y, z) ((x) << 16 | (y) << 8 | (z)) #endif #ifndef CURL_AT_LEAST_VERSION -# define CURL_AT_LEAST_VERSION(x,y,z) \ - (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS (x, y, z)) +# define CURL_AT_LEAST_VERSION(x, y, z) \ + (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS (x, y, z)) #endif -#if CURL_AT_LEAST_VERSION (7,83,0) +#if CURL_AT_LEAST_VERSION (7, 83, 0) # define HAVE_LIBCRUL_NEW_HDR_API 1 #endif @@ -109,9 +109,9 @@ write_cb (void *ptr, struct WriteBuffer *wb = stream; size_t prod = size * nmemb; - if ( (prod / size != nmemb) || - (wb->pos + prod < wb->pos) || - (wb->pos + prod > wb->len) ) + if ((prod / size != nmemb) + || (wb->pos + prod < wb->pos) + || (wb->pos + prod > wb->len)) { wb->err = 1; return CURLE_WRITE_ERROR; @@ -144,7 +144,7 @@ write_cb (void *ptr, * * @param c CURL handle */ -#define SETUP_WB(c) do { \ +#define SETUP_WB(c) do { \ if (CURLE_OK != \ curl_easy_setopt (c, \ CURLOPT_WRITEFUNCTION, \ @@ -159,23 +159,23 @@ write_cb (void *ptr, &wb)) \ { \ curl_easy_cleanup (c); \ - return "Failed to set write buffer for curl request"; \ - } \ -} while (0) + return "Failed to set write buffer for curl request"; \ + } \ + } while (0) /** * Check that we received the expected text. * * @param text text we expect to have downloaded */ -#define CHECK_WB(text) do { \ +#define CHECK_WB(text) do { \ if ( (wb_tlen != wb.pos) || \ (0 != wb.err) || \ (0 != memcmp (text, \ wb_buf, \ wb_tlen)) ) \ return "Downloaded data does not match expectations"; \ -} while (0) + } while (0) /** @@ -192,7 +192,7 @@ write_cb (void *ptr, curl_easy_cleanup (c); \ return "Failed to fetch URL"; \ } \ -} while (0) + } while (0) /** * Check that the curl request @a c completed @@ -202,13 +202,13 @@ write_cb (void *ptr, * @param c request to check * @param want desired HTTP status code */ -#define CHECK_STATUS(c,want) do { \ +#define CHECK_STATUS(c, want) do { \ if (! check_status (c, want)) \ { \ curl_easy_cleanup (c); \ return "Unexpected HTTP status"; \ } \ -} while (0) + } while (0) /** * Chec that the HTTP status of @a c matches @a expected_status @@ -232,7 +232,7 @@ check_status (CURL *c, "Failed to get HTTP status"); return false; } - if (((unsigned int) status) != expected_status) + if (((unsigned int)status) != expected_status) { fprintf (stderr, "Expected HTTP status %u, got %ld\n", @@ -265,37 +265,37 @@ set_url (CURL *c, curl_easy_cleanup (c); return "Failed to set URL"; } - if ( (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_TIMEOUT_MS, - 500)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_CONNECTTIMEOUT_MS, - 50)) || + if ((CURLE_OK != + curl_easy_setopt (c, + CURLOPT_TIMEOUT_MS, + 500)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_CONNECTTIMEOUT_MS, + 50)) || #ifdef CURLOPT_SERVER_RESPONSE_TIMEOUT_MS - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_SERVER_RESPONSE_TIMEOUT_MS, - 250)) || + (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_SERVER_RESPONSE_TIMEOUT_MS, + 250)) || #else - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_SERVER_RESPONSE_TIMEOUT, - 1)) || + (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_SERVER_RESPONSE_TIMEOUT, + 1)) || #endif - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_FRESH_CONNECT, - 1L)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_FORBID_REUSE, - 1L)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_VERBOSE, - 0)) ) + (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_FRESH_CONNECT, + 1L)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_FORBID_REUSE, + 1L)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_VERBOSE, + 0))) { curl_easy_cleanup (c); return "Failed to set curl options"; @@ -319,7 +319,7 @@ set_url (CURL *c, snprintf (ri, sizeof (ri), "%.*s:127.0.0.1", - (int) (end - host), + (int)(end - host), host); pc->hosts = curl_slist_append (NULL, ri); @@ -352,14 +352,14 @@ set_url (CURL *c, else { /* disable certificate checking */ - if ( (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_SSL_VERIFYPEER, - 0L)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_SSL_VERIFYHOST, - 0L)) ) + if ((CURLE_OK != + curl_easy_setopt (c, + CURLOPT_SSL_VERIFYPEER, + 0L)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_SSL_VERIFYHOST, + 0L))) { curl_easy_cleanup (c); return "Failed to disable X509 server certificate checks"; @@ -631,7 +631,7 @@ MHDT_client_expect_header (const void *cls, PERFORM_REQUEST (c); CHECK_STATUS (c, MHD_HTTP_STATUS_NO_CONTENT); - for (size_t index = 0; ! found; index++) + for (size_t index = 0; !found; index++) { CURLHcode rval; struct curl_header *hout; @@ -647,7 +647,7 @@ MHDT_client_expect_header (const void *cls, found = (0 == strcmp (value, hout->value)); } - if (! found) + if (!found) { curl_easy_cleanup (c); return "Expected HTTP response header not found"; @@ -655,7 +655,8 @@ MHDT_client_expect_header (const void *cls, curl_easy_cleanup (c); return NULL; #else /* ! HAVE_LIBCRUL_NEW_HDR_API */ - (void) cls; (void) pc; + (void)cls; + (void)pc; return NULL; #endif /* ! HAVE_LIBCRUL_NEW_HDR_API */ } @@ -712,8 +713,8 @@ read_cb (void *ptr, return CURLE_WRITE_ERROR; if (limit > rb->len - rb->pos) limit = rb->len - rb->pos; - if ( (rb->chunks > 1) && - (limit > 1) ) + if ((rb->chunks > 1) + && (limit > 1)) { limit /= rb->chunks; rb->chunks--; @@ -774,7 +775,7 @@ MHDT_client_put_data ( if (CURLE_OK != curl_easy_setopt (c, CURLOPT_INFILESIZE_LARGE, - (curl_off_t) rb.len)) + (curl_off_t)rb.len)) { curl_easy_cleanup (c); return "Failed to set INFILESIZE_LARGE for curl request"; @@ -889,7 +890,7 @@ MHDT_client_do_post ( if (CURLE_OK != curl_easy_setopt (c, CURLOPT_POSTFIELDSIZE_LARGE, - (curl_off_t) pi->postdata_size)) + (curl_off_t)pi->postdata_size)) { curl_easy_cleanup (c); return "Failed to set POSTFIELDS for curl request"; @@ -918,7 +919,7 @@ MHDT_client_do_post ( { for (unsigned int i = 0; NULL != pi->wants[i].key; i++) { - if (! pi->wants[i].satisfied) + if (!pi->wants[i].satisfied) { fprintf (stderr, "Server did not correctly detect key '%s'\n", @@ -970,18 +971,18 @@ send_basic_auth (const char *cred, curl_easy_cleanup (c); return err; } - if ( (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_HTTPAUTH, - (long) CURLAUTH_BASIC)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_USERNAME, - user)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_PASSWORD, - pass)) ) + if ((CURLE_OK != + curl_easy_setopt (c, + CURLOPT_HTTPAUTH, + (long)CURLAUTH_BASIC)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_USERNAME, + user)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_PASSWORD, + pass))) { curl_easy_cleanup (c); free (user); @@ -996,7 +997,7 @@ send_basic_auth (const char *cred, { return "Failed to get HTTP status"; } - *http_status = (unsigned int) status; + *http_status = (unsigned int)status; curl_easy_cleanup (c); return NULL; } @@ -1081,18 +1082,18 @@ send_digest_auth (const char *cred, curl_easy_cleanup (c); return err; } - if ( (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_HTTPAUTH, - (long) CURLAUTH_DIGEST)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_USERNAME, - user)) || - (CURLE_OK != - curl_easy_setopt (c, - CURLOPT_PASSWORD, - pass)) ) + if ((CURLE_OK != + curl_easy_setopt (c, + CURLOPT_HTTPAUTH, + (long)CURLAUTH_DIGEST)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_USERNAME, + user)) + || (CURLE_OK != + curl_easy_setopt (c, + CURLOPT_PASSWORD, + pass))) { curl_easy_cleanup (c); free (user); @@ -1107,7 +1108,7 @@ send_digest_auth (const char *cred, { return "Failed to get HTTP status"; } - *http_status = (unsigned int) status; + *http_status = (unsigned int)status; curl_easy_cleanup (c); return NULL; } diff --git a/src/tests/client_server/libtest_convenience_server_reply.c b/src/tests/client_server/libtest_convenience_server_reply.c @@ -54,11 +54,11 @@ #include <assert.h> #ifndef CURL_VERSION_BITS -# define CURL_VERSION_BITS(x,y,z) ((x) << 16 | (y) << 8 | (z)) +# define CURL_VERSION_BITS(x, y, z) ((x) << 16 | (y) << 8 | (z)) #endif #ifndef CURL_AT_LEAST_VERSION -# define CURL_AT_LEAST_VERSION(x,y,z) \ - (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS (x, y, z)) +# define CURL_AT_LEAST_VERSION(x, y, z) \ + (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS (x, y, z)) #endif const struct MHD_Action * @@ -71,7 +71,9 @@ MHDT_server_reply_text ( { const char *text = cls; - (void) path; (void) method; (void) upload_size; /* Unused */ + (void)path; + (void)method; + (void)upload_size; /* Unused */ return MHD_action_from_response ( request, @@ -94,7 +96,9 @@ MHDT_server_reply_file ( char fn[] = "/tmp/mhd-test-XXXXXX"; int fd; - (void) path; (void) method; (void) upload_size; /* Unused */ + (void)path; + (void)method; + (void)upload_size; /* Unused */ fd = mkstemp (fn); if (-1 == fd) @@ -103,7 +107,7 @@ MHDT_server_reply_file ( "Failed to mkstemp() temporary file\n"); return MHD_action_abort_request (request); } - if (((ssize_t) tlen) != write (fd, text, tlen)) + if (((ssize_t)tlen) != write (fd, text, tlen)) { fprintf (stderr, "Failed to write() temporary file in one go: %s\n", @@ -142,7 +146,9 @@ MHDT_server_reply_with_header ( const char *value; struct MHD_Response *resp; - (void) path; (void) method; (void) upload_size; /* Unused */ + (void)path; + (void)method; + (void)upload_size; /* Unused */ memcpy (name, header, @@ -177,7 +183,9 @@ MHDT_server_reply_check_query ( size_t qlen = strlen (equery) + 1; char qc[qlen]; - (void) path; (void) method; (void) upload_size; /* Unused */ + (void)path; + (void)method; + (void)upload_size; /* Unused */ memcpy (qc, equery, @@ -201,7 +209,7 @@ MHDT_server_reply_check_query ( val = end + 1; } { - size_t alen = (size_t) (end - tok); + size_t alen = (size_t)(end - tok); char arg[alen + 1]; memcpy (arg, @@ -276,7 +284,9 @@ MHDT_server_reply_check_header ( struct MHD_StringNullable have; const char *value; - (void) path; (void) method; (void) upload_size; /* Unused */ + (void)path; + (void)method; + (void)upload_size; /* Unused */ memcpy (key, want, @@ -402,12 +412,14 @@ MHDT_server_reply_check_upload ( const char *want = cls; size_t wlen = strlen (want); - (void) path; (void) method; (void) upload_size; /* Unused */ + (void)path; + (void)method; + (void)upload_size; /* Unused */ return MHD_action_process_upload_full (request, wlen, &check_upload_cb, - (void *) want); + (void *)want); } @@ -452,12 +464,12 @@ chunk_return (void *cls, size_t imax = strlen (cc->pos); const char *space = strchr (cc->pos, ' '); - (void) pos; // TODO: add check + (void)pos; // TODO: add check if (0 == imax) return MHD_DCC_action_finish (ctx); if (NULL != space) - imax = (size_t) (space - cc->pos) + 1; + imax = (size_t)(space - cc->pos) + 1; if (imax > max) imax = max; memcpy (buf, @@ -480,7 +492,9 @@ MHDT_server_reply_chunked_text ( const char *text = cls; struct ChunkContext *cc; - (void) path; (void) method; (void) upload_size; /* Unused */ + (void)path; + (void)method; + (void)upload_size; /* Unused */ cc = malloc (sizeof (struct ChunkContext)); if (NULL == cc) @@ -508,12 +522,12 @@ static bool nstrcmp (const char *wants, const struct MHD_StringNullable *have) { - if ( (NULL == wants) && - (NULL == have->cstr) && - (0 == have->len) ) + if ((NULL == wants) + && (NULL == have->cstr) + && (0 == have->len)) return true; - if ( (NULL == wants) || - (NULL == have->cstr) ) + if ((NULL == wants) + || (NULL == have->cstr)) return false; return (0 == strcmp (wants, have->cstr)); @@ -569,7 +583,7 @@ post_stream_reader (struct MHD_Request *req, struct MHDT_PostInstructions *pi = cls; struct MHDT_PostWant *wants = pi->wants; - (void) encoding; // TODO: add check + (void)encoding; // TODO: add check if (NULL != wants) { @@ -582,13 +596,13 @@ post_stream_reader (struct MHD_Request *req, if (0 != strcmp (want->key, name->cstr)) continue; - if (! nstrcmp (want->filename, - filename)) + if (!nstrcmp (want->filename, + filename)) continue; - if (! nstrcmp (want->content_type, - content_type)) + if (!nstrcmp (want->content_type, + content_type)) continue; - if (! want->incremental) + if (!want->incremental) continue; if (want->value_off != off) continue; @@ -661,10 +675,10 @@ check_complete_post_value ( } else { - if ((want->value_size == nv->value.len) && - (0 == memcmp (nv->value.cstr, - want->value, - want->value_size))) + if ((want->value_size == nv->value.len) + && (0 == memcmp (nv->value.cstr, + want->value, + want->value_size))) want->satisfied = true; } } @@ -692,7 +706,7 @@ post_stream_done (struct MHD_Request *req, { fprintf (stderr, "POST parsing was not successful. The result: %d\n", - (int) parsing_result); + (int)parsing_result); return MHD_upload_action_abort_request (req); } @@ -731,14 +745,14 @@ MHDT_server_reply_check_post ( { struct MHDT_PostInstructions *pi = cls; - (void) path; /* Unused */ - (void) upload_size; // TODO: add check + (void)path; /* Unused */ + (void)upload_size; // TODO: add check if (MHD_HTTP_METHOD_POST != method) { fprintf (stderr, "Reported HTTP method other then POST. Reported method: %u\n", - (unsigned) method); + (unsigned)method); return MHD_action_abort_request (req); } @@ -786,13 +800,13 @@ MHDT_server_reply_check_basic_auth ( } ba = dd.v_auth_basic_creds; assert (NULL != ba); - if ( (0 != strncmp (ba->username.cstr, - cred, - ba->username.len)) || - (':' != cred[ba->username.len]) || - (NULL == ba->password.cstr) || - (0 != strcmp (ba->password.cstr, - &cred[ba->username.len + 1])) ) + if ((0 != strncmp (ba->username.cstr, + cred, + ba->username.len)) + || (':' != cred[ba->username.len]) + || (NULL == ba->password.cstr) + || (0 != strcmp (ba->password.cstr, + &cred[ba->username.len + 1]))) { fprintf (stderr, "Wrong credentials (Got: %s/%s Want: %s)!\n", @@ -827,14 +841,14 @@ MHDT_server_reply_check_digest_auth ( const char *password; enum MHD_DigestAuthResult dar; const char *realm = "test-realm"; -#if CURL_AT_LEAST_VERSION (7,57,0) +#if CURL_AT_LEAST_VERSION (7, 57, 0) enum MHD_DigestAuthAlgo algo = MHD_DIGEST_AUTH_ALGO_SHA256; #else enum MHD_DigestAuthAlgo algo = MHD_DIGEST_AUTH_ALGO_MD5; #endif size_t digest_len = MHD_digest_get_hash_size (algo); - (void) cls; /* Unused, mute compiler warning */ + (void)cls; /* Unused, mute compiler warning */ if (0 == digest_len) return NULL; @@ -860,7 +874,7 @@ MHDT_server_reply_check_digest_auth ( { fprintf (stderr, "MHD_digest_auth_calc_userdigest: %d\n", - (int) sc); + (int)sc); free (username); return NULL; } @@ -871,7 +885,7 @@ MHDT_server_reply_check_digest_auth ( digest, 0, /* maximum nonce counter; 0: default */ MHD_DIGEST_AUTH_MULT_QOP_AUTH, - (enum MHD_DigestAuthMultiAlgo) algo); + (enum MHD_DigestAuthMultiAlgo)algo); } free (username); if ((MHD_DAUTH_HEADER_MISSING == dar) @@ -895,14 +909,14 @@ MHDT_server_reply_check_digest_auth ( NULL, /* domain */ (MHD_DAUTH_NONCE_STALE == dar) ? MHD_YES : MHD_NO, /* indicate stale */ MHD_DIGEST_AUTH_MULT_QOP_AUTH, - (enum MHD_DigestAuthMultiAlgo) algo, + (enum MHD_DigestAuthMultiAlgo)algo, MHD_NO /* userhash_support */, MHD_YES /* prefer UTF8 */); if (MHD_SC_OK != sc) { fprintf (stderr, "MHD_response_add_auth_digest_challenge failed: %d\n", - (int) sc); + (int)sc); return NULL; } return MHD_action_from_response ( diff --git a/src/tests/client_server/test_authentication.c b/src/tests/client_server/test_authentication.c @@ -78,34 +78,34 @@ main (int argc, char *argv[]) { .label = "simple basic authentication", .server_cb = &MHDT_server_reply_check_basic_auth, - .server_cb_cls = (void *) "username:password", + .server_cb_cls = (void *)"username:password", .client_cb = &MHDT_client_send_basic_auth, - .client_cb_cls = (void *) "username:password", + .client_cb_cls = (void *)"username:password", .timeout_ms = 2500, }, { .label = "failing basic authentication", .server_cb = &MHDT_server_reply_check_basic_auth, - .server_cb_cls = (void *) "username:password", + .server_cb_cls = (void *)"username:password", .client_cb = &MHDT_client_fail_basic_auth, - .client_cb_cls = (void *) "username:word", /* incorrect on purpose */ + .client_cb_cls = (void *)"username:word", /* incorrect on purpose */ .timeout_ms = 2500, }, #endif { .label = "simple digest authentication", .server_cb = &MHDT_server_reply_check_digest_auth, - .server_cb_cls = (void *) "username:password", + .server_cb_cls = (void *)"username:password", .client_cb = &MHDT_client_send_digest_auth, - .client_cb_cls = (void *) "username:password", + .client_cb_cls = (void *)"username:password", .timeout_ms = 2500, }, { .label = "failing digest authentication", .server_cb = &MHDT_server_reply_check_digest_auth, - .server_cb_cls = (void *) "username:password", + .server_cb_cls = (void *)"username:password", .client_cb = &MHDT_client_fail_digest_auth, - .client_cb_cls = (void *) "username:word", /* incorrect on purpose */ + .client_cb_cls = (void *)"username:word", /* incorrect on purpose */ .timeout_ms = 2500, }, { @@ -114,8 +114,8 @@ main (int argc, char *argv[]) }; unsigned int i; - (void) argc; /* Unused. Silence compiler warning. */ - (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ + (void)argv; /* Unused. Silence compiler warning. */ for (i = 0; NULL != configs[i].server_setup; i++) { diff --git a/src/tests/client_server/test_cert_tls.c b/src/tests/client_server/test_cert_tls.c @@ -99,7 +99,7 @@ main (int argc, char *argv[]) .phase = { .label = "simple RCA get", .server_cb = &MHDT_server_reply_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_host, .client_cb_cls = "localhost", .timeout_ms = 2500, @@ -118,7 +118,7 @@ main (int argc, char *argv[]) .phase = { .label = "simple RCA get", .server_cb = &MHDT_server_reply_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_host, .client_cb_cls = "localhost", .timeout_ms = 2500, @@ -138,7 +138,7 @@ main (int argc, char *argv[]) .phase = { .label = "simple RCA get", .server_cb = &MHDT_server_reply_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_host, .client_cb_cls = "localhost", .timeout_ms = 2500, @@ -156,8 +156,8 @@ main (int argc, char *argv[]) unsigned int i; int ret = 0; - (void) argc; /* Unused. Silence compiler warning. */ - (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ + (void)argv; /* Unused. Silence compiler warning. */ for (i = 0; NULL != configs[i].server_setup; i++) { diff --git a/src/tests/client_server/test_client_server.c b/src/tests/client_server/test_client_server.c @@ -207,7 +207,7 @@ main (int argc, char *argv[]) { .label = "simple get", .server_cb = &MHDT_server_reply_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -215,7 +215,7 @@ main (int argc, char *argv[]) { .label = "GET with sendfile", .server_cb = &MHDT_server_reply_file, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -223,7 +223,7 @@ main (int argc, char *argv[]) { .label = "client PUT with content-length", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "simple-upload-value", + .server_cb_cls = (void *)"simple-upload-value", .client_cb = &MHDT_client_put_data, .client_cb_cls = "simple-upload-value", .timeout_ms = 2500, @@ -231,7 +231,7 @@ main (int argc, char *argv[]) { .label = "client PUT with 2 chunks", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "chunky-upload-value", + .server_cb_cls = (void *)"chunky-upload-value", .client_cb = &MHDT_client_chunk_data, .client_cb_cls = "chunky-upload-value", .timeout_ms = 2500, @@ -239,7 +239,7 @@ main (int argc, char *argv[]) { .label = "client request with custom header", .server_cb = &MHDT_server_reply_check_header, - .server_cb_cls = (void *) "C-Header:testvalue", + .server_cb_cls = (void *)"C-Header:testvalue", .client_cb = &MHDT_client_set_header, .client_cb_cls = "C-Header:testvalue", .timeout_ms = 2500, @@ -247,7 +247,7 @@ main (int argc, char *argv[]) { .label = "server response with custom header", .server_cb = &MHDT_server_reply_with_header, - .server_cb_cls = (void *) "X-Header:testvalue", + .server_cb_cls = (void *)"X-Header:testvalue", .client_cb = &MHDT_client_expect_header, .client_cb_cls = "X-Header:testvalue", .timeout_ms = 2500, @@ -255,7 +255,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 1", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", + .server_cb_cls = (void *)"a=b&c", .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b&c", .timeout_ms = 5000, @@ -264,7 +264,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 2", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", /* a => b, c => NULL */ + .server_cb_cls = (void *)"a=b&c", /* a => b, c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=b", .timeout_ms = 5000, @@ -273,7 +273,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 3", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=&c", /* a => "", c => NULL */ + .server_cb_cls = (void *)"a=&c", /* a => "", c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=", .timeout_ms = 5000, @@ -282,7 +282,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 4", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=", /* a => "" */ + .server_cb_cls = (void *)"a=", /* a => "" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=", .timeout_ms = 5000, @@ -291,7 +291,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 5", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b", /* a => "b" */ + .server_cb_cls = (void *)"a=b", /* a => "b" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b", .timeout_ms = 5000, @@ -300,7 +300,7 @@ main (int argc, char *argv[]) { .label = "chunked response get", .server_cb = &MHDT_server_reply_chunked_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -312,8 +312,8 @@ main (int argc, char *argv[]) }; unsigned int i; - (void) argc; /* Unused. Silence compiler warning. */ - (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ + (void)argv; /* Unused. Silence compiler warning. */ for (i = 0; NULL != configs[i].server_setup; i++) { diff --git a/src/tests/client_server/test_http2.c b/src/tests/client_server/test_http2.c @@ -172,7 +172,7 @@ main (int argc, char *argv[]) { .label = "simple get", .server_cb = &MHDT_server_reply_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -181,7 +181,7 @@ main (int argc, char *argv[]) { .label = "GET with sendfile", .server_cb = &MHDT_server_reply_file, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -191,7 +191,7 @@ main (int argc, char *argv[]) { .label = "client PUT with content-length", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "simple-upload-value", + .server_cb_cls = (void *)"simple-upload-value", .client_cb = &MHDT_client_put_data, .client_cb_cls = "simple-upload-value", .timeout_ms = 2500, @@ -200,7 +200,7 @@ main (int argc, char *argv[]) { .label = "client PUT with 2 chunks", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "chunky-upload-value", + .server_cb_cls = (void *)"chunky-upload-value", .client_cb = &MHDT_client_chunk_data, .client_cb_cls = "chunky-upload-value", .timeout_ms = 2500, @@ -210,7 +210,7 @@ main (int argc, char *argv[]) { .label = "client request with custom header", .server_cb = &MHDT_server_reply_check_header, - .server_cb_cls = (void *) "C-Header:testvalue", + .server_cb_cls = (void *)"C-Header:testvalue", .client_cb = &MHDT_client_set_header, .client_cb_cls = "C-Header:testvalue", .timeout_ms = 2500, @@ -219,7 +219,7 @@ main (int argc, char *argv[]) { .label = "server response with custom header", .server_cb = &MHDT_server_reply_with_header, - .server_cb_cls = (void *) "X-Header:testvalue", + .server_cb_cls = (void *)"X-Header:testvalue", .client_cb = &MHDT_client_expect_header, .client_cb_cls = "X-Header:testvalue", .timeout_ms = 2500, @@ -228,7 +228,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 1", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", + .server_cb_cls = (void *)"a=b&c", .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b&c", .timeout_ms = 5000, @@ -238,7 +238,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 2", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", /* a => b, c => NULL */ + .server_cb_cls = (void *)"a=b&c", /* a => b, c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=b", .timeout_ms = 5000, @@ -248,7 +248,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 3", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=&c", /* a => "", c => NULL */ + .server_cb_cls = (void *)"a=&c", /* a => "", c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=", .timeout_ms = 5000, @@ -258,7 +258,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 4", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=", /* a => "" */ + .server_cb_cls = (void *)"a=", /* a => "" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=", .timeout_ms = 5000, @@ -268,7 +268,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 5", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b", /* a => "b" */ + .server_cb_cls = (void *)"a=b", /* a => "b" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b", .timeout_ms = 5000, @@ -279,7 +279,7 @@ main (int argc, char *argv[]) { .label = "chunked response get", .server_cb = &MHDT_server_reply_chunked_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -293,8 +293,8 @@ main (int argc, char *argv[]) }; unsigned int i; - (void) argc; /* Unused. Silence compiler warning. */ - (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ + (void)argv; /* Unused. Silence compiler warning. */ for (i = 0; NULL != configs[i].server_setup; i++) { diff --git a/src/tests/client_server/test_postparser.c b/src/tests/client_server/test_postparser.c @@ -174,8 +174,8 @@ main (int argc, char *argv[]) }; unsigned int i; - (void) argc; /* Unused. Silence compiler warning. */ - (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ + (void)argv; /* Unused. Silence compiler warning. */ for (i = 0; NULL != configs[i].server_setup; i++) { diff --git a/src/tests/client_server/test_tls.c b/src/tests/client_server/test_tls.c @@ -110,14 +110,14 @@ main (int argc, char *argv[]) .server_setup_cls = thread2select, .server_runner = &MHDT_server_run_minimal, }, -#if MHD_SUPPORT_GNUTLS +# if MHD_SUPPORT_GNUTLS { .label = "multi-threaded select, forcing GnuTLS", .server_setup = &MHDT_server_setup_gnutls, .server_setup_cls = thread2select, .server_runner = &MHDT_server_run_minimal, }, -#endif +# endif #endif #ifdef MHD_SUPPORT_POLL { @@ -132,14 +132,14 @@ main (int argc, char *argv[]) .server_setup_cls = thread2poll, .server_runner = &MHDT_server_run_minimal, }, -#ifdef MHD_SUPPORT_GNUTLS +# ifdef MHD_SUPPORT_GNUTLS { .label = "multi-threaded poll, forcing GnuTLS", .server_setup = &MHDT_server_setup_gnutls, .server_setup_cls = thread2poll, .server_runner = &MHDT_server_run_minimal, }, -#endif +# endif #endif #ifdef MHD_SUPPORT_EPOLL { @@ -154,14 +154,14 @@ main (int argc, char *argv[]) .server_setup_cls = thread2epoll, .server_runner = &MHDT_server_run_minimal, }, -#ifdef MHD_SUPPORT_GNUTLS +# ifdef MHD_SUPPORT_GNUTLS { .label = "multi-threaded epoll, forcing GnuTLS", .server_setup = &MHDT_server_setup_gnutls, .server_setup_cls = thread2epoll, .server_runner = &MHDT_server_run_minimal, }, -#endif +# endif #endif { .label = "auto-selected mode, single threaded", @@ -206,7 +206,7 @@ main (int argc, char *argv[]) { .label = "simple get", .server_cb = &MHDT_server_reply_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -216,7 +216,7 @@ main (int argc, char *argv[]) { .label = "GET with sendfile", .server_cb = &MHDT_server_reply_file, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -226,7 +226,7 @@ main (int argc, char *argv[]) { .label = "client PUT with content-length", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "simple-upload-value", + .server_cb_cls = (void *)"simple-upload-value", .client_cb = &MHDT_client_put_data, .client_cb_cls = "simple-upload-value", .timeout_ms = 2500, @@ -236,7 +236,7 @@ main (int argc, char *argv[]) { .label = "client PUT with 2 chunks", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "chunky-upload-value", + .server_cb_cls = (void *)"chunky-upload-value", .client_cb = &MHDT_client_chunk_data, .client_cb_cls = "chunky-upload-value", .timeout_ms = 2500, @@ -246,7 +246,7 @@ main (int argc, char *argv[]) { .label = "client request with custom header", .server_cb = &MHDT_server_reply_check_header, - .server_cb_cls = (void *) "C-Header:testvalue", + .server_cb_cls = (void *)"C-Header:testvalue", .client_cb = &MHDT_client_set_header, .client_cb_cls = "C-Header:testvalue", .timeout_ms = 2500, @@ -256,7 +256,7 @@ main (int argc, char *argv[]) { .label = "server response with custom header", .server_cb = &MHDT_server_reply_with_header, - .server_cb_cls = (void *) "X-Header:testvalue", + .server_cb_cls = (void *)"X-Header:testvalue", .client_cb = &MHDT_client_expect_header, .client_cb_cls = "X-Header:testvalue", .timeout_ms = 2500, @@ -266,7 +266,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 1", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", + .server_cb_cls = (void *)"a=b&c", .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b&c", .timeout_ms = 5000, @@ -277,7 +277,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 2", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", /* a => b, c => NULL */ + .server_cb_cls = (void *)"a=b&c", /* a => b, c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=b", .timeout_ms = 5000, @@ -288,7 +288,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 3", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=&c", /* a => "", c => NULL */ + .server_cb_cls = (void *)"a=&c", /* a => "", c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=", .timeout_ms = 5000, @@ -299,7 +299,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 4", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=", /* a => "" */ + .server_cb_cls = (void *)"a=", /* a => "" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=", .timeout_ms = 5000, @@ -310,7 +310,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 5", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b", /* a => "b" */ + .server_cb_cls = (void *)"a=b", /* a => "b" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b", .timeout_ms = 5000, @@ -321,7 +321,7 @@ main (int argc, char *argv[]) { .label = "chunked response get", .server_cb = &MHDT_server_reply_chunked_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -336,8 +336,8 @@ main (int argc, char *argv[]) unsigned int i; int ret = 0; - (void) argc; /* Unused. Silence compiler warning. */ - (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ + (void)argv; /* Unused. Silence compiler warning. */ for (i = 0; NULL != configs[i].server_setup; i++) { diff --git a/src/tests/client_server/test_tls2.c b/src/tests/client_server/test_tls2.c @@ -110,14 +110,14 @@ main (int argc, char *argv[]) .server_setup_cls = thread2select, .server_runner = &MHDT_server_run_minimal, }, -#if MHD_SUPPORT_GNUTLS +# if MHD_SUPPORT_GNUTLS { .label = "multi-threaded select, forcing GnuTLS", .server_setup = &MHDT_server_setup_gnutls, .server_setup_cls = thread2select, .server_runner = &MHDT_server_run_minimal, }, -#endif +# endif #endif #ifdef MHD_SUPPORT_POLL { @@ -132,14 +132,14 @@ main (int argc, char *argv[]) .server_setup_cls = thread2poll, .server_runner = &MHDT_server_run_minimal, }, -#ifdef MHD_SUPPORT_GNUTLS +# ifdef MHD_SUPPORT_GNUTLS { .label = "multi-threaded poll, forcing GnuTLS", .server_setup = &MHDT_server_setup_gnutls, .server_setup_cls = thread2poll, .server_runner = &MHDT_server_run_minimal, }, -#endif +# endif #endif #ifdef MHD_SUPPORT_EPOLL { @@ -154,14 +154,14 @@ main (int argc, char *argv[]) .server_setup_cls = thread2epoll, .server_runner = &MHDT_server_run_minimal, }, -#ifdef MHD_SUPPORT_GNUTLS +# ifdef MHD_SUPPORT_GNUTLS { .label = "multi-threaded epoll, forcing GnuTLS", .server_setup = &MHDT_server_setup_gnutls, .server_setup_cls = thread2epoll, .server_runner = &MHDT_server_run_minimal, }, -#endif +# endif #endif { .label = "auto-selected mode, single threaded", @@ -206,7 +206,7 @@ main (int argc, char *argv[]) { .label = "simple get", .server_cb = &MHDT_server_reply_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -217,7 +217,7 @@ main (int argc, char *argv[]) { .label = "GET with sendfile", .server_cb = &MHDT_server_reply_file, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -227,7 +227,7 @@ main (int argc, char *argv[]) { .label = "client PUT with content-length", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "simple-upload-value", + .server_cb_cls = (void *)"simple-upload-value", .client_cb = &MHDT_client_put_data, .client_cb_cls = "simple-upload-value", .timeout_ms = 2500, @@ -237,7 +237,7 @@ main (int argc, char *argv[]) { .label = "client PUT with 2 chunks", .server_cb = &MHDT_server_reply_check_upload, - .server_cb_cls = (void *) "chunky-upload-value", + .server_cb_cls = (void *)"chunky-upload-value", .client_cb = &MHDT_client_chunk_data, .client_cb_cls = "chunky-upload-value", .timeout_ms = 2500, @@ -248,7 +248,7 @@ main (int argc, char *argv[]) { .label = "client request with custom header", .server_cb = &MHDT_server_reply_check_header, - .server_cb_cls = (void *) "C-Header:testvalue", + .server_cb_cls = (void *)"C-Header:testvalue", .client_cb = &MHDT_client_set_header, .client_cb_cls = "C-Header:testvalue", .timeout_ms = 2500, @@ -258,7 +258,7 @@ main (int argc, char *argv[]) { .label = "server response with custom header", .server_cb = &MHDT_server_reply_with_header, - .server_cb_cls = (void *) "X-Header:testvalue", + .server_cb_cls = (void *)"X-Header:testvalue", .client_cb = &MHDT_client_expect_header, .client_cb_cls = "X-Header:testvalue", .timeout_ms = 2500, @@ -268,7 +268,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 1", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", + .server_cb_cls = (void *)"a=b&c", .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b&c", .timeout_ms = 5000, @@ -279,7 +279,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 2", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b&c", /* a => b, c => NULL */ + .server_cb_cls = (void *)"a=b&c", /* a => b, c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=b", .timeout_ms = 5000, @@ -290,7 +290,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 3", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=&c", /* a => "", c => NULL */ + .server_cb_cls = (void *)"a=&c", /* a => "", c => NULL */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?c&a=", .timeout_ms = 5000, @@ -301,7 +301,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 4", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=", /* a => "" */ + .server_cb_cls = (void *)"a=", /* a => "" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=", .timeout_ms = 5000, @@ -312,7 +312,7 @@ main (int argc, char *argv[]) { .label = "URL with query parameters 5", .server_cb = &MHDT_server_reply_check_query, - .server_cb_cls = (void *) "a=b", /* a => "b" */ + .server_cb_cls = (void *)"a=b", /* a => "b" */ .client_cb = &MHDT_client_get_with_query, .client_cb_cls = "?a=b", .timeout_ms = 5000, @@ -324,7 +324,7 @@ main (int argc, char *argv[]) { .label = "chunked response get", .server_cb = &MHDT_server_reply_chunked_text, - .server_cb_cls = (void *) "Hello world", + .server_cb_cls = (void *)"Hello world", .client_cb = &MHDT_client_get_root, .client_cb_cls = "Hello world", .timeout_ms = 2500, @@ -340,8 +340,8 @@ main (int argc, char *argv[]) unsigned int i; int ret = 0; - (void) argc; /* Unused. Silence compiler warning. */ - (void) argv; /* Unused. Silence compiler warning. */ + (void)argc; /* Unused. Silence compiler warning. */ + (void)argv; /* Unused. Silence compiler warning. */ for (i = 0; NULL != configs[i].server_setup; i++) { diff --git a/src/tests/mhdt_checks.h b/src/tests/mhdt_checks.h @@ -54,9 +54,9 @@ #endif #if defined(_MSC_VER) -#pragma warning(push) +# pragma warning(push) /* Disable C4505 "unreferenced local function has been removed" */ -#pragma warning(disable:4505) +# pragma warning(disable:4505) #endif /* _MSC_VER */ #ifndef HAVE_SNPRINTF @@ -72,22 +72,22 @@ #ifdef MHD_HAVE_MHD_FUNC_ # define MHDT_ERR_EXIT() \ - do { fprintf (stderr, "\n\n%s:%lu:%s(): Unexpected error exit!\n", \ - __FILE__, (unsigned long) __LINE__, MHD_FUNC_); \ - fflush (stderr); exit (99);} while (0) + do { fprintf (stderr, "\n\n%s:%lu:%s(): Unexpected error exit!\n", \ + __FILE__, (unsigned long) __LINE__, MHD_FUNC_); \ + fflush (stderr); exit (99);} while (0) # define MHDT_ERR_EXIT_D(desc) \ - do { fprintf (stderr, "\n\n%s:%lu:%s(): Unexpected error exit: %s\n", \ - __FILE__, (unsigned long) __LINE__, MHD_FUNC_, (desc)); \ - fflush (stderr); exit (99);} while (0) + do { fprintf (stderr, "\n\n%s:%lu:%s(): Unexpected error exit: %s\n", \ + __FILE__, (unsigned long) __LINE__, MHD_FUNC_, (desc)); \ + fflush (stderr); exit (99);} while (0) #else # define MHDT_ERR_EXIT() \ - do { fprintf (stderr, "\n\n%s:%lu: Unexpected error exit!\n", \ - __FILE__, (unsigned long) __LINE__); \ - fflush (stderr); exit (99);} while (0) + do { fprintf (stderr, "\n\n%s:%lu: Unexpected error exit!\n", \ + __FILE__, (unsigned long) __LINE__); \ + fflush (stderr); exit (99);} while (0) # define MHDT_ERR_EXIT_D(desc) \ - do { fprintf (stderr, "\n\n%s:%lu: Unexpected error exit: %s\n", \ - __FILE__, (unsigned long) __LINE__, (desc)); \ - fflush (stderr); exit (99);} while (0) + do { fprintf (stderr, "\n\n%s:%lu: Unexpected error exit: %s\n", \ + __FILE__, (unsigned long) __LINE__, (desc)); \ + fflush (stderr); exit (99);} while (0) #endif /** @@ -147,7 +147,7 @@ mhdt_mark_print_in_test_set (void) return; fprintf (stdout, "_____\n"); fflush (stdout); - MHDT_cur_test_printed_something = ! 0; + MHDT_cur_test_printed_something = !0; } @@ -198,7 +198,7 @@ MHDT_test_result (const char *filename, MHDT_checks_err_counter = 0u; /* Reset the counter for the next test */ - if (test_succeed && ! mhdt_print_test_succeed ()) + if (test_succeed && !mhdt_print_test_succeed ()) return test_succeed; fprintf (test_succeed ? stdout : stderr, @@ -285,9 +285,9 @@ MHDT_check_bool (int result, int exp_different; int check_succeed; - check_succeed = ((! ! result) == (! ! expected)); + check_succeed = ((!!result) == (!!expected)); - if (check_succeed && ! mhdt_print_check_succeed ()) + if (check_succeed && !mhdt_print_check_succeed ()) return check_succeed; mhdt_mark_print_in_test_set (); @@ -308,8 +308,8 @@ MHDT_check_bool (int result, (exp_different ? "\n\texpanded: '" : ""), (exp_different ? check_str_exp : ""), (exp_different ? "'" : ""), - ((! ! result) ? "NON-zero" : "ZERO"), - ((! ! expected) ? "NON-zero" : "ZERO")); + ((!!result) ? "NON-zero" : "ZERO"), + ((!!expected) ? "NON-zero" : "ZERO")); fflush (check_succeed ? stdout : stderr); MHDT_checks_err_counter += (check_succeed ? 0 : 1); @@ -359,9 +359,9 @@ MHDT_check_ptr (const void *ptr, int exp_different; int check_succeed; - check_succeed = ((NULL != ptr) == (! ! expected_non_null)); + check_succeed = ((NULL != ptr) == (!!expected_non_null)); - if (check_succeed && ! mhdt_print_check_succeed ()) + if (check_succeed && !mhdt_print_check_succeed ()) return check_succeed; mhdt_mark_print_in_test_set (); @@ -383,7 +383,7 @@ MHDT_check_ptr (const void *ptr, (exp_different ? check_str_exp : ""), (exp_different ? "'" : ""), ((NULL != ptr) ? "non-NULL" : "NULL"), - ((! ! expected_non_null) ? "non-NULL" : "NULL")); + ((!!expected_non_null) ? "non-NULL" : "NULL")); fflush (check_succeed ? stdout : stderr); MHDT_checks_err_counter += (check_succeed ? 0 : 1); @@ -393,22 +393,22 @@ MHDT_check_ptr (const void *ptr, #define MHDT_EXPECT_PTR_NULL(ptr) \ - MHDT_check_ptr ((ptr), 0, #ptr, \ - mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ - NULL) + MHDT_check_ptr ((ptr), 0, #ptr, \ + mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ + NULL) #define MHDT_EXPECT_PTR_NONNULL(ptr) \ - MHDT_check_ptr ((ptr), ! 0, #ptr, \ - mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ - NULL) + MHDT_check_ptr ((ptr), ! 0, #ptr, \ + mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ + NULL) #define MHDT_EXPECT_PTR_NULL_D(ptr, desc) \ - MHDT_check_ptr ((ptr), 0, #ptr, \ - mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ - desc) + MHDT_check_ptr ((ptr), 0, #ptr, \ + mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ + desc) #define MHDT_EXPECT_PTR_NONNULL_D(ptr, desc) \ - MHDT_check_ptr ((ptr), ! 0, #ptr, \ - mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ - desc) + MHDT_check_ptr ((ptr), ! 0, #ptr, \ + mhdt_STR_MACRO_EXP (ptr), __FILE__, __LINE__, MHD_FUNC_, \ + desc) #ifdef PRIuMAX typedef uintmax_t mhdt_uint_t; @@ -434,7 +434,7 @@ enum mhdt_CmpType MHDT_CMP_LE,/**< a <= b */ MHDT_CMP_NE,/**< a != b */ MHDT_CMP_GE,/**< a >= b */ - MHDT_CMP_GT,/**< a > b */ + MHDT_CMP_GT /**< a > b */ }; @@ -498,10 +498,10 @@ MHDT_check_ui_cmp (mhdt_uint_t val_a, break; } - if (check_succeed && ! mhdt_print_check_succeed ()) + if (check_succeed && !mhdt_print_check_succeed ()) return check_succeed; - both_str_has_suff = ! 0; + both_str_has_suff = !0; str_has_suff = 0; if (1) /* For local scope */ { @@ -518,20 +518,20 @@ MHDT_check_ui_cmp (mhdt_uint_t val_a, #endif "%" MHDT_UINT_PRI, MHDT_UINT_PRI_CAST (val)); - if ((0 > print_res) || - (buf_size <= (unsigned int) print_res)) + if ((0 > print_res) + || (buf_size <= (unsigned int)print_res)) MHDT_ERR_EXIT (); if (0 != strcmp (str, print_buf)) { const size_t str_len = strlen (str); - if (str_len - 1 != (unsigned int) print_res) - use_buf_print = ! 0; + if (str_len - 1 != (unsigned int)print_res) + use_buf_print = !0; else if ((('u' == str[str_len - 1u]) || ('U' == str[str_len - 1u])) && (0 == memcmp (str, print_buf, str_len - 1u))) - str_has_suff = ! 0; + str_has_suff = !0; else - use_buf_print = ! 0; + use_buf_print = !0; } else both_str_has_suff = 0; @@ -551,26 +551,26 @@ MHDT_check_ui_cmp (mhdt_uint_t val_a, #endif "%" MHDT_UINT_PRI, MHDT_UINT_PRI_CAST (val)); - if ((0 > print_res) || - (buf_size <= (unsigned int) print_res)) + if ((0 > print_res) + || (buf_size <= (unsigned int)print_res)) MHDT_ERR_EXIT (); if (0 != strcmp (str, print_buf)) { const size_t str_len = strlen (str); - if (str_len - 1 != (unsigned int) print_res) - use_buf_print = ! 0; + if (str_len - 1 != (unsigned int)print_res) + use_buf_print = !0; else if ((('u' == str[str_len - 1u]) || ('U' == str[str_len - 1u])) && (0 == memcmp (str, print_buf, str_len - 1u))) - str_has_suff = ! 0; + str_has_suff = !0; else - use_buf_print = ! 0; + use_buf_print = !0; } else both_str_has_suff = 0; } - if (! use_buf_print && str_has_suff && ! both_str_has_suff) - use_buf_print = ! 0; + if (!use_buf_print && str_has_suff && !both_str_has_suff) + use_buf_print = !0; mhdt_mark_print_in_test_set (); fprintf (check_succeed ? stdout : stderr, @@ -586,8 +586,8 @@ MHDT_check_ui_cmp (mhdt_uint_t val_a, (have_func_name ? "(): " : ""), (check_succeed ? "passed" : "failed"), val_a_str, cmp_str, val_b_str); - if ((0 != strcmp (val_a_str, val_a_str_exp)) || - (0 != strcmp (val_b_str, val_b_str_exp))) + if ((0 != strcmp (val_a_str, val_a_str_exp)) + || (0 != strcmp (val_b_str, val_b_str_exp))) fprintf (check_succeed ? stdout : stderr, "\texpanded: '%s %s %s'\n", val_a_str_exp, cmp_str, val_b_str_exp); @@ -604,74 +604,74 @@ MHDT_check_ui_cmp (mhdt_uint_t val_a, } -#define MHDT_EXPECT_UINT_EQ_VAL(uiv_l,uiv_r) \ +#define MHDT_EXPECT_UINT_EQ_VAL(uiv_l, uiv_r) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_EQ, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_UINT_LT_VAL(uiv_l,uiv_r) \ +#define MHDT_EXPECT_UINT_LT_VAL(uiv_l, uiv_r) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_LT, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_UINT_LE_VAL(uiv_l,uiv_r) \ +#define MHDT_EXPECT_UINT_LE_VAL(uiv_l, uiv_r) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_LE, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_UINT_NE_VAL(uiv_l,uiv_r) \ +#define MHDT_EXPECT_UINT_NE_VAL(uiv_l, uiv_r) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_NE, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_UINT_GE_VAL(uiv_l,uiv_r) \ +#define MHDT_EXPECT_UINT_GE_VAL(uiv_l, uiv_r) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_GE, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_UINT_GT_VAL(uiv_l,uiv_r) \ +#define MHDT_EXPECT_UINT_GT_VAL(uiv_l, uiv_r) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_GT, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_UINT_EQ_VAL_D(uiv_l,uiv_r,desc) \ +#define MHDT_EXPECT_UINT_EQ_VAL_D(uiv_l, uiv_r, desc) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_EQ, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_UINT_LT_VAL_D(uiv_l,uiv_r,desc) \ +#define MHDT_EXPECT_UINT_LT_VAL_D(uiv_l, uiv_r, desc) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_LT, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_UINT_LE_VAL_D(uiv_l,uiv_r,desc) \ +#define MHDT_EXPECT_UINT_LE_VAL_D(uiv_l, uiv_r, desc) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_LE, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_UINT_NE_VAL_D(uiv_l,uiv_r,desc) \ +#define MHDT_EXPECT_UINT_NE_VAL_D(uiv_l, uiv_r, desc) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_NE, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_UINT_GE_VAL_D(uiv_l,uiv_r,desc) \ +#define MHDT_EXPECT_UINT_GE_VAL_D(uiv_l, uiv_r, desc) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_GE, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ mhdt_STR_MACRO_EXP (uiv_r), \ __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_UINT_GT_VAL_D(uiv_l,uiv_r,desc) \ +#define MHDT_EXPECT_UINT_GT_VAL_D(uiv_l, uiv_r, desc) \ MHDT_check_ui_cmp ((uiv_l), MHDT_CMP_GT, (uiv_r), \ #uiv_l, #uiv_r, \ mhdt_STR_MACRO_EXP (uiv_l), \ @@ -752,7 +752,7 @@ MHDT_check_i_cmp (mhdt_int_t val_a, break; } - if (check_succeed && ! mhdt_print_check_succeed ()) + if (check_succeed && !mhdt_print_check_succeed ()) return check_succeed; if (1) /* For local scope */ @@ -770,12 +770,12 @@ MHDT_check_i_cmp (mhdt_int_t val_a, #endif "%" MHDT_INT_PRI, MHDT_INT_PRI_CAST (val)); - if ((0 > print_res) || - (buf_size <= (unsigned int) print_res)) + if ((0 > print_res) + || (buf_size <= (unsigned int)print_res)) MHDT_ERR_EXIT (); if (0 != strcmp (str, print_buf)) - use_buf_print = ! 0; + use_buf_print = !0; } if (1) /* For local scope */ { @@ -792,12 +792,12 @@ MHDT_check_i_cmp (mhdt_int_t val_a, #endif "%" MHDT_INT_PRI, MHDT_INT_PRI_CAST (val)); - if ((0 > print_res) || - (buf_size <= (unsigned int) print_res)) + if ((0 > print_res) + || (buf_size <= (unsigned int)print_res)) MHDT_ERR_EXIT (); if (0 != strcmp (str, print_buf)) - use_buf_print = ! 0; + use_buf_print = !0; } mhdt_mark_print_in_test_set (); @@ -814,8 +814,8 @@ MHDT_check_i_cmp (mhdt_int_t val_a, (have_func_name ? "(): " : ""), (check_succeed ? "passed" : "failed"), val_a_str, cmp_str, val_b_str); - if ((0 != strcmp (val_a_str, val_a_str_exp)) || - (0 != strcmp (val_b_str, val_b_str_exp))) + if ((0 != strcmp (val_a_str, val_a_str_exp)) + || (0 != strcmp (val_b_str, val_b_str_exp))) fprintf (check_succeed ? stdout : stderr, "\texpanded: '%s %s %s'\n", val_a_str_exp, cmp_str, val_b_str_exp); @@ -832,67 +832,67 @@ MHDT_check_i_cmp (mhdt_int_t val_a, } -#define MHDT_EXPECT_INT_EQ_VAL(iv_l,iv_r) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_EQ, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_INT_LT_VAL(iv_l,iv_r) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_LT, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_INT_LE_VAL(iv_l,iv_r) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_LE, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_INT_NE_VAL(iv_l,iv_r) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_NE, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_INT_GE_VAL(iv_l,iv_r) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_GE, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, NULL) -#define MHDT_EXPECT_INT_GT_VAL(iv_l,iv_r) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_GT, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, NULL) - -#define MHDT_EXPECT_INT_EQ_VAL_D(iv_l,iv_r,desc) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_EQ, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_INT_LT_VAL_D(iv_l,iv_r,desc) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_LT, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_INT_LE_VAL_D(iv_l,iv_r,desc) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_LE, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_INT_NE_VAL_D(iv_l,iv_r,desc) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_NE, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_INT_GE_VAL_D(iv_l,iv_r,desc) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_GE, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, desc) -#define MHDT_EXPECT_INT_GT_VAL_D(iv_l,iv_r,desc) \ - MHDT_check_i_cmp ((iv_l), MHDT_CMP_GT, (iv_r), \ - #iv_l, #iv_r, \ - mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ - __FILE__, __LINE__, MHD_FUNC_, desc) +#define MHDT_EXPECT_INT_EQ_VAL(iv_l, iv_r) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_EQ, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, NULL) +#define MHDT_EXPECT_INT_LT_VAL(iv_l, iv_r) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_LT, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, NULL) +#define MHDT_EXPECT_INT_LE_VAL(iv_l, iv_r) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_LE, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, NULL) +#define MHDT_EXPECT_INT_NE_VAL(iv_l, iv_r) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_NE, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, NULL) +#define MHDT_EXPECT_INT_GE_VAL(iv_l, iv_r) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_GE, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, NULL) +#define MHDT_EXPECT_INT_GT_VAL(iv_l, iv_r) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_GT, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, NULL) + +#define MHDT_EXPECT_INT_EQ_VAL_D(iv_l, iv_r, desc) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_EQ, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, desc) +#define MHDT_EXPECT_INT_LT_VAL_D(iv_l, iv_r, desc) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_LT, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, desc) +#define MHDT_EXPECT_INT_LE_VAL_D(iv_l, iv_r, desc) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_LE, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, desc) +#define MHDT_EXPECT_INT_NE_VAL_D(iv_l, iv_r, desc) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_NE, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, desc) +#define MHDT_EXPECT_INT_GE_VAL_D(iv_l, iv_r, desc) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_GE, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, desc) +#define MHDT_EXPECT_INT_GT_VAL_D(iv_l, iv_r, desc) \ + MHDT_check_i_cmp ((iv_l), MHDT_CMP_GT, (iv_r), \ + #iv_l, #iv_r, \ + mhdt_STR_MACRO_EXP (iv_l), mhdt_STR_MACRO_EXP (iv_r), \ + __FILE__, __LINE__, MHD_FUNC_, desc) /* Return non-zero if succeeded, zero if failed */ @@ -920,7 +920,7 @@ MHDT_check_str (const char *result, check_succeed = ((NULL != result) && (0 == strcmp (result, expected))); - if (check_succeed && ! mhdt_print_check_succeed ()) + if (check_succeed && !mhdt_print_check_succeed ()) return check_succeed; mhdt_mark_print_in_test_set (); @@ -987,7 +987,7 @@ MHDT_check_strn_str (size_t result_len, && (result_len == strlen (expected)) && (0 == memcmp (result, expected, result_len))); - if (check_succeed && ! mhdt_print_check_succeed ()) + if (check_succeed && !mhdt_print_check_succeed ()) return check_succeed; mhdt_mark_print_in_test_set (); @@ -1003,9 +1003,9 @@ MHDT_check_strn_str (size_t result_len, line, (have_func_name ? func_name : ""), (have_func_name ? "(): " : ""), - (int) (result ? result_len : strlen (MHDT_NULL_PRNT)), - (result ? result : MHDT_NULL_PRNT), (unsigned long) result_len, - expected, (unsigned long) strlen (expected)); + (int)(result ? result_len : strlen (MHDT_NULL_PRNT)), + (result ? result : MHDT_NULL_PRNT), (unsigned long)result_len, + expected, (unsigned long)strlen (expected)); fflush (check_succeed ? stdout : stderr); MHDT_checks_err_counter += (check_succeed ? 0 : 1); @@ -1048,7 +1048,7 @@ MHDT_check_strn (size_t result_len, if (check_succeed && (0u != expected_len)) check_succeed = (0 == memcmp (result, expected, result_len)); - if (check_succeed && ! mhdt_print_check_succeed ()) + if (check_succeed && !mhdt_print_check_succeed ()) return check_succeed; mhdt_mark_print_in_test_set (); @@ -1064,11 +1064,11 @@ MHDT_check_strn (size_t result_len, line, (have_func_name ? func_name : ""), (have_func_name ? "(): " : ""), - (int) (result ? result_len : strlen (MHDT_NULL_PRNT)), - (result ? result : MHDT_NULL_PRNT), (unsigned long) result_len, - (int) (expected ? expected_len : strlen (MHDT_NULL_PRNT)), + (int)(result ? result_len : strlen (MHDT_NULL_PRNT)), + (result ? result : MHDT_NULL_PRNT), (unsigned long)result_len, + (int)(expected ? expected_len : strlen (MHDT_NULL_PRNT)), (expected ? expected : MHDT_NULL_PRNT), - (unsigned long) expected_len); + (unsigned long)expected_len); fflush (check_succeed ? stdout : stderr); MHDT_checks_err_counter += (check_succeed ? 0 : 1); @@ -1083,11 +1083,9 @@ MHDT_check_strn (size_t result_len, desc) - - #if defined(_MSC_VER) /* Restore warnings */ -#pragma warning(pop) +# pragma warning(pop) #endif /* _MSC_VER */ #endif /* ! MHDT_CHECKS_H */ diff --git a/src/tests/mhdt_has_in_name.h b/src/tests/mhdt_has_in_name.h @@ -65,7 +65,7 @@ mhdt_has_in_name (const char *prog_name, const char *marker) const char *dir_symb; const char *basename; - if (! prog_name || ! marker || ! prog_name[0] || ! marker[0]) + if (!prog_name || !marker || !prog_name[0] || !marker[0]) return 0; basename = prog_name; diff --git a/src/tests/mhdt_has_param.h b/src/tests/mhdt_has_param.h @@ -60,13 +60,13 @@ static inline int mhdt_has_param (int argc, char *const argv[], const char *param) { int i; - if (! argv || ! param || ! param[0]) + if (!argv || !param || !param[0]) return 0; for (i = 1; i < argc; i++) { - if (argv[i] && (strcmp (argv[i], param) == 0) ) - return ! 0; + if (argv[i] && (strcmp (argv[i], param) == 0)) + return !0; } return 0; diff --git a/src/tests/raw/test_incompatible.c b/src/tests/raw/test_incompatible.c @@ -776,7 +776,7 @@ write_all (int fd, { fprintf (stderr, "Writing %u bytes to %d failed: %s\n", - (unsigned int) (buf_size - off), + (unsigned int)(buf_size - off), fd, strerror (errno)); exit (1); @@ -808,7 +808,7 @@ run_test () "127.0.0.1", &sa.sin_addr); if (0 != connect (s, - (struct sockaddr *) &sa, + (struct sockaddr *)&sa, sizeof (sa))) { fprintf (stderr, @@ -822,7 +822,7 @@ run_test () strlen (current->upload)); shutdown (s, SHUT_WR); - if (((ssize_t) sizeof (dummy)) != + if (((ssize_t)sizeof (dummy)) != read (s, &dummy, sizeof (dummy))) @@ -872,7 +872,7 @@ run (MHD_RequestCallback cb, MHD_DAEMON_SET_OPTIONS ( d, MHD_D_OPTION_WM_WORKER_THREADS (2), -#if ! LOG +#if !LOG MHD_D_OPTION_LOG_CALLBACK (NULL, NULL), #endif @@ -900,7 +900,7 @@ run (MHD_RequestCallback cb, #else fprintf (stderr, "Failed to start server: %u\n", - (unsigned int) sc); + (unsigned int)sc); #endif MHD_daemon_destroy (d); return 1; @@ -919,7 +919,7 @@ run (MHD_RequestCallback cb, { fprintf (stderr, "Failed to determine our port: %u\n", - (unsigned int) sc); + (unsigned int)sc); MHD_daemon_destroy (d); return 1; } diff --git a/src/tests/raw/test_oom.c b/src/tests/raw/test_oom.c @@ -168,9 +168,9 @@ upload_cb (void *upload_cls, { int *flag; - (void) upload_cls; - (void) content_data_size; - (void) content_data; + (void)upload_cls; + (void)content_data_size; + (void)content_data; flag = malloc (sizeof (int)); *flag = 1; @@ -214,10 +214,10 @@ server_req_cb (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - (void) cls; - (void) path; - (void) method; - (void) upload_size; + (void)cls; + (void)path; + (void)method; + (void)upload_size; return MHD_action_process_upload_full (request, upload_size, &upload_cb, @@ -238,7 +238,7 @@ write_all (int fd, const void *buf, size_t buf_size) { - const char *cbuf = (const char *) buf; + const char *cbuf = (const char *)buf; size_t off; off = 0; @@ -253,12 +253,12 @@ write_all (int fd, { fprintf (stderr, "Writing %u bytes to %d failed: %s\n", - (unsigned int) (buf_size - off), + (unsigned int)(buf_size - off), fd, strerror (errno)); exit (1); } - off += (size_t) ret; + off += (size_t)ret; } } @@ -298,7 +298,7 @@ run_test (unsigned int url_len, "127.0.0.1", &sa.sin_addr); if (0 != connect (s, - (struct sockaddr *) &sa, + (struct sockaddr *)&sa, sizeof (sa))) { fprintf (stderr, @@ -320,19 +320,19 @@ run_test (unsigned int url_len, "Key: %.*s\r\n" "Cookie: a=%.*s\r\n\r\n" "%.*s", - (int) url_len, + (int)url_len, filler, - (int) query_len, + (int)query_len, filler, body_len, - (int) header_len, + (int)header_len, filler, - (int) cookie_len, + (int)cookie_len, filler, - (int) body_len, + (int)body_len, filler); - if ( (-1 == iret) || - ( ((size_t) iret) > sizeof (upload)) ) + if ((-1 == iret) + || (((size_t)iret) > sizeof (upload))) { fprintf (stderr, "failed to build request buffer: %d\n", @@ -376,7 +376,7 @@ run_test (unsigned int url_len, } if (nice) out_of_memory = true; - if (! got_data) + if (!got_data) { out_of_memory = true; fprintf (stderr, @@ -414,14 +414,14 @@ test_url (void) { oom_hit = true; } - if ( (oom_hit) && (1 != ret) ) + if ((oom_hit) && (1 != ret)) { fprintf (stderr, "Strange: OOM stopped at %u after being hit earlier (url)?\n", i); } } - if (! oom_hit) + if (!oom_hit) { fprintf (stderr, "Failed to trigger OOM condition via URL\n"); @@ -452,14 +452,14 @@ test_query (void) { oom_hit = true; } - if ( (oom_hit) && (1 != ret) ) + if ((oom_hit) && (1 != ret)) { fprintf (stderr, "Strange: OOM stopped at %u after being hit earlier (query)?\n", i); } } - if (! oom_hit) + if (!oom_hit) { fprintf (stderr, "Failed to trigger OOM condition via query\n"); @@ -490,14 +490,14 @@ test_header (void) { oom_hit = true; } - if ( (oom_hit) && (1 != ret) ) + if ((oom_hit) && (1 != ret)) { fprintf (stderr, "Strange: OOM stopped at %u after being hit earlier (header)?\n", i); } } - if (! oom_hit) + if (!oom_hit) { fprintf (stderr, "Failed to trigger OOM condition via header\n"); @@ -528,14 +528,14 @@ test_cookie (void) { oom_hit = true; } - if ( (oom_hit) && (1 != ret) ) + if ((oom_hit) && (1 != ret)) { fprintf (stderr, "Strange: OOM stopped at %u after being hit earlier (cookie)?\n", i); } } - if (! oom_hit) + if (!oom_hit) { fprintf (stderr, "Failed to trigger OOM condition via cookie\n"); @@ -566,14 +566,14 @@ test_body (void) { oom_hit = true; } - if ( (oom_hit) && (1 != ret) ) + if ((oom_hit) && (1 != ret)) { fprintf (stderr, "Strange: OOM stopped at %u after being hit earlier (body)?\n", i); } } - if (! oom_hit) + if (!oom_hit) { fprintf (stderr, "Failed to trigger OOM condition via body\n"); @@ -604,14 +604,14 @@ test_mix (void) { oom_hit = true; } - if ( (oom_hit) && (1 != ret) ) + if ((oom_hit) && (1 != ret)) { fprintf (stderr, "Strange: OOM stopped at %u after being hit earlier (mix)?\n", i); } } - if (! oom_hit) + if (!oom_hit) { fprintf (stderr, "Failed to trigger OOM condition in mix-and-match\n"); @@ -646,10 +646,10 @@ no_log (void *cls, const char *fm, va_list ap) { - (void) cls; - (void) sc; - (void) fm; - (void) ap; + (void)cls; + (void)sc; + (void)fm; + (void)ap; /* intentionally empty */ } @@ -690,7 +690,7 @@ main (void) #else fprintf (stderr, "Failed to start server: %u\n", - (unsigned int) sc); + (unsigned int)sc); #endif MHD_daemon_destroy (d); return 1; @@ -709,7 +709,7 @@ main (void) { fprintf (stderr, "Failed to determine our port: %u\n", - (unsigned int) sc); + (unsigned int)sc); MHD_daemon_destroy (d); return 1; } diff --git a/src/tests/raw/test_raw.c b/src/tests/raw/test_raw.c @@ -595,19 +595,19 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_HEADER, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_HEADER, + key, + &have)) { fprintf (stderr, "Expected header `%s' missing\n", key); ok = false; } - else if ( (NULL == have.cstr) || - (0 != strcmp (have.cstr, - value)) ) + else if ((NULL == have.cstr) + || (0 != strcmp (have.cstr, + value))) { fprintf (stderr, "Wrong header value `%s' under key `%s', expected `%s'\n", @@ -625,19 +625,19 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_COOKIE, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_COOKIE, + key, + &have)) { fprintf (stderr, "Expected cookie `%s' missing\n", key); ok = false; } - else if ( (NULL == have.cstr) || - (0 != strcmp (have.cstr, - value)) ) + else if ((NULL == have.cstr) + || (0 != strcmp (have.cstr, + value))) { fprintf (stderr, "Wrong cookie value `%s' under key `%s', expected `%s'\n", @@ -655,19 +655,19 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_URI_QUERY_PARAM, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_URI_QUERY_PARAM, + key, + &have)) { fprintf (stderr, "Expected URI query parameter `%s' missing\n", key); ok = false; } - else if ( (NULL == have.cstr) || - (0 != strcmp (have.cstr, - value)) ) + else if ((NULL == have.cstr) + || (0 != strcmp (have.cstr, + value))) { fprintf (stderr, "Wrong URI query parameter value `%s' under key `%s', expected `%s'\n", @@ -685,19 +685,19 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_HEADER, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_HEADER, + key, + &have)) { fprintf (stderr, "Expected header `%s' missing\n", key); ok = false; } /* HTTP header can never be "NULL", only empty string */ - else if ( (NULL == have.cstr) || - (0 != strcmp (have.cstr, - "")) ) + else if ((NULL == have.cstr) + || (0 != strcmp (have.cstr, + ""))) { fprintf (stderr, "Unexpected non-empty header value `%s' under key `%s'\n", @@ -715,19 +715,19 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_COOKIE, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_COOKIE, + key, + &have)) { fprintf (stderr, "Expected cookie `%s' missing\n", key); ok = false; } - else if ( (NULL == have.cstr) || - (0 != strcmp (have.cstr, - "")) ) + else if ((NULL == have.cstr) + || (0 != strcmp (have.cstr, + ""))) { fprintf (stderr, "Unexpected non-empty cookie value `%s' under key `%s'\n", @@ -744,10 +744,10 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_COOKIE, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_COOKIE, + key, + &have)) { fprintf (stderr, "Expected cookie `%s' missing\n", @@ -772,19 +772,19 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_URI_QUERY_PARAM, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_URI_QUERY_PARAM, + key, + &have)) { fprintf (stderr, "Expected URI query parameter `%s' missing\n", key); ok = false; } - else if ( (NULL == have.cstr) || - (0 != strcmp (have.cstr, - "")) ) + else if ((NULL == have.cstr) + || (0 != strcmp (have.cstr, + ""))) { fprintf (stderr, "Unexpected non-empty URI query parameter value `%s' under key `%s'\n", @@ -801,10 +801,10 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_URI_QUERY_PARAM, - key, - &have)) + if (!MHD_request_get_value (request, + MHD_VK_URI_QUERY_PARAM, + key, + &have)) { fprintf (stderr, "Expected URI query parameter `%s' missing\n", @@ -827,18 +827,18 @@ check_headers (struct MHD_Request *MHD_RESTRICT request, { struct MHD_StringNullable have; - if (! MHD_request_get_value (request, - MHD_VK_URI_QUERY_PARAM, - "", - &have)) + if (!MHD_request_get_value (request, + MHD_VK_URI_QUERY_PARAM, + "", + &have)) { fprintf (stderr, "Expected URI query parameter without key missing\n"); ok = false; } - else if ( (NULL == have.cstr) || - (0 != strcmp (have.cstr, - value)) ) + else if ((NULL == have.cstr) + || (0 != strcmp (have.cstr, + value))) { fprintf (stderr, "Wrong URI query parameter value `%s' under missing key, expected `%s'\n", @@ -914,9 +914,9 @@ server_req_cb (void *cls, path->cstr); failed = true; } - if ( (NULL != current->expect_parser) && - (! check_headers (request, - current->expect_parser)) ) + if ((NULL != current->expect_parser) + && (!check_headers (request, + current->expect_parser))) failed = true; if (failed) return NULL; @@ -954,7 +954,7 @@ write_all (int fd, { fprintf (stderr, "Writing %u bytes to %d failed: %s\n", - (unsigned int) (buf_size - off), + (unsigned int)(buf_size - off), fd, strerror (errno)); exit (1); @@ -986,7 +986,7 @@ run_test () "127.0.0.1", &sa.sin_addr); if (0 != connect (s, - (struct sockaddr *) &sa, + (struct sockaddr *)&sa, sizeof (sa))) { fprintf (stderr, @@ -1068,7 +1068,7 @@ main (void) #else fprintf (stderr, "Failed to start server: %u\n", - (unsigned int) sc); + (unsigned int)sc); #endif MHD_daemon_destroy (d); return 1; @@ -1087,7 +1087,7 @@ main (void) { fprintf (stderr, "Failed to determine our port: %u\n", - (unsigned int) sc); + (unsigned int)sc); MHD_daemon_destroy (d); return 1; } diff --git a/src/tests/unit/unit_h2_huffman_codec.c b/src/tests/unit/unit_h2_huffman_codec.c @@ -60,7 +60,7 @@ #ifndef MHD_ENABLE_SLOW_TESTS static int enable_deep_tests = 0; #else -static int enable_deep_tests = ! 0; +static int enable_deep_tests = !0; #endif struct mhdt_HEcondedData @@ -614,9 +614,9 @@ print_hex (FILE *stream, size_t hex_size, const uint8_t *hex) size_t i; if (0 == hex_size) return; - fprintf (stream, "%02X", (unsigned int) hex[0]); + fprintf (stream, "%02X", (unsigned int)hex[0]); for (i = 1; i < hex_size; ++i) - fprintf (stream, " %02X", (unsigned int) hex[i]); + fprintf (stream, " %02X", (unsigned int)hex[i]); } @@ -637,9 +637,9 @@ print_mixed (size_t str_len, const char *str) for (i = 0, out_idx = 0; i < str_len; ++i) { const char c = str[i]; - if (0x20 <= c && 0x7E >= c) + if ((0x20 <= c) && (0x7E >= c)) { - if (! quote_open) + if (!quote_open) { if (0 != i) { @@ -651,7 +651,7 @@ print_mixed (size_t str_len, const char *str) break; buf[out_idx++] = '"'; - quote_open = ! 0; + quote_open = !0; } else if (buf_size <= out_idx + 1) break; @@ -660,8 +660,8 @@ print_mixed (size_t str_len, const char *str) } else { - const uint8_t digit1 = ((uint8_t) c) & 0xFu; - const uint8_t digit2 = ((uint8_t) c) >> 4; + const uint8_t digit1 = ((uint8_t)c) & 0xFu; + const uint8_t digit2 = ((uint8_t)c) >> 4; if (quote_open) { if (buf_size <= out_idx + 8) @@ -676,9 +676,9 @@ print_mixed (size_t str_len, const char *str) buf[out_idx++] = '\\'; buf[out_idx++] = 'x'; buf[out_idx++] = - (char) ((digit1 < 10) ? ('0' + digit1) : ('A' + digit1 - 10)); + (char)((digit1 < 10) ? ('0' + digit1) : ('A' + digit1 - 10)); buf[out_idx++] = - (char) ((digit2 < 10) ? ('0' + digit2) : ('A' + digit2 - 10)); + (char)((digit2 < 10) ? ('0' + digit2) : ('A' + digit2 - 10)); buf[out_idx++] = '"'; } } @@ -715,7 +715,7 @@ basic_data_check (void) fflush (stdout); fprintf (stderr, "ERROR: wrong zero length of the string data for " "the entry number %lu\n", - (unsigned long) i); + (unsigned long)i); return 99; } #endif /* Disabled check */ @@ -724,7 +724,7 @@ basic_data_check (void) fflush (stdout); fprintf (stderr, "ERROR: wrong zero NULL pointer for the string data for " "the entry number %lu\n", - (unsigned long) i); + (unsigned long)i); return 99; } else if (h_data[i].str.len < strlen (h_data[i].str.cstr)) @@ -732,7 +732,7 @@ basic_data_check (void) fflush (stdout); fprintf (stderr, "ERROR: unterminated string data for " "the entry number %lu\n", - (unsigned long) i); + (unsigned long)i); return 99; } if (0 != h_data[i].str.cstr[h_data[i].str.len]) @@ -740,7 +740,7 @@ basic_data_check (void) fflush (stdout); fprintf (stderr, "ERROR: unterminated string for the string data for " "the entry number %lu\n", - (unsigned long) i); + (unsigned long)i); return 99; } if ((0 == h_data[i].enc.size) @@ -752,8 +752,8 @@ basic_data_check (void) h_data[i].str.cstr); return 99; } - if (((sizeof(h_data[i].enc.data) != h_data[i].enc.size)) && - (0 != h_data[i].enc.data[h_data[i].enc.size])) + if (((sizeof(h_data[i].enc.data) != h_data[i].enc.size)) + && (0 != h_data[i].enc.data[h_data[i].enc.size])) { fflush (stdout); fprintf (stderr, "ERROR: wrong length of encoded data for " @@ -787,8 +787,8 @@ perform_single_enc_check (size_t str_len, "the check.\n" "The specified size: %lu\n" "The maximum possible size: %lu\n", - (unsigned long) use_buff_size, - (unsigned long) sizeof(buff)); + (unsigned long)use_buff_size, + (unsigned long)sizeof(buff)); return 99; } memset (buff, 0, sizeof(buff)); @@ -806,10 +806,10 @@ perform_single_enc_check (size_t str_len, "returned value %lu, while expected ZERO\n" "If the buffer would have enough space then " "the encoded data must be:", - (unsigned long) str_len, + (unsigned long)str_len, print_mixed (str_len, str), - (unsigned long) use_buff_size, - (unsigned long) res); + (unsigned long)use_buff_size, + (unsigned long)res); print_hex (stderr, valid_enc_size, valid_enc); fprintf (stderr, "\nResulting encoded data: "); print_hex (stderr, res, buff); @@ -822,11 +822,11 @@ perform_single_enc_check (size_t str_len, fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_encode(%lu, %s, %lu, buffer) " "returned value %lu, while expected %lu\n", - (unsigned long) str_len, + (unsigned long)str_len, print_mixed (str_len, str), - (unsigned long) valid_enc_size, - (unsigned long) res, - (unsigned long) valid_enc_size); + (unsigned long)valid_enc_size, + (unsigned long)res, + (unsigned long)valid_enc_size); return 1; } if (0 != memcmp (valid_enc, buff, res)) @@ -835,10 +835,10 @@ perform_single_enc_check (size_t str_len, fprintf (stderr, "FAILED: mhd_h2_huffman_encode(%lu, %s, %lu, buffer) " "returned expected value %lu, " "but the data is encoded incorrectly in the output buffer.\n", - (unsigned long) str_len, + (unsigned long)str_len, print_mixed (str_len, str), - (unsigned long) valid_enc_size, - (unsigned long) res); + (unsigned long)valid_enc_size, + (unsigned long)res); fprintf (stderr, "Expected encoded data: "); print_hex (stderr, valid_enc_size, valid_enc); fprintf (stderr, "\nResulting encoded data: "); @@ -1036,8 +1036,8 @@ perform_single_dec_valid_check (size_t enc_size, "the check.\n" "The specified size: %lu\n" "The maximum possible size: %lu\n", - (unsigned long) use_buff_size, - (unsigned long) sizeof(buff)); + (unsigned long)use_buff_size, + (unsigned long)sizeof(buff)); return 99; } memset (buff, 0, sizeof(buff)); @@ -1054,15 +1054,15 @@ perform_single_dec_valid_check (size_t enc_size, fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, %s%s, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) use_buff_size, + (unsigned long)enc_size, + (unsigned long)use_buff_size, (0 == ret_size) ? "buffer" : "->", (0 == ret_size) ? "" : print_mixed (ret_size, buff), decode_result_to_string (res), - (unsigned long) ret_size); + (unsigned long)ret_size); if (0 != ret_size) fprintf (stderr, "The function returned value %lu, while expected ZERO\n", - (unsigned long) ret_size); + (unsigned long)ret_size); else fprintf (stderr, "The function returned ZERO as expected, but the status " "must be 'NO_SPACE'\n"); @@ -1075,26 +1075,26 @@ perform_single_dec_valid_check (size_t enc_size, return 3; } - if ((valid_str_len != ret_size) || - ((MHD_H2_HUFF_DEC_RES_OK != res))) + if ((valid_str_len != ret_size) + || ((MHD_H2_HUFF_DEC_RES_OK != res))) { fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, %s%s, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) use_buff_size, + (unsigned long)enc_size, + (unsigned long)use_buff_size, (0 == ret_size) ? "buffer" : "->", (0 == ret_size) ? "" : print_mixed (ret_size, buff), decode_result_to_string (res), - (unsigned long) ret_size); + (unsigned long)ret_size); if (valid_str_len != ret_size) fprintf (stderr, "The function returned value %lu, while expected %lu\n", - (unsigned long) ret_size, (unsigned long) valid_str_len); + (unsigned long)ret_size, (unsigned long)valid_str_len); else fprintf (stderr, "The function returned expected value %lu, " "but the status must be 'OK'\n", - (unsigned long) ret_size); + (unsigned long)ret_size); fprintf (stderr, "The encoded data is: "); print_hex (stderr, enc_size, enc); @@ -1108,14 +1108,14 @@ perform_single_dec_valid_check (size_t enc_size, fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, buffer, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) use_buff_size, + (unsigned long)enc_size, + (unsigned long)use_buff_size, decode_result_to_string (res), - (unsigned long) ret_size); - fprintf (stderr,"The function returned expected value %lu and set " + (unsigned long)ret_size); + fprintf (stderr, "The function returned expected value %lu and set " "correct 'OK' status, but the data is decoded incorrectly " "in the output buffer.\n", - (unsigned long) ret_size); + (unsigned long)ret_size); fprintf (stderr, "The decoded string: %s\n", print_mixed (ret_size, buff)); fprintf (stderr, "The expected string: %s\n", @@ -1264,8 +1264,8 @@ perform_single_dec_unknow_seq_check (size_t enc_size, "the check.\n" "The specified size: %lu\n" "The maximum possible size: %lu\n", - (unsigned long) enc_size, - (unsigned long) buff_size / 4); + (unsigned long)enc_size, + (unsigned long)buff_size / 4); return 99; } if (0 == enc_size) @@ -1282,34 +1282,34 @@ perform_single_dec_unknow_seq_check (size_t enc_size, buff, &res); - if (0 == ret_size && MHD_H2_HUFF_DEC_RES_OK == res) + if ((0 == ret_size) && (MHD_H2_HUFF_DEC_RES_OK == res)) { fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, %s%s, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) buff_size, + (unsigned long)enc_size, + (unsigned long)buff_size, (0 == ret_size) ? "buffer" : "->", (0 == ret_size) ? "" : print_mixed (ret_size, buff), decode_result_to_string (res), - (unsigned long) ret_size); + (unsigned long)ret_size); fprintf (stderr, "The function returned ZERO, but the status was not " "set to 'OK' (actual: %s), while the size of the input data" " is not ZERO.\n", decode_result_to_string (res)); return 5; } - if (0 != ret_size && MHD_H2_HUFF_DEC_RES_OK != res) + if ((0 != ret_size) && (MHD_H2_HUFF_DEC_RES_OK != res)) { fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, %s%s, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) buff_size, + (unsigned long)enc_size, + (unsigned long)buff_size, (0 == ret_size) ? "buffer" : "->", (0 == ret_size) ? "" : print_mixed (ret_size, buff), decode_result_to_string (res), - (unsigned long) ret_size); + (unsigned long)ret_size); fprintf (stderr, "The function returned non-ZERO, but the status was " "set to 'OK'.\n"); return 5; @@ -1319,12 +1319,12 @@ perform_single_dec_unknow_seq_check (size_t enc_size, fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, %s%s, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) buff_size, + (unsigned long)enc_size, + (unsigned long)buff_size, (0 == ret_size) ? "buffer" : "->", (0 == ret_size) ? "" : print_mixed (ret_size, buff), decode_result_to_string (res), - (unsigned long) ret_size); + (unsigned long)ret_size); fprintf (stderr, "The function set the status set to 'NO_SPACE', but " "the buffer should be enough to hold the result.\n"); return 6; @@ -1343,53 +1343,53 @@ perform_single_dec_unknow_seq_check (size_t enc_size, fflush (stdout); fprintf (stderr, "ERROR: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, %s%s, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) buff_size, + (unsigned long)enc_size, + (unsigned long)buff_size, (0 == ret_size) ? "buffer" : "->", (0 == ret_size) ? "" : print_mixed (ret_size, buff), decode_result_to_string (res), - (unsigned long) check_enc_size); + (unsigned long)check_enc_size); fprintf (stderr, "However, when checking the decoded result by " "encoding it back to H2 Huffman encoding the function " "mhd_h2_huffman_encode(%lu, %s, %lu, buffer) returned " "ZERO, which should not happen as the output " "buffer is large enough.\n", - (unsigned long) ret_size, + (unsigned long)ret_size, print_mixed (ret_size, buff), - (unsigned long) sizeof(check_enc_buf)); + (unsigned long)sizeof(check_enc_buf)); return 99; } - if ((enc_size != check_enc_size) || - (0 != memcmp (enc, check_enc_buf, check_enc_size))) + if ((enc_size != check_enc_size) + || (0 != memcmp (enc, check_enc_buf, check_enc_size))) { fflush (stdout); fprintf (stderr, "FAILED: mhd_h2_huffman_decode(%lu, encoded_data, " "%lu, %s%s, ->%s) returned %lu\n", - (unsigned long) enc_size, - (unsigned long) buff_size, + (unsigned long)enc_size, + (unsigned long)buff_size, (0 == ret_size) ? "buffer" : "->", (0 == ret_size) ? "" : print_mixed (ret_size, buff), decode_result_to_string (res), - (unsigned long) ret_size); + (unsigned long)ret_size); if (enc_size != check_enc_size) fprintf (stderr, "However, when checking the decoded result by " "encoding it back to H2 Huffman encoding the function " "mhd_h2_huffman_encode(%lu, %s, %lu, buffer) returned " "%lu, which does not match the original data size.\n", - (unsigned long) ret_size, + (unsigned long)ret_size, print_mixed (ret_size, buff), - (unsigned long) sizeof(check_enc_buf), - (unsigned long) check_enc_size); + (unsigned long)sizeof(check_enc_buf), + (unsigned long)check_enc_size); else fprintf (stderr, "However, when checking the decoded result by " "encoding it back to H2 Huffman encoding the function " "mhd_h2_huffman_encode(%lu, %s, %lu, buffer) returned " "%lu (as expected), but the encoded data does not match " "original encoded data.\n", - (unsigned long) ret_size, + (unsigned long)ret_size, print_mixed (ret_size, buff), - (unsigned long) sizeof(check_enc_buf), - (unsigned long) ret_size); + (unsigned long)sizeof(check_enc_buf), + (unsigned long)ret_size); fprintf (stderr, "The decoded string: %s\n", print_mixed (ret_size, buff)); @@ -1423,7 +1423,7 @@ check_h2_h_decode_all_one_byte_values (void) { uint8_t test_data[1]; int res; - test_data[0] = (uint8_t) i; + test_data[0] = (uint8_t)i; res = perform_single_dec_unknow_seq_check (sizeof(test_data), test_data, @@ -1438,8 +1438,8 @@ check_h2_h_decode_all_one_byte_values (void) fflush (stdout); fprintf (stderr, "The check found %lu valid code values, while" "the expected number of valid code values is %lu.\n", - (unsigned long) valid_codes_counter, - (unsigned long) known_valid_codes); + (unsigned long)valid_codes_counter, + (unsigned long)known_valid_codes); return 9; } @@ -1461,8 +1461,8 @@ check_h2_h_decode_all_two_bytes_values (void) { uint8_t test_data[2]; int res; - test_data[0] = (uint8_t) i & 0xFFu; - test_data[1] = (uint8_t) ((i & 0xFF00u) >> 8u); + test_data[0] = (uint8_t)i & 0xFFu; + test_data[1] = (uint8_t)((i & 0xFF00u) >> 8u); res = perform_single_dec_unknow_seq_check (sizeof(test_data), test_data, @@ -1477,8 +1477,8 @@ check_h2_h_decode_all_two_bytes_values (void) fflush (stdout); fprintf (stderr, "The check found %lu valid code values, while " "the expected number of valid code values is %lu.\n", - (unsigned long) valid_codes_counter, - (unsigned long) known_valid_codes); + (unsigned long)valid_codes_counter, + (unsigned long)known_valid_codes); return 9; } @@ -1503,9 +1503,9 @@ check_h2_h_decode_all_three_bytes_values (void) { uint8_t test_data[3]; int res; - test_data[0] = (uint8_t) i & 0xFFu; - test_data[1] = (uint8_t) ((i & 0xFF00u) >> 8u); - test_data[2] = (uint8_t) ((i & 0xFF0000u) >> 16u); + test_data[0] = (uint8_t)i & 0xFFu; + test_data[1] = (uint8_t)((i & 0xFF00u) >> 8u); + test_data[2] = (uint8_t)((i & 0xFF0000u) >> 16u); res = perform_single_dec_unknow_seq_check (sizeof(test_data), test_data, @@ -1517,7 +1517,7 @@ check_h2_h_decode_all_three_bytes_values (void) /* Imperfect calculations, but enough for tracking the progress */ if (0u == (i % one_pct_step)) { - printf ("\b\b\b\b%02u%% ", (unsigned int) (i / one_pct_step)); + printf ("\b\b\b\b%02u%% ", (unsigned int)(i / one_pct_step)); fflush (stdout); } } while (0xFFFFFFu > i++); @@ -1528,8 +1528,8 @@ check_h2_h_decode_all_three_bytes_values (void) fflush (stdout); fprintf (stderr, "The check found %lu valid code values, while " "the expected number of valid code values is %lu.\n", - (unsigned long) valid_codes_counter, - (unsigned long) known_valid_codes); + (unsigned long)valid_codes_counter, + (unsigned long)known_valid_codes); return 9; } @@ -1554,10 +1554,10 @@ check_h2_h_decode_all_four_bytes_values (void) { uint8_t test_data[4]; int res; - test_data[0] = (uint8_t) i & 0xFFu; - test_data[1] = (uint8_t) ((i & 0xFF00u) >> 8u); - test_data[2] = (uint8_t) ((i & 0xFF0000u) >> 16u); - test_data[3] = (uint8_t) ((i & 0xFF000000u) >> 24u); + test_data[0] = (uint8_t)i & 0xFFu; + test_data[1] = (uint8_t)((i & 0xFF00u) >> 8u); + test_data[2] = (uint8_t)((i & 0xFF0000u) >> 16u); + test_data[3] = (uint8_t)((i & 0xFF000000u) >> 24u); res = perform_single_dec_unknow_seq_check (sizeof(test_data), test_data, @@ -1569,7 +1569,7 @@ check_h2_h_decode_all_four_bytes_values (void) /* Imperfect calculations, but enough for tracking the progress */ if (0u == (i % one_pct_step)) { - printf ("\b\b\b\b%02u%% ", (unsigned int) (i / one_pct_step)); + printf ("\b\b\b\b%02u%% ", (unsigned int)(i / one_pct_step)); fflush (stdout); } } while (0xFFFFFFFFu > i++); @@ -1580,8 +1580,8 @@ check_h2_h_decode_all_four_bytes_values (void) fflush (stdout); fprintf (stderr, "The check found %lu valid code values, while " "the expected number of valid code values is %lu.\n", - (unsigned long) valid_codes_counter, - (unsigned long) known_valid_codes); + (unsigned long)valid_codes_counter, + (unsigned long)known_valid_codes); return 9; } @@ -1675,7 +1675,7 @@ main (int argc, if (argc < 1) return 99; - if (! enable_deep_tests) + if (!enable_deep_tests) enable_deep_tests = mhdt_has_param (argc, argv, "--deep"); if (0 != basic_data_check ()) diff --git a/src/tests/unit/unit_hpack_tables.c b/src/tests/unit/unit_hpack_tables.c @@ -57,7 +57,7 @@ #ifndef MHD_ENABLE_SLOW_TESTS static int mhdtl_enable_deep_tests = 0; #else -static int mhdtl_enable_deep_tests = ! 0; +static int mhdtl_enable_deep_tests = !0; #endif #define MHDTL_DYN_ENTRY_MIN_SIZE mhd_HPACK_ENTRY_OVERHEAD @@ -66,7 +66,7 @@ static int mhdtl_enable_deep_tests = ! 0; * Local test helpers */ -#define MHDTL_HPACK_ENTRY_SIZE(name_len,val_len) \ +#define MHDTL_HPACK_ENTRY_SIZE(name_len, val_len) \ (name_len + val_len + mhd_HPACK_ENTRY_OVERHEAD) @@ -85,12 +85,12 @@ mhdtl_mix16 (uint_fast16_t a, uint_fast16_t b) { /* Mix with Golden Ratio's fractional part */ uint_least16_t res = - (uint_least16_t) (((a & 0xFFFFu) * 0x9E37u) - ^ mhdtl_rotl16 ((uint_least16_t) b, 5)); + (uint_least16_t)(((a & 0xFFFFu) * 0x9E37u) + ^ mhdtl_rotl16 ((uint_least16_t)b, 5)); /* Re-mix bits better */ - res ^= (uint_least16_t) (res >> 7); - res = (uint_least16_t) ((res * 0x9E37u) & 0xFFFFu); - res ^= (uint_least16_t) (res >> 9); + res ^= (uint_least16_t)(res >> 7); + res = (uint_least16_t)((res * 0x9E37u) & 0xFFFFu); + res ^= (uint_least16_t)(res >> 9); return res; } @@ -116,10 +116,10 @@ mhdtl_dyn_get_free (const struct mhd_HpackDTblContext *dyn) } -#define MHDTL_DTBL_FIND_ENTRY_STR(dyn,name,val) \ +#define MHDTL_DTBL_FIND_ENTRY_STR(dyn, name, val) \ mhd_dtbl_find_entry (dyn, strlen (name), name, strlen (val), val) -#define MHDTL_DTBL_FIND_NAME_STR(dyn,name) \ +#define MHDTL_DTBL_FIND_NAME_STR(dyn, name) \ mhd_dtbl_find_name (dyn, strlen (name), name) @@ -127,39 +127,39 @@ mhdtl_dyn_get_free (const struct mhd_HpackDTblContext *dyn) static int mhdtl_dyn_check_get_valid_invalid (const struct mhd_HpackDTblContext *dyn) { - const dtbl_idx_ft num_entries = (dtbl_idx_t) mhd_dtbl_get_num_entries (dyn); + const dtbl_idx_ft num_entries = (dtbl_idx_t)mhd_dtbl_get_num_entries (dyn); struct mhd_BufferConst check_name; struct mhd_BufferConst check_value; - if (! MHDT_EXPECT_FALSE_D (mhd_dtbl_get_entry (dyn, \ - mhd_HPACK_STBL_LAST_IDX + 1u \ - + num_entries, \ - &check_name, \ - &check_value), \ - "getting entry with the index outside valid " - "range should fail")) + if (!MHDT_EXPECT_FALSE_D (mhd_dtbl_get_entry (dyn, \ + mhd_HPACK_STBL_LAST_IDX + 1u \ + + num_entries, \ + &check_name, \ + &check_value), \ + "getting entry with the index outside valid " + "range should fail")) return 0; if (0u == num_entries) - return ! 0; - - if (! MHDT_EXPECT_TRUE_D (mhd_dtbl_get_entry (dyn, \ - mhd_HPACK_STBL_LAST_IDX + 1u, \ - &check_name, \ - &check_value), \ - "non-empty table should return successfully " \ - "the first valid entry")) + return !0; + + if (!MHDT_EXPECT_TRUE_D (mhd_dtbl_get_entry (dyn, \ + mhd_HPACK_STBL_LAST_IDX + 1u, \ + &check_name, \ + &check_value), \ + "non-empty table should return successfully " \ + "the first valid entry")) return 0; - if (! MHDT_EXPECT_TRUE_D (mhd_dtbl_get_entry (dyn, \ - mhd_HPACK_STBL_LAST_IDX \ - + num_entries, \ - &check_name, \ - &check_value), \ - "non-empty table should return successfully " \ - "the last valid entry")) + if (!MHDT_EXPECT_TRUE_D (mhd_dtbl_get_entry (dyn, \ + mhd_HPACK_STBL_LAST_IDX \ + + num_entries, \ + &check_name, \ + &check_value), \ + "non-empty table should return successfully " \ + "the last valid entry")) return 0; - return ! 0; + return !0; } @@ -175,7 +175,7 @@ mhdtl_dyn_check_entry_n_at_idx (struct mhd_HpackDTblContext *dyn, struct mhd_BufferConst check_name; struct mhd_BufferConst check_value; - dtbl_idx_t idx_idx = (dtbl_idx_t) idx; + dtbl_idx_t idx_idx = (dtbl_idx_t)idx; if (0 == idx) MHDT_ERR_EXIT (); if (idx_idx != idx) @@ -219,7 +219,7 @@ mhdtl_dyn_check_entry_n_at_idx (struct mhd_HpackDTblContext *dyn, "search by known entry name " \ "should succeed"); - return ! 0; + return !0; } @@ -240,7 +240,7 @@ mhdtl_dyn_check_entry_at_idx (struct mhd_HpackDTblContext *dyn, /* Return non-zero if succeeded, zero if failed */ -static MHD_FN_PAR_IN_SIZE_ (3,2) MHD_FN_PAR_IN_SIZE_ (5,4) int +static MHD_FN_PAR_IN_SIZE_ (3, 2) MHD_FN_PAR_IN_SIZE_ (5, 4) int mhdtl_dyn_add_hdr_n_with_check (struct mhd_HpackDTblContext *dyn, size_t hdr_name_len, const char *hdr_name, @@ -265,9 +265,9 @@ mhdtl_dyn_add_hdr_n_with_check (struct mhd_HpackDTblContext *dyn, struct mhd_BufferConst check_name = {0u, NULL}; struct mhd_BufferConst check_value = {0u, NULL}; - if ((mhd_DTBL_MAX_SIZE < hdr_name_len) || - (mhd_DTBL_MAX_SIZE < hdr_value_len) || - (mhd_DTBL_MAX_SIZE < hdr_size)) + if ((mhd_DTBL_MAX_SIZE < hdr_name_len) + || (mhd_DTBL_MAX_SIZE < hdr_value_len) + || (mhd_DTBL_MAX_SIZE < hdr_size)) MHDT_ERR_EXIT (); MHDT_EXPECT_UINT_GE_VAL (table_max_size, table_free_before); @@ -298,7 +298,7 @@ mhdtl_dyn_add_hdr_n_with_check (struct mhd_HpackDTblContext *dyn, check_value.size); prev_val_buf[check_value.size] = 0; /* Zero-terminate for convenience */ prev_val_len = check_value.size; - have_prev_entry = ! 0; + have_prev_entry = !0; } } } @@ -325,7 +325,7 @@ mhdtl_dyn_add_hdr_n_with_check (struct mhd_HpackDTblContext *dyn, check_value.size); last_val_buf[check_value.size] = 0; /* Zero-terminate for convenience */ last_val_len = check_value.size; - have_last_entry = ! 0; + have_last_entry = !0; } } } @@ -368,7 +368,7 @@ mhdtl_dyn_add_hdr_n_with_check (struct mhd_HpackDTblContext *dyn, MHDT_EXPECT_UINT_EQ_VAL (mhdtl_dyn_get_free (dyn), table_max_size); MHDT_EXPECT_UINT_EQ_VAL (mhd_dtbl_get_table_max_size (dyn), \ table_max_size); - return ! 0; + return !0; } else if (hdr_size + MHDTL_DYN_ENTRY_MIN_SIZE > table_max_size) MHDT_EXPECT_UINT_EQ_VAL_D (mhd_dtbl_get_num_entries (dyn), 1u, \ @@ -387,44 +387,44 @@ mhdtl_dyn_add_hdr_n_with_check (struct mhd_HpackDTblContext *dyn, MHDT_EXPECT_UINT_GE_VAL (mhdtl_dyn_get_size_used (dyn), \ hdr_size + MHDTL_DYN_ENTRY_MIN_SIZE); - if (! MHDT_EXPECT_TRUE_D (mhd_dtbl_get_entry (dyn, \ - mhd_HPACK_STBL_LAST_IDX + 1u, \ - &check_name, \ - &check_value), \ - "new entry should be available as the newest " \ - "entry in the dynamic table")) + if (!MHDT_EXPECT_TRUE_D (mhd_dtbl_get_entry (dyn, \ + mhd_HPACK_STBL_LAST_IDX + 1u, \ + &check_name, \ + &check_value), \ + "new entry should be available as the newest " \ + "entry in the dynamic table")) return 0; - if (! MHDT_EXPECT_STRN_EQ_D (check_name.size, \ - check_name.data, \ - hdr_name_len, \ - hdr_name, \ - "The name of the newest entry should " \ - "match the last added entry's name")) + if (!MHDT_EXPECT_STRN_EQ_D (check_name.size, \ + check_name.data, \ + hdr_name_len, \ + hdr_name, \ + "The name of the newest entry should " \ + "match the last added entry's name")) return 0; - if (! MHDT_EXPECT_STRN_EQ_D (check_value.size, \ - check_value.data, \ - hdr_value_len, \ - hdr_value, \ - "The value of the newest entry should " \ - "match the last added entry's value")) + if (!MHDT_EXPECT_STRN_EQ_D (check_value.size, \ + check_value.data, \ + hdr_value_len, \ + hdr_value, \ + "The value of the newest entry should " \ + "match the last added entry's value")) return 0; - if (! MHDT_EXPECT_UINT_GT_VAL_D (mhd_dtbl_find_entry (dyn, \ - hdr_name_len, \ - hdr_name, \ - hdr_value_len, \ - hdr_value), \ - mhd_HPACK_STBL_LAST_IDX, \ - "search for the newly added entry should " \ - "be successful")) - return 0; - if (! MHDT_EXPECT_UINT_GT_VAL_D (mhd_dtbl_find_name (dyn, \ + if (!MHDT_EXPECT_UINT_GT_VAL_D (mhd_dtbl_find_entry (dyn, \ hdr_name_len, \ - hdr_name), \ - mhd_HPACK_STBL_LAST_IDX, \ - "search for the newly added entry name " - "should be successful")) + hdr_name, \ + hdr_value_len, \ + hdr_value), \ + mhd_HPACK_STBL_LAST_IDX, \ + "search for the newly added entry should " \ + "be successful")) + return 0; + if (!MHDT_EXPECT_UINT_GT_VAL_D (mhd_dtbl_find_name (dyn, \ + hdr_name_len, \ + hdr_name), \ + mhd_HPACK_STBL_LAST_IDX, \ + "search for the newly added entry name " + "should be successful")) return 0; if (have_prev_entry) @@ -446,7 +446,7 @@ mhdtl_dyn_add_hdr_n_with_check (struct mhd_HpackDTblContext *dyn, mhdtl_dyn_check_get_valid_invalid (dyn); - return ! 0; + return !0; } @@ -493,8 +493,8 @@ mhdtl_dyn_add_sized_strs_with_check (struct mhd_HpackDTblContext *dyn, size_t i; for (i = 0; i < sizeof(names); ++i) { - names[i] = (char) ('a' + (char) (i % ('z' - 'a' + 1))); - values[i] = (char) (' ' + (char) ((bufs_size - i) % ('~' - ' ' + 1))); + names[i] = (char)('a' + (char)(i % ('z' - 'a' + 1))); + values[i] = (char)(' ' + (char)((bufs_size - i) % ('~' - ' ' + 1))); } } @@ -539,7 +539,7 @@ mhdtl_stat_check_entry_n_at_idx (size_t idx, struct mhd_BufferConst check_name; struct mhd_BufferConst check_value; - dtbl_idx_t idx_idx = (dtbl_idx_t) idx; + dtbl_idx_t idx_idx = (dtbl_idx_t)idx; if (0 == idx) MHDT_ERR_EXIT (); if (idx_idx != idx) @@ -633,7 +633,7 @@ mhdtl_stat_check_entry_at_idx (size_t idx, } -#define MHDTL_STBL_FIND_ENTRY_REAL_STR(name,value) \ +#define MHDTL_STBL_FIND_ENTRY_REAL_STR(name, value) \ mhd_stbl_find_entry_real (strlen (name),(name), \ strlen (value),(value)) #define MHDTL_STBL_FIND_NAME_REAL_STR(name) \ @@ -652,7 +652,7 @@ mhdtl_comb_check_entry_n_at_idx (struct mhd_HpackDTblContext *dyn, struct mhd_BufferConst check_name; struct mhd_BufferConst check_value; - dtbl_idx_t idx_idx = (dtbl_idx_t) idx; + dtbl_idx_t idx_idx = (dtbl_idx_t)idx; dtbl_idx_t found_by_name_and_value; dtbl_idx_t found_by_name_only; if (0 == idx) @@ -695,8 +695,8 @@ mhdtl_comb_check_entry_n_at_idx (struct mhd_HpackDTblContext *dyn, expect_name_len, expect_name); - if ((0u == expect_name_len) || - (':' != expect_name[0])) + if ((0u == expect_name_len) + || (':' != expect_name[0])) { MHDT_EXPECT_UINT_NE_VAL_D (found_by_name_and_value, \ 0u, \ @@ -746,7 +746,7 @@ mhdtl_comb_check_entry_n_at_idx (struct mhd_HpackDTblContext *dyn, "should fail"); } - return ! 0; + return !0; } @@ -766,10 +766,10 @@ mhdtl_comb_check_entry_at_idx (struct mhd_HpackDTblContext *dyn, } -#define MHDTL_HTBL_FIND_ENTRY_REAL_STR(dyn,name,value) \ +#define MHDTL_HTBL_FIND_ENTRY_REAL_STR(dyn, name, value) \ mhd_htbl_find_entry_real (dyn,strlen (name),(name), \ strlen (value),(value)) -#define MHDTL_HTBL_FIND_NAME_REAL_STR(dyn,name) \ +#define MHDTL_HTBL_FIND_NAME_REAL_STR(dyn, name) \ mhd_htbl_find_name_real (dyn,strlen (name),(name)) @@ -780,7 +780,7 @@ mhdtl_comb_check_entry_at_idx (struct mhd_HpackDTblContext *dyn, static int test_dyn_create_destroy (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = \ mhd_dtbl_create (mhd_hpack_def_dyn_table_size), \ @@ -801,7 +801,7 @@ test_dyn_create_destroy (void) static int test_dyn_create_destroy_larger (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (59u * 1024u), \ "Create HPACK dynamic table"); @@ -833,7 +833,7 @@ test_dyn_create_destroy_larger (void) static int test_dyn_add_three (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (256u), \ "Create HPACK dynamic table"); @@ -854,7 +854,7 @@ test_dyn_add_three (void) static int test_dyn_add_empty (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (256u), \ "Create HPACK dynamic table"); @@ -874,7 +874,7 @@ test_dyn_add_empty (void) static int test_dyn_add_evict_simple (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (128u), \ "Create HPACK dynamic table"); @@ -897,7 +897,7 @@ test_dyn_add_evict_simple (void) static int test_dyn_add_evict_wrap (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (280u), \ "Create HPACK dynamic table"); @@ -1396,7 +1396,7 @@ test_dyn_add_evict_wrap (void) static int test_dyn_add_evict_inter (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; struct mhd_BufferConst check_name; struct mhd_BufferConst check_value; @@ -1652,7 +1652,7 @@ test_dyn_add_series (void) const uint_fast16_t num_inter = (uint_fast16_t) (mhdtl_enable_deep_tests ? (16u * 1024u) : (1024u)); - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; uint_fast16_t i; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (925u), \ @@ -1671,7 +1671,7 @@ test_dyn_add_series (void) do { strs_size = 50u + mhdtl_mix16 (i, - (uint_least16_t) prev_used) % 256u; + (uint_least16_t)prev_used) % 256u; prev_used = cur_used; mhdtl_dyn_add_sized_strs_with_check (dyn, strs_size); @@ -1693,7 +1693,7 @@ test_dyn_add_series (void) do { strs_size = mhdtl_mix16 (i, - (uint_least16_t) prev_used) % 16u; + (uint_least16_t)prev_used) % 16u; prev_used = cur_used; mhdtl_dyn_add_sized_strs_with_check (dyn, strs_size); @@ -1715,7 +1715,7 @@ test_dyn_add_series (void) do { strs_size = mhdtl_mix16 (i, - (uint_least16_t) prev_used) % 312u; + (uint_least16_t)prev_used) % 312u; prev_used = cur_used; mhdtl_dyn_add_sized_strs_with_check (dyn, strs_size); @@ -1738,7 +1738,7 @@ test_dyn_add_evict_series (void) const uint_fast16_t num_inter = (uint_fast16_t) (mhdtl_enable_deep_tests ? (1024u) : (64u)); - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; uint_fast16_t i; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (925u), \ @@ -1812,7 +1812,7 @@ test_dyn_add_evict_series (void) static int test_dyn_evict_to_size (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (256u), \ "Create HPACK dynamic table"); @@ -1912,7 +1912,7 @@ test_dyn_evict_to_size (void) static int test_dyn_resize (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; /* zero-sized table */ MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (321u), \ @@ -2012,7 +2012,7 @@ test_dyn_find (void) static const char *hdr3_val = "third value"; static const char *hdr4_name = "fourth-hdr"; static const char *hdr4_val = "fourth value"; - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (256u), \ "Create HPACK dynamic table"); @@ -2047,7 +2047,7 @@ static int test_dyn_reset_on_too_large (void) { static const size_t tbl_size = 133u; /* not a power of two */ - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (tbl_size), \ "Create HPACK dynamic table"); @@ -2094,7 +2094,7 @@ test_dyn_reset_on_too_large (void) static int test_dyn_zero_sizes (void) { - struct mhd_HpackDTblContext*dyn; + struct mhd_HpackDTblContext *dyn; /* zero-sized table */ MHDT_EXPECT_PTR_NONNULL_D (dyn = mhd_dtbl_create (0u), \ @@ -2278,22 +2278,22 @@ test_stat_get_find (void) static int test_stat_find_non_pseudo_entry_absent (void) { - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("foo","bar"), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("foo", "bar"), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("foo",""), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("foo", ""), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("","bar"), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("", "bar"), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("",""), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR ("", ""), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR (":foo",""), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR (":foo", ""), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR (":authority",""), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR (":authority", ""), \ 0u, \ "search for pseudo-header should fail"); MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_STBL_FIND_ENTRY_REAL_STR (":status", \ @@ -2413,20 +2413,20 @@ test_comb_find_entry_absent (void) mhdtl_dyn_add_hdr_with_check (dyn, "hdr2", "value2"); mhdtl_dyn_add_hdr_with_check (dyn, "empty-value", ""); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, "foo","bar"), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, "foo", "bar"), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, "foo",""), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, "foo", ""), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, "","bar"), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, "", "bar"), \ 0u, \ "search for non-existing header should fail"); - MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, ":foo",""), \ + MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, ":foo", ""), \ 0u, \ "search for non-existing header should fail"); MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, \ - ":authority",""), \ + ":authority", ""), \ 0u, \ "search for pseudo-header should fail"); MHDT_EXPECT_UINT_EQ_VAL_D (MHDTL_HTBL_FIND_ENTRY_REAL_STR (dyn, ":status", \ @@ -2499,14 +2499,14 @@ main (int argc, if (argc < 1) return 99; - if (mhdt_has_param (argc, argv, "-v") || - mhdt_has_param (argc, argv, "--verbose")) + if (mhdt_has_param (argc, argv, "-v") + || mhdt_has_param (argc, argv, "--verbose")) MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); - else if (mhdt_has_param (argc, argv, "-s") || - mhdt_has_param (argc, argv, "--silent")) + else if (mhdt_has_param (argc, argv, "-s") + || mhdt_has_param (argc, argv, "--silent")) MHDT_set_verbosity (MHDT_VERB_LVL_SILENT); - if (! mhdtl_enable_deep_tests) + if (!mhdtl_enable_deep_tests) mhdtl_enable_deep_tests = mhdt_has_param (argc, argv, "--deep"); if (mhdt_has_in_name (argv[0], "_dynamic")) diff --git a/src/tests/unit/unit_md5.c b/src/tests/unit/unit_md5.c @@ -53,13 +53,13 @@ #include "mhdt_has_param.h" #if defined MHD_MD5_EXTR_OPENSSL -#include "../mhd2/md5_ext_openssl.c" +# include "../mhd2/md5_ext_openssl.c" #elif defined MHD_MD5_EXTR_GNUTLS -#include "../mhd2/md5_ext_gnutls.c" +# include "../mhd2/md5_ext_gnutls.c" #elif defined MHD_MD5_EXTR_MBEDTLS -#include "../mhd2/md5_ext_mbedtls.c" +# include "../mhd2/md5_ext_mbedtls.c" #else -#include "../mhd2/md5_int.c" +# include "../mhd2/md5_int.c" #endif #include "../mhd2/mhd_md5.h" @@ -115,9 +115,9 @@ bin2hex (const uint8_t *bin, { unsigned int b1, b2; b1 = (*bin >> 4) & 0xf; - *hex++ = (char) ((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); + *hex++ = (char)((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); b2 = *bin++ & 0xf; - *hex++ = (char) ((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); + *hex++ = (char)((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); } *hex = 0; } @@ -255,7 +255,7 @@ test1_str (void) if (0 != data_units1[i].str_l.len) mhd_MD5_update (&ctx, data_units1[i].str_l.len, - (const uint8_t *) data_units1[i].str_l.str); + (const uint8_t *)data_units1[i].str_l.str); mhd_MD5_finish_reset (&ctx, digest); #if defined(MHD_MD5_EXTR) @@ -476,11 +476,11 @@ test2_str (void) if (0 != part_s) mhd_MD5_update (&ctx, part_s, - (const uint8_t *) data_units1[i].str_l.str); + (const uint8_t *)data_units1[i].str_l.str); if (data_units1[i].str_l.len != part_s) mhd_MD5_update (&ctx, data_units1[i].str_l.len - part_s, - (const uint8_t *) data_units1[i].str_l.str + part_s); + (const uint8_t *)data_units1[i].str_l.str + part_s); mhd_MD5_finish_reset (&ctx, digest); #if defined(MHD_MD5_EXTR) @@ -557,10 +557,10 @@ test_unaligned (void) uint8_t *digest_buf; struct mhd_Md5Ctx ctx; - buf = (uint8_t *) malloc (tdata->bin_l.len + MAX_OFFSET); - digest_buf = (uint8_t *) malloc (mhd_MD5_DIGEST_SIZE + MAX_OFFSET); - if ( (NULL == buf) || - (NULL == digest_buf) ) + buf = (uint8_t *)malloc (tdata->bin_l.len + MAX_OFFSET); + digest_buf = (uint8_t *)malloc (mhd_MD5_DIGEST_SIZE + MAX_OFFSET); + if ((NULL == buf) + || (NULL == digest_buf)) exit (99); mhd_MD5_init_one_time (&ctx); @@ -698,15 +698,15 @@ main (int argc, unsigned int total = 0; unsigned int num_failed; - if (mhdt_has_param (argc, argv, "-v") || - mhdt_has_param (argc, argv, "--verbose")) + if (mhdt_has_param (argc, argv, "-v") + || mhdt_has_param (argc, argv, "--verbose")) verbose = 1; while (NULL != tests[total].name) { const struct Test *t = &tests[total]; mhd_MD5_init_one_time (&ctx); - if (! mhd_MD5_has_err (&ctx)) + if (!mhd_MD5_has_err (&ctx)) { data_len = hex2bin (t->input, data, @@ -717,7 +717,7 @@ main (int argc, data); mhd_MD5_finish_deinit (&ctx, digest); - if (! mhd_MD5_has_err (&ctx)) + if (!mhd_MD5_has_err (&ctx)) { if (check_digest (digest, mhd_MD5_DIGEST_SIZE, @@ -744,7 +744,7 @@ main (int argc, */ total++; mhd_MD5_init_one_time (&ctx); - if (! mhd_MD5_has_err (&ctx)) + if (!mhd_MD5_has_err (&ctx)) { data[0] = 'a'; mhd_MD5_update (&ctx, @@ -760,7 +760,7 @@ main (int argc, data); mhd_MD5_finish_deinit (&ctx, digest); - if (! mhd_MD5_has_err (&ctx)) + if (!mhd_MD5_has_err (&ctx)) { if (check_digest (digest, mhd_MD5_DIGEST_SIZE, @@ -775,7 +775,7 @@ main (int argc, */ total++; mhd_MD5_init_one_time (&ctx); - if (! mhd_MD5_has_err (&ctx)) + if (!mhd_MD5_has_err (&ctx)) { /* First hash */ data_len = hex2bin ("616263", @@ -796,7 +796,7 @@ main (int argc, mhd_MD5_finish_deinit (&ctx, digest); - if (! mhd_MD5_has_err (&ctx)) + if (!mhd_MD5_has_err (&ctx)) { if (check_digest (digest, mhd_MD5_DIGEST_SIZE, diff --git a/src/tests/unit/unit_sha256.c b/src/tests/unit/unit_sha256.c @@ -55,13 +55,13 @@ #include "mhdt_has_param.h" #if defined MHD_SHA256_EXTR_OPENSSL -#include "../mhd2/sha256_ext_openssl.c" +# include "../mhd2/sha256_ext_openssl.c" #elif defined MHD_SHA256_EXTR_GNUTLS -#include "../mhd2/sha256_ext_gnutls.c" +# include "../mhd2/sha256_ext_gnutls.c" #elif defined MHD_SHA256_EXTR_MBEDTLS -#include "../mhd2/sha256_ext_mbedtls.c" +# include "../mhd2/sha256_ext_mbedtls.c" #else -#include "../mhd2/sha256_int.c" +# include "../mhd2/sha256_int.c" #endif #include "../mhd2/mhd_sha256.h" @@ -384,9 +384,9 @@ bin2hex (const uint8_t *bin, { unsigned int b1, b2; b1 = (*bin >> 4) & 0xf; - *hex++ = (char) ((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); + *hex++ = (char)((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); b2 = *bin++ & 0xf; - *hex++ = (char) ((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); + *hex++ = (char)((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); } *hex = 0; } @@ -449,7 +449,7 @@ test1_str (void) if (0 != data_units1[i].str_l.len) mhd_SHA256_update (&ctx, data_units1[i].str_l.len, - (const uint8_t *) data_units1[i].str_l.str); + (const uint8_t *)data_units1[i].str_l.str); mhd_SHA256_finish_reset (&ctx, digest); #ifdef MHD_SHA256_HAS_EXT_ERROR @@ -517,11 +517,11 @@ test2_str (void) if (0 != part_s) mhd_SHA256_update (&ctx, part_s, - (const uint8_t *) data_units1[i].str_l.str); + (const uint8_t *)data_units1[i].str_l.str); if (data_units1[i].str_l.len != part_s) mhd_SHA256_update (&ctx, data_units1[i].str_l.len - part_s, - (const uint8_t *) data_units1[i].str_l.str + part_s); + (const uint8_t *)data_units1[i].str_l.str + part_s); mhd_SHA256_finish_reset (&ctx, digest); #ifdef MHD_SHA256_EXTR if (0 != ctx.ext_error) @@ -592,8 +592,8 @@ test_unaligned (void) const struct data_unit2 *const tdata = data_units2 + DATA_POS; mhd_SHA256_init_one_time (&ctx); - buf = (uint8_t *) malloc (tdata->bin_l.len + MAX_OFFSET); - digest_buf = (uint8_t *) malloc (mhd_SHA256_DIGEST_SIZE + MAX_OFFSET); + buf = (uint8_t *)malloc (tdata->bin_l.len + MAX_OFFSET); + digest_buf = (uint8_t *)malloc (mhd_SHA256_DIGEST_SIZE + MAX_OFFSET); if ((NULL == buf) || (NULL == digest_buf)) exit (99); @@ -685,8 +685,8 @@ main (int argc, unsigned int total = 0; unsigned int num_failed; - if (mhdt_has_param (argc, argv, "-v") || - mhdt_has_param (argc, argv, "--verbose")) + if (mhdt_has_param (argc, argv, "-v") + || mhdt_has_param (argc, argv, "--verbose")) verbose = 1; @@ -695,7 +695,7 @@ main (int argc, const struct Test *t = &tests[total]; mhd_SHA256_init_one_time (&ctx); - if (! mhd_SHA256_has_err (&ctx)) + if (!mhd_SHA256_has_err (&ctx)) { data_len = hex2bin (t->input, data, @@ -706,7 +706,7 @@ main (int argc, data); mhd_SHA256_finish_deinit (&ctx, digest); - if (! mhd_SHA256_has_err (&ctx)) + if (!mhd_SHA256_has_err (&ctx)) { if (check_digest (digest, mhd_SHA256_DIGEST_SIZE, diff --git a/src/tests/unit/unit_sha512_256.c b/src/tests/unit/unit_sha512_256.c @@ -56,11 +56,11 @@ #include "mhdt_has_param.h" #if defined MHD_SHA512_256_EXTR_OPENSSL -#include "../mhd2/sha512_256_ext_openssl.c" +# include "../mhd2/sha512_256_ext_openssl.c" #elif defined MHD_SHA512_256_EXTR_MBEDTLS -#include "../mhd2/sha512_256_ext_mbedtls.c" +# include "../mhd2/sha512_256_ext_mbedtls.c" #else -#include "../mhd2/sha512_256_int.c" +# include "../mhd2/sha512_256_int.c" #endif #include "../mhd2/mhd_sha512_256.h" @@ -492,9 +492,9 @@ bin2hex (const uint8_t *bin, { unsigned int b1, b2; b1 = (*bin >> 4) & 0xf; - *hex++ = (char) ((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); + *hex++ = (char)((b1 > 9) ? (b1 + 'A' - 10) : (b1 + '0')); b2 = *bin++ & 0xf; - *hex++ = (char) ((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); + *hex++ = (char)((b2 > 9) ? (b2 + 'A' - 10) : (b2 + '0')); } *hex = 0; } @@ -556,7 +556,7 @@ test1_str (void) if (0 != data_units1[i].str_l.len) mhd_SHA512_256_update (&ctx, data_units1[i].str_l.len, - (const uint8_t *) data_units1[i].str_l.str); + (const uint8_t *)data_units1[i].str_l.str); mhd_SHA512_256_finish_reset (&ctx, digest); num_failed += check_result (MHD_FUNC_, @@ -613,11 +613,11 @@ test2_str (void) if (0 != part_s) mhd_SHA512_256_update (&ctx, part_s, - (const uint8_t *) data_units1[i].str_l.str); + (const uint8_t *)data_units1[i].str_l.str); if (data_units1[i].str_l.len != part_s) mhd_SHA512_256_update (&ctx, data_units1[i].str_l.len - part_s, - (const uint8_t *) data_units1[i].str_l.str + part_s + (const uint8_t *)data_units1[i].str_l.str + part_s ); mhd_SHA512_256_finish_reset (&ctx, digest); @@ -676,8 +676,8 @@ test_unaligned (void) struct mhd_Sha512_256Ctx ctx; const struct data_unit2 *const tdata = data_units2 + DATA_POS; - buf = (uint8_t *) malloc (tdata->bin_l.len + MAX_OFFSET); - digest_buf = (uint8_t *) malloc (mhd_SHA512_256_DIGEST_SIZE + MAX_OFFSET); + buf = (uint8_t *)malloc (tdata->bin_l.len + MAX_OFFSET); + digest_buf = (uint8_t *)malloc (mhd_SHA512_256_DIGEST_SIZE + MAX_OFFSET); if ((NULL == buf) || (NULL == digest_buf)) exit (99); @@ -762,8 +762,8 @@ main (int argc, unsigned int total = 0; unsigned int num_failed; - if (mhdt_has_param (argc, argv, "-v") || - mhdt_has_param (argc, argv, "--verbose")) + if (mhdt_has_param (argc, argv, "-v") + || mhdt_has_param (argc, argv, "--verbose")) verbose = 1; @@ -772,7 +772,7 @@ main (int argc, const struct Test *t = &tests[total]; mhd_SHA512_256_init_one_time (&ctx); - if (! mhd_SHA512_256_has_err (&ctx)) + if (!mhd_SHA512_256_has_err (&ctx)) { data_len = hex2bin (t->input, data, @@ -783,7 +783,7 @@ main (int argc, data); mhd_SHA512_256_finish_deinit (&ctx, digest); - if (! mhd_SHA512_256_has_err (&ctx)) + if (!mhd_SHA512_256_has_err (&ctx)) { if (check_digest (digest, mhd_SHA512_256_DIGEST_SIZE, diff --git a/src/tests/unit/unit_str.c b/src/tests/unit/unit_str.c @@ -56,8 +56,8 @@ int main (int argc, char *const *argv) { - if (mhdt_has_param (argc, argv, "-s") || - mhdt_has_param (argc, argv, "--silent")) + if (mhdt_has_param (argc, argv, "-s") + || mhdt_has_param (argc, argv, "--silent")) MHDT_set_verbosity (MHDT_VERB_LVL_SILENT); else MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); diff --git a/src/tests/unit/unit_str_base64.c b/src/tests/unit/unit_str_base64.c @@ -37,7 +37,7 @@ /** * Determine length of static string / macro strings at compile time. */ -#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) +# define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! MHD_STATICSTR_LEN_ */ @@ -85,8 +85,8 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_base64_to_bin_n ('%.*s', %u, ->(too long), %u)" " -> %u\n", - (int) encoded_len, encoded, (unsigned) encoded_len, - (unsigned) decoded_size, (unsigned) res_size); + (int)encoded_len, encoded, (unsigned)encoded_len, + (unsigned)decoded_size, (unsigned)res_size); } else { @@ -96,18 +96,18 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_base64_to_bin_n ('%.*s', %u, ->%.*sh, %u)" " -> %u\n", - (int) encoded_len, encoded, (unsigned) encoded_len, - (int) prnt_size, prnt, (unsigned) decoded_size, - (unsigned) res_size); + (int)encoded_len, encoded, (unsigned)encoded_len, + (int)prnt_size, prnt, (unsigned)decoded_size, + (unsigned)res_size); } prnt_size = mhd_bin_to_hex_z (decoded, decoded_size, prnt); mhd_assert (2 * decoded_size == prnt_size); fprintf (stderr, "\tEXPECTED: mhd_base64_to_bin_n ('%.*s', %u, ->%.*sh, %u)" " -> %u\n", - (int) encoded_len, encoded, (unsigned) encoded_len, - (int) prnt_size, prnt, (unsigned) decoded_size, - (unsigned) decoded_size); + (int)encoded_len, encoded, (unsigned)encoded_len, + (int)prnt_size, prnt, (unsigned)decoded_size, + (unsigned)decoded_size); fprintf (stderr, "The check is at line: %u\n\n", line_num); } @@ -115,7 +115,7 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, } -#define expect_decoded(e,d) \ +#define expect_decoded(e, d) \ expect_decoded_n (e,MHD_STATICSTR_LEN_ (e), \ (const uint8_t*) (d),MHD_STATICSTR_LEN_ (d), \ __LINE__) @@ -188,7 +188,7 @@ check_decode_str (void) } -#define expect_decoded_arr(e,a) \ +#define expect_decoded_arr(e, a) \ expect_decoded_n (e,MHD_STATICSTR_LEN_ (e), \ a,(sizeof(a) / sizeof(a[0])), \ __LINE__) @@ -666,8 +666,8 @@ expect_fail_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_base64_to_bin_n ('%.*s', %u, ->(too long), %u)" " -> %u\n", - (int) encoded_len, encoded, (unsigned) encoded_len, - (unsigned) sizeof(buf), (unsigned) res_size); + (int)encoded_len, encoded, (unsigned)encoded_len, + (unsigned)sizeof(buf), (unsigned)res_size); } else { @@ -677,15 +677,15 @@ expect_fail_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_base64_to_bin_n ('%.*s', %u, ->%.*sh, %u)" " -> %u\n", - (int) encoded_len, encoded, (unsigned) encoded_len, - (int) prnt_size, prnt, (unsigned) sizeof(buf), - (unsigned) res_size); + (int)encoded_len, encoded, (unsigned)encoded_len, + (int)prnt_size, prnt, (unsigned)sizeof(buf), + (unsigned)res_size); } fprintf (stderr, "\tEXPECTED: mhd_base64_to_bin_n ('%.*s', %u, ->(empty), %u)" " -> 0\n", - (int) encoded_len, encoded, (unsigned) encoded_len, - (unsigned) sizeof(buf)); + (int)encoded_len, encoded, (unsigned)encoded_len, + (unsigned)sizeof(buf)); fprintf (stderr, "The check is at line: %u\n\n", line_num); } @@ -789,11 +789,12 @@ int main (int argc, char *argv[]) { unsigned int errcount = 0; - (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silent compiler warning. */ errcount += check_decode_str (); errcount += check_decode_bin (); errcount += check_fail (); if (0 == errcount) printf ("All tests were passed without errors.\n"); - return errcount == 0 ? 0 : 1; + return (errcount == 0) ? 0 : 1; } diff --git a/src/tests/unit/unit_str_bin_hex.c b/src/tests/unit/unit_str_bin_hex.c @@ -35,7 +35,7 @@ /** * Determine length of static string / macro strings at compile time. */ -#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) +# define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! MHD_STATICSTR_LEN_ */ @@ -56,22 +56,22 @@ n_prnt (const char *str, size_t len) while (len > r_pos && w_pos + 1 < buf_size) { - const unsigned char c = (unsigned char) str[r_pos]; - if ((c == '\\') || (c == '"') ) + const unsigned char c = (unsigned char)str[r_pos]; + if ((c == '\\') || (c == '"')) { if (w_pos + 2 >= buf_size) break; buf[w_pos++] = '\\'; - buf[w_pos++] = (char) c; + buf[w_pos++] = (char)c; } - else if ((c >= 0x20) && (c <= 0x7E) ) - buf[w_pos++] = (char) c; + else if ((c >= 0x20) && (c <= 0x7E)) + buf[w_pos++] = (char)c; else { if (w_pos + 4 >= buf_size) break; if (snprintf (buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned - int) c) != 4) + int)c) != 4) break; w_pos += 4; } @@ -130,8 +130,8 @@ expect_decoded_n (const char *const hex, const size_t hex_len, } else { - if ((0 != bin_size) && - (0 != memcmp (buf, bin, bin_size))) + if ((0 != bin_size) + && (0 != memcmp (buf, bin, bin_size))) { check_res = 1; fprintf (stderr, @@ -153,15 +153,15 @@ expect_decoded_n (const char *const hex, const size_t hex_len, fprintf (stderr, "\tRESULT : mhd_hex_to_bin (\"%s\", %u, " "->\"%s\") -> %u\n", - n_prnt (hex, hex_len), (unsigned) hex_len, + n_prnt (hex, hex_len), (unsigned)hex_len, n_prnt (buf, res_size), - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_hex_to_bin (\"%s\", %u, " "->\"%s\") -> %u\n", - n_prnt (hex, hex_len), (unsigned) hex_len, - n_prnt ((const char *) bin, bin_size), - (unsigned) bin_size); + n_prnt (hex, hex_len), (unsigned)hex_len, + n_prnt ((const char *)bin, bin_size), + (unsigned)bin_size); } } @@ -182,8 +182,8 @@ expect_decoded_n (const char *const hex, const size_t hex_len, } else { - if ((0 != hex_len) && - (! mhd_str_equal_caseless_bin_n (buf, hex, hex_len))) + if ((0 != hex_len) + && (!mhd_str_equal_caseless_bin_n (buf, hex, hex_len))) { check_res = 1; fprintf (stderr, @@ -211,15 +211,15 @@ expect_decoded_n (const char *const hex, const size_t hex_len, fprintf (stderr, "\tRESULT : mhd_bin_to_hex (\"%s\", %u, " "->\"%s\") -> %u\n", - n_prnt ((const char *) bin, bin_size), (unsigned) bin_size, + n_prnt ((const char *)bin, bin_size), (unsigned)bin_size, n_prnt (buf, res_size), - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_bin_to_hex (\"%s\", %u, " "->(lower case)\"%s\") -> %u\n", - n_prnt ((const char *) bin, bin_size), (unsigned) bin_size, + n_prnt ((const char *)bin, bin_size), (unsigned)bin_size, n_prnt (hex, hex_len), - (unsigned) bin_size); + (unsigned)bin_size); } } @@ -232,7 +232,7 @@ expect_decoded_n (const char *const hex, const size_t hex_len, } -#define expect_decoded_arr(h,a) \ +#define expect_decoded_arr(h, a) \ expect_decoded_n (h,MHD_STATICSTR_LEN_ (h), \ a,(sizeof(a) / sizeof(a[0])), \ __LINE__) @@ -397,13 +397,13 @@ expect_failed_n (const char *const hex, const size_t hex_len, fprintf (stderr, "\tRESULT : mhd_hex_to_bin (\"%s\", %u, " "->\"%s\") -> %u\n", - n_prnt (hex, hex_len), (unsigned) hex_len, + n_prnt (hex, hex_len), (unsigned)hex_len, n_prnt (buf, res_size), - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_hex_to_bin (\"%s\", %u, " "->(not defined)) -> 0\n", - n_prnt (hex, hex_len), (unsigned) hex_len); + n_prnt (hex, hex_len), (unsigned)hex_len); } } @@ -442,10 +442,11 @@ int main (int argc, char *argv[]) { unsigned int errcount = 0; - (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silent compiler warning. */ errcount += check_decode_bin (); errcount += check_broken_str (); if (0 == errcount) printf ("All tests have been passed without errors.\n"); - return errcount == 0 ? 0 : 1; + return (errcount == 0) ? 0 : 1; } diff --git a/src/tests/unit/unit_str_compare.c b/src/tests/unit/unit_str_compare.c @@ -29,15 +29,15 @@ #include <locale.h> #include <string.h> #ifdef HAVE_INTTYPES_H -#include <inttypes.h> +# include <inttypes.h> #else /* ! HAVE_INTTYPES_H */ -#define PRIu64 "llu" -#define PRIuPTR "u" -#define PRIX64 "llX" +# define PRIu64 "llu" +# define PRIuPTR "u" +# define PRIX64 "llX" #endif /* ! HAVE_INTTYPES_H */ #include <stdint.h> #ifdef HAVE_STDLIB_H -#include <stdlib.h> +# include <stdlib.h> #endif /* HAVE_STDLIB_H */ #include "mhd_limits.h" @@ -57,7 +57,7 @@ static int verbose = 0; /* verbose level (0-3)*/ static const char *const locale_names[] = { "C", "", /* System default locale */ -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) ".OCP", /* W32 system default OEM code page */ ".ACP", /* W32 system default ANSI code page */ ".65001", /* UTF-8 */ @@ -75,7 +75,7 @@ static const char *const locale_names[] = { "de", "zh-Hans", "ru-RU.1251" -#if 0 /* Disabled extra checks */ +# if 0 /* Disabled extra checks */ , ".1254", ".20866", /* number for KOI8-R */ @@ -128,7 +128,7 @@ static const char *const locale_names[] = { "Russian_Russia.65001", "zh-Hans.936", "chinese-simplified" -#endif /* Disabled extra checks */ +# endif /* Disabled extra checks */ #else /* ! _WIN32 || __CYGWIN__ */ "C.UTF-8", "POSIX", @@ -258,7 +258,7 @@ n_prnt (const char *str) { static char *buf; /* should be enough for testing */ static const size_t buf_size = sizeof(tmp_bufs[0]); - const unsigned char *p = (const unsigned char *) str; + const unsigned char *p = (const unsigned char *)str; size_t w_pos = 0; if (++buf_idx > 3) buf_idx = 0; @@ -267,21 +267,21 @@ n_prnt (const char *str) while (*p && w_pos + 1 < buf_size) { const unsigned char c = *p; - if ((c == '\\') || (c == '"') ) + if ((c == '\\') || (c == '"')) { if (w_pos + 2 >= buf_size) break; buf[w_pos++] = '\\'; - buf[w_pos++] = (char) c; + buf[w_pos++] = (char)c; } - else if ((c >= 0x20) && (c <= 0x7E) ) - buf[w_pos++] = (char) c; + else if ((c >= 0x20) && (c <= 0x7E)) + buf[w_pos++] = (char)c; else { if (w_pos + 4 >= buf_size) break; if (snprintf (buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned - int) c) != 4) + int)c) != 4) break; w_pos += 4; } @@ -443,8 +443,8 @@ static const struct two_eq_strs eq_strings[] = { "\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5" "\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9" "\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed" - "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff") - } /* Full with A/a match */ + "\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")} + /* Full with A/a match */ }; struct two_neq_strs @@ -536,25 +536,29 @@ check_eq_strings (void) const struct two_eq_strs *const t = eq_strings + i; if (c_failed[i]) continue; /* skip already failed checks */ - if (! mhd_str_equal_caseless (t->s1.str, t->s2.str)) + if (!mhd_str_equal_caseless (t->s1.str, t->s2.str)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned zero, while expected non-zero." - " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str), + " Locale: %s\n", + n_prnt (t->s1.str), + n_prnt (t->s2.str), get_current_locale_str ()); } - else if (! mhd_str_equal_caseless (t->s2.str, t->s1.str)) + else if (!mhd_str_equal_caseless (t->s2.str, t->s1.str)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned zero, while expected non-zero." - " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str), + " Locale: %s\n", + n_prnt (t->s2.str), + n_prnt (t->s1.str), get_current_locale_str ()); } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_equal_caseless(\"%s\", \"%s\") != 0 && \\\n" " mhd_str_equal_caseless(\"%s\", \"%s\") != 0\n", n_prnt (t->s1.str), n_prnt (t->s2.str), @@ -586,22 +590,26 @@ check_neq_strings (void) if (mhd_str_equal_caseless (t->s1.str, t->s2.str)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned non-zero, while expected zero." - " Locale: %s\n", n_prnt (t->s1.str), n_prnt (t->s2.str), + " Locale: %s\n", + n_prnt (t->s1.str), + n_prnt (t->s2.str), get_current_locale_str ()); } else if (mhd_str_equal_caseless (t->s2.str, t->s1.str)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless(\"%s\", \"%s\") returned non-zero, while expected zero." - " Locale: %s\n", n_prnt (t->s2.str), n_prnt (t->s1.str), + " Locale: %s\n", + n_prnt (t->s2.str), + n_prnt (t->s1.str), get_current_locale_str ()); } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_equal_caseless(\"%s\", \"%s\") == 0 && \\\n" " mhd_str_equal_caseless(\"%s\", \"%s\") == 0\n", n_prnt (t->s1.str), n_prnt (t->s2.str), @@ -630,36 +638,40 @@ check_eq_strings_n (void) size_t m_len; const struct two_eq_strs *const t = eq_strings + i; m_len = (t->s1.len > t->s2.len) ? t->s1.len : t->s2.len; - for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++) + for (k = 0; k <= m_len + 1 && !c_failed[i]; k++) { - if (! mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) + if (!mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," " while expected non-zero. Locale: %s\n", - n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, + n_prnt (t->s1.str), + n_prnt (t->s2.str), + (unsigned int)k, get_current_locale_str ()); } - else if (! mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) + else if (!mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," " while expected non-zero. Locale: %s\n", - n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, + n_prnt (t->s2.str), + n_prnt (t->s1.str), + (unsigned int)k, get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_equal_caseless_n(\"%s\", \"%s\", N) " \ "!= 0 && \\\n" \ " mhd_str_equal_caseless_n(\"%s\", \"%s\", N) " \ "!= 0, where N is 0..%u\n", n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), - n_prnt (t->s1.str), (unsigned int) m_len + 1); + n_prnt (t->s1.str), (unsigned int)m_len + 1); } } return t_failed; @@ -688,52 +700,63 @@ check_neq_strings_n (void) { fprintf (stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less than " - "s1.len (%u) or s2.len (%u).\n", (unsigned int) i, (unsigned - int) t-> + "s1.len (%u) or s2.len (%u).\n", + (unsigned int)i, + (unsigned + int)t-> dif_pos, - (unsigned int) t->s1.len, (unsigned int) t->s2.len); + (unsigned int)t->s1.len, + (unsigned int)t->s2.len); exit (99); } if (t->dif_pos > t->s1.len) { fprintf (stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " - "equal to s1.len (%u).\n", (unsigned int) i, (unsigned - int) t->dif_pos, - (unsigned int) t->s1.len); + "equal to s1.len (%u).\n", + (unsigned int)i, + (unsigned + int)t->dif_pos, + (unsigned int)t->s1.len); exit (99); } if (t->dif_pos > t->s2.len) { fprintf (stderr, "ERROR: neq_strings[%u] has wrong dif_pos (%u): dif_pos is expected to be less or " - "equal to s2.len (%u).\n", (unsigned int) i, (unsigned - int) t->dif_pos, - (unsigned int) t->s2.len); + "equal to s2.len (%u).\n", + (unsigned int)i, + (unsigned + int)t->dif_pos, + (unsigned int)t->s2.len); exit (99); } - for (k = 0; k <= m_len + 1 && ! c_failed[i]; k++) + for (k = 0; k <= m_len + 1 && !c_failed[i]; k++) { if (k <= t->dif_pos) { - if (! mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) + if (!mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," " while expected non-zero. Locale: %s\n", - n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, + n_prnt (t->s1.str), + n_prnt (t->s2.str), + (unsigned int)k, get_current_locale_str ()); } - else if (! mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) + else if (!mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned zero," " while expected non-zero. Locale: %s\n", - n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, + n_prnt (t->s2.str), + n_prnt (t->s1.str), + (unsigned int)k, get_current_locale_str ()); } } @@ -742,40 +765,49 @@ check_neq_strings_n (void) if (mhd_str_equal_caseless_n (t->s1.str, t->s2.str, k)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned non-zero," " while expected zero. Locale: %s\n", - n_prnt (t->s1.str), n_prnt (t->s2.str), (unsigned int) k, + n_prnt (t->s1.str), + n_prnt (t->s2.str), + (unsigned int)k, get_current_locale_str ()); } else if (mhd_str_equal_caseless_n (t->s2.str, t->s1.str, k)) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_equal_caseless_n(\"%s\", \"%s\", %u) returned non-zero," " while expected zero. Locale: %s\n", - n_prnt (t->s2.str), n_prnt (t->s1.str), (unsigned int) k, + n_prnt (t->s2.str), + n_prnt (t->s1.str), + (unsigned int)k, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) { printf ( "PASSED: mhd_str_equal_caseless_n(\"%s\", \"%s\", N) != 0 && \\\n" " mhd_str_equal_caseless_n(\"%s\", \"%s\", N) != 0, where N is 0..%u\n", - n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), n_prnt (t->s1.str), - (unsigned int) t->dif_pos); + n_prnt (t->s2.str), + n_prnt (t->s2.str), + n_prnt (t->s1.str), + (unsigned int)t->dif_pos); printf ( "PASSED: mhd_str_equal_caseless_n(\"%s\", \"%s\", N) == 0 && \\\n" " mhd_str_equal_caseless_n(\"%s\", \"%s\", N) == 0, where N is %u..%u\n", - n_prnt (t->s1.str), n_prnt (t->s2.str), n_prnt (t->s2.str), n_prnt (t->s1.str), - (unsigned int) t->dif_pos + 1, (unsigned int) m_len + 1); + n_prnt (t->s2.str), + n_prnt (t->s2.str), + n_prnt (t->s1.str), + (unsigned int)t->dif_pos + 1, + (unsigned int)m_len + 1); } } } @@ -814,7 +846,7 @@ run_eq_neq_str_tests (void) if (str_equal_caseless_fails) fprintf (stderr, "FAILED: function mhd_str_equal_caseless() failed %lu time%s.\n\n", - (unsigned long) str_equal_caseless_fails, + (unsigned long)str_equal_caseless_fails, str_equal_caseless_fails == 1 ? "" : "s"); else if (verbose > 0) @@ -842,7 +874,7 @@ run_eq_neq_str_tests (void) if (str_equal_caseless_n_fails) fprintf (stderr, "FAILED: function mhd_str_equal_caseless_n() failed %lu time%s.\n\n", - (unsigned long) str_equal_caseless_n_fails, + (unsigned long)str_equal_caseless_n_fails, str_equal_caseless_n_fails == 1 ? "" : "s"); else if (verbose > 0) @@ -868,12 +900,12 @@ int main (int argc, char *argv[]) { - if (mhdt_has_param (argc, argv, "-v") || - mhdt_has_param (argc, argv, "--verbose") || - mhdt_has_param (argc, argv, "--verbose1")) + if (mhdt_has_param (argc, argv, "-v") + || mhdt_has_param (argc, argv, "--verbose") + || mhdt_has_param (argc, argv, "--verbose1")) MHDT_set_verbosity (MHDT_VERB_LVL_BASIC); - if (mhdt_has_param (argc, argv, "-vv") || - mhdt_has_param (argc, argv, "--verbose2")) + if (mhdt_has_param (argc, argv, "-vv") + || mhdt_has_param (argc, argv, "--verbose2")) MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); return run_eq_neq_str_tests (); diff --git a/src/tests/unit/unit_str_from_value.c b/src/tests/unit/unit_str_from_value.c @@ -29,15 +29,15 @@ #include <locale.h> #include <string.h> #ifdef HAVE_INTTYPES_H -#include <inttypes.h> +# include <inttypes.h> #else /* ! HAVE_INTTYPES_H */ -#define PRIuFAST64 "llu" -#define PRIuPTR "llu" -#define PRIXFAST64 "llX" +# define PRIuFAST64 "llu" +# define PRIuPTR "llu" +# define PRIXFAST64 "llX" #endif /* ! HAVE_INTTYPES_H */ #include <stdint.h> #ifdef HAVE_STDLIB_H -#include <stdlib.h> +# include <stdlib.h> #endif /* HAVE_STDLIB_H */ #include "mhd_str.h" @@ -55,7 +55,7 @@ static int verbose = 0; /* verbose level (0-3)*/ static const char *const locale_names[] = { "C", "", /* System default locale */ -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) ".OCP", /* W32 system default OEM code page */ ".ACP", /* W32 system default ANSI code page */ ".65001", /* UTF-8 */ @@ -73,7 +73,7 @@ static const char *const locale_names[] = { "de", "zh-Hans", "ru-RU.1251" -#if 0 /* Disabled extra checks */ +# if 0 /* Disabled extra checks */ , ".1254", ".20866", /* number for KOI8-R */ @@ -126,7 +126,7 @@ static const char *const locale_names[] = { "Russian_Russia.65001", "zh-Hans.936", "chinese-simplified" -#endif /* Disabled extra checks */ +# endif /* Disabled extra checks */ #else /* ! _WIN32 || __CYGWIN__ */ "C.UTF-8", "POSIX", @@ -491,8 +491,10 @@ check_str_from_uint16 (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } @@ -507,7 +509,7 @@ check_str_from_uint16 (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has too long (%u) string, " "size of 'buf' should be increased.\n", - (unsigned int) i, (unsigned int) t->str.len); + (unsigned int)i, (unsigned int)t->str.len); exit (99); } rs = 0; /* Only to mute compiler warning */ @@ -516,7 +518,7 @@ check_str_from_uint16 (void) /* fill buffer with pseudo-random values */ memcpy (buf, erase, sizeof(buf)); - rs = mhd_uint16_to_str ((uint_least16_t) t->val, buf, b_size); + rs = mhd_uint16_to_str ((uint_least16_t)t->val, buf, b_size); if (t->num_of_digt > b_size) { @@ -525,12 +527,12 @@ check_str_from_uint16 (void) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> buf," " %d) returned %" PRIuPTR ", while expecting 0." - " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, + " Locale: %s\n", t->val, (int)b_size, (uintptr_t)rs, get_current_locale_str ()); } } @@ -540,43 +542,43 @@ check_str_from_uint16 (void) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> buf," " %d) returned %" PRIuPTR ", while expecting %d." - " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)b_size, (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } else if (0 != memcmp (buf, t->str.str, t->num_of_digt)) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> \"%.*s\"," " %d) returned %" PRIuPTR "." - " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)rs, buf, (int)b_size, + (uintptr_t)rs, get_current_locale_str ()); } else if (0 != memcmp (buf + rs, erase + rs, sizeof(buf) - rs)) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint16_to_str(%" PRIuFAST64 ", -> \"%.*s\"," " %d) returned %" PRIuPTR " and touched data after the resulting string." - " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)rs, buf, (int)b_size, + (uintptr_t)rs, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_uint16_to_str(%" PRIuFAST64 ", -> \"%.*s\", %d) " "== %" PRIuPTR "\n", - t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs); + t->val, (int)rs, buf, (int)b_size - 1, (uintptr_t)rs); } } return t_failed; @@ -616,8 +618,10 @@ check_str_from_uint64 (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } @@ -630,7 +634,7 @@ check_str_from_uint64 (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has too long (%u) string, " "size of 'buf' should be increased.\n", - (unsigned int) i, (unsigned int) t->str.len); + (unsigned int)i, (unsigned int)t->str.len); exit (99); } rs = 0; /* Only to mute compiler warning */ @@ -648,12 +652,12 @@ check_str_from_uint64 (void) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> buf," " %d) returned %" PRIuPTR ", while expecting 0." - " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, + " Locale: %s\n", t->val, (int)b_size, (uintptr_t)rs, get_current_locale_str ()); } } @@ -663,43 +667,43 @@ check_str_from_uint64 (void) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> buf," " %d) returned %" PRIuPTR ", while expecting %d." - " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)b_size, (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } else if (0 != memcmp (buf, t->str.str, t->num_of_digt)) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> \"%.*s\"," " %d) returned %" PRIuPTR "." - " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)rs, buf, (int)b_size, + (uintptr_t)rs, get_current_locale_str ()); } else if (0 != memcmp (buf + rs, erase + rs, sizeof(buf) - rs)) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint64_to_str(%" PRIuFAST64 ", -> \"%.*s\"," " %d) returned %" PRIuPTR " and touched data after the resulting string." - " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)rs, buf, (int)b_size, + (uintptr_t)rs, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_uint64_to_str(%" PRIuFAST64 ", -> \"%.*s\", %d) " "== %" PRIuPTR "\n", - t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs); + t->val, (int)rs, buf, (int)b_size - 1, (uintptr_t)rs); } } return t_failed; @@ -739,8 +743,10 @@ check_strx_from_uint32 (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } @@ -755,7 +761,7 @@ check_strx_from_uint32 (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has too long (%u) string, " "size of 'buf' should be increased.\n", - (unsigned int) i, (unsigned int) t->str.len); + (unsigned int)i, (unsigned int)t->str.len); exit (99); } rs = 0; /* Only to mute compiler warning */ @@ -764,7 +770,7 @@ check_strx_from_uint32 (void) /* fill buffer with pseudo-random values */ memcpy (buf, erase, sizeof(buf)); - rs = mhd_uint32_to_strx ((uint_fast32_t) t->val, buf, b_size); + rs = mhd_uint32_to_strx ((uint_fast32_t)t->val, buf, b_size); if (t->num_of_digt > b_size) { @@ -773,12 +779,12 @@ check_strx_from_uint32 (void) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64 ", -> buf," " %d) returned %" PRIuPTR ", while expecting 0." - " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, + " Locale: %s\n", t->val, (int)b_size, (uintptr_t)rs, get_current_locale_str ()); } } @@ -788,55 +794,55 @@ check_strx_from_uint32 (void) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64 ", -> buf," " %d) returned %" PRIuPTR ", while expecting %d." - " Locale: %s\n", t->val, (int) b_size, (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)b_size, (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } else if (0 == mhd_str_equal_caseless_bin_n (buf, t->str.str, t->num_of_digt)) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64 ", -> \"%.*s\"," " %d) returned %" PRIuPTR "." - " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)rs, buf, (int)b_size, + (uintptr_t)rs, get_current_locale_str ()); } else if (sizeof(buf) <= rs) { fprintf (stderr, "ERROR: dstrs_w_values[%u] has string with too many" "(%u) digits, size of 'buf' should be increased.\n", - (unsigned int) i, (unsigned int) rs); + (unsigned int)i, (unsigned int)rs); exit (99); } else if (0 != memcmp (buf + rs, erase + rs, sizeof(buf) - rs)) { if (0 == c_failed[i]) t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_uint32_to_strx(0x%" PRIXFAST64 ", -> \"%.*s\"," " %d) returned %" PRIuPTR " and touched data after the resulting string." - " Locale: %s\n", t->val, (int) rs, buf, (int) b_size, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", t->val, (int)rs, buf, (int)b_size, + (uintptr_t)rs, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_uint32_to_strx(0x%" PRIXFAST64 ", -> \"%.*s\", %d) " "== %" PRIuPTR "\n", - t->val, (int) rs, buf, (int) b_size - 1, (uintptr_t) rs); + t->val, (int)rs, buf, (int)b_size - 1, (uintptr_t)rs); } } return t_failed; @@ -1631,9 +1637,9 @@ check_str_from_uint8_pad (void) uint8_t pad; size_t t_failed = 0; - if ((256 != sizeof(duint8_w_values_p1) / sizeof(duint8_w_values_p1[0])) || - (256 != sizeof(duint8_w_values_p2) / sizeof(duint8_w_values_p2[0])) || - (256 != sizeof(duint8_w_values_p3) / sizeof(duint8_w_values_p3[0]))) + if ((256 != sizeof(duint8_w_values_p1) / sizeof(duint8_w_values_p1[0])) + || (256 != sizeof(duint8_w_values_p2) / sizeof(duint8_w_values_p2[0])) + || (256 != sizeof(duint8_w_values_p3) / sizeof(duint8_w_values_p3[0]))) { fprintf (stderr, "ERROR: wrong number of items in duint8_w_values_p*.\n"); @@ -1659,8 +1665,10 @@ check_str_from_uint8_pad (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } @@ -1669,7 +1677,7 @@ check_str_from_uint8_pad (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has too long (%u) string, " "size of 'buf' should be increased.\n", - (unsigned int) i, (unsigned int) t->str.len); + (unsigned int)i, (unsigned int)t->str.len); exit (99); } for (b_size = 0; b_size <= t->str.len + 1; ++b_size) @@ -1677,7 +1685,7 @@ check_str_from_uint8_pad (void) /* fill buffer with pseudo-random values */ memset (buf, '#', sizeof(buf)); - rs = mhd_uint8_to_str_pad ((uint8_t) t->val, pad, buf, b_size); + rs = mhd_uint8_to_str_pad ((uint8_t)t->val, pad, buf, b_size); if (t->num_of_digt > b_size) { @@ -1688,8 +1696,8 @@ check_str_from_uint8_pad (void) fprintf (stderr, "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d, -> buf," " %d) returned %" PRIuPTR - ", while expecting 0.\n", t->val, (int) pad, (int) b_size, - (uintptr_t) rs); + ", while expecting 0.\n", t->val, (int)pad, (int)b_size, + (uintptr_t)rs); } else if (0 != memcmp (buf + b_size, "##########", @@ -1702,11 +1710,11 @@ check_str_from_uint8_pad (void) " and touched memory outside provided buffer.\n" "The tail of the buffer must be \"%.*s\", " "but it is \"%.*s\".\n", - t->val, (int) pad, (int) rs, buf, (int) b_size, - (uintptr_t) rs, - (int) (sizeof(buf) - b_size), + t->val, (int)pad, (int)rs, buf, (int)b_size, + (uintptr_t)rs, + (int)(sizeof(buf) - b_size), "##########", - (int) (sizeof(buf) - b_size), + (int)(sizeof(buf) - b_size), buf + b_size); } } @@ -1718,8 +1726,8 @@ check_str_from_uint8_pad (void) fprintf (stderr, "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d, -> buf," " %d) returned %" PRIuPTR - ", while expecting %d.\n", t->val, (int) pad, - (int) b_size, (uintptr_t) rs, (int) t->num_of_digt); + ", while expecting %d.\n", t->val, (int)pad, + (int)b_size, (uintptr_t)rs, (int)t->num_of_digt); } else if (0 != memcmp (buf, t->str.str, t->num_of_digt)) { @@ -1727,8 +1735,8 @@ check_str_from_uint8_pad (void) fprintf (stderr, "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d, " "-> \"%.*s\", %d) returned %" PRIuPTR ".\n", - t->val, (int) pad, (int) rs, buf, - (int) b_size, (uintptr_t) rs); + t->val, (int)pad, (int)rs, buf, + (int)b_size, (uintptr_t)rs); } else if (0 != memcmp (buf + rs, "########", sizeof(buf) - rs)) { @@ -1737,8 +1745,8 @@ check_str_from_uint8_pad (void) "FAILED: mhd_uint8_to_str_pad(%" PRIuFAST64 ", %d," " -> \"%.*s\", %d) returned %" PRIuPTR " and touched data after the resulting string.\n", - t->val, (int) pad, (int) rs, buf, (int) b_size, - (uintptr_t) rs); + t->val, (int)pad, (int)rs, buf, (int)b_size, + (uintptr_t)rs); } } } @@ -1823,12 +1831,12 @@ run_str_from_X_tests (void) int main (int argc, char *argv[]) { - if (mhdt_has_param (argc, argv, "-v") || - mhdt_has_param (argc, argv, "--verbose") || - mhdt_has_param (argc, argv, "--verbose1")) + if (mhdt_has_param (argc, argv, "-v") + || mhdt_has_param (argc, argv, "--verbose") + || mhdt_has_param (argc, argv, "--verbose1")) MHDT_set_verbosity (MHDT_VERB_LVL_BASIC); - if (mhdt_has_param (argc, argv, "-vv") || - mhdt_has_param (argc, argv, "--verbose2")) + if (mhdt_has_param (argc, argv, "-vv") + || mhdt_has_param (argc, argv, "--verbose2")) MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); return run_str_from_X_tests (); diff --git a/src/tests/unit/unit_str_pct.c b/src/tests/unit/unit_str_pct.c @@ -35,7 +35,7 @@ /** * Determine length of static string / macro strings at compile time. */ -#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) +# define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! MHD_STATICSTR_LEN_ */ @@ -56,22 +56,22 @@ n_prnt (const char *str, size_t len) while (len > r_pos && w_pos + 1 < buf_size) { - const unsigned char c = (unsigned char) str[r_pos]; - if ((c == '\\') || (c == '"') ) + const unsigned char c = (unsigned char)str[r_pos]; + if ((c == '\\') || (c == '"')) { if (w_pos + 2 >= buf_size) break; buf[w_pos++] = '\\'; - buf[w_pos++] = (char) c; + buf[w_pos++] = (char)c; } - else if ((c >= 0x20) && (c <= 0x7E) ) - buf[w_pos++] = (char) c; + else if ((c >= 0x20) && (c <= 0x7E)) + buf[w_pos++] = (char)c; else { if (w_pos + 4 >= buf_size) break; if (snprintf (buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned - int) c) != 4) + int)c) != 4) break; w_pos += 4; } @@ -150,8 +150,8 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, "Wrong returned value:\n"); } } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -165,15 +165,15 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_strict_n (\"%s\", %u, " "->\"%s\", %u) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) decoded_size, - (unsigned) res_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)decoded_size, + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_strict_n (\"%s\", %u, " "->\"%s\", %u) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (decoded, decoded_size), (unsigned) decoded_size, - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (decoded, decoded_size), (unsigned)decoded_size, + (unsigned)decoded_size); } } @@ -201,8 +201,8 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, "'mhd_str_pct_decode_strict_n ()' FAILED: " "A char written outside the buffer:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -216,15 +216,15 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_strict_n (\"%s\", %u, " "->\"%s\", %u) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) (encoded_len + 1), - (unsigned) res_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)(encoded_len + 1), + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_strict_n (\"%s\", %u, " "->\"%s\", %u) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (decoded, decoded_size), (unsigned) (encoded_len + 1), - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (decoded, decoded_size), (unsigned)(encoded_len + 1), + (unsigned)decoded_size); } } @@ -274,8 +274,8 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, "'mhd_str_pct_decode_lenient_n ()' FAILED: " "Wrong 'broken_encoding' result:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -289,16 +289,16 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->%s) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) decoded_size, + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)decoded_size, is_broken ? "true" : "false", - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->false) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (decoded, decoded_size), (unsigned) decoded_size, - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (decoded, decoded_size), (unsigned)decoded_size, + (unsigned)decoded_size); } } @@ -334,8 +334,8 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, "'mhd_str_pct_decode_lenient_n ()' FAILED: " "Wrong 'broken_encoding' result:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -349,16 +349,16 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->%s) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) (encoded_len + 1), + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)(encoded_len + 1), is_broken ? "true" : "false", - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->false) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (decoded, decoded_size), (unsigned) (encoded_len + 1), - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (decoded, decoded_size), (unsigned)(encoded_len + 1), + (unsigned)decoded_size); } } @@ -398,8 +398,8 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, "'mhd_str_pct_decode_in_place_strict ()' FAILED: " "A char written outside the buffer:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -415,13 +415,13 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, "-> \"%s\") -> %u\n", n_prnt (encoded, encoded_len), n_prnt (buf, res_size), - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_in_place_strict (\"%s\" " "-> \"%s\") -> %u\n", n_prnt (encoded, encoded_len), n_prnt (decoded, decoded_size), - (unsigned) decoded_size); + (unsigned)decoded_size); } } @@ -467,8 +467,8 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, "'mhd_str_pct_decode_in_place_lenient ()' FAILED: " "Wrong 'broken_encoding' result:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -485,13 +485,13 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, n_prnt (encoded, encoded_len), n_prnt (buf, res_size), is_broken ? "true" : "false", - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_in_place_lenient (\"%s\" " "-> \"%s\", ->false) -> %u\n", n_prnt (encoded, encoded_len), n_prnt (decoded, decoded_size), - (unsigned) decoded_size); + (unsigned)decoded_size); } } } @@ -505,7 +505,7 @@ expect_decoded_n (const char *const encoded, const size_t encoded_len, } -#define expect_decoded(e,d) \ +#define expect_decoded(e, d) \ expect_decoded_n (e,MHD_STATICSTR_LEN_ (e), \ d,MHD_STATICSTR_LEN_ (d), \ __LINE__) @@ -585,7 +585,7 @@ check_decode_str (void) } -#define expect_decoded_arr(e,a) \ +#define expect_decoded_arr(e, a) \ expect_decoded_n (e,MHD_STATICSTR_LEN_ (e), \ (const char *) a,(sizeof(a) / sizeof(a[0])), \ __LINE__) @@ -731,14 +731,14 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_strict_n (\"%s\", %u, " "->\"%s\", %u) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) decoded_size, - (unsigned) res_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)decoded_size, + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_strict_n (\"%s\", %u, " "->(not defined), %u) -> 0\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + (unsigned)decoded_size); } } @@ -763,14 +763,14 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_strict_n (\"%s\", %u, " "->\"%s\", %u) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) (encoded_len + 1), - (unsigned) res_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)(encoded_len + 1), + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_strict_n (\"%s\", %u, " "->(not defined), %u) -> 0\n", - n_prnt (encoded, encoded_len), (unsigned) (encoded_len + 1), - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)(encoded_len + 1), + (unsigned)decoded_size); } } @@ -813,15 +813,15 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, "Wrong returned value:\n"); } } - if (! is_broken) + if (!is_broken) { check_res = 1; fprintf (stderr, "'mhd_str_pct_decode_lenient_n ()' FAILED: " "Wrong 'broken_encoding' result:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -835,16 +835,16 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->%s) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) decoded_size, + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)decoded_size, is_broken ? "true" : "false", - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->true) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (decoded, decoded_size), (unsigned) decoded_size, - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (decoded, decoded_size), (unsigned)decoded_size, + (unsigned)decoded_size); } } @@ -873,15 +873,15 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, "'mhd_str_pct_decode_lenient_n ()' FAILED: " "A char written outside the buffer:\n"); } - if (! is_broken) + if (!is_broken) { check_res = 1; fprintf (stderr, "'mhd_str_pct_decode_lenient_n ()' FAILED: " "Wrong 'broken_encoding' result:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -895,16 +895,16 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, fprintf (stderr, "\tRESULT : mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->%s) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (buf, res_size), (unsigned) (encoded_len + 1), + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (buf, res_size), (unsigned)(encoded_len + 1), is_broken ? "true" : "false", - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_lenient_n (\"%s\", %u, " "->\"%s\", %u, ->true) -> %u\n", - n_prnt (encoded, encoded_len), (unsigned) encoded_len, - n_prnt (decoded, decoded_size), (unsigned) (encoded_len + 1), - (unsigned) decoded_size); + n_prnt (encoded, encoded_len), (unsigned)encoded_len, + n_prnt (decoded, decoded_size), (unsigned)(encoded_len + 1), + (unsigned)decoded_size); } } @@ -934,7 +934,7 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, "-> \"%s\") -> %u\n", n_prnt (encoded, encoded_len), n_prnt (buf, res_size), - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_in_place_strict (\"%s\" " "-> (not defined)) -> 0\n", @@ -977,15 +977,15 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, "'mhd_str_pct_decode_in_place_lenient ()' FAILED: " "A char written outside the buffer:\n"); } - if (! is_broken) + if (!is_broken) { check_res = 1; fprintf (stderr, "'mhd_str_pct_decode_in_place_lenient ()' FAILED: " "Wrong 'broken_encoding' result:\n"); } - if ((res_size == decoded_size) && (0 != decoded_size) && - (0 != memcmp (buf, decoded, decoded_size))) + if ((res_size == decoded_size) && (0 != decoded_size) + && (0 != memcmp (buf, decoded, decoded_size))) { check_res = 1; fprintf (stderr, @@ -1002,13 +1002,13 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, n_prnt (encoded, encoded_len), n_prnt (buf, res_size), is_broken ? "true" : "false", - (unsigned) res_size); + (unsigned)res_size); fprintf (stderr, "\tEXPECTED: mhd_str_pct_decode_in_place_lenient (\"%s\" " "-> \"%s\", ->true) -> %u\n", n_prnt (encoded, encoded_len), n_prnt (decoded, decoded_size), - (unsigned) decoded_size); + (unsigned)decoded_size); } } } @@ -1022,7 +1022,7 @@ expect_decoded_bad_n (const char *const encoded, const size_t encoded_len, } -#define expect_decoded_bad(e,d) \ +#define expect_decoded_bad(e, d) \ expect_decoded_bad_n (e,MHD_STATICSTR_LEN_ (e), \ d,MHD_STATICSTR_LEN_ (d), \ __LINE__) @@ -1052,11 +1052,12 @@ int main (int argc, char *argv[]) { unsigned int errcount = 0; - (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silent compiler warning. */ errcount += check_decode_str (); errcount += check_decode_bin (); errcount += check_decode_bad_str (); if (0 == errcount) printf ("All tests have been passed without errors.\n"); - return errcount == 0 ? 0 : 1; + return (errcount == 0) ? 0 : 1; } diff --git a/src/tests/unit/unit_str_quote.c b/src/tests/unit/unit_str_quote.c @@ -38,7 +38,7 @@ /** * Determine length of static string / macro strings at compile time. */ -#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) +# define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! MHD_STATICSTR_LEN_ */ @@ -85,17 +85,17 @@ expect_result_unquote_n (const char *const quoted, const size_t quoted_len, fprintf (stderr, "\tRESULT : mhd_str_unquote('%.*s', %u, ->'%.*s') -> %u\n" "\tEXPECTED: mhd_str_unquote('%.*s', %u, ->'%.*s') -> %u\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) res_len, buf, (unsigned) res_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)res_len, buf, (unsigned)res_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); } /* Second check: mhd_str_equal_quoted_bin_n () */ ret2 = 0; - if (! mhd_str_equal_quoted_bin_n (quoted, quoted_len, unquoted, unquoted_len)) + if (!mhd_str_equal_quoted_bin_n (quoted, quoted_len, unquoted, unquoted_len)) { fprintf (stderr, "'mhd_str_equal_quoted_bin_n ()' FAILED: Wrong result:\n"); @@ -105,10 +105,10 @@ expect_result_unquote_n (const char *const quoted, const size_t quoted_len, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret2 = 1; @@ -116,10 +116,10 @@ expect_result_unquote_n (const char *const quoted, const size_t quoted_len, /* Third check: mhd_str_equal_caseless_quoted_bin_n () */ ret3 = 0; - if (! mhd_str_equal_caseless_quoted_bin_n (quoted, - quoted_len, - unquoted, - unquoted_len)) + if (!mhd_str_equal_caseless_quoted_bin_n (quoted, + quoted_len, + unquoted, + unquoted_len)) { fprintf (stderr, "'mhd_str_equal_caseless_quoted_bin_n ()' FAILED: Wrong result:\n") @@ -130,10 +130,10 @@ expect_result_unquote_n (const char *const quoted, const size_t quoted_len, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_caseless_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret3 = 1; @@ -161,11 +161,11 @@ expect_result_unquote_n (const char *const quoted, const size_t quoted_len, fprintf (stderr, "\tRESULT : mhd_str_quote('%.*s', %u, ->'%.*s', %u) -> %u\n" "\tEXPECTED: mhd_str_quote('%.*s', %u, ->'%.*s', %u) -> %u\n", - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) res_len, buf, (unsigned) quoted_len, (unsigned) res_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (unsigned) unquoted_len); + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)res_len, buf, (unsigned)quoted_len, (unsigned)res_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); } @@ -174,7 +174,7 @@ expect_result_unquote_n (const char *const quoted, const size_t quoted_len, } -#define expect_result_unquote(q,u) \ +#define expect_result_unquote(q, u) \ expect_result_unquote_n (q,MHD_STATICSTR_LEN_ (q), \ u,MHD_STATICSTR_LEN_ (u),__LINE__) @@ -235,11 +235,11 @@ expect_result_quote_failed_n (const char *const unquoted, fprintf (stderr, "\tRESULT : mhd_str_quote('%.*s', %u, ->'%.*s', %u) -> %u\n" "\tEXPECTED: mhd_str_quote('%.*s', %u, (not checked), %u) -> 0\n", - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) res_len, buf, - (unsigned) buf_size, (unsigned) res_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (unsigned) buf_size); + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)res_len, buf, + (unsigned)buf_size, (unsigned)res_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (unsigned)buf_size); fprintf (stderr, "The check is at line: %u\n\n", line_num); } @@ -248,7 +248,7 @@ expect_result_quote_failed_n (const char *const unquoted, } -#define expect_result_quote_failed(q,s) \ +#define expect_result_quote_failed(q, s) \ expect_result_quote_failed_n (q,MHD_STATICSTR_LEN_ (q), \ s,__LINE__) @@ -303,10 +303,10 @@ expect_match_caseless_n (const char *const quoted, const size_t quoted_len, /* The check: mhd_str_equal_caseless_quoted_bin_n () */ ret3 = 0; - if (! mhd_str_equal_caseless_quoted_bin_n (quoted, - quoted_len, - unquoted, - unquoted_len)) + if (!mhd_str_equal_caseless_quoted_bin_n (quoted, + quoted_len, + unquoted, + unquoted_len)) { fprintf (stderr, "'mhd_str_equal_caseless_quoted_bin_n ()' FAILED: Wrong result:\n") @@ -317,10 +317,10 @@ expect_match_caseless_n (const char *const quoted, const size_t quoted_len, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_caseless_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret3 = 1; @@ -330,7 +330,7 @@ expect_match_caseless_n (const char *const quoted, const size_t quoted_len, } -#define expect_match_caseless(q,u) \ +#define expect_match_caseless(q, u) \ expect_match_caseless_n (q,MHD_STATICSTR_LEN_ (q), \ u,MHD_STATICSTR_LEN_ (u),__LINE__) @@ -392,9 +392,9 @@ expect_result_invalid_n (const char *const quoted, const size_t quoted_len, fprintf (stderr, "\tRESULT : mhd_str_unquote('%.*s', %u, (not checked)) -> %u\n" "\tEXPECTED: mhd_str_unquote('%.*s', %u, (not checked)) -> 0\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (unsigned) res_len, - (int) quoted_len, quoted, (unsigned) quoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (unsigned)res_len, + (int)quoted_len, quoted, (unsigned)quoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); } @@ -448,10 +448,10 @@ expect_result_unmatch_n (const char *const quoted, const size_t quoted_len, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret2 = 1; @@ -471,10 +471,10 @@ expect_result_unmatch_n (const char *const quoted, const size_t quoted_len, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_caseless_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret3 = 1; @@ -484,7 +484,7 @@ expect_result_unmatch_n (const char *const quoted, const size_t quoted_len, } -#define expect_result_unmatch(q,u) \ +#define expect_result_unmatch(q, u) \ expect_result_unmatch_n (q,MHD_STATICSTR_LEN_ (q), \ u,MHD_STATICSTR_LEN_ (u),__LINE__) @@ -625,10 +625,10 @@ expect_result_case_unmatch_n (const char *const quoted, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret2 = 1; @@ -638,7 +638,7 @@ expect_result_case_unmatch_n (const char *const quoted, } -#define expect_result_case_unmatch(q,u) \ +#define expect_result_case_unmatch(q, u) \ expect_result_case_unmatch_n (q,MHD_STATICSTR_LEN_ (q), \ u,MHD_STATICSTR_LEN_ (u),__LINE__) @@ -695,10 +695,10 @@ expect_result_caseless_unmatch_n (const char *const quoted, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret2 = 1; @@ -720,10 +720,10 @@ expect_result_caseless_unmatch_n (const char *const quoted, "'%.*s', %u) -> true\n" "\tEXPECTED: mhd_str_equal_caseless_quoted_bin_n('%.*s', %u, " "'%.*s', %u) -> false\n", - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len, - (int) quoted_len, quoted, (unsigned) quoted_len, - (int) unquoted_len, unquoted, (unsigned) unquoted_len); + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len, + (int)quoted_len, quoted, (unsigned)quoted_len, + (int)unquoted_len, unquoted, (unsigned)unquoted_len); fprintf (stderr, "The check is at line: %u\n\n", line_num); ret3 = 1; @@ -733,7 +733,7 @@ expect_result_caseless_unmatch_n (const char *const quoted, } -#define expect_result_caseless_unmatch(q,u) \ +#define expect_result_caseless_unmatch(q, u) \ expect_result_caseless_unmatch_n (q,MHD_STATICSTR_LEN_ (q), \ u,MHD_STATICSTR_LEN_ (u),__LINE__) @@ -799,7 +799,8 @@ int main (int argc, char *argv[]) { unsigned int errcount = 0; - (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silent compiler warning. */ errcount += check_match (); errcount += check_quote_failed (); errcount += check_match_caseless (); @@ -809,5 +810,5 @@ main (int argc, char *argv[]) errcount += check_unmatch_caseless (); if (0 == errcount) printf ("All tests were passed without errors.\n"); - return errcount == 0 ? 0 : 1; + return (errcount == 0) ? 0 : 1; } diff --git a/src/tests/unit/unit_str_to_value.c b/src/tests/unit/unit_str_to_value.c @@ -29,15 +29,15 @@ #include <locale.h> #include <string.h> #ifdef HAVE_INTTYPES_H -#include <inttypes.h> +# include <inttypes.h> #else /* ! HAVE_INTTYPES_H */ -#define PRIuFAST64 "llu" -#define PRIuPTR "llu" -#define PRIXFAST64 "llX" +# define PRIuFAST64 "llu" +# define PRIuPTR "llu" +# define PRIXFAST64 "llX" #endif /* ! HAVE_INTTYPES_H */ #include <stdint.h> #ifdef HAVE_STDLIB_H -#include <stdlib.h> +# include <stdlib.h> #endif /* HAVE_STDLIB_H */ #include "mhd_str.h" @@ -56,7 +56,7 @@ static int verbose = 0; /* verbose level (0-3)*/ static const char *const locale_names[] = { "C", "", /* System default locale */ -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) ".OCP", /* W32 system default OEM code page */ ".ACP", /* W32 system default ANSI code page */ ".65001", /* UTF-8 */ @@ -74,7 +74,7 @@ static const char *const locale_names[] = { "de", "zh-Hans", "ru-RU.1251" -#if 0 /* Disabled extra checks */ +# if 0 /* Disabled extra checks */ , ".1254", ".20866", /* number for KOI8-R */ @@ -127,7 +127,7 @@ static const char *const locale_names[] = { "Russian_Russia.65001", "zh-Hans.936", "chinese-simplified" -#endif /* Disabled extra checks */ +# endif /* Disabled extra checks */ #else /* ! _WIN32 || __CYGWIN__ */ "C.UTF-8", "POSIX", @@ -257,7 +257,7 @@ n_prnt (const char *str) { static char *buf; /* should be enough for testing */ static const size_t buf_size = sizeof(tmp_bufs[0]); - const unsigned char *p = (const unsigned char *) str; + const unsigned char *p = (const unsigned char *)str; size_t w_pos = 0; if (++buf_idx > 3) buf_idx = 0; @@ -266,21 +266,21 @@ n_prnt (const char *str) while (*p && w_pos + 1 < buf_size) { const unsigned char c = *p; - if ((c == '\\') || (c == '"') ) + if ((c == '\\') || (c == '"')) { if (w_pos + 2 >= buf_size) break; buf[w_pos++] = '\\'; - buf[w_pos++] = (char) c; + buf[w_pos++] = (char)c; } - else if ((c >= 0x20) && (c <= 0x7E) ) - buf[w_pos++] = (char) c; + else if ((c >= 0x20) && (c <= 0x7E)) + buf[w_pos++] = (char)c; else { if (w_pos + 4 >= buf_size) break; if (snprintf (buf + w_pos, buf_size - w_pos, "\\x%02hX", (short unsigned - int) c) != 4) + int)c) != 4) break; w_pos += 4; } @@ -603,8 +603,10 @@ check_str_to_uint64_valid (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } @@ -613,19 +615,19 @@ check_str_to_uint64_valid (void) if (rs != t->num_of_digt) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 ") returned %" PRIuPTR ", while expecting %d." - " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } if (rv != t->val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 ") converted string to value %" @@ -634,7 +636,7 @@ check_str_to_uint64_valid (void) n_prnt (t->str.str), rv, rv, t->val, get_current_locale_str ()); } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 ") == %" \ PRIuPTR "\n", n_prnt (t->str.str), rv, rs); @@ -664,42 +666,45 @@ check_str_to_uint64_all_chars (void) { static const uint_fast64_t rnd_val = 24941852; size_t rs; - if ((c >= '0') && (c <= '9') ) + if ((c >= '0') && (c <= '9')) continue; /* skip digits */ - for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += rnd_val) { char test_str[] = "0123"; uint_fast64_t rv = test_val; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ rs = mhd_str_to_uint64 (test_str, &rv); if (rs != 0) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t) rs, + " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", &ret_val) modified value of ret_val" " (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 "). Locale: %s\n", - n_prnt (test_str), test_val, rv, get_current_locale_str ()); + n_prnt (test_str), + test_val, + rv, + get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) { char test_str[] = "0123"; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ printf ("PASSED: mhd_str_to_uint64(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", @@ -731,7 +736,7 @@ check_str_to_uint64_overflow (void) static const uint_fast64_t rnd_val = 2; uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -740,26 +745,29 @@ check_str_to_uint64_overflow (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, + " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", &ret_val) modified value of ret_val" " (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 "). Locale: %s\n", - n_prnt (t->str), test_val, rv, get_current_locale_str ()); + n_prnt (t->str), + test_val, + rv, + get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_to_uint64(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", n_prnt (t->str)); @@ -789,7 +797,7 @@ check_str_to_uint64_no_val (void) static const uint_fast64_t rnd_val = 74218431; uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -798,26 +806,29 @@ check_str_to_uint64_no_val (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", ->%" PRIuFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, + " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64(\"%s\", &ret_val) modified value of ret_val" " (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 "). Locale: %s\n", - n_prnt (t->str), test_val, rv, get_current_locale_str ()); + n_prnt (t->str), + test_val, + rv, + get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_to_uint64(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", n_prnt (t->str)); @@ -853,45 +864,47 @@ check_str_to_uint64_n_valid (void) fprintf (stderr, "ERROR: dstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } - for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++) + for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) { rs = mhd_str_to_uint64_n (t->str.str, len, &rv); if (rs != t->num_of_digt) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" PRIuFAST64 ")" " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", - n_prnt (t->str.str), (uintptr_t) len, rv, (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + n_prnt (t->str.str), (uintptr_t)len, rv, (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } if (rv != t->val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" PRIuFAST64 ")" " converted string to value %" PRIuFAST64 ", while expecting result %" PRIuFAST64 - ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t) len, rv, + ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t)len, rv, rv, t->val, get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->%" PRIuFAST64 ")" " == %" PRIuPTR "\n", n_prnt (t->str.str), - (uintptr_t) t->num_of_digt, - (uintptr_t) t->str.len + 1, rv, rs); + (uintptr_t)t->num_of_digt, + (uintptr_t)t->str.len + 1, rv, rs); } } return t_failed; @@ -920,50 +933,50 @@ check_str_to_uint64_n_all_chars (void) size_t rs; size_t len; - if ((c >= '0') && (c <= '9') ) + if ((c >= '0') && (c <= '9')) continue; /* skip digits */ for (len = 0; len <= 5; len++) { - for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += rnd_val) { char test_str[] = "0123"; uint_fast64_t rv = test_val; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ rs = mhd_str_to_uint64_n (test_str, len, &rv); if (rs != 0) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" PRIuFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (test_str), (uintptr_t) len, rv, (uintptr_t) rs, + n_prnt (test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 ")." " Locale: %s\n", - n_prnt (test_str), (uintptr_t) len, test_val, rv, + n_prnt (test_str), (uintptr_t)len, test_val, rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) { char test_str[] = "0123"; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ printf ("PASSED: mhd_str_to_uint64_n(\"%s\", 0..5, &ret_val) == 0, " "value of ret_val is unmodified\n", @@ -998,7 +1011,7 @@ check_str_to_uint64_n_overflow (void) for (len = t->len; len <= t->len + 1; len++) { uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -1007,36 +1020,36 @@ check_str_to_uint64_n_overflow (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" PRIuFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, + n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 ")." - " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, + " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, test_val, rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," " value of ret_val is unmodified\n", n_prnt (t->str), - (uintptr_t) t->len, - (uintptr_t) t->len + 1); + (uintptr_t)t->len, + (uintptr_t)t->len + 1); } } return t_failed; @@ -1066,7 +1079,7 @@ check_str_to_uint64_n_no_val (void) for (len = 0; len <= t->len + 1; len++) { uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -1075,35 +1088,35 @@ check_str_to_uint64_n_no_val (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", ->%" PRIuFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, + n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_str_to_uint64_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: %" PRIuFAST64 ", after call %" PRIuFAST64 ")." - " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, + " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, test_val, rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_str_to_uint64_n(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," " value of ret_val is unmodified\n", n_prnt (t->str), - (uintptr_t) t->len + 1); + (uintptr_t)t->len + 1); } } return t_failed; @@ -1130,7 +1143,7 @@ check_strx_to_uint32_valid (void) size_t rs; const struct str_with_value *const t = xdstrs_w_values + i; - if (t->val != (uint_fast32_t) t->val) + if (t->val != (uint_fast32_t)t->val) continue; /* number is too high for this function */ if (c_failed[i]) @@ -1141,8 +1154,10 @@ check_strx_to_uint32_valid (void) fprintf (stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } @@ -1151,33 +1166,33 @@ check_strx_to_uint32_valid (void) if (rs != t->num_of_digt) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR " digits, while expecting %d." " Locale: %s\n", - n_prnt (t->str.str), (uint_fast64_t) rv, - (uintptr_t) rs, - (int) t->num_of_digt, + n_prnt (t->str.str), (uint_fast64_t)rv, + (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } if (rv != t->val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 ") converted string to value 0x%" PRIXFAST64 "," " while expecting result 0x%" PRIXFAST64 ". Locale: %s\n", - n_prnt (t->str.str), (uint_fast64_t) rv, (uint_fast64_t) rv, + n_prnt (t->str.str), (uint_fast64_t)rv, (uint_fast64_t)rv, t->val, get_current_locale_str ()); } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 ") == %" PRIuPTR "\n", - n_prnt (t->str.str), (uint_fast64_t) rv, rs); + n_prnt (t->str.str), (uint_fast64_t)rv, rs); } } return t_failed; @@ -1204,46 +1219,47 @@ check_strx_to_uint32_all_chars (void) { static const uint_fast32_t rnd_val = 234234; size_t rs; - if (( (c >= '0') && (c <= '9') ) - || ( (c >= 'A') && (c <= 'F') ) - || ( (c >= 'a') && (c <= 'f') )) + if (((c >= '0') && (c <= '9')) + || ((c >= 'A') && (c <= 'F')) + || ((c >= 'a') && (c <= 'f'))) continue; /* skip xdigits */ - for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += rnd_val) { char test_str[] = "0123"; uint_fast32_t rv = test_val; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ rs = mhd_strx_to_uint32 (test_str, &rv); if (rs != 0) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR " digits, while expecting zero." - " Locale: %s\n", n_prnt (test_str), (uint_fast64_t) rv, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", n_prnt (test_str), (uint_fast64_t)rv, + (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", &ret_val) modified value of ret_val" " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 "). Locale: %s\n", - n_prnt (test_str), (uint_fast64_t) test_val, - (uint_fast64_t) rv, + n_prnt (test_str), + (uint_fast64_t)test_val, + (uint_fast64_t)rv, get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) { char test_str[] = "0123"; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ printf ("PASSED: mhd_strx_to_uint32(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", @@ -1286,13 +1302,13 @@ check_strx_to_uint32_overflow (void) { const struct str_with_value *const t = xdstrs_w_values + (i - n_checks1); - if (t->val == (uint_fast32_t) t->val) + if (t->val == (uint_fast32_t)t->val) continue; /* check only strings that should overflow uint_fast32_t */ str = t->str.str; } - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast32_t rv = test_val; @@ -1301,28 +1317,30 @@ check_strx_to_uint32_overflow (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (str), (uint_fast64_t) rv, - (uintptr_t) rs, + " Locale: %s\n", n_prnt (str), (uint_fast64_t)rv, + (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", &ret_val) modified value of ret_val" " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 "). Locale: %s\n", - n_prnt (str), (uint_fast64_t) test_val, (uint_fast64_t) rv, + n_prnt (str), + (uint_fast64_t)test_val, + (uint_fast64_t)rv, get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint32(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", n_prnt (str)); @@ -1352,7 +1370,7 @@ check_strx_to_uint32_no_val (void) static const uint_fast32_t rnd_val = 74218431; uint_fast32_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast32_t rv = test_val; @@ -1361,28 +1379,29 @@ check_strx_to_uint32_no_val (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (t->str), (uint_fast64_t) rv, - (uintptr_t) rs, get_current_locale_str ()); + " Locale: %s\n", n_prnt (t->str), (uint_fast64_t)rv, + (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32(\"%s\", &ret_val) modified value of ret_val" " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 "). Locale: %s\n", - n_prnt (t->str), (uint_fast64_t) test_val, - (uint_fast64_t) rv, + n_prnt (t->str), + (uint_fast64_t)test_val, + (uint_fast64_t)rv, get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint32(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", n_prnt (t->str)); @@ -1413,7 +1432,7 @@ check_strx_to_uint32_n_valid (void) size_t len; const struct str_with_value *const t = xdstrs_w_values + i; - if (t->val != (uint_fast32_t) t->val) + if (t->val != (uint_fast32_t)t->val) continue; /* number is too high for this function */ if (t->str.len < t->num_of_digt) @@ -1421,48 +1440,50 @@ check_strx_to_uint32_n_valid (void) fprintf (stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } - for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++) + for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) { rs = mhd_strx_to_uint32_n (t->str.str, len, &rv); if (rs != t->num_of_digt) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", - n_prnt (t->str.str), (uintptr_t) len, (uint_fast64_t) rv, - (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + n_prnt (t->str.str), (uintptr_t)len, (uint_fast64_t)rv, + (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } if (rv != t->val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " converted string to value 0x%" PRIXFAST64 ", while expecting result 0x%" PRIXFAST64 - ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t) len, - (uint_fast64_t) rv, (uint_fast64_t) rv, + ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t)len, + (uint_fast64_t)rv, (uint_fast64_t)rv, t->val, get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ( "PASSED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIXFAST64 ")" " == %" PRIuPTR "\n", n_prnt (t->str.str), - (uintptr_t) t->num_of_digt, - (uintptr_t) t->str.len + 1, (uint_fast64_t) rv, rs); + (uintptr_t)t->num_of_digt, + (uintptr_t)t->str.len + 1, (uint_fast64_t)rv, rs); } } return t_failed; @@ -1491,54 +1512,54 @@ check_strx_to_uint32_n_all_chars (void) size_t rs; size_t len; - if (( (c >= '0') && (c <= '9') ) - || ( (c >= 'A') && (c <= 'F') ) - || ( (c >= 'a') && (c <= 'f') )) + if (((c >= '0') && (c <= '9')) + || ((c >= 'A') && (c <= 'F')) + || ((c >= 'a') && (c <= 'f'))) continue; /* skip xdigits */ for (len = 0; len <= 5; len++) { - for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += rnd_val) { char test_str[] = "0123"; uint_fast32_t rv = test_val; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ rs = mhd_strx_to_uint32_n (test_str, len, &rv); if (rs != 0) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (test_str), (uintptr_t) len, (uint_fast64_t) rv, - (uintptr_t) rs, get_current_locale_str ()); + n_prnt (test_str), (uintptr_t)len, (uint_fast64_t)rv, + (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 ")." " Locale: %s\n", - n_prnt (test_str), (uintptr_t) len, - (uint_fast64_t) test_val, - (uint_fast64_t) rv, get_current_locale_str ()); + n_prnt (test_str), (uintptr_t)len, + (uint_fast64_t)test_val, + (uint_fast64_t)rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) { char test_str[] = "0123"; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ printf ("PASSED: mhd_strx_to_uint32_n(\"%s\", 0..5, &ret_val) == 0, " "value of ret_val is unmodified\n", @@ -1584,7 +1605,7 @@ check_strx_to_uint32_n_overflow (void) { const struct str_with_value *const t = xdstrs_w_values + (i - n_checks1); - if (t->val == (uint_fast32_t) t->val) + if (t->val == (uint_fast32_t)t->val) continue; /* check only strings that should overflow uint_fast32_t */ if (t->str.len < t->num_of_digt) @@ -1592,9 +1613,10 @@ check_strx_to_uint32_n_overflow (void) fprintf (stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) (i - n_checks1), (unsigned - int) t->num_of_digt, - (unsigned int) t->str.len); + (unsigned int)(i - n_checks1), + (unsigned + int)t->num_of_digt, + (unsigned int)t->str.len); exit (99); } str = t->str.str; @@ -1605,7 +1627,7 @@ check_strx_to_uint32_n_overflow (void) for (len = min_len; len <= max_len; len++) { uint_fast32_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast32_t rv = test_val; @@ -1614,37 +1636,37 @@ check_strx_to_uint32_n_overflow (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (str), (uintptr_t) len, (uint_fast64_t) rv, - (uintptr_t) rs, get_current_locale_str ()); + n_prnt (str), (uintptr_t)len, (uint_fast64_t)rv, + (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 ")." - " Locale: %s\n", n_prnt (str), (uintptr_t) len, - (uint_fast64_t) test_val, (uint_fast64_t) rv, + " Locale: %s\n", n_prnt (str), (uintptr_t)len, + (uint_fast64_t)test_val, (uint_fast64_t)rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," " value of ret_val is unmodified\n", n_prnt (str), - (uintptr_t) min_len, - (uintptr_t) max_len); + (uintptr_t)min_len, + (uintptr_t)max_len); } } return t_failed; @@ -1674,7 +1696,7 @@ check_strx_to_uint32_n_no_val (void) for (len = 0; len <= t->len + 1; len++) { uint_fast32_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast32_t rv = test_val; @@ -1683,36 +1705,36 @@ check_strx_to_uint32_n_no_val (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (t->str), (uintptr_t) len, (uint_fast64_t) rv, - (uintptr_t) rs, get_current_locale_str ()); + n_prnt (t->str), (uintptr_t)len, (uint_fast64_t)rv, + (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint32_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 ")." - " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, - (uint_fast64_t) test_val, (uint_fast64_t) rv, + " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, + (uint_fast64_t)test_val, (uint_fast64_t)rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint32_n(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," " value of ret_val is unmodified\n", n_prnt (t->str), - (uintptr_t) t->len + 1); + (uintptr_t)t->len + 1); } } return t_failed; @@ -1747,8 +1769,10 @@ check_strx_to_uint64_valid (void) fprintf (stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } @@ -1757,18 +1781,18 @@ check_strx_to_uint64_valid (void) if (rs != t->num_of_digt) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR ", while expecting %d." - " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + " Locale: %s\n", n_prnt (t->str.str), rv, (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } if (rv != t->val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 ") converted string to value 0x%" @@ -1777,7 +1801,7 @@ check_strx_to_uint64_valid (void) n_prnt (t->str.str), rv, rv, t->val, get_current_locale_str ()); } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 ") == %" PRIuPTR "\n", n_prnt (t->str.str), rv, rs); @@ -1807,44 +1831,47 @@ check_strx_to_uint64_all_chars (void) { static const uint_fast64_t rnd_val = 234234; size_t rs; - if (( (c >= '0') && (c <= '9') ) - || ( (c >= 'A') && (c <= 'F') ) - || ( (c >= 'a') && (c <= 'f') )) + if (((c >= '0') && (c <= '9')) + || ((c >= 'A') && (c <= 'F')) + || ((c >= 'a') && (c <= 'f'))) continue; /* skip xdigits */ - for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += rnd_val) { char test_str[] = "0123"; uint_fast64_t rv = test_val; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ rs = mhd_strx_to_uint64 (test_str, &rv); if (rs != 0) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t) rs, + " Locale: %s\n", n_prnt (test_str), rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", &ret_val) modified value of ret_val" " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 "). Locale: %s\n", - n_prnt (test_str), test_val, rv, get_current_locale_str ()); + n_prnt (test_str), + test_val, + rv, + get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) { char test_str[] = "0123"; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ printf ("PASSED: mhd_strx_to_uint64(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", @@ -1876,7 +1903,7 @@ check_strx_to_uint64_overflow (void) static const uint_fast64_t rnd_val = 74218431; uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -1885,26 +1912,29 @@ check_strx_to_uint64_overflow (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, + " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", &ret_val) modified value of ret_val" " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 "). Locale: %s\n", - n_prnt (t->str), test_val, rv, get_current_locale_str ()); + n_prnt (t->str), + test_val, + rv, + get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint64(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", n_prnt (t->str)); @@ -1934,7 +1964,7 @@ check_strx_to_uint64_no_val (void) static const uint_fast64_t rnd_val = 74218431; uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -1943,26 +1973,29 @@ check_strx_to_uint64_no_val (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", ->0x%" PRIXFAST64 ") returned %" PRIuPTR ", while expecting zero." - " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t) rs, + " Locale: %s\n", n_prnt (t->str), rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64(\"%s\", &ret_val) modified value of ret_val" " (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 "). Locale: %s\n", - n_prnt (t->str), test_val, rv, get_current_locale_str ()); + n_prnt (t->str), + test_val, + rv, + get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint64(\"%s\", &ret_val) == 0, " "value of ret_val is unmodified\n", n_prnt (t->str)); @@ -1997,46 +2030,48 @@ check_strx_to_uint64_n_valid (void) fprintf (stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected" " to be less or equal to str.len (%u).\n", - (unsigned int) i, (unsigned int) t->num_of_digt, (unsigned - int) t->str. + (unsigned int)i, + (unsigned int)t->num_of_digt, + (unsigned + int)t->str. len); exit (99); } - for (len = t->num_of_digt; len <= t->str.len + 1 && ! c_failed[i]; len++) + for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++) { rs = mhd_strx_to_uint64_n (t->str.str, len, &rv); if (rs != t->num_of_digt) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting %d. Locale: %s\n", - n_prnt (t->str.str), (uintptr_t) len, rv, (uintptr_t) rs, - (int) t->num_of_digt, get_current_locale_str ()); + n_prnt (t->str.str), (uintptr_t)len, rv, (uintptr_t)rs, + (int)t->num_of_digt, get_current_locale_str ()); } if (rv != t->val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " converted string to value 0x%" PRIXFAST64 ", while expecting result 0x%" PRIXFAST64 - ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t) len, rv, + ". Locale: %s\n", n_prnt (t->str.str), (uintptr_t)len, rv, rv, t->val, get_current_locale_str ()); } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIXFAST64 ")" " == %" PRIuPTR "\n", n_prnt (t->str.str), - (uintptr_t) t->num_of_digt, - (uintptr_t) t->str.len + 1, rv, rs); + (uintptr_t)t->num_of_digt, + (uintptr_t)t->str.len + 1, rv, rs); } } return t_failed; @@ -2065,53 +2100,53 @@ check_strx_to_uint64_n_all_chars (void) size_t rs; size_t len; - if (( (c >= '0') && (c <= '9') ) - || ( (c >= 'A') && (c <= 'F') ) - || ( (c >= 'a') && (c <= 'f') )) + if (((c >= '0') && (c <= '9')) + || ((c >= 'A') && (c <= 'F')) + || ((c >= 'a') && (c <= 'f'))) continue; /* skip xdigits */ for (len = 0; len <= 5; len++) { - for (test_val = 0; test_val <= rnd_val && ! c_failed[c]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[c]; test_val += rnd_val) { char test_str[] = "0123"; uint_fast64_t rv = test_val; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ rs = mhd_strx_to_uint64_n (test_str, len, &rv); if (rs != 0) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (test_str), (uintptr_t) len, rv, (uintptr_t) rs, + n_prnt (test_str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[c] = ! 0; + c_failed[c] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 ")." " Locale: %s\n", - n_prnt (test_str), (uintptr_t) len, test_val, rv, + n_prnt (test_str), (uintptr_t)len, test_val, rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[c]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[c]) { char test_str[] = "0123"; - test_str[0] = (char) (unsigned char) c; /* replace first char with non-digit char */ + test_str[0] = (char)(unsigned char)c; /* replace first char with non-digit char */ printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", 0..5, &ret_val) == 0, " "value of ret_val is unmodified\n", @@ -2146,7 +2181,7 @@ check_strx_to_uint64_n_overflow (void) for (len = t->len; len <= t->len + 1; len++) { uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -2155,37 +2190,37 @@ check_strx_to_uint64_n_overflow (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, + n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 ")." - " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, + " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, test_val, rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0," " value of ret_val is unmodified\n", n_prnt (t->str), - (uintptr_t) t->len, - (uintptr_t) t->len + 1); + (uintptr_t)t->len, + (uintptr_t)t->len + 1); } } return t_failed; @@ -2215,7 +2250,7 @@ check_strx_to_uint64_n_no_val (void) for (len = 0; len <= t->len + 1; len++) { uint_fast64_t test_val; - for (test_val = 0; test_val <= rnd_val && ! c_failed[i]; test_val += + for (test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val) { uint_fast64_t rv = test_val; @@ -2224,36 +2259,36 @@ check_strx_to_uint64_n_no_val (void) if (rs != 0) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", ->0x%" PRIXFAST64 ")" " returned %" PRIuPTR ", while expecting zero. Locale: %s\n", - n_prnt (t->str), (uintptr_t) len, rv, (uintptr_t) rs, + n_prnt (t->str), (uintptr_t)len, rv, (uintptr_t)rs, get_current_locale_str ()); } else if (rv != test_val) { t_failed++; - c_failed[i] = ! 0; + c_failed[i] = !0; fprintf (stderr, "FAILED: mhd_strx_to_uint64_n(\"%s\", %" PRIuPTR ", &ret_val)" " modified value of ret_val (before call: 0x%" PRIXFAST64 ", after call 0x%" PRIXFAST64 ")." - " Locale: %s\n", n_prnt (t->str), (uintptr_t) len, + " Locale: %s\n", n_prnt (t->str), (uintptr_t)len, test_val, rv, get_current_locale_str ()); } } } - if ((verbose > 1) && (j == locale_name_count - 1) && ! c_failed[i]) + if ((verbose > 1) && (j == locale_name_count - 1) && !c_failed[i]) printf ("PASSED: mhd_strx_to_uint64_n(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0," " value of ret_val is unmodified\n", n_prnt (t->str), - (uintptr_t) t->len + 1); + (uintptr_t)t->len + 1); } } return t_failed; @@ -2318,7 +2353,7 @@ run_str_to_X_tests (void) if (str_to_uint64_fails) fprintf (stderr, "FAILED: function mhd_str_to_uint64() failed %lu time%s.\n\n", - (unsigned long) str_to_uint64_fails, + (unsigned long)str_to_uint64_fails, str_to_uint64_fails == 1 ? "" : "s"); else if (verbose > 0) printf ("PASSED: function mhd_str_to_uint64() successfully " @@ -2371,7 +2406,7 @@ run_str_to_X_tests (void) if (str_to_uint64_n_fails) fprintf (stderr, "FAILED: function mhd_str_to_uint64_n() failed %lu time%s.\n\n", - (unsigned long) str_to_uint64_n_fails, + (unsigned long)str_to_uint64_n_fails, str_to_uint64_n_fails == 1 ? "" : "s"); else if (verbose > 0) printf ("PASSED: function mhd_str_to_uint64_n() successfully " @@ -2424,7 +2459,7 @@ run_str_to_X_tests (void) if (strx_to_uint32_fails) fprintf (stderr, "FAILED: function mhd_strx_to_uint32() failed %lu time%s.\n\n", - (unsigned long) strx_to_uint32_fails, + (unsigned long)strx_to_uint32_fails, strx_to_uint32_fails == 1 ? "" : "s"); else if (verbose > 0) printf ("PASSED: function mhd_strx_to_uint32() successfully " @@ -2477,7 +2512,7 @@ run_str_to_X_tests (void) if (strx_to_uint32_n_fails) fprintf (stderr, "FAILED: function mhd_strx_to_uint32_n() failed %lu time%s.\n\n", - (unsigned long) strx_to_uint32_n_fails, + (unsigned long)strx_to_uint32_n_fails, strx_to_uint32_n_fails == 1 ? "" : "s"); else if (verbose > 0) printf ("PASSED: function mhd_strx_to_uint32_n() successfully " @@ -2530,7 +2565,7 @@ run_str_to_X_tests (void) if (strx_to_uint64_fails) fprintf (stderr, "FAILED: function mhd_strx_to_uint64() failed %lu time%s.\n\n", - (unsigned long) strx_to_uint64_fails, + (unsigned long)strx_to_uint64_fails, strx_to_uint64_fails == 1 ? "" : "s"); else if (verbose > 0) printf ("PASSED: function mhd_strx_to_uint64() successfully " @@ -2583,15 +2618,15 @@ run_str_to_X_tests (void) if (strx_to_uint64_n_fails) fprintf (stderr, "FAILED: function mhd_strx_to_uint64_n() failed %lu time%s.\n\n", - (unsigned long) strx_to_uint64_n_fails, + (unsigned long)strx_to_uint64_n_fails, strx_to_uint64_n_fails == 1 ? "" : "s"); else if (verbose > 0) printf ("PASSED: function mhd_strx_to_uint64_n() successfully " "passed all checks.\n\n"); - if (str_to_uint64_fails || str_to_uint64_n_fails || - strx_to_uint32_fails || strx_to_uint32_n_fails || - strx_to_uint64_fails || strx_to_uint64_n_fails) + if (str_to_uint64_fails || str_to_uint64_n_fails + || strx_to_uint32_fails || strx_to_uint32_n_fails + || strx_to_uint64_fails || strx_to_uint64_n_fails) { if (verbose > 0) printf ("At least one test failed.\n"); @@ -2609,12 +2644,12 @@ run_str_to_X_tests (void) int main (int argc, char *argv[]) { - if (mhdt_has_param (argc, argv, "-v") || - mhdt_has_param (argc, argv, "--verbose") || - mhdt_has_param (argc, argv, "--verbose1")) + if (mhdt_has_param (argc, argv, "-v") + || mhdt_has_param (argc, argv, "--verbose") + || mhdt_has_param (argc, argv, "--verbose1")) MHDT_set_verbosity (MHDT_VERB_LVL_BASIC); - if (mhdt_has_param (argc, argv, "-vv") || - mhdt_has_param (argc, argv, "--verbose2")) + if (mhdt_has_param (argc, argv, "-vv") + || mhdt_has_param (argc, argv, "--verbose2")) MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); return run_str_to_X_tests (); diff --git a/src/tests/unit/unit_str_token.c b/src/tests/unit/unit_str_token.c @@ -34,25 +34,27 @@ /** * Determine length of static string / macro strings at compile time. */ -#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) +# define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! MHD_STATICSTR_LEN_ */ static int expect_found_n (const char *str, const char *token, size_t token_len) { - if (! mhd_str_has_token_caseless (str, token, token_len)) + if (!mhd_str_has_token_caseless (str, token, token_len)) { fprintf (stderr, "mhd_str_has_token_caseless() FAILED:\n\tmhd_str_has_token_caseless(%s, %s, %lu) return false\n", - str, token, (unsigned long) token_len); + str, + token, + (unsigned long)token_len); return 1; } return 0; } -#define expect_found(s,t) expect_found_n ((s),(t),MHD_STATICSTR_LEN_ (t)) +#define expect_found(s, t) expect_found_n ((s),(t),MHD_STATICSTR_LEN_ (t)) static int expect_not_found_n (const char *str, const char *token, size_t token_len) @@ -61,15 +63,17 @@ expect_not_found_n (const char *str, const char *token, size_t token_len) { fprintf (stderr, "mhd_str_has_token_caseless() FAILED:\n\tmhd_str_has_token_caseless(%s, %s, %lu) return true\n", - str, token, (unsigned long) token_len); + str, + token, + (unsigned long)token_len); return 1; } return 0; } -#define expect_not_found(s,t) expect_not_found_n ((s),(t),MHD_STATICSTR_LEN_ ( \ - t)) +#define expect_not_found(s, t) \ + expect_not_found_n ((s),(t),MHD_STATICSTR_LEN_ (t)) static int check_match (void) @@ -131,8 +135,9 @@ int main (int argc, char *argv[]) { int errcount = 0; - (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silent compiler warning. */ errcount += check_match (); errcount += check_not_match (); - return errcount == 0 ? 0 : 1; + return (errcount == 0) ? 0 : 1; } diff --git a/src/tests/unit/unit_str_token_remove.c b/src/tests/unit/unit_str_token_remove.c @@ -37,7 +37,7 @@ /** * Determine length of static string / macro strings at compile time. */ -#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) +# define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! MHD_STATICSTR_LEN_ */ @@ -67,7 +67,7 @@ expect_result_n (const char *str, size_t str_len, ssize_t result_len; memset (buf_out, '$', sizeof(buf_out)); - result_len = (ssize_t) buf_len; + result_len = (ssize_t)buf_len; mhd_assert (0 <= result_len); res = mhd_str_remove_token_caseless (buf_in, str_len, buf_token, token_len, @@ -80,29 +80,29 @@ expect_result_n (const char *str, size_t str_len, "mhd_str_remove_token_caseless() FAILED:\n" "\tmhd_str_remove_token_caseless(\"%.*s\", %lu," " \"%.*s\", %lu, buf, &(%ld->%ld)) returned %s\n", - (int) str_len + 2, buf_in, (unsigned long) str_len, - (int) token_len + 2, buf_token, (unsigned long) token_len, - (long) buf_len, (long) result_len, res ? "true" : "false"); + (int)str_len + 2, buf_in, (unsigned long)str_len, + (int)token_len + 2, buf_token, (unsigned long)token_len, + (long)buf_len, (long)result_len, res ? "true" : "false"); return 1; } } else { /* The result should fit into the buffer */ - if ( (expected_removed != res) || - (result_len < 0) || - (expected_len != (size_t) result_len) || - ((0 != result_len) && (0 != memcmp (expected, buf_out, - (size_t) result_len))) || - ('$' != buf_out[result_len])) + if ((expected_removed != res) + || (result_len < 0) + || (expected_len != (size_t)result_len) + || ((0 != result_len) && (0 != memcmp (expected, buf_out, + (size_t)result_len))) + || ('$' != buf_out[result_len])) { fprintf (stderr, "mhd_str_remove_token_caseless() FAILED:\n" "\tmhd_str_remove_token_caseless(\"%.*s\", %lu," " \"%.*s\", %lu, \"%.*s\", &(%ld->%ld)) returned %s\n", - (int) str_len + 2, buf_in, (unsigned long) str_len, - (int) token_len + 2, buf_token, (unsigned long) token_len, - (int) expected_len + 2, buf_out, - (long) buf_len, (long) result_len, + (int)str_len + 2, buf_in, (unsigned long)str_len, + (int)token_len + 2, buf_token, (unsigned long)token_len, + (int)expected_len + 2, buf_out, + (long)buf_len, (long)result_len, res ? "true" : "false"); return 1; } @@ -112,7 +112,7 @@ expect_result_n (const char *str, size_t str_len, } -#define expect_result(s,t,e,found) \ +#define expect_result(s, t, e, found) \ expect_result_n ((s),MHD_STATICSTR_LEN_ (s), \ (t),MHD_STATICSTR_LEN_ (t), \ (e),MHD_STATICSTR_LEN_ (e), found) @@ -162,7 +162,7 @@ check_result (void) "a, b, c", true); errcount += expect_result (" the-token , a , the-token , the-token, b ," \ "the-token , c , the-token ", "the-token", - "a, b, c",true); + "a, b, c", true); errcount += expect_result ("the-token,aa, the-token , the-token,bb," \ "the-token , cc,the-token", "the-token", "aa, bb, cc", true); @@ -255,7 +255,8 @@ int main (int argc, char *argv[]) { int errcount = 0; - (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silent compiler warning. */ errcount += check_result (); - return errcount == 0 ? 0 : 1; + return (errcount == 0) ? 0 : 1; } diff --git a/src/tests/unit/unit_str_tokens_remove.c b/src/tests/unit/unit_str_tokens_remove.c @@ -38,7 +38,7 @@ /** * Determine length of static string / macro strings at compile time. */ -#define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) +# define MHD_STATICSTR_LEN_(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! MHD_STATICSTR_LEN_ */ @@ -66,10 +66,10 @@ expect_result_n (const char *str, size_t str_len, res = mhd_str_remove_tokens_caseless (buf_in, &result_len, buf_tokens, tokens_len); - if ( (expected_removed != res) || - (expected_len != result_len) || - ((0 != result_len) && (0 != memcmp (expected, buf_in, result_len))) || - ('$' != buf_in[str_len])) + if ((expected_removed != res) + || (expected_len != result_len) + || ((0 != result_len) && (0 != memcmp (expected, buf_in, result_len))) + || ('$' != buf_in[str_len])) { fprintf (stderr, "mhd_str_remove_tokens_caseless() FAILED:\n" @@ -77,9 +77,9 @@ expect_result_n (const char *str, size_t str_len, "\tmhd_str_remove_token_caseless(\"%s\"->\"%.*s\", &(%lu->%lu)," " \"%.*s\", %lu) returned %s\n", str, - (int) result_len, buf_in, - (unsigned long) str_len, (unsigned long) result_len, - (int) tokens_len, buf_tokens, (unsigned long) tokens_len, + (int)result_len, buf_in, + (unsigned long)str_len, (unsigned long)result_len, + (int)tokens_len, buf_tokens, (unsigned long)tokens_len, res ? "true" : "false"); fprintf (stderr, "\tEXPECTED: " @@ -87,8 +87,8 @@ expect_result_n (const char *str, size_t str_len, " \"%.*s\", %lu) returned %s\n", str, expected, - (unsigned long) str_len, (unsigned long) expected_len, - (int) tokens_len, buf_tokens, (unsigned long) tokens_len, + (unsigned long)str_len, (unsigned long)expected_len, + (int)tokens_len, buf_tokens, (unsigned long)tokens_len, expected_removed ? "true" : "false"); return 1; } @@ -96,7 +96,7 @@ expect_result_n (const char *str, size_t str_len, } -#define expect_result(s,t,e,found) \ +#define expect_result(s, t, e, found) \ expect_result_n ((s),MHD_STATICSTR_LEN_ (s), \ (t),MHD_STATICSTR_LEN_ (t), \ (e),MHD_STATICSTR_LEN_ (e), found) @@ -216,15 +216,18 @@ check_result (void) errcount += expect_result ("the-token, the-token, the-token, " \ "the-token, the-token", "the-token", "", true); errcount += expect_result ("the-token, a, the-token, the-token, b, " \ - "the-token, c, the-token, a", "c,a,b", + "the-token, c, the-token, a", + "c,a,b", "the-token, the-token, the-token, the-token, the-token", true); errcount += expect_result ("the-token, xx, the-token, the-token, zz, " \ - "the-token, yy, the-token, ww", "ww,zz,yy", + "the-token, yy, the-token, ww", + "ww,zz,yy", "the-token, xx, the-token, the-token, the-token, the-token", true); errcount += expect_result ("the-token, a, the-token, the-token, b, " \ - "the-token, c, the-token, a", " c,\t a,b,,,", + "the-token, c, the-token, a", + " c,\t a,b,,,", "the-token, the-token, the-token, the-token, the-token", true); errcount += expect_result ("the-token, xx, the-token, the-token, zz, " \ @@ -233,11 +236,13 @@ check_result (void) "the-token, xx, the-token, the-token, the-token, the-token", true); errcount += expect_result ("the-token, a, the-token, the-token, b, " \ - "the-token, c, the-token, a", ",,,,c,\t a,b", + "the-token, c, the-token, a", + ",,,,c,\t a,b", "the-token, the-token, the-token, the-token, the-token", true); errcount += expect_result ("the-token, xx, the-token, the-token, zz, " \ - "the-token, yy, the-token, ww", " ww,\t zz,yy,,,,", + "the-token, yy, the-token, ww", + " ww,\t zz,yy,,,,", "the-token, xx, the-token, the-token, the-token, the-token", true); errcount += expect_result ("close, 2", "close", @@ -286,9 +291,10 @@ int main (int argc, char *argv[]) { int errcount = 0; - (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + (void)argc; + (void)argv; /* Unused. Silent compiler warning. */ errcount += check_result (); if (0 == errcount) printf ("All tests were passed without errors.\n"); - return errcount == 0 ? 0 : 1; + return (errcount == 0) ? 0 : 1; } diff --git a/src/tests/upgrade/test_upgrade.c b/src/tests/upgrade/test_upgrade.c @@ -84,7 +84,7 @@ # ifdef MHD_SOCKETS_KIND_WINSOCK # error Both MHD_SOCKETS_KIND_POSIX and MHD_SOCKETS_KIND_WINSOCK are defined # endif /* MHD_SOCKETS_KIND_WINSOCK */ -#elif ! defined(MHD_SOCKETS_KIND_WINSOCK) +#elif !defined(MHD_SOCKETS_KIND_WINSOCK) # error Neither MHD_SOCKETS_KIND_POSIX nor MHD_SOCKETS_KIND_WINSOCK are defined #endif /* MHD_SOCKETS_KIND_WINSOCK */ @@ -93,18 +93,18 @@ /** * Determine length of static string / macro strings at compile time. */ -#define mhd_SSTR_LEN(macro) (sizeof(macro) / sizeof(char) - 1) +# define mhd_SSTR_LEN(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! mhd_SSTR_LEN */ -#if ! defined(SHUT_WR) && defined(SD_SEND) +#if !defined(SHUT_WR) && defined(SD_SEND) # define SHUT_WR SD_SEND #endif -#if ! defined(SHUT_RD) && defined(SD_RECEIVE) +#if !defined(SHUT_RD) && defined(SD_RECEIVE) # define SHUT_RD SD_RECEIVE #endif -#if ! defined(SHUT_RDWR) && defined(SD_BOTH) +#if !defined(SHUT_RDWR) && defined(SD_BOTH) # define SHUT_RDWR SD_BOTH #endif @@ -145,7 +145,7 @@ _externalErrorExit_func (const char *errDesc, const char *funcName, fprintf (stderr, ".\nLast errno value: %d (%s)\n", last_errno, strerror (last_errno)); #ifdef MHD_SOCKETS_KIND_WINSOCK - fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ()); + fprintf (stderr, "WSAGetLastError() value: %d\n", (int)WSAGetLastError ()); #endif /* MHD_SOCKETS_KIND_WINSOCK */ fflush (stderr); exit (test_failed ? 9 : 99); @@ -191,37 +191,37 @@ _testErrorLog_func (const char *errDesc, const char *funcName, int lineNum) fprintf (stderr, ".\nLast errno value: %d (%s)\n", last_errno, strerror (last_errno)); #ifdef MHD_SOCKETS_KIND_WINSOCK - fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ()); + fprintf (stderr, "WSAGetLastError() value: %d\n", (int)WSAGetLastError ()); #endif /* MHD_SOCKETS_KIND_WINSOCK */ fflush (stderr); } #ifdef MHD_HAVE_MHD_FUNC_ -#define externalErrorExit() \ - _externalErrorExit_func (NULL, MHD_FUNC_, __LINE__, 0) -#define externalErrorExitDesc(errDesc) \ - _externalErrorExit_func (errDesc, MHD_FUNC_, __LINE__, 0) -#define testFailedExitDesc(errDesc) \ - _externalErrorExit_func (errDesc, MHD_FUNC_, __LINE__, ! 0) -#define mhdErrorExit(ignore) \ - _mhdErrorExit_func (NULL, MHD_FUNC_, __LINE__) -#define mhdErrorExitDesc(errDesc) \ - _mhdErrorExit_func (errDesc, MHD_FUNC_, __LINE__) -#define testErrorLog(ignore) \ - _testErrorLog_func (NULL, MHD_FUNC_, __LINE__) -#define testErrorLogDesc(errDesc) \ - _testErrorLog_func (errDesc, MHD_FUNC_, __LINE__) +# define externalErrorExit() \ + _externalErrorExit_func (NULL, MHD_FUNC_, __LINE__, 0) +# define externalErrorExitDesc(errDesc) \ + _externalErrorExit_func (errDesc, MHD_FUNC_, __LINE__, 0) +# define testFailedExitDesc(errDesc) \ + _externalErrorExit_func (errDesc, MHD_FUNC_, __LINE__, ! 0) +# define mhdErrorExit(ignore) \ + _mhdErrorExit_func (NULL, MHD_FUNC_, __LINE__) +# define mhdErrorExitDesc(errDesc) \ + _mhdErrorExit_func (errDesc, MHD_FUNC_, __LINE__) +# define testErrorLog(ignore) \ + _testErrorLog_func (NULL, MHD_FUNC_, __LINE__) +# define testErrorLogDesc(errDesc) \ + _testErrorLog_func (errDesc, MHD_FUNC_, __LINE__) #else /* ! MHD_HAVE_MHD_FUNC_ */ -#define externalErrorExit() _externalErrorExit_func (NULL, NULL, __LINE__, 0) -#define externalErrorExitDesc(errDesc) \ - _externalErrorExit_func (errDesc, NULL, __LINE__, 0) -#define testFailedExitDesc(errDesc) \ - _externalErrorExit_func (errDesc, NULL, __LINE__, ! 0) -#define mhdErrorExit(ignore) _mhdErrorExit_func (NULL, NULL, __LINE__) -#define mhdErrorExitDesc(errDesc) _mhdErrorExit_func (errDesc, NULL, __LINE__) -#define testErrorLog(ignore) _testErrorLog_func (NULL, NULL, __LINE__) -#define testErrorLogDesc(errDesc) _testErrorLog_func (errDesc, NULL, __LINE__) +# define externalErrorExit() _externalErrorExit_func (NULL, NULL, __LINE__, 0) +# define externalErrorExitDesc(errDesc) \ + _externalErrorExit_func (errDesc, NULL, __LINE__, 0) +# define testFailedExitDesc(errDesc) \ + _externalErrorExit_func (errDesc, NULL, __LINE__, ! 0) +# define mhdErrorExit(ignore) _mhdErrorExit_func (NULL, NULL, __LINE__) +# define mhdErrorExitDesc(errDesc) _mhdErrorExit_func (errDesc, NULL, __LINE__) +# define testErrorLog(ignore) _testErrorLog_func (NULL, NULL, __LINE__) +# define testErrorLogDesc(errDesc) _testErrorLog_func (errDesc, NULL, __LINE__) #endif /* ! MHD_HAVE_MHD_FUNC_ */ /* ** External parameters ** */ @@ -293,7 +293,7 @@ gnutlscli_connect (int *sock, sp)) { testErrorLogDesc ("socketpair() failed"); - return (pid_t) -1; + return (pid_t)-1; } chld = fork (); if (0 != chld) @@ -303,8 +303,8 @@ gnutlscli_connect (int *sock, return chld; } mhd_socket_close (sp[1]); - (void) close (0); - (void) close (1); + (void)close (0); + (void)close (1); if (-1 == dup2 (sp[0], 0)) externalErrorExitDesc ("dup2() failed"); if (-1 == dup2 (sp[0], 1)) @@ -315,21 +315,21 @@ gnutlscli_connect (int *sock, snprintf (destination, sizeof(destination), "%u", - (unsigned int) port); + (unsigned int)port); execlp ("gnutls-cli", "gnutls-cli", "--insecure", "-p", destination, "127.0.0.1", - (char *) NULL); + (char *)NULL); } else if (TLS_CLI_OPENSSL == use_tls_tool) { snprintf (destination, sizeof(destination), "127.0.0.1:%u", - (unsigned int) port); + (unsigned int)port); execlp ("openssl", "openssl", "s_client", @@ -337,7 +337,7 @@ gnutlscli_connect (int *sock, destination, "-verify", "1", - (char *) NULL); + (char *)NULL); } _exit (1); } @@ -355,7 +355,7 @@ gnutlscli_connect (int *sock, static void make_blocking (MHD_Socket fd) { -#if defined(MHD_SOCKETS_KIND_POSIX) +# if defined(MHD_SOCKETS_KIND_POSIX) int flags; flags = fcntl (fd, F_GETFL); @@ -364,12 +364,12 @@ make_blocking (MHD_Socket fd) if ((flags & ~O_NONBLOCK) != flags) if (-1 == fcntl (fd, F_SETFL, flags & ~O_NONBLOCK)) externalErrorExitDesc ("fcntl() failed"); -#elif defined(MHD_SOCKETS_KIND_WINSOCK) +# elif defined(MHD_SOCKETS_KIND_WINSOCK) unsigned long flags = 0; - if (0 != ioctlsocket (fd, (int) FIONBIO, &flags)) + if (0 != ioctlsocket (fd, (int)FIONBIO, &flags)) externalErrorExitDesc ("ioctlsocket() failed"); -#endif /* MHD_SOCKETS_KIND_WINSOCK */ +# endif /* MHD_SOCKETS_KIND_WINSOCK */ } @@ -396,7 +396,7 @@ make_nonblocking (MHD_Socket fd) #elif defined(MHD_SOCKETS_KIND_WINSOCK) unsigned long flags = 1; - if (0 != ioctlsocket (fd, (int) FIONBIO, &flags)) + if (0 != ioctlsocket (fd, (int)FIONBIO, &flags)) externalErrorExitDesc ("ioctlsocket() failed"); #endif /* MHD_SOCKETS_KIND_WINSOCK */ } @@ -416,17 +416,17 @@ make_nodelay (MHD_Socket fd) if (0 == setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, - (const void *) &on_val, + (const void *)&on_val, sizeof (on_val))) return; /* Success exit point */ -#ifndef MHD_SOCKETS_KIND_WINSOCK +# ifndef MHD_SOCKETS_KIND_WINSOCK fprintf (stderr, "Failed to enable TCP_NODELAY on socket (ignored). " - "errno: %d (%s)\n", (int) errno, strerror (errno)); -#else /* MHD_SOCKETS_KIND_WINSOCK */ + "errno: %d (%s)\n", (int)errno, strerror (errno)); +# else /* MHD_SOCKETS_KIND_WINSOCK */ fprintf (stderr, "Failed to enable TCP_NODELAY on socket (ignored). " - "WSAGetLastError() value: %d\n", (int) WSAGetLastError ()); -#endif /* MHD_SOCKETS_KIND_WINSOCK */ + "WSAGetLastError() value: %d\n", (int)WSAGetLastError ()); +# endif /* MHD_SOCKETS_KIND_WINSOCK */ fflush (stderr); #endif /* TCP_NODELAY */ } @@ -488,7 +488,7 @@ struct wr_socket #if 0 /* Unused code */ static void -wr_make_blocking (struct wr_socket *s) +wr_make_blocking (struct wr_socket *s) { if (s->is_nonblocking) make_blocking (s->fd); @@ -500,9 +500,9 @@ wr_make_blocking (struct wr_socket *s) static void -wr_make_nonblocking (struct wr_socket *s) +wr_make_nonblocking (struct wr_socket *s) { - if (! s->is_nonblocking) + if (!s->is_nonblocking) make_nonblocking (s->fd); s->is_nonblocking = true; } @@ -516,7 +516,7 @@ static struct wr_socket * wr_create_plain_sckt (void) { struct wr_socket *s = - (struct wr_socket *) malloc (sizeof(struct wr_socket)); + (struct wr_socket *)malloc (sizeof(struct wr_socket)); if (NULL == s) { testErrorLogDesc ("malloc() failed"); @@ -570,13 +570,13 @@ wr_create_tls_sckt (void) GNUTLS_CRD_CERTIFICATE, s->tls_crd)) { -#if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && ! defined(_WIN64) - gnutls_transport_set_int (s->tls_s, (int) (s->fd)); -#else /* GnuTLS before 3.1.9 or Win x64 */ +# if (GNUTLS_VERSION_NUMBER + 0 >= 0x030109) && !defined(_WIN64) + gnutls_transport_set_int (s->tls_s, (int)(s->fd)); +# else /* GnuTLS before 3.1.9 or Win x64 */ gnutls_transport_set_ptr (s->tls_s, (gnutls_transport_ptr_t) \ - (intptr_t) (s->fd)); -#endif /* GnuTLS before 3.1.9 or Win x64 */ + (intptr_t)(s->fd)); +# endif /* GnuTLS before 3.1.9 or Win x64 */ return s; } else @@ -592,7 +592,7 @@ wr_create_tls_sckt (void) } else testErrorLogDesc ("gnutls_init() failed"); - (void) mhd_socket_close (s->fd); + (void)mhd_socket_close (s->fd); } else testErrorLogDesc ("socket() failed"); @@ -673,12 +673,12 @@ wr_wait_socket_ready_noabort_ (struct wr_socket *s, FD_SET (s->fd, &fds); if (0 <= timeout_ms) { -#if ! defined(_WIN32) || defined(__CYGWIN__) - tmo.tv_sec = (time_t) (timeout_ms / 1000); +#if !defined(_WIN32) || defined(__CYGWIN__) + tmo.tv_sec = (time_t)(timeout_ms / 1000); #else /* Native W32 */ - tmo.tv_sec = (long) (timeout_ms / 1000); + tmo.tv_sec = (long)(timeout_ms / 1000); #endif /* Native W32 */ - tmo.tv_usec = ((long) (timeout_ms % 1000)) * 1000; + tmo.tv_usec = ((long)(timeout_ms % 1000)) * 1000; tmo_ptr = &tmo; } else @@ -687,9 +687,9 @@ wr_wait_socket_ready_noabort_ (struct wr_socket *s, do { if (WR_WAIT_FOR_RECV == wait_for) - sel_res = select (1 + (int) s->fd, &fds, NULL, NULL, tmo_ptr); + sel_res = select (1 + (int)s->fd, &fds, NULL, NULL, tmo_ptr); else - sel_res = select (1 + (int) s->fd, NULL, &fds, NULL, tmo_ptr); + sel_res = select (1 + (int)s->fd, NULL, &fds, NULL, tmo_ptr); } while (0 > sel_res && mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())); if (1 == sel_res) @@ -700,10 +700,10 @@ wr_wait_socket_ready_noabort_ (struct wr_socket *s, else { #ifndef MHD_SOCKETS_KIND_WINSOCK - fprintf (stderr, "Error %d (%s)", (int) errno, strerror (errno)); + fprintf (stderr, "Error %d (%s)", (int)errno, strerror (errno)); #else /* MHD_SOCKETS_KIND_WINSOCK */ fprintf (stderr, "Error (WSAGetLastError code: %d)", - (int) WSAGetLastError ()); + (int)WSAGetLastError ()); #endif /* MHD_SOCKETS_KIND_WINSOCK */ } fprintf (stderr, " waiting for socket to be available for %s.\n", @@ -742,17 +742,17 @@ wr_connect_tmo (struct wr_socket *s, unsigned int length, int timeout_ms) { - if (0 != connect (s->fd, addr, (socklen_t) length)) + if (0 != connect (s->fd, addr, (socklen_t)length)) { int err; bool connect_completed = false; err = mhd_SCKT_GET_LERR (); #if defined(MHD_SOCKETS_KIND_POSIX) - while (! connect_completed && (EINTR == err)) + while (!connect_completed && (EINTR == err)) { - connect_completed = (0 == connect (s->fd, addr, (socklen_t) length)); - if (! connect_completed) + connect_completed = (0 == connect (s->fd, addr, (socklen_t)length)); + if (!connect_completed) { err = errno; if (EALREADY == err) @@ -762,12 +762,12 @@ wr_connect_tmo (struct wr_socket *s, } } #endif /* MHD_SOCKETS_KIND_POSIX */ - if (! connect_completed && - (mhd_SCKT_ERR_IS_INPROGRESS (err) - || mhd_SCKT_ERR_IS_EAGAIN (err))) /* No modern system uses EAGAIN, except W32 */ + if (!connect_completed + && (mhd_SCKT_ERR_IS_INPROGRESS (err) + || mhd_SCKT_ERR_IS_EAGAIN (err))) /* No modern system uses EAGAIN, except W32 */ connect_completed = wr_wait_socket_ready_noabort_ (s, timeout_ms, WR_WAIT_FOR_SEND); - if (! connect_completed) + if (!connect_completed) { testErrorLogDesc ("connect() failed"); return -1; @@ -829,12 +829,12 @@ wr_handshake_tmo_ (struct wr_socket *s, else { fprintf (stderr, "The error returned by gnutls_handshake() is " - "'%s' ", gnutls_strerror ((int) res)); -#if GNUTLS_VERSION_NUMBER >= 0x020600 - fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int) res)); -#else /* GNUTLS_VERSION_NUMBER < 0x020600 */ - fprintf (stderr, "(%d)\n", (int) res); -#endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ + "'%s' ", gnutls_strerror ((int)res)); +# if GNUTLS_VERSION_NUMBER >= 0x020600 + fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int)res)); +# else /* GNUTLS_VERSION_NUMBER < 0x020600 */ + fprintf (stderr, "(%d)\n", (int)res); +# endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ testErrorLogDesc ("gnutls_handshake() failed with hard error"); mhd_SCKT_SET_LERR (mhdt_SCKT_HARD_ERR); /* hard error */ } @@ -842,7 +842,7 @@ wr_handshake_tmo_ (struct wr_socket *s, } -#if 0 /* Unused function */ +# if 0 /* Unused function */ /* Only to be called from wr_send() and wr_recv() ! */ static bool wr_handshake_ (struct wr_socket *s) @@ -851,7 +851,7 @@ wr_handshake_ (struct wr_socket *s) } -#endif /* Unused function */ +# endif /* Unused function */ #endif /* HTTPS_SUPPORT */ @@ -876,14 +876,14 @@ wr_send_tmo (struct wr_socket *s, if (wr_plain == s->t) { ssize_t res; - while (! 0) + while (!0) { int err; res = mhd_sys_send (s->fd, buf, len); if (0 <= res) break; /* Success */ err = mhd_SCKT_GET_LERR (); - if (! mhd_SCKT_ERR_IS_EAGAIN (err) && ! mhd_SCKT_ERR_IS_EINTR (err)) + if (!mhd_SCKT_ERR_IS_EAGAIN (err) && !mhd_SCKT_ERR_IS_EINTR (err)) break; /* Failure */ wr_wait_socket_ready_ (s, timeout_ms, WR_WAIT_FOR_SEND); } @@ -893,7 +893,7 @@ wr_send_tmo (struct wr_socket *s, else if (wr_tls == s->t) { ssize_t ret; - if (! s->tls_connected && ! wr_handshake_tmo_ (s, timeout_ms)) + if (!s->tls_connected && !wr_handshake_tmo_ (s, timeout_ms)) return -1; while (1) @@ -908,12 +908,12 @@ wr_send_tmo (struct wr_socket *s, WR_WAIT_FOR_SEND : WR_WAIT_FOR_RECV); } fprintf (stderr, "The error returned by gnutls_record_send() is " - "'%s' ", gnutls_strerror ((int) ret)); -#if GNUTLS_VERSION_NUMBER >= 0x020600 - fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int) ret)); -#else /* GNUTLS_VERSION_NUMBER < 0x020600 */ - fprintf (stderr, "(%d)\n", (int) ret); -#endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ + "'%s' ", gnutls_strerror ((int)ret)); +# if GNUTLS_VERSION_NUMBER >= 0x020600 + fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int)ret)); +# else /* GNUTLS_VERSION_NUMBER < 0x020600 */ + fprintf (stderr, "(%d)\n", (int)ret); +# endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ testErrorLogDesc ("gnutls_record_send() failed with hard error"); mhd_SCKT_SET_LERR (mhdt_SCKT_HARD_ERR); /* hard error */ return -1; @@ -964,7 +964,7 @@ wr_recv_tmo (struct wr_socket *s, if (wr_plain == s->t) { ssize_t res; - while (! 0) + while (!0) { int err; res = mhd_sys_recv (s->fd, buf, len); @@ -973,7 +973,7 @@ wr_recv_tmo (struct wr_socket *s, if (0 <= res) break; /* Success */ err = mhd_SCKT_GET_LERR (); - if (! mhd_SCKT_ERR_IS_EAGAIN (err) && ! mhd_SCKT_ERR_IS_EINTR (err)) + if (!mhd_SCKT_ERR_IS_EAGAIN (err) && !mhd_SCKT_ERR_IS_EINTR (err)) break; /* Failure */ wr_wait_socket_ready_ (s, timeout_ms, WR_WAIT_FOR_RECV); } @@ -983,7 +983,7 @@ wr_recv_tmo (struct wr_socket *s, if (wr_tls == s->t) { ssize_t ret; - if (! s->tls_connected && ! wr_handshake_tmo_ (s, timeout_ms)) + if (!s->tls_connected && !wr_handshake_tmo_ (s, timeout_ms)) return -1; while (1) @@ -1001,12 +1001,12 @@ wr_recv_tmo (struct wr_socket *s, } fprintf (stderr, "The error returned by gnutls_record_recv() is " - "'%s' ", gnutls_strerror ((int) ret)); -#if GNUTLS_VERSION_NUMBER >= 0x020600 - fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int) ret)); -#else /* GNUTLS_VERSION_NUMBER < 0x020600 */ - fprintf (stderr, "(%d)\n", (int) ret); -#endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ + "'%s' ", gnutls_strerror ((int)ret)); +# if GNUTLS_VERSION_NUMBER >= 0x020600 + fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int)ret)); +# else /* GNUTLS_VERSION_NUMBER < 0x020600 */ + fprintf (stderr, "(%d)\n", (int)ret); +# endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ testErrorLogDesc ("gnutls_record_recv() failed with hard error"); mhd_SCKT_SET_LERR (mhdt_SCKT_HARD_ERR); /* hard error */ return -1; @@ -1061,27 +1061,27 @@ wr_shutdown_tmo (struct wr_socket *s, int how, int timeout_ms) } if (wr_plain == s->t) { - (void) timeout_ms; /* Unused parameter for plain sockets */ + (void)timeout_ms; /* Unused parameter for plain sockets */ return shutdown (s->fd, how); } #ifdef HTTPS_SUPPORT if (wr_tls == s->t) { ssize_t ret; - if (! s->tls_connected && ! wr_handshake_tmo_ (s, timeout_ms)) + if (!s->tls_connected && !wr_handshake_tmo_ (s, timeout_ms)) return -1; while (1) { ret = - gnutls_bye (s->tls_s, - (SHUT_WR == how) ? GNUTLS_SHUT_WR : GNUTLS_SHUT_RDWR); + gnutls_bye (s->tls_s, + (SHUT_WR == how) ? GNUTLS_SHUT_WR : GNUTLS_SHUT_RDWR); if (GNUTLS_E_SUCCESS == ret) { -#if 0 /* Disabled to test pure behaviour */ +# if 0 /* Disabled to test pure behaviour */ if (SHUT_RDWR == how) - (void) shutdown (s->fd, how); /* Also shutdown the underlying transport layer */ -#endif + (void)shutdown (s->fd, how); /* Also shutdown the underlying transport layer */ +# endif return 0; } if ((GNUTLS_E_AGAIN != ret) && (GNUTLS_E_INTERRUPTED != ret)) @@ -1092,12 +1092,12 @@ wr_shutdown_tmo (struct wr_socket *s, int how, int timeout_ms) } fprintf (stderr, "The error returned by gnutls_bye() is " - "'%s' ", gnutls_strerror ((int) ret)); -#if GNUTLS_VERSION_NUMBER >= 0x020600 - fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int) ret)); -#else /* GNUTLS_VERSION_NUMBER < 0x020600 */ - fprintf (stderr, "(%d)\n", (int) ret); -#endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ + "'%s' ", gnutls_strerror ((int)ret)); +# if GNUTLS_VERSION_NUMBER >= 0x020600 + fprintf (stderr, "(%s)\n", gnutls_strerror_name ((int)ret)); +# else /* GNUTLS_VERSION_NUMBER < 0x020600 */ + fprintf (stderr, "(%d)\n", (int)ret); +# endif /* GNUTLS_VERSION_NUMBER < 0x020600 */ testErrorLogDesc ("gnutls_bye() failed with hard error"); mhd_SCKT_SET_LERR (mhdt_SCKT_HARD_ERR); /* hard error */ return -1; @@ -1174,18 +1174,18 @@ send_all (struct wr_socket *sock, { ssize_t ret; size_t sent; - const uint8_t *const buf = (const uint8_t *) data; + const uint8_t *const buf = (const uint8_t *)data; wr_make_nonblocking (sock); - for (sent = 0; sent < data_size; sent += (size_t) ret) + for (sent = 0; sent < data_size; sent += (size_t)ret) { ret = wr_send (sock, buf + sent, data_size - sent); if (0 > ret) { - if (mhd_SCKT_ERR_IS_EAGAIN (mhd_SCKT_GET_LERR ()) || - mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())) + if (mhd_SCKT_ERR_IS_EAGAIN (mhd_SCKT_GET_LERR ()) + || mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())) { ret = 0; continue; @@ -1196,7 +1196,7 @@ send_all (struct wr_socket *sock, } -#define send_all_stext(sk,st) send_all (sk,st,mhd_SSTR_LEN (st)) +#define send_all_stext(sk, st) send_all (sk,st,mhd_SSTR_LEN (st)) /** @@ -1259,20 +1259,20 @@ recv_all (struct wr_socket *sock, ssize_t ret; size_t rcvd; - buf = (uint8_t *) malloc (data_size); + buf = (uint8_t *)malloc (data_size); if (NULL == buf) externalErrorExitDesc ("malloc() failed"); wr_make_nonblocking (sock); - for (rcvd = 0; rcvd < data_size; rcvd += (size_t) ret) + for (rcvd = 0; rcvd < data_size; rcvd += (size_t)ret) { ret = wr_recv (sock, buf + rcvd, data_size - rcvd); if (0 > ret) { - if (mhd_SCKT_ERR_IS_EAGAIN (mhd_SCKT_GET_LERR ()) || - mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())) + if (mhd_SCKT_ERR_IS_EAGAIN (mhd_SCKT_GET_LERR ()) + || mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())) { ret = 0; continue; @@ -1283,18 +1283,18 @@ recv_all (struct wr_socket *sock, { fprintf (stderr, "Partial only received text. Expected: '%.*s' " "(length: %ud). Got: '%.*s' (length: %ud). ", - (int) data_size, (const char *) data, (unsigned int) data_size, - (int) rcvd, (const char *) buf, (unsigned int) rcvd); + (int)data_size, (const char *)data, (unsigned int)data_size, + (int)rcvd, (const char *)buf, (unsigned int)rcvd); mhdErrorExitDesc ("The server unexpectedly closed connection"); } - if ((data_size - rcvd) < (size_t) ret) + if ((data_size - rcvd) < (size_t)ret) testFailedExitDesc ("recv() returned excessive amount of data"); - if (0 != memcmp (data, buf, rcvd + (size_t) ret)) + if (0 != memcmp (data, buf, rcvd + (size_t)ret)) { fprintf (stderr, "Wrong received text. Expected: '%.*s'. " "Got: '%.*s'. ", - (int) (rcvd + (size_t) ret), (const char *) data, - (int) (rcvd + (size_t) ret), (const char *) buf); + (int)(rcvd + (size_t)ret), (const char *)data, + (int)(rcvd + (size_t)ret), (const char *)buf); mhdErrorExit (); } } @@ -1302,15 +1302,15 @@ recv_all (struct wr_socket *sock, { fprintf (stderr, "Wrong received text. Expected: '%.*s'. " "Got: '%.*s'. ", - (int) data_size, (const char *) data, - (int) data_size, (const char *) buf); + (int)data_size, (const char *)data, + (int)data_size, (const char *)buf); mhdErrorExit (); } free (buf); } -#define recv_all_stext(sk,st) recv_all (sk,st,mhd_SSTR_LEN (st)) +#define recv_all_stext(sk, st) recv_all (sk,st,mhd_SSTR_LEN (st)) /** @@ -1345,15 +1345,15 @@ receive_eof (struct wr_socket *sock) bool got_eof = false; wr_make_nonblocking (sock); - for (rcvd = 0; rcvd < sizeof(buf); rcvd += (size_t) ret) + for (rcvd = 0; rcvd < sizeof(buf); rcvd += (size_t)ret) { ret = wr_recv (sock, buf + rcvd, sizeof(buf) - rcvd); if (0 > ret) { - if (mhd_SCKT_ERR_IS_EAGAIN (mhd_SCKT_GET_LERR ()) || - mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())) + if (mhd_SCKT_ERR_IS_EAGAIN (mhd_SCKT_GET_LERR ()) + || mhd_SCKT_ERR_IS_EINTR (mhd_SCKT_GET_LERR ())) { ret = 0; continue; @@ -1374,15 +1374,15 @@ receive_eof (struct wr_socket *sock) if (sizeof(buf) == rcvd) { fprintf (stderr, "Received at least %lu extra bytes while " - "end-of-file is expected.\n", (unsigned long) sizeof(buf)); + "end-of-file is expected.\n", (unsigned long)sizeof(buf)); mhdErrorExit (); } fprintf (stderr, "Received at %lu extra bytes and then %s" - "end-of-file marker.\n", (unsigned long) rcvd, + "end-of-file marker.\n", (unsigned long)rcvd, got_eof ? "" : "NO "); mhdErrorExit (); } - if (! got_eof) + if (!got_eof) mhdErrorExitDesc ("Failed to receive end-of-file marker."); } @@ -1398,7 +1398,7 @@ recv_upg_all (struct MHD_UpgradedHandle *urh, size_t last_rcvd; size_t rcvd; - buf = (uint8_t *) malloc (data_size); + buf = (uint8_t *)malloc (data_size); if (NULL == buf) externalErrorExitDesc ("malloc() failed"); @@ -1409,26 +1409,26 @@ recv_upg_all (struct MHD_UpgradedHandle *urh, data_size - rcvd, buf + rcvd, &last_rcvd, - 1000 * (unsigned long) test_timeout)) + 1000 * (unsigned long)test_timeout)) mhdErrorExitDesc ("MHD_upgraded_recv() failed"); if (0 == last_rcvd) { fprintf (stderr, "Partial only received text. Expected: '%.*s' " "(length: %ud). Got: '%.*s' (length: %ud). ", - (int) data_size, (const char *) data, (unsigned int) data_size, - (int) rcvd, (const char *) buf, (unsigned int) rcvd); + (int)data_size, (const char *)data, (unsigned int)data_size, + (int)rcvd, (const char *)buf, (unsigned int)rcvd); mhdErrorExitDesc ("The server unexpectedly closed connection"); } if ((data_size - rcvd) < last_rcvd) mhdErrorExitDesc ("MHD_upgraded_recv() returned excessive " \ "amount of data"); - if (0 != memcmp (data, buf, rcvd + (size_t) last_rcvd)) + if (0 != memcmp (data, buf, rcvd + (size_t)last_rcvd)) { fprintf (stderr, "Wrong received text. Expected: '%.*s'. " "Got: '%.*s'. ", - (int) (rcvd + last_rcvd), (const char *) data, - (int) (rcvd + last_rcvd), (const char *) buf); + (int)(rcvd + last_rcvd), (const char *)data, + (int)(rcvd + last_rcvd), (const char *)buf); mhdErrorExit (); } } @@ -1436,15 +1436,15 @@ recv_upg_all (struct MHD_UpgradedHandle *urh, { fprintf (stderr, "Wrong received text. Expected: '%.*s'. " "Got: '%.*s'. ", - (int) data_size, (const char *) data, - (int) data_size, (const char *) buf); + (int)data_size, (const char *)data, + (int)data_size, (const char *)buf); mhdErrorExit (); } free (buf); } -#define recv_upg_all_stext(uh,st) recv_upg_all (uh,st,mhd_SSTR_LEN (st)) +#define recv_upg_all_stext(uh, st) recv_upg_all (uh,st,mhd_SSTR_LEN (st)) static void @@ -1459,7 +1459,7 @@ send_upg_all (struct MHD_UpgradedHandle *urh, data_size, data, &sent_size, - 1000 * (unsigned long) test_timeout, + 1000 * (unsigned long)test_timeout, MHD_NO)) mhdErrorExitDesc ("MHD_upgraded_send() failed"); @@ -1483,7 +1483,7 @@ receive_upg_eof (struct MHD_UpgradedHandle *urh) sizeof(buf), buf, &rcvd_sise, - 1000 * (unsigned long) test_timeout)) + 1000 * (unsigned long)test_timeout)) mhdErrorExitDesc ("MHD_upgraded_recv() failed"); if (0 != rcvd_sise) @@ -1501,7 +1501,7 @@ receive_upg_eof (struct MHD_UpgradedHandle *urh) static void * run_usock_server (void *cls) { - struct MHD_UpgradedHandle *urh = (struct MHD_UpgradedHandle *) cls; + struct MHD_UpgradedHandle *urh = (struct MHD_UpgradedHandle *)cls; recv_upg_all (urh, rclient_msg, @@ -1511,7 +1511,7 @@ run_usock_server (void *cls) app_msg_size); recv_upg_all_stext (urh, \ "Finished"); - if (! test_tls) + if (!test_tls) { receive_upg_eof (urh); } @@ -1533,7 +1533,7 @@ run_usock_server (void *cls) static void * run_usock_client (void *cls) { - struct wr_socket *sock = (struct wr_socket *) cls; + struct wr_socket *sock = (struct wr_socket *)cls; send_all_stext (sock, "GET / HTTP/1.1\r\n" \ @@ -1550,7 +1550,7 @@ run_usock_client (void *cls) app_msg_size); send_all_stext (sock, "Finished"); - if (! test_tls) + if (!test_tls) { send_eof (sock); } @@ -1706,7 +1706,7 @@ test_upgrade (void) if (0 == dinfo.v_bind_port_uint16) mhdErrorExitDesc ("MHD_daemon_get_info_fixed() returned wrong data"); global_port = dinfo.v_bind_port_uint16; /* Re-use the same port for the next checks */ - if (! test_tls || (TLS_LIB_GNUTLS == use_tls_tool)) + if (!test_tls || (TLS_LIB_GNUTLS == use_tls_tool)) { sock = test_tls ? wr_create_tls_sckt () : wr_create_plain_sckt (); if (NULL == sock) @@ -1720,7 +1720,7 @@ test_upgrade (void) memcpy (&(sa.sin_addr.s_addr), "\x7f\0\0\1", 4); #endif /* ! INADDR_LOOPBACK */ if (0 != wr_connect (sock, - (struct sockaddr *) &sa, + (struct sockaddr *)&sa, sizeof (sa))) externalErrorExitDesc ("Connect socket failed"); } @@ -1760,14 +1760,14 @@ test_upgrade (void) #if defined(HTTPS_SUPPORT) && defined(HAVE_FORK) && defined(HAVE_WAITPID) if (test_tls && (TLS_LIB_GNUTLS != use_tls_tool)) { - if ((pid_t) -1 == waitpid (pid, NULL, 0)) + if ((pid_t)-1 == waitpid (pid, NULL, 0)) externalErrorExitDesc ("waitpid() failed"); } #endif /* HTTPS_SUPPORT && HAVE_FORK && HAVE_WAITPID */ - if (! client_done) + if (!client_done) testFailedExitDesc ("The client thread has not signalled " \ "successful finish"); - if (! app_done) + if (!app_done) testFailedExitDesc ("The application thread has not signalled " \ "successful finish"); MHD_daemon_destroy (d); @@ -1794,8 +1794,8 @@ static void * init_test_msg (void *buf, size_t buf_size, enum test_msg_type msg_type) { size_t i; - char *const text_buf = (char *) buf; - uint8_t *const bin_buf = (uint8_t *) buf; + char *const text_buf = (char *)buf; + uint8_t *const bin_buf = (uint8_t *)buf; if (0 == buf_size) return buf; switch (msg_type) @@ -1810,11 +1810,11 @@ init_test_msg (void *buf, size_t buf_size, enum test_msg_type msg_type) pos = i + 43; else pos = i + 26; - if ((0 == i) || (2 == pos % 100) ) + if ((0 == i) || (2 == pos % 100)) text_buf[i] = - (char) (unsigned char) ((test_msg_large_app_data == msg_type) ? - ('Z' - pos % ('Z' - 'A' + 1)) : - ('A' + pos % ('Z' - 'A' + 1))); + (char)(unsigned char)((test_msg_large_app_data == msg_type) ? + ('Z' - pos % ('Z' - 'A' + 1)) : + ('A' + pos % ('Z' - 'A' + 1))); else if (0 == pos % 100) text_buf[i] = '.'; else if (1 == pos % 100) @@ -1822,23 +1822,23 @@ init_test_msg (void *buf, size_t buf_size, enum test_msg_type msg_type) else if ((99 != pos % 100) && (2 != pos % 100) && (0 == pos % 5)) text_buf[i] = ' '; else if (test_msg_large_app_data == msg_type) - text_buf[i] = (char) (unsigned char) ('z' - pos % ('z' - 'a' + 1)); + text_buf[i] = (char)(unsigned char)('z' - pos % ('z' - 'a' + 1)); else - text_buf[i] = (char) (unsigned char) ('a' + pos % ('z' - 'a' + 1)); + text_buf[i] = (char)(unsigned char)('a' + pos % ('z' - 'a' + 1)); } break; case test_msg_vlarge_app_data: /* Simulate binary data */ for (i = 0; i < buf_size; ++i) { - bin_buf[i] = (uint8_t) ((i + 182) & 0xFF); + bin_buf[i] = (uint8_t)((i + 182) & 0xFF); } break; case test_msg_vlarge_rclient_data: /* Simulate binary data */ for (i = 0; i < buf_size; ++i) { - bin_buf[i] = (uint8_t) ((111 - i) & 0xFF); + bin_buf[i] = (uint8_t)((111 - i) & 0xFF); } break; default: @@ -1928,22 +1928,22 @@ main (int argc, unsigned int res; use_vlarge = (0 != mhdt_has_in_name (argv[0], "_vlarge")); - use_large = (! use_vlarge) && (0 != mhdt_has_in_name (argv[0], "_large")); + use_large = (!use_vlarge) && (0 != mhdt_has_in_name (argv[0], "_large")); use_tls_tool = TLS_CLI_NO_TOOL; test_tls = mhdt_has_in_name (argv[0], "_tls"); - verbose = ! (mhdt_has_param (argc, argv, "-q") || - mhdt_has_param (argc, argv, "--quiet") || - mhdt_has_param (argc, argv, "-s") || - mhdt_has_param (argc, argv, "--silent")); + verbose = !(mhdt_has_param (argc, argv, "-q") + || mhdt_has_param (argc, argv, "--quiet") + || mhdt_has_param (argc, argv, "-s") + || mhdt_has_param (argc, argv, "--silent")); - if ((((int) ((~((unsigned int) 0U)) >> 1)) / 1000) < test_timeout) + if ((((int)((~((unsigned int)0U)) >> 1)) / 1000) < test_timeout) { fprintf (stderr, "The test timeout value (%d) is too large.\n" "The test cannot run.\n", test_timeout); fprintf (stderr, "The maximum allowed timeout value is %d.\n", - (((int) ((~((unsigned int) 0U)) >> 1)) / 1000)); + (((int)((~((unsigned int)0U)) >> 1)) / 1000)); return 3; } @@ -1957,12 +1957,12 @@ main (int argc, use_tls_tool = TLS_CLI_OPENSSL; else if (mhdt_has_param (argc, argv, "--use-gnutls-lib")) use_tls_tool = TLS_LIB_GNUTLS; -#if defined(HAVE_FORK) && defined(HAVE_WAITPID) +# if defined(HAVE_FORK) && defined(HAVE_WAITPID) else if (0 == system ("gnutls-cli --version 1> /dev/null 2> /dev/null")) use_tls_tool = TLS_CLI_GNUTLS; else if (0 == system ("openssl version 1> /dev/null 2> /dev/null")) use_tls_tool = TLS_CLI_OPENSSL; -#endif /* HAVE_FORK && HAVE_WAITPID */ +# endif /* HAVE_FORK && HAVE_WAITPID */ if (verbose) { switch (use_tls_tool) @@ -1981,8 +1981,8 @@ main (int argc, externalErrorExitDesc ("Wrong 'use_tls_tool' value"); } } - if ( (TLS_LIB_GNUTLS == use_tls_tool) && - (GNUTLS_E_SUCCESS != gnutls_global_init ()) ) + if ((TLS_LIB_GNUTLS == use_tls_tool) + && (GNUTLS_E_SUCCESS != gnutls_global_init ())) externalErrorExitDesc ("gnutls_global_init() failed"); #else /* ! HTTPS_SUPPORT */ @@ -1991,7 +1991,7 @@ main (int argc, #endif /* ! HTTPS_SUPPORT */ } - if (! global_test_init ()) + if (!global_test_init ()) { #ifdef HTTPS_SUPPORT if (test_tls && (TLS_LIB_GNUTLS == use_tls_tool)) diff --git a/src/tools/mhdtl_get_cpu_count.c b/src/tools/mhdtl_get_cpu_count.c @@ -80,7 +80,7 @@ # ifndef ALL_PROCESSOR_GROUPS # define ALL_PROCESSOR_GROUPS 0xFFFFu # endif /* ALL_PROCESSOR_GROUPS */ -#elif defined(_WIN32) && ! defined (__CYGWIN__) +#elif defined(_WIN32) && !defined(__CYGWIN__) # error Windows headers are required for Windows build #endif /* HAVE_WINDOWS_H */ #ifdef HAVE_SCHED_H @@ -93,7 +93,7 @@ # include <stdbool.h> #endif /* HAVE_STDBOOL_H */ -#if ! defined(HAS_DECL_CPU_SETSIZE) && ! defined(CPU_SETSIZE) +#if !defined(HAS_DECL_CPU_SETSIZE) && !defined(CPU_SETSIZE) # define CPU_SETSIZE (1024) # define CPU_SETSIZE_SAFE (64) #else /* HAS_DECL_CPU_SETSIZE || CPU_SETSIZE */ @@ -101,35 +101,35 @@ #endif /* HAS_DECL_CPU_SETSIZE || CPU_SETSIZE */ /* Check and fix possible missing macros */ -#if ! defined(HAS_DECL_CTL_HW) && defined(CTL_HW) +#if !defined(HAS_DECL_CTL_HW) && defined(CTL_HW) # define HAS_DECL_CTL_HW 1 #endif /* ! HAS_DECL_CTL_HW && CTL_HW */ -#if ! defined(HAS_DECL_HW_NCPUONLINE) && defined(HW_NCPUONLINE) +#if !defined(HAS_DECL_HW_NCPUONLINE) && defined(HW_NCPUONLINE) # define HAS_DECL_HW_NCPUONLINE 1 #endif /* ! HAS_DECL_HW_NCPUONLINE && HW_NCPUONLINE */ -#if ! defined(HAS_DECL_HW_AVAILCPU) && defined(HW_AVAILCPU) +#if !defined(HAS_DECL_HW_AVAILCPU) && defined(HW_AVAILCPU) # define HAS_DECL_HW_AVAILCPU 1 #endif /* ! HAS_DECL_HW_AVAILCPU && HW_AVAILCPU */ -#if ! defined(HAS_DECL_HW_NCPU) && defined(HW_NCPU) +#if !defined(HAS_DECL_HW_NCPU) && defined(HW_NCPU) # define HAS_DECL_HW_NCPU 1 #endif /* ! HAS_DECL_HW_NCPU && HW_NCPU */ -#if ! defined(HAS_DECL__SC_NPROCESSORS_ONLN) && defined(_SC_NPROCESSORS_ONLN) +#if !defined(HAS_DECL__SC_NPROCESSORS_ONLN) && defined(_SC_NPROCESSORS_ONLN) # define HAS_DECL__SC_NPROCESSORS_ONLN 1 #endif /* ! HAS_DECL__SC_NPROCESSORS_ONLN && _SC_NPROCESSORS_ONLN */ -#if ! defined(HAS_DECL__SC_NPROC_ONLN) && defined(_SC_NPROC_ONLN) +#if !defined(HAS_DECL__SC_NPROC_ONLN) && defined(_SC_NPROC_ONLN) # define HAS_DECL__SC_NPROC_ONLN 1 #endif /* ! HAS_DECL__SC_NPROC_ONLN && _SC_NPROC_ONLN */ -#if ! defined(HAS_DECL__SC_CRAY_NCPU) && defined(_SC_CRAY_NCPU) +#if !defined(HAS_DECL__SC_CRAY_NCPU) && defined(_SC_CRAY_NCPU) # define HAS_DECL__SC_CRAY_NCPU 1 #endif /* ! HAS_DECL__SC_CRAY_NCPU && _SC_CRAY_NCPU */ -#if ! defined(HAS_DECL__SC_NPROCESSORS_CONF) && defined(_SC_NPROCESSORS_CONF) +#if !defined(HAS_DECL__SC_NPROCESSORS_CONF) && defined(_SC_NPROCESSORS_CONF) # define HAS_DECL__SC_NPROCESSORS_CONF 1 #endif /* ! HAVE_DECL__SC_NPROCESSORS_CONF && _SC_NPROCESSORS_CONF */ @@ -155,9 +155,9 @@ mhdtl_get_proc_cpu_count_sched_getaffinity_ (void) cpu_set_t cur_set; if (0 == sched_getaffinity (getpid (), sizeof (cur_set), &cur_set)) { -#ifdef HAVE_CPU_COUNT +# ifdef HAVE_CPU_COUNT ret = CPU_COUNT (&cur_set); -#else /* ! HAVE_CPU_COUNT */ +# else /* ! HAVE_CPU_COUNT */ unsigned int i; ret = 0; for (i = 0; i < CPU_SETSIZE_SAFE; ++i) @@ -167,10 +167,10 @@ mhdtl_get_proc_cpu_count_sched_getaffinity_ (void) } if (0 == ret) ret = -1; -#endif /* ! HAVE_CPU_COUNT */ +# endif /* ! HAVE_CPU_COUNT */ } } -#ifdef HAVE_CPU_COUNT_S +# ifdef HAVE_CPU_COUNT_S if (0 >= ret) { /* Use 256 times larger size than size for default maximum CPU number. @@ -184,16 +184,16 @@ mhdtl_get_proc_cpu_count_sched_getaffinity_ (void) { if (0 == sched_getaffinity (getpid (), set_size_bytes, p_set)) { -#ifndef MHD_FUNC_CPU_COUNT_S_GETS_CPUS +# ifndef MHD_FUNC_CPU_COUNT_S_GETS_CPUS ret = CPU_COUNT_S (set_size_bytes, p_set); -#else /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ +# else /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ ret = CPU_COUNT_S (set_size_cpus, p_set); -#endif /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ +# endif /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ } CPU_FREE (p_set); } } -#endif /* HAVE_CPU_COUNT_S */ +# endif /* HAVE_CPU_COUNT_S */ #endif /* HAVE_SCHED_GETAFFINITY && HAVE_GETPID */ if (0 >= ret) return -1; @@ -218,12 +218,12 @@ mhdtl_get_proc_cpu_count_cpuset_getaffinity_ (void) cpuset_t cur_mask; /* The should get "anonymous" mask/set. The anonymous mask is always a subset of the assigned set (which is a subset of the root set). */ - if (0 == cpuset_getaffinity (CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, + if (0 == cpuset_getaffinity (CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t)-1, sizeof (cur_mask), &cur_mask)) { -#ifdef HAVE_CPU_COUNT +# ifdef HAVE_CPU_COUNT ret = CPU_COUNT (&cur_mask); -#else /* ! HAVE_CPU_COUNT */ +# else /* ! HAVE_CPU_COUNT */ unsigned int i; ret = 0; for (i = 0; i < CPU_SETSIZE_SAFE; ++i) @@ -233,10 +233,10 @@ mhdtl_get_proc_cpu_count_cpuset_getaffinity_ (void) } if (0 == ret) ret = -1; -#endif /* ! HAVE_CPU_COUNT */ +# endif /* ! HAVE_CPU_COUNT */ } } -#ifdef HAVE_CPU_COUNT_S +# ifdef HAVE_CPU_COUNT_S if (0 >= ret) { /* Use 256 times larger size than size for default maximum CPU number. @@ -248,19 +248,19 @@ mhdtl_get_proc_cpu_count_cpuset_getaffinity_ (void) p_mask = CPU_ALLOC (mask_size_cpus); if (NULL != p_mask) { - if (0 == cpuset_getaffinity (CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, + if (0 == cpuset_getaffinity (CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t)-1, mask_size_bytes, p_mask)) { -#ifndef MHD_FUNC_CPU_COUNT_S_GETS_CPUS +# ifndef MHD_FUNC_CPU_COUNT_S_GETS_CPUS ret = CPU_COUNT_S (mask_size_bytes, p_mask); -#else /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ +# else /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ ret = CPU_COUNT_S (mask_size_cpus, p_mask); -#endif /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ +# endif /* MHD_FUNC_CPU_COUNT_S_GETS_CPUS */ } CPU_FREE (p_mask); } } -#endif /* HAVE_CPU_COUNT_S */ +# endif /* HAVE_CPU_COUNT_S */ #endif /* HAVE_CPUSET_GETAFFINITY */ if (0 >= ret) return -1; @@ -288,12 +288,12 @@ mhdtl_get_proc_cpu_count_sched_getaffinity_np_ (void) cpuset_ptr)) { cpuid_t cpu_num; -#if defined(HAVE_SYSCONF) && defined(HAVE_DECL__SC_NPROCESSORS_CONF) +# if defined(HAVE_SYSCONF) && defined(HAVE_DECL__SC_NPROCESSORS_CONF) unsigned int max_num = 0; long sc_value; sc_value = sysconf (_SC_NPROCESSORS_ONLN); if (0 < sc_value) - max_num = (unsigned int) sc_value; + max_num = (unsigned int)sc_value; if (0 < max_num) { ret = 0; @@ -302,7 +302,7 @@ mhdtl_get_proc_cpu_count_sched_getaffinity_np_ (void) ++ret; } else /* Combined with the next 'if' */ -#endif /* HAVE_SYSCONF && HAVE_DECL__SC_NPROCESSORS_CONF */ +# endif /* HAVE_SYSCONF && HAVE_DECL__SC_NPROCESSORS_CONF */ if (1) { int res; @@ -315,14 +315,14 @@ mhdtl_get_proc_cpu_count_sched_getaffinity_np_ (void) ++ret; } while (0 <= res); } -#ifdef __NetBSD__ +# ifdef __NetBSD__ if (0 == ret) { /* On NetBSD "unset" affinity (exactly zero CPUs) means "all CPUs are available". */ ret = mhdtl_get_sys_cpu_count_sysctl_ (); } -#endif /* __NetBSD__ */ +# endif /* __NetBSD__ */ } cpuset_destroy (cpuset_ptr); } @@ -343,13 +343,13 @@ static int mhdtl_get_proc_cpu_count_w32_ (void) { int ret = -1; -#if defined(_WIN32) && ! defined(__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) /* W32 Native */ /** * Maximum used number of CPU groups. * Improvement: Implement dynamic allocation when it would be reasonable */ -#define MHDT_MAX_GROUP_COUNT 128 +# define MHDT_MAX_GROUP_COUNT 128 /** * The count of logical CPUs as returned by GetProcessAffinityMask() */ @@ -378,8 +378,8 @@ mhdtl_get_proc_cpu_count_w32_ (void) PUSHORT GroupArray); GPGA_PTR ptrGetProcessGroupAffinity; ptrGetProcessGroupAffinity = - (GPGA_PTR) (void *) GetProcAddress (k32hndl, - "GetProcessGroupAffinity"); + (GPGA_PTR)(void *)GetProcAddress (k32hndl, + "GetProcessGroupAffinity"); if (NULL == ptrGetProcessGroupAffinity) { /* Windows version before Win7 */ @@ -419,7 +419,7 @@ mhdtl_get_proc_cpu_count_w32_ (void) { /* Exactly one processor group assigned to the process */ single_cpu_group_assigned = true; -#if 0 /* Disabled code */ +# if 0 /* Disabled code */ /* The value returned by GetThreadGroupAffinity() is not relevant as for the new threads the process affinity mask is used. */ ULONG_PTR proc_aff2; @@ -428,20 +428,20 @@ mhdtl_get_proc_cpu_count_w32_ (void) GroupAffinity); GTGA_PTR ptrGetThreadGroupAffinity; ptrGetThreadGroupAffinity = - (GTGA_PTR) (void *) GetProcAddress (k32hndl, - "GetThreadGroupAffinity"); + (GTGA_PTR)(void *)GetProcAddress (k32hndl, + "GetThreadGroupAffinity"); if (NULL != ptrGetThreadGroupAffinity) { struct mhdt_GR_AFFINITY thr_gr_aff; if (ptrGetThreadGroupAffinity (GetCurrentThread (), &thr_gr_aff)) - proc_aff2 = (ULONG_PTR) thr_gr_aff.Mask; + proc_aff2 = (ULONG_PTR)thr_gr_aff.Mask; } -#endif /* Disabled code */ +# endif /* Disabled code */ } } ptrGetProcessDefaultCpuSetMasks = - (GPDCSM_PTR) (void *) GetProcAddress (k32hndl, - "GetProcessDefaultCpuSetMasks"); + (GPDCSM_PTR)(void *)GetProcAddress (k32hndl, + "GetProcessDefaultCpuSetMasks"); if (NULL != ptrGetProcessDefaultCpuSetMasks) { /* This is Iron Release / Codename Fe @@ -473,7 +473,7 @@ mhdtl_get_proc_cpu_count_w32_ (void) win_fe_or_later = false; cpu_set_mask_assigned = false; } - if (! win_fe_or_later) + if (!win_fe_or_later) { /* The OS is not capable of distributing threads across different processor groups. Results reported by GetProcessAffinityMask() @@ -494,7 +494,7 @@ mhdtl_get_proc_cpu_count_w32_ (void) } else { - if (! single_cpu_group_assigned) + if (!single_cpu_group_assigned) { /* This is a multi processor group process on Win11 (or later). Each processor group may have different affinity and @@ -593,11 +593,11 @@ mhdtl_get_sys_cpu_count_special_api_ (void) { /* HP-UX things */ struct pst_dynamic psd_data; - memset ((void *) &psd_data, 0, sizeof (psd_data)); - if (1 == pstat_getdynamic (&psd_data, sizeof (psd_data), (size_t) 1, 0)) + memset ((void *)&psd_data, 0, sizeof (psd_data)); + if (1 == pstat_getdynamic (&psd_data, sizeof (psd_data), (size_t)1, 0)) { if (0 < psd_data.psd_proc_cnt) - ret = (int) psd_data.psd_proc_cnt; + ret = (int)psd_data.psd_proc_cnt; } } #endif /* HAVE_PSTAT_GETDYNAMIC */ @@ -612,7 +612,7 @@ mhdtl_get_sys_cpu_count_special_api_ (void) ++ret; } #endif /* HAVE_VXCPUENABLEDGET */ -#if defined(_WIN32) && ! defined (__CYGWIN__) +#if defined(_WIN32) && !defined(__CYGWIN__) if (0 >= ret) { /* Native W32 */ @@ -624,13 +624,13 @@ mhdtl_get_sys_cpu_count_special_api_ (void) GAPC_PTR ptrGetActiveProcessorCount; /* Available on W7 or later */ ptrGetActiveProcessorCount = - (GAPC_PTR) (void *) GetProcAddress (k32hndl, "GetActiveProcessorCount"); + (GAPC_PTR)(void *)GetProcAddress (k32hndl, "GetActiveProcessorCount"); if (NULL != ptrGetActiveProcessorCount) { DWORD res; res = ptrGetActiveProcessorCount (ALL_PROCESSOR_GROUPS); - ret = (int) res; - if (res != (DWORD) ret) + ret = (int)res; + if (res != (DWORD)ret) ret = -1; /* Overflow */ } } @@ -641,15 +641,15 @@ mhdtl_get_sys_cpu_count_special_api_ (void) /* May give incorrect (low) result on versions from W7 to W11 when more then 64 CPUs are available */ ptrGetNativeSystemInfo = - (GNSI_PTR) (void *) GetProcAddress (k32hndl, "GetNativeSystemInfo"); + (GNSI_PTR)(void *)GetProcAddress (k32hndl, "GetNativeSystemInfo"); if (NULL != ptrGetNativeSystemInfo) { SYSTEM_INFO sysInfo; - memset ((void *) &sysInfo, 0, sizeof (sysInfo)); + memset ((void *)&sysInfo, 0, sizeof (sysInfo)); ptrGetNativeSystemInfo (&sysInfo); - ret = (int) sysInfo.dwNumberOfProcessors; - if (sysInfo.dwNumberOfProcessors != (DWORD) ret) + ret = (int)sysInfo.dwNumberOfProcessors; + if (sysInfo.dwNumberOfProcessors != (DWORD)ret) ret = -1; /* Overflow */ } } @@ -661,10 +661,10 @@ mhdtl_get_sys_cpu_count_special_api_ (void) /* May give incorrect (low) result on versions from W7 to W11 when more then 64 CPUs are available */ SYSTEM_INFO sysInfo; - memset ((void *) &sysInfo, 0, sizeof (sysInfo)); + memset ((void *)&sysInfo, 0, sizeof (sysInfo)); GetSystemInfo (&sysInfo); - ret = (int) sysInfo.dwNumberOfProcessors; - if (sysInfo.dwNumberOfProcessors != (DWORD) ret) + ret = (int)sysInfo.dwNumberOfProcessors; + if (sysInfo.dwNumberOfProcessors != (DWORD)ret) ret = -1; /* Overflow */ } #endif /* _WIN32 && ! __CYGWIN__ */ @@ -690,7 +690,7 @@ mhdtl_get_sys_cpu_count_sysctl_ (void) /* Do not use sysctl() function on GNU/Linux even if sysctl() is available */ #ifndef __linux__ -#ifdef HAVE_SYSCTLBYNAME +# ifdef HAVE_SYSCTLBYNAME if (0 >= ret) { size_t value_size = sizeof (ret); @@ -736,8 +736,8 @@ mhdtl_get_sys_cpu_count_sysctl_ (void) || (sizeof (ret) != value_size)) ret = -1; } -#endif /* HAVE_SYSCTLBYNAME */ -#if defined(HAVE_SYSCTL) && \ +# endif /* HAVE_SYSCTLBYNAME */ +# if defined(HAVE_SYSCTL) && \ defined(HAS_DECL_CTL_HW) && \ defined(HAS_DECL_HW_NCPUONLINE) if (0 >= ret) @@ -749,8 +749,8 @@ mhdtl_get_sys_cpu_count_sysctl_ (void) || (sizeof (ret) != value_size)) ret = -1; } -#endif /* HAVE_SYSCTL && HAS_DECL_CTL_HW && HAS_DECL_HW_NCPUONLINE */ -#if defined(HAVE_SYSCTL) && \ +# endif /* HAVE_SYSCTL && HAS_DECL_CTL_HW && HAS_DECL_HW_NCPUONLINE */ +# if defined(HAVE_SYSCTL) && \ defined(HAS_DECL_CTL_HW) && \ defined(HAS_DECL_HW_AVAILCPU) if (0 >= ret) @@ -762,7 +762,7 @@ mhdtl_get_sys_cpu_count_sysctl_ (void) || (sizeof (ret) != value_size)) ret = -1; } -#endif /* HAVE_SYSCTL && HAS_DECL_CTL_HW && HAS_DECL_HW_AVAILCPU */ +# endif /* HAVE_SYSCTL && HAS_DECL_CTL_HW && HAS_DECL_HW_AVAILCPU */ #endif /* ! __linux__ */ if (0 >= ret) return -1; @@ -788,7 +788,7 @@ mhdtl_get_sys_cpu_count_sysctl_fallback_ (void) /* Do not use sysctl() function on GNU/Linux even if sysctl() is available */ #ifndef __linux__ -#ifdef HAVE_SYSCTLBYNAME +# ifdef HAVE_SYSCTLBYNAME if (0 >= ret) { size_t value_size = sizeof (ret); @@ -798,8 +798,8 @@ mhdtl_get_sys_cpu_count_sysctl_fallback_ (void) || (sizeof (ret) != value_size)) ret = -1; } -#endif /* HAVE_SYSCTLBYNAME */ -#if defined(HAVE_SYSCTL) && \ +# endif /* HAVE_SYSCTLBYNAME */ +# if defined(HAVE_SYSCTL) && \ defined(HAS_DECL_CTL_HW) && \ defined(HAS_DECL_HW_NCPU) if (0 >= ret) @@ -811,7 +811,7 @@ mhdtl_get_sys_cpu_count_sysctl_fallback_ (void) || (sizeof (ret) != value_size)) ret = -1; } -#endif /* HAVE_SYSCTL && HAS_DECL_CTL_HW && HAS_DECL_HW_NCPU */ +# endif /* HAVE_SYSCTL && HAS_DECL_CTL_HW && HAS_DECL_HW_NCPU */ #endif /* ! __linux__ */ if (0 >= ret) return -1; @@ -834,18 +834,18 @@ mhdtl_get_sys_cpu_count_sysconf_ (void) #if defined(HAVE_SYSCONF) && \ (defined(HAS_DECL__SC_NPROCESSORS_ONLN) || defined(HAS_DECL__SC_NPROC_ONLN)) long value = -1; -#ifdef HAS_DECL__SC_NPROCESSORS_ONLN +# ifdef HAS_DECL__SC_NPROCESSORS_ONLN if (0 >= value) value = sysconf (_SC_NPROCESSORS_ONLN); -#endif /* HAS_DECL__SC_NPROCESSORS_ONLN */ -#ifdef HAS_DECL__SC_NPROC_ONLN +# endif /* HAS_DECL__SC_NPROCESSORS_ONLN */ +# ifdef HAS_DECL__SC_NPROC_ONLN if (0 >= value) value = sysconf (_SC_NPROC_ONLN); -#endif /* HAS_DECL__SC_NPROC_ONLN */ +# endif /* HAS_DECL__SC_NPROC_ONLN */ if (0 >= value) return -1; - ret = (int) value; - if ((long) ret != value) + ret = (int)value; + if ((long)ret != value) return -1; /* Overflow */ #endif /* HAVE_SYSCONF && (HAS_DECL__SC_NPROCESSORS_ONLN || HAS_DECL__SC_NPROC_ONLN) */ @@ -870,18 +870,18 @@ mhdtl_get_sys_cpu_count_sysconf_fallback_ (void) #if defined(HAVE_SYSCONF) && \ (defined(HAS_DECL__SC_CRAY_NCPU) || defined(HAS_DECL__SC_NPROCESSORS_CONF)) long value = -1; -#ifdef HAS_DECL__SC_CRAY_NCPU +# ifdef HAS_DECL__SC_CRAY_NCPU if (0 >= value) value = sysconf (_SC_CRAY_NCPU); -#endif /* HAS_DECL__SC_CRAY_NCPU */ -#ifdef HAS_DECL__SC_NPROCESSORS_CONF +# endif /* HAS_DECL__SC_CRAY_NCPU */ +# ifdef HAS_DECL__SC_NPROCESSORS_CONF if (0 >= value) value = sysconf (_SC_NPROCESSORS_CONF); -#endif /* HAS_DECL__SC_NPROCESSORS_CONF */ +# endif /* HAS_DECL__SC_NPROCESSORS_CONF */ if (0 >= value) return -1; - ret = (int) value; - if ((long) ret != value) + ret = (int)value; + if ((long)ret != value) return -1; /* Overflow */ #endif /* HAVE_SYSCONF && (HAS_DECL__SC_CRAY_NCPU || HAS_DECL__SC_NPROCESSORS_CONF) */ @@ -915,7 +915,7 @@ mhdtl_get_system_cpu_count (void) /* Try sysconf() as the last resort as this is a generic interface which can be implemented by parsing system files. */ res = mhdtl_get_sys_cpu_count_sysconf_ (); -#if ! defined(__linux__) && ! defined(__GLIBC__) +#if !defined(__linux__) && !defined(__GLIBC__) if (0 < res) return res; #else /* __linux__ || __GLIBC__ */ @@ -947,7 +947,7 @@ mhdtl_get_system_cpu_count (void) return res; res = mhdtl_get_sys_cpu_count_sysconf_fallback_ (); -#if ! defined(__linux__) && ! defined(__GLIBC__) +#if !defined(__linux__) && !defined(__GLIBC__) if (0 < res) return res; #else /* __linux__ || __GLIBC__ */ diff --git a/src/tools/mhdtl_str_to_uint.h b/src/tools/mhdtl_str_to_uint.h @@ -69,7 +69,7 @@ mhdtl_str_to_uint (const char *str, unsigned int *value) unsigned int prev_v; if (('0' > chr) || ('9' < chr)) break; - digit = (unsigned char) (chr - '0'); + digit = (unsigned char)(chr - '0'); prev_v = v; v *= 10; if (v / 10 == prev_v) diff --git a/src/tools/perf_replies.c b/src/tools/perf_replies.c @@ -57,7 +57,7 @@ /** * Determine length of static string / macro strings at compile time. */ -#define mhd_SSTR_LEN(macro) (sizeof(macro) / sizeof(char) - 1) +# define mhd_SSTR_LEN(macro) (sizeof(macro) / sizeof(char) - 1) #endif /* ! mhd_SSTR_LEN */ /* Static constants */ @@ -90,8 +90,8 @@ set_self_name (int argc, char *const *argv) { const char *last_w32_dir_sep; last_w32_dir_sep = strrchr (argv[0], '\\'); - if ((NULL == last_dir_sep) || - ((NULL != last_w32_dir_sep) && (last_w32_dir_sep > last_dir_sep))) + if ((NULL == last_dir_sep) + || ((NULL != last_w32_dir_sep) && (last_w32_dir_sep > last_dir_sep))) last_dir_sep = last_w32_dir_sep; } #endif /* _WIN32 */ @@ -147,7 +147,7 @@ detect_cpu_core_count (void) printf ("Detected %d logical CPU core%s on this system.\n", sys_cpu_count, (1 == sys_cpu_count) ? "" : "s"); } - return (unsigned int) sys_cpu_count; + return (unsigned int)sys_cpu_count; } @@ -185,7 +185,7 @@ detect_process_cpu_core_count (void) { printf ("Detected %d logical CPU core%s available to run threads " "of this process.\n", res, (1 == res) ? "" : "s"); - num_proc_cpu_cores = (unsigned int) res; + num_proc_cpu_cores = (unsigned int)res; } if (num_proc_cpu_cores > sys_cpu_cores) { @@ -318,8 +318,8 @@ static void show_help (void) { union MHD_LibInfoFixedData mhdl_info; - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, - &mhdl_info); + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, + &mhdl_info); printf ("Usage: %s [OPTIONS] [PORT_NUMBER]\n", self_name); printf ("Start MHD2-based web-server optimised for fast replies.\n"); printf ("\n"); @@ -370,9 +370,9 @@ show_help (void) printf ("\n"); printf ("This tool is part of GNU libmicrohttpd suite.\n"); printf ("%s\n", tool_copyright); - if ((MHD_NO == mhdl_info.v_types_sockets_polling.func_select) && - (MHD_NO == mhdl_info.v_types_sockets_polling.func_poll) && - (MHD_NO == mhdl_info.v_types_sockets_polling.tech_epoll)) + if ((MHD_NO == mhdl_info.v_types_sockets_polling.func_select) + && (MHD_NO == mhdl_info.v_types_sockets_polling.func_poll) + && (MHD_NO == mhdl_info.v_types_sockets_polling.tech_epoll)) fprintf (stderr, "No internal sockets polling function is available!\n"); } @@ -442,9 +442,9 @@ process_param__all_cpus (const char *param_name) "with '-P' or '--thread-per-conn'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.all_cpus = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.all_cpus = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -508,9 +508,9 @@ process_param__thread_per_conn (const char *param_name) "with '-t' or '--threads'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.thread_per_conn = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.thread_per_conn = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -532,9 +532,9 @@ process_param__epoll (const char *param_name) "with '-s' or '--select'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.epoll = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.epoll = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -553,9 +553,9 @@ process_param__poll (const char *param_name) "with '-s' or '--select'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.poll = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.poll = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -574,9 +574,9 @@ process_param__select (const char *param_name) "with '-p' or '--poll'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.select = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.select = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -613,9 +613,9 @@ process_param__empty (const char *param_name) "with '-J' or '--jumbo'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.empty = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.empty = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -652,9 +652,9 @@ process_param__tiny (const char *param_name) "with '-J' or '--jumbo'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.tiny = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.tiny = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -691,9 +691,9 @@ process_param__medium (const char *param_name) "with '-J' or '--jumbo'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.medium = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.medium = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -730,9 +730,9 @@ process_param__large (const char *param_name) "with '-J' or '--jumbo'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.large = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.large = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -769,9 +769,9 @@ process_param__xlarge (const char *param_name) "with '-J' or '--jumbo'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.xlarge = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.xlarge = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -808,9 +808,9 @@ process_param__jumbo (const char *param_name) "with '-X' or '--xlarge'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.jumbo = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.jumbo = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -829,9 +829,9 @@ process_param__shared (const char *param_name) "with '-U' or '--unique'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.shared = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.shared = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -850,9 +850,9 @@ process_param__single (const char *param_name) "with '-U' or '--unique'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.single = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.single = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -871,9 +871,9 @@ process_param__unique (const char *param_name) "with '-I' or '--single'.\n", param_name); return PERF_RPL_PARAM_ERROR; } - tool_params.unique = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.unique = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -938,9 +938,9 @@ process_param__timeout (const char *param_name, const char *param_tail, static enum PerfRepl_param_result process_param__date_header (const char *param_name) { - tool_params.date_header = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + tool_params.date_header = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -948,10 +948,10 @@ static enum PerfRepl_param_result process_param__help (const char *param_name) { /* Use only one of help | version */ - if (! tool_params.version) - tool_params.help = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + if (!tool_params.version) + tool_params.help = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -959,10 +959,10 @@ static enum PerfRepl_param_result process_param__version (const char *param_name) { /* Use only one of help | version */ - if (! tool_params.help) - tool_params.version = ! 0; - return '-' == param_name[1] ? - PERF_RPL_PARAM_FULL_STR :PERF_RPL_PARAM_ONE_CHAR; + if (!tool_params.help) + tool_params.version = !0; + return ('-' == param_name[1]) ? + PERF_RPL_PARAM_FULL_STR : PERF_RPL_PARAM_ONE_CHAR; } @@ -1065,78 +1065,78 @@ process_long_param (const char *param, const char *next_param) { const size_t param_len = strlen (param); - if ((mhd_SSTR_LEN ("all-cpus") == param_len) && - (0 == memcmp (param, "all-cpus", mhd_SSTR_LEN ("all-cpus")))) + if ((mhd_SSTR_LEN ("all-cpus") == param_len) + && (0 == memcmp (param, "all-cpus", mhd_SSTR_LEN ("all-cpus")))) return process_param__all_cpus ("--all-cpus"); - else if ((mhd_SSTR_LEN ("threads") <= param_len) && - (0 == memcmp (param, "threads", mhd_SSTR_LEN ("threads")))) + else if ((mhd_SSTR_LEN ("threads") <= param_len) + && (0 == memcmp (param, "threads", mhd_SSTR_LEN ("threads")))) return process_param__threads ("--threads", param + mhd_SSTR_LEN ("threads"), next_param); #if 0 /* disabled code */ - else if ((mhd_SSTR_LEN ("thread-per-conn") == param_len) && - (0 == memcmp (param, "thread-per-conn", - mhd_SSTR_LEN ("thread-per-conn")))) + else if ((mhd_SSTR_LEN ("thread-per-conn") == param_len) + && (0 == memcmp (param, "thread-per-conn", + mhd_SSTR_LEN ("thread-per-conn")))) return process_param__thread_per_conn ("--thread-per-conn"); #endif /* disabled code */ - else if ((mhd_SSTR_LEN ("epoll") == param_len) && - (0 == memcmp (param, "epoll", mhd_SSTR_LEN ("epoll")))) + else if ((mhd_SSTR_LEN ("epoll") == param_len) + && (0 == memcmp (param, "epoll", mhd_SSTR_LEN ("epoll")))) return process_param__epoll ("--epoll"); - else if ((mhd_SSTR_LEN ("poll") == param_len) && - (0 == memcmp (param, "poll", mhd_SSTR_LEN ("poll")))) + else if ((mhd_SSTR_LEN ("poll") == param_len) + && (0 == memcmp (param, "poll", mhd_SSTR_LEN ("poll")))) return process_param__poll ("--poll"); - else if ((mhd_SSTR_LEN ("select") == param_len) && - (0 == memcmp (param, "select", mhd_SSTR_LEN ("select")))) + else if ((mhd_SSTR_LEN ("select") == param_len) + && (0 == memcmp (param, "select", mhd_SSTR_LEN ("select")))) return process_param__select ("--select"); - else if ((mhd_SSTR_LEN ("empty") == param_len) && - (0 == memcmp (param, "empty", mhd_SSTR_LEN ("empty")))) + else if ((mhd_SSTR_LEN ("empty") == param_len) + && (0 == memcmp (param, "empty", mhd_SSTR_LEN ("empty")))) return process_param__empty ("--empty"); - else if ((mhd_SSTR_LEN ("tiny") == param_len) && - (0 == memcmp (param, "tiny", mhd_SSTR_LEN ("tiny")))) + else if ((mhd_SSTR_LEN ("tiny") == param_len) + && (0 == memcmp (param, "tiny", mhd_SSTR_LEN ("tiny")))) return process_param__tiny ("--tiny"); - else if ((mhd_SSTR_LEN ("medium") == param_len) && - (0 == memcmp (param, "medium", mhd_SSTR_LEN ("medium")))) + else if ((mhd_SSTR_LEN ("medium") == param_len) + && (0 == memcmp (param, "medium", mhd_SSTR_LEN ("medium")))) return process_param__medium ("--medium"); - else if ((mhd_SSTR_LEN ("large") == param_len) && - (0 == memcmp (param, "large", mhd_SSTR_LEN ("large")))) + else if ((mhd_SSTR_LEN ("large") == param_len) + && (0 == memcmp (param, "large", mhd_SSTR_LEN ("large")))) return process_param__large ("--large"); - else if ((mhd_SSTR_LEN ("xlarge") == param_len) && - (0 == memcmp (param, "xlarge", mhd_SSTR_LEN ("xlarge")))) + else if ((mhd_SSTR_LEN ("xlarge") == param_len) + && (0 == memcmp (param, "xlarge", mhd_SSTR_LEN ("xlarge")))) return process_param__xlarge ("--xlarge"); - else if ((mhd_SSTR_LEN ("jumbo") == param_len) && - (0 == memcmp (param, "jumbo", mhd_SSTR_LEN ("jumbo")))) + else if ((mhd_SSTR_LEN ("jumbo") == param_len) + && (0 == memcmp (param, "jumbo", mhd_SSTR_LEN ("jumbo")))) return process_param__jumbo ("--jumbo"); - else if ((mhd_SSTR_LEN ("shared") == param_len) && - (0 == memcmp (param, "shared", mhd_SSTR_LEN ("shared")))) + else if ((mhd_SSTR_LEN ("shared") == param_len) + && (0 == memcmp (param, "shared", mhd_SSTR_LEN ("shared")))) return process_param__shared ("--shared"); - else if ((mhd_SSTR_LEN ("single") == param_len) && - (0 == memcmp (param, "single", mhd_SSTR_LEN ("single")))) + else if ((mhd_SSTR_LEN ("single") == param_len) + && (0 == memcmp (param, "single", mhd_SSTR_LEN ("single")))) return process_param__single ("--single"); - else if ((mhd_SSTR_LEN ("unique") == param_len) && - (0 == memcmp (param, "unique", mhd_SSTR_LEN ("unique")))) + else if ((mhd_SSTR_LEN ("unique") == param_len) + && (0 == memcmp (param, "unique", mhd_SSTR_LEN ("unique")))) return process_param__unique ("--unique"); - else if ((mhd_SSTR_LEN ("connections") <= param_len) && - (0 == memcmp (param, "connections", - mhd_SSTR_LEN ("connections")))) + else if ((mhd_SSTR_LEN ("connections") <= param_len) + && (0 == memcmp (param, "connections", + mhd_SSTR_LEN ("connections")))) return process_param__connections ("--connections", param + mhd_SSTR_LEN ("connections"), next_param); - else if ((mhd_SSTR_LEN ("timeout") <= param_len) && - (0 == memcmp (param, "timeout", - mhd_SSTR_LEN ("timeout")))) + else if ((mhd_SSTR_LEN ("timeout") <= param_len) + && (0 == memcmp (param, "timeout", + mhd_SSTR_LEN ("timeout")))) return process_param__timeout ("--timeout", param + mhd_SSTR_LEN ("timeout"), next_param); - else if ((mhd_SSTR_LEN ("date-header") == param_len) && - (0 == memcmp (param, "date-header", - mhd_SSTR_LEN ("date-header")))) + else if ((mhd_SSTR_LEN ("date-header") == param_len) + && (0 == memcmp (param, "date-header", + mhd_SSTR_LEN ("date-header")))) return process_param__date_header ("--date-header"); - else if ((mhd_SSTR_LEN ("help") == param_len) && - (0 == memcmp (param, "help", mhd_SSTR_LEN ("help")))) + else if ((mhd_SSTR_LEN ("help") == param_len) + && (0 == memcmp (param, "help", mhd_SSTR_LEN ("help")))) return process_param__help ("--help"); - else if ((mhd_SSTR_LEN ("version") == param_len) && - (0 == memcmp (param, "version", mhd_SSTR_LEN ("version")))) + else if ((mhd_SSTR_LEN ("version") == param_len) + && (0 == memcmp (param, "version", mhd_SSTR_LEN ("version")))) return process_param__version ("--version"); fprintf (stderr, "Unrecognised parameter: --%s.\n", param); @@ -1147,7 +1147,7 @@ process_long_param (const char *param, const char *next_param) static int process_params (int argc, char *const *argv) { - int proc_dash_param = ! 0; + int proc_dash_param = !0; int i; for (i = 1; i < argc; ++i) { @@ -1203,7 +1203,7 @@ process_params (int argc, char *const *argv) fprintf (stderr, "Wrong port number: %s\n", p); return PERF_RPL_ERR_CODE_BAD_PARAM; } - mhd_port = (uint_least16_t) read_port; + mhd_port = (uint_least16_t)read_port; } else { @@ -1219,8 +1219,8 @@ static void print_version (void) { union MHD_LibInfoFixedData mhdl_data; - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_STRING, - &mhdl_data); + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_VERSION_STRING, + &mhdl_data); printf ("%s (GNU libmicrohttpd2", self_name); if (0 != build_revision[0]) printf ("; %s", build_revision); @@ -1244,7 +1244,7 @@ print_all_cores_used (void) static void check_apply_param__all_cpus (void) { - if (! tool_params.all_cpus) + if (!tool_params.all_cpus) return; num_threads = get_process_cpu_core_count (); @@ -1291,8 +1291,8 @@ check_apply_param__threads (void) static int check_apply_param__thread_per_conn (void) { - if (! tool_params.thread_per_conn) - return ! 0; + if (!tool_params.thread_per_conn) + return !0; if (tool_params.epoll) { @@ -1302,7 +1302,7 @@ check_apply_param__thread_per_conn (void) } num_threads = 1; - return ! 0; + return !0; } @@ -1314,17 +1314,17 @@ static int check_param__epoll (void) { union MHD_LibInfoFixedData mhdl_info; - if (! tool_params.epoll) - return ! 0; - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, - &mhdl_info); + if (!tool_params.epoll) + return !0; + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, + &mhdl_info); if (MHD_NO == mhdl_info.v_types_sockets_polling.tech_epoll) { fprintf (stderr, "'epoll' was requested, but this MHD build does not " "support 'epoll' functionality.\n"); return 0; } - return ! 0; + return !0; } @@ -1333,17 +1333,17 @@ static int check_param__poll (void) { union MHD_LibInfoFixedData mhdl_info; - if (! tool_params.poll) - return ! 0; - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, - &mhdl_info); + if (!tool_params.poll) + return !0; + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, + &mhdl_info); if (MHD_NO == mhdl_info.v_types_sockets_polling.func_poll) { fprintf (stderr, "poll() was requested, but this MHD build does not " "support polling by poll().\n"); return 0; } - return ! 0; + return !0; } @@ -1352,17 +1352,17 @@ static int check_param__select (void) { union MHD_LibInfoFixedData mhdl_info; - if (! tool_params.select) - return ! 0; - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, - &mhdl_info); + if (!tool_params.select) + return !0; + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_TYPES_SOCKETS_POLLING, + &mhdl_info); if (MHD_NO == mhdl_info.v_types_sockets_polling.func_select) { fprintf (stderr, "select() was requested, but this MHD build does not " "support polling by select().\n"); return 0; } - return ! 0; + return !0; } @@ -1371,7 +1371,7 @@ check_param__empty_tiny_medium_large_xlarge_jumbo (void) { if (0 == (tool_params.empty | tool_params.tiny | tool_params.medium | tool_params.large | tool_params.xlarge | tool_params.jumbo)) - tool_params.tiny = ! 0; + tool_params.tiny = !0; } @@ -1379,7 +1379,7 @@ static void check_param__shared_single_unique (void) { if (0 == (tool_params.shared | tool_params.single | tool_params.unique)) - tool_params.shared = ! 0; + tool_params.shared = !0; } @@ -1390,7 +1390,7 @@ static int check_param__connections (void) { if (0 == tool_params.connections) - return ! 0; + return !0; if (get_num_threads () > tool_params.connections) { fprintf (stderr, "The connections number limit (%u) is less than number " @@ -1398,7 +1398,7 @@ check_param__connections (void) tool_params.connections, get_num_threads ()); return 0; } - return ! 0; + return !0; } @@ -1424,18 +1424,18 @@ check_apply_params (void) check_apply_param__all_cpus (); check_apply_param__threads (); #if 0 /* disabled code */ - if (! check_apply_param__thread_per_conn ()) + if (!check_apply_param__thread_per_conn ()) return PERF_RPL_ERR_CODE_BAD_PARAM; #endif /* disabled code */ - if (! check_param__epoll ()) + if (!check_param__epoll ()) return PERF_RPL_ERR_CODE_BAD_PARAM; - if (! check_param__poll ()) + if (!check_param__poll ()) return PERF_RPL_ERR_CODE_BAD_PARAM; - if (! check_param__select ()) + if (!check_param__select ()) return PERF_RPL_ERR_CODE_BAD_PARAM; check_param__empty_tiny_medium_large_xlarge_jumbo (); check_param__shared_single_unique (); - if (! check_param__connections ()) + if (!check_param__connections ()) return PERF_RPL_ERR_CODE_BAD_PARAM; return 0; } @@ -1482,7 +1482,7 @@ init_response_body_data (void) { if (0 != body_dyn_size) { - body_dyn = (char *) malloc (body_dyn_size); + body_dyn = (char *)malloc (body_dyn_size); if (NULL == body_dyn) { fprintf (stderr, "Failed to allocate memory.\n"); @@ -1521,7 +1521,7 @@ init_response_body_data (void) /* Fill the body with binary-like content */ size_t pos; for (pos = 0; pos < body_dyn_size; ++pos) - body_dyn[pos] = (char) (unsigned char) (255U - pos % 256U); + body_dyn[pos] = (char)(unsigned char)(255U - pos % 256U); } else { @@ -1532,24 +1532,24 @@ init_response_body_data (void) pos += 8) { rnd_data = mini_rnd (); - body_dyn[pos + 0] = (char) (unsigned char) (rnd_data >> 0); - body_dyn[pos + 1] = (char) (unsigned char) (rnd_data >> 8); - body_dyn[pos + 2] = (char) (unsigned char) (rnd_data >> 16); - body_dyn[pos + 3] = (char) (unsigned char) (rnd_data >> 24); - body_dyn[pos + 4] = (char) (unsigned char) (rnd_data >> 32); - body_dyn[pos + 5] = (char) (unsigned char) (rnd_data >> 40); - body_dyn[pos + 6] = (char) (unsigned char) (rnd_data >> 48); - body_dyn[pos + 7] = (char) (unsigned char) (rnd_data >> 56); + body_dyn[pos + 0] = (char)(unsigned char)(rnd_data >> 0); + body_dyn[pos + 1] = (char)(unsigned char)(rnd_data >> 8); + body_dyn[pos + 2] = (char)(unsigned char)(rnd_data >> 16); + body_dyn[pos + 3] = (char)(unsigned char)(rnd_data >> 24); + body_dyn[pos + 4] = (char)(unsigned char)(rnd_data >> 32); + body_dyn[pos + 5] = (char)(unsigned char)(rnd_data >> 40); + body_dyn[pos + 6] = (char)(unsigned char)(rnd_data >> 48); + body_dyn[pos + 7] = (char)(unsigned char)(rnd_data >> 56); } rnd_data = mini_rnd (); - for ((void) pos; pos < body_dyn_size; ++pos) + for ((void)pos; pos < body_dyn_size; ++pos) { - body_dyn[pos] = (char) (unsigned char) (rnd_data); + body_dyn[pos] = (char)(unsigned char)(rnd_data); rnd_data >>= 8u; } } } - return ! 0; + return !0; } @@ -1597,7 +1597,7 @@ init_data (void) else body_dyn_size = 0; - if (! init_response_body_data ()) + if (!init_response_body_data ()) return 25; if (tool_params.unique) @@ -1616,7 +1616,7 @@ init_data (void) /* Use more responses to minimise waiting in threads while the response used by other thread. */ - if (! tool_params.thread_per_conn) + if (!tool_params.thread_per_conn) num_resps = 16 * get_num_threads (); else num_resps = 16 * get_cpu_core_count (); @@ -1689,12 +1689,12 @@ answer_shared_response (void *cls, { unsigned int resp_index; static volatile unsigned int last_index = 0; - (void) cls; /* Unused */ - (void) path; /* Unused */ - (void) upload_size; /* Unused */ + (void)cls; /* Unused */ + (void)path; /* Unused */ + (void)upload_size; /* Unused */ - if ((MHD_HTTP_METHOD_GET != method) && - (MHD_HTTP_METHOD_HEAD != method)) + if ((MHD_HTTP_METHOD_GET != method) + && (MHD_HTTP_METHOD_HEAD != method)) return MHD_action_abort_request (request); /* Unsupported method, close connection */ /* This kind of operation does not guarantee that numbers are not reused @@ -1714,12 +1714,12 @@ answer_single_response (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - (void) cls; /* Unused */ - (void) path; /* Unused */ - (void) upload_size; /* Unused */ + (void)cls; /* Unused */ + (void)path; /* Unused */ + (void)upload_size; /* Unused */ - if ((MHD_HTTP_METHOD_GET != method) && - (MHD_HTTP_METHOD_HEAD != method)) + if ((MHD_HTTP_METHOD_GET != method) + && (MHD_HTTP_METHOD_HEAD != method)) return MHD_action_abort_request (request); /* Unsupported method, close connection */ return MHD_action_from_response (request, @@ -1735,12 +1735,12 @@ answer_unique_empty_response (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - (void) cls; /* Unused */ - (void) path; /* Unused */ - (void) upload_size; /* Unused */ + (void)cls; /* Unused */ + (void)path; /* Unused */ + (void)upload_size; /* Unused */ - if ((MHD_HTTP_METHOD_GET != method) && - (MHD_HTTP_METHOD_HEAD != method)) + if ((MHD_HTTP_METHOD_GET != method) + && (MHD_HTTP_METHOD_HEAD != method)) return MHD_action_abort_request (request); /* Unsupported method, close connection */ return @@ -1757,12 +1757,12 @@ answer_unique_tiny_response (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - (void) cls; /* Unused */ - (void) path; /* Unused */ - (void) upload_size; /* Unused */ + (void)cls; /* Unused */ + (void)path; /* Unused */ + (void)upload_size; /* Unused */ - if ((MHD_HTTP_METHOD_GET != method) && - (MHD_HTTP_METHOD_HEAD != method)) + if ((MHD_HTTP_METHOD_GET != method) + && (MHD_HTTP_METHOD_HEAD != method)) return MHD_action_abort_request (request); /* Unsupported method, close connection */ return @@ -1782,12 +1782,12 @@ answer_unique_dyn_response (void *cls, enum MHD_HTTP_Method method, uint_fast64_t upload_size) { - (void) cls; /* Unused */ - (void) path; /* Unused */ - (void) upload_size; /* Unused */ + (void)cls; /* Unused */ + (void)path; /* Unused */ + (void)upload_size; /* Unused */ - if ((MHD_HTTP_METHOD_GET != method) && - (MHD_HTTP_METHOD_HEAD != method)) + if ((MHD_HTTP_METHOD_GET != method) + && (MHD_HTTP_METHOD_HEAD != method)) return MHD_action_abort_request (request); /* Unsupported method, close connection */ return @@ -1803,31 +1803,31 @@ static void print_perf_warnings (void) { int newline_needed = 0; -#if ! defined(NDEBUG) || defined(_DEBUG) +#if !defined(NDEBUG) || defined(_DEBUG) fprintf (stderr, "WARNING: Running with debug asserts enabled, " "the performance is suboptimal.\n"); - newline_needed |= ! 0; + newline_needed |= !0; #endif /* _DEBUG */ -#if defined(__GNUC__) && ! defined (__OPTIMIZE__) +#if defined(__GNUC__) && !defined(__OPTIMIZE__) fprintf (stderr, "WARNING: This tool is compiled without compiler " "optimisations enabled, the performance is suboptimal.\n"); - newline_needed |= ! 0; + newline_needed |= !0; #endif /* __GNUC__ && ! __OPTIMIZE__ */ -#if defined(__GNUC__) && defined (__OPTIMIZE_SIZE__) +#if defined(__GNUC__) && defined(__OPTIMIZE_SIZE__) fprintf (stderr, "WARNING: This tool is compiled with size-optimisations, " "the performance is suboptimal.\n"); - newline_needed |= ! 0; + newline_needed |= !0; #endif /* __GNUC__ && ! __OPTIMIZE__ */ if (1) { union MHD_LibInfoFixedData mhdl_info; - (void) MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_IS_NON_DEBUG, - &mhdl_info); + (void)MHD_lib_get_info_fixed (MHD_LIB_INFO_FIXED_IS_NON_DEBUG, + &mhdl_info); if (MHD_NO == mhdl_info.v_is_non_debug_bool) { fprintf (stderr, "WARNING: The libmicrohttpd2 library is compiled with " "debug asserts enabled, performance is suboptimal.\n"); - newline_needed |= ! 0; + newline_needed |= !0; } } if (newline_needed) @@ -1915,7 +1915,7 @@ get_mhd_def_timeout (struct MHD_Daemon *d) MHD_DAEMON_INFO_FIXED_DEFAULT_TIMEOUT_MILSEC, &d_info)) abort (); - return (unsigned long) d_info.v_default_timeout_milsec_uint32; + return (unsigned long)d_info.v_default_timeout_milsec_uint32; } @@ -1928,7 +1928,7 @@ get_mhd_suppr_date (struct MHD_Daemon *d) MHD_DAEMON_INFO_FIXED_SUPPRESS_DATE_HEADER, &d_info)) abort (); - return (int) d_info.v_suppress_date_header_bool; + return (int)d_info.v_suppress_date_header_bool; } @@ -1964,7 +1964,7 @@ run_mhd (void) /* Make sure that the detection message is printed already */ #if 0 /* Disabled code */ - if (! tool_params.thread_per_conn) + if (!tool_params.thread_per_conn) #endif /* Disabled code */ num_requsted_threads = get_num_threads (); @@ -2015,7 +2015,7 @@ run_mhd (void) #endif /* Disabled code */ opt_arr[opt_count++] = MHD_D_OPTION_WM_WORKER_THREADS (num_requsted_threads); - if (! tool_params.date_header) + if (!tool_params.date_header) opt_arr[opt_count++] = MHD_D_OPTION_SUPPRESS_DATE_HEADER (MHD_YES); if (0 != tool_params.connections) @@ -2024,7 +2024,7 @@ run_mhd (void) opt_arr[opt_count++] = MHD_D_OPTION_DEFAULT_TIMEOUT_MILSEC (tool_params.timeout - * (uint_fast32_t) 1000u); + * (uint_fast32_t)1000u); if (opt_count > (sizeof(opt_arr) / sizeof(opt_arr[0]))) abort (); @@ -2060,7 +2060,7 @@ run_mhd (void) num_used_threads = get_mhd_num_threads (d); printf ("MHD2 daemon is running.\n"); - printf (" Bind port: %u\n", (unsigned int) port); + printf (" Bind port: %u\n", (unsigned int)port); printf (" Polling function: %s\n", get_mhd_poll_func_name (d)); printf (" Threading: "); #if 0 /* Disabled code */ @@ -2080,13 +2080,13 @@ run_mhd (void) 0 == def_timeout ? "(no timeout)" : "milliseconds"); } printf (" 'Date:' header: %s\n", - (! get_mhd_suppr_date (d)) ? "Yes" : "No"); + (!get_mhd_suppr_date (d)) ? "Yes" : "No"); if (0 != port) { printf ("To test with remote client use\n" - " http://HOST_IP:%u/\n", (unsigned int) port); + " http://HOST_IP:%u/\n", (unsigned int)port); printf ("To test with client on the same host use\n" - " http://localhost:%u/\n", (unsigned int) port); + " http://localhost:%u/\n", (unsigned int)port); printf ("\nPress ENTER to stop.\n"); } if (1) @@ -2094,7 +2094,7 @@ run_mhd (void) char buf[10]; const char *get_ret; get_ret = fgets (buf, sizeof(buf), stdin); - (void) get_ret; /* Mute compiler warning */ + (void)get_ret; /* Mute compiler warning */ } MHD_daemon_destroy (d); return 0; diff --git a/w32/common/mhd_config.h b/w32/common/mhd_config.h @@ -8,12 +8,12 @@ #ifndef __clang__ /* Define that MS VC does not support VLAs */ -#ifndef __STDC_NO_VLA__ -#define __STDC_NO_VLA__ 1 -#endif /* ! __STDC_NO_VLA__ */ +# ifndef __STDC_NO_VLA__ +# define __STDC_NO_VLA__ 1 +# endif /* ! __STDC_NO_VLA__ */ #else /* If clang is used then variable-length arrays are supported. */ -#define HAVE_C_VARARRAYS 1 +# define HAVE_C_VARARRAYS 1 #endif @@ -38,7 +38,7 @@ /* Compound literals are supported natively since VS2013, but only in C */ #if defined(__clang__) || \ - (defined(_MSC_VER) && _MSC_VER >= 1800 && ! defined(__cplusplus) && \ + (defined(_MSC_VER) && _MSC_VER >= 1800 && !defined(__cplusplus) && \ (defined(_MSC_EXTENSIONS) || \ ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112)))) /* Define to '1' if your compiler supports compound literals */ @@ -87,7 +87,7 @@ # define HAVE_RESTRICT 1 #endif -#if ! defined(HAVE_RESTRICT) +#if !defined(HAVE_RESTRICT) # define restrict /* empty */ #endif @@ -104,7 +104,7 @@ # endif #endif -#if ! defined(mhd_FALLTHROUGH) +#if !defined(mhd_FALLTHROUGH) /* Define to keyword marking intentional missing 'break' at the end of 'case:' This macro is actually just empty. */ # define mhd_FALLTHROUGH /* Intentional fallthrough */ @@ -121,9 +121,9 @@ /* The size of 'size_t', as computed by sizeof. */ #if defined(_M_X64) || defined(_M_AMD64) || defined(_M_ARM64) || defined(_WIN64) -#define SIZEOF_SIZE_T 8 +# define SIZEOF_SIZE_T 8 #else /* ! _WIN64 */ -#define SIZEOF_SIZE_T 4 +# define SIZEOF_SIZE_T 4 #endif /* ! _WIN64 */ /* The size of `tv_sec' member of `struct timeval', as computed by sizeof */ @@ -137,9 +137,9 @@ /* Define to supported 'noreturn' function declaration */ #if defined(_STDC_VERSION__) && (__STDC_VERSION__ + 0) >= 201112L -#define MHD_NORETURN_ _Noreturn +# define MHD_NORETURN_ _Noreturn #else /* before C11 */ -#define MHD_NORETURN_ __declspec(noreturn) +# define MHD_NORETURN_ __declspec(noreturn) #endif /* before C11 */ /* *** OS features *** */ @@ -166,7 +166,7 @@ #ifndef _WIN32_WINNT /* MHD supports Windows XP and later W32 systems*/ -#define _WIN32_WINNT 0x0600 +# define _WIN32_WINNT 0x0600 #endif /* _WIN32_WINNT */ /* winsock poll is available only on Vista and later */ @@ -192,12 +192,12 @@ #if _MSC_VER >= 1900 /* snprintf() supported natively since VS2015 */ /* Define to 1 if you have the `snprintf' function. */ -#define HAVE_SNPRINTF 1 +# define HAVE_SNPRINTF 1 #endif #if _MSC_VER + 0 >= 1800 /* VS 2013 and later */ || defined(__cplusplus) -# if ! defined(__cplusplus) && \ - (! defined(__STDC_VERSION__) || (__STDC_VERSION__ + 0) < 202311) +# if !defined(__cplusplus) && \ + (!defined(__STDC_VERSION__) || (__STDC_VERSION__ + 0) < 202311) /* Define to 1 if you have the <stdbool.h> header file and <stdbool.h> is required to use 'bool' type. */ # define HAVE_STDBOOL_H 1 @@ -208,27 +208,27 @@ #else /* before VS 2013 */ /* Define to type name which will be used as boolean type. */ -#define bool int +# define bool int /* Define to value interpreted by compiler as boolean "false", if "false" is not defined by system headers. */ -#define false 0 +# define false 0 /* Define to value interpreted by compiler as boolean "true", if "true" is not defined by system headers. */ -#define true (! 0) +# define true (! 0) #endif /* before VS 2013 */ /* Define if you have usable `getsockname' function. */ #define MHD_USE_GETSOCKNAME 1 #if _MSC_VER + 0 >= 1900 /* VS 2015 and later */ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ + 0) >= 201112L +# if defined(__STDC_VERSION__) && (__STDC_VERSION__ + 0) >= 201112L /* Define to 1 if your compiler supports 'alignof()' */ -#define HAVE_C_ALIGNOF 1 +# define HAVE_C_ALIGNOF 1 /* Define to 1 if you have the <stdalign.h> header file. */ -#define HAVE_STDALIGN_H 1 -#endif /* C11 */ +# define HAVE_STDALIGN_H 1 +# endif /* C11 */ #endif /* VS 2015 and later */ /* Define to '1' if you have the declaration of 'AF_UNIX' */ @@ -256,7 +256,7 @@ #if _MSC_VER >= 1800 /* Define to 1 if you have the <inttypes.h> header file. */ -#define HAVE_INTTYPES_H 1 +# define HAVE_INTTYPES_H 1 #endif /* Define to 1 if you have the <windows.h> header file. */