author | Sebastian Brannstrom <sebastianb@symbian.org> |
Tue, 19 Oct 2010 14:02:32 +0100 | |
branch | RCL_3 |
changeset 259 | af83e0ffbf4b |
parent 256 | 572d166c9421 |
child 285 | 4d42a5e09930 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB |
|
3 |
* |
|
4 |
* All rights reserved. |
|
5 |
* This component and the accompanying materials are made available |
|
6 |
* under the terms of the License "Eclipse Public License v1.0" |
|
7 |
* which accompanies this distribution, and is available |
|
8 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
9 |
* |
|
10 |
* Initial Contributors: |
|
11 |
* EmbedDev AB - initial contribution. |
|
12 |
* |
|
13 |
* Contributors: |
|
14 |
* |
|
15 |
* Description: |
|
16 |
* |
|
17 |
*/ |
|
18 |
||
19 |
// HttpEventHandler.cpp |
|
20 |
#include <e32debug.h> |
|
21 |
#include <httperr.h> |
|
256
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
22 |
#include <sysutil.h> |
2 | 23 |
#include "HttpEventHandler.h" |
24 |
#include "bautils.h" |
|
25 |
#include "Httpclient.h" |
|
26 |
||
256
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
27 |
const TInt64 KMinDiskSpace = 1024 * 1024; // at least 1 MB must remain |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
28 |
|
2 | 29 |
void CHttpEventHandler::ConstructL() |
30 |
{ |
|
31 |
//iVerbose = ETrue; |
|
32 |
} |
|
33 |
||
34 |
||
35 |
CHttpEventHandler::CHttpEventHandler(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs): |
|
36 |
iFileServ(aFs), iHttpClient(aClient), iCallbacks(aCallbacks) |
|
37 |
{ |
|
38 |
} |
|
39 |
||
40 |
||
41 |
CHttpEventHandler::~CHttpEventHandler() |
|
42 |
{ |
|
43 |
} |
|
44 |
||
45 |
||
46 |
CHttpEventHandler* CHttpEventHandler::NewLC(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs) |
|
47 |
{ |
|
48 |
CHttpEventHandler* me = new(ELeave)CHttpEventHandler(aClient, aCallbacks, aFs); |
|
49 |
CleanupStack::PushL(me); |
|
50 |
me->ConstructL(); |
|
51 |
return me; |
|
52 |
} |
|
53 |
||
54 |
||
55 |
CHttpEventHandler* CHttpEventHandler::NewL(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs) |
|
56 |
{ |
|
57 |
CHttpEventHandler* me = NewLC(aClient, aCallbacks, aFs); |
|
58 |
CleanupStack::Pop(me); |
|
59 |
return me; |
|
60 |
} |
|
61 |
||
62 |
void CHttpEventHandler::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
63 |
{ |
|
64 |
switch (aEvent.iStatus) |
|
65 |
{ |
|
66 |
case THTTPEvent::EGotResponseHeaders: |
|
67 |
{ |
|
68 |
// HTTP response headers have been received. We can determine now if there is |
|
69 |
// going to be a response body to save. |
|
70 |
RHTTPResponse resp = aTransaction.Response(); |
|
71 |
iLastStatusCode = resp.StatusCode(); |
|
119
a2933afe16a7
Fix for bug 2488: RHTTPResponse::StatusText returns KNullDesc for 404 for FeedBurner, but this text was only used in debug output.
teknolog
parents:
117
diff
changeset
|
72 |
DP1("Status: %d", iLastStatusCode); |
2 | 73 |
|
74 |
// Dump the headers if we're being verbose |
|
75 |
//DumpRespHeadersL(aTransaction); |
|
76 |
||
77 |
if (resp.HasBody() && (iLastStatusCode >= 200) && (iLastStatusCode < 300) && (iLastStatusCode != 204)) |
|
78 |
{ |
|
79 |
TInt dataSize = resp.Body()->OverallDataSize(); |
|
80 |
if (dataSize >= 0) { |
|
81 |
DP1("Response body size is %d", dataSize); |
|
82 |
iBytesTotal = dataSize; |
|
83 |
} else { |
|
84 |
DP("Response body size is unknown"); |
|
85 |
iBytesTotal = -1; |
|
86 |
} |
|
87 |
iCallbacks.DownloadInfo(iHttpClient, dataSize); |
|
88 |
||
89 |
} |
|
90 |
||
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
91 |
DP1("iFileOpen=%d", iFileOpen); |
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
92 |
if (!iFileOpen) |
2 | 93 |
{ |
94 |
iFileServ.Parse(iFileName, iParsedFileName); |
|
95 |
TInt valid = iFileServ.IsValidName(iFileName); |
|
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
96 |
|
2 | 97 |
if (!valid) |
98 |
{ |
|
99 |
DP("The specified filename is not valid!."); |
|
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
100 |
iHttpClient->ClientRequestCompleteL(KErrBadName); |
2 | 101 |
} |
102 |
else |
|
103 |
{ |
|
104 |
if (iContinue) { |
|
105 |
TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite); |
|
106 |
if (err) |
|
107 |
{ |
|
163
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
108 |
DP2("There was an error=%d opening file '%S'", err, &iParsedFileName.FullName()); |
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
109 |
iHttpClient->ClientRequestCompleteL(KErrInUse); |
2 | 110 |
User::Leave(err); |
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
111 |
} |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
112 |
else |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
113 |
{ |
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
114 |
iFileOpen = ETrue; |
2 | 115 |
int pos = -KByteOverlap; |
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
116 |
if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone) |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
117 |
{ |
2 | 118 |
DP("Failed to set position!"); |
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
119 |
iHttpClient->ClientRequestCompleteL(KErrWrite); |
2 | 120 |
User::Leave(err); |
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
121 |
} |
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
122 |
iBytesDownloaded = (pos > 0) ? pos : 0; |
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
123 |
iBytesTotal += iBytesDownloaded; |
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
124 |
DP1("Total bytes is now %u", iBytesTotal); |
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
125 |
DP1("Seeking end: %d", pos); |
2 | 126 |
} |
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
127 |
} |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
128 |
else |
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
129 |
{ |
2 | 130 |
TInt err = iRespBodyFile.Replace(iFileServ, |
131 |
iParsedFileName.FullName(), |
|
132 |
EFileWrite); |
|
133 |
if (err) |
|
134 |
{ |
|
135 |
DP("There was an error replacing file"); |
|
136 |
User::Leave(err); |
|
137 |
} |
|
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
138 |
else |
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
139 |
{ |
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
140 |
iFileOpen = ETrue; |
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
141 |
} |
2 | 142 |
} |
143 |
} |
|
144 |
} |
|
145 |
} break; |
|
146 |
case THTTPEvent::EGotResponseBodyData: |
|
147 |
{ |
|
148 |
// Get the body data supplier |
|
149 |
iRespBody = aTransaction.Response().Body(); |
|
150 |
||
151 |
// Some (more) body data has been received (in the HTTP response) |
|
152 |
//DumpRespBody(aTransaction); |
|
153 |
//DP1("Saving: %d", iSavingResponseBody); |
|
256
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
154 |
|
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
155 |
// check if we have enough disk space |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
156 |
if (iDriveNo != -1 && SysUtil::DiskSpaceBelowCriticalLevelL( &iFileServ, KMinDiskSpace, iDriveNo )) |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
157 |
{ |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
158 |
TInt error = KErrDiskFull; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
159 |
iFileOpen = EFalse; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
160 |
iRespBodyFile.Close(); |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
161 |
iCallbacks.FileError(error); |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
162 |
iHttpClient->ClientRequestCompleteL(error); |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
163 |
return; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
164 |
} |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
165 |
|
2 | 166 |
// Append to the output file if we're saving responses |
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
167 |
if (iFileOpen) |
2 | 168 |
{ |
169 |
TPtrC8 bodyData; |
|
170 |
iRespBody->GetNextDataPart(bodyData); |
|
171 |
iBytesDownloaded += bodyData.Length(); |
|
172 |
TInt error = iRespBodyFile.Write(bodyData); |
|
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
173 |
|
2 | 174 |
// on writing error we close connection |
175 |
if (error != KErrNone) { |
|
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
176 |
iFileOpen = EFalse; |
115
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents:
2
diff
changeset
|
177 |
iRespBodyFile.Close(); |
2 | 178 |
iCallbacks.FileError(error); |
179 |
iHttpClient->ClientRequestCompleteL(error); |
|
180 |
return; |
|
181 |
} |
|
182 |
||
183 |
if (!iSilent) { |
|
184 |
iCallbacks.Progress(iHttpClient, iBytesDownloaded, iBytesTotal); |
|
185 |
} |
|
186 |
} |
|
187 |
||
188 |
// Done with that bit of body data |
|
189 |
iRespBody->ReleaseData(); |
|
190 |
} break; |
|
191 |
case THTTPEvent::EResponseComplete: |
|
192 |
{ |
|
193 |
// The transaction's response is complete |
|
194 |
DP("Transaction Complete"); |
|
195 |
DP("Closing file"); |
|
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
196 |
iFileOpen = EFalse; |
2 | 197 |
iRespBodyFile.Close(); |
198 |
} break; |
|
199 |
case THTTPEvent::ESucceeded: |
|
200 |
{ |
|
201 |
DP("Transaction Successful"); |
|
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
202 |
iFileOpen = EFalse; |
126 | 203 |
iRespBodyFile.Close(); |
2 | 204 |
aTransaction.Close(); |
205 |
iHttpClient->ClientRequestCompleteL(KErrNone); |
|
206 |
} break; |
|
207 |
case THTTPEvent::EFailed: |
|
208 |
{ |
|
209 |
DP("Transaction Failed"); |
|
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
210 |
iFileOpen = EFalse; |
126 | 211 |
iRespBodyFile.Close(); |
2 | 212 |
aTransaction.Close(); |
213 |
||
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
214 |
if(iLastStatusCode == HTTPStatus::EOk || iLastStatusCode == HTTPStatus::ECreated || iLastStatusCode == HTTPStatus::EAccepted) |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
215 |
{ |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
216 |
iLastStatusCode = KErrNone; |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
217 |
} |
2 | 218 |
|
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
219 |
iHttpClient->ClientRequestCompleteL(iLastStatusCode); |
2 | 220 |
} break; |
221 |
case THTTPEvent::ERedirectedPermanently: |
|
222 |
{ |
|
223 |
DP("Permanent Redirection"); |
|
224 |
} break; |
|
225 |
case THTTPEvent::ERedirectedTemporarily: |
|
226 |
{ |
|
227 |
DP("Temporary Redirection"); |
|
228 |
} break; |
|
229 |
default: |
|
230 |
{ |
|
231 |
DP1("<unrecognised event: %d>", aEvent.iStatus); |
|
232 |
// close off the transaction if it's an error |
|
233 |
if (aEvent.iStatus < 0) |
|
234 |
{ |
|
172
c2a99fe1afd0
Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
163
diff
changeset
|
235 |
iFileOpen = EFalse; |
126 | 236 |
iRespBodyFile.Close(); |
2 | 237 |
aTransaction.Close(); |
238 |
iHttpClient->ClientRequestCompleteL(aEvent.iStatus); |
|
239 |
} |
|
240 |
} break; |
|
241 |
} |
|
242 |
} |
|
243 |
||
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
244 |
TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) |
2 | 245 |
{ |
246 |
DP1("MHFRunError fired with error code %d", aError); |
|
117
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
247 |
aTransaction.Close(); |
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents:
116
diff
changeset
|
248 |
TRAP_IGNORE(iHttpClient->ClientRequestCompleteL(aError)); |
2 | 249 |
return KErrNone; |
250 |
} |
|
251 |
||
252 |
void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue) |
|
253 |
{ |
|
163
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
126
diff
changeset
|
254 |
DP1("CHttpEventHandler::SetSaveFileName, aContinue=%d", aContinue); |
2 | 255 |
iFileName.Copy(fName); |
256 |
iContinue = aContinue; |
|
256
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
257 |
|
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
258 |
switch(fName[0]) |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
259 |
{ |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
260 |
case 'C': |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
261 |
iDriveNo = EDriveC; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
262 |
break; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
263 |
case 'E': |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
264 |
iDriveNo = EDriveE; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
265 |
break; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
266 |
case 'F': |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
267 |
iDriveNo = EDriveF; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
268 |
break; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
269 |
case 'G': |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
270 |
iDriveNo = EDriveG; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
271 |
break; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
272 |
default: |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
273 |
iDriveNo = -1; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
274 |
break; |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
275 |
} |
572d166c9421
Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
172
diff
changeset
|
276 |
DP1("iDriveNo set to %d", iDriveNo); |
2 | 277 |
} |
278 |
||
279 |
void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans) |
|
280 |
{ |
|
281 |
RHTTPResponse resp = aTrans.Response(); |
|
282 |
RStringPool strP = aTrans.Session().StringPool(); |
|
283 |
RHTTPHeaders hdr = resp.GetHeaderCollection(); |
|
284 |
THTTPHdrFieldIter it = hdr.Fields(); |
|
285 |
||
286 |
TBuf<KMaxHeaderNameLen> fieldName16; |
|
287 |
TBuf<KMaxHeaderValueLen> fieldVal16; |
|
288 |
||
289 |
while (it.AtEnd() == EFalse) |
|
290 |
{ |
|
291 |
RStringTokenF fieldName = it(); |
|
292 |
RStringF fieldNameStr = strP.StringF(fieldName); |
|
293 |
THTTPHdrVal fieldVal; |
|
294 |
if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone) |
|
295 |
{ |
|
296 |
const TDesC8& fieldNameDesC = fieldNameStr.DesC(); |
|
297 |
fieldName16.Copy(fieldNameDesC.Left(KMaxHeaderNameLen)); |
|
298 |
switch (fieldVal.Type()) |
|
299 |
{ |
|
300 |
case THTTPHdrVal::KTIntVal: |
|
301 |
DP2("%S: %d", &fieldName16, fieldVal.Int()); |
|
302 |
break; |
|
303 |
case THTTPHdrVal::KStrFVal: |
|
304 |
{ |
|
305 |
RStringF fieldValStr = strP.StringF(fieldVal.StrF()); |
|
306 |
const TDesC8& fieldValDesC = fieldValStr.DesC(); |
|
307 |
fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); |
|
308 |
DP2("%S: %S", &fieldName16, &fieldVal16); |
|
309 |
} |
|
310 |
break; |
|
311 |
case THTTPHdrVal::KStrVal: |
|
312 |
{ |
|
313 |
RString fieldValStr = strP.String(fieldVal.Str()); |
|
314 |
const TDesC8& fieldValDesC = fieldValStr.DesC(); |
|
315 |
fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); |
|
316 |
DP2("%S: %S", &fieldName16, &fieldVal16); |
|
317 |
} |
|
318 |
break; |
|
319 |
case THTTPHdrVal::KDateVal: |
|
320 |
{ |
|
321 |
TDateTime date = fieldVal.DateTime(); |
|
322 |
} |
|
323 |
break; |
|
324 |
default: |
|
325 |
DP1("%S: <unrecognised value type>", &fieldName16); |
|
326 |
break; |
|
327 |
} |
|
328 |
||
329 |
// Display realm for WWW-Authenticate header |
|
330 |
RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); |
|
331 |
if (fieldNameStr == wwwAuth) |
|
332 |
{ |
|
333 |
// check the auth scheme is 'basic' |
|
334 |
RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable()); |
|
335 |
RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable()); |
|
336 |
THTTPHdrVal realmVal; |
|
337 |
if ((fieldVal.StrF() == basic) && |
|
338 |
(!hdr.GetParam(wwwAuth, realm, realmVal))) |
|
339 |
{ |
|
340 |
RStringF realmValStr = strP.StringF(realmVal.StrF()); |
|
341 |
fieldVal16.Copy(realmValStr.DesC()); |
|
342 |
DP1("Realm is: %S", &fieldVal16); |
|
343 |
} |
|
344 |
} |
|
345 |
} |
|
346 |
++it; |
|
347 |
} |
|
348 |
} |
|
349 |
||
350 |
void CHttpEventHandler::DumpRespBody(RHTTPTransaction& aTrans) |
|
351 |
{ |
|
352 |
MHTTPDataSupplier* body = aTrans.Response().Body(); |
|
353 |
TPtrC8 dataChunk; |
|
354 |
TBool isLast = body->GetNextDataPart(dataChunk); |
|
355 |
DumpIt(dataChunk); |
|
356 |
if (isLast) |
|
357 |
DP("Got last data chunk."); |
|
358 |
} |
|
359 |
||
360 |
||
361 |
void CHttpEventHandler::DumpIt(const TDesC8& aData) |
|
362 |
//Do a formatted dump of binary data |
|
363 |
{ |
|
364 |
// Iterate the supplied block of data in blocks of cols=80 bytes |
|
365 |
const TInt cols=16; |
|
366 |
TInt pos = 0; |
|
367 |
TBuf<KMaxFileName - 2> logLine; |
|
368 |
TBuf<KMaxFileName - 2> anEntry; |
|
369 |
const TInt dataLength = aData.Length(); |
|
370 |
||
371 |
while (pos < dataLength) |
|
372 |
{ |
|
373 |
//start-line hexadecimal( a 4 digit number) |
|
374 |
anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos); |
|
375 |
logLine.Append(anEntry); |
|
376 |
||
377 |
// Hex output |
|
378 |
TInt offset; |
|
379 |
for (offset = 0; offset < cols; ++offset) |
|
380 |
{ |
|
381 |
if (pos + offset < aData.Length()) |
|
382 |
{ |
|
383 |
TInt nextByte = aData[pos + offset]; |
|
384 |
anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte); |
|
385 |
logLine.Append(anEntry); |
|
386 |
} |
|
387 |
else |
|
388 |
{ |
|
389 |
//fill the remaining spaces with blanks untill the cols-th Hex number |
|
390 |
anEntry.Format(TRefByValue<const TDesC>_L(" ")); |
|
391 |
logLine.Append(anEntry); |
|
392 |
} |
|
393 |
} |
|
394 |
anEntry.Format(TRefByValue<const TDesC>_L(": ")); |
|
395 |
logLine.Append(anEntry); |
|
396 |
||
397 |
// Char output |
|
398 |
for (offset = 0; offset < cols; ++offset) |
|
399 |
{ |
|
400 |
if (pos + offset < aData.Length()) |
|
401 |
{ |
|
402 |
TInt nextByte = aData[pos + offset]; |
|
403 |
if ((nextByte >= ' ') && (nextByte <= '~')) |
|
404 |
{ |
|
405 |
anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte); |
|
406 |
logLine.Append(anEntry); |
|
407 |
} |
|
408 |
else |
|
409 |
{ |
|
410 |
anEntry.Format(TRefByValue<const TDesC>_L(".")); |
|
411 |
logLine.Append(anEntry); |
|
412 |
} |
|
413 |
} |
|
414 |
else |
|
415 |
{ |
|
416 |
anEntry.Format(TRefByValue<const TDesC>_L(" ")); |
|
417 |
logLine.Append(anEntry); |
|
418 |
} |
|
419 |
} |
|
420 |
logLine.Zero(); |
|
421 |
||
422 |
// Advance to next byte segment (1 seg= cols) |
|
423 |
pos += cols; |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
void CHttpEventHandler::SetSilent(TBool aSilent) |
|
428 |
{ |
|
429 |
iSilent = aSilent; |
|
430 |
} |
|
431 |
||
432 |
void CHttpEventHandler::CloseSaveFile() |
|
433 |
{ |
|
434 |
if(iRespBody != NULL) |
|
435 |
{ |
|
436 |
if(iRespBodyFile.SubSessionHandle() != 0) |
|
437 |
{ |
|
438 |
TInt size; |
|
439 |
iRespBodyFile.Size(size); |
|
440 |
DP2("Closing file at size %d, bytes downloaded %d", size, iBytesDownloaded); |
|
441 |
iRespBodyFile.Close(); |
|
442 |
} |
|
443 |
} |
|
444 |
} |
|
445 |