Browse Source

codedweller namespace to CFGmgr

master
Pete McNeil 4 years ago
parent
commit
01ddf0c328
2 changed files with 60 additions and 60 deletions
  1. 34
    34
      snfCFGmgr.cpp
  2. 26
    26
      snfCFGmgr.hpp

+ 34
- 34
snfCFGmgr.cpp View File

} }


void snfCFGData::initializeFromFile(const char* FileName) { // Initialize from the provided file. void snfCFGData::initializeFromFile(const char* FileName) { // Initialize from the provided file.
ConfigurationData MyCFGData(FileName); // Create a cfg data object from the file.
cd::ConfigurationData MyCFGData(FileName); // Create a cfg data object from the file.
if(0 == MyCFGData.Data(0)) throw false; // If we didn't read a config file throw! if(0 == MyCFGData.Data(0)) throw false; // If we didn't read a config file throw!
MyCFGReader.initialize(); // Initialize to defaults. MyCFGReader.initialize(); // Initialize to defaults.
MyCFGReader.interpret(MyCFGData); // Interpret the data. MyCFGReader.interpret(MyCFGData); // Interpret the data.
InitLicenseId = (NULL==LicenseId)?"":LicenseId; // any time load() is called. InitLicenseId = (NULL==LicenseId)?"":LicenseId; // any time load() is called.
InitAuthentication = (NULL==Authentication)?"":Authentication; InitAuthentication = (NULL==Authentication)?"":Authentication;
} }
//*****************************************************************************
//// IMPORTANT: If the authentication string is provided in the initialize() it
//// MUST NOT be put into D.node_authentication.
//*****************************************************************************
//// When the license ID and security string come from an OEM application they
//// may not appear in the configuration files. If that is the case we will assume
//// that they developer wants to keep the security string secret by encrypting it
//// in their application and providing it to SNF at runtime. In that case we will
//// not display the security key in the configuration log.
////
//// To prevent hacking attempts, if the authentication information appears to be
//// provided by configuration data then we will build the string from that data.
//// that way an attacker can't trick the application into disclosing the true
//// authentication string -- they will only get out what they put in.
string SecurityKeyDisplayString(snfCFGData& D) { // Returns appropriate SecurityKey: data
string ConfigLogSecurityKey = "************************"; // Start with a masked display.
if(0 < D.node_authentication.length()) { // If auth info is in the config files then
ConfigLogSecurityKey = D.node_licenseid + D.node_authentication; // build up the key from that data so it
} // can be displayed in the config log.
return ConfigLogSecurityKey;
}
//*****************************************************************************
//// IMPORTANT: If the authentication string is provided in the initialize() it
//// MUST NOT be put into D.node_authentication.
//*****************************************************************************
//// When the license ID and security string come from an OEM application they
//// may not appear in the configuration files. If that is the case we will assume
//// that they developer wants to keep the security string secret by encrypting it
//// in their application and providing it to SNF at runtime. In that case we will
//// not display the security key in the configuration log.
////
//// To prevent hacking attempts, if the authentication information appears to be
//// provided by configuration data then we will build the string from that data.
//// that way an attacker can't trick the application into disclosing the true
//// authentication string -- they will only get out what they put in.
string SecurityKeyDisplayString(snfCFGData& D) { // Returns appropriate SecurityKey: data
string ConfigLogSecurityKey = "************************"; // Start with a masked display.
if(0 < D.node_authentication.length()) { // If auth info is in the config files then
ConfigLogSecurityKey = D.node_licenseid + D.node_authentication; // build up the key from that data so it
} // can be displayed in the config log.
return ConfigLogSecurityKey;
}


