tcpiputils/dnd/src/servers.cpp
branchRCL_3
changeset 58 8d540f55e491
parent 57 abbed5a4b42a
child 75 c1029e558ef5
equal deleted inserted replaced
57:abbed5a4b42a 58:8d540f55e491
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
     1 // All rights reserved.
     3 // This component and the accompanying materials are made available
     2 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     3 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     4 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     5 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    34 class TDnsInterfaceData
    33 class TDnsInterfaceData
    35 	{
    34 	{
    36 public:
    35 public:
    37 	TName iName;				//< Name of the interface
    36 	TName iName;				//< Name of the interface
    38 	TUint32 iScope[16];			//< The scope vector
    37 	TUint32 iScope[16];			//< The scope vector
       
    38 	RInetSuffixList iSuffixList;//< Structure to hold the interface specific domain search list
    39 	};
    39 	};
    40 
    40 
    41 // Item of the configured servers list
    41 // Item of the configured servers list
    42 class TDnsConfiguredServer
    42 class TDnsConfiguredServer
    43 	{
    43 	{
    68 	TInt ServerId(const TInetAddr &aAddr) const;
    68 	TInt ServerId(const TInetAddr &aAddr) const;
    69 	TUint32 NameSpace(const TDnsServerFilter &aFilter, TInt aServerId) const;
    69 	TUint32 NameSpace(const TDnsServerFilter &aFilter, TInt aServerId) const;
    70 	TInt BuildServerList();
    70 	TInt BuildServerList();
    71 	void AddServerAddress(const TName &aInterface, const TInetAddr &aAddr);
    71 	void AddServerAddress(const TName &aInterface, const TInetAddr &aAddr);
    72 	void LockByAddress(const TInetAddr &aAddr, TUint32 aNid, TDnsServerFilter &aFilter);
    72 	void LockByAddress(const TInetAddr &aAddr, TUint32 aNid, TDnsServerFilter &aFilter);
       
    73 	// Retrieves the domain search list configured on the interface associated with the nominated name server
       
    74 	void InterfaceSuffixList(TInt aServerId, RInetSuffixList& aSuffixList);
       
    75 	// Performs the network id selection for the query based on the domain name on the query
       
    76 	void UpdateDomain(TDnsServerFilter &aFilter) const;
    73 
    77 
    74 private:
    78 private:
    75 	// Build and add interface entry to the list (basic operation)
    79 	// Build and add interface entry to the list (basic operation)
    76 	TInt AddInterfaceEntry(const TSoInetIfQuery &aInfo);
    80 	TInt AddInterfaceEntry(const TSoInetIfQuery &aInfo);
    77 	// Find interface matching the destination address
    81 	// Find interface matching the destination address
    91 	TUint iCacheFlushed:1;			//< = 1, when cache has been flushed (only used with "FlushOnConfig" ini-option)
    95 	TUint iCacheFlushed:1;			//< = 1, when cache has been flushed (only used with "FlushOnConfig" ini-option)
    92 
    96 
    93 	CArrayFixFlat<TDnsServerData> *iServerList;	//< Current list of servers
    97 	CArrayFixFlat<TDnsServerData> *iServerList;	//< Current list of servers
    94 	CArrayFixFlat<TDnsInterfaceData> *iInterfaceList; //< Current list of interfaces
    98 	CArrayFixFlat<TDnsInterfaceData> *iInterfaceList; //< Current list of interfaces
    95 	CArrayFixFlat<TDnsConfiguredServer> *iConfiguredList; //< Current list of configured servers
    99 	CArrayFixFlat<TDnsConfiguredServer> *iConfiguredList; //< Current list of configured servers
       
   100 	
       
   101 private:
       
   102 	TInt AddInterfaceEntry(const TSoInetIfQuery &aInfo, RSocket& aSocket);
    96 	};
   103 	};
    97 
   104 
    98 
   105 
    99 MDnsServerManager *DnsServerManager::NewL(CDndEngine &aControl)
   106 MDnsServerManager *DnsServerManager::NewL(CDndEngine &aControl)
   100 	{
   107 	{
   138 	delete iServerList;
   145 	delete iServerList;
   139 	delete iInterfaceList;
   146 	delete iInterfaceList;
   140 	delete iConfiguredList;
   147 	delete iConfiguredList;
   141 	}
   148 	}
   142 
   149 
   143 // CDnsServerManager::AddInterfaceData
   150 // CDnsServerManager::AddInterfaceEntry
       
   151 TInt CDnsServerManager::AddInterfaceEntry(const TSoInetIfQuery &aInfo, RSocket& aSocket)
       
   152 	{
       
   153     TRAPD(err,
       
   154 	TDnsInterfaceData &ifd = iInterfaceList->ExtendL();
       
   155 
       
   156     ifd.iName = aInfo.iName;
       
   157     for (TInt i = sizeof(ifd.iScope) / sizeof(ifd.iScope[0]); --i >= 0; )
       
   158         ifd.iScope[i] = aInfo.iZone[i];
       
   159     
       
   160     if (aSocket.SetOpt(KSoInetEnumDomainSuffix, KSolInetIfCtrl) == KErrNone)
       
   161         {
       
   162         ifd.iSuffixList.Reset();
       
   163         TInetSuffix data;
       
   164         TPckg<TInetSuffix> opt(data);
       
   165         while (aSocket.GetOpt(KSoInetNextDomainSuffix, KSolInetIfCtrl, opt) == KErrNone)
       
   166             {
       
   167             TSuffixName tmpBuf;
       
   168             tmpBuf.Copy(opt().iSuffixName);
       
   169             ifd.iSuffixList.AppendL(tmpBuf);
       
   170             }
       
   171         }
       
   172 		);
       
   173 		
       
   174 	return err < 0 ? err : iInterfaceList->Count() - 1;
       
   175 	}
       
   176 
   144 TInt CDnsServerManager::AddInterfaceEntry(const TSoInetIfQuery &aInfo)
   177 TInt CDnsServerManager::AddInterfaceEntry(const TSoInetIfQuery &aInfo)
   145 	{
   178     {
   146 	TRAPD(err,
   179     TRAPD(err,
   147 		TDnsInterfaceData &ifd = iInterfaceList->ExtendL();
   180         TDnsInterfaceData &ifd = iInterfaceList->ExtendL();
   148 		ifd.iName = aInfo.iName;
   181         ifd.iName = aInfo.iName;
   149 		for (TInt i = sizeof(ifd.iScope) / sizeof(ifd.iScope[0]); --i >= 0; )
   182         for (TInt i = sizeof(ifd.iScope) / sizeof(ifd.iScope[0]); --i >= 0; )
   150 			ifd.iScope[i] = aInfo.iZone[i];
   183             ifd.iScope[i] = aInfo.iZone[i];
   151 		);
   184         );
   152 	return err < 0 ? err : iInterfaceList->Count() - 1;
   185     return err < 0 ? err : iInterfaceList->Count() - 1;
   153 	}
   186     }
   154 
   187 
   155 // CDnsServerManager::AddToInterfaceList
   188 // CDnsServerManager::AddToInterfaceList
   156 // *************************************
   189 // *************************************
   157 /**
   190 /**
   158 // Add the interface to the interface list, if it does not already exist.
   191 // Add the interface to the interface list, if it does not already exist.
   176 		{
   209 		{
   177 		const TDnsInterfaceData &data = iInterfaceList->At(i);
   210 		const TDnsInterfaceData &data = iInterfaceList->At(i);
   178 		if (data.iName.Compare(aInfo.iName) == 0)
   211 		if (data.iName.Compare(aInfo.iName) == 0)
   179 			return i;	// Interface already present in the list
   212 			return i;	// Interface already present in the list
   180 		}
   213 		}
       
   214 
   181 	//
   215 	//
   182 	// A new interface, get the scope vector
   216 	// A new interface, get the scope vector
   183 	//
   217 	//
   184 	TPckgBuf<TSoInetIfQuery> opt;
   218 	TPckgBuf<TSoInetIfQuery> opt;
   185 	opt().iName = aInfo.iName;
   219 	opt().iName = aInfo.iName;
   186 	const TInt err = aSocket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, opt);
   220 	const TInt err = aSocket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, opt);
   187 	return err < 0 ? err : AddInterfaceEntry(opt());
   221 	return err < 0 ? err : AddInterfaceEntry(opt(), aSocket);
   188 	}
   222 	}
   189 
   223 
   190 // CDnsServerManager::FindInterface
   224 // CDnsServerManager::FindInterface
   191 // ********************************
   225 // ********************************
   192 //
   226 //
   443 			return FALSE;	// Not in locked scope
   477 			return FALSE;	// Not in locked scope
   444 		}
   478 		}
   445 	return 	TRUE;
   479 	return 	TRUE;
   446 	}
   480 	}
   447 
   481 
       
   482 /**
       
   483 // @name	UpdateDomain
       
   484 // @param   aFilter the server filter
       
   485 // @param   aServer to be tested against the filter
       
   486 */
       
   487 void CDnsServerManager::UpdateDomain(TDnsServerFilter &aFilter) const
       
   488     {
       
   489 	LOG(Log::Printf(_L("CDnsServerManager -- RHostResolver opened on implicit connection")));
       
   490     if ( aFilter.iDomainName.Length() )
       
   491         {
       
   492         TBool updatedDomain(FALSE);
       
   493         for (TInt i = iInterfaceList->Count(); --i >= 0 && !updatedDomain; )
       
   494             {
       
   495             TDnsInterfaceData &id = iInterfaceList->At(i);
       
   496             for (TInt i=0; i<id.iSuffixList.Count();i++)
       
   497                 {
       
   498                 if (aFilter.iDomainName.Find(id.iSuffixList[i]) != KErrNotFound)
       
   499                     {
       
   500                     aFilter.iLockId = id.iScope[aFilter.iLockType-1];
       
   501                     updatedDomain = TRUE;
       
   502                     break;
       
   503                     }
       
   504                 }
       
   505             }
       
   506         }
       
   507     }
   448 
   508 
   449 //
   509 //
   450 // MDnsServerManager API
   510 // MDnsServerManager API
   451 //
   511 //
   452 TInt CDnsServerManager::OpenList(const TDnsServerFilter &aFilter, MDnsServerListNotify * /*aNotify*/)
   512 TInt CDnsServerManager::OpenList(const TDnsServerFilter &aFilter, MDnsServerListNotify * /*aNotify*/)
   679 			aFilter.iLockId = id.iScope[aFilter.iLockType-1];
   739 			aFilter.iLockId = id.iScope[aFilter.iLockType-1];
   680 			break;
   740 			break;
   681 			}
   741 			}
   682 		}
   742 		}
   683 	}
   743 	}
       
   744 
       
   745 /**
       
   746 // @name 	InterfaceSuffixList
       
   747 // @param	aServerId	Id of the server used for name resolution
       
   748 // @param	aSuffixList	reference to array for reading the interface specific domain suffices
       
   749 */
       
   750 void CDnsServerManager::InterfaceSuffixList(TInt aServerId, RInetSuffixList& aSuffixList)
       
   751     {
       
   752     const TInt N = iServerList->Count();
       
   753     for (TInt i = 0; i < N; ++i)
       
   754         {
       
   755         const TDnsServerData &server =  iServerList->At(i);
       
   756         if (server.iServerId == aServerId)
       
   757             {
       
   758             aSuffixList = iInterfaceList->At(server.iInterface).iSuffixList;
       
   759             break;
       
   760             }
       
   761         }
       
   762     }