|
1 /** @file |
|
2 * Copyright (c) 2005-2006 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: Defines the CUpnpargument class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <e32base.h> |
|
22 #include "upnpargument.h" |
|
23 #include "upnpservice.h" |
|
24 #include "upnpstring.h" |
|
25 #define KLogFile _L("UPnPStack.txt") |
|
26 #include "upnpcustomlog.h" |
|
27 |
|
28 // logs |
|
29 #include "f32file.h" |
|
30 #include "s32file.h" |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CUpnpArgument::CUpnpArgument |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CUpnpArgument::CUpnpArgument( CUpnpService& aParentService ) |
|
45 : iParentService( aParentService ) |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 void CUpnpArgument::ConstructL() |
|
51 { |
|
52 iName = HBufC8::NewL(0); |
|
53 iValue = HBufC8::NewL(0); |
|
54 iRelatedStateVariable = HBufC8::NewL(0); |
|
55 } |
|
56 |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CUpnpArgument::ConstructL |
|
60 // Symbian 2nd phase constructor can leave. |
|
61 // ----------------------------------------------------------------------------- |
|
62 //. |
|
63 void CUpnpArgument::ConstructL( CUpnpArgument& aArgument ) |
|
64 { |
|
65 |
|
66 |
|
67 iName = aArgument.Name().AllocL(); |
|
68 |
|
69 iValue = HBufC8::NewL(0); |
|
70 |
|
71 iDirection = aArgument.Direction(); |
|
72 |
|
73 iRelatedStateVariable = aArgument.RelatedStateVariable().AllocL(); |
|
74 |
|
75 |
|
76 CUpnpStateVariable* var = iParentService.StateVariable( *iRelatedStateVariable ); |
|
77 |
|
78 if ( var ) |
|
79 { |
|
80 iType = var->Type(); |
|
81 } |
|
82 else |
|
83 { |
|
84 iType = EUndefined; |
|
85 } |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CUpnpArgument::NewL |
|
90 // Two-phased constructor. |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CUpnpArgument* CUpnpArgument::NewL( CUpnpService& aParentService ) |
|
94 { |
|
95 CUpnpArgument* self = new(ELeave) CUpnpArgument(aParentService); |
|
96 self->ConstructL(); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CUpnpArgument::NewL |
|
102 // Two-phased constructor. |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CUpnpArgument* CUpnpArgument::NewL( CUpnpArgument& aArgument, |
|
106 CUpnpService& aParentService ) |
|
107 { |
|
108 CUpnpArgument* self = new (ELeave) CUpnpArgument( aParentService ); |
|
109 CleanupStack::PushL( self ); |
|
110 self->ConstructL( aArgument ); |
|
111 CleanupStack::Pop( self ); |
|
112 |
|
113 return self; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CUpnpArgument::~CUpnpArgument |
|
118 // Destructor |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 CUpnpArgument::~CUpnpArgument() |
|
122 { |
|
123 delete iName; |
|
124 delete iValue; |
|
125 delete iRelatedStateVariable; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CUpnpArgument::Name |
|
130 // |
|
131 // (other items were commented in a header). |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C TDesC8& CUpnpArgument::Name() |
|
135 { |
|
136 return *iName; |
|
137 } |
|
138 |
|
139 void CUpnpArgument::SetNameL(const TDesC8& aName) |
|
140 { |
|
141 HBufC8* tmp = aName.AllocL(); |
|
142 delete iName; |
|
143 iName = tmp; |
|
144 } |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CUpnpArgument::SetValueL |
|
147 // If the value is inproper, the method leaves with EInvalidArgs, |
|
148 // which is the internal upnp error code used by UPnP Stack |
|
149 // (other items were commented in a header). |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 EXPORT_C void CUpnpArgument::SetValueL( const TDesC8& aValue ) |
|
153 { |
|
154 LOGS("CUpnpArgument::SetValueL(TDesC8&) [Name/Value]"); |
|
155 |
|
156 |
|
157 // Dates, times, URIs and UUIDs are not validated to save process time. |
|
158 // These must be validated if used in actual service, |
|
159 // which uses these arguments. |
|
160 TArgumentType type = Type(); |
|
161 LOGS1( "type: %i", type ); |
|
162 TLex8 lex(aValue); |
|
163 switch ( type ) |
|
164 { |
|
165 |
|
166 case EUi1: |
|
167 { |
|
168 TUint8 tryVal; |
|
169 CheckErrorL( ( lex.Val(tryVal, EDecimal) ), aValue ); |
|
170 break; |
|
171 } |
|
172 case EUi2: |
|
173 { |
|
174 TUint16 tryVal; |
|
175 CheckErrorL ( lex.Val(tryVal, EDecimal), aValue ); |
|
176 break; |
|
177 } |
|
178 case EUi4: |
|
179 { |
|
180 TUint32 tryVal; |
|
181 CheckErrorL( lex.Val(tryVal, EDecimal), aValue ); |
|
182 break; |
|
183 } |
|
184 case EI1: |
|
185 { |
|
186 TInt8 tryVal; |
|
187 CheckErrorL( lex.Val(tryVal), aValue ); |
|
188 break; |
|
189 } |
|
190 case EI2: |
|
191 { |
|
192 TInt16 tryVal; |
|
193 CheckErrorL( lex.Val(tryVal), aValue ); |
|
194 break; |
|
195 } |
|
196 case EI4: |
|
197 { |
|
198 TInt32 tryVal; |
|
199 CheckErrorL( lex.Val(tryVal), aValue ); |
|
200 break; |
|
201 } |
|
202 case EInt: |
|
203 { |
|
204 TInt64 tryVal; |
|
205 CheckErrorL( lex.Val(tryVal), aValue ); |
|
206 break; |
|
207 } |
|
208 case ER4: |
|
209 { |
|
210 TReal32 tryVal; |
|
211 CheckErrorL( lex.Val(tryVal), aValue ); |
|
212 break; |
|
213 } |
|
214 case ER8: |
|
215 case EFloat: |
|
216 case ENumber: |
|
217 { |
|
218 TReal64 tryVal; |
|
219 CheckErrorL( ( lex.Val(tryVal) ), aValue ); |
|
220 break; |
|
221 } |
|
222 case EFixed144: |
|
223 { |
|
224 TReal64 tryVal; |
|
225 switch ( lex.Val(tryVal) ) |
|
226 { |
|
227 case KErrOverflow: |
|
228 { |
|
229 // sizeof argument |
|
230 User::Leave(EInvalidArgs); |
|
231 break; |
|
232 } |
|
233 case KErrGeneral: |
|
234 { |
|
235 // bad argument |
|
236 User::Leave(EInvalidArgs); |
|
237 break; |
|
238 } |
|
239 default: |
|
240 { |
|
241 |
|
242 TInt left = aValue.Find(UpnpString::KDot8); |
|
243 TInt right; |
|
244 //only decimal part exists |
|
245 if ( left == KErrNotFound ) |
|
246 { |
|
247 left = aValue.Length(); |
|
248 right = left; |
|
249 //occurances of minus are not counted as a seprate digit positions |
|
250 TInt minus = aValue.Find(UpnpString::KMinus); |
|
251 |
|
252 if (minus > KErrNone) |
|
253 { |
|
254 left --; |
|
255 } |
|
256 else if(minus == KErrNone) |
|
257 { |
|
258 left--; |
|
259 if(aValue.Find(UpnpString::KMinus)>=KErrNone) |
|
260 { |
|
261 left--; |
|
262 } |
|
263 } |
|
264 } |
|
265 else //fractional part exists |
|
266 { |
|
267 right = left+1; |
|
268 if(tryVal<0) |
|
269 { |
|
270 left--; |
|
271 } |
|
272 |
|
273 if (aValue.Mid(right).Find(UpnpString::KMinus) >= KErrNone) |
|
274 { |
|
275 right++; |
|
276 } |
|
277 } |
|
278 |
|
279 //checking decimal digits |
|
280 if ( left > KMaxFixed144Left ) |
|
281 { |
|
282 User::Leave(EInvalidArgs); |
|
283 } |
|
284 //checking fractal digits |
|
285 right = (aValue.Length() - right ); |
|
286 if ( right > KMaxFixed144Right ) |
|
287 { |
|
288 User::Leave(EInvalidArgs); |
|
289 } |
|
290 |
|
291 // NULL value, if AllocL leaves then the pointer is invalid |
|
292 DeleteAndNullValue(); |
|
293 iValue = aValue.AllocL(); |
|
294 } |
|
295 } |
|
296 break; |
|
297 } |
|
298 case EBinBase64: |
|
299 { |
|
300 // NULL value, if AllocL leaves then the pointer is invalid |
|
301 DeleteAndNullValue(); |
|
302 iValue = aValue.AllocL(); |
|
303 |
|
304 break; |
|
305 } |
|
306 case EBinHex: |
|
307 { |
|
308 TInt64 tryVal; |
|
309 CheckErrorL( lex.Val(tryVal, EHex), aValue ); |
|
310 break; |
|
311 } |
|
312 case EChar: |
|
313 { |
|
314 // just one character allowed |
|
315 if (aValue.Length() > 1) |
|
316 { |
|
317 User::Leave(EInvalidArgs); |
|
318 } |
|
319 // NULL value, if AllocL leaves then the pointer is invalid |
|
320 DeleteAndNullValue(); |
|
321 iValue = aValue.AllocL(); |
|
322 |
|
323 break; |
|
324 } |
|
325 case EDate: |
|
326 case EDateTime: |
|
327 case EDateTimeTz: |
|
328 case ETime: |
|
329 case ETimeTz: |
|
330 case EUri: |
|
331 case EUuid: |
|
332 case EString: |
|
333 { |
|
334 // NULL value, if AllocL leaves then the pointer is invalid |
|
335 DeleteAndNullValue(); |
|
336 iValue = aValue.AllocL(); |
|
337 |
|
338 break; |
|
339 } |
|
340 default: |
|
341 { |
|
342 // unknown |
|
343 // must be tolerant |
|
344 // NULL value, if AllocL leaves then the pointer is invalid |
|
345 DeleteAndNullValue(); |
|
346 iValue = aValue.AllocL(); |
|
347 |
|
348 break; |
|
349 } |
|
350 } |
|
351 |
|
352 |
|
353 } |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CUpnpArgument::Value |
|
357 // |
|
358 // (other items were commented in a header). |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 EXPORT_C TDesC8& CUpnpArgument::Value() |
|
362 { |
|
363 LOGS("CUpnpArgument::Value() [Name/Value]"); |
|
364 return *iValue; |
|
365 } |
|
366 |
|
367 // ----------------------------------------------------------------------------- |
|
368 // CUpnpArgument::RelatedStateVariable |
|
369 // |
|
370 // (other items were commented in a header). |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 EXPORT_C TDesC8& CUpnpArgument::RelatedStateVariable() |
|
374 { |
|
375 return *iRelatedStateVariable; |
|
376 } |
|
377 |
|
378 void CUpnpArgument::SetRelatedStateVarL(const TDesC8& aRelatedStateVar) |
|
379 { |
|
380 HBufC8* tmp = aRelatedStateVar.AllocL(); |
|
381 delete iRelatedStateVariable; |
|
382 iRelatedStateVariable = tmp; |
|
383 } |
|
384 // ----------------------------------------------------------------------------- |
|
385 // CUpnpArgument::Direction |
|
386 // |
|
387 // (other items were commented in a header). |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 EXPORT_C TInt CUpnpArgument::Direction() const |
|
391 { |
|
392 return iDirection; |
|
393 } |
|
394 |
|
395 void CUpnpArgument::SetDirectionL( TInt aDirection ) |
|
396 { |
|
397 iDirection = aDirection; |
|
398 } |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CUpnpArgument::Type |
|
402 // |
|
403 // (other items were commented in a header). |
|
404 // ----------------------------------------------------------------------------- |
|
405 // |
|
406 EXPORT_C TArgumentType CUpnpArgument::Type() |
|
407 { |
|
408 CUpnpStateVariable* var = iParentService.StateVariable( *iRelatedStateVariable ); |
|
409 if( var ) |
|
410 { |
|
411 return var->Type(); |
|
412 } |
|
413 else |
|
414 { |
|
415 return EUnknown; |
|
416 } |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CUpnpArgument::DeleteAndNullValue |
|
421 // Delete and NULL iValue. |
|
422 // ----------------------------------------------------------------------------- |
|
423 // |
|
424 void CUpnpArgument::DeleteAndNullValue() |
|
425 { |
|
426 delete iValue; |
|
427 iValue = NULL; |
|
428 } |
|
429 |
|
430 // ----------------------------------------------------------------------------- |
|
431 // CUpnpArgument::CheckErrorL |
|
432 // Checks the error code for the SetValue method and leaves if needed. |
|
433 // ----------------------------------------------------------------------------- |
|
434 // |
|
435 void CUpnpArgument::CheckErrorL(TInt aError, const TDesC8& aValue) |
|
436 { |
|
437 switch ( aError ) |
|
438 { |
|
439 case KErrOverflow: |
|
440 { |
|
441 // sizeof argument |
|
442 User::Leave(EInvalidArgs); |
|
443 break; |
|
444 } |
|
445 case KErrGeneral: |
|
446 { |
|
447 // bad argument |
|
448 User::Leave(EInvalidArgs); |
|
449 break; |
|
450 } |
|
451 default: |
|
452 { |
|
453 // NULL value, if AllocL leaves then the pointer is invalid |
|
454 DeleteAndNullValue(); |
|
455 iValue = aValue.AllocL(); |
|
456 } |
|
457 } |
|
458 } |
|
459 |
|
460 void CUpnpArgument::SetType(TInt aType) |
|
461 { |
|
462 iType = aType; |
|
463 } |
|
464 |
|
465 // End of File |