webengine/osswebengine/cache/src/HttpCacheUtil.cpp
branchRCL_3
changeset 91 30342f40acbf
parent 36 0ed94ceaa377
child 93 79859ed3eea9
equal deleted inserted replaced
84:800203832575 91:30342f40acbf
    25 #include <stringpool.h>
    25 #include <stringpool.h>
    26 #include <flogger.h>
    26 #include <flogger.h>
    27 #include "TInternetdate.h"
    27 #include "TInternetdate.h"
    28 #include "httpfiltercommonstringsext.h"
    28 #include "httpfiltercommonstringsext.h"
    29 #include "HttpCacheEntry.h"
    29 #include "HttpCacheEntry.h"
       
    30 #include <browser_platform_variant.hrh>
    30 
    31 
    31 // EXTERNAL DATA STRUCTURES
    32 // EXTERNAL DATA STRUCTURES
    32 
    33 
    33 // EXTERNAL FUNCTION PROTOTYPES
    34 // EXTERNAL FUNCTION PROTOTYPES
    34 
    35 
  1638         }
  1639         }
  1639 
  1640 
  1640     // init the field name
  1641     // init the field name
  1641     fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() );
  1642     fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() );
  1642     TRAP( status, cacheCount = aHeaders.FieldPartsL( fieldName ) );
  1643     TRAP( status, cacheCount = aHeaders.FieldPartsL( fieldName ) );
       
  1644     
       
  1645 #ifdef __CACHELOG__
       
  1646             HttpCacheUtil::WriteLog(0,_L("cacheCount ="),cacheCount);
       
  1647 #endif
       
  1648             
  1643     if( status == KErrNone )
  1649     if( status == KErrNone )
  1644         {
  1650         {
  1645         for( i = 0; i < cacheCount; i++ )
  1651         for( i = 0; i < cacheCount; i++ )
  1646             {
  1652             {
  1647             status = GetCacheControlDirective( aHeaders, i, directive, &value, &extraValues, aStrP );
  1653             status = GetCacheControlDirective( aHeaders, i, directive, &value, &extraValues, aStrP );
  1720     THTTPHdrVal hdrVal;
  1726     THTTPHdrVal hdrVal;
  1721     TInt err;
  1727     TInt err;
  1722 
  1728 
  1723     // Get the cache-control from the headers
  1729     // Get the cache-control from the headers
  1724     fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() );
  1730     fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() );
       
  1731 
  1725     aHeaders.GetField( fieldName, aIndex, hdrVal );
  1732     aHeaders.GetField( fieldName, aIndex, hdrVal );
  1726 
  1733     
       
  1734 #ifdef __CACHELOG__
       
  1735     HttpCacheUtil::WriteLog(0,_L("In GetCacheControlDirective Printing fieldName"));
       
  1736     HttpCacheUtil::WriteUrlToLog( 0, fieldName.DesC().Left(fieldName.DesC().Length()) );
       
  1737 #endif
       
  1738     
  1727     if( hdrVal.Type() == THTTPHdrVal::KStrVal || hdrVal.Type() == THTTPHdrVal::KStrFVal )
  1739     if( hdrVal.Type() == THTTPHdrVal::KStrVal || hdrVal.Type() == THTTPHdrVal::KStrFVal )
  1728         {
  1740         {
  1729         RStringF cacheDir = hdrVal.StrF();
  1741         RStringF cacheDir = hdrVal.StrF();
  1730 
  1742         
       
  1743 #ifdef __CACHELOG__
       
  1744         HttpCacheUtil::WriteLog(0,_L("In GetCacheControlDirective Printing hdrVal.StrF()"));
       
  1745         HttpCacheUtil::WriteUrlToLog( 0, hdrVal.StrF().DesC().Left(hdrVal.StrF().DesC().Length()) );
       
  1746         
       
  1747         HttpCacheUtil::WriteLog(0,_L("In GetCacheControlDirective Printing cacheDir"));
       
  1748         HttpCacheUtil::WriteUrlToLog( 0, cacheDir.DesC().Left(cacheDir.DesC().Length()) );
       
  1749 #endif
       
  1750         
       
  1751 #ifdef BRDO_CACHE_MAX_AGE
       
  1752         
       
  1753         //If the cache-control is key value pair
       
  1754         if(cacheDir.DesC().Length() == NULL)
       
  1755             {
       
  1756         
       
  1757             err = ExtractCacheControlDirectivePairValue(aHeaders,aStrP,aDirective,aDirectiveValue,aIndex);
       
  1758 #ifdef __CACHELOG__
       
  1759             HttpCacheUtil::WriteLog(0,_L("In GetCacheControlDirective Printing aDirective"));
       
  1760             HttpCacheUtil::WriteUrlToLog(0, aDirective.DesC().Left(aDirective.DesC().Length()) );
       
  1761 #endif
       
  1762 #else
  1731         TInt endPos;
  1763         TInt endPos;
  1732         _LIT8(KFind, "=");
  1764         _LIT8(KFind, "=");
  1733 
  1765 
  1734         endPos = cacheDir.DesC().Find( KFind );
  1766         endPos = cacheDir.DesC().Find( KFind );
  1735         if( endPos != -1 )
  1767         if( endPos != -1 )
  1739                 {
  1771                 {
  1740                 return err;
  1772                 return err;
  1741                 }
  1773                 }
  1742             TPtrC8 value = cacheDir.DesC().Right( cacheDir.DesC().Length() - endPos - 1 );
  1774             TPtrC8 value = cacheDir.DesC().Right( cacheDir.DesC().Length() - endPos - 1 );
  1743             err = ExtractCacheControlDirectiveValue( aStrP, aDirective, value, aDirectiveValue, aExtraValue );
  1775             err = ExtractCacheControlDirectiveValue( aStrP, aDirective, value, aDirectiveValue, aExtraValue );
       
  1776 
       
  1777 #ifdef __CACHELOG__
       
  1778             HttpCacheUtil::WriteLog(0,_L("In GetCacheControlDirective Printing aDirective"));
       
  1779             HttpCacheUtil::WriteUrlToLog(0, aDirective.DesC().Left(aDirective.DesC().Length()) );
       
  1780 #endif
       
  1781             
  1744             if( err != KErrNone )
  1782             if( err != KErrNone )
  1745                 {
  1783                 {
  1746                 aDirective.Close();
  1784                 aDirective.Close();
  1747                 return err;
  1785                 return err;
  1748                 }
  1786                 }
  1749             }
  1787 #endif 
       
  1788             }
       
  1789         //If the cache-control is a normal value
  1750         else
  1790         else
  1751             {
  1791             {
  1752             aDirective = cacheDir.Copy();
  1792             aDirective = cacheDir.Copy();
  1753             // Directives which MUST have values
  1793             
       
  1794 #ifdef __CACHELOG__
       
  1795             HttpCacheUtil::WriteLog(0,_L("In GetCacheControlDirective Printing aDirective"));
       
  1796             HttpCacheUtil::WriteUrlToLog(0, aDirective.DesC().Left(aDirective.DesC().Length()) );
       
  1797 #endif
       
  1798             
  1754             if( ( aDirective == aStrP.StringF( HTTP::EMaxAge, RHTTPSession::GetTable() ) ) ||
  1799             if( ( aDirective == aStrP.StringF( HTTP::EMaxAge, RHTTPSession::GetTable() ) ) ||
  1755                 ( aDirective == aStrP.StringF( HTTP::EMinFresh, RHTTPSession::GetTable() ) ) ||
  1800                 ( aDirective == aStrP.StringF( HTTP::EMinFresh, RHTTPSession::GetTable() ) ) ||
  1756                 ( aDirective == aStrP.StringF( HTTP::ESMaxAge, RHTTPSession::GetTable() ) ) )
  1801                 ( aDirective == aStrP.StringF( HTTP::ESMaxAge, RHTTPSession::GetTable() ) ) )
  1757                 {
  1802                 {
  1758                 aDirective.Close();
  1803                 aDirective.Close();
  1759                 return KErrGeneral;
  1804                 return KErrGeneral;
  1760                 }
  1805                 }
       
  1806 #ifdef BRDO_CACHE_MAX_AGE
       
  1807             err = KErrNone;
       
  1808             }
       
  1809         }
       
  1810     return err;
       
  1811 #else
  1761             }
  1812             }
  1762         }
  1813         }
  1763     return KErrNone;
  1814     return KErrNone;
  1764     }
  1815 #endif
  1765 
  1816     }
       
  1817 
       
  1818 #ifdef BRDO_CACHE_MAX_AGE
       
  1819 // -----------------------------------------------------------------------------
       
  1820 // HttpCacheUtil::ExtractCacheControlDirectivePairValue
       
  1821 //
       
  1822 // -----------------------------------------------------------------------------
       
  1823 //
       
  1824 
       
  1825 TInt HttpCacheUtil::ExtractCacheControlDirectivePairValue(
       
  1826     const RHTTPHeaders& aHeaders,
       
  1827     RStringPool aStrP,
       
  1828     RStringF& aDirective,
       
  1829     TInt64* aDirectiveValue,
       
  1830     TInt aIndex)
       
  1831     {
       
  1832     RStringF fieldName;
       
  1833     THTTPHdrVal hdrVal;
       
  1834 
       
  1835     // Get the cache-control from the headers
       
  1836     fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() );
       
  1837     
       
  1838 #ifdef __CACHELOG__
       
  1839     HttpCacheUtil::WriteLog(0,_L("In ExtractCacheControlDirectivePairValue Printing fieldName"));
       
  1840     HttpCacheUtil::WriteUrlToLog(0, fieldName.DesC().Left(fieldName.DesC().Length()) );
       
  1841 #endif
       
  1842     
       
  1843     //Get the param name
       
  1844     RStringF paramName = aStrP.StringF( HTTP::EMaxAge, RHTTPSession::GetTable() );
       
  1845     
       
  1846     if(KErrNone != ExtractCacheControlDirectiveValueforParam(aHeaders,aStrP,aDirectiveValue,paramName,aDirective,aIndex))
       
  1847         {
       
  1848         paramName.Close();
       
  1849         paramName = aStrP.StringF( HTTP::EMaxStale, RHTTPSession::GetTable() );
       
  1850         if(KErrNone != ExtractCacheControlDirectiveValueforParam(aHeaders,aStrP,aDirectiveValue,paramName,aDirective,aIndex))
       
  1851             {
       
  1852             paramName.Close();
       
  1853             paramName = aStrP.StringF( HTTP::EMinFresh, RHTTPSession::GetTable() );
       
  1854             if(KErrNone != ExtractCacheControlDirectiveValueforParam(aHeaders,aStrP,aDirectiveValue,paramName,aDirective,aIndex))
       
  1855                 {
       
  1856                 paramName.Close();
       
  1857                 paramName = aStrP.StringF( HTTP::EMustRevalidate, RHTTPSession::GetTable() );
       
  1858                 if(KErrNone != ExtractCacheControlDirectiveValueforParam(aHeaders,aStrP,aDirectiveValue,paramName,aDirective,aIndex))
       
  1859                     {
       
  1860                     paramName.Close();
       
  1861                     paramName = aStrP.StringF( HTTP::ENoCache, RHTTPSession::GetTable() );
       
  1862                     if(KErrNone != ExtractCacheControlDirectiveValueforParam(aHeaders,aStrP,aDirectiveValue,paramName,aDirective,aIndex))
       
  1863                         {
       
  1864                         paramName.Close();
       
  1865                         paramName = aStrP.StringF( HTTP::ENoStore, RHTTPSession::GetTable() );
       
  1866                         if(KErrNone != ExtractCacheControlDirectiveValueforParam(aHeaders,aStrP,aDirectiveValue,paramName,aDirective,aIndex))
       
  1867                             {
       
  1868                             return KErrGeneral;
       
  1869                             }
       
  1870                         }
       
  1871                     }
       
  1872                 }
       
  1873             }
       
  1874         }
       
  1875   
       
  1876     return KErrNone;
       
  1877     }
       
  1878 // -----------------------------------------------------------------------------
       
  1879 // HttpCacheUtil::ExtractCacheControlDirectiveValueforParam
       
  1880 //
       
  1881 // -----------------------------------------------------------------------------
       
  1882 //
       
  1883 TInt HttpCacheUtil::ExtractCacheControlDirectiveValueforParam(
       
  1884     const RHTTPHeaders& aHeaders,
       
  1885     RStringPool aStrP,
       
  1886     TInt64* aDirectiveValue,
       
  1887     RStringF& aFieldParam,
       
  1888     RStringF& aDirective,
       
  1889     TInt aIndex)
       
  1890     {
       
  1891     
       
  1892     RStringF fieldName;
       
  1893     THTTPHdrVal hdrVal;
       
  1894     
       
  1895     // Get the cache-control from the headers
       
  1896     fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() );
       
  1897     
       
  1898     aHeaders.GetParam(fieldName,aFieldParam,hdrVal,aIndex);
       
  1899 #ifdef __CACHELOG__
       
  1900     HttpCacheUtil::WriteLog(0,_L("In ExtractCacheControlDirectiveValueforParam Printing fieldName"));
       
  1901     HttpCacheUtil::WriteUrlToLog( 0, fieldName.DesC().Left(fieldName.DesC().Length()) );
       
  1902     HttpCacheUtil::WriteLog(0,_L("In ExtractCacheControlDirectiveValueforParam Printing aFieldParam"));
       
  1903     HttpCacheUtil::WriteUrlToLog( 0, aFieldParam.DesC().Left(aFieldParam.DesC().Length()) );
       
  1904 #endif
       
  1905     
       
  1906     //If the field param does not exist
       
  1907     if(hdrVal.Type() == THTTPHdrVal::KNoType)
       
  1908         {
       
  1909         return KErrGeneral;
       
  1910         }
       
  1911     else if( hdrVal.Type() == THTTPHdrVal::KTIntVal )
       
  1912         {
       
  1913         if( !(( aFieldParam == aStrP.StringF( HTTP::EMaxAge, RHTTPSession::GetTable() ) ) ||
       
  1914             ( aFieldParam == aStrP.StringF( HTTP::EMinFresh, RHTTPSession::GetTable() ) ) ||
       
  1915             ( aFieldParam == aStrP.StringF( HTTP::ESMaxAge, RHTTPSession::GetTable() ) ) ) )
       
  1916             {
       
  1917                 return KErrGeneral;
       
  1918             }
       
  1919         TInt value = hdrVal.Int();
       
  1920         *aDirectiveValue = (TInt64)value;
       
  1921         }
       
  1922     else
       
  1923         {
       
  1924         if( !(( aFieldParam == aStrP.StringF( HTTP::ENoCache, RHTTPSession::GetTable() ) ) ||
       
  1925               ( aFieldParam == aStrP.StringF( HTTP::EPrivate, RHTTPSession::GetTable() ) ) ||
       
  1926               ( aFieldParam == aStrP.StringF( HTTP::EMustRevalidate, RHTTPSession::GetTable() ) )) )
       
  1927             {
       
  1928                 return KErrGeneral;
       
  1929             }
       
  1930         }
       
  1931         aDirective = aFieldParam.Copy();
       
  1932         return KErrNone;
       
  1933     }
       
  1934 
       
  1935 #else
  1766 // -----------------------------------------------------------------------------
  1936 // -----------------------------------------------------------------------------
  1767 // HttpCacheUtil::ExtractCacheControlDirectiveValue
  1937 // HttpCacheUtil::ExtractCacheControlDirectiveValue
  1768 //
  1938 //
  1769 // -----------------------------------------------------------------------------
  1939 // -----------------------------------------------------------------------------
  1770 //
  1940 //
       
  1941 
  1771 TInt HttpCacheUtil::ExtractCacheControlDirectiveValue(
  1942 TInt HttpCacheUtil::ExtractCacheControlDirectiveValue(
  1772     RStringPool aStrP,
  1943     RStringPool aStrP,
  1773     RStringF& aDirective,
  1944     RStringF& aDirective,
  1774     TDesC8& aValue,
  1945     TDesC8& aValue,
  1775     TInt64* aDirectiveValue,
  1946     TInt64* aDirectiveValue,
  1777     {
  1948     {
  1778     TInt status( KErrNone );
  1949     TInt status( KErrNone );
  1779     TInt temp;
  1950     TInt temp;
  1780     char* errorIfNull;
  1951     char* errorIfNull;
  1781 
  1952 
       
  1953 #ifdef __CACHELOG__
       
  1954     HttpCacheUtil::WriteLog(0,_L("In ExtractCacheControlDirectiveValue "));
       
  1955 #endif
       
  1956     
  1782     *aDirectiveValue = -1;
  1957     *aDirectiveValue = -1;
  1783     *aExtraValue = NULL;
  1958     *aExtraValue = NULL;
  1784     char* valuestr = (char*)User::Alloc( aValue.Length() + 1 );
  1959     char* valuestr = (char*)User::Alloc( aValue.Length() + 1 );
  1785     if( !valuestr )
  1960     if( !valuestr )
  1786         {
  1961         {
  1827         return status;
  2002         return status;
  1828         }
  2003         }
  1829     User::Free( valuestr );
  2004     User::Free( valuestr );
  1830     return status;
  2005     return status;
  1831     }
  2006     }
  1832 
  2007 #endif
  1833 
       
  1834 // -----------------------------------------------------------------------------
  2008 // -----------------------------------------------------------------------------
  1835 // FilePathHash
  2009 // FilePathHash
  1836 // Hash function for Symbian file paths: discards case first
  2010 // Hash function for Symbian file paths: discards case first
  1837 // -----------------------------------------------------------------------------
  2011 // -----------------------------------------------------------------------------
  1838 static TUint32 FilepathHash(const TDesC& aDes)
  2012 static TUint32 FilepathHash(const TDesC& aDes)