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 <dpl/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,
65 * Constructor used by ACE serializer
66 * @param is Input stream to which the object will be serialized
69 Attribute(std::istream& is);
72 * Constructor used to create default attribute ( used for unit tests )
73 * @param nm name of the default attribute
75 Attribute(const std::string& nm) :
76 matchFunction(Match::Error),
77 modifierFunction(Modifier::Non)
80 m_typeId = Type::Subject;
81 m_undetermindState = false;
89 bool serialize(std::ostream& os) const;
91 std::list<std::string> * getValue() const
93 return AceDB::BaseAttribute::getValue();
95 Match getMatchFunction() const
100 /* --- Setters --- */
101 void addValue (const std::string *value);
103 MatchResult matchAttributes(const BaseAttribute *) const;
106 * Operator used in for attribute set,used to distinguished only attribute names
107 * It cannot take attribute type into consideration
109 bool operator< (const Attribute & obj) const
111 int result = this->m_name.compare(*obj.getName());
112 if (result == 0) { //If names are equal check attribute types
113 if (this->m_typeId < obj.getType()) {
115 } else if (this->m_typeId > obj.getType()) {
119 //If result is negative that means that 'this' was '<' than obj
123 /** Checks if object type is equal to argument */
124 bool instanceOf(Type type_)
126 return type_ == m_typeId;
129 friend std::ostream & operator<<(std::ostream & out,
130 const Attribute & attr);
134 bool searchAndCut(const char *);
137 * URI definition from rfc2396
139 * <scheme>://<authority><path>?<query>
140 * Each of the components may be absent, apart from the scheme.
141 * Host is a part of authority as in definition below:
143 * authority = server | reg_name
144 * server = [ [ userinfo "@" ] hostport ]
145 * <userinfo>@<host>:<port>
147 * Extract from rfc2396
148 * The authority component is preceded by a double slash "//" and is
149 * terminated by the next slash "/", question-mark "?", or by the end of
150 * the URI. Within the authority component, the characters ";", ":",
151 * "@", "?", and "/" are reserved.
153 * Modifiers should return pointer to empty string if given part of string was empty.
154 * Modifiers should return NULL if the string to be modified was not an URI.
156 std::string * uriScheme(const std::string *) const;
157 std::string * uriAuthority(const std::string *) const;
158 std::string * uriSchemeAuthority(const std::string *) const;
159 std::string * uriHost(const std::string *) const;
160 std::string * uriPath(const std::string *) const;
161 std::string * applyModifierFunction(const std::string * val) const;
163 bool parse(const std::string *input,
164 std::string *part) const;
165 bool find_error(const std::string *part) const;
167 bool checkScheme(const std::string *scheme) const;
168 bool checkAuthority(const std::string *scheme) const;
169 std::string * getHost(const std::string *scheme) const;
170 bool checkPath(const std::string *scheme) const;
172 bool isSchemeAllowedCharacter(int c) const;
173 bool isSegmentAllowedCharacter(int c) const;
174 bool isUserInfoAllowedString(const std::string *str) const;
175 bool isHostAllowedString(const std::string *str) const;
176 bool isHostNameAllowedString(const std::string * str) const;
177 bool isIPv4AllowedString(const std::string * str) const;
178 bool isDomainLabelAllowedString(const char * data,
180 bool isTopLabelAllowedString(const char* data,
183 bool isUnreserved(int c) const;
184 bool isAlphanum(int c) const;
185 bool isEscaped(const char esc[3]) const;
186 bool isHex(int c) const;
188 MatchResult lists_comparator(
189 const std::list<std::string> *first,
190 const std::list<std::string> *second,
191 MatchResult (*comparator)(const std::string *,
192 const std::string *)) const;
195 * Map used to check if character is a 'mark'
197 static const bool mark[256];
199 * Map used to check if character is a 'digit'
202 static const bool digit[256];
204 * Map used to check if character is an 'alphanumeric' value
207 static const bool alpha[256];
211 Modifier modifierFunction;
214 typedef AceDB::BaseAttributeSet AttributeSet;
216 //TODO remove later or ifdef debug methods
217 void printAttributes(const AttributeSet& attrs);
218 void printAttributes(const std::list<Attribute> & attrs);
220 #endif //_ATTRIBUTE_H