Code cosmetic: Having the code following our coding style

This commit also update some methods parameters to const.
This commit is contained in:
Felipe Zimmerle 2015-07-08 17:33:29 -03:00
parent 73154b51a1
commit 7ea9ff8836
19 changed files with 70 additions and 69 deletions

View File

@ -85,8 +85,8 @@ class Assay {
~Assay(); ~Assay();
/** TODO: Should be an structure that fits an IP address */ /** TODO: Should be an structure that fits an IP address */
int processConnection(char *ip); int processConnection(const char *ip);
int processURI(char *uri); int processURI(const char *uri);
int processRequestHeaders(); int processRequestHeaders();
@ -130,8 +130,8 @@ class Assay {
private: private:
std::ofstream myfile; std::ofstream myfile;
Rules *m_rules; Rules *m_rules;
char *m_ipAddress; const char *m_ipAddress;
char *m_uri; const char *m_uri;
std::ostringstream m_requestBody; std::ostringstream m_requestBody;
std::ostringstream m_responseBody; std::ostringstream m_responseBody;
ModSecurityCollectionsVariables m_variables_collections; ModSecurityCollectionsVariables m_variables_collections;
@ -148,7 +148,7 @@ extern "C" {
Assay *msc_new_assay(ModSecurity *ms, Rules *rules); Assay *msc_new_assay(ModSecurity *ms, Rules *rules);
/** @ingroup ModSecurity_C_API */ /** @ingroup ModSecurity_C_API */
int msc_process_connection(Assay *assay, char *ip); int msc_process_connection(Assay *assay, const char *ip);
/** @ingroup ModSecurity_C_API */ /** @ingroup ModSecurity_C_API */
int msc_process_request_headers(Assay *assay); int msc_process_request_headers(Assay *assay);
@ -184,7 +184,7 @@ int msc_append_response_body(Assay *assay,
const unsigned char *body, size_t size); const unsigned char *body, size_t size);
/** @ingroup ModSecurity_C_API */ /** @ingroup ModSecurity_C_API */
int msc_process_uri(Assay *assay, char *uri); int msc_process_uri(Assay *assay, const char *uri);
/** @ingroup ModSecurity_C_API */ /** @ingroup ModSecurity_C_API */
const char *msc_get_response_body(Assay *assay); const char *msc_get_response_body(Assay *assay);
/** @ingroup ModSecurity_C_API */ /** @ingroup ModSecurity_C_API */

View File

@ -23,8 +23,8 @@ namespace ModSecurity {
typedef struct ModSecurityIntervention_t { typedef struct ModSecurityIntervention_t {
int status; int status;
int pause; int pause;
char *url; const char *url;
char *log; const char *log;
} ModSecurityIntervention; } ModSecurityIntervention;
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -64,7 +64,7 @@ class Rules {
*/ */
int loadFromUri(char *uri); int loadFromUri(char *uri);
int loadRemote(char *key, char *uri); int loadRemote(char *key, char *uri);
int load(char *rules); int load(const char *rules);
int merge(Driver *driver); int merge(Driver *driver);
int merge(Rules *rules); int merge(Rules *rules);
@ -100,7 +100,7 @@ Rules *msc_create_rules_set();
int msc_rules_merge(Rules *rules_dst, Rules *rules_from); int msc_rules_merge(Rules *rules_dst, Rules *rules_from);
int msc_rules_add_remote(Rules *rules, char *key, char *uri); int msc_rules_add_remote(Rules *rules, char *key, char *uri);
int msc_rules_add_file(Rules *rules, char *file); int msc_rules_add_file(Rules *rules, char *file);
int msc_rules_add(Rules *rules, char *plain_rules); int msc_rules_add(Rules *rules, const char *plain_rules);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -44,7 +44,7 @@ void Redirect::fill_intervention(ModSecurityIntervention *i) {
i->status = this->status; i->status = this->status;
} }
// reinterpret_cast<char *> // reinterpret_cast<char *>
i->url = (char *) this->url.c_str(); //** TODO: wheee */ i->url = this->url.c_str(); //** TODO: wheee */
i->log = "Redirecting"; i->log = "Redirecting";
} }

View File

@ -40,7 +40,8 @@ std::string& CompressWhitespace::evaluate(std::string value,
/** /**
* @todo Implement the transformation CompressWhitespace * @todo Implement the transformation CompressWhitespace
*/ */
assay->debug(4, "Transformation CompressWhitespace is not implemented yet."); assay->debug(4, "Transformation CompressWhitespace is " \
"not implemented yet.");
} }
} // namespace transformations } // namespace transformations

