1 /* |
|
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: For checking a PAOS XML document |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef PNP_PAOS_XML_H |
|
21 #define PNP_PAOS_XML_H |
|
22 |
|
23 #include <e32std.h> |
|
24 #include <sysutil.h> |
|
25 #include <xml/parser.h> // for XML parser |
|
26 #include <xml/contenthandler.h> // for MContentHandler |
|
27 #include <http/mhttpdatasupplier.h> |
|
28 #include <PnpUtilImpl.h> |
|
29 |
|
30 |
|
31 using namespace Xml; |
|
32 |
|
33 class CPnpUtil; |
|
34 |
|
35 |
|
36 /** |
|
37 For checking a PAOS XML document. Checks that the XML is of right format. |
|
38 Currently only a request for "SetOfKeys" is allowed. |
|
39 */ |
|
40 |
|
41 class CPnpPaosXml : |
|
42 public CBase, |
|
43 public MContentHandler, |
|
44 public MHTTPDataSupplier /* to set the body of a http request*/ |
|
45 { |
|
46 public: |
|
47 /** |
|
48 Possible PAOS request states, currently only ERequestingKeys is available. |
|
49 */ |
|
50 enum TPaosStates |
|
51 { |
|
52 EPaosStatusUnknown = 0, |
|
53 EPaosStatusRequestingPnPKeys, /* Received a PAOS request for PnP-MS parameters */ |
|
54 EPaosStatusRequestingHdcKeys /* Received a PAOS request for HelpDeskConnect parameters */ |
|
55 }; |
|
56 |
|
57 static CPnpPaosXml* NewL(); |
|
58 ~CPnpPaosXml(); |
|
59 |
|
60 /** |
|
61 Construct a response to the PnP PAOS request received, |
|
62 the response is put into iPaosResponse buffer. |
|
63 */ |
|
64 void ConstructPnPPaosResponseL(); |
|
65 |
|
66 /** |
|
67 Construct a response to the HelpDeskConnect PAOS request received, |
|
68 the response is put into iPaosResponse buffer. |
|
69 */ |
|
70 void ConstructHdcPaosResponseL(); |
|
71 |
|
72 /** |
|
73 Construct a response to a PAOS request. The response is put into |
|
74 iPaosResponse buffer. |
|
75 @param aResponse The literal used in formatting the response. It is assumed |
|
76 to have %S directives to be replaced by the given parameter values. Maximum |
|
77 number of the directives is 8 as the first occurrence is always replaced by |
|
78 XML that contains PAOS message ids. |
|
79 @param aParameter1 Descriptor that replaces the second occurrence of %S directive in aResponse. |
|
80 The default value is an empty descriptor. |
|
81 @param aParameter2 Descriptor that replaces the third occurrence of %S directive in aResponse. |
|
82 The default value is an empty descriptor. |
|
83 @param aParameter3 And so on... |
|
84 */ |
|
85 void ConstructPaosResponseL( |
|
86 const TDesC8& aResponse, |
|
87 const TDesC8& aParameter1 = KNullDesC8, |
|
88 const TDesC8& aParameter2 = KNullDesC8, |
|
89 const TDesC8& aParameter3 = KNullDesC8, |
|
90 const TDesC8& aParameter4 = KNullDesC8, |
|
91 const TDesC8& aParameter5 = KNullDesC8, |
|
92 const TDesC8& aParameter6 = KNullDesC8, |
|
93 const TDesC8& aParameter7 = KNullDesC8, |
|
94 const TDesC8& aParameter8 = KNullDesC8 |
|
95 ); |
|
96 |
|
97 /** |
|
98 Goes through the PAOS request received from the server. Leaves with |
|
99 KErrArgument if the XML document was not correctly formatted. |
|
100 */ |
|
101 void ParseL( TPaosStates& aPaosRequest ); |
|
102 |
|
103 /** |
|
104 For storing the PAOS request piece by piece. |
|
105 @return ETrue if this was the last data part from MHTTPDataSupplier. |
|
106 */ |
|
107 TBool CollectResponseBodyL( MHTTPDataSupplier& aBody ); |
|
108 |
|
109 //#ifndef __SERIES60_ |
|
110 /** |
|
111 @return A pointer to a descriptor containing response body. |
|
112 */ |
|
113 // TPtrC8 ResponseBodyL(); |
|
114 //#endif |
|
115 |
|
116 /** |
|
117 Returns the parameter responseConsumerUrl of the previous PAOS request parsed. |
|
118 */ |
|
119 const TDesC8& GetPaosPostUrlL(){ return *iPaosPostUrlPath; }; |
|
120 |
|
121 /** |
|
122 Returns the parameter referenceMessageId for the constructed PAOS response message |
|
123 */ |
|
124 const TDesC8& GetReferenceMessageId(){ return *iReferenceMessageId; }; |
|
125 |
|
126 /** |
|
127 Resets the PAOS request. |
|
128 */ |
|
129 void ResetPaosRequest(); |
|
130 |
|
131 public: // from MContentHandler |
|
132 |
|
133 /** |
|
134 This method is a callback to indicate the start of the document. |
|
135 @param aDocParam Specifies the various parameters of the document. |
|
136 @arg aDocParam.iCharacterSetName The character encoding of the document. |
|
137 @param aErrorCode is the error code. |
|
138 If this is not KErrNone then special action may be required. |
|
139 */ |
|
140 void OnStartDocumentL( const RDocumentParameters& aDocParam, TInt aErrorCode ); |
|
141 |
|
142 /** |
|
143 This method is a callback to indicate the end of the document. |
|
144 @param aErrorCode is the error code. |
|
145 If this is not KErrNone then special action may be required. |
|
146 */ |
|
147 void OnEndDocumentL( TInt aErrorCode ); |
|
148 |
|
149 /** |
|
150 This method is a callback to indicate an element has been parsed. |
|
151 @param aElement is a handle to the element's details. |
|
152 @param aAttributes contains the attributes for the element. |
|
153 @param aErrorCode is the error code. |
|
154 If this is not KErrNone then special action may be required. |
|
155 */ |
|
156 void OnStartElementL( const RTagInfo& aElement, |
|
157 const RAttributeArray& aAttributes, TInt aErrorCode ); |
|
158 |
|
159 /** |
|
160 This method is a callback to indicate the end of the element has been reached. |
|
161 @param aElement is a handle to the element's details. |
|
162 @param aErrorCode is the error code. |
|
163 If this is not KErrNone then special action may be required. |
|
164 */ |
|
165 void OnEndElementL( const RTagInfo& aElement, TInt aErrorCode ); |
|
166 |
|
167 |
|
168 /** |
|
169 This method is a callback that sends the content of the element. |
|
170 Not all the content may be returned in one go. The data may be sent in chunks. |
|
171 When an OnEndElementL is received this means there is no more content to be sent. |
|
172 @param aBytes is the raw content data for the element. |
|
173 The client is responsible for converting the data to the |
|
174 required character set if necessary. |
|
175 In some instances the content may be binary and must not be converted. |
|
176 @param aErrorCode is the error code. |
|
177 If this is not KErrNone then special action may be required. |
|
178 */ |
|
179 void OnContentL( const TDesC8& aBytes, TInt aErrorCode ); |
|
180 |
|
181 |
|
182 /** |
|
183 This method is a notification of the beginning of the scope of |
|
184 a prefix-URI Namespace mapping. |
|
185 This method is always called before the corresponding OnStartElementL method. |
|
186 @param aPrefix is the Namespace prefix being declared. |
|
187 @param aUri is the Namespace URI the prefix is mapped to. |
|
188 @param aErrorCode is the error code. |
|
189 If this is not KErrNone then special action may be required. |
|
190 */ |
|
191 void OnStartPrefixMappingL( const RString& aPrefix, const RString& aUri, |
|
192 TInt aErrorCode ); |
|
193 |
|
194 /** |
|
195 This method is a notification of the end of the scope of a prefix-URI mapping. |
|
196 This method is called after the corresponding DoEndElementL method. |
|
197 @param aPrefix is the Namespace prefix that was mapped. |
|
198 @param aErrorCode is the error code. |
|
199 If this is not KErrNone then special action may be required. |
|
200 */ |
|
201 void OnEndPrefixMappingL( const RString& aPrefix, TInt aErrorCode ); |
|
202 |
|
203 /** |
|
204 This method is a notification of ignorable whitespace in element content. |
|
205 @param aBytes are the ignored bytes from the document being parsed. |
|
206 @param aErrorCode is the error code. |
|
207 If this is not KErrNone then special action may be required. |
|
208 */ |
|
209 void OnIgnorableWhiteSpaceL( const TDesC8& aBytes, TInt aErrorCode ); |
|
210 |
|
211 |
|
212 /** |
|
213 This method is a notification of a skipped entity. If the parser encounters an |
|
214 external entity it does not need to expand it - it can return the entity as aName |
|
215 for the client to deal with. |
|
216 @param aName is the name of the skipped entity. |
|
217 @param aErrorCode is the error code. |
|
218 If this is not KErrNone then special action may be required. |
|
219 */ |
|
220 void OnSkippedEntityL( const RString& aName, TInt aErrorCode ); |
|
221 |
|
222 /** |
|
223 This method is a receive notification of a processing instruction. |
|
224 @param aTarget is the processing instruction target. |
|
225 @param aData is the processing instruction data. If empty none was supplied. |
|
226 @param aErrorCode is the error code. |
|
227 If this is not KErrNone then special action may be required. |
|
228 */ |
|
229 void OnProcessingInstructionL( const TDesC8& aTarget, const TDesC8& aData, |
|
230 TInt aErrorCode ); |
|
231 |
|
232 /** |
|
233 This method indicates an error has occurred. |
|
234 @param aError is the error code |
|
235 */ |
|
236 void OnError( TInt aErrorCode ); |
|
237 |
|
238 /** |
|
239 This method obtains the interface matching the specified uid. |
|
240 @return 0 if no interface matching the uid is found. |
|
241 Otherwise, the this pointer cast to that interface. |
|
242 @param aUid the uid identifying the required interface. |
|
243 */ |
|
244 TAny* GetExtendedInterface( const TInt32 aUid ); |
|
245 |
|
246 /** |
|
247 This method is indicates there is no more data in the data supplier to parse. |
|
248 If there is more data to parse the Start method should be called once there |
|
249 is more data in the supplier to continue parsing. |
|
250 */ |
|
251 virtual void OnOutOfData(); |
|
252 |
|
253 public: // From MHTTPDataSupplier |
|
254 /** |
|
255 From MHTTPDataSupplier. |
|
256 |
|
257 Obtains a data part from the supplier. |
|
258 The data is guaranteed to survive until a call is made to ReleaseData(). |
|
259 |
|
260 @param aDataPart The data part |
|
261 @return ETrue if this is the last part, EFalse otherwise |
|
262 */ |
|
263 virtual TBool GetNextDataPart( TPtrC8& aDataPart ); |
|
264 |
|
265 /** |
|
266 From MHTTPDataSupplier. |
|
267 |
|
268 Releases the current data part being held at the data supplier. |
|
269 This call indicates to the supplier that the part is no longer needed, |
|
270 and another one can be supplied, if appropriate. |
|
271 */ |
|
272 virtual void ReleaseData(); |
|
273 |
|
274 /** |
|
275 From MHTTPDataSupplier. |
|
276 |
|
277 Obtains the overall size of the data being supplied, if known to the |
|
278 supplier. Where a body of data is supplied in several parts, this size is |
|
279 the sum of all the part sizes. If the size is not known, KErrNotFound is |
|
280 returned; in this case the caller must use the return code of |
|
281 GetNextDataPart() to find out when the data is complete. |
|
282 @return A size in bytes, or KErrNotFound if the size is not known. |
|
283 */ |
|
284 virtual TInt OverallDataSize(); |
|
285 |
|
286 /** |
|
287 From MHTTPDataSupplier. |
|
288 Resets the data supplier. |
|
289 |
|
290 This indicates to the data supplier that it should return to the first part |
|
291 of the data. This could be used in a situation where the data consumer has |
|
292 encountered an error and needs the data to be supplied afresh. Even if the |
|
293 last part has been supplied (i.e. GetNextDataPart() has returned ETrue), |
|
294 the data supplier should reset to the first part. |
|
295 |
|
296 @return If the supplier cannot reset, it should return an error code, |
|
297 otherwise it should return KErrNone, where the reset will be |
|
298 assumed to have succeeded. |
|
299 */ |
|
300 virtual TInt Reset(); |
|
301 |
|
302 private: |
|
303 CPnpPaosXml(); |
|
304 void ConstructL(); |
|
305 |
|
306 /** |
|
307 Generates a random character string. The original descriptor contents is lost. |
|
308 */ |
|
309 void GenerateNonceString( TDes8& aString ); |
|
310 |
|
311 /** |
|
312 * Fetch product model |
|
313 * @since 2.0 |
|
314 * @return void |
|
315 */ |
|
316 void FetchProductModelL( TDes8& aModel ); |
|
317 |
|
318 /** For parsing XML */ |
|
319 CParser* iParser; |
|
320 |
|
321 /** Buffer for storing a http response (PAOS request) */ |
|
322 HBufC8* iPaosRequest; |
|
323 /** Buffer for storing a http request (PAOS response) */ |
|
324 HBufC8* iPaosResponse; |
|
325 /** The path for posting PAOS response to (responseConsumerURL) */ |
|
326 HBufC8* iPaosPostUrlPath; |
|
327 /** messageID parameter PAOS spec: |
|
328 "RECOMMENDED that the value of this attribute have nonce characteristic" */ |
|
329 HBufC8* iMessageId; |
|
330 /** refToMessageID parameter; references to the messageID of the PAOS query received. |
|
331 PAOS spec: "RECOMMENDED that the value of this attribute have nonce characteristic" */ |
|
332 HBufC8* iReferenceMessageId; |
|
333 TPaosStates iPaosStatus; |
|
334 /** ETrue if there was the parameter responseConsumerURL in the xml, |
|
335 EFalse otherwise */ |
|
336 TBool iResponseConsumerUrlFound; |
|
337 /** Set to ETrue if parsing the XML caused a call to MContentHandler::OnError */ |
|
338 TBool iErrorFound; |
|
339 /** An enum value for storing the current xml element */ |
|
340 TInt iCurrentElement; |
|
341 }; |
|
342 |
|
343 #endif // PNP_PAOS_XML_H |
|