httpfilters/cookie/ManagerSrc/Cookie.cpp
branchRCL_3
changeset 15 bdd8a827a7de
parent 11 8f055b80aa5b
equal deleted inserted replaced
13:26ce6fb6aee2 15:bdd8a827a7de
   179 	}
   179 	}
   180 // ---------------------------------------------------------
   180 // ---------------------------------------------------------
   181 // CCookie::NewL
   181 // CCookie::NewL
   182 // ---------------------------------------------------------
   182 // ---------------------------------------------------------
   183 //
   183 //
   184 CCookie* CCookie::CloneL( const CCookie& aCopy )
   184 CCookie* CCookie::CloneL( const CCookie& aCopy,const TDesC8& aDomain,const TDesC8& aPath, const TDesC8& aPort)
   185     {
   185     {
   186     CCookie* self = new(ELeave) CCookie( aCopy.iStringPool );
   186     CCookie* self = new(ELeave) CCookie( aCopy.iStringPool );
   187     CleanupStack::PushL( self );
   187     CleanupStack::PushL( self );
   188     self->CopyFromL( aCopy );
   188     self->CopyFromL( aCopy, aDomain, aPath, aPort);
   189     CleanupStack::Pop( self );
   189     CleanupStack::Pop( self );
   190     return self;
   190     return self;
   191     }
   191     }
   192 	
   192 	
   193 
   193 
   442 
   442 
   443 // ---------------------------------------------------------
   443 // ---------------------------------------------------------
   444 // CCookie::CopyFromL
   444 // CCookie::CopyFromL
   445 // ---------------------------------------------------------
   445 // ---------------------------------------------------------
   446 //
   446 //
   447 void CCookie::CopyFromL( const CCookie& aCopyFrom  )
   447 void CCookie::CopyFromL( const CCookie& aCopyFrom, const TDesC8& aDomain, const TDesC8& aPath, const TDesC8& aPort  )
   448     {
   448     {
   449     CLOG( ( ECookie, 0, _L( "-> CCookie::CopyFromL ") ) );
   449     CLOG( ( ECookie, 0, _L( "-> CCookie::CopyFromL ") ) );
       
   450     TBool defaultDiscard( EFalse );
   450     THTTPHdrVal attributevalue;
   451     THTTPHdrVal attributevalue;
   451     TBool defaulted( EFalse );
   452     TBool defaulted( EFalse );
       
   453     iSetCookie2 = aCopyFrom.iSetCookie2;
   452     if ( aCopyFrom.Attribute( EName, attributevalue, defaulted ) != KErrNotFound )
   454     if ( aCopyFrom.Attribute( EName, attributevalue, defaulted ) != KErrNotFound )
   453         {
   455         {
   454         if ( attributevalue.Type() != THTTPHdrVal::KStrVal )
   456         if ( attributevalue.Type() != THTTPHdrVal::KStrVal )
   455              {
   457              {
   456              RString correctedStringType = iStringPool.OpenStringL( attributevalue.StrF().DesC() );
   458              RString correctedStringType = iStringPool.OpenStringL( attributevalue.StrF().DesC() );
   461              CLOG( ( ECookie, 0, _L8( "CCookie::CopyFromL - attribute EName Value : %S" ), &pVal ) );
   463              CLOG( ( ECookie, 0, _L8( "CCookie::CopyFromL - attribute EName Value : %S" ), &pVal ) );
   462              }
   464              }
   463         else 
   465         else 
   464             {
   466             {
   465             SetAttribute( EName, attributevalue, defaulted );    
   467             SetAttribute( EName, attributevalue, defaulted );    
       
   468             const TPtrC8 pVal( attributevalue.Str().DesC() );
       
   469             CLOG( ( ECookie, 0, _L8( "CCookie::CopyFromL - attribute EName Value : %S" ), &pVal ) );
   466             }
   470             }
   467         }
   471         }
   468 
   472 
   469     if ( aCopyFrom.Attribute( EValue, attributevalue, defaulted ) != KErrNotFound )
   473     if ( aCopyFrom.Attribute( EValue, attributevalue, defaulted ) != KErrNotFound )
   470         {
   474         {
   477             const TPtrC8 pVal( attributevalue.Str().DesC() );
   481             const TPtrC8 pVal( attributevalue.Str().DesC() );
   478             CLOG( ( ECookie, 0, _L8( "CCookie::CopyFromL - attribute EValue value: %S" ), &pVal ) );
   482             CLOG( ( ECookie, 0, _L8( "CCookie::CopyFromL - attribute EValue value: %S" ), &pVal ) );
   479             }
   483             }
   480          else
   484          else
   481              {
   485              {
   482              SetAttribute( EValue, attributevalue, defaulted );             
   486              SetAttribute( EValue, attributevalue, defaulted );
       
   487              const TPtrC8 pVal( attributevalue.Str().DesC() );
       
   488              CLOG( ( ECookie, 0, _L8( "CCookie::CopyFromL - attribute EValue Value : %S" ), &pVal ) );
   483              }
   489              }
   484         }
   490         }
   485 	if ( aCopyFrom.Attribute( EComment, attributevalue, defaulted ) != KErrNotFound )
   491     if ( aCopyFrom.Attribute( EVersion, attributevalue, defaulted ) != KErrNotFound )
   486         {
   492         {
   487         SetAttribute( EComment, attributevalue, defaulted );
   493         SetAttribute( EVersion, attributevalue, defaulted );    
   488         }
   494         SetFromNetscape( EFalse );
   489 
   495         }
   490 	if ( aCopyFrom.Attribute( ECommentURI, attributevalue, defaulted ) != KErrNotFound )
   496     else
   491         {
   497         {
   492         SetAttribute( ECommentURI, attributevalue, defaulted );
   498         SetFromNetscape( ETrue );
   493         }
   499         }
   494 
   500 
   495 	if ( aCopyFrom.Attribute( EDiscard, attributevalue, defaulted ) != KErrNotFound )
   501     if ( aCopyFrom.Attribute( EPath, attributevalue, defaulted ) != KErrNotFound )
   496         {
   502         {
   497         SetAttribute( EDiscard, attributevalue, defaulted );
   503          if ( attributevalue.Type() != THTTPHdrVal::KStrFVal )
   498         }
   504              {
   499 
   505              SetAttribute( EPath, attributevalue, defaulted );    
   500 	if ( aCopyFrom.Attribute( EDomain, attributevalue, defaulted ) != KErrNotFound )
   506              }
   501         {
   507         }
   502         SetAttribute( EDomain, attributevalue, defaulted );
   508     else
   503         }
   509         {
   504 
   510         // defaulting
   505 	if ( aCopyFrom.Attribute( EMaxAge, attributevalue, defaulted ) != KErrNotFound )
   511         RStringF defPath = iStringPool.OpenFStringL( aPath );
   506         {
   512         THTTPHdrVal defPathVal( defPath );
   507         SetAttribute( EMaxAge, attributevalue, defaulted );
   513         SetAttribute( EPath, defPathVal, ETrue );// ignore the result 
   508         }
   514         defPath.Close();
   509 
   515         }
   510 	if ( aCopyFrom.Attribute( EPath, attributevalue, defaulted ) != KErrNotFound )
   516     if ( aCopyFrom.Attribute( EDomain, attributevalue, defaulted ) != KErrNotFound )
   511         {
   517           {
   512         SetAttribute( EPath, attributevalue, defaulted );
   518           if ( attributevalue.Type() != THTTPHdrVal::KStrFVal )
   513         }
   519               {
   514 
   520               SetAttribute( EDomain, attributevalue, defaulted );    
   515 	if ( aCopyFrom.Attribute( EPort, attributevalue, defaulted ) != KErrNotFound )
   521               }
   516         {
   522           }
   517         SetAttribute( EPort, attributevalue, defaulted );
   523     else
   518         }
   524        {
   519 
   525          // Default handling 
   520 	if ( aCopyFrom.Attribute( ESecure, attributevalue, defaulted ) != KErrNotFound )
   526          // in this case the default is the effective request host        
   521         {
   527          RStringF defDomain = iStringPool.OpenFStringL( aDomain );
   522         SetAttribute( ESecure, attributevalue, defaulted );
   528          THTTPHdrVal defdomVal( defDomain );
   523         }
   529          SetAttribute( EDomain, defdomVal, ETrue );// ignore the result 
   524 
   530          defDomain.Close();
   525 	if ( aCopyFrom.Attribute( EVersion, attributevalue, defaulted ) != KErrNotFound )
   531        }
   526         {
   532   
   527         SetAttribute( EVersion, attributevalue, defaulted );
   533     
   528         }
   534     if ( aCopyFrom.Attribute( ESecure, attributevalue, defaulted ) != KErrNotFound )
   529 
   535 	      {
   530 	if ( aCopyFrom.Attribute( EExpires, attributevalue, defaulted ) != KErrNotFound )
   536             SetAttribute( ESecure, attributevalue, defaulted );    
   531         {
   537 	      }
   532         SetAttribute( EExpires, attributevalue, defaulted );
   538     if (iNetscape)
   533         }
   539          {
   534 		
   540          if ( aCopyFrom.Attribute( EExpires, attributevalue, defaulted ) != KErrNotFound )
   535 	TTime nowTime;
   541               {
   536     nowTime.UniversalTime();
   542                   SetAttribute( EExpires, attributevalue, defaulted );    
   537     TDateTime attrTime = nowTime.DateTime();
   543               }
   538     THTTPHdrVal attributeVal( attrTime );
   544          else if ( aCopyFrom.Attribute( EComment, attributevalue, defaulted ) != KErrNotFound ||
   539     SetAttribute( EDate, attributeVal, defaulted );
   545                            aCopyFrom.Attribute( EMaxAge, attributevalue, defaulted ) != KErrNotFound )
       
   546              {
       
   547              iNetscape = EFalse;
       
   548              }
       
   549          }
       
   550      if ( aCopyFrom.Attribute( EDate, attributevalue, defaulted ) != KErrNotFound )
       
   551           {
       
   552           TDateTime attrTime = attributevalue.DateTime();
       
   553           THTTPHdrVal attributeVal( attrTime );
       
   554           SetAttribute( CCookie::EDate, attributeVal, defaulted );
       
   555           }
       
   556      else
       
   557          {
       
   558            TTime nowTime;
       
   559            nowTime.UniversalTime();
       
   560            TDateTime attrTime = nowTime.DateTime();
       
   561            THTTPHdrVal attributeVal( attrTime );
       
   562            SetAttribute( EDate, attributeVal, defaulted );
       
   563          }
       
   564      if (iNetscape == EFalse)
       
   565          {
       
   566          if ( aCopyFrom.Attribute( EComment, attributevalue, defaulted ) != KErrNotFound )
       
   567              {
       
   568              SetAttribute( EComment, attributevalue );
       
   569              }
       
   570          else
       
   571              {
       
   572              
       
   573              }
       
   574          if ( aCopyFrom.Attribute( EMaxAge, attributevalue, defaulted ) != KErrNotFound)
       
   575              {
       
   576              SetAttribute( EMaxAge, attributevalue );
       
   577              }
       
   578          else
       
   579              {
       
   580               if(iSetCookie2)
       
   581                   {
       
   582                   defaultDiscard = ETrue;
       
   583                   }
       
   584              }
       
   585          if(iSetCookie2)
       
   586              {
       
   587              if ( aCopyFrom.Attribute( ECommentURI, attributevalue, defaulted ) != KErrNotFound )
       
   588                  {
       
   589                  SetAttribute( ECommentURI, attributevalue, defaulted );
       
   590                  }
       
   591              else
       
   592                  {
       
   593                  
       
   594                  }
       
   595              if ( aCopyFrom.Attribute( EDiscard, attributevalue, defaulted ) != KErrNotFound )
       
   596                   {
       
   597                       SetAttribute( EDiscard, attributevalue, defaulted );    
       
   598                   }
       
   599              else
       
   600                 {
       
   601                  if (defaultDiscard)
       
   602                      {
       
   603                      RStringF emptyStr = iStringPool.OpenFStringL( KNullDesC8() );
       
   604                      THTTPHdrVal emptyVal( emptyStr );
       
   605                      SetAttribute( EDiscard, emptyVal, ETrue );
       
   606                      emptyStr.Close();
       
   607                      }
       
   608                  if (aCopyFrom.Attribute( EPort, attributevalue, defaulted ) != KErrNotFound)
       
   609                      {
       
   610                      SetAttribute( EPort, attributevalue, ETrue );    // ignore the result of this method
       
   611                      }
       
   612                  else
       
   613                      {
       
   614                      RStringF requestPort;
       
   615                      if(!aPort.Compare(KNullDesC8()))
       
   616                          {
       
   617                          requestPort = iStringPool.OpenFStringL( aPort );
       
   618                          }
       
   619                      else
       
   620                          {
       
   621                          requestPort = iStringPool.OpenFStringL( KCookieDefaultRequestPort() );
       
   622                          }
       
   623                      THTTPHdrVal portVal( requestPort );
       
   624                      SetAttribute( EPort, portVal, ETrue );
       
   625                      requestPort.Close();
       
   626                      }
       
   627                 }
       
   628              
       
   629              }
       
   630              
       
   631          }
       
   632 	
   540 
   633 
   541     //SetCookie2( aCopyFrom.FromCookie2() );
   634     //SetCookie2( aCopyFrom.FromCookie2() );
   542     // Other properties
   635     // Other properties
   543     iSetCookie2 = aCopyFrom.iSetCookie2;
   636     
   544     iNetscape = aCopyFrom.iNetscape;
       
   545     iSize = aCopyFrom.iSize;
   637     iSize = aCopyFrom.iSize;
   546     iReceivedTime = aCopyFrom.iReceivedTime;
   638     iReceivedTime = aCopyFrom.iReceivedTime;
   547     CLOG( ( ECookie, 0, _L( "<- CCookie::CopyFromL ") ) );
   639     CLOG( ( ECookie, 0, _L( "<- CCookie::CopyFromL ") ) );
   548     }
   640     }
   549 
   641 
  1032 	RStringF setCookie2Name = iStringPool.StringF( HTTP::ESetCookie2,
  1124 	RStringF setCookie2Name = iStringPool.StringF( HTTP::ESetCookie2,
  1033                                                    commonStringTable );
  1125                                                    commonStringTable );
  1034 
  1126 
  1035 	iSetCookie2 = ( aFieldName == setCookie2Name );
  1127 	iSetCookie2 = ( aFieldName == setCookie2Name );
  1036 
  1128 
  1037     TBool DefaultDiscard( EFalse );
  1129     TBool defaultDiscard( EFalse );
  1038 
  1130 
  1039 	THTTPHdrVal hVal;
  1131 	THTTPHdrVal hVal;
  1040 
  1132 
  1041 	// Retrieval of NAME attribute
  1133 	// Retrieval of NAME attribute
  1042     // ---------------------------------------------------------
  1134     // ---------------------------------------------------------
  1235             // Defaults to Discard, discard the cookie on agent termination
  1327             // Defaults to Discard, discard the cookie on agent termination
  1236             // -> transient cookie
  1328             // -> transient cookie
  1237             // in case of SetCookie2, also set Discard, defaulted
  1329             // in case of SetCookie2, also set Discard, defaulted
  1238             if ( iSetCookie2 )
  1330             if ( iSetCookie2 )
  1239                 {
  1331                 {
  1240                 DefaultDiscard = ETrue;
  1332                 defaultDiscard = ETrue;
  1241                 }
  1333                 }
  1242            }
  1334            }
  1243 
  1335 
  1244         // now if it is SetCookie2, than get SetCookie2 specific parts
  1336         // now if it is SetCookie2, than get SetCookie2 specific parts
  1245         if ( iSetCookie2 )
  1337         if ( iSetCookie2 )
  1273                 }
  1365                 }
  1274             else
  1366             else
  1275                 { // Add default handling if applies
  1367                 { // Add default handling if applies
  1276 		        // no defaulting for EDiscard
  1368 		        // no defaulting for EDiscard
  1277                 // only if it is caused by MAx-Age beeing not supplied
  1369                 // only if it is caused by MAx-Age beeing not supplied
  1278                 if ( DefaultDiscard )
  1370                 if ( defaultDiscard )
  1279                     {
  1371                     {
  1280 		            RStringF emptyStr = iStringPool.OpenFStringL( KNullDesC8() );
  1372 		            RStringF emptyStr = iStringPool.OpenFStringL( KNullDesC8() );
  1281                     THTTPHdrVal emptyVal( emptyStr );
  1373                     THTTPHdrVal emptyVal( emptyStr );
  1282     		        SetAttribute( EDiscard, emptyVal, ETrue );
  1374     		        SetAttribute( EDiscard, emptyVal, ETrue );
  1283 	    	        emptyStr.Close();
  1375 	    	        emptyStr.Close();