terminalsecurity/SCP/SCPDatabase/inc/SCPParamDB.h
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 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 "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 #ifndef __CSCPARAMDB_H_
       
    18 #define __CSCPARAMDB_H_
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <e32std.h>
       
    22 #include <badesca.h>
       
    23 #include <e32def.h>
       
    24 #include <e32base.h>
       
    25 #include <f32file.h>
       
    26 #include <d32dbms.h>
       
    27 
       
    28 _LIT(KDatabaseName,             "c:scp.db");
       
    29 _LIT(KTblParameter,             "PARAMETER");
       
    30 _LIT(KColParamId,               "PARAMID");
       
    31 _LIT(KColAppId,                 "APPID");
       
    32 _LIT(KColValueInt,              "VALUEINT");
       
    33 _LIT(KColValueDes,              "VALUEDES");
       
    34 
       
    35 _LIT(KSelectAll,                        "SELECT * FROM PARAMETER");
       
    36 _LIT(KSelectAllAscParamID,               "SELECT * FROM PARAMETER ORDER BY PARAMID ASC");
       
    37 _LIT(KSelectWhereParamId,               "SELECT * FROM PARAMETER WHERE PARAMID=%d");
       
    38 _LIT(KSelectWhereParamIdAppID,          "SELECT * FROM PARAMETER WHERE PARAMID=%d AND APPID=%d");
       
    39 _LIT(KSelectAppIDParamValNotIn,         "SELECT * FROM PARAMETER WHERE NOT APPID=%d AND VALUEDES='%S'");
       
    40 _LIT(KSelectWhereAppId,                 "SELECT * FROM PARAMETER WHERE APPID=%d");
       
    41 _LIT(KSelectWhereAppIdByAscParamID,    "SELECT * FROM PARAMETER WHERE APPID=%d ORDER BY PARAMID ASC");
       
    42 _LIT(KDeleteWhereParamIDValueDes,       "DELETE FROM PARAMETER WHERE PARAMID=%d AND VALUEDES='%S'");
       
    43 _LIT(KDeleteWhereParamIDValueDesAppID,  "DELETE FROM PARAMETER WHERE PARAMID=%d AND VALUEDES='%S' AND APPID=%d");
       
    44 _LIT(KDeleteWhereParamIDAppID,          "DELETE FROM PARAMETER WHERE PARAMID=%d AND APPID=%d");
       
    45 _LIT(KDeleteWhereParamID,               "DELETE FROM PARAMETER WHERE PARAMID=%d");
       
    46 _LIT(KUpdateValIntWhereParamId,         "UPDATE PARAMETER SET APPID=%d, VALUEINT=%d WHERE PARAMID=%d");
       
    47 _LIT(KInsertValInt,                     "INSERT INTO PARAMETER (PARAMID, VALUEINT, APPID) VALUES(%d, %d, %d)");
       
    48 _LIT(KInsertValDes,                     "INSERT INTO PARAMETER (PARAMID, VALUEDES, APPID) VALUES(%d, '%S', %d)");
       
    49 _LIT(KUpdateValDesWhereParamId,         "UPDATE PARAMETER SET APPID=%d, VALUEDES='%S' WHERE PARAMID=%d");
       
    50 _LIT(KCreateTable,                      "CREATE TABLE PARAMETER (PARAMID INTEGER NOT NULL,\
       
    51                                             APPID INTEGER, VALUEINT INTEGER, VALUEDES CHAR(255))");
       
    52 
       
    53 /**
       
    54  *  Database class
       
    55  *
       
    56  *  @lib
       
    57  *  @since
       
    58  */
       
    59 NONSHARABLE_CLASS(CSCPParamDB) : public CBase {
       
    60 public:
       
    61     ~CSCPParamDB();
       
    62     static CSCPParamDB* NewL();
       
    63     static CSCPParamDB* NewLC();
       
    64 
       
    65     /*
       
    66      * Store value for a parameter into the database. The parameter value that can be stored through this function
       
    67      * can only be of type numeric/boolean (The 16 shared parameters excepting EPasscodeClearSpecificStrings, 
       
    68      * EPasscodeDisallowSpecific and EPasscodeAllowSpecific)
       
    69      * 
       
    70      * @Params - aParamID: The Parameter ID 
       
    71      *                     (Has to be one from the enum list, RTerminalControl3rdPartySession :: TTerminalControl3rdPartyMessages)
       
    72      *           aValue: The value of the parameter identified by aParamID
       
    73      *           aApp: The UID of the calling application.
       
    74      * 
       
    75      * @returns -   KErrNone: on successful completion.
       
    76      *              
       
    77      */
       
    78     TInt SetValueForParameterL(TInt aParamID, const TInt32 aValue, const TInt32 aApp);
       
    79     
       
    80     /*
       
    81      * Store values of a literal/string type parameter into the database. Currently the function supports set operations on
       
    82      * only EPasscodeDisallowSpecific
       
    83      * 
       
    84      * @Params - aParamID: The Parameter ID 
       
    85      *                     (Currently it has to be EPasscodeDisallowSpecific, for anything else an KErrNotSupported is returned)
       
    86      *           aParamValues: Multiple values (if any) can be specified through this array.
       
    87      *              NOTE: The values contained in this array has to be cleaned explicitly by the caller. (by a call to ResetAndDestroy())
       
    88      *              
       
    89      *           aApp: The UID of the calling application.
       
    90      *           
       
    91      * @returns -   KErrNone: on successful completion.           
       
    92      */
       
    93 	TInt SetValuesForParameterL(TInt aParamID, const RPointerArray <HBufC>& aParamValues, const TInt32 aApp);
       
    94 
       
    95     /*
       
    96      * Returns the value associated with the parameter ID (The 16 shared parameters excepting EPasscodeClearSpecificStrings, 
       
    97      * EPasscodeDisallowSpecific and EPasscodeAllowSpecific)
       
    98      * 
       
    99      * @Params - aParamID: The Parameter ID 
       
   100      *                     (Has to be one from the enum list, RTerminalControl3rdPartySession :: TTerminalControl3rdPartyMessages)
       
   101      *           aValue: The value of the parameter identified by aParamID
       
   102      *           aApp: The UID of the calling application.
       
   103      *           
       
   104      * @returns -   KErrNone: on successful completion.           
       
   105      */
       
   106     TInt GetValueForParameterL(TInt aParamID, TInt32& aValue, TInt32& aApp);
       
   107     
       
   108     
       
   109     /*
       
   110      * Returns the string/descriptor values associated with the parameter.
       
   111      * 
       
   112      * @Params - aParamID: The Parameter ID 
       
   113      *                     (Currently it has to be EPasscodeDisallowSpecific, for anything else KErrNotSupported is returned)
       
   114      *                     
       
   115      *           aParamValues: Parameter value(s) as an array
       
   116      *              NOTE: The values contained in this array has to be cleaned explicitly by the caller. (by a call to ResetAndDestroy())
       
   117      *              
       
   118      *           aApp: The UID of the calling application.
       
   119      *           
       
   120      * @returns -   KErrNone: on successful completion.
       
   121      * 
       
   122      */
       
   123     TInt GetValuesForParameterL(TInt aParamID, RPointerArray <HBufC>& aParamValues, const TInt32 aApp);
       
   124     
       
   125     /*
       
   126      * Returns the list of applications that have currently set one or more values
       
   127      * 
       
   128      * @Params - aIDArray: Contains the UID's of the applications
       
   129      *           
       
   130      * @returns -   KErrNone: on successful completion.           
       
   131      */    
       
   132     TInt GetApplicationIDListL(RArray <TUid>& aIDArray);
       
   133     
       
   134     /*
       
   135      * This function can be called to check if any of the entries made for the descriptor column matches. The case might arise if 
       
   136      * multiple applications have set 'DisallowString' values that are same. This function can be called before DropValuesL()
       
   137      * to make sure that a shared value is not dropped from the DB.
       
   138      * 
       
   139      * @Params - aParamValue: The parameter value that needs to be checked.
       
   140      *           aApp: The UID of the calling application.
       
   141      *           
       
   142      * @returns - ETrue if the value is shared, EFalse otherwise (EFalse is returned also if the entry is not availble in the DB).
       
   143      */
       
   144     TBool IsParamValueSharedL(HBufC* aParamValue, const TInt32 aApp);
       
   145     
       
   146     /*
       
   147      * Removes all the entries corresponding to the values mentioned in the input array from the DB.
       
   148      * 
       
   149      * @Params - aParamValues: Parameter value(s) that need to be dropped from the DB.
       
   150      * 
       
   151      *           aApp:  The UID of the calling application (Only the entries of this application are dropped).
       
   152      *                  By default, if aApp is not specified, the function drops all the entries that match
       
   153      *                  the values mentioned in the input array.
       
   154      *           
       
   155      * @returns -   KErrNone: on successful completion.
       
   156      * 
       
   157      * NOTE:    The function by default (if aApp=-1) does not check if the value is shared accross multiple applications. As a safer approach, 
       
   158      *          IsParamValueSharedL() can be called on each of the parameter values being passed in the input 
       
   159      *          array before a call to this function.     *          
       
   160      *          If the function leaves, the parameter aParamValues has to be cleaned explicitly by a call to ResetAndDestroy.           
       
   161      * 
       
   162      * Currently this function can be called only to drop values set on EPasscodeDisallowSpecific.
       
   163      */
       
   164     TInt DropValuesL(TInt aParamID, RPointerArray <HBufC>& aParamValues, const TInt32 aApp=-1);
       
   165     
       
   166     /*
       
   167      * Lists the parameters (ID's) that the specified application has set.
       
   168      * 
       
   169      * @Params -    aParamIds: Contains the list of parameter ID's set by the specified application. 
       
   170      *              (All unique parameter ID's is aApp is not specified)
       
   171      * 
       
   172      *              aApp:  The UID of the calling application. (Optional)
       
   173      *           
       
   174      * @returns -   KErrNone: on successful completion.
       
   175      * 
       
   176      */   
       
   177     TInt ListParamsUsedByAppL(RArray <TInt>& aParamIds, const TInt32 aApp=-1);
       
   178     
       
   179     /*
       
   180      * Removes all entries of the parameter for the specified application.
       
   181      * 
       
   182      * @Params - aParamID: ID of the parameter that needs to be dropped.
       
   183      * 
       
   184      *           aApp:  The UID of the calling application (Only the entries of this application are dropped).
       
   185      *                  By default, if aApp is not specified, the function drops all the entries that match
       
   186      *                  the parameter ID.
       
   187      *           
       
   188      * @returns -   KErrNone: on successful completion.
       
   189      * 
       
   190      */   
       
   191     TInt DropValuesL(TInt aParamID, const TInt32 aApp=-1);
       
   192     
       
   193     /*
       
   194      * Provides a dump of all the entries currently available in the DB (For debug purposes only)
       
   195      * 
       
   196      * @Params - aNumCols:  On return, contains values of all the numeric type columns (PARAMID, APPID, VALUEINT) 
       
   197      *                      in column major fashion.
       
   198      *           
       
   199      *           aDesCols: Contains the values of the descriptor column (VALUEDES).
       
   200      * 
       
   201      *           aApp:  The UID of the calling application (Only the entries of this application are listed).
       
   202      *                  By default, if aApp is not specified, the application lists the entire DB)
       
   203      *           
       
   204      * @returns -   KErrNone: on successful completion.
       
   205      * 
       
   206      */
       
   207     TInt ListEntriesL(RArray <TInt32>& aNumCols, RPointerArray <HBufC>& aDesCols, const TInt32 aApp=-1);
       
   208 
       
   209 private:
       
   210     CSCPParamDB() {}
       
   211     void ConstructL();
       
   212 
       
   213     TInt OpenDB();
       
   214 
       
   215 private:
       
   216     RDbs iRdbSession;
       
   217     RDbNamedDatabase iParameterDB;
       
   218     CDbColSet* iColSet;
       
   219     RDbTable iTable;
       
   220 };
       
   221 
       
   222 #endif // __CSCPARAMDB_H_