Bladeren bron

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 jaren geleden
bovenliggende
commit
727b31b9b0
2 gewijzigde bestanden met toevoegingen van 69 en 16 verwijderingen
  1. 64
    13
      SNF4CGP/JobPool.cpp
  2. 5
    3
      SNF4CGP/JobPool.hpp

+ 64
- 13
SNF4CGP/JobPool.cpp Bestand weergeven

@@ -25,9 +25,6 @@ const int StringReserveSize = 2048;
//// Job ///////////////////////////////////////////////////////////////////////
void Job::emitCommentPrefix() {
}
void Job::emitComment(const string& Comment) {
ostringstream O;
O << "* " << Comment << endl;
@@ -93,6 +90,7 @@ void Job::emitDISCARD() {
void Job::emitREJECTED(const string& Report) {
ostringstream O;
O << CurrentCommand.Number << " REJECTED " << formatAsCGPString(Report) << endl;
OutputBuffer.append(O.str());
}
void Job::finalize() { // Cleanup and report this job.
@@ -110,7 +108,7 @@ void Job::doINTF() {
emitINTF();
}
void Job::doFAIL() {
void Job::doUNKNOWN() {
ostringstream O;
O << "* SNF4CGP[" << CurrentCommand.Number << "] Does not understand: "
<< formatAsCGPString(CurrentCommand.Data) << endl;
@@ -119,7 +117,7 @@ void Job::doFAIL() {
}
void Job::doFILE() {
doRead();
doInitialRead();
doScan();
doAction();
closeReader();
@@ -173,7 +171,7 @@ void Job::closeWriter() {
}
}
void Job::doRead() {
void Job::doInitialRead() {
openReader(Job::CurrentCommand.Data);
ReadBuffer.assign(ReadBufferSize, 0);
Reader().read(reinterpret_cast<char*>(&ReadBuffer[0]), ReadBuffer.size());
@@ -187,6 +185,18 @@ string Job::ScanName() {
void Job::setConfigurationFromScanResult(ScopeScanner& myScanner) {
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.EmitXMLLog) XMLLogData = myScanner.Engine().getXMLLog();
if(ScanResultConfiguration.EmitClassicLog) ClassicLogData = myScanner.Engine().getClassicLog();
@@ -201,21 +211,61 @@ void Job::doScan() {
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() {
// 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() {
emitOK();
}
void Job::doAllow() {
if(0 < HeadersToInject.length()) emitADDHEADER(HeadersToInject);
else emitOK();
}
void Job::doReject() {
emitREJECTED(ScanResultConfiguration.RejectionReason);
}
void Job::doDelete() {
emitDISCARD();
}
void Job::emitMessageMovedTo(string& Destination) {
@@ -280,9 +330,9 @@ void Job::injectHeadersInMessageMove() {
}
void Job::copyRestOfLongMessage() {
//// while(MoreToDo) {
//// readBufferFull()
//// writeBufferFull()
//// while(Reader.good() && !Reader.eof()) {
//// readBlockOfData()
//// writeBlockOfData()
//// }
}
@@ -297,7 +347,7 @@ const string PathSeparators = "\\/";
string FileNamePart(string Path) { // How to get the file name part of a path:
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.
}
@@ -312,6 +362,7 @@ void Job::doHold() {
string Destination = calculateDestinationFileName();
moveMessageToHoldPath(Destination);
emitMessageMovedTo(Destination);
emitDISCARD();
}
const int NoScanYet = -1;
@@ -360,7 +411,7 @@ void Job::executeCommand() {
case Command::WAKE: { doWakeUp(); break; }
case Command::INTF: { doINTF(); break; }
case Command::FILE: { doFILE(); break; }
default: { doFAIL(); break; }
default: { doUNKNOWN(); break; }
}
}

+ 5
- 3
SNF4CGP/JobPool.hpp Bestand weergeven

@@ -82,7 +82,6 @@ class Job {
//// Utility methods
void emitCommentPrefix();
void emitComment(const string& Comment);
void emitOK();
@@ -101,13 +100,16 @@ class Job {
void emitException(const string& What);
void emitUnknownException();
void emitXMLLogData();
void emitClassicLogData();
//// These methods embody how we get jobs done.
void doWakeUp();
void doINTF();
void doFAIL();
void doUNKNOWN();
void doFILE();
void doRead();
void doInitialRead();
void doScan();
void doAction();
void doBypass();

Laden…
Annuleren
Opslaan