applayerprotocols/httpservice/src/chttpservice.cpp
branchRCL_3
changeset 20 a0da872af3fa
parent 19 c0c2f28ace9c
equal deleted inserted replaced
19:c0c2f28ace9c 20:a0da872af3fa
    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  * 
       
    27  * @publishedAll
       
    28  * @prototype 
    27  */
    29  */
    28 EXPORT_C CHttpService* CHttpService::NewL()
    30 EXPORT_C CHttpService* CHttpService::NewL()
    29 	{
    31 	{
    30     CHttpService* self = new(ELeave) CHttpService;
    32     CHttpService* self = new(ELeave) CHttpService;
    31 	CleanupStack::PushL(self);
    33 	CleanupStack::PushL(self);
    33 	CleanupStack::Pop(); // self
    35 	CleanupStack::Pop(); // self
    34 	return self;	
    36 	return self;	
    35 	}
    37 	}
    36 /**
    38 /**
    37  * Destructor
    39  * Destructor
       
    40  * @publishedAll
       
    41  * @prototype 
    38  */	
    42  */	
    39 
    43 
    40 EXPORT_C CHttpService::~CHttpService()
    44 EXPORT_C CHttpService::~CHttpService()
    41 	{
    45 	{
    42 	if(iHttpServiceStruct)
    46 	if(iHttpServiceStruct)
    46 	delete iHttpServiceStruct;
    50 	delete iHttpServiceStruct;
    47 	}
    51 	}
    48 
    52 
    49 /**
    53 /**
    50  * Destructor of the inner class CHttpServiceStruct
    54  * Destructor of the inner class CHttpServiceStruct
       
    55  * @publishedAll
       
    56  * @prototype 
    51  */ 
    57  */ 
    52 CHttpService::CHttpServiceStruct::~CHttpServiceStruct()
    58 CHttpService::CHttpServiceStruct::~CHttpServiceStruct()
    53     {
    59     {
    54     delete iHttpClientAuthentication;
    60     delete iHttpClientAuthentication;
    55     }
    61     }
    61  * @param @aStringId String ID
    67  * @param @aStringId String ID
    62  * @param aPtr  String
    68  * @param aPtr  String
    63  * 
    69  * 
    64  * @return KErrNotFound if the string ID is not found in the HTTP string pool
    70  * @return KErrNotFound if the string ID is not found in the HTTP string pool
    65  *          otherwise KErrNone for success
    71  *          otherwise KErrNone for success
    66  */
    72  *
       
    73  * @publishedAll
       
    74  * @prototype 
       
    75  */
       
    76 
    67 EXPORT_C TInt CHttpService::String(TInt aStringId, TPtrC8& aPtr)
    77 EXPORT_C TInt CHttpService::String(TInt aStringId, TPtrC8& aPtr)
    68     {
    78     {
    69     RStringF str = iHttpServiceStruct->iHttpSession.StringPool().StringF(aStringId, RHTTPSession::GetTable());
    79     RStringF str = iHttpServiceStruct->iHttpSession.StringPool().StringF(aStringId, RHTTPSession::GetTable());
    70     aPtr.Set(str.DesC());
    80     aPtr.Set(str.DesC());
    71     return KErrNone;
    81     return KErrNone;
    72     }
    82     }
       
    83 
    73 /**
    84 /**
    74  * Set the proxy that applies to all HTTP client transactions that "this"
    85  * Set the proxy that applies to all HTTP client transactions that "this"
    75  * CHttpService instance creates
    86  * CHttpService instance creates
    76  * 
    87  * 
    77  * @param aProxyAddress Proxy address. [for ex;  http://myproxy.org:8081]
    88  * @param aProxyAddress Proxy address. [for ex;  http://myproxy.org:8081]
   104  * Returns the proxy address that is set
   115  * Returns the proxy address that is set
   105  * 
   116  * 
   106  * @return Proxy address otherwise KNullDesC8 if the proxy information
   117  * @return Proxy address otherwise KNullDesC8 if the proxy information
   107  *         is not set.
   118  *         is not set.
   108  * 
   119  * 
       
   120  * @publishedAll
       
   121  * @prototype 
   109  */
   122  */
   110 
   123 
   111 EXPORT_C const TDesC8& CHttpService::ProxyAddress() const
   124 EXPORT_C const TDesC8& CHttpService::ProxyAddress() const
   112 	{
   125 	{
   113 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   126 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   128 /**
   141 /**
   129  * Set the maxuimum number of TCP connections[socket] CHttpService instance that can activated 
   142  * 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.
   143  * at any time. The default no. of connections that the CHttpService instance uses is 6.
   131  * 
   144  * 
   132  * @param aValue aValue No. of connections
   145  * @param aValue aValue No. of connections
       
   146  * 
       
   147  * @publishedAll
       
   148  * @prototype 
   133  */
   149  */
   134 
   150 
   135 EXPORT_C void CHttpService::SetMaxConnections(TInt aValue)
   151 EXPORT_C void CHttpService::SetMaxConnections(TInt aValue)
   136 	{
   152 	{
   137 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   153 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   142 	}
   158 	}
   143 
   159 
   144 /**
   160 /**
   145  * Returns the maximum no. of TCP connections that is set.
   161  * Returns the maximum no. of TCP connections that is set.
   146  * 
   162  * 
       
   163  * @publishedAll
       
   164  * @prototype 
   147  */
   165  */
   148 
   166 
   149 EXPORT_C TInt CHttpService::MaxConnections() const
   167 EXPORT_C TInt CHttpService::MaxConnections() const
   150 	{
   168 	{
   151 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   169 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   159 		}
   177 		}
   160 	return 0;
   178 	return 0;
   161 	}
   179 	}
   162 	
   180 	
   163 
   181 
       
   182 /**
       
   183  * Sets the maximum number of transactions to be pipelined.
       
   184  * @param aValue - number of transactions
       
   185  *
       
   186  * @publishedAll
       
   187  * @prototype 
       
   188  */ 
   164 EXPORT_C void CHttpService::SetMaxTransactionsToPipeline(TInt aValue)
   189 EXPORT_C void CHttpService::SetMaxTransactionsToPipeline(TInt aValue)
   165 	{
   190 	{
   166 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   191 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   167 	RStringPool sp = sess.StringPool();
   192 	RStringPool sp = sess.StringPool();
   168 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   193 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   169 	
   194 	
   170 	connInfo.SetProperty(sp.StringF(HTTP::EMaxNumTransactionsToPipeline, RHTTPSession::GetTable()), THTTPHdrVal(aValue));				
   195 	connInfo.SetProperty(sp.StringF(HTTP::EMaxNumTransactionsToPipeline, RHTTPSession::GetTable()), THTTPHdrVal(aValue));				
   171 	}
   196 	}
   172 	
   197 	
       
   198 /**
       
   199  * Returns the maximum number of transactions to be pipelined.
       
   200  * 
       
   201  * @publishedAll
       
   202  * @prototype 
       
   203  */ 
   173 EXPORT_C TInt CHttpService::MaxTransactionsToPipeline() const
   204 EXPORT_C TInt CHttpService::MaxTransactionsToPipeline() const
   174 	{
   205 	{
   175 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   206 	RHTTPSession sess = iHttpServiceStruct->iHttpSession;
   176 	RStringPool sp = sess.StringPool();
   207 	RStringPool sp = sess.StringPool();
   177 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   208 	RHTTPConnectionInfo connInfo = sess.ConnectionInfo();
   187 /**
   218 /**
   188  * This method facilitates to set the header once in the CHttpService instance that is applicable
   219  * 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] 
   220  * for all HTTP client transactions. [For ex; User-Agent header] 
   190  * 
   221  * 
   191  * @param aStringId - Pre-defined String ID in the HTTP string pool
   222  * @param aStringId - Pre-defined String ID in the HTTP string pool
   192  * @param aHeaderValue - Value for the header 
   223  * @param aHeaderValue - Value for the header
       
   224  *  
       
   225  * @publishedAll
       
   226  * @prototype 
   193  */
   227  */
   194 EXPORT_C TInt CHttpService::AddRequestHeader(TInt aStringId, const THttpHeaderValueVariant& aHeaderValue)
   228 EXPORT_C TInt CHttpService::AddRequestHeader(TInt aStringId, const THttpHeaderValueVariant& aHeaderValue)
   195 	{
   229 	{
   196 	RHTTPHeaders sessHeaders = iHttpServiceStruct->iSessionHeaders;
   230 	RHTTPHeaders sessHeaders = iHttpServiceStruct->iSessionHeaders;
   197     RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   231     RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   204 /**
   238 /**
   205  * This method facilitates to set the custom HTTP header once in the CHttpService instance that is 
   239  * 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] 
   240  * applicable for all HTTP client transactions. [For ex; User-Agent header] 
   207  * 
   241  * 
   208  * @param aHeaderName - Custom header name
   242  * @param aHeaderName - Custom header name
   209  * @param aHeaderValue - Value for the header 
   243  * @param aHeaderValue - Value for the header
       
   244  *  
       
   245  * @publishedAll
       
   246  * @prototype 
   210  */
   247  */
   211 EXPORT_C TInt CHttpService::AddCustomRequestHeader(const TDesC8& aHeaderName, const TDesC8& aHeaderValue)
   248 EXPORT_C TInt CHttpService::AddCustomRequestHeader(const TDesC8& aHeaderName, const TDesC8& aHeaderValue)
   212 	{
   249 	{
   213 	_LIT8(KFieldSeparator, "\n");
   250 	_LIT8(KFieldSeparator, "\n");
   214 	RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   251 	RStringPool sp = iHttpServiceStruct->iHttpSession.StringPool();
   220 	TInt err = iHttpServiceStruct->iSessionHeaders.SetRawField(str, aHeaderValue, KFieldSeparator);
   257 	TInt err = iHttpServiceStruct->iSessionHeaders.SetRawField(str, aHeaderValue, KFieldSeparator);
   221 	str.Close();
   258 	str.Close();
   222 	return err;
   259 	return err;
   223 	}
   260 	}
   224 
   261 
       
   262 /**
       
   263  * This method facilitates to set to construct the authentication credentials to be passed by the application
       
   264  * The derived class from MHTTPServiceAuthentication  will be called from the framework, if authentication is required.
       
   265  * @param aCallback - Derived class from MHTTPServiceAuthentication
       
   266  *
       
   267  * @publishedAll
       
   268  * @prototype 
       
   269  */
   225 EXPORT_C TInt CHttpService::SetAuthentication(MHTTPServiceAuthentication* aCallback)
   270 EXPORT_C TInt CHttpService::SetAuthentication(MHTTPServiceAuthentication* aCallback)
   226     {
   271     {
   227     TInt error = KErrGeneral;
   272     TInt error = KErrGeneral;
   228     iHttpServiceStruct->iHttpClientAuthentication = CHttpClientAuthentication::New(iHttpServiceStruct->iHttpSession, aCallback);
   273     iHttpServiceStruct->iHttpClientAuthentication = CHttpClientAuthentication::New(iHttpServiceStruct->iHttpSession, aCallback);
   229     if(iHttpServiceStruct->iHttpClientAuthentication)
   274     if(iHttpServiceStruct->iHttpClientAuthentication)
   246     iHttpServiceStruct->iSessionHeaders = iHttpServiceStruct->iHttpSession.RequestSessionHeadersL();
   291     iHttpServiceStruct->iSessionHeaders = iHttpServiceStruct->iHttpSession.RequestSessionHeadersL();
   247     SetMaxConnections(KMaxNoOfConnections);
   292     SetMaxConnections(KMaxNoOfConnections);
   248     SetMaxTransactionsToPipeline(KMaxTransToPipeline);    
   293     SetMaxTransactionsToPipeline(KMaxTransToPipeline);    
   249 	}
   294 	}
   250 	
   295 	
       
   296 /**
       
   297  * returns the CHttpNetworkConnection instance created by the framework.
       
   298  * The class can be used to set the connection properties.
       
   299  *
       
   300  * @publishedAll
       
   301  * @prototype 
       
   302  */
   251 EXPORT_C CHttpNetworkConnection* CHttpService::HttpNetworkConnection()
   303 EXPORT_C CHttpNetworkConnection* CHttpService::HttpNetworkConnection()
   252     {
   304     {
   253     CHttpNetworkConnection *httpNetworkConn = CHttpNetworkConnection::New();
   305     CHttpNetworkConnection *httpNetworkConn = CHttpNetworkConnection::New();
   254     httpNetworkConn->SetHttpService(this);
   306     httpNetworkConn->SetHttpService(this);
   255     return httpNetworkConn;
   307     return httpNetworkConn;
   256     }
   308     }
       
   309 
       
   310 void CHttpService::RemoveUnwantedFilters()
       
   311     {
       
   312     THTTPFilterRegistration filterInfo;
       
   313     RStringPool stringPool = iHttpServiceStruct->iHttpSession.StringPool();
       
   314 
       
   315     RHTTPFilterCollection filterArray = iHttpServiceStruct->iHttpSession.FilterCollection();
       
   316     THTTPFilterIterator iter = filterArray.Query();
       
   317     const TStringTable& st = RHTTPSession::GetTable();
       
   318   
       
   319     iter.First();
       
   320 
       
   321     while (!iter.AtEnd())
       
   322         {
       
   323         // Get next filter registration info
       
   324         filterInfo = iter();
       
   325         RStringF filterName = stringPool.StringF(filterInfo.iName);
       
   326         switch(filterName.Index(st))
       
   327             {
       
   328             //dont remove these filters
       
   329             case HTTP::EClient:
       
   330             case HTTP::EProtocolHandler:
       
   331             case HTTP::EValidation:
       
   332             case HTTP::ERedirect:
       
   333             case HTTP::EHttpConnectFilter:
       
   334                 break;
       
   335             //anything other than above, remove.    
       
   336             default:
       
   337                 filterArray.RemoveFilter(filterName);
       
   338              }
       
   339         ++iter;
       
   340         }
       
   341     }