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