Update contrib.
2 * Copyright (c) 2007-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.
19 #include "policylist.h"
20 #include "policyreader.h"
21 #include "promptrequest.h"
23 #include <ups/upserr.h>
26 using namespace UserPromptService;
28 // CPolicyList::TId ----------------------------------------------------------
29 EXPORT_C CPolicyList::TId::TId()
33 : iServerSid(), iServiceId(TUid::Null())
37 EXPORT_C CPolicyList::TId::TId(const TSecureId& aServerSid, const TServiceId& aServiceId)
40 @param aServerSid The secure id of the system server
41 @param aServiceId The UID of the service.
43 : iServerSid(aServerSid), iServiceId(aServiceId)
47 EXPORT_C TBool CPolicyList::TId::operator==(const CPolicyList::TId& aId) const
49 Tests whether this policy list id is euivalent to another policy list id.
51 @param aId The policy list id object to compare this object against.
52 @return ETrue if the system server secure id and the service UID match;
53 otherwise, EFalse is returned.
56 return (iServerSid == aId.iServerSid && iServiceId == aId.iServiceId);
59 EXPORT_C void CPolicyList::TId::IdL(const TDesC& aPolicyFile, CPolicyList::TId& aId)
61 Determines the policy list id from the name of the policy file.
62 @param aPolicyFile The filename of the policy file.
63 @param aId The id object to populate.
65 @leave KErrUpsInvalidPolicyFileName if the policy file is not in the correct format.
68 TParse* p = new (ELeave) TParse();
69 CleanupStack::PushL(p);
72 if ((err = p->Set(aPolicyFile, NULL, NULL)) == KErrNone)
74 TPtrC n = p->NameAndExt();
75 _LIT(KPolicyFilePattern, "ups_????????_????????.rsc");
77 if (n.MatchF(KPolicyFilePattern) != KErrNotFound)
81 if ((err = l.Val(serverSid, EHex)) == KErrNone)
85 if ((err = l.Val(serviceId, EHex)) == KErrNone)
87 aId.iServerSid = TSecureId(serverSid);
88 aId.iServiceId = TServiceId::Uid(serviceId);
96 User::Leave(KErrUpsInvalidPolicyFileName);
99 CleanupStack::PopAndDestroy(p);
102 EXPORT_C void CPolicyList::TId::AppendNameToPath(TDes& aFileName) const
104 _LIT(KPolicyFileNameFormat, "ups_%08x_%08x.rsc");
105 aFileName.AppendFormat(KPolicyFileNameFormat, iServerSid.iId, iServiceId.iUid);
108 // CPolicyList ---------------------------------------------------------------
109 EXPORT_C CPolicyList* CPolicyList::NewL(const CPolicyList::TId& aId, CPolicyReader& aReader)
111 Factory method for creating policy list objects.
112 @param aId The id (system server SID and service id) of the UPS policy file.
113 @param aReader The policy file resource parser.
114 @return A pointer to the new policy list.
117 CPolicyList* self = CPolicyList::NewLC(aId, aReader);
118 CleanupStack::Pop(self);
122 EXPORT_C CPolicyList* CPolicyList::NewLC(const CPolicyList::TId& aId, CPolicyReader& aReader)
124 Factory method for policy list objects. A pointer to the new policy list object is placed
125 on the cleanup stack.
127 @param aId The id (system server SID and service id) of the UPS policy file.
128 @param aReader The policy file resource parser.
129 @return A pointer to the new policy list.
132 CPolicyList* self = new(ELeave) CPolicyList(aId);
133 CleanupStack::PushL(self);
134 self->ConstructL(aReader);
138 CPolicyList::CPolicyList(const CPolicyList::TId& aId) : iId(aId)
141 @param aId The ID of the UPS policy list file.
146 CPolicyList::~CPolicyList()
151 delete iDefaultPolicy;
152 iPolicies.ResetAndDestroy();
155 void CPolicyList::ConstructL(CPolicyReader& aReader)
157 Second phase constructor that reads all policies in the policy file.
158 @param aReader The policy reader instance.
161 const TPolicyHeader& hdr = aReader.Header();
162 iServiceConfig.iServiceId = iId.iServiceId.iUid;
163 iServiceConfig.iPolicy = hdr.iAuthPolicy;
164 iServiceConfig.iMajorVersion = hdr.iMajorVersion;
165 iServiceConfig.iMinorVersion = hdr.iMinorVersion;
168 while ((p = aReader.NextPolicyL()) != 0)
170 CleanupStack::PushL(p);
171 iPolicies.AppendL(p);
172 CleanupStack::Pop(p);
175 iDefaultPolicy = aReader.DefaultPolicyL();
178 EXPORT_C const CPolicy* CPolicyList::Match(const CPromptRequest& aRequest) const
180 Tests each policy in the list in turn and returns the first matching policy. If no match
181 is found then a 'default' policy object is returned.
183 @param aRequest The request to match against the policies.
184 @return A pointer to the policy object to use for the request.
187 TInt n = iPolicies.Count();
189 for (TInt i = 0; i < n; ++i)
191 if (iPolicies[i]->Matches(aRequest.ClientSid(), aRequest.Destination(), aRequest.SecurityResult()))
194 DEBUG_PRINTF5(_L8("Using policy %d for client sid = 0x%08x, system server sid = 0x%08x, service id = 0x%08x"),
195 i, aRequest.ClientSid().iId, aRequest.ServerSid().iId, aRequest.ServiceId().iUid);
202 DEBUG_PRINTF4(_L8("Using default policy for client sid = 0x%08x, system server sid = 0x%08x, service id = 0x%08x"),
203 aRequest.ClientSid().iId, aRequest.ServerSid().iId, aRequest.ServiceId().iUid);
209 EXPORT_C const CPolicyList::TId& CPolicyList::Id() const
211 Gets the ID that associates a list of policies with a system server SID and service ID.
212 @return The ID of the policy list.
218 EXPORT_C const TServiceConfig& CPolicyList::ServiceConfig() const
220 Gets the service configuration information for this policy file. This is used
221 by the UPS system-server API to determine whether or not to invoke the UPS.
222 @return A const reference to the service configuration information.
225 return iServiceConfig;