applayerprotocols/httpservice/src/chttpservice.cpp
changeset 49 b91bcc4b38e4
parent 19 2f328ce1b263
equal deleted inserted replaced
48:cfbc3a3bd32b 49:b91bcc4b38e4
    21 const TInt KMaxNoOfConnections = 6;
    21 const TInt KMaxNoOfConnections = 6;
    22 const TInt KMaxTransToPipeline = 5;
    22 const TInt KMaxTransToPipeline = 5;
    23 
    23 
    24 /**
    24 /**
    25  * The default 2-phase constructor to create a CHttpService instance
    25  * The default 2-phase constructor to create a CHttpService instance
    26  * 
    26  * @publishedAll
       
    27  * @prototype  
    27  */
    28  */
    28 EXPORT_C CHttpService* CHttpService::NewL()
    29 EXPORT_C CHttpService* CHttpService::NewL()
    29 	{
    30 	{
    30     CHttpService* self = new(ELeave) CHttpService;
    31     CHttpService* self = new(ELeave) CHttpService;
    31 	CleanupStack::PushL(self);
    32 	CleanupStack::PushL(self);
    33 	CleanupStack::Pop(); // self
    34 	CleanupStack::Pop(); // self
    34 	return self;	
    35 	return self;	
    35 	}
    36 	}
    36 /**
    37 /**
    37  * Destructor
    38  * Destructor
       
    39  * @publishedAll
       
    40  * @prototype  
    38  */	
    41  */	
    39 
    42 
    40 EXPORT_C CHttpService::~CHttpService()
    43 EXPORT_C CHttpService::~CHttpService()
    41 	{
    44 	{
    42 	if(iHttpServiceStruct)
    45 	if(iHttpServiceStruct)
    61  * @param @aStringId String ID
    64  * @param @aStringId String ID
    62  * @param aPtr  String
    65  * @param aPtr  String
    63  * 
    66  * 
    64  * @return KErrNotFound if the string ID is not found in the HTTP string pool
    67  * @return KErrNotFound if the string ID is not found in the HTTP string pool
    65  *          otherwise KErrNone for success
    68  *          otherwise KErrNone for success
       
    69  *          
       
    70  * @publishedAll
       
    71  * @prototype 
    66  */
    72  */
    67 EXPORT_C TInt CHttpService::String(TInt aStringId, TPtrC8& aPtr)
    73 EXPORT_C TInt CHttpService::String(TInt aStringId, TPtrC8& aPtr)
    68     {
    74     {
    69     RStringF str = iHttpServiceStruct->iHttpSession.StringPool().StringF(aStringId, RHTTPSession::GetTable());
    75     RStringF str = iHttpServiceStruct->iHttpSession.StringPool().StringF(aStringId, RHTTPSession::GetTable());
    70     aPtr.Set(str.DesC());
    76     aPtr.Set(str.DesC());
   103 /**
   109 /**
   104  * Returns the proxy address that is set
   110  * Returns the proxy address that is set
   105  * 
   111  * 
   106  * @return Proxy address otherwise KNullDesC8 if the proxy information
   112  * @return Proxy address otherwise KNullDesC8 if the proxy information
   107  *         is not set.
   113  *         is not set.
   108  * 
   114  *         
       
   115  * @publishedAll
       
   116  * @prototype  
   109  */
   117  */
   110 
   118 
   111 EXPORT_C const TDesC8& CHttpService::ProxyAddress() const
   119 EXPORT_C const TDesC8& CHttpService::ProxyAddress() const
   112 	{
   120 	{
   113 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   121 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   128 /**
   136 /**
   129  * Set the maxuimum number of TCP connections[socket] CHttpService instance that can activated 
   137  * Set the maxuimum number of TCP connections[socket] CHttpService instance that can activated 
   130  * at any time. The default no. of connections that the CHttpService instance uses is 6.
   138  * at any time. The default no. of connections that the CHttpService instance uses is 6.
   131  * 
   139  * 
   132  * @param aValue aValue No. of connections
   140  * @param aValue aValue No. of connections
       
   141  * 
       
   142  * @publishedAll
       
   143  * @prototype  
   133  */
   144  */
   134 
   145 
   135 EXPORT_C void CHttpService::SetMaxConnections(TInt aValue)
   146 EXPORT_C void CHttpService::SetMaxConnections(TInt aValue)
   136 	{
   147 	{
   137 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   148 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   158 			return val.Int();
   169 			return val.Int();
   159 		}
   170 		}
   160 	return 0;
   171 	return 0;
   161 	}
   172 	}
   162 	
   173 	
   163 
   174 /**
       
   175  * Sets the maximum number of transactions to be pipelined.
       
   176  * @param aValue - number of transactions
       
   177  *
       
   178  * @publishedAll
       
   179  * @prototype 
       
   180  */ 
   164 EXPORT_C void CHttpService::SetMaxTransactionsToPipeline(TInt aValue)
   181 EXPORT_C void CHttpService::SetMaxTransactionsToPipeline(TInt aValue)
   165 	{
   182 	{
   166 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   183 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   167 	RStringPool sp = sess.StringPool();
   184 	RStringPool sp = sess.StringPool();
   168 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   185 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   169 	
   186 	
   170 	connInfo.SetProperty(sp.StringF(HTTP::EMaxNumTransactionsToPipeline, RHTTPSession::GetTable()), THTTPHdrVal(aValue));				
   187 	connInfo.SetProperty(sp.StringF(HTTP::EMaxNumTransactionsToPipeline, RHTTPSession::GetTable()), THTTPHdrVal(aValue));				
   171 	}
   188 	}
   172 	
   189 
       
   190 /**
       
   191  * Returns the maximum number of transactions to be pipelined.
       
   192  * 
       
   193  * @publishedAll
       
   194  * @prototype 
       
   195  */ 
   173 EXPORT_C TInt CHttpService::MaxTransactionsToPipeline() const
   196 EXPORT_C TInt CHttpService::MaxTransactionsToPipeline() const
   174 	{
   197 	{
   175 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   198 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   176 	RStringPool sp = sess.StringPool();
   199 	RStringPool sp = sess.StringPool();
   177 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   200 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   188  * This method facilitates to set the header once in the CHttpService instance that is applicable
   211  * This method facilitates to set the header once in the CHttpService instance that is applicable
   189  * for all HTTP client transactions. [For ex; User-Agent header] 
   212  * for all HTTP client transactions. [For ex; User-Agent header] 
   190  * 
   213  * 
   191  * @param aStringId - Pre-defined String ID in the HTTP string pool
   214  * @param aStringId - Pre-defined String ID in the HTTP string pool
   192  * @param aHeaderValue - Value for the header 
   215  * @param aHeaderValue - Value for the header 
       
   216  * 
       
   217  * @publishedAll
       
   218  * @prototype 
   193  */
   219  */
   194 EXPORT_C TInt CHttpService::AddRequestHeader(TInt aStringId, const THttpHeaderValueVariant& aHeaderValue)
   220 EXPORT_C TInt CHttpService::AddRequestHeader(TInt aStringId, const THttpHeaderValueVariant& aHeaderValue)
   195 	{
   221 	{
   196 	RHTTPHeaders sessHeaders = iHttpServiceStruct->iSessionHeaders;
   222 	RHTTPHeaders sessHeaders = iHttpServiceStruct->iSessionHeaders;
   197     RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   223     RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   205  * This method facilitates to set the custom HTTP header once in the CHttpService instance that is 
   231  * This method facilitates to set the custom HTTP header once in the CHttpService instance that is 
   206  * applicable for all HTTP client transactions. [For ex; User-Agent header] 
   232  * applicable for all HTTP client transactions. [For ex; User-Agent header] 
   207  * 
   233  * 
   208  * @param aHeaderName - Custom header name
   234  * @param aHeaderName - Custom header name
   209  * @param aHeaderValue - Value for the header 
   235  * @param aHeaderValue - Value for the header 
       
   236  * 
       
   237  * @publishedAll
       
   238  * @prototype 
   210  */
   239  */
   211 EXPORT_C TInt CHttpService::AddCustomRequestHeader(const TDesC8& aHeaderName, const TDesC8& aHeaderValue)
   240 EXPORT_C TInt CHttpService::AddCustomRequestHeader(const TDesC8& aHeaderName, const TDesC8& aHeaderValue)
   212 	{
   241 	{
   213 	_LIT8(KFieldSeparator, "\n");
   242 	_LIT8(KFieldSeparator, "\n");
   214 	RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   243 	RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   220 	TInt err = iHttpServiceStruct->iSessionHeaders.SetRawField(str, aHeaderValue, KFieldSeparator);
   249 	TInt err = iHttpServiceStruct->iSessionHeaders.SetRawField(str, aHeaderValue, KFieldSeparator);
   221 	str.Close();
   250 	str.Close();
   222 	return err;
   251 	return err;
   223 	}
   252 	}
   224 
   253 
       
   254 /**
       
   255  * This method facilitates to set to construct the authentication credentials to be passed by the application
       
   256  * The derived class from MHTTPServiceAuthentication  will be called from the framework, if authentication is required.
       
   257  * @param aCallback - Derived class from MHTTPServiceAuthentication
       
   258  *
       
   259  * @publishedAll
       
   260  * @prototype 
       
   261  */
   225 EXPORT_C TInt CHttpService::SetAuthentication(MHTTPServiceAuthentication* aCallback)
   262 EXPORT_C TInt CHttpService::SetAuthentication(MHTTPServiceAuthentication* aCallback)
   226     {
   263     {
   227     TInt error = KErrGeneral;
   264     TInt error = KErrGeneral;
   228     iHttpServiceStruct->iHttpClientAuthentication = CHttpClientAuthentication::New(iHttpServiceStruct->iHttpSession, aCallback);
   265     iHttpServiceStruct->iHttpClientAuthentication = CHttpClientAuthentication::New(iHttpServiceStruct->iHttpSession, aCallback);
   229     if(iHttpServiceStruct->iHttpClientAuthentication)
   266     if(iHttpServiceStruct->iHttpClientAuthentication)
   245     iHttpServiceStruct->iHttpSession.OpenL();
   282     iHttpServiceStruct->iHttpSession.OpenL();
   246     iHttpServiceStruct->iSessionHeaders = iHttpServiceStruct->iHttpSession.RequestSessionHeadersL();
   283     iHttpServiceStruct->iSessionHeaders = iHttpServiceStruct->iHttpSession.RequestSessionHeadersL();
   247     SetMaxConnections(KMaxNoOfConnections);
   284     SetMaxConnections(KMaxNoOfConnections);
   248     SetMaxTransactionsToPipeline(KMaxTransToPipeline);    
   285     SetMaxTransactionsToPipeline(KMaxTransToPipeline);    
   249 	}
   286 	}
   250 	
   287 
       
   288 /**
       
   289  * returns the CHttpNetworkConnection instance created by the framework.
       
   290  * The class can be used to set the connection properties.
       
   291  *
       
   292  * @publishedAll
       
   293  * @prototype 
       
   294  */
   251 EXPORT_C CHttpNetworkConnection* CHttpService::HttpNetworkConnection()
   295 EXPORT_C CHttpNetworkConnection* CHttpService::HttpNetworkConnection()
   252     {
   296     {
   253     CHttpNetworkConnection *httpNetworkConn = CHttpNetworkConnection::New();
   297     CHttpNetworkConnection *httpNetworkConn = CHttpNetworkConnection::New();
   254     httpNetworkConn->SetHttpService(this);
   298     httpNetworkConn->SetHttpService(this);
   255     return httpNetworkConn;
   299     return httpNetworkConn;
   256     }
   300     }
       
   301 
       
   302 void CHttpService::RemoveUnwantedFilters()
       
   303     {
       
   304     THTTPFilterRegistration filterInfo;
       
   305     RStringPool stringPool = iHttpServiceStruct->iHttpSession.StringPool();
       
   306 
       
   307     RHTTPFilterCollection filterArray = iHttpServiceStruct->iHttpSession.FilterCollection();
       
   308     THTTPFilterIterator iter = filterArray.Query();
       
   309     const TStringTable& st = RHTTPSession::GetTable();
       
   310   
       
   311     iter.First();
       
   312 
       
   313     while (!iter.AtEnd())
       
   314         {
       
   315         // Get next filter registration info
       
   316         filterInfo = iter();
       
   317         RStringF filterName = stringPool.StringF(filterInfo.iName);
       
   318         switch(filterName.Index(st))
       
   319             {
       
   320             //dont remove these filters
       
   321             case HTTP::EClient:
       
   322             case HTTP::EProtocolHandler:
       
   323             case HTTP::EValidation:
       
   324             case HTTP::ERedirect:
       
   325             case HTTP::EHttpConnectFilter:
       
   326                 break;
       
   327             //anything other than above, remove.    
       
   328             default:
       
   329                 filterArray.RemoveFilter(filterName);
       
   330              }
       
   331         ++iter;
       
   332         }
       
   333     }