Tizen 2.1 base
[framework/web/wrt-commons.git] / modules / ace / include / dpl / 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
45 #define whitespaces " \n\t\r"
46
47 enum CanonicalizationAlgorithm
48 {
49     C14N,
50     C14NEXCLUSIVE
51 };
52
53 class Parser
54 {
55   private:
56
57     xmlTextReaderPtr reader;
58
59     TreeNode * root;
60     TreeNode * currentRoot;
61     Subject * currentSubject;
62     Condition * currentCondition;
63     Attribute * currentAttribute;
64     std::string * currentText;
65
66     bool processingSignature;
67     bool canonicalizeOnce;
68
69     void processNode(xmlTextReaderPtr reader);
70
71     //Node Handlers
72     void endNodeHandler(xmlTextReaderPtr reader);
73     void textNodeHandler(xmlTextReaderPtr reader);
74     void startNodeHandler(xmlTextReaderPtr reader);
75
76     //Node names handlers
77     void handleAttr(xmlTextReaderPtr reader);
78     void handleRule(xmlTextReaderPtr reader);
79     void handleSubject();
80     void handleCondition(xmlTextReaderPtr reader);
81     void handleSubjectMatch(xmlTextReaderPtr reader);
82     void handleMatch(xmlTextReaderPtr reader,
83             Attribute::Type);
84     void handlePolicy(xmlTextReaderPtr reader,
85             TreeNode::TypeID type);
86
87     //helpers
88     Policy::CombineAlgorithm convertToCombineAlgorithm(xmlChar*);
89     Effect convertToEffect(xmlChar *effect);
90     Attribute::Match convertToMatchFunction(xmlChar * func);
91     void consumeCurrentText();
92     void consumeCurrentAttribute();
93     void consumeSubjectMatch(xmlChar * value = NULL);
94     void consumeCurrentSubject();
95     void consumeCurrentCondition();
96     void trim(std::string *);
97     // KW     void canonicalize(const char *, const char *, CanonicalizationAlgorithm canonicalizationAlgorithm);
98     // KW     int extractNodeToFile(xmlTextReaderPtr reader, const char * filename);
99
100     static const char *TOKEN_PARAM;
101   public:
102     Parser();
103     ~Parser();
104     TreeNode * parse(const std::string& filename, const std::string& schema);
105 };
106
107 #endif  //_PARSER_H