|
1 // Copyright (c) 2003-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 @file |
|
18 @internalComponent |
|
19 */ |
|
20 |
|
21 #include <obexheaders.h> |
|
22 #include "OBEXUTIL.H" |
|
23 #include "logger.h" |
|
24 |
|
25 #ifdef __FLOG_ACTIVE |
|
26 _LIT8(KLogComponent, "OBEX"); |
|
27 #endif |
|
28 |
|
29 /** |
|
30 Called in response to First() being called on the iterator object. |
|
31 The default implementation does nothing---some implementations may |
|
32 wish to reset state variables. |
|
33 |
|
34 @publishedAll |
|
35 @released |
|
36 */ |
|
37 EXPORT_C void MObexHeaderCheck::Reset() |
|
38 { |
|
39 LOG_LINE |
|
40 LOG_FUNC |
|
41 } |
|
42 |
|
43 /** |
|
44 This virtual function allows the M- classes to be extended in future in a binary |
|
45 compatible way by providing a method that clients can override in future to |
|
46 allow extra callbacks to be made via aObject. |
|
47 */ |
|
48 EXPORT_C void MObexHeaderCheck::MOHC_ExtensionInterfaceL(TUid /*aInterface*/, void*& aObject) |
|
49 { |
|
50 aObject = NULL; |
|
51 } |
|
52 |
|
53 /** |
|
54 @return ETrue if this header is the requested one. |
|
55 |
|
56 @publishedAll |
|
57 @released |
|
58 */ |
|
59 EXPORT_C TBool TObexMatchHeader::Interested(TUint8 aHI) |
|
60 { |
|
61 LOG_LINE |
|
62 LOG_FUNC |
|
63 |
|
64 return (aHI == iHI); |
|
65 } |
|
66 |
|
67 /** |
|
68 Sets the header identifier required. |
|
69 @code : iHI = aHI; |
|
70 @publishedAll |
|
71 @released |
|
72 */ |
|
73 EXPORT_C void TObexMatchHeader::SetHeader(TUint8 aHI) |
|
74 { |
|
75 LOG_LINE |
|
76 LOG_FUNC |
|
77 |
|
78 iHI = aHI; |
|
79 } |
|
80 |
|
81 /** |
|
82 @return ETrue if this header is of the requested type. |
|
83 @publishedAll |
|
84 @released |
|
85 */ |
|
86 EXPORT_C TBool TObexMatchHeaderType::Interested(TUint8 aHI) |
|
87 { |
|
88 LOG_LINE |
|
89 LOG_FUNC |
|
90 |
|
91 return (ObexHeaderType(aHI) == iType); |
|
92 } |
|
93 |
|
94 /** |
|
95 Set the header type required. |
|
96 @code : iType = aType; |
|
97 @publishedAll |
|
98 @released |
|
99 */ |
|
100 EXPORT_C void TObexMatchHeaderType::SetType(CObexHeader::THeaderType aType) |
|
101 { |
|
102 LOG_LINE |
|
103 LOG_FUNC |
|
104 |
|
105 iType = aType; |
|
106 } |
|
107 |
|
108 /** |
|
109 Creates an empty CObexHeaderSet object. |
|
110 @publishedAll |
|
111 @released |
|
112 */ |
|
113 EXPORT_C CObexHeaderSet* CObexHeaderSet::NewL() |
|
114 { |
|
115 LOG_LINE |
|
116 LOG_STATIC_FUNC_ENTRY |
|
117 |
|
118 CObexHeaderSet* self = new(ELeave) CObexHeaderSet(); |
|
119 return self; |
|
120 } |
|
121 |
|
122 /** |
|
123 Copies an existing CObexHeaderSet to populate a new object. |
|
124 @return A new CObexHeaderSet object populated with the headers. |
|
125 This method returns ownership of the new object. |
|
126 @publishedAll |
|
127 @released |
|
128 */ |
|
129 EXPORT_C CObexHeaderSet* CObexHeaderSet::CopyL() |
|
130 { |
|
131 LOG_LINE |
|
132 LOG_FUNC |
|
133 |
|
134 CObexHeaderSet* newHeaderSet = new(ELeave) CObexHeaderSet(); |
|
135 CleanupStack::PushL(newHeaderSet); |
|
136 |
|
137 TInt maxHeader = iHeaders.Count(); |
|
138 for (TInt pos = 0; pos < maxHeader; pos++) |
|
139 { |
|
140 CObexHeader* newHeader = iHeaders[pos]->CopyL(); |
|
141 CleanupStack::PushL(newHeader); |
|
142 LEAVEIFERRORL(newHeaderSet->iHeaders.Append(newHeader)); |
|
143 CleanupStack::Pop(newHeader); |
|
144 } |
|
145 |
|
146 CleanupStack::Pop(newHeaderSet); |
|
147 return newHeaderSet; |
|
148 } |
|
149 |
|
150 /** |
|
151 Copies interesting headers from an existing CObexHeaderSet to populate a new object. |
|
152 @param aHeaderCheck The object to use to filter headers of interest. |
|
153 @return A new CObexHeaderSet object with the desired headers. |
|
154 This method returns ownership of the new object. |
|
155 @publishedAll |
|
156 @released |
|
157 */ |
|
158 EXPORT_C CObexHeaderSet* CObexHeaderSet::CopyL(MObexHeaderCheck& aHeaderCheck) |
|
159 { |
|
160 LOG_LINE |
|
161 LOG_FUNC |
|
162 |
|
163 CObexHeaderSet* newHeaderSet = new(ELeave) CObexHeaderSet(); |
|
164 CleanupStack::PushL(newHeaderSet); |
|
165 |
|
166 aHeaderCheck.Reset(); |
|
167 |
|
168 TInt maxHeader = iHeaders.Count(); |
|
169 for (TInt pos = 0; pos < maxHeader; pos++) |
|
170 { |
|
171 CObexHeader* header = iHeaders[pos]; |
|
172 |
|
173 if (aHeaderCheck.Interested(header->HI())) |
|
174 { |
|
175 CObexHeader* newHeader = header->CopyL(); |
|
176 CleanupStack::PushL(newHeader); |
|
177 LEAVEIFERRORL(newHeaderSet->iHeaders.Append(newHeader)); |
|
178 CleanupStack::Pop(newHeader); |
|
179 } |
|
180 } |
|
181 |
|
182 CleanupStack::Pop(newHeaderSet); |
|
183 return newHeaderSet; |
|
184 } |
|
185 |
|
186 /** |
|
187 Constructor |
|
188 */ |
|
189 CObexHeaderSet::CObexHeaderSet() |
|
190 { |
|
191 } |
|
192 |
|
193 /** |
|
194 Destructor |
|
195 This method deletes each individual item that the pointer array |
|
196 points at. |
|
197 |
|
198 @internalComponent |
|
199 */ |
|
200 CObexHeaderSet::~CObexHeaderSet() |
|
201 { |
|
202 iHeaders.ResetAndDestroy(); |
|
203 } |
|
204 |
|
205 /** |
|
206 Adds a header to the set. |
|
207 @param aHeader pointer to the header to be added. Ownership is transferred on a |
|
208 successful addition. |
|
209 @return A standard error code giving the results of the insertion. |
|
210 |
|
211 @publishedAll |
|
212 @released |
|
213 */ |
|
214 EXPORT_C TInt CObexHeaderSet::AddHeader(CObexHeader* aHeader) |
|
215 { |
|
216 LOG_LINE |
|
217 LOG_FUNC |
|
218 |
|
219 TInt ret = iHeaders.Append(aHeader); |
|
220 |
|
221 return ret; |
|
222 } |
|
223 |
|
224 /** |
|
225 Deletes the current header from the headerset. |
|
226 |
|
227 @publishedAll |
|
228 @released |
|
229 */ |
|
230 EXPORT_C void CObexHeaderSet::DeleteCurrentHeader() |
|
231 { |
|
232 LOG_LINE |
|
233 LOG_FUNC |
|
234 |
|
235 if ((iPos >= 0) && (iPos < iHeaders.Count())) |
|
236 { |
|
237 delete iHeaders[iPos]; |
|
238 iHeaders.Remove(iPos); |
|
239 } |
|
240 |
|
241 First(); |
|
242 } |
|
243 |
|
244 /** |
|
245 Sets a header mask. Functions will only return values which the |
|
246 mask claims are interesting. The only 'accessor' functions which |
|
247 ignore this mask are the NewL overloads which copy an existing |
|
248 header set. |
|
249 |
|
250 The object defaults to a mask where all headers are considered |
|
251 interesting. Passing in a null parameter reverts to this behaviour. |
|
252 |
|
253 @param aMask The mask to use. |
|
254 @publishedAll |
|
255 @released |
|
256 */ |
|
257 EXPORT_C void CObexHeaderSet::SetMask(MObexHeaderCheck* aMask) |
|
258 { |
|
259 LOG_LINE |
|
260 LOG_FUNC |
|
261 |
|
262 iMask = aMask; |
|
263 First(); |
|
264 } |
|
265 |
|
266 /** |
|
267 Removes from this header set any headers which the mask claims are |
|
268 not interesting. The position of the iterator is reset to the first |
|
269 remaining header. |
|
270 The mask will get reset to zero at the end of this method. |
|
271 |
|
272 @publishedAll |
|
273 @released |
|
274 */ |
|
275 EXPORT_C void CObexHeaderSet::DeleteMasked() |
|
276 { |
|
277 LOG_LINE |
|
278 LOG_FUNC |
|
279 |
|
280 First(); |
|
281 |
|
282 if (!iMask) |
|
283 { |
|
284 return; |
|
285 } |
|
286 |
|
287 TInt count = iHeaders.Count(); |
|
288 for (TInt pos = 0; pos < count; /*no iterative step*/) |
|
289 { |
|
290 TUint8 hi = iHeaders[pos]->HI(); |
|
291 if (!iMask->Interested(hi)) |
|
292 { |
|
293 delete iHeaders[pos]; |
|
294 iHeaders.Remove(pos); |
|
295 //do not increment pos as old [pos+1] element is now stored in [pos] |
|
296 count--; |
|
297 } |
|
298 else |
|
299 { |
|
300 pos++; |
|
301 } |
|
302 } |
|
303 |
|
304 iMask = 0; |
|
305 |
|
306 First(); |
|
307 } |
|
308 |
|
309 /** |
|
310 Resets the mask, then advances the iterator to the first interesting header. |
|
311 |
|
312 @publishedAll |
|
313 @released |
|
314 */ |
|
315 EXPORT_C void CObexHeaderSet::First() const |
|
316 { |
|
317 LOG_LINE |
|
318 LOG_FUNC |
|
319 |
|
320 iPos = 0; |
|
321 |
|
322 if (iMask) |
|
323 { |
|
324 iMask->Reset(); |
|
325 } |
|
326 |
|
327 if (Next(0) == KErrNotFound) |
|
328 { |
|
329 iPos = -1; |
|
330 } |
|
331 } |
|
332 |
|
333 /** |
|
334 Links the supplied header to the same underlying header that is used by the |
|
335 iterator's current header. |
|
336 @param aHeader The header object to populate. |
|
337 @return KErrNotFound if the iterator is not currently pointing to a valid |
|
338 header. |
|
339 @publishedAll |
|
340 @released |
|
341 */ |
|
342 EXPORT_C TInt CObexHeaderSet::This(CObexHeader* aHeader) const |
|
343 { |
|
344 LOG_LINE |
|
345 LOG_FUNC |
|
346 |
|
347 if (iPos < 0) |
|
348 { |
|
349 return KErrNotFound; |
|
350 } |
|
351 |
|
352 aHeader->Set(iHeaders[iPos]); |
|
353 return KErrNone; |
|
354 } |
|
355 |
|
356 /** |
|
357 Advances the iterator to the next interesting header, skipping over the current header before |
|
358 starting to search. |
|
359 @return KErrNotFound if there are no more interesting headers in the set. |
|
360 @publishedAll |
|
361 @released |
|
362 */ |
|
363 EXPORT_C TInt CObexHeaderSet::Next() const |
|
364 { |
|
365 return Next(1); |
|
366 } |
|
367 |
|
368 /** |
|
369 Advances the iterator to the next interesting header, skipping over aSkip headers before |
|
370 starting to search. |
|
371 @param aSkip The minimum number of headers to move on from the current position, |
|
372 independant of whether a mask has been set or not. |
|
373 A value of zero therefore makes Next() essentially a no-op but presents the current |
|
374 header to the header filter again. |
|
375 @return KErrNotFound if there are no more interesting headers in the set. |
|
376 @publishedAll |
|
377 @released |
|
378 */ |
|
379 EXPORT_C TInt CObexHeaderSet::Next(TInt aSkip) const |
|
380 { |
|
381 // Don't log this function as it's too verbose. |
|
382 //LOG_LINE |
|
383 //LOG_FUNC |
|
384 |
|
385 iPos += aSkip; |
|
386 TInt count = iHeaders.Count(); |
|
387 |
|
388 if (iMask) |
|
389 { |
|
390 for (; iPos < count; iPos++) |
|
391 { |
|
392 TUint8 hi = iHeaders[iPos]->HI(); |
|
393 if (iMask->Interested(hi)) |
|
394 break; |
|
395 } |
|
396 } |
|
397 |
|
398 if (iPos >= count) |
|
399 { |
|
400 iPos = -1; |
|
401 } |
|
402 |
|
403 return (iPos < 0) ? KErrNotFound : KErrNone; |
|
404 } |
|
405 |
|
406 /** |
|
407 Returns the total number of headers in this set, ie. ignores the mask. |
|
408 @return Count of the total number of headers (masked and unmasked) in this set. |
|
409 @released |
|
410 */ |
|
411 EXPORT_C TInt CObexHeaderSet::Count() const |
|
412 { |
|
413 LOG_LINE |
|
414 LOG_FUNC |
|
415 |
|
416 return iHeaders.Count(); |
|
417 } |
|
418 |
|
419 /** |
|
420 Returns the first instance of the header with the required HI value |
|
421 by inserting it into the supplied CObexHeader object. This uses the |
|
422 standard iterator functionality, so is limited by the current mask, and |
|
423 starts from the current iterator position. |
|
424 @param aHI The header to search for. Consult the Obex specification for values. |
|
425 @param aHeader The header object to populate. |
|
426 @return KErrNotFound if the header was not present. |
|
427 */ |
|
428 EXPORT_C TInt CObexHeaderSet::Find(TUint8 aHI, CObexHeader& aHeader) const |
|
429 { |
|
430 LOG_LINE |
|
431 LOG_FUNC |
|
432 |
|
433 if (iPos >= iHeaders.Count()) |
|
434 { |
|
435 // Already searched all available headers |
|
436 return KErrNotFound; |
|
437 } |
|
438 |
|
439 if (iPos >= 0) |
|
440 { |
|
441 TUint8 hi = iHeaders[iPos]->HI(); |
|
442 TInt err = KErrNone; |
|
443 while ((err == KErrNone) && |
|
444 (hi != aHI)) |
|
445 { |
|
446 err = Next(); |
|
447 if (err == KErrNone) |
|
448 { |
|
449 hi = iHeaders[iPos]->HI(); |
|
450 } |
|
451 } |
|
452 |
|
453 if (hi == aHI) |
|
454 { |
|
455 aHeader.Set(iHeaders[iPos]); |
|
456 return KErrNone; |
|
457 } |
|
458 else |
|
459 { |
|
460 return KErrNotFound; |
|
461 } |
|
462 } |
|
463 else |
|
464 { |
|
465 return KErrNotFound; |
|
466 } |
|
467 } |