|
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: Declares ServiceInfi class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <e32cons.h> |
|
23 #include "upnpdevice.h" |
|
24 #include "upnpserviceinfo.h" |
|
25 #include "upnpcontrolpoint.h" |
|
26 #include "upnpcommonupnplits.h" |
|
27 #include "upnpgenamessagefactory.h" |
|
28 |
|
29 #undef KLogFile |
|
30 #define KLogFile _L("UPnPCP.txt") |
|
31 #include "upnpcustomlog.h" |
|
32 using namespace UpnpHTTP; |
|
33 |
|
34 static const TInt KSubscriptionRenewalTimeWindow = 3; |
|
35 static const TInt KSubscriptionRenewalMinimalTime = 6; |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CUpnpAction::NewLC |
|
40 // Two-phased constructor. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CUpnpServiceInfo* CUpnpServiceInfo::NewLC( |
|
44 CUpnpControlPoint* aControlPoint, |
|
45 CUpnpService* aService ) |
|
46 { |
|
47 CUpnpServiceInfo* self = new (ELeave) CUpnpServiceInfo( |
|
48 aControlPoint, |
|
49 aService ); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 return self; |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CUpnpServiceInfo::ConstructL |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void CUpnpServiceInfo::ConstructL() |
|
60 { |
|
61 iResubscribeTimer = CUpnpNotifyTimer::NewL( this ); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CUpnpServiceInfo::CUpnpServiceInfo |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 CUpnpServiceInfo::CUpnpServiceInfo( CUpnpControlPoint* aControlPoint, |
|
69 CUpnpService* aService ): |
|
70 iService( aService ), |
|
71 iControlPoint( aControlPoint ), |
|
72 iTimeOut( CUpnpControlPoint::KDefaultSubscriptionTimeout ) |
|
73 { |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CUpnpServiceInfo::~CUpnpServiceInfo |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CUpnpServiceInfo::~CUpnpServiceInfo() |
|
81 { |
|
82 delete iResubscribeTimer; |
|
83 delete iSid; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CUpnpServiceInfo::TimerEventL |
|
88 // Callback function |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 void CUpnpServiceInfo::TimerEventL( CUpnpNotifyTimer* /*aTimer*/ ) |
|
92 { |
|
93 ResubscribeL(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CUpnpServiceInfo::StartTimerL |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 void CUpnpServiceInfo::StartTimerL( const TDesC8& aTimeout ) |
|
101 { |
|
102 if ( aTimeout.FindC( KSeconds() ) != KErrNotFound ) |
|
103 { |
|
104 TLex8 lex( aTimeout ); |
|
105 static const TInt KLengthOfWordSecondMinus = 7; |
|
106 lex.Inc( KLengthOfWordSecondMinus ); |
|
107 TInt tOutValue; |
|
108 TInt err( lex.Val( tOutValue ) ); |
|
109 User::LeaveIfError( err ); |
|
110 iTimeOut = tOutValue; |
|
111 } |
|
112 else |
|
113 { |
|
114 iTimeOut = |
|
115 CUpnpControlPoint::KDefaultSubscriptionTimeout ; |
|
116 } |
|
117 //prevention from too frequent subscriptions |
|
118 if ( iTimeOut < KSubscriptionRenewalMinimalTime ) |
|
119 { |
|
120 iTimeOut = KSubscriptionRenewalMinimalTime; |
|
121 } |
|
122 iResubscribeTimer->AfterSeconds( |
|
123 iTimeOut - KSubscriptionRenewalTimeWindow); |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CUpnpServiceInfo::SessionId |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 TInt CUpnpServiceInfo::SessionId() |
|
131 { |
|
132 return iSessionId; |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CUpnpServiceInfo::Service |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 CUpnpService* CUpnpServiceInfo::Service() |
|
140 { |
|
141 return iService; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CUpnpServiceInfo::Sid |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 const TDesC8& CUpnpServiceInfo::Sid() const |
|
149 { |
|
150 if ( iSid ) |
|
151 { |
|
152 return *iSid; |
|
153 } |
|
154 else |
|
155 { |
|
156 return KNullDesC8; |
|
157 } |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CUpnpServiceInfo::SetSidL |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CUpnpServiceInfo::SetSidL( const TDesC8& aSid ) |
|
165 { |
|
166 delete iSid; |
|
167 iSid = NULL; |
|
168 iSid = aSid.AllocL(); |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CUpnpServiceInfo::SetSeq |
|
173 // Sets sequence |
|
174 // ----------------------------------------------------------------------------- |
|
175 // |
|
176 void CUpnpServiceInfo::SetSeq( TUint32 aSeq ) |
|
177 { |
|
178 iSeq = aSeq; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CUpnpServiceInfo::Seq |
|
183 // |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TUint32 CUpnpServiceInfo::Seq() const |
|
187 { |
|
188 return iSeq; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CUpnpServiceInfo::CreateSubscribtionMessageL |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 CUpnpGenaMessage* CUpnpServiceInfo::CreateSubscriptionMessageL( |
|
196 THTTPMsgType aType) |
|
197 { |
|
198 return CreateSubscriptionMessageL( *iSid, aType ); |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CUpnpServiceInfo::CreateSubscribtionMessageL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 CUpnpGenaMessage* CUpnpServiceInfo::CreateSubscriptionMessageL( |
|
206 const TDesC8& aPath, THTTPMsgType aType) |
|
207 { |
|
208 CUpnpGenaMessage* result = NULL; |
|
209 |
|
210 TBuf8<UpnpString::KMaxIntLength> timeoutBuf; |
|
211 timeoutBuf.Num( iTimeOut ); |
|
212 |
|
213 CUpnpDevice& device = iService->Device(); |
|
214 |
|
215 TInetAddr servAddress = iService->Address(); |
|
216 TPtrC8 subscribe = iService->SubscriptionUrl(); |
|
217 |
|
218 // check if path is not absolute |
|
219 if( subscribe.Find( KHttp() ) == 0 ) |
|
220 { |
|
221 subscribe.Set( subscribe.Mid( KHttp().Length() ) ); |
|
222 TInt slashPos = subscribe.Find( UpnpString::KSlash() ); |
|
223 if( slashPos != KErrNotFound ) |
|
224 { |
|
225 servAddress = iControlPoint->GiveAddressL( subscribe.Left( slashPos )); |
|
226 subscribe.Set( subscribe.Mid( slashPos ) ); |
|
227 } |
|
228 } |
|
229 |
|
230 switch( aType ) |
|
231 { |
|
232 case ESubscription: |
|
233 { |
|
234 result = RUpnpGenaMessageFactory::SubscribeL( |
|
235 subscribe, servAddress, aPath, timeoutBuf ); |
|
236 break; |
|
237 } |
|
238 case EResubscription: |
|
239 { |
|
240 result = RUpnpGenaMessageFactory::ResubscribeL( |
|
241 subscribe, servAddress, aPath, timeoutBuf ); |
|
242 break; |
|
243 } |
|
244 case EUnSubscription: |
|
245 { |
|
246 result = RUpnpGenaMessageFactory::UnsubscribeL( |
|
247 subscribe, servAddress, aPath); |
|
248 break; |
|
249 } |
|
250 default: |
|
251 { |
|
252 // Undefined. Should not come here at all! |
|
253 User::Leave(KErrArgument); |
|
254 break; |
|
255 } |
|
256 } |
|
257 if(result == NULL) |
|
258 { |
|
259 // To avoid Coverity FORWARD_NULL errors |
|
260 User::Leave(KErrArgument); |
|
261 } |
|
262 |
|
263 result->SetType( aType ); |
|
264 iSessionId = result->SessionId(); |
|
265 |
|
266 return result; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CUpnpServiceInfo::ResubscribeL |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 void CUpnpServiceInfo::ResubscribeL() |
|
274 { |
|
275 LOGS( "CUpnpServiceInfo::ResubscribeL - start" ); |
|
276 iControlPoint->ResubscribeL( this ); |
|
277 LOGS( "CUpnpServiceInfo::ResubscribeL - end" ); |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CUpnpServiceInfo::ConstructSubscribtionPathLC |
|
282 // |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 HBufC8* CUpnpServiceInfo::ConstructSubscribtionPathLC( const TDesC8& aPath, |
|
286 TInetAddr& aAddr ) |
|
287 { |
|
288 TBuf8<UpnpString::KMaxAddrOutputLength> addrBuf; |
|
289 CUpnpHttpMessage::AddrOutput( aAddr, addrBuf ); |
|
290 |
|
291 TBuf<UpnpString::KMaxIntLength> port; |
|
292 port.Num( aAddr.Port() ); |
|
293 |
|
294 HBufC8* longPath = HBufC8::NewLC( |
|
295 1 + KHTTPUrl().Length() + // "<" |
|
296 addrBuf.Length() + 1 + // ":" |
|
297 port.Length() + 1 + // "\" |
|
298 aPath.Length() + 1 + // "\" |
|
299 aPath.Length() + 1 ); // ">" |
|
300 |
|
301 TPtr8 longPathPtr( longPath->Des() ); |
|
302 longPathPtr.Append( KLessThan8() ); |
|
303 longPathPtr.Append( KHTTPUrl() ); |
|
304 longPathPtr.Append( addrBuf ); |
|
305 longPathPtr.Append( UpnpString::KColon() ); |
|
306 longPathPtr.Append( port ); |
|
307 longPathPtr.Append( UpnpString::KSlash() ); |
|
308 longPathPtr.Append( aPath ); |
|
309 longPathPtr.Append( UpnpString::KSlash() ); |
|
310 longPathPtr.Append( aPath ); |
|
311 longPathPtr.Append( KGreaterThan8() ); |
|
312 |
|
313 return longPath; |
|
314 } |
|
315 |
|
316 //end of file |