|
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: Document structure validator. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CWPValidator.h" |
|
21 #include "MWPElement.h" |
|
22 #include "CWPParameter.h" |
|
23 #include "CWPCharacteristic.h" |
|
24 #include "WPEngineDebug.h" |
|
25 |
|
26 // DATA TYPES |
|
27 // Element in the validating table. |
|
28 struct TMapping |
|
29 { |
|
30 // The contained element type |
|
31 TInt iTo; |
|
32 |
|
33 // Pointer to the validating table for the contained element |
|
34 const TMapping* iMapping; |
|
35 }; |
|
36 |
|
37 // CONSTANTS |
|
38 |
|
39 // Validating table for unknown characteristics |
|
40 const TMapping KMappingArrayNamedCharacteristic[] = |
|
41 { |
|
42 { KWPParameter, NULL }, |
|
43 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
44 { KWPElement, NULL } |
|
45 }; |
|
46 |
|
47 // Validating table for parameters only characteristics |
|
48 const TMapping KMappingArrayParametersOnly[] = |
|
49 { |
|
50 { KWPParameter, NULL }, |
|
51 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
52 { KWPElement, NULL } |
|
53 }; |
|
54 |
|
55 // Validating table for PXPHYSICAL |
|
56 const TMapping KMappingArrayPxPhysical[] = |
|
57 { |
|
58 { KWPParameter, NULL }, |
|
59 { KWPPort, KMappingArrayParametersOnly }, |
|
60 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
61 { KWPElement, NULL } |
|
62 }; |
|
63 |
|
64 // Validating table for PXLOGICAL |
|
65 const TMapping KMappingArrayPxLogical[] = |
|
66 { |
|
67 { KWPParameter, NULL }, |
|
68 { KWPPxPhysical, KMappingArrayPxPhysical }, |
|
69 { KWPPort, KMappingArrayParametersOnly }, |
|
70 { KWPPxAuthInfo, KMappingArrayParametersOnly }, |
|
71 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
72 { KWPElement, NULL } |
|
73 }; |
|
74 |
|
75 // Validating table for WLAN |
|
76 const TMapping KMappingArrayWLAN[] = |
|
77 { |
|
78 { KWPParameter, NULL }, |
|
79 { KWPWepKey, KMappingArrayParametersOnly }, |
|
80 { KWPElement, NULL } |
|
81 }; |
|
82 |
|
83 // Validating table for NAPDEF |
|
84 const TMapping KMappingArrayNapDef[] = |
|
85 { |
|
86 { KWPParameter, NULL }, |
|
87 { KWPValidity, KMappingArrayParametersOnly }, |
|
88 { KWPNapAuthInfo, KMappingArrayParametersOnly }, |
|
89 { KWPBearerInfo, KMappingArrayParametersOnly }, |
|
90 { KWPDNSAddrInfo, KMappingArrayParametersOnly }, |
|
91 { KWPWLAN, KMappingArrayWLAN }, |
|
92 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
93 { KWPElement, NULL } |
|
94 }; |
|
95 |
|
96 // Validating table for APPADDR |
|
97 const TMapping KMappingArrayAppAddr[] = |
|
98 { |
|
99 { KWPParameter, NULL }, |
|
100 { KWPPort, KMappingArrayParametersOnly }, |
|
101 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
102 { KWPElement, NULL } |
|
103 }; |
|
104 |
|
105 // Validating table for APPLICATION |
|
106 const TMapping KMappingArrayApplication[] = |
|
107 { |
|
108 { KWPParameter, NULL }, |
|
109 { KWPAppAddr, KMappingArrayAppAddr }, |
|
110 { KWPAppAuth, KMappingArrayParametersOnly }, |
|
111 { KWPResource, KMappingArrayParametersOnly }, |
|
112 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
113 { KWPElement, NULL } |
|
114 }; |
|
115 |
|
116 // Validating table for the document root |
|
117 const TMapping KMappingArrayRoot[] = |
|
118 { |
|
119 { KWPPxLogical, KMappingArrayPxLogical }, |
|
120 { KWPNapDef, KMappingArrayNapDef }, |
|
121 { KWPBootstrap, KMappingArrayParametersOnly }, |
|
122 { KWPVendorConfig, KMappingArrayParametersOnly }, |
|
123 { KWPClientIdentity, KMappingArrayParametersOnly }, |
|
124 { KWPAccess, KMappingArrayParametersOnly }, |
|
125 { KWPApplication, KMappingArrayApplication }, |
|
126 { KWPBearerInfo, KMappingArrayParametersOnly }, |
|
127 { KWPWLAN, KMappingArrayParametersOnly }, |
|
128 { KWPDNSAddrInfo, KMappingArrayParametersOnly }, |
|
129 { KWPLoginScript, KMappingArrayParametersOnly }, |
|
130 { KWPNamedCharacteristic, KMappingArrayNamedCharacteristic }, |
|
131 { KWPElement, NULL } |
|
132 }; |
|
133 |
|
134 // ============================ MEMBER FUNCTIONS =============================== |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CWPValidator::CWPValidator |
|
138 // C++ default constructor can NOT contain any code, that |
|
139 // might leave. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 CWPValidator::CWPValidator() |
|
143 { |
|
144 iCurrentMapping = KMappingArrayRoot; |
|
145 iFlag = ETrue; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CWPValidator::ConstructL |
|
150 // Symbian 2nd phase constructor can leave. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void CWPValidator::ConstructL() |
|
154 { |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CWPValidator::NewL |
|
159 // Two-phased constructor. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 CWPValidator* CWPValidator::NewL() |
|
163 { |
|
164 CWPValidator* self = NewLC(); |
|
165 CleanupStack::Pop(); |
|
166 |
|
167 return self; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CWPValidator::NewLC |
|
172 // Two-phased constructor. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 CWPValidator* CWPValidator::NewLC() |
|
176 { |
|
177 CWPValidator* self = new( ELeave ) CWPValidator; |
|
178 |
|
179 CleanupStack::PushL( self ); |
|
180 self->ConstructL(); |
|
181 |
|
182 return self; |
|
183 } |
|
184 |
|
185 // Destructor |
|
186 CWPValidator::~CWPValidator() |
|
187 { |
|
188 iCurrentMapping = NULL; |
|
189 iCurrentElement = NULL; |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CWPValidator::Visit |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CWPValidator::VisitL( CWPParameter& aParameter ) |
|
197 { |
|
198 // Store the current mapping and element |
|
199 const TMapping* currentMapping = iCurrentMapping; |
|
200 const MWPElement* currentElement = iCurrentElement; |
|
201 |
|
202 DVA( "Validator: Mapping to parameter %d", aParameter.ID() ); |
|
203 // Check if the mapping is valid |
|
204 MapToL( aParameter ); |
|
205 DEBUG( "Validator: Exit" ); |
|
206 |
|
207 // Restore the current mapping and element |
|
208 iCurrentMapping = currentMapping; |
|
209 iCurrentElement = currentElement; |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CWPValidator::Visit |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CWPValidator::VisitL( CWPCharacteristic& aCharacteristic ) |
|
217 { |
|
218 // Store the current mapping and element |
|
219 const TMapping* currentMapping = iCurrentMapping; |
|
220 const MWPElement* currentElement = iCurrentElement; |
|
221 |
|
222 DVA( "Validator: Mapping to characteristic %d", aCharacteristic.Type() ); |
|
223 // Check if the mapping is valid |
|
224 MapToL( aCharacteristic ); |
|
225 |
|
226 // Mapping is valid, so enter the characteristic |
|
227 if(iFlag) |
|
228 { |
|
229 aCharacteristic.AcceptL( *this ); |
|
230 } |
|
231 DEBUG( "Validator: Exit" ); |
|
232 |
|
233 // Restore the current mapping and element |
|
234 iCurrentMapping = currentMapping; |
|
235 iCurrentElement = currentElement; |
|
236 iFlag = ETrue; |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CWPValidator::VisitLink |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CWPValidator::VisitLinkL( CWPCharacteristic& /*aLink*/ ) |
|
244 { |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CWPValidator::MapToL |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 |
|
252 void CWPValidator::MapToL( MWPElement& aTo ) |
|
253 { |
|
254 TInt toType( aTo.Type() ); |
|
255 |
|
256 for( TInt i( 0 ); iCurrentMapping[i].iTo != KWPElement; i++ ) |
|
257 { |
|
258 if( iCurrentMapping[i].iTo == toType ) |
|
259 { |
|
260 iCurrentMapping = iCurrentMapping[i].iMapping; |
|
261 iCurrentElement = &aTo; |
|
262 return; |
|
263 } |
|
264 } |
|
265 if ( Rangecheck( toType ) ) |
|
266 { |
|
267 iFlag = EFalse; |
|
268 return; |
|
269 } |
|
270 |
|
271 DEBUG( "Validator: Error" ); |
|
272 User::Leave( KErrCorrupt ); |
|
273 } |
|
274 |
|
275 TBool CWPValidator::Rangecheck(const TInt toType ) |
|
276 { |
|
277 if((toType != KWPElement) || (toType != KWPParameter) || |
|
278 (toType != KWPPxLogical ) || (toType != KWPPxPhysical) || |
|
279 (toType != KWPPort) || (toType != KWPValidity) || |
|
280 (toType != KWPNapDef) || (toType != KWPBootstrap) || |
|
281 (toType != KWPVendorConfig) || (toType != KWPClientIdentity) || |
|
282 (toType != KWPPxAuthInfo) || (toType != KWPNapAuthInfo) || |
|
283 (toType != KWPAccess) || (toType != KWPBearerInfo) || |
|
284 (toType != KWPDNSAddrInfo) || (toType != KWPWLAN) || |
|
285 (toType != KWPWepKey) || (toType != KWPPort1) || |
|
286 (toType != KWPApplication) || (toType != KWPAppAddr) || |
|
287 (toType != KWPAppAuth) || (toType != KWPClientIdentity1) || |
|
288 (toType != KWPResource) || (toType != KWPLoginScript) || |
|
289 (toType != KWPNamedCharacteristic)) |
|
290 return ETrue; |
|
291 else |
|
292 return EFalse; |
|
293 } |
|
294 |
|
295 // End of File |