26f15e2b9468f87e672e8ef0f5432c00c06db637
[framework/security/security-server.git] / ace / include / ace / parser.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 //
18 //
19 //  @ Project : Access Control Engine
20 //  @ File Name : parser.h
21 //  @ Date : 2009-05-06
22 //  @ Author : Samsung
23 //
24 //
25
26 #ifndef _PARSER_H_
27 #define _PARSER_H_
28
29 //#include "/usr/include/libxml2/libxml/parser.h"
30 #include <string>
31 #include <libxml/xmlreader.h>
32 #include <libxml/c14n.h>
33 #include <libxml/xpath.h>
34 #include <libxml/xpathInternals.h>
35
36 #include "Policy.h"
37 #include "PolicySet.h"
38 #include "Request.h"
39 #include "Rule.h"
40 #include "Attribute.h"
41 #include "TreeNode.h"
42 #include "Subject.h"
43 #include "Condition.h"
44 #include "Effect.h"
45
46 #define whitespaces " \n\t\r"
47
48 enum CanonicalizationAlgorithm
49 {
50     C14N,
51     C14NEXCLUSIVE
52 };
53
54 class Parser
55 {
56   private:
57     RuleId ruleId;
58     xmlTextReaderPtr reader;
59
60     TreeNode * root;
61     TreeNode * currentRoot;
62     Subject * currentSubject;
63     Condition * currentCondition;
64     Attribute * currentAttribute;
65     std::string * currentText;
66
67     bool processingSignature;
68     bool canonicalizeOnce;
69
70     void processNode(xmlTextReaderPtr reader);
71
72     //Node Handlers
73     void endNodeHandler(xmlTextReaderPtr reader);
74     void textNodeHandler(xmlTextReaderPtr reader);
75     void startNodeHandler(xmlTextReaderPtr reader);
76
77     //Node names handlers
78     void handleAttr(xmlTextReaderPtr reader);
79     void handleRule(xmlTextReaderPtr reader);
80     void handleSubject();
81     void handleCondition(xmlTextReaderPtr reader);
82     void handleSubjectMatch(xmlTextReaderPtr reader);
83     void handleMatch(xmlTextReaderPtr reader,
84             Attribute::Type);
85     void handlePolicy(xmlTextReaderPtr reader,
86             TreeNode::TypeID type);
87
88     //helpers
89     Policy::CombineAlgorithm convertToCombineAlgorithm(xmlChar*);
90     ExtendedEffect convertToEffect(xmlChar *effect);
91     Attribute::Match convertToMatchFunction(xmlChar * func);
92     void consumeCurrentText();
93     void consumeCurrentAttribute();
94     void consumeSubjectMatch(xmlChar * value = NULL);
95     void consumeCurrentSubject();
96     void consumeCurrentCondition();
97     void trim(std::string *);
98     // KW     void canonicalize(const char *, const char *, CanonicalizationAlgorithm canonicalizationAlgorithm);
99     // KW     int extractNodeToFile(xmlTextReaderPtr reader, const char * filename);
100
101     static const char *TOKEN_PARAM;
102   public:
103     Parser();
104     ~Parser();
105     TreeNode * parse(const std::string& filename, const std::string& schema);
106 };
107
108 #endif  //_PARSER_H