diff --git a/headers/modsecurity/assay.h b/headers/modsecurity/assay.h index 547df60c..13c71bcf 100644 --- a/headers/modsecurity/assay.h +++ b/headers/modsecurity/assay.h @@ -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 */ diff --git a/headers/modsecurity/intervention.h b/headers/modsecurity/intervention.h index 0a5d13ab..a6bedb42 100644 --- a/headers/modsecurity/intervention.h +++ b/headers/modsecurity/intervention.h @@ -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 diff --git a/headers/modsecurity/rules.h b/headers/modsecurity/rules.h index b0f195e6..e74f3fd1 100644 --- a/headers/modsecurity/rules.h +++ b/headers/modsecurity/rules.h @@ -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 } diff --git a/src/actions/redirect.cc b/src/actions/redirect.cc index 47cc7456..36a1197a 100644 --- a/src/actions/redirect.cc +++ b/src/actions/redirect.cc @@ -44,7 +44,7 @@ void Redirect::fill_intervention(ModSecurityIntervention *i) { i->status = this->status; } // reinterpret_cast - i->url = (char *) this->url.c_str(); //** TODO: wheee */ + i->url = this->url.c_str(); //** TODO: wheee */ i->log = "Redirecting"; } diff --git a/src/actions/transformations/compress_whitespace.cc b/src/actions/transformations/compress_whitespace.cc index c6864ad3..e0ac69e3 100644 --- a/src/actions/transformations/compress_whitespace.cc +++ b/src/actions/transformations/compress_whitespace.cc @@ -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 diff --git a/src/actions/transformations/hex_decode.h b/src/actions/transformations/hex_decode.h index a863f9b5..3f6bc48b 100644 --- a/src/actions/transformations/hex_decode.h +++ b/src/actions/transformations/hex_decode.h @@ -41,4 +41,4 @@ class HexDecode : public Transformation { #endif -#endif // SRC_ACTIONS_TRANSFORMATIONS_BASE64DECODE_H_ +#endif // SRC_ACTIONS_TRANSFORMATIONS_HEX_DECODE_H_ diff --git a/src/actions/transformations/hex_encode.h b/src/actions/transformations/hex_encode.h index 4709a76c..4946e85d 100644 --- a/src/actions/transformations/hex_encode.h +++ b/src/actions/transformations/hex_encode.h @@ -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_ diff --git a/src/actions/transformations/parity_odd_7bit.h b/src/actions/transformations/parity_odd_7bit.h index 491d7ce4..63e81a8e 100644 --- a/src/actions/transformations/parity_odd_7bit.h +++ b/src/actions/transformations/parity_odd_7bit.h @@ -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_ diff --git a/src/actions/transformations/remove_comments.cc b/src/actions/transformations/remove_comments.cc index 997d0860..3ee437d1 100644 --- a/src/actions/transformations/remove_comments.cc +++ b/src/actions/transformations/remove_comments.cc @@ -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; } diff --git a/src/actions/transformations/remove_comments_char.cc b/src/actions/transformations/remove_comments_char.cc index f4833bc2..dfb3fed2 100644 --- a/src/actions/transformations/remove_comments_char.cc +++ b/src/actions/transformations/remove_comments_char.cc @@ -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; } diff --git a/src/actions/transformations/transformation.cc b/src/actions/transformations/transformation.cc index bb166b66..62e91fa2 100644 --- a/src/actions/transformations/transformation.cc +++ b/src/actions/transformations/transformation.cc @@ -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); } diff --git a/src/actions/transformations/trim_right.cc b/src/actions/transformations/trim_right.cc index 05bc5125..911749e2 100644 --- a/src/actions/transformations/trim_right.cc +++ b/src/actions/transformations/trim_right.cc @@ -30,7 +30,7 @@ namespace ModSecurity { namespace actions { namespace transformations { - + TrimRight::TrimRight(std::string action) : Trim(action) { this->action_kind = 1; diff --git a/src/actions/transformations/trim_right.h b/src/actions/transformations/trim_right.h index a2d93a2f..9ac171f6 100644 --- a/src/actions/transformations/trim_right.h +++ b/src/actions/transformations/trim_right.h @@ -42,4 +42,4 @@ class TrimRight : public Trim { #endif -#endif // SRC_ACTIONS_TRANSFORMATIONS_TRIM_H_ +#endif // SRC_ACTIONS_TRANSFORMATIONS_TRIM_RIGHT_H_ diff --git a/src/actions/transformations/utf8_to_unicode.h b/src/actions/transformations/utf8_to_unicode.h index a6904503..3435aa11 100644 --- a/src/actions/transformations/utf8_to_unicode.h +++ b/src/actions/transformations/utf8_to_unicode.h @@ -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_ diff --git a/src/assay.cc b/src/assay.cc index 463fcfe2..1a74f06c 100644 --- a/src/assay.cc +++ b/src/assay.cc @@ -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); } diff --git a/src/parser/driver.cc b/src/parser/driver.cc index c3ba621f..f2d820e8 100644 --- a/src/parser/driver.cc +++ b/src/parser/driver.cc @@ -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; diff --git a/src/rules.cc b/src/rules.cc index 0095a495..78de4bf2 100644 --- a/src/rules.cc +++ b/src/rules.cc @@ -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; diff --git a/test/benchmark/benchmark.cc b/test/benchmark/benchmark.cc index d1108519..fdf491f9 100644 --- a/test/benchmark/benchmark.cc +++ b/test/benchmark/benchmark.cc @@ -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(); diff --git a/test/regression/regression.cc b/test/regression/regression.cc index 870b8be3..9ab7788e 100644 --- a/test/regression/regression.cc +++ b/test/regression/regression.cc @@ -72,7 +72,7 @@ void perform_unit_test(std::vector *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 *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 *tests, for (std::pair 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 *tests, for (std::pair 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();