|
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: CNcdRequestBase declaration |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdrequestbase.h" |
|
20 #include "ncdrequestconfigurationdata.h" |
|
21 #include "ncdprotocolwords.h" |
|
22 #include "ncdprotocolutils.h" |
|
23 #include "ncd_cp_detail.h" |
|
24 #include "ncd_cp_cookie.h" |
|
25 #include "ncd_cp_queryresponse.h" |
|
26 #include "ncdqueryitem.h" |
|
27 #include "catalogsdebug.h" |
|
28 |
|
29 |
|
30 CNcdRequestBase* CNcdRequestBase::NewL() |
|
31 { |
|
32 CNcdRequestBase* self = |
|
33 CNcdRequestBase::NewLC(); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 CNcdRequestBase* CNcdRequestBase::NewLC() |
|
39 { |
|
40 CNcdRequestBase* self = new (ELeave) CNcdRequestBase(); |
|
41 CleanupStack::PushL(self); |
|
42 self->ConstructL( KTagPreminetRequest ); |
|
43 return self; |
|
44 } |
|
45 |
|
46 void CNcdRequestBase::ConstructL( const TDesC8& aRootName ) |
|
47 { |
|
48 DLTRACEIN(( "aRootName=%S", &aRootName )); |
|
49 iRootName = aRootName.AllocL(); |
|
50 |
|
51 iPrefix = TXmlEngString(); |
|
52 iId = TXmlEngString(); |
|
53 iNamespace = TXmlEngString(); |
|
54 iVersion = TXmlEngString(); |
|
55 iSession = TXmlEngString(); |
|
56 |
|
57 #ifdef RD_XML_ENGINE_API_CHANGE |
|
58 iDomImplementation.OpenL(); |
|
59 #endif |
|
60 InitializeDocumentL(); |
|
61 DLTRACEOUT(("")); |
|
62 } |
|
63 |
|
64 CNcdRequestBase::CNcdRequestBase() |
|
65 { |
|
66 } |
|
67 |
|
68 CNcdRequestBase::~CNcdRequestBase() |
|
69 { |
|
70 DLTRACEIN(("")); |
|
71 delete iConfiguration; |
|
72 |
|
73 iCookies.ResetAndDestroy(); |
|
74 iQueryResponses.ResetAndDestroy(); |
|
75 |
|
76 iDocument.Close(); // NOTE: leaks memory (S60 3.2 wk38 emulator) |
|
77 #ifdef RD_XML_ENGINE_API_CHANGE |
|
78 iDomImplementation.Close(); |
|
79 #endif |
|
80 |
|
81 iId.Free(); |
|
82 iVersion.Free(); |
|
83 iSession.Free(); |
|
84 iNamespace.Free(); |
|
85 iPrefix.Free(); |
|
86 |
|
87 delete iRootName; |
|
88 DLTRACEOUT(("")); |
|
89 } |
|
90 |
|
91 HBufC8* CNcdRequestBase::ExternalizeL() |
|
92 { |
|
93 DLTRACEIN(("")); |
|
94 |
|
95 const TXmlEngSerializationOptions KSerializationOptions = |
|
96 TXmlEngSerializationOptions( 0x09, KSerializationOptionUtf8 ); |
|
97 |
|
98 #ifndef RD_XML_ENGINE_API_CHANGE |
|
99 TXmlEngString str; |
|
100 iDocument.SaveL(str, iRoot, KSerializationOptions); |
|
101 |
|
102 str.PushL(); |
|
103 |
|
104 HBufC8* buf = HBufC8::NewL( str.Size() ); |
|
105 *buf = str.PtrC8(); |
|
106 |
|
107 // Free the original C-string |
|
108 CleanupStack::PopAndDestroy(); |
|
109 #else |
|
110 |
|
111 RBuf8 rbuf; |
|
112 iDocument.SaveL( rbuf, iRoot, KSerializationOptions ); |
|
113 |
|
114 CleanupClosePushL( rbuf ); |
|
115 HBufC8* buf = rbuf.AllocL(); |
|
116 CleanupStack::PopAndDestroy(); // rbuf |
|
117 |
|
118 #endif |
|
119 |
|
120 DLTRACEOUT(("")); |
|
121 return buf; |
|
122 } |
|
123 |
|
124 HBufC8* CNcdRequestBase::CreateRequestL() |
|
125 { |
|
126 DLTRACEIN(("")); |
|
127 // check required attributes |
|
128 if (iNamespace.IsNull() || iVersion.IsNull()) |
|
129 { |
|
130 DLERROR(("not creating request")); |
|
131 DASSERT( 0 ); |
|
132 // do not create request if required attributes are not set |
|
133 DLTRACEOUT(( "NULL" )); |
|
134 return NULL; |
|
135 } |
|
136 |
|
137 // namespace, required |
|
138 NcdProtocolUtils::NewAttributeL( iRoot, KAttrNamespace, iNamespace); |
|
139 |
|
140 // id, optional |
|
141 if (iId.NotNull()) |
|
142 { |
|
143 NcdProtocolUtils::NewAttributeL( iRoot, KAttrId, iId ); |
|
144 } |
|
145 |
|
146 // version, required |
|
147 NcdProtocolUtils::NewAttributeL( iRoot, KAttrVersion, iVersion); |
|
148 |
|
149 // session, optional |
|
150 if (iSession.NotNull()) |
|
151 { |
|
152 NcdProtocolUtils::NewAttributeL( iRoot, KAttrSession, iSession); |
|
153 } |
|
154 |
|
155 // configuration, optional |
|
156 if (iConfiguration) |
|
157 { |
|
158 TXmlEngElement configuration = |
|
159 iConfiguration->GetConfigurationElementL(iDocument); |
|
160 if (configuration.NotNull()) |
|
161 iRoot.AppendChildL(configuration); |
|
162 |
|
163 TXmlEngElement cookies = |
|
164 iConfiguration->GetCookiesElementL(iDocument); |
|
165 if (cookies.NotNull()) |
|
166 iRoot.AppendChildL(cookies); |
|
167 |
|
168 TXmlEngElement queryResponse = |
|
169 iConfiguration->GetQueryResponseElementL(iDocument); |
|
170 if (queryResponse.NotNull()) |
|
171 iRoot.AppendChildL(queryResponse); |
|
172 } |
|
173 |
|
174 // cookies, optional |
|
175 TXmlEngElement cookies = GetCookiesElementL(KCdpNamespacePrefix); |
|
176 if ( cookies.NotNull() ) |
|
177 { |
|
178 iRoot.AppendChildL(cookies); |
|
179 } |
|
180 |
|
181 TXmlEngElement queryResponses = GetQueryResponsesElementL(KCdpNamespacePrefix); |
|
182 if ( queryResponses.NotNull() ) |
|
183 { |
|
184 iRoot.AppendChildL(queryResponses); |
|
185 } |
|
186 |
|
187 // add element generated in the inheriting class, one of the following: |
|
188 // browse / search / manageSubscriptions / purchase / |
|
189 // installationReport / diffQuery |
|
190 iRoot.AppendChildL(iRequestElement); |
|
191 |
|
192 |
|
193 HBufC8* result = ExternalizeL(); |
|
194 |
|
195 DLTRACEOUT(("")); |
|
196 return result; |
|
197 } |
|
198 |
|
199 void CNcdRequestBase::InitializeDocumentL() |
|
200 { |
|
201 DLTRACEIN(("")); |
|
202 if (iDocument.NotNull()) |
|
203 { |
|
204 iDocument.Close(); // ! this leaks! |
|
205 } |
|
206 |
|
207 #ifndef RD_XML_ENGINE_API_CHANGE |
|
208 iDocument = RXmlEngDocument::NewL(); |
|
209 #else |
|
210 iDocument.OpenL( iDomImplementation ); |
|
211 #endif |
|
212 iRoot = iDocument.CreateDocumentElementL(*iRootName); |
|
213 |
|
214 #ifndef RD_XML_ENGINE_API_CHANGE |
|
215 TXmlEngString defNs; |
|
216 NcdProtocolUtils::DesToStringL(defNs, KDefaultNamespaceUri); |
|
217 iRoot.SetDefaultNamespaceL( defNs ); |
|
218 defNs.Free(); |
|
219 |
|
220 TXmlEngString cdpNs; |
|
221 NcdProtocolUtils::DesToStringL(cdpNs, KCdpNamespaceUri); |
|
222 TXmlEngString cdpNsPrefix; |
|
223 NcdProtocolUtils::DesToStringL(cdpNsPrefix, KCdpNamespacePrefix); |
|
224 iCdpNamespace = iRoot.AddNamespaceDeclarationL( cdpNs, cdpNsPrefix ); |
|
225 cdpNs.Free(); |
|
226 cdpNsPrefix.Free(); |
|
227 |
|
228 TXmlEngString xsNs; |
|
229 NcdProtocolUtils::DesToStringL(xsNs, KXsNamespaceUri); |
|
230 TXmlEngString xsNsPrefix; |
|
231 NcdProtocolUtils::DesToStringL(xsNsPrefix, KXsNamespacePrefix); |
|
232 iXsNamespace = iRoot.AddNamespaceDeclarationL(xsNs, xsNsPrefix); |
|
233 xsNs.Free(); |
|
234 xsNsPrefix.Free(); |
|
235 |
|
236 TXmlEngString xsiNs; |
|
237 NcdProtocolUtils::DesToStringL(xsiNs, KXsiNamespaceUri); |
|
238 TXmlEngString xsiNsPrefix; |
|
239 NcdProtocolUtils::DesToStringL(xsiNsPrefix, KXsiNamespacePrefix); |
|
240 iXsiNamespace = iRoot.AddNamespaceDeclarationL(xsiNs, xsiNsPrefix); |
|
241 xsiNs.Free(); |
|
242 xsiNsPrefix.Free(); |
|
243 |
|
244 #else |
|
245 iRoot.SetDefaultNamespaceL( KDefaultNamespaceUri ); |
|
246 iCdpNamespace = iRoot.AddNamespaceDeclarationL( KCdpNamespaceUri, KCdpNamespacePrefix ); |
|
247 iXsNamespace = iRoot.AddNamespaceDeclarationL( KXsNamespaceUri, KXsNamespacePrefix ); |
|
248 iXsiNamespace = iRoot.AddNamespaceDeclarationL( KXsiNamespaceUri, KXsiNamespacePrefix ); |
|
249 #endif |
|
250 |
|
251 DLTRACEOUT(("")); |
|
252 } |
|
253 |
|
254 CNcdRequestConfigurationData* CNcdRequestBase::Configuration() |
|
255 { |
|
256 return iConfiguration; |
|
257 } |
|
258 |
|
259 void CNcdRequestBase::SetConfigurationL( |
|
260 CNcdRequestConfigurationData* aConfiguration) |
|
261 { |
|
262 DLTRACEIN(("")); |
|
263 delete iConfiguration; |
|
264 iConfiguration = aConfiguration; |
|
265 } |
|
266 |
|
267 void CNcdRequestBase::SetRequestIdL(TInt aId) |
|
268 { |
|
269 TBuf<32> buf; |
|
270 buf.AppendNum(aId); |
|
271 TXmlEngString id; |
|
272 id.SetL(buf); |
|
273 iId = id; |
|
274 } |
|
275 |
|
276 void CNcdRequestBase::SetProtocolVersionL(const TDesC8& aVersion) |
|
277 { |
|
278 iVersion.SetL(aVersion); |
|
279 } |
|
280 |
|
281 void CNcdRequestBase::SetSessionL(const TDesC& aSession) |
|
282 { |
|
283 iSession.SetL(aSession); |
|
284 } |
|
285 |
|
286 void CNcdRequestBase::SetNamespaceL( const TDesC& aNamespace) |
|
287 { |
|
288 iNamespace.SetL(aNamespace); |
|
289 } |
|
290 |
|
291 HBufC* CNcdRequestBase::IdLC() const |
|
292 { |
|
293 return iId.AllocLC(); |
|
294 } |
|
295 |
|
296 HBufC* CNcdRequestBase::SessionLC() const |
|
297 { |
|
298 return iSession.AllocLC();; |
|
299 } |
|
300 |
|
301 HBufC* CNcdRequestBase::NamespaceLC() const |
|
302 { |
|
303 return iNamespace.AllocLC(); |
|
304 } |
|
305 |
|
306 void CNcdRequestBase::AddQueryResponseL(MNcdConfigurationProtocolQueryResponse* aResponse) |
|
307 { |
|
308 iQueryResponses.AppendL(aResponse); |
|
309 } |
|
310 |
|
311 void CNcdRequestBase::AddCookieL(MNcdConfigurationProtocolCookie* aCookie) |
|
312 { |
|
313 iCookies.AppendL(aCookie); |
|
314 } |
|
315 |
|
316 TXmlEngElement CNcdRequestBase::GetCookiesElementL( const TDesC8& aPrefix ) |
|
317 { |
|
318 TXmlEngElement cookies; |
|
319 |
|
320 if ( iCookies.Count() > 0 ) |
|
321 { |
|
322 cookies = NcdProtocolUtils::NewElementL( iDocument, iRoot, KTagCookies ); |
|
323 for ( TInt i = 0; i < iCookies.Count(); ++i ) |
|
324 { |
|
325 MNcdConfigurationProtocolCookie* cook = iCookies[i]; |
|
326 TXmlEngElement cookie = |
|
327 NcdProtocolUtils::NewElementL( iDocument, cookies, KTagCookie ); |
|
328 NcdProtocolUtils::NewAttributeL( cookie, KAttrKey, cook->Key() ); |
|
329 for ( TInt j = 0; j < cook->ValueCount(); ++j ) |
|
330 { |
|
331 TXmlEngElement value = |
|
332 NcdProtocolUtils::NewElementL( iDocument, cookie, KTagValue, aPrefix ); |
|
333 #ifndef RD_XML_ENGINE_API_CHANGE |
|
334 value.SetTextL( cook->Value(j) ); |
|
335 #else |
|
336 HBufC8* tempBuf = NcdProtocolUtils::ConvertUnicodeToUtf8L( cook->Value(j) ); |
|
337 CleanupStack::PushL( tempBuf ); |
|
338 value.SetTextL( *tempBuf ); |
|
339 CleanupStack::PopAndDestroy( tempBuf ); |
|
340 #endif |
|
341 } |
|
342 } |
|
343 } |
|
344 return cookies; |
|
345 } |
|
346 |
|
347 TXmlEngElement CNcdRequestBase::GetQueryResponsesElementL( const TDesC8& aPrefix ) |
|
348 { |
|
349 TXmlEngElement queryResponse; |
|
350 // queryResponses, optional |
|
351 if ( iQueryResponses.Count() > 0 ) |
|
352 { |
|
353 for (TInt i = 0; i < iQueryResponses.Count(); ++i) |
|
354 { |
|
355 MNcdConfigurationProtocolQueryResponse* resp = iQueryResponses[i]; |
|
356 queryResponse = NcdProtocolUtils::NewElementL(iDocument, iRoot, KTagQueryResponse); |
|
357 if ( resp->Id() != KNullDesC ) |
|
358 NcdProtocolUtils::NewAttributeL(queryResponse, KAttrId, resp->Id()); |
|
359 if ( resp->Semantics() != MNcdQueryItem::ESemanticsNone ) |
|
360 NcdProtocolUtils::NewAttributeL(queryResponse, KAttrSemantics, resp->Semantics()); |
|
361 if ( resp->Cancel() ) |
|
362 NcdProtocolUtils::NewBoolAttributeL(queryResponse, KAttrCancel, resp->Cancel()); |
|
363 |
|
364 for (TInt j = 0; j < resp->ResponseCount(); ++j) |
|
365 { |
|
366 const MNcdConfigurationProtocolQueryResponseValue& val = resp->ResponseL(j); |
|
367 TXmlEngElement response = NcdProtocolUtils::NewElementL( |
|
368 iDocument, queryResponse, KTagResponse, aPrefix); |
|
369 NcdProtocolUtils::NewAttributeL(response, KAttrId, val.Id()); |
|
370 NcdProtocolUtils::NewAttributeL(response, KAttrSemantics, val.Semantics()); |
|
371 for (TInt k = 0; k < val.ValueCount(); ++k) |
|
372 { |
|
373 TXmlEngElement value = NcdProtocolUtils::NewElementL( |
|
374 iDocument, response, KTagValue, aPrefix); |
|
375 #ifndef RD_XML_ENGINE_API_CHANGE |
|
376 value.SetTextL( val.ValueL(k) ); |
|
377 #else |
|
378 HBufC8* tempBuf = NcdProtocolUtils::ConvertUnicodeToUtf8L( val.ValueL(k) ); |
|
379 CleanupStack::PushL( tempBuf ); |
|
380 value.SetTextL( *tempBuf ); |
|
381 CleanupStack::PopAndDestroy( tempBuf ); |
|
382 #endif |
|
383 } |
|
384 } |
|
385 } |
|
386 } |
|
387 return queryResponse; |
|
388 } |
|
389 |
|
390 |
|
391 TXmlEngElement CNcdRequestBase::GetDetailsElementL( const TDesC8& /*aPrefix*/ ) |
|
392 { |
|
393 DLTRACEIN(("")); |
|
394 return TXmlEngElement(); |
|
395 } |