|
1 // Copyright (c) 2008-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 // System includes |
|
17 #include <e32std.h> |
|
18 #include <http/thttphdrval.h> |
|
19 |
|
20 // Local includes |
|
21 #include "CHeaders.h" |
|
22 #include "rhttpheaders.h" |
|
23 |
|
24 |
|
25 EXPORT_C THTTPHdrVal::THTTPHdrVal() |
|
26 { |
|
27 iType = KNoType; |
|
28 } |
|
29 |
|
30 EXPORT_C |
|
31 THTTPHdrVal::THTTPHdrVal(TInt aIntVal) |
|
32 { |
|
33 SetInt(aIntVal); |
|
34 } |
|
35 |
|
36 EXPORT_C |
|
37 THTTPHdrVal::THTTPHdrVal(RStringF aStrVal) |
|
38 { |
|
39 SetStrF(aStrVal); |
|
40 } |
|
41 EXPORT_C |
|
42 THTTPHdrVal::THTTPHdrVal(RString aStrVal) |
|
43 { |
|
44 SetStr(aStrVal); |
|
45 } |
|
46 |
|
47 EXPORT_C |
|
48 THTTPHdrVal::THTTPHdrVal(TDateTime aDateVal) |
|
49 { |
|
50 SetDateTime(aDateVal); |
|
51 } |
|
52 |
|
53 // |
|
54 // Clone this header value |
|
55 // |
|
56 |
|
57 EXPORT_C |
|
58 THTTPHdrVal THTTPHdrVal::Copy() const |
|
59 { |
|
60 THTTPHdrVal ret = *this; |
|
61 if (iType == KStrVal) |
|
62 Str().Copy(); |
|
63 if (iType == KStrFVal) |
|
64 StrF().Copy(); |
|
65 return ret; |
|
66 } |
|
67 |
|
68 |
|
69 // |
|
70 // Accessors |
|
71 // |
|
72 |
|
73 EXPORT_C |
|
74 THTTPHdrVal::THTTPValType THTTPHdrVal::Type() const |
|
75 { |
|
76 return iType; |
|
77 } |
|
78 |
|
79 EXPORT_C |
|
80 TInt THTTPHdrVal::Int() const |
|
81 { |
|
82 __ASSERT_DEBUG(iType == KTIntVal, User::Invariant());//HTTPPanic::Panic(HTTPPanic::EHeaderInvalidType)); |
|
83 return iVal; |
|
84 } |
|
85 |
|
86 EXPORT_C |
|
87 RStringF THTTPHdrVal::StrF() const |
|
88 { |
|
89 __ASSERT_DEBUG(iType == KStrFVal, User::Invariant());//HTTPPanic::Panic(HTTPPanic::EHeaderInvalidType)); |
|
90 return *reinterpret_cast<const RStringF*>(&iVal); |
|
91 } |
|
92 EXPORT_C |
|
93 RString THTTPHdrVal::Str() const |
|
94 { |
|
95 __ASSERT_DEBUG(iType == KStrVal, User::Invariant());//HTTPPanic::Panic(HTTPPanic::EHeaderInvalidType)); |
|
96 return *reinterpret_cast<const RString*>(&iVal); |
|
97 } |
|
98 |
|
99 EXPORT_C |
|
100 TDateTime THTTPHdrVal::DateTime() const |
|
101 { |
|
102 __ASSERT_DEBUG(iType == KDateVal, User::Invariant());//HTTPPanic::Panic(HTTPPanic::EHeaderInvalidType)); |
|
103 return reinterpret_cast<const TTime*>(&iVal)->DateTime(); |
|
104 } |
|
105 |
|
106 EXPORT_C |
|
107 void THTTPHdrVal::SetInt(TInt aIntVal) |
|
108 { |
|
109 iVal = aIntVal; |
|
110 iType = KTIntVal; |
|
111 } |
|
112 |
|
113 EXPORT_C |
|
114 void THTTPHdrVal::SetStr(RString aStrVal) |
|
115 { |
|
116 *reinterpret_cast<RString*>(&iVal) = aStrVal; |
|
117 iType = KStrVal; |
|
118 } |
|
119 EXPORT_C |
|
120 void THTTPHdrVal::SetStrF(RStringF aStrVal) |
|
121 { |
|
122 *reinterpret_cast<RStringF*>(&iVal) = aStrVal; |
|
123 iType = KStrFVal; |
|
124 } |
|
125 |
|
126 EXPORT_C |
|
127 void THTTPHdrVal::SetDateTime(TDateTime aDateVal) |
|
128 { |
|
129 *reinterpret_cast<TTime*>(&iVal) = aDateVal; |
|
130 iType = KDateVal; |
|
131 } |
|
132 |
|
133 EXPORT_C |
|
134 TBool THTTPHdrVal::operator==(THTTPHdrVal aVal) const |
|
135 { |
|
136 TBool ret = EFalse; |
|
137 if (aVal.iType == iType) |
|
138 { |
|
139 switch (iType) |
|
140 { |
|
141 case KTIntVal: |
|
142 ret = (aVal.iVal == iVal); |
|
143 break; |
|
144 case KStrVal: |
|
145 case KStrFVal: |
|
146 case KDateVal: |
|
147 ret = (aVal.iVal == iVal && aVal.iMoreSpace == iMoreSpace); |
|
148 break; |
|
149 default: |
|
150 User::Invariant();//HTTPPanic::Panic(HTTPPanic::EHeaderInvalidType); |
|
151 break; |
|
152 } |
|
153 } |
|
154 return ret; |
|
155 } |
|
156 |
|
157 EXPORT_C |
|
158 TBool THTTPHdrVal::operator!=(THTTPHdrVal aVal) const |
|
159 { |
|
160 return !operator==(aVal); |
|
161 } |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 EXPORT_C |
|
168 void RHTTPHeaders::SetFieldL(RStringF aFieldName, THTTPHdrVal aFieldValue) |
|
169 { |
|
170 iImplementation->SetFieldL(aFieldName, aFieldValue); |
|
171 } |
|
172 |
|
173 EXPORT_C |
|
174 void RHTTPHeaders::SetFieldL(RStringF aFieldName, THTTPHdrVal aFieldValue, |
|
175 RStringF aParamName, THTTPHdrVal aParamValue) |
|
176 { |
|
177 iImplementation->SetFieldL(aFieldName, aFieldValue, aParamName, aParamValue); |
|
178 } |
|
179 |
|
180 EXPORT_C |
|
181 void RHTTPHeaders::SetRawFieldL(RStringF aFieldName, const TDesC8& aOtaFieldData, const TDesC8& aFieldSeparator) |
|
182 { |
|
183 iImplementation->SetRawFieldL(aFieldName, aOtaFieldData, aFieldSeparator); |
|
184 } |
|
185 |
|
186 EXPORT_C |
|
187 TInt RHTTPHeaders::RemoveField(RStringF aFieldName) |
|
188 { |
|
189 return iImplementation->RemoveField(aFieldName); |
|
190 } |
|
191 |
|
192 |
|
193 EXPORT_C TInt RHTTPHeaders::RemoveFieldPart(RStringF aFieldName, TInt aIndex) |
|
194 { |
|
195 TRAPD(err,iImplementation->RemoveFieldPartL(aFieldName, aIndex)); |
|
196 return err; |
|
197 } |
|
198 |
|
199 EXPORT_C void RHTTPHeaders::RemoveAllFields() |
|
200 { |
|
201 iImplementation->RemoveAllFields(); |
|
202 } |
|
203 |
|
204 |
|
205 EXPORT_C |
|
206 TInt RHTTPHeaders::FieldPartsL(RStringF aFieldName) const |
|
207 { |
|
208 return iImplementation->FieldPartsL(aFieldName); |
|
209 } |
|
210 |
|
211 EXPORT_C TInt RHTTPHeaders::GetField(RStringF aFieldName, TInt aPartIdx, |
|
212 THTTPHdrVal& aHeaderValue) const |
|
213 { |
|
214 return iImplementation->GetField(aFieldName, aPartIdx, aHeaderValue); |
|
215 } |
|
216 |
|
217 EXPORT_C |
|
218 TInt RHTTPHeaders::GetRawField(RStringF aFieldName, TPtrC8& aRawFieldData) const |
|
219 { |
|
220 return iImplementation->GetRawField(aFieldName, aRawFieldData); |
|
221 } |
|
222 |
|
223 EXPORT_C |
|
224 TInt RHTTPHeaders::GetParam(RStringF aFieldName, RStringF aParamName, |
|
225 THTTPHdrVal& aValue, TInt aPartIdx) const |
|
226 { |
|
227 return iImplementation->GetParam(aFieldName, aParamName, aValue, aPartIdx); |
|
228 } |
|
229 |
|
230 EXPORT_C void RHTTPHeaders::SetParamL(RStringF aFieldName, RStringF aParamName, |
|
231 THTTPHdrVal aParamValue, TInt aPartIdx) |
|
232 { |
|
233 iImplementation->SetParamL(aFieldName, aParamName, aParamValue, aPartIdx); |
|
234 } |
|
235 |
|
236 EXPORT_C |
|
237 THTTPHdrFieldIter RHTTPHeaders::Fields() const |
|
238 { |
|
239 return iImplementation->Fields(); |
|
240 } |
|
241 |
|
242 |
|
243 |
|
244 EXPORT_C |
|
245 THTTPHdrFieldIter::~THTTPHdrFieldIter() |
|
246 { |
|
247 // does nothing |
|
248 } |
|
249 |
|
250 EXPORT_C |
|
251 void THTTPHdrFieldIter::First() |
|
252 { |
|
253 // Check existence of the field name array in CHeaders. If it hasn't been created yet |
|
254 // then we must start off 'at the end'. This is indicated by the position index set |
|
255 // to KErrNotFound |
|
256 iPosIdx = 0; |
|
257 CheckInvalidation(); |
|
258 } |
|
259 |
|
260 EXPORT_C |
|
261 TBool THTTPHdrFieldIter::AtEnd() const |
|
262 { |
|
263 return (iPosIdx == KErrNotFound); |
|
264 } |
|
265 |
|
266 EXPORT_C |
|
267 void THTTPHdrFieldIter::operator++() |
|
268 { |
|
269 // Do nothing if we're already at the end |
|
270 if (iPosIdx >= 0) |
|
271 { |
|
272 ++iPosIdx; |
|
273 CheckInvalidation(); |
|
274 } |
|
275 } |
|
276 |
|
277 EXPORT_C |
|
278 RStringTokenF THTTPHdrFieldIter::operator()() |
|
279 { |
|
280 CheckInvalidation(); |
|
281 if (iPosIdx > KErrNotFound) |
|
282 return iHeaders->iFields[iPosIdx].iFieldName; |
|
283 else |
|
284 return RStringF(); |
|
285 } |
|
286 |
|
287 void THTTPHdrFieldIter::CheckInvalidation() |
|
288 { |
|
289 // iPosIdx may have been valid after the last use of operator() but |
|
290 // if an item was subsequently removed from the collection the iterator |
|
291 // may have gone off the end. |
|
292 if (iPosIdx >= iHeaders->iFields.Count()) |
|
293 iPosIdx = KErrNotFound; // Hit the end |
|
294 } |
|
295 |