|
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 // User Includes |
|
17 #include "cwspheadercodec.h" |
|
18 #include "cwspheaderwriter.h" |
|
19 #include "cwspheaderreader.h" |
|
20 |
|
21 // System Includes |
|
22 #include <wspstringconstants.h> |
|
23 #include <wspparamconstants.h> |
|
24 #include <wspcontenttypes.h> |
|
25 #include <wspregcontenttypes.h> |
|
26 #include <wspcharactersets.h> |
|
27 #include <wspstdconstants.h> |
|
28 #include <wsplanguages.h> |
|
29 #include <wsptypeconstants.h> |
|
30 |
|
31 CWspHeaderCodec* CWspHeaderCodec::NewL(RStringPool aStrPool, const TStringTable& aStrTable) |
|
32 { |
|
33 CWspHeaderCodec* self = new(ELeave)CWspHeaderCodec(aStrPool, aStrTable); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CWspHeaderCodec::~CWspHeaderCodec() |
|
41 { |
|
42 } |
|
43 |
|
44 TBool CWspHeaderCodec::CanEncode(RStringF aHeaderField) const |
|
45 { |
|
46 TBool encode = EFalse; |
|
47 switch( aHeaderField.Index(iStrTable) ) |
|
48 { |
|
49 // List headers in reverse order of encoding version |
|
50 // No v1.4 headers |
|
51 // v1.3 |
|
52 case WSP::EEncodingVersion: |
|
53 case WSP::ECookie: |
|
54 case WSP::ETrailer: |
|
55 case WSP::ETE: |
|
56 case WSP::EExpect: |
|
57 { |
|
58 // These are v1.3 headers so if the WSP version is less then do not encode |
|
59 if( iWspVersion < EVersion1_3 ) |
|
60 break; // use defaul return of EFalse |
|
61 // Drop through... |
|
62 } |
|
63 |
|
64 //v1.2 |
|
65 case WSP::EProfile: |
|
66 case WSP::EProfileDiff: |
|
67 case WSP::EXWapApplicationId: |
|
68 { |
|
69 // These are v1.2 headers so if the WSP version is less then do not encode |
|
70 if( iWspVersion < EVersion1_2 ) |
|
71 break; // use defaul return of EFalse |
|
72 // Drop through... |
|
73 } |
|
74 |
|
75 //v1.1 |
|
76 case WSP::EAccept: |
|
77 case WSP::EAcceptCharset: |
|
78 case WSP::EAcceptCharsetDep: |
|
79 case WSP::EAcceptEncoding: |
|
80 case WSP::EAcceptEncodingDep: |
|
81 case WSP::EAcceptLanguage: |
|
82 case WSP::EAllow: |
|
83 case WSP::EAuthorization: |
|
84 case WSP::EContentEncoding: |
|
85 case WSP::EContentLanguage: |
|
86 case WSP::EContentLocation: |
|
87 case WSP::EContentMD5: |
|
88 case WSP::EContentRange: |
|
89 case WSP::EContentRangeDep: |
|
90 case WSP::EContentType: |
|
91 case WSP::EDate: |
|
92 case WSP::EFrom: |
|
93 case WSP::ELastModified: |
|
94 case WSP::EPragma: |
|
95 case WSP::ERange: |
|
96 case WSP::EReferer: |
|
97 case WSP::EUpgrade: |
|
98 case WSP::EUserAgent: |
|
99 case WSP::EVia: |
|
100 case WSP::EWarning: |
|
101 { |
|
102 encode = ETrue; |
|
103 } break; |
|
104 } |
|
105 return encode; |
|
106 } |
|
107 |
|
108 TBool CWspHeaderCodec::CanDecode(RStringF aHeaderField) const |
|
109 { |
|
110 TBool decode = EFalse; |
|
111 switch( aHeaderField.Index(iStrTable) ) |
|
112 { |
|
113 case WSP::EContentType: |
|
114 case WSP::EDate: |
|
115 case WSP::ELastModified: |
|
116 case WSP::EPragma: |
|
117 case WSP::EVary: |
|
118 case WSP::EWWWAuthenticate: |
|
119 case WSP::ESetCookie: |
|
120 case WSP::EContentLocation: |
|
121 case WSP::ELocation: |
|
122 case WSP::EEncodingVersion: |
|
123 case WSP::EAcceptRanges: |
|
124 case WSP::EContentEncoding: |
|
125 case WSP::EContentLanguage: |
|
126 case WSP::EContentMD5: |
|
127 case WSP::EProxyAuthenticate: |
|
128 case WSP::EServer: |
|
129 case WSP::ERetryAfter: |
|
130 case WSP::EVia: |
|
131 case WSP::ETrailer: |
|
132 case WSP::EContentRange: |
|
133 case WSP::EContentRangeDep: |
|
134 case WSP::EXWapApplicationId: |
|
135 case WSP::EXWapInitiatorURI: |
|
136 case WSP::EPushFlag: |
|
137 case WSP::EAllow: |
|
138 case WSP::EUpgrade: |
|
139 case WSP::EWarning: |
|
140 case WSP::EProfileWarning: |
|
141 case WSP::EProfileWarningDep: |
|
142 { |
|
143 decode = ETrue; |
|
144 } break; |
|
145 } |
|
146 return decode; |
|
147 } |
|
148 |
|
149 CHeaderCodec* CWspHeaderCodec::FindDelegateCodecL(RStringF /*aHeaderField*/) const |
|
150 { |
|
151 // Create and return the WSP default header codec |
|
152 return CWspDefaultHeaderCodec::NewL(iStrPool);; |
|
153 } |
|
154 |
|
155 CWspHeaderCodec::CWspHeaderCodec(RStringPool aStrPool, const TStringTable& aStrTable) |
|
156 : CHeaderCodec(), iStrPool(aStrPool), iStrTable(aStrTable), iWspVersion(EVersion1_2) |
|
157 { |
|
158 } |
|
159 |
|
160 void CWspHeaderCodec::ConstructL() |
|
161 { |
|
162 // Add the well known parameter values string table |
|
163 iStrPool.OpenL(WSPParam::Table); |
|
164 iStrPool.OpenL(WSPContentTypes::Table); |
|
165 iStrPool.OpenL(WSPRegContentTypes::Table); |
|
166 iStrPool.OpenL(WSPCharacterSets::Table); |
|
167 iStrPool.OpenL(WSPStdConstants::Table); |
|
168 iStrPool.OpenL(WSPLanguages::Table); |
|
169 iStrPool.OpenL(WSPTypeConstants::Table); |
|
170 |
|
171 // First do 2nd phase construction of the base class |
|
172 CHeaderCodec::ConstructL(); |
|
173 |
|
174 // Create the header writer and reader objects on behalf of the base class |
|
175 iWriter = CWspHeaderWriter::NewL(iStrPool, iStrTable, *this); |
|
176 iReader = CWspHeaderReader::NewL(iStrPool, iStrTable, *this); |
|
177 } |
|
178 |
|
179 CWspHeaderCodec::TWspVersion CWspHeaderCodec::GetWspVersion() const |
|
180 { |
|
181 return iWspVersion; |
|
182 } |
|
183 |
|
184 void CWspHeaderCodec::SetWspVersion(TWspVersion aWspVersion) |
|
185 { |
|
186 iWspVersion = aWspVersion; |
|
187 } |
|
188 |
|
189 TInt CWspHeaderCodec::EncodeFieldName(RStringF aFieldName) const |
|
190 { |
|
191 return (STATIC_CAST(CWspHeaderWriter*, iWriter))->EncodeFieldName(aFieldName); |
|
192 } |
|
193 |
|
194 // Implementation of Default WSP Header Codec |
|
195 //------------------------------------------------------------------------- |
|
196 |
|
197 CWspDefaultHeaderCodec* CWspDefaultHeaderCodec::NewL(RStringPool aStrPool) |
|
198 { |
|
199 CWspDefaultHeaderCodec* me = new(ELeave)CWspDefaultHeaderCodec(aStrPool); |
|
200 CleanupStack::PushL(me); |
|
201 me->ConstructL(); |
|
202 CleanupStack::Pop(me); |
|
203 return me; |
|
204 } |
|
205 |
|
206 CWspDefaultHeaderCodec::~CWspDefaultHeaderCodec() |
|
207 { |
|
208 } |
|
209 |
|
210 TBool CWspDefaultHeaderCodec::CanEncode(RStringF /*aHeaderField*/) const |
|
211 { |
|
212 // the default codec handles anything else that slips through, hence return True - it can handle the field. |
|
213 return ETrue; |
|
214 } |
|
215 |
|
216 TBool CWspDefaultHeaderCodec::CanDecode(RStringF /*aHeaderField*/) const |
|
217 { |
|
218 // the default codec handles anything else that slips through, hence return True - it can handle the field. |
|
219 return ETrue; |
|
220 } |
|
221 |
|
222 CHeaderCodec* CWspDefaultHeaderCodec::FindDelegateCodecL(RStringF /*aHeaderField*/) const |
|
223 { |
|
224 // the default codec cannot delegate, hence no delegated codec is created and return NULL |
|
225 return NULL; |
|
226 } |
|
227 |
|
228 CWspDefaultHeaderCodec::CWspDefaultHeaderCodec(RStringPool aStrPool) |
|
229 : CHeaderCodec(), iStrPool(aStrPool) |
|
230 { |
|
231 } |
|
232 |
|
233 void CWspDefaultHeaderCodec::ConstructL() |
|
234 { |
|
235 // First do 2nd phase construction of the base class |
|
236 CHeaderCodec::ConstructL(); |
|
237 |
|
238 // Create the header writer and reader objects on behalf of the base class |
|
239 iWriter = CWspDefaultHdrWriter::NewL(iStrPool); |
|
240 iReader = CWspDefaultHdrReader::NewL(iStrPool); |
|
241 } |