networkprotocols/dnsproxy/dnsproxyserver/inc/dnsproxyengine.h
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 //dnsproxyengine.h
       
     2 /*
       
     3 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 * All rights reserved.
       
     5 * This component and the accompanying materials are made available
       
     6 * under the terms of "Eclipse Public License v1.0"
       
     7 * which accompanies this distribution, and is available
       
     8 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 *
       
    10 * Initial Contributors:
       
    11 * Nokia Corporation - initial contribution.
       
    12 *
       
    13 * Contributors:
       
    14 *
       
    15 * Description:
       
    16 * dnsproxyengine.h - Dns Engine class
       
    17 * @file
       
    18 * @internalTechnology
       
    19 *
       
    20 */
       
    21 
       
    22 
       
    23 
       
    24 #ifndef DNS_PROXY_ENGINE_H
       
    25 #define DNS_PROXY_ENGINE_H
       
    26 
       
    27 #include <es_ini.h>
       
    28 #include <es_enum.h> 
       
    29 #include "dnsproxyserver.h"
       
    30 #include "dnsproxydb.h"
       
    31 #include "dns_hdr.h"
       
    32 
       
    33 //Literals constants for reading .ini file
       
    34 _LIT(DNS_PROXY_INI_DATA,             "resolver.ini");
       
    35 _LIT(DNS_PROXY_INI_SECTION,          "proxyresolver");	
       
    36 _LIT(DNS_PROXY_INI_NUM_SOCK_SESSION, "sessioncount");
       
    37 _LIT(DNS_PROXY_INI_NUM_RETRIES,      "retries");	
       
    38 _LIT(DNS_PROXY_INI_QUEUE_SIZE,       "queuesize");
       
    39 _LIT(DNS_PROXY_INI_TTL,              "TTL");
       
    40 _LIT(DNS_PROXY_INI_DB_SIZE,          "dbsize");
       
    41 _LIT(DNS_PROXY_INI_TIMER_VAL,        "timerval");
       
    42 _LIT(DNS_PROXY_INI_SERIAL_NUM,       "serialnum");
       
    43 _LIT(DNS_PROXY_INI_REFRESH_TIME,     "refreshtime");
       
    44 _LIT(DNS_PROXY_INI_RETRY_TIME,       "retrytime");
       
    45 _LIT(DNS_PROXY_INI_EXPIRE_TIME,      "expiretime");
       
    46 
       
    47 const TUint   KSessioncount = 1;
       
    48 const TUint   KRetrycount   = 2;
       
    49 const TUint   KQSize 		= 20;
       
    50 const TUint   KTtl		    = 21600;//dhcp lease timer is 6 hrs
       
    51 const TUint   KDbSize       = 10;
       
    52 const TUint   KTimerVal     = 5;
       
    53 const TUint32 KSerialNum   = 10000;
       
    54 const TUint32 KRefreshTime = 900;
       
    55 const TUint32 KRetryTime   = 600;
       
    56 const TUint32 KExpireTime  = 300;
       
    57 const TUint32 KAddrLength  = 100;
       
    58 
       
    59 
       
    60 
       
    61 
       
    62 //T Type class for DNS Proxy Configuration parameters
       
    63 class TDnsProxyConfigParams
       
    64 	{
       
    65 public:
       
    66     TUint iSessionCount;//< Max number of Socket sessions  
       
    67     TUint iRetryCount;	//< Possible number of retries 
       
    68     TUint iQSize;       //< Queue size limit 
       
    69     TUint iTTL;			//< Time to Live
       
    70     TUint iDbSize;      //< Max number of DB entries
       
    71 	TUint iTimerVal;	//< Timeout value for response timer
       
    72 	TUint32 iSerialNum; //< This is required for NS response
       
    73 	TUint32 iRefreshTime; //< This is required for NS response
       
    74 	TUint32 iRetryTime; //< This is required for NS response
       
    75 	TUint32 iExpiretime; //< This is required for NS response
       
    76 	};
       
    77 
       
    78 
       
    79 //forward declaration
       
    80 class CDnsProxyListener;
       
    81 class CESockIniData;
       
    82 class CDnsProxyDb;
       
    83 class CDnsServerConfig;
       
    84 
       
    85 	
       
    86 /**
       
    87  *  This class is an entry point and reads all configuration values and creates 
       
    88  *  some necessary objects
       
    89  *  @internalTechnology
       
    90  * */
       
    91 class CDnsProxyEngine:public CBase
       
    92 	{
       
    93 	public:
       
    94 		//two phase construction
       
    95         static CDnsProxyEngine* GetInstanceL();
       
    96 		~CDnsProxyEngine();
       
    97 		//Starts DNSProxy. The method is called from DNSProxy server session.
       
    98 		TInt Start(const RMessage2& aMessage);
       
    99 		//Stops DNSProxy. The method is called from DNSProxy server session.
       
   100 		void Stop();
       
   101 		//Returns instance of socket server
       
   102 		RSocketServ& GetSocketServer();
       
   103 		//Returns an instance of Listener
       
   104 		CDnsProxyListener* GetProxyListener();
       
   105 	    // The method updates DNS Proxy DB. 
       
   106 		TInt AddDbEntryL(const RMessage2& aMsg);
       
   107 		//remove entry from db
       
   108 		TInt RemoveDbEntry(const RMessage2& aMsg);
       
   109 		//This method updates domain name
       
   110 		void UpdateDomainName(const RMessage2& aMsg);
       
   111 		// The method to update domain info
       
   112 		TInt UpdateDomainInfo(const RMessage2& aMsg);
       
   113 		void UpdateLocalAddr(TInetAddr& aAddr);
       
   114 		// Suffix is available or not
       
   115 		TInt IsSuffixAvailable();
       
   116 	    //This method returns the configuration parameters read from .ini file.
       
   117 		const TDnsProxyConfigParams& GetConfig() const;
       
   118 		TInt SetDlinkConnectionInfo(const RMessage2 &aMessage);
       
   119 		TInt SetUplinkConnectionInfo(const RMessage2 &aMessage);
       
   120 					
       
   121 	protected:
       
   122 	    // Initializes the member variables
       
   123 		void ConstructL();	
       
   124 		
       
   125 	private:
       
   126         static CDnsProxyEngine* NewL();
       
   127 		//constructor
       
   128 		CDnsProxyEngine();
       
   129 		//reads the configuation file
       
   130 		void ReadConfiguration();
       
   131 		//reads the configuation file for specified name /value pair	
       
   132 		TInt GetIniValue(const TDesC& aSection, const TDesC& aName, TInt aValue=0);
       
   133 		//finds the value for given name 
       
   134 		TBool FindVar(const TDesC& aSection, const TDesC& aVarName, TInt& aResult);
       
   135 		//loads the cinfiguaration file 
       
   136 		TBool LoadConfigurationFile();
       
   137 		//unloads cinfiguration file
       
   138 		void UnLoadConfigurationFile();
       
   139 		
       
   140 				
       
   141 	public:
       
   142 		TDnsProxyConfigParams 	    iConfigParams;		//< Parsed configuration parameters
       
   143 		CDnsServerConfig* 		    iProxyServer;		//< DNS server configuration
       
   144 		CDnsProxyDb* 				iDnsproxydb;          //< DNS Proxy db instance
       
   145 		TInetAddr                   iProxyIfAddr;		//< Listener interface address
       
   146 		TBuf8<KMaxName>             iSuffixInfo;
       
   147 	
       
   148 	private:
       
   149 		CESockIniData* 			    iConfigData;		//< Used to read config data 		
       
   150 		TInt 					    iConfigDataErr;     //< Contains config data error
       
   151 		RSocketServ 			    iSockServ;          //< socket server handler
       
   152 		CDnsProxyListener* 		    iListener;          //< Intance of listener object
       
   153 		TBool                       iSuffixAvailable;   //< Suffix is available
       
   154 		
       
   155 					
       
   156 	private:
       
   157 		TBuf<KDnsMaxMessage> iBuf;	      //< Receive buffer
       
   158 		TBuf<KDnsMaxMessage> iDomainName; 
       
   159 		static CDnsProxyEngine* iDnsProxyEngine;
       
   160 
       
   161 	};
       
   162 	
       
   163  inline const TDnsProxyConfigParams& CDnsProxyEngine::GetConfig() const
       
   164  /**
       
   165  *  This method returns an instance of config params 
       
   166  *  @internalTechnology
       
   167  * */ 
       
   168  	{ 
       
   169  	return iConfigParams; 
       
   170  	}
       
   171  	
       
   172  inline RSocketServ& CDnsProxyEngine::GetSocketServer()
       
   173 /**
       
   174  *  This method returns an instance of socket server 
       
   175  *  @internalTechnology
       
   176  * */
       
   177 	{
       
   178 	return iSockServ;
       
   179 	}
       
   180 	
       
   181 inline CDnsProxyListener* CDnsProxyEngine::GetProxyListener()
       
   182 /**
       
   183  *  This method returns an instance of listener object
       
   184  *  @internalTechnology
       
   185  * */
       
   186 	{
       
   187 	return iListener;
       
   188 	}
       
   189 	
       
   190 #endif /* DNS_PROXY_ENGINE_H */