Format rest of the sources

This commit is contained in:
Markus Mäkelä
2019-05-09 11:31:40 +03:00
parent fbd61967a7
commit de95fcc9d6
29 changed files with 384 additions and 388 deletions

View File

@ -58,7 +58,8 @@ public:
{
TimePoint time_point;
int count;
Timestamp(TimePoint p, int c) : time_point(p)
Timestamp(TimePoint p, int c)
: time_point(p)
, count(c)
{
}

View File

@ -38,5 +38,4 @@ std::string to_binary_size(int64_t size);
* @return The result string
*/
std::string string_printf(const char* format, ...) mxb_attribute((format (printf, 1, 2)));
}

View File

@ -117,5 +117,4 @@ inline bool operator!=(const Host& l, const Host& r)
* @return True on success
*/
bool reverse_dns(const std::string& ip, std::string* output);
}

View File

@ -57,28 +57,28 @@ public:
enum
{
DEFAULT_CONNECT_TIMEOUT = 10, // @see https://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html
DEFAULT_TIMEOUT = 10 // @see https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
DEFAULT_CONNECT_TIMEOUT = 10, // @see https://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html
DEFAULT_TIMEOUT = 10 // @see https://curl.haxx.se/libcurl/c/CURLOPT_TIMEOUT.html
};
struct Config
{
int connect_timeout_s = DEFAULT_CONNECT_TIMEOUT;
int timeout_s = DEFAULT_TIMEOUT;
int timeout_s = DEFAULT_TIMEOUT;
};
struct Result
{
enum
{
ERROR = -1, // Some non-specific error occurred.
COULDNT_RESOLVE_HOST = -2, // The specified host cold not be resolved.
OPERATION_TIMEDOUT = -3 // The operation timed out.
ERROR = -1, // Some non-specific error occurred.
COULDNT_RESOLVE_HOST = -2, // The specified host cold not be resolved.
OPERATION_TIMEDOUT = -3 // The operation timed out.
};
int code = 0; // HTTP response code
std::string body; // Response body
std::map<std::string, std::string> headers; // Headers attached to the response
int code = 0;// HTTP response code
std::string body; // Response body
std::map<std::string, std::string> headers; // Headers attached to the response
};
/**
@ -156,9 +156,9 @@ class Async
public:
enum status_t
{
READY, // The result is ready.
ERROR, // The operation has failed.
PENDING // The operation is pending.
READY, // The result is ready.
ERROR, // The operation has failed.
PENDING // The operation is pending.
};
class Imp
@ -197,7 +197,7 @@ public:
*
* @return *this.
*/
Async& operator = (const Async& rhs)
Async& operator=(const Async& rhs)
{
std::shared_ptr<Imp> sImp(rhs.m_sImp);
m_sImp.swap(sImp);
@ -307,7 +307,5 @@ Async get_async(const std::vector<std::string>& urls,
Async get_async(const std::vector<std::string>& urls,
const std::string& user, const std::string& password,
const Config& config = Config());
}
}

View File

@ -51,17 +51,17 @@ public:
return prev;
}
bool operator == (const intrusive_slist_iterator& rhs) const
bool operator==(const intrusive_slist_iterator& rhs) const
{
return m_pT == rhs.m_pT;
}
bool operator != (const intrusive_slist_iterator& rhs) const
bool operator!=(const intrusive_slist_iterator& rhs) const
{
return !(m_pT == rhs.m_pT);
}
T& operator * () const
T& operator*() const
{
mxb_assert(m_pT);
return *m_pT;
@ -70,5 +70,4 @@ public:
private:
T* m_pT;
};
}

View File

@ -17,32 +17,32 @@
namespace maxbase
{
class PamResult
class PamResult
{
public:
enum class Result
{
public:
enum class Result
{
SUCCESS,
WRONG_USER_PW, /**< Username or password was wrong */
ACCOUNT_INVALID, /**< pam_acct_mgmt returned error */
MISC_ERROR /**< Miscellaneous error */
};
Result type {Result::MISC_ERROR};
std::string error;
SUCCESS,
WRONG_USER_PW, /**< Username or password was wrong */
ACCOUNT_INVALID, /**< pam_acct_mgmt returned error */
MISC_ERROR /**< Miscellaneous error */
};
/**
* Check if the user & password can log into the given PAM service. This function will block until the
* operation completes.
*
* @param user Username
* @param password Password
* @param service Which PAM service is the user logging to
* @param expected_msg The first expected message from the PAM authentication system.
* Typically "Password: ", which is also the default value. If set to empty, the message is not checked.
* @return A result struct with the result and an error message.
*/
PamResult pam_authenticate(const std::string& user, const std::string& password,
const std::string& service, const std::string& expected_msg = "Password: ");
Result type {Result::MISC_ERROR};
std::string error;
};
/**
* Check if the user & password can log into the given PAM service. This function will block until the
* operation completes.
*
* @param user Username
* @param password Password
* @param service Which PAM service is the user logging to
* @param expected_msg The first expected message from the PAM authentication system.
* Typically "Password: ", which is also the default value. If set to empty, the message is not checked.
* @return A result struct with the result and an error message.
*/
PamResult pam_authenticate(const std::string& user, const std::string& password,
const std::string& service, const std::string& expected_msg = "Password: ");
}

View File

