|
1 /* |
|
2 * Copyright (c) 2007 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: WMDRM Server implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32std.h> |
|
20 #include "slot.h" |
|
21 #include "slotdatacache.h" |
|
22 #include "enumerator.h" |
|
23 #include "slotdata.h" |
|
24 #include "wmdrmserver.h" |
|
25 |
|
26 #define _LOGGING_FILE L"wmdrmserver.txt" |
|
27 |
|
28 #include "flogger.h" |
|
29 #include "logfn.h" |
|
30 |
|
31 #ifdef __WINSCW__ |
|
32 _LIT8( KDummyKey, "0123456789012345" ); |
|
33 #endif |
|
34 |
|
35 _LIT8( KEmptyID, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" ); |
|
36 |
|
37 LOCAL_C void ExtractSlotComponentsL( |
|
38 const TDesC8& aMessageBuffer, |
|
39 TDes8& aStore, |
|
40 TDes8& aNamespace, |
|
41 TDes8& aHashKey, |
|
42 TDes8& aUniqueKey ) |
|
43 { |
|
44 TInt len; |
|
45 TInt offset; |
|
46 TInt total = aMessageBuffer.Length(); |
|
47 |
|
48 offset = 0; |
|
49 len = aMessageBuffer[offset]; |
|
50 if ( len <= 0 || len > KMaxWmDrmStoreNameSize || offset + len + 1 > total ) |
|
51 { |
|
52 User::Leave( KErrArgument ); |
|
53 } |
|
54 aStore.Copy( aMessageBuffer.Mid( offset + 1, len ) ); |
|
55 |
|
56 offset += len + 1; |
|
57 if ( offset >= total ) |
|
58 { |
|
59 User::Leave( KErrArgument ); |
|
60 } |
|
61 len = aMessageBuffer[offset]; |
|
62 if ( len <= 0 || len > KMaxWmDrmNamespaceNameSize || offset + len + 1 > total ) |
|
63 { |
|
64 User::Leave( KErrArgument ); |
|
65 } |
|
66 aNamespace.Copy( aMessageBuffer.Mid( offset + 1, len ) ); |
|
67 |
|
68 offset += len + 1; |
|
69 if ( offset >= total ) |
|
70 { |
|
71 User::Leave( KErrArgument ); |
|
72 } |
|
73 len = aMessageBuffer[offset]; |
|
74 if ( len != KWmDrmIdSize || offset + len + 1 > total ) |
|
75 { |
|
76 User::Leave( KErrArgument ); |
|
77 } |
|
78 aHashKey.Copy( aMessageBuffer.Mid( offset + 1, len ) ); |
|
79 |
|
80 offset += len + 1; |
|
81 if ( offset >= total ) |
|
82 { |
|
83 User::Leave( KErrArgument ); |
|
84 } |
|
85 len = aMessageBuffer[offset]; |
|
86 if ( len != KWmDrmIdSize || offset + len + 1 > total ) |
|
87 { |
|
88 User::Leave( KErrArgument ); |
|
89 } |
|
90 aUniqueKey.Copy( aMessageBuffer.Mid( offset + 1, len ) ); |
|
91 if ( aUniqueKey.CompareC( KEmptyID ) == 0 ) |
|
92 { |
|
93 aUniqueKey.Fill( '0' ); |
|
94 } |
|
95 } |
|
96 |
|
97 CSlot* CSlot::NewL( CWmDrmServer* aServer, const TDesC8& aMessageBuffer ) |
|
98 { |
|
99 CSlot* self = new (ELeave) CSlot(); |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL( aServer, aMessageBuffer ); |
|
102 CleanupStack::Pop( self ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 CSlot* CSlot::NewL( CWmDrmServer* aServer, CEnumerator* aEnumerator ) |
|
107 { |
|
108 CSlot* self = new (ELeave) CSlot(); |
|
109 CleanupStack::PushL( self ); |
|
110 self->ConstructL( aServer, aEnumerator ); |
|
111 CleanupStack::Pop( self ); |
|
112 return self; |
|
113 } |
|
114 |
|
115 void CSlot::ConstructL( |
|
116 CWmDrmServer* aServer, |
|
117 const TDesC8& aMessageBuffer ) |
|
118 { |
|
119 LOGFN( "CSlot::ConstructL" ); |
|
120 ExtractSlotComponentsL( aMessageBuffer, iStore, iNamespace, iHashKey, iUniqueKey ); |
|
121 iData = aServer->Cache()->GetSlotDataL( iStore, iNamespace, iHashKey, iUniqueKey ); |
|
122 iDataPosition = 0; |
|
123 } |
|
124 |
|
125 void CSlot::ConstructL( |
|
126 CWmDrmServer* aServer, |
|
127 CEnumerator* aEnumerator ) |
|
128 { |
|
129 LOGFN( "CSlot::ConstructL (2)" ); |
|
130 aEnumerator->GetHashKey( iHashKey ); |
|
131 aEnumerator->GetUniqueKey( iUniqueKey ); |
|
132 iStore.Copy( aEnumerator->iStore ); |
|
133 iNamespace.Copy( aEnumerator->iNamespace ); |
|
134 iData = aServer->Cache()->GetSlotDataL( iStore, iNamespace, iHashKey, iUniqueKey ); |
|
135 iDataPosition = 0; |
|
136 } |
|
137 |
|
138 |
|
139 CSlot::~CSlot() |
|
140 { |
|
141 LOGFN( "CSlot::~CSlot" ); |
|
142 if ( iData != NULL ) |
|
143 { |
|
144 iData->Close(); |
|
145 } |
|
146 } |
|
147 |
|
148 void CSlot::CreateL( TInt& aInitialSize ) |
|
149 { |
|
150 LOGFN( "CSlot::CreateL" ); |
|
151 iData->CreateL( aInitialSize ); |
|
152 } |
|
153 |
|
154 TInt CSlot::OpenL( TInt& aCurrentSize ) |
|
155 { |
|
156 TInt r = KErrNone; |
|
157 |
|
158 LOGFNR( "CSlot::Open", r ); |
|
159 r = iData->OpenL( aCurrentSize ); |
|
160 iDataPosition = 0; |
|
161 return r; |
|
162 } |
|
163 |
|
164 TInt CSlot::SeekL( TInt& aOffset, TSeek aOrigin ) |
|
165 { |
|
166 TInt r = KErrNone; |
|
167 TInt size; |
|
168 |
|
169 LOGFNR( "CSlot::Seek", r ); |
|
170 if ( iData == NULL ) |
|
171 { |
|
172 User::Leave( KErrNotReady ); |
|
173 } |
|
174 size = iData->Size(); |
|
175 switch ( aOrigin ) |
|
176 { |
|
177 case ESeekStart: |
|
178 iDataPosition = aOffset; |
|
179 break; |
|
180 case ESeekEnd: |
|
181 iDataPosition = size + aOffset; |
|
182 break; |
|
183 case ESeekCurrent: |
|
184 iDataPosition += aOffset; |
|
185 break; |
|
186 } |
|
187 iDataPosition = Max( iDataPosition, 0 ); |
|
188 iDataPosition = Min( iDataPosition, size ); |
|
189 LOG5( "Origin: %d, offset: %d, new pos: %d (size: %d)", aOrigin, aOffset, iDataPosition, size ); |
|
190 aOffset = iDataPosition; |
|
191 return r; |
|
192 } |
|
193 |
|
194 TInt CSlot::Read( TDes8& aBuffer ) |
|
195 { |
|
196 TInt r = KErrNone; |
|
197 |
|
198 LOGFNR( "CSlot::Read", r ); |
|
199 if ( iData == NULL ) |
|
200 { |
|
201 r = KErrNotReady; |
|
202 } |
|
203 else |
|
204 { |
|
205 r = iData->Read( iDataPosition, aBuffer ); |
|
206 } |
|
207 if ( r == KErrNone ) |
|
208 { |
|
209 iDataPosition += aBuffer.Length(); |
|
210 } |
|
211 return r; |
|
212 } |
|
213 |
|
214 TInt CSlot::WriteL( const TDesC8& aBuffer ) |
|
215 { |
|
216 TInt r = KErrNone; |
|
217 |
|
218 LOGFNR( "CSlot::Write", r ); |
|
219 r = iData->WriteL( iDataPosition, aBuffer ); |
|
220 if ( r == KErrNone ) |
|
221 { |
|
222 iDataPosition += aBuffer.Length(); |
|
223 } |
|
224 return r; |
|
225 } |
|
226 |
|
227 TInt CSlot::ResizeL( TInt aNewSize ) |
|
228 { |
|
229 TInt r = KErrNone; |
|
230 LOGFNR( "CSlot::Resize", r ); |
|
231 |
|
232 if ( iData == NULL ) |
|
233 { |
|
234 r = KErrNotReady; |
|
235 } |
|
236 else |
|
237 { |
|
238 iData->ResizeL( aNewSize ); |
|
239 if ( iDataPosition > aNewSize - 1 ) |
|
240 { |
|
241 iDataPosition = aNewSize - 1; |
|
242 } |
|
243 } |
|
244 return r; |
|
245 } |
|
246 |
|
247 TInt CSlot::DeleteL() |
|
248 { |
|
249 TInt r = KErrNone; |
|
250 |
|
251 LOGFNR( "CSlot::Delete", r ); |
|
252 if ( iData == NULL ) |
|
253 { |
|
254 r = KErrNotReady; |
|
255 } |
|
256 else |
|
257 { |
|
258 r = iData->DeleteL(); |
|
259 } |
|
260 return r; |
|
261 } |
|
262 |
|
263 TInt CSlot::Size() |
|
264 { |
|
265 TInt r = KErrNone; |
|
266 |
|
267 LOGFNR( "CSlot::Size", r ); |
|
268 if ( iData == NULL ) |
|
269 { |
|
270 r = KErrNotReady; |
|
271 } |
|
272 else |
|
273 { |
|
274 r = iData->Size(); |
|
275 } |
|
276 return r; |
|
277 } |
|
278 |
|
279 void CSlot::Close() |
|
280 { |
|
281 LOGFN( "CSlot::Close" ); |
|
282 if ( iData != NULL ) |
|
283 { |
|
284 iData->Close(); |
|
285 iData = NULL; |
|
286 } |
|
287 } |