author | František Kučera <franta-hg@frantovo.cz> |
Sun, 20 Jun 2021 20:16:46 +0200 | |
branch | v_0 |
changeset 13 | d5e2cb9e31f1 |
parent 9 | 7a6abdd00ab5 |
child 15 | 95ca127ba816 |
permissions | -rw-r--r-- |
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2021 František Kučera (Frantovo.cz, GlobalCode.info) |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#pragma once |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
18 |
|
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
19 |
#include "ASN1ContentHandler.h" |
7
afb7f3a4981a
rename SAXContentHandler to XMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
20 |
#include "XMLContentHandler.h" |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
21 |
|
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
namespace relpipe { |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
namespace in { |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
namespace asn1 { |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
namespace lib { |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
|
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
27 |
/** |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
28 |
* Converts ASN.1 events to XML SAX events. |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
29 |
* |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
30 |
* Does not need to know anything about the model/schema – works with generic events (nodes). |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
31 |
*/ |
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
class GenericASN1ContentHandler : public ASN1ContentHandler { |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
33 |
private: |
7
afb7f3a4981a
rename SAXContentHandler to XMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
34 |
XMLContentHandlerProxy handlers; |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
35 |
public: |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
36 |
|
7
afb7f3a4981a
rename SAXContentHandler to XMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
37 |
void addHandler(std::shared_ptr<XMLContentHandler> handler) { |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
38 |
handlers.addHandler(handler); |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
39 |
} |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
40 |
|
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
41 |
virtual ~GenericASN1ContentHandler() { |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
42 |
} |
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
43 |
|
9
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
44 |
void writeStreamStart() override { |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
45 |
handlers.writeStartElement("asn1"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
46 |
} |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
47 |
|
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
48 |
void writeStreamEnd() override { |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
49 |
handlers.writeEndElement(); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
50 |
} |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
51 |
|
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
52 |
void writeCollectionStart(CollectionType type) override { |
9
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
53 |
if (type == CollectionType::Sequence) handlers.writeStartElement("sequence"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
54 |
else if (type == CollectionType::Set) handlers.writeStartElement("set"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
55 |
else handlers.writeStartElement("unknown-collection"); // TODO: exception? |
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
56 |
} |
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
57 |
|
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
58 |
void writeCollectionEnd() override { |
9
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
59 |
handlers.writeEndElement(); |
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
60 |
} |
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
61 |
|
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
62 |
void writeBoolean(bool value) override { |
9
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
63 |
handlers.writeStartElement("boolean"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
64 |
handlers.writeCharacters(value ? "true" : "false"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
65 |
handlers.writeEndElement(); |
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
66 |
} |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
67 |
|
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
68 |
void writeNull() override { |
9
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
69 |
handlers.writeStartElement("null"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
70 |
handlers.writeEndElement(); |
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
71 |
} |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
72 |
|
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
73 |
void writeInteger(int64_t value) override { |
9
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
74 |
handlers.writeStartElement("integer"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
75 |
handlers.writeCharacters(std::to_string(value)); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
76 |
handlers.writeEndElement(); |
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
77 |
} |
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
78 |
|
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
79 |
void writeString(StringType type, std::string value) override { |
9
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
80 |
handlers.writeStartElement("string"); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
81 |
handlers.writeCharacters(value); |
7a6abdd00ab5
partial implementation of DOMBuildingXMLContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
82 |
handlers.writeEndElement(); |
8
d37c1a5d09ce
bit more meaningful methods in ASN1ContentHandler
František Kučera <franta-hg@frantovo.cz>
parents:
7
diff
changeset
|
83 |
} |
4
7230e1ea0b07
proxy handlers forwarding events to all subordinate handlers
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
84 |
|
1
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
85 |
}; |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
86 |
|
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
87 |
} |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
88 |
} |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
89 |
} |
2179f13227f4
AbstractParser: AbstractParser, ASN1Reader, ASN1ContentHandler, SAXContentHandler, BasicASN1Reader, DOMBuildingSAXContentHandler, GenericASN1ContentHandler skeletons
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
90 |
} |