|
1 /* |
|
2 * Copyright (c) 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: AO for file sharing operations |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 // INCLUDE FILES |
|
24 // upnp stack api |
|
25 #include <upnpfilesharing.h> |
|
26 #include <upnpitem.h> |
|
27 |
|
28 // upnpframework / avcontroller helper api |
|
29 #include "upnpconstantdefs.h" // for upnp-specific stuff |
|
30 #include "upnpitemutility.h" // for GetResElements |
|
31 |
|
32 // upnpframework / internal api's |
|
33 #include "upnpsecaccesscontroller.h" |
|
34 |
|
35 // avcontroller internal |
|
36 #include "upnpfilesharingactive.h" |
|
37 |
|
38 _LIT( KComponentLogfile, "upnpavcontrollerserver.txt"); |
|
39 #include "upnplog.h" |
|
40 |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 // -------------------------------------------------------------------------- |
|
45 // CUPnPFileSharingActive::NewL |
|
46 // See upnpfilesharingactive.h |
|
47 // -------------------------------------------------------------------------- |
|
48 CUPnPFileSharingActive* CUPnPFileSharingActive::NewL() |
|
49 { |
|
50 CUPnPFileSharingActive* self = new (ELeave) CUPnPFileSharingActive(); |
|
51 CleanupStack::PushL( self ); |
|
52 self->ConstructL(); |
|
53 CleanupStack::Pop( self ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // -------------------------------------------------------------------------- |
|
58 // CUPnPFileSharingActive::CUPnPFileSharingActive |
|
59 // See upnpfilesharingactive.h |
|
60 // -------------------------------------------------------------------------- |
|
61 CUPnPFileSharingActive::CUPnPFileSharingActive(): |
|
62 CActive( EPriorityStandard )//, |
|
63 { |
|
64 CActiveScheduler::Add( this ); |
|
65 } |
|
66 |
|
67 // -------------------------------------------------------------------------- |
|
68 // CUPnPFileSharingActive::~CUPnPFileSharingActive |
|
69 // See upnpfilesharingactive.h |
|
70 // -------------------------------------------------------------------------- |
|
71 CUPnPFileSharingActive::~CUPnPFileSharingActive() |
|
72 { |
|
73 Cancel(); |
|
74 delete iFileSharing; |
|
75 } |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CUPnPFileSharingActive::ConstructL |
|
79 // See upnpfilesharingactive.h |
|
80 // -------------------------------------------------------------------------- |
|
81 void CUPnPFileSharingActive::ConstructL() |
|
82 { |
|
83 __LOG( "CUPnPFileSharingActive::ConstructL" ); |
|
84 |
|
85 iFileSharing = CUpnpFileSharing::NewL(); |
|
86 } |
|
87 |
|
88 // -------------------------------------------------------------------------- |
|
89 // CUPnPFileSharingActive::RunL |
|
90 // See upnpfilesharingactive.h |
|
91 // -------------------------------------------------------------------------- |
|
92 void CUPnPFileSharingActive::RunL() |
|
93 { |
|
94 CActiveScheduler::Stop(); |
|
95 } |
|
96 |
|
97 // -------------------------------------------------------------------------- |
|
98 // CUPnPFileSharingActive::DoCancel |
|
99 // See upnpfilesharingactive.h |
|
100 // -------------------------------------------------------------------------- |
|
101 void CUPnPFileSharingActive::DoCancel() |
|
102 { |
|
103 __LOG( "CUPnPFileSharingActive::DoCancel" ); |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // CUPnPFileSharingActive::RunError |
|
108 // See upnpfilesharingactive.h |
|
109 // -------------------------------------------------------------------------- |
|
110 TInt CUPnPFileSharingActive::RunError( TInt /*aError*/ ) |
|
111 { |
|
112 |
|
113 return KErrNone; |
|
114 } |
|
115 |
|
116 // -------------------------------------------------------------------------- |
|
117 // CUPnPFileSharingActive::ShareItemL |
|
118 // See upnpfilesharingactive.h |
|
119 // -------------------------------------------------------------------------- |
|
120 void CUPnPFileSharingActive::ShareItemL( CUpnpItem& aItem ) |
|
121 { |
|
122 __LOG( "CUPnPFileSharingActive::ShareItemL" ); |
|
123 |
|
124 TInt status = KErrNone; |
|
125 |
|
126 // Allow access to the files listed in res-elements |
|
127 SetAccesstoItemResourcesL( aItem, ETrue ); |
|
128 |
|
129 // Share the item |
|
130 TRAP( status, |
|
131 iFileSharing->ShareItemL( KContainerIdRoot, aItem, iStatus ) ); |
|
132 if( status == KErrNone ) |
|
133 { |
|
134 SetActive(); |
|
135 CActiveScheduler::Start(); |
|
136 status = iStatus.Int(); |
|
137 } |
|
138 |
|
139 // If the sharing failed |
|
140 if( status != KErrNone ) |
|
141 { |
|
142 // Deny access to the files listed in res-elements |
|
143 SetAccesstoItemResourcesL( aItem, EFalse ); |
|
144 } |
|
145 |
|
146 // Leave if the was an error |
|
147 if( status != KErrNone ) |
|
148 { |
|
149 User::Leave( status ); |
|
150 } |
|
151 |
|
152 __LOG( "CUPnPFileSharingActive::ShareItemL - end" ); |
|
153 } |
|
154 |
|
155 // -------------------------------------------------------------------------- |
|
156 // CUPnPFileSharingActive::UnShareItemL |
|
157 // See upnpfilesharingactive.h |
|
158 // -------------------------------------------------------------------------- |
|
159 void CUPnPFileSharingActive::UnShareItemL( const TDesC8& aId ) |
|
160 { |
|
161 __LOG( "CUPnPFileSharingActive::ConstructL" ); |
|
162 |
|
163 TLex8 lex( aId ); |
|
164 TInt id; |
|
165 User::LeaveIfError( lex.Val( id ) ); |
|
166 TInt status = KErrNone; |
|
167 |
|
168 // Get the shared items data via Metadata API |
|
169 CUpnpItem* item = CUpnpItem::NewL(); |
|
170 CleanupStack::PushL( item ); |
|
171 iFileSharing->GetSharedItemL( id, *item, iStatus ); |
|
172 SetActive(); |
|
173 CActiveScheduler::Start(); |
|
174 status = iStatus.Int(); |
|
175 |
|
176 // If the item's metadata was resolved succesfully |
|
177 if( status == KErrNone ) |
|
178 { |
|
179 // Unshare the item |
|
180 TRAP( status, iFileSharing->UnshareItemL( id, iStatus ) ); |
|
181 if( status == KErrNone ) |
|
182 { |
|
183 SetActive(); |
|
184 CActiveScheduler::Start(); |
|
185 status = iStatus.Int(); |
|
186 } |
|
187 } |
|
188 |
|
189 // If the unsharing succeeded |
|
190 if( status == KErrNone ) |
|
191 { |
|
192 // Deny access to the files listed in res-elements |
|
193 SetAccesstoItemResourcesL( *item, EFalse ); |
|
194 } |
|
195 |
|
196 // Clean up |
|
197 CleanupStack::PopAndDestroy( item ); |
|
198 item = NULL; |
|
199 |
|
200 // Leave if error |
|
201 if( status != KErrNone ) |
|
202 { |
|
203 User::LeaveIfError( status ); |
|
204 } |
|
205 |
|
206 __LOG( "CUPnPFileSharingActive::UnShareItemL - end" ); |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CUPnPFileSharingActive::SetAccesstoItemResourcesL |
|
211 // See upnpfilesharingactive.h |
|
212 // -------------------------------------------------------------------------- |
|
213 void CUPnPFileSharingActive::SetAccesstoItemResourcesL( |
|
214 CUpnpItem& aItem, |
|
215 TBool aAccessAllowed ) |
|
216 { |
|
217 __LOG( "CUPnPFileSharingActive::SetAccesstoItemResourcesL" ); |
|
218 |
|
219 // Create security access controller |
|
220 CUpnpSecAccessController* accessController = |
|
221 CUpnpSecAccessController::NewL(); |
|
222 CleanupStack::PushL( accessController ); |
|
223 |
|
224 // Get all filenames and set the access for those. |
|
225 RUPnPElementsArray resElements; |
|
226 UPnPItemUtility::GetResElements( aItem, resElements ); |
|
227 for( TInt i=0; i<resElements.Count(); i++ ) |
|
228 { |
|
229 if( aAccessAllowed ) |
|
230 { |
|
231 accessController->AddAllowedFile( resElements[i]->FilePath() ); |
|
232 } |
|
233 else |
|
234 { |
|
235 accessController->RemoveAllowedFile( |
|
236 resElements[i]->FilePath() ); |
|
237 } |
|
238 } |
|
239 |
|
240 // Clean up |
|
241 resElements.Close(); |
|
242 CleanupStack::PopAndDestroy( accessController ); |
|
243 accessController = NULL; |
|
244 } |
|
245 |
|
246 // End of file |