tcpiputils/dnd/src/servers.cpp
branchRCL_3
changeset 21 abbed5a4b42a
parent 20 7e41d162e158
child 22 8d540f55e491
equal deleted inserted replaced
20:7e41d162e158 21:abbed5a4b42a
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // All rights reserved.
     2 // All rights reserved.
     2 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     3 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     4 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     5 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    33 class TDnsInterfaceData
    34 class TDnsInterfaceData
    34 	{
    35 	{
    35 public:
    36 public:
    36 	TName iName;				//< Name of the interface
    37 	TName iName;				//< Name of the interface
    37 	TUint32 iScope[16];			//< The scope vector
    38 	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;
       
    77 
    73 
    78 private:
    74 private:
    79 	// Build and add interface entry to the list (basic operation)
    75 	// Build and add interface entry to the list (basic operation)
    80 	TInt AddInterfaceEntry(const TSoInetIfQuery &aInfo);
    76 	TInt AddInterfaceEntry(const TSoInetIfQuery &aInfo);
    81 	// Find interface matching the destination address
    77 	// Find interface matching the destination address
    95 	TUint iCacheFlushed:1;			//< = 1, when cache has been flushed (only used with "FlushOnConfig" ini-option)
    91 	TUint iCacheFlushed:1;			//< = 1, when cache has been flushed (only used with "FlushOnConfig" ini-option)
    96 
    92 
    97 	CArrayFixFlat<TDnsServerData> *iServerList;	//< Current list of servers
    93 	CArrayFixFlat<TDnsServerData> *iServerList;	//< Current list of servers
    98 	CArrayFixFlat<TDnsInterfaceData> *iInterfaceList; //< Current list of interfaces
    94 	CArrayFixFlat<TDnsInterfaceData> *iInterfaceList; //< Current list of interfaces
    99 	CArrayFixFlat<TDnsConfiguredServer> *iConfiguredList; //< Current list of configured servers
    95 	CArrayFixFlat<TDnsConfiguredServer> *iConfiguredList; //< Current list of configured servers
   100 	
       
   101 private:
       
   102 	TInt AddInterfaceEntry(const TSoInetIfQuery &aInfo, RSocket& aSocket);
       
   103 	};
    96 	};
   104 
    97 
   105 
    98 
   106 MDnsServerManager *DnsServerManager::NewL(CDndEngine &aControl)
    99 MDnsServerManager *DnsServerManager::NewL(CDndEngine &aControl)
   107 	{
   100 	{
   145 	delete iServerList;
   138 	delete iServerList;
   146 	delete iInterfaceList;
   139 	delete iInterfaceList;
   147 	delete iConfiguredList;
   140 	delete iConfiguredList;
   148 	}
   141 	}
   149 
   142 
   150 // CDnsServerManager::AddInterfaceEntry
   143 // CDnsServerManager::AddInterfaceData
   151 TInt CDnsServerManager::AddInterfaceEntry(const TSoInetIfQuery &aInfo, RSocket& aSocket)
   144 TInt CDnsServerManager::AddInterfaceEntry(const TSoInetIfQuery &aInfo)
   152 	{
   145 	{
   153     TRAPD(err,
   146 	TRAPD(err,
   154 	TDnsInterfaceData &ifd = iInterfaceList->ExtendL();
   147 		TDnsInterfaceData &ifd = iInterfaceList->ExtendL();
   155 
   148 		ifd.iName = aInfo.iName;
   156     ifd.iName = aInfo.iName;
   149 		for (TInt i = sizeof(ifd.iScope) / sizeof(ifd.iScope[0]); --i >= 0; )
   157     for (TInt i = sizeof(ifd.iScope) / sizeof(ifd.iScope[0]); --i >= 0; )
   150 			ifd.iScope[i] = aInfo.iZone[i];
   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 		);
   151 		);
   173 		
       
   174 	return err < 0 ? err : iInterfaceList->Count() - 1;
   152 	return err < 0 ? err : iInterfaceList->Count() - 1;
   175 	}
   153 	}
   176 
       
   177 TInt CDnsServerManager::AddInterfaceEntry(const TSoInetIfQuery &aInfo)
       
   178     {
       
   179     TRAPD(err,
       
   180         TDnsInterfaceData &ifd = iInterfaceList->ExtendL();
       
   181         ifd.iName = aInfo.iName;
       
   182         for (TInt i = sizeof(ifd.iScope) / sizeof(ifd.iScope[0]); --i >= 0; )
       
   183             ifd.iScope[i] = aInfo.iZone[i];
       
   184         );
       
   185     return err < 0 ? err : iInterfaceList->Count() - 1;
       
   186     }
       
   187 
   154 
   188 // CDnsServerManager::AddToInterfaceList
   155 // CDnsServerManager::AddToInterfaceList
   189 // *************************************
   156 // *************************************
   190 /**
   157 /**
   191 // Add the interface to the interface list, if it does not already exist.
   158 // Add the interface to the interface list, if it does not already exist.
   209 		{
   176 		{
   210 		const TDnsInterfaceData &data = iInterfaceList->At(i);
   177 		const TDnsInterfaceData &data = iInterfaceList->At(i);
   211 		if (data.iName.Compare(aInfo.iName) == 0)
   178 		if (data.iName.Compare(aInfo.iName) == 0)
   212 			return i;	// Interface already present in the list
   179 			return i;	// Interface already present in the list
   213 		}
   180 		}
   214 
       
   215 	//
   181 	//
   216 	// A new interface, get the scope vector
   182 	// A new interface, get the scope vector
   217 	//
   183 	//
   218 	TPckgBuf<TSoInetIfQuery> opt;
   184 	TPckgBuf<TSoInetIfQuery> opt;
   219 	opt().iName = aInfo.iName;
   185 	opt().iName = aInfo.iName;
   220 	const TInt err = aSocket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, opt);
   186 	const TInt err = aSocket.GetOpt(KSoInetIfQueryByName, KSolInetIfQuery, opt);
   221 	return err < 0 ? err : AddInterfaceEntry(opt(), aSocket);
   187 	return err < 0 ? err : AddInterfaceEntry(opt());
   222 	}
   188 	}
   223 
   189 
   224 // CDnsServerManager::FindInterface
   190 // CDnsServerManager::FindInterface
   225 // ********************************
   191 // ********************************
   226 //
   192 //
   477 			return FALSE;	// Not in locked scope
   443 			return FALSE;	// Not in locked scope
   478 		}
   444 		}
   479 	return 	TRUE;
   445 	return 	TRUE;
   480 	}
   446 	}
   481 
   447 
   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     }
       
   508 
   448 
   509 //
   449 //
   510 // MDnsServerManager API
   450 // MDnsServerManager API
   511 //
   451 //
   512 TInt CDnsServerManager::OpenList(const TDnsServerFilter &aFilter, MDnsServerListNotify * /*aNotify*/)
   452 TInt CDnsServerManager::OpenList(const TDnsServerFilter &aFilter, MDnsServerListNotify * /*aNotify*/)
   739 			aFilter.iLockId = id.iScope[aFilter.iLockType-1];
   679 			aFilter.iLockId = id.iScope[aFilter.iLockType-1];
   740 			break;
   680 			break;
   741 			}
   681 			}
   742 		}
   682 		}
   743 	}
   683 	}
   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     }