Procházet zdrojové kódy

Updated to use HEAD of submodules.

Added codedweller namespace, and snfIPRange prefix.
master
Alban Deniz před 9 měsíci
rodič
revize
e012e6f03e
2 změnil soubory, kde provedl 24 přidání a 24 odebrání
  1. 19
    19
      SNFMilter.cpp
  2. 5
    5
      SNFMilter.hpp

+ 19
- 19
SNFMilter.cpp Zobrazit soubor

@@ -79,13 +79,13 @@ void logError(const string &ContextName, const int &Code, const std::string &Mes
MilterContexts->logThisError(ContextName, Code, Message); // Log message.
}
class ResultActionHandler : public Configurator {
class ResultActionHandler : public codedweller::Configurator {
private:
SNFMilterEngine* Target;
public:
ResultActionHandler(SNFMilterEngine* T) : Target(T) {}
void operator()(ConfigurationElement& E, ConfigurationData& D) {
void operator()(codedweller::ConfigurationElement& E, codedweller::ConfigurationData& D) {
Target->setResultAction(
Code,
(Action >= Allow && Action <= Quarantine) ?
@@ -114,7 +114,7 @@ void SNFMilterEngine::readConfiguration() {
NonZeroAction = NoAction; // NoAction if no configuration for
// non-zero result.
ResultActionHandler ResultActionConfigurator(this); // Create a Result/Action handler.
ConfigurationElement Reader("milter"); // Create a configuration reader.
codedweller::ConfigurationElement Reader("milter"); // Create a configuration reader.
Reader
.Element("connect")
.Element("white")
@@ -177,7 +177,7 @@ void SNFMilterEngine::readConfiguration() {
.End("nonzero")
.End("scan")
.End("milter");
ConfigurationData ConfigurationData( // Convert our configuration string
codedweller::ConfigurationData ConfigurationData( // Convert our configuration string
NewConfiguration.c_str(), // to a configuration data buffer.
NewConfiguration.length());
@@ -214,7 +214,7 @@ SNFMilterEngine::SNFMilterEngine(snf_RulebaseHandler* R) :
SNFMilterEngine::~SNFMilterEngine() { // Destroy the engine.
try {
ScopeMutex EngineLock(ConfigMutex); // Don't die while scanning.
codedweller::ScopeMutex EngineLock(ConfigMutex); // Don't die while scanning.
if(myEngine) { // If we're not dead then die.
myEngine->close(); // Close the engine.
delete myEngine; // Delete it.
@@ -227,16 +227,16 @@ SNFMilterEngine::~SNFMilterEngine() {
SNFMilterAction SNFMilterEngine::scanIP(unsigned long int IP) { // Scans an IP.
IPTestRecord Tester(IP); // Make up a test record for this IP.
ScopeMutex ConfigurationLock(ConfigMutex); // Lock our configuration.
codedweller::ScopeMutex ConfigurationLock(ConfigMutex); // Lock our configuration.
if(0 == myEngine) throw runtime_error("Null engine when scanning IP"); // Skip safely if we're down.
checkConfiguration(); // Re-read our config if it is old.
myRulebase->performIPTest(Tester); // Tun it past the engine.
SNFMilterAction TestResult = Allow; // Allow by default.
switch(Tester.R) { // Convert the result to an action.
case White: { TestResult = WhiteAction; break; } // If the IP scan range is recognized
case Caution: { TestResult = CautionAction; break; } // in our configuration then we will
case Black: { TestResult = BlackAction; break; } // return the action code that is
case Truncate: { TestResult = TruncateAction; break; } // configured. Otherwise we will return
case snfIPRange::White: { TestResult = WhiteAction; break; } // If the IP scan range is recognized
case snfIPRange::Caution: { TestResult = CautionAction; break; } // in our configuration then we will
case snfIPRange::Black: { TestResult = BlackAction; break; } // return the action code that is
case snfIPRange::Truncate: { TestResult = TruncateAction; break; } // configured. Otherwise we will return
default: break;
} // the default "Allow" action.
return TestResult; // Tell them what we've got.
@@ -245,7 +245,7 @@ SNFMilterAction SNFMilterEngine::scanIP(unsigned long int IP) {
SNFMilterAction SNFMilterEngine::scanMessage( // Scans a message.
const unsigned char* bfr, // Requires a pointer to the buffer.
int length) { // Requires the buffer length.
ScopeMutex ConfigurationLock(ConfigMutex); // Lock the configuration.
codedweller::ScopeMutex ConfigurationLock(ConfigMutex); // Lock the configuration.
if(0 == myEngine) throw runtime_error("Null engine when scanning message"); // Skip safely if we're down.
checkConfiguration(); // Re-read our config if it is old.
int R = myEngine->scanMessage(bfr, length, "", 0); // Scan the message & get the result.
@@ -255,7 +255,7 @@ SNFMilterAction SNFMilterEngine::scanMessage(
}
string SNFMilterEngine::XHeaders() { // Return X headers from last scan.
ScopeMutex EngineLock(ConfigMutex); // Use myEngine safely.
codedweller::ScopeMutex EngineLock(ConfigMutex); // Use myEngine safely.
if(0 == myEngine) return ""; // Return no headers if dead.
return myEngine->getXHDRs(); // Simply return them.
}
@@ -324,7 +324,7 @@ SNFMilterContextPool::SNFMilterContextPool(snf_RulebaseHandler* Rulebase) :
MilterSocketPort(0) {
string NewConfiguration = myRulebase->PlatformConfiguration(); // Get the latest configuration.
ConfigurationElement Reader("milter"); // Create a configuration reader.
codedweller::ConfigurationElement Reader("milter"); // Create a configuration reader.
Reader
.Element("socket")
.Attribute("type", reinterpret_cast<int&>(MilterSocketType), static_cast<int>(NOMilterSocket))
@@ -337,9 +337,9 @@ SNFMilterContextPool::SNFMilterContextPool(snf_RulebaseHandler* Rulebase) :
.End("socket")
.End("milter");
ConfigurationData ConfigurationData( // Convert our configuration string
NewConfiguration.c_str(), // to a configuration data buffer.
NewConfiguration.length());
codedweller::ConfigurationData ConfigurationData( // Convert our configuration string
NewConfiguration.c_str(), // to a configuration data buffer.
NewConfiguration.length());
Reader.initialize(); // Initialize the defaults.
Reader.interpret(ConfigurationData); // Read the new configuration.
@@ -413,7 +413,7 @@ string SNFMilterContextPool::getSocketIP() { return MilterSocketIP; }
int SNFMilterContextPool::getSocketPort() { return MilterSocketPort; }
SNFMilterContextPool::~SNFMilterContextPool() { // Dtor gracefully discards contexts.
ScopeMutex ContextPoolLock(ContextAllocationControl); // Lock the context allocation system.
codedweller::ScopeMutex ContextPoolLock(ContextAllocationControl); // Lock the context allocation system.
myRulebase = 0; // Forget our rulebase. We're dead.
for( // Loop through the context pool
vector<SNFMilterContext*>::iterator iC = ContextPool.begin(); // and delete any contexts we have
@@ -422,7 +422,7 @@ SNFMilterContextPool::~SNFMilterContextPool() {
}
SNFMilterContext* SNFMilterContextPool::grab() { // Get a context to use.
ScopeMutex ContextPoolLock(ContextAllocationControl); // Lock the context allocation system.
codedweller::ScopeMutex ContextPoolLock(ContextAllocationControl); // Lock the context allocation system.
if(0 == myRulebase) return 0; // No contexts left if we're dead.
if(1 > AvailableContexts.size()) { // If we need more contexts then
SNFMilterContext* N = new SNFMilterContext(myRulebase); // Create a new context,
@@ -1364,7 +1364,7 @@ void runLibMilter(SNFMilterContextPool* Contexts, bool DebugMode) {
logInfo(ContextName, InfoCode, "Shutdown command received. Waiting for message processing to complete...");
Sleeper WaitATic;
codedweller::Sleeper WaitATic;
try {

+ 5
- 5
SNFMilter.hpp Zobrazit soubor

@@ -85,7 +85,7 @@ const string UnknownExceptionMessage = "Unknown exception occurred.";
class SNFMilterEngine { // Milter config objec. One per scan.
private:
Mutex ConfigMutex; // Configuration lock mutex.
codedweller::Mutex ConfigMutex; // Configuration lock mutex.
snf_RulebaseHandler* myRulebase; // Where is my rulebase?
snf_EngineHandler* myEngine; // Where is my engine?
@@ -103,7 +103,7 @@ private:
SNFMilterAction ResultActions[ResultCodesCount]; // Array of possible scan actions.
Timeout ConfigurationCheckTime; // Timer for checking the configuration.
codedweller::Timeout ConfigurationCheckTime; // Timer for checking the configuration.
string RunningConfiguration; // The current running config string.
void readConfiguration(); // Parses the configuration.
void checkConfiguration(); // Reload the config if it is old.
@@ -162,7 +162,7 @@ public:
// Connection data.
struct SNFMilterConnectionData {
string HostName;
IP4Address HostIP;
codedweller::IP4Address HostIP;
string HostHelo;
// Clear the object.
@@ -200,9 +200,9 @@ public:
class SNFMilterContextPool { // SNFMilter Pool Manager
private:
Mutex ContextAllocationControl; // Protects context allocation.
codedweller::Mutex ContextAllocationControl; // Protects context allocation.
vector<SNFMilterContext*> ContextPool; // Contains all created contexts.
ProductionQueue<SNFMilterContext*> AvailableContexts; // Contains all available contexts.
codedweller::ProductionQueue<SNFMilterContext*> AvailableContexts; // Contains all available contexts.
snf_RulebaseHandler* myRulebase; // Rulebase handler.

Načítá se…
Zrušit
Uložit