author | František Kučera <franta-hg@frantovo.cz> |
Sun, 04 Jul 2021 11:51:13 +0200 | |
branch | v_0 |
changeset 27 | d9cc2d356cdb |
parent 13 | d5e2cb9e31f1 |
child 40 | 85b6f13f1088 |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Relational pipes |
|
3 |
* Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
#pragma once |
|
18 |
||
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
19 |
#include <memory> |
13
d5e2cb9e31f1
switch TransactionalBuffer from char to uint8_t + partial parser of tags and lengths
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
20 |
#include <stdexcept> |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
21 |
|
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
22 |
#include <libxml++-2.6/libxml++/libxml++.h> |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
23 |
|
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
24 |
#include "lib/BasicASN1Reader.h" |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
25 |
#include "lib/GenericASN1ContentHandler.h" |
7
afb7f3a4981a
rename SAXContentHandler to XMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
26 |
#include "lib/DOMBuildingXMLContentHandler.h" |
10 | 27 |
#include "lib/TransactionalBuffer.h" |
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
28 |
|
0 | 29 |
namespace relpipe { |
30 |
namespace in { |
|
31 |
namespace xmltable { |
|
32 |
||
33 |
class XMLDocumentConstructor { |
|
34 |
private: |
|
35 |
std::istream* input = nullptr; |
|
36 |
xmlpp::DomParser* parser = nullptr; |
|
37 |
public: |
|
38 |
||
39 |
XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) { |
|
40 |
} |
|
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
41 |
|
0 | 42 |
void setOption(const std::string& uri, const std::string& value) { |
43 |
} |
|
44 |
||
45 |
void process() { |
|
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
46 |
|
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
47 |
relpipe::in::asn1::lib::BasicASN1Reader reader; |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
48 |
std::shared_ptr<relpipe::in::asn1::lib::GenericASN1ContentHandler> asn1handler = make_shared<relpipe::in::asn1::lib::GenericASN1ContentHandler>(); |
7
afb7f3a4981a
rename SAXContentHandler to XMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
49 |
std::shared_ptr<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler> saxHandler = make_shared<relpipe::in::asn1::lib::DOMBuildingXMLContentHandler>(parser->get_document()); |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
50 |
|
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
51 |
asn1handler->addHandler(saxHandler); |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
52 |
reader.addHandler(asn1handler); |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
53 |
|
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
54 |
|
10 | 55 |
try { |
56 |
// TODO: buffering? (reader itself also buffers) |
|
13
d5e2cb9e31f1
switch TransactionalBuffer from char to uint8_t + partial parser of tags and lengths
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
57 |
for (uint8_t b = input->get(); input->good(); b = input->get()) reader.write(&b, 1); |
10 | 58 |
} catch (const relpipe::in::asn1::lib::TransactionalBuffer::WriteBufferOverflowException& e) { |
59 |
// TODO: avoid leaky abstraction and use different exception |
|
60 |
throw relpipe::writer::RelpipeWriterException(L"Transactional buffer for ASN.1 input is too small"); |
|
61 |
} |
|
5
15c3221e66af
read the input stream and pass dummy events through
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
62 |
|
3
68026fe3aaf5
AbstractParser: documentation + close() method
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
63 |
reader.close(); |
10 | 64 |
|
65 |
if (parser->get_document()->get_root_node() == nullptr) throw relpipe::writer::RelpipeWriterException(L"Empty ASN.1 input"); // TODO: move to common class |
|
0 | 66 |
} |
67 |
}; |
|
68 |
||
69 |
} |
|
70 |
} |
|
71 |
} |