|
1 // Copyright (c) 2004-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 // |
|
15 |
|
16 #include "es_ptestinternalsocket.h" |
|
17 |
|
18 #include <comms-infras/nifif_internal.h> |
|
19 |
|
20 #include "proxyprotocol.h" |
|
21 #include "ptestcases.h" |
|
22 |
|
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 (iTestStepNotify) |
|
196 { |
|
197 iTestStepNotify->AboutToShutdown(); |
|
198 } |
|
199 if (iCompleteIoctl) |
|
200 { |
|
201 iSocket->IoctlComplete(NULL); |
|
202 } |
|
203 if (anOption==ENormal) |
|
204 iSocket->CanClose(); |
|
205 } |
|
206 |
|
207 void CProxyProvd::Start() |
|
208 // |
|
209 // |
|
210 // |
|
211 { |
|
212 } |
|
213 |
|
214 void CProxyProvd::Shutdown(TCloseType /*anOption*/,const TDesC8 &/*aDisconnectData*/) |
|
215 { |
|
216 Panic(EBadCall); |
|
217 } |
|
218 |
|
219 void CProxyProvd::AutoBind( void ) |
|
220 { |
|
221 // test.Printf(_L("CTestIntSocketProvd::AutoBind\n")); |
|
222 iIsBound=ETrue; |
|
223 } |
|
224 |
|
225 |
|
226 void CProxyProvd::Ioctl(TUint /*level*/,TUint name,TDes8* aOption) |
|
227 { |
|
228 switch (name) |
|
229 { |
|
230 case KProxyProtocolTestRequest: |
|
231 { |
|
232 const TProxyProtocolRequest* request = reinterpret_cast<const TProxyProtocolRequest*>(aOption->Ptr()); |
|
233 TRAPD(r,CEIntSockTestBase::StartTestL(request->name,this)); |
|
234 if (r == KErrNone) |
|
235 { |
|
236 break; |
|
237 } |
|
238 } |
|
239 default: |
|
240 iSocket->Error(KErrNotSupported,MSocketNotify::EErrorIoctl); |
|
241 } |
|
242 } |
|
243 |
|
244 void CProxyProvd::TestComplete(TProxyProtocolTestResult aResult) |
|
245 /** |
|
246 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. |
|
247 @param aResult The result of the test (EPass or EFail) |
|
248 */ |
|
249 { |
|
250 TProxyProtocolRequest resultStruct; |
|
251 resultStruct.result = aResult; |
|
252 TPckg<TProxyProtocolRequest> resultPckg(resultStruct); |
|
253 iSocket->IoctlComplete(&resultPckg); |
|
254 } |
|
255 |
|
256 void CProxyProvd::CancelIoctl(TUint /*aLevel*/,TUint /*aName*/) |
|
257 {} |
|
258 |
|
259 TInt CProxyProvd::Write(RMBufChain& /*aData*/, TUint /*options*/, TSockAddr* /*anAddr*/) |
|
260 { |
|
261 return KErrNotSupported; |
|
262 } |
|
263 |
|
264 TUint CProxyProvd::Write(const TDesC8& /*aDesc*/, TUint /*options*/, TSockAddr* /*anAddr*/) |
|
265 { |
|
266 return (TUint)KErrNotSupported; //The return should really be a TInt possibly need to change the interface |
|
267 } |
|
268 |
|
269 TInt CProxyProvd::GetData(RMBufChain& /*aData*/, TUint /*aLength*/, TUint /*options*/,TSockAddr* /*anAddr*/) |
|
270 { |
|
271 return KErrNotSupported; |
|
272 } |
|
273 |
|
274 void CProxyProvd::GetData(TDes8& /*aDesc*/,TUint /*options*/,TSockAddr* /*anAddr*/) |
|
275 {} |
|
276 |
|
277 void CProxyProvd::ActiveOpen(void) |
|
278 {} |
|
279 |
|
280 void CProxyProvd::ActiveOpen(const TDesC8 &/*aConnectionData*/) |
|
281 {} |
|
282 |
|
283 TInt CProxyProvd::PassiveOpen(TUint /*aQue*/) |
|
284 { |
|
285 return KErrNotSupported; |
|
286 } |
|
287 |
|
288 TInt CProxyProvd::PassiveOpen(TUint /*aQue*/,const TDesC8& /*aConnectionData*/) |
|
289 { |
|
290 return KErrNotSupported; |
|
291 } |
|
292 |
|
293 TInt CProxyProvd::GetOption(TUint /*level*/,TUint /*name*/,TDes8& /*anOption*/ )const |
|
294 { |
|
295 return KErrNotSupported; |
|
296 } |
|
297 |
|
298 TInt CProxyProvd::SetOption(TUint /*level*/,TUint /*name*/,const TDesC8& /*anOption*/) |
|
299 { |
|
300 return KErrNotSupported; |
|
301 } |
|
302 |
|
303 |