|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: implementation of class CCookie |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 // System includes |
|
22 #include <httpstringconstants.h> |
|
23 #include <http/rhttpheaders.h> |
|
24 #include <http/rhttpsession.h> |
|
25 #include <Uri8.h> |
|
26 |
|
27 // User includes |
|
28 #include "cookie.h" |
|
29 #include "CookieCommonConstants.h" |
|
30 |
|
31 |
|
32 const TUint8 KDayOfWeekSeparator = ','; |
|
33 // const TUint8 KTimeSeparator = ':'; |
|
34 |
|
35 _LIT8 ( KUT, "UT" ); |
|
36 _LIT8 ( KGMT, "GMT" ); |
|
37 _LIT8 ( KEST, "EST" ); |
|
38 _LIT8 ( KEDT, "EDT" ); |
|
39 _LIT8 ( KCST, "CST" ); |
|
40 _LIT8 ( KCDT, "CDT" ); |
|
41 _LIT8 ( KMST, "MST" ); |
|
42 _LIT8 ( KMDT, "MDT" ); |
|
43 _LIT8 ( KPST, "PST" ); |
|
44 _LIT8 ( KPDT, "PDT" ); |
|
45 |
|
46 const TUint8 KLocalTimeZoneSeparator1 = '+'; |
|
47 const TUint8 KLocalTimeZoneSeparator2 = '-'; |
|
48 |
|
49 const TInt KDateTokenCount = 3; |
|
50 const TInt KTimeTokenCount = 3; |
|
51 const TInt KAsciiTokenCount = 4; |
|
52 |
|
53 _LIT8( KLocalSeparators, " -"); |
|
54 _LIT8( KLocalTimeSeparator, ":"); |
|
55 |
|
56 _LIT8( KLocalMonthNames, "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec" ); |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CCookie::NewL |
|
63 // --------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CCookie* CCookie::NewL( RHTTPHeaders aRequestHeaders, TInt aPartIndex, |
|
66 RStringF aFieldName, RStringPool aStringPool, |
|
67 const TUriC8& aUri ) |
|
68 { |
|
69 CCookie* self = new (ELeave) CCookie( aStringPool ); |
|
70 |
|
71 CleanupStack::PushL( self ); |
|
72 |
|
73 self->ConstructL( aRequestHeaders, aPartIndex, aFieldName, aUri ); |
|
74 |
|
75 CleanupStack::Pop(); // self |
|
76 |
|
77 return self; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CCookie::NewL |
|
83 // --------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C CCookie* CCookie::NewL( RStringPool aStringPool ) |
|
86 { |
|
87 return new (ELeave) CCookie( aStringPool ); |
|
88 } |
|
89 |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CCookie::~CCookie |
|
93 // --------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CCookie::~CCookie() |
|
96 { |
|
97 // go through each attribute closing any attribute strings |
|
98 TInt numAttributes = iAttributes.Count(); |
|
99 for ( TInt ii = 0; ii < numAttributes; ++ii ) |
|
100 { |
|
101 iAttributes[ii].Close(); |
|
102 } |
|
103 |
|
104 iAttributes.Close(); |
|
105 } |
|
106 |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CCookie::AddDefaultPathL |
|
110 // --------------------------------------------------------- |
|
111 // |
|
112 void CCookie::AddDefaultPathL( const TUriC8& aUri ) |
|
113 { |
|
114 // RFC2965 : Defaults to the path of the request URL that generated the |
|
115 // Set-Cookie2 response, up to and including the right-most /. |
|
116 // Note : there is a contradiction as we must not include the right-most / |
|
117 // per RFC2109, which is obsolete. Decision : we support RFC2965. |
|
118 const TUint8 KCookiePathSeparator = '/'; |
|
119 TPtrC8 requestPath; |
|
120 if ( aUri.IsPresent( EUriPath ) ) |
|
121 { |
|
122 requestPath.Set( aUri.Extract( EUriPath ) ); |
|
123 |
|
124 TInt sepPos = requestPath.LocateReverse( KCookiePathSeparator ); |
|
125 // if / is not the last character |
|
126 if ( 0 <= sepPos && ( ( sepPos + 1 != requestPath.Length() ) ) ) |
|
127 { |
|
128 // then remove characters after the right-most / |
|
129 requestPath.Set( requestPath.Left( sepPos + 1 ) ); |
|
130 } |
|
131 } |
|
132 else |
|
133 { |
|
134 requestPath.Set( &KCookiePathSeparator, |
|
135 sizeof( KCookiePathSeparator ) ); |
|
136 } |
|
137 |
|
138 RStringF defPath = iStringPool.OpenFStringL( requestPath ); |
|
139 THTTPHdrVal defPathVal( defPath ); |
|
140 SetAttribute( EPath, defPathVal, ETrue );// ignore the result |
|
141 defPath.Close(); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CCookie::AddToRequestL |
|
146 // --------------------------------------------------------- |
|
147 // |
|
148 EXPORT_C void CCookie::AddToRequestL( RHTTPHeaders aRequestHeaders, |
|
149 TInt aPartIndex ) const |
|
150 { |
|
151 const TStringTable& commonStringTable = RHTTPSession::GetTable(); |
|
152 |
|
153 // We're writing out the "Cookie:" string |
|
154 RStringF cookieString = |
|
155 iStringPool.StringF( HTTP::ECookie, commonStringTable ); |
|
156 aRequestHeaders.SetFieldL( cookieString, THTTPHdrVal() ); |
|
157 |
|
158 THTTPHdrVal hVal; |
|
159 |
|
160 // We're writing out the Version attribute - it is a serious error if this |
|
161 // attribute is missing |
|
162 if ( Attribute( CCookie::EVersion, hVal ) == KErrNone ) |
|
163 { |
|
164 aRequestHeaders.SetParamL( cookieString, |
|
165 iStringPool.StringF( HTTP::EVersion, |
|
166 commonStringTable ), |
|
167 hVal, |
|
168 aPartIndex ); |
|
169 } |
|
170 else |
|
171 { |
|
172 if ( iSetCookie2 ) |
|
173 { |
|
174 // if this is a new-style cookie (it is from a Set-Cookie2 header), |
|
175 // then it must have a Version attribute. |
|
176 // TBD : or should we insert a '$Version=1' string instead? |
|
177 User::Leave( KErrCorrupt ); |
|
178 } |
|
179 } |
|
180 |
|
181 // We're writing out the NAME attribute - it is a serious error if this |
|
182 // attribute is missing |
|
183 User::LeaveIfError( Attribute( CCookie::EName, hVal ) ); |
|
184 aRequestHeaders.SetParamL( cookieString, |
|
185 iStringPool.StringF( HTTP::ECookieName, |
|
186 commonStringTable ), |
|
187 hVal, |
|
188 aPartIndex ); |
|
189 |
|
190 // We're writing out the VALUE attribute - it is a serious error if this |
|
191 // attribute is missing |
|
192 User::LeaveIfError( Attribute( CCookie::EValue, hVal ) ); |
|
193 aRequestHeaders.SetParamL( cookieString, |
|
194 iStringPool.StringF( HTTP::ECookieValue, |
|
195 commonStringTable ), |
|
196 hVal, |
|
197 aPartIndex ); |
|
198 |
|
199 // Writing out the rest : domain, path and port. These are not mandatory, |
|
200 // thus we do not leave if they are missing. |
|
201 // Writing out Domain attribute |
|
202 if ( Attribute( CCookie::EDomain, hVal ) == KErrNone && hVal.StrF().DesC().Length() > 0 ) |
|
203 { |
|
204 aRequestHeaders.SetParamL( cookieString, |
|
205 iStringPool.StringF( HTTP::EDomain, |
|
206 commonStringTable ), |
|
207 hVal, |
|
208 aPartIndex ); |
|
209 } |
|
210 |
|
211 // Writing out Path attribute |
|
212 if ( Attribute( CCookie::EPath, hVal ) == KErrNone ) |
|
213 { |
|
214 aRequestHeaders.SetParamL( cookieString, |
|
215 iStringPool.StringF( HTTP::EPath, |
|
216 commonStringTable ), |
|
217 hVal, |
|
218 aPartIndex ); |
|
219 } |
|
220 |
|
221 // Writing out Port attribute |
|
222 if ( Attribute( CCookie::EPort, hVal ) == KErrNone ) |
|
223 { |
|
224 aRequestHeaders.SetParamL( cookieString, |
|
225 iStringPool.StringF( HTTP::ECookiePort, |
|
226 commonStringTable ), |
|
227 hVal, |
|
228 aPartIndex ); |
|
229 } |
|
230 } |
|
231 |
|
232 |
|
233 // --------------------------------------------------------- |
|
234 // CCookie::Attribute |
|
235 // --------------------------------------------------------- |
|
236 // |
|
237 EXPORT_C TInt CCookie::Attribute |
|
238 ( CCookie::TCookieAttributeName aAttributeName, |
|
239 THTTPHdrVal& aAttributeVal) const |
|
240 { |
|
241 TCookieAttribute attribute; |
|
242 if ( FindAttribute( aAttributeName, attribute ) != KErrNotFound ) |
|
243 { |
|
244 aAttributeVal = attribute.Value(); |
|
245 return KErrNone; |
|
246 } |
|
247 |
|
248 return KErrNotFound; |
|
249 } |
|
250 |
|
251 |
|
252 // --------------------------------------------------------- |
|
253 // CCookie::SetAttribute |
|
254 // --------------------------------------------------------- |
|
255 // |
|
256 EXPORT_C TInt CCookie::SetAttribute |
|
257 ( CCookie::TCookieAttributeName aAttributeName, |
|
258 const THTTPHdrVal& aAttributeVal ) |
|
259 { |
|
260 return SetAttribute( aAttributeName, aAttributeVal, EFalse ); |
|
261 } |
|
262 |
|
263 |
|
264 |
|
265 // --------------------------------------------------------- |
|
266 // CCookie::Attribute |
|
267 // --------------------------------------------------------- |
|
268 // |
|
269 TInt CCookie::Attribute( TCookieAttributeName aAttributeName, |
|
270 THTTPHdrVal& aAttributeVal, |
|
271 TBool& aDefaulted ) const |
|
272 { |
|
273 TCookieAttribute attribute; |
|
274 if ( FindAttribute( aAttributeName, attribute ) != KErrNotFound ) |
|
275 { |
|
276 aAttributeVal = attribute.Value(); |
|
277 aDefaulted = attribute.Defaulted(); |
|
278 return KErrNone; |
|
279 } |
|
280 |
|
281 return KErrNotFound; |
|
282 } |
|
283 |
|
284 |
|
285 // --------------------------------------------------------- |
|
286 // CCookie::SetAttribute |
|
287 // --------------------------------------------------------- |
|
288 // |
|
289 TInt CCookie::SetAttribute( TCookieAttributeName aAttributeName, |
|
290 const THTTPHdrVal& aAttributeVal, |
|
291 TBool aDefaulted ) |
|
292 { |
|
293 TInt result( KErrNone ); |
|
294 |
|
295 TCookieAttribute attribute; |
|
296 TInt index = FindAttribute( aAttributeName, attribute ); |
|
297 if ( index != KErrNotFound ) |
|
298 { |
|
299 result = KErrAlreadyExists; |
|
300 } |
|
301 else |
|
302 { |
|
303 TCookieAttribute newAttribute( aAttributeName, |
|
304 aAttributeVal, aDefaulted ); |
|
305 |
|
306 result = iAttributes.Append( newAttribute ); |
|
307 if ( result == KErrNone ) |
|
308 { |
|
309 iSize += ( KCookieAttributePrefixLength + newAttribute.Size() + |
|
310 KCookieAttributeDefaultedLength + |
|
311 KCookieAttributeFoundLength ); |
|
312 } |
|
313 else |
|
314 { |
|
315 newAttribute.Close(); |
|
316 } |
|
317 } |
|
318 return result; |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------- |
|
322 // CCookie::CopyFromL |
|
323 // --------------------------------------------------------- |
|
324 // |
|
325 void CCookie::CopyFromL( const CCookie& aCopyFrom ) |
|
326 { |
|
327 THTTPHdrVal attributevalue; |
|
328 TBool aDefaulted( EFalse ); |
|
329 |
|
330 if ( aCopyFrom.Attribute( EName, attributevalue, aDefaulted ) != KErrNotFound ) |
|
331 { |
|
332 SetAttribute( EName, attributevalue, aDefaulted ); |
|
333 } |
|
334 |
|
335 if ( aCopyFrom.Attribute( EValue, attributevalue, aDefaulted ) != KErrNotFound ) |
|
336 { |
|
337 SetAttribute( EValue, attributevalue, aDefaulted ); |
|
338 } |
|
339 |
|
340 if ( aCopyFrom.Attribute( EComment, attributevalue, aDefaulted ) != KErrNotFound ) |
|
341 { |
|
342 SetAttribute( EComment, attributevalue, aDefaulted ); |
|
343 } |
|
344 |
|
345 if ( aCopyFrom.Attribute( ECommentURI, attributevalue, aDefaulted ) != KErrNotFound ) |
|
346 { |
|
347 SetAttribute( ECommentURI, attributevalue, aDefaulted ); |
|
348 } |
|
349 |
|
350 if ( aCopyFrom.Attribute( EDiscard, attributevalue, aDefaulted ) != KErrNotFound ) |
|
351 { |
|
352 SetAttribute( EDiscard, attributevalue, aDefaulted ); |
|
353 } |
|
354 |
|
355 if ( aCopyFrom.Attribute( EDomain, attributevalue, aDefaulted ) != KErrNotFound ) |
|
356 { |
|
357 SetAttribute( EDomain, attributevalue, aDefaulted ); |
|
358 } |
|
359 |
|
360 if ( aCopyFrom.Attribute( EMaxAge, attributevalue, aDefaulted ) != KErrNotFound ) |
|
361 { |
|
362 SetAttribute( EMaxAge, attributevalue, aDefaulted ); |
|
363 } |
|
364 |
|
365 if ( aCopyFrom.Attribute( EPath, attributevalue, aDefaulted ) != KErrNotFound ) |
|
366 { |
|
367 SetAttribute( EPath, attributevalue, aDefaulted ); |
|
368 } |
|
369 |
|
370 if ( aCopyFrom.Attribute( EPort, attributevalue, aDefaulted ) != KErrNotFound ) |
|
371 { |
|
372 SetAttribute( EPort, attributevalue, aDefaulted ); |
|
373 } |
|
374 |
|
375 if ( aCopyFrom.Attribute( ESecure, attributevalue, aDefaulted ) != KErrNotFound ) |
|
376 { |
|
377 SetAttribute( ESecure, attributevalue, aDefaulted ); |
|
378 } |
|
379 |
|
380 if ( aCopyFrom.Attribute( EVersion, attributevalue, aDefaulted ) != KErrNotFound ) |
|
381 { |
|
382 SetAttribute( EVersion, attributevalue, aDefaulted ); |
|
383 } |
|
384 |
|
385 if ( aCopyFrom.Attribute( EExpires, attributevalue, aDefaulted ) != KErrNotFound ) |
|
386 { |
|
387 SetAttribute( EExpires, attributevalue, aDefaulted ); |
|
388 } |
|
389 |
|
390 SetCookie2( aCopyFrom.FromCookie2() ); |
|
391 |
|
392 } |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 // --------------------------------------------------------- |
|
398 // CCookie::StringPool |
|
399 // --------------------------------------------------------- |
|
400 // |
|
401 RStringPool CCookie::StringPool() |
|
402 { |
|
403 return iStringPool; |
|
404 } |
|
405 |
|
406 |
|
407 |
|
408 // --------------------------------------------------------- |
|
409 // CCookie::Expired |
|
410 // --------------------------------------------------------- |
|
411 // |
|
412 TBool CCookie::Expired() const |
|
413 { |
|
414 // the cookie has expired if: |
|
415 // 1. it's Age > Max-Age |
|
416 // 2. current_date > expires |
|
417 // Expires is in Netscape cookie only !!! |
|
418 |
|
419 TBool retval( EFalse ); |
|
420 THTTPHdrVal attrVal; |
|
421 TInt err( KErrNone ); |
|
422 |
|
423 if ( FromNetscapeVersion() && ( Attribute( CCookie::EExpires, attrVal ) == KErrNone )) |
|
424 { |
|
425 if ( attrVal.Type() == THTTPHdrVal::KDateVal ) |
|
426 { |
|
427 TDateTime expires; |
|
428 expires = attrVal.DateTime(); |
|
429 TTime Expirytime( expires ); |
|
430 TTime NowTime; |
|
431 NowTime.UniversalTime(); |
|
432 if ( Expirytime <= NowTime ) |
|
433 { // EXPIRED !!!! |
|
434 retval = ETrue; |
|
435 } |
|
436 } |
|
437 else |
|
438 { |
|
439 if ( attrVal.Type() == THTTPHdrVal::KStrFVal ) |
|
440 { |
|
441 TRAP_IGNORE( retval = ExpiredNetscapeL( attrVal ) ); |
|
442 // The only real error is KErrNoMemory, |
|
443 // so we simply ignore the error here |
|
444 } |
|
445 } |
|
446 } |
|
447 else |
|
448 { |
|
449 if ( Attribute( CCookie::EMaxAge, attrVal ) == KErrNone ) |
|
450 { |
|
451 TInt MaxAge(0); |
|
452 if ( attrVal.Type() == THTTPHdrVal::KTIntVal ) |
|
453 { |
|
454 MaxAge = attrVal.Int(); |
|
455 } |
|
456 else |
|
457 { |
|
458 TPtrC8 MaxAgePtr=CCookie::RemoveQuotes( attrVal.StrF().DesC() ); |
|
459 TLex8 lex( MaxAgePtr ); |
|
460 err = lex.Val( MaxAge ); |
|
461 } |
|
462 if ( err == KErrNone ) |
|
463 { |
|
464 // it's Age > Max-Age? |
|
465 // Age = ( now_time - EDate ) |
|
466 // TTime.SecondsFrom(TTime) |
|
467 // UniversalTime.SecondsFrom( EDate_time ): real age |
|
468 TTime NowTime; |
|
469 NowTime.UniversalTime(); |
|
470 TTimeIntervalSeconds CurrAgeInterval; |
|
471 err = NowTime.SecondsFrom( iReceivedTime, CurrAgeInterval ); |
|
472 // now compare to specified Max-Age |
|
473 if ( MaxAge <= CurrAgeInterval.Int() ) |
|
474 { // EXPIRED !!!! |
|
475 retval = ETrue; |
|
476 } |
|
477 |
|
478 |
|
479 } |
|
480 } |
|
481 } |
|
482 return retval; |
|
483 } |
|
484 // --------------------------------------------------------- |
|
485 // CCookie::RemoveQuotes |
|
486 // --------------------------------------------------------- |
|
487 // |
|
488 TPtrC8 CCookie::RemoveQuotes( const TDesC8& aDes ) |
|
489 { |
|
490 |
|
491 TInt firstChar = 0; // position of the first character |
|
492 TInt lastChar = aDes.Length() - 1; // position of the last character |
|
493 TPtrC8 result; |
|
494 if ( lastChar < 0 ) // that is, aDes has a length of zero |
|
495 { |
|
496 result.Set( aDes ); // the result is the same |
|
497 } |
|
498 else |
|
499 { |
|
500 TUint8 quotationMark = '"'; |
|
501 |
|
502 if ( aDes[ firstChar ] == quotationMark ) |
|
503 { |
|
504 firstChar++; |
|
505 } |
|
506 |
|
507 if ( aDes[ lastChar ] == quotationMark ) |
|
508 { |
|
509 lastChar--; |
|
510 } |
|
511 |
|
512 if ( lastChar < firstChar ) |
|
513 { |
|
514 result.Set( KNullDesC8() ); |
|
515 } |
|
516 else |
|
517 { |
|
518 result.Set( aDes.Mid( firstChar, lastChar - firstChar + 1 ) ); |
|
519 } |
|
520 } |
|
521 |
|
522 return result; |
|
523 } |
|
524 |
|
525 |
|
526 |
|
527 // --------------------------------------------------------- |
|
528 // CCookie::ExpiredNetscapeL |
|
529 // --------------------------------------------------------- |
|
530 // |
|
531 TBool CCookie::ExpiredNetscapeL( THTTPHdrVal aAttrVal) const |
|
532 { |
|
533 TBool retval( EFalse ); |
|
534 TPtrC8 datePtr8( aAttrVal.StrF().DesC() ); |
|
535 TInt dateLen( datePtr8.Length() ); |
|
536 if( dateLen == 0 ) |
|
537 { |
|
538 // blank "expires" attribute evaluate as not expired |
|
539 // additional check is done in Persistent() function |
|
540 return EFalse; |
|
541 } |
|
542 HBufC8* temp1 = HBufC8::NewLC( dateLen ); |
|
543 TPtr8 temp1Des( temp1->Des() ); |
|
544 temp1Des.Copy( datePtr8 ); |
|
545 HBufC8* temp2; |
|
546 HBufC8 *desDate; |
|
547 |
|
548 // ascii time format |
|
549 // asctime-date = wkday SP date3 SP time SP 4DIGIT |
|
550 // date3 = month SP ( 2DIGIT | ( SP 1DIGIT )) |
|
551 TBool asciiTime = EFalse; |
|
552 |
|
553 if(KErrNotFound == temp1->Locate( KDayOfWeekSeparator )) |
|
554 { |
|
555 asciiTime=ETrue; |
|
556 } |
|
557 |
|
558 if(asciiTime) |
|
559 { |
|
560 temp2 = HBufC8::NewLC( temp1->Length() ); |
|
561 temp2 = temp1; |
|
562 } |
|
563 else |
|
564 { |
|
565 temp2 = GetCleanedDateTimeLC( temp1 ); |
|
566 } |
|
567 |
|
568 TInt cleanupNum( 2 ); // temp1, temp2 |
|
569 TPtr8 temp2Des( temp2->Des() ); |
|
570 temp2Des.Trim(); |
|
571 |
|
572 TDateTime tempDate( 1997, EJanuary, 1, 0, 0, 0, 0 ); |
|
573 TLex8 lex; |
|
574 TInt error( KErrNone ); |
|
575 TInt tempInt; |
|
576 TInt sepPos[4]; |
|
577 |
|
578 // date string is formatted as: "DD-Mon-YYYY HH:MM:SS" |
|
579 // and must be evaluated as a GMT time |
|
580 |
|
581 // parsing Date |
|
582 // find token's position |
|
583 TInt token = FindTokens( temp2Des, KLocalSeparators, asciiTime?KAsciiTokenCount:KDateTokenCount, sepPos ); |
|
584 |
|
585 if( token < (asciiTime?KAsciiTokenCount:KDateTokenCount -1) ) |
|
586 { |
|
587 CleanupStack::PopAndDestroy( cleanupNum ); // temp1, temp2 |
|
588 return ETrue; |
|
589 } |
|
590 |
|
591 if(!asciiTime) |
|
592 { |
|
593 if( token == KDateTokenCount - 1 ) // if no Time is specified |
|
594 { |
|
595 sepPos[2] = temp2Des.Length(); |
|
596 } |
|
597 } |
|
598 |
|
599 // initizalize Date |
|
600 |
|
601 if(asciiTime) |
|
602 { |
|
603 desDate=temp2Des.AllocLC(); |
|
604 } |
|
605 else |
|
606 { |
|
607 desDate = temp2Des.Left( sepPos[2] ).AllocLC(); |
|
608 } |
|
609 |
|
610 cleanupNum++; // temp1, temp2, desDate |
|
611 desDate->Des().Trim(); |
|
612 |
|
613 // day |
|
614 if(asciiTime) |
|
615 { |
|
616 lex = desDate->Des().Mid( sepPos[1]+1,sepPos[2]- sepPos[1] - 1); |
|
617 } |
|
618 else |
|
619 { |
|
620 lex = desDate->Des().Left( sepPos[0] ); |
|
621 } |
|
622 |
|
623 error += lex.Val( tempInt ); |
|
624 error += tempDate.SetDay( tempInt - 1 ); // day's offset is 0! |
|
625 |
|
626 // year |
|
627 if(asciiTime) |
|
628 { |
|
629 lex = desDate->Des().Right( desDate->Length() - sepPos[3] - 1 ); |
|
630 } |
|
631 else |
|
632 { |
|
633 lex = desDate->Des().Right( desDate->Length() - sepPos[1] - 1 ); |
|
634 } |
|
635 error += lex.Val( tempInt ); |
|
636 if(tempInt < 100) // make sure it has four digit length |
|
637 { |
|
638 tempInt += 2000; |
|
639 } |
|
640 error += tempDate.SetYear( tempInt ); |
|
641 |
|
642 // month |
|
643 TPtrC8 monthPtr = desDate->Des().Mid( sepPos[0] + 1, sepPos[1] - sepPos[0] - 1 ); |
|
644 TPtrC8 monthNamesPtr( KLocalMonthNames ); |
|
645 TInt monthNum = monthNamesPtr.Find( monthPtr ); |
|
646 if( monthNum == KErrNotFound ) |
|
647 { |
|
648 // probably using digits for month rather than its English name |
|
649 lex = monthPtr; |
|
650 error += lex.Val( monthNum ); |
|
651 monthNum--; // month's offset is 0! |
|
652 if ( (monthNum < 0) || (monthNum > 11) ) |
|
653 // invalid month, cookie must be removed |
|
654 { |
|
655 CleanupStack::PopAndDestroy( cleanupNum ); // temp1, temp2, desDate |
|
656 return ETrue; |
|
657 } |
|
658 } |
|
659 // now we have a position for month's English name |
|
660 else if( (monthNum % 4 ) != 0 ) |
|
661 // something strange happened, cookie must be removed |
|
662 { |
|
663 CleanupStack::PopAndDestroy( cleanupNum ); // temp1, temp2, desDate |
|
664 return ETrue; |
|
665 } |
|
666 else |
|
667 { |
|
668 // divide by 4 to convert from index into month's English name to month number, zero relative |
|
669 monthNum >>= 2; |
|
670 } |
|
671 error += tempDate.SetMonth( TMonth( monthNum ) ); // month's offset is 0! |
|
672 |
|
673 // parsing Time |
|
674 if( (sepPos[2] != temp2Des.Length()) && // Time is present |
|
675 (error == KErrNone) ) // and no error yet |
|
676 { |
|
677 HBufC8 *desTime; |
|
678 // initialize Time |
|
679 if(asciiTime) |
|
680 { |
|
681 desTime=temp2Des.Mid( sepPos[2] + 1, sepPos[3] - sepPos[2] - 1 ).AllocLC(); |
|
682 } |
|
683 else |
|
684 { |
|
685 desTime = temp2Des.Right( temp2Des.Length() - sepPos[2] - 1 ).AllocLC(); |
|
686 } |
|
687 cleanupNum++; // 4 |
|
688 desTime->Des().Trim(); |
|
689 |
|
690 token = FindTokens( desTime->Des(), KLocalTimeSeparator, KTimeTokenCount, sepPos ); |
|
691 if(token >= KTimeTokenCount - 1) // 2, 3 tokens found |
|
692 { |
|
693 // hour |
|
694 lex = desTime->Des().Left( sepPos[0] ); |
|
695 error += lex.Val( tempInt ); |
|
696 error += tempDate.SetHour( tempInt ); |
|
697 |
|
698 // second |
|
699 lex = desTime->Des().Right( desTime->Length() - sepPos[1] - 1 ); |
|
700 error += lex.Val( tempInt ); |
|
701 error += tempDate.SetSecond( tempInt ); |
|
702 |
|
703 // minute |
|
704 lex = desTime->Des().Mid( sepPos[0] + 1, sepPos[1] - sepPos[0] - 1 ); |
|
705 error += lex.Val( tempInt ); |
|
706 error += tempDate.SetMinute( tempInt ); |
|
707 } |
|
708 } |
|
709 |
|
710 // is parsing OK? |
|
711 if( error == KErrNone ) |
|
712 { |
|
713 TTime expiryTime( tempDate ); |
|
714 THTTPHdrVal aAttributeVal; |
|
715 TCookieAttribute attribute; |
|
716 TDateTime ResponseDate; |
|
717 if ( FindAttribute( EDate, attribute ) != KErrNotFound ) |
|
718 { |
|
719 aAttributeVal = attribute.Value(); |
|
720 ResponseDate=aAttributeVal.DateTime(); |
|
721 } |
|
722 TTime RespTime(ResponseDate); |
|
723 TTimeIntervalMicroSeconds diffMsec=expiryTime.MicroSecondsFrom(RespTime); |
|
724 TTime nowTime; |
|
725 nowTime.UniversalTime(); |
|
726 // TDateTime temptime2; |
|
727 TTime newexpiryTime = iReceivedTime + diffMsec; |
|
728 // temptime2 = nowTime.DateTime(); |
|
729 if( newexpiryTime <= nowTime ) |
|
730 { // EXPIRED !!!! |
|
731 retval = ETrue; |
|
732 } |
|
733 } |
|
734 else // invalid Date is expired! |
|
735 { |
|
736 retval = ETrue; |
|
737 } |
|
738 CleanupStack::PopAndDestroy( cleanupNum ); // temp1, temp2, desDate, desTime |
|
739 return retval; |
|
740 } |
|
741 |
|
742 |
|
743 // --------------------------------------------------------- |
|
744 // CCookie::FindTokens |
|
745 // --------------------------------------------------------- |
|
746 // |
|
747 TInt CCookie::FindTokens( const TDesC8& aString, |
|
748 const TDesC8& aTokenSeparators, |
|
749 const TInt aTokenCount, |
|
750 TInt* aTokens ) const |
|
751 { |
|
752 TLex8 lex = aString; |
|
753 TChar ch; |
|
754 TInt tokenCount( 0 ), ii; |
|
755 for(ii=0; ii<aTokenCount; aTokens[ii++] = KErrNotFound) ; |
|
756 |
|
757 while( !( (tokenCount==aTokenCount) || lex.Eos() ) ) |
|
758 { |
|
759 ch = lex.Get(); |
|
760 if( aTokenSeparators.Locate( ch ) != KErrNotFound ) |
|
761 { |
|
762 aTokens[tokenCount++] = lex.Offset()-1; |
|
763 } |
|
764 } |
|
765 return tokenCount; |
|
766 } |
|
767 |
|
768 // --------------------------------------------------------- |
|
769 // CCookie::Persistent |
|
770 // --------------------------------------------------------- |
|
771 // |
|
772 TBool CCookie::Persistent() const |
|
773 { |
|
774 TBool result( EFalse ); |
|
775 THTTPHdrVal attrVal; |
|
776 |
|
777 if ( FromNetscapeVersion() ) |
|
778 { |
|
779 if ( Attribute( CCookie::EExpires, attrVal ) == KErrNone ) |
|
780 { |
|
781 // blank "expires" attribute evaluate as expired. |
|
782 // check only for string type attribute |
|
783 if ( attrVal.Type() == THTTPHdrVal::KStrFVal ) |
|
784 { |
|
785 if( attrVal.StrF().DesC().Length() > 0 ) |
|
786 { |
|
787 result = ETrue; |
|
788 } |
|
789 } |
|
790 else |
|
791 { |
|
792 result = ETrue; |
|
793 } |
|
794 } |
|
795 } |
|
796 else |
|
797 { |
|
798 if ( Attribute( CCookie::EDiscard, attrVal ) == KErrNotFound ) |
|
799 { |
|
800 if ( Attribute( CCookie::EMaxAge, attrVal ) == KErrNone ) |
|
801 { // has max age, to be stored until it expires... |
|
802 // check if MaxAge is 0, in that case, discard immediatelly. |
|
803 TInt MaxAge(0); |
|
804 if ( attrVal.Type() == THTTPHdrVal::KTIntVal ) |
|
805 { |
|
806 MaxAge = attrVal.Int(); |
|
807 } |
|
808 else |
|
809 { |
|
810 TPtrC8 MaxAgePtr( attrVal.StrF().DesC() ); |
|
811 TLex8 lex( MaxAgePtr ); |
|
812 lex.Val( MaxAge ); |
|
813 } |
|
814 if ( MaxAge > 0) |
|
815 { |
|
816 result = ETrue; |
|
817 } |
|
818 } |
|
819 } |
|
820 } |
|
821 return result; |
|
822 } |
|
823 |
|
824 // --------------------------------------------------------- |
|
825 // CCookie::IsUnknownVersion |
|
826 // --------------------------------------------------------- |
|
827 // |
|
828 TBool CCookie::IsUnknownVersion() const |
|
829 { |
|
830 TBool unknownVersion( EFalse ); |
|
831 THTTPHdrVal attrVal; |
|
832 if( Attribute( CCookie::EVersion, attrVal ) != KErrNotFound ) |
|
833 { |
|
834 if( attrVal.StrF().DesC().Compare( KCookieKnownVersion() ) != 0 ) |
|
835 { |
|
836 unknownVersion = ETrue; |
|
837 } |
|
838 } |
|
839 return unknownVersion; |
|
840 } |
|
841 |
|
842 // --------------------------------------------------------- |
|
843 // CCookie::CCookie |
|
844 // --------------------------------------------------------- |
|
845 // |
|
846 CCookie::CCookie( RStringPool aStringPool ) |
|
847 : iStringPool( aStringPool ), iSetCookie2( EFalse ), iNetscape( EFalse ) |
|
848 { |
|
849 iReceivedTime.UniversalTime(); |
|
850 } |
|
851 |
|
852 |
|
853 // --------------------------------------------------------- |
|
854 // CCookie::ConstructL |
|
855 // --------------------------------------------------------- |
|
856 // |
|
857 void CCookie::ConstructL( RHTTPHeaders aRequestHeaders, TInt aPartIndex, |
|
858 RStringF aFieldName, const TUriC8& aUri ) |
|
859 { |
|
860 const TStringTable& commonStringTable = RHTTPSession::GetTable(); |
|
861 |
|
862 // Determining if this object is constructed from a Set-Cookie2 HTTP header |
|
863 RStringF setCookie2Name = iStringPool.StringF( HTTP::ESetCookie2, |
|
864 commonStringTable ); |
|
865 |
|
866 iSetCookie2 = ( aFieldName == setCookie2Name ); |
|
867 |
|
868 TBool DefaultDiscard( EFalse ); |
|
869 |
|
870 THTTPHdrVal hVal; |
|
871 |
|
872 // Retrieval of NAME attribute |
|
873 // --------------------------------------------------------- |
|
874 // retrieving Name atribute |
|
875 // --------------------------------------------------------- |
|
876 if ( aRequestHeaders.GetParam( aFieldName, |
|
877 iStringPool.StringF( HTTP::ECookieName, |
|
878 commonStringTable ), |
|
879 hVal, |
|
880 aPartIndex ) == KErrNone ) |
|
881 { |
|
882 SetAttribute( EName, hVal ); // ignore the result of this method |
|
883 } |
|
884 |
|
885 // --------------------------------------------------------- |
|
886 // retrieving Value atribute |
|
887 // --------------------------------------------------------- |
|
888 if ( aRequestHeaders.GetParam( aFieldName, |
|
889 iStringPool.StringF( HTTP::ECookieValue, |
|
890 commonStringTable ), |
|
891 hVal, |
|
892 aPartIndex ) == KErrNone ) |
|
893 { |
|
894 SetAttribute( EValue, hVal ); // ignore the result of this method |
|
895 } |
|
896 |
|
897 // now get the VERSION attribute. |
|
898 // if it is there, then it is either RFC 2109 or RFC 2965 |
|
899 // if it is not there, then it is NETSCAPE style cookie |
|
900 // --------------------------------------------------------- |
|
901 // retrieving Version atribute |
|
902 // --------------------------------------------------------- |
|
903 if ( aRequestHeaders.GetParam( |
|
904 aFieldName, |
|
905 iStringPool.StringF( HTTP::EVersion, |
|
906 commonStringTable ), |
|
907 hVal, aPartIndex ) == KErrNone ) |
|
908 { |
|
909 iNetscape = EFalse; |
|
910 SetAttribute( EVersion, hVal ); // ignore the result of this method |
|
911 } |
|
912 else |
|
913 { |
|
914 iNetscape = ETrue; |
|
915 } |
|
916 |
|
917 // now get common attributes for all |
|
918 // that is, Path, Domain, Secure |
|
919 // Add Path attribute if it exists + defaulting |
|
920 // --------------------------------------------------------- |
|
921 // retrieving Path atribute |
|
922 // --------------------------------------------------------- |
|
923 if ( aRequestHeaders.GetParam( |
|
924 aFieldName, |
|
925 iStringPool.StringF( HTTP::EPath, |
|
926 commonStringTable ), |
|
927 hVal, aPartIndex ) == KErrNone ) |
|
928 { |
|
929 SetAttribute( EPath, hVal ); // ignore the result of this method |
|
930 } |
|
931 else |
|
932 { |
|
933 // defaulting |
|
934 AddDefaultPathL( aUri ); |
|
935 } |
|
936 |
|
937 // --------------------------------------------------------- |
|
938 // retrieving Domain atribute |
|
939 // --------------------------------------------------------- |
|
940 if ( aRequestHeaders.GetParam( |
|
941 aFieldName, |
|
942 iStringPool.StringF( HTTP::EDomain, |
|
943 commonStringTable ), |
|
944 hVal, aPartIndex ) == KErrNone && hVal.StrF().DesC().Length() > 0) |
|
945 { |
|
946 SetAttribute( EDomain, hVal ); // ignore the result of this method |
|
947 } |
|
948 else |
|
949 { // Default handling |
|
950 // in this case the default is the effective request host |
|
951 RStringF defDomain = |
|
952 iStringPool.OpenFStringL( aUri.Extract( EUriHost ) ); |
|
953 THTTPHdrVal defdomVal( defDomain ); |
|
954 SetAttribute( EDomain, defdomVal, ETrue );// ignore the result |
|
955 defDomain.Close(); |
|
956 } |
|
957 |
|
958 // --------------------------------------------------------- |
|
959 // retrieving Secure atribute |
|
960 // --------------------------------------------------------- |
|
961 if ( aRequestHeaders.GetParam( |
|
962 aFieldName, |
|
963 iStringPool.StringF( HTTP::ESecure, |
|
964 commonStringTable ), |
|
965 hVal, aPartIndex ) == KErrNone ) |
|
966 { |
|
967 SetAttribute( ESecure, hVal ); // ignore the result of this method |
|
968 } |
|
969 else |
|
970 { // Default handling if applies |
|
971 // if not present, then cookie is not 'secure' |
|
972 // no action here as if attribute is not present, |
|
973 // cookie might be sended by default. |
|
974 } |
|
975 |
|
976 |
|
977 // now if it is Netscape, get Netscape specific parts |
|
978 if ( iNetscape ) |
|
979 { |
|
980 // that is, Expires |
|
981 // --------------------------------------------------------- |
|
982 // retrieving Expires atribute |
|
983 // --------------------------------------------------------- |
|
984 if ( aRequestHeaders.GetParam( |
|
985 aFieldName, |
|
986 iStringPool.StringF( HTTP::EExpires, |
|
987 commonStringTable ), |
|
988 hVal, aPartIndex ) == KErrNone ) |
|
989 { |
|
990 SetAttribute( EExpires, hVal ); // ignore the result of this method |
|
991 } |
|
992 //----------------------------------------------------------- |
|
993 // Default handling is does not applies. |
|
994 // Reference: error ID:ESAN-6XWHRL |
|
995 // If "version" is not present but "max-age/comment" is present |
|
996 // then we can considere cookie as RFC 2109 or RFC 2965 type |
|
997 else if(( aRequestHeaders.GetParam( aFieldName, |
|
998 iStringPool.StringF( HTTP::EComment, |
|
999 commonStringTable ), |
|
1000 hVal, aPartIndex ) == KErrNone ) || |
|
1001 ( aRequestHeaders.GetParam( aFieldName, |
|
1002 iStringPool.StringF( HTTP::EMaxAge, |
|
1003 commonStringTable ), |
|
1004 hVal, aPartIndex ) == KErrNone )) |
|
1005 { |
|
1006 // Not a NETSCAPE style cookie |
|
1007 iNetscape = EFalse; |
|
1008 } |
|
1009 } |
|
1010 |
|
1011 // --------------------------------------------------------- |
|
1012 // retrieving Date atribute |
|
1013 // --------------------------------------------------------- |
|
1014 // get the Date header field name |
|
1015 RStringF dateFieldName = iStringPool.StringF( HTTP::EDate, |
|
1016 commonStringTable ); |
|
1017 if ( aRequestHeaders.GetField( dateFieldName, 0, hVal) == KErrNone ) |
|
1018 |
|
1019 { |
|
1020 SetAttribute( EDate, hVal ); // ignore the result of this method |
|
1021 } |
|
1022 else |
|
1023 |
|
1024 // as the expiration comparison is based on the UniversalTime, |
|
1025 // we use the curreent (arriving time) for the cookie's born time too. :-) |
|
1026 { // Add default handling if applies |
|
1027 TTime nowTime; |
|
1028 nowTime.UniversalTime(); |
|
1029 // TDateTime dateTime( nowTime.DateTime() ); |
|
1030 hVal.SetDateTime( nowTime.DateTime() ); |
|
1031 SetAttribute( EDate, hVal ); |
|
1032 } |
|
1033 if( EFalse == iNetscape ) |
|
1034 { |
|
1035 // now get RFC SetCookie and SetCookie2 common parts |
|
1036 // that is, Comment, Max-Age |
|
1037 // get EDate to be able to calculate cookie age if needed. |
|
1038 // --------------------------------------------------------- |
|
1039 // retrieving Comment atribute |
|
1040 // --------------------------------------------------------- |
|
1041 if ( aRequestHeaders.GetParam( aFieldName, |
|
1042 iStringPool.StringF( HTTP::EComment, |
|
1043 commonStringTable ), |
|
1044 hVal, aPartIndex ) == KErrNone ) |
|
1045 { |
|
1046 SetAttribute( EComment, hVal ); // ignore the result of this method |
|
1047 } |
|
1048 else |
|
1049 { // Add default handling if applies |
|
1050 // no defaulting for EComment |
|
1051 } |
|
1052 |
|
1053 // --------------------------------------------------------- |
|
1054 // retrieving Max-Age atribute |
|
1055 // --------------------------------------------------------- |
|
1056 if ( aRequestHeaders.GetParam( |
|
1057 aFieldName, |
|
1058 iStringPool.StringF( HTTP::EMaxAge, |
|
1059 commonStringTable ), |
|
1060 hVal, aPartIndex ) == KErrNone ) |
|
1061 { |
|
1062 SetAttribute( EMaxAge, hVal ); // ignore the result of this method |
|
1063 } |
|
1064 else |
|
1065 { // Add default handling if applies |
|
1066 // Defaults to Discard, discard the cookie on agent termination |
|
1067 // -> transient cookie |
|
1068 // in case of SetCookie2, also set Discard, defaulted |
|
1069 if ( iSetCookie2 ) |
|
1070 { |
|
1071 DefaultDiscard = ETrue; |
|
1072 } |
|
1073 } |
|
1074 |
|
1075 // now if it is SetCookie2, than get SetCookie2 specific parts |
|
1076 if ( iSetCookie2 ) |
|
1077 { |
|
1078 // that is, CommentUrl, Discard, Port |
|
1079 // --------------------------------------------------------- |
|
1080 // retrieving CommentURL atribute |
|
1081 // --------------------------------------------------------- |
|
1082 if ( aRequestHeaders.GetParam( aFieldName, |
|
1083 iStringPool.StringF( HTTP::ECommentURL, |
|
1084 commonStringTable ), |
|
1085 hVal, aPartIndex ) == KErrNone ) |
|
1086 { |
|
1087 SetAttribute( ECommentURI, hVal ); // ignore the result of this method |
|
1088 } |
|
1089 else |
|
1090 { // Add default handling if applies |
|
1091 // no defaulting for ECommentURL |
|
1092 } |
|
1093 |
|
1094 // --------------------------------------------------------- |
|
1095 // retrieving Discard atribute |
|
1096 // --------------------------------------------------------- |
|
1097 if ( aRequestHeaders.GetParam( |
|
1098 aFieldName, |
|
1099 iStringPool.StringF( HTTP::EDiscard, |
|
1100 commonStringTable ), |
|
1101 hVal, aPartIndex ) == KErrNone ) |
|
1102 { |
|
1103 SetAttribute( EDiscard, hVal ); // ignore the result of this method |
|
1104 } |
|
1105 else |
|
1106 { // Add default handling if applies |
|
1107 // no defaulting for EDiscard |
|
1108 // only if it is caused by MAx-Age beeing not supplied |
|
1109 if ( DefaultDiscard ) |
|
1110 { |
|
1111 RStringF emptyStr = iStringPool.OpenFStringL( KNullDesC8() ); |
|
1112 THTTPHdrVal emptyVal( emptyStr ); |
|
1113 SetAttribute( EDiscard, emptyVal, ETrue ); |
|
1114 emptyStr.Close(); |
|
1115 } |
|
1116 } |
|
1117 |
|
1118 // Add Port attribute if it exists + defaulting |
|
1119 // --------------------------------------------------------- |
|
1120 // retrieving Port atribute |
|
1121 // --------------------------------------------------------- |
|
1122 if ( aRequestHeaders.GetParam( aFieldName, |
|
1123 iStringPool.StringF( HTTP::ECookiePort, |
|
1124 commonStringTable ), |
|
1125 hVal, |
|
1126 aPartIndex ) == KErrNone ) |
|
1127 { |
|
1128 // if it is a string and contains at least 1 character, then store it |
|
1129 if ( ( hVal.Type() == THTTPHdrVal::KStrFVal && |
|
1130 hVal.StrF().DesC().Length() ) || |
|
1131 ( hVal.Type() == THTTPHdrVal::KStrVal && |
|
1132 hVal.Str().DesC().Length() ) ) |
|
1133 { |
|
1134 SetAttribute( EPort, hVal, ETrue ); // ignore the result of this method |
|
1135 } |
|
1136 else // the Port attrib is either empty or incorrect |
|
1137 { |
|
1138 RStringF requestPort; |
|
1139 if ( aUri.IsPresent( EUriPort ) ) |
|
1140 { |
|
1141 requestPort = |
|
1142 iStringPool.OpenFStringL( aUri.Extract( EUriPort ) ); |
|
1143 } |
|
1144 else |
|
1145 { |
|
1146 requestPort = iStringPool.OpenFStringL |
|
1147 ( KCookieDefaultRequestPort() ); |
|
1148 } |
|
1149 |
|
1150 THTTPHdrVal reqPort( requestPort ); |
|
1151 |
|
1152 SetAttribute( EPort, reqPort, ETrue ); // ignore the result |
|
1153 |
|
1154 requestPort.Close(); |
|
1155 } |
|
1156 } |
|
1157 else |
|
1158 { |
|
1159 // if the Port attrib does not exist, leave it blank |
|
1160 } |
|
1161 } |
|
1162 } |
|
1163 } |
|
1164 |
|
1165 |
|
1166 |
|
1167 // --------------------------------------------------------- |
|
1168 // CCookie::FindAttribute |
|
1169 // --------------------------------------------------------- |
|
1170 // |
|
1171 TInt CCookie::FindAttribute( TCookieAttributeName aAttributeName, |
|
1172 TCookieAttribute& aAttribute ) const |
|
1173 { |
|
1174 const TInt numAttributes = iAttributes.Count(); |
|
1175 for ( TInt index = 0; index < numAttributes; ++index ) |
|
1176 { |
|
1177 if ( iAttributes[index].Name() == aAttributeName ) |
|
1178 { |
|
1179 aAttribute = iAttributes[index]; |
|
1180 return index; |
|
1181 } |
|
1182 } |
|
1183 |
|
1184 return KErrNotFound; |
|
1185 } |
|
1186 |
|
1187 // --------------------------------------------------------- |
|
1188 // CCookie::RemoveAttribute |
|
1189 // --------------------------------------------------------- |
|
1190 // |
|
1191 void CCookie::RemoveAttribute( TInt aIndex ) |
|
1192 { |
|
1193 iSize -= ( KCookieAttributePrefixLength + iAttributes[ aIndex ].Size() + |
|
1194 KCookieAttributeDefaultedLength + |
|
1195 KCookieAttributeFoundLength ); |
|
1196 iAttributes[ aIndex ].Close(); |
|
1197 iAttributes.Remove( aIndex ); |
|
1198 } |
|
1199 |
|
1200 // --------------------------------------------------------- |
|
1201 // CCookie::RemoveAttribute |
|
1202 // --------------------------------------------------------- |
|
1203 // |
|
1204 void CCookie::RemoveAttribute( TCookieAttributeName aAttributeName ) |
|
1205 { |
|
1206 TCookieAttribute attribute; |
|
1207 TInt index( FindAttribute( aAttributeName, attribute ) ); |
|
1208 if( index != KErrNotFound ) |
|
1209 { |
|
1210 RemoveAttribute( index ); |
|
1211 } |
|
1212 } |
|
1213 |
|
1214 // --------------------------------------------------------- |
|
1215 // CCookie::GetLocalOffset |
|
1216 // --------------------------------------------------------- |
|
1217 // |
|
1218 TInt CCookie::GetLocalOffset( HBufC8* aDate, TInt& aHour, |
|
1219 TInt& aMinute, TInt& aLength ) const |
|
1220 { |
|
1221 TInt retval( 0 ); |
|
1222 TInt pos(0); |
|
1223 // TInt fwspos(0); |
|
1224 // TBool plus( ETrue ); |
|
1225 TPtrC8 datePtr( aDate->Des() ); |
|
1226 |
|
1227 |
|
1228 TLex8 lex( datePtr ); |
|
1229 TInt oldoffset( 0 ); |
|
1230 TInt curroffset( 0 ); |
|
1231 TInt i( 0 ); |
|
1232 TInt tokencount( 0 ); |
|
1233 TInt deltaoffset( 0 ); |
|
1234 // firstoffset is to store the first token length/endposition |
|
1235 TInt firstoffset( 0 ); |
|
1236 TBool repeat( ETrue ); |
|
1237 do |
|
1238 { |
|
1239 lex.SkipCharacters(); |
|
1240 curroffset = lex.Offset(); |
|
1241 deltaoffset = curroffset-oldoffset; |
|
1242 if ( deltaoffset ) |
|
1243 { |
|
1244 if ( !tokencount ) |
|
1245 { |
|
1246 firstoffset = deltaoffset; |
|
1247 } |
|
1248 for(i=0; i<deltaoffset; i++) |
|
1249 { |
|
1250 lex.Get(); |
|
1251 } |
|
1252 tokencount++; |
|
1253 /* |
|
1254 if ( deltaoffset != aDate->Length() ) |
|
1255 { |
|
1256 tokencount++; |
|
1257 } |
|
1258 */ |
|
1259 oldoffset = curroffset; |
|
1260 } |
|
1261 else |
|
1262 { // end of string, oldoffset1 holds position |
|
1263 repeat = EFalse; |
|
1264 } |
|
1265 }while (repeat); |
|
1266 |
|
1267 |
|
1268 |
|
1269 pos = aDate->LocateReverse( KLocalTimeZoneSeparator1 ); |
|
1270 |
|
1271 if ( pos > 0 ) |
|
1272 { // found at least one "+" |
|
1273 // plus = ETrue; |
|
1274 } |
|
1275 else |
|
1276 { |
|
1277 pos = aDate->LocateReverse( KLocalTimeZoneSeparator2 ); |
|
1278 if ( pos > 0 ) |
|
1279 { // found at least one "-" |
|
1280 // now check if it is in the date... |
|
1281 // if it is in the date part, then we did found only one tokens... |
|
1282 // and the position MUST be larger than the end of |
|
1283 // the first token (date)... |
|
1284 if ( ( tokencount > 1) && ( firstoffset < pos ) ) |
|
1285 { |
|
1286 // plus = EFalse; |
|
1287 } |
|
1288 else |
|
1289 { |
|
1290 pos = KErrNotFound; |
|
1291 retval = KErrNotFound; |
|
1292 } |
|
1293 } |
|
1294 else |
|
1295 { |
|
1296 retval = KErrNotFound; |
|
1297 } |
|
1298 } |
|
1299 if ( pos > 0 ) |
|
1300 { |
|
1301 // get the length |
|
1302 aLength = aDate->Length()-pos; |
|
1303 // now get the offset |
|
1304 HBufC8* temp = aDate->Right( aLength ).AllocLC(); |
|
1305 temp->Des().Trim(); |
|
1306 TLex8 lex(temp->Left(2)); |
|
1307 lex.Val( aHour ); |
|
1308 TLex8 lex1(temp->Right(2)); |
|
1309 lex1.Val( aMinute ); |
|
1310 CleanupStack::PopAndDestroy( temp ); // temp |
|
1311 } |
|
1312 return retval; |
|
1313 } |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 // --------------------------------------------------------- |
|
1319 // CCookie::GetMilitaryOffset |
|
1320 // --------------------------------------------------------- |
|
1321 // |
|
1322 TInt CCookie::GetMilitaryOffset( HBufC8* /*aDate*/, TInt& aHour ) const |
|
1323 { |
|
1324 // TODO: Add military timezone handling here... |
|
1325 TInt retval( KErrNotFound ); |
|
1326 aHour = 0; |
|
1327 return retval; |
|
1328 } |
|
1329 |
|
1330 |
|
1331 |
|
1332 // --------------------------------------------------------- |
|
1333 // CCookie::GetTimeZone |
|
1334 // --------------------------------------------------------- |
|
1335 // |
|
1336 TInt CCookie::GetTimeZone( HBufC8* aDate, TInt& aHour, |
|
1337 TInt& aLength ) const |
|
1338 { |
|
1339 TInt retval( 0 ); |
|
1340 TInt zonepos = aDate->Find( KUT() ); |
|
1341 if ( zonepos != KErrNotFound ) |
|
1342 { |
|
1343 aHour = 0; |
|
1344 } |
|
1345 else |
|
1346 { |
|
1347 zonepos = aDate->Find( KGMT ); |
|
1348 if ( zonepos != KErrNotFound ) |
|
1349 { |
|
1350 aHour = 0; |
|
1351 } |
|
1352 else |
|
1353 { |
|
1354 zonepos = aDate->Find( KEST ); |
|
1355 if ( zonepos != KErrNotFound ) |
|
1356 { |
|
1357 aHour = -5; |
|
1358 } |
|
1359 else |
|
1360 { |
|
1361 zonepos = aDate->Find( KEDT ); |
|
1362 if ( zonepos != KErrNotFound ) |
|
1363 { |
|
1364 aHour = -4; |
|
1365 } |
|
1366 else |
|
1367 { |
|
1368 zonepos = aDate->Find( KCST ); |
|
1369 if ( zonepos != KErrNotFound ) |
|
1370 { |
|
1371 aHour = -6; |
|
1372 } |
|
1373 else |
|
1374 { |
|
1375 zonepos = aDate->Find( KCDT ); |
|
1376 if ( zonepos != KErrNotFound ) |
|
1377 { |
|
1378 aHour = -5; |
|
1379 } |
|
1380 else |
|
1381 { |
|
1382 zonepos = aDate->Find( KMST ); |
|
1383 if ( zonepos != KErrNotFound ) |
|
1384 { |
|
1385 aHour = -7; |
|
1386 } |
|
1387 else |
|
1388 { |
|
1389 zonepos = aDate->Find( KMDT ); |
|
1390 if ( zonepos != KErrNotFound ) |
|
1391 { |
|
1392 aHour = -6; |
|
1393 } |
|
1394 else |
|
1395 { |
|
1396 zonepos = aDate->Find( KPST ); |
|
1397 if ( zonepos != KErrNotFound ) |
|
1398 { |
|
1399 aHour = -8; |
|
1400 } |
|
1401 else |
|
1402 { |
|
1403 zonepos = aDate->Find( KPDT ); |
|
1404 if ( zonepos != KErrNotFound ) |
|
1405 { |
|
1406 aHour = -7; |
|
1407 } |
|
1408 else |
|
1409 { |
|
1410 retval = KErrNotFound; |
|
1411 } |
|
1412 } |
|
1413 } |
|
1414 } |
|
1415 } |
|
1416 } |
|
1417 } |
|
1418 } |
|
1419 } |
|
1420 } |
|
1421 |
|
1422 if ( zonepos != KErrNotFound ) |
|
1423 { |
|
1424 // get the length |
|
1425 aLength = aDate->Length() - zonepos; |
|
1426 } |
|
1427 |
|
1428 return retval; |
|
1429 } |
|
1430 |
|
1431 |
|
1432 |
|
1433 // --------------------------------------------------------- |
|
1434 // CCookie::GetCleanedDateTimeLC |
|
1435 // --------------------------------------------------------- |
|
1436 // |
|
1437 HBufC8* CCookie::GetCleanedDateTimeLC( HBufC8* aDate ) const |
|
1438 { |
|
1439 // as http time might contain a "DayOfWeek," optional part |
|
1440 // which is not understood by the parser, we need to |
|
1441 // remove it |
|
1442 TInt pos = aDate->Locate( KDayOfWeekSeparator ); |
|
1443 if ( pos < 0 ) |
|
1444 { |
|
1445 pos = 0; |
|
1446 } |
|
1447 else |
|
1448 { |
|
1449 if ( pos ) |
|
1450 { |
|
1451 pos++; |
|
1452 } |
|
1453 } |
|
1454 |
|
1455 HBufC8* result = HBufC8::NewLC( aDate->Length() ); |
|
1456 HBufC8* temp = aDate->Mid( pos ).AllocLC(); |
|
1457 // reduce multiple spaces |
|
1458 temp->Des().TrimAll(); |
|
1459 |
|
1460 // now try to remove time zone values... |
|
1461 TInt hour( 0 ); |
|
1462 TInt minute( 0 ); |
|
1463 TInt length( 0 ); |
|
1464 |
|
1465 // Accordign to RFC 2822, the correct date-time syntax: |
|
1466 // [dayofweek","] date FWS time [CFWS] |
|
1467 // where: |
|
1468 // date : day month year |
|
1469 // time : time-of-day FWS zone |
|
1470 // |
|
1471 // zone : (( "+" / "-" ) 4DIGIT) / obs-zone |
|
1472 // obs-zone : "GMT", "UT", "EST", "EDT", "CST", "CDT", |
|
1473 // "MST", "MDT", "PST", "PDT" |
|
1474 // and the military 1 letter version |
|
1475 // so first try to get the +/-hhmm format... |
|
1476 // check if time is locale offset in +/- HHMM form |
|
1477 if ( GetLocalOffset( temp, hour, minute, length ) == KErrNotFound ) |
|
1478 { |
|
1479 // not a local offset, check if it is one of the |
|
1480 // known 2 or three digit ones |
|
1481 if ( GetTimeZone( temp, hour, length ) == KErrNotFound ) |
|
1482 { |
|
1483 //Not, check if it is Military, |
|
1484 //which is a one digit ALPHA |
|
1485 if ( GetMilitaryOffset( temp, hour ) == KErrNotFound ) |
|
1486 { |
|
1487 // not a military one, |
|
1488 // error, unknown time zone or none... |
|
1489 } |
|
1490 else |
|
1491 { // Military offset |
|
1492 length = 1; |
|
1493 } |
|
1494 } |
|
1495 else |
|
1496 {// other know one |
|
1497 } |
|
1498 } |
|
1499 else |
|
1500 { // locale offset |
|
1501 } |
|
1502 *result = temp->Left( temp->Length() - length); |
|
1503 // return ( temp->Left( temp->Length() - length).AllocLC() ); |
|
1504 CleanupStack::PopAndDestroy( temp ); |
|
1505 return result; |
|
1506 } |
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 // --------------------------------------------------------- |
|
1514 // CCookie::TCookieAttribute::TCookieAttribute |
|
1515 // --------------------------------------------------------- |
|
1516 // |
|
1517 CCookie::TCookieAttribute::TCookieAttribute( TCookieAttributeName aName, |
|
1518 const THTTPHdrVal& aHdrVal, |
|
1519 TBool aDefaulted ) |
|
1520 : iName( aName ), |
|
1521 iDefaulted( aDefaulted ) |
|
1522 { |
|
1523 iValue = aHdrVal.Copy(); |
|
1524 |
|
1525 |
|
1526 switch ( iValue.Type() ) |
|
1527 { |
|
1528 case THTTPHdrVal::KTIntVal : |
|
1529 { |
|
1530 iSize = sizeof( TInt ); |
|
1531 break; |
|
1532 } |
|
1533 case THTTPHdrVal::KStrVal : |
|
1534 { |
|
1535 iSize = iValue.Str().DesC().Length(); |
|
1536 break; |
|
1537 } |
|
1538 case THTTPHdrVal::KDateVal : |
|
1539 { |
|
1540 iSize = sizeof( TDateTime ); |
|
1541 break; |
|
1542 } |
|
1543 case THTTPHdrVal::KStrFVal : |
|
1544 { |
|
1545 iSize = iValue.StrF().DesC().Length(); |
|
1546 break; |
|
1547 } |
|
1548 default : // THTTPHdrVal::KNoType |
|
1549 { |
|
1550 iSize = 0; |
|
1551 } |
|
1552 } |
|
1553 } |
|
1554 |
|
1555 |
|
1556 // --------------------------------------------------------- |
|
1557 // CCookie::TCookieAttribute::TCookieAttribute |
|
1558 // --------------------------------------------------------- |
|
1559 // |
|
1560 CCookie::TCookieAttribute::TCookieAttribute() |
|
1561 { |
|
1562 } |
|
1563 |
|
1564 |
|
1565 // --------------------------------------------------------- |
|
1566 // CCookie::TCookieAttribute::Close |
|
1567 // --------------------------------------------------------- |
|
1568 // |
|
1569 void CCookie::TCookieAttribute::Close() |
|
1570 { |
|
1571 THTTPHdrVal::THTTPValType type = iValue.Type(); |
|
1572 if ( type == THTTPHdrVal::KStrVal ) |
|
1573 { |
|
1574 iValue.Str().Close(); |
|
1575 } |
|
1576 else if ( type == THTTPHdrVal::KStrFVal ) |
|
1577 { |
|
1578 iValue.StrF().Close(); |
|
1579 } |
|
1580 |
|
1581 // TBD : iValue = THTTPHdrVal();? |
|
1582 iSize = 0; |
|
1583 } |
|
1584 |
|
1585 |
|
1586 // --------------------------------------------------------- |
|
1587 // CCookie::TCookieAttribute::Name |
|
1588 // --------------------------------------------------------- |
|
1589 // |
|
1590 CCookie::TCookieAttributeName CCookie::TCookieAttribute::Name() const |
|
1591 { |
|
1592 return iName; |
|
1593 } |
|
1594 |
|
1595 // --------------------------------------------------------- |
|
1596 // CCookie::TCookieAttribute::Size |
|
1597 // --------------------------------------------------------- |
|
1598 // |
|
1599 TInt CCookie::TCookieAttribute::Size() const |
|
1600 { |
|
1601 return iSize; |
|
1602 } |
|
1603 |
|
1604 |
|
1605 // --------------------------------------------------------- |
|
1606 // CCookie::TCookieAttribute::Defaulted |
|
1607 // --------------------------------------------------------- |
|
1608 // |
|
1609 TBool CCookie::TCookieAttribute::Defaulted() const |
|
1610 { |
|
1611 return iDefaulted; |
|
1612 } |
|
1613 |
|
1614 // --------------------------------------------------------- |
|
1615 // CCookie::TCookieAttribute::Value |
|
1616 // --------------------------------------------------------- |
|
1617 // |
|
1618 const THTTPHdrVal& CCookie::TCookieAttribute::Value() const |
|
1619 { |
|
1620 return iValue; |
|
1621 } |
|
1622 |
|
1623 |
|
1624 |