|
1 /** @file |
|
2 * Copyright (c) 2009 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: CUpnpHttpServerTransaction implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <f32file.h> |
|
19 #include "upnpcons.h" |
|
20 #include "upnphttpservertransaction.h" |
|
21 #include "upnphttpmessage.h" |
|
22 #include "upnpfileutils.h" |
|
23 #include "upnphttpservertransactioncreator.h" |
|
24 #define KLogFile _L("DLNAWebServer.txt") |
|
25 #include "upnpcustomlog.h" |
|
26 // --------------------------------------------------------------------------- |
|
27 // CUpnpHttpServerTransaction::CUpnpHttpServerTransaction |
|
28 // |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 EXPORT_C CUpnpHttpServerTransaction::CUpnpHttpServerTransaction() |
|
32 { |
|
33 } |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // CUpnpHttpServerTransaction::~CUpnpHttpServerTransaction |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 EXPORT_C CUpnpHttpServerTransaction::~CUpnpHttpServerTransaction() |
|
41 { |
|
42 iHeaderBuffer.Close(); |
|
43 iFile.Close(); |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CUpnpHttpServerTransaction::SetDataSourceL |
|
48 // used for GET |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 EXPORT_C void CUpnpHttpServerTransaction::SetDataSourceL( RFile& aFile ) |
|
52 { |
|
53 iFile.Close(); |
|
54 iFile = aFile; |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CUpnpHttpServerTransaction::SetDataSinkL |
|
59 // used for POST |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 EXPORT_C void CUpnpHttpServerTransaction::SetDataSinkL( RFile& aFile ) |
|
63 { |
|
64 iFile.Close(); |
|
65 iFile = aFile; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // CUpnpHttpServerTransaction::DataSource |
|
70 // used for GET |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 RFile& CUpnpHttpServerTransaction::DataSource() |
|
74 { |
|
75 return iFile; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // CUpnpHttpServerTransaction::DataSink |
|
80 // used for POST |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 RFile& CUpnpHttpServerTransaction::DataSink() |
|
84 { |
|
85 return iFile; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CUpnpHttpServerTransaction::AddResponseHeaderL |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 EXPORT_C void CUpnpHttpServerTransaction::AddResponseHeaderL( const TDesC8& aName, |
|
94 const TDesC8& aValue ) |
|
95 { |
|
96 TInt newLength = iHeaderBuffer.Length() + aValue.Length() |
|
97 + UpnpString::KDoubleLineFeed().Length(); |
|
98 TBool nameUsed = ( aName != KNullDesC8() ); |
|
99 TInt dlfLen = UpnpString::KDoubleLineFeed().Length(); |
|
100 |
|
101 if ( iHeaderBuffer.Right( dlfLen ).Compare( UpnpString::KDoubleLineFeed() ) == 0 ) |
|
102 { // if buffer ends with double line feed then remove it and append line feed |
|
103 iHeaderBuffer.Delete( iHeaderBuffer.Length() - dlfLen, dlfLen ); |
|
104 iHeaderBuffer.Append( UpnpString::KLineFeed() ); |
|
105 } |
|
106 |
|
107 if ( nameUsed ) |
|
108 { |
|
109 newLength += UpnpString::KColon().Length() + UpnpString::KSpace().Length() |
|
110 + aName.Length(); |
|
111 } |
|
112 |
|
113 iHeaderBuffer.ReAllocL( newLength ); |
|
114 |
|
115 if ( nameUsed ) |
|
116 { |
|
117 iHeaderBuffer.Append( aName ); |
|
118 iHeaderBuffer.Append( UpnpString::KColon() ); |
|
119 iHeaderBuffer.Append( UpnpString::KSpace() ); |
|
120 } |
|
121 else |
|
122 { |
|
123 iHeaderBuffer.Zero(); |
|
124 } |
|
125 |
|
126 iHeaderBuffer.Append( aValue ); |
|
127 iHeaderBuffer.Append( UpnpString::KLineFeed() ); |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // CUpnpHttpServerTransaction::QueryResponseHeader |
|
132 // |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 EXPORT_C const TDesC8& CUpnpHttpServerTransaction::QueryResponseHeader() |
|
136 { |
|
137 if ( iHeaderBuffer.Find( UpnpString::KDoubleLineFeed() ) == KErrNotFound ) |
|
138 { |
|
139 if ( iHeaderBuffer.Right( UpnpString::KLineFeed().Length() ). |
|
140 Compare( UpnpString::KLineFeed() ) == 0 ) |
|
141 { |
|
142 if ( iHeaderBuffer.ReAlloc( iHeaderBuffer.Length() + |
|
143 UpnpString::KLineFeed().Length() ) == KErrNone ) |
|
144 { |
|
145 iHeaderBuffer.Append( UpnpString::KLineFeed() ); |
|
146 } |
|
147 } |
|
148 else |
|
149 { |
|
150 if ( iHeaderBuffer.ReAlloc( iHeaderBuffer.Length() + |
|
151 UpnpString::KDoubleLineFeed().Length() ) == KErrNone ) |
|
152 { |
|
153 iHeaderBuffer.Append( UpnpString::KDoubleLineFeed() ); |
|
154 } |
|
155 } |
|
156 } |
|
157 return iHeaderBuffer; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CUpnpHttpServerTransaction::SetHttpCode |
|
162 // |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C void CUpnpHttpServerTransaction::SetHttpCode( TInt aCode ) |
|
166 { |
|
167 iHttpCode = aCode; |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // CUpnpHttpServerTransaction::QueryRequestHeader |
|
172 // |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 EXPORT_C TDesC8& CUpnpHttpServerTransaction::QueryRequestHeader( const TDesC8& aHeaderName ) |
|
176 { |
|
177 return iRequest->GetHeaderValue( aHeaderName ); |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CUpnpHttpServerTransaction::Error |
|
182 // |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 EXPORT_C TInt CUpnpHttpServerTransaction::Error() |
|
186 { |
|
187 return iHttpCode; |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CUpnpHttpServerTransaction::SetRequest |
|
192 // |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 EXPORT_C void CUpnpHttpServerTransaction::SetRequest( CUpnpHttpMessage* aRequest ) |
|
196 { |
|
197 iRequest = aRequest; |
|
198 } |
|
199 |
|
200 |