|
1 /* |
|
2 * Copyright (c) 2002 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: WPIMUtil is a utility class for reading resource strings. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <f32file.h> |
|
23 #include <barsc.h> |
|
24 #include <bautils.h> |
|
25 #include "WPIMUtil.h" |
|
26 #include <data_caging_path_literals.hrh> |
|
27 |
|
28 #include <CWPCharacteristic.h> |
|
29 #include <ApDataHandler.h> |
|
30 #include <ApAccessPointItem.h> |
|
31 #include <ApUtils.h> |
|
32 #include <commdb.h> |
|
33 #include "WPAdapterUtil.h" |
|
34 #include <wpwvadapterresource.rsg> |
|
35 #include <uri16.h> // TUriParser8 |
|
36 |
|
37 // CONSTANTS |
|
38 const TInt KWVLastIllegalCharIndex = 32; |
|
39 const TInt KNameMaxLength = 30; |
|
40 const TInt KUserIdMaxLength = 50; |
|
41 const TInt KPasswordMaxLenth = 50; |
|
42 const TInt KURIMaxLength = 100; |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CWPPecAdapter::FindGPRSL |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CApAccessPointItem* WPIMUtil::FindGPRSL( |
|
51 RPointerArray<CWPCharacteristic>& aLinks ) |
|
52 { |
|
53 CCommsDatabase* commDb = CCommsDatabase::NewL(); |
|
54 CleanupStack::PushL( commDb ); |
|
55 CApDataHandler* apHandler = CApDataHandler::NewLC( *commDb ); |
|
56 |
|
57 for( TInt i( 0 ); i < aLinks.Count(); i++ ) |
|
58 { |
|
59 CWPCharacteristic* curr = aLinks[i]; |
|
60 |
|
61 TPckgBuf<TUint32> uidPckg; |
|
62 for( TInt dataNum( 0 ); curr->Data( dataNum ).Length() == uidPckg.MaxLength(); dataNum++ ) |
|
63 { |
|
64 uidPckg.Copy( curr->Data( dataNum ) ); |
|
65 |
|
66 CApAccessPointItem* item = CApAccessPointItem::NewLC(); |
|
67 // Read the access point pointed to by TO-NAPID or TO-PROXY |
|
68 apHandler->AccessPointDataL( uidPckg(), *item ); |
|
69 |
|
70 if( item->BearerTypeL() == EApBearerTypeGPRS ) |
|
71 { |
|
72 CleanupStack::Pop(); // item |
|
73 CleanupStack::PopAndDestroy( 2 ); // apHandler, commDb |
|
74 return item; |
|
75 } |
|
76 CleanupStack::PopAndDestroy( item ); |
|
77 } |
|
78 } |
|
79 |
|
80 // This leave is absolutely needed as it pops & destroys |
|
81 // data in CleanupStack |
|
82 User::Leave( KErrNotFound ); |
|
83 return NULL; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // WPIMUtil::HasIllegalChars |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 TBool WPIMUtil::HasIllegalChars( const TDesC& aDes ) |
|
91 { |
|
92 // check is there any special chars between 00h to 1Fh |
|
93 for (TInt i=0; i< KWVLastIllegalCharIndex ; i++) |
|
94 { |
|
95 if (aDes.Locate(i) !=KErrNotFound ) |
|
96 { |
|
97 return ETrue; |
|
98 } |
|
99 } |
|
100 |
|
101 return EFalse; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // WPIMUtil::IsValid |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TBool WPIMUtil::IsValid( TData* aCurrentData ) |
|
109 { |
|
110 TBool ret(ETrue); |
|
111 |
|
112 // validate name: |
|
113 TPtrC dataItem(aCurrentData->iName); |
|
114 |
|
115 // cut the name to its max length. |
|
116 TPtrC newPtr = dataItem.Left(KNameMaxLength); |
|
117 aCurrentData->iName.Set(newPtr); |
|
118 |
|
119 dataItem.Set( aCurrentData->iName ); |
|
120 |
|
121 if ( dataItem.Length() == 0 || WPIMUtil::HasIllegalChars( dataItem ) ) |
|
122 { |
|
123 // set the default name |
|
124 TFileName fileName; |
|
125 Dll::FileName( fileName ); |
|
126 HBufC* defaultName = NULL; |
|
127 TRAPD( retVal, defaultName = WPAdapterUtil::ReadHBufCL( fileName, |
|
128 KWVAdapterName, |
|
129 R_QTN_SM_IM_SERVER_DNAME ) ); |
|
130 CleanupStack::PushL( defaultName ); |
|
131 if ( ( retVal == KErrNone ) && defaultName ) |
|
132 { |
|
133 aCurrentData->iName.Set(*defaultName); |
|
134 } |
|
135 CleanupStack::PopAndDestroy( defaultName ); |
|
136 } |
|
137 |
|
138 // cut the name to max length |
|
139 // validate URL |
|
140 dataItem.Set( aCurrentData->iURL ); |
|
141 if ( dataItem.Length() == 0 || |
|
142 dataItem.Length() > KURIMaxLength || |
|
143 WPIMUtil::HasIllegalChars( dataItem ) ) |
|
144 { |
|
145 ret = EFalse; |
|
146 } |
|
147 else |
|
148 { |
|
149 TUriParser16 uriParser; |
|
150 TInt err = uriParser.Parse( dataItem ); |
|
151 |
|
152 if (err != KErrNone) |
|
153 { |
|
154 ret = EFalse; |
|
155 } |
|
156 } |
|
157 |
|
158 if (ret) |
|
159 { |
|
160 // validate userID |
|
161 dataItem.Set( aCurrentData->iUserID ); |
|
162 if ( dataItem.Length() > KUserIdMaxLength || |
|
163 WPIMUtil::HasIllegalChars( dataItem ) ) |
|
164 { |
|
165 ret = EFalse; |
|
166 } |
|
167 } |
|
168 if (ret) |
|
169 { |
|
170 // validate password |
|
171 dataItem.Set(aCurrentData->iPassword); |
|
172 if ( dataItem.Length() > KPasswordMaxLenth ) |
|
173 { |
|
174 ret = EFalse; |
|
175 } |
|
176 } |
|
177 return ret; |
|
178 } |
|
179 |
|
180 // ----------------------------------------------------------------------------- |
|
181 // TData::TData |
|
182 // C++ default constructor can NOT contain any code, that |
|
183 // might leave. |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TData::TData() |
|
187 { |
|
188 iName.Set( KNullDesC ); |
|
189 iURL.Set( KNullDesC ); |
|
190 iUserID.Set( KNullDesC ); |
|
191 iPassword.Set( KNullDesC ); |
|
192 iSAPId = 0; |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // Destructor |
|
197 // ----------------------------------------------------------------------------- |
|
198 TData::~TData() |
|
199 { |
|
200 iLinks.Close(); |
|
201 } |
|
202 |
|
203 // End of File |