View File

@ -41,4 +41,4 @@ class HexDecode : public Transformation {
#endif #endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_BASE64DECODE_H_ #endif // SRC_ACTIONS_TRANSFORMATIONS_HEX_DECODE_H_

View File

@ -18,8 +18,8 @@
#include "actions/action.h" #include "actions/action.h"
#include "actions/transformations/transformation.h" #include "actions/transformations/transformation.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_BASE64DECODE_H_ #ifndef SRC_ACTIONS_TRANSFORMATIONS_HEX_ENCODE_H_
#define SRC_ACTIONS_TRANSFORMATIONS_BASE64DECODE_H_ #define SRC_ACTIONS_TRANSFORMATIONS_HEX_ENCODE_H_
#ifdef __cplusplus #ifdef __cplusplus
namespace ModSecurity { namespace ModSecurity {
@ -41,4 +41,4 @@ class HexEncode : public Transformation {
#endif #endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_BASE64DECODE_H_ #endif // SRC_ACTIONS_TRANSFORMATIONS_HEX_ENCODE_H_

View File

@ -41,4 +41,4 @@ class ParityOdd7bit : public Transformation {
#endif #endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_PARITY_EVEN_7BIT_H_ #endif // SRC_ACTIONS_TRANSFORMATIONS_PARITY_ODD_7BIT_H_

View File

@ -40,7 +40,8 @@ std::string& RemoveComments::evaluate(std::string value,
/** /**
* @todo Implement the transformation RemoveComments * @todo Implement the transformation RemoveComments
*/ */
assay->debug(4, "Transformation RemoveComments is not implemented yet."); assay->debug(4, "Transformation RemoveComments is not " \
"implemented yet.");
return value; return value;
} }

View File

@ -40,7 +40,8 @@ std::string& RemoveCommentsChar::evaluate(std::string value,
/** /**
* @todo Implement the transformation RemoveCommentsChar * @todo Implement the transformation RemoveCommentsChar
*/ */
assay->debug(4, "Transformation RemoveCommentsChar is not implemented yet."); assay->debug(4, "Transformation RemoveCommentsChar " \
"is not implemented yet.");
return value; return value;
} }

View File

@ -49,7 +49,6 @@
#include "actions/transformations/replace_nulls.h" #include "actions/transformations/replace_nulls.h"
#include "actions/transformations/sha1.h" #include "actions/transformations/sha1.h"
#include "actions/transformations/sql_hex_decode.h" #include "actions/transformations/sql_hex_decode.h"
#include "actions/transformations/transformation.h"
#include "actions/transformations/trim.h" #include "actions/transformations/trim.h"
#include "actions/transformations/trim_left.h" #include "actions/transformations/trim_left.h"
#include "actions/transformations/trim_right.h" #include "actions/transformations/trim_right.h"
@ -79,7 +78,6 @@ std::string &Transformation::evaluate(std::string value,
} }
Transformation* Transformation::instantiate(std::string a) { Transformation* Transformation::instantiate(std::string a) {
IF_MATCH(base64_decode_ext) { return new Base64DecodeExt(a); } IF_MATCH(base64_decode_ext) { return new Base64DecodeExt(a); }
IF_MATCH(base64_decode) { return new Base64Decode(a); } IF_MATCH(base64_decode) { return new Base64Decode(a); }
IF_MATCH(cmd_line) { return new CmdLine(a); } IF_MATCH(cmd_line) { return new CmdLine(a); }

View File

@ -42,4 +42,4 @@ class TrimRight : public Trim {
#endif #endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_ #endif // SRC_ACTIONS_TRANSFORMATIONS_TRIM_RIGHT_H_

View File

@ -18,8 +18,8 @@
#include "actions/action.h" #include "actions/action.h"
#include "actions/transformations/transformation.h" #include "actions/transformations/transformation.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_UTF8_UNICODE_H_ #ifndef SRC_ACTIONS_TRANSFORMATIONS_UTF8_TO_UNICODE_H_
#define SRC_ACTIONS_TRANSFORMATIONS_UTF8_UNICODE_H_ #define SRC_ACTIONS_TRANSFORMATIONS_UTF8_TO_UNICODE_H_
#ifdef __cplusplus #ifdef __cplusplus
namespace ModSecurity { namespace ModSecurity {
@ -41,4 +41,4 @@ class Utf8Unicode : public Transformation {
#endif #endif
#endif // SRC_ACTIONS_TRANSFORMATIONS_UTF8_UNICODE_H_ #endif // SRC_ACTIONS_TRANSFORMATIONS_UTF8_TO_UNICODE_H_

View File

@ -118,7 +118,7 @@ void Assay::debug(int level, std::string message) {
* @retval false Operation failed. * @retval false Operation failed.
* *
*/ */
int Assay::processConnection(char *ipAddress) { int Assay::processConnection(const char *ipAddress) {
this->m_ipAddress = ipAddress; this->m_ipAddress = ipAddress;
debug(4, "Transaction context created (blah blah)"); debug(4, "Transaction context created (blah blah)");
debug(4, "Starting phase CONNECTION. (SecRules 0)"); debug(4, "Starting phase CONNECTION. (SecRules 0)");
@ -149,10 +149,10 @@ int Assay::processConnection(char *ipAddress) {
* @retval false Operation failed. * @retval false Operation failed.
* *
*/ */
int Assay::processURI(char *uri) { int Assay::processURI(const char *uri) {
debug(4, "Starting phase URI. (SecRules 0 + 1/2)"); debug(4, "Starting phase URI. (SecRules 0 + 1/2)");
char *pos = strchr(uri, '?'); const char *pos = strchr(uri, '?');
if (pos != NULL && strlen(pos) > 2) { if (pos != NULL && strlen(pos) > 2) {
/** /**
@ -711,7 +711,7 @@ extern "C" Assay *msc_new_assay(ModSecurity *ms,
* @retval 0 Operation failed. * @retval 0 Operation failed.
* *
*/ */
extern "C" int msc_process_connection(Assay *assay, char *buf) { extern "C" int msc_process_connection(Assay *assay, const char *buf) {
return assay->processConnection(buf); return assay->processConnection(buf);
} }
@ -737,7 +737,7 @@ extern "C" int msc_process_connection(Assay *assay, char *buf) {
* @retval 0 Operation failed. * @retval 0 Operation failed.
* *
*/ */
extern "C" int msc_process_uri(Assay *assay, char *buf) { extern "C" int msc_process_uri(Assay *assay, const char *buf) {
return assay->processURI(buf); return assay->processURI(buf);
} }

View File

@ -58,7 +58,7 @@ int Driver::parseFile(const std::string &f) {
parser.set_debug_level(trace_parsing); parser.set_debug_level(trace_parsing);
int res = parser.parse(); int res = parser.parse();
//std::cout << "Leaving the parser: " << res << std::endl; // std::cout << "Leaving the parser: " << res << std::endl;
scan_end(); scan_end();
return res; return res;

View File

@ -105,7 +105,7 @@ int Rules::loadRemote(char *key, char *uri) {
} }
int Rules::load(char *plain_rules) { int Rules::load(const char *plain_rules) {
bool ret = true; bool ret = true;
/** /**
* @todo rgg. we should make the parser work out of the buffer. * @todo rgg. we should make the parser work out of the buffer.
@ -252,7 +252,7 @@ extern "C" int msc_rules_add_file(Rules *rules, char *file) {
} }
extern "C" int msc_rules_add(Rules *rules, char *plain_rules) { extern "C" int msc_rules_add(Rules *rules, const char *plain_rules) {
rules->load(plain_rules); rules->load(plain_rules);
return 0; return 0;

View File

@ -93,30 +93,30 @@ int main(int argc, char *argv[]) {
continue; continue;
} }
modsecAssay->addRequestHeader((char *) "Host", modsecAssay->addRequestHeader("Host",
(char *) "net.tutsplus.com"); "net.tutsplus.com");
modsecAssay->addRequestHeader((char *) "User-Agent", (char *) modsecAssay->addRequestHeader("User-Agent",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) " \ "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) " \
"Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)\n\r"); "Gecko/20091102 Firefox/3.5.5 (.NET CLR 3.5.30729)\n\r");
modsecAssay->addRequestHeader((char *) "Accept", modsecAssay->addRequestHeader("Accept",
(char *) "text/html,application/xhtml+xml,application/xml;" \ "text/html,application/xhtml+xml,application/xml;" \
"q=0.9,*/*;q=0.8"); "q=0.9,*/*;q=0.8");
modsecAssay->addRequestHeader((char *) "Accept-Language", modsecAssay->addRequestHeader("Accept-Language",
(char *) "en-us,en;q=0.5"); "en-us,en;q=0.5");
modsecAssay->addRequestHeader((char *) "Accept-Encoding", modsecAssay->addRequestHeader("Accept-Encoding",
(char *) "gzip,deflate"); "gzip,deflate");
modsecAssay->addRequestHeader((char *) "Accept-Charset", modsecAssay->addRequestHeader("Accept-Charset",
(char *) "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
modsecAssay->addRequestHeader((char *) "Keep-Alive", modsecAssay->addRequestHeader("Keep-Alive",
(char *) "300"); "300");
modsecAssay->addRequestHeader((char *) "Connection", modsecAssay->addRequestHeader("Connection",
(char *) "keep-alive"); "keep-alive");
modsecAssay->addRequestHeader((char *) "Cookie", modsecAssay->addRequestHeader("Cookie",
(char *) "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120"); "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120");
modsecAssay->addRequestHeader((char *) "Pragma", modsecAssay->addRequestHeader("Pragma",
(char *) "no-cache"); "no-cache");
modsecAssay->addRequestHeader((char *) "Cache-Control", modsecAssay->addRequestHeader("Cache-Control",
(char *) "no-cache"); "no-cache");
modsecAssay->processRequestHeaders(); modsecAssay->processRequestHeaders();
if (modsecAssay->intervention()) { if (modsecAssay->intervention()) {
@ -132,12 +132,12 @@ int main(int argc, char *argv[]) {
continue; continue;
} }
modsecAssay->addResponseHeader((char *) "HTTP/1.1", modsecAssay->addResponseHeader("HTTP/1.1",
(char *) "200 OK"); "200 OK");
modsecAssay->addResponseHeader((char *) "Content-Type", modsecAssay->addResponseHeader("Content-Type",
(char *) "text/xml; charset=utf-8"); "text/xml; charset=utf-8");
modsecAssay->addResponseHeader((char *) "Content-Length", modsecAssay->addResponseHeader("Content-Length",
(char *) "200"); "200");
modsecAssay->processResponseHeaders(); modsecAssay->processResponseHeaders();

View File

@ -72,7 +72,7 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
modsec = new ModSecurity::ModSecurity(); modsec = new ModSecurity::ModSecurity();
modsec_rules = new ModSecurity::Rules(debug_log); modsec_rules = new ModSecurity::Rules(debug_log);
if (modsec_rules->load((char *)(t->rules.c_str())) == false) { if (modsec_rules->load(t->rules.c_str()) == false) {
std::cerr << "Problems parsing the rules, aborting!" << std::endl; std::cerr << "Problems parsing the rules, aborting!" << std::endl;
return; return;
} }
@ -80,14 +80,14 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
if (t->ip.empty() == false) { if (t->ip.empty() == false) {
// FIXME: no cast please. // FIXME: no cast please.
modsec_assay->processConnection((char *)(t->ip.c_str())); modsec_assay->processConnection(t->ip.c_str());
actions(&r, modsec_assay->intervention()); actions(&r, modsec_assay->intervention());
if (r.status != 200) { if (r.status != 200) {
goto end; goto end;
} }
} }
if (t->uri.empty() == false) { if (t->uri.empty() == false) {
modsec_assay->processURI((char *)(t->uri.c_str())); modsec_assay->processURI(t->uri.c_str());
actions(&r, modsec_assay->intervention()); actions(&r, modsec_assay->intervention());
if (r.status != 200) { if (r.status != 200) {
goto end; goto end;
@ -96,8 +96,8 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
for (std::pair<std::string, std::string> headers : for (std::pair<std::string, std::string> headers :
t->request_headers) { t->request_headers) {
modsec_assay->addRequestHeader((char *)headers.first.c_str(), modsec_assay->addRequestHeader(headers.first.c_str(),
(char *)headers.second.c_str()); headers.second.c_str());
} }
modsec_assay->processRequestHeaders(); modsec_assay->processRequestHeaders();
@ -117,8 +117,8 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
for (std::pair<std::string, std::string> headers : for (std::pair<std::string, std::string> headers :
t->response_headers) { t->response_headers) {
modsec_assay->addResponseHeader((char *)headers.first.c_str(), modsec_assay->addResponseHeader(headers.first.c_str(),
(char *)headers.second.c_str()); headers.second.c_str());
} }
modsec_assay->processResponseHeaders(); modsec_assay->processResponseHeaders();