smf/smfcredentialmgr/smfcredmgrcommon/src/smfcredmgrclientdatastruct.cpp
changeset 14 a469c0e6e7fb
child 18 013a02bf2bb0
equal deleted inserted replaced
13:b5d63d5fc252 14:a469c0e6e7fb
       
     1 /**
       
     2  * Copyright (c) 2010 Sasken Communication Technologies Ltd.
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the "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  * Pritam Roy Biswas, Sasken Communication Technologies Ltd - Initial contribution
       
    11  *
       
    12  * Description:
       
    13  *	This source file gives different data classes to be used
       
    14  * by Credential Manager Client and Server for data transfer.	
       
    15  *
       
    16  */
       
    17 
       
    18 #include "smfcredmgrclientdatastruct.h"
       
    19 #include "smfutils.h"
       
    20 #include <f32file.h>
       
    21 
       
    22 void TSmfAuthToken::ExternalizeL(RWriteStream& aStream)
       
    23 	{
       
    24 
       
    25 	TPtr firstArgPtr(iKey->Des());
       
    26 	SmfUtils::ExternalizeDesL(firstArgPtr, aStream);
       
    27 
       
    28 	TPtr secondArgPtr(iSecret->Des());
       
    29 	SmfUtils::ExternalizeDesL(secondArgPtr, aStream);
       
    30 	}
       
    31 
       
    32 void TSmfAuthToken::InternalizeL(RReadStream& aStream)
       
    33 	{
       
    34 
       
    35 	// Delete the current values
       
    36 	delete iKey;
       
    37 	iKey = SmfUtils::InternalizeDesL(aStream);
       
    38 
       
    39 	delete iSecret;
       
    40 	iSecret = SmfUtils::InternalizeDesL(aStream);
       
    41 	}
       
    42 
       
    43 void CSmfFetchAuthTokenSet::ExternalizeL(RWriteStream& aStream)
       
    44 	{
       
    45 	aStream.WriteUint32L(iValidity);
       
    46 
       
    47 	TPtr tokenPtr(iRegistrationToken->Des());
       
    48 	SmfUtils::ExternalizeDesL(tokenPtr, aStream);
       
    49 
       
    50 	TInt32 countTokenSet = iAuthTokenArray.Count();
       
    51 	aStream.WriteInt32L(countTokenSet);
       
    52 
       
    53 	for (int i = 0; i < countTokenSet; i++)
       
    54 		{
       
    55 		iAuthTokenArray[i].ExternalizeL(aStream);
       
    56 		}
       
    57 
       
    58 	}
       
    59 
       
    60 void CSmfFetchAuthTokenSet::InternalizeL(const RBuf8& aSource)
       
    61 	{
       
    62 	// Create stream to read from the given buffer
       
    63 	RDesReadStream stream(aSource);
       
    64 	CleanupClosePushL(stream);
       
    65 
       
    66 	iValidity = stream.ReadUint32L();
       
    67 	
       
    68 	// Delete the current values
       
    69 	delete iRegistrationToken;
       
    70 	iRegistrationToken = SmfUtils::InternalizeDesL(stream);
       
    71 
       
    72 	TInt32 countTokenSet = stream.ReadInt32L();
       
    73 	iAuthTokenArray.Reset();
       
    74 	for (int i = 0; i < countTokenSet; i++)
       
    75 		{
       
    76 		TSmfAuthToken set;
       
    77 		set.InternalizeL(stream);
       
    78 		iAuthTokenArray.Insert(set, i);
       
    79 		}
       
    80 	CleanupStack::PopAndDestroy(&stream);
       
    81 	}
       
    82 
       
    83 void CSmfURLListParams::ExternalizeL(RWriteStream& aStream)
       
    84 	{
       
    85 	TInt32 countPlugin = iURLList.Count();
       
    86 	aStream.WriteInt32L(countPlugin);
       
    87 	for (int i = 0; i < countPlugin; i++)
       
    88 		{
       
    89 		TPtr pluginBufPtr(iURLList[i]->Des());
       
    90 		SmfUtils::ExternalizeDesL(pluginBufPtr, aStream);
       
    91 		}
       
    92 
       
    93 	TPtr tokenPtr(iPluginID->Des());
       
    94 	SmfUtils::ExternalizeDesL(tokenPtr, aStream);
       
    95 	}
       
    96 
       
    97 void CSmfURLListParams::InternalizeL(const TDesC8& aSource)
       
    98 	{
       
    99 	// Create stream to read from the given buffer
       
   100 	RDesReadStream stream(aSource);
       
   101 	CleanupClosePushL(stream);
       
   102 
       
   103 	//internalize plugin ids
       
   104 	TInt32 countPlugin = stream.ReadInt32L();
       
   105 	iURLList.Reset();
       
   106 	for (int i = 0; i < countPlugin; i++)
       
   107 		{
       
   108 		HBufC* bufPlugin(SmfUtils::InternalizeDesL(stream));
       
   109 		iURLList.Insert(bufPlugin, i);
       
   110 		}
       
   111 	iPluginID = SmfUtils::InternalizeDesL(stream);
       
   112 
       
   113 	CleanupStack::PopAndDestroy(&stream);
       
   114 	}
       
   115 
       
   116 void CSmfPluginIDListParams::ExternalizeL(RWriteStream& aStream)
       
   117 	{
       
   118 	TPtr tokenPtr(iRegistrationToken->Des());
       
   119 	SmfUtils::ExternalizeDesL(tokenPtr, aStream);
       
   120 
       
   121 	TInt32 countPlugin = iPluginList.Count();
       
   122 	aStream.WriteInt32L(countPlugin);
       
   123 	for (int i = 0; i < countPlugin; i++)
       
   124 		{
       
   125 		TPtr pluginBufPtr(iPluginList[i]->Des());
       
   126 		SmfUtils::ExternalizeDesL(pluginBufPtr, aStream);
       
   127 		}
       
   128 	}
       
   129 
       
   130 void CSmfPluginIDListParams::InternalizeL(const RBuf8& aSource)
       
   131 	{
       
   132 	// Create stream to use given buffer.
       
   133 	RDesReadStream stream(aSource);
       
   134 	CleanupClosePushL(stream);
       
   135 
       
   136 	// Delete the current values
       
   137 	delete iRegistrationToken;
       
   138 	iRegistrationToken = SmfUtils::InternalizeDesL(stream);
       
   139 
       
   140 	//internalize plugin ids
       
   141 	TInt32 countPlugin = stream.ReadInt32L();
       
   142 	iPluginList.Reset();
       
   143 	for (int i = 0; i < countPlugin; i++)
       
   144 		{
       
   145 		HBufC* bufPlugin(SmfUtils::InternalizeDesL(stream));
       
   146 		iPluginList.Insert(bufPlugin, i);
       
   147 		}
       
   148 	CleanupStack::PopAndDestroy(&stream);
       
   149 	}
       
   150 
       
   151 void CSmfStoreAuthParams::ExternalizeL(RWriteStream& aStream)
       
   152 	{
       
   153 	aStream.WriteInt32L(pluginIDEnabled);
       
   154 
       
   155 	aStream.WriteUint32L(iValidity);
       
   156 
       
   157 	TPtr tokenPtr(iRegistrationToken->Des());
       
   158 	SmfUtils::ExternalizeDesL(tokenPtr, aStream);
       
   159 
       
   160 	TPtr AuthAppIdPtr(iAuthAppID->Des());
       
   161 	SmfUtils::ExternalizeDesL(AuthAppIdPtr, aStream);
       
   162 
       
   163 	TInt32 countTokenSet = iAuthTokenArray.Count();
       
   164 	aStream.WriteInt32L(countTokenSet);
       
   165 
       
   166 	for (int i = 0; i < countTokenSet; i++)
       
   167 		{
       
   168 		iAuthTokenArray[i].ExternalizeL(aStream);
       
   169 		}
       
   170 
       
   171 	TInt32 countPlugin = iPluginIDList.Count();
       
   172 
       
   173 	aStream.WriteInt32L(countPlugin);
       
   174 
       
   175 	for (int i = 0; i < countPlugin; i++)
       
   176 		{
       
   177 
       
   178 		TPtr pluginBufPtr(iPluginIDList[i]->Des());
       
   179 		SmfUtils::ExternalizeDesL(pluginBufPtr, aStream);
       
   180 		}
       
   181 
       
   182 	TInt32 countUrl = iURLList.Count();
       
   183 	aStream.WriteInt32L(countUrl);
       
   184 
       
   185 	for (int i = 0; i < countUrl; i++)
       
   186 		{
       
   187 		TPtr urlBufPtr(iURLList[i]->Des());
       
   188 		SmfUtils::ExternalizeDesL(urlBufPtr, aStream);
       
   189 		}
       
   190 	}
       
   191 
       
   192 void CSmfStoreAuthParams::InternalizeL(const RBuf8& aSource)
       
   193 	{
       
   194 	// Create stream to read from the given buffer
       
   195 	RDesReadStream stream(aSource);
       
   196 	CleanupClosePushL(stream);
       
   197 
       
   198 	pluginIDEnabled = stream.ReadInt32L();
       
   199 
       
   200 	iValidity = stream.ReadUint32L();
       
   201 
       
   202 	// Delete the current values
       
   203 	delete iRegistrationToken;
       
   204 	iRegistrationToken = SmfUtils::InternalizeDesL(stream);
       
   205 
       
   206 	delete iAuthAppID;
       
   207 	iAuthAppID = SmfUtils::InternalizeDesL(stream);
       
   208 
       
   209 	TInt32 countTokenSet = stream.ReadInt32L();
       
   210 	iAuthTokenArray.Reset();
       
   211 	for (int i = 0; i < countTokenSet; i++)
       
   212 		{
       
   213 		TSmfAuthToken set;
       
   214 		set.InternalizeL(stream);
       
   215 		iAuthTokenArray.Insert(set, i);
       
   216 		}
       
   217 
       
   218 	//internalize plugin ids
       
   219 	TInt32 countPlugin = stream.ReadInt32L();
       
   220 	iPluginIDList.Reset();
       
   221 	for (int i = 0; i < countPlugin; i++)
       
   222 		{
       
   223 		HBufC* bufPlugin = SmfUtils::InternalizeDesL(stream);
       
   224 		iPluginIDList.Insert(bufPlugin, i);
       
   225 		}
       
   226 
       
   227 	//internalize URLs
       
   228 	TInt32 countURL = stream.ReadInt32L();
       
   229 	iURLList.Reset();
       
   230 	for (int i = 0; i < countURL; i++)
       
   231 		{
       
   232 		HBufC* bufURL = SmfUtils::InternalizeDesL(stream);
       
   233 		iURLList.Insert(bufURL, i);
       
   234 		}
       
   235 	CleanupStack::PopAndDestroy(&stream);
       
   236 	}
       
   237 
       
   238 void CSmfPluginIDUpdate::ExternalizeL(RWriteStream& aStream)
       
   239 	{
       
   240 	aStream.WriteInt32L(pluginIDEnabled);
       
   241 
       
   242 	TPtr newPtr(iNewPluginID->Des());
       
   243 	SmfUtils::ExternalizeDesL(newPtr, aStream);
       
   244 
       
   245 	TPtr oldPtr(iOldPluginID->Des());
       
   246 	SmfUtils::ExternalizeDesL(oldPtr, aStream);
       
   247 	}
       
   248 
       
   249 void CSmfPluginIDUpdate::InternalizeL(const RBuf8& aSource)
       
   250 	{
       
   251 	// Create stream to read from the given buffer
       
   252 	RDesReadStream stream(aSource);
       
   253 	CleanupClosePushL(stream);
       
   254 
       
   255 	pluginIDEnabled = stream.ReadInt32L();
       
   256 
       
   257 	// Delete the current values
       
   258 	delete iNewPluginID;
       
   259 	iNewPluginID = SmfUtils::InternalizeDesL(stream);
       
   260 
       
   261 	delete iOldPluginID;
       
   262 	iOldPluginID = SmfUtils::InternalizeDesL(stream);
       
   263 
       
   264 	CleanupStack::PopAndDestroy(&stream);
       
   265 	}
       
   266 
       
   267 CSmfSignParameters* CSmfSignParameters::NewL(
       
   268 	const TDesC8& aMessage, const TDesC8& aKey ) 
       
   269 	{
       
   270 	CSmfSignParameters* self = new( ELeave ) CSmfSignParameters();
       
   271 	CleanupStack::PushL( self );
       
   272 	self->ConstructL( aMessage, aKey );
       
   273 	CleanupStack::Pop( self );
       
   274 	return self;
       
   275 	}
       
   276 
       
   277 CSmfSignParameters* CSmfSignParameters::NewL( const TDesC8& aData ) 
       
   278 	{
       
   279 	CSmfSignParameters* self = new( ELeave ) CSmfSignParameters();
       
   280 	CleanupStack::PushL( self );
       
   281 	self->ConstructL( aData );
       
   282 	CleanupStack::Pop( self );
       
   283 	return self;
       
   284 	}
       
   285 
       
   286 CSmfSignParameters::~CSmfSignParameters() 
       
   287 	{
       
   288 	iMessage.Close();
       
   289 	iKey.Close();
       
   290 	}
       
   291 
       
   292 void CSmfSignParameters::ExternalizeL( RWriteStream& aStream ) const
       
   293 	{
       
   294 	SmfUtils::ExternalizeDesL( iMessage, aStream );
       
   295 	SmfUtils::ExternalizeDesL( iKey, aStream );
       
   296 	}
       
   297 
       
   298 const TDesC8& CSmfSignParameters::Key() const 
       
   299 	{
       
   300 	return iKey;
       
   301 	}
       
   302 
       
   303 const TDesC8& CSmfSignParameters::Message() const 
       
   304 	{
       
   305 	return iMessage;
       
   306 	}
       
   307 
       
   308 CSmfSignParameters::CSmfSignParameters() 
       
   309 	{
       
   310 	}
       
   311 
       
   312 void CSmfSignParameters::ConstructL( const TDesC8& aMessage, const TDesC8& aKey )
       
   313 	{
       
   314 	iMessage.CreateL( aMessage );
       
   315 	iKey.CreateL( aKey );
       
   316 	}
       
   317 
       
   318 void CSmfSignParameters::ConstructL( const TDesC8& aData ) 
       
   319 	{
       
   320 	RDesReadStream stream( aData );
       
   321 	CleanupClosePushL( stream );
       
   322 	SmfUtils::InternalizeDesL( iMessage, stream );
       
   323 	SmfUtils::InternalizeDesL( iKey, stream );
       
   324 	CleanupStack::PopAndDestroy( &stream );
       
   325 	}
       
   326 
       
   327 CSmfRsaKeyParameters* CSmfRsaKeyParameters::NewL(
       
   328 		const TDesC& aKeyName, const TTime& startDate,
       
   329 		const TTime& endDate, const TDesC8& aKeyData )
       
   330 	{
       
   331 	CSmfRsaKeyParameters* self = new( ELeave ) CSmfRsaKeyParameters;
       
   332 	CleanupStack::PushL( self );
       
   333 	self->ConstructL( aKeyName, startDate, endDate, aKeyData );
       
   334 	CleanupStack::Pop( self );
       
   335 	return self;
       
   336 	}
       
   337 
       
   338 CSmfRsaKeyParameters* CSmfRsaKeyParameters::NewL( const TDesC8& aData )
       
   339 	{
       
   340 	CSmfRsaKeyParameters* self = new( ELeave ) CSmfRsaKeyParameters;
       
   341 	CleanupStack::PushL( self );
       
   342 	self->ConstructL( aData );
       
   343 	CleanupStack::Pop( self );
       
   344 	return self;
       
   345 	}
       
   346 
       
   347 CSmfRsaKeyParameters::~CSmfRsaKeyParameters() 
       
   348 	{
       
   349 	iKeyName.Close();
       
   350 	iKeyData.Close();
       
   351 	}
       
   352 
       
   353 void CSmfRsaKeyParameters::ExternalizeL( RWriteStream& aStream ) const
       
   354 	{
       
   355 	SmfUtils::ExternalizeDesL( iKeyName, aStream );
       
   356 	SmfUtils::ExternalizeDesL( iKeyData, aStream );
       
   357 	SmfUtils::ExternalizeInt64L( iStartDate.Int64(), aStream );
       
   358 	SmfUtils::ExternalizeInt64L( iEndDate.Int64(), aStream );		
       
   359 	}
       
   360 
       
   361 const TDesC& CSmfRsaKeyParameters::KeyName() const
       
   362 	{
       
   363 	return iKeyName;
       
   364 	}
       
   365 
       
   366 const TDesC8& CSmfRsaKeyParameters::KeyData() const
       
   367 	{
       
   368 	return iKeyData;
       
   369 	}
       
   370 
       
   371 const TTime& CSmfRsaKeyParameters::StartDate() const
       
   372 	{
       
   373 	return iStartDate;
       
   374 	}
       
   375 
       
   376 const TTime& CSmfRsaKeyParameters::EndDate() const
       
   377 	{
       
   378 	return iEndDate;
       
   379 	}
       
   380 
       
   381 void CSmfRsaKeyParameters::ConstructL( 
       
   382 		const TDesC& aKeyName, const TTime& startDate,
       
   383 		const TTime& endDate, const TDesC8& aKeyData )
       
   384 	{
       
   385 	iKeyName.CreateL( aKeyName );
       
   386 	iKeyData.CreateL( aKeyData );
       
   387 	iStartDate = startDate;
       
   388 	iEndDate = endDate;
       
   389 	}
       
   390 
       
   391 void CSmfRsaKeyParameters::ConstructL( const TDesC8& aData )
       
   392 	{
       
   393 	RDesReadStream stream( aData );
       
   394 	CleanupClosePushL( stream );
       
   395 	SmfUtils::InternalizeDesL( iKeyName, stream );
       
   396 	SmfUtils::InternalizeDesL( iKeyData, stream );
       
   397 	TInt64 startDate;
       
   398 	TInt64 endDate;
       
   399 	SmfUtils::InternalizeInt64L( startDate, stream );
       
   400 	SmfUtils::InternalizeInt64L( endDate, stream );
       
   401 	iStartDate = TTime( startDate );
       
   402 	iEndDate = TTime( endDate );
       
   403 	CleanupStack::PopAndDestroy( &stream );	
       
   404 	}