void logCFGData(snfCFGData& D) { // Log interpreted cfg data (debug aid). void logCFGData(snfCFGData& D) { // Log interpreted cfg data (debug aid).


try { try {
string CFGLogPath; // Build the snf_cfg log path. string CFGLogPath; // Build the snf_cfg log path.
CFGLogPath = D.paths_log_path + CFGLogPath = D.paths_log_path +
D.node_licenseid + "_snf_engine_cfg.log";
D.node_licenseid + "_snf_engine_cfg.log";


ofstream cfgl(CFGLogPath.c_str(), ios::trunc); // Open and truncate the cfg log file. ofstream cfgl(CFGLogPath.c_str(), ios::trunc); // Open and truncate the cfg log file.
cfgl // Report important cfg information. cfgl // Report important cfg information.
//// If an identity path has been provided we must load that data. //// If an identity path has been provided we must load that data.


if(0 < CFGData.node_identity.length()) { // If an identity path was provided if(0 < CFGData.node_identity.length()) { // If an identity path was provided
ConfigurationData Identity(CFGData.node_identity.c_str()); // then get the data from that file.
ConfigurationElement IdentityReader("snf"); // Create an Identity reader and
cd::ConfigurationData Identity(CFGData.node_identity.c_str()); // then get the data from that file.
cd::ConfigurationElement IdentityReader("snf"); // Create an Identity reader and
IdentityReader // configure it. IdentityReader // configure it.
.Element("identity") .Element("identity")
.Attribute("licenseid", CFGData.node_licenseid) .Attribute("licenseid", CFGData.node_licenseid)
} }


//// The SecurityKey is built from the licenseID and the Authentication //// The SecurityKey is built from the licenseID and the Authentication
if(InitLicenseIdIsProvided) { // If the LicenseID is OEM provided then if(InitLicenseIdIsProvided) { // If the LicenseID is OEM provided then
CFGData.SecurityKey = InitLicenseId; // the first part of our security key is that.
CFGData.SecurityKey = InitLicenseId; // the first part of our security key is that.
CFGData.node_licenseid = InitLicenseId; // Also override any file-loaded license ID. CFGData.node_licenseid = InitLicenseId; // Also override any file-loaded license ID.
} else { // If it was not provided then we will get } else { // If it was not provided then we will get
CFGData.SecurityKey = CFGData.node_licenseid; // the LicenseID from our config file. CFGData.SecurityKey = CFGData.node_licenseid; // the LicenseID from our config file.
} }
string LicenseIDToUse = CFGData.SecurityKey; // Grab the License ID we want to use.
string LicenseIDToUse = CFGData.SecurityKey; // Grab the License ID we want to use.


if(InitAuthenticationIsProvided) { // If the Authentication has been provided then if(InitAuthenticationIsProvided) { // If the Authentication has been provided then
CFGData.SecurityKey += InitAuthentication; // we use it for the second part of our CFGData.SecurityKey += InitAuthentication; // we use it for the second part of our


if(InitPathIsRulebase) { // If the Rulebase path was provided if(InitPathIsRulebase) { // If the Rulebase path was provided
CFGData.RuleFilePath = InitFileName; // then we have our rulebase path. CFGData.RuleFilePath = InitFileName; // then we have our rulebase path.
} else { // If not then we must figure it out...
} else { // If not then we must figure it out...
CFGData.RuleFilePath = // We build the path from the base CFGData.RuleFilePath = // We build the path from the base
CFGData.paths_rulebase_path + // rulebase path concattonated with CFGData.paths_rulebase_path + // rulebase path concattonated with
LicenseIDToUse + // the license id concattonated with LicenseIDToUse + // the license id concattonated with
SNFExt; // the rulebase extension.
SNFExt; // the rulebase extension.
} }


// Once all of the configuration data is correct we make it active. // Once all of the configuration data is correct we make it active.

+ 26
- 26
snfCFGmgr.hpp View File

#include <string> #include <string>
#include <set> #include <set>


using namespace std;
namespace cd = codedweller;


const unsigned long int HeaderDirectiveBypass = 0x00000001; // Bypass hd rule flag. const unsigned long int HeaderDirectiveBypass = 0x00000001; // Bypass hd rule flag.
const unsigned long int HeaderDirectiveWhite = 0x00000002; // White hd rule flag. const unsigned long int HeaderDirectiveWhite = 0x00000002; // White hd rule flag.
const unsigned long int HeaderDirectiveSource = 0x00000008; // Source rule flag. const unsigned long int HeaderDirectiveSource = 0x00000008; // Source rule flag.
const unsigned long int HeaderDirectiveContext = 0x80000000; // Context activation flag. const unsigned long int HeaderDirectiveContext = 0x80000000; // Context activation flag.


class HeaderDirectiveHandler : public Configurator { // Handle inputs to header directives.
class HeaderDirectiveHandler : public cd::Configurator { // Handle inputs to header directives.
public: public:


HeaderDirectiveSet HeaderDirectives; // Managed set of Header Directives. HeaderDirectiveSet HeaderDirectives; // Managed set of Header Directives.


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The configurator call adds the Input.
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The configurator call adds the Input.


if(HeaderDirectiveContext == ContextInput.Directive) { // If a context has been established if(HeaderDirectiveContext == ContextInput.Directive) { // If a context has been established
ContextInput.Context = HeaderDirectives.size() + 1; // then setup the context ID and ContextInput.Context = HeaderDirectives.size() + 1; // then setup the context ID and


}; };


class HeaderDirectiveInitializer : public Configurator { // Initializes Header Directives.
class HeaderDirectiveInitializer : public cd::Configurator { // Initializes Header Directives.
private: private:


HeaderDirectiveHandler* MyTarget; // Needs to know it's target. HeaderDirectiveHandler* MyTarget; // Needs to know it's target.


void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-) void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-)


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The configurator() function goes to the
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The configurator() function goes to the
if(NULL!=MyTarget) { // target (if it's set) and pushes the if(NULL!=MyTarget) { // target (if it's set) and pushes the
MyTarget->reset(); // reset button (empties the set). MyTarget->reset(); // reset button (empties the set).
} }
} }
}; };


