|
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 #include <ss_glob.h> |
|
19 #include <comms-infras/ss_thread.h> |
|
20 #include <comms-infras/ss_nodemessages_factory.h> |
|
21 #include <comms-infras/ss_nodemessages_dataclient.h> |
|
22 #include "ptcpservertests.h" |
|
23 #include "upnp_cf_msgs.h" |
|
24 #include "upnpflowbase.h" |
|
25 #include "upnpflowfactory.h" |
|
26 #include "CTcpServerTestCase.h" |
|
27 |
|
28 |
|
29 #include <httperr.h> |
|
30 #include "CTcpServerTestUPnP41.h" |
|
31 #include "upnpserverconstants.h" |
|
32 |
|
33 _LIT8 ( KTestUPnPServiceUri,"http://127.0.0.1:80/testserviceuri1" ); |
|
34 _LIT8 ( KData, "POST /testserviceuri1 HTTP/1.1\r\nHost: 127.0.0.1\r\nContent-Length: 330\r\nContent-Type: text/xml; charset=utf-8\r\nSoapAction: :urn:shemas-upnp-org:control-1-0#QueryStateVariableResponse:\r\n\r\n"); |
|
35 _LIT8 ( KData1, "<?xml version=\"1.0\" encoding=\"utf-8\"?><s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:QueryStateVariableResponse xmlns:u=\"urn:shemas-upnp-org:control-1-0\"><return>Query return value</return></u:QueryStateVariableResponse></s:Body></s:Envelope>" ); |
|
36 _LIT8 ( KExpectedResponse, "HTTP/1.1 200 OK"); |
|
37 |
|
38 CTcpServerTestUPnP41* CTcpServerTestUPnP41::NewL ( CProxyProvd* aProvd ) |
|
39 { |
|
40 CTcpServerTestUPnP41* ret = new ( ELeave ) CTcpServerTestUPnP41 ( aProvd ); |
|
41 CleanupStack::PushL ( ret ); |
|
42 ret->ConstructL (); |
|
43 CleanupStack::Pop ( ret ); |
|
44 return ret; |
|
45 } |
|
46 |
|
47 CTcpServerTestUPnP41::CTcpServerTestUPnP41 ( CProxyProvd* aProvd ) : |
|
48 CTcpServerTestCase ( aProvd ),iSentHeaders(EFalse),iIsWriteDone(EFalse) |
|
49 { |
|
50 } |
|
51 |
|
52 CTcpServerTestUPnP41::~CTcpServerTestUPnP41 () |
|
53 { |
|
54 |
|
55 } |
|
56 |
|
57 void CTcpServerTestUPnP41::ConstructL () |
|
58 { |
|
59 CTcpServerTestCase::ConstructL(KTestUPnPServiceUri); |
|
60 } |
|
61 |
|
62 TVerdict CTcpServerTestUPnP41::RunTestL () |
|
63 { |
|
64 switch ( iState ) |
|
65 { |
|
66 |
|
67 case ESendData: |
|
68 { |
|
69 |
|
70 if(!iIsWriteDone) |
|
71 { |
|
72 iSendChain.CreateL ( KData ); |
|
73 iSocketHandler.Send ( iSendChain ); |
|
74 iSentHeaders = ETrue; |
|
75 } |
|
76 else |
|
77 { |
|
78 |
|
79 TCHMessageOption option ( 0, 330 ); |
|
80 TPckg < TCHMessageOption > optionBuf ( option ); |
|
81 |
|
82 iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf); |
|
83 |
|
84 RBuf8 resData; |
|
85 iSSP->GetOption(23, KCHMaxLength, resData); |
|
86 //iSSP->GetOption(KCHOptionLevel, KCHMaxLength, resData); |
|
87 |
|
88 RMBufChain bodyBuf; |
|
89 |
|
90 iSSPData->Write(bodyBuf, 0, NULL); |
|
91 |
|
92 TCHMessageOption option1 ( 1, 330 ); |
|
93 TPckg < TCHMessageOption > optionBuf1 ( option1 ); |
|
94 |
|
95 iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf1); |
|
96 |
|
97 //iSSP->SetOption(KCHOptionLevel, KCHLastMessage, optionBuf1); |
|
98 bodyBuf.CreateL(KData1); |
|
99 iSSPData->Write(bodyBuf, 1, NULL); |
|
100 |
|
101 iSSP->Shutdown(MSessionControl::EStopInput); |
|
102 |
|
103 iState = ESendStopServer; |
|
104 |
|
105 } |
|
106 iStatus = KRequestPending; |
|
107 Reschedule (); |
|
108 return EPass; |
|
109 } |
|
110 |
|
111 default: |
|
112 { |
|
113 return CTcpServerTestCase::RunTestL(); |
|
114 } |
|
115 } |
|
116 } |
|
117 |
|
118 |
|
119 void CTcpServerTestUPnP41::RecvComplete ( RMBufChain& aData ) |
|
120 { |
|
121 RBuf8 responseBuf; |
|
122 |
|
123 responseBuf.CreateMax ( aData.Length () ); |
|
124 aData.CopyOut ( responseBuf ); |
|
125 aData.Free (); |
|
126 |
|
127 if ( responseBuf.FindF ( KExpectedResponse ) != KErrNotFound ) |
|
128 { |
|
129 iResponse = EPass; // test case Passed |
|
130 iSocketHandler.Recv (); |
|
131 } |
|
132 else if ( responseBuf.FindF ( KData1 ) != KErrNotFound ) |
|
133 { |
|
134 CompleteSelf ( KErrNone ); |
|
135 } |
|
136 |
|
137 responseBuf.Close (); |
|
138 |
|
139 } |
|
140 |
|
141 void CTcpServerTestUPnP41::SendComplete ( TInt /*aLength*/ ) |
|
142 { |
|
143 iSendChain.Init (); |
|
144 if(iSentHeaders) |
|
145 { |
|
146 TRAP_IGNORE(iSendChain.CreateL ( KData1 )); |
|
147 iSocketHandler.Send ( iSendChain ); |
|
148 iSentHeaders = EFalse; |
|
149 } |
|
150 else |
|
151 iSocketHandler.Recv (); |
|
152 } |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 void CTcpServerTestUPnP41::NewData(TUint aCount) |
|
158 { |
|
159 |
|
160 |
|
161 iResponseLength = iResponseLength + aCount; |
|
162 |
|
163 if(!aCount && (iResponseLength == 334)) |
|
164 { |
|
165 iIsWriteDone = ETrue; |
|
166 CompleteSelf ( KErrNone ); |
|
167 } |
|
168 else |
|
169 { |
|
170 RBuf8 responseBuf; |
|
171 RBuf8 resData; |
|
172 RMBufChain dataReceived; |
|
173 |
|
174 iSSPData->GetData(dataReceived, aCount, 0, NULL); |
|
175 |
|
176 responseBuf.CreateMax ( dataReceived.Length () ); |
|
177 dataReceived.CopyOut ( responseBuf ); |
|
178 dataReceived.Free (); |
|
179 responseBuf.Close (); |
|
180 } |
|
181 /* |
|
182 iSSP->GetOption(KCHOptionLevel, KCHLastMessage, resData); |
|
183 TBool isLastMsg = *(TUint*) resData.Ptr(); |
|
184 |
|
185 if(isLastMsg) |
|
186 { |
|
187 iIsWriteDone = ETrue; |
|
188 CompleteSelf ( KErrNone ); |
|
189 } |
|
190 */ |
|
191 |
|
192 } |
|
193 |
|
194 void CTcpServerTestUPnP41::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
195 { |
|
196 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
197 { |
|
198 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
199 iTcpServer = msg.iNodeId; |
|
200 |
|
201 iFlow = mcfnode_cast<CSubConnectionFlowBase>( |
|
202 reinterpret_cast<Messages::ANode*>( iTcpServer.Ptr())); |
|
203 |
|
204 |
|
205 // Perform the binding to the flow below |
|
206 iFlowBinder = iFlow->GetBinderControlL(); |
|
207 iSSP = iFlowBinder->GetControlL(KSockStream, *this); |
|
208 iSSPData = iFlowBinder->BindL(*this); |
|
209 |
|
210 CompleteSelf ( KErrNone ); |
|
211 } |
|
212 else if ( aMessage.IsMessage<TCFDataClient::TStarted> () |
|
213 || aMessage.IsMessage<TCFDataClient::TStopped> () ) |
|
214 { |
|
215 CompleteSelf ( KErrNone ); |
|
216 } |
|
217 else if ( aMessage.IsMessage<TUpnpMessage::TUPnPRequestInfo> ()) |
|
218 { |
|
219 |
|
220 } |
|
221 } |
|
222 |
|
223 ///////////////////////////////////////////////////////////////////////////////////////////////////// |
|
224 |
|
225 _LIT8 ( KMPostData, "M-POST /testserviceuri1 HTTP/1.1\r\nHost: 127.0.0.1\r\nMAN: http://schemas.xmlsoap.org/soap/envelope/\r\nContent-Length: 330\r\nContent-Type: text/xml; charset=utf-8\r\nSoapAction: :urn:shemas-upnp-org:control-1-0#QueryStateVariableResponse:\r\n\r\n"); |
|
226 |
|
227 |
|
228 CTcpServerTestUPnP42* CTcpServerTestUPnP42::NewL ( CProxyProvd* aProvd ) |
|
229 { |
|
230 CTcpServerTestUPnP42* ret = new ( ELeave ) CTcpServerTestUPnP42 ( aProvd ); |
|
231 CleanupStack::PushL ( ret ); |
|
232 ret->ConstructL (); |
|
233 CleanupStack::Pop ( ret ); |
|
234 return ret; |
|
235 } |
|
236 |
|
237 CTcpServerTestUPnP42::CTcpServerTestUPnP42 ( CProxyProvd* aProvd ) : |
|
238 CTcpServerTestCase ( aProvd ),iSentHeaders(EFalse),iIsWriteDone(EFalse) |
|
239 { |
|
240 } |
|
241 |
|
242 CTcpServerTestUPnP42::~CTcpServerTestUPnP42 () |
|
243 { |
|
244 |
|
245 } |
|
246 |
|
247 void CTcpServerTestUPnP42::ConstructL () |
|
248 { |
|
249 CTcpServerTestCase::ConstructL(KTestUPnPServiceUri); |
|
250 } |
|
251 |
|
252 TVerdict CTcpServerTestUPnP42::RunTestL () |
|
253 { |
|
254 switch ( iState ) |
|
255 { |
|
256 |
|
257 case ESendData: |
|
258 { |
|
259 |
|
260 if(!iIsWriteDone) |
|
261 { |
|
262 iSendChain.CreateL ( KMPostData ); |
|
263 iSocketHandler.Send ( iSendChain ); |
|
264 iSentHeaders = ETrue; |
|
265 } |
|
266 else |
|
267 { |
|
268 |
|
269 TCHMessageOption option ( 0, 330 ); |
|
270 TPckg < TCHMessageOption > optionBuf ( option ); |
|
271 |
|
272 iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf); |
|
273 |
|
274 RBuf8 resData; |
|
275 iSSP->GetOption(23, KCHMaxLength, resData); |
|
276 //iSSP->GetOption(KCHOptionLevel, KCHMaxLength, resData); |
|
277 |
|
278 RMBufChain bodyBuf; |
|
279 |
|
280 iSSPData->Write(bodyBuf, 0, NULL); |
|
281 |
|
282 TCHMessageOption option1 ( 1, 330 ); |
|
283 TPckg < TCHMessageOption > optionBuf1 ( option1 ); |
|
284 |
|
285 iSSP->SetOption(KCHOptionLevel, KCHMaxLength, optionBuf1); |
|
286 |
|
287 //iSSP->SetOption(KCHOptionLevel, KCHLastMessage, optionBuf1); |
|
288 bodyBuf.CreateL(KData1); |
|
289 iSSPData->Write(bodyBuf, 1, NULL); |
|
290 |
|
291 iSSP->Shutdown(MSessionControl::EStopInput); |
|
292 |
|
293 iState = ESendStopServer; |
|
294 |
|
295 } |
|
296 iStatus = KRequestPending; |
|
297 Reschedule (); |
|
298 return EPass; |
|
299 } |
|
300 |
|
301 default: |
|
302 { |
|
303 return CTcpServerTestCase::RunTestL(); |
|
304 } |
|
305 } |
|
306 } |
|
307 |
|
308 |
|
309 void CTcpServerTestUPnP42::RecvComplete ( RMBufChain& aData ) |
|
310 { |
|
311 RBuf8 responseBuf; |
|
312 |
|
313 responseBuf.CreateMax ( aData.Length () ); |
|
314 aData.CopyOut ( responseBuf ); |
|
315 aData.Free (); |
|
316 |
|
317 if ( responseBuf.FindF ( KExpectedResponse ) != KErrNotFound ) |
|
318 { |
|
319 iResponse = EPass; // test case Passed |
|
320 iSocketHandler.Recv (); |
|
321 } |
|
322 else if ( responseBuf.FindF ( KData1 ) != KErrNotFound ) |
|
323 { |
|
324 CompleteSelf ( KErrNone ); |
|
325 } |
|
326 |
|
327 responseBuf.Close (); |
|
328 |
|
329 } |
|
330 |
|
331 void CTcpServerTestUPnP42::SendComplete ( TInt /*aLength*/ ) |
|
332 { |
|
333 iSendChain.Init (); |
|
334 if(iSentHeaders) |
|
335 { |
|
336 TRAP_IGNORE(iSendChain.CreateL ( KData1 )); |
|
337 iSocketHandler.Send ( iSendChain ); |
|
338 iSentHeaders = EFalse; |
|
339 } |
|
340 else |
|
341 iSocketHandler.Recv (); |
|
342 } |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 void CTcpServerTestUPnP42::NewData(TUint aCount) |
|
348 { |
|
349 |
|
350 |
|
351 iResponseLength = iResponseLength + aCount; |
|
352 |
|
353 if(!aCount && (iResponseLength == 334)) |
|
354 { |
|
355 iIsWriteDone = ETrue; |
|
356 CompleteSelf ( KErrNone ); |
|
357 } |
|
358 else |
|
359 { |
|
360 RBuf8 responseBuf; |
|
361 RBuf8 resData; |
|
362 RMBufChain dataReceived; |
|
363 |
|
364 iSSPData->GetData(dataReceived, aCount, 0, NULL); |
|
365 |
|
366 responseBuf.CreateMax ( dataReceived.Length () ); |
|
367 dataReceived.CopyOut ( responseBuf ); |
|
368 dataReceived.Free (); |
|
369 responseBuf.Close (); |
|
370 } |
|
371 /* |
|
372 iSSP->GetOption(KCHOptionLevel, KCHLastMessage, resData); |
|
373 TBool isLastMsg = *(TUint*) resData.Ptr(); |
|
374 |
|
375 if(isLastMsg) |
|
376 { |
|
377 iIsWriteDone = ETrue; |
|
378 CompleteSelf ( KErrNone ); |
|
379 } |
|
380 */ |
|
381 |
|
382 } |
|
383 |
|
384 void CTcpServerTestUPnP42::ReceivedL ( const TRuntimeCtxId& /*aSender*/, const TNodeId& /*aRecipient*/, TSignatureBase& aMessage ) |
|
385 { |
|
386 if ( aMessage.IsMessage<TCFFactory::TPeerFoundOrCreated> () ) |
|
387 { |
|
388 const TCFFactory::TPeerFoundOrCreated& msg = message_cast < const TCFFactory::TPeerFoundOrCreated > ( aMessage ); |
|
389 iTcpServer = msg.iNodeId; |
|
390 |
|
391 iFlow = mcfnode_cast<CSubConnectionFlowBase>( |
|
392 reinterpret_cast<Messages::ANode*>( iTcpServer.Ptr())); |
|
393 |
|
394 |
|
395 // Perform the binding to the flow below |
|
396 iFlowBinder = iFlow->GetBinderControlL(); |
|
397 iSSP = iFlowBinder->GetControlL(KSockStream, *this); |
|
398 iSSPData = iFlowBinder->BindL(*this); |
|
399 |
|
400 CompleteSelf ( KErrNone ); |
|
401 } |
|
402 else if ( aMessage.IsMessage<TCFDataClient::TStarted> () |
|
403 || aMessage.IsMessage<TCFDataClient::TStopped> () ) |
|
404 { |
|
405 CompleteSelf ( KErrNone ); |
|
406 } |
|
407 else if ( aMessage.IsMessage<TUpnpMessage::TUPnPRequestInfo> ()) |
|
408 { |
|
409 |
|
410 } |
|
411 } |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |