applayerpluginsandutils/httpprotocolplugins/httpclient/chttpclienthandler.cpp
changeset 49 b91bcc4b38e4
parent 14 ce2bfba3d005
--- a/applayerpluginsandutils/httpprotocolplugins/httpclient/chttpclienthandler.cpp	Mon Sep 27 10:31:51 2010 +0530
+++ b/applayerpluginsandutils/httpprotocolplugins/httpclient/chttpclienthandler.cpp	Mon Oct 04 15:35:43 2010 +0530
@@ -1,4 +1,4 @@
-// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
+// Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
 // All rights reserved.
 // This component and the accompanying materials are made available
 // under the terms of "Eclipse Public License v1.0"
@@ -766,6 +766,49 @@
 	return manager;
 	}
 
+
+/*
+*   The below function selects correct NTLM connection manger. Connection manager is associate with a socket.
+*   NTLM protocol needs all authentication messages Negotiate(->),Challenge(<-) and Authorise(->) packets
+*   to be sent on the same port.  In this function, the connection manager is identified by NTLM id which is set
+*   when CHttpResponseParser when 401 unauthorised message is received from ntlm enabled server.
+*   The same iNtlmConnId will be maintained until authentication is successful. 
+*/
+CHttpConnectionManager* CHttpClientHandler::SelectNtlmConnectionL(const CHttpConnectionInfo& aConnectionInfo,RHTTPTransaction aTrans)
+    {
+    
+    TInt ntlmConnId;
+    CHttpConnectionManager* fourthChoice=NULL;
+    _LIT8( KNtlmId, "NTLMConnId" );
+    RStringPool stringPool = aTrans.Session().StringPool();
+    RStringF ntlmId = stringPool.OpenFStringL( KNtlmId );
+    THTTPHdrVal value;
+    
+    if (aTrans.PropertySet().Property(ntlmId,value))
+        {
+        ntlmConnId = value.Int();
+        for (TInt i=0;i<iConnectionManagers.Count();i++)
+            {
+            const CHttpConnectionInfo& connectionInfo = iConnectionManagers[i]->ConnectionInfo();
+            if( connectionInfo.HostAndPortMatches(aConnectionInfo) )
+                {
+                if (iConnectionManagers[i]->GetNtlmConnId() ==  ntlmConnId)
+                    {
+                    ntlmId.Close();
+                    return iConnectionManagers[i];
+                    }
+                }
+            else
+                {
+                fourthChoice = iConnectionManagers[i];
+                }
+            }
+        }
+    ntlmId.Close();
+    return fourthChoice;
+    }
+
+
 TInt CHttpClientHandler::MaxNumConnectionManagers() const
 	{
 	// Has this value been previously cached?
@@ -930,8 +973,31 @@
 		}
 	else
 		{
-		// Look for a normal connection.
-		isNewConnection = SelectConnectionManagerL(*info, aTrans.Transaction(), canPipeline, manager);
+	    THTTPHdrVal value;
+        _LIT8( KNtlmStateStr, "NTLMState" );
+        RStringPool stringPool = iSession.StringPool();
+        RStringF strF = stringPool.OpenFStringL( KNtlmStateStr );
+        CleanupClosePushL(strF);
+        if ( aTrans.Transaction().PropertySet().Property( strF, value ) && (value.Int() == ENtlmNegotiate || value.Int() == ENtlmAuthenticate) )
+            {
+            manager = SelectNtlmConnectionL(*info,aTrans.Transaction());
+            if (manager == NULL)
+                {
+                __FLOG_0(_T8("No NTLM connection manger!!!"));
+                }
+            else if (value.Int() == ENtlmAuthenticate)
+                {
+#if defined (_DEBUG) && defined (_LOGGING)
+                __FLOG_1(_T8(" NTLM AUTH msg Id %d and resetting to  -1"),manager->GetNtlmConnId());
+#endif
+                manager->SetNtlmConnId(KErrNotFound);//reset it
+                }
+            }
+        else// Look for a normal connection.
+            {
+            isNewConnection = SelectConnectionManagerL(*info, aTrans.Transaction(), canPipeline, manager);
+            }
+        CleanupStack::PopAndDestroy(&strF);
 		}
 
 	if( manager != NULL )