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 * Evaluator mix-in classes implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 /** |
|
21 @file |
|
22 @released |
|
23 @internalComponent |
|
24 */ |
|
25 |
|
26 #ifndef AUTHSERVER_EVALUATOR_H |
|
27 #define AUTHSERVER_EVALUATOR_H |
|
28 |
|
29 #include "authexpression_impl.h" |
|
30 |
|
31 namespace AuthServer { |
|
32 |
|
33 class MEvaluatorPluginInterface |
|
34 /** |
|
35 CEvaluator uses this interface to invoke a plugin, |
|
36 which can be specified by type or ID. |
|
37 |
|
38 @see CEvaluator |
|
39 */ |
|
40 { |
|
41 public: |
|
42 /** |
|
43 Invoke the specified plugin and record the identity |
|
44 which was returned. |
|
45 |
|
46 @param aPluginId Plugin to use. |
|
47 @param aIdentityId On successful completion this |
|
48 object is set to the returned |
|
49 identity. |
|
50 @param aType The type of plugin represented |
|
51 by this instance. |
|
52 @param aStatus On completion (successful or |
|
53 otherwise) this object is |
|
54 completed with the error code. |
|
55 */ |
|
56 virtual void Evaluate(TPluginId aPluginId, TIdentityId& aIdentityId, |
|
57 CAuthExpressionImpl::TType aType, TRequestStatus& aStatus) = 0; |
|
58 |
|
59 /** |
|
60 Cancel the plugin currently being invoked. |
|
61 **/ |
|
62 virtual void CancelEvaluate() = 0; |
|
63 |
|
64 /** |
|
65 Invoke a plugin of the requested type and record |
|
66 the identity which was returned. |
|
67 |
|
68 @param aPluginType Type of plugin to use. The |
|
69 implementation maps this to a |
|
70 single, specific plugin. |
|
71 @param aIdentityId On successful completion this |
|
72 object is set to the returned |
|
73 identity. |
|
74 @param aType The type of plugin represented |
|
75 by this instance. |
|
76 @param aStatus On completion (successful or |
|
77 otherwise) this object is |
|
78 completed with the error code. |
|
79 */ |
|
80 virtual void Evaluate(TAuthPluginType aPluginType, TIdentityId& aIdentityId, |
|
81 CAuthExpressionImpl::TType aType, TRequestStatus& aStatus) = 0; |
|
82 }; |
|
83 |
|
84 class MEvaluatorClientInterface |
|
85 /** |
|
86 CEvaluator uses this interface to notify the server |
|
87 when an evaluation has finished, successfully or otherwise. |
|
88 |
|
89 The server implements this interface to notify |
|
90 the client that the authentication request has |
|
91 completed. |
|
92 */ |
|
93 { |
|
94 public: |
|
95 /** |
|
96 This function is called by the evaluator when it |
|
97 has successfully parsed and evaluated an expression. |
|
98 |
|
99 In this context, successful means there were no |
|
100 errors in running the plugins, or otherwise in |
|
101 evaluating the expression, such as OOM. It does |
|
102 not mean that a specific user was identified - |
|
103 aIdentity can still be CIdentity::KUnknown. |
|
104 |
|
105 @param aIdentityId Identified user. This can |
|
106 be CIdentity::KUnknown. |
|
107 @see EvaluationFailed |
|
108 */ |
|
109 virtual void EvaluationSucceeded(TIdentityId aIdentityId) = 0; |
|
110 /** |
|
111 This function is called by the evaluator when |
|
112 it has failed to evaluate an expression. Reasons |
|
113 for failure include failing to run a plugin; |
|
114 the user cancelling a plugin; OOM; and others. |
|
115 |
|
116 Failure in this sense does not means the expression |
|
117 was evaluated but no specific user was identified. |
|
118 That case is handled by EvaluationSucceeded. |
|
119 |
|
120 @param aReason Symbian OS error code. |
|
121 |
|
122 @see EvaluationSucceeded |
|
123 */ |
|
124 virtual void EvaluationFailed(TInt aReason) = 0; |
|
125 }; |
|
126 |
|
127 class CEvaluator : public CActive |
|
128 /** |
|
129 Expression evaluator. This asynchronously |
|
130 evaluates the supplied expression by calling |
|
131 the referenced plugins. |
|
132 */ |
|
133 { |
|
134 public: |
|
135 static CEvaluator* NewL(MEvaluatorPluginInterface* aPluginInterface, MEvaluatorClientInterface* aClientInterface); |
|
136 virtual ~CEvaluator(); |
|
137 |
|
138 void Evaluate(const CAuthExpressionImpl* aExpr); |
|
139 |
|
140 private: |
|
141 CEvaluator(MEvaluatorPluginInterface* aPluginInterface, MEvaluatorClientInterface* aClientInterface); |
|
142 void ConstructL(); |
|
143 |
|
144 void EvaluatedNode(TIdentityId aIdentity); |
|
145 void EvaluateCompound(const CAuthExpressionImpl* aParent); |
|
146 void ReplaceComplexIdentity(TIdentityId aIdentity); |
|
147 |
|
148 // complete client request |
|
149 void NotifyClientSucceeded(TIdentityId aIdentity); |
|
150 void NotifyClientFailed(TInt aReason); |
|
151 |
|
152 // manipulate RPN stack |
|
153 TBool PushIdentity(TIdentityId aIdentity); |
|
154 TIdentityId PopIdentity(); |
|
155 TIdentityId& LastIdentity(); |
|
156 void ResetRpnStack(); |
|
157 // implement CActive |
|
158 virtual void RunL(); |
|
159 virtual void DoCancel(); |
|
160 |
|
161 #ifdef _DEBUG |
|
162 enum TPanic |
|
163 { |
|
164 EENRpnStackNonZero = 0x10, |
|
165 EECRpnStackTooLow = 0x20, EECBadParentType, EECRpnStackNotOneAtRoot, EECBadRightParent, |
|
166 EBusy = 0x30, |
|
167 }; |
|
168 static void Panic(TPanic aPanic); |
|
169 TInt RpnDepth() const; |
|
170 #endif |
|
171 |
|
172 private: |
|
173 /** The evaluator uses this to invoke plugins. */ |
|
174 MEvaluatorPluginInterface*const iPluginInterface; |
|
175 /** |
|
176 The evaluator uses this to notify the server |
|
177 when an evaluation has completed, successfully |
|
178 or otherwise. |
|
179 */ |
|
180 MEvaluatorClientInterface*const iClientInterface; |
|
181 |
|
182 /** Constant value defined for short name readability only. */ |
|
183 static const CAuthExpressionImpl::TType KAnd; |
|
184 /** Constant value defined for short name readability only. */ |
|
185 static const CAuthExpressionImpl::TType KOr; |
|
186 |
|
187 /** The expression which is currently being evaluated. */ |
|
188 const CAuthExpressionImpl* iCurrentNode; |
|
189 |
|
190 /** The plugin sets this value to the returned identity. */ |
|
191 TIdentityId iIdentity; |
|
192 |
|
193 /** |
|
194 Granularity of RPN stack. This value should be large |
|
195 to parse a reasonable expression without having to |
|
196 reallocate, and without wasting too much memory. |
|
197 */ |
|
198 static const TInt KRPNGranularity; |
|
199 /** |
|
200 Intermediate results. (A CArrayFixFlat is used here |
|
201 instead of an RArray because, although it uses more |
|
202 memory, it can be resized when items are popped.) |
|
203 */ |
|
204 CArrayFixFlat<TIdentityId>* iRpnStack; |
|
205 }; |
|
206 |
|
207 } // namespace AuthServer |
|
208 |
|
209 #endif // #ifndef AUTHSERVER_EVALUATOR_H |
|
210 |
|
211 |
|