2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 // @ Project : Access Control Engine
20 // @ File Name : Attribute.h
21 // @ Date : 2009-05-06
26 #if !defined(_ATTRIBUTE_H)
34 #include <ace-dao-ro/BaseAttribute.h>
36 class Attribute : public AceDB::BaseAttribute
40 * Types of match functions
42 enum class Match { Equal, Glob, Regexp, Error };
44 * Types of attribute value modifiers
46 enum class Modifier { Non, Scheme, Authority, SchemeAuthority, Host, Path };
48 * Possible match results
50 enum class MatchResult { MRUndetermined = -1, MRFalse = 0, MRTrue = 1};
55 * New attribute constructor
56 * @param name name of the new attribute
57 * @param matchFunction match function used in the attribute
58 * @param type attribute type
60 Attribute(const std::string *name,
61 const Match matchFunction,
66 * Constructor used to create default attribute ( used for unit tests )
67 * @param nm name of the default attribute
69 Attribute(const std::string& nm) :
70 matchFunction(Match::Error),
71 modifierFunction(Modifier::Non)
74 m_typeId = Type::Subject;
75 m_undetermindState = false;
83 std::list<std::string> * getValue() const
85 return AceDB::BaseAttribute::getValue();
87 Match getMatchFunction() const
93 void addValue (const std::string *value);
95 MatchResult matchAttributes(const BaseAttribute *) const;
98 * Operator used in for attribute set,used to distinguished only attribute names
99 * It cannot take attribute type into consideration
101 bool operator< (const Attribute & obj) const
103 int result = this->m_name.compare(*obj.getName());
104 if (result == 0) { //If names are equal check attribute types
105 if (this->m_typeId < obj.getType()) {
107 } else if (this->m_typeId > obj.getType()) {
111 //If result is negative that means that 'this' was '<' than obj
115 /** Checks if object type is equal to argument */
116 bool instanceOf(Type type_)
118 return type_ == m_typeId;
121 friend std::ostream & operator<<(std::ostream & out,
122 const Attribute & attr);
126 bool searchAndCut(const char *);
129 * URI definition from rfc2396
131 * <scheme>://<authority><path>?<query>
132 * Each of the components may be absent, apart from the scheme.
133 * Host is a part of authority as in definition below:
135 * authority = server | reg_name
136 * server = [ [ userinfo "@" ] hostport ]
137 * <userinfo>@<host>:<port>
139 * Extract from rfc2396
140 * The authority component is preceded by a double slash "//" and is
141 * terminated by the next slash "/", question-mark "?", or by the end of
142 * the URI. Within the authority component, the characters ";", ":",
143 * "@", "?", and "/" are reserved.
145 * Modifiers should return pointer to empty string if given part of string was empty.
146 * Modifiers should return NULL if the string to be modified was not an URI.
148 std::string * uriScheme(const std::string *) const;
149 std::string * uriAuthority(const std::string *) const;
150 std::string * uriSchemeAuthority(const std::string *) const;
151 std::string * uriHost(const std::string *) const;
152 std::string * uriPath(const std::string *) const;
153 std::string * applyModifierFunction(const std::string * val) const;
155 bool parse(const std::string *input,
156 std::string *part) const;
157 bool find_error(const std::string *part) const;
159 bool checkScheme(const std::string *scheme) const;
160 bool checkAuthority(const std::string *scheme) const;
161 std::string * getHost(const std::string *scheme) const;
162 bool checkPath(const std::string *scheme) const;
164 bool isSchemeAllowedCharacter(int c) const;
165 bool isSegmentAllowedCharacter(int c) const;
166 bool isUserInfoAllowedString(const std::string *str) const;
167 bool isHostAllowedString(const std::string *str) const;
168 bool isHostNameAllowedString(const std::string * str) const;
169 bool isIPv4AllowedString(const std::string * str) const;
170 bool isDomainLabelAllowedString(const char * data,
172 bool isTopLabelAllowedString(const char* data,
175 bool isUnreserved(int c) const;
176 bool isAlphanum(int c) const;
177 bool isEscaped(const char esc[3]) const;
178 bool isHex(int c) const;
180 MatchResult lists_comparator(
181 const std::list<std::string> *first,
182 const std::list<std::string> *second,
183 MatchResult (*comparator)(const std::string *,
184 const std::string *)) const;
187 * Map used to check if character is a 'mark'
189 static const bool mark[256];
191 * Map used to check if character is a 'digit'
194 static const bool digit[256];
196 * Map used to check if character is an 'alphanumeric' value
199 static const bool alpha[256];
203 Modifier modifierFunction;
206 typedef AceDB::BaseAttributeSet AttributeSet;
208 //TODO remove later or ifdef debug methods
209 void printAttributes(const AttributeSet& attrs);
210 void printAttributes(const std::list<Attribute> & attrs);
212 #endif //_ATTRIBUTE_H