1726 THTTPHdrVal hdrVal; |
1720 THTTPHdrVal hdrVal; |
1727 TInt err; |
1721 TInt err; |
1728 |
1722 |
1729 // Get the cache-control from the headers |
1723 // Get the cache-control from the headers |
1730 fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() ); |
1724 fieldName = aStrP.StringF( HTTP::ECacheControl, RHTTPSession::GetTable() ); |
1731 |
|
1732 aHeaders.GetField( fieldName, aIndex, hdrVal ); |
1725 aHeaders.GetField( fieldName, aIndex, hdrVal ); |
1733 |
1726 |
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 |
|
1739 if( hdrVal.Type() == THTTPHdrVal::KStrVal || hdrVal.Type() == THTTPHdrVal::KStrFVal ) |
1727 if( hdrVal.Type() == THTTPHdrVal::KStrVal || hdrVal.Type() == THTTPHdrVal::KStrFVal ) |
1740 { |
1728 { |
1741 RStringF cacheDir = hdrVal.StrF(); |
1729 RStringF cacheDir = hdrVal.StrF(); |
1742 |
1730 |
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 |
|
1763 TInt endPos; |
1731 TInt endPos; |
1764 _LIT8(KFind, "="); |
1732 _LIT8(KFind, "="); |
1765 |
1733 |
1766 endPos = cacheDir.DesC().Find( KFind ); |
1734 endPos = cacheDir.DesC().Find( KFind ); |
1767 if( endPos != -1 ) |
1735 if( endPos != -1 ) |
1771 { |
1739 { |
1772 return err; |
1740 return err; |
1773 } |
1741 } |
1774 TPtrC8 value = cacheDir.DesC().Right( cacheDir.DesC().Length() - endPos - 1 ); |
1742 TPtrC8 value = cacheDir.DesC().Right( cacheDir.DesC().Length() - endPos - 1 ); |
1775 err = ExtractCacheControlDirectiveValue( aStrP, aDirective, value, aDirectiveValue, aExtraValue ); |
1743 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 |
|
1782 if( err != KErrNone ) |
1744 if( err != KErrNone ) |
1783 { |
1745 { |
1784 aDirective.Close(); |
1746 aDirective.Close(); |
1785 return err; |
1747 return err; |
1786 } |
1748 } |
1787 #endif |
1749 } |
1788 } |
|
1789 //If the cache-control is a normal value |
|
1790 else |
1750 else |
1791 { |
1751 { |
1792 aDirective = cacheDir.Copy(); |
1752 aDirective = cacheDir.Copy(); |
1793 |
1753 // Directives which MUST have values |
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 |
|
1799 if( ( aDirective == aStrP.StringF( HTTP::EMaxAge, RHTTPSession::GetTable() ) ) || |
1754 if( ( aDirective == aStrP.StringF( HTTP::EMaxAge, RHTTPSession::GetTable() ) ) || |
1800 ( aDirective == aStrP.StringF( HTTP::EMinFresh, RHTTPSession::GetTable() ) ) || |
1755 ( aDirective == aStrP.StringF( HTTP::EMinFresh, RHTTPSession::GetTable() ) ) || |
1801 ( aDirective == aStrP.StringF( HTTP::ESMaxAge, RHTTPSession::GetTable() ) ) ) |
1756 ( aDirective == aStrP.StringF( HTTP::ESMaxAge, RHTTPSession::GetTable() ) ) ) |
1802 { |
1757 { |
1803 aDirective.Close(); |
1758 aDirective.Close(); |
1804 return KErrGeneral; |
1759 return KErrGeneral; |
1805 } |
1760 } |
1806 #ifdef BRDO_CACHE_MAX_AGE |
|
1807 err = KErrNone; |
|
1808 } |
|
1809 } |
|
1810 return err; |
|
1811 #else |
|
1812 } |
1761 } |
1813 } |
1762 } |
1814 return KErrNone; |
1763 return KErrNone; |
1815 #endif |
1764 } |
1816 } |
1765 |
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 |
|
1936 // ----------------------------------------------------------------------------- |
1766 // ----------------------------------------------------------------------------- |
1937 // HttpCacheUtil::ExtractCacheControlDirectiveValue |
1767 // HttpCacheUtil::ExtractCacheControlDirectiveValue |
1938 // |
1768 // |
1939 // ----------------------------------------------------------------------------- |
1769 // ----------------------------------------------------------------------------- |
1940 // |
1770 // |
1941 |
|
1942 TInt HttpCacheUtil::ExtractCacheControlDirectiveValue( |
1771 TInt HttpCacheUtil::ExtractCacheControlDirectiveValue( |
1943 RStringPool aStrP, |
1772 RStringPool aStrP, |
1944 RStringF& aDirective, |
1773 RStringF& aDirective, |
1945 TDesC8& aValue, |
1774 TDesC8& aValue, |
1946 TInt64* aDirectiveValue, |
1775 TInt64* aDirectiveValue, |