From ce7410c97ae5c41d47cea1b03048e1ba931cbcf3 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Mon, 13 Jan 2025 15:39:57 -0600 Subject: [PATCH 01/18] Clean up some linter warnings in SSLNetVConnection (#11937) * Remove unused #includes * Use C++20 instead of C typedefs * Convert some #define constants to constexpr --- src/api/InkAPI.cc | 2 +- src/iocore/net/P_SSLNetVConnection.h | 31 +++++++++++++--------------- src/iocore/net/SSLNetVConnection.cc | 12 +++++------ 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index 8a2ffdd4599..a1925e848c9 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -7916,7 +7916,7 @@ TSVConnTunnel(TSVConn sslp) SSLNetVConnection *ssl_vc = dynamic_cast(vc); TSReturnCode zret = TS_SUCCESS; if (nullptr != ssl_vc) { - ssl_vc->hookOpRequested = SSL_HOOK_OP_TUNNEL; + ssl_vc->hookOpRequested = SslVConnOp::SSL_HOOK_OP_TUNNEL; } else { zret = TS_ERROR; } diff --git a/src/iocore/net/P_SSLNetVConnection.h b/src/iocore/net/P_SSLNetVConnection.h index 2babaeb0d69..e9a959d948e 100644 --- a/src/iocore/net/P_SSLNetVConnection.h +++ b/src/iocore/net/P_SSLNetVConnection.h @@ -31,10 +31,8 @@ ****************************************************************************/ #pragma once -#include "tscore/ink_platform.h" #include "ts/apidefs.h" -#include "../eventsystem/P_EventSystem.h" #include "P_UnixNetVConnection.h" #include "P_UnixNet.h" #include "iocore/net/TLSALPNSupport.h" @@ -68,7 +66,7 @@ #define SSL_TLSEXT_ERR_NOACK 3 #endif -#define SSL_OP_HANDSHAKE 0x16 +constexpr char SSL_OP_HANDSHAKE = 0x16; // TS-2503: dynamic TLS record sizing // For smaller records, we should also reserve space for various TCP options @@ -76,19 +74,18 @@ // (another 20-60 bytes on average, depending on the negotiated ciphersuite [2]). // All in all: 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options) - TLS overhead (60-100) // For larger records, the size is determined by TLS protocol record size -#define SSL_DEF_TLS_RECORD_SIZE 1300 // 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options) - TLS overhead (60-100) -#define SSL_MAX_TLS_RECORD_SIZE 16383 // 2^14 - 1 -#define SSL_DEF_TLS_RECORD_BYTE_THRESHOLD 1000000 -#define SSL_DEF_TLS_RECORD_MSEC_THRESHOLD 1000 +constexpr uint32_t SSL_DEF_TLS_RECORD_SIZE = 1300; // 1500 - 40 (IP) - 20 (TCP) - 40 (TCP options) - TLS overhead (60-100) +constexpr uint32_t SSL_MAX_TLS_RECORD_SIZE = 16383; // 2^14 - 1 +constexpr int64_t SSL_DEF_TLS_RECORD_BYTE_THRESHOLD = 1000000; +constexpr int SSL_DEF_TLS_RECORD_MSEC_THRESHOLD = 1000; struct SSLCertLookup; -typedef enum { - SSL_HOOK_OP_DEFAULT, ///< Null / initialization value. Do normal processing. - SSL_HOOK_OP_TUNNEL, ///< Switch to blind tunnel - SSL_HOOK_OP_TERMINATE, ///< Termination connection / transaction. - SSL_HOOK_OP_LAST = SSL_HOOK_OP_TERMINATE ///< End marker value. -} SslVConnOp; +enum class SslVConnOp { + SSL_HOOK_OP_DEFAULT, ///< Null / initialization value. Do normal processing. + SSL_HOOK_OP_TUNNEL, ///< Switch to blind tunnel + SSL_HOOK_OP_TERMINATE ///< Termination connection / transaction. +}; enum class SSLHandshakeStatus { SSL_HANDSHAKE_ONGOING, SSL_HANDSHAKE_DONE, SSL_HANDSHAKE_ERROR }; @@ -109,7 +106,7 @@ class SSLNetVConnection : public UnixNetVConnection, public TLSEventSupport, public TLSBasicSupport { - typedef UnixNetVConnection super; ///< Parent type. + using super = UnixNetVConnection; ///< Parent type. public: int sslStartHandShake(int event, int &err) override; @@ -237,7 +234,7 @@ class SSLNetVConnection : public UnixNetVConnection, std::shared_ptr client_sess = nullptr; /// Set by asynchronous hooks to request a specific operation. - SslVConnOp hookOpRequested = SSL_HOOK_OP_DEFAULT; + SslVConnOp hookOpRequested = SslVConnOp::SSL_HOOK_OP_DEFAULT; // noncopyable SSLNetVConnection(const SSLNetVConnection &) = delete; @@ -326,7 +323,7 @@ class SSLNetVConnection : public UnixNetVConnection, bool _is_tunneling_requested() const override { - return SSL_HOOK_OP_TUNNEL == hookOpRequested; + return SslVConnOp::SSL_HOOK_OP_TUNNEL == hookOpRequested; } void _switch_to_tunneling_mode() override @@ -386,6 +383,6 @@ class SSLNetVConnection : public UnixNetVConnection, void _out_context_tunnel() override; }; -typedef int (SSLNetVConnection::*SSLNetVConnHandler)(int, void *); +using SSLNetVConnHandler = int (SSLNetVConnection::*)(int, void *); extern ClassAllocator sslNetVCAllocator; diff --git a/src/iocore/net/SSLNetVConnection.cc b/src/iocore/net/SSLNetVConnection.cc index 12055c6ca74..efbd16b6a1d 100644 --- a/src/iocore/net/SSLNetVConnection.cc +++ b/src/iocore/net/SSLNetVConnection.cc @@ -23,12 +23,10 @@ #include "iocore/net/NetVConnection.h" #include "tscore/ink_config.h" -#include "tscore/EventNotify.h" #include "tscore/Layout.h" #include "tscore/InkErrno.h" #include "tscore/TSSystemState.h" -#include "api/InkAPIInternal.h" // Added to include the ssl_hook definitions #include "iocore/net/ProxyProtocol.h" #include "iocore/net/SSLSNIConfig.h" @@ -918,7 +916,7 @@ SSLNetVConnection::clear() sslTotalBytesSent = 0; sslClientRenegotiationAbort = false; - hookOpRequested = SSL_HOOK_OP_DEFAULT; + hookOpRequested = SslVConnOp::SSL_HOOK_OP_DEFAULT; free_handshake_buffers(); super::clear(); @@ -1034,7 +1032,7 @@ SSLNetVConnection::sslStartHandShake(int event, int &err) this->ssl = nullptr; return EVENT_DONE; } else { - hookOpRequested = SSL_HOOK_OP_TUNNEL; + hookOpRequested = SslVConnOp::SSL_HOOK_OP_TUNNEL; } } @@ -1194,7 +1192,7 @@ SSLNetVConnection::sslServerHandShakeEvent(int &err) // without data replay. // Note we can't arrive here if a hook is active. - if (SSL_HOOK_OP_TUNNEL == hookOpRequested) { + if (SslVConnOp::SSL_HOOK_OP_TUNNEL == hookOpRequested) { this->attributes = HttpProxyPort::TRANSPORT_BLIND_TUNNEL; SSL_free(this->ssl); this->ssl = nullptr; @@ -1203,7 +1201,7 @@ SSLNetVConnection::sslServerHandShakeEvent(int &err) // we get out of this callback, and then will shuffle // over the buffered handshake packets to the O.S. return EVENT_DONE; - } else if (SSL_HOOK_OP_TERMINATE == hookOpRequested) { + } else if (SslVConnOp::SSL_HOOK_OP_TERMINATE == hookOpRequested) { sslHandshakeStatus = SSLHandshakeStatus::SSL_HANDSHAKE_DONE; return EVENT_DONE; } @@ -1395,7 +1393,7 @@ SSLNetVConnection::sslServerHandShakeEvent(int &err) case SSL_ERROR_PENDING_CERTIFICATE: #endif #if defined(SSL_ERROR_WANT_SNI_RESOLVE) || defined(SSL_ERROR_WANT_X509_LOOKUP) || defined(SSL_ERROR_PENDING_CERTIFICATE) - if (this->attributes == HttpProxyPort::TRANSPORT_BLIND_TUNNEL || SSL_HOOK_OP_TUNNEL == hookOpRequested) { + if (this->attributes == HttpProxyPort::TRANSPORT_BLIND_TUNNEL || SslVConnOp::SSL_HOOK_OP_TUNNEL == hookOpRequested) { this->attributes = HttpProxyPort::TRANSPORT_BLIND_TUNNEL; sslHandshakeStatus = SSLHandshakeStatus::SSL_HANDSHAKE_ONGOING; return EVENT_CONT; From 62fef5a53d73cb661b4aa152cd86becb8d0daad6 Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Tue, 14 Jan 2025 08:11:28 +0900 Subject: [PATCH 02/18] [traffic_crashlog] Log full version info (#11949) --- src/traffic_crashlog/traffic_crashlog.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traffic_crashlog/traffic_crashlog.cc b/src/traffic_crashlog/traffic_crashlog.cc index 42b411ef042..fd037db7611 100644 --- a/src/traffic_crashlog/traffic_crashlog.cc +++ b/src/traffic_crashlog/traffic_crashlog.cc @@ -232,7 +232,7 @@ main(int /* argc ATS_UNUSED */, const char **argv) crashlog_write_procname(fp, target); crashlog_write_exename(fp, target); - fprintf(fp, LABELFMT "Traffic Server %s\n", "Version:", PACKAGE_VERSION); + fprintf(fp, LABELFMT "%s\n", "Version:", version.full_version()); crashlog_write_uname(fp, target); crashlog_write_datime(fp, target); From 9dce7846c3e7e79763083051ff9754b9b35ea08e Mon Sep 17 00:00:00 2001 From: Damian Meden Date: Tue, 14 Jan 2025 10:45:04 +0100 Subject: [PATCH 03/18] Coverity: Fix for CID-1587277 (#11950) JA4, zero initialization for TLS version member variable. --- plugins/experimental/ja4_fingerprint/ja4.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/experimental/ja4_fingerprint/ja4.h b/plugins/experimental/ja4_fingerprint/ja4.h index 743b8672502..31b151dc0c0 100644 --- a/plugins/experimental/ja4_fingerprint/ja4.h +++ b/plugins/experimental/ja4_fingerprint/ja4.h @@ -54,7 +54,7 @@ class TLSClientHelloSummary using difference_type = std::iterator_traits::iterator>::difference_type; Protocol protocol; - std::uint16_t TLS_version; + std::uint16_t TLS_version{0}; // 0 is not the default, this is only to not have it un-initialized. std::string ALPN; std::vector const &get_ciphers() const; From 8cb3f78177d3111df1f32104c40b26249b72e650 Mon Sep 17 00:00:00 2001 From: Brian Neradt Date: Tue, 14 Jan 2025 10:14:15 -0600 Subject: [PATCH 04/18] ci-ubuntu preset: use clang (#11955) Update the ci-ubuntu preset to explicitly use clang. Currently CI configures clang via setting CC and CXX environment variables. This will configure clang across other environments more consistently. --- CMakePresets.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakePresets.json b/CMakePresets.json index 786a34e4aa9..218a4654246 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -226,7 +226,11 @@ "name": "ci-ubuntu", "displayName": "CI Ubuntu Hardened Build", "description": "CI Pipeline config for Ubuntu with hardening flags", - "inherits": ["ci", "hardened"] + "inherits": ["ci", "hardened"], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + } }, { "name": "ci-clang-analyzer", From 302a31fd8d2580e3dcfaeab8838681e8e8995b59 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Tue, 14 Jan 2025 14:24:56 -0600 Subject: [PATCH 05/18] Add unit tests for remap rules. Fix release-assert crasher (#11951) * Add unit tests for remap rules. Fix release-assert when adding default src ip rule * move RegressionSM from proxy to cache * Fix link for linux * fix memory leaks * Clear rules_list in destructor * Move rules cleanup to destructor from reset --------- Co-authored-by: Chris McFarlen --- include/proxy/http/remap/RemapConfig.h | 1 + include/proxy/http/remap/UrlRewrite.h | 4 +- src/iocore/cache/CMakeLists.txt | 3 +- src/iocore/cache/CacheTest.cc | 2 +- src/iocore/cache/P_CacheTest.h | 2 +- src/{proxy => iocore/cache}/RegressionSM.cc | 4 +- .../proxy => src/iocore/cache}/RegressionSM.h | 0 src/proxy/CMakeLists.txt | 4 - src/proxy/http/remap/RemapConfig.cc | 42 ++--- .../http/remap/unit-tests/CMakeLists.txt | 18 ++ .../http/remap/unit-tests/test_RemapRules.cc | 166 ++++++++++++++++++ 11 files changed, 213 insertions(+), 33 deletions(-) rename src/{proxy => iocore/cache}/RegressionSM.cc (98%) rename {include/proxy => src/iocore/cache}/RegressionSM.h (100%) create mode 100644 src/proxy/http/remap/unit-tests/test_RemapRules.cc diff --git a/include/proxy/http/remap/RemapConfig.h b/include/proxy/http/remap/RemapConfig.h index c8809a7fd23..b303ba2dd09 100644 --- a/include/proxy/http/remap/RemapConfig.h +++ b/include/proxy/http/remap/RemapConfig.h @@ -76,6 +76,7 @@ struct BUILD_TABLE_INFO { }; const char *remap_parse_directive(BUILD_TABLE_INFO *bti, char *errbuf, size_t errbufsize); +bool remap_parse_config_bti(const char *path, BUILD_TABLE_INFO *bti); const char *remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, int argc, char *errStrBuf, size_t errStrBufSize, ACLBehaviorPolicy behavior_policy); diff --git a/include/proxy/http/remap/UrlRewrite.h b/include/proxy/http/remap/UrlRewrite.h index b58dc9092d2..ca820a108a6 100644 --- a/include/proxy/http/remap/UrlRewrite.h +++ b/include/proxy/http/remap/UrlRewrite.h @@ -25,7 +25,6 @@ #pragma once #include "iocore/eventsystem/Freer.h" -#include "tscore/ink_config.h" #include "proxy/http/remap/UrlMapping.h" #include "proxy/http/remap/UrlMappingPathIndex.h" #include "proxy/http/HttpTransact.h" @@ -40,9 +39,8 @@ #define URL_REMAP_FILTER_REFERER 0x00000001 /* enable "referer" header validation */ #define URL_REMAP_FILTER_REDIRECT_FMT 0x00010000 /* enable redirect URL formatting */ -struct BUILD_TABLE_INFO; - /** + * used for redirection, mapping, and reverse mapping **/ enum mapping_type { diff --git a/src/iocore/cache/CMakeLists.txt b/src/iocore/cache/CMakeLists.txt index b52a9993b48..0f5111bb5a4 100644 --- a/src/iocore/cache/CMakeLists.txt +++ b/src/iocore/cache/CMakeLists.txt @@ -40,8 +40,7 @@ add_library( add_library(ts::inkcache ALIAS inkcache) if(BUILD_REGRESSION_TESTING) - target_sources(inkcache PRIVATE CacheTest.cc) - target_link_libraries(inkcache PRIVATE ts::proxy) + target_sources(inkcache PRIVATE CacheTest.cc RegressionSM.cc) endif() target_include_directories(inkcache PRIVATE ${CMAKE_SOURCE_DIR}/lib) diff --git a/src/iocore/cache/CacheTest.cc b/src/iocore/cache/CacheTest.cc index 3572b2f0594..d2a15d6104e 100644 --- a/src/iocore/cache/CacheTest.cc +++ b/src/iocore/cache/CacheTest.cc @@ -24,7 +24,7 @@ #include "P_Cache.h" #include "P_CacheTest.h" -#include "proxy/RegressionSM.h" +#include "RegressionSM.h" #include "tscore/Random.h" #include #include diff --git a/src/iocore/cache/P_CacheTest.h b/src/iocore/cache/P_CacheTest.h index cb4988f0699..dd12f8b2b0a 100644 --- a/src/iocore/cache/P_CacheTest.h +++ b/src/iocore/cache/P_CacheTest.h @@ -25,7 +25,7 @@ #include "P_Cache.h" #include "P_CacheDoc.h" -#include "proxy/RegressionSM.h" +#include "RegressionSM.h" #define MAX_HOSTS_POSSIBLE 256 #define PINNED_DOC_TABLE_SIZE 16 diff --git a/src/proxy/RegressionSM.cc b/src/iocore/cache/RegressionSM.cc similarity index 98% rename from src/proxy/RegressionSM.cc rename to src/iocore/cache/RegressionSM.cc index 033c151a5c8..4955f334890 100644 --- a/src/proxy/RegressionSM.cc +++ b/src/iocore/cache/RegressionSM.cc @@ -21,8 +21,8 @@ limitations under the License. */ -#include "../iocore/eventsystem/P_EventSystem.h" -#include "proxy/RegressionSM.h" +#include "../eventsystem/P_EventSystem.h" +#include "RegressionSM.h" #define REGRESSION_SM_RETRY (100 * HRTIME_MSECOND) diff --git a/include/proxy/RegressionSM.h b/src/iocore/cache/RegressionSM.h similarity index 100% rename from include/proxy/RegressionSM.h rename to src/iocore/cache/RegressionSM.h diff --git a/src/proxy/CMakeLists.txt b/src/proxy/CMakeLists.txt index 865d512ac42..7e82edba8f0 100644 --- a/src/proxy/CMakeLists.txt +++ b/src/proxy/CMakeLists.txt @@ -39,10 +39,6 @@ add_library( ) add_library(ts::proxy ALIAS proxy) -if(BUILD_REGRESSION_TESTING) - target_sources(proxy PRIVATE RegressionSM.cc) -endif() - target_link_libraries( proxy PUBLIC ts::inkcache ts::inkevent ts::tsutil ts::tscore diff --git a/src/proxy/http/remap/RemapConfig.cc b/src/proxy/http/remap/RemapConfig.cc index a2b3e7e6ea2..c702d98a3fe 100644 --- a/src/proxy/http/remap/RemapConfig.cc +++ b/src/proxy/http/remap/RemapConfig.cc @@ -46,9 +46,6 @@ namespace DbgCtl dbg_ctl_url_rewrite{"url_rewrite"}; DbgCtl dbg_ctl_remap_plugin{"remap_plugin"}; DbgCtl dbg_ctl_url_rewrite_regex{"url_rewrite_regex"}; - -bool remap_parse_config_bti(const char *path, BUILD_TABLE_INFO *bti); - } // end anonymous namespace /** @@ -100,6 +97,14 @@ BUILD_TABLE_INFO::BUILD_TABLE_INFO() BUILD_TABLE_INFO::~BUILD_TABLE_INFO() { this->reset(); + + // clean up any leftover named filter rules + auto *rp = rules_list; + while (rp != nullptr) { + auto *tmp = rp->next; + delete rp; + rp = tmp; + } } void @@ -146,6 +151,15 @@ process_filter_opt(url_mapping *mp, const BUILD_TABLE_INFO *bti, char *errStrBuf nullptr) { break; } + if (auto rule = *rpp; rule) { + // If no IP addresses are listed, treat that like `@src_ip=all`. + if (rule->src_ip_valid == 0 && rule->src_ip_cnt == 0) { + src_ip_info_t *ipi = &rule->src_ip_array[rule->src_ip_cnt]; + ipi->match_all_addresses = true; + rule->src_ip_cnt++; + rule->src_ip_valid = 1; + } + } } } @@ -469,8 +483,7 @@ remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, i Dbg(dbg_ctl_url_rewrite, "[validate_filter_args] new acl_filter_rule class was created during remap rule processing"); } - bool action_flag = false; - bool ip_is_listed = false; + bool action_flag = false; for (i = 0; i < argc; i++) { unsigned long ul; bool hasarg; @@ -553,7 +566,6 @@ remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, i if (ipi) { rule->src_ip_cnt++; rule->src_ip_valid = 1; - ip_is_listed = true; } } @@ -583,7 +595,6 @@ remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, i if (ipi) { rule->src_ip_category_cnt++; rule->src_ip_category_valid = 1; - ip_is_listed = true; } } @@ -626,7 +637,6 @@ remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, i if (ipi) { rule->in_ip_cnt++; rule->in_ip_valid = 1; - ip_is_listed = true; } } @@ -635,6 +645,10 @@ remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, i std::string_view err = "Only one @action= is allowed per remap ACL"; Dbg(dbg_ctl_url_rewrite, "%s", err.data()); snprintf(errStrBuf, errStrBufSize, "%s", err.data()); + if (new_rule_flg) { + delete rule; + *rule_pp = nullptr; + } return errStrBuf; } action_flag = true; @@ -685,15 +699,6 @@ remap_validate_filter_args(acl_filter_rule **rule_pp, const char *const *argv, i } } - if (!ip_is_listed) { - // If no IP addresses are listed, treat that like `@src_ip=all`. - ink_release_assert(rule->src_ip_valid == 0 && rule->src_ip_cnt == 0); - src_ip_info_t *ipi = &rule->src_ip_array[rule->src_ip_cnt]; - ipi->match_all_addresses = true; - rule->src_ip_cnt++; - rule->src_ip_valid = 1; - } - if (dbg_ctl_url_rewrite.on()) { rule->print(); } @@ -1023,8 +1028,6 @@ process_regex_mapping_config(const char *from_host_lower, url_mapping *new_mappi return false; } -namespace -{ bool remap_parse_config_bti(const char *path, BUILD_TABLE_INFO *bti) { @@ -1470,7 +1473,6 @@ remap_parse_config_bti(const char *path, BUILD_TABLE_INFO *bti) IpAllow::enableAcceptCheck(bti->accept_check_p); return true; } -} // end anonymous namespace bool remap_parse_config(const char *path, UrlRewrite *rewrite) diff --git a/src/proxy/http/remap/unit-tests/CMakeLists.txt b/src/proxy/http/remap/unit-tests/CMakeLists.txt index 04ed65782ab..ed651e29ec7 100644 --- a/src/proxy/http/remap/unit-tests/CMakeLists.txt +++ b/src/proxy/http/remap/unit-tests/CMakeLists.txt @@ -269,3 +269,21 @@ target_link_libraries( ) add_test(NAME test_NextHopConsistentHash COMMAND $) + +### test_RemapRules ######################################################################## +add_executable(test_RemapRules "${PROJECT_SOURCE_DIR}/src/iocore/cache/unit_tests/stub.cc" test_RemapRules.cc) + +target_link_libraries( + test_RemapRules + PRIVATE catch2::catch2 + ts::http + ts::hdrs # transitive + logging # transitive + ts::http_remap # transitive + ts::proxy + inkdns # transitive + ts::inknet + ts::jsonrpc_protocol +) + +add_test(NAME test_RemapRules COMMAND $) diff --git a/src/proxy/http/remap/unit-tests/test_RemapRules.cc b/src/proxy/http/remap/unit-tests/test_RemapRules.cc new file mode 100644 index 00000000000..0cec0133d3b --- /dev/null +++ b/src/proxy/http/remap/unit-tests/test_RemapRules.cc @@ -0,0 +1,166 @@ +/** @file + + Unit tests for a class that deals with remap rules + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + @section details Details + + Implements code necessary for Reverse Proxy which mostly consists of + general purpose hostname substitution in URLs. + + */ + +#include "proxy/hdrs/HdrHeap.h" +#include "proxy/http/remap/RemapConfig.h" +#include "proxy/http/remap/UrlMapping.h" +#include "proxy/http/remap/UrlRewrite.h" +#include "records/RecordsConfig.h" +#include "swoc/swoc_file.h" +#include "ts/apidefs.h" +#include "tscore/BaseLogFile.h" +#include + +#define CATCH_CONFIG_MAIN /* include main function */ +#include /* catch unit-test framework */ + +struct TestListener : Catch::TestEventListenerBase { + using TestEventListenerBase::TestEventListenerBase; + + void + testRunStarting(Catch::TestRunInfo const & /* testRunInfo ATS_UNUSED */) override + { + Thread *main_thread = new EThread(); + main_thread->set_specific(); + + DiagsPtr::set(new Diags("test_RemapRules", "*", "", new BaseLogFile("stderr"))); + // diags()->activate_taglist(".*", DiagsTagType_Debug); + // diags()->config.enabled(DiagsTagType_Debug, 1); + diags()->show_location = SHOW_LOCATION_DEBUG; + + url_init(); + mime_init(); + http_init(); + Layout::create(); + RecProcessInit(diags()); + LibRecordsConfigInit(); + } +}; + +CATCH_REGISTER_LISTENER(TestListener); + +swoc::file::path +write_test_remap(const std::string &config, const std::string &tag) +{ + auto tmpdir = swoc::file::temp_directory_path(); + auto path = tmpdir / swoc::file::path(tag + ".config"); + + std::ofstream f(path.c_str(), std::ios::trunc); + f.write(config.data(), config.size()); + f.close(); + + return path; +} + +SCENARIO("Parsing ACL named filters", "[proxy][remap]") +{ + GIVEN("Named filter definitions with multiple actions") + { + BUILD_TABLE_INFO bti{}; + UrlRewrite rewrite{}; + + bti.rewrite = &rewrite; + + WHEN("filter rule definition has multiple @action") + { + std::string config = R"RMCFG( + .definefilter deny_methods @action=deny @method=CONNECT @action=allow @method=PUT @method=DELETE + )RMCFG"; + auto cpath = write_test_remap(config, "test2"); + THEN("The remap parse fails with an error") + { + REQUIRE(remap_parse_config_bti(cpath.c_str(), &bti) == false); + } + } + + WHEN("filter rule redefine has multiple @action") + { + std::string config = R"RMCFG( + .definefilter deny_methods @action=deny @method=CONNECT + .definefilter deny_methods @action=allow @method=PUT @method=DELETE + )RMCFG"; + auto cpath = write_test_remap(config, "test2"); + THEN("The rule uses the last action specified") + { + REQUIRE(remap_parse_config_bti(cpath.c_str(), &bti) == true); + REQUIRE(bti.rules_list != nullptr); + REQUIRE(bti.rules_list->next == nullptr); + REQUIRE(bti.rules_list->allow_flag == true); + } + } + } +} + +struct EasyURL { + URL url; + HdrHeap *heap; + + EasyURL(std::string_view s) + { + heap = new_HdrHeap(); + url.create(heap); + url.parse(s); + } + ~EasyURL() { heap->destroy(); } +}; + +SCENARIO("Parsing UrlRewrite", "[proxy][remap]") +{ + GIVEN("A named remap rule without ips") + { + std::unique_ptr urlrw = std::make_unique(); + + std::string config = R"RMCFG( +.definefilter deny_methods @action=deny @method=CONNECT @method=PUT @method=DELETE +.activatefilter deny_methods +map https://h1.example.com \ + https://h2.example.com +.deactivatefilter deny_methods + )RMCFG"; + + auto cpath = write_test_remap(config, "test1"); + printf("wrote config to path: %s\n", cpath.c_str()); + int rc = urlrw->BuildTable(cpath.c_str()); + EasyURL url("https://h1.example.com"); + const char *host = "h1.example.com"; + + THEN("the remap rules has an ip=all") + { + REQUIRE(rc == TS_SUCCESS); + REQUIRE(urlrw->rule_count() == 1); + UrlMappingContainer urlmap; + + REQUIRE(urlrw->forwardMappingLookup(&url.url, 443, host, strlen(host), urlmap)); + REQUIRE(urlmap.getMapping()->filter); + REQUIRE(urlmap.getMapping()->filter->src_ip_cnt == 1); + REQUIRE(urlmap.getMapping()->filter->src_ip_valid); + REQUIRE(urlmap.getMapping()->filter->src_ip_array[0].match_all_addresses); + } + } +} From e1f49f64eb2a52d27b95c71b93a4758867a5bf66 Mon Sep 17 00:00:00 2001 From: JosiahWI <41302989+JosiahWI@users.noreply.github.com> Date: Tue, 14 Jan 2025 17:09:38 -0600 Subject: [PATCH 06/18] Zero-initialize struct variables in JA4 plugin (#11953) This should appease the compiler's warning checker and ensure that the structs are always initialized. Fixes #11952. --- plugins/experimental/ja4_fingerprint/plugin.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/experimental/ja4_fingerprint/plugin.cc b/plugins/experimental/ja4_fingerprint/plugin.cc index 7c31dd45ab2..711f53d7812 100644 --- a/plugins/experimental/ja4_fingerprint/plugin.cc +++ b/plugins/experimental/ja4_fingerprint/plugin.cc @@ -95,7 +95,7 @@ get_log_handle() static constexpr TSPluginRegistrationInfo get_registration_info() { - TSPluginRegistrationInfo info; + TSPluginRegistrationInfo info{}; info.plugin_name = PLUGIN_NAME; info.vendor_name = PLUGIN_VENDOR; info.support_email = PLUGIN_SUPPORT_EMAIL; @@ -179,7 +179,7 @@ handle_client_hello(TSCont /* cont ATS_UNUSED */, TSEvent event, void *edata) std::string get_fingerprint(SSL *ssl) { - JA4::TLSClientHelloSummary summary; + JA4::TLSClientHelloSummary summary{}; summary.protocol = JA4::Protocol::TLS; summary.TLS_version = get_version(ssl); summary.ALPN = get_first_ALPN(ssl); From 5ded0e4a31b732e1a6dc8062c59d198ae7613a2c Mon Sep 17 00:00:00 2001 From: Damian Meden Date: Wed, 15 Jan 2025 01:07:56 +0100 Subject: [PATCH 07/18] Coverity. Make global variables a singleton. (#11908) This is an attempt to fix some ordering creation issues for some global variables. The whole idea is to get swoc::bwf::Global_Names initialized first. --- lib/swoc/include/swoc/bwf_base.h | 10 +++++----- lib/swoc/src/bw_format.cc | 6 +++++- lib/swoc/unit_tests/ex_bw_format.cc | 8 ++++---- src/proxy/http/HttpProxyServerMain.cc | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/swoc/include/swoc/bwf_base.h b/lib/swoc/include/swoc/bwf_base.h index d5c426d2b1b..e76ccc78a30 100644 --- a/lib/swoc/include/swoc/bwf_base.h +++ b/lib/swoc/include/swoc/bwf_base.h @@ -467,7 +467,7 @@ template class ContextNames : public NameMap BufferWriter & BufferWriter::print(const TextView &fmt, Args &&...args) { - return this->print_nfv(bwf::Global_Names.bind(), bwf::Format::bind(fmt), bwf::ArgTuple{std::forward_as_tuple(args...)}); + return this->print_nfv(bwf::Global_Names().bind(), bwf::Format::bind(fmt), bwf::ArgTuple{std::forward_as_tuple(args...)}); } template BufferWriter & BufferWriter::print(bwf::Format const &fmt, Args &&...args) { - return this->print_nfv(bwf::Global_Names.bind(), fmt.bind(), bwf::ArgTuple{std::forward_as_tuple(args...)}); + return this->print_nfv(bwf::Global_Names().bind(), fmt.bind(), bwf::ArgTuple{std::forward_as_tuple(args...)}); } template BufferWriter & BufferWriter::print_v(TextView const &fmt, std::tuple const &args) { - return this->print_nfv(bwf::Global_Names.bind(), bwf::Format::bind(fmt), bwf::ArgTuple{args}); + return this->print_nfv(bwf::Global_Names().bind(), bwf::Format::bind(fmt), bwf::ArgTuple{args}); } template BufferWriter & BufferWriter::print_v(const bwf::Format &fmt, const std::tuple &args) { - return this->print_nfv(bwf::Global_Names.bind(), fmt.bind(), bwf::ArgTuple{args}); + return this->print_nfv(bwf::Global_Names().bind(), fmt.bind(), bwf::ArgTuple{args}); } template diff --git a/lib/swoc/src/bw_format.cc b/lib/swoc/src/bw_format.cc index 60ceacce08d..a5ccbb71501 100644 --- a/lib/swoc/src/bw_format.cc +++ b/lib/swoc/src/bw_format.cc @@ -24,12 +24,16 @@ using namespace std::literals; using namespace swoc::literals; -swoc::bwf::ExternalNames swoc::bwf::Global_Names; + using swoc::svto_radix; namespace swoc { inline namespace SWOC_VERSION_NS { namespace bwf { +ExternalNames& Global_Names() { + static swoc::bwf::ExternalNames Global_Names; + return Global_Names; +} const Spec Spec::DEFAULT; diff --git a/lib/swoc/unit_tests/ex_bw_format.cc b/lib/swoc/unit_tests/ex_bw_format.cc index fa33238055f..d26b70cac28 100644 --- a/lib/swoc/unit_tests/ex_bw_format.cc +++ b/lib/swoc/unit_tests/ex_bw_format.cc @@ -127,10 +127,10 @@ struct Context { void EX_BWF_Format_Init() { - swoc::bwf::Global_Names.assign("timestamp", &BWF_Timestamp); - swoc::bwf::Global_Names.assign("now", &BWF_Now); - swoc::bwf::Global_Names.assign("version", &BWF_Version); - swoc::bwf::Global_Names.assign("dave", &BWF_EvilDave); + swoc::bwf::Global_Names().assign("timestamp", &BWF_Timestamp); + swoc::bwf::Global_Names().assign("now", &BWF_Now); + swoc::bwf::Global_Names().assign("version", &BWF_Version); + swoc::bwf::Global_Names().assign("dave", &BWF_EvilDave); } // Work with external / global names. diff --git a/src/proxy/http/HttpProxyServerMain.cc b/src/proxy/http/HttpProxyServerMain.cc index 373dabb137a..83753e2f9c4 100644 --- a/src/proxy/http/HttpProxyServerMain.cc +++ b/src/proxy/http/HttpProxyServerMain.cc @@ -66,10 +66,10 @@ bool et_udp_threads_ready = false; // File / process scope initializations static bool HTTP_SERVER_INITIALIZED __attribute__((unused)) = []() -> bool { - swoc::bwf::Global_Names.assign("ts-thread", [](swoc::BufferWriter &w, swoc::bwf::Spec const &spec) -> swoc::BufferWriter & { + swoc::bwf::Global_Names().assign("ts-thread", [](swoc::BufferWriter &w, swoc::bwf::Spec const &spec) -> swoc::BufferWriter & { return bwformat(w, spec, this_thread()); }); - swoc::bwf::Global_Names.assign("ts-ethread", [](swoc::BufferWriter &w, swoc::bwf::Spec const &spec) -> swoc::BufferWriter & { + swoc::bwf::Global_Names().assign("ts-ethread", [](swoc::BufferWriter &w, swoc::bwf::Spec const &spec) -> swoc::BufferWriter & { return bwformat(w, spec, this_ethread()); }); return true; From 9f440c2bd48cedb0bf58bba15735eb223c452e05 Mon Sep 17 00:00:00 2001 From: Masakazu Kitajo Date: Tue, 14 Jan 2025 17:17:30 -0700 Subject: [PATCH 08/18] Fix a test case for malformed chunk header (#11956) --- .../replays/malformed_chunked_header.replay.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/gold_tests/chunked_encoding/replays/malformed_chunked_header.replay.yaml b/tests/gold_tests/chunked_encoding/replays/malformed_chunked_header.replay.yaml index b428141aca9..1118036b3c8 100644 --- a/tests/gold_tests/chunked_encoding/replays/malformed_chunked_header.replay.yaml +++ b/tests/gold_tests/chunked_encoding/replays/malformed_chunked_header.replay.yaml @@ -192,4 +192,4 @@ sessions: transfer: plain encoding: uri # BWS cannot have CR - data: 3%0D%0D%0Aabc%0D%0A0%0D%0A%0D%0A + data: 3%0D%0D%0Adef%0D%0A0%0D%0A%0D%0A From 33c279363ababcb3d9b9188e2938b58a04abae75 Mon Sep 17 00:00:00 2001 From: Damian Meden Date: Wed, 15 Jan 2025 10:01:16 +0100 Subject: [PATCH 09/18] Coverity: Fix for CID 1587263. (#11954) Add missing delete. --- src/iocore/hostdb/test_RefCountCache.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/iocore/hostdb/test_RefCountCache.cc b/src/iocore/hostdb/test_RefCountCache.cc index 50d4c6b96f3..334c24b258f 100644 --- a/src/iocore/hostdb/test_RefCountCache.cc +++ b/src/iocore/hostdb/test_RefCountCache.cc @@ -194,6 +194,8 @@ testclear() ret |= item->refcount() != 0; ret |= item->idx != -1; + delete cache; + return ret; } From 0c1b1423eba624ad04b01d9bdf1ed43bdf47097f Mon Sep 17 00:00:00 2001 From: Brian Neradt Date: Wed, 15 Jan 2025 14:19:54 -0600 Subject: [PATCH 10/18] libswoc version update: 1.5.13 (#11958) We cut a release of trafficserver-libswoc that has our latest ATS changes to lib/swoc. That release is 1.5.13. This updates our local swoc_version.h to reflect this new release. --- lib/swoc/include/swoc/swoc_version.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/swoc/include/swoc/swoc_version.h b/lib/swoc/include/swoc/swoc_version.h index e346be1ebe7..f9ffbedd8be 100644 --- a/lib/swoc/include/swoc/swoc_version.h +++ b/lib/swoc/include/swoc/swoc_version.h @@ -23,11 +23,11 @@ #pragma once #if !defined(SWOC_VERSION_NS) -#define SWOC_VERSION_NS _1_5_12 +#define SWOC_VERSION_NS _1_5_13 #endif namespace swoc { inline namespace SWOC_VERSION_NS { static constexpr unsigned MAJOR_VERSION = 1; static constexpr unsigned MINOR_VERSION = 5; -static constexpr unsigned POINT_VERSION = 12; +static constexpr unsigned POINT_VERSION = 13; }} // namespace swoc::SWOC_VERSION_NS From 28c8105687c9b883c2eee8b3357af322fe52ff4e Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Fri, 17 Jan 2025 08:26:10 +0900 Subject: [PATCH 11/18] Add nullptr check in PluginVC read and write (#11961) --- src/proxy/PluginVC.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/proxy/PluginVC.cc b/src/proxy/PluginVC.cc index b9ca711a4e7..427b271eba2 100644 --- a/src/proxy/PluginVC.cc +++ b/src/proxy/PluginVC.cc @@ -483,7 +483,7 @@ PluginVC::process_write_side() need_write_process = false; // Check write_state - if (write_state.vio.op != VIO::WRITE || closed || write_state.shutdown) { + if (write_state.vio.cont == nullptr || write_state.vio.op != VIO::WRITE || closed || write_state.shutdown) { return; } @@ -493,9 +493,13 @@ PluginVC::process_write_side() return; } - IOBufferReader *reader = write_state.vio.get_reader(); - int64_t bytes_avail = reader->read_avail(); - int64_t act_on = std::min(bytes_avail, ntodo); + IOBufferReader *reader = write_state.vio.get_reader(); + if (reader == nullptr) { + return; + } + + int64_t bytes_avail = reader->read_avail(); + int64_t act_on = std::min(bytes_avail, ntodo); Dbg(dbg_ctl_pvc, "[%u] %s: process_write_side; act_on %" PRId64 "", core_obj->id, PVC_TYPE, act_on); @@ -601,7 +605,8 @@ PluginVC::process_read_side() need_read_process = false; // Check read_state - if (read_state.vio.op != VIO::READ || closed || read_state.shutdown || !read_state.vio.ntodo()) { + if (read_state.vio.cont == nullptr || read_state.vio.op != VIO::READ || closed || read_state.shutdown || + !read_state.vio.ntodo()) { return; } From 8ee4f67d0ea9e1630ea3a5503b13368d7dd0dc4e Mon Sep 17 00:00:00 2001 From: Evan Zelkowitz Date: Wed, 22 Jan 2025 08:51:59 -0700 Subject: [PATCH 12/18] Codeql updates (#11978) * Update codeql.yml * Update codeql.yml --- .github/workflows/codeql.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index acf9dc38d1a..efc00f8ff41 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -36,14 +36,14 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install dependencies run: | sudo apt update - sudo apt install libmagick++-dev libncurses-dev libpcre2-dev libbrotli-dev libluajit-5.1-dev luajit libjansson-dev libcjose-dev libmaxminddb-dev libgeoip-dev ninja-build + sudo apt install libmagick++-dev libncurses-dev libpcre2-dev libbrotli-dev libluajit-5.1-dev luajit libjansson-dev libcjose-dev libmaxminddb-dev libgeoip-dev ninja-build cmake libpcre3-dev # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -70,6 +70,6 @@ jobs: cmake -B build --preset ci cmake --build build -v - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 with: category: "/language:${{matrix.language}}" From 8eaddba2c797b47187e887b5c01f74a335656b43 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Wed, 22 Jan 2025 09:57:32 -0700 Subject: [PATCH 13/18] Make LLVM19 builds happy again (#11977) --- .../experimental/txn_box/plugin/include/txn_box/Context.h | 2 +- .../experimental/txn_box/plugin/include/txn_box/common.h | 6 +++--- plugins/experimental/txn_box/plugin/src/Machinery.cc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/experimental/txn_box/plugin/include/txn_box/Context.h b/plugins/experimental/txn_box/plugin/include/txn_box/Context.h index cf03cb766b3..48c851fff7f 100644 --- a/plugins/experimental/txn_box/plugin/include/txn_box/Context.h +++ b/plugins/experimental/txn_box/plugin/include/txn_box/Context.h @@ -793,7 +793,7 @@ Context::render_transient(F const &f) // create the writer and clean it up. Also, the outer is responsible for finalizing the // transient buffer used. if (!_transient_writer.has_value()) { - _transient_writer.template emplace(this->transient_buffer()); + _transient_writer.emplace(this->transient_buffer()); outer_p = true; } else { base = _transient_writer->extent(); diff --git a/plugins/experimental/txn_box/plugin/include/txn_box/common.h b/plugins/experimental/txn_box/plugin/include/txn_box/common.h index 166e2fba665..1bd279acb3d 100644 --- a/plugins/experimental/txn_box/plugin/include/txn_box/common.h +++ b/plugins/experimental/txn_box/plugin/include/txn_box/common.h @@ -185,13 +185,13 @@ constexpr std::array FeatureIndexToValue{ namespace detail { template -constexpr std::initializer_list> +constexpr std::initializer_list> indexed_init_list(GENERATOR &&g, std::index_sequence &&) { return {g(IDX)...}; } template -constexpr std::initializer_list> +constexpr std::initializer_list> indexed_init_list(GENERATOR &&g) { return indexed_init_list(std::forward(g), std::make_index_sequence()); @@ -204,7 +204,7 @@ indexed_array(GENERATOR &&g, std::index_sequence &&) return std::array, sizeof...(IDX)>{g(IDX)...}; } template -constexpr std::array, N> +constexpr std::array, N> indexed_array(GENERATOR &&g) { return indexed_array(std::forward(g), std::make_index_sequence()); diff --git a/plugins/experimental/txn_box/plugin/src/Machinery.cc b/plugins/experimental/txn_box/plugin/src/Machinery.cc index 758173c4998..2ff2f912936 100644 --- a/plugins/experimental/txn_box/plugin/src/Machinery.cc +++ b/plugins/experimental/txn_box/plugin/src/Machinery.cc @@ -1832,7 +1832,7 @@ class FieldDirective : public Directive auto operator()(T &&t) -> EnableForFeatureTypes { - this->assign(_ctx.template render_transient([&t](BufferWriter &w) { bwformat(w, bwf::Spec::DEFAULT, t); })); + this->assign(_ctx.render_transient([&t](BufferWriter &w) { bwformat(w, bwf::Spec::DEFAULT, t); })); this->clear_dups(); } }; From 5c0b0399d14d17885c295906136aa023f1fc4a0a Mon Sep 17 00:00:00 2001 From: Masakazu Kitajo Date: Wed, 22 Jan 2025 16:32:50 -0700 Subject: [PATCH 14/18] Disable h2 prior knowledge on tls (#11881) * Don't allow using HTTP/2 prior knowledge on TLS connections * Update debug log message * Use ALPN on autest tls_0rtt_server * Add a comment --- src/proxy/ProtocolProbeSessionAccept.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/proxy/ProtocolProbeSessionAccept.cc b/src/proxy/ProtocolProbeSessionAccept.cc index 66fe9f624f5..8b974d2f08b 100644 --- a/src/proxy/ProtocolProbeSessionAccept.cc +++ b/src/proxy/ProtocolProbeSessionAccept.cc @@ -136,7 +136,13 @@ struct ProtocolProbeTrampoline : public Continuation, public ProtocolProbeSessio } // end of Proxy Protocol processing if (proto_is_http2(reader)) { - key = PROTO_HTTP2; + if (netvc->get_service() == nullptr) { + key = PROTO_HTTP2; + } else { + // RFC 9113 Section 3.3: Prior knowledge is only permissible for HTTP/2 over plaintext (non-TLS) connections. + Dbg(dbg_ctl_http, "HTTP/2 prior knowledge was used on a TLS connection (protocol violation). Selecting HTTP/1 instead."); + key = PROTO_HTTP; + } } else { key = PROTO_HTTP; } From 5abce9669155c74aed2fb249a8e52e4541fc67a1 Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Thu, 23 Jan 2025 08:48:01 +0900 Subject: [PATCH 15/18] Add micro benchmark of EventSystem (#11940) --- tools/benchmark/CMakeLists.txt | 8 +- tools/benchmark/benchmark_EventSystem.cc | 120 +++++++++++++++++++++++ 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 tools/benchmark/benchmark_EventSystem.cc diff --git a/tools/benchmark/CMakeLists.txt b/tools/benchmark/CMakeLists.txt index bbed6fca7b3..c776f74d07d 100644 --- a/tools/benchmark/CMakeLists.txt +++ b/tools/benchmark/CMakeLists.txt @@ -15,10 +15,16 @@ # ####################### +add_executable(benchmark_EventSystem benchmark_Eventsystem.cc) +target_link_libraries(benchmark_EventSystem PRIVATE catch2::catch2 ts::inkevent libswoc::libswoc) +if(TS_USE_HWLOC) + target_link_libraries(benchmark_EventSystem PRIVATE hwloc::hwloc) +endif() + add_executable(benchmark_FreeList benchmark_FreeList.cc) target_link_libraries(benchmark_FreeList PRIVATE catch2::catch2 ts::tscore libswoc::libswoc) if(TS_USE_HWLOC) - target_link_libraries(benchmark_FreeList PRIVATE hwloc) + target_link_libraries(benchmark_FreeList PRIVATE hwloc::hwloc) endif() add_executable(benchmark_ProxyAllocator benchmark_ProxyAllocator.cc) diff --git a/tools/benchmark/benchmark_EventSystem.cc b/tools/benchmark/benchmark_EventSystem.cc new file mode 100644 index 00000000000..20c0eadc58f --- /dev/null +++ b/tools/benchmark/benchmark_EventSystem.cc @@ -0,0 +1,120 @@ +/** @file + + Micro Benchmark tool for Event System - requires Catch2 v2.9.0+ + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#define CATCH_CONFIG_ENABLE_BENCHMARKING +#define CATCH_CONFIG_RUNNER + +#include "catch.hpp" + +#include "iocore/eventsystem/Continuation.h" +#include "iocore/eventsystem/EventSystem.h" +#include "iocore/eventsystem/Lock.h" + +#include "iocore/utils/diags.i" + +#include "tscore/Layout.h" +#include "tscore/TSSystemState.h" + +namespace +{ +// Args +int nevents = 1; +int nthreads = 1; + +std::atomic counter = 0; + +struct Task : public Continuation { + Task() : Continuation(new_ProxyMutex()) { SET_HANDLER(&Task::event_handler); } + + int + event_handler(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) + { + ++counter; + + if (counter == nevents) { + TSSystemState::shut_down_event_system(); + } + + return 0; + } +}; +} // namespace + +TEST_CASE("event process benchmark", "") +{ + char name[64]; + snprintf(name, sizeof(name), "nevents = %d nthreads = %d", nevents, nthreads); + + BENCHMARK(name) + { + REQUIRE(!TSSystemState::is_initializing()); + + for (int i = 0; i < nevents; ++i) { + Task *t = new Task(); + eventProcessor.schedule_in(t, 0); + } + + while (!TSSystemState::is_event_system_shut_down()) { + sleep(1); + } + }; +} + +struct EventProcessorListener : Catch::TestEventListenerBase { + using TestEventListenerBase::TestEventListenerBase; + + void + testRunStarting(Catch::TestRunInfo const & /* testRunInfo ATS_UNUSED */) override + { + Layout::create(); + init_diags("", nullptr); + RecProcessInit(); + + ink_event_system_init(EVENT_SYSTEM_MODULE_PUBLIC_VERSION); + eventProcessor.start(nthreads, 1048576); // Hardcoded stacksize at 1MB + + EThread *main_thread = new EThread; + main_thread->set_specific(); + + TSSystemState::initialization_done(); + } +}; + +CATCH_REGISTER_LISTENER(EventProcessorListener); + +int +main(int argc, char *argv[]) +{ + Catch::Session session; + + using namespace Catch::clara; + + auto cli = session.cli() | Opt(nevents, "n")["--ts-nevents"]("number of events (default: 1)\n") | + Opt(nthreads, "n")["--ts-nthreads"]("number of ethreads (default: 1)\n"); + + session.cli(cli); + + if (int res = session.applyCommandLine(argc, argv); res != 0) { + return res; + } + + return session.run(); +} From b10652bbce4000c3cd930dd6b068a94a12d6e966 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Thu, 23 Jan 2025 10:53:39 -0600 Subject: [PATCH 16/18] Fix linter warnings in InkAPI.cc (#11980) --- src/api/InkAPI.cc | 785 +++++++++++++++++++++++----------------------- 1 file changed, 393 insertions(+), 392 deletions(-) diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index a1925e848c9..fce56027493 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -27,6 +27,8 @@ #include #include +#include "iocore/net/NetVConnection.h" +#include "iocore/net/UDPNet.h" #include "tscore/ink_platform.h" #include "tscore/ink_base64.h" #include "tscore/Encoding.h" @@ -35,7 +37,6 @@ #include "tscore/Diags.h" #include "tsutil/Metrics.h" -#include "tscore/Version.h" #include "api/InkAPIInternal.h" #include "api/HttpAPIHooks.h" #include "proxy/logging/Log.h" @@ -49,10 +50,7 @@ #include "proxy/http/HttpConfig.h" #include "proxy/PluginHttpConnect.h" #include "../iocore/net/P_Net.h" -#include "../iocore/net/P_SSLNextProtocolAccept.h" #include "../iocore/net/P_SSLNetVConnection.h" -#include "../iocore/net/P_UDPNet.h" -#include "../iocore/hostdb/P_HostDB.h" #include "../iocore/cache/P_Cache.h" #include "records/RecCore.h" #include "../records/P_RecCore.h" @@ -77,7 +75,6 @@ #include "iocore/eventsystem/Tasks.h" #include "../iocore/net/P_OCSPStapling.h" -#include "records/RecordsConfig.h" #include "records/RecDefs.h" #include "records/RecCore.h" #include "records/RecYAMLDecoder.h" @@ -362,9 +359,9 @@ _hdr_obj_to_mime_hdr_impl(HdrHeapObjImpl *obj) { MIMEHdrImpl *impl; if (obj->m_type == HDR_HEAP_OBJ_HTTP_HEADER) { - impl = ((HTTPHdrImpl *)obj)->m_fields_impl; + impl = static_cast(obj)->m_fields_impl; } else if (obj->m_type == HDR_HEAP_OBJ_MIME_HEADER) { - impl = (MIMEHdrImpl *)obj; + impl = static_cast(obj); } else { ink_release_assert(!"mloc not a header type"); impl = nullptr; /* gcc does not know about 'ink_release_assert' - make it happy */ @@ -375,7 +372,7 @@ _hdr_obj_to_mime_hdr_impl(HdrHeapObjImpl *obj) inline MIMEHdrImpl * _hdr_mloc_to_mime_hdr_impl(TSMLoc mloc) { - return _hdr_obj_to_mime_hdr_impl((HdrHeapObjImpl *)mloc); + return _hdr_obj_to_mime_hdr_impl(reinterpret_cast(mloc)); } TSReturnCode @@ -385,7 +382,7 @@ sdk_sanity_check_field_handle(TSMLoc field, TSMLoc parent_hdr = nullptr) return TS_ERROR; } - MIMEFieldSDKHandle *field_handle = (MIMEFieldSDKHandle *)field; + MIMEFieldSDKHandle *field_handle = reinterpret_cast(field); if (field_handle->m_type != HDR_HEAP_OBJ_FIELD_SDK_HANDLE) { return TS_ERROR; } @@ -402,7 +399,7 @@ sdk_sanity_check_field_handle(TSMLoc field, TSMLoc parent_hdr = nullptr) TSReturnCode sdk_sanity_check_mbuffer(TSMBuffer bufp) { - HdrHeapSDKHandle *handle = (HdrHeapSDKHandle *)bufp; + HdrHeapSDKHandle *handle = reinterpret_cast(bufp); if ((handle == nullptr) || (handle->m_heap == nullptr) || (handle->m_heap->m_magic != HDR_BUF_MAGIC_ALIVE)) { return TS_ERROR; } @@ -417,7 +414,7 @@ sdk_sanity_check_mime_hdr_handle(TSMLoc field) return TS_ERROR; } - MIMEFieldSDKHandle *field_handle = (MIMEFieldSDKHandle *)field; + MIMEFieldSDKHandle *field_handle = reinterpret_cast(field); if (field_handle->m_type != HDR_HEAP_OBJ_MIME_HEADER) { return TS_ERROR; } @@ -432,7 +429,7 @@ sdk_sanity_check_url_handle(TSMLoc field) return TS_ERROR; } - MIMEFieldSDKHandle *field_handle = (MIMEFieldSDKHandle *)field; + MIMEFieldSDKHandle *field_handle = reinterpret_cast(field); if (field_handle->m_type != HDR_HEAP_OBJ_URL) { return TS_ERROR; } @@ -447,7 +444,7 @@ sdk_sanity_check_http_hdr_handle(TSMLoc field) return TS_ERROR; } - HTTPHdrImpl *field_handle = (HTTPHdrImpl *)field; + HTTPHdrImpl *field_handle = reinterpret_cast(field); if (field_handle->m_type != HDR_HEAP_OBJ_HTTP_HEADER) { return TS_ERROR; } @@ -458,7 +455,7 @@ sdk_sanity_check_http_hdr_handle(TSMLoc field) TSReturnCode sdk_sanity_check_continuation(TSCont cont) { - if ((cont == nullptr) || (((INKContInternal *)cont)->m_free_magic == INKCONT_INTERN_MAGIC_DEAD)) { + if ((cont == nullptr) || (reinterpret_cast(cont)->m_free_magic == INKCONT_INTERN_MAGIC_DEAD)) { return TS_ERROR; } @@ -488,7 +485,7 @@ sdk_sanity_check_http_ssn(TSHttpSsn ssnp) TSReturnCode sdk_sanity_check_txn(TSHttpTxn txnp) { - if ((txnp != nullptr) && (((HttpSM *)txnp)->magic == HTTP_SM_MAGIC_ALIVE)) { + if ((txnp != nullptr) && ((reinterpret_cast(txnp))->magic == HTTP_SM_MAGIC_ALIVE)) { return TS_SUCCESS; } return TS_ERROR; @@ -578,7 +575,7 @@ bool isWriteable(TSMBuffer bufp) { if (bufp != nullptr) { - return ((HdrHeapSDKHandle *)bufp)->m_heap->m_writeable; + return (reinterpret_cast(bufp))->m_heap->m_writeable; } return false; } @@ -783,13 +780,13 @@ TSfopen(const char *filename, const char *mode) return nullptr; } - return (TSFile)file; + return reinterpret_cast(file); } void TSfclose(TSFile filep) { - FileImpl *file = (FileImpl *)filep; + FileImpl *file = reinterpret_cast(filep); file->fclose(); delete file; } @@ -797,28 +794,28 @@ TSfclose(TSFile filep) ssize_t TSfread(TSFile filep, void *buf, size_t length) { - FileImpl *file = (FileImpl *)filep; + FileImpl *file = reinterpret_cast(filep); return file->fread(buf, length); } ssize_t TSfwrite(TSFile filep, const void *buf, size_t length) { - FileImpl *file = (FileImpl *)filep; + FileImpl *file = reinterpret_cast(filep); return file->fwrite(buf, length); } void TSfflush(TSFile filep) { - FileImpl *file = (FileImpl *)filep; + FileImpl *file = reinterpret_cast(filep); file->fflush(); } char * TSfgets(TSFile filep, char *buf, size_t length) { - FileImpl *file = (FileImpl *)filep; + FileImpl *file = reinterpret_cast(filep); return file->fgets(buf, length); } @@ -832,7 +829,7 @@ TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) { MIMEFieldSDKHandle *field_handle; - HdrHeapObjImpl *obj = (HdrHeapObjImpl *)mloc; + HdrHeapObjImpl *obj = reinterpret_cast(mloc); if (mloc == TS_NULL_MLOC) { return TS_SUCCESS; @@ -847,7 +844,7 @@ TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) return TS_SUCCESS; case HDR_HEAP_OBJ_FIELD_SDK_HANDLE: - field_handle = (MIMEFieldSDKHandle *)obj; + field_handle = static_cast(obj); if (sdk_sanity_check_field_handle(mloc, parent) != TS_SUCCESS) { return TS_ERROR; } @@ -876,7 +873,7 @@ TSMBufferCreate() HdrHeapSDKHandle *new_heap = new HdrHeapSDKHandle; new_heap->m_heap = new_HdrHeap(); - bufp = (TSMBuffer)new_heap; + bufp = reinterpret_cast(new_heap); // TODO: Should remove this when memory allocation is guaranteed to fail. sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); return bufp; @@ -894,7 +891,7 @@ TSMBufferDestroy(TSMBuffer bufp) } sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); - HdrHeapSDKHandle *sdk_heap = (HdrHeapSDKHandle *)bufp; + HdrHeapSDKHandle *sdk_heap = reinterpret_cast(bufp); sdk_heap->m_heap->destroy(); delete sdk_heap; return TS_SUCCESS; @@ -915,8 +912,8 @@ TSUrlCreate(TSMBuffer bufp, TSMLoc *locp) sdk_assert(sdk_sanity_check_null_ptr(locp) == TS_SUCCESS); if (isWriteable(bufp)) { - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - *locp = (TSMLoc)url_create(heap); + HdrHeap *heap = reinterpret_cast(bufp)->m_heap; + *locp = reinterpret_cast(url_create(heap)); return TS_SUCCESS; } return TS_ERROR; @@ -937,12 +934,12 @@ TSUrlClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_url, TSMLoc *locp HdrHeap *s_heap, *d_heap; URLImpl *s_url, *d_url; - s_heap = ((HdrHeapSDKHandle *)src_bufp)->m_heap; - d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; - s_url = (URLImpl *)src_url; + s_heap = reinterpret_cast(src_bufp)->m_heap; + d_heap = reinterpret_cast(dest_bufp)->m_heap; + s_url = reinterpret_cast(src_url); d_url = url_copy(s_url, s_heap, d_heap, (s_heap != d_heap)); - *locp = (TSMLoc)d_url; + *locp = reinterpret_cast(d_url); return TS_SUCCESS; } @@ -961,10 +958,10 @@ TSUrlCopy(TSMBuffer dest_bufp, TSMLoc dest_obj, TSMBuffer src_bufp, TSMLoc src_o HdrHeap *s_heap, *d_heap; URLImpl *s_url, *d_url; - s_heap = ((HdrHeapSDKHandle *)src_bufp)->m_heap; - d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; - s_url = (URLImpl *)src_obj; - d_url = (URLImpl *)dest_obj; + s_heap = reinterpret_cast(src_bufp)->m_heap; + d_heap = reinterpret_cast(dest_bufp)->m_heap; + s_url = reinterpret_cast(src_obj); + d_url = reinterpret_cast(dest_obj); url_copy_onto(s_url, s_heap, d_url, d_heap, (s_heap != d_heap)); return TS_SUCCESS; @@ -977,15 +974,15 @@ TSUrlPrint(TSMBuffer bufp, TSMLoc obj, TSIOBuffer iobufp) sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); sdk_assert(sdk_sanity_check_iocore_structure(iobufp) == TS_SUCCESS); - MIOBuffer *b = (MIOBuffer *)iobufp; + MIOBuffer *b = reinterpret_cast(iobufp); IOBufferBlock *blk; int bufindex; int tmp, dumpoffset; int done; URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); dumpoffset = 0; do { @@ -1019,10 +1016,10 @@ TSUrlParse(TSMBuffer bufp, TSMLoc obj, const char **start, const char *end) } URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); url_clear(u.m_url_impl); - return (TSParseResult)u.parse(start, end); + return static_cast(u.parse(start, end)); } int @@ -1031,7 +1028,7 @@ TSUrlLengthGet(TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); - URLImpl *url_impl = (URLImpl *)obj; + URLImpl *url_impl = reinterpret_cast(obj); return url_length_get(url_impl); } @@ -1045,7 +1042,7 @@ TSUrlStringGet(TSMBuffer bufp, TSMLoc obj, int *length) sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)length) == TS_SUCCESS); - URLImpl *url_impl = (URLImpl *)obj; + URLImpl *url_impl = reinterpret_cast(obj); return url_string_get(url_impl, nullptr, length, nullptr); } @@ -1061,8 +1058,8 @@ URLPartGet(TSMBuffer bufp, TSMLoc obj, int *length, URLPartGetF url_f) URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); return (u.*url_f)(length); } @@ -1078,8 +1075,8 @@ URLPartSet(TSMBuffer bufp, TSMLoc obj, const char *value, int length, URLPartSet } URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); if (!value) { length = 0; @@ -1171,8 +1168,8 @@ TSUrlPortGet(TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); return u.port_get(); } @@ -1184,8 +1181,8 @@ TSUrlRawPortGet(TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); return u.port_get_raw(); } @@ -1202,8 +1199,8 @@ TSUrlPortSet(TSMBuffer bufp, TSMLoc obj, int port) URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); u.port_set(port); return TS_SUCCESS; } @@ -1231,8 +1228,8 @@ TSUrlFtpTypeGet(TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); return u.type_code_get(); } @@ -1247,8 +1244,8 @@ TSUrlFtpTypeSet(TSMBuffer bufp, TSMLoc obj, int type) if ((type == 0 || type == 'A' || type == 'E' || type == 'I' || type == 'a' || type == 'i' || type == 'e') && isWriteable(bufp)) { URL u; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); u.type_code_set(type); return TS_SUCCESS; } @@ -1354,7 +1351,7 @@ TSUrlPercentEncode(TSMBuffer bufp, TSMLoc obj, char *dst, size_t dst_size, size_ char *url; int url_len; TSReturnCode ret; - URLImpl *url_impl = (URLImpl *)obj; + URLImpl *url_impl = reinterpret_cast(obj); // TODO: at some point, it might be nice to allow this to write to a pre-allocated buffer url = url_string_get(url_impl, nullptr, &url_len, nullptr); @@ -1392,7 +1389,7 @@ TSMimeParserCreate() { TSMimeParser parser = reinterpret_cast(ats_malloc(sizeof(MIMEParser))); - mime_parser_init((MIMEParser *)parser); + mime_parser_init(reinterpret_cast(parser)); return parser; } @@ -1401,7 +1398,7 @@ TSMimeParserClear(TSMimeParser parser) { sdk_assert(sdk_sanity_check_mime_parser(parser) == TS_SUCCESS); - mime_parser_clear((MIMEParser *)parser); + mime_parser_clear(reinterpret_cast(parser)); } void @@ -1409,7 +1406,7 @@ TSMimeParserDestroy(TSMimeParser parser) { sdk_assert(sdk_sanity_check_mime_parser(parser) == TS_SUCCESS); - mime_parser_clear((MIMEParser *)parser); + mime_parser_clear(reinterpret_cast(parser)); ats_free(parser); } @@ -1433,7 +1430,7 @@ TSMimeHdrCreate(TSMBuffer bufp, TSMLoc *locp) return TS_ERROR; } - *locp = reinterpret_cast(mime_hdr_create(((HdrHeapSDKHandle *)bufp)->m_heap)); + *locp = reinterpret_cast(mime_hdr_create((reinterpret_cast(bufp))->m_heap)); return TS_SUCCESS; } @@ -1453,7 +1450,7 @@ TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc obj) MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(obj); - mime_hdr_destroy(((HdrHeapSDKHandle *)bufp)->m_heap, mh); + mime_hdr_destroy((reinterpret_cast(bufp))->m_heap, mh); return TS_SUCCESS; } @@ -1476,12 +1473,12 @@ TSMimeHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc * HdrHeap *s_heap, *d_heap; MIMEHdrImpl *s_mh, *d_mh; - s_heap = ((HdrHeapSDKHandle *)src_bufp)->m_heap; - d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; + s_heap = (reinterpret_cast(src_bufp))->m_heap; + d_heap = (reinterpret_cast(dest_bufp))->m_heap; s_mh = _hdr_mloc_to_mime_hdr_impl(src_hdr); d_mh = mime_hdr_clone(s_mh, s_heap, d_heap, (s_heap != d_heap)); - *locp = (TSMLoc)d_mh; + *locp = reinterpret_cast(d_mh); return TS_SUCCESS; } @@ -1507,8 +1504,8 @@ TSMimeHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_obj, TSMBuffer src_bufp, TSMLoc s HdrHeap *s_heap, *d_heap; MIMEHdrImpl *s_mh, *d_mh; - s_heap = ((HdrHeapSDKHandle *)src_bufp)->m_heap; - d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; + s_heap = (reinterpret_cast(src_bufp))->m_heap; + d_heap = (reinterpret_cast(dest_bufp))->m_heap; s_mh = _hdr_mloc_to_mime_hdr_impl(src_obj); d_mh = _hdr_mloc_to_mime_hdr_impl(dest_obj); @@ -1524,7 +1521,7 @@ TSMimeHdrPrint(TSMLoc obj, TSIOBuffer iobufp) sdk_assert(sdk_sanity_check_iocore_structure(iobufp) == TS_SUCCESS); MIMEHdrImpl const *mh = _hdr_mloc_to_mime_hdr_impl(obj); - MIOBuffer *b = (MIOBuffer *)iobufp; + MIOBuffer *b = reinterpret_cast(iobufp); IOBufferBlock *blk; int bufindex; int tmp, dumpoffset = 0; @@ -1561,8 +1558,9 @@ TSMimeHdrParse(TSMimeParser parser, TSMBuffer bufp, TSMLoc obj, const char **sta MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(obj); - return (TSParseResult)mime_parser_parse((MIMEParser *)parser, ((HdrHeapSDKHandle *)bufp)->m_heap, mh, start, end, false, false, - false); + return static_cast(mime_parser_parse(reinterpret_cast(parser), + (reinterpret_cast(bufp))->m_heap, mh, start, end, false, + false, false)); } int @@ -1587,7 +1585,7 @@ TSMimeHdrFieldsClear(TSMBuffer bufp, TSMLoc obj) MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(obj); - mime_hdr_fields_clear(((HdrHeapSDKHandle *)bufp)->m_heap, mh); + mime_hdr_fields_clear((reinterpret_cast(bufp))->m_heap, mh); return TS_SUCCESS; } @@ -1606,7 +1604,7 @@ TSMimeHdrFieldsCount(TSMBuffer bufp, TSMLoc obj) static const char * TSMimeFieldValueGet(TSMBuffer /* bufp ATS_UNUSED */, TSMLoc field_obj, int idx, int *value_len_ptr) { - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field_obj; + MIMEFieldSDKHandle *handle = reinterpret_cast(field_obj); if (idx >= 0) { return mime_field_value_get_comma_val(handle->field_ptr, value_len_ptr, idx); @@ -1618,8 +1616,8 @@ TSMimeFieldValueGet(TSMBuffer /* bufp ATS_UNUSED */, TSMLoc field_obj, int idx, static void TSMimeFieldValueSet(TSMBuffer bufp, TSMLoc field_obj, int idx, const char *value, int length) { - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field_obj; - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; + MIMEFieldSDKHandle *handle = reinterpret_cast(field_obj); + HdrHeap *heap = (reinterpret_cast(bufp))->m_heap; if (length == -1) { length = strlen(value); @@ -1635,8 +1633,8 @@ TSMimeFieldValueSet(TSMBuffer bufp, TSMLoc field_obj, int idx, const char *value static void TSMimeFieldValueInsert(TSMBuffer bufp, TSMLoc field_obj, const char *value, int length, int idx) { - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field_obj; - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; + MIMEFieldSDKHandle *handle = reinterpret_cast(field_obj); + HdrHeap *heap = (reinterpret_cast(bufp))->m_heap; if (length == -1) { length = strlen(value); @@ -1716,7 +1714,7 @@ TSMimeHdrFieldAppend(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc field_mloc) MIMEField *mh_field; MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(mh_mloc); - MIMEFieldSDKHandle *field_handle = (MIMEFieldSDKHandle *)field_mloc; + MIMEFieldSDKHandle *field_handle = reinterpret_cast(field_mloc); ////////////////////////////////////////////////////////////////////// // The field passed in field_mloc might have been allocated from // @@ -1729,7 +1727,7 @@ TSMimeHdrFieldAppend(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc field_mloc) // forwarding pointer to the real field, in case it's used again // ////////////////////////////////////////////////////////////////////// if (field_handle->mh == nullptr) { - HdrHeap *heap = (HdrHeap *)(((HdrHeapSDKHandle *)bufp)->m_heap); + HdrHeap *heap = ((reinterpret_cast(bufp))->m_heap); // allocate a new hdr field and copy any pre-set info mh_field = mime_field_create(heap, mh); @@ -1765,7 +1763,7 @@ TSMimeHdrFieldRemove(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc field_mloc) return TS_ERROR; } - MIMEFieldSDKHandle *field_handle = (MIMEFieldSDKHandle *)field_mloc; + MIMEFieldSDKHandle *field_handle = reinterpret_cast(field_mloc); if (field_handle->mh != nullptr) { MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(mh_mloc); @@ -1792,13 +1790,13 @@ TSMimeHdrFieldDestroy(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc field_mloc) return TS_ERROR; } - MIMEFieldSDKHandle *field_handle = (MIMEFieldSDKHandle *)field_mloc; + MIMEFieldSDKHandle *field_handle = reinterpret_cast(field_mloc); if (field_handle->mh == nullptr) { // NOT SUPPORTED!! ink_release_assert(!"Failed MH"); } else { MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(mh_mloc); - HdrHeap *heap = (HdrHeap *)(((HdrHeapSDKHandle *)bufp)->m_heap); + HdrHeap *heap = ((reinterpret_cast(bufp))->m_heap); ink_assert(mh == field_handle->mh); if (sdk_sanity_check_field_handle(field_mloc, mh_mloc) != TS_SUCCESS) { @@ -1829,7 +1827,7 @@ TSMimeHdrFieldCreate(TSMBuffer bufp, TSMLoc mh_mloc, TSMLoc *locp) } MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(mh_mloc); - HdrHeap *heap = (HdrHeap *)(((HdrHeapSDKHandle *)bufp)->m_heap); + HdrHeap *heap = ((reinterpret_cast(bufp))->m_heap); MIMEFieldSDKHandle *h = sdk_alloc_field_handle(bufp, mh); h->field_ptr = mime_field_create(heap, mh); @@ -1855,7 +1853,7 @@ TSMimeHdrFieldCreateNamed(TSMBuffer bufp, TSMLoc mh_mloc, const char *name, int } MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(mh_mloc); - HdrHeap *heap = (HdrHeap *)(((HdrHeapSDKHandle *)bufp)->m_heap); + HdrHeap *heap = ((reinterpret_cast(bufp))->m_heap); MIMEFieldSDKHandle *h = sdk_alloc_field_handle(bufp, mh); h->field_ptr = mime_field_create_named(heap, mh, name, name_len); *locp = reinterpret_cast(h); @@ -1883,9 +1881,9 @@ TSMimeHdrFieldCopy(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMLoc dest_field, TSMB } bool dest_attached; - MIMEFieldSDKHandle *s_handle = (MIMEFieldSDKHandle *)src_field; - MIMEFieldSDKHandle *d_handle = (MIMEFieldSDKHandle *)dest_field; - HdrHeap *d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; + MIMEFieldSDKHandle *s_handle = reinterpret_cast(src_field); + MIMEFieldSDKHandle *d_handle = reinterpret_cast(dest_field); + HdrHeap *d_heap = (reinterpret_cast(dest_bufp))->m_heap; // FIX: This tortuous detach/change/attach algorithm is due to the // fact that we can't change the name of an attached header (assertion) @@ -1958,9 +1956,9 @@ TSMimeHdrFieldCopyValues(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMLoc dest_field return TS_ERROR; } - MIMEFieldSDKHandle *s_handle = (MIMEFieldSDKHandle *)src_field; - MIMEFieldSDKHandle *d_handle = (MIMEFieldSDKHandle *)dest_field; - HdrHeap *d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; + MIMEFieldSDKHandle *s_handle = reinterpret_cast(src_field); + MIMEFieldSDKHandle *d_handle = reinterpret_cast(dest_field); + HdrHeap *d_heap = (reinterpret_cast(dest_bufp))->m_heap; MIMEField *s_field, *d_field; s_field = s_handle->field_ptr; @@ -1997,7 +1995,7 @@ TSMimeHdrFieldNextDup(TSMBuffer bufp, TSMLoc hdr, TSMLoc field) sdk_assert(sdk_sanity_check_field_handle(field, hdr) == TS_SUCCESS); MIMEHdrImpl *mh = _hdr_mloc_to_mime_hdr_impl(hdr); - MIMEFieldSDKHandle *field_handle = (MIMEFieldSDKHandle *)field; + MIMEFieldSDKHandle *field_handle = reinterpret_cast(field); MIMEField *next = field_handle->field_ptr->m_next_dup; if (next == nullptr) { return TS_NULL_MLOC; @@ -2005,7 +2003,7 @@ TSMimeHdrFieldNextDup(TSMBuffer bufp, TSMLoc hdr, TSMLoc field) MIMEFieldSDKHandle *next_handle = sdk_alloc_field_handle(bufp, mh); next_handle->field_ptr = next; - return (TSMLoc)next_handle; + return reinterpret_cast(next_handle); } int @@ -2015,7 +2013,7 @@ TSMimeHdrFieldLengthGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field) sdk_assert((sdk_sanity_check_mime_hdr_handle(hdr) == TS_SUCCESS) || (sdk_sanity_check_http_hdr_handle(hdr) == TS_SUCCESS)); sdk_assert(sdk_sanity_check_field_handle(field, hdr) == TS_SUCCESS); - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field; + MIMEFieldSDKHandle *handle = reinterpret_cast(field); return mime_field_length_get(handle->field_ptr); } @@ -2051,8 +2049,8 @@ TSMimeHdrFieldNameSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, const char *name length = strlen(name); } - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field; - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; + MIMEFieldSDKHandle *handle = reinterpret_cast(field); + HdrHeap *heap = (reinterpret_cast(bufp))->m_heap; int attached = (handle->mh && handle->field_ptr->is_live()); @@ -2083,8 +2081,8 @@ TSMimeHdrFieldValuesClear(TSMBuffer bufp, TSMLoc hdr, TSMLoc field) return TS_ERROR; } - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field; - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; + MIMEFieldSDKHandle *handle = reinterpret_cast(field); + HdrHeap *heap = (reinterpret_cast(bufp))->m_heap; /** * Modified the string value passed from an empty string ("") to null. @@ -2102,7 +2100,7 @@ TSMimeHdrFieldValuesCount(TSMBuffer bufp, TSMLoc hdr, TSMLoc field) sdk_assert((sdk_sanity_check_mime_hdr_handle(hdr) == TS_SUCCESS) || (sdk_sanity_check_http_hdr_handle(hdr) == TS_SUCCESS)); sdk_assert(sdk_sanity_check_field_handle(field, hdr) == TS_SUCCESS); - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field; + MIMEFieldSDKHandle *handle = reinterpret_cast(field); return mime_field_value_get_comma_val_count(handle->field_ptr); } @@ -2128,7 +2126,7 @@ TSMimeHdrFieldValueDateGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field) const char *value_str = TSMimeFieldValueGet(bufp, field, -1, &value_len); if (value_str == nullptr) { - return (time_t)0; + return static_cast(0); } return mime_parse_date(value_str, value_str + value_len); @@ -2138,7 +2136,7 @@ time_t TSMimeParseDate(char const *const value_str, int const value_len) { if (value_str == nullptr) { - return (time_t)0; + return static_cast(0); } return mime_parse_date(value_str, value_str + value_len); @@ -2341,8 +2339,8 @@ TSMimeHdrFieldValueAppend(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, con return TS_ERROR; } - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field; - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; + MIMEFieldSDKHandle *handle = reinterpret_cast(field); + HdrHeap *heap = (reinterpret_cast(bufp))->m_heap; if (length == -1) { length = strlen(value); @@ -2457,8 +2455,8 @@ TSMimeHdrFieldValueDelete(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx) return TS_ERROR; } - MIMEFieldSDKHandle *handle = (MIMEFieldSDKHandle *)field; - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; + MIMEFieldSDKHandle *handle = reinterpret_cast(field); + HdrHeap *heap = (reinterpret_cast(bufp))->m_heap; mime_field_value_delete_comma_val(heap, handle->mh, handle->field_ptr, idx); return TS_SUCCESS; @@ -2481,7 +2479,7 @@ TSHttpParser TSHttpParserCreate() { TSHttpParser parser = reinterpret_cast(ats_malloc(sizeof(HTTPParser))); - http_parser_init((HTTPParser *)parser); + http_parser_init(reinterpret_cast(parser)); return parser; } @@ -2490,14 +2488,14 @@ void TSHttpParserClear(TSHttpParser parser) { sdk_assert(sdk_sanity_check_http_parser(parser) == TS_SUCCESS); - http_parser_clear((HTTPParser *)parser); + http_parser_clear(reinterpret_cast(parser)); } void TSHttpParserDestroy(TSHttpParser parser) { sdk_assert(sdk_sanity_check_http_parser(parser) == TS_SUCCESS); - http_parser_clear((HTTPParser *)parser); + http_parser_clear(reinterpret_cast(parser)); ats_free(parser); } @@ -2511,9 +2509,9 @@ TSHttpHdrCreate(TSMBuffer bufp) sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); HTTPHdr h; - h.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; + h.m_heap = (reinterpret_cast(bufp))->m_heap; h.create(HTTP_TYPE_UNKNOWN); - return (TSMLoc)(h.m_http); + return reinterpret_cast(h.m_http); } void @@ -2545,9 +2543,9 @@ TSHttpHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc * HdrHeap *s_heap, *d_heap; HTTPHdrImpl *s_hh, *d_hh; - s_heap = ((HdrHeapSDKHandle *)src_bufp)->m_heap; - d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; - s_hh = (HTTPHdrImpl *)src_hdr; + s_heap = (reinterpret_cast(src_bufp))->m_heap; + d_heap = (reinterpret_cast(dest_bufp))->m_heap; + s_hh = reinterpret_cast(src_hdr); if (s_hh->m_type != HDR_HEAP_OBJ_HTTP_HEADER) { return TS_ERROR; @@ -2556,7 +2554,7 @@ TSHttpHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc * // TODO: This is never used // inherit_strs = (s_heap != d_heap ? true : false); d_hh = http_hdr_clone(s_hh, s_heap, d_heap); - *locp = (TSMLoc)d_hh; + *locp = reinterpret_cast(d_hh); return TS_SUCCESS; } @@ -2581,17 +2579,17 @@ TSHttpHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_obj, TSMBuffer src_bufp, TSMLoc s HdrHeap *s_heap, *d_heap; HTTPHdrImpl *s_hh, *d_hh; - s_heap = ((HdrHeapSDKHandle *)src_bufp)->m_heap; - d_heap = ((HdrHeapSDKHandle *)dest_bufp)->m_heap; - s_hh = (HTTPHdrImpl *)src_obj; - d_hh = (HTTPHdrImpl *)dest_obj; + s_heap = (reinterpret_cast(src_bufp))->m_heap; + d_heap = (reinterpret_cast(dest_bufp))->m_heap; + s_hh = reinterpret_cast(src_obj); + d_hh = reinterpret_cast(dest_obj); if ((s_hh->m_type != HDR_HEAP_OBJ_HTTP_HEADER) || (d_hh->m_type != HDR_HEAP_OBJ_HTTP_HEADER)) { return TS_ERROR; } inherit_strs = (s_heap != d_heap ? true : false); - TSHttpHdrTypeSet(dest_bufp, dest_obj, (TSHttpType)(s_hh->m_polarity)); + TSHttpHdrTypeSet(dest_bufp, dest_obj, static_cast(s_hh->m_polarity)); http_hdr_copy_onto(s_hh, s_heap, d_hh, d_heap, inherit_strs); return TS_SUCCESS; } @@ -2603,7 +2601,7 @@ TSHttpHdrPrint(TSMBuffer bufp, TSMLoc obj, TSIOBuffer iobufp) sdk_assert(sdk_sanity_check_http_hdr_handle(obj) == TS_SUCCESS); sdk_assert(sdk_sanity_check_iocore_structure(iobufp) == TS_SUCCESS); - MIOBuffer *b = (MIOBuffer *)iobufp; + MIOBuffer *b = reinterpret_cast(iobufp); IOBufferBlock *blk; HTTPHdr h; int bufindex; @@ -2649,7 +2647,7 @@ TSHttpHdrParseReq(TSHttpParser parser, TSMBuffer bufp, TSMLoc obj, const char ** SET_HTTP_HDR(h, bufp, obj); ink_assert(h.m_http->m_type == HDR_HEAP_OBJ_HTTP_HEADER); TSHttpHdrTypeSet(bufp, obj, TS_HTTP_TYPE_REQUEST); - return (TSParseResult)h.parse_req((HTTPParser *)parser, start, end, false); + return static_cast(h.parse_req(reinterpret_cast(parser), start, end, false)); } TSParseResult @@ -2670,7 +2668,7 @@ TSHttpHdrParseResp(TSHttpParser parser, TSMBuffer bufp, TSMLoc obj, const char * SET_HTTP_HDR(h, bufp, obj); ink_assert(h.m_http->m_type == HDR_HEAP_OBJ_HTTP_HEADER); TSHttpHdrTypeSet(bufp, obj, TS_HTTP_TYPE_RESPONSE); - return (TSParseResult)h.parse_resp((HTTPParser *)parser, start, end, false); + return static_cast(h.parse_resp(reinterpret_cast(parser), start, end, false)); } int @@ -2697,7 +2695,7 @@ TSHttpHdrTypeGet(TSMBuffer bufp, TSMLoc obj) /* Don't need the assert as the check is done in sdk_sanity_check_http_hdr_handle ink_assert(h.m_http->m_type == HDR_HEAP_OBJ_HTTP_HEADER); */ - return (TSHttpType)h.type_get(); + return static_cast(h.type_get()); } TSReturnCode @@ -2729,11 +2727,11 @@ TSHttpHdrTypeSet(TSMBuffer bufp, TSMLoc obj, TSHttpType type) // people change the types of a header. If they // try, too bad. if (h.m_http->m_polarity == HTTP_TYPE_UNKNOWN) { - if (type == (TSHttpType)HTTP_TYPE_REQUEST) { + if (type == static_cast(HTTP_TYPE_REQUEST)) { h.m_http->u.req.m_url_impl = url_create(h.m_heap); - h.m_http->m_polarity = (HTTPType)type; - } else if (type == (TSHttpType)HTTP_TYPE_RESPONSE) { - h.m_http->m_polarity = (HTTPType)type; + h.m_http->m_polarity = static_cast(type); + } else if (type == static_cast(HTTP_TYPE_RESPONSE)) { + h.m_http->m_polarity = static_cast(type); } } return TS_SUCCESS; @@ -2834,13 +2832,13 @@ TSHttpHdrUrlGet(TSMBuffer bufp, TSMLoc obj, TSMLoc *locp) sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_http_hdr_handle(obj) == TS_SUCCESS); - HTTPHdrImpl *hh = (HTTPHdrImpl *)obj; + HTTPHdrImpl *hh = reinterpret_cast(obj); if (hh->m_polarity != HTTP_TYPE_REQUEST) { return TS_ERROR; } - *locp = ((TSMLoc)hh->u.req.m_url_impl); + *locp = (reinterpret_cast(hh->u.req.m_url_impl)); return TS_SUCCESS; } @@ -2859,14 +2857,14 @@ TSHttpHdrUrlSet(TSMBuffer bufp, TSMLoc obj, TSMLoc url) return TS_ERROR; } - HdrHeap *heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - HTTPHdrImpl *hh = (HTTPHdrImpl *)obj; + HdrHeap *heap = (reinterpret_cast(bufp))->m_heap; + HTTPHdrImpl *hh = reinterpret_cast(obj); if (hh->m_type != HDR_HEAP_OBJ_HTTP_HEADER) { return TS_ERROR; } - URLImpl *url_impl = (URLImpl *)url; + URLImpl *url_impl = reinterpret_cast(url); http_hdr_url_set(heap, hh, url_impl); return TS_SUCCESS; } @@ -2880,7 +2878,7 @@ TSHttpHdrStatusGet(TSMBuffer bufp, TSMLoc obj) HTTPHdr h; SET_HTTP_HDR(h, bufp, obj); - return (TSHttpStatus)h.status_get(); + return static_cast(h.status_get()); } TSReturnCode @@ -2901,7 +2899,7 @@ TSHttpHdrStatusSet(TSMBuffer bufp, TSMLoc obj, TSHttpStatus status) SET_HTTP_HDR(h, bufp, obj); ink_assert(h.m_http->m_type == HDR_HEAP_OBJ_HTTP_HEADER); - h.status_set((HTTPStatus)status); + h.status_set(static_cast(status)); return TS_SUCCESS; } @@ -2950,7 +2948,7 @@ TSHttpHdrReasonSet(TSMBuffer bufp, TSMLoc obj, const char *value, int length) const char * TSHttpHdrReasonLookup(TSHttpStatus status) { - return http_hdr_reason_lookup((HTTPStatus)status); + return http_hdr_reason_lookup(static_cast(status)); } //////////////////////////////////////////////////////////////////// @@ -2972,7 +2970,7 @@ sdk_sanity_check_cachekey(TSCacheKey key) TSCacheKey TSCacheKeyCreate() { - TSCacheKey key = (TSCacheKey) new CacheInfo(); + TSCacheKey key = reinterpret_cast(new CacheInfo()); // TODO: Probably remove this when we can be use "NEW" can't fail. sdk_assert(sdk_sanity_check_cachekey(key) == TS_SUCCESS); @@ -3000,11 +2998,11 @@ TSCacheKeyDigestFromUrlSet(TSCacheKey key, TSMLoc url) { sdk_assert(sdk_sanity_check_cachekey(key) == TS_SUCCESS); - if (((CacheInfo *)key)->magic != CACHE_INFO_MAGIC_ALIVE) { + if ((reinterpret_cast(key))->magic != CACHE_INFO_MAGIC_ALIVE) { return TS_ERROR; } - url_CryptoHash_get((URLImpl *)url, &((CacheInfo *)key)->cache_key); + url_CryptoHash_get(reinterpret_cast(url), &(reinterpret_cast(key))->cache_key); return TS_SUCCESS; } @@ -3013,17 +3011,17 @@ TSCacheKeyDataTypeSet(TSCacheKey key, TSCacheDataType type) { sdk_assert(sdk_sanity_check_cachekey(key) == TS_SUCCESS); - if (((CacheInfo *)key)->magic != CACHE_INFO_MAGIC_ALIVE) { + if ((reinterpret_cast(key))->magic != CACHE_INFO_MAGIC_ALIVE) { return TS_ERROR; } switch (type) { case TS_CACHE_DATA_TYPE_NONE: - ((CacheInfo *)key)->frag_type = CACHE_FRAG_TYPE_NONE; + (reinterpret_cast(key))->frag_type = CACHE_FRAG_TYPE_NONE; break; case TS_CACHE_DATA_TYPE_OTHER: /* other maps to http */ case TS_CACHE_DATA_TYPE_HTTP: - ((CacheInfo *)key)->frag_type = CACHE_FRAG_TYPE_HTTP; + (reinterpret_cast(key))->frag_type = CACHE_FRAG_TYPE_HTTP; break; default: return TS_ERROR; @@ -3039,14 +3037,14 @@ TSCacheKeyHostNameSet(TSCacheKey key, const char *hostname, int host_len) sdk_assert(sdk_sanity_check_null_ptr((void *)hostname) == TS_SUCCESS); sdk_assert(host_len > 0); - if (((CacheInfo *)key)->magic != CACHE_INFO_MAGIC_ALIVE) { + if ((reinterpret_cast(key))->magic != CACHE_INFO_MAGIC_ALIVE) { return TS_ERROR; } - CacheInfo *i = (CacheInfo *)key; + CacheInfo *i = reinterpret_cast(key); /* need to make a copy of the hostname. The caller might deallocate it anytime in the future */ - i->hostname = (char *)ats_malloc(host_len); + i->hostname = static_cast(ats_malloc(host_len)); memcpy(i->hostname, hostname, host_len); i->len = host_len; return TS_SUCCESS; @@ -3057,11 +3055,11 @@ TSCacheKeyPinnedSet(TSCacheKey key, time_t pin_in_cache) { sdk_assert(sdk_sanity_check_cachekey(key) == TS_SUCCESS); - if (((CacheInfo *)key)->magic != CACHE_INFO_MAGIC_ALIVE) { + if ((reinterpret_cast(key))->magic != CACHE_INFO_MAGIC_ALIVE) { return TS_ERROR; } - CacheInfo *i = (CacheInfo *)key; + CacheInfo *i = reinterpret_cast(key); i->pin_in_cache = pin_in_cache; return TS_SUCCESS; } @@ -3071,11 +3069,11 @@ TSCacheKeyDestroy(TSCacheKey key) { sdk_assert(sdk_sanity_check_cachekey(key) == TS_SUCCESS); - if (((CacheInfo *)key)->magic != CACHE_INFO_MAGIC_ALIVE) { + if ((reinterpret_cast(key))->magic != CACHE_INFO_MAGIC_ALIVE) { return TS_ERROR; } - CacheInfo *i = (CacheInfo *)key; + CacheInfo *i = reinterpret_cast(key); ats_free(i->hostname); i->magic = CACHE_INFO_MAGIC_DEAD; @@ -3088,14 +3086,14 @@ TSCacheHttpInfoCopy(TSCacheHttpInfo infop) { CacheHTTPInfo *new_info = new CacheHTTPInfo; - new_info->copy((CacheHTTPInfo *)infop); + new_info->copy(reinterpret_cast(infop)); return reinterpret_cast(new_info); } void TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj) { - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); *(reinterpret_cast(bufp)) = info->request_get(); *obj = reinterpret_cast(info->request_get()->m_http); @@ -3105,7 +3103,7 @@ TSCacheHttpInfoReqGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj) void TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj) { - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); *(reinterpret_cast(bufp)) = info->response_get(); *obj = reinterpret_cast(info->response_get()->m_http); @@ -3115,21 +3113,21 @@ TSCacheHttpInfoRespGet(TSCacheHttpInfo infop, TSMBuffer *bufp, TSMLoc *obj) time_t TSCacheHttpInfoReqSentTimeGet(TSCacheHttpInfo infop) { - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); return info->request_sent_time_get(); } time_t TSCacheHttpInfoRespReceivedTimeGet(TSCacheHttpInfo infop) { - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); return info->response_received_time_get(); } int64_t TSCacheHttpInfoSizeGet(TSCacheHttpInfo infop) { - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); return info->object_size_get(); } @@ -3140,7 +3138,7 @@ TSCacheHttpInfoReqSet(TSCacheHttpInfo infop, TSMBuffer bufp, TSMLoc obj) SET_HTTP_HDR(h, bufp, obj); - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); info->request_set(&h); } @@ -3151,14 +3149,14 @@ TSCacheHttpInfoRespSet(TSCacheHttpInfo infop, TSMBuffer bufp, TSMLoc obj) SET_HTTP_HDR(h, bufp, obj); - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); info->response_set(&h); } int TSCacheHttpInfoVector(TSCacheHttpInfo infop, void *data, int length) { - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); CacheHTTPInfoVector vector; vector.insert(info); @@ -3170,13 +3168,13 @@ TSCacheHttpInfoVector(TSCacheHttpInfo infop, void *data, int length) return 0; } - return vector.marshal((char *)data, length); + return vector.marshal(static_cast(data), length); } void TSCacheHttpInfoDestroy(TSCacheHttpInfo infop) { - ((CacheHTTPInfo *)infop)->destroy(); + (reinterpret_cast(infop))->destroy(); } TSCacheHttpInfo @@ -3212,13 +3210,13 @@ TSConfigGet(unsigned int id) void TSConfigRelease(unsigned int id, TSConfig configp) { - configProcessor.release(id, (ConfigInfo *)configp); + configProcessor.release(id, reinterpret_cast(configp)); } void * TSConfigDataGet(TSConfig configp) { - INKConfigImpl *config = (INKConfigImpl *)configp; + INKConfigImpl *config = reinterpret_cast(configp); return config->mdata; } @@ -3234,13 +3232,13 @@ TSMgmtUpdateRegister(TSCont contp, const char *plugin_name, const char *plugin_f sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)plugin_name) == TS_SUCCESS); - global_config_cbs->insert((INKContInternal *)contp, plugin_name, plugin_file_name); + global_config_cbs->insert(reinterpret_cast(contp), plugin_name, plugin_file_name); } TSReturnCode TSMgmtIntGet(const char *var_name, TSMgmtInt *result) { - auto res = RecGetRecordInt((char *)var_name, (RecInt *)result); + auto res = RecGetRecordInt(const_cast(var_name), static_cast(result)); // Try the old librecords first if (res == REC_ERR_FAIL) { @@ -3259,7 +3257,7 @@ TSMgmtIntGet(const char *var_name, TSMgmtInt *result) TSReturnCode TSMgmtCounterGet(const char *var_name, TSMgmtCounter *result) { - auto res = RecGetRecordCounter((char *)var_name, (RecCounter *)result); + auto res = RecGetRecordCounter(const_cast(var_name), static_cast(result)); // Try the old librecords first if (res == REC_ERR_FAIL) { @@ -3279,14 +3277,14 @@ TSMgmtCounterGet(const char *var_name, TSMgmtCounter *result) TSReturnCode TSMgmtFloatGet(const char *var_name, TSMgmtFloat *result) { - return RecGetRecordFloat((char *)var_name, (RecFloat *)result) == REC_ERR_OKAY ? TS_SUCCESS : TS_ERROR; + return RecGetRecordFloat(const_cast(var_name), static_cast(result)) == REC_ERR_OKAY ? TS_SUCCESS : TS_ERROR; } TSReturnCode TSMgmtStringGet(const char *var_name, TSMgmtString *result) { RecString tmp = nullptr; - (void)RecGetRecordString_Xmalloc((char *)var_name, &tmp); + (void)RecGetRecordString_Xmalloc(const_cast(var_name), &tmp); if (tmp) { *result = tmp; @@ -3329,7 +3327,7 @@ TSContCreate(TSEventFunc funcp, TSMutex mutexp) INKContInternal *i = THREAD_ALLOC(INKContAllocator, this_thread()); i->init(funcp, mutexp, pluginThreadContext); - return (TSCont)i; + return reinterpret_cast(i); } void @@ -3337,7 +3335,7 @@ TSContDestroy(TSCont contp) { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); - INKContInternal *i = (INKContInternal *)contp; + INKContInternal *i = reinterpret_cast(contp); if (i->m_context) { reinterpret_cast(i->m_context)->release(); @@ -3351,7 +3349,7 @@ TSContDataSet(TSCont contp, void *data) { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); - INKContInternal *i = (INKContInternal *)contp; + INKContInternal *i = reinterpret_cast(contp); i->mdata = data; } @@ -3361,7 +3359,7 @@ TSContDataGet(TSCont contp) { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); - INKContInternal *i = (INKContInternal *)contp; + INKContInternal *i = reinterpret_cast(contp); return i->mdata; } @@ -3410,7 +3408,7 @@ TSContScheduleOnPool(TSCont contp, TSHRTime timeout, TSThreadPool tp) } /* This is a hack. Should be handled in ink_types */ - action = (TSAction)((uintptr_t)action | 0x1); + action = reinterpret_cast(reinterpret_cast(action) | 0x1); return action; } @@ -3442,7 +3440,7 @@ TSContScheduleOnThread(TSCont contp, TSHRTime timeout, TSEventThread ethread) } /* This is a hack. Should be handled in ink_types */ - action = (TSAction)((uintptr_t)action | 0x1); + action = reinterpret_cast(reinterpret_cast(action) | 0x1); return action; } @@ -3525,7 +3523,7 @@ TSContScheduleEveryOnPool(TSCont contp, TSHRTime every, TSThreadPool tp) TSAction action = reinterpret_cast(eventProcessor.schedule_every(i, HRTIME_MSECONDS(every), etype)); /* This is a hack. Should be handled in ink_types */ - action = (TSAction)((uintptr_t)action | 0x1); + action = reinterpret_cast(reinterpret_cast(action) | 0x1); return action; } @@ -3552,7 +3550,7 @@ TSContScheduleEveryOnThread(TSCont contp, TSHRTime every, TSEventThread ethread) TSAction action = reinterpret_cast(eth->schedule_every(i, HRTIME_MSECONDS(every))); /* This is a hack. Should be handled in ink_types */ - action = (TSAction)((uintptr_t)action | 0x1); + action = reinterpret_cast(reinterpret_cast(action) | 0x1); return action; } @@ -3647,15 +3645,15 @@ TSHttpSchedule(TSCont contp, TSHttpTxn txnp, TSHRTime timeout) FORCE_PLUGIN_SCOPED_MUTEX(contp); - INKContInternal *i = (INKContInternal *)contp; + INKContInternal *i = reinterpret_cast(contp); - if (ink_atomic_increment((int *)&i->m_event_count, 1) < 0) { + if (ink_atomic_increment(&i->m_event_count, 1) < 0) { ink_assert(!"not reached"); } TSAction action; - Continuation *cont = (Continuation *)contp; - HttpSM *sm = (HttpSM *)txnp; + Continuation *cont = reinterpret_cast(contp); + HttpSM *sm = reinterpret_cast(txnp); sm->set_http_schedule(cont); @@ -3665,20 +3663,20 @@ TSHttpSchedule(TSCont contp, TSHttpTxn txnp, TSHRTime timeout) action = reinterpret_cast(eventProcessor.schedule_in(sm, HRTIME_MSECONDS(timeout), ET_NET)); } - action = (TSAction)((uintptr_t)action | 0x1); + action = reinterpret_cast(reinterpret_cast(action) | 0x1); return action; } int TSContCall(TSCont contp, TSEvent event, void *edata) { - Continuation *c = (Continuation *)contp; + Continuation *c = reinterpret_cast(contp); WEAK_MUTEX_TRY_LOCK(lock, c->mutex, this_ethread()); if (!lock.is_locked()) { // If we cannot get the lock, the caller needs to restructure to handle rescheduling ink_release_assert(0); } - return c->handleEvent((int)event, edata); + return c->handleEvent(static_cast(event), edata); } TSMutex @@ -3686,8 +3684,8 @@ TSContMutexGet(TSCont contp) { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); - Continuation *c = (Continuation *)contp; - return (TSMutex)(c->mutex.get()); + Continuation *c = reinterpret_cast(contp); + return reinterpret_cast(c->mutex.get()); } /* HTTP hooks */ @@ -3715,7 +3713,7 @@ TSLifecycleHookAdd(TSLifecycleHookID id, TSCont contp) sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_lifecycle_hook_id(id) == TS_SUCCESS); - g_lifecycle_hooks->append(id, (INKContInternal *)contp); + g_lifecycle_hooks->append(id, reinterpret_cast(contp)); } /* HTTP sessions */ @@ -3727,7 +3725,7 @@ TSHttpSsnHookAdd(TSHttpSsn ssnp, TSHttpHookID id, TSCont contp) sdk_assert(sdk_sanity_check_hook_id(id) == TS_SUCCESS); ProxySession *cs = reinterpret_cast(ssnp); - cs->hook_add(id, (INKContInternal *)contp); + cs->hook_add(id, reinterpret_cast(contp)); } int @@ -3791,7 +3789,7 @@ class TSHttpSsnCallback : public Continuation if (!trylock.is_locked()) { eth->schedule_imm(this); } else { - m_cs->handleEvent((int)m_event, nullptr); + m_cs->handleEvent(static_cast(m_event), nullptr); delete this; } return 0; @@ -3832,7 +3830,7 @@ TSHttpSsnReenable(TSHttpSsn ssnp, TSEvent event) eventProcessor.schedule_imm(new TSHttpSsnCallback(cs, cs->mutex, event), ET_NET); } } else { - cs->handleEvent((int)event, nullptr); + cs->handleEvent(static_cast(event), nullptr); } } } @@ -3845,17 +3843,17 @@ TSHttpTxnHookAdd(TSHttpTxn txnp, TSHttpHookID id, TSCont contp) sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_hook_id(id) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); APIHook *hook = sm->txn_hook_get(id); // Traverse list of hooks and add a particular hook only once while (hook != nullptr) { - if (hook->m_cont == (INKContInternal *)contp) { + if (hook->m_cont == reinterpret_cast(contp)) { return; } hook = hook->m_link.next; } - sm->txn_hook_add(id, (INKContInternal *)contp); + sm->txn_hook_add(id, reinterpret_cast(contp)); } TSHttpSsn @@ -3864,7 +3862,7 @@ TSHttpTxnSsnGet(TSHttpTxn txnp) sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); HttpSM *sm = reinterpret_cast(txnp); - return reinterpret_cast(sm->get_ua_txn() ? (TSHttpSsn)sm->get_ua_txn()->get_proxy_ssn() : nullptr); + return reinterpret_cast(sm->get_ua_txn() ? reinterpret_cast(sm->get_ua_txn()->get_proxy_ssn()) : nullptr); } TSReturnCode @@ -3874,7 +3872,7 @@ TSHttpTxnClientReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *hptr = &(sm->t_state.hdr_info.client_request); if (hptr->valid()) { @@ -3897,16 +3895,16 @@ TSHttpTxnPristineUrlGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *url_loc) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)url_loc) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *hptr = &(sm->t_state.hdr_info.client_request); if (hptr->valid()) { *(reinterpret_cast(bufp)) = hptr; - *url_loc = (TSMLoc)sm->t_state.unmapped_url.m_url_impl; + *url_loc = reinterpret_cast(sm->t_state.unmapped_url.m_url_impl); if (sdk_sanity_check_mbuffer(*bufp) == TS_SUCCESS) { if (*url_loc == nullptr) { - *url_loc = (TSMLoc)hptr->m_http->u.req.m_url_impl; + *url_loc = reinterpret_cast(hptr->m_http->u.req.m_url_impl); } if (*url_loc) { return TS_SUCCESS; @@ -3921,7 +3919,7 @@ TSHttpTxnServerSsnTransactionCount(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); // Any value greater than zero indicates connection reuse. return sm->server_transact_count; } @@ -3983,7 +3981,7 @@ TSHttpTxnClientRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *hptr = &(sm->t_state.hdr_info.client_response); if (hptr->valid()) { @@ -4003,7 +4001,7 @@ TSHttpTxnServerReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *hptr = &(sm->t_state.hdr_info.server_request); if (hptr->valid()) { @@ -4023,7 +4021,7 @@ TSHttpTxnServerRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *hptr = &(sm->t_state.hdr_info.server_response); if (hptr->valid()) { @@ -4043,7 +4041,7 @@ TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPInfo *cached_obj = sm->t_state.cache_info.object_read; // The following check is need to prevent the HttpSM handle copy from going bad @@ -4063,7 +4061,7 @@ TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) HdrHeapSDKHandle **handle = &(sm->t_state.cache_req_hdr_heap_handle); if (*handle == nullptr) { - *handle = (HdrHeapSDKHandle *)sm->t_state.arena.alloc(sizeof(HdrHeapSDKHandle)); + *handle = static_cast(sm->t_state.arena.alloc(sizeof(HdrHeapSDKHandle))); (*handle)->m_heap = cached_hdr->m_heap; } @@ -4081,7 +4079,7 @@ TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPInfo *cached_obj = sm->t_state.cache_info.object_read; // The following check is need to prevent the HttpSM handle copy from going bad @@ -4101,7 +4099,7 @@ TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) HdrHeapSDKHandle **handle = &(sm->t_state.cache_resp_hdr_heap_handle); if (*handle == nullptr) { - *handle = (HdrHeapSDKHandle *)sm->t_state.arena.alloc(sizeof(HdrHeapSDKHandle)); + *handle = static_cast(sm->t_state.arena.alloc(sizeof(HdrHeapSDKHandle))); } // Always reset the m_heap to make sure the heap is not stale (*handle)->m_heap = cached_hdr->m_heap; @@ -4120,7 +4118,7 @@ TSHttpTxnCachedRespModifiableGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HttpTransact::State *s = &(sm->t_state); HTTPHdr *c_resp = nullptr; HTTPInfo *cached_obj = sm->t_state.cache_info.object_read; @@ -4155,7 +4153,7 @@ TSHttpTxnCacheLookupStatusGet(TSHttpTxn txnp, int *lookup_status) sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)lookup_status) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); switch (sm->t_state.cache_lookup_result) { case HttpTransact::CACHE_LOOKUP_MISS: @@ -4185,7 +4183,7 @@ TSHttpTxnCacheLookupCountGet(TSHttpTxn txnp, int *lookup_count) sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)lookup_count) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); *lookup_count = sm->t_state.cache_info.lookup_count; return TS_SUCCESS; } @@ -4199,7 +4197,7 @@ TSHttpTxnCacheLookupStatusSet(TSHttpTxn txnp, int cachelookup) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HttpTransact::CacheLookupResult_t *sm_status = &(sm->t_state.cache_lookup_result); // converting from a miss to a hit is not allowed @@ -4296,7 +4294,7 @@ TSHttpTxnIsWebsocket(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->t_state.is_websocket; } @@ -4325,11 +4323,11 @@ TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); URL u, *l_url; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); if (!u.valid()) { return TS_ERROR; } @@ -4350,11 +4348,11 @@ TSHttpTxnCacheLookupUrlSet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); URL u, *l_url; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); if (!u.valid()) { return TS_ERROR; } @@ -4384,7 +4382,7 @@ TSHttpTxnActiveTimeoutSet(TSHttpTxn txnp, int timeout) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); s->api_txn_active_timeout_value = timeout; } @@ -4397,7 +4395,7 @@ TSHttpTxnConnectTimeoutSet(TSHttpTxn txnp, int timeout) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); s->api_txn_connect_timeout_value = timeout; } @@ -4410,7 +4408,7 @@ TSHttpTxnDNSTimeoutSet(TSHttpTxn txnp, int timeout) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); s->api_txn_dns_timeout_value = timeout; } @@ -4424,7 +4422,7 @@ TSHttpTxnNoActivityTimeoutSet(TSHttpTxn txnp, int timeout) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); s->api_txn_no_activity_timeout_value = timeout; } @@ -4433,7 +4431,7 @@ TSHttpTxnServerRespNoStoreSet(TSHttpTxn txnp, int flag) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); s->api_server_response_no_store = (flag != 0); return TS_SUCCESS; @@ -4444,7 +4442,7 @@ TSHttpTxnServerRespNoStoreGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); return s->api_server_response_no_store; } @@ -4453,7 +4451,7 @@ TSHttpTxnServerRespIgnore(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); HTTPInfo *cached_obj = s->cache_info.object_read; HTTPHdr *cached_resp; @@ -4480,7 +4478,7 @@ TSHttpTxnShutDown(TSHttpTxn txnp, TSEvent event) return TS_ERROR; } - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); s->api_http_sm_shutdown = true; return TS_SUCCESS; @@ -4493,7 +4491,7 @@ TSHttpTxnAborted(TSHttpTxn txnp, bool *client_abort) sdk_assert(client_abort != nullptr); *client_abort = false; - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); switch (sm->t_state.squid_codes.log_code) { case SQUID_LOG_ERR_CLIENT_ABORT: case SQUID_LOG_ERR_CLIENT_READ_ERROR: @@ -4518,7 +4516,7 @@ TSHttpTxnReqCacheableSet(TSHttpTxn txnp, int flag) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); sm->t_state.api_req_cacheable = (flag != 0); } @@ -4527,7 +4525,7 @@ TSHttpTxnRespCacheableSet(TSHttpTxn txnp, int flag) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); sm->t_state.api_resp_cacheable = (flag != 0); } @@ -4536,7 +4534,7 @@ TSHttpTxnClientReqIsServerStyle(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return (sm->t_state.hdr_info.client_req_is_server_style ? 1 : 0); } @@ -4545,7 +4543,7 @@ TSHttpTxnUpdateCachedObject(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HttpTransact::State *s = &(sm->t_state); HTTPInfo *cached_obj_store = &(sm->t_state.cache_info.object_store); HTTPHdr *client_request = &(sm->t_state.hdr_info.client_request); @@ -4571,7 +4569,7 @@ TSHttpTxnTransformRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *hptr = &(sm->t_state.hdr_info.transform_response); if (hptr->valid()) { @@ -4679,7 +4677,7 @@ TSReturnCode TSHttpTxnOutgoingAddrSet(TSHttpTxn txnp, const struct sockaddr *addr) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); sm->get_ua_txn()->upstream_outbound_options.outbound_port = ats_ip_port_host_order(addr); sm->get_ua_txn()->set_outbound_ip(swoc::IPAddr(addr)); @@ -4754,7 +4752,7 @@ TSReturnCode TSHttpTxnClientPacketMarkSet(TSHttpTxn txnp, int mark) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); if (nullptr == sm->get_ua_txn()) { return TS_ERROR; } @@ -4764,7 +4762,7 @@ TSHttpTxnClientPacketMarkSet(TSHttpTxn txnp, int mark) return TS_ERROR; } - vc->options.packet_mark = (uint32_t)mark; + vc->options.packet_mark = static_cast(mark); vc->apply_options(); return TS_SUCCESS; } @@ -4773,14 +4771,14 @@ TSReturnCode TSHttpTxnServerPacketMarkSet(TSHttpTxn txnp, int mark) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); // change the mark on an active server session ProxyTransaction *ssn = sm->get_server_txn(); if (nullptr != ssn) { NetVConnection *vc = ssn->get_netvc(); if (vc != nullptr) { - vc->options.packet_mark = (uint32_t)mark; + vc->options.packet_mark = static_cast(mark); vc->apply_options(); } } @@ -4794,7 +4792,7 @@ TSReturnCode TSHttpTxnClientPacketDscpSet(TSHttpTxn txnp, int dscp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); if (nullptr == sm->get_ua_txn()) { return TS_ERROR; } @@ -4804,7 +4802,7 @@ TSHttpTxnClientPacketDscpSet(TSHttpTxn txnp, int dscp) return TS_ERROR; } - vc->options.packet_tos = (uint32_t)dscp << 2; + vc->options.packet_tos = static_cast(dscp) << 2; vc->apply_options(); return TS_SUCCESS; } @@ -4813,14 +4811,14 @@ TSReturnCode TSHttpTxnServerPacketDscpSet(TSHttpTxn txnp, int dscp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); // change the tos on an active server session ProxyTransaction *ssn = sm->get_server_txn(); if (nullptr != ssn) { NetVConnection *vc = ssn->get_netvc(); if (vc != nullptr) { - vc->options.packet_tos = (uint32_t)dscp << 2; + vc->options.packet_tos = static_cast(dscp) << 2; vc->apply_options(); } } @@ -4836,7 +4834,7 @@ TSHttpTxnErrorBodySet(TSHttpTxn txnp, char *buf, size_t buflength, char *mimetyp { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HttpTransact::State *s = &(sm->t_state); // Cleanup anything already set. @@ -4855,7 +4853,7 @@ TSHttpTxnErrorBodyGet(TSHttpTxn txnp, size_t *buflength, char **mimetype) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HttpTransact::State *s = &(sm->t_state); if (buflength) { @@ -4874,7 +4872,7 @@ TSHttpTxnServerRequestBodySet(TSHttpTxn txnp, char *buf, int64_t buflength) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HttpTransact::State *s = &(sm->t_state); // Cleanup anything already set. @@ -4897,7 +4895,7 @@ TSHttpTxnParentProxyGet(TSHttpTxn txnp, const char **hostname, int *port) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); *hostname = sm->t_state.api_info.parent_proxy_name; *port = sm->t_state.api_info.parent_proxy_port; @@ -4912,7 +4910,7 @@ TSHttpTxnParentProxySet(TSHttpTxn txnp, const char *hostname, int port) sdk_assert(sdk_sanity_check_null_ptr((void *)hostname) == TS_SUCCESS); sdk_assert(port > 0); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); sm->t_state.api_info.parent_proxy_name = sm->t_state.arena.str_store(hostname, strlen(hostname)); sm->t_state.api_info.parent_proxy_port = port; @@ -4925,11 +4923,11 @@ TSHttpTxnParentSelectionUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); URL u, *l_url; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); if (!u.valid()) { return TS_ERROR; } @@ -4950,11 +4948,11 @@ TSHttpTxnParentSelectionUrlSet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj) sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); URL u, *l_url; - u.m_heap = ((HdrHeapSDKHandle *)bufp)->m_heap; - u.m_url_impl = (URLImpl *)obj; + u.m_heap = (reinterpret_cast(bufp))->m_heap; + u.m_url_impl = reinterpret_cast(obj); if (!u.valid()) { return TS_ERROR; } @@ -4983,7 +4981,7 @@ TSHttpTxnUntransformedRespCache(TSHttpTxn txnp, int on) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); sm->t_state.api_info.cache_untransformed = (on ? true : false); } @@ -4992,7 +4990,7 @@ TSHttpTxnTransformedRespCache(TSHttpTxn txnp, int on) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); sm->t_state.api_info.cache_transformed = (on ? true : false); } @@ -5007,7 +5005,7 @@ class TSHttpSMCallback : public Continuation int event_handler(int, void *) { - m_sm->state_api_callback((int)m_event, nullptr); + m_sm->state_api_callback(static_cast(m_event), nullptr); delete this; return 0; } @@ -5023,7 +5021,7 @@ TSHttpTxnReenable(TSHttpTxn txnp, TSEvent event) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); EThread *eth = this_ethread(); // TS-2271: If this function is being executed on a thread which was not @@ -5036,7 +5034,7 @@ TSHttpTxnReenable(TSHttpTxn txnp, TSEvent event) MUTEX_TRY_LOCK(trylock, sm->mutex, eth); if (trylock.is_locked()) { ink_assert(eth->is_event_type(ET_NET)); - sm->state_api_callback((int)event, nullptr); + sm->state_api_callback(static_cast(event), nullptr); return; } } @@ -5177,7 +5175,7 @@ TSHttpTxnCntlSet(TSHttpTxn txnp, TSHttpCntlType cntl, bool data) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); switch (cntl) { case TS_HTTP_CNTL_LOGGING_MODE: @@ -5221,7 +5219,7 @@ TSHttpTxnCntlGet(TSHttpTxn txnp, TSHttpCntlType ctrl) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); switch (ctrl) { case TS_HTTP_CNTL_LOGGING_MODE: @@ -5267,22 +5265,22 @@ TSHttpTxnServerStateGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpTransact::State *s = &(((HttpSM *)txnp)->t_state); - return (TSServerState)s->current.state; + HttpTransact::State *s = &((reinterpret_cast(txnp))->t_state); + return static_cast(s->current.state); } void TSHttpTxnDebugSet(TSHttpTxn txnp, int on) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - ((HttpSM *)txnp)->debug_on = on; + (reinterpret_cast(txnp))->debug_on = on; } int TSHttpTxnDebugGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - return ((HttpSM *)txnp)->debug_on; + return (reinterpret_cast(txnp))->debug_on; } void @@ -5306,7 +5304,7 @@ TSHttpTxnClientReqHdrBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->client_request_hdr_bytes; } @@ -5315,7 +5313,7 @@ TSHttpTxnClientReqBodyBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->client_request_body_bytes; } @@ -5324,7 +5322,7 @@ TSHttpTxnServerReqHdrBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->server_request_hdr_bytes; } @@ -5333,7 +5331,7 @@ TSHttpTxnServerReqBodyBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->server_request_body_bytes; } @@ -5342,7 +5340,7 @@ TSHttpTxnServerRespHdrBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->server_response_hdr_bytes; } @@ -5351,7 +5349,7 @@ TSHttpTxnServerRespBodyBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->server_response_body_bytes; } @@ -5360,7 +5358,7 @@ TSHttpTxnClientRespHdrBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->client_response_hdr_bytes; } @@ -5369,7 +5367,7 @@ TSHttpTxnClientRespBodyBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->client_response_body_bytes; } @@ -5414,7 +5412,7 @@ TSHttpTxnPushedRespHdrBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->pushed_response_hdr_bytes; } @@ -5423,7 +5421,7 @@ TSHttpTxnPushedRespBodyBytesGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->pushed_response_body_bytes; } @@ -5434,7 +5432,7 @@ TSHttpTxnMilestoneGet(TSHttpTxn txnp, TSMilestonesType milestone, ink_hrtime *ti { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr(time) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); TSReturnCode ret = TS_SUCCESS; if ((milestone < TS_MILESTONE_UA_BEGIN) || (milestone >= TS_MILESTONE_LAST_ENTRY)) { @@ -5452,7 +5450,7 @@ TSHttpTxnCachedRespTimeGet(TSHttpTxn txnp, time_t *resp_time) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPInfo *cached_obj = sm->t_state.cache_info.object_read; if (cached_obj == nullptr || !cached_obj->valid()) { @@ -5506,7 +5504,7 @@ TSHttpAltInfoClientReqGet(TSHttpAltInfo infop, TSMBuffer *bufp, TSMLoc *obj) { sdk_assert(sdk_sanity_check_alt_info(infop) == TS_SUCCESS); - HttpAltInfo *info = (HttpAltInfo *)infop; + HttpAltInfo *info = reinterpret_cast(infop); *(reinterpret_cast(bufp)) = &info->m_client_req; *obj = reinterpret_cast(info->m_client_req.m_http); @@ -5519,7 +5517,7 @@ TSHttpAltInfoCachedReqGet(TSHttpAltInfo infop, TSMBuffer *bufp, TSMLoc *obj) { sdk_assert(sdk_sanity_check_alt_info(infop) == TS_SUCCESS); - HttpAltInfo *info = (HttpAltInfo *)infop; + HttpAltInfo *info = reinterpret_cast(infop); *(reinterpret_cast(bufp)) = &info->m_cached_req; *obj = reinterpret_cast(info->m_cached_req.m_http); @@ -5532,7 +5530,7 @@ TSHttpAltInfoCachedRespGet(TSHttpAltInfo infop, TSMBuffer *bufp, TSMLoc *obj) { sdk_assert(sdk_sanity_check_alt_info(infop) == TS_SUCCESS); - HttpAltInfo *info = (HttpAltInfo *)infop; + HttpAltInfo *info = reinterpret_cast(infop); *(reinterpret_cast(bufp)) = &info->m_cached_resp; *obj = reinterpret_cast(info->m_cached_resp.m_http); @@ -5545,7 +5543,7 @@ TSHttpAltInfoQualitySet(TSHttpAltInfo infop, float quality) { sdk_assert(sdk_sanity_check_alt_info(infop) == TS_SUCCESS); - HttpAltInfo *info = (HttpAltInfo *)infop; + HttpAltInfo *info = reinterpret_cast(infop); info->m_qvalue = quality; } @@ -5649,16 +5647,16 @@ TSActionCancel(TSAction actionp) } /* This is a hack. Should be handled in ink_types */ - if ((uintptr_t)actionp & 0x1) { - thisaction = (Action *)((uintptr_t)actionp - 1); + if (reinterpret_cast(actionp) & 0x1) { + thisaction = reinterpret_cast(reinterpret_cast(actionp) - 1); if (thisaction) { - i = (INKContInternal *)thisaction->continuation; + i = static_cast(thisaction->continuation); i->handle_event_count(EVENT_IMMEDIATE); } else { // The action pointer for an INKContInternal was effectively null, just go away return; } } else { - thisaction = (Action *)actionp; + thisaction = reinterpret_cast(actionp); } thisaction->cancel(); @@ -5668,7 +5666,7 @@ TSActionCancel(TSAction actionp) int TSActionDone(TSAction actionp) { - return ((Action *)actionp == ACTION_RESULT_DONE) ? 1 : 0; + return (reinterpret_cast(actionp) == ACTION_RESULT_DONE) ? 1 : 0; } /* Connections */ @@ -5677,7 +5675,7 @@ TSVConn TSVConnCreate(TSEventFunc event_funcp, TSMutex mutexp) { if (mutexp == nullptr) { - mutexp = (TSMutex)new_ProxyMutex(); + mutexp = reinterpret_cast(new_ProxyMutex()); } // TODO: probably don't need this if memory allocations fails properly @@ -5718,7 +5716,7 @@ TSVConnFdCreate(int fd) return nullptr; } - vc = (UnixNetVConnection *)netProcessor.allocate_vc(t); + vc = static_cast(netProcessor.allocate_vc(t)); if (vc == nullptr) { return nullptr; } @@ -5733,7 +5731,7 @@ TSVConnFdCreate(int fd) vc->submit_time = ink_get_hrtime(); vc->mutex = new_ProxyMutex(); vc->set_is_transparent(false); - vc->set_context(NET_VCONNECTION_OUT); + vc->set_context(NetVConnectionContext_t::NET_VCONNECTION_OUT); // We should take the nh's lock and vc's lock before we get into the connectUp SCOPED_MUTEX_LOCK(lock, get_NetHandler(t)->mutex, t); @@ -5751,7 +5749,7 @@ TSVConnReadVIOGet(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); TSVIO data; if (vc->get_data(TS_API_DATA_READ_VIO, &data)) { @@ -5766,7 +5764,7 @@ TSVConnWriteVIOGet(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); TSVIO data; if (vc->get_data(TS_API_DATA_WRITE_VIO, &data)) { @@ -5781,7 +5779,7 @@ TSVConnClosedGet(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); int data = 0; bool f = vc->get_data(TS_API_DATA_CLOSED, &data); ink_assert(f); // This can fail in some cases, we need to track those down. @@ -5797,9 +5795,10 @@ TSVConnRead(TSVConn connp, TSCont contp, TSIOBuffer bufp, int64_t nbytes) sdk_assert(nbytes >= 0); FORCE_PLUGIN_SCOPED_MUTEX(contp); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); - return reinterpret_cast(vc->do_io_read((INKContInternal *)contp, nbytes, (MIOBuffer *)bufp)); + return reinterpret_cast( + vc->do_io_read(reinterpret_cast(contp), nbytes, reinterpret_cast(bufp))); } TSVIO @@ -5811,9 +5810,10 @@ TSVConnWrite(TSVConn connp, TSCont contp, TSIOBufferReader readerp, int64_t nbyt sdk_assert(nbytes >= 0); FORCE_PLUGIN_SCOPED_MUTEX(contp); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); - return reinterpret_cast(vc->do_io_write((INKContInternal *)contp, nbytes, (IOBufferReader *)readerp)); + return reinterpret_cast( + vc->do_io_write(reinterpret_cast(contp), nbytes, reinterpret_cast(readerp))); } void @@ -5821,7 +5821,7 @@ TSVConnClose(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); vc->do_io_close(); } @@ -5830,7 +5830,7 @@ TSVConnAbort(TSVConn connp, int error) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); vc->do_io_close(error); } @@ -5839,7 +5839,7 @@ TSVConnShutdown(TSVConn connp, int read, int write) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); if (read && write) { vc->do_io_shutdown(IO_SHUTDOWN_READWRITE); @@ -5855,7 +5855,7 @@ TSVConnCacheObjectSizeGet(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - CacheVC *vc = (CacheVC *)connp; + CacheVC *vc = reinterpret_cast(connp); return vc->get_object_size(); } @@ -5864,9 +5864,9 @@ TSVConnCacheHttpInfoSet(TSVConn connp, TSCacheHttpInfo infop) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - CacheVC *vc = (CacheVC *)connp; + CacheVC *vc = reinterpret_cast(connp); if (static_cast(vc->op_type) == CacheOpType::Scan) { - vc->set_http_info((CacheHTTPInfo *)infop); + vc->set_http_info(reinterpret_cast(infop)); } } @@ -5886,7 +5886,7 @@ TSTransformOutputVConnGet(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - VConnection *vc = (VConnection *)connp; + VConnection *vc = reinterpret_cast(connp); TSVConn data; vc->get_data(TS_API_DATA_OUTPUT_VC, &data); // This case can't fail. @@ -5896,7 +5896,7 @@ TSTransformOutputVConnGet(TSVConn connp) void TSHttpTxnServerIntercept(TSCont contp, TSHttpTxn txnp) { - HttpSM *http_sm = (HttpSM *)txnp; + HttpSM *http_sm = reinterpret_cast(txnp); sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS); @@ -5905,13 +5905,13 @@ TSHttpTxnServerIntercept(TSCont contp, TSHttpTxn txnp) TSIOBufferWaterMark buffer_water_mark = TSPluginVCIOBufferWaterMarkGet(txnp); http_sm->plugin_tunnel_type = HTTP_PLUGIN_AS_SERVER; - http_sm->plugin_tunnel = PluginVCCore::alloc((INKContInternal *)contp, buffer_index, buffer_water_mark); + http_sm->plugin_tunnel = PluginVCCore::alloc(reinterpret_cast(contp), buffer_index, buffer_water_mark); } void TSHttpTxnIntercept(TSCont contp, TSHttpTxn txnp) { - HttpSM *http_sm = (HttpSM *)txnp; + HttpSM *http_sm = reinterpret_cast(txnp); sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS); @@ -5920,7 +5920,7 @@ TSHttpTxnIntercept(TSCont contp, TSHttpTxn txnp) TSIOBufferWaterMark buffer_water_mark = TSPluginVCIOBufferWaterMarkGet(txnp); http_sm->plugin_tunnel_type = HTTP_PLUGIN_AS_INTERCEPT; - http_sm->plugin_tunnel = PluginVCCore::alloc((INKContInternal *)contp, buffer_index, buffer_water_mark); + http_sm->plugin_tunnel = PluginVCCore::alloc(reinterpret_cast(contp), buffer_index, buffer_water_mark); } TSIOBufferSizeIndex @@ -5955,7 +5955,7 @@ TSVConnInactivityTimeoutSet(TSVConn connp, TSHRTime timeout) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - NetVConnection *vc = (NetVConnection *)connp; + NetVConnection *vc = reinterpret_cast(connp); vc->set_inactivity_timeout(timeout); } @@ -5964,7 +5964,7 @@ TSVConnInactivityTimeoutCancel(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - NetVConnection *vc = (NetVConnection *)connp; + NetVConnection *vc = reinterpret_cast(connp); vc->cancel_inactivity_timeout(); } @@ -5973,7 +5973,7 @@ TSVConnActiveTimeoutSet(TSVConn connp, TSHRTime timeout) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - NetVConnection *vc = (NetVConnection *)connp; + NetVConnection *vc = reinterpret_cast(connp); vc->set_active_timeout(timeout); } @@ -5982,7 +5982,7 @@ TSVConnActiveTimeoutCancel(TSVConn connp) { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); - NetVConnection *vc = (NetVConnection *)connp; + NetVConnection *vc = reinterpret_cast(connp); vc->cancel_active_timeout(); } @@ -6098,7 +6098,7 @@ TSNetAcceptNamedProtocol(TSCont contp, const char *protocol) sdk_assert(contp != nullptr); sdk_assert(sdk_sanity_check_continuation(contp) == TS_SUCCESS); - if (!ssl_register_protocol(protocol, (INKContInternal *)contp)) { + if (!ssl_register_protocol(protocol, reinterpret_cast(contp))) { return TS_ERROR; } @@ -6147,7 +6147,7 @@ TSHostLookup(TSCont contp, const char *hostname, size_t namelen) auto bouncer = INKContAllocator.alloc(); bouncer->init(&TSHostLookupTrampoline, reinterpret_cast(reinterpret_cast(contp)->mutex.get())); bouncer->mdata = contp; - return (TSAction)hostDBProcessor.getbyname_re(bouncer, hostname, namelen); + return reinterpret_cast(hostDBProcessor.getbyname_re(bouncer, hostname, namelen)); } sockaddr const * @@ -6171,10 +6171,10 @@ TSCacheRead(TSCont contp, TSCacheKey key) FORCE_PLUGIN_SCOPED_MUTEX(contp); - CacheInfo *info = (CacheInfo *)key; - Continuation *i = (INKContInternal *)contp; + CacheInfo *info = reinterpret_cast(key); + Continuation *i = reinterpret_cast(contp); - return (TSAction)cacheProcessor.open_read(i, &info->cache_key, info->frag_type, info->hostname, info->len); + return reinterpret_cast(cacheProcessor.open_read(i, &info->cache_key, info->frag_type, info->hostname, info->len)); } TSAction @@ -6185,11 +6185,11 @@ TSCacheWrite(TSCont contp, TSCacheKey key) FORCE_PLUGIN_SCOPED_MUTEX(contp); - CacheInfo *info = (CacheInfo *)key; - Continuation *i = (INKContInternal *)contp; + CacheInfo *info = reinterpret_cast(key); + Continuation *i = reinterpret_cast(contp); - return (TSAction)cacheProcessor.open_write(i, &info->cache_key, info->frag_type, 0, false, info->pin_in_cache, info->hostname, - info->len); + return reinterpret_cast( + cacheProcessor.open_write(i, &info->cache_key, info->frag_type, 0, false, info->pin_in_cache, info->hostname, info->len)); } TSAction @@ -6200,10 +6200,10 @@ TSCacheRemove(TSCont contp, TSCacheKey key) FORCE_PLUGIN_SCOPED_MUTEX(contp); - CacheInfo *info = (CacheInfo *)key; - INKContInternal *i = (INKContInternal *)contp; + CacheInfo *info = reinterpret_cast(key); + INKContInternal *i = reinterpret_cast(contp); - return (TSAction)cacheProcessor.remove(i, &info->cache_key, info->frag_type, info->hostname, info->len); + return reinterpret_cast(cacheProcessor.remove(i, &info->cache_key, info->frag_type, info->hostname, info->len)); } TSAction @@ -6214,11 +6214,11 @@ TSCacheScan(TSCont contp, TSCacheKey key, int KB_per_second) FORCE_PLUGIN_SCOPED_MUTEX(contp); - INKContInternal *i = (INKContInternal *)contp; + INKContInternal *i = reinterpret_cast(contp); if (key) { - CacheInfo *info = (CacheInfo *)key; - return (TSAction)cacheProcessor.scan(i, info->hostname, info->len, KB_per_second); + CacheInfo *info = reinterpret_cast(key); + return reinterpret_cast(cacheProcessor.scan(i, info->hostname, info->len, KB_per_second)); } return reinterpret_cast(cacheProcessor.scan(i, nullptr, 0, KB_per_second)); } @@ -6295,7 +6295,7 @@ TSTextLogObjectCreate(const char *filename, int mode, TSTextLogObject *new_objec } TextLogObject *tlog = new TextLogObject( - filename, Log::config->logfile_dir, (bool)mode & TS_LOG_MODE_ADD_TIMESTAMP, nullptr, Log::config->rolling_enabled, + filename, Log::config->logfile_dir, static_cast(mode) & TS_LOG_MODE_ADD_TIMESTAMP, nullptr, Log::config->rolling_enabled, Log::config->preproc_threads, Log::config->rolling_interval_sec, Log::config->rolling_offset_hr, Log::config->rolling_size_mb, Log::config->rolling_max_count, Log::config->rolling_min_count, Log::config->rolling_allow_empty); if (tlog == nullptr) { @@ -6311,7 +6311,7 @@ TSTextLogObjectCreate(const char *filename, int mode, TSTextLogObject *new_objec return TS_ERROR; } - *new_object = (TSTextLogObject)tlog; + *new_object = reinterpret_cast(tlog); return TS_SUCCESS; } @@ -6325,7 +6325,7 @@ TSTextLogObjectWrite(TSTextLogObject the_object, const char *format, ...) va_list ap; va_start(ap, format); - switch (((TextLogObject *)the_object)->va_write(format, ap)) { + switch ((reinterpret_cast(the_object))->va_write(format, ap)) { case (Log::LOG_OK): case (Log::SKIP): case (Log::AGGR): @@ -6349,7 +6349,7 @@ TSTextLogObjectFlush(TSTextLogObject the_object) { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); - ((TextLogObject *)the_object)->force_new_buffer(); + (reinterpret_cast(the_object))->force_new_buffer(); } TSReturnCode @@ -6357,7 +6357,7 @@ TSTextLogObjectDestroy(TSTextLogObject the_object) { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); - if (Log::config->log_object_manager.unmanage_api_object((TextLogObject *)the_object)) { + if (Log::config->log_object_manager.unmanage_api_object(reinterpret_cast(the_object))) { return TS_SUCCESS; } @@ -6369,7 +6369,7 @@ TSTextLogObjectHeaderSet(TSTextLogObject the_object, const char *header) { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); - ((TextLogObject *)the_object)->set_log_file_header(header); + (reinterpret_cast(the_object))->set_log_file_header(header); } TSReturnCode @@ -6378,7 +6378,7 @@ TSTextLogObjectRollingEnabledSet(TSTextLogObject the_object, int rolling_enabled sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); if (LogRollingEnabledIsValid(rolling_enabled)) { - ((TextLogObject *)the_object)->set_rolling_enabled((Log::RollingEnabledValues)rolling_enabled); + (reinterpret_cast(the_object))->set_rolling_enabled(static_cast(rolling_enabled)); return TS_SUCCESS; } @@ -6390,7 +6390,7 @@ TSTextLogObjectRollingIntervalSecSet(TSTextLogObject the_object, int rolling_int { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); - ((TextLogObject *)the_object)->set_rolling_interval_sec(rolling_interval_sec); + (reinterpret_cast(the_object))->set_rolling_interval_sec(rolling_interval_sec); } void @@ -6398,7 +6398,7 @@ TSTextLogObjectRollingOffsetHrSet(TSTextLogObject the_object, int rolling_offset { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); - ((TextLogObject *)the_object)->set_rolling_offset_hr(rolling_offset_hr); + (reinterpret_cast(the_object))->set_rolling_offset_hr(rolling_offset_hr); } void @@ -6406,7 +6406,7 @@ TSTextLogObjectRollingSizeMbSet(TSTextLogObject the_object, int rolling_size_mb) { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); - ((TextLogObject *)the_object)->set_rolling_size_mb(rolling_size_mb); + (reinterpret_cast(the_object))->set_rolling_size_mb(rolling_size_mb); } TSReturnCode @@ -6478,7 +6478,7 @@ TSCacheUrlSet(TSHttpTxn txnp, const char *url, int length) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); Dbg(dbg_ctl_cache_url, "[TSCacheUrlSet]"); if (sm->t_state.cache_info.lookup_url == nullptr) { @@ -6501,8 +6501,8 @@ void TSCacheHttpInfoKeySet(TSCacheHttpInfo infop, TSCacheKey keyp) { // TODO: Check input ? - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; - CryptoHash *key = (CryptoHash *)keyp; + CacheHTTPInfo *info = reinterpret_cast(infop); + CryptoHash *key = reinterpret_cast(keyp); info->object_key_set(*key); } @@ -6511,7 +6511,7 @@ void TSCacheHttpInfoSizeSet(TSCacheHttpInfo infop, int64_t size) { // TODO: Check input ? - CacheHTTPInfo *info = (CacheHTTPInfo *)infop; + CacheHTTPInfo *info = reinterpret_cast(infop); info->object_size_set(size); } @@ -6523,13 +6523,13 @@ TSHttpTxnRedirectUrlSet(TSHttpTxn txnp, const char *url, const int url_len) sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)url) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); ats_free(sm->redirect_url); sm->redirect_url = nullptr; sm->redirect_url_len = 0; - sm->redirect_url = (char *)url; + sm->redirect_url = const_cast(url); sm->redirect_url_len = url_len; sm->enable_redirection = true; sm->redirection_tries = 0; @@ -6546,7 +6546,7 @@ TSHttpTxnRedirectUrlGet(TSHttpTxn txnp, int *url_len_ptr) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); *url_len_ptr = sm->redirect_url_len; return sm->redirect_url; @@ -6557,7 +6557,7 @@ TSHttpTxnRedirectRetries(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); return sm->redirection_tries; } @@ -6576,7 +6576,7 @@ TSFetchPageRespGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *obj) sdk_assert(sdk_sanity_check_null_ptr((void *)bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)obj) == TS_SUCCESS); - HTTPHdr *hptr = (HTTPHdr *)txnp; + HTTPHdr *hptr = reinterpret_cast(txnp); if (hptr->valid()) { *(reinterpret_cast(bufp)) = hptr; @@ -6596,8 +6596,8 @@ TSFetchPages(TSFetchUrlParams_t *params) FetchSM *fetch_sm = FetchSMAllocator.alloc(); sockaddr *addr = ats_ip_sa_cast(&myparams->ip); - fetch_sm->init((Continuation *)myparams->contp, myparams->options, myparams->events, myparams->request, myparams->request_len, - addr); + fetch_sm->init(reinterpret_cast(myparams->contp), myparams->options, myparams->events, myparams->request, + myparams->request_len, addr); fetch_sm->httpConnect(); myparams = myparams->next; } @@ -6613,7 +6613,7 @@ TSFetchUrl(const char *headers, int request_len, sockaddr const *ip, TSCont cont FetchSM *fetch_sm = FetchSMAllocator.alloc(); - fetch_sm->init((Continuation *)contp, callback_options, events, headers, request_len, ip); + fetch_sm->init(reinterpret_cast(contp), callback_options, events, headers, request_len, ip); fetch_sm->httpConnect(); return reinterpret_cast(fetch_sm); @@ -6634,7 +6634,7 @@ TSFetchCreate(TSCont contp, const char *method, const char *url, const char *ver FetchSM *fetch_sm = FetchSMAllocator.alloc(); - fetch_sm->ext_init((Continuation *)contp, method, url, version, client_addr, flags); + fetch_sm->ext_init(reinterpret_cast(contp), method, url, version, client_addr, flags); return reinterpret_cast(fetch_sm); } @@ -6700,7 +6700,7 @@ TSFetchRespHdrMBufGet(TSFetchSM fetch_sm) { sdk_assert(sdk_sanity_check_fetch_sm(fetch_sm) == TS_SUCCESS); - return ((FetchSM *)fetch_sm)->resp_hdr_bufp(); + return (reinterpret_cast(fetch_sm))->resp_hdr_bufp(); } TSMLoc @@ -6708,7 +6708,7 @@ TSFetchRespHdrMLocGet(TSFetchSM fetch_sm) { sdk_assert(sdk_sanity_check_fetch_sm(fetch_sm) == TS_SUCCESS); - return ((FetchSM *)fetch_sm)->resp_hdr_mloc(); + return (reinterpret_cast(fetch_sm))->resp_hdr_mloc(); } int @@ -6874,7 +6874,7 @@ TSAIORead(int fd, off_t offset, char *buf, size_t buffSize, TSCont contp) { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); - Continuation *pCont = (Continuation *)contp; + Continuation *pCont = reinterpret_cast(contp); AIOCallback *pAIO = new_AIOCallback(); if (pAIO == nullptr) { @@ -6899,15 +6899,15 @@ TSAIORead(int fd, off_t offset, char *buf, size_t buffSize, TSCont contp) char * TSAIOBufGet(TSAIOCallback data) { - AIOCallback *pAIO = (AIOCallback *)data; - return (char *)pAIO->aiocb.aio_buf; + AIOCallback *pAIO = reinterpret_cast(data); + return static_cast(pAIO->aiocb.aio_buf); } int TSAIONBytesGet(TSAIOCallback data) { - AIOCallback *pAIO = (AIOCallback *)data; - return (int)pAIO->aio_result; + AIOCallback *pAIO = reinterpret_cast(data); + return static_cast(pAIO->aio_result); } TSReturnCode @@ -6915,7 +6915,7 @@ TSAIOWrite(int fd, off_t offset, char *buf, const size_t bufSize, TSCont contp) { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); - Continuation *pCont = (Continuation *)contp; + Continuation *pCont = reinterpret_cast(contp); AIOCallback *pAIO = new_AIOCallback(); // TODO: Might be able to remove this when allocations can never fail. @@ -6948,7 +6948,7 @@ TSAIOThreadNumSet(int thread_num) void TSRecordDump(int rec_type, TSRecordDumpCb callback, void *edata) { - RecDumpRecords((RecT)rec_type, (RecDumpEntryCb)callback, edata); + RecDumpRecords(static_cast(rec_type), reinterpret_cast(callback), edata); } /* ability to skip the remap phase of the State Machine @@ -6959,7 +6959,7 @@ TSSkipRemappingSet(TSHttpTxn txnp, int flag) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); sm->t_state.api_skip_all_remapping = (flag != 0); } @@ -7702,7 +7702,7 @@ TSHttpTxnPrivateSessionSet(TSHttpTxn txnp, int private_session) if (sdk_sanity_check_txn(txnp) != TS_SUCCESS) { return TS_ERROR; } - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); if (sm->set_server_session_private(private_session)) { return TS_SUCCESS; } @@ -7717,9 +7717,9 @@ TSMgmtStringCreate(TSRecordType rec_type, const char *name, const TSMgmtString d if (check_regex == nullptr && check_type != TS_RECORDCHECK_NULL) { return TS_ERROR; } - if (REC_ERR_OKAY != RecRegisterConfigString((enum RecT)rec_type, name, data_default, (enum RecUpdateT)update_type, - (enum RecCheckT)check_type, check_regex, REC_SOURCE_PLUGIN, - (enum RecAccessT)access_type)) { + if (REC_ERR_OKAY != RecRegisterConfigString(static_cast(rec_type), name, data_default, + static_cast(update_type), static_cast(check_type), + check_regex, REC_SOURCE_PLUGIN, static_cast(access_type))) { return TS_ERROR; } @@ -7733,9 +7733,9 @@ TSMgmtIntCreate(TSRecordType rec_type, const char *name, TSMgmtInt data_default, if (check_regex == nullptr && check_type != TS_RECORDCHECK_NULL) { return TS_ERROR; } - if (REC_ERR_OKAY != RecRegisterConfigInt((enum RecT)rec_type, name, (RecInt)data_default, (enum RecUpdateT)update_type, - (enum RecCheckT)check_type, check_regex, REC_SOURCE_PLUGIN, - (enum RecAccessT)access_type)) { + if (REC_ERR_OKAY != RecRegisterConfigInt(static_cast(rec_type), name, static_cast(data_default), + static_cast(update_type), static_cast(check_type), + check_regex, REC_SOURCE_PLUGIN, static_cast(access_type))) { return TS_ERROR; } @@ -7749,7 +7749,7 @@ TSHttpTxnCloseAfterResponse(TSHttpTxn txnp, int should_close) return TS_ERROR; } - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); if (should_close) { sm->t_state.client_info.keep_alive = HTTP_NO_KEEPALIVE; if (sm->get_ua_txn()) { @@ -7771,7 +7771,7 @@ TSPortDescriptorParse(const char *descriptor) HttpProxyPort *port = new HttpProxyPort(); if (descriptor && port->processOptions(descriptor)) { - return (TSPortDescriptor)port; + return reinterpret_cast(port); } delete port; @@ -7782,13 +7782,13 @@ TSReturnCode TSPortDescriptorAccept(TSPortDescriptor descp, TSCont contp) { Action *action = nullptr; - HttpProxyPort *port = (HttpProxyPort *)descp; + HttpProxyPort *port = reinterpret_cast(descp); NetProcessor::AcceptOptions net(make_net_accept_options(port, -1 /* nthreads */)); if (port->isSSL()) { - action = sslNetProcessor.main_accept((INKContInternal *)contp, port->m_fd, net); + action = sslNetProcessor.main_accept(reinterpret_cast(contp), port->m_fd, net); } else { - action = netProcessor.main_accept((INKContInternal *)contp, port->m_fd, net); + action = netProcessor.main_accept(reinterpret_cast(contp), port->m_fd, net); } return action ? TS_SUCCESS : TS_ERROR; @@ -7803,7 +7803,7 @@ TSPluginDescriptorAccept(TSCont contp) for (auto &port : proxy_ports) { if (port.isPlugin()) { NetProcessor::AcceptOptions net(make_net_accept_options(&port, -1 /* nthreads */)); - action = netProcessor.main_accept((INKContInternal *)contp, port.m_fd, net); + action = netProcessor.main_accept(reinterpret_cast(contp), port.m_fd, net); } } return action ? TS_SUCCESS : TS_ERROR; @@ -7813,7 +7813,7 @@ int TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *s = (HttpSM *)txnp; + HttpSM *s = reinterpret_cast(txnp); return (s->background_fill == BACKGROUND_FILL_STARTED); } @@ -7822,7 +7822,7 @@ int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *req, *resp; // We allow for either request or response to be empty (or both), in @@ -7848,7 +7848,7 @@ int TSHttpTxnGetMaxAge(TSHttpTxn txnp, TSMBuffer response) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); HTTPHdr *resp; if (response) { @@ -8024,7 +8024,7 @@ TSReturnCode TSSslSecretSet(const char *secret_name, int secret_name_length, const char *secret_data, int secret_data_len) { TSReturnCode retval = TS_SUCCESS; - std::string const secret_name_str{secret_name, unsigned(secret_name_length)}; + std::string const secret_name_str{secret_name, static_cast(secret_name_length)}; SSLConfigParams *load_params = SSLConfig::load_acquire(); SSLConfigParams *params = SSLConfig::acquire(); if (load_params != nullptr) { // Update the current data structure @@ -8466,14 +8466,14 @@ TSUuid TSUuidCreate() { ATSUuid *uuid = new ATSUuid(); - return (TSUuid)uuid; + return reinterpret_cast(uuid); } void TSUuidDestroy(TSUuid uuid) { sdk_assert(sdk_sanity_check_null_ptr((void *)uuid) == TS_SUCCESS); - delete (ATSUuid *)uuid; + delete reinterpret_cast(uuid); } TSReturnCode @@ -8481,8 +8481,8 @@ TSUuidCopy(TSUuid dest, const TSUuid src) { sdk_assert(sdk_sanity_check_null_ptr((void *)dest) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)src) == TS_SUCCESS); - ATSUuid *d = (ATSUuid *)dest; - ATSUuid *s = (ATSUuid *)src; + ATSUuid *d = reinterpret_cast(dest); + ATSUuid *s = reinterpret_cast(src); if (s->valid()) { *d = *s; @@ -8496,7 +8496,7 @@ TSReturnCode TSUuidInitialize(TSUuid uuid, TSUuidVersion v) { sdk_assert(sdk_sanity_check_null_ptr((void *)uuid) == TS_SUCCESS); - ATSUuid *u = (ATSUuid *)uuid; + ATSUuid *u = reinterpret_cast(uuid); u->initialize(v); return u->valid() ? TS_SUCCESS : TS_ERROR; @@ -8506,14 +8506,14 @@ TSUuid TSProcessUuidGet() { Machine *machine = Machine::instance(); - return (TSUuid)(&machine->uuid); + return reinterpret_cast(&machine->uuid); } const char * TSUuidStringGet(const TSUuid uuid) { sdk_assert(sdk_sanity_check_null_ptr((void *)uuid) == TS_SUCCESS); - ATSUuid *u = (ATSUuid *)(uuid); + ATSUuid *u = reinterpret_cast(uuid); if (u->valid()) { return u->getString(); @@ -8527,8 +8527,8 @@ TSClientRequestUuidGet(TSHttpTxn txnp, char *uuid_str) { sdk_assert(sdk_sanity_check_null_ptr((void *)uuid_str) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; - const char *machine = (char *)Machine::instance()->uuid.getString(); + HttpSM *sm = reinterpret_cast(txnp); + const char *machine = const_cast(Machine::instance()->uuid.getString()); int len; len = snprintf(uuid_str, TS_CRUUID_STRING_LEN + 1, "%s-%" PRId64 "", machine, sm->sm_id); @@ -8544,7 +8544,7 @@ TSUuidStringParse(TSUuid uuid, const char *str) { sdk_assert(sdk_sanity_check_null_ptr((void *)uuid) == TS_SUCCESS); sdk_assert(sdk_sanity_check_null_ptr((void *)str) == TS_SUCCESS); - ATSUuid *u = (ATSUuid *)uuid; + ATSUuid *u = reinterpret_cast(uuid); if (u->parseString(str)) { return TS_SUCCESS; @@ -8557,7 +8557,7 @@ TSUuidVersion TSUuidVersionGet(TSUuid uuid) { sdk_assert(sdk_sanity_check_null_ptr((void *)uuid) == TS_SUCCESS); - ATSUuid *u = (ATSUuid *)uuid; + ATSUuid *u = reinterpret_cast(uuid); return u->version(); } @@ -8567,9 +8567,9 @@ uint64_t TSHttpTxnIdGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); - return (uint64_t)sm->sm_id; + return static_cast(sm->sm_id); } // Returns unique client session identifier @@ -8815,8 +8815,8 @@ TSIOBufferReader TSHttpTxnPostBufferReaderGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; - return (TSIOBufferReader)sm->get_postbuf_clone_reader(); + HttpSM *sm = reinterpret_cast(txnp); + return reinterpret_cast(sm->get_postbuf_clone_reader()); } TSRPCProviderHandle @@ -8838,7 +8838,7 @@ TSRPCRegister(const char *provider_name, size_t provider_len, const char *yaml_v ::rpc::RPCRegistryInfo *info = new ::rpc::RPCRegistryInfo(); info->provider = {provider_name, provider_len}; - return (TSRPCProviderHandle)info; + return reinterpret_cast(info); } TSReturnCode @@ -8851,9 +8851,9 @@ TSRPCRegisterMethodHandler(const char *name, size_t name_len, TSRPCMethodCb call {name, name_len}, [callback](std::string_view const &id, const YAML::Node ¶ms) -> void { std::string msgId{id.data(), id.size()}; - callback(msgId.c_str(), (TSYaml)¶ms); + callback(msgId.c_str(), reinterpret_cast(const_cast(¶ms))); }, - (const ::rpc::RPCRegistryInfo *)info, *opt)) { + reinterpret_cast(info), *opt)) { return TS_ERROR; } return TS_SUCCESS; @@ -8866,8 +8866,9 @@ TSRPCRegisterNotificationHandler(const char *name, size_t name_len, TSRPCNotific sdk_assert(sdk_sanity_check_rpc_handler_options(opt) == TS_SUCCESS); if (!::rpc::add_notification_handler( - {name, name_len}, [callback](const YAML::Node ¶ms) -> void { callback((TSYaml)¶ms); }, - (const ::rpc::RPCRegistryInfo *)info, *opt)) { + {name, name_len}, + [callback](const YAML::Node ¶ms) -> void { callback(reinterpret_cast(const_cast(¶ms))); }, + reinterpret_cast(info), *opt)) { return TS_ERROR; } return TS_SUCCESS; @@ -8878,7 +8879,7 @@ TSRPCHandlerDone(TSYaml resp) { Dbg(dbg_ctl_rpc_api, ">> Handler seems to be done"); std::lock_guard lock(::rpc::g_rpcHandlingMutex); - auto data = *(YAML::Node *)resp; + auto data = *reinterpret_cast(resp); ::rpc::g_rpcHandlerResponseData = data; ::rpc::g_rpcHandlerProcessingCompleted = true; ::rpc::g_rpcHandlingCompletion.notify_one(); @@ -8932,7 +8933,7 @@ TSTxnType TSHttpTxnTypeGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *sm = (HttpSM *)txnp; + HttpSM *sm = reinterpret_cast(txnp); TSTxnType retval = TS_TXN_TYPE_UNKNOWN; if (sm != nullptr) { if (sm->t_state.transparent_passthrough) { From 416f6ed3412aabb9a1c882f3b53175dcc73ef128 Mon Sep 17 00:00:00 2001 From: Damian Meden Date: Mon, 27 Jan 2025 09:46:00 +0100 Subject: [PATCH 17/18] Coverity: Some fixes. (#11982) * Coverity: Fix for CID-1528633 and CID-1523681 * CID-1544434 - Unchecked return value * CID-1544425 Use of auto that causes a copy --- src/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc | 4 ++-- src/proxy/http/remap/unit-tests/test_PluginFactory.cc | 4 ++-- src/tscore/unit_tests/test_Ptr.cc | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc b/src/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc index aef2a1f36df..e26c8ec721e 100644 --- a/src/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc +++ b/src/proxy/http/remap/unit-tests/test_NextHopRoundRobin.cc @@ -248,10 +248,10 @@ SCENARIO("Testing NextHopRoundRobin class, using policy 'rr-ip'", "[NextHopRound sockaddr_in sa2 = {}; sa1.sin_port = 10000; sa1.sin_family = AF_INET; - inet_pton(AF_INET, "192.168.1.1", &(sa1.sin_addr)); + REQUIRE(inet_pton(AF_INET, "192.168.1.1", &(sa1.sin_addr)) == 1); sa2.sin_port = 10001; sa2.sin_family = AF_INET; - inet_pton(AF_INET, "192.168.1.2", &(sa2.sin_addr)); + REQUIRE(inet_pton(AF_INET, "192.168.1.2", &(sa2.sin_addr)) == 1); HttpSM sm; ParentResult *result = &sm.t_state.parent_result; TSHttpTxn txnp = reinterpret_cast(&sm); diff --git a/src/proxy/http/remap/unit-tests/test_PluginFactory.cc b/src/proxy/http/remap/unit-tests/test_PluginFactory.cc index 6997da4d348..ff78963e5ea 100644 --- a/src/proxy/http/remap/unit-tests/test_PluginFactory.cc +++ b/src/proxy/http/remap/unit-tests/test_PluginFactory.cc @@ -468,7 +468,7 @@ SCENARIO("multiple search dirs + multiple or no plugins installed", "[plugin][co std::string error; - for (auto searchDir : searchDirs) { + for (auto const &searchDir : searchDirs) { CHECK(fs::create_directories(searchDir, ec)); fs::copy(pluginBuildPath, searchDir, ec); } @@ -477,7 +477,7 @@ SCENARIO("multiple search dirs + multiple or no plugins installed", "[plugin][co /* Instantiate and initialize a plugin DSO instance. */ PluginFactoryUnitTest factory(tempComponent); factory.setRuntimeDir(runtimeRootDir); - for (auto searchDir : searchDirs) { + for (auto const &searchDir : searchDirs) { factory.addSearchDir(searchDir); } diff --git a/src/tscore/unit_tests/test_Ptr.cc b/src/tscore/unit_tests/test_Ptr.cc index cfa721df362..79ef8313f51 100644 --- a/src/tscore/unit_tests/test_Ptr.cc +++ b/src/tscore/unit_tests/test_Ptr.cc @@ -49,7 +49,7 @@ TEST_CASE("Ptr", "[libts][ptr]") REQUIRE(p1->refcount() == 3); p3 = nullptr; // clear ref drops ref count. REQUIRE(p1->refcount() == 2); - p2->refcount_dec(); + REQUIRE(p2->refcount_dec() == 1); delete p1.detach(); // If that doesn't work, the subsequent alive counts will be off. @@ -72,7 +72,7 @@ TEST_CASE("Ptr", "[libts][ptr]") Ptr pn2(pn1); REQUIRE(pn1->refcount() == 2); - Ptr pn3 = p1; + Ptr pn3 = std::move(p1); } // Everything goes out of scope, so the refcounts should drop to zero. From d543c8a30e4447a422bf688cb0299cf3074ece51 Mon Sep 17 00:00:00 2001 From: Masaori Koshiba Date: Tue, 28 Jan 2025 08:10:51 +0900 Subject: [PATCH 18/18] [compress] Make warning if compress plugin has cache and range-request config (#11986) --- plugins/compress/configuration.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/compress/configuration.cc b/plugins/compress/configuration.cc index 208ea79d8dd..82cb15d75de 100644 --- a/plugins/compress/configuration.cc +++ b/plugins/compress/configuration.cc @@ -405,6 +405,11 @@ Configuration::Parse(const char *path) // Update the defaults for the last host configuration too, if needed. current_host_configuration->update_defaults(); + // Check combination of configs + if (!current_host_configuration->cache() && current_host_configuration->range_request()) { + warning("Combination of 'cache false' and 'range-request true' might deliver corrupted content"); + } + if (state != kParseStart) { warning("the parser state indicates that data was expected when it reached the end of the file (%d)", state); }