apengine/apeng/src/ApProtHandler.cpp
changeset 0 5a93021fdf25
child 8 2e6c4614c58e
child 18 fcbbe021d614
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Declaration of the CApProtHandler class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <cdbcols.h>
       
    21 #include <commdb.h>
       
    22 #include <ApEngineConsts.h>
       
    23 
       
    24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    25 #include <ProtectDb.h>
       
    26 #include <ProtectcpDb.h>
       
    27 #else
       
    28 #include <comms-infras/commdb/protection/protectdb.h>
       
    29 #include <comms-infras/commdb/protection/protectcpdb.h>
       
    30 #endif
       
    31 
       
    32 #include <ApProtHandler.h>
       
    33 #include <ApListItem.h>
       
    34 #include <ApListItemList.h>
       
    35 #include <ApDataHandler.h>
       
    36 #include <ApSelect.h>
       
    37 
       
    38 #include "ApEngineCommons.h"
       
    39 #include "APEngineVariant.hrh"
       
    40 #include "ApEngineLogger.h"
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // ---------------------------------------------------------
       
    45 // CApProtHandler::IsTableProtectedL
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 EXPORT_C TBool CApProtHandler::IsTableProtectedL( CCommsDatabase* aDb )
       
    49     {
       
    50     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::IsTableProtectedL" ) ) );
       
    51 
       
    52     TBool retval( EFalse );
       
    53     retval = IsTableProtectedL( aDb, TPtrC(WAP_ACCESS_POINT) );
       
    54 
       
    55     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::IsTableProtectedL" ) ) );
       
    56     return retval;
       
    57     }
       
    58 
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CApProtHandler::IsApProtectedL
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 EXPORT_C TBool CApProtHandler::IsApProtectedL( CCommsDatabase* aDb,
       
    65                                                      TUint32 aUid )
       
    66     {
       
    67     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::IsApProtectedL" ) ) );
       
    68 
       
    69     TBool retval( EFalse );
       
    70     retval = IsRecordProtectedL( aDb, TPtrC(WAP_ACCESS_POINT), aUid );
       
    71     
       
    72     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::IsApProtectedL" ) ) );
       
    73     return retval;
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CApProtHandler::ProtectItemL
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 EXPORT_C void CApProtHandler::ProtectItemL( CCommsDatabase* aDb,
       
    82                                              TUint32 aUid )
       
    83     {
       
    84     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::ProtectItemL" ) ) );
       
    85 
       
    86     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
    87         {
       
    88         User::Leave( KErrNotSupported );
       
    89         }
       
    90 #ifdef __TEST_CDMA_WRITE_PROTECT
       
    91     User::Leave( KErrNotSupported );
       
    92 #endif // __TEST_CDMA_WRITE_PROTECT
       
    93 
       
    94     ProtectRecordL( aDb, TPtrC(WAP_ACCESS_POINT), aUid );
       
    95     
       
    96     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::ProtectItemL" ) ) );
       
    97     }
       
    98 
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CApProtHandler::UnprotectItemL
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 EXPORT_C void CApProtHandler::UnprotectItemL( CCommsDatabase* aDb,
       
   105                                                TUint32 aUid )
       
   106     {
       
   107     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::UnprotectItemL" ) ) );
       
   108 
       
   109     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   110         {
       
   111         User::Leave( KErrNotSupported );
       
   112         }
       
   113 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   114     User::Leave( KErrNotSupported );
       
   115 #endif // __TEST_CDMA_WRITE_PROTECT
       
   116 
       
   117     UnprotectRecordL( aDb, TPtrC(WAP_ACCESS_POINT), aUid );
       
   118     
       
   119     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::UnprotectItemL" ) ) );
       
   120     }
       
   121 
       
   122 
       
   123 
       
   124 // ---------------------------------------------------------
       
   125 // CApProtHandler::ProtectTableL
       
   126 // ---------------------------------------------------------
       
   127 //
       
   128 EXPORT_C void CApProtHandler::ProtectTableL( CCommsDatabase* aDb )
       
   129     {
       
   130     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::ProtectTableL" ) ) );
       
   131 
       
   132     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   133         {
       
   134         User::Leave( KErrNotSupported );
       
   135         }
       
   136 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   137     User::Leave( KErrNotSupported );
       
   138 #endif // __TEST_CDMA_WRITE_PROTECT
       
   139 
       
   140     ProtectTableL( aDb, TPtrC(WAP_ACCESS_POINT) );
       
   141     
       
   142     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::ProtectTableL" ) ) );
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------
       
   147 // CApProtHandler::UnprotectTableL
       
   148 // ---------------------------------------------------------
       
   149 //
       
   150 EXPORT_C void CApProtHandler::UnprotectTableL( CCommsDatabase* aDb )
       
   151     {
       
   152     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::UnprotectTableL" ) ) );
       
   153 
       
   154     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   155         {
       
   156         User::Leave( KErrNotSupported );
       
   157         }
       
   158 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   159     User::Leave( KErrNotSupported );
       
   160 #endif // __TEST_CDMA_WRITE_PROTECT
       
   161 
       
   162     UnprotectTableL( aDb, TPtrC(WAP_ACCESS_POINT) );
       
   163 
       
   164     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::UnprotectTableL" ) ) );
       
   165     }
       
   166 
       
   167 
       
   168 // ---------------------------------------------------------
       
   169 // CApProtHandler::IsPreferencesProtectedL
       
   170 // ---------------------------------------------------------
       
   171 //
       
   172 EXPORT_C TBool CApProtHandler::IsPreferencesProtectedL( CCommsDatabase* aDb )
       
   173     {
       
   174     CLOG( ( EProtection, 0, 
       
   175         _L( "-> CApProtHandler::IsPreferencesProtectedL" ) ) );
       
   176 
       
   177     CCommsDatabase* db = aDb;
       
   178     if ( !aDb )
       
   179         {
       
   180         // create DB object
       
   181         db = CCommsDatabase::NewL( ETrue );
       
   182         CleanupStack::PushL( db );
       
   183         }
       
   184 
       
   185     CCommsDbProtectConnectPrefTableView* table = 
       
   186         STATIC_CAST( CCommsDbProtectConnectPrefTableView*, 
       
   187                      db->OpenConnectionPrefTableLC());
       
   188 
       
   189     TInt err = table->GotoFirstRecord();
       
   190     if ( err != KErrNotFound )
       
   191         {
       
   192         User::LeaveIfError( err );
       
   193         }
       
   194 
       
   195     RDbRowSet::TAccess access;
       
   196     User::LeaveIfError( table->GetTableAccess( access ) ); 
       
   197     CleanupStack::PopAndDestroy( table ); 
       
   198     if ( !aDb )
       
   199         {
       
   200         CleanupStack::PopAndDestroy( db ); //db
       
   201         }
       
   202     
       
   203     //access is EUpdatable if record is updatable
       
   204     TBool retval( !(access == RDbRowSet::EUpdatable) );
       
   205 
       
   206     CLOG( ( EProtection, 1, 
       
   207         _L( "<- CApProtHandler::IsPreferencesProtectedL" ) ) );
       
   208     return retval;
       
   209     }
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CApProtHandler::ProtectPreferencesL
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 EXPORT_C void CApProtHandler::ProtectPreferencesL( CCommsDatabase* aDb )
       
   217     {
       
   218     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::ProtectPreferencesL" ) ) );
       
   219 
       
   220     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   221         {
       
   222         User::Leave( KErrNotSupported );
       
   223         }
       
   224 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   225     User::Leave( KErrNotSupported );
       
   226 #endif // __TEST_CDMA_WRITE_PROTECT
       
   227 
       
   228     CCommsDatabase* db = aDb;
       
   229     if ( !aDb )
       
   230         {
       
   231         // create DB object
       
   232         db = CCommsDatabase::NewL( ETrue );
       
   233         CleanupStack::PushL( db );
       
   234         }
       
   235 
       
   236     CCommsDbProtectConnectPrefTableView* table = 
       
   237         STATIC_CAST( CCommsDbProtectConnectPrefTableView*, 
       
   238                      db->OpenConnectionPrefTableLC());
       
   239 
       
   240     User::LeaveIfError( table->GotoFirstRecord() );
       
   241     User::LeaveIfError( table->ProtectTable() );
       
   242     
       
   243     CleanupStack::PopAndDestroy( table ); 
       
   244 
       
   245     if ( !aDb )
       
   246         {
       
   247         CleanupStack::PopAndDestroy( db ); //db
       
   248         }
       
   249 
       
   250     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::ProtectPreferencesL" ) ) );
       
   251     }
       
   252 
       
   253 
       
   254 
       
   255 // ---------------------------------------------------------
       
   256 // CApProtHandler::UnprotectPreferencesL
       
   257 // ---------------------------------------------------------
       
   258 //
       
   259 EXPORT_C void CApProtHandler::UnprotectPreferencesL( CCommsDatabase* aDb )
       
   260     {
       
   261     CLOG( ( EProtection, 0, 
       
   262         _L( "-> CApProtHandler::UnprotectPreferencesL" ) ) );
       
   263 
       
   264     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   265         {
       
   266         User::Leave( KErrNotSupported );
       
   267         }
       
   268 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   269     User::Leave( KErrNotSupported );
       
   270 #endif // __TEST_CDMA_WRITE_PROTECT
       
   271 
       
   272     CCommsDatabase* db = aDb;
       
   273     if ( !aDb )
       
   274         {
       
   275         // create DB object
       
   276         db = CCommsDatabase::NewL( ETrue );
       
   277         CleanupStack::PushL( db );
       
   278         }
       
   279     CCommsDbProtectConnectPrefTableView* table = 
       
   280         STATIC_CAST( CCommsDbProtectConnectPrefTableView*, 
       
   281                      db->OpenConnectionPrefTableLC());
       
   282 
       
   283     User::LeaveIfError( table->GotoFirstRecord() );
       
   284     User::LeaveIfError( table->UnprotectTable() );
       
   285     
       
   286     CleanupStack::PopAndDestroy( table );
       
   287     if ( !aDb )
       
   288         {
       
   289         CleanupStack::PopAndDestroy( db ); //db
       
   290         }
       
   291     
       
   292     CLOG( ( EProtection, 1, 
       
   293         _L( "<- CApProtHandler::UnprotectPreferencesL" ) ) );
       
   294     }
       
   295 
       
   296 
       
   297 
       
   298 // ---------------------------------------------------------
       
   299 // CApProtHandler::RemoveProtectedAccessPointsL
       
   300 // ---------------------------------------------------------
       
   301 //
       
   302 EXPORT_C void CApProtHandler::RemoveProtectedAccessPointsL(
       
   303                                           CCommsDatabase* aDb)
       
   304     {
       
   305     CLOG( ( EProtection, 0, 
       
   306         _L( "-> CApProtHandler::RemoveProtectedAccessPointsL" ) ) );
       
   307 
       
   308     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   309         {
       
   310         User::Leave( KErrNotSupported );
       
   311         }
       
   312 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   313     User::Leave( KErrNotSupported );
       
   314 #endif // __TEST_CDMA_WRITE_PROTECT
       
   315 
       
   316     CCommsDatabase* db;
       
   317     if ( !aDb )
       
   318         {
       
   319         // create DB object
       
   320         db = CCommsDatabase::NewL( ETrue );
       
   321         CleanupStack::PushL( db );
       
   322         }
       
   323     else
       
   324         {
       
   325         db = aDb;
       
   326         }
       
   327     DoRemoveProtectedAccessPointsL( *db );
       
   328 
       
   329     if ( !aDb )
       
   330         {
       
   331         CleanupStack::PopAndDestroy( db ); // db
       
   332         }
       
   333 
       
   334     CLOG( ( EProtection, 1, 
       
   335         _L( "<- CApProtHandler::RemoveProtectedAccessPointsL" ) ) );
       
   336     }
       
   337 
       
   338 // ================== OTHER MEMBER FUNCTIONS ===============
       
   339 
       
   340 
       
   341 
       
   342 
       
   343 
       
   344 // ---------------------------------------------------------
       
   345 // CApProtHandler::IsRecordProtectedL
       
   346 // ---------------------------------------------------------
       
   347 //
       
   348 TBool CApProtHandler::IsRecordProtectedL( CCommsDatabase* aDb,
       
   349                                             const TDesC& aTable,
       
   350                                             TUint32 aUid )
       
   351     {
       
   352     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::IsRecordProtectedL" ) ) );
       
   353 
       
   354     CCommsDatabase* db = aDb;
       
   355     if ( !aDb )
       
   356         {
       
   357         // create DB object
       
   358         db = CCommsDatabase::NewL( ETrue );
       
   359         CleanupStack::PushL( db );
       
   360         }
       
   361 
       
   362     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *db, ETrue );
       
   363 
       
   364     CCommsDbProtectTableView* view =
       
   365         (CCommsDbProtectTableView*)db->OpenViewMatchingUintLC
       
   366                                              (
       
   367                                               aTable,
       
   368                                               TPtrC(COMMDB_ID),
       
   369                                               aUid
       
   370                                              );
       
   371 
       
   372     TInt err = view->GotoFirstRecord();
       
   373     User::LeaveIfError( err );
       
   374 
       
   375     TInt prot( EFalse );
       
   376     User::LeaveIfError( view->GetRecordAccess( prot ) );
       
   377 
       
   378     CleanupStack::PopAndDestroy( view ); // view
       
   379 
       
   380     if ( ownTransaction )
       
   381         {
       
   382         ApCommons::CommitTransaction( *db );
       
   383         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   384         }
       
   385 
       
   386     if ( !aDb )
       
   387         {
       
   388         CleanupStack::PopAndDestroy( db ); // db
       
   389         }
       
   390         
       
   391     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::IsRecordProtectedL" ) ) );
       
   392     return prot;
       
   393     }
       
   394 
       
   395 
       
   396 
       
   397 // ---------------------------------------------------------
       
   398 // CApProtHandler::ProtectRecordL
       
   399 // ---------------------------------------------------------
       
   400 //
       
   401 void CApProtHandler::ProtectRecordL( CCommsDatabase* aDb,
       
   402                                     const TDesC& aTable, TUint32 aUid )
       
   403     {
       
   404     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::ProtectRecordL" ) ) );
       
   405 
       
   406     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   407         {
       
   408         User::Leave( KErrNotSupported );
       
   409         }
       
   410 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   411     User::Leave( KErrNotSupported );
       
   412 #endif // __TEST_CDMA_WRITE_PROTECT
       
   413 
       
   414     CCommsDatabase* db = aDb;
       
   415     if ( !aDb )
       
   416         {
       
   417         // create DB object
       
   418         db = CCommsDatabase::NewL( ETrue );
       
   419         CleanupStack::PushL( db );
       
   420         }
       
   421     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *db, ETrue );
       
   422 
       
   423     CCommsDbProtectTableView* view =
       
   424         (CCommsDbProtectTableView*)db->OpenViewMatchingUintLC
       
   425                                                 (
       
   426                                                  aTable,
       
   427                                                  TPtrC(COMMDB_ID),
       
   428                                                  aUid
       
   429                                                 );
       
   430 
       
   431     TInt err = view->GotoFirstRecord();
       
   432     User::LeaveIfError( err );
       
   433 
       
   434     User::LeaveIfError( view->ProtectRecord() );
       
   435 
       
   436     CleanupStack::PopAndDestroy( view ); // view
       
   437 
       
   438     if ( ownTransaction )
       
   439         {
       
   440         ApCommons::CommitTransaction( *db );
       
   441         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   442         }
       
   443 
       
   444     if ( !aDb )
       
   445         {
       
   446         CleanupStack::PopAndDestroy( db ); // db
       
   447         }
       
   448     
       
   449     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::ProtectRecordL" ) ) );
       
   450     }
       
   451 
       
   452 
       
   453 
       
   454 // ---------------------------------------------------------
       
   455 // CApProtHandler::UnprotectRecordL
       
   456 // ---------------------------------------------------------
       
   457 //
       
   458 void CApProtHandler::UnprotectRecordL( CCommsDatabase* aDb,
       
   459                                       const TDesC& aTable, TUint32 aUid )
       
   460     {
       
   461     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::UnprotectRecordL" ) ) );
       
   462 
       
   463     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   464         {
       
   465         User::Leave( KErrNotSupported );
       
   466         }
       
   467 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   468     User::Leave( KErrNotSupported );
       
   469 #endif // __TEST_CDMA_WRITE_PROTECT
       
   470 
       
   471     CCommsDatabase* db = aDb;
       
   472     if ( !aDb )
       
   473         {
       
   474         // create DB object
       
   475         db = CCommsDatabase::NewL( ETrue );
       
   476         CleanupStack::PushL( db );
       
   477         }
       
   478     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *db, ETrue );
       
   479 
       
   480     CCommsDbProtectTableView* view =
       
   481         (CCommsDbProtectTableView*)db->OpenViewMatchingUintLC
       
   482                                              (
       
   483                                               aTable,
       
   484                                               TPtrC(COMMDB_ID),
       
   485                                               aUid
       
   486                                              );
       
   487 
       
   488     TInt err = view->GotoFirstRecord();
       
   489     User::LeaveIfError( err );
       
   490 
       
   491     User::LeaveIfError( view->UnprotectRecord() );
       
   492 
       
   493     CleanupStack::PopAndDestroy( view ); // view
       
   494 
       
   495     if ( ownTransaction )
       
   496         {
       
   497         ApCommons::CommitTransaction( *db );
       
   498         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   499         }
       
   500 
       
   501     if ( !aDb )
       
   502         {
       
   503         CleanupStack::PopAndDestroy( db ); // db
       
   504         }
       
   505 
       
   506     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::UnprotectRecordL" ) ) );
       
   507     }
       
   508 
       
   509 
       
   510 
       
   511 
       
   512 // ---------------------------------------------------------
       
   513 // CApProtHandler::IsTableProtectedL
       
   514 // ---------------------------------------------------------
       
   515 //
       
   516 TBool CApProtHandler::IsTableProtectedL( CCommsDatabase* aDb,
       
   517                                                const TDesC& aTable )
       
   518     {
       
   519     CLOG( ( EProtection, 0, 
       
   520         _L( "-> CApProtHandler::IsTableProtectedL(table)" ) ) );
       
   521 
       
   522     TBool retval( EFalse );
       
   523     CCommsDatabase* db = aDb;
       
   524     if ( !aDb )
       
   525         {
       
   526         // create DB object
       
   527         db = CCommsDatabase::NewL( ETrue );
       
   528         CleanupStack::PushL( db );
       
   529         }
       
   530     TBool ownTransaction = ApCommons::StartPushedTransactionLC( *db, ETrue );
       
   531 
       
   532     CCommsDbProtectTableView* view =
       
   533         (CCommsDbProtectTableView*)db->OpenTableLC( aTable );
       
   534 
       
   535     RDbRowSet::TAccess aAccessType( RDbRowSet::EUpdatable );
       
   536     
       
   537     User::LeaveIfError( view->GetTableAccess( aAccessType) );
       
   538     
       
   539     if ( aAccessType == RDbRowSet::EUpdatable )
       
   540         {
       
   541         retval = EFalse;
       
   542         }
       
   543     else
       
   544         { // EReadOnly, EInsertOnly
       
   545         retval = ETrue;
       
   546         }
       
   547 
       
   548     CleanupStack::PopAndDestroy( view ); // view
       
   549 
       
   550     if ( ownTransaction )
       
   551         {
       
   552         ApCommons::CommitTransaction( *db );
       
   553         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   554         }
       
   555 
       
   556     if ( !aDb )
       
   557         {
       
   558         CleanupStack::PopAndDestroy( db ); // db
       
   559         }
       
   560     
       
   561     CLOG( ( EProtection, 1, 
       
   562         _L( "<- CApProtHandler::IsTableProtectedL(table)" ) ) );
       
   563     return retval;
       
   564     }
       
   565 
       
   566 
       
   567 // ---------------------------------------------------------
       
   568 // CApProtHandler::ProtectTableL
       
   569 // ---------------------------------------------------------
       
   570 //
       
   571 void CApProtHandler::ProtectTableL( CCommsDatabase* aDb,
       
   572                                      const TDesC& aTable )
       
   573     {
       
   574     CLOG( ( EProtection, 0, 
       
   575         _L( "-> CApProtHandler::ProtectTableL(table)" ) ) );
       
   576 
       
   577     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   578         {
       
   579         User::Leave( KErrNotSupported );
       
   580         }
       
   581 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   582     User::Leave( KErrNotSupported );
       
   583 #endif // __TEST_CDMA_WRITE_PROTECT
       
   584 
       
   585     CCommsDatabase* db = aDb;
       
   586     if ( !aDb )
       
   587         {
       
   588         // create DB object
       
   589         db = CCommsDatabase::NewL( ETrue );
       
   590         CleanupStack::PushL( db );
       
   591         }
       
   592 
       
   593     CCommsDbProtectTableView* view =
       
   594         (CCommsDbProtectTableView*)db->OpenTableLC( aTable );
       
   595 
       
   596     TInt err = view->GotoFirstRecord();
       
   597     User::LeaveIfError( err );
       
   598 
       
   599     User::LeaveIfError( view->ProtectTable() );
       
   600 
       
   601     CleanupStack::PopAndDestroy( view ); // view
       
   602 
       
   603     if ( !aDb )
       
   604         {
       
   605         CleanupStack::PopAndDestroy( db ); //db
       
   606         }
       
   607 
       
   608     CLOG( ( EProtection, 1, 
       
   609         _L( "<- CApProtHandler::ProtectTableL(table)" ) ) );
       
   610     }
       
   611 
       
   612 
       
   613 
       
   614 // ---------------------------------------------------------
       
   615 // CApProtHandler::UnprotectTableL
       
   616 // ---------------------------------------------------------
       
   617 //
       
   618 void CApProtHandler::UnprotectTableL( CCommsDatabase* aDb,
       
   619                                        const TDesC& aTable )
       
   620     {
       
   621     CLOG( ( EProtection, 0, 
       
   622         _L( "-> CApProtHandler::UnprotectTableL(table)" ) ) );
       
   623 
       
   624     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   625         {
       
   626         User::Leave( KErrNotSupported );
       
   627         }
       
   628 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   629     User::Leave( KErrNotSupported );
       
   630 #endif // __TEST_CDMA_WRITE_PROTECT
       
   631 
       
   632     CCommsDatabase* db = aDb;
       
   633     if ( !aDb )
       
   634         {
       
   635         // create DB object
       
   636         db = CCommsDatabase::NewL( ETrue );
       
   637         CleanupStack::PushL( db );
       
   638         }
       
   639 //    Follow related error rep. and act accordingly:
       
   640 //    JBAH-58FCHH
       
   641 //    TBool ownTransaction = ApCommons::StartPushedTransactionLC( *db, ETrue );
       
   642 
       
   643     CCommsDbProtectTableView* view =
       
   644         (CCommsDbProtectTableView*)db->OpenTableLC( aTable );
       
   645 
       
   646 
       
   647     TInt err = view->GotoFirstRecord();
       
   648     // If not found, no problem, Unprotect will be carried out correctly
       
   649     // But if no GotoFirstRecord, and no records, it will Panic...
       
   650     if ( err != KErrNotFound )
       
   651         {
       
   652         User::LeaveIfError( err );
       
   653         }
       
   654 
       
   655     User::LeaveIfError( view->UnprotectTable() );
       
   656 
       
   657     CleanupStack::PopAndDestroy( view ); // view
       
   658 
       
   659 
       
   660 /*
       
   661     if ( ownTransaction )
       
   662         {
       
   663         ApCommons::CommitTransaction( *db );
       
   664         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   665         }
       
   666 */
       
   667     if ( !aDb )
       
   668         {
       
   669         CleanupStack::PopAndDestroy( db ); // db
       
   670         }
       
   671 
       
   672     CLOG( ( EProtection, 1, 
       
   673         _L( "<- CApProtHandler::UnprotectTableL(table)" ) ) );
       
   674     }
       
   675 
       
   676 
       
   677 // ---------------------------------------------------------
       
   678 // CApProtHandler::GetProtectionStateL
       
   679 // ---------------------------------------------------------
       
   680 //
       
   681 TBool CApProtHandler::GetProtectionStateL( CCommsDbTableView& aTable )
       
   682     {
       
   683     CLOG( ( EProtection, 0, _L( "-> CApProtHandler::GetProtectionStateL" ) ) );
       
   684 
       
   685     TInt aAccess( 0 );
       
   686     User::LeaveIfError(
       
   687         ( (CCommsDbProtectTableView*) &aTable )->GetRecordAccess( aAccess ) );
       
   688     
       
   689     CLOG( ( EProtection, 1, _L( "<- CApProtHandler::GetProtectionStateL" ) ) );
       
   690     return aAccess;
       
   691     }
       
   692 
       
   693 
       
   694 
       
   695 // ---------------------------------------------------------
       
   696 // CApProtHandler::DoRemoveProtectedAccessPointsL
       
   697 // ---------------------------------------------------------
       
   698 //
       
   699 void CApProtHandler::DoRemoveProtectedAccessPointsL(
       
   700                                           CCommsDatabase& aDb)
       
   701     {
       
   702     CLOG( ( EProtection, 0, 
       
   703         _L( "-> CApProtHandler::DoRemoveProtectedAccessPointsL" ) ) );
       
   704 
       
   705     if ( ApCommons::GetVariantL() & KApUiEditOnlyVPNs )
       
   706         {
       
   707         User::Leave( KErrNotSupported );
       
   708         }
       
   709 #ifdef __TEST_CDMA_WRITE_PROTECT
       
   710     User::Leave( KErrNotSupported );
       
   711 #endif // __TEST_CDMA_WRITE_PROTECT
       
   712 
       
   713     // TRANSACTION STARTING IS REMOVED UNTIL ERROR 
       
   714     // JBAH-58FCHH IS CORRECTED BY SYMBIAN
       
   715     // start a transaction, just to make sure
       
   716 //    TBool ownTransaction = ApCommons::StartPushedTransactionLC( aDb, ETrue );
       
   717     
       
   718     // make AP table updatable
       
   719     UnprotectTableL( &aDb );
       
   720 
       
   721     // remove all protected AP
       
   722     // first get a list of current AP-s
       
   723     CApListItemList* list = new( ELeave )CApListItemList();
       
   724     CleanupStack::PushL( list );
       
   725     CApDataHandler* handler = CApDataHandler::NewLC( aDb );
       
   726     CApSelect* sel = 
       
   727         CApSelect::NewLC( aDb, KEApIspTypeAll, EApBearerTypeAllBearers,
       
   728                          KEApSortNameAscending);
       
   729     sel->AllListItemDataL( *list );
       
   730     // now get protected ones and delete them
       
   731     TInt count( list->Count() );
       
   732     for( TInt i = 0; i<count; i++)
       
   733         {
       
   734         if ( list->At( i )->IsReadOnly() )
       
   735             {
       
   736             UnprotectItemL( &aDb, list->At( i )->Uid() );
       
   737             handler->RemoveAPL( list->At( i )->Uid() );
       
   738             }
       
   739         }
       
   740     CleanupStack::PopAndDestroy( 3, list ); // sel, handler, list
       
   741 
       
   742 /*
       
   743     if ( ownTransaction )
       
   744         {
       
   745         ApCommons::CommitTransaction( *aDb );
       
   746         CleanupStack::Pop(); // RollbackTransactionOnLeave
       
   747         }
       
   748 */
       
   749     
       
   750     CLOG( ( EProtection, 1, 
       
   751         _L( "<- CApProtHandler::DoRemoveProtectedAccessPointsL" ) ) );
       
   752     }
       
   753 
       
   754 
       
   755 //  End of File