33
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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: Parser for SIM control procedures.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "cphonegsmsimcontrolparser.h"
|
|
21 |
#include "cphonegsmparserresult.h"
|
|
22 |
#include "cphonegsmoptioncontainer.h"
|
|
23 |
|
|
24 |
// CONSTANTS
|
|
25 |
_LIT( KPhoneSimControlPinChangeCode, "04" );
|
|
26 |
_LIT( KPhoneSimControlPin2ChangeCode, "042" );
|
|
27 |
_LIT( KPhoneSimControlPinUnblockCode, "05" );
|
|
28 |
_LIT( KPhoneSimControlPin2UnblockCode, "052" );
|
|
29 |
|
|
30 |
const TInt KPhoneSimControlPinMinLength = 4;
|
|
31 |
const TInt KPhoneSimControlPinMaxLength = 8;
|
|
32 |
const TInt KPhoneSimControlPukLength = 8;
|
|
33 |
|
|
34 |
const TInt KPhoneSimControlAsterisk = '*';
|
|
35 |
const TInt KPhoneSimControlHash = '#';
|
|
36 |
|
|
37 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
38 |
|
|
39 |
// -----------------------------------------------------------------------------
|
|
40 |
// CPhoneGsmSimControlParser::CPhoneGsmSimControlParser
|
|
41 |
// -----------------------------------------------------------------------------
|
|
42 |
//
|
|
43 |
CPhoneGsmSimControlParser::CPhoneGsmSimControlParser()
|
|
44 |
{
|
|
45 |
}
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
// CPhoneGsmSimControlParser::NewLC
|
|
49 |
// -----------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
CPhoneGsmSimControlParser* CPhoneGsmSimControlParser::NewLC()
|
|
52 |
{
|
|
53 |
CPhoneGsmSimControlParser* self =
|
|
54 |
new ( ELeave ) CPhoneGsmSimControlParser;
|
|
55 |
|
|
56 |
CleanupStack::PushL( self );
|
|
57 |
|
|
58 |
return self;
|
|
59 |
}
|
|
60 |
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
// CPhoneGsmSimControlParser::ParseL
|
|
63 |
//
|
|
64 |
// Parse sim control procedures.
|
|
65 |
// -----------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
TBool CPhoneGsmSimControlParser::ParseL(
|
|
68 |
const TDesC& aString,
|
|
69 |
CPhoneGsmParserResult& aResult,
|
|
70 |
CPhoneGsmOptionContainerBase& aOptions )
|
|
71 |
{
|
|
72 |
aResult.ClearL();
|
|
73 |
|
|
74 |
TBool sendOperation = aOptions.FindOptionStatus( KPhoneOptionSend );
|
|
75 |
TBool incall = aOptions.FindOptionStatus( KPhoneOptionInCall );
|
|
76 |
|
|
77 |
TBool result = DoParseL( aString, aResult, sendOperation, incall );
|
|
78 |
|
|
79 |
if ( !result )
|
|
80 |
{
|
|
81 |
aResult.ClearL();
|
|
82 |
}
|
|
83 |
|
|
84 |
return result;
|
|
85 |
}
|
|
86 |
|
|
87 |
// -----------------------------------------------------------------------------
|
|
88 |
// CPhoneGsmSimControlParser::DoParseL
|
|
89 |
//
|
|
90 |
// Parse sim control procedures.
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
//
|
|
93 |
TBool CPhoneGsmSimControlParser::DoParseL(
|
|
94 |
const TDesC& aString,
|
|
95 |
CPhoneGsmParserResult& aResult,
|
|
96 |
TBool aSendOperation,
|
|
97 |
TBool /*aInCall*/ )
|
|
98 |
{
|
|
99 |
TBool result = EFalse;
|
|
100 |
aResult.ClearL();
|
|
101 |
|
|
102 |
TLex input( aString );
|
|
103 |
|
|
104 |
if ( !aSendOperation )
|
|
105 |
{
|
|
106 |
result = HandlePinOperationsL( input, aResult );
|
|
107 |
}
|
|
108 |
|
|
109 |
return result;
|
|
110 |
}
|
|
111 |
|
|
112 |
// -----------------------------------------------------------------------------
|
|
113 |
// CPhoneGsmSimControlParser::HandlePinOperationsL
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
TBool CPhoneGsmSimControlParser::HandlePinOperationsL(
|
|
117 |
TLex& aInput,
|
|
118 |
CPhoneGsmParserResult& aResult )
|
|
119 |
{
|
|
120 |
TBool result = EFalse;
|
|
121 |
TLexMark start;
|
|
122 |
aInput.Mark( start );
|
|
123 |
|
|
124 |
if ( HandlePinPrefix( aInput, aResult ) )
|
|
125 |
{
|
|
126 |
TPtrC number( NextNumber( aInput ) );
|
|
127 |
|
|
128 |
if ( number == KPhoneSimControlPinChangeCode )
|
|
129 |
{
|
|
130 |
aResult.SetUid( KPhoneUidPinChange );
|
|
131 |
result = HandlePinChangeL( aInput, aResult );
|
|
132 |
}
|
|
133 |
else if ( number == KPhoneSimControlPin2ChangeCode )
|
|
134 |
{
|
|
135 |
aResult.SetUid( KPhoneUidPin2Change );
|
|
136 |
result = HandlePinChangeL( aInput, aResult );
|
|
137 |
}
|
|
138 |
else if ( number == KPhoneSimControlPinUnblockCode )
|
|
139 |
{
|
|
140 |
aResult.SetUid( KPhoneUidPinUnblock );
|
|
141 |
result = HandlePinUnblockL( aInput, aResult );
|
|
142 |
}
|
|
143 |
else if ( number == KPhoneSimControlPin2UnblockCode )
|
|
144 |
{
|
|
145 |
aResult.SetUid( KPhoneUidPin2Unblock );
|
|
146 |
result = HandlePinUnblockL( aInput, aResult );
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
if ( !result )
|
|
151 |
{
|
|
152 |
aResult.ClearL();
|
|
153 |
aInput.UnGetToMark( start );
|
|
154 |
}
|
|
155 |
|
|
156 |
return result;
|
|
157 |
}
|
|
158 |
|
|
159 |
// -----------------------------------------------------------------------------
|
|
160 |
// CPhoneGsmSimControlParser::HandlePinPrefix
|
|
161 |
// -----------------------------------------------------------------------------
|
|
162 |
//
|
|
163 |
TBool CPhoneGsmSimControlParser::HandlePinPrefix(
|
|
164 |
TLex& aInput,
|
|
165 |
CPhoneGsmParserResult& /*aResult*/ )
|
|
166 |
{
|
|
167 |
TBool result = ETrue;
|
|
168 |
|
|
169 |
TLexMark start;
|
|
170 |
aInput.Mark( start );
|
|
171 |
|
|
172 |
if ( aInput.Peek() != KPhoneSimControlAsterisk )
|
|
173 |
{
|
|
174 |
result = EFalse;
|
|
175 |
}
|
|
176 |
else
|
|
177 |
{
|
|
178 |
aInput.Inc();
|
|
179 |
|
|
180 |
if ( aInput.Peek() != KPhoneSimControlAsterisk )
|
|
181 |
{
|
|
182 |
result = EFalse;
|
|
183 |
}
|
|
184 |
else
|
|
185 |
{
|
|
186 |
aInput.Inc();
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
if ( !result )
|
|
191 |
{
|
|
192 |
aInput.UnGetToMark( start );
|
|
193 |
}
|
|
194 |
|
|
195 |
return result;
|
|
196 |
}
|
|
197 |
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
// CPhoneGsmSimControlParser::HandlePinChangeL
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
//
|
|
202 |
TBool CPhoneGsmSimControlParser::HandlePinChangeL(
|
|
203 |
TLex& aInput,
|
|
204 |
CPhoneGsmParserResult& aResult )
|
|
205 |
{
|
|
206 |
TBool result = EFalse;
|
|
207 |
TLexMark start;
|
|
208 |
aInput.Mark( start );
|
|
209 |
|
|
210 |
result = HandlePinL( aInput, aResult );
|
|
211 |
result = result && HandlePinL( aInput, aResult );
|
|
212 |
result = result && HandlePinL( aInput, aResult );
|
|
213 |
result = result && HandleNoParameters( aInput, aResult );
|
|
214 |
|
|
215 |
if ( !result )
|
|
216 |
{
|
|
217 |
aInput.UnGetToMark( start );
|
|
218 |
}
|
|
219 |
|
|
220 |
return result;
|
|
221 |
}
|
|
222 |
|
|
223 |
// -----------------------------------------------------------------------------
|
|
224 |
// CPhoneGsmSimControlParser::HandlePinUnblockL
|
|
225 |
// -----------------------------------------------------------------------------
|
|
226 |
//
|
|
227 |
TBool CPhoneGsmSimControlParser::HandlePinUnblockL(
|
|
228 |
TLex& aInput,
|
|
229 |
CPhoneGsmParserResult& aResult )
|
|
230 |
{
|
|
231 |
TBool result = EFalse;
|
|
232 |
TLexMark start;
|
|
233 |
aInput.Mark( start );
|
|
234 |
|
|
235 |
result = HandlePukL( aInput, aResult );
|
|
236 |
result = result && HandlePinL( aInput, aResult );
|
|
237 |
result = result && HandlePinL( aInput, aResult );
|
|
238 |
result = result && HandleNoParameters( aInput, aResult );
|
|
239 |
|
|
240 |
if ( !result )
|
|
241 |
{
|
|
242 |
aInput.UnGetToMark( start );
|
|
243 |
}
|
|
244 |
|
|
245 |
return result;
|
|
246 |
}
|
|
247 |
|
|
248 |
// -----------------------------------------------------------------------------
|
|
249 |
// CPhoneGsmSimControlParser::HandleNoParameters
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
//
|
|
252 |
TBool CPhoneGsmSimControlParser::HandleNoParameters(
|
|
253 |
TLex& aInput,
|
|
254 |
CPhoneGsmParserResult& /*aResult*/ )
|
|
255 |
{
|
|
256 |
TBool result = EFalse;
|
|
257 |
|
|
258 |
if ( aInput.Remainder().Length() == 1 && // single character
|
|
259 |
aInput.Peek() == KPhoneSimControlHash )
|
|
260 |
{
|
|
261 |
result = ETrue;
|
|
262 |
aInput.Inc();
|
|
263 |
}
|
|
264 |
|
|
265 |
return result;
|
|
266 |
}
|
|
267 |
|
|
268 |
// -----------------------------------------------------------------------------
|
|
269 |
// CPhoneGsmSimControlParser::HandlePinL
|
|
270 |
// -----------------------------------------------------------------------------
|
|
271 |
//
|
|
272 |
TBool CPhoneGsmSimControlParser::HandlePinL(
|
|
273 |
TLex& aInput,
|
|
274 |
CPhoneGsmParserResult& aResult )
|
|
275 |
{
|
|
276 |
return HandleParameterL(
|
|
277 |
aInput,
|
|
278 |
aResult,
|
|
279 |
CPhoneGsmSimControlParser::ValidatePin );
|
|
280 |
}
|
|
281 |
|
|
282 |
// -----------------------------------------------------------------------------
|
|
283 |
// CPhoneGsmSimControlParser::HandlePukL
|
|
284 |
// -----------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
TBool CPhoneGsmSimControlParser::HandlePukL(
|
|
287 |
TLex& aInput,
|
|
288 |
CPhoneGsmParserResult& aResult )
|
|
289 |
{
|
|
290 |
return HandleParameterL(
|
|
291 |
aInput,
|
|
292 |
aResult,
|
|
293 |
CPhoneGsmSimControlParser::ValidatePuk );
|
|
294 |
}
|
|
295 |
|
|
296 |
// -----------------------------------------------------------------------------
|
|
297 |
// CPhoneGsmSimControlParser::HandleParameterL
|
|
298 |
// -----------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
TBool CPhoneGsmSimControlParser::HandleParameterL(
|
|
301 |
TLex& aInput,
|
|
302 |
CPhoneGsmParserResult& aResult,
|
|
303 |
TParameterValidationFunction aFunc )
|
|
304 |
{
|
|
305 |
TBool result = EFalse;
|
|
306 |
|
|
307 |
TLexMark start;
|
|
308 |
aInput.Mark( start );
|
|
309 |
|
|
310 |
if ( aInput.Peek() == KPhoneSimControlAsterisk )
|
|
311 |
{
|
|
312 |
aInput.Inc();
|
|
313 |
|
|
314 |
TPtrC password( NextNumber( aInput ) );
|
|
315 |
|
|
316 |
if ( aFunc( password ) )
|
|
317 |
{
|
|
318 |
aResult.AddParameterL( password );
|
|
319 |
result = ETrue;
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
if ( !result )
|
|
324 |
{
|
|
325 |
aInput.UnGetToMark( start );
|
|
326 |
}
|
|
327 |
|
|
328 |
return result;
|
|
329 |
}
|
|
330 |
|
|
331 |
|
|
332 |
// -----------------------------------------------------------------------------
|
|
333 |
// CPhoneGsmSimControlParser::NextNumber
|
|
334 |
// -----------------------------------------------------------------------------
|
|
335 |
//
|
|
336 |
TPtrC CPhoneGsmSimControlParser::NextNumber(
|
|
337 |
TLex& aInput )
|
|
338 |
{
|
|
339 |
TLexMark start;
|
|
340 |
aInput.Mark( start );
|
|
341 |
|
|
342 |
while ( aInput.Peek().IsDigit() )
|
|
343 |
{
|
|
344 |
aInput.Inc();
|
|
345 |
}
|
|
346 |
|
|
347 |
return aInput.MarkedToken( start );
|
|
348 |
}
|
|
349 |
|
|
350 |
// -----------------------------------------------------------------------------
|
|
351 |
// CPhoneGsmSimControlParser::ValidatePin
|
|
352 |
// -----------------------------------------------------------------------------
|
|
353 |
//
|
|
354 |
TBool CPhoneGsmSimControlParser::ValidatePin( const TDesC& aParam )
|
|
355 |
{
|
|
356 |
return ( aParam.Length() >= KPhoneSimControlPinMinLength ) &&
|
|
357 |
( aParam.Length() <= KPhoneSimControlPinMaxLength );
|
|
358 |
}
|
|
359 |
|
|
360 |
// -----------------------------------------------------------------------------
|
|
361 |
// CPhoneGsmSimControlParser::ValidatePuk
|
|
362 |
// -----------------------------------------------------------------------------
|
|
363 |
//
|
|
364 |
TBool CPhoneGsmSimControlParser::ValidatePuk( const TDesC& aParam )
|
|
365 |
{
|
|
366 |
return ( aParam.Length() == KPhoneSimControlPukLength );
|
|
367 |
}
|
|
368 |
|
|
369 |
// End of File
|