Просмотр исходного кода

tidy namespace FilterChain

master
Pete McNeil 4 лет назад
Родитель
Сommit
d27d36f80e
2 измененных файлов: 34 добавлений и 40 удалений
  1. 1
    1
      FilterChain.cpp
  2. 33
    39
      FilterChain.hpp

+ 1
- 1
FilterChain.cpp Просмотреть файл

@@ -1291,7 +1291,7 @@ unsigned char FilterChainHeaderAnalysis::doEndOfHeaders() {
return GetByte(); // Return the first byte from there :-)
}

void FilterChainHeaderAnalysis::SetOutputBuffer(string& s) { // Setup the OutputBuffer.
void FilterChainHeaderAnalysis::SetOutputBuffer(std::string& s) { // Setup the OutputBuffer.
OutputBuffer = (char*) s.c_str(); OutputIndex = 0; // Capture the c_str and reset the index.
}


+ 33
- 39
FilterChain.hpp Просмотреть файл

@@ -1,6 +1,6 @@
// FilterChain.hpp
//
// (C) 2002-2009 MicroNeil Research Corporation
// (C) 2002-2020 MicroNeil Research Corporation
//
// This is the base class header for FilterChain objects.
// FilterChain objects can be chained together to filter
@@ -54,8 +54,7 @@
// it's source's data, or a stream of '0's if none has been
// defined.

#ifndef _MN_FilterChain
#define _MN_FilterChain
#pragma once

#include <stdexcept>
#include <iostream>
@@ -66,9 +65,6 @@
#include <cctype>


using namespace std;


// Define parameters for this module.

const static int ScanBufferSize = 128; // Define the buffer size.
@@ -83,11 +79,11 @@ class FilterChain {

public:

class BadSource : public invalid_argument { // Bad Source Exception.
public: BadSource(const string& w):invalid_argument(w){}
class BadSource : public std::invalid_argument { // Bad Source Exception.
public: BadSource(const std::string& w):invalid_argument(w){}
};
class Empty : public underflow_error { // Empty Exception.
public: Empty(const string& w):underflow_error(w){}
class Empty : public std::underflow_error { // Empty Exception.
public: Empty(const std::string& w):underflow_error(w){}
};

virtual unsigned char GetByte() { // Return either 0
@@ -102,8 +98,8 @@ class FilterChain {
FilterChain(FilterChain* S) {
if(NULL==S) throw BadSource("FilterChain: NULL source not valid");
else Source = S;
}
}
virtual ~FilterChain() {} // Stop Warns about no virt dtor
};

@@ -115,7 +111,7 @@ class FilterChainInput : public FilterChain {

private:

istream* SourceIstream;
std::istream* SourceIstream;

public:

@@ -146,7 +142,7 @@ class FilterChainInput : public FilterChain {

// Here we overload the constructor to accept a stream.

FilterChainInput(istream* S){ // Build me with a stream.
FilterChainInput(std::istream* S){ // Build me with a stream.
if(NULL==S) throw BadSource("FilterChainInput: Null source not valid" ); // If it's NULL that's bad.
if(!S->good()) throw BadSource("FilterChainInput: Bad istream"); // Not good is bad.
else SourceIstream = S; // If it's good we keep it.
@@ -220,9 +216,9 @@ class FilterChainCBFR : public FilterChain {

unsigned char* InputBuffer;
unsigned int BufferLength;
unsigned int BufferIndex;
unsigned int BufferIndex;

stringstream& PrependedHeaders;
std::stringstream& PrependedHeaders;

bool PrependNotBuffer;

@@ -266,7 +262,7 @@ class FilterChainCBFR : public FilterChain {

// Here we overload the constructor to accept a stream.

FilterChainCBFR(unsigned char* S, int l, stringstream& P) : // Give me a bfr and a stringstream.
FilterChainCBFR(unsigned char* S, int l, std::stringstream& P) : // Give me a bfr and a stringstream.
InputBuffer(S), // Grab the buffer,
BufferLength(l), // Grab the buffer length,
BufferIndex(0), // Initialize the index to 0,
@@ -352,7 +348,7 @@ class FilterChainBase64 : public FilterChain {

unsigned int ScanIx; // Scanning Index.
unsigned int DequeIx; // Dequeing Index.
unsigned char Buffer; // Define a buffer.
unsigned char Buffer; // Define a buffer.
bool ValidBuffer; // Set if Buffer has data.

bool ValidByte(unsigned char y); // True if y can be decoded.
@@ -431,14 +427,14 @@ static const int DefunkerQueueSize = 24; // Size of defunk
class FilterChainDefunker : public FilterChain { // Class definition.

private:
// Occasionally when parsing a chunk of data we must return nothing and
// instead try again for the next character. Instead of resursing we can
// set this flag and the root state will simply try again in a loop.
bool ReturnNothing; // Set true to skip this round;
// Storeage
// Occasionally when parsing a chunk of data we must return nothing and
// instead try again for the next character. Instead of resursing we can
// set this flag and the root state will simply try again in a loop.
bool ReturnNothing; // Set true to skip this round;
// Storeage

unsigned char StoreBuffer[DefunkerSize];
int InputPosition;
@@ -555,11 +551,11 @@ class FilterChainDefunker : public FilterChain { // Class definiti

FilterChainDefunker(FilterChain* S) // Sourced constructor...
:FilterChain(S), // Call the base constructor.
InputPosition(0), // Reset both position pointers.
OutputPosition(0),
LastRawByte(0),
LastReadOut(0),
LastGetStore(0),
InputPosition(0), // Reset both position pointers.
OutputPosition(0),
LastRawByte(0),
LastReadOut(0),
LastGetStore(0),
Master(&FilterChainDefunker::SkipHeaders), // Set the initial external and
Internal(&FilterChainDefunker::Preamble) { // internal states.

@@ -652,7 +648,7 @@ class FilterChainUrlDecode : public FilterChain {

class FilterChainIPTester {
public:
virtual string& test(string& input, string& output) = 0;
virtual std::string& test(std::string& input, std::string& output) = 0;
};

// The supplied test() function accepts the input string and returns the
@@ -670,19 +666,19 @@ class FilterChainHeaderAnalysis : public FilterChain {

unsigned char (FilterChainHeaderAnalysis::*Mode)(); // Internal State Fn Pointer (What Mode)
FilterChainIPTester& IPTester; // This is the IP tester we use.
string IPToTest; // String to capture IPs for testing.
string IPTestResult; // String to receive IPtest results.
std::string IPToTest; // String to capture IPs for testing.
std::string IPTestResult; // String to receive IPtest results.

// Header analysis output state...

string EndOfHeaderResults; // String to capture EndOfHeaderResults.
std::string EndOfHeaderResults; // String to capture EndOfHeaderResults.

// OutputIndex and OutputLength are used to inject string data.
// These are used to inject IPTestResult data and Header Analysis data.

char* OutputBuffer; // Pointer to output injection string.
int OutputIndex; // End of header output results index.
void SetOutputBuffer(string& s); // Setup the OutputBuffer.
void SetOutputBuffer(std::string& s); // Setup the OutputBuffer.
unsigned char doInjectIPTestResult(); // Inject OutputBuffer and go to doSeekNL.
unsigned char doInjectAnalysis(); // Inject OutputBuffer and go to doOff.

@@ -740,7 +736,7 @@ class FilterChainHeaderAnalysis : public FilterChain {

FilterChainHeaderAnalysis(FilterChain* S, FilterChainIPTester& T) : // Construct with the chain and a tester.
FilterChain(S), // Capture the chain.
Mode(&FilterChainHeaderAnalysis::doSeekDispatch), // Start in SeekDispatch() mode
Mode(&FilterChainHeaderAnalysis::doSeekDispatch), // Start in SeekDispatch() mode
IPTester(T), // Capture the tester.
IPToTest(""), // IPToTest and
IPTestResult(""), // IPTestResult are both empty to start.
@@ -762,5 +758,3 @@ class FilterChainHeaderAnalysis : public FilterChain {
bool HighBitCharacters() { return (FoundHighBitCharacters); } // True if High bit characters were found.

};

#endif

Загрузка…
Отмена
Сохранить