1 /* |
|
2 * Copyright (c) 2009-2010 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 #include "voicemailboxdefsinternal.h" |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KVmbxPhoneNumMinLength = 2; |
|
31 const TInt KVmbxPhoneNumMaxLength = 40; |
|
32 |
|
33 _LIT( KAllowedTelNumChars, "0123456789" ); |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS ============================= |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // VmbxUtilities::IsValidPhoneNumber |
|
39 // Validates phone number |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 TBool VmbxUtilities::IsValidPhoneNumber( const TDesC& aNumber ) |
|
43 { |
|
44 VMBLOGSTRING( "VMBX: VmbxUtilities::IsValidPhoneNumber: =>" ); |
|
45 TBool result( EFalse ); |
|
46 if ( KVmbxPhoneNumMinLength < aNumber.Length() |
|
47 && KVmbxPhoneCharMaxLength >= aNumber.Length() ) |
|
48 { |
|
49 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsValidPhoneNumber: aNumber %S", |
|
50 &aNumber ); |
|
51 TLex lexer( aNumber ); |
|
52 lexer.SkipSpace(); |
|
53 TChar current = lexer.Peek(); |
|
54 // If no SS code then consider this is valid and return true. |
|
55 if ( '*' == current ) |
|
56 { |
|
57 // check whether accord ss regulation, |
|
58 lexer.Inc(); // Skip first * |
|
59 } |
|
60 result = ValidateTelNum( lexer ); |
|
61 // If zero length then consider as valid and return value of |
|
62 // result, If not the end of the string, check if it's DTMF numbers |
|
63 if ( !lexer.Eos() && result ) |
|
64 { |
|
65 result = ValdateDtmfPart( lexer ); |
|
66 } |
|
67 } |
|
68 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsValidPhoneNumber: result = %d<=", |
|
69 result ); |
|
70 return result; |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // VmbxUtilities::AlsLine |
|
75 // |
|
76 // --------------------------------------------------------------------------- |
|
77 // |
|
78 TVmbxAlsLineType VmbxUtilities::AlsLine() |
|
79 { |
|
80 VMBLOGSTRING( "VMBX: VmbxUtilities::AlsLine: =>" ); |
|
81 TInt ssLine( ESSSettingsAlsNotSupported ); |
|
82 TVmbxAlsLineType alsLine( EVmbxAlsLineDefault ); |
|
83 RSSSettings ssSettings; |
|
84 TInt res = ssSettings.Open(); |
|
85 if( KErrNone == res ) |
|
86 { |
|
87 res = ssSettings.Get( ESSSettingsAls, ssLine ); |
|
88 if( KErrNone == res ) |
|
89 { |
|
90 if ( ESSSettingsAlsAlternate == ssLine ) |
|
91 { |
|
92 alsLine = EVmbxAlsLine2; |
|
93 } |
|
94 else if ( ESSSettingsAlsPrimary == ssLine ) |
|
95 { |
|
96 alsLine = EVmbxAlsLine1; |
|
97 } |
|
98 } |
|
99 } |
|
100 ssSettings.Close(); |
|
101 VMBLOGSTRING2( "VMBX: VmbxUtilities::AlsLine: alsLine=%I <=", |
|
102 alsLine ); |
|
103 return alsLine; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // CVmbxUiUtilities::VideoSupported |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 TBool VmbxUtilities::VideoSupported() |
|
112 { |
|
113 VMBLOGSTRING( "VMBX: VmbxUtilities::VideoSupported: =>" ); |
|
114 TBool result( EFalse ); |
|
115 |
|
116 if ( FeatureManager::FeatureSupported( KFeatureIdCsVideoTelephony ) ) |
|
117 { |
|
118 CVmbxCenRepHandler* cenRepHandler( NULL ); |
|
119 // TRAP_IGNORE for no leave function |
|
120 TRAP_IGNORE( cenRepHandler = CVmbxCenRepHandler::NewL() ); |
|
121 if ( cenRepHandler ) |
|
122 { |
|
123 result = cenRepHandler->VideoSupported(); |
|
124 } |
|
125 delete cenRepHandler; |
|
126 cenRepHandler = NULL; |
|
127 } |
|
128 VMBLOGSTRING2( "VMBX: VmbxUtilities::VideoSupported: %d <=", result ); |
|
129 return result; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // VmbxUtilities::IsEmergencyNumber |
|
134 // Verifies if the given number is an emergency number |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 TBool VmbxUtilities::IsEmergencyNumber( const TDesC& aNumber ) |
|
138 { |
|
139 VMBLOGSTRING( "VMBX: VmbxUtilities::IsEmergencyNumber: =>" ); |
|
140 TBool result( EFalse ); |
|
141 CVmbxEmergencyCall* emergencyCall( NULL ); |
|
142 // TRAP_IGNORE for no leave function |
|
143 TRAP_IGNORE( emergencyCall = CVmbxEmergencyCall::NewL() ); |
|
144 if ( emergencyCall ) |
|
145 { |
|
146 result = emergencyCall->IsEmergencyNumber( aNumber ); |
|
147 } |
|
148 delete emergencyCall; |
|
149 emergencyCall = NULL; |
|
150 VMBLOGSTRING2( "VMBX: VmbxUtilities::IsEmergencyNumber: result%d <=", |
|
151 result); |
|
152 return result; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // CVmbxUiUtilities::VoIPSupported |
|
157 // |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 TBool VmbxUtilities::VoIPSupported() |
|
161 { |
|
162 VMBLOGSTRING( "VMBX: VmbxUtilities::VoIPSupported: <=>" ); |
|
163 return FeatureManager::FeatureSupported( KFeatureIdCommonVoip ); |
|
164 } |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // VmbxUtilities::ValidateTelNum |
|
168 // Parses string until end or invalid tel number character is found. |
|
169 // Check number length. |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 TBool VmbxUtilities::ValidateTelNum( TLex& aLexer ) |
|
173 { |
|
174 VMBLOGSTRING( "VMBX: VmbxUtilities::ValidateTelNum: =>" ); |
|
175 TBool result( ETrue ); |
|
176 |
|
177 // Skip country code prefix '+' |
|
178 if ( '+' == aLexer.Peek() ) |
|
179 { |
|
180 aLexer.Inc(); // Skip country code separator |
|
181 } |
|
182 |
|
183 TInt telNumDigits( 0 ); |
|
184 TBool invalidCharFound( EFalse ); |
|
185 // Parse until invalid telnumber char found |
|
186 while ( !aLexer.Eos() && !invalidCharFound ) |
|
187 { |
|
188 const TChar nextChar = aLexer.Peek(); |
|
189 // Check validSS chars |
|
190 if ( KErrNotFound == KAllowedTelNumChars().Locate( nextChar ) ) |
|
191 { |
|
192 // Invalid char found so string before it is the tel number part |
|
193 invalidCharFound = ETrue; |
|
194 } |
|
195 else |
|
196 { |
|
197 aLexer.Inc(); |
|
198 telNumDigits++; |
|
199 } |
|
200 } |
|
201 |
|
202 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
|
203 telNumDigits %d", telNumDigits ); |
|
204 // digitlength <3 or digit length>40, invalid telnumber |
|
205 if ( KVmbxPhoneNumMinLength >= telNumDigits |
|
206 || KVmbxPhoneNumMaxLength < telNumDigits |
|
207 ) |
|
208 { |
|
209 result = EFalse; |
|
210 } |
|
211 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValidateTelNum:\ |
|
212 result %d<=", result ); |
|
213 return result; |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // VmbxUtilities::ValdateDtmfPart |
|
218 // Parse string until end and validate for allowed characters. |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 TBool VmbxUtilities::ValdateDtmfPart( TLex& aLexer ) |
|
222 { |
|
223 VMBLOGSTRING( "VMBX: VmbxUtilities::ValdateDtmfPart: =>" ); |
|
224 // DTMF string consists of following three parts: |
|
225 // the first part of the string is a phone number, |
|
226 // the second part of the string a DTMF special character (p, w or +), |
|
227 // the last third part is an actual DTMF tone string, which is sent to the |
|
228 // remote end. |
|
229 TBool result( EFalse ); |
|
230 // check the second part of the string |
|
231 const TChar nextChar = aLexer.Peek(); |
|
232 // Check DTMF number discover or not |
|
233 if ( 'p' == nextChar || 'P' == nextChar |
|
234 || 'w'== nextChar || 'W' == nextChar || '+' == nextChar ) |
|
235 { |
|
236 // After DTMF char, is tone string, there is no specfic rule about tone string, |
|
237 // so just do a simple check. |
|
238 result = ETrue; |
|
239 VMBLOGSTRING( "VMBX: VmbxUtilities::ValdateDtmfPart DtmfNumberDiscover" ); |
|
240 } |
|
241 VMBLOGSTRING2( "VMBX: VmbxUtilities::ValdateDtmfPart: result = %d<=", |
|
242 result ); |
|
243 return result; |
|
244 } |
|
245 |
|
246 // End of file |
|