cryptoservices/filebasedcertificateandkeystores/source/certapps/server/CCertAppsConduit.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2003-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 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CCertAppsConduit.h"
       
    20 #include "CFSCertAppsServer.h"
       
    21 #include <certificateapps.h>
       
    22 #include "fstokencliserv.h"
       
    23 #include "fstokenutil.h"
       
    24 #include "fsmarshaller.h"
       
    25 
       
    26 _LIT_SECURITY_POLICY_C1(KAddRemovePolicy, ECapabilityWriteDeviceData);
       
    27 
       
    28 CCertAppsConduit* CCertAppsConduit::NewL(CFSCertAppsServer& aServer)
       
    29 	{
       
    30 	CCertAppsConduit* self = new (ELeave) CCertAppsConduit(aServer);
       
    31 	CleanupStack::PushL(self);
       
    32 	self->ConstructL();
       
    33 	CleanupStack::Pop(self);
       
    34 	return self;
       
    35 	}
       
    36 
       
    37 CCertAppsConduit::CCertAppsConduit(CFSCertAppsServer& aServer) :
       
    38 	iServer(aServer)
       
    39 	{
       
    40 	}
       
    41 
       
    42 void CCertAppsConduit::ConstructL()
       
    43 	{
       
    44 	}
       
    45 
       
    46 CCertAppsConduit::~CCertAppsConduit()
       
    47 	{
       
    48 	}
       
    49 
       
    50 void CCertAppsConduit::ServiceCertAppsRequestL(const RMessage2& aMessage)
       
    51 	{
       
    52 	switch(aMessage.Function())
       
    53 		{
       
    54 		case EAddApp:
       
    55 			AddL(aMessage);
       
    56 			break;
       
    57 
       
    58 		case ERemoveApp:
       
    59 			RemoveL(aMessage);
       
    60 			break;
       
    61 
       
    62 		case EGetAppCount:
       
    63 			ApplicationCountL(aMessage);
       
    64 			break;
       
    65 
       
    66 		case EGetApps:
       
    67 			ApplicationsL(aMessage);
       
    68 			break;
       
    69 
       
    70 		case EGetApplication:
       
    71 			ApplicationL(aMessage);
       
    72 			break;
       
    73 
       
    74 		default:
       
    75 			// Client made an illegal request
       
    76 			PanicClient(aMessage, EPanicInvalidRequest);
       
    77 		}
       
    78 	
       
    79 	aMessage.Complete(KErrNone);
       
    80 	}
       
    81 
       
    82 void CCertAppsConduit::AddL(const RMessage2& aMessage) const
       
    83 	{
       
    84 	// Add message is composed of the following structure
       
    85 	// Parameter 1 - TPckg<TCertificateAppInfo>
       
    86 
       
    87 	// Check the calling process has the correct capabilities
       
    88 	if (!KAddRemovePolicy.CheckPolicy(aMessage))
       
    89 		{
       
    90 		User::Leave(KErrPermissionDenied);
       
    91 		}
       
    92 
       
    93 	TCertificateAppInfo appInfo;
       
    94 	TPckg<TCertificateAppInfo> pckg(appInfo);
       
    95 	aMessage.ReadL(1, pckg);
       
    96 
       
    97 	// Now that we have extracted the appInfo, we can call the
       
    98 	// real server
       
    99 	iServer.AddL(appInfo);
       
   100 	}
       
   101 
       
   102 void CCertAppsConduit::RemoveL(const RMessage2& aMessage) const
       
   103 	{
       
   104 	// Remove message is composed of a single TPckg<TUid>
       
   105 
       
   106 	// Check the calling process has the correct capabilities
       
   107 	if (!KAddRemovePolicy.CheckPolicy(aMessage))
       
   108 		{
       
   109 		User::Leave(KErrPermissionDenied);
       
   110 		}
       
   111 
       
   112 	TUid uid;
       
   113 	TPckg<TUid> pckg(uid);
       
   114 	aMessage.ReadL(1, pckg);
       
   115 	iServer.RemoveL(uid);
       
   116 	}
       
   117 
       
   118 void CCertAppsConduit::ApplicationCountL(const RMessage2& aMessage) const
       
   119 	{
       
   120 	// This message contains a single output descriptor of type
       
   121 	// TPckg<TInt>
       
   122 	TInt appCount = iServer.ApplicationCountL();
       
   123 	aMessage.WriteL(1, TPckg<TInt>(appCount));
       
   124 	}
       
   125 
       
   126 void CCertAppsConduit::ApplicationsL(const RMessage2& aMessage) const
       
   127 	{
       
   128 	// This message contains the following parameters:
       
   129 	// Param1: [IN] TInt - maximum buffer length allowed
       
   130 	// Param2: [OUT] TDes8 - The buffer to write into; if buffer size too
       
   131 	//               small then will return KErrOverflow with param 2 being 
       
   132 	//               required size
       
   133 
       
   134 	// Firstly, the maximum allowable length of the buffer
       
   135 	
       
   136 	// now get the array to be transmitted
       
   137 	RArray<TCertificateAppInfo> arr;
       
   138 	CleanupClosePushL(arr);
       
   139 
       
   140 	// retrieve the array and marshall them into the message
       
   141 	iServer.ApplicationsL(arr);
       
   142 
       
   143 	TInt reqdSize = TokenDataMarshaller::Size(arr);
       
   144 	TInt bufLen = User::LeaveIfError(aMessage.GetDesLength(2));
       
   145 
       
   146 	if (reqdSize <= bufLen)
       
   147 		{
       
   148 		HBufC8* buf = HBufC8::NewMaxLC(reqdSize);
       
   149 		TPtr8 ptr(buf->Des());
       
   150 		TokenDataMarshaller::Write(arr, ptr);
       
   151 		aMessage.WriteL(2, ptr);
       
   152 		CleanupStack::PopAndDestroy(buf);
       
   153 		}
       
   154 	else
       
   155 		{
       
   156 		aMessage.WriteL(2, TPckg<TInt>(reqdSize));
       
   157 		User::Leave(KErrOverflow);
       
   158 		}
       
   159 
       
   160 	CleanupStack::PopAndDestroy(&arr);
       
   161 	}
       
   162 
       
   163 void CCertAppsConduit::ApplicationL(const RMessage2& aMessage) const
       
   164 	{
       
   165 	// The parameters for the ApplicationL function are as follows:
       
   166 	// Param1: [IN] TUid - The Uid of the app to retrieve
       
   167 	// Param2: [OUT] TCertificateAppInfo - The app info returned
       
   168 
       
   169 	// Read the UID first
       
   170 	TUid uid;
       
   171 	TPckg<TUid> pckgUid(uid);
       
   172 	aMessage.ReadL(1, pckgUid);
       
   173 
       
   174 	// Now call the server
       
   175 	TCertificateAppInfo appInfo;
       
   176 	iServer.ApplicationL(uid, appInfo);
       
   177 
       
   178 	// Now wrap the returned parameters into packages
       
   179 	aMessage.WriteL(2, TPckg<TCertificateAppInfo>(appInfo));
       
   180 	}