|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <bautils.h> |
|
17 #include <f32file.h> |
|
18 #include <mtp/tmtptyperequest.h> |
|
19 #include <mtp/mmtpdataproviderframework.h> |
|
20 #include <mtp/mtpprotocolconstants.h> |
|
21 #include <mtp/cmtptypestring.h> |
|
22 #include <mtp/mmtpobjectmgr.h> |
|
23 |
|
24 #include "cmtpsetobjectpropvalue.h" |
|
25 #include "mtpdpconst.h" |
|
26 #include "mtpdppanic.h" |
|
27 #include "cmtpdataprovidercontroller.h" |
|
28 #include "mtpframeworkconst.h" |
|
29 #include "rmtpdpsingletons.h" |
|
30 #include "rmtputility.h" |
|
31 |
|
32 /** |
|
33 Verification data for the SetObjectPropValue request |
|
34 */ |
|
35 const TMTPRequestElementInfo KMTPSetObjectPropValuePolicy[] = |
|
36 { |
|
37 {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeObjectHandle, EMTPElementAttrWrite, 0, 0, 0}, |
|
38 }; |
|
39 |
|
40 /** |
|
41 Two-phase construction method |
|
42 @param aPlugin The data provider plugin |
|
43 @param aFramework The data provider framework |
|
44 @param aConnection The connection from which the request comes |
|
45 @return a pointer to the created request processor object |
|
46 */ |
|
47 EXPORT_C MMTPRequestProcessor* CMTPSetObjectPropValue::NewL( |
|
48 MMTPDataProviderFramework& aFramework, |
|
49 MMTPConnection& aConnection) |
|
50 { |
|
51 CMTPSetObjectPropValue* self = new (ELeave) CMTPSetObjectPropValue(aFramework, aConnection); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 /** |
|
59 Destructor |
|
60 */ |
|
61 EXPORT_C CMTPSetObjectPropValue::~CMTPSetObjectPropValue() |
|
62 { |
|
63 delete iMTPTypeString; |
|
64 iSingleton.Close(); |
|
65 iDpSingletons.Close(); |
|
66 delete iObjMeta; |
|
67 } |
|
68 |
|
69 /** |
|
70 Standard c++ constructor |
|
71 */ |
|
72 CMTPSetObjectPropValue::CMTPSetObjectPropValue( |
|
73 MMTPDataProviderFramework& aFramework, |
|
74 MMTPConnection& aConnection) |
|
75 :CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPSetObjectPropValuePolicy)/sizeof(TMTPRequestElementInfo), KMTPSetObjectPropValuePolicy), |
|
76 iRfs(aFramework.Fs()) |
|
77 { |
|
78 } |
|
79 |
|
80 |
|
81 /** |
|
82 A helper function of CheckRequestL. To check whether the object property code is readonly. |
|
83 @param aObjectPropCode the object property code passed in. |
|
84 @return ETrue if the object property code is readonly. Otherwise EFalse. |
|
85 */ |
|
86 TBool CMTPSetObjectPropValue::IsPropCodeReadonly(TUint32 aObjectPropCode) |
|
87 { |
|
88 TBool returnCode = EFalse; |
|
89 if(aObjectPropCode == EMTPObjectPropCodeStorageID |
|
90 || aObjectPropCode == EMTPObjectPropCodeObjectFormat |
|
91 || aObjectPropCode == EMTPObjectPropCodeProtectionStatus |
|
92 || aObjectPropCode == EMTPObjectPropCodeObjectSize |
|
93 || aObjectPropCode == EMTPObjectPropCodeParentObject |
|
94 || aObjectPropCode == EMTPObjectPropCodePersistentUniqueObjectIdentifier) |
|
95 { |
|
96 returnCode = ETrue; |
|
97 } |
|
98 return returnCode; |
|
99 } |
|
100 |
|
101 /** |
|
102 Verify request |
|
103 */ |
|
104 TMTPResponseCode CMTPSetObjectPropValue::CheckRequestL() |
|
105 { |
|
106 TMTPResponseCode responseCode = CMTPRequestProcessor::CheckRequestL(); |
|
107 |
|
108 TUint32 handle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
109 CMTPObjectMetaData* meta = iRequestChecker->GetObjectInfo(handle); |
|
110 __ASSERT_DEBUG(meta, Panic(EMTPDpObjectNull)); |
|
111 |
|
112 if(responseCode == EMTPRespCodeOK) |
|
113 { |
|
114 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
115 |
|
116 if(propCode != EMTPObjectPropCodeAssociationType && propCode != EMTPObjectPropCodeAssociationDesc) |
|
117 { |
|
118 const TInt count = sizeof(KMTPDpSupportedProperties) / sizeof(TUint16); |
|
119 TInt i = 0; |
|
120 for(i = 0; i < count; i++) |
|
121 { |
|
122 if(KMTPDpSupportedProperties[i] == propCode |
|
123 && IsPropCodeReadonly(propCode)) |
|
124 // Object property code supported, but cann't be set. |
|
125 { |
|
126 responseCode = EMTPRespCodeAccessDenied; |
|
127 break; |
|
128 } |
|
129 else if(KMTPDpSupportedProperties[i] == propCode) |
|
130 // Object property code supported and can be set. |
|
131 { |
|
132 break; |
|
133 } |
|
134 } |
|
135 if(i == count) |
|
136 { |
|
137 responseCode = EMTPRespCodeInvalidObjectPropCode; |
|
138 } |
|
139 } |
|
140 else if(meta->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation) |
|
141 { |
|
142 responseCode = EMTPRespCodeInvalidObjectFormatCode; |
|
143 } |
|
144 } |
|
145 else |
|
146 { |
|
147 const TDesC& suid(meta->DesC(CMTPObjectMetaData::ESuid)); |
|
148 TEntry entry; |
|
149 User::LeaveIfError( iFramework.Fs().Entry(suid, entry) ); |
|
150 |
|
151 //According to spec, there are 4 statuses: No Protection; Read-only; Read-only data; Non-transferrable data |
|
152 //Currently, we only use FS's Read-only attribute to support No Protection and Read-only statuses. |
|
153 //so if the attribute is read-only, we will return EMTPRespCodeAccessDenied. |
|
154 if (entry.IsReadOnly()) |
|
155 { |
|
156 responseCode = EMTPRespCodeAccessDenied; |
|
157 } |
|
158 } |
|
159 |
|
160 return responseCode; |
|
161 } |
|
162 |
|
163 /** |
|
164 SetObjectPropValue request handler |
|
165 */ |
|
166 void CMTPSetObjectPropValue::ServiceL() |
|
167 { |
|
168 __ASSERT_DEBUG(iRequestChecker, Panic(EMTPDpRequestCheckNull)); |
|
169 TUint32 handle = Request().Uint32(TMTPTypeRequest::ERequestParameter1); |
|
170 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
171 |
|
172 iFramework.ObjectMgr().ObjectL(TMTPTypeUint32(handle), *iObjMeta); |
|
173 User::LeaveIfError(iRfs.Entry(iObjMeta->DesC(CMTPObjectMetaData::ESuid), iFileEntry)); |
|
174 |
|
175 delete iMTPTypeString; |
|
176 iMTPTypeString = NULL; |
|
177 iMTPTypeString = CMTPTypeString::NewL(); |
|
178 switch(propCode) |
|
179 { |
|
180 case EMTPObjectPropCodeDateModified: |
|
181 case EMTPObjectPropCodeObjectFileName: |
|
182 case EMTPObjectPropCodeName: |
|
183 ReceiveDataL(*iMTPTypeString); |
|
184 break; |
|
185 case EMTPObjectPropCodeNonConsumable: |
|
186 ReceiveDataL(iMTPTypeUint8); |
|
187 break; |
|
188 case EMTPObjectPropCodeAssociationType: |
|
189 { |
|
190 ReceiveDataL(iMTPTypeUint16); |
|
191 } |
|
192 break; |
|
193 case EMTPObjectPropCodeAssociationDesc: |
|
194 { |
|
195 ReceiveDataL(iMTPTypeUint32); |
|
196 } |
|
197 break; |
|
198 |
|
199 case EMTPObjectPropCodeStorageID: |
|
200 case EMTPObjectPropCodeObjectFormat: |
|
201 case EMTPObjectPropCodeProtectionStatus: |
|
202 case EMTPObjectPropCodeObjectSize: |
|
203 case EMTPObjectPropCodeParentObject: |
|
204 case EMTPObjectPropCodePersistentUniqueObjectIdentifier: |
|
205 { |
|
206 //!!! Never come here, it should be blocked on CheckRequestL() |
|
207 // and EMTPRespCodeAccessDenied will be reported. |
|
208 //No break sentance, goto Panic |
|
209 } |
|
210 default: |
|
211 Panic(EMTPDpUnsupportedProperty); |
|
212 } |
|
213 } |
|
214 |
|
215 /** |
|
216 Apply the references to the specified object |
|
217 @return EFalse |
|
218 */ |
|
219 TBool CMTPSetObjectPropValue::DoHandleResponsePhaseL() |
|
220 { |
|
221 TMTPResponseCode responseCode = EMTPRespCodeInvalidObjectPropFormat; |
|
222 TUint32 propCode = Request().Uint32(TMTPTypeRequest::ERequestParameter2); |
|
223 |
|
224 switch(propCode) |
|
225 { |
|
226 case EMTPObjectPropCodeDateModified: |
|
227 { |
|
228 TTime modifiedTime; |
|
229 if( iDpSingletons.MTPUtility().MTPTimeStr2TTime(iMTPTypeString->StringChars(), modifiedTime) ) |
|
230 { |
|
231 iRfs.SetModified( iObjMeta->DesC(CMTPObjectMetaData::ESuid), modifiedTime ); |
|
232 responseCode = EMTPRespCodeOK; |
|
233 |
|
234 } |
|
235 else |
|
236 { |
|
237 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
238 } |
|
239 } |
|
240 break; |
|
241 |
|
242 case EMTPObjectPropCodeObjectFileName: |
|
243 { |
|
244 |
|
245 TRAPD(err, iDpSingletons.MTPUtility().RenameObjectL(iObjMeta->Uint(CMTPObjectMetaData::EHandle),iMTPTypeString->StringChars())) ; |
|
246 if( KErrNone == err ) |
|
247 { |
|
248 responseCode = EMTPRespCodeOK; |
|
249 } |
|
250 else if(KErrNotFound == err) |
|
251 { |
|
252 responseCode = EMTPRespCodeInvalidObjectHandle; |
|
253 } |
|
254 else if( KErrAlreadyExists == err) |
|
255 { |
|
256 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
257 } |
|
258 else |
|
259 { |
|
260 responseCode = EMTPRespCodeAccessDenied; |
|
261 } |
|
262 } |
|
263 break; |
|
264 case EMTPObjectPropCodeName: |
|
265 { |
|
266 //Might need to consider to save this name into meta-data base. |
|
267 //Notify all the Data Providers if the Owner of the object is DeviceDP |
|
268 const TDesC& name = iMTPTypeString->StringChars(); |
|
269 if(name != iFileEntry.iName) |
|
270 { |
|
271 iObjMeta->SetDesCL( CMTPObjectMetaData::EName, name); |
|
272 iFramework.ObjectMgr().ModifyObjectL(*iObjMeta); |
|
273 } |
|
274 responseCode = EMTPRespCodeOK; |
|
275 } |
|
276 break; |
|
277 case EMTPObjectPropCodeNonConsumable: |
|
278 { |
|
279 iObjMeta->SetUint( CMTPObjectMetaData::ENonConsumable, iMTPTypeUint8.Value()); |
|
280 iFramework.ObjectMgr().ModifyObjectL(*iObjMeta); |
|
281 responseCode = EMTPRespCodeOK; |
|
282 } |
|
283 break; |
|
284 case EMTPObjectPropCodeAssociationType: |
|
285 { |
|
286 if (EModeMTP != iFramework.Mode()) |
|
287 { |
|
288 responseCode = EMTPRespCodeOK; |
|
289 } |
|
290 else if( iMTPTypeUint16.Value() != EMTPAssociationTypeGenericFolder ) |
|
291 { |
|
292 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
293 } |
|
294 else |
|
295 { |
|
296 responseCode = EMTPRespCodeOK; |
|
297 } |
|
298 } |
|
299 break; |
|
300 case EMTPObjectPropCodeAssociationDesc: |
|
301 { |
|
302 if(TUint32(iMTPTypeUint32.Value()) == 0 ) |
|
303 { |
|
304 responseCode = EMTPRespCodeOK; |
|
305 } |
|
306 else |
|
307 responseCode = EMTPRespCodeInvalidObjectPropValue; |
|
308 } |
|
309 break; |
|
310 |
|
311 |
|
312 default: |
|
313 Panic(EMTPDpUnsupportedProperty); |
|
314 } |
|
315 |
|
316 SendResponseL(responseCode); |
|
317 return EFalse; |
|
318 } |
|
319 |
|
320 TBool CMTPSetObjectPropValue::HasDataphase() const |
|
321 { |
|
322 return ETrue; |
|
323 } |
|
324 |
|
325 /** |
|
326 Second-phase construction |
|
327 */ |
|
328 void CMTPSetObjectPropValue::ConstructL() |
|
329 { |
|
330 iSingleton.OpenL(); |
|
331 iObjMeta = CMTPObjectMetaData::NewL(); |
|
332 iDpSingletons.OpenL(iFramework); |
|
333 } |
|
334 |