|
1 /** @file |
|
2 * Copyright (c) 2009 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 CUpnpSecurityManagerSession class |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include "upnpsecuritymanagersession.h" |
|
20 #include "upnpsecuritymanagerengine.h" |
|
21 #include "upnpsecuritymanagerserver.h" |
|
22 #include "upnpsymbianserverbase.h" |
|
23 #include "upnpsecuritymanagerclientsession.h" |
|
24 |
|
25 // ============================= MEMBER FUNCTIONS ============================== |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CUpnpSecurityManagerSession::NewL |
|
29 // Two-phased constructor. |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 CUpnpSecurityManagerSession* CUpnpSecurityManagerSession::NewL( |
|
33 CUpnpSecurityManagerEngine& aEngine ) |
|
34 { |
|
35 CUpnpSecurityManagerSession* self = |
|
36 CUpnpSecurityManagerSession::NewLC( aEngine ); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CUpnpSecurityManagerSession::NewLC |
|
43 // Two-phased constructor. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CUpnpSecurityManagerSession* CUpnpSecurityManagerSession::NewLC( |
|
47 CUpnpSecurityManagerEngine& aEngine ) |
|
48 { |
|
49 CUpnpSecurityManagerSession* self = |
|
50 new (ELeave) CUpnpSecurityManagerSession( aEngine ); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CUpnpSecurityManagerSession::CUpnpSecurityManagerSession |
|
58 // C++ default constructor can NOT contain any code, that |
|
59 // might leave. |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CUpnpSecurityManagerSession::CUpnpSecurityManagerSession( |
|
63 CUpnpSecurityManagerEngine& aEngine ) : |
|
64 CSession2(), iEngine( aEngine ) |
|
65 { |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CUpnpSecurityManagerSession::~CUpnpSecurityManagerSession |
|
70 // Destructor. |
|
71 // ----------------------------------------------------------------------------- |
|
72 // |
|
73 CUpnpSecurityManagerSession::~CUpnpSecurityManagerSession() |
|
74 { |
|
75 delete iAuthorizationNote; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CUpnpSecurityManagerSession::ConstructL |
|
80 // Second phase constructor. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CUpnpSecurityManagerSession::ConstructL() |
|
84 { |
|
85 // Create object responsible for authorisation dialog |
|
86 iAuthorizationNote = CUpnpAuthorizationNote::NewL(); |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CUpnpSecurityManagerSession::ServiceL |
|
91 // Handle client requests. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CUpnpSecurityManagerSession::ServiceL( const RMessage2& aMessage ) |
|
95 { |
|
96 switch ( aMessage.Function() ) |
|
97 { |
|
98 case EAddFile: |
|
99 { |
|
100 EventAddFileL( aMessage ); |
|
101 aMessage.Complete( KErrNone ); |
|
102 break; |
|
103 } |
|
104 case ERemoveFile: |
|
105 { |
|
106 EventRemoveFileL( aMessage ); |
|
107 aMessage.Complete( KErrNone ); |
|
108 break; |
|
109 } |
|
110 case EAddAddress: |
|
111 { |
|
112 EventAddAddressL( aMessage ); |
|
113 aMessage.Complete( KErrNone ); |
|
114 break; |
|
115 } |
|
116 case ERemoveAddress: |
|
117 { |
|
118 EventRemoveAddressL( aMessage ); |
|
119 aMessage.Complete( KErrNone ); |
|
120 break; |
|
121 } |
|
122 case EResetFileList: |
|
123 { |
|
124 EventResetFileListL( aMessage ); |
|
125 aMessage.Complete( KErrNone ); |
|
126 break; |
|
127 } |
|
128 case EResetAddressList: |
|
129 { |
|
130 EventResetAddressListL( aMessage ); |
|
131 aMessage.Complete( KErrNone ); |
|
132 break; |
|
133 } |
|
134 case ECheckAuthorization: |
|
135 { |
|
136 EventCheckAuthorizationL( aMessage ); |
|
137 aMessage.Complete( KErrNone ); |
|
138 break; |
|
139 } |
|
140 case EQueryAuthorisation: |
|
141 { |
|
142 EventQueryAuthorisationL( aMessage ); |
|
143 //won't complete message as we have to wait for user response |
|
144 break; |
|
145 } |
|
146 default: |
|
147 PanicClient( aMessage, CUpnpSymbianServerBase::EBadRequest ); |
|
148 break; |
|
149 } |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CUpnpSecurityManagerSession::PanicClient |
|
154 // Panic client. |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 void CUpnpSecurityManagerSession::PanicClient( const RMessage2& aMessage, |
|
158 TInt aPanic ) const |
|
159 { |
|
160 static_cast<const CUpnpSymbianServerBase*> ( Server() )->PanicClient( |
|
161 aMessage, aPanic ); |
|
162 } |
|
163 |
|
164 // ----------------------------------------------------------------------------- |
|
165 // CUpnpSecurityManagerSession::EventAddFileL |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CUpnpSecurityManagerSession::EventAddFileL( const RMessage2& aMessage ) |
|
169 { |
|
170 TInt length = aMessage.GetDesLength( 0 ); |
|
171 RBuf fileName; |
|
172 fileName.CreateL( length ); |
|
173 CleanupClosePushL( fileName ); |
|
174 aMessage.ReadL( 0, fileName ); |
|
175 |
|
176 iEngine.AddNewFileL( fileName ); |
|
177 |
|
178 CleanupStack::PopAndDestroy( &fileName ); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CUpnpSecurityManagerSession::EventRemoveFileL |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 void CUpnpSecurityManagerSession::EventRemoveFileL( const RMessage2& aMessage ) |
|
186 { |
|
187 TInt length = aMessage.GetDesLength( 0 ); |
|
188 RBuf fileName; |
|
189 fileName.CreateL( length ); |
|
190 CleanupClosePushL( fileName ); |
|
191 aMessage.ReadL( 0, fileName ); |
|
192 |
|
193 iEngine.RemoveFileL( fileName ); |
|
194 |
|
195 CleanupStack::PopAndDestroy( &fileName ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CUpnpSecurityManagerSession::EventAddAddressL |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 void CUpnpSecurityManagerSession::EventAddAddressL( const RMessage2& aMessage ) |
|
203 { |
|
204 TInetAddr addr; |
|
205 TPtr8 ptr( reinterpret_cast<TUint8*> ( &addr ), sizeof(addr), |
|
206 sizeof(addr) ); |
|
207 aMessage.ReadL( 0, ptr ); |
|
208 |
|
209 iEngine.AddNewAddressL( addr ); |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CUpnpSecurityManagerSession::EventRemoveAddressL |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CUpnpSecurityManagerSession::EventRemoveAddressL( |
|
217 const RMessage2& aMessage ) |
|
218 { |
|
219 TInetAddr addr; |
|
220 TPtr8 ptr( reinterpret_cast<TUint8*> ( &addr ), sizeof(addr), |
|
221 sizeof(addr) ); |
|
222 aMessage.ReadL( 0, ptr ); |
|
223 |
|
224 iEngine.RemoveAddressL( addr ); |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CUpnpSecurityManagerSession::EventResetFileListL |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void CUpnpSecurityManagerSession::EventResetFileListL( const RMessage2& /*aMessage*/) |
|
232 { |
|
233 iEngine.ResetFileListL(); |
|
234 } |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CUpnpSecurityManagerSession::EventResetAddressListL |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CUpnpSecurityManagerSession::EventResetAddressListL( const RMessage2& /*aMessage*/) |
|
241 { |
|
242 iEngine.ResetAddressListL(); |
|
243 } |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CUpnpSecurityManagerSession::EventCheckAuthorizationL |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 void CUpnpSecurityManagerSession::EventCheckAuthorizationL( |
|
250 const RMessage2& aMessage ) |
|
251 { |
|
252 TInetAddr addr; |
|
253 TPtr8 ptr( reinterpret_cast<TUint8*> ( &addr ), sizeof(addr), |
|
254 sizeof(addr) ); |
|
255 aMessage.ReadL( 0, ptr ); |
|
256 |
|
257 TInt length = aMessage.GetDesLength( 1 ); |
|
258 RBuf fileName; |
|
259 fileName.CreateL( length ); |
|
260 CleanupClosePushL( fileName ); |
|
261 aMessage.ReadL( 1, fileName ); |
|
262 |
|
263 TAccessType at = iEngine.CheckAuthorization( addr, fileName ); |
|
264 |
|
265 TPckg<TAccessType> atPtr( at ); |
|
266 aMessage.WriteL( 2, atPtr ); |
|
267 |
|
268 CleanupStack::PopAndDestroy( &fileName ); |
|
269 } |
|
270 |
|
271 // ----------------------------------------------------------------------------- |
|
272 // CUpnpSecurityManagerSession::EventQueryAuthorisationL |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CUpnpSecurityManagerSession::EventQueryAuthorisationL( |
|
276 const RMessage2& aMessage ) |
|
277 { |
|
278 iAuthorizationNote->ShowNoteL( this ); |
|
279 iQueryAuthMessage = aMessage; //copy message as we can't complete it now |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // CUpnpSecurityManagerEngine::NoteResponseL |
|
284 // Callback from CUpnpAuthorizationNote. |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 void CUpnpSecurityManagerSession::NoteResponseL( TBool aAuthorized ) |
|
288 { |
|
289 TInetAddr addr; |
|
290 TPtr8 ptr( reinterpret_cast<TUint8*> ( &addr ), sizeof(addr), |
|
291 sizeof(addr) ); |
|
292 iQueryAuthMessage.ReadL( 0, ptr ); |
|
293 |
|
294 TAccessType noteResult; |
|
295 if ( aAuthorized ) |
|
296 { |
|
297 noteResult = EAddressAllowed; |
|
298 iEngine.AddNewAddressL( addr ); |
|
299 } |
|
300 else |
|
301 { |
|
302 noteResult = ENoneAllowed; |
|
303 } |
|
304 TPckg<TAccessType> resPtr( noteResult ); |
|
305 iQueryAuthMessage.WriteL( 1, resPtr ); |
|
306 iQueryAuthMessage.Complete( KErrNone ); |
|
307 } |
|
308 |
|
309 // End of File |