os/security/authorisation/userpromptservice/server/source/upsclient/rupsmanagement.cpp
First public contribution.
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.
15 * RUpsManagement implementation. See class and function definitions
26 #include <ups/upsclient.h>
29 #include "upscommon.h"
30 #include <scs/nullstream.h>
32 namespace UserPromptService
34 EXPORT_C RUpsManagement::RUpsManagement()
36 This constructor provides a single point of definition from
37 which the superclass constructor is called.
39 : RScsClientBase(), iCreateViewFilterBuf(), iMatchLengthBuf()
41 iMatchLengthBuf() = 0;
44 EXPORT_C TInt RUpsManagement::Connect()
46 Connect to the UPS server.
48 @return Symbian OS error code where KErrNone indicates
49 success and any other value indicates failure.
52 TVersion v = UserPromptService::Version();
53 TUidType serverFullUid = UserPromptService::ServerImageFullUid();
55 TInt r = RScsClientBase::Connect(
56 UserPromptService::KUpsServerName, v, UserPromptService::KServerImageName, serverFullUid);
61 EXPORT_C void RUpsManagement::Close()
63 Cleanup and call RScsClientBase::Close
66 RScsClientBase::Close();
69 EXPORT_C void RUpsManagement::DeleteDatabaseL()
71 Deletes all stored UPS decisions.
73 @capability WriteDeviceData
76 User::LeaveIfError(CallSessionFunction(EDeleteDatabase));
79 EXPORT_C void RUpsManagement::CreateView(const CDecisionFilter& aFilter, TRequestStatus &aStatus)
81 Creates a view for records which match the supplied CDecisionFilter.
83 If the CDecisionFilter is created using the constructor which specifies all fields (or all fields are set), then an exact match will be
85 If the CDecisionFilter is created without parameters, then any fields which are not set will match any record.
87 Only one view can be active in a single RUpsManagement session at any one time.
89 Simultaneous database updates, either from this management session, another session or the main UPS
90 operation may cause the query to be aborted with KErrAbort.
92 When you are finished with the view you should call CancelAndCloseView (otherwise you
93 will not be able to create a new view).
95 @param aFilter Specifies the filter to be matched.
96 @capability ReadDeviceData
99 aStatus = KRequestPending;
101 RNullWriteStream nullstream;
102 nullstream << aFilter;
103 nullstream.CommitL();
104 TInt bytesWritten = nullstream.BytesWritten();
106 iCreateViewFilterBuf.Close();
107 iCreateViewFilterBuf.CreateL(bytesWritten);
109 // Arg 0 - The CDecisionFilter
110 // Externalize to iCreateViewFilterBuf
111 RDesWriteStream desstream(iCreateViewFilterBuf);
112 CleanupClosePushL(desstream);
113 desstream << aFilter;
115 CleanupStack::PopAndDestroy(&desstream);
117 // Arg 1 - TUint32 length of first match returned by server
118 // Server writes into iMatchLengthBuf
119 CallSessionFunction(ECreateView, TIpcArgs(&iCreateViewFilterBuf, &iMatchLengthBuf), aStatus);
123 TRequestStatus *rs = &aStatus;
124 User::RequestComplete(rs, err);
128 EXPORT_C CDecisionRecord *RUpsManagement::NextMatchL()
130 Returns the next matching record in the view created with CreateViewL.
132 Simultaneous database updates, either from this management session, another session or the main UPS
133 operation may cause the query to be aborted with KErrAbort.
135 When you are finished with the view you should call CancelAndCloseView.
137 @return record ptr, or 0 if there are no more matching records. Leaves for other errors.
139 @capability ReadDeviceData
142 if(iMatchLengthBuf() == 0)
144 return 0; // No more matches
147 CDecisionRecord *record = CDecisionRecord::NewLC();
149 // Arg 0 - The CDecisionRecord buffer
151 CleanupClosePushL(buf);
152 buf.CreateL(iMatchLengthBuf());
154 // Arg 1 - TUint32 length of next match
156 User::LeaveIfError(CallSessionFunction(ENextMatch, TIpcArgs(&buf, &iMatchLengthBuf)));
158 RDesReadStream readStream(buf);
159 CleanupClosePushL(readStream);
161 readStream >> *record;
163 CleanupStack::PopAndDestroy(&readStream);
164 CleanupStack::PopAndDestroy(&buf);
165 CleanupStack::Pop(record);
169 EXPORT_C void RUpsManagement::CancelAndCloseView()
171 Close down a view. This can also be used to cancel an outstanding CreateView request.
173 @capability ReadDeviceData
176 CancelSessionFunction(ECreateView);
177 (void) CallSessionFunction(ECloseView);
178 iCreateViewFilterBuf.Close();
179 iMatchLengthBuf() = 0;
182 EXPORT_C void RUpsManagement::RemoveDecisionsL(const CDecisionFilter& aFilter)
184 Removes all records which match the supplied CDecisionFilter.
186 The filter can match/delete multiple records in one operation.
188 @param aFilter Specifies the records to be deleted.
190 @capability WriteDeviceData
193 // Calculate the buffer length required to represent the filter object
194 RNullWriteStream nullstream;
195 nullstream << aFilter;
196 nullstream.CommitL();
197 TInt bytesWritten = nullstream.BytesWritten();
199 // Create buffer for filter
201 CleanupClosePushL(filterBuf);
202 filterBuf.CreateL(bytesWritten);
204 // Arg 0 - The CDecisionFilter
205 // Externalize to iCreateViewFilterBuf
206 RDesWriteStream desstream(filterBuf);
207 CleanupClosePushL(desstream);
208 desstream << aFilter;
210 CleanupStack::PopAndDestroy(&desstream);
212 User::LeaveIfError(CallSessionFunction(ERemoveDecisions, TIpcArgs(&filterBuf)));
214 CleanupStack::PopAndDestroy(&filterBuf);
217 EXPORT_C void RUpsManagement::UpdateDecision(TUint32 aRecordId, TBool aAllow, TRequestStatus &aStatus)
219 Updates the single record which matches the unique record ID.
221 This API ONLY updates the CDecisionRecord result field. The only legal values are ETrue (always) or EFalse (never)
223 @param aRecordId Specifies the single record to update.
224 @param aAllow Allow or reject the request.
229 TIpcArgs args(aRecordId, aAllow);
230 CallSessionFunction(EUpdateDecision, args, aStatus);
233 EXPORT_C void RUpsManagement::CancelUpdateDecision()
235 Cancel an outstanding UpdateDecision request.
237 Normally this will not be used because an UpdateDecision call will complete very quickly, but
238 internally the request is asynchronous and exposing the cancel API allows the cancel code path
244 CancelSessionFunction(EUpdateDecision);
247 EXPORT_C void RUpsManagement::DeleteDecisionsForExeL(const TSecureId& aExeSid)
249 Delete all decisions in the database for the specified executable.
251 @param aExeSid The SID of the executable which has been deleted.
253 @capability SWI observer plugin SID only
256 User::LeaveIfError(CallSessionFunction(EDeleteDecisionsForExe, TIpcArgs(aExeSid.iId)));
259 EXPORT_C void RUpsManagement::NotifyPluginsMayHaveChangedL()
261 Notify the UPS that an ECOM plugin has been installed somewhere, which may be an evaluator.
262 The UPS will reload all ECOM plugins ASAP.
264 @capability SWI observer plugin SID only
267 User::LeaveIfError(CallSessionFunction(ENotifyPluginsMayHaveChanged));
270 EXPORT_C void RUpsManagement::NotifyPolicyFilesChanged(TRequestStatus &aStatus)
272 Policy files have been added, changed or deleted.
274 The UPS server will rebuild its policy file cache and delete decisions which relate to policy files
275 which are no longer active (ie. have been deleted, or eclipsed by a policy file with a different
276 major version number).
278 @capability SWI observer plugin SID only
282 CallSessionFunction(ENotifyPolicyFilesChanged, args, aStatus);
286 EXPORT_C void RUpsManagement::CancelNotifyPolicyFilesChanged()
288 Cancel a previous call to NotifyPolicyFilesChanged.
290 Normally this functions should not be used, it is only present for testing the handling
293 @capability SWI observer plugin SID only
296 CancelSessionFunction(ENotifyPolicyFilesChanged);
301 } // End of namespace UserPromptService