pushmtm/MtmUtilSrc/PushInitiatorList.cpp
changeset 0 84ad3b177aa3
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     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 the License "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:  The definition of CPushInitiatorList.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "PushInitiatorList.h"
       
    23 #include "PushMtmLog.h"
       
    24 #include "PushMtmUtilPanic.h"
       
    25 #include "WhiteListImporter.h"
       
    26 #include "PushMtmPrivateCRKeys.h"
       
    27 #include <centralrepository.h> 
       
    28 
       
    29 // ================= MEMBER FUNCTIONS =======================
       
    30 
       
    31 // ---------------------------------------------------------
       
    32 // CPushInitiatorList::NewL
       
    33 // ---------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CPushInitiatorList* CPushInitiatorList::NewL()
       
    36     {
       
    37     const TInt KGranularity( 8 );
       
    38     return new (ELeave) CPushInitiatorList( KGranularity );
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CPushInitiatorList::~CPushInitiatorList
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 EXPORT_C CPushInitiatorList::~CPushInitiatorList()
       
    46     {
       
    47     ResetAndDestroy();
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CPushInitiatorList::AddL
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 EXPORT_C TUint32 CPushInitiatorList::AddL
       
    55     ( const CPushInitiator& aPushInitiator )
       
    56     {
       
    57     CPushInitiator* temp = aPushInitiator.AllocLC();
       
    58     TUint32 entryId = AddL( temp );
       
    59     CleanupStack::Pop( temp );
       
    60     return entryId;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CPushInitiatorList::AddL
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 EXPORT_C TUint32 CPushInitiatorList::AddL( CPushInitiator* aPushInitiator )
       
    68     {
       
    69     PUSHLOG_ENTERFN("CPushInitiatorList::AddL")
       
    70 
       
    71     __ASSERT_DEBUG( aPushInitiator, UtilPanic( EPushMtmUtilPanNull ) );
       
    72 
       
    73     TUint32 entryId( ENullInitiatorEntryId );
       
    74 
       
    75     if ( !aPushInitiator )
       
    76         {
       
    77         // Nothing to insert.
       
    78         }
       
    79     else
       
    80         {
       
    81         // Get an ID for the new entry before we insert it to the list if it 
       
    82         // has not set yet:
       
    83         entryId = aPushInitiator->EntryID();
       
    84         if ( entryId == ENullInitiatorEntryId )
       
    85             {
       
    86             entryId = FreeId();
       
    87             // Give this new ID to the new entry:
       
    88             aPushInitiator->SetEntryID( entryId );
       
    89             }
       
    90         __ASSERT_DEBUG( entryId != ENullInitiatorEntryId, 
       
    91                         UtilPanic( EPushMtmUtilPanNull ) );
       
    92         // And append it to the list:
       
    93         AppendL( aPushInitiator );
       
    94         // Set flag that indicates that the list has changed:
       
    95         iPushInitiatorListChanged = ETrue;
       
    96         }
       
    97 
       
    98     PUSHLOG_WRITE_FORMAT(" entryId <%d>",entryId)
       
    99     PUSHLOG_LEAVEFN("CPushInitiatorList::AddL")
       
   100     return entryId;
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------
       
   104 // CPushInitiatorList::At
       
   105 // ---------------------------------------------------------
       
   106 //
       
   107 EXPORT_C CPushInitiator& CPushInitiatorList::At( TInt aIndex ) const
       
   108     {
       
   109     return (CPushInitiator&)
       
   110             (*CArrayPtrFlat<CPushInitiator>::At( aIndex ));
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------
       
   114 // CPushInitiatorList::Delete
       
   115 // ---------------------------------------------------------
       
   116 //
       
   117 EXPORT_C void CPushInitiatorList::Delete( TInt aIndex )
       
   118     {
       
   119     delete &At( aIndex );
       
   120     CArrayPtrFlat<CPushInitiator>::Delete( aIndex );
       
   121     // Set indicator flag.
       
   122     iPushInitiatorListChanged = ETrue;
       
   123     }
       
   124 
       
   125 // ---------------------------------------------------------
       
   126 // CPushInitiatorList::Count
       
   127 // ---------------------------------------------------------
       
   128 //
       
   129 EXPORT_C TInt CPushInitiatorList::Count() const
       
   130     {
       
   131     return CArrayPtrFlat<CPushInitiator>::Count();
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------
       
   135 // CPushInitiatorList::FreeId
       
   136 // ---------------------------------------------------------
       
   137 //
       
   138 TUint32 CPushInitiatorList::FreeId() const
       
   139     {
       
   140     TUint32 largestId( 0 );
       
   141     // Find the largest ID:
       
   142     const TInt count( Count() );
       
   143     for ( TInt i = 0; i < count; ++i )
       
   144         {
       
   145         if ( largestId < At(i).EntryID() )
       
   146             {
       
   147             largestId = At(i).EntryID();
       
   148             }
       
   149         }
       
   150     if ( largestId == KMaxTUint32 )
       
   151         {
       
   152         return 0;
       
   153         }
       
   154 
       
   155     return ( largestId + 1 );
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CPushInitiatorList::Changed
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 TBool CPushInitiatorList::Changed() const
       
   163     {
       
   164     return iPushInitiatorListChanged;
       
   165     }
       
   166 
       
   167 // ---------------------------------------------------------
       
   168 // CPushInitiatorList::ResetChanged
       
   169 // ---------------------------------------------------------
       
   170 //
       
   171 void CPushInitiatorList::ResetChanged()
       
   172     {
       
   173     iPushInitiatorListChanged = EFalse;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------
       
   177 // CPushInitiatorList::ResetAndDestroy
       
   178 // ---------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void CPushInitiatorList::ResetAndDestroy()
       
   181     {
       
   182     CArrayPtrFlat<CPushInitiator>::ResetAndDestroy();
       
   183     // Set indicator flag.
       
   184     iPushInitiatorListChanged = ETrue;
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------
       
   188 // CPushInitiatorList::Find
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 EXPORT_C TInt CPushInitiatorList::Find( const CPushInitiator& aPushInitiator, 
       
   192                                         TInt& aIndex ) const
       
   193     {
       
   194     PUSHLOG_ENTERFN("CPushInitiatorList::Find")
       
   195 
       
   196     TInt ret( KErrNotFound );
       
   197 
       
   198     PUSHLOG_WRITE_FORMAT2(" Searching for: <%S>, <%d>",
       
   199         &aPushInitiator.Addr(),aPushInitiator.Type())
       
   200 
       
   201     const TInt count( Count() );
       
   202     for ( TInt i = 0; i < count; ++i )
       
   203         {
       
   204         PUSHLOG_WRITE_FORMAT2(" Item: <%S>, <%d>",
       
   205                               &At( i ).Addr(),At( i ).Type())
       
   206 
       
   207         if ( At( i ) == aPushInitiator )
       
   208             {
       
   209             // We have found push initiator which is identical with the one 
       
   210             // given in the parameter.
       
   211             PUSHLOG_WRITE(" WL Found!")
       
   212             aIndex = i;
       
   213             ret = KErrNone;
       
   214             break;
       
   215             }
       
   216         }
       
   217 
       
   218     PUSHLOG_LEAVEFN("CPushInitiatorList::Find")
       
   219     return ret;
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------
       
   223 // CPushInitiatorList::operator==
       
   224 // ---------------------------------------------------------
       
   225 //
       
   226 EXPORT_C TBool CPushInitiatorList::operator==
       
   227                                    ( const CPushInitiatorList& aList ) const
       
   228     {
       
   229     TBool equal( EFalse );
       
   230     const TInt count = Count();
       
   231 
       
   232     if ( count == aList.Count() )
       
   233         {
       
   234         TBool inequalFound( EFalse );
       
   235         for ( TInt i = 0; i < count; ++i )
       
   236             {
       
   237             if ( At(i) != aList.At(i) )
       
   238                 {
       
   239                 inequalFound = ETrue;
       
   240                 break;
       
   241                 }
       
   242             }
       
   243         equal = !inequalFound;
       
   244         }
       
   245 
       
   246     return equal;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------
       
   250 // CPushInitiatorList::operator!=
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 EXPORT_C TBool CPushInitiatorList::operator!=
       
   254                                    ( const CPushInitiatorList& aList ) const
       
   255     {
       
   256     return !( *this == aList );
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------
       
   260 // CPushInitiatorList::ExternalizeL
       
   261 // ---------------------------------------------------------
       
   262 //
       
   263 void CPushInitiatorList::ExternalizeL( CRepository& aRepository ) const
       
   264     {
       
   265     PUSHLOG_ENTERFN("CPushInitiatorList::ExternalizeL");
       
   266     
       
   267     HBufC* wlBuf = ParseAndProcessList2BufL();
       
   268     CleanupStack::PushL( wlBuf );
       
   269     User::LeaveIfError( aRepository.Set( KPushMtmWhiteList, *wlBuf ) );
       
   270     CleanupStack::PopAndDestroy( wlBuf ); // wlBuf
       
   271     
       
   272     PUSHLOG_LEAVEFN("CPushInitiatorList::ExternalizeL");
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // CPushInitiatorList::InternalizeL
       
   277 // ---------------------------------------------------------
       
   278 //
       
   279 void CPushInitiatorList::InternalizeL( CRepository& aRepository )
       
   280     {
       
   281     PUSHLOG_ENTERFN("CPushInitiatorList::InternalizeL");
       
   282     
       
   283     HBufC* wlBuf = HBufC::NewLC( NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   284     TPtr nonConstWLBuf = wlBuf->Des();
       
   285     User::LeaveIfError( aRepository.Get( KPushMtmWhiteList, nonConstWLBuf ) );
       
   286     ParseAndProcessBuf2ListL( *wlBuf );
       
   287     CleanupStack::PopAndDestroy( wlBuf ); // wlBuf
       
   288     
       
   289     PUSHLOG_LEAVEFN("CPushInitiatorList::InternalizeL");
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------
       
   293 // CPushInitiatorList::CPushInitiatorList
       
   294 // ---------------------------------------------------------
       
   295 //
       
   296 CPushInitiatorList::CPushInitiatorList( const TInt aGranularity )
       
   297 :   CArrayPtrFlat<CPushInitiator>( aGranularity ), 
       
   298     iPushInitiatorListChanged( EFalse )
       
   299     {
       
   300     }
       
   301 
       
   302 // ---------------------------------------------------------
       
   303 // CPushInitiatorList::ParseAndProcessBuf2ListL
       
   304 // ---------------------------------------------------------
       
   305 //
       
   306 void CPushInitiatorList::ParseAndProcessBuf2ListL
       
   307                          ( const TDesC& aStreamedBuf )
       
   308     {
       
   309     PUSHLOG_ENTERFN("CPushInitiatorList::ParseAndProcessBuf2ListL");
       
   310     PUSHLOG_WRITE_FORMAT(" param: <%S>",&aStreamedBuf)
       
   311     
       
   312     CWhiteListConverter* converter = CWhiteListConverter::NewL( *this );
       
   313     CleanupStack::PushL( converter );
       
   314 
       
   315     TRAPD( err, converter->Buffer2ListL( aStreamedBuf ) );
       
   316     PUSHLOG_WRITE_FORMAT(" <%d>",err);
       
   317     if ( err == KErrOverflow || err == KErrCorrupt )
       
   318         {
       
   319         // The input is corrupted. Leave the White List as is and 
       
   320         // do not forward these LEAVE values, because it would 
       
   321         // terminate the RFS of Push.
       
   322         }
       
   323     else
       
   324         {
       
   325         // Other error. Must be forwarded.
       
   326         User::LeaveIfError( err );
       
   327         }
       
   328 
       
   329     CleanupStack::PopAndDestroy( converter ); // converter
       
   330 
       
   331     PUSHLOG_LEAVEFN("CPushInitiatorList::ParseAndProcessBuf2ListL");
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------
       
   335 // CPushInitiatorList::ParseAndProcessList2BufL
       
   336 // ---------------------------------------------------------
       
   337 //
       
   338 HBufC* CPushInitiatorList::ParseAndProcessList2BufL() const
       
   339     {
       
   340     PUSHLOG_ENTERFN("CPushInitiatorList::ParseAndProcessList2BufL");
       
   341 
       
   342     CPushInitiatorList& nonConstPiList = (CPushInitiatorList&)*this;
       
   343     CWhiteListConverter* converter = CWhiteListConverter::NewL( nonConstPiList );
       
   344     CleanupStack::PushL( converter );
       
   345 
       
   346     HBufC* retBuf(0);
       
   347     TRAPD( err, retBuf = converter->List2BufferL() );
       
   348     PUSHLOG_WRITE_FORMAT(" <%d>",err);
       
   349     User::LeaveIfError( err );
       
   350 
       
   351     CleanupStack::PopAndDestroy( converter ); // converter
       
   352 
       
   353     PUSHLOG_WRITE_FORMAT(" ret: <%S>",retBuf)
       
   354     PUSHLOG_LEAVEFN("CPushInitiatorList::ParseAndProcessList2BufL");
       
   355     return retBuf;
       
   356     }
       
   357 
       
   358 //  End of File.