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();
/** TODO: Should be an structure that fits an IP address */
int processConnection(char *ip);
int processURI(char *uri);
int processConnection(const char *ip);
int processURI(const char *uri);
int processRequestHeaders();
@ -130,8 +130,8 @@ class Assay {
private:
std::ofstream myfile;
Rules *m_rules;
char *m_ipAddress;
char *m_uri;
const char *m_ipAddress;
const char *m_uri;
std::ostringstream m_requestBody;
std::ostringstream m_responseBody;
ModSecurityCollectionsVariables m_variables_collections;
@ -148,7 +148,7 @@ extern "C" {
Assay *msc_new_assay(ModSecurity *ms, Rules *rules);
/** @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 */
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);
/** @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 */
const char *msc_get_response_body(Assay *assay);
/** @ingroup ModSecurity_C_API */

View File

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

View File

@ -64,7 +64,7 @@ class Rules {
*/
int loadFromUri(char *uri);
int loadRemote(char *key, char *uri);
int load(char *rules);
int load(const char *rules);
int merge(Driver *driver);
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_add_remote(Rules *rules, char *key, char *uri);
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
}

View File

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

View File

@ -40,7 +40,8 @@ std::string& CompressWhitespace::evaluate(std::string value,
/**
* @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

View File

@ -41,4 +41,4 @@ class HexDecode : public Transformation {
#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/transformations/transformation.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_BASE64DECODE_H_
#define SRC_ACTIONS_TRANSFORMATIONS_BASE64DECODE_H_
#ifndef SRC_ACTIONS_TRANSFORMATIONS_HEX_ENCODE_H_
#define SRC_ACTIONS_TRANSFORMATIONS_HEX_ENCODE_H_
#ifdef __cplusplus
namespace ModSecurity {
@ -41,4 +41,4 @@ class HexEncode : public Transformation {
#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 // 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
*/
assay->debug(4, "Transformation RemoveComments is not implemented yet.");
assay->debug(4, "Transformation RemoveComments is not " \
"implemented yet.");
return value;
}

View File

@ -40,7 +40,8 @@ std::string& RemoveCommentsChar::evaluate(std::string value,
/**
* @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;
}

View File

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

View File

@ -30,7 +30,7 @@ namespace ModSecurity {
namespace actions {
namespace transformations {
TrimRight::TrimRight(std::string action)
: Trim(action) {
this->action_kind = 1;

View File

@ -42,4 +42,4 @@ class TrimRight : public Trim {
#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/transformations/transformation.h"
#ifndef SRC_ACTIONS_TRANSFORMATIONS_UTF8_UNICODE_H_
#define SRC_ACTIONS_TRANSFORMATIONS_UTF8_UNICODE_H_
#ifndef SRC_ACTIONS_TRANSFORMATIONS_UTF8_TO_UNICODE_H_
#define SRC_ACTIONS_TRANSFORMATIONS_UTF8_TO_UNICODE_H_
#ifdef __cplusplus
namespace ModSecurity {
@ -41,4 +41,4 @@ class Utf8Unicode : public Transformation {
#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.
*
*/
int Assay::processConnection(char *ipAddress) {
int Assay::processConnection(const char *ipAddress) {
this->m_ipAddress = ipAddress;
debug(4, "Transaction context created (blah blah)");
debug(4, "Starting phase CONNECTION. (SecRules 0)");
@ -149,10 +149,10 @@ int Assay::processConnection(char *ipAddress) {
* @retval false Operation failed.
*
*/
int Assay::processURI(char *uri) {
int Assay::processURI(const char *uri) {
debug(4, "Starting phase URI. (SecRules 0 + 1/2)");
char *pos = strchr(uri, '?');
const char *pos = strchr(uri, '?');
if (pos != NULL && strlen(pos) > 2) {
/**
@ -711,7 +711,7 @@ extern "C" Assay *msc_new_assay(ModSecurity *ms,
* @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);
}
@ -737,7 +737,7 @@ extern "C" int msc_process_connection(Assay *assay, char *buf) {
* @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);
}

View File

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

View File

@ -93,30 +93,30 @@ int main(int argc, char *argv[]) {
continue;
}
modsecAssay->addRequestHeader((char *) "Host",
(char *) "net.tutsplus.com");
modsecAssay->addRequestHeader((char *) "User-Agent", (char *)
modsecAssay->addRequestHeader("Host",
"net.tutsplus.com");
modsecAssay->addRequestHeader("User-Agent",
"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");
modsecAssay->addRequestHeader((char *) "Accept",
(char *) "text/html,application/xhtml+xml,application/xml;" \
modsecAssay->addRequestHeader("Accept",
"text/html,application/xhtml+xml,application/xml;" \
"q=0.9,*/*;q=0.8");
modsecAssay->addRequestHeader((char *) "Accept-Language",
(char *) "en-us,en;q=0.5");
modsecAssay->addRequestHeader((char *) "Accept-Encoding",
(char *) "gzip,deflate");
modsecAssay->addRequestHeader((char *) "Accept-Charset",
(char *) "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
modsecAssay->addRequestHeader((char *) "Keep-Alive",
(char *) "300");
modsecAssay->addRequestHeader((char *) "Connection",
(char *) "keep-alive");
modsecAssay->addRequestHeader((char *) "Cookie",
(char *) "PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120");
modsecAssay->addRequestHeader((char *) "Pragma",
(char *) "no-cache");
modsecAssay->addRequestHeader((char *) "Cache-Control",
(char *) "no-cache");
modsecAssay->addRequestHeader("Accept-Language",
"en-us,en;q=0.5");
modsecAssay->addRequestHeader("Accept-Encoding",
"gzip,deflate");
modsecAssay->addRequestHeader("Accept-Charset",
"ISO-8859-1,utf-8;q=0.7,*;q=0.7");
modsecAssay->addRequestHeader("Keep-Alive",
"300");
modsecAssay->addRequestHeader("Connection",
"keep-alive");
modsecAssay->addRequestHeader("Cookie",
"PHPSESSID=r2t5uvjq435r4q7ib3vtdjq120");
modsecAssay->addRequestHeader("Pragma",
"no-cache");
modsecAssay->addRequestHeader("Cache-Control",
"no-cache");
modsecAssay->processRequestHeaders();
if (modsecAssay->intervention()) {
@ -132,12 +132,12 @@ int main(int argc, char *argv[]) {
continue;
}
modsecAssay->addResponseHeader((char *) "HTTP/1.1",
(char *) "200 OK");
modsecAssay->addResponseHeader((char *) "Content-Type",
(char *) "text/xml; charset=utf-8");
modsecAssay->addResponseHeader((char *) "Content-Length",
(char *) "200");
modsecAssay->addResponseHeader("HTTP/1.1",
"200 OK");
modsecAssay->addResponseHeader("Content-Type",
"text/xml; charset=utf-8");
modsecAssay->addResponseHeader("Content-Length",
"200");
modsecAssay->processResponseHeaders();

View File

@ -72,7 +72,7 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
modsec = new ModSecurity::ModSecurity();
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;
return;
}
@ -80,14 +80,14 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
if (t->ip.empty() == false) {
// FIXME: no cast please.
modsec_assay->processConnection((char *)(t->ip.c_str()));
modsec_assay->processConnection(t->ip.c_str());
actions(&r, modsec_assay->intervention());
if (r.status != 200) {
goto end;
}
}
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());
if (r.status != 200) {
goto end;
@ -96,8 +96,8 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
for (std::pair<std::string, std::string> headers :
t->request_headers) {
modsec_assay->addRequestHeader((char *)headers.first.c_str(),
(char *)headers.second.c_str());
modsec_assay->addRequestHeader(headers.first.c_str(),
headers.second.c_str());
}
modsec_assay->processRequestHeaders();
@ -117,8 +117,8 @@ void perform_unit_test(std::vector<RegressionTest *> *tests,
for (std::pair<std::string, std::string> headers :
t->response_headers) {
modsec_assay->addResponseHeader((char *)headers.first.c_str(),
(char *)headers.second.c_str());
modsec_assay->addResponseHeader(headers.first.c_str(),
headers.second.c_str());
}
modsec_assay->processResponseHeaders();