1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
22 |
22 |
23 #include "vmbxlogger.h" |
23 #include "vmbxlogger.h" |
24 #include "vmbxcenrephandler.h" |
24 #include "vmbxcenrephandler.h" |
25 #include "vmbxemergencycall.h" |
25 #include "vmbxemergencycall.h" |
26 #include "vmbxutilities.h" |
26 #include "vmbxutilities.h" |
|
27 #include "voicemailboxdefsinternal.h" |
27 |
28 |
28 // CONSTANTS |
29 // CONSTANTS |
29 const TInt KVmbxPhoneNumMinLength = 2; |
30 const TInt KVmbxPhoneNumMinLength = 2; |
30 const TInt KVmbxPhoneNumMaxLength = 40; |
31 const TInt KVmbxPhoneNumMaxLength = 40; |
31 const TInt KVmbxPhoneCharMaxLength = 48; |
|
32 |
32 |
33 _LIT( KAllowedTelNumChars, "0123456789" ); |
33 _LIT( KAllowedTelNumChars, "0123456789" ); |
34 _LIT( KAllowedDtmfChars, "0123456789+pwPW" ); |
|
35 _LIT( KAllowedSSChars, "*+0123456789#" ); |
|
36 |
34 |
37 // ============================ MEMBER FUNCTIONS ============================= |
35 // ============================ MEMBER FUNCTIONS ============================= |
38 |
36 |
39 // --------------------------------------------------------------------------- |
37 // --------------------------------------------------------------------------- |
40 // VmbxUtilities::IsValidPhoneNumber |
38 // VmbxUtilities::IsValidPhoneNumber |
52 &aNumber ); |
50 &aNumber ); |
53 TLex lexer( aNumber ); |
51 TLex lexer( aNumber ); |
54 lexer.SkipSpace(); |
52 lexer.SkipSpace(); |
55 TChar current = lexer.Peek(); |
53 TChar current = lexer.Peek(); |
56 // If no SS code then consider this is valid and return true. |
54 // If no SS code then consider this is valid and return true. |
57 if ( '#' == current || '*' == current ) |
55 if ( '*' == current ) |
58 { |
56 { |
59 // check whether accord ss regulation, |
57 // check whether accord ss regulation, |
60 result = ValidateSsNum( lexer ); |
58 lexer.Inc(); // Skip first * |
61 } |
59 } |
62 else |
60 result = ValidateTelNum( lexer ); |
63 { |
61 // If zero length then consider as valid and return value of |
64 result = ValidateTelNum( lexer ); |
62 // result, If not the end of the string, check if it's DTMF numbers |
65 // If zero length then consider as valid and return value of |
63 if ( !lexer.Eos() && result ) |
66 // result, If not the end of the string, check if it's DTMF numbers |
64 { |
67 if ( !lexer.Eos() && result ) |
65 result = ValdateDtmfPart( lexer ); |
68 { |
66 } |
69 result = ValdateDtmfPart( lexer ); |
67 } |
70 } |
|
71 } |
|
72 } |
|
73 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsValidPhoneNumber: result = %d<=", |
68 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsValidPhoneNumber: result = %d<=", |
74 result ); |
69 result ); |
75 return result; |
70 return result; |
76 } |
71 } |
77 |
72 |
167 VMBLOGSTRING( "VMBX: VmbxUtilities::VoIPSupported: <=>" ); |
162 VMBLOGSTRING( "VMBX: VmbxUtilities::VoIPSupported: <=>" ); |
168 return FeatureManager::FeatureSupported( KFeatureIdCommonVoip ); |
163 return FeatureManager::FeatureSupported( KFeatureIdCommonVoip ); |
169 } |
164 } |
170 |
165 |
171 // ----------------------------------------------------------------------------- |
166 // ----------------------------------------------------------------------------- |
172 // VmbxUtilities::ValidateSSfix |
|
173 // Skips over SS code if it exists. |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 TBool VmbxUtilities::ValidateSsNum( TLex& aLexer ) |
|
177 { |
|
178 VMBLOGSTRING( "VMBX: VmbxUtilities::ValidateSsNum: =>" ); |
|
179 //The procedure always starts with *, #, **, ## or *# and is finished by #. |
|
180 // Each part within the procedure is separated by *. |
|
181 |
|
182 TBool result( EFalse ); |
|
183 // Get and skip the first '#' or '*' separator |
|
184 TChar current = aLexer.Get(); |
|
185 |
|
186 current = aLexer.Peek(); |
|
187 |
|
188 if ( '#' == current || '*' == current ) |
|
189 { |
|
190 aLexer.Inc(); // Skip the second '#' or '*' separator |
|
191 } |
|
192 // Define another string which aready skip the prefix '*' or |
|
193 // '#', the sring to judge the string whether end of '#' and |
|
194 // valid |
|
195 TLex nextLexer( aLexer ); |
|
196 TChar nextChar = nextLexer.Peek(); |
|
197 TBool invalidCharFound( EFalse ); |
|
198 while ( !nextLexer.Eos() && !invalidCharFound ) |
|
199 { |
|
200 nextChar = nextLexer.Get(); |
|
201 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
|
202 nextChar %S", &nextChar ); |
|
203 // Check the string valid or invalid for SS string |
|
204 if ( KErrNotFound == KAllowedSSChars().Locate( nextChar ) ) |
|
205 { |
|
206 invalidCharFound = ETrue; |
|
207 } |
|
208 } |
|
209 |
|
210 // Check if the string end of '#' and check if it's validate ss code. |
|
211 if ( nextLexer.Eos() && ( '#' == nextChar ) && !invalidCharFound ) |
|
212 { |
|
213 result = ETrue; |
|
214 if ( result && !aLexer.Eos() ) |
|
215 { |
|
216 // It already skip prefix and |
|
217 // Check SC(Service Code) length,it should be more than 2 digits |
|
218 result = ValidateTelNum( aLexer ); |
|
219 } |
|
220 } |
|
221 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateSsNum: result = %d<=", |
|
222 result ); |
|
223 return result; |
|
224 } |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 // VmbxUtilities::ValidateTelNum |
167 // VmbxUtilities::ValidateTelNum |
228 // Parses string until end or invalid tel number character is found. |
168 // Parses string until end or invalid tel number character is found. |
229 // Check number length. |
169 // Check number length. |
230 // ----------------------------------------------------------------------------- |
170 // ----------------------------------------------------------------------------- |
231 // |
171 // |
259 } |
199 } |
260 } |
200 } |
261 |
201 |
262 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
202 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
263 telNumDigits %d", telNumDigits ); |
203 telNumDigits %d", telNumDigits ); |
264 |
204 // digitlength <3 or digit length>40, invalid telnumber |
265 if ( KVmbxPhoneNumMinLength > telNumDigits |
205 if ( KVmbxPhoneNumMinLength >= telNumDigits |
266 || KVmbxPhoneNumMaxLength < telNumDigits |
206 || KVmbxPhoneNumMaxLength < telNumDigits |
267 || invalidCharFound ) |
207 ) |
268 { |
208 { |
269 result = EFalse; |
209 result = EFalse; |
270 } |
210 } |
271 |
|
272 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
211 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
273 result %d<=", result ); |
212 result %d<=", result ); |
274 return result; |
213 return result; |
275 } |
214 } |
276 |
215 |
285 // DTMF string consists of following three parts: |
224 // DTMF string consists of following three parts: |
286 // the first part of the string is a phone number, |
225 // the first part of the string is a phone number, |
287 // the second part of the string a DTMF special character (p, w or +), |
226 // the second part of the string a DTMF special character (p, w or +), |
288 // the last third part is an actual DTMF tone string, which is sent to the |
227 // the last third part is an actual DTMF tone string, which is sent to the |
289 // remote end. |
228 // remote end. |
290 TBool result( ETrue ); |
229 TBool result( EFalse ); |
291 TLex lexer( aLexer ); |
|
292 TInt telNumDigitsBeforeDtmf( 0 ); |
|
293 TBool isDtmfNumberDiscover( EFalse ); |
|
294 TBool invalidCharFound( EFalse ); |
|
295 // check the second part of the string |
230 // check the second part of the string |
296 while ( !lexer.Eos() && !invalidCharFound ) |
231 const TChar nextChar = aLexer.Peek(); |
297 { |
232 // Check DTMF number discover or not |
298 const TChar nextChar = aLexer.Peek(); |
233 if ( 'p' == nextChar || 'P' == nextChar |
299 // Check valid DTMF chars |
234 || 'w'== nextChar || 'W' == nextChar || '+' == nextChar ) |
300 if ( KErrNotFound == KAllowedDtmfChars().Locate( lexer.Get() ) ) |
235 { |
301 { |
236 // After DTMF char, is tone string, there is no specfic rule about tone string, |
302 invalidCharFound = ETrue; |
237 // so just do a simple check. |
303 } |
238 result = ETrue; |
304 else |
239 VMBLOGSTRING( "VMBX: VmbxUtilities::ValdateDtmfPart DtmfNumberDiscover" ); |
305 { |
|
306 // Check DTMF number discover or not |
|
307 if ( 'p' == nextChar || 'P'== nextChar |
|
308 || 'w'== nextChar || 'w'== nextChar ) |
|
309 { |
|
310 isDtmfNumberDiscover = ETrue; |
|
311 } |
|
312 // Telnumber count without '+' before 'p' or 'w' |
|
313 if ( '+' != aLexer.Peek() && !isDtmfNumberDiscover ) |
|
314 { |
|
315 telNumDigitsBeforeDtmf++; |
|
316 } |
|
317 aLexer.Inc(); |
|
318 } |
|
319 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValdateDtmfPart:\ |
|
320 telNumDigitsBeforeDtmf %d", telNumDigitsBeforeDtmf ); |
|
321 } |
|
322 |
|
323 if ( KVmbxPhoneNumMinLength > telNumDigitsBeforeDtmf |
|
324 || KVmbxPhoneNumMaxLength < telNumDigitsBeforeDtmf |
|
325 || invalidCharFound ) |
|
326 { |
|
327 result = EFalse; |
|
328 } |
240 } |
329 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValdateDtmfPart: result = %d<=", |
241 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValdateDtmfPart: result = %d<=", |
330 result ); |
242 result ); |
331 return result; |
243 return result; |
332 } |
244 } |