ncdengine/provider/protocol/src/ncd_cp_cookieimpl.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Implementation of CNcdCookieHandler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncd_cp_cookieimpl.h"
       
    20 #include "ncdprotocolutils.h"
       
    21 #include "catalogsdebug.h"
       
    22 #include "catalogsutils.h"
       
    23 
       
    24 // ---------------------------------------------------------------------------
       
    25 // Constructor
       
    26 // ---------------------------------------------------------------------------
       
    27 //
       
    28 CNcdConfigurationProtocolCookie::CNcdConfigurationProtocolCookie()
       
    29     {
       
    30     }
       
    31 
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // NewL
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CNcdConfigurationProtocolCookie* 
       
    38     CNcdConfigurationProtocolCookie::NewL()
       
    39     {
       
    40     CNcdConfigurationProtocolCookie* self = new(ELeave) 
       
    41         CNcdConfigurationProtocolCookie();
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // NewLC
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CNcdConfigurationProtocolCookie* 
       
    54     CNcdConfigurationProtocolCookie::NewLC()
       
    55     {
       
    56     CNcdConfigurationProtocolCookie* self = 
       
    57         new (ELeave) CNcdConfigurationProtocolCookie();
       
    58     CleanupStack::PushL(self);
       
    59     self->ConstructL();
       
    60     return self;
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Copy constructor
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CNcdConfigurationProtocolCookie* 
       
    69     CNcdConfigurationProtocolCookie::NewLC( 
       
    70     const MNcdConfigurationProtocolCookie& aCookie )
       
    71     {
       
    72     CNcdConfigurationProtocolCookie* self = 
       
    73         new (ELeave) CNcdConfigurationProtocolCookie();
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL( aCookie );
       
    76     return self;    
       
    77     }
       
    78 
       
    79                                              
       
    80 // ---------------------------------------------------------------------------
       
    81 // ConstructL
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CNcdConfigurationProtocolCookie::ConstructL()
       
    85     {
       
    86     NcdProtocolUtils::AssignEmptyDesL( iKey );
       
    87     NcdProtocolUtils::AssignDesL( iType, 
       
    88         NcdConfigurationProtocolCookieTypes::KSaveAndSend );
       
    89     NcdProtocolUtils::AssignDesL( iScope, 
       
    90         NcdConfigurationProtocolCookieScopes::KClient );
       
    91     NcdProtocolUtils::AssignEmptyDesL( iSim );
       
    92     }
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // ConstructL 
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CNcdConfigurationProtocolCookie::ConstructL( 
       
   100     const MNcdConfigurationProtocolCookie & aCookie )
       
   101     {
       
   102     NcdProtocolUtils::AssignDesL( iKey, aCookie.Key() );
       
   103     NcdProtocolUtils::AssignDesL( iType, aCookie.Type() );
       
   104     NcdProtocolUtils::AssignDesL( iScope, aCookie.Scope() );
       
   105     iExpirationDelta = aCookie.ExpirationDelta();
       
   106     iValues.ReserveL( aCookie.ValueCount() );
       
   107     for ( TInt i = 0; i < aCookie.ValueCount(); ++i )
       
   108         {
       
   109         HBufC* value = aCookie.Value( i ).AllocL();
       
   110         iValues.Append( value );
       
   111         }
       
   112     NcdProtocolUtils::AssignDesL( iSim, aCookie.Sim() );
       
   113     }
       
   114     
       
   115 // ---------------------------------------------------------------------------
       
   116 // Destructor
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CNcdConfigurationProtocolCookie::~CNcdConfigurationProtocolCookie()
       
   120     {
       
   121     delete iKey;
       
   122     delete iType;
       
   123     delete iScope;
       
   124     iValues.ResetAndDestroy();
       
   125     delete iSim;
       
   126     }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Key
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 const TDesC& CNcdConfigurationProtocolCookie::Key() const
       
   133     {
       
   134     DASSERT( iKey );
       
   135     return *iKey;
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // Type
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 const TDesC& CNcdConfigurationProtocolCookie::Type() const
       
   143     {
       
   144     DASSERT( iType );
       
   145     return *iType;
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Scope
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 const TDesC& CNcdConfigurationProtocolCookie::Scope() const
       
   154     {
       
   155     DASSERT( iScope );
       
   156     return *iScope;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // ExpirationDelta
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 TInt CNcdConfigurationProtocolCookie::ExpirationDelta() const
       
   164     {
       
   165     return iExpirationDelta;
       
   166     }
       
   167 
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // ValueCount
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 TInt CNcdConfigurationProtocolCookie::ValueCount() const
       
   174     {
       
   175     return iValues.Count();
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // Value
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 const TDesC& CNcdConfigurationProtocolCookie::Value( TInt aIndex ) const
       
   183     {
       
   184     DASSERT( aIndex >= 0 && aIndex < ValueCount() );
       
   185     return *( iValues[aIndex]);
       
   186     }
       
   187 
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // Sim
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 const TDesC8& CNcdConfigurationProtocolCookie::Sim() const
       
   194     {
       
   195     return *iSim;
       
   196     }
       
   197 
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // Expiration time getter
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 TTime CNcdConfigurationProtocolCookie::ExpirationTime() const
       
   204     {
       
   205     return iExpirationTime;
       
   206     }
       
   207     
       
   208     
       
   209 // ---------------------------------------------------------------------------
       
   210 // Identity
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 TBool CNcdConfigurationProtocolCookie::Identity( 
       
   214     const MNcdConfigurationProtocolCookie& aFirst,
       
   215     const MNcdConfigurationProtocolCookie& aSecond )
       
   216     {
       
   217     return aFirst.Key() == aSecond.Key();
       
   218     }
       
   219 
       
   220 // ---------------------------------------------------------------------------
       
   221 // ExternalizeL
       
   222 // ---------------------------------------------------------------------------
       
   223 //
       
   224 
       
   225 void CNcdConfigurationProtocolCookie::ExternalizeL( RWriteStream& aStream )
       
   226     {
       
   227     DLTRACEIN((""));
       
   228     DASSERT( iKey );    
       
   229     DASSERT( iType );
       
   230     DASSERT( iScope );
       
   231     ExternalizeDesL( *iKey, aStream ); 
       
   232     
       
   233     DLTRACE(("Externalizing cookie values"));
       
   234     // Externalize values
       
   235     aStream.WriteInt32L( ValueCount() );
       
   236     for ( TInt i = 0; i < ValueCount(); ++i ) 
       
   237         {
       
   238         ExternalizeDesL( Value( i ), aStream );
       
   239         }
       
   240     
       
   241     DLTRACE(("Cookie values externalized"));
       
   242     ExternalizeDesL( *iType, aStream );
       
   243     ExternalizeDesL( *iScope, aStream );
       
   244     ExternalizeDesL( *iSim, aStream );
       
   245     aStream.WriteInt32L( iExpirationDelta );
       
   246     aStream << iExpirationTime.Int64();
       
   247     DLTRACEOUT((""));
       
   248     }
       
   249 
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // InternalizeL
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 void CNcdConfigurationProtocolCookie::InternalizeL( RReadStream& aStream )
       
   256     {
       
   257     DLTRACEIN((""));
       
   258     InternalizeDesL( iKey, aStream );
       
   259     
       
   260     TInt valueCount = aStream.ReadInt32L();
       
   261     iValues.ResetAndDestroy();
       
   262     iValues.ReserveL( valueCount );
       
   263     
       
   264     DLTRACE(( "Internalizing cookie values, count: %d", valueCount ));
       
   265     for ( TInt i = 0; i < valueCount; ++i )
       
   266         {
       
   267         HBufC* value = NULL;
       
   268         InternalizeDesL( value, aStream );
       
   269         // "Can't" fail
       
   270         iValues.Append( value );        
       
   271         }
       
   272     DLTRACE(( "Cookies values internalized" ));
       
   273     
       
   274     InternalizeDesL( iType, aStream );
       
   275     InternalizeDesL( iScope, aStream );
       
   276     InternalizeDesL( iSim, aStream );
       
   277     iExpirationDelta = aStream.ReadInt32L();
       
   278     
       
   279     // Read expiration time
       
   280     TInt64 time( 0 );
       
   281     aStream >> time;
       
   282     iExpirationTime = TTime( time );
       
   283     DLTRACEOUT((""));
       
   284     }
       
   285