smf/smfcredentialmgr/smfcredmgrserver/src/smfcredmgrdbuser.cpp
changeset 18 013a02bf2bb0
parent 14 a469c0e6e7fb
child 24 1cee9f1b95e0
equal deleted inserted replaced
17:106a4bfcb866 18:013a02bf2bb0
     5  * under the terms of the "Eclipse Public License v1.0"
     5  * under the terms of the "Eclipse Public License v1.0"
     6  * which accompanies  this distribution, and is available
     6  * which accompanies  this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html"
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html"
     8  *
     8  *
     9  * Initial Contributors:
     9  * Initial Contributors:
    10  * Pritam Roy Biswas, Sasken Communication Technologies Ltd - Initial contribution
    10  * Chandradeep Gandhi, Sasken Communication Technologies Ltd - Initial contribution
       
    11  * 
       
    12  * Contributors:
       
    13  * Pritam Roy Biswas, Nalina Hariharan, Sasken Communication Technologies Ltd
    11  *
    14  *
    12  * Description:
    15  * Description:
    13  * This file contains routines to handle the data-base operations like insertion, query etc. 
    16  * This file contains routines to handle the data-base operations like insertion, query etc. 
    14  * on Credential Manager Server Database
    17  * on Credential Manager Server Database
    15  */
    18  */
    16 
    19 
    17 #include <BAUTILS.H>
    20 #include <BAUTILS.H>
       
    21 
    18 #include "smfcredmgrdbuser.h"
    22 #include "smfcredmgrdbuser.h"
    19 #include "smfcredmgrdb.h"
    23 #include "smfcredmgrdb.h"
    20 
    24 
       
    25 /**
       
    26  * NewL function
       
    27  * @param aSession the session object using this class
       
    28  * @return The constructed CSmfCredMgrDbUser instance
       
    29  */
    21 CSmfCredMgrDbUser* CSmfCredMgrDbUser::NewL(CSmfCredMgrServerSession* aSession)
    30 CSmfCredMgrDbUser* CSmfCredMgrDbUser::NewL(CSmfCredMgrServerSession* aSession)
    22 	{
    31 	{
    23 	CSmfCredMgrDbUser* self = CSmfCredMgrDbUser::NewLC(aSession);
    32 	CSmfCredMgrDbUser* self = CSmfCredMgrDbUser::NewLC(aSession);
    24 	CleanupStack::Pop(self);
    33 	CleanupStack::Pop(self);
    25 	return (self);
    34 	return (self);
    26 	}
    35 	}
    27 
    36 
       
    37 /**
       
    38  * NewLC function. This method adds the return value to the 
       
    39  * Cleanup Stack if constructed
       
    40  * @param aSession the session object using this class
       
    41  * @return The constructed CSmfCredMgrDbUser instance
       
    42  */
    28 CSmfCredMgrDbUser* CSmfCredMgrDbUser::NewLC(CSmfCredMgrServerSession* aSession)
    43 CSmfCredMgrDbUser* CSmfCredMgrDbUser::NewLC(CSmfCredMgrServerSession* aSession)
    29 	{
    44 	{
    30 	CSmfCredMgrDbUser* self = new (ELeave) CSmfCredMgrDbUser(aSession);
    45 	CSmfCredMgrDbUser* self = new (ELeave) CSmfCredMgrDbUser(aSession);
    31 	CleanupStack::PushL(self);
    46 	CleanupStack::PushL(self);
    32 	self->ConstructL();
    47 	self->ConstructL();
    33 	return (self);
    48 	return (self);
    34 	}
    49 	}
    35 
    50 
       
    51 /**
       
    52  * Two phase constructor
       
    53  */
    36 void CSmfCredMgrDbUser::ConstructL()
    54 void CSmfCredMgrDbUser::ConstructL()
    37 	{
    55 	{
    38 	TInt err = iFileSession.Connect();
    56 	TInt err = iFileSession.Connect();
    39 	User::LeaveIfError(err);
    57 	User::LeaveIfError(err);
    40 
    58 
    69 		//path not present
    87 		//path not present
    70 		User::Leave(KErrPathNotFound);
    88 		User::Leave(KErrPathNotFound);
    71 		}
    89 		}
    72 	}
    90 	}
    73 
    91 
       
    92 /**
       
    93  * Constructor
       
    94  * @param aSession The CSmfCredMgrServerSession instance
       
    95  */
    74 CSmfCredMgrDbUser::CSmfCredMgrDbUser(CSmfCredMgrServerSession* aSession) :
    96 CSmfCredMgrDbUser::CSmfCredMgrDbUser(CSmfCredMgrServerSession* aSession) :
    75 	iSession(aSession)
    97 	iSession(aSession)
    76 	{
    98 	{
    77 	}
    99 	}
    78 
   100 
       
   101 /**
       
   102  * Destructor
       
   103  */
    79 CSmfCredMgrDbUser::~CSmfCredMgrDbUser()
   104 CSmfCredMgrDbUser::~CSmfCredMgrDbUser()
    80 	{
   105 	{
    81 	iFileSession.Close();
   106 	iFileSession.Close();
    82 	iDataBase.Close();
   107 	iDataBase.Close();
    83 	}
   108 	}
    84 
   109 
       
   110 /**
       
   111  * Method to insert PluginIDTable
       
   112  * @param aPluginID The ID of the plugin 
       
   113  * @param aAuthAppId The ID of the Authentication app associated with the plugin
       
   114  * @param aEnableFlag A flag to indicate if the plugin is enabled, 
       
   115  * i.e, aEnableFlag = 0 for a disabled plugin
       
   116  * @return Returns KErrNone if success. Refer ESqlDbError and system-wide 
       
   117  * error codes for detailed error description.
       
   118  */
    85 TInt CSmfCredMgrDbUser::PluginIDTableInsert(const TDesC& aPluginId,
   119 TInt CSmfCredMgrDbUser::PluginIDTableInsert(const TDesC& aPluginId,
    86 		const TDesC& aAuthAppId, TBool aEnableFlag)
   120 		const TDesC& aAuthAppId, TBool aEnableFlag)
    87 	{
   121 	{
    88 	TInt err(KErrNone);
   122 	TInt err(KErrNone);
    89 	RSqlStatement sqlStatement;
   123 	RSqlStatement sqlStatement;
   133 		return KErrNone;
   167 		return KErrNone;
   134 		}
   168 		}
   135 	return err;
   169 	return err;
   136 	}
   170 	}
   137 
   171 
       
   172 /**
       
   173  * Method to insert URLTable
       
   174  * @param aAuthAppId The ID of the Authentication app associated with the URLs 
       
   175  * @param aURL The URL to be stored
       
   176  * @return Returns KErrNone if success. Refer ESqlDbError and system-wide 
       
   177  * error codes for detailed error description.
       
   178  */
   138 TInt CSmfCredMgrDbUser::URLTableInsert(const TDesC& aAuthAppId,
   179 TInt CSmfCredMgrDbUser::URLTableInsert(const TDesC& aAuthAppId,
   139 		const TDesC& aURL)
   180 		const TDesC& aURL)
   140 	{
   181 	{
   141 	TInt err(KErrNone);
   182 	TInt err(KErrNone);
   142 	RSqlStatement sqlStatement;
   183 	RSqlStatement sqlStatement;
   183 		return KErrNone;
   224 		return KErrNone;
   184 		}
   225 		}
   185 	return err;
   226 	return err;
   186 	}
   227 	}
   187 
   228 
       
   229 /**
       
   230  * Method to insert RegTokenValidityTable
       
   231  * @param aRegToken The Registration token for the authentication app 
       
   232  * @param aAuthAppId The ID of the Authentication app
       
   233  * @param aValidity The time by which the set will expire
       
   234  * @return Returns KErrNone if success. Refer ESqlDbError and system-wide 
       
   235  * error codes for detailed error description. 
       
   236  */
   188 TInt CSmfCredMgrDbUser::RegTokenValidityTableInsert(const TDesC& aRegToken,
   237 TInt CSmfCredMgrDbUser::RegTokenValidityTableInsert(const TDesC& aRegToken,
   189 		const TDesC& aAuthAppId, const TUint aValidity)
   238 		const TDesC& aAuthAppId, const TUint aValidity)
   190 	{
   239 	{
   191 	TInt err(KErrNone);
   240 	TInt err(KErrNone);
   192 	RSqlStatement sqlStatement;
   241 	RSqlStatement sqlStatement;
   237 		}
   286 		}
   238 	return err;
   287 	return err;
   239 
   288 
   240 	}
   289 	}
   241 
   290 
       
   291 /**
       
   292  * Method to insert AuthParamsTable
       
   293  * @param aAuthAppId The ID of the Authentication app
       
   294  * @param aKey The Key
       
   295  * @param aSecret The Secret
       
   296  * @return Returns KErrNone if success. Refer ESqlDbError and system-wide 
       
   297  * error codes for detailed error description. 
       
   298  */
   242 TInt CSmfCredMgrDbUser::AuthParamsTableInsert(const TDesC& aAuthAppId,
   299 TInt CSmfCredMgrDbUser::AuthParamsTableInsert(const TDesC& aAuthAppId,
   243 		const TDesC& aKey, const TDesC& aSecret)
   300 		const TDesC& aKey, const TDesC& aSecret)
   244 	{
   301 	{
   245 	TInt err(KErrNone);
   302 	TInt err(KErrNone);
   246 	RSqlStatement sqlStatement;
   303 	RSqlStatement sqlStatement;
   291 		return KErrNone;
   348 		return KErrNone;
   292 		}
   349 		}
   293 	return err;
   350 	return err;
   294 	}
   351 	}
   295 
   352 
   296 void CSmfCredMgrDbUser::readFlagInPluginIdTable(const TDesC& aPluginID,
   353 /**
   297 		TInt& aFlag)
   354  * Method to fetch all the plugins associated with the registration token
   298 	{
   355  * @param aRegToken The Registration token of the authentication app
   299 	TInt err(KErrNone);
   356  * @param aArray [out] The array to be updated with plugin ids
   300 
   357  */
   301 	RSqlStatement sqlReadStatement;
   358 void CSmfCredMgrDbUser::fetchPluginListL(const TDesC& aRegToken, RPointerArray<
   302 	TInt paramIndex(KErrNone);
   359 		HBufC>& aArray)
   303 
   360 	{
   304 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadFlagInPluginTable);
   361 	TBuf<KMaxBufSize> authAppID;
   305 
   362 	readAuthAppIdInRegTokenTable(aRegToken, authAppID);
   306 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
   363 	readPluginIdL(authAppID, aArray);
   307 	err = sqlReadStatement.BindText(paramIndex, aPluginID);
   364 	}
   308 
   365 
   309 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
   366 /**
   310 		{
   367  * Method to Key-Secret pairs of the Authentication app
   311 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
   368  * @param aAuthAppId The ID of the Authentication app
   312 		if (!sqlReadStatement.IsNull(0))
   369  * @param aArray [out] The array containing the key-secret pair
   313 			{
   370  */
   314 			aFlag = sqlReadStatement.ColumnInt(0);
   371 void CSmfCredMgrDbUser::readAuthTokensL(const TDesC& aAuthAppId, RArray<
   315 			}
       
   316 		}
       
   317 	sqlReadStatement.Close();
       
   318 	}
       
   319 
       
   320 void CSmfCredMgrDbUser::readAuthAppIdInPluginIdTable(const TDesC& aPluginID,
       
   321 		TDes& aAuthAppId)
       
   322 	{
       
   323 	TInt err(KErrNone);
       
   324 
       
   325 	RSqlStatement sqlReadStatement;
       
   326 	TInt paramIndex(KErrNone);
       
   327 
       
   328 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadAuthAppIdInPluginTable);
       
   329 
       
   330 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   331 	err = sqlReadStatement.BindText(paramIndex, aPluginID);
       
   332 
       
   333 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   334 		{
       
   335 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   336 		if (!sqlReadStatement.IsNull(0))
       
   337 			{
       
   338 			sqlReadStatement.ColumnText(0, aAuthAppId);
       
   339 			}
       
   340 		}
       
   341 	sqlReadStatement.Close();
       
   342 	}
       
   343 
       
   344 void CSmfCredMgrDbUser::readAuthTokens(const TDesC& aAuthAppId, RArray<
       
   345 		TSmfAuthToken>& aArray)
   372 		TSmfAuthToken>& aArray)
   346 	{
   373 	{
   347 	TInt err(KErrNone);
   374 	TInt err(KErrNone);
   348 
   375 
   349 	RSqlStatement sqlReadStatement;
   376 	RSqlStatement sqlReadStatement;
   381 			}
   408 			}
   382 		}
   409 		}
   383 	sqlReadStatement.Close();
   410 	sqlReadStatement.Close();
   384 	}
   411 	}
   385 
   412 
   386 void CSmfCredMgrDbUser::fetchPluginList(const TDesC& aRegToken, RPointerArray<
   413 /**
   387 		HBufC>& aArray)
   414  * Method to fetch all the URLs associated with the Authentication app
   388 	{
   415  * @param aAuthAppId The ID of the Authentication app
   389 	TBuf<KMaxBufSize> authAppID;
   416  * @param aArray [out] The array to be updated with URLs 
   390 	readAuthAppIdInRegTokenTable(aRegToken, authAppID);
   417  */
   391 	readPluginId(authAppID, aArray);
   418 void CSmfCredMgrDbUser::readUrlL(const TDesC& aAuthAppId,
   392 	}
   419 		RPointerArray<HBufC>& aArray)
   393 
   420 	{
       
   421 	TInt err(KErrNone);
       
   422 
       
   423 	RSqlStatement sqlReadStatement;
       
   424 	TInt paramIndex(KErrNone);
       
   425 
       
   426 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadURL);
       
   427 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   428 	err = sqlReadStatement.BindText(paramIndex, aAuthAppId);
       
   429 
       
   430 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   431 		{
       
   432 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   433 		if (!sqlReadStatement.IsNull(0))
       
   434 			{
       
   435 			TBuf<KMaxBufSize> urlBuf;
       
   436 			HBufC* buf = HBufC::NewL(KMaxBufSize);
       
   437 			sqlReadStatement.ColumnText(0, urlBuf);
       
   438 			buf->Des().Copy(urlBuf);
       
   439 			aArray.Append(buf);
       
   440 			}
       
   441 		else
       
   442 			{
       
   443 			__ASSERT_DEBUG( 0, User::Invariant());
       
   444 			}
       
   445 		}
       
   446 	sqlReadStatement.Close();
       
   447 	}
       
   448 
       
   449 /**
       
   450  * Method to fetch Validity of the Authentication app
       
   451  * @param aAuthAppId The ID of the Authentication app
       
   452  * @param aValidity [out] The time by which the Auth set will expire
       
   453  */
       
   454 void CSmfCredMgrDbUser::readValidity(const TDesC& aAuthAppId, TInt64& aValidity)
       
   455 	{
       
   456 	TInt err(KErrNone);
       
   457 
       
   458 	RSqlStatement sqlReadStatement;
       
   459 	TInt paramIndex(KErrNone);
       
   460 
       
   461 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadValidity);
       
   462 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   463 	err = sqlReadStatement.BindText(paramIndex, aAuthAppId);
       
   464 
       
   465 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   466 		{
       
   467 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   468 		if (!sqlReadStatement.IsNull(0))
       
   469 			{
       
   470 			aValidity = sqlReadStatement.ColumnInt64(1);
       
   471 			}
       
   472 		else
       
   473 			{
       
   474 			__ASSERT_DEBUG( 0, User::Invariant());
       
   475 			}
       
   476 		}
       
   477 	sqlReadStatement.Close();
       
   478 
       
   479 	}
       
   480 
       
   481 /**
       
   482  * Method to fetch Registration token of the Authentication app from RegTokenValidityTable
       
   483  * @param aAuthAppId The ID of the Authentication app
       
   484  * @param aRegToken [out] The Registration token of the authentication app
       
   485  */
       
   486 void CSmfCredMgrDbUser::readRegistrationTokenL(const TDesC& aAuthAppId,
       
   487 		TDesC& aRegToken)
       
   488 	{
       
   489 	TInt err(KErrNone);
       
   490 
       
   491 	RSqlStatement sqlReadStatement;
       
   492 	TInt paramIndex(KErrNone);
       
   493 
       
   494 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadRegistrationToken);
       
   495 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   496 	err = sqlReadStatement.BindText(paramIndex, aAuthAppId);
       
   497 
       
   498 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   499 		{
       
   500 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   501 		if (!sqlReadStatement.IsNull(0))
       
   502 			{
       
   503 			aRegToken = sqlReadStatement.ColumnTextL(0);//aKey.AllocL();
       
   504 			}
       
   505 		else
       
   506 			{
       
   507 			__ASSERT_DEBUG( 0, User::Invariant());
       
   508 			}
       
   509 		}
       
   510 	sqlReadStatement.Close();
       
   511 	}
       
   512 
       
   513 /**
       
   514  * Method to fetch Authentication app ID from RegTokenValidityTable 
       
   515  * giving the reg token
       
   516  * @param aRegToken The Registration token of the authentication app
       
   517  * @param aAuthAppId [out] The ID of the Authentication app
       
   518  */
   394 void CSmfCredMgrDbUser::readAuthAppIdInRegTokenTable(const TDesC& aRegToken,
   519 void CSmfCredMgrDbUser::readAuthAppIdInRegTokenTable(const TDesC& aRegToken,
   395 		TDes& aAuthAppId)
   520 		TDes& aAuthAppId)
   396 	{
   521 	{
   397 	TInt err(KErrNone);
   522 	TInt err(KErrNone);
   398 
   523 
   421 			__ASSERT_DEBUG( 0, User::Invariant());
   546 			__ASSERT_DEBUG( 0, User::Invariant());
   422 			}
   547 			}
   423 		}
   548 		}
   424 	sqlReadStatement.Close();
   549 	sqlReadStatement.Close();
   425 	}
   550 	}
   426 void CSmfCredMgrDbUser::readPluginId(const TDesC& aAuthAppId, RPointerArray<
   551 
       
   552 
       
   553 /**
       
   554  * Method to fetch Authentication app ID from PluginIDTable giving the plugin ID
       
   555  * @param aPluginID the ID of the plugin
       
   556  * @param aAuthAppId [out] ID of the Authentication app
       
   557  */
       
   558 void CSmfCredMgrDbUser::readAuthAppIdInPluginIdTable(const TDesC& aPluginID,
       
   559 		TDes& aAuthAppId)
       
   560 	{
       
   561 	TInt err(KErrNone);
       
   562 
       
   563 	RSqlStatement sqlReadStatement;
       
   564 	TInt paramIndex(KErrNone);
       
   565 
       
   566 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadAuthAppIdInPluginTable);
       
   567 
       
   568 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   569 	err = sqlReadStatement.BindText(paramIndex, aPluginID);
       
   570 
       
   571 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   572 		{
       
   573 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   574 		if (!sqlReadStatement.IsNull(0))
       
   575 			{
       
   576 			sqlReadStatement.ColumnText(0, aAuthAppId);
       
   577 			}
       
   578 		}
       
   579 	sqlReadStatement.Close();
       
   580 	}
       
   581 
       
   582 /**
       
   583  * Method to read the IsEnabled flag from plugin Id table
       
   584  * @param aPluginID The ID of the plugin
       
   585  * @param aFlag [out] The flag that indicates the plugin id is enables or disabled
       
   586  */
       
   587 void CSmfCredMgrDbUser::readFlagInPluginIdTable(const TDesC& aPluginID,
       
   588 		TInt& aFlag)
       
   589 	{
       
   590 	TInt err(KErrNone);
       
   591 
       
   592 	RSqlStatement sqlReadStatement;
       
   593 	TInt paramIndex(KErrNone);
       
   594 
       
   595 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadFlagInPluginTable);
       
   596 
       
   597 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   598 	err = sqlReadStatement.BindText(paramIndex, aPluginID);
       
   599 
       
   600 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   601 		{
       
   602 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   603 		if (!sqlReadStatement.IsNull(0))
       
   604 			{
       
   605 			aFlag = sqlReadStatement.ColumnInt(0);
       
   606 			}
       
   607 		}
       
   608 	sqlReadStatement.Close();
       
   609 	}
       
   610 
       
   611 
       
   612 
       
   613 /**
       
   614  * Method to change a plugin id in plugin Id table
       
   615  * @param aNewPluginID The ID of the new plugin
       
   616  * @param aFlag The flag that indicates the plugin id is enables or disabled
       
   617  * @param aOldPluginID The ID of the plugin to be replaced
       
   618  * @return Returns KErrNone if success. Refer ESqlDbError and system-wide 
       
   619  * error codes for detailed error description.
       
   620  */
       
   621 TInt CSmfCredMgrDbUser::updatePlugin(const TDesC& aPluginID,
       
   622 		const TBool& aFlag, const TDesC& aOldPluginID)
       
   623 	{
       
   624 	TInt err(KErrNone);
       
   625 	RSqlStatement sqlStatement;
       
   626 	TInt paramIndex(KErrNone);
       
   627 	TBuf<KMaxBufSize> newPluginBuf(aPluginID);
       
   628 	TBuf<KMaxBufSize> OldPluginBuf(aOldPluginID);
       
   629 	RSqlDatabase db;
       
   630 
       
   631 	err = db.Open(iDbFilePathName);
       
   632 	__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   633 
       
   634 	err = sqlStatement.Prepare(db, KUpdatePluginID);
       
   635 
       
   636 	paramIndex = sqlStatement.ParameterIndex(_L(":iText"));
       
   637 	err = sqlStatement.BindText(paramIndex, newPluginBuf);
       
   638 
       
   639 	paramIndex = sqlStatement.ParameterIndex(_L(":iFlag"));
       
   640 	err = sqlStatement.BindInt(paramIndex, aFlag);
       
   641 
       
   642 	paramIndex = sqlStatement.ParameterIndex(_L(":iID"));
       
   643 	err = sqlStatement.BindText(paramIndex, OldPluginBuf);
       
   644 
       
   645 	err = db.Exec(KBegin);
       
   646 	__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   647 	err = sqlStatement.Exec();
       
   648 	if (KSqlErrConstraint == err)
       
   649 		{
       
   650 		//
       
   651 		}
       
   652 	else if (err < KErrNone)
       
   653 		{
       
   654 		__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   655 		}
       
   656 
       
   657 	err = db.Exec(KCommit);
       
   658 	__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   659 
       
   660 	//if commit fails we have to roll back
       
   661 	if (err < KErrNone)
       
   662 		{
       
   663 		err = db.Exec(KRollback);
       
   664 		}
       
   665 	sqlStatement.Close();
       
   666 	db.Close();
       
   667 	if (err >= 0)
       
   668 		{
       
   669 		return KErrNone;
       
   670 		}
       
   671 	return err;
       
   672 	}
       
   673 
       
   674 /**
       
   675  * Method to fetch the list of plugin ids associated with Authentication App id, 
       
   676  * it is called internally by fetchPluginList().
       
   677  * @param aAuthAppId ID of the Authentication app
       
   678  * @param aArray [out] The array to be updated with plugin ids 
       
   679  */
       
   680 void CSmfCredMgrDbUser::readPluginIdL(const TDesC& aAuthAppId, RPointerArray<
   427 		HBufC>& aArray)
   681 		HBufC>& aArray)
   428 	{
   682 	{
   429 	TInt err(KErrNone);
   683 	TInt err(KErrNone);
   430 	RSqlStatement sqlReadStatement;
   684 	RSqlStatement sqlReadStatement;
   431 	TInt paramIndex(KErrNone);
   685 	TInt paramIndex(KErrNone);
   455 			__ASSERT_DEBUG( 0, User::Invariant());
   709 			__ASSERT_DEBUG( 0, User::Invariant());
   456 			}
   710 			}
   457 		}
   711 		}
   458 	sqlReadStatement.Close();
   712 	sqlReadStatement.Close();
   459 	}
   713 	}
   460 
       
   461 void CSmfCredMgrDbUser::readURL(const TDesC& aAuthAppId,
       
   462 		RPointerArray<HBufC>& aArray)
       
   463 	{
       
   464 	TInt err(KErrNone);
       
   465 
       
   466 	RSqlStatement sqlReadStatement;
       
   467 	TInt paramIndex(KErrNone);
       
   468 
       
   469 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadURL);
       
   470 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   471 	err = sqlReadStatement.BindText(paramIndex, aAuthAppId);
       
   472 
       
   473 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   474 		{
       
   475 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   476 		if (!sqlReadStatement.IsNull(0))
       
   477 			{
       
   478 			TBuf<KMaxBufSize> urlBuf;
       
   479 			HBufC* buf = HBufC::NewL(KMaxBufSize);
       
   480 			sqlReadStatement.ColumnText(0, urlBuf);
       
   481 			buf->Des().Copy(urlBuf);
       
   482 			aArray.Append(buf);
       
   483 			}
       
   484 		else
       
   485 			{
       
   486 			__ASSERT_DEBUG( 0, User::Invariant());
       
   487 			}
       
   488 		}
       
   489 	sqlReadStatement.Close();
       
   490 	}
       
   491 
       
   492 void CSmfCredMgrDbUser::readValidity(const TDesC& aAuthAppId, TInt64& aValidity)
       
   493 	{
       
   494 	TInt err(KErrNone);
       
   495 
       
   496 	RSqlStatement sqlReadStatement;
       
   497 	TInt paramIndex(KErrNone);
       
   498 
       
   499 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadValidity);
       
   500 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   501 	err = sqlReadStatement.BindText(paramIndex, aAuthAppId);
       
   502 
       
   503 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   504 		{
       
   505 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   506 		if (!sqlReadStatement.IsNull(0))
       
   507 			{
       
   508 			aValidity = sqlReadStatement.ColumnInt64(1);
       
   509 			}
       
   510 		else
       
   511 			{
       
   512 			__ASSERT_DEBUG( 0, User::Invariant());
       
   513 			}
       
   514 		}
       
   515 	sqlReadStatement.Close();
       
   516 
       
   517 	}
       
   518 
       
   519 void CSmfCredMgrDbUser::readRegistrationToken(const TDesC& aAuthAppId,
       
   520 		TDesC& aRegToken)
       
   521 	{
       
   522 	TInt err(KErrNone);
       
   523 
       
   524 	RSqlStatement sqlReadStatement;
       
   525 	TInt paramIndex(KErrNone);
       
   526 
       
   527 	err = sqlReadStatement.Prepare(iDataBase, KSmfDbReadRegistrationToken);
       
   528 	paramIndex = sqlReadStatement.ParameterIndex(_L(":iID"));
       
   529 	err = sqlReadStatement.BindText(paramIndex, aAuthAppId);
       
   530 
       
   531 	while ((err = sqlReadStatement.Next()) == KSqlAtRow)
       
   532 		{
       
   533 		//sometimes sqlStmt.Next returns KSqlAtRow even if no row is present
       
   534 		if (!sqlReadStatement.IsNull(0))
       
   535 			{
       
   536 			aRegToken = sqlReadStatement.ColumnTextL(0);//aKey.AllocL();
       
   537 			}
       
   538 		else
       
   539 			{
       
   540 			__ASSERT_DEBUG( 0, User::Invariant());
       
   541 			}
       
   542 		}
       
   543 	sqlReadStatement.Close();
       
   544 	}
       
   545 
       
   546 TInt CSmfCredMgrDbUser::updatePlugin(const TDesC& aPluginID,
       
   547 		const TBool& aFlag, const TDesC& aOldPluginID)
       
   548 	{
       
   549 	TInt err(KErrNone);
       
   550 	RSqlStatement sqlStatement;
       
   551 	TInt paramIndex(KErrNone);
       
   552 	TBuf<KMaxBufSize> newPluginBuf(aPluginID);
       
   553 	TBuf<KMaxBufSize> OldPluginBuf(aOldPluginID);
       
   554 	RSqlDatabase db;
       
   555 
       
   556 	err = db.Open(iDbFilePathName);
       
   557 	__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   558 
       
   559 	err = sqlStatement.Prepare(db, KUpdatePluginID);
       
   560 
       
   561 	paramIndex = sqlStatement.ParameterIndex(_L(":iText"));
       
   562 	err = sqlStatement.BindText(paramIndex, newPluginBuf);
       
   563 
       
   564 	paramIndex = sqlStatement.ParameterIndex(_L(":iFlag"));
       
   565 	err = sqlStatement.BindInt(paramIndex, aFlag);
       
   566 
       
   567 	paramIndex = sqlStatement.ParameterIndex(_L(":iID"));
       
   568 	err = sqlStatement.BindText(paramIndex, OldPluginBuf);
       
   569 
       
   570 	err = db.Exec(KBegin);
       
   571 	__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   572 	err = sqlStatement.Exec();
       
   573 	if (KSqlErrConstraint == err)
       
   574 		{
       
   575 		//
       
   576 		}
       
   577 	else if (err < KErrNone)
       
   578 		{
       
   579 		__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   580 		}
       
   581 
       
   582 	err = db.Exec(KCommit);
       
   583 	__ASSERT_DEBUG( (err >= KErrNone), User::Invariant());
       
   584 
       
   585 	//if commit fails we have to roll back
       
   586 	if (err < KErrNone)
       
   587 		{
       
   588 		err = db.Exec(KRollback);
       
   589 		}
       
   590 	sqlStatement.Close();
       
   591 	db.Close();
       
   592 	if (err >= 0)
       
   593 		{
       
   594 		return KErrNone;
       
   595 		}
       
   596 	return err;
       
   597 	}