tizen 2.3 release
[framework/web/wearable/wrt-security.git] / ace / engine / Rule.cpp
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 : Rule.h
21 //  @ Date : 2009-05-06
22 //  @ Author : Samsung
23 //
24 //
25
26 #include <iostream>
27 #include <dpl/log/log.h>
28
29 #include <ace/Rule.h>
30
31 void Rule::printData()
32 {
33     std::cout << "Rule: effect: " << printEffect(this->effect) <<
34     " condition: " << this->condition;
35 }
36
37 std::string Rule::printEffect(const ExtendedEffect &effect) const
38 {
39     switch (effect.getEffect()) {
40     case Deny:
41         return "Deny";
42     case PromptBlanket:
43         return "PromptBlanket";
44     case PromptOneShot:
45         return "PromptOneShot";
46     case PromptSession:
47         return "PromptSession";
48     case Permit:
49         return "Permit";
50     case Inapplicable:
51         return "Inapplicable";
52     case Error:
53         return "Error";
54     default:
55         return "ERROR";
56     }
57 }
58
59 ExtendedEffect Rule::evaluateRule(const AttributeSet * attrSet) const
60 {
61     Attribute::MatchResult result = condition.evaluateCondition(attrSet);
62
63     if (result == Attribute::MatchResult::MRUndetermined) {
64         //        LogInfo("Rule is undetermined");
65         return ExtendedEffect(Undetermined);
66     } else if (result == Attribute::MatchResult::MRTrue) {
67         //       LogInfo("Rule effect "<<printEffect(effect));
68         return effect;
69     }
70     // LogInfo("Rule is inapplicable");
71     return Inapplicable;
72 }
73
74