class HeaderDirectiveWhiteHeaderInitializer : public Configurator { // Initializes White Header Directives.
class HeaderDirectiveWhiteHeaderInitializer : public cd::Configurator { // Initializes White Header Directives.
private: private:


HeaderDirectiveHandler* MyTarget; // Needs to know it's target. HeaderDirectiveHandler* MyTarget; // Needs to know it's target.


void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-) void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-)


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The configurator() function goes to the
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The configurator() function goes to the
if(NULL!=MyTarget) { // target (if it's set) and sets it up if(NULL!=MyTarget) { // target (if it's set) and sets it up
MyTarget->ContextInput.clear(); // for a white header directive. MyTarget->ContextInput.clear(); // for a white header directive.
MyTarget->DirectiveInput.clear(); MyTarget->DirectiveInput.clear();
} }
}; };


class HeaderDirectiveBypassHeaderInitializer : public Configurator { // Initializes Bypass Header Directives.
class HeaderDirectiveBypassHeaderInitializer : public cd::Configurator { // Initializes Bypass Header Directives.
private: private:


HeaderDirectiveHandler* MyTarget; // Needs to know it's target. HeaderDirectiveHandler* MyTarget; // Needs to know it's target.


void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-) void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-)


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The configurator() function goes to the
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The configurator() function goes to the
if(NULL!=MyTarget) { // target (if it's set) and sets it up if(NULL!=MyTarget) { // target (if it's set) and sets it up
MyTarget->ContextInput.clear(); // for a bypass header directive. MyTarget->ContextInput.clear(); // for a bypass header directive.
MyTarget->DirectiveInput.clear(); MyTarget->DirectiveInput.clear();
} }
}; };


class HeaderDirectiveDrilldownInitializer : public Configurator { // Initializes Drilldown Header Directives.
class HeaderDirectiveDrilldownInitializer : public cd::Configurator { // Initializes Drilldown Header Directives.
private: private:


HeaderDirectiveHandler* MyTarget; // Needs to know it's target. HeaderDirectiveHandler* MyTarget; // Needs to know it's target.


void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-) void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-)


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The configurator() function goes to the
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The configurator() function goes to the
if(NULL!=MyTarget) { // target (if it's set) and sets it up for if(NULL!=MyTarget) { // target (if it's set) and sets it up for
MyTarget->ContextInput.clear(); // a drilldown header directive. MyTarget->ContextInput.clear(); // a drilldown header directive.
MyTarget->DirectiveInput.clear(); MyTarget->DirectiveInput.clear();
} }
}; };


class HeaderDirectiveSourceHeaderInitializer : public Configurator { // Initializes Source Header Directives.
class HeaderDirectiveSourceHeaderInitializer : public cd::Configurator { // Initializes Source Header Directives.
private: private:


HeaderDirectiveHandler* MyTarget; // Needs to know it's target. HeaderDirectiveHandler* MyTarget; // Needs to know it's target.


void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-) void setTarget(HeaderDirectiveHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-)


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The configurator() function goes to the
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The configurator() function goes to the
if(NULL!=MyTarget) { // target (if it's set) and sets it up if(NULL!=MyTarget) { // target (if it's set) and sets it up
MyTarget->ContextInput.clear(); // for a context sensitive source header MyTarget->ContextInput.clear(); // for a context sensitive source header
MyTarget->DirectiveInput.clear(); // directive. Activation context as well MyTarget->DirectiveInput.clear(); // directive. Activation context as well
} }
}; };


