|
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 <f32file.h> |
|
17 #include <inetprottextutils.h> |
|
18 |
|
19 #include "upnpsppublishinfocontainer.h" |
|
20 #include "upnpdescriptionschema.h" |
|
21 #include "cupnpdescriptionparser.h" |
|
22 |
|
23 |
|
24 CUPnPRootDeviceInfoContainer* CUPnPRootDeviceInfoContainer::NewL ( ) |
|
25 { |
|
26 CUPnPRootDeviceInfoContainer* self = new ( ELeave ) CUPnPRootDeviceInfoContainer ( ); |
|
27 CleanupStack::PushL ( self ); |
|
28 self->ConstructL ( ); |
|
29 CleanupStack::Pop ( self ); |
|
30 return self; |
|
31 } |
|
32 |
|
33 CUPnPRootDeviceInfoContainer::CUPnPRootDeviceInfoContainer ( ) |
|
34 { |
|
35 } |
|
36 |
|
37 CUPnPRootDeviceInfoContainer::~CUPnPRootDeviceInfoContainer ( ) |
|
38 { |
|
39 iStringPoolMgr->Release( ); |
|
40 delete iRootDeviceDescription; |
|
41 } |
|
42 |
|
43 void CUPnPRootDeviceInfoContainer::ConstructL ( ) |
|
44 { |
|
45 iRootDeviceDescription = CUPnPDeviceDescription::NewL ( ); |
|
46 |
|
47 RFile fileHandle; |
|
48 RFs fs; |
|
49 User::LeaveIfError ( fs.Connect ( ) ); |
|
50 CleanupClosePushL ( fs ); |
|
51 |
|
52 TInt err = fileHandle.Open ( fs, _L("z:\\private\\101F7989\\upnp\\device.xml"), EFileShareReadersOnly ); |
|
53 // ..remove Hard coded |
|
54 User::LeaveIfError ( err ); |
|
55 CleanupClosePushL ( fileHandle ); |
|
56 |
|
57 iStringPoolMgr = CStringPoolManager::NewL ( ); |
|
58 const RStringPool& stringPool = iStringPoolMgr->StringPool(); |
|
59 |
|
60 CUPnPDescriptionParser* parser = CUPnPDescriptionParser::NewL (stringPool, CUPnPDescriptionParser::EDevice); |
|
61 CleanupStack::PushL ( parser ); |
|
62 |
|
63 TInt fileSize = 0; |
|
64 fileHandle.Size ( fileSize ); |
|
65 |
|
66 HBufC8* buf = HBufC8::NewLC ( fileSize ); |
|
67 TPtr8 ptr = buf->Des( ); |
|
68 |
|
69 User::LeaveIfError ( fileHandle.Read ( ptr, fileSize ) ); |
|
70 |
|
71 iRootDeviceDescription = static_cast<CUPnPDeviceDescription*> (parser->ParseDescriptionBufL( ptr )); |
|
72 |
|
73 CleanupStack::PopAndDestroy ( buf ); |
|
74 CleanupStack::PopAndDestroy ( parser ); |
|
75 CleanupStack::PopAndDestroy ( &fileHandle ); |
|
76 CleanupStack::PopAndDestroy ( &fs ); |
|
77 } |
|
78 |
|
79 |
|
80 CUPnPDeviceDescription& CUPnPRootDeviceInfoContainer::GetRootDeviceDesciption ( ) const |
|
81 { |
|
82 return *iRootDeviceDescription; |
|
83 } |
|
84 |
|
85 const TDesC8& CUPnPRootDeviceInfoContainer::GetRootdeviceUid() const |
|
86 { |
|
87 CUPnPDevice* device = iRootDeviceDescription->DeviceObject( ); |
|
88 RStringPool& sp = iStringPoolMgr->StringPool( ); |
|
89 |
|
90 return device->Property( sp.String ( UPNPDESCRIPTIONXMLTAGS::EUdn,iStringPoolMgr->GetUPnPTable() ) ); |
|
91 } |
|
92 |
|
93 CStringPoolManager& CUPnPRootDeviceInfoContainer::StringPoolManager ( ) const |
|
94 { |
|
95 return *iStringPoolMgr; |
|
96 } |
|
97 |
|
98 TInt CUPnPRootDeviceInfoContainer::PerformValidation ( const TDesC8& aDeviceUid, const TDesC8& aServiceType ) |
|
99 { |
|
100 RStringPool& sp = iStringPoolMgr->StringPool( ); |
|
101 |
|
102 const CUPnPDevice* device = GetDeviceByUuid ( aDeviceUid ); |
|
103 if ( device ) |
|
104 { |
|
105 // device is present now look for service type; |
|
106 const CUPnPServiceInfo* servInfo = NULL; |
|
107 for ( TInt i = 0; i < device->CountOfServiceInfoTable( ); i++ ) |
|
108 { |
|
109 servInfo = device->AtServiceInfoTable( i ); |
|
110 if ( aServiceType.Compare ( servInfo->Property( sp.String ( UPNPDESCRIPTIONXMLTAGS::EServiceType,iStringPoolMgr->GetUPnPTable()) ) ) == 0 ) |
|
111 return KErrAlreadyExists; |
|
112 } |
|
113 } |
|
114 else |
|
115 { |
|
116 return KErrNotFound; |
|
117 } |
|
118 return KErrNone; |
|
119 } |
|
120 |
|
121 void CUPnPRootDeviceInfoContainer::AppendEmbeddedDeviceL ( const TDesC8& aParentUuid, CUPnPDevice* aDevice ) |
|
122 { |
|
123 CUPnPDevice* parentDevice = GetDeviceByUuid ( aParentUuid ); |
|
124 __ASSERT_DEBUG ( parentDevice != NULL, User::Invariant ( ) ); // Device to which service has to added is Not Found |
|
125 |
|
126 parentDevice->AppendToEmbeddedDeviceInfoTableL( aDevice ); |
|
127 } |
|
128 |
|
129 void CUPnPRootDeviceInfoContainer::AppendServiceInfoL ( const TDesC8& aParentUuid, CUPnPServiceInfo* aServiceInfo ) |
|
130 { |
|
131 CUPnPDevice* device = iRootDeviceDescription->DeviceObject( ); |
|
132 TBool res = AppendServiceL ( aParentUuid, aServiceInfo, device ); |
|
133 |
|
134 __ASSERT_DEBUG ( res, User::Invariant ( ) ); // Device to which service has to added is Not Found |
|
135 } |
|
136 |
|
137 TBool CUPnPRootDeviceInfoContainer::AppendServiceL ( const TDesC8& aParentUuid, const CUPnPServiceInfo* aServiceInfo, CUPnPDevice* aDevice ) |
|
138 { |
|
139 RStringPool& sp = iStringPoolMgr->StringPool( ); |
|
140 |
|
141 const TDesC8& uuid = aDevice->Property( sp.String ( UPNPDESCRIPTIONXMLTAGS::EUdn,iStringPoolMgr->GetUPnPTable() ) ); |
|
142 if ( uuid.Compare ( aParentUuid ) == 0 ) |
|
143 { |
|
144 aDevice->AppendToServiceInfoTableL( aServiceInfo ); |
|
145 return ETrue; |
|
146 } |
|
147 else |
|
148 { |
|
149 for ( TInt i=0; i < aDevice->CountOfEmbeddedDeviceInfoTable( ); i++ ) |
|
150 { |
|
151 if ( AppendServiceL ( aParentUuid, aServiceInfo, aDevice->AtEmbeddedDeviceInfoTable( i ) ) ) |
|
152 return ETrue; |
|
153 } |
|
154 } |
|
155 |
|
156 return EFalse; |
|
157 } |
|
158 |
|
159 void CUPnPRootDeviceInfoContainer::DeleteDeviceInfoL ( const TDesC8& aUuid ) |
|
160 { |
|
161 CUPnPDevice* device = iRootDeviceDescription->DeviceObject( ); |
|
162 TBool res = DeleteDeviceL ( aUuid, device ); |
|
163 if ( res==EFalse ) |
|
164 User::Leave ( KErrNotFound ); |
|
165 } |
|
166 |
|
167 TBool CUPnPRootDeviceInfoContainer::DeleteDeviceL ( const TDesC8& aUuid, CUPnPDevice* aDevice ) |
|
168 { |
|
169 RStringPool& sp = iStringPoolMgr->StringPool( ); |
|
170 |
|
171 for ( TInt i = 0; i < aDevice->CountOfEmbeddedDeviceInfoTable( ); i++) |
|
172 { |
|
173 if ( aUuid.Compare ( aDevice->AtEmbeddedDeviceInfoTable( i )->Property( sp.String ( UPNPDESCRIPTIONXMLTAGS::EUdn, iStringPoolMgr->GetUPnPTable() ) ) ) == 0 ) |
|
174 { |
|
175 aDevice->DeleteEmbeddedDeviceInfoAtIndexL( i ); |
|
176 return ETrue; |
|
177 } |
|
178 else |
|
179 { |
|
180 if ( DeleteDeviceL ( aUuid, aDevice->AtEmbeddedDeviceInfoTable( i ) ) == 1 ) |
|
181 { |
|
182 return ETrue; |
|
183 } |
|
184 } |
|
185 } |
|
186 return EFalse; |
|
187 } |
|
188 |
|
189 void CUPnPRootDeviceInfoContainer::DeleteServiceInfoL ( const TDesC8& aScpdUrl ) |
|
190 { |
|
191 CUPnPDevice* device = iRootDeviceDescription->DeviceObject( ); |
|
192 TBool res = DeleteServiceL ( aScpdUrl, device ); |
|
193 if ( res == EFalse ) |
|
194 User::Leave ( KErrNotFound ); |
|
195 } |
|
196 |
|
197 TBool CUPnPRootDeviceInfoContainer::DeleteServiceL ( const TDesC8& aScpdUrl, CUPnPDevice* aDevice ) |
|
198 { |
|
199 RStringPool& sp = iStringPoolMgr->StringPool( ); |
|
200 const CUPnPServiceInfo* serviceInfo = NULL; |
|
201 TPtrC8 urlPtr ( NULL, 0 ); |
|
202 |
|
203 for ( TInt i = 0; i < aDevice->CountOfServiceInfoTable( ); i++ ) |
|
204 { |
|
205 serviceInfo = aDevice->AtServiceInfoTable( i ); |
|
206 urlPtr.Set ( serviceInfo->Property( sp.String ( UPNPDESCRIPTIONXMLTAGS::EScpdUrl,iStringPoolMgr->GetUPnPTable() ) ).Mid (1) ); |
|
207 |
|
208 if ( aScpdUrl.Compare ( urlPtr ) == 0 ) |
|
209 { |
|
210 aDevice->DeleteServiceInfoAtIndexL( i ); |
|
211 return ETrue; |
|
212 } |
|
213 } |
|
214 |
|
215 for ( TInt i=0; i < aDevice->CountOfEmbeddedDeviceInfoTable( ); i++ ) |
|
216 { |
|
217 if ( DeleteServiceL ( aScpdUrl, aDevice->AtEmbeddedDeviceInfoTable( i ) ) == 1 ) |
|
218 return ETrue; |
|
219 } |
|
220 |
|
221 return EFalse; |
|
222 } |
|
223 |
|
224 |
|
225 CUPnPDevice* CUPnPRootDeviceInfoContainer::GetDeviceByUuid ( const TDesC8& aDeviceUuid ) |
|
226 { |
|
227 CUPnPDevice* device = iRootDeviceDescription->DeviceObject( ); |
|
228 if ( SearchDevice ( device, aDeviceUuid ) ) |
|
229 return device; |
|
230 else |
|
231 return NULL; |
|
232 } |
|
233 |
|
234 const CUPnPDevice* CUPnPRootDeviceInfoContainer::SearchDevice ( const CUPnPDevice* aDevice, const TDesC8& aDeviceUuid ) |
|
235 { |
|
236 RStringPool& sp = iStringPoolMgr->StringPool( ); |
|
237 |
|
238 if ( aDeviceUuid.Compare ( aDevice->Property( sp.String ( UPNPDESCRIPTIONXMLTAGS::EUdn,iStringPoolMgr->GetUPnPTable() ) ) ) == 0 ) |
|
239 { |
|
240 return aDevice; |
|
241 } |
|
242 else |
|
243 { |
|
244 for ( TInt i = 0; i < aDevice->CountOfEmbeddedDeviceInfoTable( ); i++ ) |
|
245 { |
|
246 if ( SearchDevice ( aDevice->AtEmbeddedDeviceInfoTable( i ), aDeviceUuid ) != NULL ) |
|
247 { |
|
248 return aDevice->AtEmbeddedDeviceInfoTable( i ); |
|
249 } |
|
250 } |
|
251 } |
|
252 return NULL; |
|
253 } |
|
254 |