Cosmetics: address cppcheck warnings

This commit is contained in:
Felipe Zimmerle
2020-01-27 18:11:08 -03:00
parent 68ef2dece3
commit fe98ce4c7d
53 changed files with 358 additions and 279 deletions

View File

@@ -71,7 +71,7 @@ struct MyHash{
class AnchoredSetVariable : public std::unordered_multimap<std::string,
VariableValue *, MyHash, MyEqual> {
public:
AnchoredSetVariable(Transaction *t, std::string name);
AnchoredSetVariable(Transaction *t, const std::string &name);
~AnchoredSetVariable();
void unset();

View File

@@ -42,15 +42,18 @@ class Transaction;
class AnchoredVariable {
public:
AnchoredVariable(Transaction* t, std::string name);
AnchoredVariable(Transaction* t, const std::string &name);
AnchoredVariable(const AnchoredVariable &a) {
m_transaction = a.m_transaction;
m_offset = a.m_offset;
m_name = a.m_name;
m_value = a.m_value;
m_var = a.m_var;
}
AnchoredVariable(const AnchoredVariable &a) = delete;
AnchoredVariable &operator= (const AnchoredVariable &a) = delete;
/*
: m_transaction(a.m_transaction),
m_offset(a.m_offset),
m_name(a.m_name),
m_value(a.m_value),
m_var(a.m_var) { }
*/
~AnchoredVariable();

View File

@@ -37,7 +37,9 @@ class Writer;
class AuditLog {
public:
AuditLog();
~AuditLog();
virtual ~AuditLog();
AuditLog(const AuditLog &a) = delete;
enum AuditLogType {
NotSetAuditLogType,
@@ -158,22 +160,22 @@ class AuditLog {
bool setStorageDir(const std::basic_string<char>& path);
bool setFormat(AuditLogFormat fmt);
int getDirectoryPermission();
int getFilePermission();
int getParts();
int getDirectoryPermission() const;
int getFilePermission() const;
int getParts() const;
bool setParts(const std::basic_string<char>& new_parts);
bool setType(AuditLogType audit_type);
bool init(std::string *error);
bool close();
virtual bool close();
bool saveIfRelevant(Transaction *transaction);
bool saveIfRelevant(Transaction *transaction, int parts);
bool isRelevant(int status);
int addParts(int parts, const std::string& new_parts);
int removeParts(int parts, const std::string& new_parts);
static int addParts(int parts, const std::string& new_parts);
static int removeParts(int parts, const std::string& new_parts);
bool merge(AuditLog *from, std::string *error);

View File

@@ -44,7 +44,7 @@ namespace collection {
class Collection {
public:
explicit Collection(std::string a) : m_name(a) { }
explicit Collection(const std::string &a) : m_name(a) { }
virtual ~Collection() { }
virtual void store(std::string key, std::string value) = 0;

View File

@@ -49,6 +49,9 @@ class Collections {
Collection *user, Collection *resource);
~Collections();
Collections(const Collections &c) = delete;
Collections& operator =(const Collections &c) = delete;
std::string m_global_collection_key;
std::string m_ip_collection_key;
std::string m_session_collection_key;

View File

@@ -43,11 +43,11 @@ class DebugLog {
virtual void write(int level, const std::string &msg);
virtual void write(int level, const std::string &id,
const std::string &uri, const std::string &msg);
bool isLogFileSet();
bool isLogLevelSet();
void setDebugLogLevel(int level);
void setDebugLogFile(const std::string &fileName, std::string *error);
const std::string& getDebugLogFile();
virtual bool isLogFileSet();
virtual bool isLogLevelSet();
virtual void setDebugLogLevel(int level);
virtual void setDebugLogFile(const std::string &fileName, std::string *error);
virtual const std::string& getDebugLogFile();
virtual int getDebugLogLevel();
int m_debugLevel;

View File

@@ -278,8 +278,11 @@ class ModSecurity {
ModSecurity();
~ModSecurity();
ModSecurity(const ModSecurity &m) = delete;
ModSecurity& operator= (const ModSecurity &m) = delete;
const std::string& whoAmI();
void setConnectorInformation(std::string connector);
void setConnectorInformation(const std::string &connector);
void setServerLogCb(ModSecLogCb cb);
/**
*
@@ -291,9 +294,9 @@ class ModSecurity {
void serverLog(void *data, std::shared_ptr<RuleMessage> rm);
const std::string& getConnectorInformation();
const std::string& getConnectorInformation() const;
int processContentOffset(const char *content, size_t len,
static int processContentOffset(const char *content, size_t len,
const char *matchString, std::string *json, const char **err);
collection::Collection *m_global_collection;

View File

@@ -74,7 +74,7 @@ class Rule {
std::list<std::pair<std::shared_ptr<std::string>,
std::shared_ptr<std::string>>> *ret,
std::string *path,
int *nth);
int *nth) const;
void getVariablesExceptions(Transaction *t,
variables::Variables *exclusion, variables::Variables *addition);
@@ -91,9 +91,9 @@ class Rule {
std::string value, std::shared_ptr<RuleMessage> rm);
void executeActionsIndependentOfChainedRuleResult(Transaction *trasn,
bool *b, std::shared_ptr<RuleMessage> ruleMessage);
inline void updateMatchedVars(Transaction *trasn, const std::string &key,
static inline void updateMatchedVars(Transaction *trasn, const std::string &key,
const std::string &value);
inline void cleanMatchedVars(Transaction *trasn);
static inline void cleanMatchedVars(Transaction *trasn);
std::vector<actions::Action *> getActionsByName(const std::string& name,
Transaction *t);

View File

@@ -67,25 +67,25 @@ class RuleMessage {
std::string log() {
return RuleMessage::log(this, 0);
return log(this, 0);
}
std::string log(int props) {
return RuleMessage::log(this, props);
return log(this, props);
}
std::string log(int props, int responseCode) {
return RuleMessage::log(this, props, responseCode);
return log(this, props, responseCode);
}
std::string errorLog() {
return RuleMessage::log(this,
return log(this,
ClientLogMessageInfo | ErrorLogTailLogMessageInfo);
}
static std::string log(const RuleMessage *rm, int props, int code);
static std::string log(const RuleMessage *rm, int props) {
return RuleMessage::log(rm, props, -1);
return log(rm, props, -1);
}
static std::string log(const RuleMessage *rm) {
return RuleMessage::log(rm, 0);
return log(rm, 0);
}
static std::string _details(const RuleMessage *rm);

View File

@@ -70,7 +70,7 @@ class Rules : public RulesProperties {
int load(const char *rules);
int load(const char *rules, const std::string &ref);
void dump();
void dump() const;
int merge(Parser::Driver *driver);
int merge(Rules *rules);
@@ -84,10 +84,10 @@ class Rules : public RulesProperties {
int64_t unicode_codepage;
private:
int m_referenceCount;
#ifndef NO_LOGS
uint8_t m_secmarker_skipped;
#endif
int m_referenceCount;
};
#endif

View File

@@ -197,6 +197,8 @@ class RulesProperties {
m_remoteRulesActionOnFailed(PropertyNotSetRemoteRulesAction),
m_secRuleEngine(PropertyNotSetRuleEngine) { }
RulesProperties(const RulesProperties &r) = delete;
RulesProperties &operator =(const RulesProperties &r) = delete;
~RulesProperties() {
int i = 0;

View File

@@ -295,7 +295,7 @@ class Transaction : public TransactionAnchoredVariables {
Transaction ( const Transaction & ) = delete;
bool operator ==(const Transaction &b) const { return false; };
Transaction operator =(const Transaction &b) const = delete;
Transaction &operator =(const Transaction &b) const = delete;
/** TODO: Should be an structure that fits an IP address */
int processConnection(const char *client, int cPort,
@@ -359,7 +359,7 @@ class Transaction : public TransactionAnchoredVariables {
bool extractArguments(const std::string &orig, const std::string& buf,
size_t offset);
const char *getResponseBody();
const char *getResponseBody() const;
size_t getResponseBodyLength();
size_t getRequestBodyLength();
@@ -368,7 +368,7 @@ class Transaction : public TransactionAnchoredVariables {
#endif
void serverLog(std::shared_ptr<RuleMessage> rm);
int getRuleEngineState();
int getRuleEngineState() const;
std::string toJSON(int parts);
std::string toOldAuditLogFormat(int parts, const std::string &trailer);

View File

@@ -39,28 +39,28 @@ class VariableValue {
public:
using Origins = std::list<std::unique_ptr<VariableOrigin>>;
VariableValue(const std::string *key,
explicit VariableValue(const std::string *key,
const std::string *value = nullptr)
: m_key(*key),
: m_collection(""),
m_key(*key),
m_keyWithCollection(*key),
m_collection(""),
m_value(value != nullptr?*value:"")
{ }
VariableValue(const std::string *collection,
const std::string *key,
const std::string *value)
: m_key(*key),
: m_collection(*collection),
m_key(*key),
m_keyWithCollection(*collection + ":" + *key),
m_collection(*collection),
m_value(*value)
{ }
explicit VariableValue(const VariableValue *o) :
m_key(o->m_key),
m_value(o->m_value),
m_collection(o->m_collection),
m_keyWithCollection(o->m_keyWithCollection)
m_key(o->m_key),
m_keyWithCollection(o->m_keyWithCollection),
m_value(o->m_value)
{
for (auto &i : o->m_orign) {
std::unique_ptr<VariableOrigin> origin(new VariableOrigin());
@@ -70,6 +70,8 @@ class VariableValue {
}
}
VariableValue(const VariableValue &v) = delete;
const std::string& getKey() const {
return m_key;