|
1 /* |
|
2 * Copyright (c) 2002 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 "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: Policy Management DM Adapter |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef __NSMLPMADAPTER_H__ |
|
21 #define __NSMLPMADAPTER_H__ |
|
22 |
|
23 // ------------------------------------------------------------------------------------------------ |
|
24 // Includes |
|
25 // ------------------------------------------------------------------------------------------------ |
|
26 #include <e32base.h> |
|
27 #include <smldmadapter.h> |
|
28 #include <PolicyEngineClient.h> |
|
29 |
|
30 // Constants |
|
31 const TUint KNSmlDMPMAdapterImplUid = 0x10207820; |
|
32 |
|
33 _LIT8( KNSmlPMDDFVersion, "1.0" ); // the DDF version must be changed if any changes in DDF structure ( built in DDFStructureL() function ) |
|
34 |
|
35 _LIT8( KNSmlPMNodeName, "PolicyMgmt" ); |
|
36 _LIT8( KNSmlPMDescription, "Root node for policy management." ); |
|
37 _LIT8( KNSmlPMPolicySetsNodeName, "PolicySets" ); |
|
38 _LIT8( KNSmlPMPolicySetsNodeDescription, "Holds a few permanent set references and dynamic sets root node." ); |
|
39 _LIT8( KNSmlPMDynamicSetsDynamicNodeDescription, "This dynamic node is placeholder for policy sets." ); |
|
40 _LIT8( KNSmlPMPolicySetPoliciesNodeName, "Policies" ); |
|
41 _LIT8( KNSmlPMPolicySetPoliciesNodeDescription, "This node is root for policy references inside a policy set." ); |
|
42 _LIT8( KNSmlPMPolicySetPoliciesDynamicNodeDescription, "This dynamic node is placeholder for policy references" ); |
|
43 _LIT8( KNSmlPMPolicySetPoliciesPolicyNodeName, "Policy" ); |
|
44 _LIT8( KNSmlPMPolicySetPoliciesPolicyNodeDescription, "This leaf holds a URI reference to actual policy in the management tree." ); |
|
45 _LIT8( KNSmlPMPolicySetPolicySetsNodeName, "PolicySets" ); |
|
46 _LIT8( KNSmlPMPolicySetPolicySetsNodeDescription, "This node is root for policy set references inside a policy set." ); |
|
47 _LIT8( KNSmlPMPolicySetPolicySetsDynamicNodeDescription, "This dynamic node is placeholder for policy set references" ); |
|
48 _LIT8( KNSmlPMPolicySetPolicySetsPolicySetNodeName, "PolicySet" ); |
|
49 _LIT8( KNSmlPMPolicySetPolicySetsPolicySetNodeDescription, "This is URI of actual policy set in the management tree." ); |
|
50 _LIT8( KNSmlPMPolicySetIDNodeName, "ID" ); |
|
51 _LIT8( KNSmlPMPolicySetIDNodeDescription, "ID of the policy set from the original policy language file." ); |
|
52 _LIT8( KNSmlPMPolicySetDataNodeName, "Data" ); |
|
53 _LIT8( KNSmlPMPolicySetDataNodeDescription, "Data of the policy set in policy language format." ); |
|
54 _LIT8( KNSmlPMPolicySetDescriptionNodeName, "Description" ); |
|
55 _LIT8( KNSmlPMPolicySetDescriptionNodeDescription, "Description of policy set from the original XACML file is reflected in this leaf." ); |
|
56 |
|
57 _LIT8( KNSmlPMPoliciesNodeName, "Policies" ); |
|
58 _LIT8( KNSmlPMPoliciesNodeDescription, "This node is root for all policies in system." ); |
|
59 _LIT8( KNSmlPMPoliciesDynaNodeDescription, "This dynamic node is placeholder for policies." ); |
|
60 _LIT8( KNSmlPMPoliciesIDNodeName, "ID" ); |
|
61 _LIT8( KNSmlPMPoliciesIDNodeDescription, "This node is root for all policies in system." ); |
|
62 _LIT8( KNSmlPMPoliciesDataNodeName, "Data" ); |
|
63 _LIT8( KNSmlPMPoliciesDataNodeDescription, "This leaf node gives access to the data of the policy in XACML format." ); |
|
64 _LIT8( KNSmlPMPoliciesDescNodeName, "Description" ); |
|
65 _LIT8( KNSmlPMPoliciesDescNodeDescription, "Description of policy from the original XACML file is reflected in this leaf." ); |
|
66 _LIT8( KNSmlPMPoliciesRulesNodeName, "Rules" ); |
|
67 _LIT8( KNSmlPMPoliciesRulesNodeDescription, "Description of policy from the original XACML file is reflected in this leaf." ); |
|
68 _LIT8( KNSmlPMPoliciesRulesDynaNodeDescription, "This dynamic node is placeholder for rule references." ); |
|
69 _LIT8( KNSmlPMPoliciesRulesRuleNodeName, "Rule" ); |
|
70 _LIT8( KNSmlPMPoliciesRulesRuleNodeDescription, "" ); |
|
71 |
|
72 _LIT8( KNSmlPMRulesNodeName, "Rules" ); |
|
73 _LIT8( KNSmlPMRulesNodeDescription, "This node is root for all rules in system." ); |
|
74 _LIT8( KNSmlPMRulesDynaNodeDescription, "This dynamic node is placeholder for rules." ); |
|
75 _LIT8( KNSmlPMRulesIDNodeName, "ID" ); |
|
76 _LIT8( KNSmlPMRulesIDNodeDescription, "This node is root for all rules in system." ); |
|
77 _LIT8( KNSmlPMRulesDataNodeName, "Data" ); |
|
78 _LIT8( KNSmlPMRulesDataNodeDescription, "This leaf node gives access to the data of the rules in XACML format." ); |
|
79 _LIT8( KNSmlPMRulesDescNodeName, "Description" ); |
|
80 _LIT8( KNSmlPMRulesDescNodeDescription, "Description of policy from the rules XACML file is reflected in this leaf." ); |
|
81 |
|
82 _LIT8( KNSmlPMPolicyDeliveryNodeName, "Delivery" ); |
|
83 _LIT8( KNSmlPMPolicyDeliveryNodeDescription, "This node holds the nodes that let DM Server to bring PolicyManagement command packages to device and observe status of such action." ); |
|
84 |
|
85 _LIT8( KNSmlPMDeliverySinkNodeName, "Sink" ); |
|
86 _LIT8( KNSmlPMDeliverySinkNodeDescription, "This node is used by DM Server to bring PolicyManagement command packages to device." ); |
|
87 |
|
88 _LIT8( KNSmlPMLastDeliveryStatusNodeName, "LastStatus" ); |
|
89 _LIT8( KNSmlPMLastDeliveryStatusNodeDescription, "Stores status of last executed delivery command." ); |
|
90 _LIT8( KNSmlPMDynamicNode, "" ); |
|
91 |
|
92 _LIT8( KNSmlPMListOfLeafs, "PolicySets/Policies/Rules/PolicyDelivery" ); |
|
93 _LIT8( KNSmlPMListOfDynamicSetsDynaLeafs, "Policies/PolicySets/ID/Data/Description" ); |
|
94 _LIT8( KNSmlPMListOfPoliciesDynaLeafs, "ID/Data/Description/Rules" ); |
|
95 _LIT8( KNSmlPMListOfRulesDynaLeafs, "ID/Data/Description" ); |
|
96 _LIT8( KNSmlPMListOfDynaPolicyLeafs, "Policy" ); |
|
97 _LIT8( KNSmlPMListOfDynaPolicySetLeafs, "PolicySet" ); |
|
98 |
|
99 _LIT8( KNSmlPMTextPlain, "text/plain" ); |
|
100 _LIT8( KNSmlPMSeparator8, "/" ); |
|
101 |
|
102 _LIT8( KTestNodeName, "TEST" ) ; |
|
103 |
|
104 // ------------------------------------------------------------------------------------------------ |
|
105 // CPmCommand |
|
106 // Struct is used to cache add command status referecne when policies are added |
|
107 // ------------------------------------------------------------------------------------------------ |
|
108 class CPmCommand : public CBase |
|
109 { |
|
110 CPmCommand( TInt aStatusRef, const TDesC8& aURI ) : iStatusRef( aStatusRef ), iURI (aURI) |
|
111 { |
|
112 } |
|
113 TInt iStatusRef ; |
|
114 TBuf8<256> iURI ; |
|
115 HBufC8 *iArgument ; |
|
116 void ConstructL(const TDesC8 &aArgument); |
|
117 public: |
|
118 virtual ~CPmCommand() ; |
|
119 static CPmCommand *NewL( TInt aStatusRef, const TDesC8& aURI, const TDesC8 &aArgument ); |
|
120 |
|
121 TInt StatusRef() const |
|
122 { |
|
123 return iStatusRef ; |
|
124 } |
|
125 const TDesC8 &URI() |
|
126 { |
|
127 return iURI ; |
|
128 } |
|
129 const TDesC8 &Argument() |
|
130 { |
|
131 return *iArgument; |
|
132 } |
|
133 }; |
|
134 |
|
135 |
|
136 // ------------------------------------------------------------------------------------------------ |
|
137 // CPmAdapter |
|
138 // ------------------------------------------------------------------------------------------------ |
|
139 class CPmAdapter : public CSmlDmAdapter |
|
140 { |
|
141 public: |
|
142 static CPmAdapter* NewL( MSmlDmCallback* aDmCallback ); |
|
143 static CPmAdapter* NewLC( MSmlDmCallback* aDmCallback ); |
|
144 |
|
145 virtual ~CPmAdapter(); |
|
146 |
|
147 // Pure virtual methods from CSmlDmAdapter |
|
148 void DDFVersionL( CBufBase& aVersion ); |
|
149 void DDFStructureL( MSmlDmDDFObject& aDDF ); |
|
150 void UpdateLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, |
|
151 const TDesC8& aObject, const TDesC8& aType, |
|
152 TInt aStatusRef ); |
|
153 void UpdateLeafObjectL( const TDesC8& /*aURI*/, const TDesC8& /*aLUID*/, |
|
154 RWriteStream*& /*aStream*/, const TDesC8& /*aType*/, |
|
155 TInt /*aStatusRef*/ ) ; |
|
156 |
|
157 void DeleteObjectL( const TDesC8& aURI, const TDesC8& aLUID, |
|
158 TInt aStatusRef ); |
|
159 |
|
160 void FetchLeafObjectL( const TDesC8& aURI, const TDesC8& aLUID, |
|
161 const TDesC8& aType, TInt aResultsRef, |
|
162 TInt aStatusRef ); |
|
163 |
|
164 void FetchLeafObjectSizeL( const TDesC8& aURI, const TDesC8& aLUID, |
|
165 const TDesC8& aType, TInt aResultsRef, |
|
166 TInt aStatusRef ) ; |
|
167 |
|
168 void ChildURIListL( const TDesC8& aURI, const TDesC8& aLUID, |
|
169 const CArrayFix<TSmlDmMappingInfo>& aPreviousURISegmentList, |
|
170 TInt aResultsRef, TInt aStatusRef ); |
|
171 |
|
172 void AddNodeObjectL( const TDesC8& aURI, const TDesC8& aParentLUID, |
|
173 TInt aStatusRef ); |
|
174 |
|
175 /** |
|
176 The function implements execute command. The information about the success |
|
177 of the command should be returned by calling SetStatusL function of |
|
178 MSmlDmCallback callback interface. This makes it possible to buffer the |
|
179 commands. |
|
180 However, all the status codes for buffered commands must be returned at |
|
181 the latest when the CompleteOutstandingCmdsL() of adapter is called. |
|
182 @param aURI URI of the command |
|
183 @param aLUID LUID of the object (if the adapter have earlier |
|
184 returned LUID to the DM Module). |
|
185 @param aArgument Argument for the command |
|
186 @param aType MIME type of the object |
|
187 @param aStatusRef Reference to correct command, i.e. this reference |
|
188 must be used when calling the SetStatusL of this |
|
189 command. |
|
190 @publishedPartner |
|
191 @prototype |
|
192 */ |
|
193 void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, |
|
194 const TDesC8& aArgument, const TDesC8& aType, |
|
195 TInt aStatusRef ); |
|
196 |
|
197 /** |
|
198 The function implements execute command. The information about the |
|
199 success of the command should be returned by calling SetStatusL function |
|
200 of MSmlDmCallback callback interface. This makes it possible to buffer the |
|
201 commands. |
|
202 However, all the status codes for buffered commands must be returned at |
|
203 the latest when the CompleteOutstandingCmdsL() of adapter is called. |
|
204 @param aURI URI of the command |
|
205 @param aLUID LUID of the object (if the adapter have earlier |
|
206 returned LUID to the DM Module). |
|
207 @param aStream Argument for the command. Adapter should create |
|
208 write stream and return, when data is written to |
|
209 stream by DM agent, StreamCommittedL() is called by |
|
210 DM engine |
|
211 @param aType MIME type of the object |
|
212 @param aStatusRef Reference to correct command, i.e. this reference |
|
213 must be used when calling the SetStatusL of this |
|
214 command. |
|
215 @publishedPartner |
|
216 @prototype |
|
217 */ |
|
218 void ExecuteCommandL( const TDesC8& aURI, const TDesC8& aLUID, |
|
219 RWriteStream*& aStream, const TDesC8& aType, |
|
220 TInt aStatusRef ) ; |
|
221 |
|
222 /** |
|
223 The function implements copy command. The information about the success of |
|
224 the command should be returned by calling SetStatusL function of |
|
225 MSmlDmCallback callback interface. This makes it possible to buffer the |
|
226 commands. |
|
227 However, all the status codes for buffered commands must be returned at |
|
228 the latest when the CompleteOutstandingCmdsL() of adapter is called. |
|
229 @param aTargetURI Target URI for the command |
|
230 @param aSourceLUID LUID of the target object (if one exists, and if the adapter |
|
231 has earlier returned a LUID to the DM Module). |
|
232 @param aSourceURI Source URI for the command |
|
233 @param aSourceLUID LUID of the source object (if the adapter has |
|
234 earlier returned a LUID to the DM Module). |
|
235 @param aType MIME type of the objects |
|
236 @param aStatusRef Reference to correct command, i.e. this reference |
|
237 must be used when calling the SetStatusL of this |
|
238 command. |
|
239 @publishedPartner |
|
240 @prototype |
|
241 */ |
|
242 void CopyCommandL( const TDesC8& aTargetURI, const TDesC8& aTargetLUID, |
|
243 const TDesC8& aSourceURI, const TDesC8& aSourceLUID, |
|
244 const TDesC8& aType, TInt aStatusRef ) ; |
|
245 |
|
246 /** |
|
247 The function indicates start of Atomic command. |
|
248 @publishedPartner |
|
249 @prototype |
|
250 */ |
|
251 void StartAtomicL(); |
|
252 |
|
253 /** |
|
254 The function indicates successful end of Atomic command. The adapter |
|
255 should commit all changes issued between StartAtomicL() and |
|
256 CommitAtomicL() |
|
257 @publishedPartner |
|
258 @prototype |
|
259 */ |
|
260 void CommitAtomicL(); |
|
261 |
|
262 /** |
|
263 The function indicates unsuccessful end of Atomic command. The adapter |
|
264 should rollback all changes issued between StartAtomicL() and |
|
265 RollbackAtomicL(). If rollback fails for a command, adapter should use |
|
266 SetStatusL() to indicate it. |
|
267 @publishedPartner |
|
268 @prototype |
|
269 */ |
|
270 void RollbackAtomicL() ; |
|
271 |
|
272 /** |
|
273 Returns ETrue if adapter supports streaming otherwise EFalse. |
|
274 @param aItemSize size limit for stream usage |
|
275 @return TBool ETrue for streaming support |
|
276 @publishedPartner |
|
277 @prototype |
|
278 */ |
|
279 TBool StreamingSupport( TInt& aItemSize ); |
|
280 |
|
281 /** |
|
282 Called when stream returned from UpdateLeafObjectL or ExecuteCommandL has |
|
283 been written to and committed. Not called when fetching item. |
|
284 @publishedPartner |
|
285 @prototype |
|
286 */ |
|
287 #ifdef __TARM_SYMBIAN_CONVERGENCY |
|
288 virtual void StreamCommittedL( RWriteStream& aStream ); |
|
289 #else |
|
290 virtual void StreamCommittedL(); |
|
291 #endif |
|
292 |
|
293 /** |
|
294 The function tells the adapter that all the commands of the message that |
|
295 can be passed to the adapter have now been passed. This indciates that |
|
296 the adapter must supply status codes and results to any buffered commands. |
|
297 This must be done at latest by the time this function returns. |
|
298 This function is used at the end of SyncML messages, and during processing |
|
299 of Atomic. In the case of Atomic processing, the function will be |
|
300 followed by a call to CommitAtomicL or RollbackAtomicL. |
|
301 @publishedPartner |
|
302 @prototype |
|
303 */ |
|
304 void CompleteOutstandingCmdsL() ; |
|
305 |
|
306 private: |
|
307 CPmAdapter(TAny* aEcomArguments); |
|
308 void ConstructL( ); |
|
309 |
|
310 /** |
|
311 * Converts given integer to string, leaving returned |
|
312 * HBufC8 into cleanupstack. |
|
313 */ |
|
314 HBufC8* IntToDes8LC( const TInt aLuid ); |
|
315 |
|
316 /** |
|
317 * Puts given elementid array to aObject |
|
318 */ |
|
319 void ArrayToDMResponseL( const RElementIdArray &aArray, CBufBase &aObject); |
|
320 |
|
321 /** |
|
322 * Finds element matching the mapping, and puts found elementid to aObject, |
|
323 * and succes code to aRet |
|
324 */ |
|
325 void GetElementAndAddToResponseL( const TDesC8 &aParentMapping, |
|
326 CBufBase &aObject, MSmlDmAdapter::TError &aRet ); |
|
327 |
|
328 |
|
329 /** |
|
330 FillNodeInfoL Sets the given node properties to given node. |
|
331 @param aNode The node to be modified |
|
332 @param aAccTypes The SyncML access types to be set to the node. |
|
333 @param aOccurrence The SyncML occurance of the node |
|
334 @param aScope The SyncML scope of the node |
|
335 @param aFormat The SyncML format of the node |
|
336 @param aDescription The description of the node |
|
337 */ |
|
338 void FillNodeInfoL( MSmlDmDDFObject& aNode,TSmlDmAccessTypes aAccTypes, |
|
339 MSmlDmDDFObject::TOccurence aOccurrence, |
|
340 MSmlDmDDFObject::TScope aScope, |
|
341 MSmlDmDDFObject::TDFFormat aFormat, |
|
342 const TDesC8& aDescription); |
|
343 |
|
344 /** |
|
345 GetElementInfoL Finds ID, Description or XACML Data (defined by aType) of |
|
346 the element (defined by aElementId) and puts result into aObject, |
|
347 and operation status to aRet. |
|
348 @param aElementId The element id whose data is to be collected |
|
349 @param aType The tree node name identifying type of data to be found |
|
350 @param aObject The buffer into which the data is put |
|
351 @param aRet The operation status in SML error codes |
|
352 @return Symbian Error code |
|
353 */ |
|
354 TInt GetElementInfoL(const TDesC8 &aElementId, |
|
355 const TDesC8 &mapping /*aType*/, CBufBase* object, TError &ret); |
|
356 |
|
357 /** |
|
358 * SetLastStatusL Helper method to set the last status |
|
359 */ |
|
360 void SetLastStatusL( const TDesC8 &aStatus ); |
|
361 |
|
362 /** |
|
363 * CheckAndAddCertL Reads cert from repository, and adds policy management |
|
364 * trust. |
|
365 */ |
|
366 void CheckAndAddCertL( ); |
|
367 |
|
368 /** |
|
369 * InsertIfFoundL if given policy element is found, places aData in aObject |
|
370 * and returns EOk, otherwise ENotFound or EError |
|
371 */ |
|
372 TError InsertIfFoundL( const TDesC8 &aElementId, const TDesC8& aData, CBufBase &aObject ); |
|
373 private: |
|
374 // The policy engine; |
|
375 RPolicyEngine iEngine ; |
|
376 |
|
377 // The management session |
|
378 RPolicyManagement iManagement ; |
|
379 |
|
380 // are we inside atomic |
|
381 TBool iInAtomic; |
|
382 |
|
383 // holds the commands that have come inside last atomic |
|
384 RPointerArray<CPmCommand> iAtomiced ; |
|
385 |
|
386 // Holds the last policy command status |
|
387 HBufC8 *iLastStatus; |
|
388 }; |
|
389 |
|
390 #endif // __NSMLPMADAPTER_H__ |