|
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 <ezlib.h> |
|
20 #include <e32math.h> |
|
21 #include <symmetric.h> |
|
22 #include <bacntf.h> |
|
23 |
|
24 #include "enumerator.h" |
|
25 #include "namespaceenumerator.h" |
|
26 #include "enumeratordata.h" |
|
27 #include "slotenumerator.h" |
|
28 #include "wmdrmserver.h" |
|
29 #include "wmdrmdb.h" |
|
30 |
|
31 #define _LOGGING_FILE L"wmdrmserver.txt" |
|
32 |
|
33 #include "flogger.h" |
|
34 #include "logfn.h" |
|
35 |
|
36 _LIT8( KZeroID, "0000000000000000" ); |
|
37 |
|
38 LOCAL_C void ExtractEnumeratorComponentsL( |
|
39 const TDesC8& aMessageBuffer, |
|
40 TDes8& aStore, |
|
41 TDes8& aNamespace, |
|
42 TDes8& aHashKey ) |
|
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 len = aMessageBuffer[offset]; |
|
70 if ( offset >= total ) |
|
71 { |
|
72 User::Leave( KErrArgument ); |
|
73 } |
|
74 if ( ( len > 0 && len != KWmDrmIdSize ) || offset + len + 1 > total ) |
|
75 { |
|
76 User::Leave( KErrArgument ); |
|
77 } |
|
78 else if ( len > 0 ) |
|
79 { |
|
80 aHashKey.Copy( aMessageBuffer.Mid( offset + 1, len ) ); |
|
81 } |
|
82 else |
|
83 { |
|
84 aHashKey.SetLength( 0 ); |
|
85 } |
|
86 } |
|
87 |
|
88 CEnumerator* CEnumerator::NewL( |
|
89 CWmDrmServer* aServer, |
|
90 const TDesC8& aMessageBuffer ) |
|
91 { |
|
92 TBuf8<KMaxWmDrmNamespaceNameSize> nameSpace; |
|
93 TBuf8<KMaxWmDrmStoreNameSize> store; |
|
94 TBuf8<KWmDrmIdSize> hashKey; |
|
95 CEnumerator* self = NULL; |
|
96 |
|
97 LOGFN( "CEnumerator::NewL" ); |
|
98 ExtractEnumeratorComponentsL( aMessageBuffer, store, nameSpace, hashKey ); |
|
99 if ( hashKey.Length() > 0 ) |
|
100 { |
|
101 self = CSlotEnumerator::NewL( aServer, store, nameSpace, hashKey ); |
|
102 } |
|
103 else |
|
104 { |
|
105 self = CNameSpaceEnumerator::NewL( aServer, store, nameSpace ); |
|
106 } |
|
107 return self; |
|
108 } |
|
109 |
|
110 CEnumerator::~CEnumerator() |
|
111 { |
|
112 LOGFN( "CEnumerator::~CEnumerator" ); |
|
113 Close(); |
|
114 } |
|
115 |
|
116 void CEnumerator::GetHashKey( TDes8& aKey ) |
|
117 { |
|
118 LOGFN( "CEnumerator::GetHashKey" ); |
|
119 aKey.SetLength( 0 ); |
|
120 aKey.Copy( iHashKey ); |
|
121 } |
|
122 |
|
123 void CEnumerator::GetUniqueKey( TDes8& aKey ) |
|
124 { |
|
125 LOGFN( "CEnumerator::GetUniqueKey" ); |
|
126 aKey.SetLength( 0 ); |
|
127 if ( iUniqueKey.CompareC( KZeroID ) == 0 ) |
|
128 { |
|
129 aKey.Fill( '\0', KWmDrmIdSize ); |
|
130 } |
|
131 else |
|
132 { |
|
133 aKey.Copy( iUniqueKey ); |
|
134 } |
|
135 } |
|
136 |
|
137 void CEnumerator::DeleteCurrentL() |
|
138 { |
|
139 LOGFN( "CEnumerator::DeleteCurrentL" ); |
|
140 iServer->Db()->DeleteRecordL( iStore, |
|
141 iNamespace, |
|
142 iHashKey, |
|
143 iUniqueKey ); |
|
144 } |
|
145 |
|
146 TInt CEnumerator::OpenL() |
|
147 { |
|
148 TInt r = KErrNone; |
|
149 LOGFNR( "CEnumerator::Open", r ); |
|
150 return r; |
|
151 } |
|
152 |
|
153 void CEnumerator::Close() |
|
154 { |
|
155 LOGFN( "CEnumerator::Close" ); |
|
156 } |