|
1 // Copyright (c) 2008-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 // |
|
15 |
|
16 #include <httpstringconstants.h> |
|
17 |
|
18 #include "cupnprequestcomposer.h" |
|
19 #include "tupnpmessagepanic.h" |
|
20 |
|
21 __FLOG_STMT(_LIT8(KSubsys,"UPnPReqComposer");) |
|
22 __FLOG_STMT(_LIT8(KComponent,"UPnPMessage");) |
|
23 |
|
24 |
|
25 EXPORT_C CUpnpRequestComposer* CUpnpRequestComposer::NewL(MComposerObserver& aObserver) |
|
26 { |
|
27 CUpnpRequestComposer* self = new (ELeave) CUpnpRequestComposer(aObserver); |
|
28 CleanupStack::PushL(self); |
|
29 self->ConstructL(); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 EXPORT_C CUpnpRequestComposer::~CUpnpRequestComposer() |
|
35 { |
|
36 iMessageComposer.Close(); |
|
37 __FLOG(_L8("-> Request composer destroyed")); |
|
38 __FLOG_CLOSE; |
|
39 } |
|
40 |
|
41 CUpnpRequestComposer::CUpnpRequestComposer(MComposerObserver& aObserver) |
|
42 :CUPnPMessageComposer(aObserver) |
|
43 { |
|
44 } |
|
45 |
|
46 void CUpnpRequestComposer::ConstructL() |
|
47 { |
|
48 CUPnPMessageComposer::ConstructL(); |
|
49 __FLOG_OPEN(KSubsys, KComponent); |
|
50 __FLOG(_L8("-> Request Composer created")); |
|
51 } |
|
52 |
|
53 void CUpnpRequestComposer::StartLineL(TPtrC8& aMethod, TPtrC8& aRequestUri, TPtrC8& aVersion) |
|
54 { |
|
55 __FLOG(_L8("-> Composing request")); |
|
56 __FLOG(_L8("-> Supplying start line")); |
|
57 |
|
58 aMethod.Set(iRequest->StringPool().StringF(iRequest->Method()).DesC()); |
|
59 aRequestUri.Set(iRequest->URI()->Uri().UriDes()); |
|
60 aVersion.Set(iRequest->StringPool().StringF(HTTP::EHttp11, THTTPTable::Table()).DesC()); |
|
61 __FLOG_3(_L8("%S %S %S"), &aMethod, &aRequestUri, &aVersion); |
|
62 } |
|
63 |
|
64 // This function should be moved to CUPnPMessageComposer once the CRequest, CResponse & CMessage |
|
65 // split happens. |
|
66 TInt CUpnpRequestComposer::NextHeaderL(TPtrC8& aHeaderName, TPtrC8& aHeaderValue) |
|
67 { |
|
68 // Are there any more headers? |
|
69 TInt err = KErrNotFound; |
|
70 |
|
71 THTTPHdrFieldIter fields = iRequest->Handle().GetHeaderCollection().Fields(); |
|
72 TInt fieldPos = 0; |
|
73 |
|
74 while(fieldPos != iFieldIterPos) |
|
75 { |
|
76 ++fields; |
|
77 fieldPos++; |
|
78 } |
|
79 |
|
80 if( !fields.AtEnd() ) |
|
81 { |
|
82 // Get field current field. |
|
83 RStringF name = iRequest->StringPool().StringF(fields()); |
|
84 |
|
85 err = KErrNone; |
|
86 |
|
87 // Get the OTA version of the field value |
|
88 TPtrC8 value; |
|
89 iRequest->Handle().GetHeaderCollection().GetRawField(name, value); |
|
90 |
|
91 // Pass back these values |
|
92 aHeaderName.Set(name.DesC()); |
|
93 aHeaderValue.Set(value); |
|
94 __FLOG(_L8("-> Supplying header value pair")); |
|
95 __FLOG_2(_L8("%S: %S"), &aHeaderName, &aHeaderValue); |
|
96 |
|
97 // Move onto next header field... |
|
98 ++fields; |
|
99 ++iFieldIterPos; |
|
100 } |
|
101 return err; |
|
102 } |
|
103 |
|
104 MHTTPDataSupplier* CUpnpRequestComposer::HasBodyL() |
|
105 { |
|
106 return iRequest->Handle().Body(); |
|
107 } |
|
108 |
|
109 void CUpnpRequestComposer::MessageComplete() |
|
110 { |
|
111 CUPnPMessageComposer::MessageComplete(); |
|
112 } |
|
113 |
|
114 void CUpnpRequestComposer::MessageDataReadyL() |
|
115 { |
|
116 CUPnPMessageComposer::MessageDataReadyL(); |
|
117 } |
|
118 |
|
119 TInt CUpnpRequestComposer::HandleComposeError(TInt aError) |
|
120 { |
|
121 return CUPnPMessageComposer::HandleComposeError(aError); |
|
122 } |
|
123 |
|
124 |
|
125 EXPORT_C void CUpnpRequestComposer::ComposeRequest(CRequest* aRequest) |
|
126 { |
|
127 __ASSERT_DEBUG(aRequest, TUPnPMessagePanic::Panic(TUPnPMessagePanic::EMissingRequest)); |
|
128 iRequest = aRequest; |
|
129 |
|
130 // Notify the Message Composer that the request composing can start. |
|
131 //iMessageComposer.MessageInfoAvailable(); |
|
132 NotifyNewBodyData ( ); |
|
133 } |
|
134 |
|
135 EXPORT_C void CUpnpRequestComposer::RequestDataSent() |
|
136 { |
|
137 // Notify the Message Composed that the current data has been read and it can |
|
138 // release it. |
|
139 __FLOG(_L8("-> Releasing message data")); |
|
140 iDataChain.Close(); //Need to check |
|
141 iMessageComposer.ReleaseMessageData(); |
|
142 } |
|
143 |
|
144 EXPORT_C void CUpnpRequestComposer::ResetComposer() |
|
145 { |
|
146 __FLOG(_L8("-> Request composer reset")); |
|
147 iMessageComposer.Reset(); |
|
148 iRequest = NULL; |
|
149 iFieldIterPos = 0; |
|
150 iDataChain.Close(); |
|
151 } |