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 <cmconnectionmethoddef.h> |
|
30 #include <cmmanagerext.h> |
|
31 #include <cmpluginpacketdatadef.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 TUint32 WPIMUtil::FindGPRSL( |
|
51 RPointerArray<CWPCharacteristic>& aLinks ) |
|
52 { |
|
53 TUint32 iapID=NULL; |
|
54 RCmManagerExt cmmanagerExt; |
|
55 cmmanagerExt.OpenL(); |
|
56 CleanupClosePushL(cmmanagerExt); |
|
57 TUint32 bearer = 0; |
|
58 |
|
59 |
|
60 for( TInt i( 0 ); i < aLinks.Count(); i++ ) |
|
61 { |
|
62 CWPCharacteristic* curr = aLinks[i]; |
|
63 |
|
64 TPckgBuf<TUint32> uidPckg; |
|
65 for( TInt dataNum( 0 ); curr->Data( dataNum ).Length() == uidPckg.MaxLength(); dataNum++ ) |
|
66 { |
|
67 uidPckg.Copy( curr->Data( dataNum ) ); |
|
68 RCmConnectionMethodExt cm; |
|
69 cm = cmmanagerExt.ConnectionMethodL( uidPckg() ); |
|
70 CleanupClosePushL( cm ); |
|
71 bearer = cm.GetIntAttributeL( CMManager::ECmBearerType ); |
|
72 if(bearer == KUidPacketDataBearerType) |
|
73 { |
|
74 iapID = cm.GetIntAttributeL(CMManager::ECmIapId); |
|
75 CleanupStack::PopAndDestroy(2); |
|
76 return iapID; |
|
77 } |
|
78 CleanupStack::PopAndDestroy(); // cm |
|
79 } |
|
80 } |
|
81 CleanupStack::PopAndDestroy(); //cmmanagerExt |
|
82 |
|
83 // This leave is absolutely needed as it pops & destroys |
|
84 // data in CleanupStack |
|
85 // User::Leave( KErrNotFound ); |
|
86 return iapID; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // WPIMUtil::HasIllegalChars |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 TBool WPIMUtil::HasIllegalChars( const TDesC& aDes ) |
|
94 { |
|
95 // check is there any special chars between 00h to 1Fh |
|
96 for (TInt i=0; i< KWVLastIllegalCharIndex ; i++) |
|
97 { |
|
98 if (aDes.Locate(i) !=KErrNotFound ) |
|
99 { |
|
100 return ETrue; |
|
101 } |
|
102 } |
|
103 |
|
104 return EFalse; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // WPIMUtil::IsValid |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 TBool WPIMUtil::IsValid( TData* aCurrentData ) |
|
112 { |
|
113 TBool ret(ETrue); |
|
114 |
|
115 // validate name: |
|
116 TPtrC dataItem(aCurrentData->iName); |
|
117 |
|
118 // cut the name to its max length. |
|
119 TPtrC newPtr = dataItem.Left(KNameMaxLength); |
|
120 aCurrentData->iName.Set(newPtr); |
|
121 |
|
122 dataItem.Set( aCurrentData->iName ); |
|
123 |
|
124 if ( dataItem.Length() == 0 || WPIMUtil::HasIllegalChars( dataItem ) ) |
|
125 { |
|
126 // set the default name |
|
127 TFileName fileName; |
|
128 Dll::FileName( fileName ); |
|
129 HBufC* defaultName = NULL; |
|
130 TRAPD( retVal, defaultName = WPAdapterUtil::ReadHBufCL( fileName, |
|
131 KWVAdapterName, |
|
132 R_QTN_SM_IM_SERVER_DNAME ) ); |
|
133 CleanupStack::PushL( defaultName ); |
|
134 if ( ( retVal == KErrNone ) && defaultName ) |
|
135 { |
|
136 aCurrentData->iName.Set(*defaultName); |
|
137 } |
|
138 CleanupStack::PopAndDestroy( defaultName ); |
|
139 } |
|
140 |
|
141 // cut the name to max length |
|
142 // validate URL |
|
143 dataItem.Set( aCurrentData->iURL ); |
|
144 if ( dataItem.Length() == 0 || |
|
145 dataItem.Length() > KURIMaxLength || |
|
146 WPIMUtil::HasIllegalChars( dataItem ) ) |
|
147 { |
|
148 ret = EFalse; |
|
149 } |
|
150 else |
|
151 { |
|
152 TUriParser16 uriParser; |
|
153 TInt err = uriParser.Parse( dataItem ); |
|
154 |
|
155 if (err != KErrNone) |
|
156 { |
|
157 ret = EFalse; |
|
158 } |
|
159 } |
|
160 |
|
161 if (ret) |
|
162 { |
|
163 // validate userID |
|
164 dataItem.Set( aCurrentData->iUserID ); |
|
165 if ( dataItem.Length() > KUserIdMaxLength || |
|
166 WPIMUtil::HasIllegalChars( dataItem ) ) |
|
167 { |
|
168 ret = EFalse; |
|
169 } |
|
170 } |
|
171 if (ret) |
|
172 { |
|
173 // validate password |
|
174 dataItem.Set(aCurrentData->iPassword); |
|
175 if ( dataItem.Length() > KPasswordMaxLenth ) |
|
176 { |
|
177 ret = EFalse; |
|
178 } |
|
179 } |
|
180 return ret; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // TData::TData |
|
185 // C++ default constructor can NOT contain any code, that |
|
186 // might leave. |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 TData::TData() |
|
190 { |
|
191 iName.Set( KNullDesC ); |
|
192 iURL.Set( KNullDesC ); |
|
193 iUserID.Set( KNullDesC ); |
|
194 iPassword.Set( KNullDesC ); |
|
195 iSAPId = 0; |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // Destructor |
|
200 // ----------------------------------------------------------------------------- |
|
201 TData::~TData() |
|
202 { |
|
203 iLinks.Close(); |
|
204 } |
|
205 |
|
206 // End of File |
|