|
1 /* |
|
2 * Copyright (c) 2002 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 the License "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: |
|
15 * Implementation of class CCodEng. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include "CodEng.h" |
|
24 #include "CodData.h" |
|
25 #include "CodError.h" |
|
26 #include "CodPanic.h" |
|
27 #include "CodStatus.h" |
|
28 #include "CodParser.h" |
|
29 #include "CodLogger.h" |
|
30 #include "CodSaver.h" |
|
31 #include <DocumentHandler.h> |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 |
|
35 // --------------------------------------------------------- |
|
36 // CCodEng::NewL() |
|
37 // --------------------------------------------------------- |
|
38 // |
|
39 EXPORT_C CCodEng* CCodEng::NewL |
|
40 ( CEikProcess* aProcess, MCodLoadObserver* aObserver ) |
|
41 { |
|
42 CCodEng* model = new (ELeave) CCodEng( aObserver ); |
|
43 CleanupStack::PushL( model ); |
|
44 model->ConstructL( aProcess ); |
|
45 CleanupStack::Pop( model ); |
|
46 return model; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CCodEng::~CCodEng() |
|
51 // --------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CCodEng::~CCodEng() |
|
54 { |
|
55 CLOG(( ECodEng, 2, _L("CCodEng::~CCodEng") )); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------- |
|
59 // CCodEng::CCodEng() |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 CCodEng::CCodEng( MCodLoadObserver* aObserver ): CCodEngBase( aObserver ) |
|
63 { |
|
64 CLOG(( ECodEng, 2, _L("CCodEng::CCodEng") )); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CCodEng::CheckDataL() |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 void CCodEng::CheckDataL() |
|
72 { |
|
73 CLOG(( ECodEng, 2, _L("-> CCodEng::CheckDataL") )); |
|
74 if( !iData->IsValid() ) |
|
75 { |
|
76 // Syntactically OK, but mandatory attributes are missing. |
|
77 User::Leave( KErrCodInvalidDescriptor ); |
|
78 } |
|
79 CLOG(( ECodEng, 4, _L("CCodEng::CheckDataL: data valid") )); |
|
80 CLOG(( ECodEng, 2, _L("<- CCodEng::CheckDataL") )); |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------- |
|
84 // CCodEng::ParseDataL() |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 void CCodEng::ParseDataL() |
|
88 { |
|
89 CLOG(( ECodEng, 2, _L("-> CCodEng::ParseDataL") )); |
|
90 |
|
91 __ASSERT_DEBUG( iCodBuf, CodPanic( ECodInternal ) ); |
|
92 __ASSERT_DEBUG( iData, CodPanic( ECodInternal ) ); |
|
93 |
|
94 TCodParser parser; |
|
95 parser.ParseL( *iCodBuf, *iData ); |
|
96 CLOG(( ECodEng, 4, _L("CCodEng::SetL: parsed OK") )); |
|
97 CLOG(( ECodEng, 2, _L("<- CCodEng::ParseDataL") )); |
|
98 } |
|
99 |
|
100 // --------------------------------------------------------- |
|
101 // CCodEng::StatusCode |
|
102 // --------------------------------------------------------- |
|
103 // |
|
104 TInt CCodEng::StatusCode( TInt aError, TState aState ) const |
|
105 { |
|
106 // Meaningless to fiddle with statuses after we are done. |
|
107 __ASSERT_DEBUG( aState <= ENotify, CodPanic( ECodInternal ) ); |
|
108 |
|
109 TInt code( KHttp924LoaderError ); |
|
110 |
|
111 switch( aError ) |
|
112 { |
|
113 case KErrNone: |
|
114 { |
|
115 code = KHttp900Success; |
|
116 break; |
|
117 } |
|
118 |
|
119 case KErrNoMemory: |
|
120 case KErrDiskFull: |
|
121 { |
|
122 code = KHttp910NoMemory; |
|
123 break; |
|
124 } |
|
125 |
|
126 case KErrCodInsufficientSpace: |
|
127 { |
|
128 code = KHttp901InsufficientMemory; |
|
129 break; |
|
130 } |
|
131 |
|
132 case KErrCancel: |
|
133 case KErrAbort: |
|
134 { |
|
135 code = aState == EReady ? |
|
136 KHttp921UserAborted : // EReady -> COD rejected by user. |
|
137 KHttp902UserCancelled; // other -> something is cancelled. |
|
138 break; |
|
139 } |
|
140 |
|
141 case KErrCodInvalidDescriptor: |
|
142 case KErrCodUnsupportedVersion: |
|
143 { |
|
144 code = KHttp906InvalidDescriptor; |
|
145 break; |
|
146 } |
|
147 |
|
148 case KErrCodAttributeMismatch: |
|
149 { |
|
150 code = KHttp905AttributeMismatch; |
|
151 break; |
|
152 } |
|
153 |
|
154 case KErrCodInvalidType: |
|
155 { |
|
156 code = KHttp907InvalidType; |
|
157 break; |
|
158 } |
|
159 |
|
160 case KBadMimeType: |
|
161 case KMimeNotSupported: |
|
162 { |
|
163 code = iState == ESet ? |
|
164 KHttp922DeviceAborted : // ESet -> COD MIME bad. |
|
165 KHttp923NonAcceptableContent;// EFetch -> content MIME bad. |
|
166 break; |
|
167 } |
|
168 |
|
169 case KErrTimedOut: |
|
170 case KErrCodHttpCommsFailed: |
|
171 case KErrCodHttpNoResponse: |
|
172 { |
|
173 code = KHttp903LossOfService; |
|
174 break; |
|
175 } |
|
176 |
|
177 default: |
|
178 { |
|
179 code = KHttp924LoaderError; |
|
180 break; |
|
181 } |
|
182 } |
|
183 return code; |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------- |
|
187 // CCodEng::StatusText() |
|
188 // --------------------------------------------------------- |
|
189 // |
|
190 const TDesC8& CCodEng::StatusText( TInt aCode ) const |
|
191 { |
|
192 switch ( aCode ) |
|
193 { |
|
194 case KHttp900Success: return KText900Success; |
|
195 case KHttp901InsufficientMemory: return KText901InsufficientMemory; |
|
196 case KHttp902UserCancelled: return KText902UserCancelled; |
|
197 case KHttp903LossOfService: return KText903LossOfService; |
|
198 case KHttp905AttributeMismatch: return KText905AttributeMismatch; |
|
199 case KHttp906InvalidDescriptor: return KText906InvalidDescriptor; |
|
200 case KHttp907InvalidType: return KText907InvalidType; |
|
201 case KHttp921UserAborted: return KText921UserAborted; |
|
202 case KHttp922DeviceAborted: return KText922DeviceAborted; |
|
203 case KHttp923NonAcceptableContent: return KText923NonAcceptableContent; |
|
204 case KHttp924LoaderError: return KText924LoaderError; |
|
205 case KHttp910NoMemory: return KText910NoMemory; |
|
206 default: CodPanic( ECodInternal ); |
|
207 } |
|
208 return KNullDesC8; /* NOTREACHED */ |
|
209 } |