Makes m_serverIpAddress a shared pointer

This commit is contained in:
Felipe Zimmerle 2019-01-22 15:18:25 -03:00
parent 8df35deadb
commit d7d5cd2a91
No known key found for this signature in database
GPG Key ID: E6DFB08CE8B11277
4 changed files with 16 additions and 14 deletions

View File

@ -108,7 +108,7 @@ class RuleMessage {
int m_ruleId; int m_ruleId;
int m_ruleLine; int m_ruleLine;
bool m_saveMessage; bool m_saveMessage;
std::string m_serverIpAddress; std::shared_ptr<std::string> m_serverIpAddress;
int m_severity; int m_severity;
std::string m_uriNoQueryStringDecoded; std::string m_uriNoQueryStringDecoded;
std::string m_ver; std::string m_ver;

View File

@ -400,7 +400,7 @@ class Transaction : public TransactionAnchoredVariables {
/** /**
* Holds the server IP Address * Holds the server IP Address
*/ */
std::string m_serverIpAddress; std::shared_ptr<std::string> m_serverIpAddress;
/** /**
* Holds the raw URI that was requested. * Holds the raw URI that was requested.

View File

@ -40,7 +40,7 @@ std::string RuleMessage::_details(const RuleMessage *rm) {
for (auto &a : rm->m_tags) { for (auto &a : rm->m_tags) {
msg.append(" [tag \"" + a + "\"]"); msg.append(" [tag \"" + a + "\"]");
} }
msg.append(" [hostname \"" + std::string(rm->m_serverIpAddress) \ msg.append(" [hostname \"" + *rm->m_serverIpAddress.get() \
+ "\"]"); + "\"]");
msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]"); msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]");
msg.append(" [unique_id \"" + rm->m_id + "\"]"); msg.append(" [unique_id \"" + rm->m_id + "\"]");
@ -53,7 +53,7 @@ std::string RuleMessage::_details(const RuleMessage *rm) {
std::string RuleMessage::_errorLogTail(const RuleMessage *rm) { std::string RuleMessage::_errorLogTail(const RuleMessage *rm) {
std::string msg; std::string msg;
msg.append("[hostname \"" + std::string(rm->m_serverIpAddress) + "\"]"); msg.append("[hostname \"" + *rm->m_serverIpAddress.get() + "\"]");
msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]"); msg.append(" [uri \"" + utils::string::limitTo(200, rm->m_uriNoQueryStringDecoded) + "\"]");
msg.append(" [unique_id \"" + rm->m_id + "\"]"); msg.append(" [unique_id \"" + rm->m_id + "\"]");

View File

@ -103,9 +103,9 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, void *logCbData)
: m_creationTimeStamp(utils::cpu_seconds()), : m_creationTimeStamp(utils::cpu_seconds()),
/* m_clientIpAddress(nullptr), */ /* m_clientIpAddress(nullptr), */
m_httpVersion(""), m_httpVersion(""),
m_serverIpAddress(""), /* m_serverIpAddress(""), */
m_uri(""), m_uri(""),
m_uri_no_query_string_decoded(""), /* m_uri_no_query_string_decoded(""), */
m_ARGScombinedSizeDouble(0), m_ARGScombinedSizeDouble(0),
m_clientPort(0), m_clientPort(0),
m_highestSeverityAction(255), m_highestSeverityAction(255),
@ -176,9 +176,9 @@ Transaction::Transaction(ModSecurity *ms, RulesSet *rules, char *id, void *logCb
: m_creationTimeStamp(utils::cpu_seconds()), : m_creationTimeStamp(utils::cpu_seconds()),
/* m_clientIpAddress(""), */ /* m_clientIpAddress(""), */
m_httpVersion(""), m_httpVersion(""),
m_serverIpAddress(""), /* m_serverIpAddress(""), */
m_uri(""), m_uri(""),
m_uri_no_query_string_decoded(""), /* m_uri_no_query_string_decoded(""), */
m_ARGScombinedSizeDouble(0), m_ARGScombinedSizeDouble(0),
m_clientPort(0), m_clientPort(0),
m_highestSeverityAction(255), m_highestSeverityAction(255),
@ -310,7 +310,7 @@ void Transaction::debug(int level, std::string message) const {
int Transaction::processConnection(const char *client, int cPort, int Transaction::processConnection(const char *client, int cPort,
const char *server, int sPort) { const char *server, int sPort) {
m_clientIpAddress = std::unique_ptr<std::string>(new std::string(client)); m_clientIpAddress = std::unique_ptr<std::string>(new std::string(client));
this->m_serverIpAddress = server; m_serverIpAddress = std::unique_ptr<std::string>(new std::string(server));
this->m_clientPort = cPort; this->m_clientPort = cPort;
this->m_serverPort = sPort; this->m_serverPort = sPort;
ms_dbg(4, "Transaction context created."); ms_dbg(4, "Transaction context created.");
@ -320,7 +320,7 @@ int Transaction::processConnection(const char *client, int cPort,
m_variableRemoteHost.set(*m_clientIpAddress.get(), m_variableOffset); m_variableRemoteHost.set(*m_clientIpAddress.get(), m_variableOffset);
m_variableUniqueID.set(m_id, m_variableOffset); m_variableUniqueID.set(m_id, m_variableOffset);
m_variableRemoteAddr.set(*m_clientIpAddress.get(), m_variableOffset); m_variableRemoteAddr.set(*m_clientIpAddress.get(), m_variableOffset);
m_variableServerAddr.set(m_serverIpAddress, m_variableOffset); m_variableServerAddr.set(*m_serverIpAddress.get(), m_variableOffset);
m_variableServerPort.set(std::to_string(this->m_serverPort), m_variableServerPort.set(std::to_string(this->m_serverPort),
m_variableOffset); m_variableOffset);
m_variableRemotePort.set(std::to_string(this->m_clientPort), m_variableRemotePort.set(std::to_string(this->m_clientPort),
@ -470,9 +470,11 @@ int Transaction::processURI(const char *uri, const char *method,
if (pos != std::string::npos) { if (pos != std::string::npos) {
m_uri_no_query_string_decoded = std::string(m_uri_decoded, 0, pos); m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
new std::string(m_uri_decoded, 0, pos));
} else { } else {
m_uri_no_query_string_decoded = std::string(m_uri_decoded); m_uri_no_query_string_decoded = std::unique_ptr<std::string>(
new std::string(m_uri_decoded));
} }
@ -1523,7 +1525,7 @@ std::string Transaction::toOldAuditLogFormat(int parts,
audit_log << " " << this->m_id.c_str(); audit_log << " " << this->m_id.c_str();
audit_log << " " << this->m_clientIpAddress; audit_log << " " << this->m_clientIpAddress;
audit_log << " " << this->m_clientPort; audit_log << " " << this->m_clientPort;
audit_log << " " << this->m_serverIpAddress; audit_log << " " << m_serverIpAddress;
audit_log << " " << this->m_serverPort; audit_log << " " << this->m_serverPort;
audit_log << std::endl; audit_log << std::endl;
@ -1644,7 +1646,7 @@ std::string Transaction::toJSON(int parts) {
LOGFY_ADD("time_stamp", ts.c_str()); LOGFY_ADD("time_stamp", ts.c_str());
LOGFY_ADD("server_id", uniqueId.c_str()); LOGFY_ADD("server_id", uniqueId.c_str());
LOGFY_ADD_NUM("client_port", m_clientPort); LOGFY_ADD_NUM("client_port", m_clientPort);
LOGFY_ADD("host_ip", m_serverIpAddress.c_str()); LOGFY_ADD("host_ip", m_serverIpAddress->c_str());
LOGFY_ADD_NUM("host_port", m_serverPort); LOGFY_ADD_NUM("host_port", m_serverPort);
LOGFY_ADD("unique_id", this->m_id.c_str()); LOGFY_ADD("unique_id", this->m_id.c_str());