|
1 /* |
|
2 * Copyright (c) 2007-2008 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: Implements TCatalogsHttpResponseComposer |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "catalogshttpresponsecomposer.h" |
|
20 |
|
21 #include "catalogshttpincludes.h" |
|
22 #include "catalogsutils.h" |
|
23 #include "catalogskeyvaluepair.h" |
|
24 #include "catalogshttpmessageconstants.h" |
|
25 |
|
26 #include "catalogsdebug.h" |
|
27 |
|
28 |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 HBufC8* TCatalogsHttpResponseComposer::ComposeResponseL( |
|
35 const MCatalogsHttpOperation& aOperation, |
|
36 const TDesC8& aBody ) const |
|
37 { |
|
38 DLTRACEIN(("")); |
|
39 |
|
40 RCatalogsBufferWriter writer; |
|
41 writer.OpenLC(); |
|
42 |
|
43 WriteStatusLineL( aOperation, writer() ); |
|
44 |
|
45 WriteHeadersL( aOperation, writer() ); |
|
46 writer().WriteL( aBody ); |
|
47 |
|
48 HBufC8* result = writer.PtrL().AllocL(); |
|
49 CleanupStack::PopAndDestroy( &writer ); |
|
50 DLINFO(("result: %S", result )); |
|
51 return result; |
|
52 } |
|
53 |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 void TCatalogsHttpResponseComposer::WriteStatusLineL( |
|
60 const MCatalogsHttpOperation& aOperation, |
|
61 RWriteStream& aStream ) const |
|
62 { |
|
63 // HTTP-version SP Status-Code SP Reason-Phrase CRLF |
|
64 aStream.WriteL( CatalogsHttpMessageConstants::KHttpVersion ); |
|
65 aStream.WriteL( CatalogsHttpMessageConstants::KSpace ); |
|
66 |
|
67 TBuf8<3> statusBuf; |
|
68 statusBuf.Num( aOperation.StatusCode() ); |
|
69 aStream.WriteL( statusBuf ); |
|
70 |
|
71 aStream.WriteL( CatalogsHttpMessageConstants::KSpace ); |
|
72 aStream.WriteL( aOperation.StatusText() ); |
|
73 aStream.WriteL( CatalogsHttpMessageConstants::KCrLf ); |
|
74 |
|
75 } |
|
76 |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void TCatalogsHttpResponseComposer::WriteHeadersL( |
|
83 const MCatalogsHttpOperation& aOperation, |
|
84 RWriteStream& aStream ) const |
|
85 { |
|
86 DLTRACEIN(("")); |
|
87 const RPointerArray<CCatalogsKeyValuePair>& headers( |
|
88 aOperation.ResponseHeadersL().Headers() ); |
|
89 |
|
90 DLTRACE(("Writing %d headers", headers.Count() )); |
|
91 for ( TInt i = 0; i < headers.Count(); ++i ) |
|
92 { |
|
93 WriteHeaderL( *headers[i], aStream ); |
|
94 } |
|
95 |
|
96 // End of headers |
|
97 aStream.WriteL( CatalogsHttpMessageConstants::KCrLf ); |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void TCatalogsHttpResponseComposer::WriteHeaderL( |
|
106 const CCatalogsKeyValuePair& aHeader, |
|
107 RWriteStream& aStream ) const |
|
108 { |
|
109 aStream.WriteL( aHeader.Key() ); |
|
110 aStream.WriteL( CatalogsHttpMessageConstants::KColon ); |
|
111 aStream.WriteL( CatalogsHttpMessageConstants::KSpace ); |
|
112 aStream.WriteL( aHeader.Value() ); |
|
113 aStream.WriteL( CatalogsHttpMessageConstants::KCrLf ); |
|
114 } |