|
1 // Copyright (c) 2002-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 #ifndef __CMESSAGEPARSERDRIVER_H__ |
|
17 #define __CMESSAGEPARSERDRIVER_H__ |
|
18 |
|
19 #include <e32base.h> |
|
20 #include <rhttpmessageparser.h> |
|
21 #include <mhttpmessageparserobserver.h> |
|
22 |
|
23 #include "mdatasupplierobserver.h" |
|
24 |
|
25 class CMessageDataSupplier; |
|
26 class MDriverObserver; |
|
27 |
|
28 class CMessageParserDriver : public CActive, |
|
29 public MHttpMessageParserObserver, |
|
30 public MDataSupplierObserver |
|
31 { |
|
32 public: // methods |
|
33 |
|
34 static CMessageParserDriver* NewL(MDriverObserver& aObserver); |
|
35 |
|
36 virtual ~CMessageParserDriver(); |
|
37 |
|
38 void SetMessageData(const TDesC8& aMessageData); |
|
39 void SetStartLine(const TDesC8& aStartLine); |
|
40 void SetHeaderL(const TDesC8& aFieldName, const TDesC8& aFieldValue); |
|
41 void SetBodyData(const TDesC8& aBodyData, TBool aIsChunked, TBool aIsUnknownLength = EFalse); |
|
42 void SetTrailerL(const TDesC8& aFieldName, const TDesC8& aFieldValue); |
|
43 |
|
44 void Start(TInt aExpectedError, TBool aTestReset = EFalse); |
|
45 |
|
46 private: // methods from CActive |
|
47 |
|
48 virtual void RunL(); |
|
49 virtual void DoCancel(); |
|
50 virtual TInt RunError(TInt aError); |
|
51 |
|
52 private: // methods from MHttpMessageParserObserver |
|
53 |
|
54 virtual void GetDataPacket(TPtrC8& aData); |
|
55 virtual void ReleaseDataPacket(); |
|
56 |
|
57 virtual void StartLineL(const TDesC8& aStartLine); |
|
58 virtual void HeaderL(const TDesC8& aFieldName, TDesC8& aFieldValue); |
|
59 virtual TInt BodySizeL(); |
|
60 virtual void BodyChunkL(const TDesC8& aData); |
|
61 virtual void BodyCompleteL(); |
|
62 virtual void MessageCompleteL(const TPtrC8& aExcessData); |
|
63 |
|
64 virtual TInt HandleParserError(TInt aError); |
|
65 |
|
66 virtual void Reserved_MHttpMessageParserObserver(); |
|
67 |
|
68 private: // methods from MDataSupplierObserver |
|
69 |
|
70 virtual void DataReady(); |
|
71 |
|
72 private: // enums |
|
73 |
|
74 enum TMessageState |
|
75 { |
|
76 EPendingStartLine = 0, |
|
77 EPendingHeaders, |
|
78 EPendingBodySize, |
|
79 EPendingBody, |
|
80 EPendingBodyComplete, |
|
81 EPendingTrailers, |
|
82 EPendingMessageComplete, |
|
83 EDone |
|
84 }; |
|
85 |
|
86 enum TEntityBodyState |
|
87 { |
|
88 ENoEntityBody = 0, |
|
89 ENonEncodedBody, |
|
90 EChunkEncodedBody, |
|
91 EUnknownBodyLength |
|
92 }; |
|
93 |
|
94 private: // helper classes |
|
95 |
|
96 class THeaderField |
|
97 { |
|
98 public: // methods |
|
99 |
|
100 THeaderField() : iName(0, NULL), iValue(0, NULL) {} |
|
101 THeaderField(const TDesC8& aName, const TDesC8& aValue) : iName(aName), iValue(aValue) {}; |
|
102 |
|
103 THeaderField& operator=(const THeaderField& aField) { this->iName.Set(aField.iName); this->iValue.Set(aField.iValue); return *this; } |
|
104 |
|
105 public: // attributes |
|
106 |
|
107 TPtrC8 iName; |
|
108 TPtrC8 iValue; |
|
109 |
|
110 }; |
|
111 |
|
112 private: // methods |
|
113 |
|
114 CMessageParserDriver(MDriverObserver& aObserver); |
|
115 |
|
116 void ConstructL(); |
|
117 |
|
118 void CompleteSelf(); |
|
119 void DoReset(); |
|
120 |
|
121 private: |
|
122 |
|
123 MDriverObserver& iObserver; |
|
124 RHttpMessageParser iMessageParser; |
|
125 CMessageDataSupplier* iDataSupplier; |
|
126 TMessageState iState; |
|
127 TPtrC8 iMessageData; |
|
128 TPtrC8 iStartLine; |
|
129 TPtrC8 iEntityBody; |
|
130 TPtrC8 iExpectBodyData; |
|
131 TEntityBodyState iExpectBodyState; |
|
132 |
|
133 RArray<THeaderField> iHeaders; |
|
134 TInt iHeaderIndex; |
|
135 RArray<THeaderField> iTrailers; |
|
136 TInt iTrailerIndex; |
|
137 |
|
138 TInt iExpectedError; |
|
139 TInt iBufferSize; |
|
140 TBool iTestFailed; |
|
141 |
|
142 TInt iResetIndex; |
|
143 TInt iBodyIndex; |
|
144 TBool iDoReset; |
|
145 TBool iReset; |
|
146 TMessageState iResetState; |
|
147 |
|
148 TInt iChunkCount; |
|
149 TInt iChunkIndex; |
|
150 |
|
151 TBool iIsUnknownLength; |
|
152 }; |
|
153 |
|
154 #endif // __CMESSAGEPARSERDRIVER_H__ |