Skip to content

Commit

Permalink
Merge pull request #418 from mmd-osm/patch/cleanup17
Browse files Browse the repository at this point in the history
Linter fixes
  • Loading branch information
mmd-osm authored Jul 8, 2024
2 parents d4d1d02 + fac12b5 commit 12c0612
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion include/cgimap/fcgi_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct fcgi_request : public request {
fcgi_request(int socket, const std::chrono::system_clock::time_point &now);
~fcgi_request() override;
const char *get_param(const char *key) const override;
const std::string get_payload() override;
std::string get_payload() override;

// getting and setting the current time
std::chrono::system_clock::time_point get_current_time() const override;
Expand Down
2 changes: 1 addition & 1 deletion include/cgimap/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct request {

// get payload provided for the request. this is useful in particular
// for HTTP POST and PUT requests.
virtual const std::string get_payload() = 0;
virtual std::string get_payload() = 0;

/********************** RESPONSE HEADER FUNCTIONS **************************/

Expand Down
4 changes: 2 additions & 2 deletions src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace po = boost::program_options;

namespace {

po::variables_map first_pass_argments(int argc, char *argv[],
po::variables_map first_pass_arguments(int argc, char *argv[],
const po::options_description &desc) {
// copy args because boost::program_options seems to destructively consume
// them
Expand Down Expand Up @@ -60,7 +60,7 @@ bool registry::set_backend(std::unique_ptr<backend> ptr) {
void registry::setup_options(int argc, char *argv[],
po::options_description &desc) {

po::variables_map vm = first_pass_argments(argc, argv, desc);
po::variables_map vm = first_pass_arguments(argc, argv, desc);

if (!vm.count("help")) {
desc.add(backend_ptr->options());
Expand Down
3 changes: 2 additions & 1 deletion src/backend/apidb/common_pgsql_selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ struct node {
using extra_columns = node_extra_columns;

struct extra_info {
double lon, lat;
double lon;
double lat;
inline void extract(const pqxx_tuple &row, const extra_columns& col) {
lon = double(row[col.longitude_col].as<int64_t>()) / (global_settings::get_scale());
lat = double(row[col.latitude_col].as<int64_t>()) / (global_settings::get_scale());
Expand Down
12 changes: 6 additions & 6 deletions src/backend/apidb/pgsql_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ std::string connect_db_str(const po::variables_map &options) {
ostr << " " << (b "=") << options[a].as<std::string>(); \
}

CONNOPT("dbname", "dbname");
CONNOPT("host", "host");
CONNOPT("username", "user");
CONNOPT("password", "password");
CONNOPT("dbport", "port");
CONNOPT("dbname", "dbname")
CONNOPT("host", "host")
CONNOPT("username", "user")
CONNOPT("password", "password")
CONNOPT("dbport", "port")

#undef CONNOPT
return ostr.str();
Expand Down Expand Up @@ -168,7 +168,7 @@ uint64_t pgsql_update::get_bbox_size_limit(osm_user_id_t uid)
auto row = res[0];
auto bbox_size_limit = row[0].as<int64_t>();

return std::max(bbox_size_limit, 0l);
return std::max(bbox_size_limit, 0L);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fcgi_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const char *fcgi_request::get_param(const char *key) const {
return FCGX_GetParam(key, m_impl->req.envp);
}

const std::string fcgi_request::get_payload() {
std::string fcgi_request::get_payload() {

// fetch and parse the content length
const char *content_length_str = FCGX_GetParam("CONTENT_LENGTH", m_impl->req.envp);
Expand Down
2 changes: 1 addition & 1 deletion src/oauth2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace oauth2 {
return std::nullopt;
}

const auto bearer_token = sm[1];
const auto& bearer_token = sm[1];

bool expired;
bool revoked;
Expand Down
18 changes: 9 additions & 9 deletions src/rate_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


std::tuple<bool, int> null_rate_limiter::check(const std::string &, bool) {
return std::make_tuple(false, 0);
return {false, 0};
}

void null_rate_limiter::update(const std::string &, int, bool) {
Expand All @@ -28,7 +28,7 @@ struct memcached_rate_limiter::state {

memcached_rate_limiter::memcached_rate_limiter(
const boost::program_options::variables_map &options) {
if (options.count("memcache") && (ptr = memcached_create(NULL)) != NULL) {
if (options.count("memcache") && (ptr = memcached_create(nullptr)) != nullptr) {
memcached_server_st *server_list;

memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
Expand All @@ -42,7 +42,7 @@ memcached_rate_limiter::memcached_rate_limiter(

memcached_server_list_free(server_list);
} else {
ptr = NULL;
ptr = nullptr;
}
}

Expand All @@ -64,10 +64,10 @@ std::tuple<bool, int> memcached_rate_limiter::check(const std::string &key, bool

if (ptr &&
(sp = (state *)memcached_get(ptr, mc_key.data(), mc_key.size(), &length,
&flags, &error)) != NULL) {
&flags, &error)) != nullptr) {
assert(length == sizeof(state));

int64_t elapsed = time(NULL) - sp->last_update;
int64_t elapsed = time(nullptr) - sp->last_update;

if (elapsed * bytes_per_sec < sp->bytes_served) {
bytes_served = sp->bytes_served - elapsed * bytes_per_sec;
Expand All @@ -78,16 +78,16 @@ std::tuple<bool, int> memcached_rate_limiter::check(const std::string &key, bool

auto max_bytes = global_settings::get_ratelimiter_maxdebt(moderator);
if (bytes_served < max_bytes) {
return std::make_tuple(false, 0);
return {false, 0};
} else {
// + 1 to reverse effect of integer flooring seconds
return std::make_tuple(true, (bytes_served - max_bytes) / bytes_per_sec + 1);
return {true, (bytes_served - max_bytes) / bytes_per_sec + 1};
}
}

void memcached_rate_limiter::update(const std::string &key, int bytes, bool moderator) {
if (ptr) {
time_t now = time(NULL);
time_t now = time(nullptr);
std::string mc_key;
state *sp;
size_t length;
Expand All @@ -101,7 +101,7 @@ void memcached_rate_limiter::update(const std::string &key, int bytes, bool mode

if (ptr &&
(sp = (state *)memcached_get(ptr, mc_key.data(), mc_key.size(), &length,
&flags, &error)) != NULL) {
&flags, &error)) != nullptr) {
assert(length == sizeof(state));

int64_t elapsed = now - sp->last_update;
Expand Down
6 changes: 3 additions & 3 deletions src/routes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ struct router {

// Process HEAD like GET, as per rfc2616: The HEAD method is identical to
// GET except that the server MUST NOT return a message-body in the response.
for (auto& rptr : rules_get) {
for (const auto& rptr : rules_get) {
if (rptr->invoke_if(p, params, hptr)) {
if (*maybe_method == http::method::GET ||
*maybe_method == http::method::HEAD ||
Expand All @@ -175,7 +175,7 @@ struct router {
}
}

for (auto& rptr : rules_post) {
for (const auto& rptr : rules_post) {
if (rptr->invoke_if(p, params, hptr)) {
if (*maybe_method == http::method::POST||
*maybe_method == http::method::OPTIONS)
Expand All @@ -184,7 +184,7 @@ struct router {
}
}

for (auto& rptr : rules_put) {
for (const auto& rptr : rules_put) {
if (rptr->invoke_if(p, params, hptr)) {
if (*maybe_method == http::method::PUT||
*maybe_method == http::method::OPTIONS)
Expand Down
4 changes: 2 additions & 2 deletions src/text_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ void text_formatter::error(const std::exception &e) {
writer->text(e.what());
}

void text_formatter::write_tags(const tags_t &tags) {
void text_formatter::write_tags(const tags_t &) {
// nothing needed here
}

void text_formatter::write_common(const element_info &elem) {
void text_formatter::write_common(const element_info &) {
// nothing needed here
}

Expand Down
2 changes: 1 addition & 1 deletion test/test_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const char *test_request::get_param(const char *key) const {
}
}

const std::string test_request::get_payload() {
std::string test_request::get_payload() {

// TODO: still a bit too much duplication from fcgi_request.cpp::get_payload

Expand Down
2 changes: 1 addition & 1 deletion test/test_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct test_request : public request {
/// implementation of request interface
~test_request() override = default;
const char *get_param(const char *key) const override;
const std::string get_payload() override;
std::string get_payload() override;
void set_payload(const std::string&);

void dispose() override;
Expand Down

0 comments on commit 12c0612

Please sign in to comment.