|
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: Gena message factory |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "upnpgenamessagefactory.h" |
|
21 #include "upnpstring.h" |
|
22 #define KLogFile _L("UPnPStack.txt") |
|
23 #include "upnpcustomlog.h" |
|
24 // for "Second-" |
|
25 #include "upnpcommonupnplits.h" |
|
26 |
|
27 // CONSTANTS |
|
28 using namespace UpnpGENA; |
|
29 using namespace UpnpHTTP; |
|
30 |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // RUpnpGenaMessageFactory::SubscribeL |
|
36 // Subscribe to path and host. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::SubscribeL( const TDesC8& aPath, |
|
40 TInetAddr& aHost, |
|
41 const TDesC8& aCallback ) |
|
42 { |
|
43 LOGS("RUpnpGenaMessageFactory::SubscribeL(TDesC8&, TInetAddr&, TDesC8&)"); |
|
44 |
|
45 CUpnpGenaMessage* msg = CUpnpGenaMessage::NewLC( aHost ); |
|
46 |
|
47 HBufC8* temp = HBufC8::NewLC( KGenaSubscribe().Length() + |
|
48 UpnpString::KSpace().Length() + |
|
49 UpnpString::KSlash().Length() + |
|
50 aPath.Length() + |
|
51 KHttp11().Length() ); |
|
52 |
|
53 temp->Des().Zero(); |
|
54 temp->Des().Append( KGenaSubscribe ); |
|
55 temp->Des().Append( UpnpString::KSpace ); |
|
56 if ( aPath.Find( UpnpString::KSlash() ) != 0 ) |
|
57 { |
|
58 temp->Des().Append( UpnpString::KSlash() ); |
|
59 } |
|
60 temp->Des().Append( aPath ); |
|
61 temp->Des().Append( KHttp11 ); |
|
62 msg->AddPairL( temp->Des(), KNullDesC8 ); |
|
63 CleanupStack::PopAndDestroy( temp ); |
|
64 |
|
65 HBufC8* host = UpnpString::InetToStringL( aHost ); |
|
66 CleanupStack::PushL( host ); |
|
67 msg->AddPairL( UpnpSSDP::KHdrHost(), *host ); |
|
68 CleanupStack::PopAndDestroy( host ); |
|
69 |
|
70 msg->AddPairL( KCallback, aCallback ); |
|
71 msg->AddPairL( UpnpSSDP::KHdrSearchTarget, KDefaultNt ); |
|
72 |
|
73 CleanupStack::Pop( msg ); |
|
74 return msg; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // RUpnpGenaMessageFactory::SubscribeL |
|
79 // Subscribe to path and host using timeout. |
|
80 // ----------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::SubscribeL( const TDesC8& aPath, |
|
83 TInetAddr& aHost, |
|
84 const TDesC8& aCallback, |
|
85 const TDesC8& aTimeout ) |
|
86 { |
|
87 LOGS("RUpnpGenaMessageFactory::SubscribeL(TDesC8&, TInetAddr&, TDesC8&, TDesC8&)"); |
|
88 |
|
89 CUpnpGenaMessage* msg = SubscribeL( aPath, aHost, aCallback ); |
|
90 CleanupStack::PushL( msg ); |
|
91 |
|
92 HBufC8* timeout = HBufC8::NewLC( KTimeoutPrefix().Length() + aTimeout.Length() ); |
|
93 timeout->Des().Append( KTimeoutPrefix() ); |
|
94 timeout->Des().Append( aTimeout ); |
|
95 |
|
96 msg->AddPairL( KTimeout, *timeout ); |
|
97 |
|
98 CleanupStack::PopAndDestroy( timeout ); |
|
99 |
|
100 CleanupStack::Pop( msg ); |
|
101 return msg; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // RUpnpGenaMessageFactory::UnsubscribeL |
|
106 // Unsubscribe from path and host. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::UnsubscribeL( const TDesC8 &aPath, |
|
110 TInetAddr &aHost, |
|
111 const TDesC8 &aSid ) |
|
112 { |
|
113 LOGS("RUpnpGenaMessageFactory::UnsubscribeL(TDesC8&, TInetAddr&, TDesC8&)"); |
|
114 |
|
115 CUpnpGenaMessage* msg = CUpnpGenaMessage::NewLC( aHost ); |
|
116 |
|
117 HBufC8* temp = HBufC8::NewLC( KGenaUnSubscribe().Length() + |
|
118 UpnpString::KSpace().Length() + |
|
119 UpnpString::KSlash().Length() + |
|
120 aPath.Length() + |
|
121 KHttp11().Length() ); |
|
122 |
|
123 temp->Des().Zero(); |
|
124 temp->Des().Append( KGenaUnSubscribe ); |
|
125 temp->Des().Append( UpnpString::KSpace ); |
|
126 if ( aPath.Find( UpnpString::KSlash() ) != 0 ) |
|
127 { |
|
128 temp->Des().Append( UpnpString::KSlash() ); |
|
129 } |
|
130 temp->Des().Append( aPath ); |
|
131 temp->Des().Append( KHttp11 ); |
|
132 msg->AddPairL( temp->Des(), KNullDesC8 ); |
|
133 CleanupStack::PopAndDestroy( temp ); |
|
134 |
|
135 HBufC8* host = UpnpString::InetToStringL( aHost ); |
|
136 CleanupStack::PushL( host ); |
|
137 msg->AddPairL( UpnpSSDP::KHdrHost(), *host ); |
|
138 CleanupStack::PopAndDestroy( host ); |
|
139 |
|
140 msg->AddPairL( UpnpGENA::KSid(), aSid ); |
|
141 |
|
142 CleanupStack::Pop( msg ); |
|
143 |
|
144 return msg; |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // RUpnpGenaMessageFactory::ResubscribeL |
|
149 // Resubscribe to path and host with SID. |
|
150 // ----------------------------------------------------------------------------- |
|
151 // |
|
152 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::ResubscribeL( const TDesC8& aPath, |
|
153 TInetAddr& aHost, |
|
154 const TDesC8& aSid ) |
|
155 { |
|
156 LOGS("RUpnpGenaMessageFactory::ResubscribeL(TDesC8&, TInetAddr&, TDesC8&)"); |
|
157 CUpnpGenaMessage* msg = CUpnpGenaMessage::NewLC( aHost ); |
|
158 |
|
159 HBufC8* temp = HBufC8::NewLC( KGenaUnSubscribe().Length() + |
|
160 UpnpString::KSpace().Length() + |
|
161 UpnpString::KSlash().Length() + |
|
162 aPath.Length() + |
|
163 KHttp11().Length() ); |
|
164 |
|
165 temp->Des().Zero(); |
|
166 temp->Des().Append( KGenaSubscribe ); |
|
167 temp->Des().Append( UpnpString::KSpace ); |
|
168 if ( aPath.Find( UpnpString::KSlash() ) != 0 ) |
|
169 { |
|
170 temp->Des().Append( UpnpString::KSlash() ); |
|
171 } |
|
172 temp->Des().Append( aPath ); |
|
173 temp->Des().Append( KHttp11 ); |
|
174 msg->AddPairL( temp->Des(), KNullDesC8 ); |
|
175 CleanupStack::PopAndDestroy( temp ); |
|
176 |
|
177 HBufC8* host = UpnpString::InetToStringL( aHost ); |
|
178 CleanupStack::PushL( host ); |
|
179 msg->AddPairL( UpnpSSDP::KHdrHost(), *host ); |
|
180 CleanupStack::PopAndDestroy( host ); |
|
181 |
|
182 msg->AddPairL( UpnpGENA::KSid, aSid ); |
|
183 |
|
184 CleanupStack::Pop( msg ); |
|
185 |
|
186 return msg; |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // RUpnpGenaMessageFactory::ResubscribeL |
|
191 // Resubscribe to path and host with SID using timeout. |
|
192 // ----------------------------------------------------------------------------- |
|
193 // |
|
194 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::ResubscribeL( const TDesC8& aPath, |
|
195 TInetAddr& aHost, |
|
196 const TDesC8& aSid, |
|
197 const TDesC8& aTimeout ) |
|
198 { |
|
199 LOGS("RUpnpGenaMessageFactory::ResubscribeL(TDesC8&, TInetAddr&, TDesC8&, TDesC8&)"); |
|
200 |
|
201 CUpnpGenaMessage* msg = ResubscribeL( aPath, aHost, aSid ); |
|
202 CleanupStack::PushL( msg ); |
|
203 |
|
204 HBufC8* timeout = HBufC8::NewLC( KTimeoutPrefix().Length() + aTimeout.Length() ); |
|
205 timeout->Des().Append( KTimeoutPrefix() ); |
|
206 timeout->Des().Append( aTimeout ); |
|
207 |
|
208 msg->AddPairL( KTimeout, *timeout ); |
|
209 |
|
210 CleanupStack::PopAndDestroy( timeout ); |
|
211 |
|
212 CleanupStack::Pop( msg ); |
|
213 |
|
214 return msg; |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // RUpnpGenaMessageFactory::SubscribeResponseL |
|
219 // Subscribe response. |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::SubscribeResponseL( |
|
223 TInt aSessionId, |
|
224 const TInetAddr& aDestination, |
|
225 const TDesC8& aSid, |
|
226 const TDesC8& aTimeout ) |
|
227 { |
|
228 LOGS("RUpnpGenaMessageFactory::SubscribeResponseL(TInt, TInetAddr&, TDesC8&, TDesC8&, TDesC8&)"); |
|
229 |
|
230 CUpnpGenaMessage* msg = SubscribeResponseL( aSessionId, aDestination, |
|
231 (TBool)ETrue, aSid, aTimeout ); |
|
232 |
|
233 return msg; |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // RUpnpGenaMessageFactory::SubscribeResponseL |
|
238 // Subscribe response. |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::SubscribeResponseL( |
|
242 TInt aSessionId, |
|
243 const TInetAddr& aDestination, |
|
244 TBool /*aTimeStamp*/, |
|
245 const TDesC8& aSid, |
|
246 const TDesC8& aTimeout ) |
|
247 { |
|
248 LOGS("RUpnpGenaMessageFactory::SubscribeResponseL(TInt, TInetAddr&, TBool, TDesC8&, TDesC8&, TDesC8&)"); |
|
249 |
|
250 CUpnpGenaMessage* msg = CUpnpGenaMessage::NewLC( aDestination ); |
|
251 |
|
252 msg->SetSessionId( aSessionId ); |
|
253 msg->AddPairL( KHttp11Ok, KNullDesC8 ); |
|
254 |
|
255 msg->AddPairL( UpnpGENA::KSid, aSid ); |
|
256 msg->AddPairL( KTimeout, aTimeout ); |
|
257 |
|
258 CleanupStack::Pop( msg ); |
|
259 return msg; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // RUpnpGenaMessageFactory::UnsubscribeResponseL |
|
264 // Unsubscribe response. |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::UnsubscribeResponseL( |
|
268 TInt aSessionId, |
|
269 const TInetAddr& aDestination ) |
|
270 { |
|
271 LOGS("RUpnpGenaMessageFactory::UnsubscribeResponseL(TInt, TInetAddr&)"); |
|
272 |
|
273 CUpnpGenaMessage* msg = CUpnpGenaMessage::NewLC( aDestination ); |
|
274 msg->SetSessionId( aSessionId ); |
|
275 msg->AddPairL( KHttp11Ok, KNullDesC8 ); |
|
276 |
|
277 CleanupStack::Pop( msg ); |
|
278 return msg; |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // RUpnpGenaMessageFactory::EventingLC |
|
283 // Eventing. |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 EXPORT_C CUpnpGenaMessage* RUpnpGenaMessageFactory::EventingLC( const TDesC8& aPath, |
|
287 TInetAddr& aHost, |
|
288 const TDesC8& aSid, |
|
289 TUint32 aSeq ) |
|
290 { |
|
291 LOGS("RUpnpGenaMessageFactory::EventingLC(TDesC8&, TInetAddr&, TDesC8&, TUint32)"); |
|
292 |
|
293 CUpnpGenaMessage* msg = CUpnpGenaMessage::NewLC( aHost ); |
|
294 |
|
295 HBufC8* temp = HBufC8::NewLC( KMaxHeaderLength ); |
|
296 |
|
297 temp->Des().Zero(); |
|
298 temp->Des().Append( KGenaNotify ); |
|
299 temp->Des().Append( UpnpString::KSpace ); |
|
300 |
|
301 if ( aPath.Find( UpnpString::KSlash() ) != 0 ) |
|
302 { |
|
303 temp->Des().Append( UpnpString::KSlash() ); |
|
304 } |
|
305 |
|
306 temp->Des().Append( aPath ); |
|
307 temp->Des().Append( UpnpString::KSpace ); |
|
308 temp->Des().Append( KHttp11WithoutSpace ); |
|
309 msg->AddPairL( temp->Des(), KNullDesC8 ); |
|
310 CleanupStack::PopAndDestroy( temp ); |
|
311 temp = NULL; |
|
312 |
|
313 HBufC8* host = UpnpString::InetToStringL( aHost ); |
|
314 CleanupStack::PushL( host ); |
|
315 msg->AddPairL( UpnpSSDP::KHdrHost(), *host ); |
|
316 CleanupStack::PopAndDestroy( host ); |
|
317 |
|
318 msg->AddPairL( UpnpGENA::KContentType, KTextXmlUtf8 ); |
|
319 // length automatic by httpmessage |
|
320 msg->AddPairL( UpnpHTTP::KHdrContentLength, KNullDesC8 ); |
|
321 msg->AddPairL( UpnpSSDP::KHdrSearchTarget, KDefaultNt ); |
|
322 msg->AddPairL( UpnpSSDP::KHdrNotificationType, KDefaultNts ); |
|
323 msg->AddPairL( UpnpGENA::KSid, aSid ); |
|
324 |
|
325 temp = HBufC8::NewLC( UpnpString::KMaxTUintLength ); |
|
326 temp->Des().NumUC( aSeq ); |
|
327 msg->AddPairL( KSeq, *temp ); |
|
328 CleanupStack::PopAndDestroy( temp ); |
|
329 |
|
330 |
|
331 return msg; |
|
332 } |
|
333 |
|
334 // End of File |