|
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 #include "thttpdatacomposer.h" |
|
17 |
|
18 #include "mhttpbuffersupplier.h" |
|
19 #include "thttpmessagepanic.h" |
|
20 |
|
21 const TUint KCarriageReturn = '\r'; |
|
22 const TUint KLineFeed = '\n'; |
|
23 const TUint KSpace = ' '; |
|
24 const TUint KColon = ':'; |
|
25 |
|
26 THttpDataComposer::THttpDataComposer(MHttpBufferSupplier& aBufferSupplier) |
|
27 : iBufferSupplier(aBufferSupplier), iBuffer(TPtr8(NULL, 0)) |
|
28 /** |
|
29 Constructor. |
|
30 @param aBufferSupplier The buffer supplier. |
|
31 */ |
|
32 { |
|
33 iRequiredLength = 0; |
|
34 } |
|
35 |
|
36 void THttpDataComposer::Release() |
|
37 /** |
|
38 Release the current data. |
|
39 @post The buffer is empty. |
|
40 */ |
|
41 { |
|
42 iBuffer.Zero(); |
|
43 iRequiredLength = 0; |
|
44 } |
|
45 |
|
46 void THttpDataComposer::Reset() |
|
47 /** |
|
48 Reset the data composer. The data buffer is deleted. |
|
49 @post The data buffer is deleted. |
|
50 */ |
|
51 { |
|
52 iBuffer.Set(NULL, 0, 0); |
|
53 iRequiredLength = 0; |
|
54 iBufferSupplier.DeleteBuffer(); |
|
55 } |
|
56 |
|
57 void THttpDataComposer::AddTokenL(const TDesC8& aToken, TDelimiterType aDelimiter) |
|
58 /** |
|
59 Adds the token followed by the specified delimiter to the data buffer. The |
|
60 delimiter types can be Space, Colon or CRLF. The Colon delimiter includes a |
|
61 following Space character. |
|
62 @param aToken The token to be added to the data buffer. |
|
63 @param aDelimiter The type of delimiter that should follow the token. |
|
64 @panic EHttpMessagePanicBadDelimiterType An illegal delimiter type |
|
65 was specified. |
|
66 */ |
|
67 { |
|
68 // Update the required length - add token and delimiter length |
|
69 iRequiredLength += aToken.Length(); |
|
70 switch( aDelimiter ) |
|
71 { |
|
72 case EColonSpace: |
|
73 case ECRLF: |
|
74 { |
|
75 // These delimiters have two characters. |
|
76 ++iRequiredLength; |
|
77 // Drop into the Space delimiter case... |
|
78 } |
|
79 case ESpace: |
|
80 { |
|
81 // Only a single character |
|
82 ++iRequiredLength; |
|
83 // Drop into the None delimiter case... |
|
84 } |
|
85 case ENone: |
|
86 // No change to required length. |
|
87 break; |
|
88 default: |
|
89 THttpMessagePanic::Panic(THttpMessagePanic::EHttpMessagePanicBadDelimiterType); |
|
90 break; |
|
91 }; |
|
92 |
|
93 // Is there enough space in the buffer? |
|
94 if( iRequiredLength > iBuffer.MaxLength() ) |
|
95 { |
|
96 // Re-allocate the buffer. |
|
97 iBufferSupplier.ReAllocBufferL(iRequiredLength, iBuffer); |
|
98 } |
|
99 |
|
100 // Append the token and delimiter |
|
101 iBuffer.Append(aToken); |
|
102 switch( aDelimiter ) |
|
103 { |
|
104 case EColonSpace: |
|
105 { |
|
106 // Append the colon - drop into the Space case to add a space char |
|
107 iBuffer.Append(KColon); |
|
108 } |
|
109 case ESpace: |
|
110 { |
|
111 iBuffer.Append(KSpace); |
|
112 } break; |
|
113 case ECRLF: |
|
114 { |
|
115 // Append the CR followed by the LF. |
|
116 iBuffer.Append(KCarriageReturn); |
|
117 iBuffer.Append(KLineFeed); |
|
118 } break; |
|
119 case ENone: |
|
120 // Do nothing... |
|
121 break; |
|
122 default: |
|
123 THttpMessagePanic::Panic(THttpMessagePanic::EHttpMessagePanicBadDelimiterType); |
|
124 break; |
|
125 }; |
|
126 } |