|
1 /* |
|
2 * Copyright (c) 2009-2010 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 * Initial Contributors: |
|
9 * Nokia Corporation - initial contribution. |
|
10 * Contributors: |
|
11 * |
|
12 * Description: |
|
13 * MSRP Implementation |
|
14 * |
|
15 */ |
|
16 |
|
17 // CLASS HEADER |
|
18 #include "CMsrpResponse.h" |
|
19 |
|
20 // EXTERNAL HEADER |
|
21 #include <MsrpStrConsts.h> |
|
22 |
|
23 // INTERNAL HEADER |
|
24 #include "MsrpCommon.h" |
|
25 #include "TMSRPHeaderUtil.h" |
|
26 #include "CMSRPFromPathHeader.h" |
|
27 #include "CMSRPToPathHeader.h" |
|
28 #include "CMSRPMessageIdHeader.h" |
|
29 #include "CMSRPByteRangeHeader.h" |
|
30 #include "CMSRPContentTypeHeader.h" |
|
31 #include "CMSRPFailureReportHeader.h" |
|
32 #include "CMSRPSuccessReportHeader.h" |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CMSRPResponse::CMSRPResponse |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CMSRPResponse::CMSRPResponse( TUint aStatusCode, RStringF aReasonPhrase ) |
|
39 : iStatusCode( aStatusCode ) |
|
40 { |
|
41 iReasonPhrase = aReasonPhrase.Copy(); |
|
42 } |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CMSRPResponse::CMSRPResponse |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 EXPORT_C CMSRPResponse::CMSRPResponse( ) |
|
49 { |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CMSRPResponse::~CMSRPResponse |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 EXPORT_C CMSRPResponse::~CMSRPResponse() |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CMSRPResponse::SetStatusCodeL |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C void CMSRPResponse::SetStatusCodeL( TUint aStatusCode ) |
|
65 { |
|
66 // make sure the status code is valid |
|
67 // sip status codes must be between 200 - 600 |
|
68 __ASSERT_ALWAYS( aStatusCode < 600, User::Leave( KErrArgument ) ); // codescanner::magicnumbers |
|
69 __ASSERT_ALWAYS( aStatusCode >= 200, User::Leave( KErrArgument ) ); // codescanner::magicnumbers |
|
70 |
|
71 iStatusCode = aStatusCode; |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CMSRPResponse::StatusCode |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 EXPORT_C TUint CMSRPResponse::StatusCode() const |
|
79 { |
|
80 return iStatusCode; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CMSRPResponse::SetReasonPhraseL |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 EXPORT_C void CMSRPResponse::SetReasonPhrase( RStringF aReasonPhrase ) |
|
88 { |
|
89 iReasonPhrase = aReasonPhrase.Copy(); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CMSRPResponse::ReasonPhrase |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 EXPORT_C RStringF CMSRPResponse::ReasonPhrase() const |
|
97 { |
|
98 return iReasonPhrase; |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CMSRPResponse::InternalizeL |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C CMSRPResponse* CMSRPResponse::InternalizeL( RReadStream& aReadStream ) |
|
106 { |
|
107 CMSRPResponse* self = new (ELeave ) CMSRPResponse(); |
|
108 CleanupStack::PushL( self ); |
|
109 self->DoInternalizeL( aReadStream ); |
|
110 CleanupStack::Pop( self ); |
|
111 return self; |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CMSRPResponse::ExternalizeL |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 EXPORT_C void CMSRPResponse::ExternalizeL( RWriteStream& aWriteStream ) |
|
119 { |
|
120 // first add the MSRP Message identifier |
|
121 aWriteStream.WriteUint8L( 101 ); // MSRP Response identifier |
|
122 |
|
123 // Reason code |
|
124 TBuf8< KMaxLengthOfStatusCode > value; |
|
125 |
|
126 // status code |
|
127 value.AppendNum( iStatusCode, EDecimal ); |
|
128 aWriteStream.WriteInt32L( value.Length() ); |
|
129 aWriteStream.WriteL( value ); |
|
130 |
|
131 // then reason phrase |
|
132 aWriteStream.WriteInt32L( iReasonPhrase.DesC().Length() ); |
|
133 aWriteStream.WriteL( iReasonPhrase.DesC() ); |
|
134 |
|
135 if( iFromPath ) |
|
136 { |
|
137 aWriteStream.WriteUint8L(1); // more headers in the stream flag |
|
138 iFromPath->ExternalizeValueL( aWriteStream ); |
|
139 } |
|
140 if( iToPath ) |
|
141 { |
|
142 aWriteStream.WriteUint8L(2); // more headers in the stream flag |
|
143 iToPath->ExternalizeValueL( aWriteStream ); |
|
144 } |
|
145 |
|
146 aWriteStream.WriteUint8L(0); // no more headers in the stream flag |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CMSRPResponse::DoInternalizeL |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CMSRPResponse::DoInternalizeL( RReadStream& aReadStream ) |
|
154 { |
|
155 TUint8 dataType( 0 ); |
|
156 |
|
157 RStringPool strings; |
|
158 CleanupClosePushL( strings ); |
|
159 strings.OpenL( MSRPStrConsts::Table ); |
|
160 |
|
161 // read the identifier |
|
162 if ( aReadStream.ReadUint8L() != 101 ) |
|
163 { |
|
164 User::Leave( KErrArgument ); |
|
165 } |
|
166 |
|
167 // The reason code |
|
168 TUint32 codeLength = aReadStream.ReadUint32L(); |
|
169 HBufC8* codeInString = HBufC8::NewLC( codeLength ); |
|
170 TPtr8 codePtr( codeInString->Des() ); |
|
171 aReadStream.ReadL( codePtr, codeLength ); |
|
172 iStatusCode = TMSRPHeaderUtil::ConvertToNumber( codeInString->Des() ); |
|
173 CleanupStack::PopAndDestroy( codeInString ); |
|
174 |
|
175 // then reason phrase |
|
176 TUint32 phraseLength = aReadStream.ReadUint32L(); |
|
177 HBufC8* phraseInString = HBufC8::NewLC( codeLength ); |
|
178 TPtr8 phrasePtr( phraseInString->Des() ); |
|
179 aReadStream.ReadL( phrasePtr, phraseLength ); |
|
180 iReasonPhrase = strings.OpenFStringL( phrasePtr ); |
|
181 CleanupStack::PopAndDestroy( phraseInString ); |
|
182 |
|
183 // and headers |
|
184 do |
|
185 { |
|
186 dataType = aReadStream.ReadUint8L(); |
|
187 |
|
188 switch( dataType ) |
|
189 { |
|
190 case 1: // from path |
|
191 { |
|
192 iFromPath = CMSRPFromPathHeader::InternalizeValueL( aReadStream ); |
|
193 break; |
|
194 } |
|
195 case 2: // to path |
|
196 { |
|
197 iToPath = CMSRPToPathHeader::InternalizeValueL( aReadStream ); |
|
198 break; |
|
199 } |
|
200 default: |
|
201 { |
|
202 // nothing to do |
|
203 break; |
|
204 } |
|
205 } |
|
206 |
|
207 } while( dataType ); |
|
208 |
|
209 CleanupStack::PopAndDestroy( ); // strings, codescanner::cleanup |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CMSRPResponse::IsResponse |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 EXPORT_C TBool CMSRPResponse::IsResponse( const TDesC8& aBuffer ) |
|
217 { |
|
218 if ( aBuffer.Length() ) |
|
219 { |
|
220 if ( aBuffer[ 0 ] == 101 ) |
|
221 { |
|
222 return ETrue; |
|
223 } |
|
224 } |
|
225 |
|
226 return EFalse; |
|
227 } |
|
228 |
|
229 // End of File |