class RangeHandler : public Configurator { // The handler adds edgepoints and holds and
class RangeHandler : public cd::Configurator { // The handler adds edgepoints and holds and
public: // tests the set that defines the region. public: // tests the set that defines the region.


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The () operator adds EdgeInput to the list.
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The () operator adds EdgeInput to the list.
EdgeMap.insert(EdgeInput); EdgeMap.insert(EdgeInput);
} }




}; };


class RangeInitializer : public Configurator { // The RangeInitializer Configurator.
class RangeInitializer : public cd::Configurator { // The RangeInitializer Configurator.
private: private:


RangeHandler* MyTarget; // Needs to know it's target. RangeHandler* MyTarget; // Needs to know it's target.


void setTarget(RangeHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-) void setTarget(RangeHandler& H) { MyTarget = &H; } // We have a way to set the target though ;-)


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The configurator() function goes to the
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The configurator() function goes to the
if(NULL!=MyTarget) { // target (if it's set) and pushes the if(NULL!=MyTarget) { // target (if it's set) and pushes the
MyTarget->reset(); // reset button. MyTarget->reset(); // reset button.
} }
} }
}; };


class IntegerSetHandler : public Configurator { // Integer set handler for rule panics.
class IntegerSetHandler : public cd::Configurator { // Integer set handler for rule panics.
public: public:
void operator()(ConfigurationElement& E, ConfigurationData& D) { // The operator() inserts IntegerInput
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The operator() inserts IntegerInput
IntegerSet.insert(IntegerInput); // if it's not already a member. IntegerSet.insert(IntegerInput); // if it's not already a member.
} }


void reset() { IntegerSet.clear(); } // How to reset (clear) the list. void reset() { IntegerSet.clear(); } // How to reset (clear) the list.
}; };


class IntegerSetInitializer : public Configurator { // The initializer resets the set.
class IntegerSetInitializer : public cd::Configurator { // The initializer resets the set.
private: private:


IntegerSetHandler* MyTarget; // It needs to know which set to init. IntegerSetHandler* MyTarget; // It needs to know which set to init.


void setTarget(IntegerSetHandler& H) { MyTarget = &H; } // Set a pointer to the handler. void setTarget(IntegerSetHandler& H) { MyTarget = &H; } // Set a pointer to the handler.


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The operator() does the trick.
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The operator() does the trick.
if(NULL!=MyTarget) { if(NULL!=MyTarget) {
MyTarget->reset(); MyTarget->reset();
} }
} // in this case. } // in this case.
}; };


class XHDRSymbolsHandler : public Configurator { // XHDRSymbol hander.
class XHDRSymbolsHandler : public cd::Configurator { // XHDRSymbol hander.
public: public:
set<XHDRSymbol> SymbolHeaders; // Carries a set of Symbol Headers. set<XHDRSymbol> SymbolHeaders; // Carries a set of Symbol Headers.


int Symbol; // Input Symbol value. int Symbol; // Input Symbol value.
string Header; // Input Header value. string Header; // Input Header value.


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The operator() inserts an XHDRSymbol
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The operator() inserts an XHDRSymbol
if(OnOff) { // if the header entry is turned on and if(OnOff) { // if the header entry is turned on and
SymbolHeaders.insert(XHDRSymbol(Symbol, Header)); // if it's not already a member. SymbolHeaders.insert(XHDRSymbol(Symbol, Header)); // if it's not already a member.
} }
} }
}; };


class XHDRSymbolsInitializer : public Configurator { // The XHDRSymbols initializer.
class XHDRSymbolsInitializer : public cd::Configurator { // The XHDRSymbols initializer.
private: private:


XHDRSymbolsHandler* MyTarget; // It needs to know which set to init. XHDRSymbolsHandler* MyTarget; // It needs to know which set to init.


void setTarget(XHDRSymbolsHandler& H) { MyTarget = &H; } // Set a pointer to the handler. void setTarget(XHDRSymbolsHandler& H) { MyTarget = &H; } // Set a pointer to the handler.


void operator()(ConfigurationElement& E, ConfigurationData& D) { // The operator() does the trick.
void operator()(cd::ConfigurationElement& E, cd::ConfigurationData& D) { // The operator() does the trick.
if(NULL!=MyTarget) { if(NULL!=MyTarget) {
MyTarget->reset(); MyTarget->reset();
} }
class snfCFGData { // Object that stores our config data. class snfCFGData { // Object that stores our config data.
private: private:


ConfigurationElement MyCFGReader; // This is how we read our cfg data.
cd::ConfigurationElement MyCFGReader; // This is how we read our cfg data.


public: public:



Loading…
Cancel
Save