1 /* |
|
2 * Copyright (c) 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 * |
|
16 */ |
|
17 |
|
18 #include <liwcommon.h> |
|
19 #include <s32mem.h> |
|
20 #include "cpserverdef.h" |
|
21 |
|
22 #include "cpglobals.h" |
|
23 #include "cblacklisthandler.h" |
|
24 #include "centralrepository.h" |
|
25 |
|
26 |
|
27 //CONST |
|
28 const TUint32 KOfficialBlacklistCRKey = { 0x1028000A }; |
|
29 const TUint32 KOfficialBlacklistSizeCRKey = { 0x1028000B }; |
|
30 const TUint32 KUnofficialBlacklistCRKey = { 0x1028000C }; |
|
31 const TUint32 KUnoficialBlacklistSizeCRKey = { 0x1028000D }; |
|
32 |
|
33 // ---------------------------------------------------------------------------- |
|
34 // |
|
35 // ---------------------------------------------------------------------------- |
|
36 // |
|
37 CBlacklistHandler* CBlacklistHandler::NewL( ) |
|
38 { |
|
39 CBlacklistHandler* self = CBlacklistHandler::NewLC( ); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // |
|
46 // ---------------------------------------------------------------------------- |
|
47 // |
|
48 CBlacklistHandler* CBlacklistHandler::NewLC( ) |
|
49 { |
|
50 CBlacklistHandler* self = new( ELeave ) CBlacklistHandler( ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 CBlacklistHandler::~CBlacklistHandler() |
|
61 { |
|
62 delete iRepository; |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 CBlacklistHandler::CBlacklistHandler( ) |
|
70 { |
|
71 |
|
72 } |
|
73 |
|
74 // ---------------------------------------------------------------------------- |
|
75 // |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 void CBlacklistHandler::ConstructL() |
|
79 { |
|
80 iRepository = CRepository::NewL( KServerUid ); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 void CBlacklistHandler::AppendL( TUid aUid ) |
|
88 { |
|
89 RArray<TUid> blacklist; |
|
90 CleanupClosePushL( blacklist ); |
|
91 GetArrayL( blacklist, EFalse ); //unofficial blacklist |
|
92 blacklist.AppendL( aUid ); |
|
93 StoreArrayL( blacklist, EFalse );//unofficial blacklist |
|
94 CleanupStack::PopAndDestroy( &blacklist ); |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 void CBlacklistHandler::RemoveL( TUid aUid ) |
|
102 { |
|
103 RArray<TUid> blacklist; |
|
104 CleanupClosePushL( blacklist ); |
|
105 GetArrayL( blacklist, EFalse );//from unofficial blacklist |
|
106 TInt index = blacklist.Find( aUid ); |
|
107 if ( index != KErrNotFound ) |
|
108 { |
|
109 blacklist.Remove( index ); |
|
110 } |
|
111 StoreArrayL( blacklist, EFalse );//unofficial blacklist |
|
112 CleanupStack::PopAndDestroy( &blacklist ); |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------------------------------- |
|
116 // |
|
117 // ---------------------------------------------------------------------------- |
|
118 // |
|
119 TBool CBlacklistHandler::IsPresentL( TUid aUid ) |
|
120 { |
|
121 TBool result(EFalse); |
|
122 RArray<TUid> blacklist; |
|
123 CleanupClosePushL( blacklist ); |
|
124 GetArrayL( blacklist, ETrue );// from official blacklist |
|
125 TInt index = blacklist.Find( aUid ); |
|
126 if ( index != KErrNotFound ) |
|
127 { |
|
128 result = ETrue; |
|
129 } |
|
130 CleanupStack::PopAndDestroy( &blacklist ); |
|
131 return result; |
|
132 } |
|
133 |
|
134 |
|
135 // ---------------------------------------------------------------------------- |
|
136 // |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 void CBlacklistHandler::GetArrayL( RArray<TUid>& aArray, TBool aOfficial ) |
|
140 { |
|
141 TInt32 repositoryKey( NULL ); |
|
142 TInt32 repositorySize( NULL ); |
|
143 if( aOfficial ) |
|
144 { |
|
145 repositorySize = KOfficialBlacklistSizeCRKey; |
|
146 repositoryKey = KOfficialBlacklistCRKey; |
|
147 } |
|
148 else |
|
149 { |
|
150 repositorySize = KUnoficialBlacklistSizeCRKey; |
|
151 repositoryKey = KUnofficialBlacklistCRKey; |
|
152 } |
|
153 |
|
154 TInt size(-1); |
|
155 if ( KErrNone == iRepository->Get( repositorySize, size ) ) |
|
156 { |
|
157 RBuf8 serializedBlacklist; |
|
158 serializedBlacklist.Create( size ); |
|
159 CleanupClosePushL( serializedBlacklist ); |
|
160 if ( KErrNone == iRepository->Get( repositoryKey, serializedBlacklist ) ) |
|
161 { |
|
162 RDesReadStream stream( serializedBlacklist ); |
|
163 CleanupClosePushL( stream ); |
|
164 TUint16 count = stream.ReadUint16L(); |
|
165 for ( TInt i = 0; i < count; i++ ) |
|
166 { |
|
167 aArray.AppendL(TUid::Uid(stream.ReadInt32L())); |
|
168 } |
|
169 CleanupStack::PopAndDestroy( &stream ); |
|
170 } |
|
171 CleanupStack::PopAndDestroy( &serializedBlacklist ); |
|
172 } |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // |
|
177 // ---------------------------------------------------------------------------- |
|
178 // |
|
179 void CBlacklistHandler::StoreArrayL( const RArray<TUid>& aArray, |
|
180 TBool aOfficial ) |
|
181 { |
|
182 TInt32 repositoryKey( NULL ); |
|
183 TInt32 repositorySize( NULL ); |
|
184 if( aOfficial ) |
|
185 { |
|
186 repositorySize = KOfficialBlacklistSizeCRKey; |
|
187 repositoryKey = KOfficialBlacklistCRKey; |
|
188 } |
|
189 else |
|
190 { |
|
191 repositorySize = KUnoficialBlacklistSizeCRKey; |
|
192 repositoryKey = KUnofficialBlacklistCRKey; |
|
193 } |
|
194 |
|
195 RBuf8 serializedBlacklist; |
|
196 serializedBlacklist.Create( aArray.Count() * sizeof(TInt32) + |
|
197 sizeof(TUint16) ); |
|
198 CleanupClosePushL( serializedBlacklist ); |
|
199 RDesWriteStream stream( serializedBlacklist ); |
|
200 CleanupClosePushL( stream ); |
|
201 stream.WriteUint16L( aArray.Count() ); |
|
202 for ( TInt i = 0; i< aArray.Count(); i++ ) |
|
203 { |
|
204 stream.WriteInt32L( aArray[i].iUid ); |
|
205 } |
|
206 stream.CommitL(); |
|
207 if ( KErrNone == iRepository->Set( repositoryKey, serializedBlacklist ) ) |
|
208 { |
|
209 iRepository->Set( repositorySize, serializedBlacklist.Size() ); |
|
210 } |
|
211 CleanupStack::PopAndDestroy( &stream ); |
|
212 CleanupStack::PopAndDestroy( &serializedBlacklist ); |
|
213 } |
|
214 |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 // ---------------------------------------------------------------------------- |
|
218 // |
|
219 void CBlacklistHandler::CopyBlacklistL( TBool aOfficialToUnofficial ) |
|
220 { |
|
221 RArray<TUid> blacklist; |
|
222 CleanupClosePushL( blacklist ); |
|
223 GetArrayL( blacklist, aOfficialToUnofficial ); |
|
224 StoreArrayL( blacklist, !aOfficialToUnofficial ); |
|
225 CleanupStack::PopAndDestroy( &blacklist ); |
|
226 } |
|
227 |
|