|
|
@@ -4,23 +4,258 @@ |
|
|
|
|
|
|
|
#include "ConfigurationEngine.hpp"
|
|
|
|
#include "..\SNFMulti\SNFMulti.hpp"
|
|
|
|
#include "..\CodeDweller\configuration.hpp"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
const int InputGroup::NotSet = -1;
|
|
|
|
const int InputGroup::SetFalse = 0;
|
|
|
|
const int InputGroup::SetTrue = 1;
|
|
|
|
|
|
|
|
ConfigurationManager::ConfigurationManager(snf_RulebaseHandler& R) :
|
|
|
|
Rulebase(R),
|
|
|
|
Generation_(0),
|
|
|
|
Configurations(ResultConfigurationSize) {
|
|
|
|
for(size_t i = 0; i < Configurations.size(); i++) {
|
|
|
|
Configurations[i].ResultCode = i;
|
|
|
|
}
|
|
|
|
Rulebase(R),
|
|
|
|
Generation_(0),
|
|
|
|
Configurations(ResultConfigurationSize) {
|
|
|
|
for(size_t i = 0; i < Configurations.size(); i++) {
|
|
|
|
Configurations[i].ResultCode = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConfigurationManager::isOutOfDate() {
|
|
|
|
return (Generation_ != Rulebase.Generation());
|
|
|
|
}
|
|
|
|
|
|
|
|
class ResultActionHandler : public Configurator {
|
|
|
|
private:
|
|
|
|
vector<ResultConfiguration>& Configurations;
|
|
|
|
InputGroup& Defaults;
|
|
|
|
InputGroup& Inputs;
|
|
|
|
set<int>& ConfiguredCodes;
|
|
|
|
|
|
|
|
bool isValidCode(int I) {
|
|
|
|
if(
|
|
|
|
0 <= I &&
|
|
|
|
I < (int) Configurations.size()
|
|
|
|
) return true;
|
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
ResultActionHandler( // ResultHanlder Constructed with...
|
|
|
|
vector<ResultConfiguration>& C, // Reference to the configuration vector,
|
|
|
|
InputGroup& D, // Defaults InputGroup,
|
|
|
|
InputGroup& I, // Code specific InputGroup,
|
|
|
|
set<int>& T) : // Configured Codes Tracker.
|
|
|
|
Configurations(C),
|
|
|
|
Defaults(D),
|
|
|
|
Inputs(I),
|
|
|
|
ConfiguredCodes(T) {}
|
|
|
|
|
|
|
|
void operator()(ConfigurationElement& E, ConfigurationData& D) {
|
|
|
|
Inputs.applyDefaults(Defaults);
|
|
|
|
if(isValidCode(Inputs.Code)) {
|
|
|
|
Configurations[Inputs.Code] = Inputs;
|
|
|
|
ConfiguredCodes.insert(Inputs.Code);
|
|
|
|
}
|
|
|
|
Inputs.reset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
string IntAsString(int I) {
|
|
|
|
ostringstream O;
|
|
|
|
O << I;
|
|
|
|
return O.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isHamResultCode(int& I) {
|
|
|
|
return (
|
|
|
|
0 == I ||
|
|
|
|
1 == I
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ConfigurationManager::hasNotBeenConfigured(int& Code) {
|
|
|
|
return (
|
|
|
|
ConfiguredCodes.end() == ConfiguredCodes.find(Code)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConfigurationManager::update() {
|
|
|
|
|
|
|
|
for(size_t i = 0; i < Configurations.size(); i++) Configurations[i].clearSettings();
|
|
|
|
|
|
|
|
InputGroup HamInputDefaults;
|
|
|
|
InputGroup SpamInputDefaults;
|
|
|
|
InputGroup CurrentInputs;
|
|
|
|
|
|
|
|
ConfiguredCodes.clear();
|
|
|
|
|
|
|
|
ResultActionHandler HamResultHandler(Configurations, HamInputDefaults, CurrentInputs, ConfiguredCodes);
|
|
|
|
ResultActionHandler SpamResultHandler(Configurations, SpamInputDefaults, CurrentInputs, ConfiguredCodes);
|
|
|
|
|
|
|
|
const string AllowMnemonic = IntAsString(ResultConfiguration::Allow);
|
|
|
|
const string BypassMnemonic = IntAsString(ResultConfiguration::Bypass);
|
|
|
|
const string DeleteMnemonic = IntAsString(ResultConfiguration::Delete);
|
|
|
|
const string HoldMnemonic = IntAsString(ResultConfiguration::Hold);
|
|
|
|
const string RejectMnemonic = IntAsString(ResultConfiguration::Reject);
|
|
|
|
const string SetTrueMnemonic = IntAsString(InputGroup::SetTrue);
|
|
|
|
const string SetFalseMnemonic = IntAsString(InputGroup::SetFalse);
|
|
|
|
const string NotSetMnemonic = IntAsString(InputGroup::NotSet);
|
|
|
|
|
|
|
|
ConfigurationElement Reader("snf4cgp");
|
|
|
|
Reader
|
|
|
|
.Element("ham")
|
|
|
|
.Attribute("code", HamInputDefaults.Code , InputGroup::NotSet)
|
|
|
|
.Attribute("action", HamInputDefaults.Action, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Allow", AllowMnemonic)
|
|
|
|
.Mnemonic("Bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("Delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("Hold", HoldMnemonic)
|
|
|
|
.Mnemonic("Reject", RejectMnemonic)
|
|
|
|
.Mnemonic("allow", AllowMnemonic)
|
|
|
|
.Mnemonic("bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("hold", HoldMnemonic)
|
|
|
|
.Mnemonic("reject", RejectMnemonic)
|
|
|
|
.Attribute("headers", HamInputDefaults.InjectHeaders, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("classic", HamInputDefaults.EmitClassicLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("xml", HamInputDefaults.EmitXMLLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("comment", HamInputDefaults.LogComment, "")
|
|
|
|
.Attribute("reason", HamInputDefaults.RejectionReason, "")
|
|
|
|
.Attribute("hold-path", HamInputDefaults.HoldPath, "")
|
|
|
|
.Element("result")
|
|
|
|
.atEndCall(HamResultHandler)
|
|
|
|
.Attribute("code", CurrentInputs.Code, InputGroup::NotSet)
|
|
|
|
.Attribute("action", CurrentInputs.Action, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Allow", AllowMnemonic)
|
|
|
|
.Mnemonic("Bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("Delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("Hold", HoldMnemonic)
|
|
|
|
.Mnemonic("Reject", RejectMnemonic)
|
|
|
|
.Mnemonic("allow", AllowMnemonic)
|
|
|
|
.Mnemonic("bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("hold", HoldMnemonic)
|
|
|
|
.Mnemonic("reject", RejectMnemonic)
|
|
|
|
.Attribute("headers", CurrentInputs.InjectHeaders, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("classic", CurrentInputs.EmitClassicLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("xml", CurrentInputs.EmitXMLLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("comment", CurrentInputs.LogComment, "")
|
|
|
|
.Attribute("reason", CurrentInputs.RejectionReason, "")
|
|
|
|
.Attribute("hold-path", CurrentInputs.HoldPath, "")
|
|
|
|
.End("result")
|
|
|
|
.End("ham")
|
|
|
|
.Element("spam")
|
|
|
|
.Attribute("code", SpamInputDefaults.Code , InputGroup::NotSet)
|
|
|
|
.Attribute("action", SpamInputDefaults.Action, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Allow", AllowMnemonic)
|
|
|
|
.Mnemonic("Bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("Delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("Hold", HoldMnemonic)
|
|
|
|
.Mnemonic("Reject", RejectMnemonic)
|
|
|
|
.Mnemonic("allow", AllowMnemonic)
|
|
|
|
.Mnemonic("bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("hold", HoldMnemonic)
|
|
|
|
.Mnemonic("reject", RejectMnemonic)
|
|
|
|
.Attribute("headers", SpamInputDefaults.InjectHeaders, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("classic", SpamInputDefaults.EmitClassicLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("xml", SpamInputDefaults.EmitXMLLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("comment", SpamInputDefaults.LogComment, "")
|
|
|
|
.Attribute("reason", SpamInputDefaults.RejectionReason, "")
|
|
|
|
.Attribute("hold-path", SpamInputDefaults.HoldPath, "")
|
|
|
|
.Element("result")
|
|
|
|
.atEndCall(SpamResultHandler)
|
|
|
|
.Attribute("code", CurrentInputs.Code , InputGroup::NotSet)
|
|
|
|
.Attribute("action", CurrentInputs.Action, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Allow", AllowMnemonic)
|
|
|
|
.Mnemonic("Bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("Delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("Hold", HoldMnemonic)
|
|
|
|
.Mnemonic("Reject", RejectMnemonic)
|
|
|
|
.Mnemonic("allow", AllowMnemonic)
|
|
|
|
.Mnemonic("bypass", BypassMnemonic)
|
|
|
|
.Mnemonic("delete", DeleteMnemonic)
|
|
|
|
.Mnemonic("hold", HoldMnemonic)
|
|
|
|
.Mnemonic("reject", RejectMnemonic)
|
|
|
|
.Attribute("headers", CurrentInputs.InjectHeaders, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("classic", CurrentInputs.EmitClassicLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("xml", CurrentInputs.EmitXMLLog, InputGroup::NotSet)
|
|
|
|
.Mnemonic("Yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("No", SetFalseMnemonic)
|
|
|
|
.Mnemonic("yes", SetTrueMnemonic)
|
|
|
|
.Mnemonic("no", SetFalseMnemonic)
|
|
|
|
.Attribute("comment", CurrentInputs.LogComment, "")
|
|
|
|
.Attribute("reason", CurrentInputs.RejectionReason, "")
|
|
|
|
.Attribute("hold-path", CurrentInputs.HoldPath, "")
|
|
|
|
.End("result")
|
|
|
|
.End("spam")
|
|
|
|
.End("snf4cgp");
|
|
|
|
|
|
|
|
string CFG = Rulebase.PlatformConfiguration();
|
|
|
|
ConfigurationData Data(CFG.c_str(), CFG.length());
|
|
|
|
|
|
|
|
Reader.initialize();
|
|
|
|
Reader.interpret(Data);
|
|
|
|
|
|
|
|
//// Establish appropriate defaults for any codes that weren't explicitly configured.
|
|
|
|
|
|
|
|
for(size_t i = 0; i < Configurations.size(); i++) {
|
|
|
|
ResultConfiguration& M = Configurations[i];
|
|
|
|
if(hasNotBeenConfigured(M.ResultCode)) {
|
|
|
|
if(isHamResultCode(M.ResultCode)) {
|
|
|
|
M = HamInputDefaults;
|
|
|
|
} else {
|
|
|
|
M = SpamInputDefaults;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Generation_ = Rulebase.Generation();
|
|
|
|
}
|
|
|
|
|
|
|
|
const int OutOfRangeDefaultCode = 0;
|