|
1 // Copyright (c) 2001-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 |
|
17 // System includes |
|
18 #include <http.h> |
|
19 #include <inetprottextutils.h> |
|
20 #include <f32file.h> |
|
21 |
|
22 // Local includes |
|
23 #include "ceventcallbackfilter.h" |
|
24 #include "cdriverdatasupplier.h" |
|
25 #include "t_wspeventdriver/tdriverpanic.h" |
|
26 #include "t_wspeventdriver/mconsoledumper.h" |
|
27 |
|
28 // Class signature |
|
29 #include "t_wspeventdriver/cwspeventdriver.h" |
|
30 |
|
31 |
|
32 _LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3"); |
|
33 |
|
34 #ifndef EKA2 |
|
35 GLDEF_C TInt E32Dll(TDllReason /*aReason*/) |
|
36 { |
|
37 return(KErrNone); |
|
38 } |
|
39 #endif // EKA2 |
|
40 |
|
41 EXPORT_C CDriverTrans* CDriverTrans::NewL(RHTTPSession aSession, RStringF aMethod, TUriC8 aUri, |
|
42 MDriverTransObs& aObs, MHTTPTransactionCallback& aCB, |
|
43 const TDesC& aId) |
|
44 { |
|
45 CDriverTrans* self = new (ELeave) CDriverTrans(aSession, aObs); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(aMethod, aUri, aCB, aId); |
|
48 CleanupStack::Pop(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 EXPORT_C CDriverTrans::~CDriverTrans() |
|
53 { |
|
54 iTransaction.Close(); |
|
55 delete iTransId; |
|
56 iObs.Closed(*this); |
|
57 } |
|
58 |
|
59 EXPORT_C RHTTPTransaction CDriverTrans::Trans() const |
|
60 { |
|
61 return iTransaction; |
|
62 } |
|
63 |
|
64 EXPORT_C void CDriverTrans::AddHeaderL(RStringF aFieldName, THdrValType aFieldType, RString aFieldValue) |
|
65 { |
|
66 THTTPHdrVal fieldValue; |
|
67 ConvertHeaderValueL(aFieldValue, aFieldType, fieldValue); |
|
68 RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection(); |
|
69 hdr.SetFieldL(aFieldName, fieldValue); |
|
70 if (aFieldType == CDriverTrans::ERStringF) |
|
71 fieldValue.StrF().Close(); |
|
72 } |
|
73 |
|
74 EXPORT_C void CDriverTrans::AddHeaderWithParamL(RStringF aFieldName, THdrValType aFieldType, RString aFieldValue, |
|
75 RStringF aParamName, THdrValType aParamType, RString aParamValue) |
|
76 { |
|
77 THTTPHdrVal fieldValue; |
|
78 ConvertHeaderValueL(aFieldValue, aFieldType, fieldValue); |
|
79 THTTPHdrVal paramValue; |
|
80 ConvertHeaderValueL(aParamValue, aParamType, paramValue); |
|
81 RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection(); |
|
82 hdr.SetFieldL(aFieldName, fieldValue, aParamName, paramValue); |
|
83 if (aFieldType == CDriverTrans::ERStringF) |
|
84 fieldValue.StrF().Close(); |
|
85 if (aParamType == CDriverTrans::ERStringF) |
|
86 paramValue.StrF().Close(); |
|
87 } |
|
88 |
|
89 EXPORT_C void CDriverTrans::AddBody(MHTTPDataSupplier& aBody) |
|
90 { |
|
91 iTransaction.Request().SetBody(aBody); |
|
92 } |
|
93 |
|
94 EXPORT_C TBool CDriverTrans::GetHeaderL(RStringF aFieldName, THdrValType& aFieldType, RString& aFieldValue, TInt aPart) |
|
95 { |
|
96 RHTTPHeaders headers = iTransaction.Response().GetHeaderCollection(); |
|
97 |
|
98 RStringPool strP = aFieldName.Pool(); |
|
99 |
|
100 THTTPHdrVal value; |
|
101 TBool hasHeader = headers.GetField(aFieldName, aPart, value) != KErrNotFound; |
|
102 |
|
103 // Set the return values, provided the header was present |
|
104 if (hasHeader) |
|
105 { |
|
106 switch( value.Type() ) |
|
107 { |
|
108 case THTTPHdrVal::KTIntVal: |
|
109 { |
|
110 aFieldType = ETInt; |
|
111 |
|
112 HBufC8* buf = NULL; |
|
113 InetProtTextUtils::ConvertIntToDescriptorL(value.Int(), buf); |
|
114 CleanupStack::PushL(buf); |
|
115 |
|
116 aFieldValue = strP.OpenStringL(*buf); |
|
117 CleanupStack::PopAndDestroy(buf); |
|
118 } break; |
|
119 case THTTPHdrVal::KStrVal: |
|
120 { |
|
121 // Value is a case-sensitive string |
|
122 aFieldType = ERString; |
|
123 |
|
124 aFieldValue = value.Str().Copy(); |
|
125 } break; |
|
126 case THTTPHdrVal::KStrFVal: |
|
127 { |
|
128 // Value is a case-insensitive string |
|
129 aFieldType = ERStringF; |
|
130 |
|
131 aFieldValue = strP.OpenStringL(value.StrF().DesC()); |
|
132 } break; |
|
133 case THTTPHdrVal::KDateVal: |
|
134 case THTTPHdrVal::KNoType: |
|
135 default: |
|
136 // No value has yet been set |
|
137 TDriverPanic::Panic(TDriverPanic::EUnsupportedHdrValueType); |
|
138 } |
|
139 } |
|
140 return hasHeader; |
|
141 } |
|
142 |
|
143 EXPORT_C MHTTPDataSupplier& CDriverTrans::GetBody() |
|
144 { |
|
145 return *iTransaction.Response().Body(); |
|
146 } |
|
147 |
|
148 EXPORT_C TInt CDriverTrans::GetStatusCode() |
|
149 { |
|
150 return iTransaction.Response().StatusCode(); |
|
151 } |
|
152 |
|
153 |
|
154 EXPORT_C void CDriverTrans::SubmitL() |
|
155 { |
|
156 iTransaction.SubmitL(); |
|
157 } |
|
158 |
|
159 EXPORT_C void CDriverTrans::Cancel() |
|
160 { |
|
161 iTransaction.Cancel(); |
|
162 } |
|
163 |
|
164 EXPORT_C void CDriverTrans::Close() |
|
165 { |
|
166 delete this; |
|
167 } |
|
168 |
|
169 EXPORT_C const TDesC& CDriverTrans::TransId() const |
|
170 { |
|
171 return *iTransId; |
|
172 } |
|
173 |
|
174 EXPORT_C void CDriverTrans::MoreRequestBodyDataL() |
|
175 { |
|
176 iTransaction.NotifyNewRequestBodyPartL(); |
|
177 } |
|
178 |
|
179 EXPORT_C void CDriverTrans::DumpResponseHeadersL(MConsoleDumper& aConsole) |
|
180 { |
|
181 aConsole.StartDump(); |
|
182 |
|
183 // Dump the status code |
|
184 TBuf<KMaxFileName> dumpBuffer; |
|
185 dumpBuffer.Format(_L("HTTP Status: %d\n\n"), GetStatusCode()); |
|
186 aConsole.WriteData(dumpBuffer); |
|
187 |
|
188 // Dump the headers |
|
189 RHTTPResponse resp = iTransaction.Response(); |
|
190 RStringPool strP = iTransaction.Session().StringPool(); |
|
191 RHTTPHeaders hdr = resp.GetHeaderCollection(); |
|
192 DumpHeaderCollectionL(strP, hdr, dumpBuffer, aConsole); |
|
193 |
|
194 aConsole.EndDump(); |
|
195 } |
|
196 |
|
197 void CDriverTrans::DumpHeaderCollectionL(RStringPool aStrP, RHTTPHeaders aHdr, TDes& aWorkingBuffer, MConsoleDumper& aDumper) |
|
198 { |
|
199 THTTPHdrFieldIter it = aHdr.Fields(); |
|
200 |
|
201 TBuf<32> fieldName16; |
|
202 TBuf<KMaxFileName> fieldVal16; |
|
203 while (it.AtEnd() == EFalse) |
|
204 { |
|
205 aWorkingBuffer.Zero(); |
|
206 RStringTokenF fieldName = it(); |
|
207 RStringF fieldNameStr = aStrP.StringF(fieldName); |
|
208 THTTPHdrVal fieldVal; |
|
209 if (aHdr.GetField(fieldNameStr,0,fieldVal) == KErrNone) |
|
210 { |
|
211 fieldName16.Copy(fieldNameStr.DesC()); |
|
212 switch (fieldVal.Type()) |
|
213 { |
|
214 case THTTPHdrVal::KTIntVal: |
|
215 { |
|
216 aWorkingBuffer.Format(_L("%S: %d\n"), &fieldName16, fieldVal.Int()); |
|
217 } break; |
|
218 case THTTPHdrVal::KStrFVal: |
|
219 { |
|
220 RStringF fieldValStr = aStrP.StringF(fieldVal.StrF()); |
|
221 fieldVal16.Copy(fieldValStr.DesC()); |
|
222 aWorkingBuffer.Format(_L("%S: %S\n"), &fieldName16, &fieldVal16); |
|
223 } break; |
|
224 case THTTPHdrVal::KStrVal: |
|
225 { |
|
226 RString fieldValStr = aStrP.String(fieldVal.Str()); |
|
227 fieldVal16.Copy(fieldValStr.DesC()); |
|
228 aWorkingBuffer.Format(_L("%S: %S\n"), &fieldName16, &fieldVal16); |
|
229 } break; |
|
230 case THTTPHdrVal::KDateVal: |
|
231 { |
|
232 TDateTime date = fieldVal.DateTime(); |
|
233 TBuf<40> dateTimeString; |
|
234 TTime t(date); |
|
235 t.FormatL(dateTimeString,KDateFormat); |
|
236 aWorkingBuffer.Format(_L("%S: %S\n"), &fieldName16, &dateTimeString); |
|
237 } break; |
|
238 default: |
|
239 { |
|
240 aWorkingBuffer.Format(_L("%S: <unrecognised value type>\n"), &fieldName16); |
|
241 } |
|
242 } |
|
243 aDumper.WriteData(aWorkingBuffer); |
|
244 } |
|
245 ++it; |
|
246 } |
|
247 } |
|
248 |
|
249 EXPORT_C void CDriverTrans::DumpResponseBody(MConsoleDumper& aConsole) |
|
250 { |
|
251 aConsole.StartDump(); |
|
252 if (iTransaction.Response().HasBody()) |
|
253 { |
|
254 MHTTPDataSupplier* body = iTransaction.Response().Body(); |
|
255 TBuf<KMaxFileName> dumpBuffer; |
|
256 dumpBuffer.Format(_L("Overall Data Size: %d\n\n"), body->OverallDataSize()); |
|
257 aConsole.WriteData(dumpBuffer); |
|
258 TPtrC8 data; |
|
259 TBool moreData = body->GetNextDataPart(data); |
|
260 aConsole.DumpData(data); |
|
261 dumpBuffer.Format(_L("More data to come: %d\n"), moreData); |
|
262 aConsole.WriteData(dumpBuffer); |
|
263 body->ReleaseData(); |
|
264 } |
|
265 else |
|
266 aConsole.WriteData(_L("No response body")); |
|
267 aConsole.EndDump(); |
|
268 } |
|
269 |
|
270 CDriverTrans::CDriverTrans(RHTTPSession aSession, MDriverTransObs& aObs) |
|
271 : CBase(), iSession(aSession), iObs(aObs) |
|
272 { |
|
273 } |
|
274 |
|
275 void CDriverTrans::ConstructL(RStringF aMethod, TUriC8 aUri, MHTTPTransactionCallback& aCB, const TDesC& aId) |
|
276 { |
|
277 iTransaction = iSession.OpenTransactionL(aUri, aCB, aMethod); |
|
278 iTransId = aId.AllocL(); |
|
279 } |
|
280 |
|
281 void CDriverTrans::ConvertHeaderValueL(RString aInValue, THdrValType aType, THTTPHdrVal& aOutValue) |
|
282 { |
|
283 RStringPool strP = aInValue.Pool(); |
|
284 switch (aType) |
|
285 { |
|
286 case ETInt: |
|
287 { |
|
288 TInt val = 0; |
|
289 TLex8 lexer(aInValue.DesC()); |
|
290 TInt err = lexer.Val(val); |
|
291 __ASSERT_ALWAYS(err == KErrNone, TDriverPanic::Panic(TDriverPanic::EInvalidInteger)); |
|
292 aOutValue = val; |
|
293 } break; |
|
294 case ERString: |
|
295 { |
|
296 aOutValue = aInValue; |
|
297 } break; |
|
298 case ERStringF: |
|
299 { |
|
300 RStringF strf = strP.OpenFStringL(aInValue.DesC()); |
|
301 aOutValue = strf; |
|
302 strf.Copy(); |
|
303 strf.Close(); |
|
304 } break; |
|
305 case ETDateTime: |
|
306 { |
|
307 HBufC16* dateBuf = HBufC16::NewL(aInValue.DesC().Length()); |
|
308 CleanupStack::PushL(dateBuf); |
|
309 dateBuf->Des().Copy(aInValue.DesC()); |
|
310 TTime time; |
|
311 TInt err = time.Set(*dateBuf); |
|
312 __ASSERT_ALWAYS(err == KErrNone, TDriverPanic::Panic(TDriverPanic::ETimeDescriptor)); |
|
313 CleanupStack::PopAndDestroy(dateBuf); |
|
314 aOutValue = time.DateTime(); |
|
315 } break; |
|
316 }; |
|
317 } |
|
318 |
|
319 |
|
320 EXPORT_C CWspEventDriver* CWspEventDriver::NewL(CEventCallbackFilter& aCallbackFilter, |
|
321 const TDesC& aTrHndIniFile) |
|
322 { |
|
323 CWspEventDriver* self = new (ELeave) CWspEventDriver(aCallbackFilter); |
|
324 CleanupStack::PushL(self); |
|
325 self->ConstructL(aTrHndIniFile); |
|
326 CleanupStack::Pop(self); |
|
327 return self; |
|
328 } |
|
329 |
|
330 EXPORT_C CWspEventDriver::~CWspEventDriver() |
|
331 { |
|
332 iTransactionList.ResetAndDestroy(); |
|
333 iSession.Close(); |
|
334 } |
|
335 |
|
336 EXPORT_C RStringPool CWspEventDriver::StringPool() |
|
337 { |
|
338 return iStrP; |
|
339 } |
|
340 |
|
341 EXPORT_C TInt CWspEventDriver::Reset() |
|
342 { |
|
343 // Remove all the transactions |
|
344 iTransactionList.ResetAndDestroy(); |
|
345 |
|
346 // Clean-out the session properties |
|
347 iSession.ConnectionInfo().RemoveAllProperties(); |
|
348 |
|
349 // Cleanup the session headers |
|
350 RHTTPHeaders requestHeaders; |
|
351 TRAPD(error, requestHeaders = iSession.RequestSessionHeadersL() ); |
|
352 if( error != KErrNone ) |
|
353 return error; |
|
354 |
|
355 // Reset the request headers |
|
356 requestHeaders.RemoveAllFields(); |
|
357 |
|
358 RHTTPHeaders responseHeaders; |
|
359 TRAP(error, responseHeaders = iSession.ResponseSessionHeadersL() ); |
|
360 if( error != KErrNone ) |
|
361 return error; |
|
362 |
|
363 // Reset the request headers |
|
364 responseHeaders.RemoveAllFields(); |
|
365 |
|
366 // Reset the protocol handler |
|
367 TRAP(error, iSession.SendSessionEventL(THTTPSessionEvent(-999), THTTPSessionEvent::EOutgoing) ); |
|
368 if( error != KErrNone ) |
|
369 return error; |
|
370 |
|
371 CActiveScheduler::Start(); |
|
372 return KErrNone; |
|
373 } |
|
374 |
|
375 |
|
376 // |
|
377 // Scriptable methods |
|
378 // |
|
379 |
|
380 EXPORT_C void CWspEventDriver::SessionConnectL() |
|
381 { |
|
382 // Send session event EConnect |
|
383 iSession.SendSessionEventL(THTTPSessionEvent::EConnect, THTTPSessionEvent::EOutgoing); |
|
384 } |
|
385 |
|
386 EXPORT_C void CWspEventDriver::SessionDisconnectL() |
|
387 { |
|
388 // Send session event EDisconnect |
|
389 iSession.SendSessionEventL(THTTPSessionEvent::EDisconnect, THTTPSessionEvent::EOutgoing); |
|
390 } |
|
391 |
|
392 EXPORT_C void CWspEventDriver::SetClientMessageSizeL(TUint32 aSize) |
|
393 { |
|
394 // Set the property |
|
395 RHTTPConnectionInfo sessProps = iSession.ConnectionInfo(); |
|
396 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspCapClientMessageSize, RHTTPSession::GetTable()), THTTPHdrVal(aSize)); |
|
397 } |
|
398 |
|
399 EXPORT_C void CWspEventDriver::SetServerMessageSizeL(TUint32 aSize) |
|
400 { |
|
401 // Set the property |
|
402 RHTTPConnectionInfo sessProps = iSession.ConnectionInfo(); |
|
403 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspCapServerMessageSize, RHTTPSession::GetTable()), THTTPHdrVal(aSize)); |
|
404 } |
|
405 |
|
406 EXPORT_C void CWspEventDriver::SetUseAcknowledgementsL() |
|
407 { |
|
408 // Set the property |
|
409 RHTTPConnectionInfo sessProps = iSession.ConnectionInfo(); |
|
410 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspCapUseAcknowledgements, RHTTPSession::GetTable()), THTTPHdrVal(ETrue)); |
|
411 } |
|
412 |
|
413 EXPORT_C void CWspEventDriver::SetUseSuspendResumeL() |
|
414 { |
|
415 // Set the property |
|
416 RHTTPConnectionInfo sessProps = iSession.ConnectionInfo(); |
|
417 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspCapSupportSuspendResume, RHTTPSession::GetTable()), THTTPHdrVal(ETrue)); |
|
418 } |
|
419 |
|
420 EXPORT_C void CWspEventDriver::SetMethodMORL(TUint32 aMOR) |
|
421 { |
|
422 // Set the property |
|
423 RHTTPConnectionInfo sessProps = iSession.ConnectionInfo(); |
|
424 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspCapMaxOutstandingRequests, RHTTPSession::GetTable()), THTTPHdrVal(aMOR)); |
|
425 } |
|
426 |
|
427 EXPORT_C void CWspEventDriver::SetConnectionPropertiesL(RStringF aProxyAddress, RStringF aBearer, TInt aLocalPort, |
|
428 TInt aRemotePort, TInt aServiceNum, RStringF aSessionType, |
|
429 RStringF aIsSecure, TInt aTimeOut) |
|
430 { |
|
431 RHTTPConnectionInfo sessProps = iSession.ConnectionInfo(); |
|
432 if (aProxyAddress != RStringF()) |
|
433 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspProxyAddress, RHTTPSession::GetTable()), THTTPHdrVal(aProxyAddress)); |
|
434 // |
|
435 if (aBearer != RStringF()) |
|
436 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspBearer, RHTTPSession::GetTable()), THTTPHdrVal(aBearer)); |
|
437 // |
|
438 if (aLocalPort >= 0) |
|
439 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspLocalPort, RHTTPSession::GetTable()), THTTPHdrVal(aLocalPort)); |
|
440 // |
|
441 if (aRemotePort >= 0) |
|
442 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspRemotePort, RHTTPSession::GetTable()), THTTPHdrVal(aRemotePort)); |
|
443 // |
|
444 if (aServiceNum >= 0) |
|
445 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspServiceNumber, RHTTPSession::GetTable()), THTTPHdrVal(aServiceNum)); |
|
446 // |
|
447 if (aSessionType != RStringF()) |
|
448 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspSessionType, RHTTPSession::GetTable()), THTTPHdrVal(aSessionType)); |
|
449 // |
|
450 if (aIsSecure != RStringF()) |
|
451 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspSecurity, RHTTPSession::GetTable()), THTTPHdrVal(aIsSecure)); |
|
452 // |
|
453 if (aTimeOut >= 0) |
|
454 sessProps.SetPropertyL(iStrP.StringF(HTTP::EWspProxyConnectionTimeout, RHTTPSession::GetTable()), THTTPHdrVal(aTimeOut)); |
|
455 } |
|
456 |
|
457 EXPORT_C void CWspEventDriver::GetConnectionProperties(RStringF& aProxyAddress, RStringF& aBearer, TInt& aLocalPort, |
|
458 TInt& aRemotePort, TInt& aServiceNum, RStringF& aSessionType, |
|
459 RStringF& aIsSecure, TInt& aTimeOut) |
|
460 { |
|
461 RHTTPConnectionInfo sessProps = iSession.ConnectionInfo(); |
|
462 THTTPHdrVal propVal; |
|
463 // |
|
464 if (sessProps.Property(iStrP.StringF(HTTP::EWspProxyAddress, RHTTPSession::GetTable()), propVal)) |
|
465 { |
|
466 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KStrFVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
467 aProxyAddress = propVal; |
|
468 } |
|
469 else |
|
470 aProxyAddress = RStringF(); |
|
471 // |
|
472 if (sessProps.Property(iStrP.StringF(HTTP::EWspBearer, RHTTPSession::GetTable()), propVal)) |
|
473 { |
|
474 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KStrFVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
475 aBearer = propVal; |
|
476 } |
|
477 else |
|
478 aBearer = RStringF(); |
|
479 // |
|
480 if (sessProps.Property(iStrP.StringF(HTTP::EWspLocalPort, RHTTPSession::GetTable()), propVal)) |
|
481 { |
|
482 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KTIntVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
483 aLocalPort = propVal; |
|
484 } |
|
485 else |
|
486 aLocalPort = -1; |
|
487 // |
|
488 if (sessProps.Property(iStrP.StringF(HTTP::EWspRemotePort, RHTTPSession::GetTable()), propVal)) |
|
489 { |
|
490 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KTIntVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
491 aRemotePort = propVal; |
|
492 } |
|
493 else |
|
494 aRemotePort = -1; |
|
495 // |
|
496 if (sessProps.Property(iStrP.StringF(HTTP::EWspServiceNumber, RHTTPSession::GetTable()), propVal)) |
|
497 { |
|
498 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KTIntVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
499 aServiceNum = propVal; |
|
500 } |
|
501 else |
|
502 aServiceNum = -1; |
|
503 // |
|
504 if (sessProps.Property(iStrP.StringF(HTTP::EWspSessionType, RHTTPSession::GetTable()), propVal)) |
|
505 { |
|
506 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KStrFVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
507 aSessionType = propVal; |
|
508 } |
|
509 else |
|
510 aSessionType = RStringF(); |
|
511 // |
|
512 if (sessProps.Property(iStrP.StringF(HTTP::EWspSecurity, RHTTPSession::GetTable()), propVal)) |
|
513 { |
|
514 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KStrFVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
515 aIsSecure = propVal; |
|
516 } |
|
517 else |
|
518 aIsSecure = RStringF(); |
|
519 // |
|
520 if (sessProps.Property(iStrP.StringF(HTTP::EWspProxyConnectionTimeout, RHTTPSession::GetTable()), propVal)) |
|
521 { |
|
522 __ASSERT_DEBUG(propVal.Type() == THTTPHdrVal::KTIntVal, TDriverPanic::Panic(TDriverPanic::EWrongPropertyType)); |
|
523 aTimeOut = propVal; |
|
524 } |
|
525 else |
|
526 aTimeOut = -1; |
|
527 } |
|
528 |
|
529 |
|
530 |
|
531 EXPORT_C CDriverTrans* CWspEventDriver::OpenTransactionL(RStringF aMethod, TUriC8 aUri, const TDesC& aId) |
|
532 { |
|
533 // Create the driver transaction and place on the list |
|
534 CDriverTrans* tr = CDriverTrans::NewL(iSession, aMethod, aUri, *this, iCallbackFilter.TransactionCallback(), aId); |
|
535 CleanupStack::PushL(tr); |
|
536 User::LeaveIfError(iTransactionList.Append(tr)); |
|
537 CleanupStack::Pop(tr); |
|
538 return tr; |
|
539 } |
|
540 |
|
541 EXPORT_C void CWspEventDriver::AddRequestSessionHeaderL(RStringF aFieldName, CDriverTrans::THdrValType aFieldType, RString aFieldValue) |
|
542 { |
|
543 THTTPHdrVal fieldValue; |
|
544 CDriverTrans::ConvertHeaderValueL(aFieldValue, aFieldType, fieldValue); |
|
545 RHTTPHeaders hdr = iSession.RequestSessionHeadersL(); |
|
546 hdr.SetFieldL(aFieldName, fieldValue); |
|
547 if (aFieldType == CDriverTrans::ERStringF) |
|
548 fieldValue.StrF().Close(); |
|
549 } |
|
550 |
|
551 EXPORT_C void CWspEventDriver::AddRequestSessionHeaderWithParamL(RStringF aFieldName, CDriverTrans::THdrValType aFieldType, |
|
552 RString aFieldValue, RStringF aParamName, |
|
553 CDriverTrans::THdrValType aParamType, RString aParamValue) |
|
554 { |
|
555 THTTPHdrVal fieldValue; |
|
556 CDriverTrans::ConvertHeaderValueL(aFieldValue, aFieldType, fieldValue); |
|
557 THTTPHdrVal paramValue; |
|
558 CDriverTrans::ConvertHeaderValueL(aParamValue, aParamType, paramValue); |
|
559 RHTTPHeaders hdr = iSession.RequestSessionHeadersL(); |
|
560 hdr.SetFieldL(aFieldName, fieldValue, aParamName, paramValue); |
|
561 if (aFieldType == CDriverTrans::ERStringF) |
|
562 fieldValue.StrF().Close(); |
|
563 if (aParamType == CDriverTrans::ERStringF) |
|
564 paramValue.StrF().Close(); |
|
565 } |
|
566 |
|
567 EXPORT_C void CWspEventDriver::DumpSessionHeadersL(MConsoleDumper& aConsole) |
|
568 { |
|
569 aConsole.StartDump(); |
|
570 |
|
571 // Dump the headers |
|
572 TBuf<KMaxFileName> dumpBuffer; |
|
573 RStringPool strP = iSession.StringPool(); |
|
574 |
|
575 // Request session headers |
|
576 aConsole.WriteData(_L("Session Request Headers:\n")); |
|
577 RHTTPHeaders hdr = iSession.RequestSessionHeadersL(); |
|
578 CDriverTrans::DumpHeaderCollectionL(strP, hdr, dumpBuffer, aConsole); |
|
579 |
|
580 // Response session headers |
|
581 aConsole.WriteData(_L("Session Response Headers:\n")); |
|
582 hdr = iSession.ResponseSessionHeadersL(); |
|
583 CDriverTrans::DumpHeaderCollectionL(strP, hdr, dumpBuffer, aConsole); |
|
584 |
|
585 aConsole.EndDump(); |
|
586 } |
|
587 |
|
588 void CWspEventDriver::Closed(CDriverTrans& aDrTr) |
|
589 { |
|
590 // Locate the trans on the list and remove it (it's already been deleted) |
|
591 TBool found = EFalse; |
|
592 TInt idx = 0; |
|
593 while (!found && (idx < iTransactionList.Count())) |
|
594 { |
|
595 if (&aDrTr == iTransactionList[idx]) |
|
596 { |
|
597 found = ETrue; |
|
598 iTransactionList.Remove(idx); |
|
599 } |
|
600 else |
|
601 ++idx; |
|
602 } |
|
603 } |
|
604 |
|
605 CDriverTrans& CWspEventDriver::LookUpTransaction(RHTTPTransaction aTr) |
|
606 { |
|
607 // Locate the trans on the list and remove it (it's already been deleted) |
|
608 TBool found = EFalse; |
|
609 TInt idx = 0; |
|
610 while (!found && (idx < iTransactionList.Count())) |
|
611 { |
|
612 if (iTransactionList[idx]->Trans() == aTr) |
|
613 found = ETrue; |
|
614 else |
|
615 ++idx; |
|
616 } |
|
617 __ASSERT_DEBUG(found, User::Invariant()); |
|
618 return *(iTransactionList[idx]); |
|
619 } |
|
620 |
|
621 CWspEventDriver::CWspEventDriver(CEventCallbackFilter& aCallbackFilter) |
|
622 : CBase(), iCallbackFilter(aCallbackFilter) |
|
623 { |
|
624 aCallbackFilter.SetTransConverter(*this); |
|
625 } |
|
626 |
|
627 void CWspEventDriver::ConstructL(const TDesC& aTrHndIniFile) |
|
628 { |
|
629 // Write the location of the ini file for the stub to pick up. The filename of the actual |
|
630 // ini file to be used is written as the contents of the link file. |
|
631 _LIT(KTrHndIniLinkFile, "wsptrhndstub_link.ini"); |
|
632 _LIT(KTrHndIniLinkDir, "C:\\"); |
|
633 RFs fileSrvHnd; |
|
634 User::LeaveIfError(fileSrvHnd.Connect()); |
|
635 TParse parsedLinkFile; |
|
636 parsedLinkFile.Set(KTrHndIniLinkDir, &(KTrHndIniLinkFile()), NULL); |
|
637 RFile linkFileHnd; |
|
638 User::LeaveIfError( linkFileHnd.Replace(fileSrvHnd, parsedLinkFile.FullName(), |
|
639 EFileWrite|EFileShareExclusive) ); |
|
640 HBufC8* iniFile8 = HBufC8::NewLC(aTrHndIniFile.Length()); |
|
641 iniFile8->Des().Copy(aTrHndIniFile); |
|
642 User::LeaveIfError( linkFileHnd.Write(iniFile8->Des()) ); |
|
643 linkFileHnd.Close(); |
|
644 CleanupStack::PopAndDestroy(iniFile8); |
|
645 |
|
646 // Open the session and get the string pool reference from it |
|
647 iSession.OpenL(_L8("WSP/WSP")); |
|
648 iStrP = iSession.StringPool(); |
|
649 |
|
650 // Set the session callback |
|
651 iSession.SetSessionEventCallback(&iCallbackFilter.SessionCallback()); |
|
652 |
|
653 // Ensure the request and response session headers are created |
|
654 (void)iSession.RequestSessionHeadersL(); |
|
655 (void)iSession.ResponseSessionHeadersL(); |
|
656 } |
|
657 |