mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-05 16:50:34 +00:00
chore(falco): apply code formatting
Signed-off-by: Poiana <poiana.bot@gmail.com>
This commit is contained in:
@@ -17,83 +17,57 @@ limitations under the License.
|
||||
|
||||
#include "falco_common.h"
|
||||
|
||||
static std::vector<std::string> priority_names = {
|
||||
"Emergency",
|
||||
"Alert",
|
||||
"Critical",
|
||||
"Error",
|
||||
"Warning",
|
||||
"Notice",
|
||||
"Informational",
|
||||
"Debug"
|
||||
};
|
||||
static std::vector<std::string> priority_names =
|
||||
{"Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debug"};
|
||||
|
||||
static std::vector<std::string> rule_matching_names = {
|
||||
"first",
|
||||
"all"
|
||||
};
|
||||
static std::vector<std::string> rule_matching_names = {"first", "all"};
|
||||
|
||||
bool falco_common::parse_priority(const std::string& v, priority_type& out)
|
||||
{
|
||||
for (size_t i = 0; i < priority_names.size(); i++)
|
||||
{
|
||||
bool falco_common::parse_priority(const std::string& v, priority_type& out) {
|
||||
for(size_t i = 0; i < priority_names.size(); i++) {
|
||||
// note: for legacy reasons, "Info" and "Informational" has been used
|
||||
// interchangeably and ambiguously, so this is the only edge case for
|
||||
// which we can't apply strict equality check
|
||||
if (!strcasecmp(v.c_str(), priority_names[i].c_str())
|
||||
|| (i == PRIORITY_INFORMATIONAL && !strcasecmp(v.c_str(), "info")))
|
||||
{
|
||||
out = (priority_type) i;
|
||||
if(!strcasecmp(v.c_str(), priority_names[i].c_str()) ||
|
||||
(i == PRIORITY_INFORMATIONAL && !strcasecmp(v.c_str(), "info"))) {
|
||||
out = (priority_type)i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
falco_common::priority_type falco_common::parse_priority(const std::string& v)
|
||||
{
|
||||
falco_common::priority_type falco_common::parse_priority(const std::string& v) {
|
||||
falco_common::priority_type out;
|
||||
if (!parse_priority(v, out))
|
||||
{
|
||||
if(!parse_priority(v, out)) {
|
||||
throw falco_exception("Unknown priority value: " + v);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool falco_common::format_priority(priority_type v, std::string& out, bool shortfmt)
|
||||
{
|
||||
if ((size_t) v < priority_names.size())
|
||||
{
|
||||
if (v == PRIORITY_INFORMATIONAL && shortfmt)
|
||||
{
|
||||
bool falco_common::format_priority(priority_type v, std::string& out, bool shortfmt) {
|
||||
if((size_t)v < priority_names.size()) {
|
||||
if(v == PRIORITY_INFORMATIONAL && shortfmt) {
|
||||
out = "Info";
|
||||
}
|
||||
else
|
||||
{
|
||||
out = priority_names[(size_t) v];
|
||||
} else {
|
||||
out = priority_names[(size_t)v];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string falco_common::format_priority(priority_type v, bool shortfmt)
|
||||
{
|
||||
std::string falco_common::format_priority(priority_type v, bool shortfmt) {
|
||||
std::string out;
|
||||
if(!format_priority(v, out, shortfmt))
|
||||
{
|
||||
if(!format_priority(v, out, shortfmt)) {
|
||||
throw falco_exception("Unknown priority enum value: " + std::to_string(v));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
bool falco_common::parse_rule_matching(const std::string& v, rule_matching& out)
|
||||
{
|
||||
for (size_t i = 0; i < rule_matching_names.size(); i++)
|
||||
{
|
||||
if (!strcasecmp(v.c_str(), rule_matching_names[i].c_str()))
|
||||
{
|
||||
out = (rule_matching) i;
|
||||
bool falco_common::parse_rule_matching(const std::string& v, rule_matching& out) {
|
||||
for(size_t i = 0; i < rule_matching_names.size(); i++) {
|
||||
if(!strcasecmp(v.c_str(), rule_matching_names[i].c_str())) {
|
||||
out = (rule_matching)i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user