# HG changeset patch # User František Kučera # Date 1615654689 -3600 # Node ID 2179f13227f4df1dd4f6fb5b47fddf76de8a1fdf # Parent bfee08a31fdcd2f0f20341eeba6e6110cf211b00 AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons diff -r bfee08a31fdc -r 2179f13227f4 nbproject/configurations.xml --- a/nbproject/configurations.xml Sun Mar 07 17:50:11 2021 +0100 +++ b/nbproject/configurations.xml Sat Mar 13 17:58:09 2021 +0100 @@ -42,6 +42,16 @@ + + ASN1ContentHandler.h + ASN1Reader.h + AbstractParser.cpp + AbstractParser.h + BasicASN1Reader.h + DOMBuildingSAXContentHandler.h + GenericASN1ContentHandler.h + SAXContentHandler.h + XMLDocumentConstructor.h relpipe-in-xmltable.cpp @@ -102,6 +112,28 @@ true + + + + + + + + + + + + + + + + @@ -143,6 +175,28 @@ + + + + + + + + + + + + + + + + diff -r bfee08a31fdc -r 2179f13227f4 src/CMakeLists.txt --- a/src/CMakeLists.txt Sun Mar 07 17:50:11 2021 +0100 +++ b/src/CMakeLists.txt Sat Mar 13 17:58:09 2021 +0100 @@ -30,6 +30,7 @@ add_executable( ${EXECUTABLE_FILE} relpipe-in-xmltable.cpp + lib/AbstractParser.cpp ) # Link libraries: diff -r bfee08a31fdc -r 2179f13227f4 src/XMLDocumentConstructor.h --- a/src/XMLDocumentConstructor.h Sun Mar 07 17:50:11 2021 +0100 +++ b/src/XMLDocumentConstructor.h Sat Mar 13 17:58:09 2021 +0100 @@ -16,12 +16,16 @@ */ #pragma once +#include + +#include "lib/BasicASN1Reader.h" +#include "lib/GenericASN1ContentHandler.h" +#include "lib/DOMBuildingSAXContentHandler.h" + namespace relpipe { namespace in { namespace xmltable { -#include - class XMLDocumentConstructor { private: std::istream* input = nullptr; @@ -30,11 +34,15 @@ XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) { } - + void setOption(const std::string& uri, const std::string& value) { } void process() { + + relpipe::in::asn1::lib::BasicASN1Reader reader; + reader.write(nullptr, 0); // FIXME: transfer data from input to reader + use DOMBuildingSAXContentHandler + parser->parse_stream(*input); } }; diff -r bfee08a31fdc -r 2179f13227f4 src/lib/ASN1ContentHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/ASN1ContentHandler.h Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,30 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +class ASN1ContentHandler { +}; + +} +} +} +} diff -r bfee08a31fdc -r 2179f13227f4 src/lib/ASN1Reader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/ASN1Reader.h Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,39 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include + +#include "AbstractParser.h" +#include "ASN1ContentHandler.h" + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +class ASN1Reader : public AbstractParser { +public: + virtual ~ASN1Reader() = default; + virtual void addHandler(std::shared_ptr handler) = 0; + virtual void process() = 0; +}; + +} +} +} +} diff -r bfee08a31fdc -r 2179f13227f4 src/lib/AbstractParser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/AbstractParser.cpp Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,95 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "AbstractParser.h" + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +class AbstractParserImpl { +private: + AbstractParser* interface; +public: + + AbstractParserImpl(AbstractParser* interface) : interface(interface) { + } + + virtual ~AbstractParserImpl() { + } + + void write(const char* buffer, const size_t length) { + // TODO: update pointers and positions + try { + // TODO: call an overridable method to get preferred minimum block size and run cycle only if we have enough data or EOF + interface->update(); + commit(); + } catch (const AbstractParser::ReadBufferUnderflowException& e) { + rollback(); + } catch (const AbstractParser::ExplicitRollbackException& e) { + rollback(); + } + } + + void rollback() { + // FIXME: store content of the current buffer + update pointers and positions + // TODO: notify rollback listeners? (they can monitor the performance / frequency of rollbacks) + } + + void commit() { + } + + void read(char* buffer, const size_t length) { + } + + void peek(char* buffer, const size_t length) { + } +}; + +AbstractParser::AbstractParser() { + implementation = new AbstractParserImpl(this); +} + +AbstractParser::~AbstractParser() { + delete (AbstractParserImpl*) implementation; +} + +void AbstractParser::write(const char* buffer, const size_t length) { + ((AbstractParserImpl*) implementation)->write(buffer, length); +} + +void AbstractParser::commit() { + ((AbstractParserImpl*) implementation)->commit(); +} + +void AbstractParser::rollback() { + ((AbstractParserImpl*) implementation)->rollback(); +} + +void AbstractParser::read(char* buffer, const size_t length) { + ((AbstractParserImpl*) implementation)->read(buffer, length); +} + +void AbstractParser::peek(char* buffer, const size_t length) { + ((AbstractParserImpl*) implementation)->peek(buffer, length); +} + +} +} +} +} \ No newline at end of file diff -r bfee08a31fdc -r 2179f13227f4 src/lib/AbstractParser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/AbstractParser.h Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,91 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +class AbstractParserImpl; + +class AbstractParser { +private: + friend AbstractParserImpl; + AbstractParserImpl* implementation; +public: + virtual ~AbstractParser(); + void write(const char* buffer, const size_t length); + void rollback(); +protected: + AbstractParser(); + + /** + * Is thrown from read() and peak() methods if there are not enough data. + * Interrupts current update() cycle and causes rollback. + */ + class ReadBufferUnderflowException { + // TODO: common super-class for exceptions, hidden implementation + }; + + /** + * May be thrown from the update() method in order to cancel currenty cycle and do explicit rollback. + * Same data will be processed in the next cycle. + */ + class ExplicitRollbackException { + // TODO: common super-class for exceptions, hidden implementation + }; + + /** + * May be called from the update() method in order to explicitly confirm that read data was successfully processed. + * Such data will not be processed again during the next cycle (even if ReadBufferUnderflowException occurs later in this cycle). + + * Explicit commit() call is useful when we did some demanding work (so we are not willing to do it again in case of ReadBufferUnderflowException); + * and is necessary when we already published some outputs or did other non-idempotent operation or caused some other significant side effects. + + * If there is no commit() called and update() just finishes, commit() is called implicitly. + * + * Note: There is no accessible rollback() method – throw ExplicitRollbackException instead. + */ + void commit(); + + /** + * + * @param buffer + * @param length + */ + void read(char* buffer, const size_t length); + + /** + * + * @param buffer + * @param length + */ + void peek(char* buffer, const size_t length); + + /** + * + */ + virtual void update() = 0; +}; + +} +} +} +} diff -r bfee08a31fdc -r 2179f13227f4 src/lib/BasicASN1Reader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/BasicASN1Reader.h Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,76 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include + +#include "ASN1Reader.h" + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +/** + * Reads ASN.1 data encoded as BER (DER, CER). + */ +class BasicASN1Reader : public ASN1Reader { +public: + virtual ~BasicASN1Reader() = default; + + virtual void addHandler(std::shared_ptr handler) { + }; + + virtual void process() { + }; + + static ASN1Reader* create(std::istream& input) { + return new BasicASN1Reader(); + } + +private: + + enum class State { + A, + B, + C + }; + + State state = State::A; + +protected: + + void update() override { + + if (state == State::A) { + + } else if (state == State::B) { + + } else if (state == State::C) { + + } + + + + } + +}; + +} +} +} +} diff -r bfee08a31fdc -r 2179f13227f4 src/lib/DOMBuildingSAXContentHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/DOMBuildingSAXContentHandler.h Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,46 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +#include + +#include "SAXContentHandler.h" + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +class DOMBuildingSAXContentHandler : public SAXContentHandler { +private: + xmlpp::Document* document; + + DOMBuildingSAXContentHandler(xmlpp::Document* document) : document(document) { + } + +public: + + static DOMBuildingSAXContentHandler* create(xmlpp::Document* document) { + return new DOMBuildingSAXContentHandler(document); + } + +}; + +} +} +} +} diff -r bfee08a31fdc -r 2179f13227f4 src/lib/GenericASN1ContentHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/GenericASN1ContentHandler.h Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,30 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +class GenericASN1ContentHandler : public ASN1ContentHandler { +}; + +} +} +} +} diff -r bfee08a31fdc -r 2179f13227f4 src/lib/SAXContentHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/SAXContentHandler.h Sat Mar 13 17:58:09 2021 +0100 @@ -0,0 +1,34 @@ +/** + * Relational pipes + * Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#pragma once + +namespace relpipe { +namespace in { +namespace asn1 { +namespace lib { + +class SAXContentHandler { +public: + + virtual ~SAXContentHandler() = default; + +}; + +} +} +} +}