networkprotocols/dnsproxy/dnsproxyserver/src/dnsproxydb.cpp
changeset 0 af10295192d8
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This class represents the database in the form of array
       
    15 //
       
    16 
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology
       
    22 */
       
    23 #include <e32debug.h>
       
    24 #include <cflog.h>
       
    25 #include "dnsproxydb.h"
       
    26 #include "dnsproxyengine.h"
       
    27 #include "inet6log.h"
       
    28 #include "dnsproxylog.h"
       
    29 
       
    30 //
       
    31 CDnsProxyDb* CDnsProxyDb::iDbObject= NULL;
       
    32 
       
    33 CDnsProxyDb* CDnsProxyDb::CreateInstanceL(CDnsProxyEngine& aEngine)
       
    34 /**
       
    35  * Creates the single object everytime
       
    36  * @return iDbObject- reference to CDnsProxyDb;
       
    37  *
       
    38  * @internalTechnology
       
    39  **/
       
    40 	{
       
    41 	if(!iDbObject)
       
    42 		{
       
    43 		iDbObject = new(ELeave)CDnsProxyDb(aEngine);
       
    44 		}
       
    45 	return iDbObject;
       
    46 	}
       
    47 
       
    48 CDnsProxyDb::CDnsProxyDb(CDnsProxyEngine& aEngine):iEngine(aEngine)
       
    49 /**
       
    50  * Constructor
       
    51  *
       
    52  * @internalTechnology
       
    53  **/
       
    54 
       
    55 	{
       
    56 	}
       
    57 
       
    58 CDnsProxyDb::~CDnsProxyDb()
       
    59 /**
       
    60  * Destructor
       
    61  *
       
    62  * @internalTechnology
       
    63  **/
       
    64 	{
       
    65 	Cleanup();
       
    66 	}
       
    67 
       
    68 void CDnsProxyDb::UpdateDbL(const TDesC8& aHostName,TInetAddr& aHostAddr)
       
    69 /**
       
    70  * Updates the DB with HostName and Host Address
       
    71  * @param aHostName - Host Name
       
    72  * @param aHostAddr - Host Address
       
    73  *
       
    74  * @internalTechnology
       
    75  **/
       
    76 	{
       
    77 	
       
    78 	TDnsProxydbElement* aDbElement = new TDnsProxydbElement;
       
    79 	aDbElement->iHostName.Copy(aHostName);
       
    80 	aDbElement->iHostAddr = aHostAddr ;
       
    81 	iElementList.AppendL(aDbElement);
       
    82 	}
       
    83 
       
    84 TDnsProxydbElement* CDnsProxyDb::GetRecordList(const TDesC8& aQName)
       
    85 /**
       
    86  * Returns the array of TDnsProxydbElement object having same name as that of QueryName
       
    87  * @param  aName- Query Name to be searched in db
       
    88  * @return element - returns the reference to TDnsProxydbElement
       
    89  *
       
    90  * @internalTechnology
       
    91  **/
       
    92 	{
       
    93 	TBool flag = EFalse;
       
    94 	TDnsProxydbElement* element = NULL;
       
    95 	for(TInt i =0;i<iElementList.Count();i++)
       
    96 		{
       
    97 		 if(iElementList[i])
       
    98 			{
       
    99 			flag = CompareNames(iElementList[i]->iHostName,aQName);
       
   100 			if(flag)
       
   101 				{
       
   102 				element = iElementList[i];
       
   103 				break;
       
   104 				}
       
   105 			}
       
   106 		}
       
   107 	return element;	
       
   108 	}
       
   109 
       
   110 void CDnsProxyDb::AddRRecord(TDnsProxydbElement& aElementList,const TDesC8& aRRecord,TUint16 aDnsQType)
       
   111 /**
       
   112  * Adds record into db
       
   113  * @param aElementList - associates with record to be inserted into db
       
   114  * @param aRRecord - record to be added into db which may be of type AN or NS
       
   115  * @param aFlag - which will indicate type of record like NS or AN
       
   116  * @internalTechnology
       
   117  **/
       
   118 	{
       
   119 	aElementList.iRecord.Copy(aRRecord);
       
   120 	aElementList.iDnsQType = aDnsQType;
       
   121 	}
       
   122 
       
   123 void CDnsProxyDb::Cleanup()
       
   124 /**
       
   125  * Destroys all the obejcts  present in the array list and empties it
       
   126  * @internalTechnology
       
   127  **/
       
   128 	{
       
   129 	iElementList.ResetAndDestroy();
       
   130 	}
       
   131 TDnsProxydbElement* CDnsProxyDb::FindIpAddress(TInetAddr& aAddr)
       
   132 /**
       
   133  * Finds specified entry from db based on IP address
       
   134  * @param aAddr - TInetAddress
       
   135  * @return dbelement - pointer to TDnsProxydbElement class
       
   136  *
       
   137  * @internalTechnology
       
   138  **/
       
   139 	{
       
   140 					
       
   141 	TDnsProxydbElement* dbelement = NULL;
       
   142 	for(TInt i = 0;i < iElementList.Count();i++)
       
   143 		{
       
   144 
       
   145 		if(iElementList[i])
       
   146 			{
       
   147 			if(aAddr.Match(iElementList[i]->iHostAddr))
       
   148 				{
       
   149 				dbelement = iElementList[i];
       
   150 				break;
       
   151 				}
       
   152 			}
       
   153 		}
       
   154 	
       
   155 	return dbelement;	
       
   156 	}
       
   157 
       
   158 void CDnsProxyDb::DeleteDbEntry(TInetAddr& aAddr)
       
   159 /**
       
   160  * Deletes specified entry from db based on IP address
       
   161  * @return TBool - returns ETrue if it is successful otherwise EFalse
       
   162  *
       
   163  * @internalTechnology
       
   164  **/
       
   165 	{
       
   166 	for(TInt i =0;i<iElementList.Count();i++)
       
   167 		{
       
   168 		if(iElementList[i])
       
   169 			{
       
   170 
       
   171 			TInetAddr ipaddr = iElementList[i]->iHostAddr;
       
   172 			if(ipaddr.Match(aAddr))
       
   173 				{
       
   174 				delete iElementList[i];
       
   175 				iElementList[i] = NULL;
       
   176 				iElementList.Remove(i);
       
   177     			iElementList.Compress();
       
   178 				}
       
   179 			}
       
   180 		}
       
   181 	}
       
   182 
       
   183 TBool CDnsProxyDb::CompareNames(const TDesC8& aHostName,const TDesC8& aQueryName)
       
   184 /**
       
   185  * Compare Query Name with Host Name present in db
       
   186  * @param aHostName - Host name retrived from db
       
   187  * @param aQueryName - Query name to be compared with Host Name
       
   188  * @return TBool - ETrue if it sucessful otherwise EFalse
       
   189  *
       
   190  * @internalTechnology
       
   191  **/
       
   192 	{
       
   193 	TInt ret_val = aHostName.Compare(aQueryName);
       
   194 	if(ret_val==0)
       
   195 		return ETrue;
       
   196 	return EFalse;
       
   197 	}
       
   198 
       
   199 TInt CDnsProxyDb::GetDbSize()
       
   200 /**
       
   201  * Retunrs the current size of the db
       
   202  * @return size - current size of db
       
   203  *
       
   204  * @internalTechnology
       
   205  **/
       
   206 	{
       
   207 	return iElementList.Count();
       
   208 	}