1 /** @file |
|
2 * Copyright (c) 2005-2006 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: CUpnpDownloadCommand |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "upnpdownloadcommand.h" |
|
20 |
|
21 #include "upnppathresolver.h" |
|
22 #include "upnppathelement.h" |
|
23 #include "upnpavcpmanager.h" |
|
24 #include "upnpavcontrolpoint.h" |
|
25 #include "upnphttpmessagefactory.h" |
|
26 |
|
27 #include "upnpstring.h" |
|
28 |
|
29 #include "upnpavcpenginehelper.h" |
|
30 using namespace UpnpAVCPEngine; |
|
31 |
|
32 _LIT8(KFilterFlag, "res,res@protocolInfo"); |
|
33 |
|
34 // Operation option flags |
|
35 const TUint KRemoteAccessOptionGetToStartOfFile = 0x01; |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CUpnpDownloadCommand::NewL |
|
39 // Two-phased constructor. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CUpnpDownloadCommand* CUpnpDownloadCommand::NewL(CUpnpAVCPManager& aAVCPManager, CUpnpAVCPEngineSession& aSession, const RMessage2& aMessage) |
|
43 { |
|
44 CUpnpDownloadCommand* self = new( ELeave ) CUpnpDownloadCommand(aAVCPManager, aSession, aMessage); |
|
45 |
|
46 CleanupStack::PushL( self ); |
|
47 self->ConstructL(); |
|
48 CleanupStack::Pop( self ); |
|
49 |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CUpnpDownloadCommand::ConstructL |
|
55 // Symbian 2nd phase constructor can leave. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CUpnpDownloadCommand::ConstructL() |
|
59 { |
|
60 CUpnpCommand::BaseConstructL(); |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CUpnpDownloadCommand::CUpnpDownloadCommand |
|
65 // C++ default constructor can NOT contain any code, that |
|
66 // might leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CUpnpDownloadCommand::CUpnpDownloadCommand(CUpnpAVCPManager& aAVCPManager, |
|
70 CUpnpAVCPEngineSession& aSession, |
|
71 const RMessage2& aMessage): |
|
72 CUpnpCommand( aAVCPManager, |
|
73 aSession, |
|
74 aMessage) |
|
75 { |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CUpnpDownloadCommand::~CUpnpDownloadCommand |
|
80 // desctructor |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 CUpnpDownloadCommand::~CUpnpDownloadCommand() |
|
84 { |
|
85 delete iObjectId; |
|
86 delete iDestPath; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CUpnpDownloadCommand::SessionId |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 TInt CUpnpDownloadCommand::SessionId() |
|
94 { |
|
95 return CUpnpCommand::SessionId(); |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CUpnpDownloadCommand::RunError |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CUpnpDownloadCommand::RunError(TInt aErrorCode) |
|
103 { |
|
104 return CUpnpCommand::RunError(aErrorCode); |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CUpnpDownloadCommand::ExecuteL |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CUpnpDownloadCommand::ExecuteL() |
|
112 { |
|
113 //ASSERT(iType == EGetFile); |
|
114 |
|
115 HBufC8* uuid = NULL; |
|
116 HBufC8* srcPath = NULL; |
|
117 HBufC* destPath = NULL; |
|
118 |
|
119 DEBUGSTRING(("Execute Download command ")); |
|
120 |
|
121 uuid = ReadDes8FromMessageLC(0); |
|
122 DEBUGSTRING8((" uuid: %S",uuid)); |
|
123 srcPath = ReadDes8FromMessageLC(1); |
|
124 DEBUGSTRING8((" srcPath: %S",srcPath)); |
|
125 destPath = ReadDes16FromMessageLC(2); |
|
126 DEBUGSTRING16((" destPath: %S",destPath)); |
|
127 |
|
128 TPckg<TFilePosition> posPkg(iPosition); |
|
129 iMessage.ReadL( 3,posPkg ); |
|
130 |
|
131 // convert to 8-bit representation |
|
132 iDestPath = HBufC8::NewL(destPath->Length()); |
|
133 iDestPath->Des().Copy(*destPath); |
|
134 |
|
135 iPathResolver = &(iAVCPManager.PathResolverL(*uuid, &iSession)); |
|
136 |
|
137 iPathResolver->ResolveIdL(*srcPath, *this); |
|
138 |
|
139 |
|
140 CleanupStack::PopAndDestroy(destPath); |
|
141 CleanupStack::PopAndDestroy(srcPath); |
|
142 CleanupStack::PopAndDestroy(uuid); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CUpnpDownloadCommand::SetResultL |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 void CUpnpDownloadCommand::SetResultL(const RMessage2& /*aMessage*/) |
|
150 { |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CUpnpDownloadCommand::Interpret |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CUpnpDownloadCommand::InterpretL(TInt aErrorCode, CUpnpAction* aAction) |
|
158 { |
|
159 DEBUGSTRING(("Interpret action response %d", aErrorCode)); |
|
160 HBufC8* resURI = NULL; |
|
161 if (aErrorCode == EHttp200Ok && |
|
162 iPathResolver->GetResUriL( aAction->ArgumentValue( KResult ), *iObjectId, resURI)) |
|
163 { |
|
164 |
|
165 DEBUGSTRING8(("Send HTTP GET request for %S", resURI)); |
|
166 // encode URI |
|
167 CleanupStack::PushL(resURI); |
|
168 HBufC8* resURIencoded = UpnpString::StringReplaceL(*resURI, _L8(" "), _L8("%20")); |
|
169 CleanupStack::PopAndDestroy(resURI); |
|
170 |
|
171 CleanupStack::PushL(resURIencoded); |
|
172 CUpnpHttpMessage* msg = RUpnpHttpMessageFactory::HttpGetL( *resURIencoded ); |
|
173 CleanupStack::PopAndDestroy(resURIencoded); |
|
174 |
|
175 CleanupStack::PushL( msg ); |
|
176 msg->SetInFilenameL( *iDestPath, ETrue ); |
|
177 msg->SetHttpPriority( EPriorityLess ); |
|
178 |
|
179 if (iPosition.iStart != 0 || iPosition.iLength != 0 ) |
|
180 { |
|
181 DEBUGSTRING8((" Use ramge header. From %d to %d (flag:%d) ", |
|
182 iPosition.iStart, iPosition.iLength, iPosition.iFlags)); |
|
183 iUseRange = ETrue; |
|
184 if (iPosition.iFlags == KRemoteAccessOptionGetToStartOfFile) |
|
185 msg->SetRangeL(iPosition.iStart, iPosition.iLength, ETrue); |
|
186 else |
|
187 msg->SetRangeL(iPosition.iStart, iPosition.iLength, EFalse); |
|
188 } |
|
189 |
|
190 iAVCPManager.SendL(msg); |
|
191 iSessionId = msg->SessionId(); |
|
192 iAVCPManager.RegisterForHttp(*this); |
|
193 |
|
194 CleanupStack::PopAndDestroy( msg ); |
|
195 } |
|
196 else |
|
197 { |
|
198 DEBUGSTRING8((" No resouse URI found")); |
|
199 iMessage.Complete(KErrAbort); |
|
200 delete this; |
|
201 } |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CUpnpDownloadCommand::Interpret |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CUpnpDownloadCommand::InterpretL(TInt aErrorCode, CUpnpHttpMessage* /*aMessage*/) |
|
209 { |
|
210 DEBUGSTRING(("HTTP Interpret %d", aErrorCode)); |
|
211 if (aErrorCode == KHttpGetStarted) |
|
212 { |
|
213 // transfer pending |
|
214 return; |
|
215 } |
|
216 iAVCPManager.UnregisterForHttp(*this); |
|
217 if (aErrorCode == EHttp200Ok || aErrorCode == EHttpPartialContent) |
|
218 { |
|
219 if (iUseRange && aErrorCode == EHttp200Ok) |
|
220 { |
|
221 iPosition.iLength = 0; |
|
222 TPckg<TFilePosition> posPkg(iPosition); |
|
223 iMessage.WriteL( 3,posPkg ); |
|
224 } |
|
225 iMessage.Complete(KErrNone); |
|
226 delete this; |
|
227 } |
|
228 else |
|
229 { |
|
230 iMessage.Complete(KErrAbort); |
|
231 delete this; |
|
232 } |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // CUpnpDownloadCommand::ResolvedId |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 void CUpnpDownloadCommand::ResolvedIdL(TInt aErrCode, CUpnpPathElement* aIdElement) |
|
240 { |
|
241 DEBUGSTRING(("ResolvedId %d", aErrCode)); |
|
242 if (aErrCode == KErrNone) |
|
243 { |
|
244 iObjectId = aIdElement->Id().AllocL(); |
|
245 |
|
246 iSessionId = iAVCPManager.CdsBrowseActionL(iPathResolver->UUID(), *iObjectId, KBrowseMetadata,KFilterFlag , 0, 0, KNullDesC8); |
|
247 |
|
248 iAVCPManager.RegisterForAction(*this); |
|
249 } |
|
250 else |
|
251 { |
|
252 iMessage.Complete(KErrNotFound); |
|
253 delete this; |
|
254 } |
|
255 }; |
|
256 |
|
257 //End of File |
|