os/security/authorisation/userpromptservice/server/source/upsclient/rupsmanagement.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-2009 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 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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * RUpsManagement implementation.	 See class and function definitions
    16 * for more detail.
    17 *
    18 */
    19 
    20 
    21 /**
    22  @file
    23 */
    24 
    25 
    26 #include <ups/upsclient.h>
    27 #include <s32mem.h>
    28 
    29 #include "upscommon.h"
    30 #include <scs/nullstream.h>
    31 
    32 namespace UserPromptService
    33 	{
    34 EXPORT_C RUpsManagement::RUpsManagement()
    35 /**
    36 	This constructor provides a single point of definition from
    37 	which the superclass constructor is called.
    38  */
    39 :	RScsClientBase(), iCreateViewFilterBuf(), iMatchLengthBuf()
    40 	{
    41 	iMatchLengthBuf() = 0;
    42 	}
    43 
    44 EXPORT_C TInt RUpsManagement::Connect()
    45 /**
    46 	Connect to the UPS server.
    47 
    48 	@return					Symbian OS error code where KErrNone indicates
    49 							success and any other value indicates failure.
    50  */
    51 	{
    52 	TVersion v = UserPromptService::Version();
    53 	TUidType serverFullUid = UserPromptService::ServerImageFullUid();
    54 
    55 	TInt r = RScsClientBase::Connect(
    56 		UserPromptService::KUpsServerName, v, UserPromptService::KServerImageName, serverFullUid);
    57 	
    58 	return r;
    59 	}
    60 	
    61 EXPORT_C void RUpsManagement::Close()
    62 /**
    63 Cleanup and call RScsClientBase::Close
    64 */
    65 	{
    66 	RScsClientBase::Close();
    67 	}
    68 
    69 EXPORT_C void RUpsManagement::DeleteDatabaseL()
    70 /**
    71 	Deletes all stored UPS decisions.
    72 
    73 	@capability WriteDeviceData 
    74 */
    75 	{
    76 	User::LeaveIfError(CallSessionFunction(EDeleteDatabase));
    77 	}
    78 
    79 EXPORT_C void RUpsManagement::CreateView(const CDecisionFilter& aFilter, TRequestStatus &aStatus)
    80 /**
    81 	Creates a view for records which match the supplied CDecisionFilter.
    82 
    83 	If the CDecisionFilter is created using the constructor which specifies all fields (or all fields are set), then an exact match will be
    84 	searched for.
    85 	If the CDecisionFilter is created without parameters, then any fields which are not set will match any record.
    86 
    87 	Only one view can be active in a single RUpsManagement session at any one time.
    88 
    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.
    91 
    92 	When you are finished with the view you should call CancelAndCloseView (otherwise you
    93 	will not be able to create a new view).
    94 
    95 	@param aFilter	Specifies the filter to be matched.
    96 	@capability ReadDeviceData 
    97 */
    98 {
    99 	aStatus = KRequestPending;
   100 	TRAPD(err,
   101 		RNullWriteStream nullstream;
   102 		nullstream << aFilter;
   103 		nullstream.CommitL();
   104 		TInt bytesWritten = nullstream.BytesWritten();
   105 
   106 		iCreateViewFilterBuf.Close();
   107 		iCreateViewFilterBuf.CreateL(bytesWritten);
   108 
   109 		// Arg 0 - The CDecisionFilter
   110 		// Externalize to iCreateViewFilterBuf
   111 		RDesWriteStream desstream(iCreateViewFilterBuf);
   112 		CleanupClosePushL(desstream);
   113 		desstream << aFilter;
   114 		desstream.CommitL();
   115 		CleanupStack::PopAndDestroy(&desstream);
   116 
   117 		// Arg 1 - TUint32 length of first match returned by server
   118 		// Server writes into iMatchLengthBuf
   119 		CallSessionFunction(ECreateView, TIpcArgs(&iCreateViewFilterBuf, &iMatchLengthBuf), aStatus);
   120 		);
   121 	if(err != KErrNone)
   122 		{
   123 		TRequestStatus *rs = &aStatus;
   124 		User::RequestComplete(rs, err);
   125 		}
   126 }
   127 
   128 EXPORT_C CDecisionRecord *RUpsManagement::NextMatchL()
   129 /**
   130 	Returns the next matching record in the view created with CreateViewL.
   131 
   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.
   134 
   135 	When you are finished with the view you should call CancelAndCloseView.
   136 
   137 	@return record ptr, or 0 if there are no more matching records. Leaves for other errors.
   138 
   139 	@capability ReadDeviceData 
   140 */
   141 {
   142 	if(iMatchLengthBuf() == 0)
   143 		{
   144 		return 0; // No more matches
   145 		}
   146 
   147 	CDecisionRecord *record = CDecisionRecord::NewLC();
   148 
   149 	// Arg 0 - The CDecisionRecord buffer
   150 	RBuf8 buf;
   151 	CleanupClosePushL(buf);
   152 	buf.CreateL(iMatchLengthBuf());
   153 
   154 	// Arg 1 - TUint32 length of next match
   155 
   156 	User::LeaveIfError(CallSessionFunction(ENextMatch, TIpcArgs(&buf, &iMatchLengthBuf)));
   157 
   158 	RDesReadStream readStream(buf);
   159 	CleanupClosePushL(readStream);
   160 
   161 	readStream >> *record;
   162 
   163 	CleanupStack::PopAndDestroy(&readStream);
   164 	CleanupStack::PopAndDestroy(&buf);
   165 	CleanupStack::Pop(record);
   166 	return record;
   167 }
   168 
   169 EXPORT_C void RUpsManagement::CancelAndCloseView()
   170 	/**
   171 	Close down a view. This can also be used to cancel an outstanding CreateView request.
   172 
   173 	@capability ReadDeviceData 
   174 	*/
   175 {
   176 	CancelSessionFunction(ECreateView);
   177 	(void) CallSessionFunction(ECloseView);
   178 	iCreateViewFilterBuf.Close();
   179 	iMatchLengthBuf() = 0;
   180 }
   181 
   182 EXPORT_C void RUpsManagement::RemoveDecisionsL(const CDecisionFilter& aFilter)
   183 /**
   184 	Removes all records which match the supplied CDecisionFilter.
   185 
   186 	The filter can match/delete multiple records in one operation.
   187 	
   188 	@param aFilter	Specifies the records to be deleted.
   189 
   190 	@capability WriteDeviceData 
   191 */
   192 	{
   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();
   198 
   199 	// Create buffer for filter
   200 	RBuf8 filterBuf;
   201 	CleanupClosePushL(filterBuf);
   202 	filterBuf.CreateL(bytesWritten);
   203 
   204 	// Arg 0 - The CDecisionFilter
   205 	// Externalize to iCreateViewFilterBuf
   206 	RDesWriteStream desstream(filterBuf);
   207 	CleanupClosePushL(desstream);
   208 	desstream << aFilter;
   209 	desstream.CommitL();
   210 	CleanupStack::PopAndDestroy(&desstream);
   211 
   212 	User::LeaveIfError(CallSessionFunction(ERemoveDecisions, TIpcArgs(&filterBuf)));
   213 
   214 	CleanupStack::PopAndDestroy(&filterBuf);
   215 	}
   216 
   217 EXPORT_C void RUpsManagement::UpdateDecision(TUint32 aRecordId, TBool aAllow, TRequestStatus &aStatus)
   218 /**
   219 	Updates the single record which matches the unique record ID.
   220 
   221 	This API ONLY updates the CDecisionRecord result field. The only legal values are ETrue (always) or EFalse (never)
   222 	
   223 	@param aRecordId	Specifies the single record to update.
   224 	@param aAllow		Allow or reject the request.
   225 	
   226 	@capability AllFiles 
   227 */
   228 	{
   229 	TIpcArgs args(aRecordId, aAllow);
   230 	CallSessionFunction(EUpdateDecision, args, aStatus);
   231 	}
   232 
   233 EXPORT_C void RUpsManagement::CancelUpdateDecision()
   234 /**
   235 	Cancel an outstanding UpdateDecision request.
   236 	
   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
   239 	to be tested.
   240 
   241 	@capability AllFiles 
   242 */
   243 	{
   244 	CancelSessionFunction(EUpdateDecision);
   245 	}
   246 
   247 EXPORT_C void RUpsManagement::DeleteDecisionsForExeL(const TSecureId& aExeSid)
   248 /**
   249 	Delete all decisions in the database for the specified executable.
   250 
   251 	@param aExeSid	The SID of the executable which has been deleted.
   252 
   253 	@capability SWI observer plugin SID only
   254 */
   255 	{
   256 	User::LeaveIfError(CallSessionFunction(EDeleteDecisionsForExe, TIpcArgs(aExeSid.iId)));
   257 	}
   258 
   259 EXPORT_C void RUpsManagement::NotifyPluginsMayHaveChangedL()
   260 /**
   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.
   263 
   264 	@capability SWI observer plugin SID only
   265 */
   266 	{
   267 	User::LeaveIfError(CallSessionFunction(ENotifyPluginsMayHaveChanged));
   268 	}
   269 
   270 EXPORT_C void RUpsManagement::NotifyPolicyFilesChanged(TRequestStatus &aStatus)
   271 /**
   272 	Policy files have been added, changed or deleted.
   273 
   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).
   277 
   278 	@capability SWI observer plugin SID only
   279 */
   280 	{
   281 	TIpcArgs args;
   282 	CallSessionFunction(ENotifyPolicyFilesChanged, args, aStatus);
   283 
   284 	}
   285 
   286 EXPORT_C void RUpsManagement::CancelNotifyPolicyFilesChanged()
   287 	/**
   288 	Cancel a previous call to NotifyPolicyFilesChanged.
   289 
   290 	Normally this functions should not be used, it is only present for testing the handling
   291 	of abnormal events.
   292 
   293 	@capability SWI observer plugin SID only
   294 	*/
   295 	{
   296 	CancelSessionFunction(ENotifyPolicyFilesChanged);
   297 	}
   298 
   299 
   300 
   301 } // End of namespace UserPromptService
   302 
   303 // End of file
   304