Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Parsing of capability names
27 // This file needs to be updated in three places whenever new capabilities are
28 // added - the list of capability names below and the methods
29 // Input::ParseCapabilityNameL and Output::writeCapabilityL.
32 _LIT8(KCapabilityTCB, "TCB");
33 _LIT8(KCapabilityCommDD, "CommDD");
34 _LIT8(KCapabilityPowerMgmt, "PowerMgmt");
35 _LIT8(KCapabilityMultimediaDD, "MultimediaDD");
36 _LIT8(KCapabilityReadDeviceData, "ReadDeviceData");
37 _LIT8(KCapabilityWriteDeviceData, "WriteDeviceData");
38 _LIT8(KCapabilityDRM, "DRM");
39 _LIT8(KCapabilityTrustedUI, "TrustedUI");
40 _LIT8(KCapabilityProtServ, "ProtServ");
41 _LIT8(KCapabilityDiskAdmin, "DiskAdmin");
42 _LIT8(KCapabilityNetworkControl, "NetworkControl");
43 _LIT8(KCapabilityAllFiles, "AllFiles");
44 _LIT8(KCapabilitySwEvent, "SwEvent");
45 _LIT8(KCapabilityNetworkServices, "NetworkServices");
46 _LIT8(KCapabilityLocalServices, "LocalServices");
47 _LIT8(KCapabilityReadUserData, "ReadUserData");
48 _LIT8(KCapabilityWriteUserData, "WriteUserData");
49 _LIT8(KCapabilityLocation, "Location");
50 _LIT8(KCapabilitySurroundingsDD, "SurroundingsDD");
51 _LIT8(KCapabilityUserEnvironment, "UserEnvironment");
54 _LIT8(KCapabilityStart, "<capability>");
55 _LIT8(KCapabilityEnd, "</capability>");
56 _LIT8(KPolicyPass, "<pass/>");
57 _LIT8(KPolicyFail, "<fail/>");
58 _LIT8(KSecureIdStart, "<secureid>");
59 _LIT8(KSecureIdEnd, "</secureid>");
60 _LIT8(KVendorIdStart, "<vendorid>");
61 _LIT8(KVendorIdEnd, "</vendorid>");
63 _LIT(KCommaSpace, ", ");
65 EXPORT_C TCapability Input::ParseCapabilityNameL(const TDesC8& aName)
67 TCapability result = ECapability_None;
69 if (aName == KCapabilityTCB) result = ECapabilityTCB;
70 else if (aName == KCapabilityCommDD) result = ECapabilityCommDD;
71 else if (aName == KCapabilityPowerMgmt) result = ECapabilityPowerMgmt;
72 else if (aName == KCapabilityMultimediaDD) result = ECapabilityMultimediaDD;
73 else if (aName == KCapabilityReadDeviceData) result = ECapabilityReadDeviceData;
74 else if (aName == KCapabilityWriteDeviceData) result = ECapabilityWriteDeviceData;
75 else if (aName == KCapabilityDRM) result = ECapabilityDRM;
76 else if (aName == KCapabilityTrustedUI) result = ECapabilityTrustedUI;
77 else if (aName == KCapabilityProtServ) result = ECapabilityProtServ;
78 else if (aName == KCapabilityDiskAdmin) result = ECapabilityDiskAdmin;
79 else if (aName == KCapabilityNetworkControl) result = ECapabilityNetworkControl;
80 else if (aName == KCapabilityAllFiles) result = ECapabilityAllFiles;
81 else if (aName == KCapabilitySwEvent) result = ECapabilitySwEvent;
82 else if (aName == KCapabilityNetworkServices) result = ECapabilityNetworkServices;
83 else if (aName == KCapabilityLocalServices) result = ECapabilityLocalServices;
84 else if (aName == KCapabilityReadUserData) result = ECapabilityReadUserData;
85 else if (aName == KCapabilityWriteUserData) result = ECapabilityWriteUserData;
86 else if (aName == KCapabilityLocation) result = ECapabilityLocation;
87 else if (aName == KCapabilitySurroundingsDD) result = ECapabilitySurroundingsDD;
88 else if (aName == KCapabilityUserEnvironment) result = ECapabilityUserEnvironment;
90 if (result == ECapability_None)
92 User::Leave(KErrArgument);
98 EXPORT_C void Input::ParseCapabilitySetL(const TDesC8& aIn, TCapabilitySet& aOut)
101 TInt pos = 0, err = KErrNone;
104 const TDesC8& match = Input::ParseElement(aIn, KCapabilityStart, KCapabilityEnd, pos, err);
109 aOut.AddCapability(ParseCapabilityNameL(match));
111 if (err != KErrNone && err != KErrNotFound)
117 EXPORT_C void Input::ParseSecurityPolicyL(const TDesC8& aIn, TSecurityPolicy& aOut)
121 TBool pass = aIn.Find(KPolicyPass) != KErrNotFound; // why didn't we use a proper xml parser?
124 TBool fail = aIn.Find(KPolicyFail) != KErrNotFound;
127 TUint secureId = ParseIntElement(aIn, KSecureIdStart, KSecureIdEnd);
128 if (secureId) ++options;
130 TUint vendorId = ParseIntElement(aIn, KVendorIdStart, KVendorIdEnd);
131 if (vendorId) ++options;
133 // Can only sepcify one of pass, fail, secureid, vendorid
135 User::Leave(KErrArgument);
137 // Parse the capabilities
138 TCapabilitySet capSet;
139 ParseCapabilitySetL(aIn, capSet);
141 // Determine maximum number of capabilities allowed
147 else if (secureId || vendorId)
159 // Extract capabilities into array
161 for (i = 0 ; i < ECapability_Limit ; ++i)
163 TCapability c = static_cast<TCapability>(i);
164 if (capSet.HasCapability(c))
166 // Check if more capabities are specified that allowed
167 if (count == maxCaps)
169 User::Leave(KErrArgument);
175 // Fill the rest of the array with ECapability_None
176 for (i = count ; i < maxCaps ; ++i)
178 caps[i] = ECapability_None;
183 aOut = TSecurityPolicy(TSecurityPolicy::EAlwaysPass);
187 aOut = TSecurityPolicy(TSecurityPolicy::EAlwaysFail);
191 aOut = TSecurityPolicy(TSecureId(secureId), caps[0], caps[1], caps[2]);
195 aOut = TSecurityPolicy(TVendorId(vendorId), caps[0], caps[1], caps[2]);
199 aOut = TSecurityPolicy(caps[0], caps[1], caps[2], caps[3],
200 caps[4], caps[5], caps[6]);
204 EXPORT_C void Output::writeCapabilityL(TCapability aCap)
209 writeString(KCapabilityTCB);
212 case ECapabilityCommDD:
213 writeString(KCapabilityCommDD);
216 case ECapabilityPowerMgmt:
217 writeString(KCapabilityPowerMgmt);
220 case ECapabilityMultimediaDD:
221 writeString(KCapabilityMultimediaDD);
224 case ECapabilityReadDeviceData:
225 writeString(KCapabilityReadDeviceData);
228 case ECapabilityWriteDeviceData:
229 writeString(KCapabilityWriteDeviceData);
233 writeString(KCapabilityDRM);
236 case ECapabilityTrustedUI:
237 writeString(KCapabilityTrustedUI);
240 case ECapabilityProtServ:
241 writeString(KCapabilityProtServ);
244 case ECapabilityDiskAdmin:
245 writeString(KCapabilityDiskAdmin);
248 case ECapabilityNetworkControl:
249 writeString(KCapabilityNetworkControl);
252 case ECapabilityAllFiles:
253 writeString(KCapabilityAllFiles);
256 case ECapabilitySwEvent:
257 writeString(KCapabilitySwEvent);
260 case ECapabilityNetworkServices:
261 writeString(KCapabilityNetworkServices);
264 case ECapabilityLocalServices:
265 writeString(KCapabilityLocalServices);
268 case ECapabilityReadUserData:
269 writeString(KCapabilityReadUserData);
272 case ECapabilityWriteUserData:
273 writeString(KCapabilityWriteUserData);
276 case ECapabilityLocation:
277 writeString(KCapabilityLocation);
280 case ECapabilitySurroundingsDD:
281 writeString(KCapabilitySurroundingsDD);
284 case ECapabilityUserEnvironment:
285 writeString(KCapabilityUserEnvironment);
293 EXPORT_C void Output::writeCapabilitySetL(const TCapabilitySet& aCaps)
296 for (TInt i = 0 ; i < ECapability_Limit ; ++i)
298 TCapability cap = static_cast<TCapability>(i);
299 if (aCaps.HasCapability(cap))
303 writeString(KCommaSpace);
309 writeCapabilityL(cap);
315 * The real TSecurityPolicy class has no accessors, so to extract information
316 * from it we cast it to this class, which has exactly the same layout.
318 class TPrintableSecurityPolicy
321 void WriteL(Output& aOut) const;
326 ETypeFail=0, // Always fail
327 ETypePass=1, // Always pass
328 ETypeC3=2, // Up to 3 capabilities
329 ETypeC7=3, // Up to 7 capabilities
330 ETypeS3=4, // SID + up to 3 capabilities
331 ETypeV3=5, // VID + up to 3 capabilities
337 TPrintableSecurityPolicy();
338 TBool WriteCapsL(Output& aOut, TBool aFirst) const;
339 void WriteExtraCapsL(Output& aOut, TBool aFirst) const;
343 TUint8 iCaps[3]; // missing capabilities are set to 0xff
348 TUint8 iExtraCaps[4]; // missing capabilities are set to 0xff
352 // Check noone added another type to the enumeration
353 __ASSERT_COMPILE(((TInt)TPrintableSecurityPolicy::ETypeLimit) == ((TInt)TSecurityPolicy::ETypeLimit));
355 EXPORT_C void Output::writeSecurityPolicyL(const TSecurityPolicy& aPolicy)
357 const TPrintableSecurityPolicy* p = reinterpret_cast<const TPrintableSecurityPolicy*>(&aPolicy);
361 void TPrintableSecurityPolicy::WriteL(Output& aOut) const
366 aOut.writeString(_L("AlwaysFail"));
369 aOut.writeString(_L("AlwaysPass"));
372 WriteCapsL(aOut, ETrue);
376 TBool first = WriteCapsL(aOut, ETrue);
377 WriteExtraCapsL(aOut, first);
381 aOut.writeString(_L("SID 0x"));
382 aOut.writeHex(iSecureId);
383 WriteCapsL(aOut, EFalse);
386 aOut.writeString(_L("VID 0x"));
387 aOut.writeHex(iVendorId);
388 WriteCapsL(aOut, EFalse);
395 TBool TPrintableSecurityPolicy::WriteCapsL(Output& aOut, TBool aFirst) const
397 for (TInt i = 0 ; i < 3 ; ++i)
399 if (iCaps[i] != 0xff)
403 aOut.writeString(KCommaSpace);
406 aOut.writeCapabilityL((TCapability) iCaps[i]);
412 void TPrintableSecurityPolicy::WriteExtraCapsL(Output& aOut, TBool aFirst) const
414 for (TInt i = 0 ; i < 3 ; ++i)
416 if (iExtraCaps[i] != 0xff)
420 aOut.writeString(KCommaSpace);
423 aOut.writeCapabilityL((TCapability) iExtraCaps[i]);