Ver código fonte

Completed doMove() logic with and without header injection


git-svn-id: https://svn.microneil.com/svn/SNF4CGP/trunk@29 59e8e3e7-56fa-483b-b4b4-fa6ab0af3dfc
master
madscientist 15 anos atrás
pai
commit
f7fc41fee1
2 arquivos alterados com 106 adições e 30 exclusões
  1. 96
    27
      SNF4CGP/JobPool.cpp
  2. 10
    3
      SNF4CGP/JobPool.hpp

+ 96
- 27
SNF4CGP/JobPool.cpp Ver arquivo

@@ -183,7 +183,12 @@ string Job::ScanName() {
return ScanNameFormatter.str();
}
const int NoScanYet = -1;
LogicFault FaultIfSettingScanResultConfigBeforeScan("Job::setConfigurationFromScanResult() Fault(NoScanYet == ScanResultCode)");
void Job::setConfigurationFromScanResult(ScopeScanner& myScanner) {
FaultIfSettingScanResultConfigBeforeScan(NoScanYet == ScanResultCode);
ScanResultConfiguration = Scanners.ConfigurationForResultCode(ScanResultCode);
//// Testing -- forcing scan results
@@ -191,8 +196,9 @@ void Job::setConfigurationFromScanResult(ScopeScanner& myScanner) {
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.LogComment = "This is my happy little log comment.";
ScanResultConfiguration.EmitXMLLog = true;
ScanResultConfiguration.EmitClassicLog = true;
ScanResultConfiguration.EmitClassicLog = false;
ScanResultConfiguration.InjectHeaders = true;
///////////////////////////////////////////////////////////////////////
@@ -222,6 +228,12 @@ void convertLogLinesToComments(ostringstream& O, string& Lines) {
}
}
void Job::emitLogComment() {
ostringstream O;
O << "* SNF4CGP[" << CurrentCommand.Number << "] Comment: " << ScanResultConfiguration.LogComment << endl;
OutputBuffer.append(O.str());
}
void Job::emitXMLLogData() {
ostringstream O;
O << "* SNF4CGP[" << CurrentCommand.Number << "] XML Scan log data: " << endl;
@@ -239,6 +251,7 @@ void Job::emitClassicLogData() {
LogicFault FaultUhandledScanResultAction("Job::doAction() switch(ScanResultConfiguration.Action) fell to default!");
void Job::doAction() {
if(0 < ScanResultConfiguration.LogComment.length()) emitLogComment();
if(ScanResultConfiguration.EmitXMLLog) emitXMLLogData();
if(ScanResultConfiguration.EmitClassicLog) emitClassicLogData();
switch(ScanResultConfiguration.Action) {
@@ -287,6 +300,26 @@ void Job::identifyLocalLineEnd() {
}
RuntimeCheck CheckLineEndsIdentified("Job::findHeaderInsertPoint() Check(0 < LocalLineEnd.length())");
RuntimeCheck CheckInsertCursorPlausable("Job::findHeaderInsertPoint() Check(isMinimumSafeDistanceFromEOF(InsertCursor))");
bool Job::isMinimumSafeDistanceFromEOF(const size_t Position) {
string MinimalEmptyMessageBody = LocalLineEnd + "." + LocalLineEnd;
size_t MinimalDistanceToEOF = MinimalEmptyMessageBody.length();
size_t SafetyCalculation = Position + MinimalDistanceToEOF;
size_t AvailableMessageLength = Reader().gcount();
return (SafetyCalculation <= AvailableMessageLength);
}
void Job::moveInsertCursorForwardToBlockTerminus(size_t& InsertCursor, string& BlockTerminus) {
size_t SafetyLimit = (Reader().gcount() - BlockTerminus.length());
for(;InsertCursor < SafetyLimit; InsertCursor++) { // Scan forward safely until we find it.
if( // At each position compare the BlockTerminus
0 == BlockTerminus.compare( // with an equal length string in the buffer.
0, BlockTerminus.length(),
reinterpret_cast<char*>(&ReadBuffer[InsertCursor]), BlockTerminus.length())
) return;
}
}
size_t Job::findHeaderInsertPoint() { // How to find the insert point:
identifyLocalLineEnd();
@@ -294,51 +327,89 @@ size_t Job::findHeaderInsertPoint() {
string BlockTerminus = LocalLineEnd + LocalLineEnd;
size_t InsertCursor = 0;
//// Search for the end of the CGP control block.
moveInsertCursorForwardToBlockTerminus(InsertCursor, BlockTerminus); // Find the end of the CGP control block.
InsertCursor += BlockTerminus.length(); // Move past this block terminus.
moveInsertCursorForwardToBlockTerminus(InsertCursor, BlockTerminus); // Find the end of the message headers.
for(;InsertCursor < (Reader().gcount() - BlockTerminus.length()); InsertCursor++) {
if(0 == BlockTerminus.compare(reinterpret_cast<char*>(&ReadBuffer[InsertCursor]))) break;
}
InsertCursor += LocalLineEnd.length(); // Split the headers BlockTerminus.
//// Search for the end of the message headers.
CheckInsertCursorPlausable(isMinimumSafeDistanceFromEOF(InsertCursor));
InsertCursor += BlockTerminus.length();
for(;InsertCursor < (Reader().gcount() - BlockTerminus.length()); InsertCursor++) {
if(0 == BlockTerminus.compare(reinterpret_cast<char*>(&ReadBuffer[InsertCursor]))) break;
}
return InsertCursor;
}
RuntimeCheck CheckFirstSegmentWriterOk("Job::writeUpToInjectionPoint() Check(Writer().good())");
void Job::writeUpToInjectionPoint(size_t InjectionPoint) {
Writer().write(reinterpret_cast<char*>(&ReadBuffer[0]), InjectionPoint);
CheckFirstSegmentWriterOk(Writer().good());
}
//// The correct insert point is between the two LocalLineEnd in the BlockTerminus
RuntimeCheck CheckHeaderWriterOk("Job::writeHeaders() Check(Writer().good())");
void Job::writeHeaders() { // Write (inject) headers while converting
for(size_t i = 0; i < HeadersToInject.length(); i++) { // line ends to the format observed in the
switch(HeadersToInject.at(i)) { // message file.
case '\r' : { break; } // Convert by ignoring <CR> and
case '\n' : { Writer() << LocalLineEnd; break; } // triggering the LocalLineEnd on <LF>
default : { Writer().put(HeadersToInject.at(i)); break; } // All other bytes as seen in the message.
}
}
CheckHeaderWriterOk(Writer().good());
}
InsertCursor += LocalLineEnd.length();
RuntimeCheck CheckEndFirstBufferWriterOk("Job::writeRestOfFirstBuffer() Check(Writer().good())");
return InsertCursor;
void Job::writeRestOfFirstBuffer(size_t InjectionPoint) {
int LengthOfRestOfBuffer = Reader().gcount() - (InjectionPoint + 1);
Writer().write(reinterpret_cast<char*>(&ReadBuffer[InjectionPoint]), LengthOfRestOfBuffer);
CheckEndFirstBufferWriterOk(Writer().good());
}
void Job::writeUpToInjectionPoint(size_t InjectionPoint) {
void Job::copyFirstBufferAndInjectHeadersInMessageMove() {
size_t HeaderInjectionPoint = findHeaderInsertPoint();
writeUpToInjectionPoint(HeaderInjectionPoint);
writeHeaders();
writeRestOfFirstBuffer(HeaderInjectionPoint);
}
void Job::writeHeaders() {
RuntimeCheck CheckFirstBufferWriterOk("Job::copyFirstBufferInMessageMove() Check(Writer().good())");
void Job::copyFirstBufferInMessageMove() {
Writer().write(reinterpret_cast<char*>(&ReadBuffer[0]), Reader().gcount());
CheckFirstBufferWriterOk(Writer().good());
}
void Job:: writeTheRestOfTheFirstBuffer() {
RuntimeFault FaultLongCopyReaderBad("Job::readLongCopyBlock() Fault(Reader().bad())");
void Job::readLongCopyBlock() {
Reader().read(reinterpret_cast<char*>(&ReadBuffer[0]), ReadBufferSize);
FaultLongCopyReaderBad(Reader().bad());
}
void Job::injectHeadersInMessageMove() {
//// writeUpToTheInjectionPoint()
//// writeTheHeaders()
//// writeTheRestOfTheFirstBuffer()
RuntimeFault FaultLongCopyWriterBad("Job::writeLongCopyBlock() Fault(Writer().bad())");
void Job::writeLongCopyBlock() {
if(Reader().gcount()) {
Writer().write(reinterpret_cast<char*>(&ReadBuffer[0]), Reader().gcount());
FaultLongCopyWriterBad(Writer().bad());
}
}
void Job::copyRestOfLongMessage() {
//// while(Reader.good() && !Reader.eof()) {
//// readBlockOfData()
//// writeBlockOfData()
//// }
while(Reader().good()) {
readLongCopyBlock();
writeLongCopyBlock();
}
}
void Job::moveMessageToHoldPath(string& Destination) {
openWriter(Destination);
if(ScanResultConfiguration.InjectHeaders) injectHeadersInMessageMove();
if(ScanResultConfiguration.InjectHeaders) {
copyFirstBufferAndInjectHeadersInMessageMove();
} else {
copyFirstBufferInMessageMove();
}
copyRestOfLongMessage();
closeWriter();
}
@@ -365,8 +436,6 @@ void Job::doHold() {
emitDISCARD();
}
const int NoScanYet = -1;
Job::Job(ScannerPool& S, OutputProcessor& O) : // Construct with important links.
Scanners(S),
Output(O),

+ 10
- 3
SNF4CGP/JobPool.hpp Ver arquivo

@@ -71,12 +71,18 @@ class Job {
string calculateDestinationFileName();
void emitMessageMovedTo(string& Destination);
string LocalLineEnd;
void Job::identifyLocalLineEnd();
void identifyLocalLineEnd();
void moveInsertCursorForwardToBlockTerminus(size_t& InsertCursor, string& BlockTerminus);
bool isMinimumSafeDistanceFromEOF(size_t Position);
size_t findHeaderInsertPoint();
void writeUpToInjectionPoint(size_t InjectionPoint);
void writeHeaders();
void writeTheRestOfTheFirstBuffer();
void injectHeadersInMessageMove();
void writeRestOfFirstBuffer(size_t InjectionPoint);
void copyFirstBufferAndInjectHeadersInMessageMove(); // With header injection.
void copyFirstBufferInMessageMove(); // Without header injection.
void readLongCopyBlock();
void writeLongCopyBlock();
void copyRestOfLongMessage();
void moveMessageToHoldPath(string& Destination);
@@ -100,6 +106,7 @@ class Job {
void emitException(const string& What);
void emitUnknownException();
void emitLogComment();
void emitXMLLogData();
void emitClassicLogData();

Carregando…
Cancelar
Salvar