applayerprotocols/ftpengine/ftpprot/RESOLVER.CPP
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 1998-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 // Active object to perform DNS lookup
       
    15 // Author:	Philippe Gabriel
       
    16 // Performs DNS lookup for the FTP client
       
    17 // 
       
    18 //
       
    19 
       
    20 /**
       
    21  @file RESOLVER.CPP
       
    22  @internalComponent
       
    23 */
       
    24 
       
    25 #include "FTPDEF.H"
       
    26 #include "DEBUG.H"
       
    27 #include "RESOLVER.H"
       
    28 #include "FTPPROT.H"
       
    29 #include <e32base.h>
       
    30 #include <in_sock.h>
       
    31 
       
    32 CFTPResolver::CFTPResolver(MFTPResolverNotifier* aNotifier
       
    33 						   ):CActive(CActive::EPriorityStandard)
       
    34 	{
       
    35 	FTPPROTDEBUG(_DBGResolver,_L("CFTPResolver::CFTPResolver called\n"));
       
    36 	iNotifier = aNotifier;
       
    37 	}
       
    38 
       
    39 CFTPResolver* CFTPResolver::NewL(MFTPResolverNotifier* aNotifier,RSocketServ& aSockServ)
       
    40 	{
       
    41 	CFTPResolver* self = new (ELeave) CFTPResolver(aNotifier);
       
    42     CleanupStack::PushL(self);
       
    43     self->ConstructL(aSockServ);
       
    44     CleanupStack::Pop();
       
    45 	return self;
       
    46 	} 
       
    47 
       
    48 void CFTPResolver::ConstructL(RSocketServ& aSockServ)
       
    49 	{
       
    50 	FTPPROTDEBUG(_DBGResolver,_L("CFTPResolver::ConstructL called\n"));
       
    51 	User::LeaveIfError(iResolver.Open(aSockServ, KAfInet, KProtocolInetTcp));
       
    52 	CActiveScheduler::Add(this);
       
    53 	} 
       
    54 
       
    55 void CFTPResolver::DoCancel()
       
    56 	{
       
    57 	iResolver.Cancel();
       
    58 	}
       
    59 
       
    60 void CFTPResolver::RunL()
       
    61 	{
       
    62 	FTPPROTDEBUG(_DBGResolver,_L("CFTPResolver::RunL called "));
       
    63 	switch (iStatus.Int())
       
    64 		{
       
    65 		case KErrNone:
       
    66 			FTPPROTDEBUG(_DBGResolver,_L("iStatus: NoError\n"));
       
    67 			// Call Upper layer notifier
       
    68 			iNotifier->FTPResolverNotifier(MFTPResolverNotifier::EDtpLookupComplete);
       
    69 			break;
       
    70 		default:
       
    71 			FTPPROTDEBUG(_DBGResolver,_L("iStatus: Error\n"));
       
    72 			iNotifier->FTPResolverNotifier(MFTPResolverNotifier::EDtpLookupFailed);
       
    73 			break;
       
    74 		}
       
    75 	} 
       
    76 CFTPResolver::~CFTPResolver()
       
    77 	{
       
    78 	FTPPROTDEBUG(_DBGResolver,_L("CFTPResolver::~CFTPResolver called\n"));
       
    79 	iResolver.Close();
       
    80 	}
       
    81 
       
    82 void CFTPResolver::Lookup(const THostName& aServerName)
       
    83 {
       
    84 	FTPPROTDEBUG(_DBGResolver,_L("CFTPResolver::Lookup resolving:>"));
       
    85 	FTPPROTDEBUG(_DBGResolver,aServerName);
       
    86 	FTPPROTDEBUG(_DBGResolver,_L("<\n"));
       
    87 	iResolver.GetByName(aServerName, iNameEntry, iStatus);
       
    88 	SetActive();
       
    89 }
       
    90 
       
    91 void CFTPResolver::SetAddress(TInetAddr& aAddress)
       
    92 {
       
    93 	// Get the 1st entry resolved
       
    94 	iNameRecord = iNameEntry();
       
    95 	// Save the address (take care not to overwrite the port, might have been already set)
       
    96 	if (TInetAddr::Cast(iNameRecord.iAddr).Family() == KAfInet)
       
    97 		aAddress.SetAddress(TInetAddr::Cast(iNameRecord.iAddr).Address());
       
    98 	else
       
    99 		aAddress.SetAddress(TInetAddr::Cast(iNameRecord.iAddr).Ip6Address());
       
   100 
       
   101 #if defined(__FTPPROTDEBUG__)
       
   102 	TBuf<512> debugBuffer; // A Buffer to output the resolved IP 
       
   103 	
       
   104 	aAddress.Output(debugBuffer);
       
   105 	debugBuffer.Append(_L(","));
       
   106 	debugBuffer.AppendNum(aAddress.Port(), EDecimal); 
       
   107 	debugBuffer.Append(_L("\n"));
       
   108 #endif
       
   109 	FTPPROTDEBUG(_DBGResolver,_L("Resolved address is:"));
       
   110 	FTPPROTDEBUG(_DBGResolver,debugBuffer);
       
   111 }