|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Meta-database declarations for use to store Comms Data on the device |
|
15 // All Data PublishedAll |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file CCommsDatUtilImpl.cpp |
|
21 */ |
|
22 |
|
23 #include "CommsDatInternalDefs.h" |
|
24 #include <commsdatutils.h> |
|
25 #include "CommsDatTypesV1_1.h" |
|
26 #include <comms-infras/commsdatschema.h> |
|
27 |
|
28 using namespace CommsDat; |
|
29 using namespace CommsDatUtils; |
|
30 |
|
31 |
|
32 EXPORT_C CCommsDatUtils* CCommsDatUtils::NewL() |
|
33 /* |
|
34 |
|
35 @publishedAll |
|
36 */ |
|
37 { |
|
38 CCommsDatUtils* ptrUtils=new(ELeave) CCommsDatUtils(); |
|
39 CleanupStack::PushL(ptrUtils); |
|
40 ptrUtils->ConstructL(); |
|
41 CleanupStack::Pop(ptrUtils); |
|
42 return ptrUtils; |
|
43 } |
|
44 |
|
45 void CCommsDatUtils::ConstructL() |
|
46 { |
|
47 iUtilsImpl = new (ELeave) CCommsDatUtilImpl(); |
|
48 } |
|
49 |
|
50 EXPORT_C CCommsDatUtils::~CCommsDatUtils() |
|
51 /* |
|
52 |
|
53 @publishedAll |
|
54 */ |
|
55 { |
|
56 delete iUtilsImpl; |
|
57 } |
|
58 |
|
59 EXPORT_C void CCommsDatUtils::ResolvePhoneNumberL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId) |
|
60 /* |
|
61 |
|
62 @publishedAll |
|
63 */ |
|
64 { |
|
65 #ifndef __TOOLS2__ |
|
66 CCommsDatUtilImpl* tUtilsImpl = new (ELeave) CCommsDatUtilImpl(); |
|
67 CleanupStack::PushL(tUtilsImpl); |
|
68 tUtilsImpl->ResolvePhoneNumberL(aNumber, aDialString, aDialParseMode, aLocationId, aChargecardId); |
|
69 CleanupStack::PopAndDestroy(tUtilsImpl); |
|
70 #endif |
|
71 } |
|
72 |
|
73 EXPORT_C void CCommsDatUtils::ResolvePhoneNumberFromDatabaseL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId) |
|
74 /* |
|
75 |
|
76 @publishedAll |
|
77 */ |
|
78 { |
|
79 CCommsDatUtils::ResolvePhoneNumberL(aNumber, aDialString, aDialParseMode, aLocationId, aChargecardId); |
|
80 } |
|
81 |
|
82 |
|
83 EXPORT_C TInt CCommsDatUtils::CheckReadCapability( const TDesC& aField, const RMessagePtr2* aMessage ) |
|
84 /* |
|
85 |
|
86 @publishedAll |
|
87 */ |
|
88 { |
|
89 return (iUtilsImpl->CheckReadCapability(aField,aMessage)); |
|
90 } |
|
91 |
|
92 |
|
93 EXPORT_C TInt CCommsDatUtils::CheckWriteCapability( const TDesC& aField, const RMessagePtr2* aMessage ) |
|
94 /* |
|
95 |
|
96 @publishedAll |
|
97 */ |
|
98 { |
|
99 return (iUtilsImpl->CheckWriteCapability(aField,aMessage)); |
|
100 } |
|
101 |
|
102 |
|
103 //CCommsDatUtilImpl// |
|
104 |
|
105 |
|
106 void CCommsDatUtilImpl::ResolvePhoneNumberL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId) |
|
107 { |
|
108 #ifndef __TOOLS2__ |
|
109 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
110 idbSession =CMDBSession::NewL(KCDVersion1_2); |
|
111 #else |
|
112 idbSession =CMDBSession::NewL(KCDVersion1_1); |
|
113 #endif |
|
114 CleanupStack::PushL(idbSession); |
|
115 idbSession->OpenTransactionL(); |
|
116 |
|
117 TRAPD(ret,this->ResolvePhoneNumberFromDatabaseL(aNumber,aDialString,aDialParseMode,aLocationId,aChargecardId)); |
|
118 |
|
119 if (ret==KErrNone) |
|
120 idbSession->CommitTransactionL(); |
|
121 else |
|
122 { |
|
123 idbSession->RollbackTransactionL(); |
|
124 User::Leave(ret); |
|
125 } |
|
126 CleanupStack::PopAndDestroy(idbSession); |
|
127 idbSession = NULL; |
|
128 #endif |
|
129 } |
|
130 |
|
131 |
|
132 void CCommsDatUtilImpl::ResolvePhoneNumberFromDatabaseL(TDesC& aNumber, TDes& aDialString, TParseMode aDialParseMode, TUint32 aLocationId, TUint32 aChargecardId) |
|
133 { |
|
134 #ifndef __TOOLS2__ |
|
135 TDialLocation location; |
|
136 PopulateDialLocationL(aLocationId,location); |
|
137 |
|
138 if (location.IsMobile()) // Special case - don't resolve for mobile locations |
|
139 { |
|
140 aDialString.Copy(aNumber); |
|
141 return; |
|
142 } |
|
143 |
|
144 TChargeCard chargeCard; |
|
145 if (aChargecardId!=0) |
|
146 { |
|
147 PopulateChargeCardL(aChargecardId,chargeCard); |
|
148 if (aDialParseMode==EForDisplay) // Hide the pin if displaying |
|
149 { |
|
150 TChargeCardPin blank; |
|
151 blank.Fill(TChar(KStarChar),chargeCard.Pin().Length()); |
|
152 chargeCard.SetPin(blank); |
|
153 } |
|
154 } |
|
155 |
|
156 // Do parsing (using DIAL parse routine) |
|
157 |
|
158 // Work around for bug in DIAL where if there is no plus the number will not be appended |
|
159 TDialString tempDialString; |
|
160 if (aNumber.Locate(KPlusChar)==KErrNotFound && aNumber.Length()>0) // needs to be Locate() to mimic DIAL |
|
161 User::LeaveIfError(TelephoneNumber::Parse(tempDialString,location,chargeCard,KNullDesC,aDialParseMode)); |
|
162 |
|
163 TDialString dialString; |
|
164 User::LeaveIfError(TelephoneNumber::Parse(dialString,location,chargeCard,aNumber,aDialParseMode)); |
|
165 |
|
166 // more of the work around.... |
|
167 if (dialString.CompareF(tempDialString)==KErrNone) |
|
168 { |
|
169 // the number has not been appended |
|
170 if ((dialString.Length()+aNumber.Length())<=dialString.MaxLength()) |
|
171 dialString.Append(aNumber); |
|
172 else |
|
173 User::Leave(KErrOverflow); |
|
174 } |
|
175 |
|
176 aDialString.Copy(dialString); |
|
177 #endif |
|
178 } |
|
179 |
|
180 |
|
181 |
|
182 void CCommsDatUtilImpl::PopulateDialLocationL(TUint32 aId, TDialLocation& aLocation) |
|
183 { |
|
184 #ifndef __TOOLS2__ |
|
185 CCDLocationRecord *locationRecord = static_cast<CCDLocationRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdLocationRecord)); |
|
186 CleanupStack::PushL(locationRecord); |
|
187 |
|
188 locationRecord->SetRecordId(aId); |
|
189 locationRecord->LoadL(*idbSession); |
|
190 |
|
191 HBufC* buffer = HBufC::NewLC(KCommsDatSvrRealMaxFieldLength); |
|
192 TPtr buf (buffer->Des()); |
|
193 |
|
194 buf = locationRecord->iIntlPrefixCode; |
|
195 aLocation.SetIntlPrefCode(buf); |
|
196 buf = locationRecord->iNatPrefixCode; |
|
197 aLocation.SetNatPrefCode(buf); |
|
198 buf = locationRecord->iNatCode; |
|
199 aLocation.SetNatCode(buf); |
|
200 buf = locationRecord->iAreaCode; |
|
201 aLocation.SetAreaCode(buf); |
|
202 buf = locationRecord->iDialOutCode; |
|
203 aLocation.SetDialOutLocalCode(buf); |
|
204 aLocation.SetDialOutLongDistanceCode(buf); |
|
205 buf = locationRecord->iDisableCallWaitingCode; |
|
206 aLocation.SetDisableCallWaitingCode(buf); |
|
207 |
|
208 TBool b; |
|
209 TUint flags=0; |
|
210 b = locationRecord->iMobile; |
|
211 if (b) |
|
212 flags|=KPhoneNumberMobile; |
|
213 b = locationRecord->iUsePulseDial; |
|
214 if (b) |
|
215 flags|=KPhoneNumberUsePulseDial; |
|
216 b = locationRecord->iWaitForDialTone; |
|
217 if (b) |
|
218 flags|=KPhoneNumberWaitForDialingTone; |
|
219 aLocation.SetDialLocationFlags(flags); |
|
220 |
|
221 TUint32 i = locationRecord->iPauseAfterDialOut; |
|
222 |
|
223 aLocation.SetPauseAfterDialout(i); |
|
224 |
|
225 CleanupStack::PopAndDestroy(buffer); |
|
226 CleanupStack::PopAndDestroy(locationRecord); |
|
227 #endif |
|
228 } |
|
229 |
|
230 |
|
231 |
|
232 void CCommsDatUtilImpl::PopulateChargeCardL(TUint32 aId, TChargeCard& aChargeCard) |
|
233 { |
|
234 #ifndef __TOOLS2__ |
|
235 CCDChargecardRecord *chargecardRecord = static_cast<CCDChargecardRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdChargecardRecord)); |
|
236 CleanupStack::PushL(chargecardRecord); |
|
237 |
|
238 // load data for requested recordId |
|
239 chargecardRecord->SetRecordId(aId); |
|
240 chargecardRecord->LoadL(*idbSession); |
|
241 |
|
242 HBufC* buffer = HBufC::NewLC(KCommsDatSvrRealMaxFieldLength); |
|
243 TPtr buf (buffer->Des()); |
|
244 |
|
245 buf = chargecardRecord->iAccountNo; |
|
246 aChargeCard.SetNumber(buf); |
|
247 buf = chargecardRecord->iPin; |
|
248 aChargeCard.SetPin(buf); |
|
249 buf = chargecardRecord->iLocalRule; |
|
250 aChargeCard.SetLocalRule(buf); |
|
251 buf = chargecardRecord->iNatRule; |
|
252 aChargeCard.SetNatRule(buf); |
|
253 buf = chargecardRecord->iIntlRule; |
|
254 aChargeCard.SetIntlRule(buf); |
|
255 |
|
256 CleanupStack::PopAndDestroy(buffer); |
|
257 CleanupStack::PopAndDestroy(chargecardRecord); |
|
258 #endif |
|
259 } |
|
260 |
|
261 |
|
262 TInt CCommsDatUtilImpl::CheckReadCapability( const TDesC& /*aField*/, const RMessagePtr2* /*aMessage*/ ) |
|
263 { |
|
264 return KErrNone; //todo to be implemented |
|
265 } |
|
266 |
|
267 |
|
268 TInt CCommsDatUtilImpl::CheckWriteCapability( const TDesC& /*aField*/, const RMessagePtr2* /*aMessage*/ ) |
|
269 { |
|
270 return KErrNone; //todo to be implemented |
|
271 } |
|
272 |
|
273 |
|
274 |
|
275 CCommsDatUtilImpl::~CCommsDatUtilImpl() |
|
276 { |
|
277 //delete idbSession; |
|
278 } |
|
279 |
|
280 |
|
281 #ifndef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
282 namespace |
|
283 { |
|
284 |
|
285 |
|
286 _LIT(KSlash, "\\"); |
|
287 |
|
288 inline TBool EndOfTable(const STableLookup& aEntry ) |
|
289 { |
|
290 TBool retval = ( aEntry.iTableId == 0 |
|
291 && aEntry.iTableName == NULL |
|
292 && aEntry.iFields == NULL ); |
|
293 return retval; |
|
294 } |
|
295 |
|
296 inline TBool EndOfTable(const CommsDat::SRecordTypeInfo& aEntry) |
|
297 { |
|
298 TBool retval = ( aEntry.iTypeId == 0 |
|
299 && aEntry.iValType == 0 |
|
300 && aEntry.iTypeAttr == CommsDat::ENoAttrs |
|
301 && aEntry.iTypeName == NULL ); |
|
302 |
|
303 return retval; |
|
304 } |
|
305 |
|
306 |
|
307 const STableLookup* GetTable(CommsDat::TMDBElementId aTable) |
|
308 { |
|
309 const STableLookup* retval = NULL; |
|
310 TInt index = 0; |
|
311 |
|
312 const STableLookup* entry = &CommsDatSchemaV1_1::iTableLookup[0]; |
|
313 |
|
314 while ( !EndOfTable( *entry ) ) |
|
315 { |
|
316 if ( entry->iTableId == aTable ) |
|
317 { |
|
318 retval = entry; |
|
319 break; // while |
|
320 } |
|
321 index++; |
|
322 entry = &CommsDatSchemaV1_1::iTableLookup[index]; |
|
323 } |
|
324 |
|
325 return retval; |
|
326 } |
|
327 |
|
328 const CommsDat::SRecordTypeInfo* FieldWithinTable(CommsDat::TMDBElementId aField, const CommsDat::SRecordTypeInfo aTable[]) |
|
329 { |
|
330 const CommsDat::SRecordTypeInfo* retval = NULL; |
|
331 const CommsDat::SRecordTypeInfo* entry = &aTable[0]; |
|
332 TInt index = 0; |
|
333 |
|
334 while( !EndOfTable( *entry ) ) |
|
335 { |
|
336 if ( entry->iTypeId == aField ) |
|
337 { |
|
338 retval = entry; |
|
339 break; |
|
340 } |
|
341 index++; |
|
342 entry = &aTable[index]; |
|
343 } |
|
344 |
|
345 return retval; |
|
346 } |
|
347 } // end of nameless namespace |
|
348 |
|
349 |
|
350 EXPORT_C TInt NameLookUp::FieldNameLookup(CommsDat::TMDBElementId aElementId, HBufC*& aFieldName, TInt& aDataType ) |
|
351 { |
|
352 TInt retval = KErrNotFound; |
|
353 CommsDat::TMDBElementId cleanElementId = aElementId & KCDMaskShowType; // 0x7fff0000; // remove last two bytes; not needed |
|
354 CommsDat::TMDBElementId table = cleanElementId & KCDMaskShowRecordType; |
|
355 CommsDat::TMDBElementId fieldInTable = cleanElementId; |
|
356 |
|
357 const STableLookup* tablePtr = NULL; |
|
358 const CommsDat::SRecordTypeInfo* fieldPtr = NULL; |
|
359 |
|
360 // find table |
|
361 tablePtr = GetTable(table); |
|
362 if ( tablePtr ) |
|
363 { |
|
364 fieldPtr = FieldWithinTable(fieldInTable, tablePtr->iFields); |
|
365 |
|
366 if ( fieldPtr == NULL ) |
|
367 { |
|
368 // field not found, this could be because we're dealing with a base |
|
369 // class id, mask out table info and search again. |
|
370 fieldInTable = cleanElementId & KCDMaskShowFieldType; |
|
371 fieldPtr = FieldWithinTable(fieldInTable, tablePtr->iFields); |
|
372 } |
|
373 } |
|
374 |
|
375 if ( fieldPtr ) |
|
376 { |
|
377 const TPtrC tableName( tablePtr->iTableName ); |
|
378 const TPtrC fieldName( fieldPtr->iTypeName ); |
|
379 |
|
380 TInt stringLength = tableName.Length() + fieldName.Length() + KSlash().Length(); |
|
381 TInt error = KErrNone; |
|
382 HBufC* ptr = HBufC::New( stringLength ); |
|
383 TPtr destination( 0, 0); |
|
384 |
|
385 if ( ptr != NULL ) |
|
386 { |
|
387 destination.Set( ptr->Des() ); |
|
388 } |
|
389 else |
|
390 { |
|
391 error = KErrNoMemory; |
|
392 } |
|
393 |
|
394 if ( error == KErrNone ) |
|
395 { |
|
396 destination.Append( tableName ); |
|
397 destination.Append( KSlash ); |
|
398 destination.Append( fieldName ); |
|
399 aFieldName = ptr; |
|
400 aDataType = fieldPtr->iValType; |
|
401 retval = KErrNone; |
|
402 } |
|
403 else |
|
404 { |
|
405 delete ptr; |
|
406 aFieldName = NULL; |
|
407 retval = error; |
|
408 } |
|
409 |
|
410 } |
|
411 |
|
412 return retval; |
|
413 } |
|
414 |
|
415 #endif // SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
416 |