Browse Source

Added temporary code for testing Actions during FILE command

Completed Bypass Action
Completed Allow Action
Completed Reject Action
Completed Delete Action


git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@28 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfc
master
madscientist 15 years ago
parent
commit
727b31b9b0
2 changed files with 69 additions and 16 deletions
  1. 64
    13
      SNF4CGP/JobPool.cpp
  2. 5
    3
      SNF4CGP/JobPool.hpp

+ 64
- 13
SNF4CGP/JobPool.cpp View File

//// Job /////////////////////////////////////////////////////////////////////// //// Job ///////////////////////////////////////////////////////////////////////
void Job::emitCommentPrefix() {
}
void Job::emitComment(const string& Comment) { void Job::emitComment(const string& Comment) {
ostringstream O; ostringstream O;
O << "* " << Comment << endl; O << "* " << Comment << endl;
void Job::emitREJECTED(const string& Report) { void Job::emitREJECTED(const string& Report) {
ostringstream O; ostringstream O;
O << CurrentCommand.Number << " REJECTED " << formatAsCGPString(Report) << endl; O << CurrentCommand.Number << " REJECTED " << formatAsCGPString(Report) << endl;
OutputBuffer.append(O.str());
} }
void Job::finalize() { // Cleanup and report this job. void Job::finalize() { // Cleanup and report this job.
emitINTF(); emitINTF();
} }
void Job::doFAIL() {
void Job::doUNKNOWN() {
ostringstream O; ostringstream O;
O << "* SNF4CGP[" << CurrentCommand.Number << "] Does not understand: " O << "* SNF4CGP[" << CurrentCommand.Number << "] Does not understand: "
<< formatAsCGPString(CurrentCommand.Data) << endl; << formatAsCGPString(CurrentCommand.Data) << endl;
} }
void Job::doFILE() { void Job::doFILE() {
doRead();
doInitialRead();
doScan(); doScan();
doAction(); doAction();
closeReader(); closeReader();
} }
} }
void Job::doRead() {
void Job::doInitialRead() {
openReader(Job::CurrentCommand.Data); openReader(Job::CurrentCommand.Data);
ReadBuffer.assign(ReadBufferSize, 0); ReadBuffer.assign(ReadBufferSize, 0);
Reader().read(reinterpret_cast<char*>(&ReadBuffer[0]), ReadBuffer.size()); Reader().read(reinterpret_cast<char*>(&ReadBuffer[0]), ReadBuffer.size());
void Job::setConfigurationFromScanResult(ScopeScanner& myScanner) { void Job::setConfigurationFromScanResult(ScopeScanner& myScanner) {
ScanResultConfiguration = Scanners.ConfigurationForResultCode(ScanResultCode); ScanResultConfiguration = Scanners.ConfigurationForResultCode(ScanResultCode);
//// Testing -- forcing scan results
ScanResultConfiguration.Action = ResultConfiguration::Hold;
ScanResultConfiguration.HoldPath = "C:\\M\\Projects\\MessageSniffer\\SNF4CGP_Work\\TestEnvironment\\hold\\";
ScanResultConfiguration.RejectionReason = "I don't like the look of it -- so there!";
ScanResultConfiguration.EmitXMLLog = true;
ScanResultConfiguration.EmitClassicLog = true;
ScanResultConfiguration.InjectHeaders = true;
///////////////////////////////////////////////////////////////////////
if(ScanResultConfiguration.InjectHeaders) HeadersToInject = myScanner.Engine().getXHDRs(); if(ScanResultConfiguration.InjectHeaders) HeadersToInject = myScanner.Engine().getXHDRs();
if(ScanResultConfiguration.EmitXMLLog) XMLLogData = myScanner.Engine().getXMLLog(); if(ScanResultConfiguration.EmitXMLLog) XMLLogData = myScanner.Engine().getXMLLog();
if(ScanResultConfiguration.EmitClassicLog) ClassicLogData = myScanner.Engine().getClassicLog(); if(ScanResultConfiguration.EmitClassicLog) ClassicLogData = myScanner.Engine().getClassicLog();
setConfigurationFromScanResult(myScanner); setConfigurationFromScanResult(myScanner);
} }
void convertLogLinesToComments(ostringstream& O, string& Lines) {
istringstream I(Lines);
while(I) {
string LogLine;
getline(I, LogLine);
if(0 < LogLine.length()) {
O << "* " << LogLine << endl;
}
}
}
void Job::emitXMLLogData() {
ostringstream O;
O << "* SNF4CGP[" << CurrentCommand.Number << "] XML Scan log data: " << endl;
convertLogLinesToComments(O, XMLLogData);
OutputBuffer.append(O.str());
}
void Job::emitClassicLogData() {
ostringstream O;
O << "* SNF4CGP[" << CurrentCommand.Number << "] Classic Scan log data: " << endl;
convertLogLinesToComments(O, ClassicLogData);
OutputBuffer.append(O.str());
}
LogicFault FaultUhandledScanResultAction("Job::doAction() switch(ScanResultConfiguration.Action) fell to default!");
void Job::doAction() { void Job::doAction() {
// Select action based on current configuration
// Do the appropriate action
if(ScanResultConfiguration.EmitXMLLog) emitXMLLogData();
if(ScanResultConfiguration.EmitClassicLog) emitClassicLogData();
switch(ScanResultConfiguration.Action) {
case ResultConfiguration::Allow : { doAllow(); break; }
case ResultConfiguration::Bypass : { doBypass(); break; }
case ResultConfiguration::Delete : { doDelete(); break; }
case ResultConfiguration::Hold : { doHold(); break; }
case ResultConfiguration::Reject : { doReject(); break; }
default: { throw FaultUhandledScanResultAction; }
}
} }
void Job::doBypass() { void Job::doBypass() {
emitOK();
} }
void Job::doAllow() { void Job::doAllow() {
if(0 < HeadersToInject.length()) emitADDHEADER(HeadersToInject);
else emitOK();
} }
void Job::doReject() { void Job::doReject() {
emitREJECTED(ScanResultConfiguration.RejectionReason);
} }
void Job::doDelete() { void Job::doDelete() {
emitDISCARD();
} }
void Job::emitMessageMovedTo(string& Destination) { void Job::emitMessageMovedTo(string& Destination) {
} }
void Job::copyRestOfLongMessage() { void Job::copyRestOfLongMessage() {
//// while(MoreToDo) {
//// readBufferFull()
//// writeBufferFull()
//// while(Reader.good() && !Reader.eof()) {
//// readBlockOfData()
//// writeBlockOfData()
//// } //// }
} }
string FileNamePart(string Path) { // How to get the file name part of a path: string FileNamePart(string Path) { // How to get the file name part of a path:
string::size_type Found = Path.find_last_of(PathSeparators); string::size_type Found = Path.find_last_of(PathSeparators);
if(string::npos != Found) Path = Path.substr(Found+1); // Return all after the last separator
if(string::npos != Found) Path = Path.substr(Found + 1); // Return all after the last separator
return Path; // or Path if no separators are found. return Path; // or Path if no separators are found.
} }
string Destination = calculateDestinationFileName(); string Destination = calculateDestinationFileName();
moveMessageToHoldPath(Destination); moveMessageToHoldPath(Destination);
emitMessageMovedTo(Destination); emitMessageMovedTo(Destination);
emitDISCARD();
} }
const int NoScanYet = -1; const int NoScanYet = -1;
case Command::WAKE: { doWakeUp(); break; } case Command::WAKE: { doWakeUp(); break; }
case Command::INTF: { doINTF(); break; } case Command::INTF: { doINTF(); break; }
case Command::FILE: { doFILE(); break; } case Command::FILE: { doFILE(); break; }
default: { doFAIL(); break; }
default: { doUNKNOWN(); break; }
} }
} }

+ 5
- 3
SNF4CGP/JobPool.hpp View File

//// Utility methods //// Utility methods
void emitCommentPrefix();
void emitComment(const string& Comment); void emitComment(const string& Comment);
void emitOK(); void emitOK();
void emitException(const string& What); void emitException(const string& What);
void emitUnknownException(); void emitUnknownException();
void emitXMLLogData();
void emitClassicLogData();
//// These methods embody how we get jobs done. //// These methods embody how we get jobs done.
void doWakeUp(); void doWakeUp();
void doINTF(); void doINTF();
void doFAIL();
void doUNKNOWN();
void doFILE(); void doFILE();
void doRead();
void doInitialRead();
void doScan(); void doScan();
void doAction(); void doAction();
void doBypass(); void doBypass();

Loading…
Cancel
Save