httpfilters/cookie/ManagerSrc/CookieManagerClient.cpp
changeset 27 974c3ee9bf20
parent 12 88a7990e456a
equal deleted inserted replaced
23:ea9c9681bbaf 27:974c3ee9bf20
    21 #include <e32std.h>
    21 #include <e32std.h>
    22 // #include <thttphdrval.h>
    22 // #include <thttphdrval.h>
    23 
    23 
    24 	// User includes
    24 	// User includes
    25 #include "cookie.h"
    25 #include "cookie.h"
       
    26 #include "CookieArray.h"
    26 #include "cookieipc.h"
    27 #include "cookieipc.h"
    27 #include "CookieCommonConstants.h"
    28 #include "CookieCommonConstants.h"
    28 #include "CookieLogger.h"
    29 #include "CookieLogger.h"
    29 #include "cookiemanagerclient.h"
    30 #include "cookiemanagerclient.h"
    30 #include "CookieManagerServer.h"
    31 #include "CookieManagerServer.h"
    31 #include "CookieManagerStart.h"
    32 #include "CookieManagerStart.h"
    32 #include "CookieServerDef.h"
    33 #include "CookieServerDef.h"
    33 
    34 #include "CookieClientDataArray.h"
       
    35 #include "CookieClientData.h"
    34 // CONSTANTS
    36 // CONSTANTS
    35 
       
    36 // TBD : do we have to set limits to the number of cookies at all?
    37 // TBD : do we have to set limits to the number of cookies at all?
    37 // Possible answer : as we store cookies in an RPointerArray that has a
    38 // Possible answer : as we store cookies in an RPointerArray that has a
    38 // restriction on the number of elements (max. 640 can be stored in an RArray
    39 // restriction on the number of elements (max. 640 can be stored in an RArray
    39 // or RPointerArray), we have to bother with it.
    40 // or RPointerArray), we have to bother with it.
    40 // TODO :
    41 // TODO :
    46 // ---------------------------------------------------------
    47 // ---------------------------------------------------------
    47 // RCookieManager::RCookieManager
    48 // RCookieManager::RCookieManager
    48 // ---------------------------------------------------------
    49 // ---------------------------------------------------------
    49 //
    50 //
    50 EXPORT_C RCookieManager::RCookieManager( RStringPool aStringPool )
    51 EXPORT_C RCookieManager::RCookieManager( RStringPool aStringPool )
    51 : iStringPool( aStringPool ), iCookiePacker( iStringPool )
    52 : iStringPool( aStringPool ),iCookieMgrData(NULL)
    52     {
    53     {
    53     CLOG(( EClient, 0, _L(" ") ));
    54     CLOG(( EClient, 0, _L(" ") ));
    54     CLOG(( EClient, 0, _L("*****************") ));
    55     CLOG(( EClient, 0, _L("*****************") ));
    55     CLOG(( EClient, 0, _L("RCookieManager::RCookieManager") ));
    56     CLOG(( EClient, 0, _L("RCookieManager::RCookieManager") ));
    56     }
    57     }
    78 // ---------------------------------------------------------
    79 // ---------------------------------------------------------
    79 //
    80 //
    80 EXPORT_C TInt RCookieManager::Connect()
    81 EXPORT_C TInt RCookieManager::Connect()
    81     {
    82     {
    82     CLOG( ( EClientConnect, 0, _L( "-> RCookieManager::Connect" ) ) );
    83     CLOG( ( EClientConnect, 0, _L( "-> RCookieManager::Connect" ) ) );
    83 
    84     iCookieMgrData = new TCookieMgrInternalStruct(iStringPool);
       
    85     if (!(iCookieMgrData && iCookieMgrData->Init() == KErrNone))
       
    86         return KErrNoMemory;
       
    87             
    84     TInt error = KErrNone;
    88     TInt error = KErrNone;
    85     RProcess server;
    89     RProcess server;
    86     error = server.Create( KCookieServerExe, TPtr( NULL, 0 ),
    90     error = server.Create( KCookieServerExe, TPtr( NULL, 0 ),
    87                            TUidType( KNullUid, KNullUid, KCookieServerExeUid ) );
    91                            TUidType( KNullUid, KNullUid, KCookieServerExeUid ) );
    88     CLOG( ( EClientConnect, 0,
    92     CLOG( ( EClientConnect, 0,
   114     CLOG( ( EClientConnect, 0, _L( "<- RCookieManager::Connect" ) ) );
   118     CLOG( ( EClientConnect, 0, _L( "<- RCookieManager::Connect" ) ) );
   115     return error;
   119     return error;
   116     }
   120     }
   117 
   121 
   118 // ---------------------------------------------------------
   122 // ---------------------------------------------------------
   119 // RCookieManager::GetCookies
   123 // RCookieManager::DoGetCookies
   120 // ---------------------------------------------------------
   124 // ---------------------------------------------------------
   121 //
   125 //
   122 TInt RCookieManager::DoGetCookies( TDes8& aBuffer ) const
   126 TInt RCookieManager::DoGetCookies( TDes8& aBuffer ) const
   123 	{
   127 	{
   124 	return SendReceive( EGetCookies, TIpcArgs( &aBuffer ) );
   128 	return SendReceive( EGetCookies, TIpcArgs( &aBuffer ) );
   125 	}
   129 	}
   126 
   130 
   127 // ---------------------------------------------------------
   131 // ---------------------------------------------------------
   128 // RCookieManager::GetCookieSize
   132 // RCookieManager::GetCookieSharableFlagFromServer
       
   133 // ---------------------------------------------------------
       
   134 //
       
   135 TInt RCookieManager::GetCookieSharableFlagFromServer(TBool& aCookieSharableFlag )const
       
   136     {
       
   137     TPckg<TBool> cookieSharableFlag(aCookieSharableFlag);
       
   138     return SendReceive( EGetCookieSharableFlag, TIpcArgs( &cookieSharableFlag ) );
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // RCookieManager::DoGetCookieSize
   129 // ---------------------------------------------------------
   143 // ---------------------------------------------------------
   130 //
   144 //
   131 TInt RCookieManager::DoGetCookieSize( const TDesC8& aRequestUri,
   145 TInt RCookieManager::DoGetCookieSize( const TDesC8& aRequestUri,
   132 									  TPckg<TInt>& aPkgSize ) const
   146 									  TPckg<TInt>& aPkgSize,TDesC& aAppuidPtr ) const
   133 	{
   147 	{
   134     return SendReceive( EGetCookieSize, TIpcArgs( aRequestUri.Length(), 
   148     return SendReceive( EGetCookieSize, TIpcArgs( &aAppuidPtr,aRequestUri.Length(), 
   135                                                   &aRequestUri, &aPkgSize ) );
   149                                                   &aRequestUri, &aPkgSize ) );
   136 	}
   150 	}
       
   151 // ---------------------------------------------------------
       
   152 // RCookieManager::DestroyCookiesFromMemory
       
   153 // ---------------------------------------------------------
       
   154 //
       
   155 TInt RCookieManager::DestroyCookiesFromMemory( TInt& aDeleteStatus )
       
   156     {
       
   157     CLOG(( EClient, 0, _L("-> RCookieManager::DestroyCookies") ));
       
   158 
       
   159     TPckg<TInt> pkgStatus( aDeleteStatus );
       
   160     TInt ret = SendReceive( EDestroyCookies, TIpcArgs( &pkgStatus ) ) ;
       
   161 
       
   162     CLOG(( EClient, 0, 
       
   163         _L("<- RCookieManager::DestroyCookies cleared %d cookies, errcode%d"),
       
   164         aDeleteStatus, ret ) );
       
   165 
       
   166     return ret;
       
   167 
       
   168     }
   137 
   169 
   138 // ---------------------------------------------------------
   170 // ---------------------------------------------------------
   139 // RCookieManager::DoStoreCookie
   171 // RCookieManager::DoStoreCookie
   140 // ---------------------------------------------------------
   172 // ---------------------------------------------------------
   141 //
   173 //
   142 TInt RCookieManager::DoStoreCookie( const TDesC8& aPackedCookie,
   174 TInt RCookieManager::DoStoreCookie( const TDesC8& aPackedCookie,
   143 								   const TDesC8& aUri ) const
   175 								   const TDesC8& aUri,TDesC& aAppUidPtr ) const
   144 	{
   176 	{
   145     return SendReceive( EStoreCookie, TIpcArgs( aPackedCookie.Length(), 
   177     return SendReceive( EStoreCookie, TIpcArgs( aPackedCookie.Length(), 
   146                                       &aPackedCookie, aUri.Length(), &aUri ) );
   178                                       &aPackedCookie, &aUri,&aAppUidPtr ) );
   147 	}
   179 	}
   148 
   180 
   149 // ---------------------------------------------------------
   181 // ---------------------------------------------------------
   150 // RCookieManager::GetCookiesL
   182 // RCookieManager::GetCookiesL
   151 // ---------------------------------------------------------
   183 // ---------------------------------------------------------
   153 EXPORT_C void RCookieManager::GetCookiesL( const TDesC8& aUri,
   185 EXPORT_C void RCookieManager::GetCookiesL( const TDesC8& aUri,
   154 										RPointerArray<CCookie>& aCookies,
   186 										RPointerArray<CCookie>& aCookies,
   155 										TBool& aCookie2Reqd )
   187 										TBool& aCookie2Reqd )
   156     {
   188     {
   157     CLOG( ( EClient, 0, _L( "-> RCookieManager::GetCookiesL" ) ) );
   189     CLOG( ( EClient, 0, _L( "-> RCookieManager::GetCookiesL" ) ) );
   158 
   190     TBool cookiefound(EFalse);
       
   191     CCookieClientDataArray* cookieclientdataarray = iCookieMgrData->GetCookieClientDataArray();
       
   192     
       
   193     if(cookieclientdataarray) 
       
   194         {
       
   195     TInt clientarraycount = cookieclientdataarray->Count();
       
   196     if ( clientarraycount!=0 )
       
   197         {
       
   198         TInt clerr = GetClientSideCookies(aUri,aCookies,cookiefound,0);
       
   199         }
       
   200       } 
       
   201 
       
   202     if(!cookiefound)
       
   203         {
   159 	aCookie2Reqd = EFalse;
   204 	aCookie2Reqd = EFalse;
   160 
   205 
   161 	TInt size = 0;
   206 	TInt size = 0;
   162 	TPckg<TInt> pkgSize( size );
   207 	TPckg<TInt> pkgSize( size );
   163 	User::LeaveIfError( DoGetCookieSize( aUri, pkgSize ) );
   208 	//Appuid value only takes 8 chars
   164 
   209     HBufC* appbuf = HBufC::New(8);
       
   210     TPtr ptr(appbuf->Des());
       
   211     TUint32 appUid(0);
       
   212     ptr.AppendNum(appUid,EHex);    
       
   213 	User::LeaveIfError( DoGetCookieSize( aUri, pkgSize,ptr ) );
       
   214     delete appbuf;
   165 	if ( size )
   215 	if ( size )
   166 		{
   216 		{
   167 		HBufC8* buf = HBufC8::NewLC( size );
   217 		HBufC8* buf = HBufC8::NewLC( size );
   168 
   218 
   169 		TPtr8 des( buf->Des() );
   219 		TPtr8 des( buf->Des() );
   170 		User::LeaveIfError( DoGetCookies( des ) );
   220 		User::LeaveIfError( DoGetCookies( des ) );
   171 
   221 
   172 		// it seems this is the only place where we cannot avoid leaving
   222 		// it seems this is the only place where we cannot avoid leaving
   173 		// ==> we allocate memory for cookies when we fill up the cookie array.
   223 		// ==> we allocate memory for cookies when we fill up the cookie array.
   174 		iCookiePacker.UnpackCookiesFromBufferL( *buf, aCookies );
   224 		iCookieMgrData->GetCookiePacker().UnpackCookiesFromBufferL( *buf, aCookies );
   175 
       
   176 		TInt count = aCookies.Count();
   225 		TInt count = aCookies.Count();
   177 		TInt i = 0;
   226 		TInt i = 0;
   178 		TBool anyCookie2( EFalse );
   227 		TBool anyCookie2( EFalse );
   179 		TBool anyUnknownVersion( EFalse );
   228 		TBool anyUnknownVersion( EFalse );
   180 		for ( ; i < count; i++ )
   229 		for ( ; i < count; i++ )
   194 			aCookie2Reqd = ETrue;
   243 			aCookie2Reqd = ETrue;
   195 			}
   244 			}
   196 
   245 
   197 		CleanupStack::PopAndDestroy();	// buf
   246 		CleanupStack::PopAndDestroy();	// buf
   198 		}
   247 		}
   199 
   248       }
   200     CLOG( ( EClient, 0, _L( "<- RCookieManager::GetCookiesL" ) ) );
   249     CLOG( ( EClient, 0, _L( "<- RCookieManager::GetCookiesL" ) ) );
   201     }
   250     }
   202 
   251 
   203 // ---------------------------------------------------------
   252 // ---------------------------------------------------------
   204 // RCookieManager::StoreCookie
   253 // RCookieManager::StoreCookie
   206 //
   255 //
   207 EXPORT_C TInt RCookieManager::StoreCookie( const CCookie& aCookie,
   256 EXPORT_C TInt RCookieManager::StoreCookie( const CCookie& aCookie,
   208 								 const TUriC8& aUri )
   257 								 const TUriC8& aUri )
   209     {
   258     {
   210     CLOG( ( EClient, 0, _L( "-> RCookieManager::StoreCookie" ) ) );
   259     CLOG( ( EClient, 0, _L( "-> RCookieManager::StoreCookie" ) ) );
   211 
   260     StoreCookieAtClientSide(&aCookie,aUri.UriDes()); 
   212 	TInt err;
   261 	TInt err;
   213 
   262 
   214 	TInt cookieSize = aCookie.Size( EFalse );
   263 	TInt cookieSize = aCookie.Size( EFalse );
   215 	HBufC8* buf = HBufC8::New( cookieSize );
   264 	HBufC8* buf = HBufC8::New( cookieSize );
   216 	if ( buf )
   265 	if ( buf )
   218 		CLOG( ( EClient, 0,
   267 		CLOG( ( EClient, 0,
   219 			    _L( "RCookieManager::StoreCookie, cookie size:%d" ), 
   268 			    _L( "RCookieManager::StoreCookie, cookie size:%d" ), 
   220                 cookieSize ) );
   269                 cookieSize ) );
   221 
   270 
   222 		TPtr8 bufDes( buf->Des() );
   271 		TPtr8 bufDes( buf->Des() );
   223 		err = iCookiePacker.CliPackCookie( bufDes, aCookie );
   272 		err = iCookieMgrData->GetCookiePacker().CliPackCookie( bufDes, aCookie );
   224 		if ( !err )
   273 		if ( !err )
   225 			{
   274 			{
   226 			err = DoStoreCookie( *buf, aUri.UriDes() );
   275 			//Appuid value only takes 8 chars
       
   276             HBufC* appbuf = HBufC::New(8);
       
   277             TPtr ptr(appbuf->Des());
       
   278             TUint32 appUid(0);
       
   279             ptr.AppendNum(appUid,EHex);    
       
   280             err = DoStoreCookie( *buf, aUri.UriDes(),ptr );
       
   281             delete appbuf;
       
   282 			//err = DoStoreCookie( *buf, aUri.UriDes() );
   227 			}
   283 			}
   228 
   284 
   229 		delete buf;
   285 		delete buf;
   230 		}
   286 		}
   231 	else
   287 	else
   251                       KCookieServerMinorVersionNumber, 
   307                       KCookieServerMinorVersionNumber, 
   252                       KCookieServerBuildVersionNumber ));
   308                       KCookieServerBuildVersionNumber ));
   253     }
   309     }
   254     
   310     
   255 // ---------------------------------------------------------
   311 // ---------------------------------------------------------
   256 // RCookieManager::SetAppUidL
   312 // RCookieManager::SetAppUidL This method is no longer being 
       
   313 // used in CookieFilter.As this method is exported so in order
       
   314 // to provide backward compatibilty this API implementation is changed 
   257 // ---------------------------------------------------------
   315 // ---------------------------------------------------------
   258 //
   316 //
   259 EXPORT_C TInt RCookieManager::SetAppUidL( const TUint32& aAppUid )
   317 EXPORT_C TInt RCookieManager::SetAppUidL( const TUint32& aAppUid )
   260     {
   318     {
   261     CLOG(( EClient, 0, _L("->RCookieManager::SetAppUid") ));   
   319     CLOG(( EClient, 0, _L("->RCookieManager::SetAppUid") ));   
   262     HBufC* buf = HBufC::NewLC(128);
   320     TUint32 groupid = RProcess().SecureId().iId;
       
   321     CCookieClientData* cookieclientdata = iCookieMgrData->GetCookieClientDataArray()->Find(groupid, const_cast<TUint32&> (aAppUid));
       
   322     if(cookieclientdata)
       
   323         {
       
   324         cookieclientdata->SetWidgetUid(aAppUid);
       
   325         }
       
   326     else
       
   327         {
       
   328         TBool cookieSharableFlag(EFalse);
       
   329         TInt err = GetCookieSharableFlagFromServer(cookieSharableFlag);
       
   330         cookieclientdata = CCookieClientData::NewL(groupid, aAppUid, cookieSharableFlag,ETrue);
       
   331         cookieclientdata->SetInitFlag(ETrue);
       
   332         iCookieMgrData->GetCookieClientDataArray()->AddClientGroupDataL(cookieclientdata);
       
   333         }
       
   334     //Appuid value only takes 8 chars
       
   335     HBufC* buf = HBufC::NewLC(8);
   263     TPtr ptr(buf->Des());
   336     TPtr ptr(buf->Des());
   264     ptr.AppendNum(aAppUid,EHex);    
   337     ptr.AppendNum(aAppUid,EHex);
   265     TInt error = SendReceive(ESetAppUid,TIpcArgs(ptr.Length(),&ptr)); 
   338     TInt error = SendReceive(ESetAppUid,TIpcArgs(ptr.Length(),&ptr)); 
   266     CleanupStack::PopAndDestroy();
   339     CleanupStack::PopAndDestroy();
   267     CLOG(( EClient, 0, _L("<-RCookieManager::SetAppUid") ));
   340     CLOG(( EClient, 0, _L("<-RCookieManager::SetAppUid") ));
   268     return error;
   341     return error;
   269     }
   342     }
       
   343 // ---------------------------------------------------------
       
   344 // RCookieManager::Close
       
   345 // ---------------------------------------------------------
       
   346 //
       
   347 
       
   348 EXPORT_C void RCookieManager::Close()
       
   349     {
       
   350     CLOG(( EClient, 0, _L("-> RCookieManager::Close") ));
       
   351     TInt deletestatus =0;
       
   352     DestroyCookiesFromMemory(deletestatus);
       
   353     delete iCookieMgrData;
       
   354     iCookieMgrData = NULL;
       
   355     CLOG(( EClient, 0, _L("-> RCookieManager::Close deletestatus = %d"), deletestatus ));
       
   356     RSessionBase::Close();
       
   357     CLOG(( EClient, 0, _L("<- RCookieManager::Close") ));
       
   358     }
       
   359 // ---------------------------------------------------------
       
   360 // RCookieManager::StoreCookie Newly Added
       
   361 // ---------------------------------------------------------
       
   362 //
       
   363 EXPORT_C TInt RCookieManager::StoreCookie( const CCookie& aCookie,
       
   364                                  const TUriC8& aUri,TUint32& aAppUid )
       
   365     {
       
   366     CLOG( ( EClient, 0, _L( "-> RCookieManager::StoreCookie" ) ) );
       
   367     StoreCookieAtClientSide(&aCookie,aUri.UriDes(),aAppUid);
       
   368     TInt err;
       
   369 
       
   370     TInt cookieSize = aCookie.Size( EFalse );
       
   371     HBufC8* buf = HBufC8::New( cookieSize );
       
   372     if ( buf )
       
   373         {
       
   374         CLOG( ( EClient, 0,
       
   375                 _L( "RCookieManager::StoreCookie, cookie size:%d" ), 
       
   376                 cookieSize ) );
       
   377 
       
   378         TPtr8 bufDes( buf->Des() );
       
   379         err = iCookieMgrData->GetCookiePacker().CliPackCookie( bufDes, aCookie );
       
   380         
       
   381         if ( !err )
       
   382             {
       
   383             //Appuid value only takes 8 chars
       
   384             HBufC* appbuf = HBufC::New(8);
       
   385             TPtr ptr(appbuf->Des());
       
   386             ptr.AppendNum(aAppUid,EHex);    
       
   387             err = DoStoreCookie( *buf, aUri.UriDes(),ptr );
       
   388             delete appbuf;
       
   389             }
       
   390 
       
   391         delete buf;
       
   392         }
       
   393     else
       
   394         {
       
   395         err = KErrNoMemory;
       
   396         }
       
   397 
       
   398     CLOG( ( EClient, 0,
       
   399             _L( "<- RCookieManager::StoreCookie errcode%d" ), err ) );
       
   400 
       
   401     return err;
       
   402     }
       
   403 
       
   404 // ---------------------------------------------------------
       
   405 // RCookieManager::GetCookiesL Newly Added
       
   406 // ---------------------------------------------------------
       
   407 //
       
   408 EXPORT_C void RCookieManager::GetCookiesL( const TDesC8& aUri,
       
   409                                         RPointerArray<CCookie>& aCookies,
       
   410                                         TBool& aCookie2Reqd,TUint32& aAppUid )
       
   411     {
       
   412     CLOG( ( EClient, 0, _L( "-> RCookieManager::GetCookiesL" ) ) );
       
   413     TBool cookiefound(EFalse);
       
   414     CCookieClientDataArray* cookieclientdataarray = iCookieMgrData->GetCookieClientDataArray();
       
   415     if(cookieclientdataarray)
       
   416         {
       
   417          TInt clientarraycount = cookieclientdataarray->Count();
       
   418          if (clientarraycount == 0)
       
   419            {
       
   420             TUint32 groupid = RProcess().SecureId().iId;
       
   421             TBool cookieSharableFlag(EFalse);
       
   422             TInt err = GetCookieSharableFlagFromServer(cookieSharableFlag);
       
   423             CCookieClientData* cookieclientdata = CCookieClientData::NewL(groupid, aAppUid, cookieSharableFlag,ETrue);
       
   424             cookieclientdata->SetInitFlag(ETrue);
       
   425             cookieclientdataarray->AddClientGroupDataL(cookieclientdata);
       
   426            }
       
   427          else
       
   428            {
       
   429         
       
   430             CLOG( ( EClient, 0, _L( "-> RCookieManager::GetClientSideCookies:" ) ) );
       
   431             //Gets the Cookie objects for aUri in case it is present
       
   432             TInt clerr = GetClientSideCookies(aUri,aCookies,cookiefound,aAppUid);
       
   433             CLOG( ( EClient, 0, _L( "RCookieManager::GetClientSideCookies:cookiefound = %d" ), cookiefound ) );
       
   434         
       
   435            }
       
   436         } 
       
   437     if(!cookiefound)
       
   438         {
       
   439             aCookie2Reqd = EFalse;
       
   440             //Appuid value only takes 8 chars
       
   441             HBufC* appuidbuf = HBufC::NewL(8);
       
   442             TPtr ptr(appuidbuf->Des());
       
   443             ptr.AppendNum(aAppUid,EHex);    
       
   444             TInt size = 0;
       
   445             TPckg<TInt> pkgSize( size );
       
   446             User::LeaveIfError( DoGetCookieSize( aUri, pkgSize, ptr ) );
       
   447             delete appuidbuf;
       
   448         if ( size )
       
   449             {
       
   450             HBufC8* buf = HBufC8::NewLC( size );
       
   451     
       
   452             TPtr8 des( buf->Des() );
       
   453             User::LeaveIfError( DoGetCookies( des ) );
       
   454     
       
   455             // it seems this is the only place where we cannot avoid leaving
       
   456             // ==> we allocate memory for cookies when we fill up the cookie array.
       
   457             iCookieMgrData->GetCookiePacker().UnpackCookiesFromBufferL( *buf, aCookies );
       
   458             TInt count = aCookies.Count();
       
   459             for(TInt j=0; j<count; j++)
       
   460                 {
       
   461                 CLOG( ( EClient, 0, _L( "-> RCookieManager::StoreClientSideCookies: aUri=%S" ), &aUri ) );
       
   462                 //cookieclientdata->StoreCookieAtClientSide( aCookies[j],aUri );
       
   463                 StoreCookieAtClientSide( aCookies[j],aUri,aAppUid );
       
   464                 }
       
   465             TInt i = 0;
       
   466             TBool anyCookie2( EFalse );
       
   467             TBool anyUnknownVersion( EFalse );
       
   468             for ( ; i < count; i++ )
       
   469                 {
       
   470                 if ( aCookies[i]->FromCookie2() )
       
   471                     {
       
   472                     anyCookie2 = ETrue;
       
   473                     anyUnknownVersion |= aCookies[i]->IsUnknownVersion();
       
   474                     }
       
   475                 }
       
   476     
       
   477             // if there were no new-style cookies or a new version info is detected
       
   478             // then we have to send an extra cookie header indicating that we're 
       
   479             // able to process new-style cookies
       
   480             if ( !anyCookie2 || anyUnknownVersion )
       
   481                 {
       
   482                 aCookie2Reqd = ETrue;
       
   483                 }
       
   484     
       
   485             CleanupStack::PopAndDestroy();  // buf
       
   486             }
       
   487       }
       
   488     CLOG( ( EClient, 0, _L( "<- RCookieManager::GetCookiesL" ) ) );
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------
       
   492 // RCookieManager::Close for Widget related destruction during 
       
   493 //uninstallation process of a widget
       
   494 // ---------------------------------------------------------
       
   495 //
       
   496 EXPORT_C TInt RCookieManager::ClearAllAppUidCookies(const TUint32& aAppUid)
       
   497     {
       
   498     CLOG(( EClient, 0, _L("-> RCookieManager::ClearCookies") ));
       
   499     //Client side cookie deletion specific to a appuid
       
   500     iCookieMgrData->GetCookieClientDataArray()->DestroyClientData(aAppUid);
       
   501     //Server side Cookie deletion specific to a appuid
       
   502     //Appuid value only takes 8 chars
       
   503     HBufC* buf = HBufC::NewLC(8);
       
   504     TPtr ptr(buf->Des());
       
   505     ptr.AppendNum(aAppUid,EHex);
       
   506     TInt error = SendReceive(EClearAppUidCookies,TIpcArgs(ptr.Length(),&ptr)); 
       
   507     CleanupStack::PopAndDestroy();
       
   508     return error;
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------
       
   512 // RCookieManager::StoreCookieAtClientSide
       
   513 // ---------------------------------------------------------
       
   514 //
       
   515 void RCookieManager::StoreCookieAtClientSide( const CCookie* aCookie, const TDesC8& aUri,TUint32 aWidgetUid )
       
   516     {
       
   517     CLOG( ( EClient, 0, _L( "-> RCookieManager::StoreCookieAtClientSide" ) ) );
       
   518     TUint32 groupid = RProcess().SecureId().iId;
       
   519     CCookieClientDataArray* cookieclientdataarray = iCookieMgrData->GetCookieClientDataArray();
       
   520     CCookieClientData* cookieclientdata(NULL);
       
   521     TInt count = cookieclientdataarray->Count();
       
   522     if (count == 0)
       
   523         {
       
   524         TBool cookieSharableFlag(EFalse);
       
   525         TInt err = GetCookieSharableFlagFromServer(cookieSharableFlag);
       
   526         cookieclientdata = CCookieClientData::NewL(groupid, aWidgetUid, cookieSharableFlag,ETrue);
       
   527         cookieclientdata->SetInitFlag(ETrue);
       
   528         cookieclientdataarray->AddClientGroupDataL(cookieclientdata);
       
   529         cookieclientdata->StoreCookieAtClientSideL(aCookie,aUri);
       
   530         return;
       
   531         }
       
   532     TInt itemIndex =0;
       
   533     for(TInt i=0; i<count; i++)
       
   534         {
       
   535           if (cookieclientdataarray->At(i)->GetGroupId() == groupid 
       
   536                   && cookieclientdataarray->At(i)->GetCookieSharableFlag())
       
   537               {
       
   538               itemIndex = i;
       
   539               break;
       
   540               }
       
   541           else if(cookieclientdataarray->At(i)->GetGroupId() == groupid
       
   542                   && !(cookieclientdataarray->At(i)->GetCookieSharableFlag()) 
       
   543                   && cookieclientdataarray->At(i)->GetWidgetUid() == aWidgetUid)
       
   544               {
       
   545               itemIndex = i;
       
   546               break;
       
   547               }
       
   548         }
       
   549     cookieclientdata = cookieclientdataarray->At(itemIndex);
       
   550     cookieclientdata->StoreCookieAtClientSideL(aCookie,aUri);
       
   551     CLOG( ( EClient, 0, _L( "<- RCookieManager::StoreCookieAtClientSide" ) ) );
       
   552     }
       
   553 
       
   554 // ---------------------------------------------------------
       
   555 // RCookieManager::GetClientSideCookies
       
   556 // ---------------------------------------------------------
       
   557 //
       
   558 TInt RCookieManager::GetClientSideCookies( const TDesC8& aRequestUri,RPointerArray<CCookie>& aCookies
       
   559                 ,TBool& aCookieFound, TUint32 aWidgetUid )
       
   560     {
       
   561     CLOG( ( EClient, 0, _L( "-> RCookieManager::GetClientSideCookies" ) ) );
       
   562     TUint32 groupid = RProcess().SecureId().iId;
       
   563     CCookieClientData* cookieclientdata = NULL;
       
   564     CCookieClientDataArray* cookieclientdataarray = iCookieMgrData->GetCookieClientDataArray();
       
   565     TInt count = cookieclientdataarray->Count();
       
   566     if (count == 0)
       
   567         {
       
   568         TBool cookieSharableFlag(EFalse);
       
   569         TInt err = GetCookieSharableFlagFromServer(cookieSharableFlag);
       
   570         cookieclientdata = CCookieClientData::NewL(groupid, aWidgetUid, cookieSharableFlag,ETrue);
       
   571         cookieclientdata->SetInitFlag(ETrue);
       
   572         cookieclientdataarray->AddClientGroupDataL(cookieclientdata);
       
   573         } else 
       
   574            {
       
   575            cookieclientdata = cookieclientdataarray->Find(groupid, aWidgetUid);
       
   576            }
       
   577      if(cookieclientdata)
       
   578         {
       
   579          if(!cookieclientdata->GetInitFlag())
       
   580            {
       
   581             TBool cookieSharableFlag(EFalse);
       
   582             TInt err = GetCookieSharableFlagFromServer(cookieSharableFlag);
       
   583             cookieclientdata->SetCookieCookieSharableFlag(cookieSharableFlag);
       
   584            }
       
   585            return cookieclientdata->GetClientSideCookies( aRequestUri,aCookies, aCookieFound );
       
   586          } else 
       
   587               {
       
   588                TBool cookieSharableFlag(EFalse);
       
   589                TInt err = GetCookieSharableFlagFromServer(cookieSharableFlag);
       
   590                if(err == KErrNone)
       
   591                  {
       
   592                    CCookieClientData* cookieclientdata 
       
   593                     = CCookieClientData::NewL(groupid, aWidgetUid, cookieSharableFlag,ETrue);
       
   594                     cookieclientdataarray->AddClientGroupDataL(cookieclientdata);
       
   595                   }
       
   596                }
       
   597     CLOG( ( EClient, 0, _L( "<- RCookieManager::GetClientSideCookies" ) ) );
       
   598     return KErrNone;
       
   599     }
       
   600 
       
   601 RCookieManager::TCookieMgrInternalStruct::~TCookieMgrInternalStruct()
       
   602     {
       
   603     delete iCookieClientDataArray;
       
   604     }
       
   605 
       
   606 TInt RCookieManager::TCookieMgrInternalStruct::Init()
       
   607     {
       
   608     iCookieClientDataArray = CCookieClientDataArray::New();
       
   609     if (iCookieClientDataArray)
       
   610         return KErrNone;
       
   611     return KErrNoMemory;
       
   612         
       
   613     }
       
   614 
   270 // End of file
   615 // End of file