|
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: Represents SSDP message |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpssdpmessage.h" |
|
21 #include "upnpcons.h" |
|
22 #include "upnplist.h" |
|
23 |
|
24 |
|
25 // LITERALS |
|
26 using namespace UpnpSSDP; |
|
27 using namespace UpnpHTTP; |
|
28 |
|
29 // ============================ MEMBER FUNCTIONS =============================== |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CUpnpSsdpMessage::CUpnpSsdpMessage |
|
33 // C++ default constructor can NOT contain any code, that |
|
34 // might leave. |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CUpnpSsdpMessage::CUpnpSsdpMessage() |
|
38 { |
|
39 } |
|
40 |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CUpnpSsdpMessage::ConstructL |
|
44 // Symbian 2nd phase constructor can leave. |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 void CUpnpSsdpMessage::ConstructL(TRequestType aRequestType) |
|
48 { |
|
49 |
|
50 switch ( aRequestType ) |
|
51 { |
|
52 case ERequestNotify: |
|
53 AddPairL( KMethodNotify, KNullDesC8 ); |
|
54 AddPairL( KHdrLocation, KNullDesC8 ); |
|
55 AddPairL( KHdrHost, KDefaultHost ); |
|
56 AddPairL( UpnpSSDP::KHdrServer, KNullDesC8 ); |
|
57 AddPairL( KHdrNotificationType,(TDesC8&) KNotificationAlive ); |
|
58 AddPairL( KHdrUuid, KNullDesC8 ); |
|
59 AddPairL( UpnpSSDP::KHdrCacheControl, KNullDesC8 ); |
|
60 AddPairL( KHdrSearchTarget, KNullDesC8 ); |
|
61 break; |
|
62 case ERequestByeBye: |
|
63 AddPairL( KMethodNotify, KNullDesC8 ); |
|
64 AddPairL( KHdrHost, KDefaultHost ); |
|
65 AddPairL( KHdrSearchTarget, KNullDesC8 ); |
|
66 AddPairL( KHdrNotificationType, KNotificationByebye ); |
|
67 AddPairL( KHdrUuid, KNullDesC8 ); |
|
68 |
|
69 break; |
|
70 case ERequestSearch: |
|
71 AddPairL( KMethodMSearch, KNullDesC8 ); |
|
72 AddPairL( KHdrHost, KDefaultHost ); |
|
73 AddPairL( KHdrMan, KNotificationDiscover ); |
|
74 AddPairL( KHdrMx, KNullDesC8 ); |
|
75 AddPairL( KHdrSt, KNullDesC8 ); |
|
76 break; |
|
77 case ERequestSearchResponse: |
|
78 { |
|
79 AddPairL( UpnpHTTP::KHTTPOk, KNullDesC8 ); |
|
80 AddPairL( UpnpSSDP::KHdrCacheControl, KNullDesC8 ); |
|
81 AddPairL( UpnpHTTP::KHdrDate, KNullDesC8 ); |
|
82 AddPairL( UpnpHTTP::KHdrExtWithoutColon, KNullDesC8 ); |
|
83 AddPairL( KHdrLocation, KNullDesC8 ); |
|
84 AddPairL( UpnpSSDP::KHdrServer, KNullDesC8 ); |
|
85 AddPairL( KHdrSt, KNullDesC8 ); |
|
86 AddPairL( KHdrUuid, KNullDesC8 ); |
|
87 |
|
88 TTime now; |
|
89 now.UniversalTime(); |
|
90 |
|
91 this->SetMessageDateL( now ); |
|
92 } |
|
93 break; |
|
94 default: |
|
95 break; |
|
96 } |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CUpnpSsdpMessage::NewL |
|
101 // Two-phased constructor. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 EXPORT_C CUpnpSsdpMessage* CUpnpSsdpMessage::NewL( TInetAddr& aAddr, |
|
105 TRequestType aRequestType ) |
|
106 { |
|
107 CUpnpSsdpMessage* self = new (ELeave) CUpnpSsdpMessage(); |
|
108 CleanupStack::PushL(self ); |
|
109 self->HttpConstructL( aAddr ); |
|
110 self->ConstructL(aRequestType ); |
|
111 CleanupStack::Pop(self ); |
|
112 |
|
113 return self; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CUpnpSsdpMessage::NewL |
|
118 // Two-phased constructor. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C CUpnpSsdpMessage* CUpnpSsdpMessage::NewL( TRequestType aRequestType ) |
|
122 { |
|
123 CUpnpSsdpMessage* self = new (ELeave) CUpnpSsdpMessage(); |
|
124 CleanupStack::PushL(self ); |
|
125 |
|
126 TInetAddr tempAddr = TInetAddr(INET_ADDR(0,0,0,0),0 ); |
|
127 self->HttpConstructL( tempAddr ); |
|
128 self->ConstructL( aRequestType ); |
|
129 |
|
130 CleanupStack::Pop( self ); |
|
131 |
|
132 return self; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CUpnpSsdpMessage::NewL |
|
137 // Two-phased constructor. |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 EXPORT_C CUpnpSsdpMessage* CUpnpSsdpMessage::NewL(TDesC8& aBuffer, TInetAddr& aAddr) |
|
141 { |
|
142 CUpnpSsdpMessage* self = new (ELeave) CUpnpSsdpMessage(); |
|
143 CleanupStack::PushL(self); |
|
144 aAddr.SetFamily(KAfInet); |
|
145 self->HttpConstructL( aAddr ); |
|
146 self->ParseL(aBuffer); |
|
147 CleanupStack::Pop(self); |
|
148 |
|
149 return self; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CCSsdpMessage::~CUpnpSsdpMessage |
|
154 // Destructor |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 CUpnpSsdpMessage::~CUpnpSsdpMessage() |
|
158 { |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CUpnpSsdpMessage::AddHostL |
|
163 // Add host. |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 EXPORT_C void CUpnpSsdpMessage::AddHostL(TDesC8& aHost) |
|
167 { |
|
168 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
169 |
|
170 while ( hdr ) |
|
171 { |
|
172 if ( hdr->Name().CompareF( KHdrHost() )== 0 ) |
|
173 { |
|
174 hdr->SetValueL(aHost); |
|
175 return; |
|
176 } |
|
177 hdr = iHeaderList->Next(hdr); |
|
178 } |
|
179 // header not found, adding it. |
|
180 AddPairL( KHdrHost(), aHost ); |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CUpnpSsdpMessage::AddUsnL |
|
185 // Add USN. |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CUpnpSsdpMessage::AddUsnL(TDesC8& aUsn) |
|
189 { |
|
190 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
191 |
|
192 while ( hdr ) |
|
193 { |
|
194 if ( hdr->Name().CompareF( KHdrUuid )== 0 ) |
|
195 { |
|
196 hdr->SetValueL(aUsn); |
|
197 return; |
|
198 } |
|
199 hdr = iHeaderList->Next(hdr); |
|
200 } |
|
201 // header not found, adding it. |
|
202 AddPairL( KHdrUuid(), aUsn ); |
|
203 } |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CUpnpSsdpMessage::AddCacheControlL |
|
207 // Add cache control. |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 void CUpnpSsdpMessage::AddCacheControlL(TDesC8& aMaxAge) |
|
211 { |
|
212 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
213 |
|
214 while ( hdr ) |
|
215 { |
|
216 if ( hdr->Name().CompareF( UpnpSSDP::KHdrCacheControl )== 0 ) |
|
217 { |
|
218 hdr->SetValueL( (TDesC8&) aMaxAge); |
|
219 return; |
|
220 } |
|
221 hdr = iHeaderList->Next(hdr); |
|
222 } |
|
223 // header not found, adding it. |
|
224 AddPairL( UpnpSSDP::KHdrCacheControl(), aMaxAge ); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CUpnpSsdpMessage::AddLocationL |
|
229 // Add location. |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 void CUpnpSsdpMessage::AddLocationL(TDesC8& aDescriptionLocation) |
|
233 { |
|
234 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
235 |
|
236 while ( hdr ) |
|
237 { |
|
238 if ( hdr->Name ().CompareF( KHdrLocation )== 0 ) |
|
239 { |
|
240 hdr->SetValueL(aDescriptionLocation); |
|
241 return; |
|
242 } |
|
243 hdr = iHeaderList->Next(hdr); |
|
244 } |
|
245 // header not found, adding it. |
|
246 AddPairL( KHdrLocation(), aDescriptionLocation ); |
|
247 } |
|
248 |
|
249 // ----------------------------------------------------------------------------- |
|
250 // CUpnpSsdpMessage::AddSearchTargetStringL |
|
251 // Add search string. |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CUpnpSsdpMessage::AddSearchTargetStringL(TDesC8& aSt) |
|
255 { |
|
256 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
257 |
|
258 while ( hdr ) |
|
259 { |
|
260 if ( hdr->Name ().CompareF( KHdrSt )== 0 ) |
|
261 { |
|
262 hdr->SetValueL(aSt); |
|
263 return; |
|
264 } |
|
265 hdr = iHeaderList->Next(hdr); |
|
266 } |
|
267 // header not found, adding it. |
|
268 AddPairL( KHdrSt(), aSt ); |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CUpnpSsdpMessage::AddServerL |
|
273 // Add server. |
|
274 // ----------------------------------------------------------------------------- |
|
275 // |
|
276 void CUpnpSsdpMessage::AddServerL(TDesC8& aServerType) |
|
277 { |
|
278 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
279 |
|
280 while ( hdr ) |
|
281 { |
|
282 if ( hdr->Name ().CompareF( UpnpSSDP::KHdrServer )== 0 ) |
|
283 { |
|
284 hdr->SetValueL(aServerType); |
|
285 return; |
|
286 } |
|
287 hdr = iHeaderList->Next(hdr); |
|
288 } |
|
289 // header not found, adding it. |
|
290 AddPairL( UpnpSSDP::KHdrServer(), aServerType ); |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CUpnpSsdpMessage::AddNotificationTypeL |
|
295 // Add notification type. |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CUpnpSsdpMessage::AddNotificationTypeL(TDesC8& aNT) |
|
299 { |
|
300 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
301 |
|
302 while ( hdr ) |
|
303 { |
|
304 if ( hdr->Name ().CompareF( KHdrSearchTarget )== 0 ) |
|
305 { |
|
306 hdr->SetValueL(aNT); |
|
307 return; |
|
308 } |
|
309 hdr = iHeaderList->Next(hdr); |
|
310 } |
|
311 // header not found, adding it. |
|
312 AddPairL( KHdrSearchTarget(), aNT ); |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CUpnpSsdpMessage::AddMxL |
|
317 // Add MX. |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 EXPORT_C void CUpnpSsdpMessage::AddMxL(TDesC8& aMx) |
|
321 { |
|
322 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
323 |
|
324 while ( hdr ) |
|
325 { |
|
326 if ( hdr->Name ().CompareF( KHdrMx )== 0 ) |
|
327 { |
|
328 hdr->SetValueL(aMx); |
|
329 return; |
|
330 } |
|
331 hdr = iHeaderList->Next(hdr); |
|
332 } |
|
333 // header not found, adding it. |
|
334 AddPairL( KHdrMx(), aMx ); |
|
335 } |
|
336 |
|
337 // ----------------------------------------------------------------------------- |
|
338 // CUpnpSsdpMessage::SearchTarget |
|
339 // Search target. |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 EXPORT_C TInt CUpnpSsdpMessage::SearchTarget() |
|
343 { |
|
344 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
345 |
|
346 while ( hdr ) |
|
347 { |
|
348 if ( hdr->Name().CompareF ( KHdrSt ) == 0 ) |
|
349 { |
|
350 |
|
351 if ( hdr->Value().CompareF(KSearchTargetAll) == 0 ) |
|
352 { |
|
353 return ESsdpAll; |
|
354 } |
|
355 |
|
356 else if ( hdr->Value().CompareF(KUPnPRootDevice) == 0 ) |
|
357 { |
|
358 return EUPnPRootDevice; |
|
359 } |
|
360 else if ( hdr->Value().FindF(KUPnPUuid) == 0 ) |
|
361 { |
|
362 return EDeviceUid; |
|
363 } |
|
364 else if ( hdr->Value().FindF(KUPnPDeviceSchema) == 0 ) |
|
365 { |
|
366 return EDeviceType; |
|
367 } |
|
368 else if ( hdr->Value().FindF(KUPnPServiceSchema) == 0 ) |
|
369 { |
|
370 return EServiceType; |
|
371 } |
|
372 else |
|
373 { |
|
374 return ESsdpNone; |
|
375 } |
|
376 |
|
377 } |
|
378 hdr = iHeaderList->Next(hdr); |
|
379 } |
|
380 return ESsdpNone; |
|
381 } |
|
382 |
|
383 // ----------------------------------------------------------------------------- |
|
384 // CUpnpSsdpMessage::IsSsdpAlive |
|
385 // Return wheter SSDP is alive. |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 EXPORT_C TBool CUpnpSsdpMessage::IsSsdpAlive() |
|
389 { |
|
390 |
|
391 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
392 |
|
393 if (IsSsdpResponse()) |
|
394 { |
|
395 return ETrue; |
|
396 } |
|
397 |
|
398 while ( hdr) |
|
399 { |
|
400 if ( hdr->Name().CompareF ( KHdrNotificationType ) == 0 ) |
|
401 { |
|
402 if ( hdr->Value().CompareF ( KNotificationAlive ) == 0 ) |
|
403 { |
|
404 return ETrue; |
|
405 } |
|
406 } |
|
407 hdr = iHeaderList->Next(hdr); |
|
408 } |
|
409 |
|
410 return EFalse; |
|
411 } |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // CUpnpSsdpMessage::IsSsdpByebye |
|
415 // |
|
416 // (other items were commented in a header). |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 EXPORT_C TBool CUpnpSsdpMessage::IsSsdpByebye() |
|
420 { |
|
421 |
|
422 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
423 |
|
424 while ( hdr) |
|
425 { |
|
426 if ( hdr->Name().CompareF( KHdrNotificationType ) == 0 ) |
|
427 { |
|
428 if ( hdr->Value().CompareF( KNotificationByebye ) == 0 ) |
|
429 { |
|
430 return ETrue; |
|
431 } |
|
432 |
|
433 } |
|
434 hdr = iHeaderList->Next(hdr); |
|
435 } |
|
436 |
|
437 return EFalse; |
|
438 } |
|
439 |
|
440 // ----------------------------------------------------------------------------- |
|
441 // CUpnpSsdpMessage::IsSsdpMSearch |
|
442 // Return whether SSP search is true or false. |
|
443 // ----------------------------------------------------------------------------- |
|
444 // |
|
445 EXPORT_C TBool CUpnpSsdpMessage::IsSsdpMSearch() |
|
446 { |
|
447 return Method().CompareF( UpnpSSDP::KMSearch() ) == 0; |
|
448 } |
|
449 |
|
450 // ----------------------------------------------------------------------------- |
|
451 // CUpnpSsdpMessage::IsSsdpResponse |
|
452 // Return whether . |
|
453 // ----------------------------------------------------------------------------- |
|
454 // |
|
455 EXPORT_C TBool CUpnpSsdpMessage::IsSsdpResponse() |
|
456 { |
|
457 return Method().CompareF( KHttp11WithoutSpace() ) == 0; |
|
458 } |
|
459 |
|
460 // ----------------------------------------------------------------------------- |
|
461 // CUpnpSsdpMessage::IsSearchAll |
|
462 // |
|
463 // (other items were commented in a header). |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 EXPORT_C TBool CUpnpSsdpMessage::IsSearchAll() |
|
467 { |
|
468 |
|
469 TBool IsSearch=IsSsdpMSearch(); |
|
470 |
|
471 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
472 |
|
473 while ( hdr ) |
|
474 { |
|
475 if ( ( IsSearch ) && ( hdr->Name().CompareF ( KHdrSt ) == 0 ) |
|
476 && ( hdr->Value().CompareF ( KSearchTargetAll ) == 0 ) ) |
|
477 { |
|
478 return ETrue; |
|
479 } |
|
480 |
|
481 hdr = iHeaderList->Next(hdr); |
|
482 } |
|
483 return EFalse; |
|
484 } |
|
485 |
|
486 // ----------------------------------------------------------------------------- |
|
487 // CUpnpSsdpMessage::IsSearchDevice |
|
488 // |
|
489 // (other items were commented in a header). |
|
490 // ----------------------------------------------------------------------------- |
|
491 // |
|
492 EXPORT_C TBool CUpnpSsdpMessage::IsSearchDevice() |
|
493 { |
|
494 TBool IsSearch=IsSsdpMSearch(); |
|
495 |
|
496 if (IsSearch) |
|
497 { |
|
498 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
499 |
|
500 while ( hdr ) |
|
501 { |
|
502 if ( hdr->Name().CompareF ( KHdrSt ) == 0 ) |
|
503 { |
|
504 if ( hdr->Value().FindF(KUPnPDeviceSchema) == 0 ) |
|
505 { |
|
506 return ETrue; |
|
507 } |
|
508 } |
|
509 |
|
510 hdr = iHeaderList->Next(hdr); |
|
511 } |
|
512 } |
|
513 |
|
514 return EFalse; |
|
515 |
|
516 } |
|
517 |
|
518 // ----------------------------------------------------------------------------- |
|
519 // CUpnpSsdpMessage::IsSearchService |
|
520 // |
|
521 // (other items were commented in a header). |
|
522 // ----------------------------------------------------------------------------- |
|
523 // |
|
524 EXPORT_C TBool CUpnpSsdpMessage::IsSearchService() |
|
525 { |
|
526 TBool IsSearch=IsSsdpMSearch(); |
|
527 |
|
528 if (IsSearch) |
|
529 { |
|
530 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
531 |
|
532 while ( hdr ) |
|
533 { |
|
534 if ( hdr->Name().CompareF ( KHdrSt ) == 0 ) |
|
535 { |
|
536 if ( hdr->Value().FindF( KUPnPServiceSchema ) == 0 ) |
|
537 { |
|
538 return ETrue; |
|
539 } |
|
540 } |
|
541 |
|
542 hdr = iHeaderList->Next(hdr); |
|
543 } |
|
544 } |
|
545 |
|
546 return EFalse; |
|
547 } |
|
548 |
|
549 // ----------------------------------------------------------------------------- |
|
550 // CUpnpSsdpMessage::St |
|
551 // |
|
552 // (other items were commented in a header). |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 EXPORT_C TDesC8& CUpnpSsdpMessage::St() |
|
556 { |
|
557 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
558 |
|
559 TBool valuefound=EFalse; |
|
560 |
|
561 while ( !valuefound && hdr ) |
|
562 { |
|
563 if ( hdr->Name().FindF(KHdrSt()) == 0 && hdr->Name().Length() == KHdrSTLen ) |
|
564 { |
|
565 return hdr->Value(); |
|
566 } |
|
567 hdr = iHeaderList->Next(hdr); |
|
568 } |
|
569 return (TDesC8&) KNullDesC8(); |
|
570 } |
|
571 |
|
572 // ----------------------------------------------------------------------------- |
|
573 // CUpnpSsdpMessage::Nt |
|
574 // |
|
575 // (other items were commented in a header). |
|
576 // ----------------------------------------------------------------------------- |
|
577 // |
|
578 EXPORT_C TDesC8& CUpnpSsdpMessage::Nt() |
|
579 { |
|
580 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
581 |
|
582 TBool valuefound=EFalse; |
|
583 |
|
584 while ( !valuefound && hdr ) |
|
585 { |
|
586 if ( hdr->Name().CompareF( KHdrSearchTarget ) == 0 ) |
|
587 { |
|
588 return hdr->Value(); |
|
589 } |
|
590 hdr = iHeaderList->Next(hdr); |
|
591 } |
|
592 |
|
593 return (TDesC8&) KNullDesC8(); |
|
594 } |
|
595 |
|
596 // ----------------------------------------------------------------------------- |
|
597 // CUpnpSsdpMessage::Usn |
|
598 // |
|
599 // (other items were commented in a header). |
|
600 // ----------------------------------------------------------------------------- |
|
601 // |
|
602 EXPORT_C TDesC8& CUpnpSsdpMessage::Usn() |
|
603 { |
|
604 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
605 |
|
606 TBool valuefound=EFalse; |
|
607 |
|
608 while ( !valuefound && hdr ) |
|
609 { |
|
610 if ( hdr->Name().CompareF( KHdrUuid ) == 0 ) |
|
611 { |
|
612 return hdr->Value(); |
|
613 } |
|
614 hdr = iHeaderList->Next(hdr); |
|
615 } |
|
616 |
|
617 return (TDesC8&) KNullDesC8(); |
|
618 |
|
619 } |
|
620 |
|
621 // ----------------------------------------------------------------------------- |
|
622 // CUpnpSsdpMessage::Nts |
|
623 // |
|
624 // (other items were commented in a header). |
|
625 // ----------------------------------------------------------------------------- |
|
626 // |
|
627 EXPORT_C TDesC8& CUpnpSsdpMessage::Nts() |
|
628 { |
|
629 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
630 |
|
631 TBool valuefound=EFalse; |
|
632 |
|
633 while ( !valuefound && hdr ) |
|
634 { |
|
635 if ( hdr->Name().CompareF(KHdrNotificationType) == 0 ) |
|
636 { |
|
637 return hdr->Value(); |
|
638 } |
|
639 hdr = iHeaderList->Next(hdr); |
|
640 } |
|
641 |
|
642 return (TDesC8&) KNullDesC8(); |
|
643 } |
|
644 |
|
645 // ----------------------------------------------------------------------------- |
|
646 // CUpnpSsdpMessage::ParseL |
|
647 // |
|
648 // (other items were commented in a header). |
|
649 // ----------------------------------------------------------------------------- |
|
650 // |
|
651 void CUpnpSsdpMessage::ParseL(TDesC8& aBuffer) |
|
652 { |
|
653 TInt index = 1,indexLWS=0, indexCRLF=0; |
|
654 TBool FirstLine=ETrue; |
|
655 TPtrC8 finderIndexPointer; |
|
656 TPtrC8 tempHeaderPointer; |
|
657 HBufC8* tempHeaderBuffer = aBuffer.AllocLC(); |
|
658 TInt endOfHeader=0; |
|
659 endOfHeader = aBuffer.Find(UpnpString::KDoubleLineFeed); |
|
660 if( endOfHeader == KErrNotFound ) |
|
661 { |
|
662 User::Leave(KErrAbort); |
|
663 } |
|
664 tempHeaderPointer.Set(aBuffer.Left(endOfHeader)); |
|
665 |
|
666 while ( index != KErrNotFound && index != KErrNone ) |
|
667 { |
|
668 //RFC822 3.2 field-name = 1*<any CHAR, excluding CTLs, SPACE, and ":"> |
|
669 index = tempHeaderBuffer->Des().Find(UpnpString::KLineFeed); |
|
670 indexLWS = FindLWS(tempHeaderPointer); |
|
671 finderIndexPointer.Set(tempHeaderPointer); |
|
672 indexCRLF = index; |
|
673 while (indexCRLF == indexLWS && indexCRLF != KErrNotFound) |
|
674 { |
|
675 finderIndexPointer.Set(finderIndexPointer.Right(finderIndexPointer.Length()-(indexCRLF+3)));//3 = LWS |
|
676 indexCRLF = finderIndexPointer.Find(UpnpString::KLineFeed); |
|
677 //+3 - index skips the length of KLineFeed and parses further... |
|
678 index += indexCRLF+3; |
|
679 indexLWS = FindLWS(finderIndexPointer); |
|
680 } |
|
681 |
|
682 |
|
683 if(index != KErrNotFound && index != KErrNone) |
|
684 { |
|
685 HBufC8* oneHeaderRow=NULL; |
|
686 oneHeaderRow=HBufC8::NewLC(index); |
|
687 oneHeaderRow->Des().Zero(); |
|
688 |
|
689 TPtrC8 ptr; |
|
690 ptr.Set(tempHeaderBuffer->Des().Left(index)); |
|
691 |
|
692 oneHeaderRow->Des().Append(ptr); |
|
693 |
|
694 // To check if is the first line of message |
|
695 // (e.g. GET / HTTP 1.1 etc.) |
|
696 if (FirstLine) |
|
697 { |
|
698 ParseHeaderRowL( (TDesC8&) *oneHeaderRow, ETrue); |
|
699 FirstLine=EFalse; |
|
700 } |
|
701 else |
|
702 { |
|
703 ParseHeaderRowL(*oneHeaderRow, EFalse); |
|
704 } |
|
705 |
|
706 |
|
707 CleanupStack::PopAndDestroy(); // oneHeaderRow |
|
708 |
|
709 // To delete one header row + "\r\n" = length+2 |
|
710 // to prepare for next row. |
|
711 tempHeaderBuffer->Des().Delete(0,index+2); |
|
712 tempHeaderPointer.Set(tempHeaderBuffer->Des()); |
|
713 |
|
714 |
|
715 } |
|
716 } |
|
717 CleanupStack::PopAndDestroy(); // TempHeaderBuffer |
|
718 |
|
719 } |
|
720 |
|
721 // ----------------------------------------------------------------------------- |
|
722 // CUpnpSsdpMessage::IsSsdpNotify |
|
723 // Return whether SSDP notify is true or false. |
|
724 // ----------------------------------------------------------------------------- |
|
725 // |
|
726 EXPORT_C TBool CUpnpSsdpMessage::IsSsdpNotify() |
|
727 { |
|
728 return Method().CompareF( UpnpSSDP::KNotify() ) == 0; |
|
729 } |
|
730 |
|
731 // ----------------------------------------------------------------------------- |
|
732 // CUpnpSsdpMessage::Location |
|
733 // Return location. |
|
734 // ----------------------------------------------------------------------------- |
|
735 // |
|
736 EXPORT_C TDesC8& CUpnpSsdpMessage::Location() |
|
737 { |
|
738 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
739 |
|
740 while ( hdr ) |
|
741 { |
|
742 if ( hdr->Name().CompareF(KHdrLocation) == 0 ) |
|
743 { |
|
744 return hdr->Value(); |
|
745 } |
|
746 hdr = iHeaderList->Next(hdr); |
|
747 } |
|
748 |
|
749 return (TDesC8&) KNullDesC8(); |
|
750 |
|
751 } |
|
752 |
|
753 // ----------------------------------------------------------------------------- |
|
754 // CUpnpSsdpMessage::Uuid |
|
755 // Return UUID. |
|
756 // ----------------------------------------------------------------------------- |
|
757 // |
|
758 EXPORT_C TPtr8 CUpnpSsdpMessage::Uuid() |
|
759 { |
|
760 TPtrC8 usn = Usn(); |
|
761 |
|
762 TInt sng = usn.Find(UpnpString::KColon); |
|
763 TInt dbl = usn.Find(UpnpString::KDblColon); |
|
764 |
|
765 TPtr8 uuid(NULL, 0, 0); |
|
766 if (dbl != KErrNotFound && dbl != sng) |
|
767 { |
|
768 TPtrC8 temp = usn.Mid(sng + 1, (dbl - sng) - 1); |
|
769 uuid.Set((unsigned char*)temp.Ptr(), temp.Length(), temp.Length()); |
|
770 } |
|
771 else |
|
772 { |
|
773 if (dbl == KErrNotFound) |
|
774 { |
|
775 TPtrC8 temp = usn.Right((usn.Length() - sng) - 1); |
|
776 uuid.Set((unsigned char*)temp.Ptr(), temp.Length(), temp.Length()); |
|
777 } |
|
778 else |
|
779 { |
|
780 TPtrC8 temp = usn.Left(dbl); |
|
781 uuid.Set((unsigned char*)temp.Ptr(), temp.Length(), temp.Length()); |
|
782 } |
|
783 } |
|
784 return uuid; |
|
785 } |
|
786 |
|
787 // ----------------------------------------------------------------------------- |
|
788 // CUpnpSsdpMessage::CacheControl |
|
789 // |
|
790 // (other items were commented in a header). |
|
791 // ----------------------------------------------------------------------------- |
|
792 // |
|
793 EXPORT_C TInt CUpnpSsdpMessage::CacheControl() |
|
794 { |
|
795 CUpnpHttpHeader* hdr = iHeaderList->First(); |
|
796 |
|
797 TBool valuefound=EFalse; |
|
798 |
|
799 while ( !valuefound && hdr ) |
|
800 { |
|
801 if ( hdr->Name().CompareF( UpnpSSDP::KHdrCacheControl() ) == KErrNone ) |
|
802 { |
|
803 |
|
804 TDesC8& value = hdr->Value(); |
|
805 |
|
806 TInt index = value.FindF(KSsdpMaxAge()); |
|
807 TInt eqIndex = value.Find(UpnpString::KEqual()); |
|
808 |
|
809 if (index != KErrNotFound && eqIndex!= KErrNotFound && index < eqIndex) |
|
810 { |
|
811 TLex8 num(value.Right((value.Length() |
|
812 - UpnpString::KEqual().Length()) - eqIndex)); |
|
813 num.SkipSpace(); |
|
814 TInt cc; |
|
815 TInt err( num.Val(cc) ); |
|
816 if ( ( cc < 0 ) || err ) |
|
817 { |
|
818 return KDefaultMaxAgeValue; |
|
819 } |
|
820 return cc; |
|
821 } |
|
822 return KDefaultMaxAgeValue; |
|
823 } |
|
824 hdr = iHeaderList->Next(hdr); |
|
825 } |
|
826 return KDefaultMaxAgeValue; |
|
827 } |
|
828 |
|
829 // ----------------------------------------------------------------------------- |
|
830 // CUpnpSsdpMessage::ToStringL |
|
831 // Convert headers to string. |
|
832 // ----------------------------------------------------------------------------- |
|
833 // |
|
834 HBufC8* CUpnpSsdpMessage::ToStringL() |
|
835 { |
|
836 HBufC8* buffer=NULL; |
|
837 buffer=HeadersToStringL(); |
|
838 |
|
839 CleanupStack::PushL(buffer); |
|
840 |
|
841 HBufC8* returnBuf = NULL; |
|
842 //+2 bytes reserved for KLineFeed |
|
843 returnBuf=HBufC8::NewLC(buffer->Des().Length() + 2); |
|
844 |
|
845 returnBuf->Des().Append(*buffer); |
|
846 returnBuf->Des().Append(UpnpString::KLineFeed()); |
|
847 |
|
848 CleanupStack::Pop( returnBuf ); |
|
849 CleanupStack::PopAndDestroy( buffer ); |
|
850 |
|
851 return returnBuf; |
|
852 } |
|
853 // ----------------------------------------------------------------------------- |
|
854 // CUpnpSsdpMessage::AppendContentLengthToHeadersL |
|
855 // Overwrites the method from CUpnpHttpMessage. It is empty on purpose!. |
|
856 // ----------------------------------------------------------------------------- |
|
857 // |
|
858 EXPORT_C void CUpnpSsdpMessage::AppendContentLengthToHeadersL(HBufC8*& /*aHeaders*/) |
|
859 { |
|
860 } |
|
861 // ----------------------------------------------------------------------------- |
|
862 // CUpnpSsdpMessage::HttpConstructL |
|
863 // Constructor of HTTP message. |
|
864 // ----------------------------------------------------------------------------- |
|
865 // |
|
866 void CUpnpSsdpMessage::HttpConstructL(TInetAddr& aAddr) |
|
867 { |
|
868 CUpnpHttpMessage::ConstructL( aAddr, 0 ); |
|
869 } |
|
870 |
|
871 // End of File |