rtsecuritymanager/rtsecuritymanagerutil/src/rtsecmgrmsg.cpp
changeset 57 61b27eec6533
parent 45 7aa6007702af
equal deleted inserted replaced
45:7aa6007702af 57:61b27eec6533
     1 /*
       
     2 * Copyright (c) 2007-2008 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:       Defines rtsecmgr common client server message types
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #include "rtsecmgrmsg.h"
       
    25 
       
    26 CRTSecMgrRegisterScriptMsg::CRTSecMgrRegisterScriptMsg(TPolicyID aPolicyID) :
       
    27 	iPolicyID(aPolicyID)
       
    28 	{
       
    29 	// No implementation required
       
    30 	}
       
    31 
       
    32 EXPORT_C CRTSecMgrRegisterScriptMsg::~CRTSecMgrRegisterScriptMsg()
       
    33 	{
       
    34 	if ( iHashMarker)
       
    35 		{
       
    36 		delete iHashMarker;
       
    37 		}
       
    38 	}
       
    39 
       
    40 EXPORT_C CRTSecMgrRegisterScriptMsg* CRTSecMgrRegisterScriptMsg::NewLC(
       
    41 		TPolicyID aPolicyID, const TDesC& aHashValue)
       
    42 	{
       
    43 	CRTSecMgrRegisterScriptMsg* self = new (ELeave)CRTSecMgrRegisterScriptMsg(aPolicyID);
       
    44 	CleanupStack::PushL (self);
       
    45 	self->ConstructL (aHashValue);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 EXPORT_C CRTSecMgrRegisterScriptMsg* CRTSecMgrRegisterScriptMsg::NewL(
       
    50 		TPolicyID aPolicyID, const TDesC& aHashValue)
       
    51 	{
       
    52 	CRTSecMgrRegisterScriptMsg* self=CRTSecMgrRegisterScriptMsg::NewLC (
       
    53 			aPolicyID, aHashValue);
       
    54 	CleanupStack::Pop (self); // self;
       
    55 	return self;
       
    56 	}
       
    57 
       
    58 // Creates a CRTSecMgrRegisterScriptMsg initialized with the contents of the
       
    59 // descriptor parameter
       
    60 EXPORT_C CRTSecMgrRegisterScriptMsg* CRTSecMgrRegisterScriptMsg::NewLC(const TDesC8& aStreamData)
       
    61 	{
       
    62 	// Reads descriptor data from a stream
       
    63 	// and creates a new CRTSecMgrRegisterScriptMsg object
       
    64 	CRTSecMgrRegisterScriptMsg* self = new (ELeave) CRTSecMgrRegisterScriptMsg();
       
    65 	CleanupStack::PushL (self);
       
    66 	
       
    67 	// Open a read stream for the descriptor
       
    68 	RDesReadStream stream(aStreamData);
       
    69 	CleanupClosePushL (stream);
       
    70 	self->InternalizeL (stream);
       
    71 	CleanupStack::PopAndDestroy (&stream); // finished with the stream
       
    72 	return (self);
       
    73 	}
       
    74 
       
    75 void CRTSecMgrRegisterScriptMsg::ConstructL(const TDesC& aHashValue)
       
    76 	{
       
    77 	if ( iHashMarker)
       
    78 		{
       
    79 		delete iHashMarker;
       
    80 		iHashMarker = NULL;
       
    81 		}
       
    82 
       
    83 	iHashMarker = aHashValue.AllocL ();
       
    84 	}
       
    85 
       
    86 // Creates and returns a heap descriptor which holds contents of ’this’
       
    87 EXPORT_C HBufC8* CRTSecMgrRegisterScriptMsg::PackMsgL() const
       
    88 	{
       
    89 	// Dynamic data buffer
       
    90 	CBufFlat* buf = CBufFlat::NewL(KMaxMsgLength);
       
    91 	CleanupStack::PushL(buf);
       
    92 	RBufWriteStream stream(*buf); // Stream over the buffer
       
    93 	CleanupClosePushL(stream);
       
    94 	ExternalizeL(stream);
       
    95 	CleanupStack::PopAndDestroy(&stream);
       
    96 	// Create a heap descriptor from the buffer
       
    97 	HBufC8* des = HBufC8::NewL(buf->Size());
       
    98 	TPtr8 ptr(des->Des());
       
    99 	buf->Read(0, ptr, buf->Size());
       
   100 	CleanupStack::PopAndDestroy(buf); // Finished with the buffer
       
   101 	return (des);
       
   102 	}
       
   103 
       
   104 // Writes ’this’ to aStream
       
   105 void CRTSecMgrRegisterScriptMsg::ExternalizeL(RWriteStream& aStream) const
       
   106 	{
       
   107 	if ( iHashMarker)
       
   108 		aStream << *iHashMarker;
       
   109 	else
       
   110 		aStream << KNullDesC8;
       
   111 	
       
   112 	aStream.WriteInt32L (iPolicyID); // Write iPolicyID to the stream
       
   113 	}
       
   114 
       
   115 // Initializes ’this’ with the contents of aStream
       
   116 void CRTSecMgrRegisterScriptMsg::InternalizeL(RReadStream& aStream)
       
   117 	{
       
   118 	iHashMarker = HBufC::NewL (aStream, KMaxHashValueDesLen);
       
   119 	iPolicyID = aStream.ReadInt32L (); // Read iPolicyID
       
   120 	}
       
   121 
       
   122 EXPORT_C CRTPermGrantMessage::~CRTPermGrantMessage()
       
   123     {
       
   124     iAllowedProviders.Close();
       
   125     iDeniedProviders.Close();
       
   126     }
       
   127 
       
   128 EXPORT_C CRTPermGrantMessage* CRTPermGrantMessage::NewL()
       
   129     {
       
   130     CRTPermGrantMessage* self = CRTPermGrantMessage::NewLC();
       
   131     CleanupStack::Pop(self);
       
   132     return self;
       
   133     }
       
   134 
       
   135 EXPORT_C CRTPermGrantMessage* CRTPermGrantMessage::NewLC()
       
   136     {
       
   137     CRTPermGrantMessage* self = new(ELeave) CRTPermGrantMessage();
       
   138     CleanupStack::PushL(self);
       
   139     return self;
       
   140     }
       
   141 
       
   142 EXPORT_C CRTPermGrantMessage* CRTPermGrantMessage::NewL(const TDesC8& aBuf)
       
   143     {
       
   144     CRTPermGrantMessage* self = CRTPermGrantMessage::NewLC(aBuf);
       
   145     CleanupStack::Pop(self);
       
   146     return self;
       
   147     }
       
   148 
       
   149 EXPORT_C CRTPermGrantMessage* CRTPermGrantMessage::NewLC(const TDesC8& aBuf)
       
   150     {
       
   151     CRTPermGrantMessage* self = new(ELeave) CRTPermGrantMessage();
       
   152     CleanupStack::PushL(self);
       
   153     self->ConstructL(aBuf);
       
   154     return self;
       
   155     }
       
   156 
       
   157 EXPORT_C CRTPermGrantMessage* CRTPermGrantMessage::NewL(RProviderArray aAllowedProviders, RProviderArray aDeniedProviders,TExecutableID aScriptId)
       
   158     {
       
   159     CRTPermGrantMessage* self = CRTPermGrantMessage::NewLC(aAllowedProviders,aDeniedProviders,aScriptId);
       
   160     CleanupStack::Pop(self);
       
   161     return self;
       
   162     }
       
   163 
       
   164 EXPORT_C CRTPermGrantMessage* CRTPermGrantMessage::NewLC(RProviderArray aAllowedProviders, RProviderArray aDeniedProviders,TExecutableID aScriptId)
       
   165     {
       
   166     CRTPermGrantMessage* self = new(ELeave) CRTPermGrantMessage(aAllowedProviders,aDeniedProviders,aScriptId);
       
   167     CleanupStack::PushL(self);
       
   168     return self;
       
   169     }
       
   170 
       
   171 CRTPermGrantMessage::CRTPermGrantMessage()
       
   172     {
       
   173     
       
   174     }
       
   175 
       
   176 CRTPermGrantMessage::CRTPermGrantMessage(RProviderArray aAllowedProviders,RProviderArray aDeniedProviders,TExecutableID aScriptId)
       
   177     {
       
   178     iAllowedProviders.Reset();
       
   179     for(TInt i(0); i < aAllowedProviders.Count(); i++)
       
   180         iAllowedProviders.Append(aAllowedProviders[i]);
       
   181     iDeniedProviders.Reset();
       
   182     for(TInt i(0); i < aDeniedProviders.Count(); i++)
       
   183         iDeniedProviders.Append(aDeniedProviders[i]);
       
   184     iScriptId = aScriptId;
       
   185     }
       
   186 
       
   187 void CRTPermGrantMessage::ConstructL(const TDesC8& aBuf)
       
   188     {
       
   189     RDesReadStream stream(aBuf);
       
   190     CleanupClosePushL (stream);
       
   191     InternalizeL (stream);
       
   192     CleanupStack::PopAndDestroy (&stream);
       
   193     }
       
   194 
       
   195 EXPORT_C void CRTPermGrantMessage::AllowedProviders(RProviderArray& aAllowedProviders)
       
   196     {
       
   197     aAllowedProviders.Reset();
       
   198     for(TInt i(0); i < iAllowedProviders.Count(); i++)
       
   199         aAllowedProviders.Append(iAllowedProviders[i]);
       
   200     }
       
   201 
       
   202 EXPORT_C void CRTPermGrantMessage::DeniedProviders(RProviderArray& aDeniedProviders)
       
   203     {
       
   204     aDeniedProviders.Reset();
       
   205     for(TInt i(0); i < iDeniedProviders.Count(); i++)
       
   206         aDeniedProviders.Append(iDeniedProviders[i]);
       
   207     }
       
   208 
       
   209 EXPORT_C TExecutableID CRTPermGrantMessage::ScriptID()
       
   210     {
       
   211     return iScriptId;
       
   212     }
       
   213 
       
   214 EXPORT_C void CRTPermGrantMessage::setAllowedProviders(RProviderArray aAllowedProviders)
       
   215     {
       
   216     iAllowedProviders.Reset();
       
   217     for(TInt i(0); i < aAllowedProviders.Count(); i++)
       
   218             iAllowedProviders.Append(aAllowedProviders[i]);
       
   219     }
       
   220 
       
   221 EXPORT_C void CRTPermGrantMessage::setDeniedProviders(RProviderArray aDeniedProviders)
       
   222     {
       
   223     iDeniedProviders.Reset();
       
   224     for(TInt i(0); i < aDeniedProviders.Count(); i++)
       
   225             iDeniedProviders.Append(aDeniedProviders[i]);
       
   226     }
       
   227 
       
   228 EXPORT_C void CRTPermGrantMessage::setScriptID(TExecutableID aScriptId)
       
   229     {
       
   230     iScriptId = aScriptId;
       
   231     }
       
   232 
       
   233 void CRTPermGrantMessage::InternalizeL(RReadStream& aSource)
       
   234     {
       
   235     iScriptId = aSource.ReadInt32L();
       
   236     TInt allowCnt = aSource.ReadInt32L();
       
   237     iAllowedProviders.Reset();
       
   238     for(TInt i(0); i < allowCnt; i++)
       
   239         {
       
   240         TInt uid = aSource.ReadInt32L();
       
   241         TUid allowPid = TUid::Uid(uid);
       
   242         iAllowedProviders.Append(allowPid);
       
   243         }
       
   244     TInt denyCnt = aSource.ReadInt32L();
       
   245     iDeniedProviders.Reset();
       
   246     for(TInt i(0); i < denyCnt; i++)
       
   247         {
       
   248         TInt uid = aSource.ReadInt32L();
       
   249         TUid denyPid = TUid::Uid(uid);
       
   250         iDeniedProviders.Append(denyPid);
       
   251         }
       
   252     }
       
   253 
       
   254 void CRTPermGrantMessage::ExternalizeL(RWriteStream& aSink)
       
   255     {
       
   256     aSink.WriteInt32L(iScriptId);
       
   257     TInt cnt = iAllowedProviders.Count();
       
   258     aSink.WriteInt32L(cnt);
       
   259     for(TInt i(0); i < iAllowedProviders.Count(); i++)
       
   260         aSink.WriteInt32L(iAllowedProviders[i].iUid);
       
   261     cnt = iDeniedProviders.Count();
       
   262     aSink.WriteInt32L(cnt);
       
   263     for(TInt i(0); i < iDeniedProviders.Count(); i++)
       
   264         aSink.WriteInt32L(iDeniedProviders[i].iUid);
       
   265     }
       
   266 
       
   267 EXPORT_C HBufC8* CRTPermGrantMessage::PackMessageL()
       
   268     {
       
   269     // Dynamic data buffer
       
   270     CBufFlat* buf = CBufFlat::NewL(KMaxMsgLength);
       
   271     CleanupStack::PushL(buf);
       
   272     RBufWriteStream stream(*buf); // Stream over the buffer
       
   273     CleanupClosePushL(stream);
       
   274     ExternalizeL(stream);
       
   275     CleanupStack::PopAndDestroy(&stream);
       
   276     // Create a heap descriptor from the buffer
       
   277     HBufC8* des = HBufC8::NewL(buf->Size());
       
   278     TPtr8 ptr(des->Des());
       
   279     buf->Read(0, ptr, buf->Size());
       
   280     CleanupStack::PopAndDestroy(buf); // Finished with the buffer
       
   281     return (des);
       
   282     }