httpfilters/cookie/ManagerSrc/CookieClientData.cpp
changeset 27 974c3ee9bf20
equal deleted inserted replaced
23:ea9c9681bbaf 27:974c3ee9bf20
       
     1 /*
       
     2  * CookieClientData.cpp
       
     3  *
       
     4  *  Created on: Dec 28, 2009
       
     5  *      Author: mohanti
       
     6  */
       
     7 //User Includes
       
     8 #include "CookieClientData.h"
       
     9 #include "cookie.h"
       
    10 #include "CookieArray.h"
       
    11 #include "CookieLogger.h"
       
    12 #include "CookieCommonConstants.h"
       
    13 #include <uri8.h>
       
    14 
       
    15 // ---------------------------------------------------------
       
    16 // CCookieGroupData::NewL
       
    17 // ---------------------------------------------------------
       
    18 //
       
    19 CCookieClientData* CCookieClientData::NewL(TUint32 aGroupId)
       
    20     {
       
    21     CCookieClientData* self = CCookieClientData::NewLC(aGroupId);
       
    22     CleanupStack::Pop();
       
    23     return self;
       
    24     }
       
    25 
       
    26 // ---------------------------------------------------------
       
    27 // CCookieClientData::NewLC
       
    28 // ---------------------------------------------------------
       
    29 //
       
    30 CCookieClientData* CCookieClientData::NewLC(TUint32 aGroupId)
       
    31     {
       
    32     CCookieClientData* self = new (ELeave) CCookieClientData(aGroupId);
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     return self;
       
    36     }
       
    37 // ---------------------------------------------------------
       
    38 // CCookieGroupData::NewL
       
    39 // ---------------------------------------------------------
       
    40 //
       
    41 CCookieClientData* CCookieClientData::NewL(TUint32 aGroupId,TUint32 aWidgetUid,TBool aCookieSharableFlag, TBool aInitFlag)
       
    42     {
       
    43     CCookieClientData* self = CCookieClientData::NewLC(aGroupId, aWidgetUid, aCookieSharableFlag, aInitFlag);
       
    44     CleanupStack::Pop();
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CCookieClientData::NewLC
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 CCookieClientData* CCookieClientData::NewLC(TUint32 aGroupId,TUint32 aWidgetUid,TBool aCookieSharableFlag, TBool aInitFlag)
       
    53     {
       
    54     CCookieClientData* self = new (ELeave) CCookieClientData(aGroupId, aWidgetUid, aCookieSharableFlag, aInitFlag);
       
    55     CleanupStack::PushL(self);
       
    56     self->ConstructL();
       
    57     return self;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------
       
    61 // CCookieClientData::CCookieClientData
       
    62 // ---------------------------------------------------------
       
    63 //
       
    64 CCookieClientData::CCookieClientData(TUint32 aGroupId,TUint32 aWidgetUid ,TBool aCookieSharableFlag , TBool aInitFlag)
       
    65 :iInitFlag(aInitFlag),iCookieSharableFlag(aCookieSharableFlag),iGroupId(aGroupId),iWidgetUid(aWidgetUid)
       
    66     {
       
    67     
       
    68     }
       
    69 // ---------------------------------------------------------
       
    70 // CCookieClientData::CCookieClientData
       
    71 // ---------------------------------------------------------
       
    72 //
       
    73 CCookieClientData::CCookieClientData(TUint32 aGroupId):iInitFlag(EFalse),iCookieSharableFlag(EFalse),iGroupId(aGroupId),iWidgetUid(0)
       
    74     {
       
    75     
       
    76     }
       
    77 // ---------------------------------------------------------
       
    78 // CCookieGroupData::ConstructL
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 void CCookieClientData::ConstructL()
       
    82     {
       
    83     iCookieArray = new (ELeave) CCookieArray;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CCookieClientData::~CCookieClientData
       
    88 // ---------------------------------------------------------
       
    89 //
       
    90 CCookieClientData::~CCookieClientData()
       
    91     {
       
    92     CLOG(( EClient, 0, _L("-> CCookieClientData::~CCookieClientData iCookieArray: 0x%08x"), iCookieArray ));
       
    93     delete iCookieArray;
       
    94     iCookieArray = NULL;
       
    95     CLOG(( EClient, 0, _L("<- CCookieClientData::~CCookieClientData") ));
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------
       
    99 // CCookieClientData::StorePersistentCookieL
       
   100 // ---------------------------------------------------------
       
   101 //
       
   102 void CCookieClientData::StorePersistentCookieL( const CCookie* aCookie,
       
   103                                                  const TDesC8& aRequestUri,
       
   104                                                  const TInt aIndex )
       
   105     {
       
   106     CLOG(( EClient, 0, _L("-> RCookieManager::StorePersistentCookieL") ));
       
   107     if (aIndex == -1)
       
   108         {
       
   109         iCookieArray->AddL( aCookie, aRequestUri);
       
   110         }
       
   111     else
       
   112         {
       
   113         iCookieArray->InsertL( aCookie, aIndex);
       
   114         }
       
   115     CLOG(( EClient, 0, _L("<- RCookieManager::StorePersistentCookieL") ));
       
   116     }
       
   117 
       
   118 // ---------------------------------------------------------
       
   119 // RCookieManager::StoreCookieAtClientSideL
       
   120 // ---------------------------------------------------------
       
   121 //
       
   122 void CCookieClientData::StoreCookieAtClientSideL(const CCookie* aCookie,const TDesC8& aUri )
       
   123     {
       
   124     CLOG(( EClient, 0, _L("-> RCookieManager::StoreCookieAtClientSideL: aUri:%S"), &aUri ));
       
   125     //Creates a clone of the passed cookie objects as the ownership of this object is held by Clint of Cookie Manager Dll
       
   126     TUriParser8 uriParser;
       
   127     
       
   128     TInt err = uriParser.Parse( aUri );
       
   129     CCookie* clone(NULL);
       
   130     if (err !=KErrNone)
       
   131         return;
       
   132     else
       
   133         {
       
   134         // first get the details of the current requestUri,
       
   135         // that is, Domain, Path and port
       
   136         TPtrC8 requestPath( uriParser.IsPresent( EUriPath ) ?
       
   137                             uriParser.Extract( EUriPath ) : KNullDesC8() );
       
   138         TPtrC8 requestDomain( uriParser.IsPresent( EUriHost ) ?
       
   139                             uriParser.Extract( EUriHost ) : KNullDesC8() );
       
   140         TPtrC8 requestPort( uriParser.IsPresent( EUriPort ) ?
       
   141                 uriParser.Extract( EUriPort ) : KCookieDefaultRequestPort() );
       
   142 
       
   143         clone = CCookie::CloneL( *aCookie,requestDomain,requestPath,requestPort);
       
   144         CleanupStack::PushL( clone );
       
   145         }
       
   146 
       
   147     //CCookie* clone = CCookie::CloneL( *aCookie,requestDomain,requestPath);
       
   148     //CleanupStack::PushL( clone );
       
   149   
       
   150     TInt index(0);
       
   151     CCookieArray* perscookiearray = CookieArray();
       
   152         if ( perscookiearray->DoesAlreadyExists( clone, index ) )
       
   153         { // must overwrite !!!
       
   154         // but first add the new one if needed
       
   155         // just not to give a chance of beeing lost...
       
   156         // persistence of the cookie will be handled on 
       
   157         // saving all cookies to disk
       
   158         perscookiearray->MakeRoomForInsertIfNeededL(clone, aUri, index);            
       
   159         if(index >=0)
       
   160             {
       
   161             // insert cookie at valid index 
       
   162             //iCookieClientData->StorePersistentCookieL(aCookie,aUri,index);
       
   163             StorePersistentCookieL(clone,aUri,index);
       
   164             //iCookieClientData->StorePersistentCookieL( aCookie, aUri, index );
       
   165             // remove the old cookie
       
   166             perscookiearray->Remove( index + 1 );
       
   167             }
       
   168         else
       
   169             {   // invalid index means old cookie has been deleted in the process of making room
       
   170                 // append the new cookie to the end of array
       
   171             //iCookieClientData->StorePersistentCookieL( aCookie, aUri );
       
   172             StorePersistentCookieL( clone, aUri );
       
   173             }
       
   174         }
       
   175     else
       
   176         { // it is not in the array yet, add it now
       
   177         //iCookieClientData->StorePersistentCookieL( aCookie, aUri );
       
   178         StorePersistentCookieL( clone, aUri );
       
   179         }
       
   180     // Cookie supervisor API takes immediate ownership of both cookie and array
       
   181     CleanupStack::Pop(clone);
       
   182     CLOG(( EClient, 0, _L("<- RCookieManager::StoreCookieAtClientSideL") )); 
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // CCookieGroupData::Count
       
   187 // ---------------------------------------------------------
       
   188 //
       
   189 TInt CCookieClientData::Count()const
       
   190     {
       
   191     return iCookieArray->Count(); 
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 
       
   196 // ---------------------------------------------------------
       
   197 // CCookieGroupData::GetClientSideCookies
       
   198 // ---------------------------------------------------------
       
   199 //
       
   200 TInt CCookieClientData::GetClientSideCookies(const TDesC8& aRequestUri,RPointerArray<CCookie>& aCookies,TBool& aCookieFound )const
       
   201     {
       
   202     return iCookieArray->GetCookies(aRequestUri,aCookies,aCookieFound);
       
   203     }
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // CCookieGroupData::CookieArray
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 CCookieArray* CCookieClientData::CookieArray()
       
   210     {
       
   211     return iCookieArray;
       
   212     }
       
   213 //EOF