diff --git a/example/plugins/c-api/ssl_preaccept/ssl_preaccept.cc b/example/plugins/c-api/ssl_preaccept/ssl_preaccept.cc index d5805844f14..be662ad29b1 100644 --- a/example/plugins/c-api/ssl_preaccept/ssl_preaccept.cc +++ b/example/plugins/c-api/ssl_preaccept/ssl_preaccept.cc @@ -39,7 +39,7 @@ namespace { -typedef std::pair IpRange; +using IpRange = std::pair; using IpRangeQueue = std::deque; IpRangeQueue ClientBlindTunnelIp; diff --git a/iocore/cache/test/main.cc b/iocore/cache/test/main.cc index 7c57a0cc638..3585ab68bea 100644 --- a/iocore/cache/test/main.cc +++ b/iocore/cache/test/main.cc @@ -210,7 +210,7 @@ CacheWriteTest::start_test(int event, void *e) } SET_HANDLER(&CacheWriteTest::write_event); - cacheProcessor.open_write(this, 0, &key, (CacheHTTPHdr *)this->info.request_get(), old_info); + cacheProcessor.open_write(this, 0, &key, static_cast(this->info.request_get()), old_info); return 0; } @@ -271,7 +271,7 @@ CacheReadTest::start_test(int event, void *e) key = generate_key(this->info); SET_HANDLER(&CacheReadTest::read_event); - cacheProcessor.open_read(this, &key, (CacheHTTPHdr *)this->info.request_get(), &this->params); + cacheProcessor.open_read(this, &key, static_cast(this->info.request_get()), &this->params); return 0; } diff --git a/iocore/net/SSLSessionCache.cc b/iocore/net/SSLSessionCache.cc index 8447e78ee2c..7f7def5fd65 100644 --- a/iocore/net/SSLSessionCache.cc +++ b/iocore/net/SSLSessionCache.cc @@ -310,7 +310,7 @@ SSLOriginSessionCache::~SSLOriginSessionCache() } void -SSLOriginSessionCache::insert_session(std::string lookup_key, SSL_SESSION *sess) +SSLOriginSessionCache::insert_session(const std::string &lookup_key, SSL_SESSION *sess) { if (is_debug_tag_set("ssl.origin_session_cache")) { Debug("ssl.origin_session_cache", "insert session: %s = %p", lookup_key.c_str(), sess); @@ -327,7 +327,7 @@ SSLOriginSessionCache::insert_session(std::string lookup_key, SSL_SESSION *sess) } void -SSLOriginSessionCache::remove_session(std::string lookup_key) +SSLOriginSessionCache::remove_session(const std::string &lookup_key) { if (is_debug_tag_set("ssl.origin_session_cache")) { Debug("ssl.origin_session_cache", "remove session: %s", lookup_key.c_str()); @@ -342,7 +342,7 @@ SSLOriginSessionCache::remove_session(std::string lookup_key) } SSL_SESSION * -SSLOriginSessionCache::get_session(std::string lookup_key) +SSLOriginSessionCache::get_session(const std::string &lookup_key) { if (is_debug_tag_set("ssl.origin_session_cache")) { Debug("ssl.origin_session_cache", "get session: %s", lookup_key.c_str()); diff --git a/iocore/net/SSLSessionCache.h b/iocore/net/SSLSessionCache.h index 4e0fc084bfc..270f2a13497 100644 --- a/iocore/net/SSLSessionCache.h +++ b/iocore/net/SSLSessionCache.h @@ -205,9 +205,9 @@ class SSLOriginSessionCache SSLOriginSessionCache(); ~SSLOriginSessionCache(); - void insert_session(std::string lookup_key, SSL_SESSION *sess); - void remove_session(std::string lookup_key); - SSL_SESSION *get_session(std::string lookup_key); + void insert_session(const std::string &lookup_key, SSL_SESSION *sess); + void remove_session(const std::string &lookup_key); + SSL_SESSION *get_session(const std::string &lookup_key); private: mutable std::shared_mutex mutex; diff --git a/plugins/background_fetch/background_fetch.cc b/plugins/background_fetch/background_fetch.cc index 13aaff4a15e..cdffeee2039 100644 --- a/plugins/background_fetch/background_fetch.cc +++ b/plugins/background_fetch/background_fetch.cc @@ -55,7 +55,7 @@ static const std::array FILTER_HEADERS{ // Hold the global background fetch state. This is currently shared across all // configurations, as a singleton. ToDo: Would it ever make sense to do this // per remap rule? Maybe for per-remap logging ?? -typedef std::unordered_map OutstandingRequests; +using OutstandingRequests = std::unordered_map; class BgFetchState { diff --git a/plugins/cache_range_requests/cache_range_requests.cc b/plugins/cache_range_requests/cache_range_requests.cc index cf2e04fc7c7..c53c868bfe7 100644 --- a/plugins/cache_range_requests/cache_range_requests.cc +++ b/plugins/cache_range_requests/cache_range_requests.cc @@ -42,10 +42,10 @@ namespace { -typedef enum parent_select_mode { +using parent_select_mode_t = enum parent_select_mode { PS_DEFAULT, // Default ATS parent selection mode PS_CACHEKEY_URL, // Set parent selection url to cache_key url -} parent_select_mode_t; +}; struct pluginconfig { parent_select_mode_t ps_mode{PS_DEFAULT}; diff --git a/plugins/escalate/escalate.cc b/plugins/escalate/escalate.cc index 32663bdb447..71bc3944b7b 100644 --- a/plugins/escalate/escalate.cc +++ b/plugins/escalate/escalate.cc @@ -49,7 +49,7 @@ struct EscalationState { std::string target; }; - typedef std::map StatusMapType; + using StatusMapType = std::map; EscalationState() { diff --git a/plugins/esi/esi.cc b/plugins/esi/esi.cc index b92da0c5224..9d223b5f997 100644 --- a/plugins/esi/esi.cc +++ b/plugins/esi/esi.cc @@ -609,7 +609,7 @@ cacheNodeList(ContData *cont_data) string body(""); cont_data->esi_proc->packNodeList(body, false); char buf[64]; - snprintf(buf, 64, "%s: %d\r\n\r\n", TS_MIME_FIELD_CONTENT_LENGTH, (int)body.size()); + snprintf(buf, 64, "%s: %d\r\n\r\n", TS_MIME_FIELD_CONTENT_LENGTH, static_cast(body.size())); post_request.append(buf); post_request.append(body); diff --git a/plugins/esi/test/parser_test.cc b/plugins/esi/test/parser_test.cc index c200eeb2cb3..f2b3873f3c9 100644 --- a/plugins/esi/test/parser_test.cc +++ b/plugins/esi/test/parser_test.cc @@ -115,7 +115,7 @@ main() { cout << endl << "==================== Test 6: Invalid Quoted URL test " << endl; EsiParser parser("parser_test", &Debug, &Error); - string input_data = ""; + string input_data = R"()"; DocNodeList node_list; assert(parser.parseChunk(input_data, node_list) == false); diff --git a/plugins/esi/test/utils_test.cc b/plugins/esi/test/utils_test.cc index 9c1e059d875..924ff936dc4 100644 --- a/plugins/esi/test/utils_test.cc +++ b/plugins/esi/test/utils_test.cc @@ -75,7 +75,7 @@ main() const char *expected_strs4[] = {"pos", " SKY BAR ", "spaceid", "12123", nullptr}; checkAttributes("test4", attr_list, expected_strs4); - string str5("a=\"b & xyz\"&c=d&e=f&g=h\""); + string str5(R"(a="b & xyz"&c=d&e=f&g=h")"); Utils::parseAttributes(str5, attr_list, "&"); const char *expected_strs5[] = {"a", "b & xyz", "c", "d", "e", "f", nullptr}; checkAttributes("test5", attr_list, expected_strs5); @@ -91,9 +91,9 @@ main() checkAttributes("test7", attr_list, expected_strs7); const char *escaped_sequence = R"({\"site-attribute\":\"content=no_expandable; ajax_cert_expandable\"})"; - string str8("pos=\"FPM1\" spaceid=96584352 extra_mime=\""); + string str8(R"(pos="FPM1" spaceid=96584352 extra_mime=")"); str8.append(escaped_sequence); - str8.append("\" foo=bar a=\"b\""); + str8.append(R"(" foo=bar a="b")"); const char *expected_strs8[] = {"pos", "FPM1", "spaceid", "96584352", "extra_mime", escaped_sequence, "foo", "bar", "a", "b", nullptr}; Utils::parseAttributes(str8, attr_list); diff --git a/plugins/experimental/access_control/utils.cc b/plugins/experimental/access_control/utils.cc index cd212d11506..53911e463b3 100644 --- a/plugins/experimental/access_control/utils.cc +++ b/plugins/experimental/access_control/utils.cc @@ -240,7 +240,7 @@ cryptoMessageDigestGet(const char *digestType, const char *data, size_t dataLen, #else ctx = HMAC_CTX_new(); #endif - if (!HMAC_Init_ex(ctx, key, keyLen, md, NULL)) { + if (!HMAC_Init_ex(ctx, key, keyLen, md, nullptr)) { AccessControlError("failed to create EVP message digest context: %s", cryptoErrStr(buffer, sizeof(buffer))); goto err; } diff --git a/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc b/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc index 9033f4e9e2d..b5063e90ad8 100644 --- a/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc +++ b/plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc @@ -75,11 +75,11 @@ static int OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = 500; static bool global_init = false; -typedef struct _RequestData { +using RequestData = struct _RequestData { TSHttpTxn txnp; int wl_retry; // write lock failure retry count std::string req_url; -} RequestData; +}; static int add_redirect_header(TSMBuffer &bufp, TSMLoc &hdr_loc, const std::string &location) diff --git a/plugins/experimental/cookie_remap/cookie_remap.cc b/plugins/experimental/cookie_remap/cookie_remap.cc index 5515497ca00..ceef473d55f 100644 --- a/plugins/experimental/cookie_remap/cookie_remap.cc +++ b/plugins/experimental/cookie_remap/cookie_remap.cc @@ -811,8 +811,8 @@ class op TSHttpStatus else_status = TS_HTTP_STATUS_NONE; }; -typedef std::pair StringPair; -using OpMap = std::vector; +using StringPair = std::pair; +using OpMap = std::vector; //---------------------------------------------------------------------------- static bool diff --git a/plugins/experimental/magick/magick.cc b/plugins/experimental/magick/magick.cc index d320d017045..24cd0f584c8 100644 --- a/plugins/experimental/magick/magick.cc +++ b/plugins/experimental/magick/magick.cc @@ -479,7 +479,7 @@ struct ImageTransform : TransformationPlugin { { TSDebug(PLUGIN_TAG, "handleInputComplete"); - threadPool_.emplace_back([this](void) { + threadPool_.emplace_back([this]() { magick::Image image; magick::Exception exception; magick::Wand wand; diff --git a/plugins/experimental/maxmind_acl/mmdb.cc b/plugins/experimental/maxmind_acl/mmdb.cc index 95ab3b0b4fa..7c1d7c3c055 100644 --- a/plugins/experimental/maxmind_acl/mmdb.cc +++ b/plugins/experimental/maxmind_acl/mmdb.cc @@ -150,8 +150,8 @@ Acl::loaddeny(const YAML::Node &denyNode) YAML::Node country = denyNode["country"]; if (!country.IsNull()) { if (country.IsSequence()) { - for (std::size_t i = 0; i < country.size(); i++) { - allow_country.insert_or_assign(country[i].as(), false); + for (auto &&i : country) { + allow_country.insert_or_assign(i.as(), false); } } else { TSDebug(PLUGIN_NAME, "Invalid country code allow list yaml"); @@ -170,9 +170,9 @@ Acl::loaddeny(const YAML::Node &denyNode) if (!ip.IsNull()) { if (ip.IsSequence()) { // Do IP Deny processing - for (std::size_t i = 0; i < ip.size(); i++) { + for (auto &&i : ip) { IpAddr min, max; - ats_ip_range_parse(std::string_view{ip[i].as()}, min, max); + ats_ip_range_parse(std::string_view{i.as()}, min, max); deny_ip_map.fill(min, max, nullptr); TSDebug(PLUGIN_NAME, "loading ip: valid: %d, fam %d ", min.isValid(), min.family()); } @@ -230,8 +230,8 @@ Acl::loadallow(const YAML::Node &allowNode) YAML::Node country = allowNode["country"]; if (!country.IsNull()) { if (country.IsSequence()) { - for (std::size_t i = 0; i < country.size(); i++) { - allow_country.insert_or_assign(country[i].as(), true); + for (auto &&i : country) { + allow_country.insert_or_assign(i.as(), true); } } else { @@ -251,9 +251,9 @@ Acl::loadallow(const YAML::Node &allowNode) if (!ip.IsNull()) { if (ip.IsSequence()) { // Do IP Allow processing - for (std::size_t i = 0; i < ip.size(); i++) { + for (auto &&i : ip) { IpAddr min, max; - ats_ip_range_parse(std::string_view{ip[i].as()}, min, max); + ats_ip_range_parse(std::string_view{i.as()}, min, max); allow_ip_map.fill(min, max, nullptr); TSDebug(PLUGIN_NAME, "loading ip: valid: %d, fam %d ", min.isValid(), min.family()); } @@ -290,9 +290,9 @@ Acl::parseregex(const YAML::Node ®ex, bool allow) if (!regex.IsNull()) { if (regex.IsSequence()) { // Parse each country-regex pair - for (std::size_t i = 0; i < regex.size(); i++) { + for (const auto &i : regex) { plugin_regex temp; - auto temprule = regex[i].as>(); + auto temprule = i.as>(); temp._regex_s = temprule.back(); const char *error; int erroffset; @@ -311,11 +311,11 @@ Acl::parseregex(const YAML::Node ®ex, bool allow) } for (std::size_t y = 0; y < temprule.size() - 1; y++) { - TSDebug(PLUGIN_NAME, "Adding regex: %s, for country: %s", temp._regex_s.c_str(), regex[i][y].as().c_str()); + TSDebug(PLUGIN_NAME, "Adding regex: %s, for country: %s", temp._regex_s.c_str(), i[y].as().c_str()); if (allow) { - allow_regex[regex[i][y].as()].push_back(temp); + allow_regex[i[y].as()].push_back(temp); } else { - deny_regex[regex[i][y].as()].push_back(temp); + deny_regex[i[y].as()].push_back(temp); } } } @@ -423,7 +423,7 @@ Acl::eval(TSRemapRequestInfo *rri, TSHttpTxn txnp) return ret; } - if (NULL != entry_data_list) { + if (nullptr != entry_data_list) { // This is useful to be able to dump out a full record of a // mmdb entry for debug. Enabling can help if you want to figure // out how to add new fields @@ -481,7 +481,7 @@ Acl::eval(TSRemapRequestInfo *rri, TSHttpTxn txnp) break; } - if (NULL != entry_data_list) { + if (nullptr != entry_data_list) { MMDB_free_entry_data_list(entry_data_list); } @@ -498,7 +498,7 @@ Acl::eval_country(MMDB_entry_data_s *entry_data, const char *path, int path_len) bool ret = false; bool allow = default_allow; char *output = nullptr; - output = (char *)malloc((sizeof(char) * entry_data->data_size)); + output = static_cast(malloc((sizeof(char) * entry_data->data_size))); strncpy(output, entry_data->utf8_string, entry_data->data_size); TSDebug(PLUGIN_NAME, "This IP Country Code: %s", output); auto exists = allow_country.count(output); diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc index 532c2bb4b31..e8197ec0608 100644 --- a/plugins/experimental/memcache/tsmemcache.cc +++ b/plugins/experimental/memcache/tsmemcache.cc @@ -132,7 +132,7 @@ MCAccept::main_event(int event, void *data) } return EVENT_CONT; } else { - Fatal("tsmemcache accept received fatal error: errno = %d", -((int)(intptr_t)data)); + Fatal("tsmemcache accept received fatal error: errno = %d", -(static_cast((intptr_t)data))); return EVENT_CONT; } } @@ -224,10 +224,10 @@ MC::add_binary_header(uint16_t err, uint8_t hdr_len, uint16_t key_len, uint32_t r.response.magic = static_cast(PROTOCOL_BINARY_RES); r.response.opcode = binary_header.request.opcode; - r.response.keylen = (uint16_t)htons(key_len); + r.response.keylen = static_cast(htons(key_len)); r.response.extlen = hdr_len; r.response.datatype = static_cast(PROTOCOL_BINARY_RAW_BYTES); - r.response.status = (uint16_t)htons(err); + r.response.status = static_cast(htons(err)); r.response.bodylen = htonl(body_len); r.response.opaque = binary_header.request.opaque; r.response.cas = ink_hton64(header.cas); diff --git a/plugins/experimental/mysql_remap/mysql_remap.cc b/plugins/experimental/mysql_remap/mysql_remap.cc index f2c69b26486..2d1551af6e1 100644 --- a/plugins/experimental/mysql_remap/mysql_remap.cc +++ b/plugins/experimental/mysql_remap/mysql_remap.cc @@ -28,9 +28,9 @@ MYSQL mysql; -typedef struct { +using my_data = struct { char *query; -} my_data; +}; bool do_mysql_remap(TSCont contp, TSHttpTxn txnp) diff --git a/plugins/experimental/parent_select/consistenthash.cc b/plugins/experimental/parent_select/consistenthash.cc index 91daf57605f..a0d3578bfe6 100644 --- a/plugins/experimental/parent_select/consistenthash.cc +++ b/plugins/experimental/parent_select/consistenthash.cc @@ -55,7 +55,7 @@ constexpr std::string_view hash_key_path_fragment = "path+fragment"; constexpr std::string_view hash_key_cache = "cache_key"; PLHostRecord * -chash_lookup(std::shared_ptr ring, uint64_t hash_key, ATSConsistentHashIter *iter, bool *wrapped, +chash_lookup(const std::shared_ptr &ring, uint64_t hash_key, ATSConsistentHashIter *iter, bool *wrapped, ATSHash64Sip24 *hash, bool *hash_init, bool *mapWrapped, uint64_t sm_id) { PLHostRecord *host_rec = nullptr; diff --git a/plugins/experimental/parent_select/consistenthash_config.cc b/plugins/experimental/parent_select/consistenthash_config.cc index 77351efaebe..0f04eb7dcb6 100644 --- a/plugins/experimental/parent_select/consistenthash_config.cc +++ b/plugins/experimental/parent_select/consistenthash_config.cc @@ -44,7 +44,7 @@ #include "consistenthash_config.h" -void loadConfigFile(const std::string fileName, std::stringstream &doc, std::unordered_set &include_once); +void loadConfigFile(const std::string &fileName, std::stringstream &doc, std::unordered_set &include_once); // createStrategy creates and initializes a Consistent Hash strategy from the given YAML node. // Caller takes ownership of the returned pointer, and must call delete on it. @@ -108,9 +108,8 @@ createStrategiesFromFile(const char *file) // std::map> strategies_map strategiesMap; - for (unsigned int i = 0; i < strategies.size(); ++i) { - YAML::Node strategy = strategies[i]; - auto name = strategy["strategy"].as(); + for (auto &&strategy : strategies) { + auto name = strategy["strategy"].as(); TSDebug(PLUGIN_NAME, "createStrategiesFromFile filename %s got strategy %s.", basename, name.c_str()); auto policy = strategy["policy"]; if (!policy) { @@ -118,7 +117,7 @@ createStrategiesFromFile(const char *file) return strategies_map(); } TSDebug(PLUGIN_NAME, "createStrategiesFromFile filename %s got strategy %s checked policy.", basename, name.c_str()); - auto policy_value = policy.Scalar(); + const auto &policy_value = policy.Scalar(); if (policy_value != consistent_hash) { TSError("[%s] strategy named '%s' has unsupported policy '%s'.", PLUGIN_NAME, name.c_str(), policy_value.c_str()); return strategies_map(); @@ -149,7 +148,7 @@ createStrategiesFromFile(const char *file) * 'strategy' yaml file would then normally have the '#include hosts.yml' in it's begining. */ void -loadConfigFile(const std::string fileName, std::stringstream &doc, std::unordered_set &include_once) +loadConfigFile(const std::string &fileName, std::stringstream &doc, std::unordered_set &include_once) { const char *sep = " \t"; char *tok, *last; @@ -187,8 +186,8 @@ loadConfigFile(const std::string fileName, std::stringstream &doc, std::unordere std::sort(files.begin(), files.end(), [](const std::string_view lhs, const std::string_view rhs) { return lhs.compare(rhs) < 0; }); - for (uint32_t i = 0; i < files.size(); i++) { - std::ifstream file(fileName + "/" + files[i].data()); + for (auto &f : files) { + std::ifstream file(fileName + "/" + f.data()); if (file.is_open()) { while (std::getline(file, line)) { if (line[0] == '#') { @@ -198,7 +197,7 @@ loadConfigFile(const std::string fileName, std::stringstream &doc, std::unordere } file.close(); } else { - throw std::invalid_argument("Unable to open and read '" + fileName + "/" + files[i].data() + "'"); + throw std::invalid_argument("Unable to open and read '" + fileName + "/" + f.data() + "'"); } } } diff --git a/plugins/experimental/parent_select/healthstatus.cc b/plugins/experimental/parent_select/healthstatus.cc index 864927ba088..4cb73367d74 100644 --- a/plugins/experimental/parent_select/healthstatus.cc +++ b/plugins/experimental/parent_select/healthstatus.cc @@ -45,8 +45,7 @@ void PLNextHopHealthStatus::insert(std::vector> &hosts) { - for (uint32_t ii = 0; ii < hosts.size(); ii++) { - std::shared_ptr h = hosts[ii]; + for (auto h : hosts) { for (auto protocol = h->protocols.begin(); protocol != h->protocols.end(); ++protocol) { const std::string host_port = h->getHostPort((*protocol)->port); host_map.emplace(std::make_pair(host_port, h)); diff --git a/plugins/experimental/parent_select/parent_select.cc b/plugins/experimental/parent_select/parent_select.cc index 31519013469..a10de675804 100644 --- a/plugins/experimental/parent_select/parent_select.cc +++ b/plugins/experimental/parent_select/parent_select.cc @@ -371,19 +371,18 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuff, int errbuff TSDebug(PLUGIN_NAME, "'%s' '%s' successfully created strategies in file %s num %d", remap_from, remap_to, config_file_path, int(file_strategies.size())); - std::unique_ptr strategy; + std::unique_ptr new_strategy; - for (auto it = file_strategies.begin(); it != file_strategies.end(); it++) { - TSDebug(PLUGIN_NAME, "'%s' '%s' TSRemapNewInstance strategy file had strategy named '%s'", remap_from, remap_to, - it->first.c_str()); - if (strncmp(strategy_name, it->first.c_str(), strlen(strategy_name)) != 0) { + for (auto &[name, strategy] : file_strategies) { + TSDebug(PLUGIN_NAME, "'%s' '%s' TSRemapNewInstance strategy file had strategy named '%s'", remap_from, remap_to, name.c_str()); + if (strncmp(strategy_name, name.c_str(), strlen(strategy_name)) != 0) { continue; } - TSDebug(PLUGIN_NAME, "'%s' '%s' TSRemapNewInstance using '%s'", remap_from, remap_to, it->first.c_str()); - strategy = std::move(it->second); + TSDebug(PLUGIN_NAME, "'%s' '%s' TSRemapNewInstance using '%s'", remap_from, remap_to, name.c_str()); + new_strategy = std::move(strategy); } - if (strategy.get() == nullptr) { + if (new_strategy.get() == nullptr) { TSDebug(PLUGIN_NAME, "'%s' '%s' TSRemapNewInstance strategy '%s' not found in file '%s'", remap_from, remap_to, strategy_name, config_file_path); return TS_ERROR; @@ -391,7 +390,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuff, int errbuff TSDebug(PLUGIN_NAME, "'%s' '%s' TSRemapNewInstance successfully loaded strategy '%s' from '%s'.", remap_from, remap_to, strategy_name, config_file_path); - *ih = static_cast(strategy.release()); + *ih = static_cast(new_strategy.release()); return TS_SUCCESS; } diff --git a/plugins/experimental/parent_select/strategy.cc b/plugins/experimental/parent_select/strategy.cc index 7fc7407b4bb..f3fb12523d9 100644 --- a/plugins/experimental/parent_select/strategy.cc +++ b/plugins/experimental/parent_select/strategy.cc @@ -125,8 +125,8 @@ PLNextHopSelectionStrategy::Init(const YAML::Node &n) PL_NH_Error("Error in the response_codes definition for the strategy named '%s', skipping response_codes.", strategy_name.c_str()); } else { - for (unsigned int k = 0; k < resp_codes_node.size(); ++k) { - auto code = resp_codes_node[k].as(); + for (auto &&k : resp_codes_node) { + auto code = k.as(); if (code > 300 && code < 599) { resp_codes.add(code); } else { @@ -192,7 +192,7 @@ PLNextHopSelectionStrategy::Init(const YAML::Node &n) host_rec->host_index = hst; if (TSHostnameIsSelf(host_rec->hostname.c_str(), host_rec->hostname.size()) == TS_SUCCESS) { TSHostStatusSet(host_rec->hostname.c_str(), host_rec->hostname.size(), TSHostStatus::TS_HOST_STATUS_DOWN, 0, - (unsigned int)TS_HOST_STATUS_SELF_DETECT); + static_cast(TS_HOST_STATUS_SELF_DETECT)); } hosts_inner.push_back(std::move(host_rec)); num_parents++; @@ -220,8 +220,8 @@ PLNextHopSelectionStrategy::nextHopExists(TSHttpTxn txnp) const int64_t sm_id = TSHttpTxnIdGet(txnp); for (uint32_t gg = 0; gg < groups; gg++) { - for (uint32_t hh = 0; hh < host_groups[gg].size(); hh++) { - PLHostRecord *p = host_groups[gg][hh].get(); + for (auto &hh : host_groups[gg]) { + PLHostRecord *p = hh.get(); if (p->available) { PL_NH_Debug(PL_NH_DEBUG_TAG, "[%" PRIu64 "] found available next hop %.*s", sm_id, int(p->hostname.size()), p->hostname.c_str()); @@ -295,8 +295,8 @@ template <> struct convert { if (proto.Type() != YAML::NodeType::Sequence) { throw std::invalid_argument("Invalid host protocol definition, expected a sequence."); } else { - for (unsigned int ii = 0; ii < proto.size(); ii++) { - YAML::Node protocol_node = proto[ii]; + for (auto &&ii : proto) { + YAML::Node protocol_node = ii; std::shared_ptr pr = std::make_shared(protocol_node.as()); nh.protocols.push_back(std::move(pr)); } diff --git a/plugins/experimental/rate_limit/rate_limit.cc b/plugins/experimental/rate_limit/rate_limit.cc index 37d8c65b5b1..f9c0835de20 100644 --- a/plugins/experimental/rate_limit/rate_limit.cc +++ b/plugins/experimental/rate_limit/rate_limit.cc @@ -17,7 +17,7 @@ */ #include #include -#include +#include #include #include diff --git a/plugins/experimental/statichit/statichit.cc b/plugins/experimental/statichit/statichit.cc index 8f06be1493e..09262844d0f 100644 --- a/plugins/experimental/statichit/statichit.cc +++ b/plugins/experimental/statichit/statichit.cc @@ -522,7 +522,7 @@ StaticHitTxnHook(TSCont contp, TSEvent event, void *edata) } method = TSHttpHdrMethodGet(bufp, hdr_loc, &method_length); - if (NULL == method) { + if (nullptr == method) { VERROR("Couldn't retrieve client request method"); goto done; } @@ -595,9 +595,9 @@ TSReturnCode TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSED */, int /* errbuf_size ATS_UNUSED */) { static const struct option longopt[] = { - {"file-path", required_argument, NULL, 'f'}, {"mime-type", required_argument, NULL, 'm'}, - {"max-age", required_argument, NULL, 'a'}, {"failure-code", required_argument, NULL, 'c'}, - {"success-code", required_argument, NULL, 's'}, {NULL, no_argument, NULL, '\0'}}; + {"file-path", required_argument, nullptr, 'f'}, {"mime-type", required_argument, nullptr, 'm'}, + {"max-age", required_argument, nullptr, 'a'}, {"failure-code", required_argument, nullptr, 'c'}, + {"success-code", required_argument, nullptr, 's'}, {nullptr, no_argument, nullptr, '\0'}}; std::string filePath; std::string mimeType = "text/plain"; @@ -610,7 +610,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE optind = 0; while (true) { - int opt = getopt_long(argc, (char *const *)argv, "f:m:a:c:s:", longopt, NULL); + int opt = getopt_long(argc, (char *const *)argv, "f:m:a:c:s:", longopt, nullptr); switch (opt) { case 'f': { @@ -640,7 +640,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE return TS_ERROR; } - if (filePath.find("/") != 0) { + if (filePath.find('/') != 0) { filePath = std::string(TSConfigDirGet()) + '/' + filePath; } diff --git a/plugins/experimental/stream_editor/stream_editor.cc b/plugins/experimental/stream_editor/stream_editor.cc index 0bd7d8a8839..e6e524e95cc 100644 --- a/plugins/experimental/stream_editor/stream_editor.cc +++ b/plugins/experimental/stream_editor/stream_editor.cc @@ -551,7 +551,7 @@ class rule_t using ruleset_t = std::vector; using rule_p = ruleset_t::const_iterator; -typedef struct contdata_t { +using contdata_t = struct contdata_t { TSCont cont = nullptr; TSIOBuffer out_buf = nullptr; TSIOBufferReader out_rd = nullptr; @@ -582,7 +582,7 @@ typedef struct contdata_t { contbuf_sz = 2 * sz - 1; } } -} contdata_t; +}; static int64_t process_block(contdata_t *contdata, TSIOBufferReader reader) diff --git a/plugins/multiplexer/ats-multiplexer.cc b/plugins/multiplexer/ats-multiplexer.cc index 8a814d88758..e192c31a9c2 100644 --- a/plugins/multiplexer/ats-multiplexer.cc +++ b/plugins/multiplexer/ats-multiplexer.cc @@ -78,7 +78,7 @@ TSRemapNewInstance(int argc, char **argv, void **i, char *, int) instance->skipPostPut = false; if (argc > 2) { - std::copy_if(argv + 2, argv + argc, std::back_inserter(instance->origins), [&](std::string s) { + std::copy_if(argv + 2, argv + argc, std::back_inserter(instance->origins), [&](const std::string &s) { if (s == "proxy.config.multiplexer.skip_post_put=1") { instance->skipPostPut = true; return false; diff --git a/proxy/CacheControl.cc b/proxy/CacheControl.cc index 91749f181ac..f1ed4e2429f 100644 --- a/proxy/CacheControl.cc +++ b/proxy/CacheControl.cc @@ -59,7 +59,7 @@ static const char *CC_directive_str[CC_NUM_TYPES] = { // "CACHE_AUTH_CONTENT" }; -typedef ControlMatcher CC_table; +using CC_table = ControlMatcher; // Global Ptrs static Ptr reconfig_mutex; diff --git a/proxy/ParentSelection.cc b/proxy/ParentSelection.cc index 1f60afa3ea2..f39686aa815 100644 --- a/proxy/ParentSelection.cc +++ b/proxy/ParentSelection.cc @@ -35,7 +35,7 @@ #define MAX_SIMPLE_RETRIES 5 #define MAX_UNAVAILABLE_SERVER_RETRIES 5 -typedef ControlMatcher P_table; +using P_table = ControlMatcher; // Global Vars for Parent Selection static const char modulePrefix[] = "[ParentSelection]"; diff --git a/proxy/hdrs/HuffmanCodec.cc b/proxy/hdrs/HuffmanCodec.cc index 562fa36b88a..546269042c6 100644 --- a/proxy/hdrs/HuffmanCodec.cc +++ b/proxy/hdrs/HuffmanCodec.cc @@ -70,11 +70,11 @@ static const huffman_entry huffman_table[] = { {0x7ffffe8, 27}, {0x7ffffe9, 27}, {0x7ffffea, 27}, {0x7ffffeb, 27}, {0xffffffe, 28}, {0x7ffffec, 27}, {0x7ffffed, 27}, {0x7ffffee, 27}, {0x7ffffef, 27}, {0x7fffff0, 27}, {0x3ffffee, 26}, {0x3fffffff, 30}}; -typedef struct node { +using Node = struct node { node *left, *right; char ascii_code; bool leaf_node; -} Node; +}; Node *HUFFMAN_TREE_ROOT; diff --git a/proxy/http2/HPACK.cc b/proxy/http2/HPACK.cc index 00a36a97c65..5a414a25f35 100644 --- a/proxy/http2/HPACK.cc +++ b/proxy/http2/HPACK.cc @@ -33,7 +33,7 @@ namespace // its value's length in octets, and 32. const static unsigned ADDITIONAL_OCTETS = 32; -typedef enum { +using TS_HPACK_STATIC_TABLE_ENTRY = enum { TS_HPACK_STATIC_TABLE_0 = 0, TS_HPACK_STATIC_TABLE_AUTHORITY, TS_HPACK_STATIC_TABLE_METHOD_GET, @@ -97,7 +97,7 @@ typedef enum { TS_HPACK_STATIC_TABLE_VIA, TS_HPACK_STATIC_TABLE_WWW_AUTHENTICATE, TS_HPACK_STATIC_TABLE_ENTRY_NUM -} TS_HPACK_STATIC_TABLE_ENTRY; +}; constexpr HpackHeaderField STATIC_TABLE[] = {{"", ""}, {":authority", ""}, diff --git a/proxy/logging/LogField.cc b/proxy/logging/LogField.cc index c884cc296d1..34d23dd187f 100644 --- a/proxy/logging/LogField.cc +++ b/proxy/logging/LogField.cc @@ -171,7 +171,7 @@ struct cmp_str { }; } // namespace -typedef std::map milestone_map; +using milestone_map = std::map; static milestone_map m_milestone_map; struct milestone { diff --git a/src/traffic_crashlog/traffic_crashlog.cc b/src/traffic_crashlog/traffic_crashlog.cc index de954ecf418..936ccefda75 100644 --- a/src/traffic_crashlog/traffic_crashlog.cc +++ b/src/traffic_crashlog/traffic_crashlog.cc @@ -192,8 +192,8 @@ main(int /* argc ATS_UNUSED */, const char **argv) diags->config.outputs[DL_Emergency].to_syslog = true; } - Note("crashlog started, target=%ld, debug=%s syslog=%s, uid=%ld euid=%ld", (long)target_pid, debug_mode ? "true" : "false", - syslog_mode ? "true" : "false", (long)getuid(), (long)geteuid()); + Note("crashlog started, target=%ld, debug=%s syslog=%s, uid=%ld euid=%ld", static_cast(target_pid), + debug_mode ? "true" : "false", syslog_mode ? "true" : "false", (long)getuid(), (long)geteuid()); mgmterr = TSInit(nullptr, (TSInitOptionT)(TS_MGMT_OPT_NO_EVENTS | TS_MGMT_OPT_NO_SOCK_TESTS)); if (mgmterr != TS_ERR_OKAY) { diff --git a/src/traffic_ctl/config.cc b/src/traffic_ctl/config.cc index d60cb3a07d0..e3433392310 100644 --- a/src/traffic_ctl/config.cc +++ b/src/traffic_ctl/config.cc @@ -369,8 +369,8 @@ CtrlEngine::config_status() CTRL_MGMT_CHECK(manager.fetch("proxy.node.config.restart_required.manager")); std::cout << CtrlMgmtRecordValue(version).c_str() << std::endl; - std::cout << "Started at " << timestr((time_t)starttime.as_int()).c_str(); - std::cout << "Last reconfiguration at " << timestr((time_t)configtime.as_int()).c_str(); + std::cout << "Started at " << timestr(static_cast(starttime.as_int())).c_str(); + std::cout << "Last reconfiguration at " << timestr(static_cast(configtime.as_int())).c_str(); std::cout << (reconfig.as_int() ? "Reconfiguration required" : "Configuration is current") << std::endl; if (proxy.as_int()) { diff --git a/src/traffic_logstats/logstats.cc b/src/traffic_logstats/logstats.cc index ca24b45197f..72d8cbfc094 100644 --- a/src/traffic_logstats/logstats.cc +++ b/src/traffic_logstats/logstats.cc @@ -391,9 +391,9 @@ class UrlLru _dump_url(u, as_object); } if (as_object) { - std::cout << " \"_timestamp\" : \"" << static_cast(ink_time_wall_seconds()) << "\"" << std::endl; + std::cout << R"( "_timestamp" : ")" << static_cast(ink_time_wall_seconds()) << "\"" << std::endl; } else { - std::cout << " { \"_timestamp\" : \"" << static_cast(ink_time_wall_seconds()) << "\" }" << std::endl; + std::cout << R"( { "_timestamp" : ")" << static_cast(ink_time_wall_seconds()) << "\" }" << std::endl; } } @@ -1940,8 +1940,8 @@ format_elapsed_line(const char *desc, const ElapsedStats &stat, bool json, bool if (json) { std::cout << " " << '"' << desc << "\" : " << "{ "; - std::cout << "\"min\": \"" << stat.min << "\", "; - std::cout << "\"max\": \"" << stat.max << "\""; + std::cout << R"("min": ")" << stat.min << "\", "; + std::cout << R"("max": ")" << stat.max << "\""; if (!concise) { std::cout << ", \"avg\": \"" << std::setiosflags(ios::fixed) << std::setprecision(2) << stat.avg << "\", "; std::cout << "\"dev\": \"" << std::setiosflags(ios::fixed) << std::setprecision(2) << stat.stddev << "\""; @@ -1979,12 +1979,12 @@ format_line(const char *desc, const StatsCounter &stat, const StatsCounter &tota if (json) { std::cout << " " << '"' << desc << "\" : " << "{ "; - std::cout << "\"req\": \"" << stat.count << "\", "; + std::cout << R"("req": ")" << stat.count << "\", "; if (!concise) { std::cout << "\"req_pct\": \"" << std::setiosflags(ios::fixed) << std::setprecision(2) << (double)stat.count / total.count * 100 << "\", "; } - std::cout << "\"bytes\": \"" << stat.bytes << "\""; + std::cout << R"("bytes": ")" << stat.bytes << "\""; if (!concise) { std::cout << ", \"bytes_pct\": \"" << std::setiosflags(ios::fixed) << std::setprecision(2) @@ -2273,7 +2273,7 @@ print_detail_stats(const OriginStats *stat, bool json, bool concise) std::cout << std::endl; std::cout << std::setw(cl.line_len) << std::setfill('_') << '_' << std::setfill(' ') << std::endl; } else { - std::cout << " \"_timestamp\" : \"" << static_cast(ink_time_wall_seconds()) << '"' << std::endl; + std::cout << R"( "_timestamp" : ")" << static_cast(ink_time_wall_seconds()) << '"' << std::endl; } } diff --git a/src/traffic_server/Crash.cc b/src/traffic_server/Crash.cc index d91f3fbbc06..fa3195880c9 100644 --- a/src/traffic_server/Crash.cc +++ b/src/traffic_server/Crash.cc @@ -158,7 +158,7 @@ crash_logger_invoke(int signo, siginfo_t *info, void *ctx) // ucontext_t can contain pointers, so it's highly platform dependent. On Linux with glibc, however, it is // a single memory block that we can just puke out. ATS_UNUSED_RETURN(write(crash_logger_fd, info, sizeof(siginfo_t))); - ATS_UNUSED_RETURN(write(crash_logger_fd, (ucontext_t *)ctx, sizeof(ucontext_t))); + ATS_UNUSED_RETURN(write(crash_logger_fd, static_cast(ctx), sizeof(ucontext_t))); #endif close(crash_logger_fd); diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index 1c114133853..e70dee896fe 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -7830,7 +7830,7 @@ char * TSMatcherReadIntoBuffer(char *file_name, int *file_len) { sdk_assert(sdk_sanity_check_null_ptr((void *)file_name) == TS_SUCCESS); - return readIntoBuffer((char *)file_name, "TSMatcher", file_len); + return readIntoBuffer(file_name, "TSMatcher", file_len); } char * diff --git a/src/traffic_server/InkAPITest.cc b/src/traffic_server/InkAPITest.cc index 946d713bc02..9a40913e716 100644 --- a/src/traffic_server/InkAPITest.cc +++ b/src/traffic_server/InkAPITest.cc @@ -3380,7 +3380,7 @@ checkHttpTxnServerRespGet(SocketTest *test, void *data) static int checkHttpTxnServerSsnTransactionCount(SocketTest *test, void *data) { - TSHttpTxn txnp = (TSHttpTxn)data; + TSHttpTxn txnp = static_cast(data); int count = TSHttpTxnServerSsnTransactionCount(txnp); if (count < 0) { diff --git a/src/traffic_server/SocksProxy.cc b/src/traffic_server/SocksProxy.cc index c1f44c25559..62799a04557 100644 --- a/src/traffic_server/SocksProxy.cc +++ b/src/traffic_server/SocksProxy.cc @@ -149,7 +149,7 @@ SocksProxy::init(NetVConnection *netVC) SCOPED_MUTEX_LOCK(lock, mutex, this_ethread()); - SET_HANDLER((EventHandler)&SocksProxy::acceptEvent); + SET_HANDLER(static_cast(&SocksProxy::acceptEvent)); handleEvent(NET_EVENT_ACCEPT, netVC); } @@ -178,7 +178,7 @@ SocksProxy::acceptEvent(int event, void *data) buf->reset(); - SET_HANDLER((EventHandler)&SocksProxy::mainEvent); + SET_HANDLER(static_cast(&SocksProxy::mainEvent)); vc_handler = &SocksProxy::state_read_client_request; timeout = this_ethread()->schedule_in(this, HRTIME_SECONDS(netProcessor.socks_conf_stuff->socks_timeout)); @@ -299,7 +299,7 @@ SocksProxy::state_read_client_request(int event, void *data) unsigned char *p = (unsigned char *)reader->start(); - Debug("SocksProxy", "Accepted connection from a version %d client", (int)p[0]); + Debug("SocksProxy", "Accepted connection from a version %d client", static_cast(p[0])); switch (p[0]) { case SOCKS4_VERSION: @@ -313,7 +313,7 @@ SocksProxy::state_read_client_request(int event, void *data) return (this->*vc_handler)(event, data); break; default: - Warning("Wrong version for Socks: %d\n", (int)p[0]); + Warning("Wrong version for Socks: %d\n", static_cast(p[0])); state = SOCKS_ERROR; break; } @@ -470,7 +470,7 @@ SocksProxy::state_read_socks5_client_request(int event, void *data) default: req_len = INT_MAX; state = SOCKS_ERROR; - Debug("SocksProxy", "Illegal address type(%d)", (int)p[3]); + Debug("SocksProxy", "Illegal address type(%d)", static_cast(p[3])); } if (state == SOCKS_ERROR) { diff --git a/src/tscore/ink_file.cc b/src/tscore/ink_file.cc index bd09666095f..6f054e7dbc1 100644 --- a/src/tscore/ink_file.cc +++ b/src/tscore/ink_file.cc @@ -56,11 +56,11 @@ #include /* for BLKGETSIZE. sys/mount.h is another candidate */ #endif -typedef union { +using ioctl_arg_t = union { uint64_t u64; uint32_t u32; off_t off; -} ioctl_arg_t; +}; int ink_fputln(FILE *stream, const char *s) diff --git a/src/tscore/ink_queue.cc b/src/tscore/ink_queue.cc index f4a2841c06f..7a528e2d58c 100644 --- a/src/tscore/ink_queue.cc +++ b/src/tscore/ink_queue.cc @@ -74,10 +74,10 @@ struct ink_freelist_ops { void (*fl_bulkfree)(InkFreeList *, void *, void *, size_t); }; -typedef struct _ink_freelist_list { +using ink_freelist_list = struct _ink_freelist_list { InkFreeList *fl; struct _ink_freelist_list *next; -} ink_freelist_list; +}; static void *freelist_new(InkFreeList *f); static void freelist_free(InkFreeList *f, void *item); diff --git a/src/tscore/unit_tests/test_layout.cc b/src/tscore/unit_tests/test_layout.cc index 736393bd847..1305d939db6 100644 --- a/src/tscore/unit_tests/test_layout.cc +++ b/src/tscore/unit_tests/test_layout.cc @@ -29,8 +29,9 @@ std::string append_slash(const char *path) { std::string ret(path); - if (ret.back() != '/') + if (ret.back() != '/') { ret.append("/"); + } return ret; }