|
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 #include "chttpdefaultheaderreader.h" |
|
17 #include "CHeaderField.h" |
|
18 #include <inetprottextutils.h> |
|
19 |
|
20 |
|
21 _LIT8(KNewLine, "\n"); |
|
22 |
|
23 CHttpDefaultHeaderReader* CHttpDefaultHeaderReader::NewL(RStringPool aStringPool) |
|
24 /** |
|
25 Factory constructor. |
|
26 @internalComponent |
|
27 @param aStringPool The current string pool. |
|
28 @return A pointer to a fully initialised object. |
|
29 @leave KErrNoMemory Not enough memory to create object. |
|
30 */ |
|
31 { |
|
32 return new (ELeave) CHttpDefaultHeaderReader(aStringPool); |
|
33 } |
|
34 |
|
35 CHttpDefaultHeaderReader::~CHttpDefaultHeaderReader() |
|
36 /** |
|
37 Destructor |
|
38 @internalComponent |
|
39 */ |
|
40 { |
|
41 } |
|
42 |
|
43 CHttpDefaultHeaderReader::CHttpDefaultHeaderReader(RStringPool aStringPool) |
|
44 : CHeaderReader(), iStringPool(aStringPool) |
|
45 /** |
|
46 Constructor |
|
47 @internalComponent |
|
48 @param aStringPool The current string pool. |
|
49 */ |
|
50 { |
|
51 } |
|
52 |
|
53 /* |
|
54 * Methods from CHeaderReader |
|
55 */ |
|
56 |
|
57 void CHttpDefaultHeaderReader::DecodeHeaderL(RHeaderField& aHeader) |
|
58 /** |
|
59 Decodes the raw header field value. The default behaviour for fields which |
|
60 are unknown consists of copying the raw data into the header fields first |
|
61 part as a string. |
|
62 @internalComponent |
|
63 @param aHeader The header field to decode. |
|
64 @todo |
|
65 */ |
|
66 { |
|
67 // Get the over-the-air encoded data and trim white space from it |
|
68 TPtrC8 rawData; |
|
69 aHeader.RawDataL(rawData); |
|
70 TBool moreParts = ETrue; |
|
71 TPtrC8 currentPartData(KNullDesC8); |
|
72 TInt remaining = rawData.Length(); |
|
73 TInt index =0; |
|
74 |
|
75 do |
|
76 { |
|
77 // Search for '\n' separator. |
|
78 remaining -= InetProtTextUtils::ExtractNextTokenFromList(rawData, currentPartData, KNewLine); |
|
79 if (remaining <= 0) |
|
80 { |
|
81 moreParts = EFalse; |
|
82 } |
|
83 |
|
84 // create and set the new header part at position zero, using the OTA data without modification |
|
85 RStringF partStr = iStringPool.OpenFStringL(currentPartData); |
|
86 CleanupClosePushL(partStr); |
|
87 CHeaderFieldPart* part = CHeaderFieldPart::NewL(partStr); |
|
88 CleanupStack::PushL(part); |
|
89 aHeader.SetPartL(part,index); |
|
90 CleanupStack::Pop(part); |
|
91 CleanupStack::PopAndDestroy(&partStr); |
|
92 ++index; |
|
93 } while (moreParts); |
|
94 } |