|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * This file contains the implementation for CAuthExpression which is only visible |
|
16 * to implementation, and not the the client code. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 /** |
|
22 @file |
|
23 @released |
|
24 @internalComponent |
|
25 */ |
|
26 |
|
27 #ifndef AUTHEXPRESSION_IMPL_H |
|
28 #define AUTHEXPRESSION_IMPL_H |
|
29 |
|
30 #include <s32buf.h> |
|
31 #include <authserver/authexpression.h> |
|
32 |
|
33 namespace AuthServer { |
|
34 |
|
35 // constants and operators used for processing authentication expression. |
|
36 |
|
37 _LIT(KAuthOpAnd,"&"); |
|
38 _LIT(KAuthOpOr,"|"); |
|
39 _LIT(KAuthBiometric, "Biometric"); |
|
40 _LIT(KAuthDefault, "Default"); |
|
41 _LIT(KAuthKnowledge, "Knowledge"); |
|
42 _LIT(KAuthToken, "Token"); |
|
43 _LIT(KAuthPerformance, "Performance"); |
|
44 _LIT(KOpenBracket, "("); |
|
45 _LIT(KCloseBracket, ")"); |
|
46 const TInt KMaxBufferSize = 2048; |
|
47 |
|
48 class TSizeStream : public MStreamBuf |
|
49 /** |
|
50 This subclass of MStreamBuf is used with |
|
51 RWriteStream to count how many bytes are |
|
52 required to externalize an object. |
|
53 */ |
|
54 { |
|
55 public: |
|
56 inline TSizeStream(); |
|
57 inline TInt Size() const; |
|
58 |
|
59 // override MStreamBuf |
|
60 IMPORT_C virtual void DoWriteL(const TAny* /* aPtr */, TInt aLength); |
|
61 |
|
62 private: |
|
63 /** Accumulated stream length in bytes. */ |
|
64 TInt iSize; |
|
65 }; |
|
66 |
|
67 |
|
68 class CAuthExpressionImpl : public CAuthExpression |
|
69 /** |
|
70 This class, which is not visible to clients, |
|
71 defines the variables and functions which are |
|
72 used by authentication expressions. |
|
73 |
|
74 Clients should use the CAuthExpression base class |
|
75 which provides type safety but provides no implementation, |
|
76 so authentication expressions can be re-implemented |
|
77 later without breaking BC. |
|
78 |
|
79 @internalComponent |
|
80 */ |
|
81 { |
|
82 public: |
|
83 /** |
|
84 The type of expression represented by an instance |
|
85 of this object, namely a plugin type, a plugin ID, |
|
86 or a complex AND expression, OR expression or a |
|
87 NULL expression. |
|
88 */ |
|
89 enum TType {EPluginType, EPluginId, EAnd, EOr, ENull}; |
|
90 |
|
91 CAuthExpressionImpl(TAuthPluginType aType); |
|
92 CAuthExpressionImpl(TPluginId aPluginId); |
|
93 CAuthExpressionImpl(); |
|
94 CAuthExpressionImpl(TType aType, CAuthExpressionImpl* aLeft, CAuthExpressionImpl* aRight); |
|
95 |
|
96 IMPORT_C static CAuthExpressionImpl* NewL(RReadStream& aReadStream); |
|
97 |
|
98 virtual ~CAuthExpressionImpl(); |
|
99 |
|
100 // implement CAuthExpression |
|
101 virtual void ExternalizeL(RWriteStream& aWriteStream) const; |
|
102 |
|
103 IMPORT_C static CAuthExpression* CreateAuthExprObjectL(const TDesC& aStrengthAliasString); |
|
104 |
|
105 IMPORT_C static void InsertSpaceBetweenOperatorsL(const TDesC& aAliasStringToBeProcessed, RBuf& aResultantAliasString); |
|
106 |
|
107 inline TType Type() const; |
|
108 inline const CAuthExpressionImpl* Left() const; |
|
109 inline const CAuthExpressionImpl* Right() const; |
|
110 inline TAuthPluginType PluginType() const; |
|
111 inline TPluginId PluginId() const; |
|
112 inline CAuthExpressionImpl* Parent() const; |
|
113 |
|
114 private: |
|
115 /** |
|
116 Current authentication expression version. |
|
117 This is embedded in the externalized expression |
|
118 so the server can reject the expression if it |
|
119 uses an unsupported version. |
|
120 */ |
|
121 static const TInt KVersion; |
|
122 void Externalize2L(RWriteStream& aWriteStream) const; |
|
123 static CAuthExpressionImpl* New2L(RReadStream& aReadStream); |
|
124 static CAuthExpression* CreateAuthExpressionL(const TDesC& aAliasString); |
|
125 static CAuthExpression* CreateAuthExpressionL(RPointerArray<CAuthExpression>& aAuthExprArray, TPtrC aOperator); |
|
126 static CAuthExpression* EvaluateAliasStringL(const RBuf& aStrengthAliasString); |
|
127 |
|
128 |
|
129 private: |
|
130 /** |
|
131 This expression's parent node. This value is |
|
132 used to navigate the expression tree during |
|
133 evaluation. |
|
134 */ |
|
135 CAuthExpressionImpl* iParent; |
|
136 |
|
137 /** This expression's type. */ |
|
138 TType iType; |
|
139 |
|
140 class TBinaryComb |
|
141 /** |
|
142 This class contains pointers to the left and |
|
143 right subexpressions when this expression is |
|
144 an AND or an OR. |
|
145 */ |
|
146 { |
|
147 public: |
|
148 /** Left subexpression. This cannot be NULL. */ |
|
149 CAuthExpressionImpl* iLeft; |
|
150 /** Right subexpression. This cannot be NULL. */ |
|
151 CAuthExpressionImpl* iRight; |
|
152 }; |
|
153 |
|
154 union |
|
155 { |
|
156 /** This field is valid iff iType == EPluginType. */ |
|
157 TAuthPluginType iPluginType; |
|
158 /** This field is valid iff iType == EPluginId. */ |
|
159 TPluginId iPluginId; |
|
160 /** This field is valid iff iType == EAnd or iType == EOr. */ |
|
161 TBinaryComb iComb; |
|
162 }; |
|
163 |
|
164 private: |
|
165 // Invariant and Panic are defined, but only as stub |
|
166 // functions for release mode. |
|
167 |
|
168 enum TPanic |
|
169 /** |
|
170 In debug builds the current thread can be halted |
|
171 with panic category "AUTHEXPR" and one of the |
|
172 following reasons to indicate that the object has |
|
173 become corrupt or that a caller has supplied an |
|
174 invalid argument to one of this class' functions. |
|
175 */ |
|
176 { |
|
177 ECtTyInvariant = 0x10, |
|
178 ECtIdInvariant = 0x20, |
|
179 ECt2BadComb = 0x30, ECt2NullLeft, ECt2NullRight, ECt2Invariant, |
|
180 ETyAInvariant = 0x40, |
|
181 ELfInvariant = 0x50, ELfNotComplex, |
|
182 ERgInvariant = 0x60, ERgNotComplex, |
|
183 EPTyInvariant = 0x70, EPTyNotPluginType, |
|
184 EPIdInvariant = 0x80, EPIdNotPluginId, |
|
185 EPPrInvariant = 0x90, |
|
186 EExtInvariant = 0xa0 |
|
187 }; |
|
188 |
|
189 |
|
190 IMPORT_C TBool Invariant() const; |
|
191 IMPORT_C static void Panic(TPanic aPanic); |
|
192 }; |
|
193 |
|
194 } // namespace AuthServer { |
|
195 |
|
196 #include "authexpression_impl.inl" |
|
197 |
|
198 #endif // #ifndef AUTHEXPRESSION_IMPL_H |
|
199 |