Refactor SignatureValidator and reduce interface headers
[platform/core/security/cert-svc.git] / vcore / vcore / SaxReader.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file        SaxReader.h
18  * @author      Bartlomiej Grzelewski (b.grzelewski@samsung.com)
19  * @version     1.0
20  * @brief       Simple c++ interface for libxml2.
21  *              Its used in wrt-installer only and should be removed
22  *              from cert-svc.
23  */
24 #ifndef _SAXREADER_H_
25 #define _SAXREADER_H_
26
27 #include <string>
28 #include <libxml/xmlreader.h>
29
30 #include <vcore/exception.h>
31
32 namespace ValidationCore {
33 class SaxReader {
34 public:
35     SaxReader();
36     ~SaxReader();
37
38     class Exception {
39     public:
40         VCORE_DECLARE_EXCEPTION_TYPE(ValidationCore::Exception, Base);
41         VCORE_DECLARE_EXCEPTION_TYPE(Base, FileOpeningError);
42         VCORE_DECLARE_EXCEPTION_TYPE(Base, FileNotValid);
43         VCORE_DECLARE_EXCEPTION_TYPE(Base, ParserInternalError);
44         VCORE_DECLARE_EXCEPTION_TYPE(Base, WrongToken);
45         VCORE_DECLARE_EXCEPTION_TYPE(Base, ReadingValueError);
46         VCORE_DECLARE_EXCEPTION_TYPE(Base, ReadingNameError);
47         VCORE_DECLARE_EXCEPTION_TYPE(Base, UnsupportedType);
48     };
49
50     enum NodeType
51     {
52         NODE_UNSUPPORTED,
53         NODE_BEGIN,
54         NODE_END,
55         NODE_TEXT
56     };
57
58     enum ThrowType
59     {
60         THROW_ENABLE = 0,
61         THROW_DISABLE
62     };
63
64     /*
65      * xml validation modes
66      */
67     enum ValidationType
68     {
69         VALIDATION_DISABLE,
70         VALIDATION_XMLSCHEME,
71         VALIDATION_DTD
72     };
73
74     /*
75      * initializes parser
76      */
77     void initialize(
78             const std::string &filename,
79             bool defaultArgs = false,
80             ValidationType validation = VALIDATION_DISABLE,
81             const std::string &schema = std::string());
82     /*
83      * deinitializes parser
84      */
85     void deinitialize();
86
87     /**
88      * Move to next xml node.
89      */
90     bool next();
91
92     /**
93      * Move to next xml node. If next node name is differ from token the exception wiil
94      * be thronw.
95      */
96     void next(const std::string &token);
97
98     /**
99      * Check if xml tag is empty.
100      */
101     bool isEmpty(void);
102
103     /**
104      * Read attribute tag.
105      */
106     std::string attribute(const std::string &token, ThrowType throwStatus = THROW_ENABLE);
107
108     /**
109      * Read xml tag name without namespace.
110      */
111     std::string name();
112
113     /**
114      * Read xml tag namespace URI
115      */
116     std::string namespaceURI();
117
118     /**
119      * Read xml tag value.
120      */
121     std::string value();
122
123     /**
124      * Return information about node type.
125      */
126     NodeType type();
127
128     /**
129      * Save all contonet of xml file which is between current tag and
130      * it's close tag into buffer.
131      */
132     void dumpNode(std::string &buffer);
133
134 private:
135     /*
136      * internal libxml text reader
137      */
138     xmlTextReaderPtr m_reader;
139 };
140 }
141
142 #endif // _SAXREADER_H_