tcpiputils/dhcp/src/DHCPStateMachine.cpp
branchRCL_3
changeset 58 8d540f55e491
parent 57 abbed5a4b42a
child 75 c1029e558ef5
--- a/tcpiputils/dhcp/src/DHCPStateMachine.cpp	Tue Aug 31 16:45:15 2010 +0300
+++ b/tcpiputils/dhcp/src/DHCPStateMachine.cpp	Wed Sep 01 12:33:58 2010 +0100
@@ -40,6 +40,7 @@
 	{
 	__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPStateMachine::~CDHCPStateMachine")));
 	Cancel();
+	UnloadConfigurationFile();
 	delete iDhcpMessage;
 	delete iMessageSender;
 	delete iTimer;
@@ -66,7 +67,7 @@
   */
 	{
 	__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPStateMachine::ConstructL")));
-	
+	LoadConfigurationFile();
 #ifdef _DEBUG
 	// let's set debug properties to something
 	//  so they can be read immediately..
@@ -422,30 +423,30 @@
 	iSocket.Close();	
 	TInt error = iSocket.Open(iEsock, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection);
 	
-	if(error == KErrNone)
-	    {
-        error = iSocket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, configInfo);
-        if(error == KErrNone)
-            {
-            // make socket invisible for interface counting
-            iSocket.SetOpt(KSoKeepInterfaceUp, KSolInetIp, 0);
-            if(error != KErrNone)
-                {
-                __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, SetOpt Failed to set KSoKeepInterfaceUp")));
-                }
-            }
-        else
-            {
-            __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, SetOpt Failed to set KSoInetConfigInterface")));
-            }
-	    }
+    if(error == KErrNone)
+		{
+		error = iSocket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, configInfo);
+		if(error == KErrNone)
+		    {	        
+		    // make socket invisible for interface counting
+		    error = iSocket.SetOpt(KSoKeepInterfaceUp, KSolInetIp, 0);
+		    if(error != KErrNone)
+		        {
+		        __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, SetOpt Failed to set KSolInetIp")));   
+		        }
+		    }
+		else
+		    {
+		    __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress,SetOpt Failed to set KsolInetIfCtrl")));   
+		    }
+		}
 	else
-	    {
-        __CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress, Socket Open Failed: Due to KErrNotReady")));
-	    }
+		{
+		__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L("CDHCPStateMachine::RemoveConfiguredAddress,Socket Open Failed: Due to %d"),error));	
+		}
 	}
 
-void CDHCPStateMachine::ConfigureInterfaceL( const TSoInet6InterfaceInfo& aInterfaceInfo )
+void CDHCPStateMachine::ConfigureInterfaceL( const TSoInetInterfaceInfoExtnDnsSuffix& aInterfaceInfo )
 /**
   * Set the interface IP address and other params
   * into the TCP/IP6 stack.
@@ -465,7 +466,7 @@
   */
 	{
 	
-	TPckgBuf<TSoInet6InterfaceInfo> configInfo(aInterfaceInfo);
+	TPckgBuf<TSoInetInterfaceInfoExtnDnsSuffix> configInfo(aInterfaceInfo);
 	
 
 	__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPStateMachine::ConfigureInterfaceL - KSoInetConfigInterface")));
@@ -712,7 +713,77 @@
 	}
 
 
+/** 
+  * @name LoadConfigurationFile
+  *			Opens up the dhcp.ini file and reads the content on to a heap buffer
+  * @return - ETrue if the dhcp.ini is successfully parsed to the buffer, EFalse otherwise
+  *
+  * @internalTechnology
+  */
+TBool CDHCPStateMachine::LoadConfigurationFile()
+    {
+    TRAP_IGNORE(iConfig = CESockIniData::NewL(DHCP_INI_DATA));
+    return (iConfig != NULL);
+    }
 
+/**
+  * @name UnloadConfigurationFile 
+  *			Frees up memory allocated for reading dhcp.ini file
+  *
+  * @internalTechnology
+  */
+void CDHCPStateMachine::UnloadConfigurationFile()
+    {
+    if (iConfig)
+        {
+        delete iConfig;
+        iConfig = NULL;
+        }
+    }
+
+/**
+ * @name IniRead
+ *          General ini file read utility. Makes use of CESockIniData object for parsing
+ *          
+ * @param   aOptionName   Key name within ini file whose value need to be parsed
+ * @param   aOptionValue    Buffer reference to store the parsed output
+ * 
+ * @return  TInt error values as approriate from the ini parsing framework
+ *          
+ * @internalTechnology
+ */
+TInt CDHCPStateMachine::IniRead(const TDesC& aOptionName, TDes8& aOptionValue)
+    {
+    TPtrC iniValue;
+    TBool iniParsed = iConfig->FindVar(KDhcpSection, aOptionName, iniValue);
+    if (!iniParsed)
+        return KErrNotFound;
+
+    if(aOptionName.CompareF(KDhcpExtraOptions) == KErrNone)
+        {
+        TLex iniLex(iniValue);
+        TChar ch;
+        
+        while((ch = iniLex.Get()) != 0)
+            {
+            while ((ch = iniLex.Peek()) != ',')
+                iniLex.Inc();
+            TLex token(iniLex.MarkedToken());
+            
+            TUint8 opCode(0);
+            token.Val(opCode,EDecimal);
+
+            if ( (opCode > 0) && (opCode < KOpCodeOutOfBounds) )
+                aOptionValue.Append(opCode);
+            
+            iniLex.Inc();
+            iniLex.Mark();
+            }
+        return KErrNone;
+        }
+    else
+        return KErrNotFound;
+    }
 
 TDhcpRnd::TDhcpRnd():iXid(0)
 /**