|
1 /* |
|
2 * Copyright (c) 2009 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: Implementation of the VmbxUtilities class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <featmgr.h> |
|
21 #include <msssettingsobserver.h> // ALS changes |
|
22 |
|
23 #include "vmbxlogger.h" |
|
24 #include "vmbxcenrephandler.h" |
|
25 #include "vmbxemergencycall.h" |
|
26 #include "vmbxutilities.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KVmbxPhoneNumMinLength = 2; |
|
30 const TInt KVmbxPhoneNumMaxLength = 40; |
|
31 const TInt KVmbxPhoneCharMaxLength = 48; |
|
32 |
|
33 _LIT( KAllowedTelNumChars, "0123456789" ); |
|
34 _LIT( KAllowedDtmfChars, "0123456789+pwPW" ); |
|
35 _LIT( KAllowedSSChars, "*+0123456789#" ); |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS ============================= |
|
38 |
|
39 // --------------------------------------------------------------------------- |
|
40 // VmbxUtilities::IsValidPhoneNumber |
|
41 // Validates phone number |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 TBool VmbxUtilities::IsValidPhoneNumber( const TDesC& aNumber ) |
|
45 { |
|
46 VMBLOGSTRING( "VMBX: VmbxUtilities::IsValidPhoneNumber: =>" ); |
|
47 TBool result( EFalse ); |
|
48 if ( KVmbxPhoneNumMinLength < aNumber.Length() |
|
49 && KVmbxPhoneCharMaxLength >= aNumber.Length() ) |
|
50 { |
|
51 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsValidPhoneNumber: aNumber %S", |
|
52 &aNumber ); |
|
53 TLex lexer( aNumber ); |
|
54 lexer.SkipSpace(); |
|
55 TChar current = lexer.Peek(); |
|
56 // If no SS code then consider this is valid and return true. |
|
57 if ( '#' == current || '*' == current ) |
|
58 { |
|
59 // check whether accord ss regulation, |
|
60 result = ValidateSsNum( lexer ); |
|
61 } |
|
62 else |
|
63 { |
|
64 result = ValidateTelNum( lexer ); |
|
65 // If zero length then consider as valid and return value of |
|
66 // result, If not the end of the string, check if it's DTMF numbers |
|
67 if ( !lexer.Eos() && result ) |
|
68 { |
|
69 result = ValdateDtmfPart( lexer ); |
|
70 } |
|
71 } |
|
72 } |
|
73 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsValidPhoneNumber: result = %d<=", |
|
74 result ); |
|
75 return result; |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------------------------- |
|
79 // VmbxUtilities::AlsLine |
|
80 // |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 TVmbxAlsLineType VmbxUtilities::AlsLine() |
|
84 { |
|
85 VMBLOGSTRING( "VMBX: VmbxUtilities::AlsLine: =>" ); |
|
86 TInt ssLine( ESSSettingsAlsNotSupported ); |
|
87 TVmbxAlsLineType alsLine( EVmbxAlsLineDefault ); |
|
88 RSSSettings ssSettings; |
|
89 TInt res = ssSettings.Open(); |
|
90 if( KErrNone == res ) |
|
91 { |
|
92 res = ssSettings.Get( ESSSettingsAls, ssLine ); |
|
93 if( KErrNone == res ) |
|
94 { |
|
95 if ( ESSSettingsAlsAlternate == ssLine ) |
|
96 { |
|
97 alsLine = EVmbxAlsLine2; |
|
98 } |
|
99 else if ( ESSSettingsAlsPrimary == ssLine ) |
|
100 { |
|
101 alsLine = EVmbxAlsLine1; |
|
102 } |
|
103 } |
|
104 } |
|
105 ssSettings.Close(); |
|
106 VMBLOGSTRING2( "VMBX: VmbxUtilities::AlsLine: alsLine=%I <=", |
|
107 alsLine ); |
|
108 return alsLine; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CVmbxUiUtilities::VideoSupported |
|
113 // |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 TBool VmbxUtilities::VideoSupported() |
|
117 { |
|
118 VMBLOGSTRING( "VMBX: VmbxUtilities::VideoSupported: =>" ); |
|
119 TBool result( EFalse ); |
|
120 |
|
121 if ( FeatureManager::FeatureSupported( KFeatureIdCsVideoTelephony ) ) |
|
122 { |
|
123 CVmbxCenRepHandler* cenRepHandler( NULL ); |
|
124 // TRAP_IGNORE for no leave function |
|
125 TRAP_IGNORE( cenRepHandler = CVmbxCenRepHandler::NewL() ); |
|
126 if ( cenRepHandler ) |
|
127 { |
|
128 result = cenRepHandler->VideoSupported(); |
|
129 } |
|
130 delete cenRepHandler; |
|
131 cenRepHandler = NULL; |
|
132 } |
|
133 VMBLOGSTRING2( "VMBX: VmbxUtilities::VideoSupported: %d <=", result ); |
|
134 return result; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // VmbxUtilities::IsEmergencyNumber |
|
139 // Verifies if the given number is an emergency number |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 TBool VmbxUtilities::IsEmergencyNumber( const TDesC& aNumber ) |
|
143 { |
|
144 VMBLOGSTRING( "VMBX: VmbxUtilities::IsEmergencyNumber: =>" ); |
|
145 TBool result( EFalse ); |
|
146 CVmbxEmergencyCall* emergencyCall( NULL ); |
|
147 // TRAP_IGNORE for no leave function |
|
148 TRAP_IGNORE( emergencyCall = CVmbxEmergencyCall::NewL() ); |
|
149 if ( emergencyCall ) |
|
150 { |
|
151 result = emergencyCall->IsEmergencyNumber( aNumber ); |
|
152 } |
|
153 delete emergencyCall; |
|
154 emergencyCall = NULL; |
|
155 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsEmergencyNumber: result%d <=", |
|
156 result); |
|
157 return result; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // CVmbxUiUtilities::VoIPSupported |
|
162 // |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 TBool VmbxUtilities::VoIPSupported() |
|
166 { |
|
167 VMBLOGSTRING( "VMBX: VmbxUtilities::VoIPSupported: <=>" ); |
|
168 return FeatureManager::FeatureSupported( KFeatureIdCommonVoip ); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
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 |
|
228 // Parses string until end or invalid tel number character is found. |
|
229 // Check number length. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 TBool VmbxUtilities::ValidateTelNum( TLex& aLexer ) |
|
233 { |
|
234 VMBLOGSTRING( "VMBX: VmbxUtilities::ValidateTelNum: =>" ); |
|
235 TBool result( ETrue ); |
|
236 |
|
237 // Skip country code prefix '+' |
|
238 if ( '+' == aLexer.Peek() ) |
|
239 { |
|
240 aLexer.Inc(); // Skip country code separator |
|
241 } |
|
242 |
|
243 TInt telNumDigits( 0 ); |
|
244 TBool invalidCharFound( EFalse ); |
|
245 // Parse until invalid telnumber char found |
|
246 while ( !aLexer.Eos() && !invalidCharFound ) |
|
247 { |
|
248 const TChar nextChar = aLexer.Peek(); |
|
249 // Check validSS chars |
|
250 if ( KErrNotFound == KAllowedTelNumChars().Locate( nextChar ) ) |
|
251 { |
|
252 // Invalid char found so string before it is the tel number part |
|
253 invalidCharFound = ETrue; |
|
254 } |
|
255 else |
|
256 { |
|
257 aLexer.Inc(); |
|
258 telNumDigits++; |
|
259 } |
|
260 } |
|
261 |
|
262 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
|
263 telNumDigits %d", telNumDigits ); |
|
264 |
|
265 if ( KVmbxPhoneNumMinLength > telNumDigits |
|
266 || KVmbxPhoneNumMaxLength < telNumDigits |
|
267 || invalidCharFound ) |
|
268 { |
|
269 result = EFalse; |
|
270 } |
|
271 |
|
272 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
|
273 result %d<=", result ); |
|
274 return result; |
|
275 } |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // VmbxUtilities::ValdateDtmfPart |
|
279 // Parse string until end and validate for allowed characters. |
|
280 // ----------------------------------------------------------------------------- |
|
281 // |
|
282 TBool VmbxUtilities::ValdateDtmfPart( TLex& aLexer ) |
|
283 { |
|
284 VMBLOGSTRING( "VMBX: VmbxUtilities::ValdateDtmfPart: =>" ); |
|
285 // DTMF string consists of following three parts: |
|
286 // the first part of the string is a phone number, |
|
287 // 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 |
|
289 // remote end. |
|
290 TBool result( ETrue ); |
|
291 TLex lexer( aLexer ); |
|
292 TInt telNumDigitsBeforeDtmf( 0 ); |
|
293 TBool isDtmfNumberDiscover( EFalse ); |
|
294 TBool invalidCharFound( EFalse ); |
|
295 // check the second part of the string |
|
296 while ( !lexer.Eos() && !invalidCharFound ) |
|
297 { |
|
298 const TChar nextChar = aLexer.Peek(); |
|
299 // Check valid DTMF chars |
|
300 if ( KErrNotFound == KAllowedDtmfChars().Locate( lexer.Get() ) ) |
|
301 { |
|
302 invalidCharFound = ETrue; |
|
303 } |
|
304 else |
|
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 } |
|
329 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValdateDtmfPart: result = %d<=", |
|
330 result ); |
|
331 return result; |
|
332 } |
|
333 |
|
334 // End of file |