@ -285,7 +285,7 @@ public:
* and in the latter `EINTR.
*/
bool timedwait(time_t seconds,
long nseconds,
long nseconds,
signal_approach_t signal_approach = IGNORE_SIGNALS) const
{
timespec ts;
@ -316,7 +316,7 @@ public:
*/
size_t timedwait_n(size_t n_wait,
time_t seconds,
long nseconds,
long nseconds,
signal_approach_t signal_approach = IGNORE_SIGNALS) const
{
timespec ts;

View File

@ -42,15 +42,15 @@ struct WORKER_STATISTICS
N_QUEUE_TIMES = 30
};
int64_t n_read = 0; /*< Number of read events */
int64_t n_write = 0; /*< Number of write events */
int64_t n_error = 0; /*< Number of error events */
int64_t n_hup = 0; /*< Number of hangup events */
int64_t n_accept = 0; /*< Number of accept events */
int64_t n_polls = 0; /*< Number of poll cycles */
int64_t n_pollev = 0; /*< Number of polls returning events */
int64_t evq_avg = 0; /*< Average event queue length */
int64_t evq_max = 0; /*< Maximum event queue length */
int64_t n_read = 0; /*< Number of read events */
int64_t n_write = 0; /*< Number of write events */
int64_t n_error = 0; /*< Number of error events */
int64_t n_hup = 0; /*< Number of hangup events */
int64_t n_accept = 0; /*< Number of accept events */
int64_t n_polls = 0; /*< Number of poll cycles */
int64_t n_pollev = 0; /*< Number of polls returning events */
int64_t evq_avg = 0; /*< Average event queue length */
int64_t evq_max = 0; /*< Maximum event queue length */
int64_t maxqtime = 0;
int64_t maxexectime = 0;
std::array<int64_t, MAXNFDS> n_fds {}; /*< Number of wakeups with particular n_fds value */
@ -249,12 +249,12 @@ class Worker : public MXB_WORKER
Worker& operator=(const Worker&) = delete;
public:
using STATISTICS = WORKER_STATISTICS;
using Task = WorkerTask;
using STATISTICS = WORKER_STATISTICS;
using Task = WorkerTask;
using DisposableTask = WorkerDisposableTask;
using Load = WorkerLoad;
using Timer = WorkerTimer;
using RandomEngine = maxbase::XorShiftRandom;
using Load = WorkerLoad;
using Timer = WorkerTimer;
using RandomEngine = maxbase::XorShiftRandom;
/**
* A delegating timer that delegates the timer tick handling

View File

@ -55,7 +55,8 @@ namespace
struct TimePointLessEqual
{
TimePoint lhs;
TimePointLessEqual(TimePoint tp) : lhs(tp)
TimePointLessEqual(TimePoint tp)
: lhs(tp)
{
}
bool operator()(const EventCount::Timestamp& rhs) const
@ -134,7 +135,8 @@ namespace
struct MatchEventId
{
std::string event_id;
MatchEventId(const std::string& id) : event_id(id)
MatchEventId(const std::string& id)
: event_id(id)
{
}
bool operator()(const EventCount& stats) const

View File

@ -95,5 +95,4 @@ std::string string_printf(const char* format, ...)
}
return rval;
}
}

View File

@ -271,5 +271,4 @@ bool reverse_dns(const std::string& ip, std::string* output)
}
return success;
}
}

View File

@ -117,7 +117,7 @@ size_t header_callback(char* ptr, size_t size, size_t nmemb, void* userdata)
CURL* get_easy_curl(const std::string& url,
const std::string& user, const std::string& password,
const Config& config,
Result *pRes,
Result* pRes,
char* pErrbuf)
{
CURL* pCurl = curl_easy_init();
@ -126,8 +126,10 @@ CURL* get_easy_curl(const std::string& url,
if (pCurl)
{
checked_curl_setopt(pCurl, CURLOPT_NOSIGNAL, 1);
checked_curl_setopt(pCurl, CURLOPT_CONNECTTIMEOUT, config.connect_timeout_s);// For connection phase
checked_curl_setopt(pCurl, CURLOPT_TIMEOUT, config.timeout_s); // For data transfer phase
checked_curl_setopt(pCurl, CURLOPT_CONNECTTIMEOUT, config.connect_timeout_s); // For connection
// phase
checked_curl_setopt(pCurl, CURLOPT_TIMEOUT, config.timeout_s); // For data transfer
// phase
checked_curl_setopt(pCurl, CURLOPT_ERRORBUFFER, pErrbuf);
checked_curl_setopt(pCurl, CURLOPT_WRITEFUNCTION, write_callback);
checked_curl_setopt(pCurl, CURLOPT_WRITEDATA, &pRes->body);
@ -169,7 +171,7 @@ struct Context
}
mxb::http::Result* pResult;
Errbuf * pErrbuf;
Errbuf* pErrbuf;
};
class ReadyImp : public Async::Imp
@ -228,7 +230,7 @@ public:
for (auto& item : m_curls)
{
CURL* pCurl = item.first;
MXB_AT_DEBUG(CURLMcode rv =) curl_multi_remove_handle(m_pCurlm, pCurl);
MXB_AT_DEBUG(CURLMcode rv = ) curl_multi_remove_handle(m_pCurlm, pCurl);
mxb_assert(rv == CURLM_OK);
curl_easy_cleanup(pCurl);
}
@ -440,7 +442,6 @@ private:
int m_still_running;
long m_wait_no_more_than;
};
}
@ -546,7 +547,7 @@ Result get(const std::string& url, const std::string& user, const std::string& p
{
case CURLE_OK:
{
long code = 0; // needs to be a long
long code = 0; // needs to be a long
curl_easy_getinfo(pCurl, CURLINFO_RESPONSE_CODE, &code);
res.code = code;
}
@ -614,7 +615,5 @@ const char* to_string(Async::status_t status)
mxb_assert(!true);
return "Unknown";
}
}
}

View File

@ -32,7 +32,7 @@ class ConversationData
public:
string m_client;
string m_password;
int m_counter {0};
int m_counter {0};
string m_expected_msg;
ConversationData(const string& client, const string& password, const string& expected_msg)
@ -97,7 +97,6 @@ int conversation_func(int num_msg,
}
return rval;
}
}
namespace maxbase
@ -123,25 +122,25 @@ PamResult pam_authenticate(const string& user, const string& password, const str
pam_status = pam_authenticate(pam_handle, 0);
switch (pam_status)
{
case PAM_SUCCESS:
authenticated = true;
MXB_DEBUG("pam_authenticate returned success.");
break;
case PAM_SUCCESS:
authenticated = true;
MXB_DEBUG("pam_authenticate returned success.");
break;
case PAM_USER_UNKNOWN:
case PAM_AUTH_ERR:
// Normal failure, username or password was wrong.
result.type = PamResult::Result::WRONG_USER_PW;
result.error = mxb::string_printf(PAM_AUTH_ERR_MSG, user.c_str(), service.c_str(),
pam_strerror(pam_handle, pam_status));
break;
case PAM_USER_UNKNOWN:
case PAM_AUTH_ERR:
// Normal failure, username or password was wrong.
result.type = PamResult::Result::WRONG_USER_PW;
result.error = mxb::string_printf(PAM_AUTH_ERR_MSG, user.c_str(), service.c_str(),
pam_strerror(pam_handle, pam_status));
break;
default:
// More exotic error
result.type = PamResult::Result::MISC_ERROR;
result.error = mxb::string_printf(PAM_AUTH_ERR_MSG, user.c_str(), service.c_str(),
pam_strerror(pam_handle, pam_status));
break;
default:
// More exotic error
result.type = PamResult::Result::MISC_ERROR;
result.error = mxb::string_printf(PAM_AUTH_ERR_MSG, user.c_str(), service.c_str(),
pam_strerror(pam_handle, pam_status));
break;
}
}
else
@ -156,20 +155,19 @@ PamResult pam_authenticate(const string& user, const string& password, const str
pam_status = pam_acct_mgmt(pam_handle, 0);
switch (pam_status)
{
case PAM_SUCCESS:
result.type = PamResult::Result::SUCCESS;
break;
case PAM_SUCCESS:
result.type = PamResult::Result::SUCCESS;
break;
default:
// Credentials have already been checked to be ok, so this is a somewhat unexpected error.
result.type = PamResult::Result::ACCOUNT_INVALID;
result.error = mxb::string_printf(PAM_ACC_ERR_MSG, user.c_str(), service.c_str(),
pam_strerror(pam_handle, pam_status));
break;
default:
// Credentials have already been checked to be ok, so this is a somewhat unexpected error.
result.type = PamResult::Result::ACCOUNT_INVALID;
result.error = mxb::string_printf(PAM_ACC_ERR_MSG, user.c_str(), service.c_str(),
pam_strerror(pam_handle, pam_status));
break;
}
}
pam_end(pam_handle, pam_status);
return result;
}
}

View File

@ -19,7 +19,7 @@ namespace maxbase
// static
void Semaphore::get_current_timespec(time_t seconds,
long nseconds,
long nseconds,
timespec* pTs)
{
mxb_assert(nseconds <= 999999999);

View File

@ -19,7 +19,6 @@ namespace
{
thread_local char errbuf[512]; // Enough for all errors
}
const char* mxb_strerror(int error)
@ -73,5 +72,4 @@ char* trim(char* str)
{
return ltrim(rtrim(str));
}
}

View File

@ -103,8 +103,8 @@ int test_multi_http()
{
cout << __func__ << endl;
vector<string> urls = { "http://www.example.com/", "http://www.example.com/", "http://non-existent.xyz" };
vector<bool> expected_successes = { true, true, false };
vector<string> urls = {"http://www.example.com/", "http://www.example.com/", "http://non-existent.xyz"};
vector<bool> expected_successes = {true, true, false};
vector<mxb::http::Result> results = mxb::http::get(urls);
int rv = check_results(urls, expected_successes, results);
@ -118,8 +118,8 @@ int test_async_http()
int rv = EXIT_FAILURE;
vector<string> urls = { "http://www.example.com/", "http://www.example.com/", "http://non-existent.xyz" };
vector<bool> expected_successes = { true, true, false };
vector<string> urls = {"http://www.example.com/", "http://www.example.com/", "http://non-existent.xyz"};
vector<bool> expected_successes = {true, true, false};
mxb::http::Async http = mxb::http::get_async(urls);
while (http.perform(0) == mxb::http::Async::PENDING)
@ -148,7 +148,6 @@ int test_async_http()
return rv == EXIT_FAILURE ? 1 : 0;
}
}
uint64_t time_since_epoch_ms()

View File

@ -116,7 +116,6 @@ int test_rtrim()
cout << "rtrim()" << endl;
return test(rtrim_testcases, n_rtrim_testcases, mxb::rtrim);
}
}
int main(int argc, char* argv[])

View File

@ -111,7 +111,7 @@ uint64_t WorkerLoad::get_time_ms()
int rv = clock_gettime(CLOCK_MONOTONIC_COARSE, &t);
if (rv != 0)
{
mxb_assert(errno == EINVAL); // CLOCK_MONOTONIC_COARSE not supported.
mxb_assert(errno == EINVAL); // CLOCK_MONOTONIC_COARSE not supported.
rv = clock_gettime(CLOCK_MONOTONIC, &t);
mxb_assert(rv == 0);
}