|
1 /* |
|
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: |
|
15 * Resolves the protection status for a file. |
|
16 * Protection checks include: |
|
17 * - CommonContenPolicy |
|
18 * - OMA DRM |
|
19 * - Java SuperD |
|
20 * |
|
21 */ |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 // INCLUDE FILES |
|
27 #include <e32std.h> |
|
28 #include <e32base.h> // CBase |
|
29 #include <apmstd.h> // TDataType |
|
30 #include <f32file.h> // RFs, RFile, CFileMan |
|
31 #include <CommonContentPolicy.h> |
|
32 |
|
33 #include <Oma2Agent.h> // EFileType |
|
34 #include <caf/caf.h> |
|
35 |
|
36 #include <bldvariant.hrh> // Feature IDs |
|
37 |
|
38 #include "fileprotectionresolver.h" |
|
39 #include "javaprotectionresolver.h" |
|
40 |
|
41 // EXTERNAL DATA STRUCTURES |
|
42 |
|
43 // EXTERNAL FUNCTION PROTOTYPES |
|
44 |
|
45 // CONSTANTS |
|
46 |
|
47 // MACROS |
|
48 |
|
49 // LOCAL CONSTANTS AND MACROS |
|
50 |
|
51 _LIT8( KFileProtMimeJar, "application/java-archive"); |
|
52 //_LIT8( KFileProtEpocApp, "x-epoc/x-app*" ); |
|
53 _LIT8( KFileProtWrongSis, "x-epoc/x-app268436505" ); |
|
54 // CCommonContentPolicy uses 16-bit MIME types |
|
55 _LIT16( KFileProtMimeSis, "application/vnd.symbian.install" ); |
|
56 |
|
57 const TInt KMaxContentUriLength = 256; |
|
58 |
|
59 // MODULE DATA STRUCTURES |
|
60 |
|
61 // LOCAL FUNCTION PROTOTYPES |
|
62 |
|
63 // FORWARD DECLARATIONS |
|
64 |
|
65 // ============================ MEMBER FUNCTIONS =============================== |
|
66 |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // Factory |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 EXPORT_C CFileProtectionResolver* CFileProtectionResolver::NewLC( RFs& aFs ) |
|
74 { |
|
75 CFileProtectionResolver* self = new ( ELeave ) CFileProtectionResolver( aFs ); |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // Factory |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 EXPORT_C CFileProtectionResolver* CFileProtectionResolver::NewL( RFs& aFs ) |
|
86 { |
|
87 CFileProtectionResolver* self = NewLC( aFs ); |
|
88 CleanupStack::Pop( self ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // C++ constructor |
|
94 // ----------------------------------------------------------------------------- |
|
95 // |
|
96 CFileProtectionResolver::CFileProtectionResolver( RFs& aFs ) : |
|
97 iFs( aFs ) |
|
98 { |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // Destructor |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CFileProtectionResolver::~CFileProtectionResolver() |
|
106 { |
|
107 delete iClosedContent; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // 2nd phase constructor |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CFileProtectionResolver::ConstructL() |
|
115 { |
|
116 iClosedContent = CCommonContentPolicy::NewL(); |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CFileProtectionResolver::CheckDRMStatus |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C TInt CFileProtectionResolver::ProtectionStatusL( const TDesC& aFilePath, |
|
124 TDataType& aMimeType ) |
|
125 { |
|
126 RFile file; |
|
127 User::LeaveIfError( file.Open( iFs, aFilePath, EFileRead | EFileShareReadersOnly ) ); |
|
128 CleanupClosePushL( file ); |
|
129 TInt ret = ProtectionStatusL( file, aMimeType ); |
|
130 CleanupStack::PopAndDestroy( &file ); |
|
131 return ret; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CFileProtectionResolver::CheckDRMStatus |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 EXPORT_C TInt CFileProtectionResolver::ProtectionStatusL( RFile& aFile, |
|
139 TDataType& aMimeType ) |
|
140 { |
|
141 TInt ret( EFileProtNoProtection ); |
|
142 HBufC8* contentUri = NULL; |
|
143 TRAPD( err, |
|
144 { |
|
145 ret = ProtectionStatusL( aFile, aMimeType, contentUri ); |
|
146 } ); |
|
147 delete contentUri; |
|
148 User::LeaveIfError( err ); |
|
149 return ret; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CFileProtectionResolver::CheckDRMStatus |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C TInt CFileProtectionResolver::ProtectionStatusL( const TDesC& aFilePath, |
|
157 TDataType& aMimeType, |
|
158 HBufC8*& aContentUri ) |
|
159 { |
|
160 RFile file; |
|
161 User::LeaveIfError( file.Open( iFs, aFilePath, EFileRead | EFileShareReadersOnly ) ); |
|
162 CleanupClosePushL( file ); |
|
163 TInt ret = ProtectionStatusL( file, aMimeType, aContentUri ); |
|
164 CleanupStack::PopAndDestroy( &file ); |
|
165 return ret; |
|
166 } |
|
167 |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CFileProtectionResolver::CheckDRMStatus |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 EXPORT_C TInt CFileProtectionResolver::ProtectionStatusL( RFile& aFile, |
|
174 TDataType& aMimeType, |
|
175 HBufC8*& aContentUri ) |
|
176 { |
|
177 TInt protection( EFileProtNoProtection ); |
|
178 TBuf<KMaxDataTypeLength> temp; |
|
179 temp.Zero(); |
|
180 //if ( aMimeType.Des8().MatchF( KFileProtEpocApp ) != KErrNotFound ) |
|
181 if ( aMimeType.Des8().CompareF( KFileProtWrongSis ) == 0 ) |
|
182 { |
|
183 // Symbian code has not been corrected. |
|
184 // For some sis files it works, for some it returns "x-epoc/x-app268436505" |
|
185 // So we must redefine all "x-epoc/x-app268436505" as "application/vnd.symbian.install" |
|
186 temp.Copy( KFileProtMimeSis ); |
|
187 } |
|
188 else |
|
189 { |
|
190 temp.Copy( aMimeType.Des8() ); |
|
191 } |
|
192 |
|
193 TFileName name; |
|
194 User::LeaveIfError( aFile.Name( name ) ); |
|
195 TParsePtrC parse( name ); |
|
196 |
|
197 if ( iClosedContent->IsClosedType( temp ) || |
|
198 iClosedContent->IsClosedExtension( parse.Ext() ) ) |
|
199 { |
|
200 protection |= EFileProtClosedContent; |
|
201 } |
|
202 |
|
203 delete aContentUri; // just in case |
|
204 aContentUri = NULL; |
|
205 |
|
206 ContentAccess::CContent* content = ContentAccess::CContent::NewLC( aFile ); |
|
207 |
|
208 TInt isProtected( 0 ); |
|
209 TInt err = content->GetAttribute( ContentAccess::EIsProtected, isProtected ); |
|
210 if ( !err && isProtected ) |
|
211 { |
|
212 TInt isForwardable( 0 ); |
|
213 err = content->GetAttribute( ContentAccess::EIsForwardable, isForwardable ); |
|
214 if ( !err && isForwardable ) |
|
215 { |
|
216 protection |= EFileProtSuperDistributable; |
|
217 } |
|
218 else |
|
219 { |
|
220 protection |= EFileProtForwardLocked; |
|
221 } |
|
222 |
|
223 // Is DRM2 |
|
224 TInt drmType( 0 ); |
|
225 content->GetAttribute( ContentAccess::EFileType, drmType ); |
|
226 if ( drmType == ContentAccess::EOma2Dcf ) |
|
227 { |
|
228 protection |= EFileProtDrm2; |
|
229 } |
|
230 else |
|
231 { |
|
232 protection &= (~EFileProtDrm2); |
|
233 } |
|
234 |
|
235 HBufC* contentUri = HBufC::NewLC( KMaxContentUriLength ); |
|
236 TPtr tempPtr = contentUri->Des(); |
|
237 // "EContentID" has the "content uri" we want. Not "EContentURI"! |
|
238 err = content->GetStringAttribute( ContentAccess::EContentID, tempPtr ); |
|
239 if ( !err && contentUri->Length() > 0 ) |
|
240 { |
|
241 // Convert to 8-bit string |
|
242 aContentUri = HBufC8::NewL( contentUri->Length() ); |
|
243 aContentUri->Des().Copy( *contentUri ); |
|
244 } |
|
245 else |
|
246 { |
|
247 // If content id cannot be retrieved or is invalid |
|
248 // then the file is treated as an DRM 2 file. |
|
249 protection |= EFileProtDrm2; |
|
250 } |
|
251 |
|
252 CleanupStack::PopAndDestroy( contentUri ); |
|
253 } |
|
254 else |
|
255 { |
|
256 if ( aMimeType.Des8().CompareF( KFileProtMimeJar ) == 0 ) |
|
257 { |
|
258 CJavaProtectionResolver* javaResolver = CJavaProtectionResolver::NewLC( iFs ); |
|
259 if ( javaResolver->IsSuperDistributionPackageL( aFile ) ) |
|
260 { |
|
261 protection |= EFileProtSuperDistributable; |
|
262 } |
|
263 CleanupStack::PopAndDestroy( javaResolver ); |
|
264 } |
|
265 } |
|
266 |
|
267 CleanupStack::PopAndDestroy( content ); |
|
268 return protection; |
|
269 } |
|
270 |
|
271 // End of File |