os/security/authorisation/userpromptservice/server/source/upsclient/rupsmanagement.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/authorisation/userpromptservice/server/source/upsclient/rupsmanagement.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,304 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* RUpsManagement implementation. See class and function definitions
1.19 +* for more detail.
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +
1.28 +
1.29 +#include <ups/upsclient.h>
1.30 +#include <s32mem.h>
1.31 +
1.32 +#include "upscommon.h"
1.33 +#include <scs/nullstream.h>
1.34 +
1.35 +namespace UserPromptService
1.36 + {
1.37 +EXPORT_C RUpsManagement::RUpsManagement()
1.38 +/**
1.39 + This constructor provides a single point of definition from
1.40 + which the superclass constructor is called.
1.41 + */
1.42 +: RScsClientBase(), iCreateViewFilterBuf(), iMatchLengthBuf()
1.43 + {
1.44 + iMatchLengthBuf() = 0;
1.45 + }
1.46 +
1.47 +EXPORT_C TInt RUpsManagement::Connect()
1.48 +/**
1.49 + Connect to the UPS server.
1.50 +
1.51 + @return Symbian OS error code where KErrNone indicates
1.52 + success and any other value indicates failure.
1.53 + */
1.54 + {
1.55 + TVersion v = UserPromptService::Version();
1.56 + TUidType serverFullUid = UserPromptService::ServerImageFullUid();
1.57 +
1.58 + TInt r = RScsClientBase::Connect(
1.59 + UserPromptService::KUpsServerName, v, UserPromptService::KServerImageName, serverFullUid);
1.60 +
1.61 + return r;
1.62 + }
1.63 +
1.64 +EXPORT_C void RUpsManagement::Close()
1.65 +/**
1.66 +Cleanup and call RScsClientBase::Close
1.67 +*/
1.68 + {
1.69 + RScsClientBase::Close();
1.70 + }
1.71 +
1.72 +EXPORT_C void RUpsManagement::DeleteDatabaseL()
1.73 +/**
1.74 + Deletes all stored UPS decisions.
1.75 +
1.76 + @capability WriteDeviceData
1.77 +*/
1.78 + {
1.79 + User::LeaveIfError(CallSessionFunction(EDeleteDatabase));
1.80 + }
1.81 +
1.82 +EXPORT_C void RUpsManagement::CreateView(const CDecisionFilter& aFilter, TRequestStatus &aStatus)
1.83 +/**
1.84 + Creates a view for records which match the supplied CDecisionFilter.
1.85 +
1.86 + If the CDecisionFilter is created using the constructor which specifies all fields (or all fields are set), then an exact match will be
1.87 + searched for.
1.88 + If the CDecisionFilter is created without parameters, then any fields which are not set will match any record.
1.89 +
1.90 + Only one view can be active in a single RUpsManagement session at any one time.
1.91 +
1.92 + Simultaneous database updates, either from this management session, another session or the main UPS
1.93 + operation may cause the query to be aborted with KErrAbort.
1.94 +
1.95 + When you are finished with the view you should call CancelAndCloseView (otherwise you
1.96 + will not be able to create a new view).
1.97 +
1.98 + @param aFilter Specifies the filter to be matched.
1.99 + @capability ReadDeviceData
1.100 +*/
1.101 +{
1.102 + aStatus = KRequestPending;
1.103 + TRAPD(err,
1.104 + RNullWriteStream nullstream;
1.105 + nullstream << aFilter;
1.106 + nullstream.CommitL();
1.107 + TInt bytesWritten = nullstream.BytesWritten();
1.108 +
1.109 + iCreateViewFilterBuf.Close();
1.110 + iCreateViewFilterBuf.CreateL(bytesWritten);
1.111 +
1.112 + // Arg 0 - The CDecisionFilter
1.113 + // Externalize to iCreateViewFilterBuf
1.114 + RDesWriteStream desstream(iCreateViewFilterBuf);
1.115 + CleanupClosePushL(desstream);
1.116 + desstream << aFilter;
1.117 + desstream.CommitL();
1.118 + CleanupStack::PopAndDestroy(&desstream);
1.119 +
1.120 + // Arg 1 - TUint32 length of first match returned by server
1.121 + // Server writes into iMatchLengthBuf
1.122 + CallSessionFunction(ECreateView, TIpcArgs(&iCreateViewFilterBuf, &iMatchLengthBuf), aStatus);
1.123 + );
1.124 + if(err != KErrNone)
1.125 + {
1.126 + TRequestStatus *rs = &aStatus;
1.127 + User::RequestComplete(rs, err);
1.128 + }
1.129 +}
1.130 +
1.131 +EXPORT_C CDecisionRecord *RUpsManagement::NextMatchL()
1.132 +/**
1.133 + Returns the next matching record in the view created with CreateViewL.
1.134 +
1.135 + Simultaneous database updates, either from this management session, another session or the main UPS
1.136 + operation may cause the query to be aborted with KErrAbort.
1.137 +
1.138 + When you are finished with the view you should call CancelAndCloseView.
1.139 +
1.140 + @return record ptr, or 0 if there are no more matching records. Leaves for other errors.
1.141 +
1.142 + @capability ReadDeviceData
1.143 +*/
1.144 +{
1.145 + if(iMatchLengthBuf() == 0)
1.146 + {
1.147 + return 0; // No more matches
1.148 + }
1.149 +
1.150 + CDecisionRecord *record = CDecisionRecord::NewLC();
1.151 +
1.152 + // Arg 0 - The CDecisionRecord buffer
1.153 + RBuf8 buf;
1.154 + CleanupClosePushL(buf);
1.155 + buf.CreateL(iMatchLengthBuf());
1.156 +
1.157 + // Arg 1 - TUint32 length of next match
1.158 +
1.159 + User::LeaveIfError(CallSessionFunction(ENextMatch, TIpcArgs(&buf, &iMatchLengthBuf)));
1.160 +
1.161 + RDesReadStream readStream(buf);
1.162 + CleanupClosePushL(readStream);
1.163 +
1.164 + readStream >> *record;
1.165 +
1.166 + CleanupStack::PopAndDestroy(&readStream);
1.167 + CleanupStack::PopAndDestroy(&buf);
1.168 + CleanupStack::Pop(record);
1.169 + return record;
1.170 +}
1.171 +
1.172 +EXPORT_C void RUpsManagement::CancelAndCloseView()
1.173 + /**
1.174 + Close down a view. This can also be used to cancel an outstanding CreateView request.
1.175 +
1.176 + @capability ReadDeviceData
1.177 + */
1.178 +{
1.179 + CancelSessionFunction(ECreateView);
1.180 + (void) CallSessionFunction(ECloseView);
1.181 + iCreateViewFilterBuf.Close();
1.182 + iMatchLengthBuf() = 0;
1.183 +}
1.184 +
1.185 +EXPORT_C void RUpsManagement::RemoveDecisionsL(const CDecisionFilter& aFilter)
1.186 +/**
1.187 + Removes all records which match the supplied CDecisionFilter.
1.188 +
1.189 + The filter can match/delete multiple records in one operation.
1.190 +
1.191 + @param aFilter Specifies the records to be deleted.
1.192 +
1.193 + @capability WriteDeviceData
1.194 +*/
1.195 + {
1.196 + // Calculate the buffer length required to represent the filter object
1.197 + RNullWriteStream nullstream;
1.198 + nullstream << aFilter;
1.199 + nullstream.CommitL();
1.200 + TInt bytesWritten = nullstream.BytesWritten();
1.201 +
1.202 + // Create buffer for filter
1.203 + RBuf8 filterBuf;
1.204 + CleanupClosePushL(filterBuf);
1.205 + filterBuf.CreateL(bytesWritten);
1.206 +
1.207 + // Arg 0 - The CDecisionFilter
1.208 + // Externalize to iCreateViewFilterBuf
1.209 + RDesWriteStream desstream(filterBuf);
1.210 + CleanupClosePushL(desstream);
1.211 + desstream << aFilter;
1.212 + desstream.CommitL();
1.213 + CleanupStack::PopAndDestroy(&desstream);
1.214 +
1.215 + User::LeaveIfError(CallSessionFunction(ERemoveDecisions, TIpcArgs(&filterBuf)));
1.216 +
1.217 + CleanupStack::PopAndDestroy(&filterBuf);
1.218 + }
1.219 +
1.220 +EXPORT_C void RUpsManagement::UpdateDecision(TUint32 aRecordId, TBool aAllow, TRequestStatus &aStatus)
1.221 +/**
1.222 + Updates the single record which matches the unique record ID.
1.223 +
1.224 + This API ONLY updates the CDecisionRecord result field. The only legal values are ETrue (always) or EFalse (never)
1.225 +
1.226 + @param aRecordId Specifies the single record to update.
1.227 + @param aAllow Allow or reject the request.
1.228 +
1.229 + @capability AllFiles
1.230 +*/
1.231 + {
1.232 + TIpcArgs args(aRecordId, aAllow);
1.233 + CallSessionFunction(EUpdateDecision, args, aStatus);
1.234 + }
1.235 +
1.236 +EXPORT_C void RUpsManagement::CancelUpdateDecision()
1.237 +/**
1.238 + Cancel an outstanding UpdateDecision request.
1.239 +
1.240 + Normally this will not be used because an UpdateDecision call will complete very quickly, but
1.241 + internally the request is asynchronous and exposing the cancel API allows the cancel code path
1.242 + to be tested.
1.243 +
1.244 + @capability AllFiles
1.245 +*/
1.246 + {
1.247 + CancelSessionFunction(EUpdateDecision);
1.248 + }
1.249 +
1.250 +EXPORT_C void RUpsManagement::DeleteDecisionsForExeL(const TSecureId& aExeSid)
1.251 +/**
1.252 + Delete all decisions in the database for the specified executable.
1.253 +
1.254 + @param aExeSid The SID of the executable which has been deleted.
1.255 +
1.256 + @capability SWI observer plugin SID only
1.257 +*/
1.258 + {
1.259 + User::LeaveIfError(CallSessionFunction(EDeleteDecisionsForExe, TIpcArgs(aExeSid.iId)));
1.260 + }
1.261 +
1.262 +EXPORT_C void RUpsManagement::NotifyPluginsMayHaveChangedL()
1.263 +/**
1.264 + Notify the UPS that an ECOM plugin has been installed somewhere, which may be an evaluator.
1.265 + The UPS will reload all ECOM plugins ASAP.
1.266 +
1.267 + @capability SWI observer plugin SID only
1.268 +*/
1.269 + {
1.270 + User::LeaveIfError(CallSessionFunction(ENotifyPluginsMayHaveChanged));
1.271 + }
1.272 +
1.273 +EXPORT_C void RUpsManagement::NotifyPolicyFilesChanged(TRequestStatus &aStatus)
1.274 +/**
1.275 + Policy files have been added, changed or deleted.
1.276 +
1.277 + The UPS server will rebuild its policy file cache and delete decisions which relate to policy files
1.278 + which are no longer active (ie. have been deleted, or eclipsed by a policy file with a different
1.279 + major version number).
1.280 +
1.281 + @capability SWI observer plugin SID only
1.282 +*/
1.283 + {
1.284 + TIpcArgs args;
1.285 + CallSessionFunction(ENotifyPolicyFilesChanged, args, aStatus);
1.286 +
1.287 + }
1.288 +
1.289 +EXPORT_C void RUpsManagement::CancelNotifyPolicyFilesChanged()
1.290 + /**
1.291 + Cancel a previous call to NotifyPolicyFilesChanged.
1.292 +
1.293 + Normally this functions should not be used, it is only present for testing the handling
1.294 + of abnormal events.
1.295 +
1.296 + @capability SWI observer plugin SID only
1.297 + */
1.298 + {
1.299 + CancelSessionFunction(ENotifyPolicyFilesChanged);
1.300 + }
1.301 +
1.302 +
1.303 +
1.304 +} // End of namespace UserPromptService
1.305 +
1.306 +// End of file
1.307 +