This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new 7f86ef2a73 Ran clang-tidy over the experimental plugins (#10550) 7f86ef2a73 is described below commit 7f86ef2a734775d4dc76c64d4b6048d0b1fea348 Author: Bryan Call <bc...@apache.org> AuthorDate: Mon Oct 9 15:01:12 2023 -0700 Ran clang-tidy over the experimental plugins (#10550) --- .../cache_range_requests/cache_range_requests.cc | 2 +- .../cache_key_genid/cache_key_genid.cc | 8 +- plugins/experimental/cookie_remap/hash.cc | 6 +- plugins/experimental/fastcgi/src/Profiler.h | 6 +- plugins/experimental/fastcgi/src/ats_fastcgi.cc | 7 +- .../experimental/fastcgi/src/ats_fcgi_client.cc | 55 ++++---- plugins/experimental/fastcgi/src/ats_fcgi_client.h | 6 +- plugins/experimental/fastcgi/src/fcgi_config.cc | 2 +- plugins/experimental/fastcgi/src/fcgi_config.h | 8 +- plugins/experimental/fastcgi/src/fcgi_protocol.h | 14 +-- plugins/experimental/fastcgi/src/server.cc | 10 +- .../experimental/fastcgi/src/server_connection.cc | 5 +- plugins/experimental/fq_pacing/fq_pacing.cc | 30 ++--- plugins/experimental/http_stats/http_stats.cc | 8 +- plugins/experimental/maxmind_acl/mmdb.h | 6 +- plugins/experimental/memcache/protocol_binary.h | 138 ++++++++++----------- plugins/experimental/memcache/tsmemcache.cc | 2 +- plugins/experimental/memcache/tsmemcache.h | 10 +- plugins/experimental/money_trace/money_trace.cc | 2 +- plugins/experimental/mp4/mp4_meta.h | 87 ++++++------- plugins/experimental/otel_tracer/otel_tracer.cc | 8 +- plugins/experimental/otel_tracer/tracer_common.h | 4 +- plugins/experimental/rate_limit/iprep_simu.cc | 19 +-- plugins/experimental/rate_limit/limiter.h | 2 +- plugins/experimental/rate_limit/txn_limiter.h | 2 +- .../experimental/ssl_session_reuse/src/Config.h | 6 +- .../experimental/ssl_session_reuse/src/message.h | 10 +- .../ssl_session_reuse/src/redis_endpoint.cc | 2 +- .../ssl_session_reuse/src/redis_endpoint.h | 8 +- plugins/experimental/system_stats/system_stats.cc | 20 +-- plugins/experimental/tls_bridge/tls_bridge.cc | 12 +- plugins/experimental/uri_signing/config.cc | 6 +- plugins/experimental/uri_signing/cookie.cc | 2 +- plugins/experimental/uri_signing/jwt.cc | 18 +-- plugins/experimental/uri_signing/match.cc | 12 +- plugins/experimental/uri_signing/normalize.cc | 10 +- plugins/experimental/uri_signing/parse.cc | 6 +- plugins/experimental/uri_signing/timing.h | 3 +- .../uri_signing/unit_tests/uri_signing_test.cc | 14 +-- plugins/experimental/uri_signing/uri_signing.cc | 24 ++-- plugins/experimental/url_sig/url_sig.cc | 39 +++--- plugins/experimental/wasm/ats_context.cc | 4 +- plugins/experimental/wasm/ats_context.h | 4 +- plugins/experimental/wasm/wasm_main.cc | 4 +- proxy/Plugin.h | 2 +- 45 files changed, 337 insertions(+), 316 deletions(-) diff --git a/plugins/cache_range_requests/cache_range_requests.cc b/plugins/cache_range_requests/cache_range_requests.cc index a5e2883ab3..aaf3ceed2f 100644 --- a/plugins/cache_range_requests/cache_range_requests.cc +++ b/plugins/cache_range_requests/cache_range_requests.cc @@ -45,7 +45,7 @@ namespace { DbgCtl dbg_ctl{PLUGIN_NAME}; -using parent_select_mode_t = enum parent_select_mode { +enum parent_select_mode_t { PS_DEFAULT, // Default ATS parent selection mode PS_CACHEKEY_URL, // Set parent selection url to cache_key url }; diff --git a/plugins/experimental/cache_key_genid/cache_key_genid.cc b/plugins/experimental/cache_key_genid/cache_key_genid.cc index 8191168345..e4083190bc 100644 --- a/plugins/experimental/cache_key_genid/cache_key_genid.cc +++ b/plugins/experimental/cache_key_genid/cache_key_genid.cc @@ -18,8 +18,8 @@ */ #include <ts/ts.h> -#include <stdio.h> -#include <string.h> +#include <cstdio> +#include <cstring> #include <kclangc.h> #define PLUGIN_NAME "cache-key-genid" @@ -95,7 +95,7 @@ get_genid(char *host) static int handle_hook(TSCont *contp, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn)edata; + TSHttpTxn txnp = static_cast<TSHttpTxn>(edata); char *url = nullptr, *host = nullptr; int url_length; int gen_id; @@ -172,5 +172,5 @@ TSPluginInit(int argc, const char *argv[]) return; } - TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate((TSEventFunc)handle_hook, nullptr)); + TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, TSContCreate(reinterpret_cast<TSEventFunc>(handle_hook), nullptr)); } diff --git a/plugins/experimental/cookie_remap/hash.cc b/plugins/experimental/cookie_remap/hash.cc index a1bdbb5ba4..0db14fcf6b 100644 --- a/plugins/experimental/cookie_remap/hash.cc +++ b/plugins/experimental/cookie_remap/hash.cc @@ -17,8 +17,8 @@ */ #include "hash.h" -#include <string.h> -#include <ctype.h> +#include <cstring> +#include <cctype> //////////////////////////////////////////////////////////////////////////////// // Implementation of the Fowler–Noll–Vo hash function // @@ -102,7 +102,7 @@ hash_fnv32_buf(const char *buf, size_t len) for (val = FNV1_32_INIT; len > 0; --len) { val *= FNV_32_PRIME; - val ^= (uint32_t)(*buf); + val ^= static_cast<uint32_t>(*buf); ++buf; } diff --git a/plugins/experimental/fastcgi/src/Profiler.h b/plugins/experimental/fastcgi/src/Profiler.h index f898e11875..a8f23155da 100644 --- a/plugins/experimental/fastcgi/src/Profiler.h +++ b/plugins/experimental/fastcgi/src/Profiler.h @@ -140,8 +140,9 @@ public: SubmitProfile(const Profile &profile) { // Ignore if not enabled - if (!this->record_enabled_) + if (!this->record_enabled_) { return; + } std::unique_lock<std::mutex> lock(this->profiles_mutex_); this->profiles_.push_back(profile); } @@ -176,8 +177,9 @@ public: set_record_enabled(bool enabled) { this->record_enabled_ = enabled; - if (!this->record_enabled_) + if (!this->record_enabled_) { this->Clear(); + } } private: diff --git a/plugins/experimental/fastcgi/src/ats_fastcgi.cc b/plugins/experimental/fastcgi/src/ats_fastcgi.cc index 41a2eddfc6..a4050426fc 100644 --- a/plugins/experimental/fastcgi/src/ats_fastcgi.cc +++ b/plugins/experimental/fastcgi/src/ats_fastcgi.cc @@ -24,7 +24,7 @@ #include <atscppapi/PluginInit.h> #include <iostream> #include <netinet/in.h> -#include <string.h> +#include <cstring> #include "ts/ink_defs.h" #include "ts/ts.h" @@ -110,8 +110,9 @@ public: if (threadKey == 0) { // setup thread local storage - while (!gServer->setupThreadLocalStorage()) - ; + while (!gServer->setupThreadLocalStorage()) { + // do nothing + } } gServer->connect(intercept); diff --git a/plugins/experimental/fastcgi/src/ats_fcgi_client.cc b/plugins/experimental/fastcgi/src/ats_fcgi_client.cc index 5b23666e5d..23b02e7b0a 100644 --- a/plugins/experimental/fastcgi/src/ats_fcgi_client.cc +++ b/plugins/experimental/fastcgi/src/ats_fcgi_client.cc @@ -96,9 +96,9 @@ FCGIClientRequest::FCGIClientRequest(int request_id, TSHttpTxn txn) string cl = state_->requestHeaders["CONTENT_LENGTH"]; stringstream strToInt(cl); strToInt >> contentLength; - state_->buff = (unsigned char *)TSmalloc(BUF_SIZE + contentLength); + state_->buff = static_cast<unsigned char *>(TSmalloc(BUF_SIZE + contentLength)); } else { - state_->buff = (unsigned char *)TSmalloc(BUF_SIZE); + state_->buff = static_cast<unsigned char *>(TSmalloc(BUF_SIZE)); } state_->pBuffInc = state_->buff; @@ -108,8 +108,9 @@ FCGIClientRequest::FCGIClientRequest(int request_id, TSHttpTxn txn) // holding response records received from fcgi server FCGIClientRequest::~FCGIClientRequest() { - if (_headerRecord) + if (_headerRecord) { delete _headerRecord; + } delete state_; } @@ -117,10 +118,11 @@ FCGIClientRequest::~FCGIClientRequest() bool endsWith(const std::string &mainStr, const std::string &toMatch) { - if (mainStr.size() >= toMatch.size() && mainStr.compare(mainStr.size() - toMatch.size(), toMatch.size(), toMatch) == 0) + if (mainStr.size() >= toMatch.size() && mainStr.compare(mainStr.size() - toMatch.size(), toMatch.size(), toMatch) == 0) { return true; - else + } else { return false; + } } map<string, string> @@ -204,7 +206,7 @@ FCGIClientRequest::emptyParam() FCGI_Header * FCGIClientRequest::createHeader(uchar type) { - FCGI_Header *tmp = (FCGI_Header *)calloc(1, sizeof(FCGI_Header)); + FCGI_Header *tmp = static_cast<FCGI_Header *>(calloc(1, sizeof(FCGI_Header))); tmp->version = FCGI_VERSION_1; tmp->type = type; fcgiHeaderSetRequestId(tmp, state_->request_id_); @@ -214,10 +216,10 @@ FCGIClientRequest::createHeader(uchar type) FCGI_BeginRequest * FCGIClientRequest::createBeginRequest() { - state_->request = (FCGI_BeginRequest *)TSmalloc(sizeof(FCGI_BeginRequest)); + state_->request = static_cast<FCGI_BeginRequest *>(TSmalloc(sizeof(FCGI_BeginRequest))); // TODO send the request id here state_->request->header = createHeader(FCGI_BEGIN_REQUEST); - state_->request->body = (FCGI_BeginRequestBody *)calloc(1, sizeof(FCGI_BeginRequestBody)); + state_->request->body = static_cast<FCGI_BeginRequestBody *>(calloc(1, sizeof(FCGI_BeginRequestBody))); state_->request->body->roleB0 = FCGI_RESPONDER; state_->request->body->flags = FCGI_KEEP_CONN; state_->request->header->contentLengthB0 = sizeof(FCGI_BeginRequestBody); @@ -402,16 +404,16 @@ FCGIClientRequest::fcgiProcessContent(uchar **beg_buf, uchar *end_buf, FCGIRecor if (*state == fcgi_state_padding) { *state = fcgi_state_done; - *beg_buf += (size_t)((int)rec->length - (int)offset + (int)h->paddingLength); + *beg_buf += static_cast<size_t>(static_cast<int>(rec->length) - static_cast<int>(offset) + static_cast<int>(h->paddingLength)); return FCGI_PROCESS_DONE; } con_len = rec->length - offset; tot_len = con_len + h->paddingLength; - if (con_len <= nb) + if (con_len <= nb) { cpy_len = con_len; - else { + } else { cpy_len = nb; } @@ -442,16 +444,18 @@ FCGIClientRequest::fcgiProcessRecord(uchar **beg_buf, uchar *end_buf, FCGIRecord { int rv; while (rec->state < fcgi_state_content_begin) { - if ((rv = fcgiProcessHeader(**beg_buf, rec)) == FCGI_PROCESS_ERR) + if ((rv = fcgiProcessHeader(**beg_buf, rec)) == FCGI_PROCESS_ERR) { return FCGI_PROCESS_ERR; + } (*beg_buf)++; - if (*beg_buf == end_buf) + if (*beg_buf == end_buf) { return FCGI_PROCESS_AGAIN; + } } if (rec->state == fcgi_state_content_begin) { rec->length = fcgiHeaderGetContentLen(rec->header); - rec->content = (uchar *)TSmalloc(rec->length); - rec->state = (FCGI_State)(int(rec->state) + 1); + rec->content = static_cast<uchar *>(TSmalloc(rec->length)); + rec->state = static_cast<FCGI_State>(static_cast<int>(rec->state) + 1); } return fcgiProcessContent(beg_buf, end_buf, rec); @@ -491,7 +495,7 @@ convert_mime_hdr_to_string(TSMBuffer bufp, TSMLoc hdr_loc) /* Allocate the string with an extra byte for the string terminator */ - output_string = (char *)TSmalloc(total_avail + 1); + output_string = static_cast<char *>(TSmalloc(total_avail + 1)); output_len = 0; /* We need to loop over all the buffer blocks to make @@ -535,10 +539,11 @@ convert_mime_hdr_to_string(TSMBuffer bufp, TSMLoc hdr_loc) bool FCGIClientRequest::fcgiProcessBuffer(uchar *beg_buf, uchar *end_buf, std::ostringstream &output) { - if (!_headerRecord) + if (!_headerRecord) { _headerRecord = new FCGIRecordList; + } - while (1) { + while (true) { if (_headerRecord->state == fcgi_state_done) { FCGIRecordList *tmp = _headerRecord; _headerRecord = new FCGIRecordList(); @@ -547,7 +552,7 @@ FCGIClientRequest::fcgiProcessBuffer(uchar *beg_buf, uchar *end_buf, std::ostrin if (fcgiProcessRecord(&beg_buf, end_buf, _headerRecord) == FCGI_PROCESS_DONE) { if (first_chunk) { - string start = std::string((char *)_headerRecord->content, _headerRecord->length); + string start = std::string(reinterpret_cast<char *>(_headerRecord->content), _headerRecord->length); string end("\r\n\r\n"); string headerString; int foundPos = start.find(end); @@ -607,12 +612,12 @@ FCGIClientRequest::fcgiProcessBuffer(uchar *beg_buf, uchar *end_buf, std::ostrin first_chunk = false; } if (_headerRecord->header->type == FCGI_STDOUT) { - output << std::string((const char *)_headerRecord->content, _headerRecord->length); + output << std::string(reinterpret_cast<const char *>(_headerRecord->content), _headerRecord->length); } if (_headerRecord->header->type == FCGI_STDERR) { // XXX(oschaaf): we may want to treat this differently, but for now this will do. output << "HTTP/1.0 500 Server Error\r\n\r\n"; - output << std::string((const char *)_headerRecord->content, _headerRecord->length); + output << std::string(reinterpret_cast<const char *>(_headerRecord->content), _headerRecord->length); Dbg(dbg_ctl, "[ FCGIClientRequest:%s ] Response FCGI_STDERR.*****\n\n", __FUNCTION__); return true; } @@ -622,15 +627,16 @@ FCGIClientRequest::fcgiProcessBuffer(uchar *beg_buf, uchar *end_buf, std::ostrin } } - if (beg_buf == end_buf) + if (beg_buf == end_buf) { return false; + } } } bool FCGIClientRequest::fcgiDecodeRecordChunk(uchar *beg_buf, size_t remain, std::ostringstream &output) { - return fcgiProcessBuffer((uchar *)beg_buf, (uchar *)beg_buf + (size_t)remain, output); + return fcgiProcessBuffer(beg_buf, beg_buf + remain, output); } void @@ -638,7 +644,8 @@ FCGIClientRequest::print_bytes(uchar *buf, int n) { int i; printf("{"); - for (i = 0; i < n; i++) + for (i = 0; i < n; i++) { printf("%02x", buf[i]); + } printf("}\n"); } diff --git a/plugins/experimental/fastcgi/src/ats_fcgi_client.h b/plugins/experimental/fastcgi/src/ats_fcgi_client.h index d1a328b6ba..c44b1ec87b 100644 --- a/plugins/experimental/fastcgi/src/ats_fcgi_client.h +++ b/plugins/experimental/fastcgi/src/ats_fcgi_client.h @@ -47,7 +47,7 @@ namespace ats_plugin { using namespace atscppapi; -using FCGI_State = enum { +enum FCGI_State { fcgi_state_version = 0, fcgi_state_type, fcgi_state_request_id_hi, @@ -74,9 +74,9 @@ struct FCGIRecordList { FCGIRecordList() : content(nullptr), state(FCGI_State::fcgi_state_version), length(0), offset(0) { - header = (FCGI_Header *)TSmalloc(sizeof(FCGI_Header)); + header = static_cast<FCGI_Header *>(TSmalloc(sizeof(FCGI_Header))); memset(header, 0, sizeof(FCGI_Header)); - endBody = (FCGI_EndRequestBody *)TSmalloc(sizeof(FCGI_EndRequestBody)); + endBody = static_cast<FCGI_EndRequestBody *>(TSmalloc(sizeof(FCGI_EndRequestBody))); memset(endBody, 0, sizeof(FCGI_EndRequestBody)); }; diff --git a/plugins/experimental/fastcgi/src/fcgi_config.cc b/plugins/experimental/fastcgi/src/fcgi_config.cc index d68c399964..f425bbffb2 100644 --- a/plugins/experimental/fastcgi/src/fcgi_config.cc +++ b/plugins/experimental/fastcgi/src/fcgi_config.cc @@ -113,7 +113,7 @@ FcgiPluginConfig::getFcgiParams() void FcgiPluginConfig::setFcgiParams(FCGIParams *params) { - params = params; + this->params = params; } TSMgmtString FcgiPluginConfig::getDocumentRootDir() diff --git a/plugins/experimental/fastcgi/src/fcgi_config.h b/plugins/experimental/fastcgi/src/fcgi_config.h index 32e3533897..e3c381eda4 100644 --- a/plugins/experimental/fastcgi/src/fcgi_config.h +++ b/plugins/experimental/fastcgi/src/fcgi_config.h @@ -31,7 +31,7 @@ #pragma once namespace ats_plugin { -using FcgiConfigKey = enum { +enum FcgiConfigKey { fcgiEnabled, fcgiHostname, fcgiServerIp, @@ -44,7 +44,7 @@ using FcgiConfigKey = enum { fcgiMaxRequests, fcgiRequestQueueSize }; -using FcgiParamKey = enum { +enum FcgiParamKey { gatewayInterface, serverSoftware, queryString, @@ -155,12 +155,12 @@ class InterceptPluginData public: InterceptPluginData() : active_hash_map(nullptr), - mutex(0), + mutex(nullptr), seq_id(0), txn_slot(0), global_config(nullptr), last_gc_time(0), - read_while_writer(0), + read_while_writer(false), tol_global_hook_reqs(0), tol_remap_hook_reqs(0), tol_non_cacheable_reqs(0), diff --git a/plugins/experimental/fastcgi/src/fcgi_protocol.h b/plugins/experimental/fastcgi/src/fcgi_protocol.h index c955f45700..1bbac1ba6a 100644 --- a/plugins/experimental/fastcgi/src/fcgi_protocol.h +++ b/plugins/experimental/fastcgi/src/fcgi_protocol.h @@ -25,7 +25,7 @@ #define FCGI_LISTENSOCK_FILENO 0 -using FCGI_Header = struct { +struct FCGI_Header { unsigned char version; unsigned char type; unsigned char requestIdB1; @@ -70,14 +70,14 @@ using FCGI_Header = struct { */ #define FCGI_NULL_REQUEST_ID 0 -using FCGI_BeginRequestBody = struct { +struct FCGI_BeginRequestBody { unsigned char roleB1; unsigned char roleB0; unsigned char flags; unsigned char reserved[5]; }; -using FCGI_BeginRequest = struct { +struct FCGI_BeginRequest { FCGI_Header *header; FCGI_BeginRequestBody *body; }; @@ -94,7 +94,7 @@ using FCGI_BeginRequest = struct { #define FCGI_AUTHORIZER 2 #define FCGI_FILTER 3 -using FCGI_EndRequestBody = struct { +struct FCGI_EndRequestBody { unsigned char appStatusB3; unsigned char appStatusB2; unsigned char appStatusB1; @@ -103,7 +103,7 @@ using FCGI_EndRequestBody = struct { unsigned char reserved[3]; }; -using FCGI_EndRequest = struct { +struct FCGI_EndRequest { FCGI_Header header; FCGI_EndRequestBody body; }; @@ -123,12 +123,12 @@ using FCGI_EndRequest = struct { #define FCGI_MAX_REQS "FCGI_MAX_REQS" #define FCGI_MPXS_CONNS "FCGI_MPXS_CONNS" -using FCGI_UnknownTypeBody = struct { +struct FCGI_UnknownTypeBody { unsigned char type; unsigned char reserved[7]; }; -using FCGI_UnknownTypeRequest = struct { +struct FCGI_UnknownTypeRequest { FCGI_Header header; FCGI_UnknownTypeBody body; }; diff --git a/plugins/experimental/fastcgi/src/server.cc b/plugins/experimental/fastcgi/src/server.cc index afb42a233a..36d09ecad4 100644 --- a/plugins/experimental/fastcgi/src/server.cc +++ b/plugins/experimental/fastcgi/src/server.cc @@ -67,19 +67,20 @@ static int handlePHPConnectionEvents(TSCont contp, TSEvent event, void *edata) { Dbg(dbg_ctl, "[%s]: event( %d )\tEventName: %s\tContp: %p ", __FUNCTION__, event, TSHttpEventNameLookup(event), contp); - ServerConnectionInfo *conn_info = (ServerConnectionInfo *)TSContDataGet(contp); + ServerConnectionInfo *conn_info = static_cast<ServerConnectionInfo *>(TSContDataGet(contp)); Server *server = conn_info->server; ServerConnection *server_connection = conn_info->server_connection; switch (event) { case TS_EVENT_NET_CONNECT: { TSStatIntIncrement(InterceptGlobal::phpConnCount, 1); - server_connection->vc_ = (TSVConn)edata; + server_connection->vc_ = static_cast<TSVConn>(edata); server_connection->setState(ServerConnection::READY); Dbg(dbg_ctl, "%s: New Connection success, %p", __FUNCTION__, server_connection); ServerIntercept *intercept = server->getIntercept(server_connection->requestId()); - if (intercept) + if (intercept) { server_connection->createFCGIClient(intercept); + } } break; @@ -136,13 +137,14 @@ handlePHPConnectionEvents(TSCont contp, TSEvent event, void *edata) break; } - if (server_connection->getState() != ServerConnection::COMPLETE) + if (server_connection->getState() != ServerConnection::COMPLETE) { if (intercept && !intercept->getOutputCompleteState()) { Dbg(dbg_ctl, "[%s]: EOS intercept->setResponseOutputComplete, _request_id: %d, connection: %p", __FUNCTION__, server_connection->requestId(), server_connection); Transaction &transaction = utils::internal::getTransaction(intercept->_txn); transaction.error("Internal server error"); } + } server_connection->setState(ServerConnection::CLOSED); server->connectionClosed(server_connection); } break; diff --git a/plugins/experimental/fastcgi/src/server_connection.cc b/plugins/experimental/fastcgi/src/server_connection.cc index 8ef2fa6bf8..e547157adb 100644 --- a/plugins/experimental/fastcgi/src/server_connection.cc +++ b/plugins/experimental/fastcgi/src/server_connection.cc @@ -139,8 +139,9 @@ ServerConnection::~ServerConnection() _req_count = 0; TSContDestroy(_contp); _contp = nullptr; - if (_fcgiRequest != nullptr) + if (_fcgiRequest != nullptr) { delete _fcgiRequest; + } delete _sConnInfo; } @@ -190,5 +191,5 @@ ServerConnection::createConnection() _sConnInfo = new ServerConnectionInfo(_server, this); TSContDataSet(_contp, _sConnInfo); // TODO: Need to handle return value of NetConnect - TSNetConnect(_contp, (struct sockaddr const *)&ip_addr); + TSNetConnect(_contp, reinterpret_cast<struct sockaddr const *>(&ip_addr)); } diff --git a/plugins/experimental/fq_pacing/fq_pacing.cc b/plugins/experimental/fq_pacing/fq_pacing.cc index 1e2a2c6994..2dff07104e 100644 --- a/plugins/experimental/fq_pacing/fq_pacing.cc +++ b/plugins/experimental/fq_pacing/fq_pacing.cc @@ -16,11 +16,11 @@ * limitations under the License. */ -#include <errno.h> +#include <cerrno> #include <getopt.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include <ts/ts.h> #include <ts/remap.h> #include <ts/remap_version.h> @@ -34,13 +34,13 @@ static DbgCtl dbg_ctl{PLUGIN_NAME}; // Sanity check max rate at 100Gbps #define MAX_PACING_RATE 100000000000 -typedef struct fq_pacing_config { +struct fq_pacing_cfg_t { unsigned long pacing_rate; -} fq_pacing_cfg_t; +}; -typedef struct fq_pacing_cont { +struct fq_pacing_cont_t { int client_fd; -} fq_pacing_cont_t; +}; // Copied from ts/ink_sock.cc since that function is not exposed to plugins int @@ -56,7 +56,7 @@ safe_setsockopt(int s, int level, int optname, char *optval, int optlevel) static int fq_is_default_qdisc() { - TSFile f = 0; + TSFile f = nullptr; ssize_t s = 0; char buffer[5] = {}; int rc = 0; @@ -164,14 +164,14 @@ TSRemapDeleteInstance(void *instance) TSError("[fq_pacing] Cleaning up..."); if (instance != nullptr) { - TSfree((fq_pacing_cfg_t *)instance); + TSfree(static_cast<fq_pacing_cfg_t *>(instance)); } } static int reset_pacing_cont(TSCont contp, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn)edata; + TSHttpTxn txnp = static_cast<TSHttpTxn>(edata); auto txn_data = static_cast<fq_pacing_cont_t *>(TSContDataGet(contp)); #ifdef SO_MAX_PACING_RATE @@ -179,7 +179,8 @@ reset_pacing_cont(TSCont contp, TSEvent event, void *edata) if (txn_data->client_fd > 0) { Dbg(dbg_ctl, "Disabling SO_MAX_PACING_RATE for client_fd=%d", txn_data->client_fd); int res = 0; - res = safe_setsockopt(txn_data->client_fd, SOL_SOCKET, SO_MAX_PACING_RATE, (char *)&pacing_off, sizeof(pacing_off)); + res = safe_setsockopt(txn_data->client_fd, SOL_SOCKET, SO_MAX_PACING_RATE, reinterpret_cast<char *>(&pacing_off), + sizeof(pacing_off)); // EBADF indicates possible client abort if ((res < 0) && (errno != EBADF)) { TSError("[fq_pacing] Error disabling SO_MAX_PACING_RATE, errno=%d", errno); @@ -207,10 +208,11 @@ TSRemapDoRemap(void *instance, TSHttpTxn txnp, TSRemapRequestInfo *rri) } #ifdef SO_MAX_PACING_RATE - fq_pacing_cfg_t *cfg = (fq_pacing_cfg_t *)instance; + fq_pacing_cfg_t *cfg = static_cast<fq_pacing_cfg_t *>(instance); int res = 0; - res = safe_setsockopt(client_fd, SOL_SOCKET, SO_MAX_PACING_RATE, (char *)&cfg->pacing_rate, sizeof(cfg->pacing_rate)); + res = safe_setsockopt(client_fd, SOL_SOCKET, SO_MAX_PACING_RATE, reinterpret_cast<char *>(&cfg->pacing_rate), + sizeof(cfg->pacing_rate)); if ((res < 0)) { TSError("[fq_pacing] Error setting SO_MAX_PACING_RATE, errno=%d", errno); } diff --git a/plugins/experimental/http_stats/http_stats.cc b/plugins/experimental/http_stats/http_stats.cc index 466320f15b..ef407c4e4a 100644 --- a/plugins/experimental/http_stats/http_stats.cc +++ b/plugins/experimental/http_stats/http_stats.cc @@ -599,8 +599,8 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE { static const struct option longopt[] = { {"csv", no_argument, nullptr, 'c' }, - {"integer-counters", no_argument, NULL, 'i' }, - {"wrap-counters", no_argument, NULL, 'w' }, + {"integer-counters", no_argument, nullptr, 'i' }, + {"wrap-counters", no_argument, nullptr, 'w' }, {"max-age", required_argument, nullptr, 'a' }, {nullptr, no_argument, nullptr, '\0'} }; @@ -755,12 +755,12 @@ std::string HTTPStatsFormatter::output() { if (csv) { - TSRecordDump((TSRecordType)(TS_RECORDTYPE_PLUGIN | TS_RECORDTYPE_NODE | TS_RECORDTYPE_PROCESS), csv_out_stat, this); + TSRecordDump(static_cast<TSRecordType>(TS_RECORDTYPE_PLUGIN | TS_RECORDTYPE_NODE | TS_RECORDTYPE_PROCESS), csv_out_stat, this); APPEND_STAT_CSV(this, "version", "%s", TSTrafficServerVersionGet()); } else { APPEND(buf, "{ \"global\": {\n"); - TSRecordDump((TSRecordType)(TS_RECORDTYPE_PLUGIN | TS_RECORDTYPE_NODE | TS_RECORDTYPE_PROCESS), json_out_stat, this); + TSRecordDump(static_cast<TSRecordType>(TS_RECORDTYPE_PLUGIN | TS_RECORDTYPE_NODE | TS_RECORDTYPE_PROCESS), json_out_stat, this); APPEND(buf, "\"server\": \""); APPEND(buf, TSTrafficServerVersionGet()); diff --git a/plugins/experimental/maxmind_acl/mmdb.h b/plugins/experimental/maxmind_acl/mmdb.h index 79cb6adc3f..9fb2ba05fd 100644 --- a/plugins/experimental/maxmind_acl/mmdb.h +++ b/plugins/experimental/maxmind_acl/mmdb.h @@ -53,13 +53,13 @@ extern DbgCtl dbg_ctl; } using namespace maxmind_acl_ns; -typedef struct { +struct plugin_regex { std::string _regex_s; pcre *_rex; pcre_extra *_extra; -} plugin_regex; +}; -using ipstate = enum { ALLOW_IP, DENY_IP, UNKNOWN_IP }; +enum ipstate { ALLOW_IP, DENY_IP, UNKNOWN_IP }; // Base class for all ACLs class Acl diff --git a/plugins/experimental/memcache/protocol_binary.h b/plugins/experimental/memcache/protocol_binary.h index 62aecfcfd6..f091f89cba 100644 --- a/plugins/experimental/memcache/protocol_binary.h +++ b/plugins/experimental/memcache/protocol_binary.h @@ -45,13 +45,13 @@ * Definition of the legal "magic" values used in a packet. * See section 3.1 Magic byte */ -typedef enum { PROTOCOL_BINARY_REQ = 0x80, PROTOCOL_BINARY_RES = 0x81 } protocol_binary_magic; +enum protocol_binary_magic { PROTOCOL_BINARY_REQ = 0x80, PROTOCOL_BINARY_RES = 0x81 }; /** * Definition of the valid response status numbers. * See section 3.2 Response Status */ -typedef enum { +enum protocol_binary_response_status { PROTOCOL_BINARY_RESPONSE_SUCCESS = 0x00, PROTOCOL_BINARY_RESPONSE_KEY_ENOENT = 0x01, PROTOCOL_BINARY_RESPONSE_KEY_EEXISTS = 0x02, @@ -63,13 +63,13 @@ typedef enum { PROTOCOL_BINARY_RESPONSE_AUTH_CONTINUE = 0x21, PROTOCOL_BINARY_RESPONSE_UNKNOWN_COMMAND = 0x81, PROTOCOL_BINARY_RESPONSE_ENOMEM = 0x82 -} protocol_binary_response_status; +}; /** * Definition of the different command opcodes. * See section 3.3 Command Opcodes */ -typedef enum { +enum protocol_binary_command { PROTOCOL_BINARY_CMD_GET = 0x00, PROTOCOL_BINARY_CMD_SET = 0x01, PROTOCOL_BINARY_CMD_ADD = 0x02, @@ -121,19 +121,19 @@ typedef enum { PROTOCOL_BINARY_CMD_RDECRQ = 0x3c /* End Range operations */ -} protocol_binary_command; +}; /** * Definition of the data types in the packet * See section 3.4 Data Types */ -typedef enum { PROTOCOL_BINARY_RAW_BYTES = 0x00 } protocol_binary_datatypes; +enum protocol_binary_datatypes { PROTOCOL_BINARY_RAW_BYTES = 0x00 }; /** * Definition of the header structure for a request packet. * See section 2 */ -typedef union { +union protocol_binary_request_header { struct { uint8_t magic; uint8_t opcode; @@ -146,13 +146,13 @@ typedef union { uint64_t cas; } request; uint8_t bytes[24]; -} protocol_binary_request_header; +}; /** * Definition of the header structure for a response packet. * See section 2 */ -typedef union { +union protocol_binary_response_header { struct { uint8_t magic; uint8_t opcode; @@ -165,43 +165,43 @@ typedef union { uint64_t cas; } response; uint8_t bytes[24]; -} protocol_binary_response_header; +}; /** * Definition of a request-packet containing no extras */ -typedef union { +union protocol_binary_request_no_extras { struct { protocol_binary_request_header header; } message; uint8_t bytes[sizeof(protocol_binary_request_header)]; -} protocol_binary_request_no_extras; +}; /** * Definition of a response-packet containing no extras */ -typedef union { +union protocol_binary_response_no_extras { struct { protocol_binary_response_header header; } message; uint8_t bytes[sizeof(protocol_binary_response_header)]; -} protocol_binary_response_no_extras; +}; /** * Definition of the packet used by the get, getq, getk and getkq command. * See section 4 */ -typedef protocol_binary_request_no_extras protocol_binary_request_get; -typedef protocol_binary_request_no_extras protocol_binary_request_getq; -typedef protocol_binary_request_no_extras protocol_binary_request_getk; -typedef protocol_binary_request_no_extras protocol_binary_request_getkq; +using protocol_binary_request_get = protocol_binary_request_no_extras; +using protocol_binary_request_getq = protocol_binary_request_no_extras; +using protocol_binary_request_getk = protocol_binary_request_no_extras; +using protocol_binary_request_getkq = protocol_binary_request_no_extras; /** * Definition of the packet returned from a successful get, getq, getk and * getkq. * See section 4 */ -typedef union { +union protocol_binary_response_get { struct { protocol_binary_response_header header; struct { @@ -209,23 +209,23 @@ typedef union { } body; } message; uint8_t bytes[sizeof(protocol_binary_response_header) + 4]; -} protocol_binary_response_get; +}; -typedef protocol_binary_response_get protocol_binary_response_getq; -typedef protocol_binary_response_get protocol_binary_response_getk; -typedef protocol_binary_response_get protocol_binary_response_getkq; +using protocol_binary_response_getq = protocol_binary_response_get; +using protocol_binary_response_getk = protocol_binary_response_get; +using protocol_binary_response_getkq = protocol_binary_response_get; /** * Definition of the packet used by the delete command * See section 4 */ -typedef protocol_binary_request_no_extras protocol_binary_request_delete; +using protocol_binary_request_delete = protocol_binary_request_no_extras; /** * Definition of the packet returned by the delete command * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_delete; +using protocol_binary_response_delete = protocol_binary_response_no_extras; /** * Definition of the packet used by the flush command @@ -233,7 +233,7 @@ typedef protocol_binary_response_no_extras protocol_binary_response_delete; * Please note that the expiration field is optional, so remember to see * check the header.bodysize to see if it is present. */ -typedef union { +union protocol_binary_request_flush { struct { protocol_binary_request_header header; struct { @@ -241,19 +241,19 @@ typedef union { } body; } message; uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; -} protocol_binary_request_flush; +}; /** * Definition of the packet returned by the flush command * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_flush; +using protocol_binary_response_flush = protocol_binary_response_no_extras; /** * Definition of the packet used by set, add and replace * See section 4 */ -typedef union { +union protocol_binary_request_set { struct { protocol_binary_request_header header; struct { @@ -262,36 +262,36 @@ typedef union { } body; } message; uint8_t bytes[sizeof(protocol_binary_request_header) + 8]; -} protocol_binary_request_set; -typedef protocol_binary_request_set protocol_binary_request_add; -typedef protocol_binary_request_set protocol_binary_request_replace; +}; +using protocol_binary_request_add = protocol_binary_request_set; +using protocol_binary_request_replace = protocol_binary_request_set; /** * Definition of the packet returned by set, add and replace * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_set; -typedef protocol_binary_response_no_extras protocol_binary_response_add; -typedef protocol_binary_response_no_extras protocol_binary_response_replace; +using protocol_binary_response_set = protocol_binary_response_no_extras; +using protocol_binary_response_add = protocol_binary_response_no_extras; +using protocol_binary_response_replace = protocol_binary_response_no_extras; /** * Definition of the noop packet * See section 4 */ -typedef protocol_binary_request_no_extras protocol_binary_request_noop; +using protocol_binary_request_noop = protocol_binary_request_no_extras; /** * Definition of the packet returned by the noop command * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_noop; +using protocol_binary_response_noop = protocol_binary_response_no_extras; /** * Definition of the structure used by the increment and decrement * command. * See section 4 */ -typedef union { +union protocol_binary_request_incr { struct { protocol_binary_request_header header; struct { @@ -301,15 +301,15 @@ typedef union { } body; } message; uint8_t bytes[sizeof(protocol_binary_request_header) + 20]; -} protocol_binary_request_incr; -typedef protocol_binary_request_incr protocol_binary_request_decr; +}; +using protocol_binary_request_decr = protocol_binary_request_incr; /** * Definition of the response from an incr or decr command * command. * See section 4 */ -typedef union { +union protocol_binary_response_incr { struct { protocol_binary_response_header header; struct { @@ -317,58 +317,58 @@ typedef union { } body; } message; uint8_t bytes[sizeof(protocol_binary_response_header) + 8]; -} protocol_binary_response_incr; -typedef protocol_binary_response_incr protocol_binary_response_decr; +}; +using protocol_binary_response_decr = protocol_binary_response_incr; /** * Definition of the quit * See section 4 */ -typedef protocol_binary_request_no_extras protocol_binary_request_quit; +using protocol_binary_request_quit = protocol_binary_request_no_extras; /** * Definition of the packet returned by the quit command * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_quit; +using protocol_binary_response_quit = protocol_binary_response_no_extras; /** * Definition of the packet used by append and prepend command * See section 4 */ -typedef protocol_binary_request_no_extras protocol_binary_request_append; -typedef protocol_binary_request_no_extras protocol_binary_request_prepend; +using protocol_binary_request_append = protocol_binary_request_no_extras; +using protocol_binary_request_prepend = protocol_binary_request_no_extras; /** * Definition of the packet returned from a successful append or prepend * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_append; -typedef protocol_binary_response_no_extras protocol_binary_response_prepend; +using protocol_binary_response_append = protocol_binary_response_no_extras; +using protocol_binary_response_prepend = protocol_binary_response_no_extras; /** * Definition of the packet used by the version command * See section 4 */ -typedef protocol_binary_request_no_extras protocol_binary_request_version; +using protocol_binary_request_version = protocol_binary_request_no_extras; /** * Definition of the packet returned from a successful version command * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_version; +using protocol_binary_response_version = protocol_binary_response_no_extras; /** * Definition of the packet used by the stats command. * See section 4 */ -typedef protocol_binary_request_no_extras protocol_binary_request_stats; +using protocol_binary_request_stats = protocol_binary_request_no_extras; /** * Definition of the packet returned from a successful stats command * See section 4 */ -typedef protocol_binary_response_no_extras protocol_binary_response_stats; +using protocol_binary_response_stats = protocol_binary_response_no_extras; /** * Definition of a request for a range operation. @@ -378,7 +378,7 @@ typedef protocol_binary_response_no_extras protocol_binary_response_stats; * this header for use in other projects. Range operations are * not expected to be implemented in the memcached server itself. */ -typedef union { +union protocol_binary_request_rangeop { struct { protocol_binary_response_header header; struct { @@ -389,18 +389,18 @@ typedef union { } body; } message; uint8_t bytes[sizeof(protocol_binary_request_header) + 4]; -} protocol_binary_request_rangeop; - -typedef protocol_binary_request_rangeop protocol_binary_request_rget; -typedef protocol_binary_request_rangeop protocol_binary_request_rset; -typedef protocol_binary_request_rangeop protocol_binary_request_rsetq; -typedef protocol_binary_request_rangeop protocol_binary_request_rappend; -typedef protocol_binary_request_rangeop protocol_binary_request_rappendq; -typedef protocol_binary_request_rangeop protocol_binary_request_rprepend; -typedef protocol_binary_request_rangeop protocol_binary_request_rprependq; -typedef protocol_binary_request_rangeop protocol_binary_request_rdelete; -typedef protocol_binary_request_rangeop protocol_binary_request_rdeleteq; -typedef protocol_binary_request_rangeop protocol_binary_request_rincr; -typedef protocol_binary_request_rangeop protocol_binary_request_rincrq; -typedef protocol_binary_request_rangeop protocol_binary_request_rdecr; -typedef protocol_binary_request_rangeop protocol_binary_request_rdecrq; +}; + +using protocol_binary_request_rget = protocol_binary_request_rangeop; +using protocol_binary_request_rset = protocol_binary_request_rangeop; +using protocol_binary_request_rsetq = protocol_binary_request_rangeop; +using protocol_binary_request_rappend = protocol_binary_request_rangeop; +using protocol_binary_request_rappendq = protocol_binary_request_rangeop; +using protocol_binary_request_rprepend = protocol_binary_request_rangeop; +using protocol_binary_request_rprependq = protocol_binary_request_rangeop; +using protocol_binary_request_rdelete = protocol_binary_request_rangeop; +using protocol_binary_request_rdeleteq = protocol_binary_request_rangeop; +using protocol_binary_request_rincr = protocol_binary_request_rangeop; +using protocol_binary_request_rincrq = protocol_binary_request_rangeop; +using protocol_binary_request_rdecr = protocol_binary_request_rangeop; +using protocol_binary_request_rdecrq = protocol_binary_request_rangeop; diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc index 15cd1490e5..1b529899dd 100644 --- a/plugins/experimental/memcache/tsmemcache.cc +++ b/plugins/experimental/memcache/tsmemcache.cc @@ -125,7 +125,7 @@ int MCAccept::main_event(int event, void *data) { if (event == NET_EVENT_ACCEPT) { - NetVConnection *netvc = (NetVConnection *)data; + NetVConnection *netvc = static_cast<NetVConnection *>(data); MC *mc = theMCAllocator.alloc(); if (!mutex->thread_holding) { mc->new_connection(netvc, netvc->thread); diff --git a/plugins/experimental/memcache/tsmemcache.h b/plugins/experimental/memcache/tsmemcache.h index 14994b1628..c85867df2b 100644 --- a/plugins/experimental/memcache/tsmemcache.h +++ b/plugins/experimental/memcache/tsmemcache.h @@ -71,7 +71,7 @@ struct MCCacheHeader { char * key() { - return ((char *)this) + sizeof(MCCacheHeader); + return (reinterpret_cast<char *>(this)) + sizeof(MCCacheHeader); } int len() @@ -130,9 +130,9 @@ struct MC : Continuation { MCCacheHeader header; char tmp_cache_header_key[256]; protocol_binary_request_header binary_header; - union { + union res { protocol_binary_response_get get; - } res; + }; char *key, *tbuf; int read_offset; int end_of_cmd; // -1 means that it is already consumed @@ -214,7 +214,7 @@ static inline char * xutoa(uint32_t i, char *e) { do { - *--e = (char)(i % 10 + 48); + *--e = static_cast<char>(i % 10 + 48); } while ((i /= 10) > 0); return e; } @@ -223,7 +223,7 @@ static inline char * xutoa(uint64_t i, char *e) { do { - *--e = (char)(i % 10 + 48); + *--e = static_cast<char>(i % 10 + 48); } while ((i /= 10) > 0); return e; } diff --git a/plugins/experimental/money_trace/money_trace.cc b/plugins/experimental/money_trace/money_trace.cc index d05ab900ad..d7a20921c9 100644 --- a/plugins/experimental/money_trace/money_trace.cc +++ b/plugins/experimental/money_trace/money_trace.cc @@ -57,7 +57,7 @@ config_from_args(int const argc, char const *argv[], PluginType const ptype) // getopt assumes args start at '1' so this hack is needed do { - int const opt = getopt_long(argc, (char *const *)argv, "a:c:h:l:p:", longopt, nullptr); + int const opt = getopt_long(argc, const_cast<char *const *>(argv), "a:c:h:l:p:", longopt, nullptr); if (-1 == opt) { break; diff --git a/plugins/experimental/mp4/mp4_meta.h b/plugins/experimental/mp4/mp4_meta.h index a834b86c28..49ca1416e3 100644 --- a/plugins/experimental/mp4/mp4_meta.h +++ b/plugins/experimental/mp4/mp4_meta.h @@ -64,7 +64,7 @@ ((u_char *)(p))[6] = (u_char)((n) >> 8); \ ((u_char *)(p))[7] = (u_char)(n) -typedef enum { +enum TSMp4AtomID { MP4_TRAK_ATOM = 0, MP4_TKHD_ATOM, MP4_MDIA_ATOM, @@ -92,20 +92,20 @@ typedef enum { MP4_CO64_ATOM, MP4_CO64_DATA, MP4_LAST_ATOM = MP4_CO64_DATA -} TSMp4AtomID; +}; -typedef struct { +struct mp4_atom_header { u_char size[4]; u_char name[4]; -} mp4_atom_header; +}; -typedef struct { +struct mp4_atom_header64 { u_char size[4]; u_char name[4]; u_char size64[8]; -} mp4_atom_header64; +}; -typedef struct { +struct mp4_mvhd_atom { u_char size[4]; u_char name[4]; u_char version[1]; @@ -125,9 +125,9 @@ typedef struct { u_char selection_duration[4]; u_char current_time[4]; u_char next_track_id[4]; -} mp4_mvhd_atom; +}; -typedef struct { +struct mp4_mvhd64_atom { u_char size[4]; u_char name[4]; u_char version[1]; @@ -147,9 +147,9 @@ typedef struct { u_char selection_duration[4]; u_char current_time[4]; u_char next_track_id[4]; -} mp4_mvhd64_atom; +}; -typedef struct { +struct mp4_tkhd_atom { u_char size[4]; u_char name[4]; u_char version[1]; @@ -167,9 +167,9 @@ typedef struct { u_char matrix[36]; u_char width[4]; u_char height[4]; -} mp4_tkhd_atom; +}; -typedef struct { +struct mp4_tkhd64_atom { u_char size[4]; u_char name[4]; u_char version[1]; @@ -187,9 +187,9 @@ typedef struct { u_char matrix[36]; u_char width[4]; u_char height[4]; -} mp4_tkhd64_atom; +}; -typedef struct { +struct mp4_mdhd_atom { u_char size[4]; u_char name[4]; u_char version[1]; @@ -200,9 +200,9 @@ typedef struct { u_char duration[4]; u_char language[2]; u_char quality[2]; -} mp4_mdhd_atom; +}; -typedef struct { +struct mp4_mdhd64_atom { u_char size[4]; u_char name[4]; u_char version[1]; @@ -213,9 +213,9 @@ typedef struct { u_char duration[8]; u_char language[2]; u_char quality[2]; -} mp4_mdhd64_atom; +}; -typedef struct { +struct mp4_stsd_atom { u_char size[4]; u_char name[4]; u_char version[1]; @@ -224,88 +224,88 @@ typedef struct { u_char media_size[4]; u_char media_name[4]; -} mp4_stsd_atom; +}; -typedef struct { +struct mp4_stts_atom { u_char size[4]; u_char name[4]; u_char version[1]; u_char flags[3]; u_char entries[4]; -} mp4_stts_atom; +}; -typedef struct { +struct mp4_stts_entry { u_char count[4]; u_char duration[4]; -} mp4_stts_entry; +}; -typedef struct { +struct mp4_stss_atom { u_char size[4]; u_char name[4]; u_char version[1]; u_char flags[3]; u_char entries[4]; -} mp4_stss_atom; +}; -typedef struct { +struct mp4_ctts_atom { u_char size[4]; u_char name[4]; u_char version[1]; u_char flags[3]; u_char entries[4]; -} mp4_ctts_atom; +}; -typedef struct { +struct mp4_ctts_entry { u_char count[4]; u_char offset[4]; -} mp4_ctts_entry; +}; -typedef struct { +struct mp4_stsc_atom { u_char size[4]; u_char name[4]; u_char version[1]; u_char flags[3]; u_char entries[4]; -} mp4_stsc_atom; +}; -typedef struct { +struct mp4_stsc_entry { u_char chunk[4]; u_char samples[4]; u_char id[4]; -} mp4_stsc_entry; +}; -typedef struct { +struct mp4_stsz_atom { u_char size[4]; u_char name[4]; u_char version[1]; u_char flags[3]; u_char uniform_size[4]; u_char entries[4]; -} mp4_stsz_atom; +}; -typedef struct { +struct mp4_stco_atom { u_char size[4]; u_char name[4]; u_char version[1]; u_char flags[3]; u_char entries[4]; -} mp4_stco_atom; +}; -typedef struct { +struct mp4_co64_atom { u_char size[4]; u_char name[4]; u_char version[1]; u_char flags[3]; u_char entries[4]; -} mp4_co64_atom; +}; class Mp4Meta; using Mp4AtomHandler = int (Mp4Meta::*)(int64_t, int64_t); -typedef struct { +struct mp4_atom_handler { const char *name; Mp4AtomHandler handler; -} mp4_atom_handler; +}; class BufferHandle { @@ -382,8 +382,9 @@ public: { uint32_t i; - for (i = 0; i < trak_num; i++) + for (i = 0; i < trak_num; i++) { delete trak_vec[i]; + } if (meta_reader) { TSIOBufferReaderFree(meta_reader); diff --git a/plugins/experimental/otel_tracer/otel_tracer.cc b/plugins/experimental/otel_tracer/otel_tracer.cc index cdfa697676..52c4e250ca 100644 --- a/plugins/experimental/otel_tracer/otel_tracer.cc +++ b/plugins/experimental/otel_tracer/otel_tracer.cc @@ -14,9 +14,9 @@ limitations under the License. */ -#include <ctype.h> -#include <stdio.h> -#include <string.h> +#include <cctype> +#include <cstdio> +#include <cstring> #include <iostream> #include <vector> #include <string_view> @@ -308,7 +308,7 @@ read_request(TSHttpTxn txnp, TSCont contp) static int plugin_handler(TSCont contp, TSEvent event, void *edata) { - TSHttpTxn txnp = (TSHttpTxn)edata; + TSHttpTxn txnp = static_cast<TSHttpTxn>(edata); switch (event) { case TS_EVENT_HTTP_READ_REQUEST_HDR: diff --git a/plugins/experimental/otel_tracer/tracer_common.h b/plugins/experimental/otel_tracer/tracer_common.h index 9eddb7c84b..e853456c73 100644 --- a/plugins/experimental/otel_tracer/tracer_common.h +++ b/plugins/experimental/otel_tracer/tracer_common.h @@ -74,7 +74,7 @@ public: return ""; } - virtual void + void Set(nostd::string_view key, nostd::string_view value) noexcept override { headers_.insert(std::pair<std::string, std::string>(std::string(key), std::string(value))); @@ -112,7 +112,7 @@ struct ExtraRequestData { }; void -InitTracer(std::string url, std::string service_name, double rate) +InitTracer(const std::string &url, const std::string &service_name, double rate) { otlp::OtlpHttpExporterOptions opts; diff --git a/plugins/experimental/rate_limit/iprep_simu.cc b/plugins/experimental/rate_limit/iprep_simu.cc index e45b86861e..2b3d33e18b 100644 --- a/plugins/experimental/rate_limit/iprep_simu.cc +++ b/plugins/experimental/rate_limit/iprep_simu.cc @@ -83,12 +83,12 @@ parseArgs(int argc, char **argv) CmdConfigs options; int c; constexpr struct option long_options[] = { - {"help", no_argument, NULL, 'h'}, - {"buckets", required_argument, NULL, 'b'}, - {"perma", required_argument, NULL, 'p'}, - {"size", required_argument, NULL, 's'}, - {"threshold", required_argument, NULL, 't'}, - {NULL, 0, NULL, 0 } + {"help", no_argument, nullptr, 'h'}, + {"buckets", required_argument, nullptr, 'b'}, + {"perma", required_argument, nullptr, 'p'}, + {"size", required_argument, nullptr, 's'}, + {"threshold", required_argument, nullptr, 't'}, + {nullptr, 0, nullptr, 0 } }; // Make sure the optional values have been set @@ -97,12 +97,13 @@ parseArgs(int argc, char **argv) options.end_permablock = 0; options.incr_permablock = 1; - while (1) { + while (true) { int ix = 0; c = getopt_long(argc, argv, "b:f:p:s:t:h?", long_options, &ix); - if (c == -1) + if (c == -1) { break; + } switch (c) { case 'h': @@ -143,7 +144,7 @@ parseArgs(int argc, char **argv) // Returns a tuple with the number of good requests and bad requests, respectively. // std::tuple<uint32_t, uint32_t> -loadFile(std::string fname, IpMap &all_ips, IpList &ips) +loadFile(const std::string &fname, IpMap &all_ips, IpList &ips) { std::ifstream infile(fname); diff --git a/plugins/experimental/rate_limit/limiter.h b/plugins/experimental/rate_limit/limiter.h index 89e65b7407..3f1d6172ac 100644 --- a/plugins/experimental/rate_limit/limiter.h +++ b/plugins/experimental/rate_limit/limiter.h @@ -189,7 +189,7 @@ public: for (int i = 0; i < RATE_LIMITER_METRIC_MAX; i++) { size_t const metricsz = metric_prefix.length() + strlen(suffixes[i]) + 2; // padding for dot+terminator - char *const metric = (char *)TSmalloc(metricsz); + char *const metric = static_cast<char *>(TSmalloc(metricsz)); snprintf(metric, metricsz, "%s.%s", metric_prefix.data(), suffixes[i]); _metrics[i] = TS_ERROR; diff --git a/plugins/experimental/rate_limit/txn_limiter.h b/plugins/experimental/rate_limit/txn_limiter.h index a801872c23..034db3cb4e 100644 --- a/plugins/experimental/rate_limit/txn_limiter.h +++ b/plugins/experimental/rate_limit/txn_limiter.h @@ -26,7 +26,7 @@ class TxnRateLimiter : public RateLimiter<TSHttpTxn> { public: - ~TxnRateLimiter() + ~TxnRateLimiter() override { if (_action) { TSActionCancel(_action); diff --git a/plugins/experimental/ssl_session_reuse/src/Config.h b/plugins/experimental/ssl_session_reuse/src/Config.h index e4ac1ffd45..ac0eb786cc 100644 --- a/plugins/experimental/ssl_session_reuse/src/Config.h +++ b/plugins/experimental/ssl_session_reuse/src/Config.h @@ -62,8 +62,9 @@ public: getValue(const std::string &category, const std::string &key, _T &value) { std::string strvalue; - if (!getValue(category, key, strvalue)) + if (!getValue(category, key, strvalue)) { return false; + } value = fromstring(strvalue); return true; } @@ -73,8 +74,9 @@ public: returnValue(const std::string &category, const std::string &key, _T default_value) { std::string strvalue; - if (!getValue(category, key, strvalue)) + if (!getValue(category, key, strvalue)) { return default_value; + } return fromstring(strvalue); } diff --git a/plugins/experimental/ssl_session_reuse/src/message.h b/plugins/experimental/ssl_session_reuse/src/message.h index a74c061158..df33f8c2fd 100644 --- a/plugins/experimental/ssl_session_reuse/src/message.h +++ b/plugins/experimental/ssl_session_reuse/src/message.h @@ -28,14 +28,14 @@ #include "redis_endpoint.h" -using Message = struct message { +struct Message { std::string channel; std::string data; bool cleanup; std::set<RedisEndpoint, RedisEndpointCompare> hosts_tried; - message() {} - message(const struct message &m) : channel(m.channel), data(m.data), cleanup(m.cleanup), hosts_tried(m.hosts_tried) {} - message(const std::string &c, const std::string &d, bool quit = false) : channel(c), data(d), cleanup(quit) {} - virtual ~message() {} + Message() {} + Message(const struct Message &m) : channel(m.channel), data(m.data), cleanup(m.cleanup), hosts_tried(m.hosts_tried) {} + Message(const std::string &c, const std::string &d, bool quit = false) : channel(c), data(d), cleanup(quit) {} + virtual ~Message() {} }; diff --git a/plugins/experimental/ssl_session_reuse/src/redis_endpoint.cc b/plugins/experimental/ssl_session_reuse/src/redis_endpoint.cc index b438c2b6d6..66f9b3ac52 100644 --- a/plugins/experimental/ssl_session_reuse/src/redis_endpoint.cc +++ b/plugins/experimental/ssl_session_reuse/src/redis_endpoint.cc @@ -24,7 +24,7 @@ #include "redis_endpoint.h" -redis_endpoint::redis_endpoint(const std::string &endpoint_spec) +RedisEndpoint::RedisEndpoint(const std::string &endpoint_spec) { std::stringstream ss; size_t delim_pos(endpoint_spec.find(':')); diff --git a/plugins/experimental/ssl_session_reuse/src/redis_endpoint.h b/plugins/experimental/ssl_session_reuse/src/redis_endpoint.h index 63ba0ca707..fa6df9f0ba 100644 --- a/plugins/experimental/ssl_session_reuse/src/redis_endpoint.h +++ b/plugins/experimental/ssl_session_reuse/src/redis_endpoint.h @@ -28,15 +28,15 @@ #include "globals.h" -using RedisEndpoint = struct redis_endpoint { +struct RedisEndpoint { std::string m_hostname; int m_port; - redis_endpoint() : m_hostname(cDefaultRedisHost), m_port(cDefaultRedisPort) {} - redis_endpoint(const std::string &endpoint_spec); + RedisEndpoint() : m_hostname(cDefaultRedisHost), m_port(cDefaultRedisPort) {} + RedisEndpoint(const std::string &endpoint_spec); }; -using RedisEndpointCompare = struct redis_endpoint_compare { +struct RedisEndpointCompare { bool operator()(const RedisEndpoint &lhs, const RedisEndpoint &rhs) const { diff --git a/plugins/experimental/system_stats/system_stats.cc b/plugins/experimental/system_stats/system_stats.cc index 2eba7dffa9..648f7e2749 100644 --- a/plugins/experimental/system_stats/system_stats.cc +++ b/plugins/experimental/system_stats/system_stats.cc @@ -23,17 +23,17 @@ #include "tscore/ink_defs.h" #include "ts/ts.h" -#include <stdio.h> -#include <stdlib.h> -#include <stdbool.h> -#include <ctype.h> -#include <limits.h> +#include <cstdio> +#include <cstdlib> + +#include <cctype> +#include <climits> #include <ts/ts.h> -#include <string.h> -#include <inttypes.h> +#include <cstring> +#include <cinttypes> #include <getopt.h> #include <sys/stat.h> -#include <time.h> +#include <ctime> #include <unistd.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -41,7 +41,7 @@ #include <fstream> #include <ts/remap.h> #include <dirent.h> -#include <stdint.h> +#include <cstdint> #include <sys/types.h> #include <chrono> @@ -49,7 +49,7 @@ #include <sys/sysinfo.h> #endif -#include <limits.h> +#include <climits> #define PLUGIN_NAME "system_stats" #define DEBUG_TAG PLUGIN_NAME diff --git a/plugins/experimental/tls_bridge/tls_bridge.cc b/plugins/experimental/tls_bridge/tls_bridge.cc index fd1dff05e8..7fd862918d 100644 --- a/plugins/experimental/tls_bridge/tls_bridge.cc +++ b/plugins/experimental/tls_bridge/tls_bridge.cc @@ -123,8 +123,8 @@ BridgeConfig::load_pair(std::string_view rxp, std::string_view service, swoc::fi if (ln) { snprintf(buff, sizeof(buff), " on line %d", ln); } - TSError("[%s] Failed to compile regular expression '%.*s' in %s%s", PLUGIN_NAME, int(rxp.size()), rxp.data(), src.c_str(), - buff); + TSError("[%s] Failed to compile regular expression '%.*s' in %s%s", PLUGIN_NAME, static_cast<int>(rxp.size()), rxp.data(), + src.c_str(), buff); } } @@ -136,7 +136,7 @@ BridgeConfig::load_config(int argc, const char *argv[]) for (int i = 0; i < argc; i += 2) { if (argv[i] == CONFIG_FILE_ARG) { if (i + 1 >= argc) { - TSError("[%s] Invalid '%.*s' argument - no file name found.", PLUGIN_NAME, int(CONFIG_FILE_ARG.size()), + TSError("[%s] Invalid '%.*s' argument - no file name found.", PLUGIN_NAME, static_cast<int>(CONFIG_FILE_ARG.size()), CONFIG_FILE_ARG.data()); } else { swoc::file::path fp(argv[i + 1]); @@ -147,8 +147,8 @@ BridgeConfig::load_config(int argc, const char *argv[]) // bulk load the file. std::string content{swoc::file::load(fp, ec)}; if (ec) { - TSError("[%s] Invalid '%.*s' argument - unable to read file '%s' : %s.", PLUGIN_NAME, int(CONFIG_FILE_ARG.size()), - CONFIG_FILE_ARG.data(), fp.c_str(), ec.message().c_str()); + TSError("[%s] Invalid '%.*s' argument - unable to read file '%s' : %s.", PLUGIN_NAME, + static_cast<int>(CONFIG_FILE_ARG.size()), CONFIG_FILE_ARG.data(), fp.c_str(), ec.message().c_str()); } else { // walk the lines. @@ -306,7 +306,7 @@ void Bridge::net_accept(TSVConn vc) { char buff[1024]; - int64_t n = snprintf(buff, sizeof(buff), CONNECT_FORMAT, int(_peer.size()), _peer.data()); + int64_t n = snprintf(buff, sizeof(buff), CONNECT_FORMAT, static_cast<int>(_peer.size()), _peer.data()); Dbg(dbg_ctl, "Received UA VConn, connecting to peer %.*s", int(_peer.size()), _peer.data()); // UA side intercepted. diff --git a/plugins/experimental/uri_signing/config.cc b/plugins/experimental/uri_signing/config.cc index 70efa1ffb0..2014ef663c 100644 --- a/plugins/experimental/uri_signing/config.cc +++ b/plugins/experimental/uri_signing/config.cc @@ -24,9 +24,9 @@ #include <cjose/cjose.h> #include <jansson.h> -#include <string.h> +#include <cstring> #include <search.h> -#include <errno.h> +#include <cerrno> #define JSONError(err) PluginError("json-err: %s:%d:%d: %s", (err).source, (err).line, (err).column, (err).text) @@ -51,7 +51,7 @@ cjose_jwk_t ** find_keys(struct config *cfg, const char *issuer) { ENTRY *entry; - if (!hsearch_r((ENTRY){.key = (char *)issuer, .data = nullptr}, FIND, &entry, cfg->issuers) || !entry) { + if (!hsearch_r((ENTRY){.key = const_cast<char *>(issuer), .data = nullptr}, FIND, &entry, cfg->issuers) || !entry) { PluginDebug("Unable to locate any keys at %p for issuer %s in %p->%p", entry, issuer, cfg, cfg->issuers); return nullptr; } diff --git a/plugins/experimental/uri_signing/cookie.cc b/plugins/experimental/uri_signing/cookie.cc index d494268e5f..ff48feac62 100644 --- a/plugins/experimental/uri_signing/cookie.cc +++ b/plugins/experimental/uri_signing/cookie.cc @@ -18,7 +18,7 @@ #include "cookie.h" #include "common.h" -#include <string.h> +#include <cstring> const char * next_cookie(const char *cookie, size_t *cookie_ct, const char **k, size_t *k_ct, const char **v, size_t *v_ct) diff --git a/plugins/experimental/uri_signing/jwt.cc b/plugins/experimental/uri_signing/jwt.cc index 841c3e6e86..00ce82d67e 100644 --- a/plugins/experimental/uri_signing/jwt.cc +++ b/plugins/experimental/uri_signing/jwt.cc @@ -22,9 +22,9 @@ #include "normalize.h" #include <jansson.h> #include <cjose/cjose.h> -#include <math.h> -#include <time.h> -#include <string.h> +#include <cmath> +#include <ctime> +#include <cstring> double parse_number(json_t *num) @@ -82,12 +82,12 @@ jwt_delete(struct jwt *jwt) } double -now(void) +now() { struct timespec t; if (!clock_gettime(CLOCK_REALTIME, &t)) { - return (double)t.tv_sec + 1.0e-9 * (double)t.tv_nsec; + return static_cast<double>(t.tv_sec) + 1.0e-9 * static_cast<double>(t.tv_nsec); } return NAN; } @@ -210,7 +210,7 @@ jwt_check_uri(const char *cdniuc, const char *uri) int uri_ct = strlen(uri); int buff_ct = uri_ct + 2; int err; - char *normal_uri = (char *)TSmalloc(buff_ct); + char *normal_uri = static_cast<char *>(TSmalloc(buff_ct)); memset(normal_uri, 0, buff_ct); err = normalize_uri(uri, uri_ct, normal_uri, buff_ct); @@ -276,7 +276,7 @@ renew_copy_raw(json_t *new_json, const char *name, json_t *old_json) void renew_copy_real(json_t *new_json, const char *name, double old) { - if (!isnan(old)) { + if (!std::isnan(old)) { json_object_set_new(new_json, name, json_real(old)); } } @@ -304,7 +304,7 @@ renew(struct jwt *jwt, const char *iss, cjose_jwk_t *jwk, const char *alg, const int buff_ct = uri_ct + 2; int normal_err; - char *normal_uri = (char *)TSmalloc(buff_ct); + char *normal_uri = static_cast<char *>(TSmalloc(buff_ct)); memset(normal_uri, 0, buff_ct); normal_err = normalize_uri(uri, uri_ct, normal_uri, buff_ct); @@ -317,7 +317,7 @@ renew(struct jwt *jwt, const char *iss, cjose_jwk_t *jwk, const char *alg, const char *path_string = nullptr; size_t path_size = normal_size + 1; - path_string = (char *)TSmalloc(path_size); + path_string = static_cast<char *>(TSmalloc(path_size)); memset(path_string, 0, path_size); PluginDebug("Renewing JWT. Stripped URI: %s", uri); diff --git a/plugins/experimental/uri_signing/match.cc b/plugins/experimental/uri_signing/match.cc index faea8953df..63adcd0aad 100644 --- a/plugins/experimental/uri_signing/match.cc +++ b/plugins/experimental/uri_signing/match.cc @@ -18,8 +18,8 @@ #include <regex.h> #include "common.h" -#include <stdbool.h> -#include <string.h> + +#include <cstring> bool match_hash(const char *needle, const char *haystack) @@ -32,9 +32,9 @@ match_regex(const char *pattern, const char *uri) { struct re_pattern_buffer pat_buff; - pat_buff.translate = 0; - pat_buff.fastmap = 0; - pat_buff.buffer = 0; + pat_buff.translate = nullptr; + pat_buff.fastmap = nullptr; + pat_buff.buffer = nullptr; pat_buff.allocated = 0; re_syntax_options = RE_SYNTAX_POSIX_MINIMAL_EXTENDED; @@ -49,7 +49,7 @@ match_regex(const char *pattern, const char *uri) } int match_ret; - match_ret = re_match(&pat_buff, uri, strlen(uri), 0, 0); + match_ret = re_match(&pat_buff, uri, strlen(uri), 0, nullptr); regfree(&pat_buff); return match_ret >= 0; diff --git a/plugins/experimental/uri_signing/normalize.cc b/plugins/experimental/uri_signing/normalize.cc index 98b4b04964..72bf60b13a 100644 --- a/plugins/experimental/uri_signing/normalize.cc +++ b/plugins/experimental/uri_signing/normalize.cc @@ -18,10 +18,10 @@ #include "normalize.h" #include "common.h" -#include <string.h> -#include <ctype.h> -#include <stdbool.h> -#include <stdio.h> +#include <cstring> +#include <cctype> + +#include <cstdio> /* Remove Dot Algorithm outlined in RFC3986 section 5.2.4 * Function writes normalizes path and writes to ret_buffer */ @@ -159,7 +159,7 @@ percent_decode(const char *uri, int uri_ct, char *decoded_uri, bool lower) int hexVal = 0; char decodeChar; sscanf(encodedVal, "%2x", &hexVal); - decodeChar = (char)hexVal; + decodeChar = static_cast<char>(hexVal); /* If encoded value is a reserved char, leave encoded*/ if (strchr(reserved_string, decodeChar)) { decoded_uri[i - offset] = uri[i]; diff --git a/plugins/experimental/uri_signing/parse.cc b/plugins/experimental/uri_signing/parse.cc index ddc665fb8d..2885c9f414 100644 --- a/plugins/experimental/uri_signing/parse.cc +++ b/plugins/experimental/uri_signing/parse.cc @@ -24,8 +24,8 @@ #include "timing.h" #include <cjose/cjose.h> #include <jansson.h> -#include <string.h> -#include <inttypes.h> +#include <cstring> +#include <cinttypes> #include <tscpp/util/PostScript.h> cjose_jws_t * @@ -83,7 +83,7 @@ get_jws_from_uri(const char *uri, size_t uri_ct, const char *paramName, char *st key_end = value; /* If the Parameter key is our target parameter name, attempt to import a JWS from the value. */ - if ((size_t)(key_end - key) == termination_ct && !strncmp(paramName, key, (size_t)(key_end - key))) { + if (static_cast<size_t>(key_end - key) == termination_ct && !strncmp(paramName, key, static_cast<size_t>(key_end - key))) { value_end = ++value; while (value_end != end && strchr(reserved_string, *value_end) == nullptr) { ++value_end; diff --git a/plugins/experimental/uri_signing/timing.h b/plugins/experimental/uri_signing/timing.h index 20768a58bf..bf1478114b 100644 --- a/plugins/experimental/uri_signing/timing.h +++ b/plugins/experimental/uri_signing/timing.h @@ -42,5 +42,6 @@ mark_timer(struct timer *t) if (clock_gettime(CLOCK_THREAD_CPUTIME_ID, &now)) { return 0; } - return (now.tv_sec - t->start.tv_sec) * (int64_t)1000000000 - (int64_t)t->start.tv_nsec + (int64_t)now.tv_nsec; + return (now.tv_sec - t->start.tv_sec) * static_cast<int64_t>(1000000000) - static_cast<int64_t>(t->start.tv_nsec) + + static_cast<int64_t>(now.tv_nsec); } diff --git a/plugins/experimental/uri_signing/unit_tests/uri_signing_test.cc b/plugins/experimental/uri_signing/unit_tests/uri_signing_test.cc index 036c23aa14..a2e882ddfc 100644 --- a/plugins/experimental/uri_signing/unit_tests/uri_signing_test.cc +++ b/plugins/experimental/uri_signing/unit_tests/uri_signing_test.cc @@ -690,7 +690,7 @@ TEST_CASE("6", "[AudTests]") json_error_t *err = nullptr; SECTION("Standard aud string match") { - json_t *raw = json_loads("{\"aud\": \"tester\"}", 0, err); + json_t *raw = json_loads(R"({"aud": "tester"})", 0, err); json_t *aud = json_object_get(raw, "aud"); REQUIRE(jwt_check_aud(aud, "tester")); json_decref(raw); @@ -698,7 +698,7 @@ TEST_CASE("6", "[AudTests]") SECTION("Standard aud array match") { - json_t *raw = json_loads("{\"aud\": [ \"foo\", \"bar\", \"tester\"]}", 0, err); + json_t *raw = json_loads(R"({"aud": [ "foo", "bar", "tester"]})", 0, err); json_t *aud = json_object_get(raw, "aud"); REQUIRE(jwt_check_aud(aud, "tester")); json_decref(raw); @@ -706,7 +706,7 @@ TEST_CASE("6", "[AudTests]") SECTION("Standard aud string mismatch") { - json_t *raw = json_loads("{\"aud\": \"foo\"}", 0, err); + json_t *raw = json_loads(R"({"aud": "foo"})", 0, err); json_t *aud = json_object_get(raw, "aud"); REQUIRE(!jwt_check_aud(aud, "tester")); json_decref(raw); @@ -714,7 +714,7 @@ TEST_CASE("6", "[AudTests]") SECTION("Standard aud array mismatch") { - json_t *raw = json_loads("{\"aud\": [\"foo\", \"bar\", \"foobar\"]}", 0, err); + json_t *raw = json_loads(R"({"aud": ["foo", "bar", "foobar"]})", 0, err); json_t *aud = json_object_get(raw, "aud"); REQUIRE(!jwt_check_aud(aud, "tester")); json_decref(raw); @@ -730,7 +730,7 @@ TEST_CASE("6", "[AudTests]") SECTION("Integer mixed into a passing aud array") { - json_t *raw = json_loads("{\"aud\": [1, \"foo\", \"bar\", \"tester\"]}", 0, err); + json_t *raw = json_loads(R"({"aud": [1, "foo", "bar", "tester"]})", 0, err); json_t *aud = json_object_get(raw, "aud"); REQUIRE(jwt_check_aud(aud, "tester")); json_decref(raw); @@ -738,7 +738,7 @@ TEST_CASE("6", "[AudTests]") SECTION("Case sensitive test for single string") { - json_t *raw = json_loads("{\"aud\": \"TESTer\"}", 0, err); + json_t *raw = json_loads(R"({"aud": "TESTer"})", 0, err); json_t *aud = json_object_get(raw, "aud"); REQUIRE(!jwt_check_aud(aud, "tester")); json_decref(raw); @@ -746,7 +746,7 @@ TEST_CASE("6", "[AudTests]") SECTION("Case sensitive test for array") { - json_t *raw = json_loads("{\"aud\": [1, \"foo\", \"bar\", \"Tester\"]}", 0, err); + json_t *raw = json_loads(R"({"aud": [1, "foo", "bar", "Tester"]})", 0, err); json_t *aud = json_object_get(raw, "aud"); REQUIRE(!jwt_check_aud(aud, "tester")); json_decref(raw); diff --git a/plugins/experimental/uri_signing/uri_signing.cc b/plugins/experimental/uri_signing/uri_signing.cc index 6f1096c6d0..32b40f5d68 100644 --- a/plugins/experimental/uri_signing/uri_signing.cc +++ b/plugins/experimental/uri_signing/uri_signing.cc @@ -25,10 +25,10 @@ #include <ts/remap.h> #include <ts/remap_version.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <inttypes.h> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <cinttypes> #include <cjose/cjose.h> @@ -95,7 +95,7 @@ add_cookie(TSCont cont, TSEvent event, void *edata) struct timer t; start_timer(&t); - TSHttpTxn txn = (TSHttpTxn)edata; + TSHttpTxn txn = static_cast<TSHttpTxn>(edata); char *cookie = static_cast<char *>(TSContDataGet(cont)); TSMBuffer buffer; TSMLoc hdr; @@ -235,7 +235,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) checkpoints[cpi++] = mark_timer(&t); strip_size = url_ct + 1; - strip_uri = (char *)TSmalloc(strip_size); + strip_uri = static_cast<char *>(TSmalloc(strip_size)); memset(strip_uri, 0, strip_size); jws = get_jws_from_uri(url, url_ct, package, strip_uri, strip_size, &strip_ct); @@ -248,8 +248,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) } else { /* There has been a JWS found in the url */ /* Strip the token from the URL for upstream if configured to do so */ - if (config_strip_token((struct config *)ih)) { - if ((int)strip_ct != url_ct) { + if (config_strip_token(static_cast<struct config *>(ih))) { + if (static_cast<int>(strip_ct) != url_ct) { int map_url_ct = 0; char *map_url = nullptr; char *map_strip_uri = nullptr; @@ -258,7 +258,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) PluginDebug("Stripping Token from requestUrl: %s", map_url); int map_strip_size = map_url_ct + 1; - map_strip_uri = (char *)TSmalloc(map_strip_size); + map_strip_uri = static_cast<char *>(TSmalloc(map_strip_size)); memset(map_strip_uri, 0, map_strip_size); size_t map_strip_ct = 0; @@ -290,7 +290,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) } } /* Check auth_dir and pass through if configured */ - if (uri_matches_auth_directive((struct config *)ih, url, url_ct)) { + if (uri_matches_auth_directive(static_cast<struct config *>(ih), url, url_ct)) { PluginDebug("Auth directive matched for %.*s", url_ct, url); if (url != nullptr) { TSfree((void *)url); @@ -310,7 +310,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) checkpoints[cpi++] = mark_timer(&t); } - jwt = validate_jws(jws, (struct config *)ih, strip_uri, strip_ct); + jwt = validate_jws(jws, static_cast<struct config *>(ih), strip_uri, strip_ct); cjose_jws_release(jws); if (cpi < max_cpi) { @@ -319,7 +319,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) if (jwt || check_cookies(checked_cookies)) { /* There has been a validated JWT found in either the cookie or url */ - struct signer *signer = config_signer((struct config *)ih); + struct signer *signer = config_signer(static_cast<struct config *>(ih)); char *cookie = renew(jwt, signer->issuer, signer->jwk, signer->alg, package, strip_uri, strip_ct); jwt_delete(jwt); diff --git a/plugins/experimental/url_sig/url_sig.cc b/plugins/experimental/url_sig/url_sig.cc index d81c7ab4fb..b45500db81 100644 --- a/plugins/experimental/url_sig/url_sig.cc +++ b/plugins/experimental/url_sig/url_sig.cc @@ -25,21 +25,20 @@ #include "url_sig.h" -#include <inttypes.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include <cinttypes> +#include <cstdio> +#include <cstdlib> +#include <cstring> #include <sys/types.h> -#include <time.h> +#include <ctime> #include <openssl/hmac.h> #include <openssl/evp.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <limits.h> -#include <ctype.h> -#include <stdint.h> -#include <stdbool.h> +#include <climits> +#include <cctype> +#include <cstdint> #ifdef HAVE_PCRE_PCRE_H #include <pcre/pcre.h> @@ -191,7 +190,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s snprintf(&cfg->keys[keynum][0], MAX_KEY_LEN, "%s", value); } else if (strncmp(line, "error_url", 9) == 0) { if (atoi(value)) { - cfg->err_status = TSHttpStatus(atoi(value)); + cfg->err_status = static_cast<TSHttpStatus>(atoi(value)); } value += 3; while (isspace(*value)) { @@ -281,7 +280,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_s void TSRemapDeleteInstance(void *ih) { - free_cfg((struct config *)ih); + free_cfg(static_cast<struct config *>(ih)); } static void @@ -492,7 +491,8 @@ urlParse(char const *const url_in, char *anchor, char *new_path_seg, int new_pat oob = 1; break; } - if (!fixedBufferWrite(&new_url_end, &new_url_len_left, (char *)decoded_string, strlen((char *)decoded_string))) { + if (!fixedBufferWrite(&new_url_end, &new_url_len_left, reinterpret_cast<char *>(decoded_string), + strlen(reinterpret_cast<char *>(decoded_string)))) { oob = 1; break; } @@ -503,7 +503,8 @@ urlParse(char const *const url_in, char *anchor, char *new_path_seg, int new_pat continue; } else if (i == numtoks - 2 && sig_anchor == nullptr) { - if (!fixedBufferWrite(&new_url_end, &new_url_len_left, (char *)decoded_string, strlen((char *)decoded_string))) { + if (!fixedBufferWrite(&new_url_end, &new_url_len_left, reinterpret_cast<char *>(decoded_string), + strlen(reinterpret_cast<char *>(decoded_string)))) { oob = 1; break; } @@ -534,7 +535,7 @@ urlParse(char const *const url_in, char *anchor, char *new_path_seg, int new_pat TSRemapStatus TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) { - const struct config *cfg = (const struct config *)ih; + const struct config *cfg = static_cast<const struct config *>(ih); int url_len = 0; int current_url_len = 0; @@ -693,7 +694,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) cp = strstr(query, EXP_QSTRING "="); if (cp != nullptr) { cp += strlen(EXP_QSTRING) + 1; - if (sscanf(cp, "%" SCNu64, &expiration) != 1 || (time_t)expiration < time(nullptr)) { + if (sscanf(cp, "%" SCNu64, &expiration) != 1 || static_cast<time_t>(expiration) < time(nullptr)) { err_log(url, "Invalid expiration, or expired"); goto deny; } @@ -806,8 +807,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) /* calculate the expected the signature with the right algorithm */ switch (algorithm) { case USIG_HMAC_SHA1: - HMAC(EVP_sha1(), (const unsigned char *)cfg->keys[keyindex], strlen(cfg->keys[keyindex]), - (const unsigned char *)signed_part, strlen(signed_part), sig, &sig_len); + HMAC(EVP_sha1(), reinterpret_cast<const unsigned char *>(cfg->keys[keyindex]), strlen(cfg->keys[keyindex]), + reinterpret_cast<const unsigned char *>(signed_part), strlen(signed_part), sig, &sig_len); if (sig_len != SHA1_SIG_SIZE) { Dbg(dbg_ctl, "sig_len: %d", sig_len); err_log(url, "Calculated sig len != SHA1_SIG_SIZE !"); @@ -816,8 +817,8 @@ TSRemapDoRemap(void *ih, TSHttpTxn txnp, TSRemapRequestInfo *rri) break; case USIG_HMAC_MD5: - HMAC(EVP_md5(), (const unsigned char *)cfg->keys[keyindex], strlen(cfg->keys[keyindex]), - (const unsigned char *)signed_part, strlen(signed_part), sig, &sig_len); + HMAC(EVP_md5(), reinterpret_cast<const unsigned char *>(cfg->keys[keyindex]), strlen(cfg->keys[keyindex]), + reinterpret_cast<const unsigned char *>(signed_part), strlen(signed_part), sig, &sig_len); if (sig_len != MD5_SIG_SIZE) { Dbg(dbg_ctl, "sig_len: %d", sig_len); err_log(url, "Calculated sig len != MD5_SIG_SIZE !"); diff --git a/plugins/experimental/wasm/ats_context.cc b/plugins/experimental/wasm/ats_context.cc index 1478a4da73..ec55a0144b 100644 --- a/plugins/experimental/wasm/ats_context.cc +++ b/plugins/experimental/wasm/ats_context.cc @@ -41,13 +41,13 @@ async_handler(TSCont cont, TSEvent event, void *edata) { // information for the handler TSHttpTxn txn = static_cast<TSHttpTxn>(edata); - AsyncInfo *ai = (AsyncInfo *)TSContDataGet(cont); + AsyncInfo *ai = static_cast<AsyncInfo *>(TSContDataGet(cont)); uint32_t token = ai->token; Context *root_context = ai->root_context; Wasm *wasm = root_context->wasm(); // variables to be used in handler - TSEvent result = (TSEvent)(FETCH_EVENT_ID_BASE + 1); + TSEvent result = static_cast<TSEvent>(FETCH_EVENT_ID_BASE + 1); const void *body = nullptr; size_t body_size = 0; TSMBuffer hdr_buf = nullptr; diff --git a/plugins/experimental/wasm/ats_context.h b/plugins/experimental/wasm/ats_context.h index 811e1e17f1..b859f63152 100644 --- a/plugins/experimental/wasm/ats_context.h +++ b/plugins/experimental/wasm/ats_context.h @@ -251,7 +251,7 @@ public: cr_hdr_loc_ = nullptr; cr_body_ = nullptr; cr_body_size_ = 0; - cr_result_ = (TSEvent)(FETCH_EVENT_ID_BASE + 1); + cr_result_ = static_cast<TSEvent>(FETCH_EVENT_ID_BASE + 1); } // transform result functions @@ -352,7 +352,7 @@ private: BufferBase buffer_; // Call result - TSEvent cr_result_ = (TSEvent)(FETCH_EVENT_ID_BASE + 1); + TSEvent cr_result_ = static_cast<TSEvent>(FETCH_EVENT_ID_BASE + 1); const void *cr_body_ = nullptr; size_t cr_body_size_ = 0; TSMBuffer cr_hdr_buf_ = nullptr; diff --git a/plugins/experimental/wasm/wasm_main.cc b/plugins/experimental/wasm/wasm_main.cc index f1cab0cb91..016e42663f 100644 --- a/plugins/experimental/wasm/wasm_main.cc +++ b/plugins/experimental/wasm/wasm_main.cc @@ -262,8 +262,8 @@ transform_entry(TSCont contp, TSEvent ev, void *edata) TSVIO input_vio; ats_wasm::TransformInfo *ti; - event = (int)ev; - ti = (ats_wasm::TransformInfo *)TSContDataGet(contp); + event = static_cast<int>(ev); + ti = static_cast<ats_wasm::TransformInfo *>(TSContDataGet(contp)); Dbg(ats_wasm::dbg_ctl, "[%s] begin transform entry", __FUNCTION__); if (TSVConnClosedGet(contp)) { diff --git a/proxy/Plugin.h b/proxy/Plugin.h index c19e7e39b4..78b25de6a0 100644 --- a/proxy/Plugin.h +++ b/proxy/Plugin.h @@ -26,7 +26,7 @@ #include <string> #include "tscore/List.h" -using PluginDynamicReloadMode = enum { RELOAD_OFF, RELOAD_ON, RELOAD_COUNT }; +enum PluginDynamicReloadMode { RELOAD_OFF, RELOAD_ON, RELOAD_COUNT }; // read records.yaml to parse plugin related configs void parsePluginConfig();