|
1 // Copyright (c) 1998-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 // Internet Service Provider Settings |
|
15 // |
|
16 // |
|
17 |
|
18 #include "BSP.H" |
|
19 #include "IACP.H" |
|
20 #include "gprsp.h" |
|
21 #include "IACPDEF.H" |
|
22 #include "IACPERR.H" |
|
23 |
|
24 //#include "t_tabdef.h" |
|
25 |
|
26 |
|
27 #include <ipaddr.h> |
|
28 |
|
29 _LIT(KGPRSDefaultIpAddress, "0.0.0.0"); |
|
30 |
|
31 CGprsParser::CGprsParser() |
|
32 { |
|
33 } |
|
34 |
|
35 CGprsParser* CGprsParser::NewLC() |
|
36 { |
|
37 CGprsParser* self=new (ELeave) CGprsParser(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CGprsParser* CGprsParser::NewL() |
|
44 { |
|
45 CGprsParser* self=CGprsParser::NewLC(); |
|
46 CleanupStack::Pop(); |
|
47 return self; |
|
48 } |
|
49 |
|
50 void CGprsParser::ConstructL() |
|
51 { |
|
52 iLoginPrompt=ETrue; //Mandatory Data |
|
53 iDnsFromServer= ETrue; |
|
54 |
|
55 iPdpAddress = CIpAddress::NewL(KGPRSDefaultIpAddress); |
|
56 |
|
57 iDbSession = CMDBSession::NewL(CMDBSession::LatestVersion()); |
|
58 } |
|
59 |
|
60 CGprsParser::~CGprsParser() |
|
61 { |
|
62 |
|
63 delete iName; |
|
64 delete iApn; |
|
65 delete iPdpAddress; |
|
66 delete iIfName; |
|
67 delete iLoginName; |
|
68 delete iLoginPass; |
|
69 delete iAddr; |
|
70 delete iNetMask; |
|
71 delete iDNS1; |
|
72 delete iDNS2; |
|
73 |
|
74 delete iDbSession; |
|
75 } |
|
76 |
|
77 |
|
78 void CGprsParser::CheckMandatoryFieldsL(CParsedFieldCollection& aIacpFields) |
|
79 { |
|
80 if (aIacpFields.GetFieldValue(GPRSS_APN).Length()==0) |
|
81 User::Leave(KIacpMandatoryDataNotSet); |
|
82 } |
|
83 |
|
84 void CGprsParser::ParseL(CParsedFieldCollection& aIacpFields) |
|
85 { |
|
86 TPtrC aFieldValueBuf; |
|
87 |
|
88 if (aIacpFields.GetFieldValueAndLength(GPRSS_NAME, aFieldValueBuf) != 0) |
|
89 { |
|
90 delete iName; |
|
91 iName = NULL; |
|
92 iName = aFieldValueBuf.AllocL(); |
|
93 } |
|
94 |
|
95 if (aIacpFields.GetFieldValueAndLength(GPRSS_APN, aFieldValueBuf) != 0) |
|
96 { |
|
97 delete iApn; |
|
98 iApn = NULL; |
|
99 iApn= aFieldValueBuf.AllocL(); |
|
100 } |
|
101 |
|
102 if (aIacpFields.GetFieldValueAndLength(GPRSS_PDP_TYPE, aFieldValueBuf) != 0) |
|
103 { |
|
104 aIacpFields.GetTUint32NumL(aFieldValueBuf,iPdpType); |
|
105 } |
|
106 |
|
107 if (aIacpFields.GetFieldValueAndLength(GPRSS_PDP_ADDRESS, aFieldValueBuf) != 0) |
|
108 { |
|
109 delete iPdpAddress; |
|
110 iPdpAddress = NULL; |
|
111 iPdpAddress = CIpAddress::NewL(aFieldValueBuf); |
|
112 } |
|
113 |
|
114 if (aIacpFields.GetFieldValueAndLength(GPRSS_IF_NAME, aFieldValueBuf) != 0) |
|
115 { |
|
116 delete iIfName; |
|
117 iIfName = NULL; |
|
118 iIfName= CIpAddress::NewL(aFieldValueBuf); |
|
119 } |
|
120 |
|
121 if (aIacpFields.GetFieldValueAndLength(GPRSS_LOGIN_NAME, aFieldValueBuf) != 0) |
|
122 { |
|
123 delete iLoginName; |
|
124 iLoginName = NULL; |
|
125 iLoginName= aFieldValueBuf.AllocL(); |
|
126 } |
|
127 |
|
128 if (aIacpFields.GetFieldValueAndLength(GPRSS_LOGIN_PASS, aFieldValueBuf) != 0) |
|
129 { |
|
130 delete iLoginPass; |
|
131 iLoginPass = NULL; |
|
132 iLoginPass= aFieldValueBuf.AllocL(); |
|
133 } |
|
134 |
|
135 if (aIacpFields.GetFieldValueAndLength(SMS_PROMPT_FOR_LOGIN, aFieldValueBuf) != 0) |
|
136 aIacpFields.GetTBoolL(aFieldValueBuf,iLoginPrompt); |
|
137 |
|
138 else if((iLoginName) || (iLoginPass) ) |
|
139 iLoginPrompt=EFalse; // if login Name or password is specified then this should be set to EFalse |
|
140 |
|
141 if (aIacpFields.GetFieldValueAndLength(GPRSS_IP_ADDR, aFieldValueBuf) != 0) |
|
142 { |
|
143 delete iAddr; |
|
144 iAddr = NULL; |
|
145 iAddr = CIpAddress::NewL(aFieldValueBuf); |
|
146 } |
|
147 |
|
148 if (aIacpFields.GetFieldValueAndLength(GPRSS_IP_NETMASK, aFieldValueBuf) != 0) |
|
149 { |
|
150 delete iNetMask; |
|
151 iNetMask = NULL; |
|
152 iNetMask = CIpAddress::NewL(aFieldValueBuf); |
|
153 } |
|
154 |
|
155 if (aIacpFields.GetFieldValueAndLength(GPRSS_IP_NAME_SERVER1, aFieldValueBuf) != 0) |
|
156 { |
|
157 delete iDNS1; |
|
158 iDNS1 = NULL; |
|
159 iDNS1 = CIpAddress::NewL(aFieldValueBuf); |
|
160 } |
|
161 |
|
162 if (aIacpFields.GetFieldValueAndLength(GPRSS_IP_NAME_SERVER2, aFieldValueBuf) != 0) |
|
163 { |
|
164 delete iDNS2; |
|
165 iDNS2 = NULL; |
|
166 iDNS2 = CIpAddress::NewL(aFieldValueBuf); |
|
167 } |
|
168 } |
|
169 |
|
170 void CGprsParser::ProcessL(CIacSettingsParser::TIacpConnectionPreferenceFlag& aConnectionPreference) |
|
171 { |
|
172 iNoExistingDNS = ETrue; |
|
173 |
|
174 |
|
175 WriteToGPRSTableL(EOutgoing); |
|
176 WriteToGPRSTableL(EIncoming); |
|
177 |
|
178 WriteToIAPTableL(); |
|
179 |
|
180 if(aConnectionPreference == CIacSettingsParser::EIacpAttempCreateAsFirstRank || |
|
181 aConnectionPreference == CIacSettingsParser::EIacpAttempCreateAsSecondRank) |
|
182 CreatePreferencesTableL(ECommDbConnectionDirectionOutgoing,aConnectionPreference); |
|
183 |
|
184 } |
|
185 |
|
186 void CGprsParser::WriteToIAPTableL() |
|
187 { |
|
188 CCDIAPRecord* iapRecord = static_cast<CCDIAPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord)); |
|
189 CleanupStack::PushL(iapRecord); |
|
190 iapRecord->iRecordName.SetMaxLengthL(iName->Length()); |
|
191 iapRecord->iRecordName = iName->Des(); |
|
192 TBool recordExist = FALSE; |
|
193 if(!(iapRecord->FindL(*iDbSession))) |
|
194 { |
|
195 iapRecord->SetRecordId(KCDNewRecordRequest); |
|
196 } |
|
197 else |
|
198 { |
|
199 recordExist = TRUE; |
|
200 } |
|
201 iapRecord->iServiceType.SetMaxLengthL(((TPtrC)KCDTypeNameOutgoingWCDMA).Length()); |
|
202 iapRecord->iServiceType = TPtrC(KCDTypeNameOutgoingWCDMA); |
|
203 iapRecord->iService = GetIapIdL(TPtrC(KCDTypeNameOutgoingWCDMA)); |
|
204 iapRecord->iBearerType.SetMaxLengthL(((TPtrC)KCDTypeNameModemBearer).Length()); |
|
205 iapRecord->iBearerType = TPtrC(KCDTypeNameModemBearer); |
|
206 //there are 7 fields in IAP table which cannot have null values, and so when creating an IAP record we were only filling in one of the fields which meant we were submitting a record with lots of null values which can't be handled. |
|
207 iapRecord->iBearer = 2; |
|
208 iapRecord->iNetwork = 1; |
|
209 iapRecord->iNetworkWeighting = 0; |
|
210 iapRecord->iLocation = 4; |
|
211 if (!recordExist) |
|
212 { |
|
213 iapRecord->StoreL(*iDbSession); |
|
214 } |
|
215 else |
|
216 { |
|
217 iapRecord->ModifyL(*iDbSession); |
|
218 } |
|
219 CleanupStack::PopAndDestroy(iapRecord); |
|
220 |
|
221 } |
|
222 |
|
223 void CGprsParser::CreatePreferencesTableL(TCommDbConnectionDirection aDirection, CIacSettingsParser::TIacpConnectionPreferenceFlag& aConnectionPreference) |
|
224 { |
|
225 CCDConnectionPrefsRecord* connectionPrefsRecord = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord)); |
|
226 CleanupStack::PushL(connectionPrefsRecord); |
|
227 connectionPrefsRecord->iRanking = aConnectionPreference; |
|
228 connectionPrefsRecord->iDirection = aDirection; |
|
229 connectionPrefsRecord->iDialogPref = ECommDbDialogPrefPrompt; |
|
230 connectionPrefsRecord->iBearerSet = ECommDbBearerWcdma; |
|
231 connectionPrefsRecord->SetRecordId(iRecordId); |
|
232 if ( connectionPrefsRecord->FindL(*iDbSession) ) |
|
233 { |
|
234 aConnectionPreference = CIacSettingsParser::EIacpDoNotCreatePreference; |
|
235 } |
|
236 else |
|
237 { |
|
238 connectionPrefsRecord->StoreL(*iDbSession); |
|
239 } |
|
240 CleanupStack::PopAndDestroy(connectionPrefsRecord); |
|
241 } |
|
242 |
|
243 |
|
244 // |
|
245 // Get COMMDB_ID from table that matches the COMMDB_NAME extracted from BioMsg |
|
246 // |
|
247 TUint32 CGprsParser::GetIapIdL(const TDesC& aTableName) |
|
248 { |
|
249 const TPtrC KNameFieldToken(iName->Des()); |
|
250 |
|
251 |
|
252 TUint32 ret = 0; |
|
253 if (aTableName.CompareF(TPtrC(KCDTypeNameOutgoingWCDMA)) == KErrNone) |
|
254 { |
|
255 CCDOutgoingGprsRecord* gprsRecord = static_cast<CCDOutgoingGprsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdOutgoingGprsRecord)); |
|
256 CleanupStack::PushL(gprsRecord); |
|
257 gprsRecord->iRecordName.SetMaxLengthL(KNameFieldToken.Length()); |
|
258 gprsRecord->iRecordName = KNameFieldToken; |
|
259 if (gprsRecord->FindL(*iDbSession)) |
|
260 { |
|
261 ret = gprsRecord->iRecordTag.RecordId(); |
|
262 } |
|
263 else |
|
264 { |
|
265 User::Leave(KErrNotFound); |
|
266 } |
|
267 CleanupStack::PopAndDestroy(gprsRecord); |
|
268 } |
|
269 return ret; |
|
270 } |
|
271 |
|
272 void CGprsParser::WriteToGPRSTableL(TDirection aDir) |
|
273 { |
|
274 CCDWCDMAPacketServiceRecord* gprsRecord = NULL; |
|
275 if (aDir == EOutgoing) |
|
276 { |
|
277 gprsRecord = static_cast<CCDOutgoingGprsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdOutgoingGprsRecord)); |
|
278 } |
|
279 else |
|
280 { |
|
281 gprsRecord = static_cast<CCDIncomingGprsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdIncomingGprsRecord)); |
|
282 } |
|
283 CleanupStack::PushL(gprsRecord); |
|
284 gprsRecord->iRecordName.SetMaxLengthL(iName->Length()); |
|
285 gprsRecord->iRecordName = iName->Des(); |
|
286 TBool recordExist = FALSE; |
|
287 if(!(gprsRecord->FindL(*iDbSession))) |
|
288 { |
|
289 gprsRecord->SetRecordId(KCDNewRecordRequest); |
|
290 } |
|
291 else |
|
292 { |
|
293 recordExist = TRUE; |
|
294 } |
|
295 gprsRecord->iGPRSAPN.SetMaxLengthL(iApn->Length()); |
|
296 gprsRecord->iGPRSAPN = *iApn; |
|
297 gprsRecord->iGPRSPDPType = iPdpType; |
|
298 gprsRecord->iGPRSPDPAddress.SetMaxLengthL(KCommsDbSvrMaxFieldLength); |
|
299 gprsRecord->iGPRSPDPAddress = iPdpAddress->Addr(); |
|
300 gprsRecord->iGPRSIfPromptForAuth = iLoginPrompt; |
|
301 if(iLoginName != NULL) |
|
302 { |
|
303 gprsRecord->iGPRSIfAuthName.SetMaxLengthL(iLoginName->Length()); |
|
304 gprsRecord->iGPRSIfAuthName = *iLoginName; |
|
305 } |
|
306 if(iLoginPass != NULL) |
|
307 { |
|
308 gprsRecord->iGPRSIfAuthPass.SetMaxLengthL(iLoginPass->Length()); |
|
309 gprsRecord->iGPRSIfAuthPass = *iLoginPass; |
|
310 } |
|
311 if(iNetMask != NULL) |
|
312 { |
|
313 gprsRecord->iGPRSIPNetMask.SetMaxLengthL(KCommsDbSvrMaxFieldLength); |
|
314 gprsRecord->iGPRSIPNetMask = iNetMask->Addr(); |
|
315 } |
|
316 if(iDNS1 != NULL) |
|
317 { |
|
318 gprsRecord->iGPRSIPNameServer1.SetMaxLengthL(KCommsDbSvrMaxFieldLength); |
|
319 gprsRecord->iGPRSIPNameServer1 = iDNS1->Addr(); |
|
320 } |
|
321 if(iDNS2 != NULL) |
|
322 { |
|
323 gprsRecord->iGPRSIPNameServer2.SetMaxLengthL(KCommsDbSvrMaxFieldLength); |
|
324 gprsRecord->iGPRSIPNameServer2 = iDNS2->Addr(); |
|
325 } |
|
326 if(!iDNS1 && !iDNS2 && iNoExistingDNS) |
|
327 { |
|
328 gprsRecord->iGPRSIPDNSAddrFromServer = EFalse; |
|
329 } |
|
330 else |
|
331 { |
|
332 gprsRecord->iGPRSIPDNSAddrFromServer = ETrue; |
|
333 } |
|
334 gprsRecord->iGPRSDisablePlainTextAuth = EFalse; |
|
335 if (!recordExist) |
|
336 { |
|
337 gprsRecord->StoreL(*iDbSession); |
|
338 } |
|
339 else |
|
340 { |
|
341 gprsRecord->ModifyL(*iDbSession); |
|
342 } |
|
343 iNoExistingDNS = gprsRecord->iGPRSIPDNSAddrFromServer; |
|
344 CleanupStack::PopAndDestroy(gprsRecord); |
|
345 } |
|
346 |
|
347 TPtrC CGprsParser::LimitStringSize(const TDesC& aString) |
|
348 { |
|
349 if (aString.Length() < KCommsDbSvrMaxFieldLength) |
|
350 return aString; |
|
351 else |
|
352 return aString.Left(KCommsDbSvrMaxFieldLength); |
|
353 } |
|
354 |
|
355 TPtrC8 CGprsParser::LimitStringSize(const TDesC8& aString) |
|
356 { |
|
357 if (aString.Length() < KCommsDbSvrMaxFieldLength) |
|
358 return aString; |
|
359 else |
|
360 return aString.Left(KCommsDbSvrMaxFieldLength); |
|
361 } |