servicediscoveryandcontrol/pnp/test/upnp/unittests/udpclient/src/proxyprotocol.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "es_ptest.h"
       
    20 #include "proxyprotocol.h"
       
    21 
       
    22 #include "pudpclienttests.h"
       
    23 
       
    24 //---------------------------------------------------------------------------------------------------------
       
    25 
       
    26 void Panic(TDPanic aPanic)
       
    27 //
       
    28 // Panic the Protocol
       
    29 //
       
    30 	{
       
    31 
       
    32 	User::Panic(_L("TestInternalSocket Prot"),aPanic);
       
    33 	}
       
    34 
       
    35 	
       
    36 CProxyProtocol::CProxyProtocol(TServerProtocolDesc* aProtoDesc)
       
    37 //
       
    38 //
       
    39 //
       
    40 	:CProtocolBase(),iProtoDesc(aProtoDesc),iProtocols(0x16)
       
    41 	{
       
    42 	__DECLARE_NAME(_S("CProxyProtocol"));
       
    43 	iStarted=EFalse;
       
    44 	}
       
    45 
       
    46 CServProviderBase * CProxyProtocol::NewSAPL(TUint /*aProtocol*/)
       
    47 	{
       
    48 	return CProxyProvd::NewL(*this);
       
    49 	}
       
    50 
       
    51 
       
    52 CProxyProtocol::~CProxyProtocol()
       
    53 	{
       
    54 	for (TInt i=0;i<iProtocols.Count();i++)
       
    55 		{
       
    56 		iProtocols[i]->Close();
       
    57 		}
       
    58 	}
       
    59 
       
    60 CProxyProtocol *CProxyProtocol::NewL(TInt aType, TServerProtocolDesc* aProtoDesc)
       
    61 	{
       
    62 
       
    63 	CProxyProtocol* prot=0;
       
    64 	switch (aType)
       
    65 		{
       
    66 	case KProxy:
       
    67 		prot=new (ELeave) CProxyProtocol(aProtoDesc);
       
    68 		break;
       
    69 
       
    70 	default:
       
    71 		prot=(CProxyProtocol*)0xABCD; // keep lint happy
       
    72 		Panic(EBadProtocol);
       
    73 		}
       
    74 	prot->iType=aType;
       
    75 	return prot;
       
    76 	}
       
    77 
       
    78 void CProxyProtocol::InitL(TDesC& /*aTag*/)
       
    79 	{
       
    80 	// Force a fail on Memory tests
       
    81 	char* ptr=new(ELeave) char;
       
    82 	delete ptr;
       
    83 	}
       
    84 
       
    85 void CProxyProtocol::BindL(CProtocolBase* /*aProtocol*/, TUint /*anId*/)
       
    86 	{
       
    87 	// Force a fail on Memory tests
       
    88 	char* ptr=new(ELeave) char;
       
    89 	delete ptr;
       
    90 	}
       
    91 
       
    92 void CProxyProtocol::BindToL(CProtocolBase* aProtocol)
       
    93 	{
       
    94 	// Force a fail on Memory tests
       
    95 	char* ptr=new(ELeave) char;
       
    96 	delete ptr;
       
    97 	iProtocols.AppendL(aProtocol);
       
    98 	aProtocol->Open();
       
    99 	}
       
   100 
       
   101 
       
   102 void CProxyProtocol::StartL(void)
       
   103 	{
       
   104 	// Force a fail on Memory tests
       
   105 	char* ptr=new(ELeave) char;
       
   106 	delete ptr;
       
   107 	iStarted=ETrue;
       
   108 	}
       
   109 
       
   110 TInt CProxyProtocol::Send(RMBufChain &,CProtocolBase* /*aSourceProtocol*/)
       
   111 	{
       
   112 	return 1;
       
   113 	}
       
   114 
       
   115 TInt CProxyProtocol::Send(TDes8 &, TSockAddr* /*to*/,TSockAddr* /*from*/,CProtocolBase* /*aSourceProtocol*/)
       
   116 	{
       
   117 	return 1;
       
   118 	}
       
   119 
       
   120 void CProxyProtocol::Process(RMBufChain &,CProtocolBase* /*aSourceProtocol*/)
       
   121 	{
       
   122 	}
       
   123 
       
   124 void CProxyProtocol::Process(TDes8 & ,TSockAddr* /*from*/,TSockAddr* /*to*/,CProtocolBase* /*aSourceProtocol*/)
       
   125 	{
       
   126 	}
       
   127 
       
   128 void CProxyProtocol::Identify(TServerProtocolDesc *aDesc) const
       
   129 	{
       
   130 	Mem::Copy(aDesc, iProtoDesc, sizeof(TServerProtocolDesc));
       
   131 	}
       
   132 
       
   133 TInt CProxyProtocol::GetOption(TUint level,TUint,TDes8&,CProtocolBase* /*aSourceProtocol*/)
       
   134 	{
       
   135 	
       
   136 	if(level==KNifOptLevel)
       
   137 		{
       
   138 		return KErrNotSupported;
       
   139 		}
       
   140 	return KErrNone;
       
   141 	}
       
   142 
       
   143 TInt CProxyProtocol::SetOption(TUint /*level*/,TUint /*name*/,const TDesC8& /*option*/,CProtocolBase* /*aSourceProtocol*/)
       
   144 	{
       
   145 	return KErrNone;
       
   146 	}
       
   147 
       
   148 void CProxyProtocol::Error(TInt /*anerror*/,CProtocolBase* /*aSourceProtocol*/)
       
   149 	{
       
   150 	}
       
   151 //----------------------------------------------------------------------------------------------
       
   152 CProxyProvd *CProxyProvd::NewL(CProxyProtocol &aProtocol)
       
   153 	{
       
   154 	CProxyProvd *sp=new(ELeave) CProxyProvd(aProtocol);
       
   155 //	CleanupStack::PushL(sp);
       
   156 //	sp->ConstructL();
       
   157 //	CleanupStack::Pop(sp);
       
   158 	return sp;
       
   159 	}
       
   160 
       
   161 CProxyProvd::CProxyProvd(CProxyProtocol &aProtocol)
       
   162 	{
       
   163 	__DECLARE_NAME(_S("CTestIntSocketProvd"));
       
   164 	iIsBound=EFalse;
       
   165 	iProtocol=&aProtocol;
       
   166 	iCompleteIoctl = FALSE;
       
   167 	}
       
   168 
       
   169 
       
   170 void CProxyProvd::LocalName(TSockAddr& anAddr) const
       
   171 	{
       
   172 	anAddr=iAddr;
       
   173 	}
       
   174 
       
   175 TInt CProxyProvd::SetLocalName(TSockAddr& anAddr)
       
   176 	{
       
   177 	iAddr=anAddr;
       
   178 	iIsBound=ETrue;
       
   179 	return KErrNone;
       
   180 	}
       
   181 
       
   182 void CProxyProvd::RemName(TSockAddr& /*anAddr*/)const
       
   183 	{
       
   184 	}
       
   185 
       
   186 TInt CProxyProvd::SetRemName(TSockAddr& /*anAddr*/)
       
   187 	{
       
   188 
       
   189 //	test.Printf(_L("CTestIntSocketProvd::SetRemName Port %x, Addr %lx\n"),addr.Port(),addr.Address());
       
   190 	return KErrNone;
       
   191 	}
       
   192 
       
   193 void CProxyProvd::Shutdown(TCloseType anOption)
       
   194 	{
       
   195 	if (iCompleteIoctl)
       
   196 		{
       
   197 		iSocket->IoctlComplete(NULL);
       
   198 		}
       
   199 	if (anOption==ENormal)
       
   200 		iSocket->CanClose();
       
   201 	}
       
   202 
       
   203 void CProxyProvd::Start()
       
   204 //
       
   205 //
       
   206 //
       
   207 	{
       
   208 	}
       
   209 
       
   210 void CProxyProvd::Shutdown(TCloseType /*anOption*/,const TDesC8 &/*aDisconnectData*/)
       
   211 	{
       
   212 	Panic(EBadCall);
       
   213 	}
       
   214 
       
   215 void CProxyProvd::AutoBind( void )
       
   216 	{
       
   217 //	test.Printf(_L("CTestIntSocketProvd::AutoBind\n"));
       
   218 	iIsBound=ETrue;
       
   219 	}
       
   220 	
       
   221 
       
   222 void CProxyProvd::Ioctl(TUint /*level*/,TUint name,TDes8* aOption)
       
   223 	{
       
   224 	/* Mallik...if you want to see connection creation, just ping www.google.com in command prompt,
       
   225 	change ip & uncomment 
       
   226 	RInternalSocket intSock;
       
   227 	intSock.Open(KAfInet, KSockStream, KProtocolInetTcp);	
       
   228 	const TUint32 ip = INET_ADDR(209,85,153,104);
       
   229 	TInetAddr addr(80);
       
   230 	addr.SetAddress(ip);
       
   231 	
       
   232 	TRequestStatus status;
       
   233 	intSock.Connect(addr, status);
       
   234 	User::WaitForRequest(status);	
       
   235 	*/
       
   236 	
       
   237 	switch (name)
       
   238 		{
       
   239 		case KProxyProtocolTestRequest:
       
   240 			{
       
   241 			const TProxyProtocolRequest* request = reinterpret_cast<const TProxyProtocolRequest*>(aOption->Ptr());
       
   242 			TRAPD(r,CUdpClientTestBase::StartTestL(request->name,this));
       
   243 			if (r == KErrNone)
       
   244 				{
       
   245 				break;
       
   246 				}
       
   247 			}
       
   248 		default:
       
   249 			iSocket->Error(KErrNotSupported,MSocketNotify::EErrorIoctl);
       
   250 		}
       
   251 	}
       
   252 	
       
   253 void CProxyProvd::TestComplete(TProxyProtocolTestResult aResult)
       
   254 /**
       
   255 Called by the state machine (CInternalSocketTester) when a test completes (or fails early). Completes the ioctl to pass the result back to the client side test code.
       
   256 @param aResult	The result of the test (EPass or EFail)
       
   257 */
       
   258 	{
       
   259 	TProxyProtocolRequest resultStruct;
       
   260 	resultStruct.result = aResult;
       
   261 	TPckg<TProxyProtocolRequest> resultPckg(resultStruct);
       
   262 	iSocket->IoctlComplete(&resultPckg);
       
   263 	}
       
   264 	
       
   265 void CProxyProvd::CancelIoctl(TUint /*aLevel*/,TUint /*aName*/)
       
   266 	{}
       
   267 	
       
   268 TInt CProxyProvd::Write(RMBufChain& /*aData*/, TUint /*options*/, TSockAddr* /*anAddr*/)
       
   269 	{
       
   270 	return KErrNotSupported;
       
   271 	}
       
   272 	
       
   273 TUint CProxyProvd::Write(const TDesC8& /*aDesc*/, TUint /*options*/, TSockAddr* /*anAddr*/)
       
   274 	{
       
   275 	return (TUint)KErrNotSupported; //The return should really be a TInt possibly need to change the interface	
       
   276 	}
       
   277 	
       
   278 TInt CProxyProvd::GetData(RMBufChain& /*aData*/, TUint /*aLength*/, TUint /*options*/,TSockAddr* /*anAddr*/)
       
   279 	{
       
   280 	return KErrNotSupported;
       
   281 	}
       
   282 
       
   283 void CProxyProvd::GetData(TDes8& /*aDesc*/,TUint /*options*/,TSockAddr* /*anAddr*/)
       
   284 	{}
       
   285 
       
   286 void CProxyProvd::ActiveOpen(void)
       
   287 	{}
       
   288 	
       
   289 void CProxyProvd::ActiveOpen(const TDesC8 &/*aConnectionData*/)
       
   290 	{}
       
   291 
       
   292 TInt CProxyProvd::PassiveOpen(TUint /*aQue*/)
       
   293 	{
       
   294 	return KErrNotSupported;
       
   295 	}
       
   296 	
       
   297 TInt CProxyProvd::PassiveOpen(TUint /*aQue*/,const TDesC8& /*aConnectionData*/)
       
   298 	{
       
   299 	return KErrNotSupported;
       
   300 	}
       
   301 	
       
   302 TInt CProxyProvd::GetOption(TUint /*level*/,TUint /*name*/,TDes8& /*anOption*/ )const
       
   303 	{
       
   304 	return KErrNotSupported;
       
   305 	}
       
   306 	
       
   307 TInt CProxyProvd::SetOption(TUint /*level*/,TUint /*name*/,const TDesC8& /*anOption*/)
       
   308 	{
       
   309 	return KErrNotSupported;
       
   310 	}
       
   311