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: CUpnpCreateCommand |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "upnpcreatecommand.h" |
|
20 |
|
21 #include "upnppathresolver.h" |
|
22 #include "upnppathelement.h" |
|
23 #include "upnpavcpmanager.h" |
|
24 #include "upnpavcontrolpoint.h" |
|
25 |
|
26 #include "upnpavcpenginehelper.h" |
|
27 using namespace UpnpAVCPEngine; |
|
28 #include "upnpstring.h" |
|
29 |
|
30 |
|
31 _LIT8(KCreateFileTemplate, |
|
32 "<DIDL-Lite xmlns:dc=\"http://purl.org/dc/elements/1.1/\" \ |
|
33 xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\" \ |
|
34 xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"> \ |
|
35 <item parentID=\"%S\" restricted=\"false\"> \ |
|
36 <dc:title>%S</dc:title> \ |
|
37 <upnp:class>object.item</upnp:class> \ |
|
38 <res protocolInfo=\"*:*:*:*\"></res> \ |
|
39 </item> \ |
|
40 </DIDL-Lite>"); |
|
41 |
|
42 _LIT8(KCreateDirTemplate, |
|
43 "<DIDL-Lite xmlns:dc=\"http://purl.org/dc/elements/1.1/\" \ |
|
44 xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\" \ |
|
45 xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"> \ |
|
46 <container parentID=\"%S\" restricted=\"false\"> \ |
|
47 <dc:title>%S</dc:title> \ |
|
48 <upnp:class>object.container</upnp:class> \ |
|
49 </container> \ |
|
50 </DIDL-Lite>"); |
|
51 |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CUpnpCreateCommand::NewL |
|
55 // Two-phased constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CUpnpCreateCommand* CUpnpCreateCommand::NewL(CUpnpAVCPManager& aAVCPManager, CUpnpAVCPEngineSession& aSession, const RMessage2& aMessage) |
|
59 { |
|
60 CUpnpCreateCommand* self = new( ELeave ) CUpnpCreateCommand(aAVCPManager, aSession, aMessage); |
|
61 |
|
62 CleanupStack::PushL( self ); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop( self ); |
|
65 |
|
66 return self; |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CUpnpCreateCommand::ConstructL |
|
71 // Symbian 2nd phase constructor can leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 void CUpnpCreateCommand::ConstructL() |
|
75 { |
|
76 CUpnpCommand::BaseConstructL(); |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CUpnpCreateCommand::CUpnpCreateCommand |
|
81 // C++ default constructor can NOT contain any code, that |
|
82 // might leave. |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CUpnpCreateCommand::CUpnpCreateCommand(CUpnpAVCPManager& aAVCPManager, |
|
86 CUpnpAVCPEngineSession& aSession, |
|
87 const RMessage2& aMessage): |
|
88 CUpnpCommand( aAVCPManager, |
|
89 aSession, |
|
90 aMessage) |
|
91 { |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CUpnpCreateCommand::~CUpnpCreateCommand |
|
96 // desctructor |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 CUpnpCreateCommand::~CUpnpCreateCommand() |
|
100 { |
|
101 delete iObjectId; |
|
102 delete iTargetName; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CUpnpCreateCommand::SessionId |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 TInt CUpnpCreateCommand::SessionId() |
|
110 { |
|
111 return CUpnpCommand::SessionId(); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CUpnpCreateCommand::RunError |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CUpnpCreateCommand::RunError(TInt aErrorCode) |
|
119 { |
|
120 return CUpnpCommand::RunError(aErrorCode); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CUpnpCreateCommand::ExecuteL |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CUpnpCreateCommand::ExecuteL() |
|
128 { |
|
129 //ASSERT(iType == ECreateDirectory || iType == ECreateFile ); |
|
130 |
|
131 HBufC8* uuid = NULL; |
|
132 HBufC8* path = NULL; |
|
133 DEBUGSTRING(("Execute Create command ")); |
|
134 uuid = ReadDes8FromMessageLC(0); |
|
135 DEBUGSTRING8((" uuid: %S",uuid)); |
|
136 path = ReadDes8FromMessageLC(1); |
|
137 DEBUGSTRING8((" path: %S",path)); |
|
138 |
|
139 TPtr8 pathPtr = path->Des(); |
|
140 // removes also last element of path |
|
141 iTargetName = GetLastPathElementL(pathPtr); |
|
142 |
|
143 iPathResolver = &(iAVCPManager.PathResolverL(*uuid, &iSession)); |
|
144 iPathResolver->ResolveIdL(*path, *this); |
|
145 |
|
146 CleanupStack::PopAndDestroy(path); |
|
147 CleanupStack::PopAndDestroy(uuid); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CUpnpCreateCommand::SetResultL |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CUpnpCreateCommand::SetResultL(const RMessage2& /*aMessage*/) |
|
155 { |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CUpnpCreateCommand::Interpret |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CUpnpCreateCommand::InterpretL(TInt aErrorCode, CUpnpAction* aAction) |
|
163 { |
|
164 DEBUGSTRING(("Interpret action response %d", aErrorCode)); |
|
165 if (aErrorCode == EHttp200Ok ) |
|
166 { |
|
167 if (iType == ECreateDirectory) |
|
168 { |
|
169 iMessage.Complete(KErrNone); |
|
170 } |
|
171 else |
|
172 { |
|
173 if(iPathResolver->BrowseCreateObjectL( aAction->ArgumentValue( KResult ))) |
|
174 { |
|
175 iMessage.Complete(KErrNone); |
|
176 } |
|
177 else |
|
178 { |
|
179 iMessage.Complete(KErrAbort); |
|
180 } |
|
181 } |
|
182 |
|
183 } |
|
184 else |
|
185 { |
|
186 iMessage.Complete(KErrAbort); |
|
187 } |
|
188 delete this; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CUpnpCreateCommand::ResolvedId |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CUpnpCreateCommand::ResolvedIdL(TInt aErrCode, CUpnpPathElement* aIdElement) |
|
196 { |
|
197 if (aErrCode == KErrNone) |
|
198 { |
|
199 iElement = aIdElement; |
|
200 iObjectId = aIdElement->Id().AllocL(); |
|
201 HBufC8* createMsg; |
|
202 if (iType == ECreateDirectory ) |
|
203 { |
|
204 createMsg = HBufC8::NewLC(KCreateDirTemplate().Length() + iObjectId->Length() + iTargetName->Length()); |
|
205 createMsg->Des().AppendFormat(KCreateDirTemplate, iObjectId, iTargetName); |
|
206 } |
|
207 else |
|
208 { |
|
209 createMsg = HBufC8::NewLC(KCreateFileTemplate().Length() + iObjectId->Length() + iTargetName->Length()); |
|
210 createMsg->Des().AppendFormat(KCreateFileTemplate, iObjectId, iTargetName); |
|
211 } |
|
212 HBufC8* encoded = UpnpString::EncodeXmlStringL( createMsg ); |
|
213 CleanupStack::PopAndDestroy(createMsg); |
|
214 CleanupStack::PushL(encoded); |
|
215 |
|
216 iSessionId = iAVCPManager.CdsCreateObjectActionL(iPathResolver->UUID(), *iObjectId, *encoded); |
|
217 iAVCPManager.RegisterForAction(*this); |
|
218 |
|
219 CleanupStack::PopAndDestroy(encoded); |
|
220 |
|
221 } |
|
222 else |
|
223 { |
|
224 iMessage.Complete(KErrNotFound); |
|
225 delete this; |
|
226 } |
|
227 |
|
228 } |
|