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: CUpnpHttpFileServeTransaction implementation. |
|
15 * |
|
16 */ |
|
17 #include "upnphttpfileservetransaction.h" |
|
18 #include "upnpdlnafilter.h" |
|
19 #include "upnpdlnafilterheaders.h" |
|
20 #include "upnperrors.h" |
|
21 #include "upnpcons.h" |
|
22 |
|
23 // --------------------------------------------------------------------------- |
|
24 // CUpnpHttpFileServeTransaction::NewL |
|
25 // |
|
26 // --------------------------------------------------------------------------- |
|
27 // |
|
28 CUpnpHttpFileServeTransaction* CUpnpHttpFileServeTransaction::NewL( |
|
29 CUpnpDlnaFilter& aClientContext, const TInetAddr& aSender, const TDesC8& aUri ) |
|
30 { |
|
31 CUpnpHttpFileServeTransaction* self = |
|
32 new (ELeave) CUpnpHttpFileServeTransaction( aClientContext ); |
|
33 CleanupStack::PushL( self ); |
|
34 self->ConstructL( aSender, aUri ); |
|
35 CleanupStack::Pop( self ); |
|
36 return self; |
|
37 } |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // CUpnpHttpFileServeTransaction::ConstructL |
|
41 // |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 void CUpnpHttpFileServeTransaction::ConstructL( |
|
45 const TInetAddr& aSender, const TDesC8& aSenderUri ) |
|
46 { |
|
47 iFilterHeaders = CUpnpDlnaFilterHeaders::NewL( ); |
|
48 iSender = aSender; |
|
49 iSenderUri = aSenderUri.AllocL(); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CUpnpHttpFileServeTransaction::FilterHeaders |
|
54 // |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CUpnpDlnaFilterHeaders& CUpnpHttpFileServeTransaction::FilterHeaders() |
|
58 { |
|
59 return *iFilterHeaders; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // CUpnpHttpFileServeTransaction::CUpnpHttpFileServeTransaction |
|
64 // |
|
65 // --------------------------------------------------------------------------- |
|
66 // |
|
67 CUpnpHttpFileServeTransaction::CUpnpHttpFileServeTransaction( CUpnpDlnaFilter& aClientContext ) |
|
68 : iClientContext( aClientContext ) |
|
69 { } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CUpnpHttpFileServeTransaction::~CUpnpHttpFileServeTransaction |
|
73 // |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CUpnpHttpFileServeTransaction::~CUpnpHttpFileServeTransaction() |
|
77 { |
|
78 delete iFilterHeaders; |
|
79 delete iSenderUri; |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CUpnpHttpFileServeTransaction::OnCallbackL |
|
84 // |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CUpnpHttpFileServeTransaction::OnCallbackL( TUpnpHttpServerEvent aEvent ) |
|
88 { |
|
89 TRAPD( err, DoCallbackL( aEvent ) ); |
|
90 if ( err ) |
|
91 { |
|
92 SetHttpCode( err ); |
|
93 } |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CUpnpHttpFileServeTransaction::SenderUri |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 const TDesC8& CUpnpHttpFileServeTransaction::SenderUri() |
|
102 { |
|
103 return *iSenderUri; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CUpnpHttpFileServeTransaction::PathWithNewMethodL |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 HBufC16* CUpnpHttpFileServeTransaction::PathWithNewMethodL() |
|
112 { |
|
113 return iPathWithNewMethod.AllocL(); |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // CUpnpHttpFileServeTransaction::DoCallbackL |
|
118 // |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 void CUpnpHttpFileServeTransaction::DoCallbackL( TUpnpHttpServerEvent aEvent ) |
|
122 { |
|
123 switch ( aEvent ) |
|
124 { |
|
125 case EOnRequestStart: |
|
126 { |
|
127 // 1. Format request file path |
|
128 // |
|
129 |
|
130 TRAPD( error, iClientContext.FormatPathL( this, iPathWithNewMethod ) ); |
|
131 |
|
132 |
|
133 if ( error != KErrNone ) |
|
134 { |
|
135 SetHttpCode( error ); |
|
136 } |
|
137 else if ( iPathWithNewMethod.Length() == 0 ) |
|
138 { |
|
139 SetHttpCode( -EHttpNotFound ); |
|
140 // Bad name, so such file doesn't exist and cannot be returned. |
|
141 } |
|
142 else |
|
143 { |
|
144 error = iClientContext.AuthorizeRequestL( iPathWithNewMethod, iSender ); |
|
145 if ( error == KErrNone ) |
|
146 { |
|
147 RFile file; |
|
148 if ( file.Open( iClientContext.FileSession(), |
|
149 iPathWithNewMethod, |
|
150 EFileShareReadersOnly | EFileRead ) == KErrNone ) |
|
151 { |
|
152 SetDataSourceL( file ); |
|
153 } |
|
154 else |
|
155 { |
|
156 SetHttpCode( -EHttpNotFound ); |
|
157 } |
|
158 } |
|
159 else |
|
160 { |
|
161 SetHttpCode( error ); |
|
162 } |
|
163 } |
|
164 break; |
|
165 } |
|
166 case EOnComplete: |
|
167 break; |
|
168 case EOnResponseStart: |
|
169 InitializeFilterHeadersL(); |
|
170 SetHttpCode( iClientContext.PrepareHeaderL( *this ) ); |
|
171 break; |
|
172 default: |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 void CUpnpHttpFileServeTransaction::InitializeFilterHeadersL() |
|
178 { |
|
179 //Copy current KHdrContentFeatures and KHdrTransferMode to filterHeaders |
|
180 if ( QueryRequestHeader( UpnpDLNA::KHdrContentFeatures ).Length() > 0 ) |
|
181 { |
|
182 iFilterHeaders->AddHeaderL( UpnpDLNA::KHdrContentFeatures, |
|
183 QueryRequestHeader( UpnpDLNA::KHdrContentFeatures ) ); |
|
184 } |
|
185 if ( QueryRequestHeader( UpnpDLNA::KHdrTransferMode ).Length() > 0 ) |
|
186 { |
|
187 iFilterHeaders->AddHeaderL( UpnpDLNA::KHdrTransferMode, |
|
188 QueryRequestHeader( UpnpDLNA::KHdrTransferMode ) ); |
|
189 } |
|
190 } |
|
191 |
|