Felipe Zimmerle 59114dd598
Refactoring on the operators parsers (2/2)
This is the first step towards remove the memory leaks in the parser
2017-03-06 15:01:50 -03:00

113 lines
3.0 KiB
C++

/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#ifndef SRC_OPERATORS_RBL_H_
#define SRC_OPERATORS_RBL_H_
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include "src/operators/operator.h"
namespace modsecurity {
namespace operators {
class Rbl : public Operator {
public:
/**
*
*/
enum RblProvider {
/**
* UnknownProvider
*
*/
UnknownProvider,
/**
* httpbl.org
*
*/
httpbl,
/**
* uribl.com
*
*/
uribl,
/**
* spamhaus.org
*
*/
spamhaus,
};
/** @ingroup ModSecurity_Operator */
Rbl(std::string op, std::string param, bool negation)
: Operator(op, param, negation),
m_service(param),
m_demandsPassword(false) {
m_provider = RblProvider::UnknownProvider;
if (m_service == "httpbl.org") {
m_demandsPassword = true;
m_provider = RblProvider::httpbl;
} else if (m_service == "uribl.com") {
m_provider = RblProvider::httpbl;
} else if (m_service == "spamhaus.org") {
m_provider = RblProvider::httpbl;
}
}
explicit Rbl(std::string param)
: Operator("Rbl", param),
m_service(param),
m_demandsPassword(false) {
m_provider = RblProvider::UnknownProvider;
if (m_service == "httpbl.org") {
m_demandsPassword = true;
m_provider = RblProvider::httpbl;
} else if (m_service == "uribl.com") {
m_provider = RblProvider::httpbl;
} else if (m_service == "spamhaus.org") {
m_provider = RblProvider::httpbl;
}
}
bool evaluate(Transaction *transaction, const std::string &str) override;
std::string mapIpToAddress(std::string ipStr, Transaction *trans);
void futherInfo_httpbl(struct sockaddr_in *sin, std::string ipStr,
Transaction *trans);
void futherInfo_spamhaus(unsigned int high8bits, std::string ipStr,
Transaction *trans);
void futherInfo_uribl(unsigned int high8bits, std::string ipStr,
Transaction *trans);
void furtherInfo(struct sockaddr_in *sin, std::string ipStr,
Transaction *trans);
std::string m_service;
bool m_demandsPassword;
RblProvider m_provider;
};
} // namespace operators
} // namespace modsecurity
#endif // SRC_OPERATORS_RBL_H_