33
|
1 |
/*
|
|
2 |
* Copyright (c) 2004-2005 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: Provides DOS emergency number policy API implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "cdosemergencynumberpolicy.h"
|
|
21 |
#include <mmtsy_names.h>
|
|
22 |
#include <telservicesvariant.hrh>
|
|
23 |
|
|
24 |
#include <centralrepository.h>
|
|
25 |
#include <telservicesinternalcrkeys.h>
|
|
26 |
#include <defaultemergencynumberscrkeys.h>
|
|
27 |
|
|
28 |
// CONSTANT
|
|
29 |
const TInt KDosEmergencyNumberMaxLength = 6;
|
|
30 |
//Prefix for Sip.
|
|
31 |
_LIT( KSipPrefix, "sip:" );
|
|
32 |
//Prefix for Tel.
|
|
33 |
_LIT( KTelPrefix, "tel:" );
|
|
34 |
//Prefix for Sos.
|
|
35 |
_LIT( KSosPrefix, "sos:" );
|
|
36 |
// @ char
|
|
37 |
_LIT( KAt, "@" );
|
|
38 |
// Prefix length
|
|
39 |
const TInt KPrefixLength = 4;
|
|
40 |
|
|
41 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
42 |
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
// CDosEmergencyNumberPolicy::~CDosEmergencyNumberPolicy()
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
//
|
|
47 |
CDosEmergencyNumberPolicy::~CDosEmergencyNumberPolicy()
|
|
48 |
{
|
|
49 |
if ( iListener )
|
|
50 |
{
|
|
51 |
iListener->StopListening();
|
|
52 |
delete iListener;
|
|
53 |
}
|
|
54 |
delete iCenRep;
|
|
55 |
|
|
56 |
iProductSpecificList.Zero();
|
|
57 |
|
|
58 |
iCustomPhone.Close();
|
|
59 |
iMobilePhone.Close();
|
|
60 |
}
|
|
61 |
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
// CDosEmergencyNumberPolicy::ConstructL()
|
|
64 |
// -----------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
void CDosEmergencyNumberPolicy::ConstructL( RTelServer& aETelServer )
|
|
67 |
{
|
|
68 |
iETelServer = aETelServer;
|
|
69 |
|
|
70 |
User::LeaveIfError( iMobilePhone.Open( iETelServer , KMmTsyPhoneName ) );
|
|
71 |
User::LeaveIfError( iCustomPhone.Open( iMobilePhone) );
|
|
72 |
|
|
73 |
TInt variantReadOnlyValues = 0;
|
|
74 |
TInt err = KErrNone;
|
|
75 |
|
|
76 |
CRepository* variationFlags = CRepository::NewL( KCRUidTelSrvVariation );
|
53
|
77 |
CleanupStack::PushL(variationFlags);
|
33
|
78 |
err = variationFlags->Get( KTelSrvVariationFlags , variantReadOnlyValues );
|
|
79 |
|
|
80 |
if ( err != KErrNotFound )
|
|
81 |
{
|
|
82 |
User::LeaveIfError( err );
|
|
83 |
}
|
|
84 |
|
|
85 |
if ( KTelSrvLVFlagAdvancedENCheck & variantReadOnlyValues )
|
|
86 |
{
|
|
87 |
iAdvancedCheck = ETrue;
|
|
88 |
}
|
|
89 |
else
|
|
90 |
{
|
|
91 |
iAdvancedCheck = EFalse;
|
|
92 |
}
|
|
93 |
|
53
|
94 |
CleanupStack::PopAndDestroy(variationFlags);
|
33
|
95 |
|
|
96 |
iCenRep = CRepository::NewL( KCRUidDefaultEmergencyNumbers );
|
|
97 |
iListener = CCenRepNotifyHandler::NewL(
|
|
98 |
*this,
|
|
99 |
*iCenRep,
|
|
100 |
CCenRepNotifyHandler::EStringKey,
|
|
101 |
KDefaultEmergencyNumbersList );
|
|
102 |
|
|
103 |
iListener->StartListeningL();
|
|
104 |
|
|
105 |
ReadProductSpecificNumbers();
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
// -----------------------------------------------------------------------------
|
|
110 |
// CDosEmergencyNumberPolicy::IsEmergencyNumberL
|
|
111 |
//
|
|
112 |
// -----------------------------------------------------------------------------
|
|
113 |
//
|
|
114 |
TInt CDosEmergencyNumberPolicy::IsEmergencyNumber (
|
|
115 |
TPhCltTelephoneNumber& aTelNumber,
|
|
116 |
TPhCltEmergencyNumberQueryMode aMode,
|
|
117 |
TBool& aIsEmergencyNumber )
|
|
118 |
{
|
|
119 |
TPhCltTelephoneNumber checkedTelNumber(aTelNumber);
|
|
120 |
ParseNumber( checkedTelNumber );
|
|
121 |
aIsEmergencyNumber = EFalse;
|
|
122 |
RMmCustomAPI::TEmerNumberCheckMode checkedNumberMode;
|
|
123 |
if ( checkedNumberMode.iNumber.MaxLength() >= checkedTelNumber.Length() ) // aTelNumber -> checkedTelNumber
|
|
124 |
{
|
|
125 |
checkedNumberMode.iNumber = checkedTelNumber; // aTelNumber -> checkedTelNumber
|
|
126 |
}
|
|
127 |
else
|
|
128 |
{
|
|
129 |
// too long, cannot be checked
|
|
130 |
return KErrArgument;
|
|
131 |
}
|
|
132 |
|
|
133 |
// set check type
|
|
134 |
switch ( aMode )
|
|
135 |
{
|
|
136 |
case EPhCltEmergencyNumberQueryModeAdvanced:
|
|
137 |
{
|
|
138 |
// check if it is a product specific number.
|
|
139 |
if ( IsInListByAdvancedMode( checkedTelNumber ) ) // aTelNumber -> checkedTelNumber
|
|
140 |
{
|
|
141 |
aTelNumber = checkedTelNumber; // aTelNumber -> checkedTelNumber
|
|
142 |
aIsEmergencyNumber = ETrue;
|
|
143 |
return KErrNone;
|
|
144 |
}
|
|
145 |
|
|
146 |
// if TSY doesn't support advanced mode, then check by S60 advanced mode
|
|
147 |
// based on TSY normal mode check.
|
|
148 |
if ( ! iAdvancedCheck )
|
|
149 |
{
|
|
150 |
TInt length =
|
|
151 |
Min( checkedTelNumber.Length(), KDosEmergencyNumberMaxLength ); // aTelNumber -> checkedTelNumber
|
|
152 |
checkedNumberMode.iCheckMode = RMmCustomAPI::EEmerNumberCheckNormal;
|
|
153 |
|
|
154 |
TInt result = KErrArgument;
|
|
155 |
while ( ( length > 0 ) && ! aIsEmergencyNumber )
|
|
156 |
{
|
|
157 |
checkedNumberMode.iNumber = checkedTelNumber.Right( length ); // aTelNumber -> checkedTelNumber
|
|
158 |
result = iCustomPhone.CheckEmergencyNumber(
|
|
159 |
checkedNumberMode, aIsEmergencyNumber );
|
|
160 |
|
|
161 |
if ( result == KErrNone && aIsEmergencyNumber )
|
|
162 |
{
|
|
163 |
aTelNumber = checkedNumberMode.iNumber;
|
|
164 |
}
|
|
165 |
|
|
166 |
length--;
|
|
167 |
}
|
|
168 |
|
|
169 |
return result;
|
|
170 |
}
|
|
171 |
else
|
|
172 |
{
|
|
173 |
checkedNumberMode.iCheckMode =
|
|
174 |
RMmCustomAPI::EEmerNumberCheckAdvanced;
|
|
175 |
}
|
|
176 |
}
|
|
177 |
break;
|
|
178 |
case EPhCltEmergencyNumberQueryModeNormal:
|
|
179 |
case EPhCltEmergencyNumberQueryModeNormalWriteback:
|
|
180 |
// check if it is a product specific number.
|
|
181 |
if ( IsInListByNormalMode( checkedTelNumber ) ) // aTelNumber -> checkedTelNumber
|
|
182 |
{
|
|
183 |
aTelNumber = checkedTelNumber; // aTelNumber -> checkedTelNumber
|
|
184 |
aIsEmergencyNumber = ETrue;
|
|
185 |
return KErrNone;
|
|
186 |
}
|
|
187 |
|
|
188 |
// flow thru
|
|
189 |
default:
|
|
190 |
checkedNumberMode.iCheckMode =
|
|
191 |
RMmCustomAPI::EEmerNumberCheckNormal;
|
|
192 |
break;
|
|
193 |
}
|
|
194 |
|
|
195 |
// do checking
|
|
196 |
TInt err = iCustomPhone.CheckEmergencyNumber (
|
|
197 |
checkedNumberMode, aIsEmergencyNumber );
|
|
198 |
|
|
199 |
aTelNumber = checkedNumberMode.iNumber;
|
|
200 |
|
|
201 |
return err;
|
|
202 |
}
|
|
203 |
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
// CDosEmergencyNumberPolicy::ReadProductSpecificNumbers
|
|
206 |
//
|
|
207 |
// Reads product specific values from central repository
|
|
208 |
// -----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
void CDosEmergencyNumberPolicy::ReadProductSpecificNumbers()
|
|
211 |
{
|
|
212 |
// This is done only once in bootup phase.
|
|
213 |
iProductSpecificList.Zero();
|
|
214 |
|
|
215 |
TInt err = KErrNone;
|
|
216 |
|
|
217 |
|
|
218 |
err = iCenRep->Get( KDefaultEmergencyNumbersList,
|
|
219 |
iProductSpecificList );
|
|
220 |
|
|
221 |
if ( err != KErrNone )
|
|
222 |
{
|
|
223 |
// just to make sure, if central repository has modified it,
|
|
224 |
// even when there was an error.
|
|
225 |
iProductSpecificList.Zero();
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
// -----------------------------------------------------------------------------
|
|
230 |
// CDosEmergencyNumberPolicy::IsInListByAdvancedMode
|
|
231 |
//
|
|
232 |
// Checks if the number is in list by advanced mode check.
|
|
233 |
//
|
|
234 |
// -----------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
TBool CDosEmergencyNumberPolicy::IsInListByAdvancedMode ( TDes& aNumber )
|
|
237 |
{
|
|
238 |
TLex list( iProductSpecificList );
|
|
239 |
TLexMark mark;
|
|
240 |
TPtrC token_candidate( KNullDesC() ) ;
|
|
241 |
|
|
242 |
for ( TInt i = 0; i < KEnPolicySDEmergencyNumberListLength; i++ )
|
|
243 |
{
|
|
244 |
list.Mark( mark );
|
|
245 |
list.SkipCharacters();
|
|
246 |
TPtrC token;
|
|
247 |
token.Set( list.MarkedToken( mark ) );
|
|
248 |
if ( token.Length() && ( token == aNumber.Right( token.Length() ) ) )
|
|
249 |
{
|
|
250 |
// _DDPRINT( 4, "ENPolicy.SDM.IsInListAdvanced.ok.", place );
|
|
251 |
if( token_candidate == KNullDesC )
|
|
252 |
{
|
|
253 |
token_candidate.Set( token );
|
|
254 |
}
|
|
255 |
else
|
|
256 |
{
|
|
257 |
if( token.Length() > token_candidate.Length() )
|
|
258 |
{
|
|
259 |
token_candidate.Set( token );
|
|
260 |
}
|
|
261 |
}
|
|
262 |
}
|
|
263 |
list.Inc();
|
|
264 |
}
|
|
265 |
|
|
266 |
if( token_candidate != KNullDesC )
|
|
267 |
{
|
|
268 |
aNumber = token_candidate;
|
|
269 |
return ETrue;
|
|
270 |
}
|
|
271 |
|
|
272 |
return EFalse;
|
|
273 |
}
|
|
274 |
|
|
275 |
// -----------------------------------------------------------------------------
|
|
276 |
// CDosEmergencyNumberPolicy::IsInListByNormalMode
|
|
277 |
//
|
|
278 |
// Checks if the number is in list by normal mode check.
|
|
279 |
//
|
|
280 |
// -----------------------------------------------------------------------------
|
|
281 |
//
|
|
282 |
TBool CDosEmergencyNumberPolicy::IsInListByNormalMode( const TDesC& aNumber )
|
|
283 |
{
|
|
284 |
TInt length = aNumber.Length();
|
|
285 |
TInt place = iProductSpecificList.Find( aNumber ); // first number of aNumber
|
|
286 |
|
|
287 |
// _DDPRINT( 4, "ENPolicy.SDM.IsInListNormal.ok.", place ); // debug print
|
|
288 |
|
|
289 |
if ( place < 0 )
|
|
290 |
{
|
|
291 |
// negative value is an error, not found!
|
|
292 |
// return immediately
|
|
293 |
return EFalse;
|
|
294 |
}
|
|
295 |
|
|
296 |
TInt endOfMatch = place + length; // end of number + 1
|
|
297 |
|
|
298 |
// we check the begining
|
|
299 |
if ( place > 0 )
|
|
300 |
{
|
|
301 |
// we are not in the begining of buffer, so we have to check
|
|
302 |
// char before that
|
|
303 |
if ( iProductSpecificList[ place -1 ] != KEnPolicySDNumberSeparator )
|
|
304 |
{
|
|
305 |
// this was just a substring numbers before that
|
|
306 |
return EFalse;
|
|
307 |
}
|
|
308 |
}
|
|
309 |
|
|
310 |
// beginning was ok, so we can continue
|
|
311 |
|
|
312 |
// now checking the end
|
|
313 |
// there must be atleast one empty space in the end that
|
|
314 |
// we do the checking of number end.
|
|
315 |
if ( endOfMatch < ( iProductSpecificList.Length() - 2 ) )
|
|
316 |
{
|
|
317 |
if ( iProductSpecificList[ endOfMatch ] != KEnPolicySDNumberSeparator )
|
|
318 |
{
|
|
319 |
return EFalse;
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
//match is wrong, only part of ememergency number is matched
|
|
324 |
int newmatchlen = 0;
|
|
325 |
for (int i = place; i < iProductSpecificList.Length(); i++)
|
|
326 |
{
|
|
327 |
if(iProductSpecificList [i] != KEnPolicySDNumberSeparator )
|
|
328 |
newmatchlen++;
|
|
329 |
else
|
|
330 |
break;
|
|
331 |
}
|
|
332 |
|
|
333 |
if (length != newmatchlen)
|
|
334 |
{
|
|
335 |
return EFalse;
|
|
336 |
}
|
|
337 |
|
|
338 |
|
|
339 |
// if we get so far, its ok.
|
|
340 |
return ETrue;
|
|
341 |
}
|
|
342 |
|
|
343 |
// -----------------------------------------------------------------------------
|
|
344 |
// CDosEmergencyNumberPolicy::ParserNumber
|
|
345 |
//
|
|
346 |
// Removes sip prefixis beging of the number and end of the number after @ char.
|
|
347 |
// @ character is also removed.
|
|
348 |
//
|
|
349 |
// -----------------------------------------------------------------------------
|
|
350 |
//
|
|
351 |
void CDosEmergencyNumberPolicy::ParseNumber( TPhCltTelephoneNumber& aTelNumber )
|
|
352 |
{
|
|
353 |
// Does number contains prefix. If yes then remove it
|
|
354 |
|
|
355 |
if ( 0 == aTelNumber.FindC( KSipPrefix ) ||
|
|
356 |
0 == aTelNumber.FindC( KTelPrefix ) ||
|
|
357 |
0 == aTelNumber.FindC( KSosPrefix ) )
|
|
358 |
{
|
|
359 |
aTelNumber.Delete( 0, KPrefixLength );
|
|
360 |
}
|
|
361 |
// Does Number contains domain part. If yes remove it at beging of @ character.
|
|
362 |
TInt atIndex = aTelNumber.Find( KAt );
|
|
363 |
TInt telNumberLength = aTelNumber.Length();
|
|
364 |
if ( 0 < atIndex &&
|
|
365 |
atIndex < telNumberLength )
|
|
366 |
{
|
|
367 |
aTelNumber.Delete( atIndex, telNumberLength - atIndex );
|
|
368 |
}
|
|
369 |
}
|
|
370 |
|
|
371 |
// -----------------------------------------------------------------------------
|
|
372 |
// CDosEmergencyNumberPolicy::HandleNotifyString
|
|
373 |
//
|
|
374 |
// Inherited from MCenRepNotifyHandlerCallback.
|
|
375 |
// -----------------------------------------------------------------------------
|
|
376 |
//
|
|
377 |
void CDosEmergencyNumberPolicy::HandleNotifyString(
|
|
378 |
TUint32 aId, const TDesC16& aNewValue )
|
|
379 |
{
|
|
380 |
if( aId == KDefaultEmergencyNumbersList )
|
|
381 |
{
|
|
382 |
iProductSpecificList.Zero();
|
|
383 |
iProductSpecificList.Copy( aNewValue );
|
|
384 |
}
|
|
385 |
|
|
386 |
}
|
|
387 |
|
|
388 |
// ========================== OTHER EXPORTED FUNCTIONS =========================
|
|
389 |
|
|
390 |
// -----------------------------------------------------------------------------
|
|
391 |
// NewEnPolicy()
|
|
392 |
//
|
|
393 |
// -----------------------------------------------------------------------------
|
|
394 |
//
|
|
395 |
EXPORT_C CEmergencyNumberPolicy* NewEnPolicyL()
|
|
396 |
{
|
|
397 |
return new (ELeave) CDosEmergencyNumberPolicy;
|
|
398 |
}
|
|
399 |
|
|
400 |
// End of File
|