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