|
1 // Copyright (c) 2006-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 // Name : CSIPHeaderBase.cpp |
|
15 // Part of : SIP Codec |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sipheaderbase.h" |
|
22 #include "SIPHeaderLookup.h" |
|
23 #include "sipstrings.h" |
|
24 #include "sipstrconsts.h" |
|
25 #include "_sipcodecdefs.h" |
|
26 |
|
27 _LIT8(KColonAndSpace, ": "); |
|
28 _LIT8(KExpiresHeaderNameDes, "Expires"); |
|
29 _LIT8(KRequireHeaderNameDes, "Require"); |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CSIPHeaderBase::CSIPHeaderBase |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CSIPHeaderBase::CSIPHeaderBase() |
|
36 { |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSIPHeaderBase::~CSIPHeaderBase |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C CSIPHeaderBase::~CSIPHeaderBase() |
|
44 { |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CSIPHeaderBase::HasCompactName |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 TBool CSIPHeaderBase::HasCompactName() const |
|
52 { |
|
53 return EFalse; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CSIPHeaderBase::CompactName |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 RStringF CSIPHeaderBase::CompactName() const |
|
61 { |
|
62 return SIPStrings::StringF(SipStrConsts::EEmpty); |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CSIPHeaderBase::IsExtensionHeader |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 TBool CSIPHeaderBase::IsExtensionHeader() const |
|
70 { |
|
71 return EFalse; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CSIPHeaderBase::EncodeMultipleToOneLine |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 TBool CSIPHeaderBase::EncodeMultipleToOneLine() const |
|
79 { |
|
80 return ETrue; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CSIPHeaderBase::MoreThanOneAllowed |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 TBool CSIPHeaderBase::MoreThanOneAllowed() const |
|
88 { |
|
89 return EFalse; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CSIPHeaderBase::ToTextL |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C HBufC8* CSIPHeaderBase::ToTextL() const |
|
97 { |
|
98 TPtrC8 fullname(Name().DesC()); |
|
99 // Because SIP Codec's string table has entry "expires" before "Expires", |
|
100 // and entry "require" before "Require", |
|
101 // literal "Expires" and "Require" must be used here. |
|
102 // Changing the order of string table entries would have caused a SC break. |
|
103 if (Name() == SIPStrings::StringF(SipStrConsts::EExpiresHeader)) |
|
104 { |
|
105 fullname.Set(KExpiresHeaderNameDes); |
|
106 } |
|
107 else if (Name() == SIPStrings::StringF(SipStrConsts::ERequireHeader)) |
|
108 { |
|
109 fullname.Set(KRequireHeaderNameDes); |
|
110 } |
|
111 else |
|
112 { |
|
113 } |
|
114 TUint headerLength = fullname.Length(); |
|
115 headerLength += KColonAndSpace().Length(); |
|
116 HBufC8* encodedHeaderValue = ToTextValueL(); |
|
117 headerLength += encodedHeaderValue->Length(); |
|
118 |
|
119 CleanupStack::PushL (encodedHeaderValue); |
|
120 |
|
121 HBufC8* encodedHeader = HBufC8::NewL(headerLength); |
|
122 TPtr8 encodedHeaderPtr = encodedHeader->Des(); |
|
123 encodedHeaderPtr.Append(fullname); |
|
124 encodedHeaderPtr.Append(KColonAndSpace); |
|
125 encodedHeaderPtr.Append(*encodedHeaderValue); |
|
126 |
|
127 CleanupStack::PopAndDestroy(encodedHeaderValue); |
|
128 |
|
129 return encodedHeader; |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CSIPHeaderBase::ToTextLC |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 EXPORT_C HBufC8* CSIPHeaderBase::ToTextLC() const |
|
137 { |
|
138 HBufC8* encodedHeader = ToTextL(); |
|
139 CleanupStack::PushL (encodedHeader); |
|
140 return encodedHeader; |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CSIPHeaderBase::ToTextValueLC |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 EXPORT_C HBufC8* CSIPHeaderBase::ToTextValueLC() const |
|
148 { |
|
149 HBufC8* encodedHeaderValue = ToTextValueL(); |
|
150 CleanupStack::PushL (encodedHeaderValue); |
|
151 return encodedHeaderValue; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CSIPHeaderBase::ExternalizeL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C void CSIPHeaderBase::ExternalizeL( |
|
159 RWriteStream& aWriteStream, |
|
160 TBool aAddName) const |
|
161 { |
|
162 if (ExternalizeSupported()) |
|
163 { |
|
164 if (aAddName) |
|
165 { |
|
166 ExternalizeNameL (aWriteStream); |
|
167 } |
|
168 ExternalizeValueL (aWriteStream); |
|
169 } |
|
170 } |
|
171 |
|
172 // ----------------------------------------------------------------------------- |
|
173 // CSIPHeaderBase::ExternalizeSupported |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 EXPORT_C TBool CSIPHeaderBase::ExternalizeSupported() const |
|
177 { |
|
178 return ETrue; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CSIPHeaderBase::PushLC |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 EXPORT_C void CSIPHeaderBase::PushLC(RPointerArray<CSIPHeaderBase>* aArray) |
|
186 { |
|
187 CleanupStack::PushL(TCleanupItem(ResetAndDestroy,aArray)); |
|
188 } |
|
189 |
|
190 // ----------------------------------------------------------------------------- |
|
191 // CSIPHeaderBase::ExternalizeNameL |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 void CSIPHeaderBase::ExternalizeNameL (RWriteStream& aWriteStream) const |
|
195 { |
|
196 TPtrC8 fullname(Name().DesC()); |
|
197 aWriteStream.WriteUint32L (fullname.Length()); |
|
198 aWriteStream.WriteL (fullname); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CSIPHeaderBase::ExternalizeValueL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void |
|
206 CSIPHeaderBase::ExternalizeValueL(RWriteStream& /*aWriteStream*/) const |
|
207 { |
|
208 // default implementation empty |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // CSIPHeaderBase::ResetAndDestroy |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CSIPHeaderBase::ResetAndDestroy(TAny* anArray) |
|
216 { |
|
217 RPointerArray<CSIPHeaderBase>* array = |
|
218 reinterpret_cast<RPointerArray<CSIPHeaderBase>*>(anArray); |
|
219 if (array) |
|
220 { |
|
221 array->ResetAndDestroy(); |
|
222 } |
|
223 } |