smf/smfcredentialmgr/smfcredmgrserver/inc/smfcredmgrdbuser.h
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 header provides a handle to use the data-base operations like insertion, query etc. which
       
    14  *  is used by the Credential Manager Server Sessions to operate on
       
    15  *  Credential Manager Server Database
       
    16  */
       
    17 #ifndef SMFCREDMGRDBUSER_H_
       
    18 #define SMFCREDMGRDBUSER_H_
       
    19 
       
    20 #include <sqldb.h>
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 #include "smfcredmgrserversession.h"
       
    24 
       
    25 //INSERTION
       
    26 _LIT(KBegin , "BEGIN");
       
    27 _LIT(KCommit, "COMMIT");
       
    28 _LIT(KRollback, "ROLLBACK");
       
    29 _LIT(KSmfPluginIDTableInsert, "INSERT INTO PluginIDTable(PluginId, AuthAppId, IsEnabled) VALUES(:Val1, :Val2, :Val3)");
       
    30 _LIT(KSmfURLTableInsert, "INSERT INTO URLTable(AuthAppId, URL) VALUES(:Val1, :Val2)");
       
    31 _LIT(KSmfRegTokenValidityTableInsert, "INSERT INTO RegTokenValidityTable(RegistrationToken, AuthAppId, Validity) VALUES(:Val1, :Val2, :Val3)");
       
    32 _LIT(KSmfAuthParamsTableInsert, "INSERT INTO AuthParamsTable(AuthAppId, AuthKey, AuthSecret) VALUES(:Val1, :Val2, :Val3)");
       
    33 //READ
       
    34 _LIT(KSmfDbReadValidity, "SELECT Validity FROM RegTokenValidityTable WHERE AuthAppId = :iID");
       
    35 _LIT(KSmfDbReadRegistrationToken, "SELECT RegistrationToken FROM RegTokenValidityTable WHERE AuthAppId = :iID");
       
    36 _LIT(KSmfDbReadAuthTokens, "SELECT AuthKey, AuthSecret FROM AuthParamsTable WHERE AuthAppId = :iID");
       
    37 _LIT(KSmfDbReadPluginID, "SELECT PluginId, IsEnabled FROM PluginIDTable WHERE AuthAppId = :iID");
       
    38 _LIT(KSmfDbReadURL, "SELECT URL FROM URLTable WHERE AuthAppId = :iID");
       
    39 _LIT(KSmfDbReadAuthAppIdInPluginTable, "SELECT AuthAppId FROM PluginIDTable WHERE PluginId = :iID");
       
    40 _LIT(KSmfDbReadFlagInPluginTable, "SELECT IsEnabled FROM PluginIDTable WHERE PluginId = :iID");
       
    41 _LIT(KSmfDbReadAuthAppIdInRegTokenTable, "SELECT AuthAppId, Validity FROM RegTokenValidityTable WHERE RegistrationToken = :iID");
       
    42 //UPDATE 
       
    43 _LIT( KUpdatePluginID, "UPDATE PluginIDTable SET PluginId =:iText, IsEnabled =:iFlag WHERE PluginId = :iID");
       
    44 
       
    45 /**
       
    46  * The class to use the server database i.e insert table in Db, query from Db.
       
    47  */
       
    48 class CSmfCredMgrDbUser : public CBase
       
    49 	{
       
    50 public:
       
    51 	/**
       
    52 	 * New functions
       
    53 	 * @param aSession the session object using this class
       
    54 	 */
       
    55 	static CSmfCredMgrDbUser* NewL(CSmfCredMgrServerSession* aSession);
       
    56 	static CSmfCredMgrDbUser* NewLC(CSmfCredMgrServerSession* aSession);
       
    57 
       
    58 	/**
       
    59 	 * Destructor
       
    60 	 */
       
    61 	~CSmfCredMgrDbUser();
       
    62 
       
    63 public:
       
    64 	/**
       
    65 	 * Method to insert PluginIDTable
       
    66 	 * @param aPluginID ID of the plugin 
       
    67 	 * @param aAuthAppId ID of the Authentication app associated with the plugin
       
    68 	 * @param aEnableFlag a flag to indicate if the plugin is enabled, 
       
    69 	 * 	   i.e aEnableFlag =0 for disabled plugin
       
    70 	 */
       
    71 	TInt PluginIDTableInsert(const TDesC& aPluginID, const TDesC& aAuthAppId,
       
    72 			TBool aEnableFlag);
       
    73 
       
    74 	/**
       
    75 	 * Method to insert URLTable
       
    76 	 * @param aAuthAppId ID of the Authentication app associated with the URLs 
       
    77 	 * @param aURL the URL to be stored 
       
    78 	 */
       
    79 	TInt URLTableInsert(const TDesC& aAuthAppId, const TDesC& aURL);
       
    80 
       
    81 	/**
       
    82 	 * Method to insert RegTokenValidityTable
       
    83 	 * @param aRegToken the Registration token for the authentication app 
       
    84 	 * @param aAuthAppId ID of the Authentication app
       
    85 	 * @param aValidity time by which the set will expire 
       
    86 	 */
       
    87 	TInt RegTokenValidityTableInsert(const TDesC& aRegToken,
       
    88 			const TDesC& aAuthAppId, const TUint aValidity);
       
    89 	/**
       
    90 	 * Method to insert AuthParamsTable
       
    91 	 * @param aAuthAppId ID of the Authentication app
       
    92 	 * @param aKey The Key
       
    93 	 * @param aSecret The Secret 
       
    94 	 */
       
    95 	TInt AuthParamsTableInsert(const TDesC& aAuthAppId, const TDesC& aKey,
       
    96 			const TDesC& aSecret);
       
    97 
       
    98 	/**
       
    99 	 * Method to fetch all the plugins associated with the registration token
       
   100 	 * @param aRegToken the Registration token of the authentication app
       
   101 	 * @param aArray The array to be updated with plugin ids 
       
   102 	 */
       
   103 	void fetchPluginList(const TDesC& aRegToken, RPointerArray<HBufC>& aArray);
       
   104 
       
   105 	/**
       
   106 	 * Method to Key-Secret pairs of the Authentication app
       
   107 	 * @param aAuthAppId ID of the Authentication app
       
   108 	 * @param aArray The array containing the key-secret pair
       
   109 	 */
       
   110 	void readAuthTokens(const TDesC& aAuthAppId, RArray<TSmfAuthToken>& aArray);
       
   111 
       
   112 	/**
       
   113 	 * Method to fetch all the URLs associated with the Authentication app
       
   114 	 * @param aAuthAppId ID of the Authentication app
       
   115 	 * @param aArray The array to be updated with URLs 
       
   116 	 */
       
   117 	void readURL(const TDesC& aAuthAppId, RPointerArray<HBufC>& aArray);
       
   118 
       
   119 	/**
       
   120 	 * Method to fetch Validity of the Authentication app
       
   121 	 * @param aAuthAppId ID of the Authentication app
       
   122 	 * @param aValidity time by which the Auth set will expire
       
   123 	 */
       
   124 	void readValidity(const TDesC& aAuthAppId, TInt64& aValidity);
       
   125 
       
   126 	/**
       
   127 	 * Method to fetch Registration token of the Authentication app from RegTokenValidityTable
       
   128 	 * @param aAuthAppId ID of the Authentication app
       
   129 	 * @param aRegToken the Registration token of the authentication app
       
   130 	 */
       
   131 	void readRegistrationToken(const TDesC& aAuthAppId, TDesC& aRegToken);
       
   132 
       
   133 	/**
       
   134 	 * Method to fetch Authentication app ID from RegTokenValidityTable
       
   135 	 * @param aRegToken the Registration token of the authentication app
       
   136 	 * @param aAuthAppId ID of the Authentication app
       
   137 	 */
       
   138 	void readAuthAppIdInRegTokenTable(const TDesC& aRegToken, TDes& aAuthAppId);
       
   139 
       
   140 	/**
       
   141 	 * Method to fetch Authentication app ID from PluginIDTable
       
   142 	 * @param aPluginID the ID of the plugin
       
   143 	 * @param aAuthAppId ID of the Authentication app
       
   144 	 */
       
   145 	void readAuthAppIdInPluginIdTable(const TDesC& aPluginID, TDes& aAuthAppId);
       
   146 
       
   147 	/**
       
   148 	 * Method to read the IsEnabled flag from plugin Id table
       
   149 	 * @param aPluginID the ID of the plugin
       
   150 	 * @param aFlag flag that indicates the plugin id is enables or disabled
       
   151 	 */
       
   152 	void readFlagInPluginIdTable(const TDesC& aPluginID, TInt& aFlag);
       
   153 
       
   154 	/**
       
   155 	 * Method to change a plugin id in plugin Id table
       
   156 	 * @param aNewPluginID the ID of the new plugin
       
   157 	 * @param aFlag flag that indicates the plugin id is enables or disabled
       
   158 	 * @param aOldPluginID the ID of the plugin to be replaced
       
   159 	 */
       
   160 	TInt updatePlugin(const TDesC& aPluginID, const TBool& aFlag,
       
   161 			const TDesC& aOldPluginID);
       
   162 
       
   163 	/**
       
   164 	 * Method to fetch a plugin id associated with Authentication App id, it is 
       
   165 	 * 	called internally by fetchPluginList().
       
   166 	 * @param aAuthAppId ID of the Authentication app
       
   167 	 * @param aArray The array to be updated with plugin ids 
       
   168 	 */
       
   169 	void readPluginId(const TDesC& aAuthAppId, RPointerArray<HBufC>& aArray);
       
   170 
       
   171 private:
       
   172 	/**
       
   173 	 * constructor
       
   174 	 */
       
   175 	CSmfCredMgrDbUser(CSmfCredMgrServerSession* aSession);
       
   176 
       
   177 	/**
       
   178 	 * Two phase constructor
       
   179 	 */
       
   180 	void ConstructL();
       
   181 
       
   182 private:
       
   183 	//data
       
   184 	RFs iFileSession;
       
   185 	TFileName iDbFilePathName;
       
   186 	RSqlDatabase iDataBase;
       
   187 	CSmfCredMgrServerSession* iSession;
       
   188 	};
       
   189 
       
   190 #endif /* SMFCREDMGRDBUSER_H_ */