45 const TInt KLengthVersion = 1; |
45 const TInt KLengthVersion = 1; |
46 const TInt KLengthFlags = 3; |
46 const TInt KLengthFlags = 3; |
47 |
47 |
48 _LIT8(KFTypPrefix, "ftyp"); |
48 _LIT8(KFTypPrefix, "ftyp"); |
49 _LIT8(KODFPrefix, "odcf"); |
49 _LIT8(KODFPrefix, "odcf"); |
50 _LIT8(KRoapTriggerElement, "roap-trigger:roapTrigger"); // before OMA spec CR, ROAP Trigger namespace prefix was roap-trigger |
50 _LIT8(KRoapTriggerElement, "roap-trigger:roapTrigger"); // before OMA spec CR, ROAP Trigger namespace prefix was roap-trigger |
51 _LIT8(KRoapTriggerElement2, "roap:roapTrigger"); |
51 _LIT8(KRoapTriggerElement2, "roap:roapTrigger"); |
52 _LIT8(KRoapTriggerType, "application/vnd.oma.drm.roap-trigger+xml"); |
52 _LIT8(KRoapTriggerType, "application/vnd.oma.drm.roap-trigger+xml"); |
53 |
53 |
54 const TImplementationProxy ImplementationTable[] = |
54 const TImplementationProxy ImplementationTable[] = |
55 { |
55 { |
56 IMPLEMENTATION_PROXY_ENTRY(0x101F6DB8, CApaDRMRecognizer::CreateRecognizerL) |
56 IMPLEMENTATION_PROXY_ENTRY(0x101F6DB8, CApaDRMRecognizer::CreateRecognizerL) |
57 }; |
57 }; |
58 |
58 |
59 #ifdef DRM_OMA2_ENABLED |
59 #ifdef DRM_OMA2_ENABLED |
60 TUint32 ReadUint32FromBlock(const TDesC8& aBlock, TInt aOffset) |
60 TUint32 ReadUint32FromBlock(const TDesC8& aBlock, TInt aOffset) |
61 { |
61 { |
62 return (aBlock[aOffset] << 24) + |
62 return (aBlock[aOffset] << 24) + |
78 return ((aBlock[aOffset] << 8) + aBlock[aOffset + 1]); |
78 return ((aBlock[aOffset] << 8) + aBlock[aOffset + 1]); |
79 } |
79 } |
80 #endif |
80 #endif |
81 |
81 |
82 CApaDRMRecognizer::CApaDRMRecognizer(): |
82 CApaDRMRecognizer::CApaDRMRecognizer(): |
83 CApaDataRecognizerType( KUidDRMRecognizer,CApaDataRecognizerType::ENormal ) |
83 CApaDataRecognizerType( KUidDRMRecognizer,CApaDataRecognizerType::ENormal ) |
84 { |
84 { |
85 |
85 |
86 iCountDataTypes = 0; |
86 iCountDataTypes = 0; |
87 return; |
87 return; |
88 } |
88 } |
89 |
89 |
90 CApaDRMRecognizer::~CApaDRMRecognizer() |
90 CApaDRMRecognizer::~CApaDRMRecognizer() |
91 { |
91 { |
92 } |
92 } |
93 |
93 |
94 |
94 |
95 CApaDataRecognizerType* CApaDRMRecognizer::CreateRecognizerL() |
95 CApaDataRecognizerType* CApaDRMRecognizer::CreateRecognizerL() |
96 { |
96 { |
97 return new (ELeave) CApaDRMRecognizer (); |
97 return new (ELeave) CApaDRMRecognizer (); |
98 } |
98 } |
99 |
99 |
100 |
100 |
101 TUint CApaDRMRecognizer::PreferredBufSize() |
101 TUint CApaDRMRecognizer::PreferredBufSize() |
102 { |
102 { |
103 return KMaxBufferLength; |
103 return KMaxBufferLength; |
104 } |
104 } |
105 |
105 |
106 #ifdef _DEBUG |
106 #ifdef _DEBUG |
107 TDataType CApaDRMRecognizer::SupportedDataTypeL( TInt aIndex ) const |
107 TDataType CApaDRMRecognizer::SupportedDataTypeL( TInt aIndex ) const |
108 #else |
108 #else |
109 TDataType CApaDRMRecognizer::SupportedDataTypeL( TInt /*aIndex*/ ) const |
109 TDataType CApaDRMRecognizer::SupportedDataTypeL( TInt /*aIndex*/ ) const |
110 #endif |
110 #endif |
111 { |
111 { |
112 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iCountDataTypes, User::Invariant() ); |
112 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iCountDataTypes, User::Invariant() ); |
113 return TDataType( _L8("application/vdn.omd.drm.content") ); // this should never be run |
113 return TDataType( _L8("application/vdn.omd.drm.content") ); // this should never be run |
114 } |
114 } |
115 |
115 |
116 void CApaDRMRecognizer::DoRecognizeL( const TDesC& aName, const TDesC8& aBuffer ) |
116 void CApaDRMRecognizer::DoRecognizeL( const TDesC& aName, const TDesC8& aBuffer ) |
117 { |
117 { |
118 if ( aBuffer.Size() < 3) |
118 if ( aBuffer.Size() < 3) |
119 { |
119 { |
120 return; |
120 return; |
121 } |
121 } |
122 |
122 |
123 #ifdef RECOGNIZE_KEY_CHAIN |
123 #ifdef RECOGNIZE_KEY_CHAIN |
124 // Recognize device key chain |
124 // Recognize device key chain |
125 if ( aName.Length() > 3 && aName.Right(4).CompareF(_L(".dkc")) == 0) |
125 if ( aName.Length() > 3 && aName.Right(4).CompareF(_L(".dkc")) == 0) |
126 { |
126 { |
127 iConfidence = ECertain; |
127 iConfidence = ECertain; |
128 iDataType = TDataType( _L8("application/x-device-key-chain") ); |
128 iDataType = TDataType( _L8("application/x-device-key-chain") ); |
129 return; |
129 return; |
130 } |
130 } |
131 #endif |
131 #endif |
132 |
132 |
133 #ifdef DRM_OMA2_ENABLED |
133 #ifdef DRM_OMA2_ENABLED |
134 // Recognize ROAP Trigger |
134 // Recognize ROAP Trigger |
135 if ( RecognizeRoapTrigger( aBuffer ) ) |
135 if ( RecognizeRoapTrigger( aBuffer ) ) |
136 { |
136 { |
137 return; |
137 return; |
138 } |
138 } |
139 |
139 |
140 // Recognize DCFv2 |
140 // Recognize DCFv2 |
141 if ( RecognizeODF( aBuffer ) ) |
141 if ( RecognizeODF( aBuffer ) ) |
142 { |
142 { |
143 return; |
143 return; |
144 } |
144 } |
145 #endif |
145 #endif |
146 // Recognize DCFv1 |
146 // Recognize DCFv1 |
147 TUint8 version = aBuffer[0]; |
147 TUint8 version = aBuffer[0]; |
148 TUint8 contentTypeLen = aBuffer[1]; |
148 TUint8 contentTypeLen = aBuffer[1]; |
149 TUint8 contentURILen = aBuffer[2]; |
149 TUint8 contentURILen = aBuffer[2]; |
150 |
150 |
151 if ( contentTypeLen < KMinContentTypeLen || contentURILen == 0 ) |
151 if ( contentTypeLen < KMinContentTypeLen || contentURILen == 0 ) |
152 { |
152 { |
153 return; |
153 return; |
154 } |
154 } |
155 if ( version != KDCFVersionSupported ) |
155 if ( version != KDCFVersionSupported ) |
156 { |
156 { |
157 return; |
157 return; |
158 } |
158 } |
159 |
159 |
160 // Too little data received |
160 // Too little data received |
161 if ( aBuffer.Size() < ( contentTypeLen + KDCFHeaderLength ) ) |
161 if ( aBuffer.Size() < ( contentTypeLen + KDCFHeaderLength ) ) |
162 { |
162 { |
163 return; |
163 return; |
164 } |
164 } |
165 |
165 |
166 TPtrC8 mimeType = aBuffer.Mid( KDCFHeaderLength, contentTypeLen ); |
166 TPtrC8 mimeType = aBuffer.Mid( KDCFHeaderLength, contentTypeLen ); |
167 if ( mimeType.Locate( '/' ) != KErrNotFound ) |
167 if ( mimeType.Locate( '/' ) != KErrNotFound ) |
168 { |
168 { |
169 iConfidence = ECertain; |
169 iConfidence = ECertain; |
170 iDataType=TDataType( mimeType ); |
170 iDataType=TDataType( mimeType ); |
171 } |
171 } |
172 |
172 |
173 |
173 |
174 return; |
174 return; |
175 } |
175 } |
176 |
176 |
177 #ifdef DRM_OMA2_ENABLED |
177 #ifdef DRM_OMA2_ENABLED |
178 TBool CApaDRMRecognizer::RecognizeRoapTrigger( const TDesC8& aBuffer ) |
178 TBool CApaDRMRecognizer::RecognizeRoapTrigger( const TDesC8& aBuffer ) |
179 { |
179 { |
182 { |
182 { |
183 iConfidence = ECertain; |
183 iConfidence = ECertain; |
184 iDataType=TDataType( KRoapTriggerType() ); |
184 iDataType=TDataType( KRoapTriggerType() ); |
185 return ETrue; |
185 return ETrue; |
186 } |
186 } |
187 return EFalse; |
187 return EFalse; |
188 } |
188 } |
189 |
189 |
190 TBool CApaDRMRecognizer::RecognizeODF( const TDesC8& aBuffer ) |
190 TBool CApaDRMRecognizer::RecognizeODF( const TDesC8& aBuffer ) |
191 { |
191 { |
192 if ( aBuffer.Size() < 24 ) return EFalse; |
192 if ( aBuffer.Size() < 24 ) return EFalse; |
193 TPtrC8 ftypPrefix = aBuffer.Mid( 4, KFTypPrefix().Length() ); |
193 TPtrC8 ftypPrefix = aBuffer.Mid( 4, KFTypPrefix().Length() ); |
194 if ( KFTypPrefix().CompareF( ftypPrefix ) == KErrNone ) |
194 if ( KFTypPrefix().CompareF( ftypPrefix ) == KErrNone ) |
195 { |
195 { |
196 TPtrC8 odfPrefix = aBuffer.Mid( 8, KODFPrefix().Length() ); |
196 TPtrC8 odfPrefix = aBuffer.Mid( 8, KODFPrefix().Length() ); |
197 if ( KODFPrefix().CompareF( odfPrefix ) == KErrNone ) |
197 if ( KODFPrefix().CompareF( odfPrefix ) == KErrNone ) |
198 { |
198 { |
199 TBuf8<4> buffer; |
199 TBuf8<4> buffer; |
200 TUint32 size; |
200 TUint32 size; |
201 TPtr8 ptr(NULL, 0); |
201 TPtr8 ptr(NULL, 0); |
202 TUint32 offset(20); |
202 TUint32 offset(20); |
203 |
203 |
204 // ODRM box header |
204 // ODRM box header |
205 buffer.Zero(); |
205 buffer.Zero(); |
206 buffer.Copy( aBuffer.Mid( offset, 4 )); |
206 buffer.Copy( aBuffer.Mid( offset, 4 )); |
207 size = ReadUint32FromBlock( buffer, 0 ); |
207 size = ReadUint32FromBlock( buffer, 0 ); |
208 offset += KLengthBoxSize + KLengthBoxType + KLengthVersion + KLengthFlags; |
208 offset += KLengthBoxSize + KLengthBoxType + KLengthVersion + KLengthFlags; |
209 |
209 |
210 if (size == 1) |
210 if (size == 1) |
211 { |
211 { |
212 offset += KLengthBoxSize64; |
212 offset += KLengthBoxSize64; |
213 } |
213 } |
214 if ( aBuffer.Size() < offset+4 ) return EFalse; |
214 if ( aBuffer.Size() < offset+4 ) return EFalse; |
215 |
215 |
216 // Discrete headers box header |
216 // Discrete headers box header |
217 buffer.Zero(); |
217 buffer.Zero(); |
218 buffer.Copy( aBuffer.Mid( offset, 4 )); |
218 buffer.Copy( aBuffer.Mid( offset, 4 )); |
219 size = ReadUint32FromBlock( buffer, 0 ); |
219 size = ReadUint32FromBlock( buffer, 0 ); |
220 offset += KLengthBoxSize + KLengthBoxType + KLengthVersion + KLengthFlags; |
220 offset += KLengthBoxSize + KLengthBoxType + KLengthVersion + KLengthFlags; |
221 if ( size == 1 ) |
221 if ( size == 1 ) |
222 { |
222 { |
223 offset += KLengthBoxSize64; |
223 offset += KLengthBoxSize64; |
224 } |
224 } |
225 if ( aBuffer.Size() < offset+1 ) return EFalse; |
225 if ( aBuffer.Size() < offset+1 ) return EFalse; |
226 |
226 |
227 // Content type |
227 // Content type |
228 buffer.Zero(); |
228 buffer.Zero(); |
229 buffer.Copy( aBuffer.Mid( offset, 1 )); |
229 buffer.Copy( aBuffer.Mid( offset, 1 )); |
230 if ( aBuffer.Size() < offset + 1 + buffer[0] ) return EFalse; |
230 if ( aBuffer.Size() < offset + 1 + buffer[0] ) return EFalse; |
231 TPtrC8 mimeType = aBuffer.Mid( offset+1, buffer[0] ); |
231 TPtrC8 mimeType = aBuffer.Mid( offset+1, buffer[0] ); |
232 |
232 |
233 iConfidence = ECertain; |
233 iConfidence = ECertain; |
234 iDataType=TDataType( mimeType ); |
234 iDataType=TDataType( mimeType ); |
235 return ETrue; |
235 return ETrue; |
236 } |
236 } |
237 |
237 |
238 } |
238 } |
239 return EFalse; |
239 return EFalse; |
240 } |
240 } |
241 #endif |
241 #endif |
242 |
242 |
243 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
243 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
244 { |
244 { |