|
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 |
|
18 #include <mtp/cmtptypearray.h> |
|
19 #include <mtp/cmtpobjectmetadata.h> |
|
20 #include <mtp/mmtpdataproviderframework.h> |
|
21 #include <mtp/mmtpobjectmgr.h> |
|
22 #include <mtp/mtpprotocolconstants.h> |
|
23 #include <mtp/mmtpstoragemgr.h> |
|
24 #include <mtp/tmtptyperequest.h> |
|
25 |
|
26 #include "cmtpdeleteobject.h" |
|
27 #include "mtpdpconst.h" |
|
28 #include "mtpdppanic.h" |
|
29 |
|
30 |
|
31 // Class constants. |
|
32 __FLOG_STMT(_LIT8(KComponent,"DeleteObject");) |
|
33 |
|
34 /** |
|
35 Verification data for the DeleteObject request |
|
36 */ |
|
37 const TMTPRequestElementInfo KMTPDeleteObjectPolicy[] = |
|
38 { |
|
39 {TMTPTypeRequest::ERequestParameter1, EMTPElementTypeObjectHandle, EMTPElementAttrWrite, 1, KMTPHandleAll, 0}, |
|
40 }; |
|
41 |
|
42 |
|
43 /** |
|
44 Standard c++ constructor |
|
45 */ |
|
46 CMTPDeleteObject::CMTPDeleteObject(MMTPDataProviderFramework& aFramework, MMTPConnection& aConnection) : |
|
47 CMTPRequestProcessor(aFramework, aConnection, sizeof(KMTPDeleteObjectPolicy)/sizeof(TMTPRequestElementInfo), KMTPDeleteObjectPolicy) |
|
48 { |
|
49 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
50 __FLOG(_L8("CMTPDeleteObject - Entry")); |
|
51 __FLOG(_L8("CMTPDeleteObject - Exit")); |
|
52 } |
|
53 |
|
54 |
|
55 /** |
|
56 Two-phase construction method |
|
57 @param aFramework The data provider framework |
|
58 @param aConnection The connection from which the request comes |
|
59 @return a pointer to the created request processor object |
|
60 */ |
|
61 EXPORT_C MMTPRequestProcessor* CMTPDeleteObject::NewL(MMTPDataProviderFramework& aFramework, |
|
62 MMTPConnection& aConnection) |
|
63 { |
|
64 CMTPDeleteObject* self = new (ELeave) CMTPDeleteObject(aFramework, aConnection); |
|
65 return self; |
|
66 } |
|
67 |
|
68 /** |
|
69 Destructor |
|
70 */ |
|
71 EXPORT_C CMTPDeleteObject::~CMTPDeleteObject() |
|
72 { |
|
73 __FLOG(_L8("~CMTPDeleteObject - Entry")); |
|
74 __FLOG(_L8("~CMTPDeleteObject - Exit")); |
|
75 __FLOG_CLOSE; |
|
76 } |
|
77 |
|
78 /** |
|
79 Verify the request |
|
80 @return EMTPRespCodeOK if request is verified, otherwise one of the error response codes |
|
81 */ |
|
82 |
|
83 |
|
84 TMTPResponseCode CMTPDeleteObject::CheckRequestL() |
|
85 { |
|
86 __FLOG(_L8("CheckRequestL - Entry")); |
|
87 TMTPResponseCode result(EMTPRespCodeOK); |
|
88 if (IsStoreReadOnlyL(Request().Uint32(TMTPTypeRequest::ERequestParameter1))) |
|
89 { |
|
90 result = EMTPRespCodeStoreReadOnly; |
|
91 } |
|
92 else |
|
93 { |
|
94 result = CMTPRequestProcessor::CheckRequestL(); |
|
95 } |
|
96 __FLOG(_L8("CheckRequestL - Exit")); |
|
97 return result; |
|
98 } |
|
99 |
|
100 void CMTPDeleteObject::DeleteFolderOrFileL(CMTPObjectMetaData* aMeta) |
|
101 { |
|
102 __ASSERT_DEBUG(aMeta, Panic(EMTPDpObjectNull)); |
|
103 if (IsFolderObject(*aMeta)) |
|
104 { |
|
105 __FLOG( _L8("Delete the folder itself which is empty ") ); |
|
106 DeleteFolderL(aMeta); |
|
107 } |
|
108 else |
|
109 { |
|
110 __FLOG(_L8("Going to delete a file.")); |
|
111 DeleteFileL(aMeta); |
|
112 } |
|
113 ProcessFinalPhaseL(); |
|
114 } |
|
115 |
|
116 void CMTPDeleteObject::DeleteFolderL(CMTPObjectMetaData* aMeta) |
|
117 { |
|
118 TParsePtrC fileNameParser(aMeta->DesC(CMTPObjectMetaData::ESuid)); |
|
119 TInt err = KErrNone; |
|
120 if ( fileNameParser.IsWild() ) |
|
121 { |
|
122 err = KErrBadName; |
|
123 } |
|
124 else |
|
125 { |
|
126 err = iFramework.Fs().RmDir(aMeta->DesC(CMTPObjectMetaData::ESuid)); |
|
127 } |
|
128 |
|
129 if( KErrNone == err ) |
|
130 { |
|
131 iFramework.ObjectMgr().RemoveObjectL(aMeta->Uint(CMTPObjectMetaData::EHandle)); |
|
132 iSuccessDeletion = ETrue; |
|
133 } |
|
134 |
|
135 } |
|
136 |
|
137 void CMTPDeleteObject::DeleteFileL(CMTPObjectMetaData* aMeta) |
|
138 { |
|
139 TParsePtrC fileNameParser(aMeta->DesC(CMTPObjectMetaData::ESuid)); |
|
140 TInt err = KErrNone; |
|
141 if ( !fileNameParser.NamePresent() ) |
|
142 { |
|
143 err = KErrBadName; |
|
144 } |
|
145 else if ( fileNameParser.IsWild() ) |
|
146 { |
|
147 err = KErrBadName; |
|
148 } |
|
149 else |
|
150 { |
|
151 err = iFramework.Fs().Delete(aMeta->DesC(CMTPObjectMetaData::ESuid)); |
|
152 } |
|
153 |
|
154 if( KErrNone == err ) |
|
155 { |
|
156 iFramework.ObjectMgr().RemoveObjectL(aMeta->Uint(CMTPObjectMetaData::EHandle)); |
|
157 iSuccessDeletion = ETrue; |
|
158 } |
|
159 else if(KErrAccessDenied == err) |
|
160 { |
|
161 err = KErrBadHandle; |
|
162 iObjectWritePotected = ETrue; |
|
163 } |
|
164 } |
|
165 |
|
166 /** |
|
167 DeleteObject request handler |
|
168 */ |
|
169 void CMTPDeleteObject::ServiceL() |
|
170 { |
|
171 __FLOG(_L8("ServiceL - Entry")); |
|
172 const TUint32 KHandle(Request().Uint32(TMTPTypeRequest::ERequestParameter1)); |
|
173 iObjectWritePotected = EFalse; |
|
174 iSuccessDeletion = EFalse; |
|
175 |
|
176 CMTPObjectMetaData* meta = NULL; |
|
177 meta = iRequestChecker->GetObjectInfo(KHandle); |
|
178 __ASSERT_DEBUG(meta, Panic(EMTPDpObjectNull)); |
|
179 __FLOG_VA((_L8("meta->Uint(CMTPObjectMetaData::EDataProviderId) is %d"), meta->Uint(CMTPObjectMetaData::EDataProviderId))); |
|
180 __FLOG_VA((_L8("iFramework.DataProviderId() is %d"), iFramework.DataProviderId())); |
|
181 |
|
182 if ( meta != NULL && meta->Uint(CMTPObjectMetaData::EDataProviderId) == iFramework.DataProviderId()) |
|
183 { |
|
184 DeleteFolderOrFileL(meta); |
|
185 } |
|
186 else |
|
187 { |
|
188 SendResponseL(EMTPRespCodeInvalidObjectHandle); |
|
189 } |
|
190 |
|
191 __FLOG(_L8("ServiceL - Exit")); |
|
192 } |
|
193 |
|
194 /** |
|
195 Signal to the initiator that the deletion operation has finished with or without error |
|
196 */ |
|
197 void CMTPDeleteObject::ProcessFinalPhaseL() |
|
198 { |
|
199 __FLOG(_L8("ProcessFinalPhaseL - Entry")); |
|
200 TMTPResponseCode rsp = EMTPRespCodeOK; |
|
201 if ( iObjectWritePotected ) |
|
202 { |
|
203 rsp = EMTPRespCodeObjectWriteProtected; |
|
204 } |
|
205 else if ( !iSuccessDeletion ) |
|
206 { |
|
207 rsp = EMTPRespCodeAccessDenied; |
|
208 } |
|
209 SendResponseL(rsp); |
|
210 __FLOG(_L8("ProcessFinalPhaseL - Exit")); |
|
211 } |
|
212 |
|
213 /** |
|
214 Indicates if the specified object is a generic folder association. |
|
215 @param aObject The object meta-data. |
|
216 @return ETrue if the specified object is a generic folder association, |
|
217 otherwise EFalse. |
|
218 */ |
|
219 TBool CMTPDeleteObject::IsFolderObject(const CMTPObjectMetaData& aObject) |
|
220 { |
|
221 return ((aObject.Uint(CMTPObjectMetaData::EFormatCode) == EMTPFormatCodeAssociation) && |
|
222 (aObject.Uint(CMTPObjectMetaData::EFormatSubCode) == EMTPAssociationTypeGenericFolder)); |
|
223 } |
|
224 |
|
225 /** |
|
226 Check whether the store on which the object resides is read only. |
|
227 @return ETrue if the store is read only, EFalse if read-write |
|
228 */ |
|
229 TBool CMTPDeleteObject::IsStoreReadOnlyL(TUint32 aObjectHandle) |
|
230 { |
|
231 __FLOG(_L8("IsStoreReadOnlyL - Entry")); |
|
232 TBool result(EFalse); |
|
233 CMTPObjectMetaData *info(CMTPObjectMetaData::NewLC()); |
|
234 if (iFramework.ObjectMgr().ObjectL(aObjectHandle, *info)) |
|
235 { |
|
236 TInt drive(iFramework.StorageMgr().DriveNumber(info->Uint(CMTPObjectMetaData::EStorageId))); |
|
237 User::LeaveIfError(drive); |
|
238 TVolumeInfo volumeInfo; |
|
239 User::LeaveIfError(iFramework.Fs().Volume(volumeInfo, drive)); |
|
240 if (volumeInfo.iDrive.iMediaAtt == KMediaAttWriteProtected) |
|
241 { |
|
242 result = ETrue; |
|
243 } |
|
244 } |
|
245 CleanupStack::PopAndDestroy(info); |
|
246 __FLOG(_L8("IsStoreReadOnlyL - Exit")); |
|
247 return result; |
|
248 } |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |