|
1 // Copyright (c) 2005-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 // @file pfqosparser.h |
|
15 // Header file for PF_QOS PARSER |
|
16 // @internalTechnology |
|
17 // @released |
|
18 // |
|
19 |
|
20 #ifndef __PFQOSPARSER_H__ |
|
21 #define __PFQOSPARSER_H__ |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <e32base.h> |
|
25 |
|
26 #include <networking/pfqoslib.h> |
|
27 |
|
28 /** @internalTechnology */ |
|
29 const TInt KBufSize = 2048; |
|
30 |
|
31 |
|
32 /** |
|
33 * Base class for extension policy variables |
|
34 * |
|
35 * @internalTechnology |
|
36 */ |
|
37 class TVariableBase |
|
38 { |
|
39 public: |
|
40 IMPORT_C virtual ~TVariableBase(); |
|
41 inline TInt Type() const; |
|
42 inline const TDesC& Name() const; |
|
43 protected: |
|
44 TInt iType; |
|
45 TName iName; |
|
46 public: |
|
47 TDblQueLink iNext; |
|
48 }; |
|
49 |
|
50 /** |
|
51 * Integer variable |
|
52 * |
|
53 * @internalTechnology |
|
54 */ |
|
55 class TIntVariable : public TVariableBase |
|
56 { |
|
57 public: |
|
58 IMPORT_C TIntVariable(const TDesC& aName, TInt aValue); |
|
59 inline void SetValue(TInt aValue); |
|
60 inline TInt Value() const; |
|
61 private: |
|
62 TInt iValue; |
|
63 }; |
|
64 |
|
65 /** |
|
66 * Real variable |
|
67 * |
|
68 * @internalTechnology |
|
69 */ |
|
70 class TRealVariable : public TVariableBase |
|
71 { |
|
72 public: |
|
73 IMPORT_C TRealVariable(const TDesC& aName, TReal aValue); |
|
74 inline void SetValue(TReal aValue); |
|
75 inline TReal Value() const; |
|
76 private: |
|
77 TReal iValue; |
|
78 }; |
|
79 |
|
80 |
|
81 /** |
|
82 * String variable |
|
83 * |
|
84 * @internalTechnology |
|
85 */ |
|
86 class TStringVariable : public TVariableBase |
|
87 { |
|
88 public: |
|
89 IMPORT_C TStringVariable(const TDesC& aName, const TDesC& aValue); |
|
90 inline void SetValue(TDesC& aValue); |
|
91 inline const TDesC& Value() const; |
|
92 private: |
|
93 TName iValue; |
|
94 }; |
|
95 |
|
96 |
|
97 /** @internalTechnology */ |
|
98 typedef TDblQue<TVariableBase> TVariableQueue; |
|
99 /** @internalTechnology */ |
|
100 typedef TDblQueIter<TVariableBase> TVariableQueueIter; |
|
101 |
|
102 /** |
|
103 * Extension policy data |
|
104 * |
|
105 * @internalTechnology |
|
106 */ |
|
107 class CExtension : public CBase |
|
108 { |
|
109 public: |
|
110 IMPORT_C static CExtension* NewL(); |
|
111 IMPORT_C static CExtension* NewL(const TDesC8& aData); |
|
112 IMPORT_C ~CExtension(); |
|
113 IMPORT_C void SetName(const TDesC& aName); |
|
114 /* |
|
115 * Adds the integer variable into the iVariables queue. |
|
116 * Exception: SBLP variables (SblpMediaComponentNumber |
|
117 * and SblpIPFlowNumber) are not checked for duplicates. |
|
118 * |
|
119 * Return KErrAlreadyExists if it already found this variable |
|
120 * in the queue otherwise KErrNone |
|
121 */ |
|
122 IMPORT_C TInt AddIntegerL(const TDesC& aName, TInt aValue); |
|
123 /* |
|
124 * Adds the real variable into the iVariables queue. |
|
125 * Exception: SBLP variables (SblpMediaComponentNumber |
|
126 * and SblpIPFlowNumber) are not checked for duplicates. |
|
127 * |
|
128 * Return KErrAlreadyExists if it already found this variable |
|
129 * in the queue otherwise KErrNone |
|
130 */ |
|
131 IMPORT_C TInt AddRealL(const TDesC& aName, TReal aValue); |
|
132 /* |
|
133 * Adds the string variable into the iVariables queue. |
|
134 * Exception: SBLP variable (SblpMediaAuthorizationToken) |
|
135 * is not checked for duplicates. |
|
136 * |
|
137 * Return KErrAlreadyExists if it already found this variable |
|
138 * in the queue otherwise KErrNone |
|
139 */ |
|
140 IMPORT_C TInt AddStringL(const TDesC& aName, const TDesC& aValue); |
|
141 IMPORT_C TVariableBase* FindVariable(const TDesC& aName); |
|
142 IMPORT_C TInt Copy(TDes8& aData); |
|
143 IMPORT_C TInt CopyL(const TDesC8& aData); |
|
144 IMPORT_C TInt CopyL(CExtension& aExtension); |
|
145 IMPORT_C const TPtrC8 Data(); |
|
146 IMPORT_C TInt Length() const; |
|
147 inline const TDesC& Name() const; |
|
148 inline void SetType(TInt aType); |
|
149 inline TInt Type() const; |
|
150 inline TVariableQueue& Queue(); |
|
151 |
|
152 public: |
|
153 TDblQueLink iNext; |
|
154 |
|
155 private: |
|
156 CExtension(); |
|
157 void ConstructL(); |
|
158 void InitL(); |
|
159 void SetIntValueL(TInt aValue, const TDesC& aName); |
|
160 void SetReal32ValueL(TReal32 aValue, const TDesC& aName); |
|
161 void SetStringValueL(const TDesC& aValue, const TDesC& aName); |
|
162 void SetLengthL(); |
|
163 void Reset(); |
|
164 |
|
165 private: |
|
166 TInt iType; |
|
167 TName iName; |
|
168 TInt iPos; |
|
169 CBufFlat* iBuf; |
|
170 TVariableQueue iVariables; |
|
171 }; |
|
172 |
|
173 |
|
174 /** |
|
175 * CSelectorBase |
|
176 * |
|
177 * @internalTechnology |
|
178 */ |
|
179 class CSelectorBase : public CBase |
|
180 { |
|
181 public: |
|
182 IMPORT_C CSelectorBase(TUint aType); |
|
183 IMPORT_C CSelectorBase(/*lint -e(1724) thinks this chould be 'const' */ CSelectorBase& aSel); |
|
184 IMPORT_C CSelectorBase(TPfqosBase& aBase, TPfqosSelector& aSel, |
|
185 TPfqosAddress& aSrc, TPfqosAddress& aDst, TUint aType); |
|
186 IMPORT_C virtual ~CSelectorBase(); |
|
187 |
|
188 TUint16 iDstPortMax; |
|
189 TInetAddr iDst; // including port selector, if port non-zero |
|
190 TInetAddr iDstMask; // only address part used, as a mask |
|
191 TUint16 iSrcPortMax; |
|
192 TInetAddr iSrc; // including port selector, if port non-zero |
|
193 TInetAddr iSrcMask; // only address part used, as a mask |
|
194 TUint8 iProtocol; // used, if non-zero |
|
195 TCheckedUid iUid; // Uid |
|
196 TUint32 iIapId; // Internet Access Point Identifier |
|
197 TUint16 iPolicyOptions; |
|
198 TUint iPriority; // Priority of the policy (default, |
|
199 // application, or override) |
|
200 TUint iType; // Policy type |
|
201 TName iName; // Policy name --experimental-- |
|
202 TUint iOwner; // Owner - reserved for QoS framework only!! |
|
203 TDblQueLink iNext; |
|
204 }; |
|
205 |
|
206 /** @internalTechnology */ |
|
207 typedef TDblQue<CExtension> TExtensionQueue; |
|
208 /** @internalTechnology */ |
|
209 typedef TDblQueIter<CExtension> TExtensionQueueIter; |
|
210 |
|
211 /** |
|
212 * Extension policy to be used by additional modules |
|
213 * |
|
214 * @internalTechnology |
|
215 */ |
|
216 class CExtensionPolicy : public CSelectorBase |
|
217 { |
|
218 public: |
|
219 IMPORT_C CExtensionPolicy(TPfqosBase& aBase, TPfqosSelector& aSel, |
|
220 TPfqosAddress& aSrc, TPfqosAddress& aDst, TInt aType); |
|
221 IMPORT_C CExtensionPolicy(); |
|
222 IMPORT_C ~CExtensionPolicy(); |
|
223 inline TInt Type() const; |
|
224 inline void SetType(TInt aType); |
|
225 IMPORT_C void AddExtensionL(CExtension& aExtension); |
|
226 IMPORT_C void AddExtensionL(const TDesC8& aExtension); |
|
227 inline TExtensionQueue& Extensions(); |
|
228 protected: |
|
229 TExtensionQueue iExtensions; |
|
230 }; |
|
231 |
|
232 |
|
233 /** @internalTechnology */ |
|
234 enum TTokenType |
|
235 { |
|
236 ETokenString, |
|
237 ETokenEqual, |
|
238 ETokenComma, |
|
239 ETokenBraceLeft, |
|
240 ETokenBraceRight, |
|
241 ETokenParLeft, |
|
242 ETokenParRight, |
|
243 ETokenError, |
|
244 ETokenEof |
|
245 }; |
|
246 |
|
247 /** @internalTechnology */ |
|
248 typedef TDblQue<CExtensionPolicy> TQoSPolicyQueue; |
|
249 /** @internalTechnology */ |
|
250 typedef TDblQueIter<CExtensionPolicy> TQoSPolicyQueueIter; |
|
251 |
|
252 /** |
|
253 * Parser for policy file |
|
254 * |
|
255 * @internalTechnology |
|
256 */ |
|
257 class TPolicyParser : public TLex |
|
258 { |
|
259 public: |
|
260 IMPORT_C TPolicyParser(const TDesC &aPolicy); |
|
261 IMPORT_C ~TPolicyParser(); |
|
262 IMPORT_C TInt ParseL(); |
|
263 inline TExtensionQueue& Extensions(); |
|
264 inline TQoSPolicyQueue& Policies(); |
|
265 |
|
266 private: |
|
267 TInt ParseIPAddrAndMask(TInetAddr& aAddr, TInetAddr& aMask); |
|
268 TInt ParseExtensionSpecL(); |
|
269 TInt ParseExtensionParams(CExtension& aBuf); |
|
270 TInt FindExtensionPolicy(CExtensionPolicy *aSel); |
|
271 TInt ParsePolicyL(TInt aPolicyType); |
|
272 TTokenType NextToken(); |
|
273 TTokenType GetStringValue(); |
|
274 void SkipSpaceAndMark(); |
|
275 // void Error(const TDesC &aFmt, ...); |
|
276 void Error(TRefByValue<const TDesC> aFmt, ...); |
|
277 void AddPolicy(CExtensionPolicy& aPolicy) { iPolicies.AddLast(aPolicy); } |
|
278 |
|
279 TExtensionQueue iExtensions; |
|
280 TQoSPolicyQueue iPolicies; |
|
281 |
|
282 public: |
|
283 int iLine; |
|
284 TBuf<200> iMsg; |
|
285 TPtrC iToken; |
|
286 }; |
|
287 |
|
288 /** @internalTechnology */ |
|
289 inline TExtensionQueue& TPolicyParser::Extensions() |
|
290 { return iExtensions; } |
|
291 |
|
292 /** @internalTechnology */ |
|
293 inline TQoSPolicyQueue& TPolicyParser::Policies() |
|
294 { return iPolicies; } |
|
295 |
|
296 // |
|
297 // Inline methods |
|
298 // |
|
299 /** @internalTechnology */ |
|
300 inline TInt TVariableBase::Type() const |
|
301 { return iType; } |
|
302 |
|
303 /** @internalTechnology */ |
|
304 inline const TDesC& TVariableBase::Name() const |
|
305 { return iName; } |
|
306 |
|
307 /** @internalTechnology */ |
|
308 inline void TIntVariable::SetValue(TInt aValue) |
|
309 { iValue = aValue; } |
|
310 |
|
311 /** @internalTechnology */ |
|
312 inline TInt TIntVariable::Value() const |
|
313 { return iValue; } |
|
314 |
|
315 /** @internalTechnology */ |
|
316 inline void TRealVariable::SetValue(TReal aValue) |
|
317 { iValue = aValue; }; |
|
318 |
|
319 /** @internalTechnology */ |
|
320 inline TReal TRealVariable::Value() const |
|
321 { return iValue; }; |
|
322 |
|
323 /** @internalTechnology */ |
|
324 inline void TStringVariable::SetValue(TDesC& aValue) |
|
325 { if (iValue.MaxLength() >= aValue.Length()) iValue.Copy(aValue); }; |
|
326 |
|
327 /** @internalTechnology */ |
|
328 inline const TDesC& TStringVariable::Value() const |
|
329 { return iValue; } |
|
330 |
|
331 /** @internalTechnology */ |
|
332 inline const TDesC& CExtension::Name() const |
|
333 { return iName; } |
|
334 |
|
335 /** @internalTechnology */ |
|
336 inline void CExtension::SetType(TInt aType) |
|
337 { iType = aType; } |
|
338 |
|
339 /** @internalTechnology */ |
|
340 inline TInt CExtension::Type() const |
|
341 { return iType; } |
|
342 |
|
343 /** @internalTechnology */ |
|
344 inline TVariableQueue& CExtension::Queue() |
|
345 { return iVariables; } |
|
346 |
|
347 /** @internalTechnology */ |
|
348 inline TInt CExtensionPolicy::Type() const |
|
349 { return iType; } |
|
350 |
|
351 /** @internalTechnology */ |
|
352 inline void CExtensionPolicy::SetType(TInt aType) |
|
353 { iType = aType; } |
|
354 |
|
355 /** @internalTechnology */ |
|
356 inline TExtensionQueue& CExtensionPolicy::Extensions() |
|
357 { return iExtensions; } |
|
358 |
|
359 |
|
360 #endif |